[Epic-ID: ODUHIGH-516][Task-ID: 527] Implementation of E2 Node Configuration Update...
[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 "du_tmr.h"
22 #include "ckw.h"
23 #include "ckw.x"
24 #include "kwu.h"
25 #include "kwu.x"
26 #include "lkw.h"
27 #include "lrg.h"
28 #include "legtp.h"
29 #include "lkw.x"
30 #include "lrg.x"
31 #include "F1AP-PDU.h"
32 #include "InitiatingMessage.h"
33 #include "SuccessfulOutcome.h"
34 #include "du_app_mac_inf.h"
35 #include "du_cfg.h"
36 #include "du_app_rlc_inf.h"
37 #include "du_e2ap_mgr.h"
38 #include "du_e2ap_msg_hdl.h"
39 #include "du_mgr_main.h"
40 #include "du_mgr.h"
41 #include "du_utils.h"
42 #include "du_ue_mgr.h"
43 #include "RAT-Type.h"
44 #include "NRFreqInfo.h"
45 #include "NRCGI.h"
46 #include "TDD-Info.h"
47 #include "NR-Mode-Info.h"
48 #include "ServedPLMNs-List.h"
49 #include "GNB-DU-Served-Cells-List.h"
50 #include "Served-Cell-Information.h"
51 #include "ProtocolExtensionContainer.h"
52 #include "RRC-Version.h"
53 #include "FDD-Info.h"
54 #include "FreqBandNrItem.h"
55 #include "ServedPLMNs-Item.h"
56 #include "GNB-DU-Served-Cells-Item.h"
57 #include "SliceSupportItem.h"
58 #include "FeatureSetUplinkPerCC.h"
59 #include "SliceSupportItem.h"
60 #include "Served-Cells-To-Modify-Item.h"
61 #include "Served-Cells-To-Delete-List.h"
62 #include "Served-Cells-To-Delete-Item.h"
63 #include "QoSInformation.h"
64 #include "ULUPTNLInformation-ToBeSetup-List.h"
65 #include "DRB-Information.h"
66 #include "DRBs-ToBeSetup-Item.h"
67 #include "DRBs-ToBeSetupMod-Item.h"
68 #include "DRBs-ToBeModified-Item.h"
69 #include "CUtoDURRCInformation.h"
70 #include "SCell-ToBeSetup-List.h"
71 #include "SRBs-ToBeSetup-List.h"
72 #include "DRBs-ToBeSetup-List.h"
73 #include "SRBs-ToBeSetup-Item.h"
74 #include "DRBs-ToBeModified-List.h"
75 #include "RRCContainer.h"
76 #include "UE-CapabilityRAT-ContainerList.h"
77 #include "DRBs-Setup-List.h"
78 #include "CellGroupConfig.h"
79 #include "ResetAll.h"
80 #include "ResetType.h"
81 #include "Cells-to-be-Activated-List.h"
82 #include "GNB-CU-Name.h"
83 #include "SRBs-SetupMod-List.h"
84 #include "DRBs-SetupMod-List.h"
85 #include "DRBs-ToBeSetupMod-List.h"
86 #include "PagingCell-Item.h"
87 #include "PagingCell-list.h"
88 #include "QoS-Characteristics.h"
89 #include "ULUPTNLInformation-ToBeSetup-Item.h"
90 #include "Flows-Mapped-To-DRB-Item.h"
91 #include "NonDynamic5QIDescriptor.h"
92 #include "Dynamic5QIDescriptor.h"
93 #include "FeatureSetDownlinkPerCC.h"
94 #include "FeatureSets.h"
95 #include "UE-NR-Capability.h"
96 #include "UE-CapabilityRAT-Container.h"
97 #include "UE-CapabilityRAT-ContainerListRRC.h"
98 #include "GNB-DU-System-Information.h"
99 #include "CellGroupConfigRrc.h"
100 #include "MAC-CellGroupConfig.h"
101 #include "SchedulingRequestConfig.h"
102 #include "SchedulingRequestToAddMod.h"
103 #include "BSR-Config.h"
104 #include "TAG-Config.h"
105 #include "TAG.h"
106 #include "PHR-Config.h"
107 #include "RLC-Config.h"
108 #include "UL-AM-RLC.h"
109 #include "DL-AM-RLC.h"
110 #include "LogicalChannelConfig.h"
111 #include "RLC-BearerConfig.h"
112 #include "PhysicalCellGroupConfig.h"
113 #include "SpCellConfig.h"
114 #include "TDD-UL-DL-ConfigDedicated.h"
115 #include "ServingCellConfig.h"
116 #include "ControlResourceSet.h"
117 #include "SearchSpace.h"
118 #include "PDCCH-Config.h"
119 #include "PDSCH-TimeDomainResourceAllocation.h"
120 #include "PDSCH-TimeDomainResourceAllocationList.h"
121 #include "PDSCH-CodeBlockGroupTransmission.h"
122 #include "PDSCH-ServingCellConfig.h"
123 #include "DMRS-DownlinkConfig.h"
124 #include "PDSCH-Config.h"
125 #include "BWP-DownlinkDedicated.h"
126 #include "BWP-Downlink.h"
127 #include "PUSCH-TimeDomainResourceAllocation.h"
128 #include "PUSCH-TimeDomainResourceAllocationList.h"
129 #include "DMRS-UplinkConfig.h"
130 #include "PUSCH-Config.h"
131 #include "SRS-ResourceId.h"
132 #include "SRS-Resource.h"
133 #include "SRS-ResourceSet.h"
134 #include "SRS-Config.h"
135 #include "BWP-UplinkDedicated.h"
136 #include "PUSCH-ServingCellConfig.h"
137 #include "UplinkConfig.h"
138 #include "DUtoCURRCContainer.h"
139 #include "GBR-QoSFlowInformation.h"
140 #include "QoSFlowLevelQoSParameters.h"
141 #include "PUCCH-Config.h"
142 #include "PUCCH-ResourceSet.h"
143 #include "PUCCH-Resource.h"
144 #include "PUCCH-PowerControl.h"
145 #include "P0-PUCCH.h"
146 #include "PUCCH-PathlossReferenceRS.h"
147 #include "PUCCH-format0.h"
148 #include "PUCCH-format1.h"
149 #include "PUCCH-format2.h"
150 #include "PUCCH-format3.h"
151 #include "PUCCH-format4.h"
152 #include "PUCCH-FormatConfig.h"
153 #include "SchedulingRequestResourceConfig.h"
154 #include<ProtocolIE-Field.h>
155 #include "ProtocolExtensionField.h"
156 #include "odu_common_codec.h"
157 #include "du_mgr.h"
158 #include "du_cell_mgr.h"
159 #include "du_f1ap_msg_hdl.h"
160 #include "DRBs-Setup-Item.h"
161 #include "DLUPTNLInformation-ToBeSetup-List.h"
162 #include "DLUPTNLInformation-ToBeSetup-Item.h"
163 #include "UPTransportLayerInformation.h"
164 #include "GTPTunnel.h"
165 #include "SupportedSULFreqBandItem.h"
166 #include "du_f1ap_conversions.h"
167 #include "CNUEPagingIdentity.h"
168 #include "PCCH-Config.h"
169 #include "SCS-SpecificCarrier.h"
170 #include "FrequencyInfoDL.h"
171 #include "DownlinkConfigCommon.h"
172 #include "FrequencyInfoUL.h"
173 #include "UplinkConfigCommon.h"
174 #include "TDD-UL-DL-ConfigCommon.h"
175 #include "RACH-ConfigDedicated.h"
176 #include "CFRA-SSB-Resource.h"
177 #include "BWP-UplinkCommon.h"
178 #include "ReconfigurationWithSync.h"
179 #include "BCCH-DL-SCH-Message.h"
180 #include "du_sys_info_hdl.h"
181 #include "DRX-ConfigRrc.h"
182 #include "MeasurementTimingConfigurationRrc.h"
183 #include "MeasurementTimingConfigurationRrc-IEs.h"
184 #include "MeasTimingList.h"
185 #include "MeasTiming.h"
186 #include "Cells-Status-List.h"
187 #include "Cells-Status-Item.h"
188
189 #ifdef O1_ENABLE
190 #include "CmInterface.h"
191 extern StartupConfig g_cfg;
192 #endif
193
194 DuCfgParams duCfgParam;
195
196 /******************************************************************
197  *
198  * @brief Function to fetch lcId based on DRB Id
199  *
200  * @details
201  *
202  *    Function : fetchLcId
203  *
204  *    @params[in] drbId
205  *
206  *    Functionality: Function to fetch lcId based on DRB Id
207  *
208  * Returns: lcId - SUCCESS
209  *          RFAILED - FAILURE
210  *****************************************************************/
211
212 uint8_t fetchLcId(uint8_t drbId)
213 {
214    uint8_t cellIdx = 0, ueIdx = 0, lcIdx = 0, numLcs = 0, lcId = 0;
215
216    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
217    {
218       for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
219       {
220          if(duCb.actvCellLst[cellIdx] != NULLP)
221          {
222             numLcs = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.numLcs;
223             for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
224             {
225                if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId == drbId && \
226                   duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
227                {
228                   lcId = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId;
229                   return lcId;
230                }
231             }
232          }
233       }
234    }
235    DU_LOG("\nERROR   -->  DU_APP: fetchLcId() failed for drbId %d", drbId);
236    return RFAILED;
237 }
238
239 /*******************************************************************
240 *
241 * @brief Adding F1AP pdu to reserved pdu list
242 *
243 * @details
244 *
245 *    Function : addToReservedF1apPduList 
246 *
247 *    Functionality: Adding F1AP pdu to reserved pdu list.
248 *     These pdu are awaiting aknowledgment from CU
249 *
250 * @params[in] uint8_t transId, F1AP_PDU_t *f1apMsg
251 *
252 * @return ROK - success
253 *         RFAILED - failure
254 *
255 * ****************************************************************/
256 void addToReservedF1apPduList(uint8_t transId, F1AP_PDU_t *f1apPdu)
257 {
258    CmLList         *node = NULLP;
259    ReservedF1apPduInfo *pduInfo = NULLP;
260    DU_ALLOC(pduInfo, sizeof(ReservedF1apPduInfo));
261    if(pduInfo)
262    {
263       DU_ALLOC(node, sizeof(CmLList));
264       if(node)
265       {
266          pduInfo->transId = transId;
267          pduInfo->f1apMsg = (void*) f1apPdu;
268
269          node->node = (PTR)pduInfo;
270          cmLListAdd2Tail(&duCb.reservedF1apPduList, node);
271       }
272    }
273 }
274
275 /*******************************************************************
276 *
277 * @brief searching for F1AP pdu from ReservedF1apPduList 
278 *
279 * @details
280 *
281 *    Function : searchFromReservedF1apPduList 
282 *
283 *    Functionality: searching for F1AP pdu information
284 *
285 * @params[in] uint8_t transId
286 *
287 * @return pointer to F1AP_PDU_t
288 *
289 * ****************************************************************/
290
291 CmLList *searchFromReservedF1apPduList(uint8_t transId)
292 {
293    CmLList         *node;
294    ReservedF1apPduInfo *f1apPdu;
295    if(duCb.reservedF1apPduList.count)
296    {
297       CM_LLIST_FIRST_NODE(&duCb.reservedF1apPduList, node);
298       while(node)
299       {
300          f1apPdu = (ReservedF1apPduInfo*)node->node;
301          if(f1apPdu->transId == transId)
302          {
303             return node;
304          }
305          node = node->next;
306       }
307    }
308    return NULL;
309 }
310
311 /*******************************************************************
312 *
313 * @brief deleting F1AP pdu information from ReservedF1apPduList
314 *
315 * @details
316 *
317 *    Function : deleteFromReservedF1apPduList 
318 *
319 *    Functionality: deleting pdu information from ReservedF1apPduList
320 *
321 * @params[in] CmLList *node 
322 *
323 * @return void 
324 *
325 * ****************************************************************/
326
327 void deleteFromReservedF1apPduList(CmLList *node)
328 {
329    ReservedF1apPduInfo *f1apPdu;
330
331    if(node != NULL)
332    {
333       f1apPdu = (ReservedF1apPduInfo *)node->node;
334       cmLListDelFrm(&duCb.reservedF1apPduList, node);
335       DU_FREE(f1apPdu, sizeof(ReservedF1apPduInfo));
336       DU_FREE(node, sizeof(CmLList));
337       node = NULL;
338    }
339 }
340
341 /*******************************************************************
342  *
343  * @brief Builds Uplink Info for NR 
344  *
345  * @details
346  *
347  *    Function : BuildULNRInfo
348  *
349  *    Functionality: Building NR Uplink Info
350  *
351  * @params[in] NRFreqInfo_t *ulnrfreq
352  * @return ROK     - success
353  *         RFAILED - failure
354  *
355  * ****************************************************************/
356 uint8_t BuildULNRInfo(NRFreqInfo_t *ulnrfreq)
357 {
358    uint8_t idx=0;
359    ulnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
360                        fdd.ulNrFreqInfo.nrArfcn;
361    ulnrfreq->freqBandListNr.list.count = 1;
362    ulnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
363    DU_ALLOC(ulnrfreq->freqBandListNr.list.array,ulnrfreq->freqBandListNr.list.size);
364    if(ulnrfreq->freqBandListNr.list.array == NULLP)
365    {
366       return RFAILED;
367    }
368    for(idx=0;idx<ulnrfreq->freqBandListNr.list.count;idx++)
369    {
370       DU_ALLOC(ulnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
371       if(ulnrfreq->freqBandListNr.list.array[idx] == NULLP)
372       {
373          return RFAILED;
374       }
375    }
376    ulnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
377                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
378                                                                  freqBand[0].nrFreqBand;
379    ulnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
380    return ROK;
381 }
382 /*******************************************************************
383  *
384  * @brief Builds Downlink NR Info 
385  *
386  * @details
387  *
388  *    Function : BuildDLNRInfo
389  *
390  *    Functionality: Building Downlink NR Info
391  *    
392  * @params[in] NRFreqInfo_t *dlnrfreq
393  * @return ROK     - success
394  *         RFAILED - failure
395  *
396  * ****************************************************************/
397 uint8_t BuildDLNRInfo(NRFreqInfo_t *dlnrfreq)
398 {
399    uint8_t idx=0;
400    dlnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
401                        fdd.dlNrFreqInfo.nrArfcn;
402    dlnrfreq->freqBandListNr.list.count = 1;
403    dlnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
404    DU_ALLOC(dlnrfreq->freqBandListNr.list.array,dlnrfreq->freqBandListNr.list.size);
405    if(dlnrfreq->freqBandListNr.list.array == NULLP)
406    {
407       return RFAILED;   
408    }
409    for(idx=0;idx< dlnrfreq->freqBandListNr.list.count;idx++)
410    {
411       DU_ALLOC(dlnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
412       if(dlnrfreq->freqBandListNr.list.array[idx] == NULLP)
413       {
414          return RFAILED;
415       }
416    }   
417    dlnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
418                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
419                                                                  freqBand[0].nrFreqBand;
420    dlnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
421
422    return ROK;
423 }
424
425 /*******************************************************************
426  *
427  * @brief Builds Nrcgi 
428  *
429  * @details
430  *
431  *    Function : BuildNrcgi
432  *
433  *    Functionality: Building the PLMN ID and NR Cell id
434  *
435  * @params[in] NRCGI_t *nrcgi
436  * @return ROK     - success
437  *         RFAILED - failure
438  *
439  * ****************************************************************/
440 uint8_t BuildNrcgi(NRCGI_t *nrcgi)
441 {
442    uint8_t ret;
443    uint8_t byteSize = 5;
444    /* Allocate Buffer Memory */
445    nrcgi->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
446    DU_ALLOC(nrcgi->pLMN_Identity.buf, nrcgi->pLMN_Identity.size);
447    if(nrcgi->pLMN_Identity.buf == NULLP)
448    {
449       return RFAILED;
450    }
451    ret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
452          nrcgi->pLMN_Identity.buf); // Building PLMN function
453    if(ret != ROK)
454    {
455       return RFAILED;
456    }
457    /*nrCellIdentity*/
458    nrcgi->nRCellIdentity.size = byteSize * sizeof(uint8_t);
459    DU_ALLOC(nrcgi->nRCellIdentity.buf, nrcgi->nRCellIdentity.size); 
460    if(nrcgi->nRCellIdentity.buf == NULLP)
461    {
462       return RFAILED;
463    }
464    fillBitString(&nrcgi->nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
465
466    return ROK;
467 }
468 /*******************************************************************
469  *
470  * @brief Builds FiveGStac 
471  *
472  * @details
473  *
474  *    Function : BuildFiveGSTac
475  *
476  *    Functionality: Building the FiveGSTac
477  *
478  * @params[in] OCTET_STRING_t *fivegsTac
479  * @return ROK     - success
480  *         RFAILED - failure
481  *
482  * ****************************************************************/
483 uint8_t BuildFiveGSTac(Served_Cell_Information_t *servcell)
484 {
485    DU_ALLOC(servcell->fiveGS_TAC,sizeof(FiveGS_TAC_t));
486    if(servcell->fiveGS_TAC == NULLP)
487    {
488       return RFAILED;
489    }
490    servcell->fiveGS_TAC->size = 3 * sizeof(uint8_t);
491    DU_ALLOC(servcell->fiveGS_TAC->buf,\
492          sizeof(servcell->fiveGS_TAC->size));
493    if(servcell->fiveGS_TAC->buf == NULLP)
494    {
495       return RFAILED;
496    }
497    servcell->fiveGS_TAC->buf[0] = 0;
498    servcell->fiveGS_TAC->buf[1] = 0;
499    servcell->fiveGS_TAC->buf[2] = duCfgParam.srvdCellLst[0].duCellInfo.tac;
500    return ROK;  
501 }
502
503 /*******************************************************************
504  *
505  * @brief fill nr frequency information
506  *
507  * @details
508  *
509  *    Function : fillNrTddInfo 
510  *
511  *    Functionality: fill nr frequency information
512  *
513  * @params[in] NRFreqInfo_t freqInfo
514  * @return ROK     - success
515  *         RFAILED - failure
516  *
517  * ****************************************************************/
518 uint8_t fillNrTddInfo(TDD_Info_t *tddInfo)
519 {
520    uint8_t elementCnt = 1, freqBandListIdx = 0, supportedBandIdx = 0;
521    NRFreqInfo_t *freqInfo = NULLP;
522
523    if(tddInfo == NULLP)
524    {
525       DU_LOG("\nERROR  --> DU APP : Null pointer received at fillNrTddInfo");
526       return RFAILED;
527    }
528    
529    freqInfo = &tddInfo->nRFreqInfo;
530    freqInfo->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.nrArfcn; 
531
532    freqInfo->freqBandListNr.list.count = elementCnt; 
533    freqInfo->freqBandListNr.list.size = freqInfo->freqBandListNr.list.count  * sizeof(FreqBandNrItem_t *);
534    DU_ALLOC(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
535    if(!freqInfo->freqBandListNr.list.array)
536    {
537       DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
538       return RFAILED;
539    }
540
541    for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
542    {
543       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
544       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx])
545       {
546          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
547          return RFAILED;
548       }
549
550       freqInfo->freqBandListNr.list.array[freqBandListIdx]->freqBandIndicatorNr = duCfgParam.srvdCellLst[0].duCellInfo.\
551       f1Mode.mode.tdd.nrFreqInfo.freqBand[0].nrFreqBand;
552
553       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count = elementCnt;
554       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size = freqInfo->freqBandListNr.list.array[freqBandListIdx]->\
555       supportedSULBandList.list.count * sizeof(SupportedSULFreqBandItem_t*);
556
557       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
558             freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
559       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
560       {
561          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
562          return RFAILED;
563       }
564
565       for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
566       {
567          DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
568                sizeof(SupportedSULFreqBandItem_t));
569          if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx])
570          {
571             DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
572             return RFAILED;
573          }
574
575          freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx]->freqBandIndicatorNr =\
576          duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[0].sulBand[0];
577       }
578    }
579
580    tddInfo->transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrScs;
581    tddInfo->transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrb;
582
583    return ROK;
584 }
585
586 /*******************************************************************
587  *
588  * @brief Builds NR Mode 
589  *
590  * @details
591  *
592  *    Function : BuildNrMode
593  *
594  *    Functionality: Building the NR Mode
595  *
596  * @params[in] NR_Mode_Info_t *fdd
597  * @return ROK     - success
598  *         RFAILED - failure
599  *
600  * ****************************************************************/
601 uint8_t BuildNrMode(NR_Mode_Info_t *mode)
602 {
603    uint8_t BuildDLNRInforet=0;
604    uint8_t BuildULNRInforet=0; 
605    
606 #ifdef NR_TDD
607    mode->present = NR_Mode_Info_PR_tDD;
608 #else
609    mode->present = NR_Mode_Info_PR_fDD;
610 #endif   
611    
612    if(mode->present == NR_Mode_Info_PR_fDD)
613    {
614       DU_ALLOC(mode->choice.fDD,sizeof(FDD_Info_t));
615       if(mode->choice.fDD == NULLP)
616       {
617          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
618          return RFAILED;
619       }
620       BuildULNRInforet = BuildULNRInfo(&mode->choice.fDD->uL_NRFreqInfo);
621       if(BuildULNRInforet != ROK)
622       {
623          DU_LOG("\nERROR  --> Failed to build UlNrFreqInfo");
624          return RFAILED;    
625       }
626       BuildDLNRInforet = BuildDLNRInfo(&mode->choice.fDD->dL_NRFreqInfo);
627       if(BuildDLNRInforet != ROK)
628       {
629          DU_LOG("\nERROR  --> Failed to build DlNrFreqInfo");
630          return RFAILED;
631       }
632       mode->choice.fDD->uL_Transmission_Bandwidth.nRSCS = \
633                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
634                                                           f1Mode.mode.fdd.ulTxBw.nrScs;
635       mode->choice.fDD->uL_Transmission_Bandwidth.nRNRB = \
636                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
637                                                           f1Mode.mode.fdd.ulTxBw.nrb;
638       mode->choice.fDD->dL_Transmission_Bandwidth.nRSCS = \
639                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
640                                                           f1Mode.mode.fdd.dlTxBw.nrScs;
641       mode->choice.fDD->dL_Transmission_Bandwidth.nRNRB = \
642                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
643                                                           f1Mode.mode.fdd.dlTxBw.nrb;
644    }
645    else if(mode->present == NR_Mode_Info_PR_tDD) 
646    {
647       DU_ALLOC(mode->choice.tDD,sizeof(TDD_Info_t));
648       if(mode->choice.tDD == NULLP)
649       {
650          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
651          return RFAILED;
652       }
653
654       if(fillNrTddInfo(mode->choice.tDD) != ROK)
655       {
656          DU_LOG("\nERROR  --> Failed to fill Nr TDD information");
657          return RFAILED;
658       }
659
660    }
661
662    return ROK;
663 }
664 /*******************************************************************
665  *
666  * @brief Builds IE Extensions for Served PLMNs 
667  *
668  * @details
669  *
670  *    Function : BuildExtensions
671  *
672  *    Functionality: Building the IE Extensions
673  *
674  * @params[in] struct ProtocolExtensionContainer_4624P3 *buildextend
675  * @return ROK     - success
676  *         RFAILED - failure
677  *
678  * ****************************************************************/
679 uint8_t BuildExtensions(ProtocolExtensionContainer_4624P3_t **ieExtend)
680 {
681    uint8_t idx=0, plmnidx=0, sliceLstIdx=0;
682    uint8_t elementCnt=0, extensionCnt=0;
683
684    extensionCnt=IE_EXTENSION_LIST_COUNT;
685    DU_ALLOC(*ieExtend,sizeof(ProtocolExtensionContainer_4624P3_t));
686    if((*ieExtend) == NULLP)
687    {
688       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
689       return RFAILED;
690    }
691    (*ieExtend)->list.count = extensionCnt;
692    (*ieExtend)->list.size = \
693                             extensionCnt * sizeof(ServedPLMNs_ItemExtIEs_t *);
694    DU_ALLOC((*ieExtend)->list.array,(*ieExtend)->list.size);
695    if((*ieExtend)->list.array == NULLP)
696    {
697       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
698       return RFAILED;
699    }
700    for(plmnidx=0;plmnidx<extensionCnt;plmnidx++)
701    {
702       DU_ALLOC((*ieExtend)->list.array[plmnidx],\
703             sizeof(ServedPLMNs_ItemExtIEs_t));
704       if((*ieExtend)->list.array[plmnidx] == NULLP)
705       {
706          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
707          return RFAILED;
708       }
709    }
710    
711    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices;
712    idx = 0;
713    (*ieExtend)->list.array[idx]->id = ProtocolIE_ID_id_TAISliceSupportList;
714    (*ieExtend)->list.array[idx]->criticality = Criticality_ignore;
715    (*ieExtend)->list.array[idx]->extensionValue.present = \
716    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
717    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
718       list.count = elementCnt;
719    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
720       list.size = (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
721       list.count * sizeof(SliceSupportItem_t *);
722
723    DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
724          list.array, elementCnt * sizeof(SliceSupportItem_t *));
725    if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
726          list.array == NULLP)
727    {
728       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
729       return RFAILED;
730    }
731
732    for(sliceLstIdx =0; sliceLstIdx<elementCnt; sliceLstIdx++)
733    {
734       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
735             list.array[sliceLstIdx],sizeof(SliceSupportItem_t));
736       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
737             list.array[sliceLstIdx] == NULLP) 
738       {
739          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
740          return RFAILED;
741       }
742       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
743          list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
744       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
745             .list.array[sliceLstIdx]->sNSSAI.sST.buf,(*ieExtend)->list.array[idx]->\
746             extensionValue.choice.SliceSupportList.\
747             list.array[sliceLstIdx]->sNSSAI.sST.size);
748       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
749             .list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
750       {
751          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
752          return RFAILED;
753       }
754       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
755          list.array[sliceLstIdx]->sNSSAI.sST.buf[0] = duCfgParam.srvdCellLst[0].duCellInfo.\
756          cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
757       
758       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
759             list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
760       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
761             list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
762       {
763          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
764          return RFAILED;
765       }
766       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
767          list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
768       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
769             list.array[sliceLstIdx]->sNSSAI.sD->buf, (*ieExtend)->list.array[idx]->extensionValue.choice.\
770             SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
771       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
772             list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
773       {
774          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
775          return RFAILED;
776       }
777       memcpy((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
778       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[0].duCellInfo.\
779       cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sd, (*ieExtend)->list.array[idx]->\
780       extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
781    }
782    return ROK;
783 }
784 /*******************************************************************
785  *
786  * @brief Builds Served PLMN 
787  *
788  * @details
789  *
790  *    Function : BuildServedPlmn
791  *
792  *    Functionality: Building the Served PLMN
793  *
794  * @params[in] GNB_DU_Served_Cells_Item_t *srvCellItem
795  * @return ROK     - success
796  *         RFAILED - failure
797  *
798  * ****************************************************************/
799 uint8_t  BuildServedPlmn(ServedPLMNs_List_t *srvplmn)
800 {  
801    uint8_t  plmnidx;
802    uint8_t  servPlmnCnt=1;
803    uint8_t buildPlmnIdret=0;
804    uint8_t BuildExtensionsret=0;
805    srvplmn->list.count = servPlmnCnt;
806    srvplmn->list.size = \
807                         servPlmnCnt*sizeof(ServedPLMNs_Item_t *);
808    DU_ALLOC(srvplmn->list.array,srvplmn->list.size);
809    if(srvplmn->list.array == NULLP)
810    {
811       return RFAILED;
812    }
813    for(plmnidx=0; plmnidx<servPlmnCnt; plmnidx++)
814    {   
815       DU_ALLOC(srvplmn->list.array[plmnidx],\
816             sizeof(ServedPLMNs_Item_t));
817       if(srvplmn->list.array[plmnidx] == NULLP)
818       {
819          return RFAILED;
820       }  
821    }
822    srvplmn->list.array[0]->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
823    DU_ALLOC(srvplmn->list.array[0]->pLMN_Identity.buf, srvplmn->list.array[0]->pLMN_Identity.size);
824    buildPlmnIdret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
825          srvplmn->list.array[0]->pLMN_Identity.buf);
826    if(buildPlmnIdret!= ROK)
827    {
828       return RFAILED;
829    }
830    BuildExtensionsret = BuildExtensions(&srvplmn->list.array[0]->iE_Extensions);
831    if(BuildExtensionsret!= ROK)
832    {
833       return RFAILED;
834    }
835    return ROK;
836 }
837
838 /*******************************************************************
839  *
840  * @brief Frees Measurement Timing configuration 
841  *
842  * @details
843  *
844  *    Function : FreeMeasTimingConf
845  *
846  *    Functionality: Frees Timing Configuration
847  *
848  * @params[in] MeasurementTimingConfigurationRrc_t measTimingConfRrc
849  * @return ROK     - success
850  *         RFAILED - failure
851  *
852  * ****************************************************************/
853 void FreeMeasTimingConf(MeasurementTimingConfigurationRrc_t   measTimingConfRrc)
854 {
855    uint8_t measIeIdx = 0;
856    MeasurementTimingConfigurationRrc_IEs_t  *measTimingConfIEs = NULLP;
857
858    if(measTimingConfRrc.criticalExtensions.choice.c1)
859    {
860       if(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf)
861       {
862          measTimingConfIEs = measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf;
863          if(measTimingConfIEs->measTiming)
864          {
865             if(measTimingConfIEs->measTiming->list.array)
866             {
867                for(measIeIdx = 0; measIeIdx < measTimingConfIEs->measTiming->list.count; measIeIdx++)
868                {
869                   if(measTimingConfIEs->measTiming->list.array[measIeIdx])
870                   {
871                      DU_FREE(measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming, sizeof(struct MeasTiming__frequencyAndTiming));
872                      DU_FREE(measTimingConfIEs->measTiming->list.array[measIeIdx], sizeof(MeasTiming_t));
873                   }
874                }
875                DU_FREE(measTimingConfIEs->measTiming->list.array, measTimingConfIEs->measTiming->list.size);
876             }
877             DU_FREE(measTimingConfIEs->measTiming, sizeof(MeasTimingList_t));
878          }
879          DU_FREE(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf, sizeof(MeasurementTimingConfigurationRrc_IEs_t));
880       }
881       DU_FREE(measTimingConfRrc.criticalExtensions.choice.c1, sizeof(struct MeasurementTimingConfigurationRrc__criticalExtensions__c1));
882    }
883 }
884
885 /*******************************************************************
886  *
887  * @brief Builds MEasuerment Timing Configuration
888  *
889  * @details
890  *
891  *    Function : BuildMeasTimingConf
892  *
893  *    Functionality: Building Measurement Timing Configuration
894  *
895  * @params[in] Pointer to octet string to store Measurement timing
896  *             Configuration
897  * @return ROK     - success
898  *         RFAILED - failure
899  *
900  * ****************************************************************/
901 uint8_t BuildMeasTimingConf(OCTET_STRING_t *measTimingConf)
902 {
903    uint8_t ret = RFAILED;
904    uint8_t elementCnt = 0;
905    uint8_t measIeIdx = 0;
906    asn_enc_rval_t encRetVal;
907    MeasurementTimingConfigurationRrc_t   measTimingConfRrc;
908    MeasurementTimingConfigurationRrc_IEs_t  *measTimingConfIEs = NULLP;
909    struct MeasTiming__frequencyAndTiming  *freqAndTiming = NULLP;
910
911    while(true)
912    {
913       measTimingConfRrc.criticalExtensions.present = MeasurementTimingConfigurationRrc__criticalExtensions_PR_c1;
914       DU_ALLOC(measTimingConfRrc.criticalExtensions.choice.c1, sizeof(struct MeasurementTimingConfigurationRrc__criticalExtensions__c1));
915       if(!measTimingConfRrc.criticalExtensions.choice.c1)
916       {
917          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for critical extension choice C1");
918          break;
919       }
920       measTimingConfRrc.criticalExtensions.choice.c1->present = MeasurementTimingConfigurationRrc__criticalExtensions__c1_PR_measTimingConf;
921
922       DU_ALLOC(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf, sizeof(MeasurementTimingConfigurationRrc_IEs_t));
923       if(!measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf)
924       {
925          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for measTimingConf");
926          break;
927       }
928       measTimingConfIEs = measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf;
929
930       DU_ALLOC(measTimingConfIEs->measTiming, sizeof(MeasTimingList_t));
931       if(!measTimingConfIEs->measTiming)
932       {
933          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList");
934          break;
935       }
936
937       elementCnt = 1;  
938       measTimingConfIEs->measTiming->list.count = elementCnt;
939       measTimingConfIEs->measTiming->list.size = elementCnt * sizeof(MeasTiming_t *);
940       DU_ALLOC(measTimingConfIEs->measTiming->list.array, measTimingConfIEs->measTiming->list.size);
941       if(!measTimingConfIEs->measTiming->list.array)
942       {
943          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList array");
944          break;
945       }
946
947       for(measIeIdx = 0; measIeIdx < elementCnt; measIeIdx++)
948       {
949          DU_ALLOC(measTimingConfIEs->measTiming->list.array[measIeIdx], sizeof(MeasTiming_t));
950          if(!measTimingConfIEs->measTiming->list.array[measIeIdx])
951          {
952             DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList array index %d", measIeIdx);
953             break;
954          }
955       }
956       if(measIeIdx < elementCnt)
957       {
958          break;
959       }
960
961       measIeIdx = 0;
962       DU_ALLOC(measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming, sizeof(struct MeasTiming__frequencyAndTiming));
963       if(!measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming)
964       {
965          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for frequencyAndTiming");
966          break;
967       }
968       freqAndTiming = measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming;
969       freqAndTiming->carrierFreq = MEAS_TIMING_ARFCN;
970       freqAndTiming->ssbSubcarrierSpacing = duCfgParam.macCellCfg.ssbCfg.scsCmn;
971       freqAndTiming->ssb_MeasurementTimingConfiguration.periodicityAndOffset.present = duCfgParam.macCellCfg.ssbCfg.ssbPeriod + 1;
972       freqAndTiming->ssb_MeasurementTimingConfiguration.periodicityAndOffset.choice.sf20 = duCfgParam.macCellCfg.ssbCfg.ssbScOffset;
973       freqAndTiming->ssb_MeasurementTimingConfiguration.duration = duCfgParam.srvdCellLst[0].duCellInfo.measTimeCfgDuration;
974
975       /* Encode the F1SetupRequest type as APER */
976       xer_fprint(stdout, &asn_DEF_MeasurementTimingConfigurationRrc, &measTimingConfRrc);
977
978       memset(encBuf, 0, ENC_BUF_MAX_LEN);
979       encBufSize = 0;
980       encRetVal = uper_encode(&asn_DEF_MeasurementTimingConfigurationRrc, 0, &measTimingConfRrc, PrepFinalEncBuf, encBuf);
981
982       /* Encode results */
983       if(encRetVal.encoded == ENCODE_FAIL)
984       {     
985          DU_LOG("\nERROR  -->  F1AP : Could not encode Measurement Timing Configuration structure (at %s)\n",\
986                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
987          break;
988       }     
989       else  
990       {     
991          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Measurement Timing Configuration \n");
992 #ifdef DEBUG_ASN_PRINT
993          for(measIeIdx=0; measIeIdx< encBufSize; measIeIdx++)
994          {
995             printf("%x",encBuf[measIeIdx]);
996          }
997 #endif
998
999          measTimingConf->size = encBufSize;
1000          DU_ALLOC(measTimingConf->buf, encBufSize);
1001          if(measTimingConf->buf == NULLP)
1002          {
1003             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed for MeasurementTimingConfiguration buffer");
1004             return RFAILED;
1005          }
1006          memcpy(measTimingConf->buf, &encBuf, encBufSize);
1007
1008          FreeMeasTimingConf(measTimingConfRrc);
1009
1010          ret = ROK;
1011          break;
1012       }
1013    }
1014    return ret;
1015 }
1016
1017 /*******************************************************************
1018  *
1019  * @brief Builds Served Cell List
1020  *
1021  * @details
1022  *
1023  *    Function : BuildServedCellList
1024  *
1025  *    Functionality: Building Served Cell List
1026  *
1027  * @params[in] PLMNID plmn
1028  * @return ROK     - success
1029  *         RFAILED - failure
1030  *
1031  * ****************************************************************/
1032
1033 uint8_t BuildServedCellList(GNB_DU_Served_Cells_List_t *duServedCell)
1034 {
1035    uint8_t  BuildNrcgiret=0;
1036    uint8_t  BuildFiveGSTacret=0;
1037    uint8_t  BuildServedPlmnret=0;
1038    uint8_t  BuildNrModeret=0;
1039    uint8_t  idx;
1040    uint8_t  plmnidx;
1041    uint8_t  plmnCnt=1;
1042    GNB_DU_Served_Cells_Item_t *srvCellItem;
1043    duServedCell->list.size = plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t *);
1044    duServedCell->list.count = plmnCnt;
1045
1046    DU_ALLOC(duServedCell->list.array, duServedCell->list.size);
1047    if(duServedCell->list.array == NULLP)
1048    {
1049       return RFAILED;
1050    }
1051    for(plmnidx=0; plmnidx<plmnCnt; plmnidx++)
1052    {
1053       DU_ALLOC(duServedCell->list.array[plmnidx],\
1054             sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1055       if(duServedCell->list.array[plmnidx] == NULLP)
1056       {
1057          return RFAILED;
1058       }
1059    }
1060    idx = 0;
1061    duServedCell->list.array[idx]->id = ProtocolIE_ID_id_GNB_DU_Served_Cells_Item;
1062    duServedCell->list.array[idx]->criticality = Criticality_reject;
1063    duServedCell->list.array[idx]->value.present = \
1064                                                   GNB_DU_Served_Cells_ItemIEs__value_PR_GNB_DU_Served_Cells_Item;
1065    srvCellItem = \
1066                  &duServedCell->list.array[idx]->value.choice.GNB_DU_Served_Cells_Item;
1067    /*nRCGI*/
1068    BuildNrcgiret = BuildNrcgi(&srvCellItem->served_Cell_Information.nRCGI);
1069    if(BuildNrcgiret != ROK)
1070    {
1071       return RFAILED;
1072    }
1073    /*nRPCI*/
1074    srvCellItem->served_Cell_Information.nRPCI = \
1075                                                 duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
1076
1077    /* fiveGS_TAC */
1078    BuildFiveGSTacret = BuildFiveGSTac(&srvCellItem->served_Cell_Information);
1079    if(BuildFiveGSTacret != ROK)
1080    {
1081       return RFAILED;
1082    }
1083
1084    /* Served PLMNs */
1085    BuildServedPlmnret = BuildServedPlmn(&srvCellItem->served_Cell_Information.servedPLMNs);
1086    if(BuildServedPlmnret !=ROK)
1087    {
1088       return RFAILED;
1089    }
1090
1091    /* nR Mode Info with FDD/TDD */
1092    BuildNrModeret = BuildNrMode(&srvCellItem->served_Cell_Information.nR_Mode_Info);
1093    if(BuildNrModeret != ROK)
1094    {
1095       return RFAILED;
1096    }
1097
1098    /*Measurement timing Config*/
1099    if(BuildMeasTimingConf(&srvCellItem->served_Cell_Information.measurementTimingConfiguration) != ROK)
1100       return RFAILED;
1101
1102    /* GNB DU System Information */
1103    DU_ALLOC(srvCellItem->gNB_DU_System_Information,
1104          sizeof(GNB_DU_System_Information_t));
1105    if(!srvCellItem->gNB_DU_System_Information)
1106    {
1107       return RFAILED;
1108    }
1109    /* MIB */
1110    srvCellItem->gNB_DU_System_Information->mIB_message.size = duCfgParam.srvdCellLst[0].duSysInfo.mibLen;
1111    DU_ALLOC(srvCellItem->gNB_DU_System_Information->mIB_message.buf,
1112          srvCellItem->gNB_DU_System_Information->mIB_message.size);
1113    if(!srvCellItem->gNB_DU_System_Information->mIB_message.buf)
1114    {
1115       return RFAILED;
1116    }
1117    memcpy(srvCellItem->gNB_DU_System_Information->mIB_message.buf, duCfgParam.srvdCellLst[0].duSysInfo.mibMsg, \
1118          srvCellItem->gNB_DU_System_Information->mIB_message.size);
1119
1120    /* SIB1 */
1121    srvCellItem->gNB_DU_System_Information->sIB1_message.size =\
1122                                                               duCfgParam.srvdCellLst[0].duSysInfo.sib1Len;
1123
1124    DU_ALLOC(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,
1125          srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1126    if(!srvCellItem->gNB_DU_System_Information->sIB1_message.buf)
1127    {
1128       return RFAILED;
1129    }
1130    for(int x=0; x<srvCellItem->gNB_DU_System_Information->sIB1_message.size; x++)
1131    {
1132       srvCellItem->gNB_DU_System_Information->sIB1_message.buf[x]=\
1133                                                                   duCfgParam.srvdCellLst[0].duSysInfo.sib1Msg[x];
1134    }
1135    return ROK; 
1136 }                                                                                                                  
1137 /*******************************************************************
1138  *
1139  * @brief Builds RRC Version 
1140  *
1141  * @details
1142  *
1143  *    Function : BuildRrcVer
1144  *
1145  *    Functionality: Building RRC Version
1146  *
1147  * @params[in] int idx,int elementCnt,RRC_Version_t *rrcver
1148  * @return ROK     - success
1149  *         RFAILED - failure
1150  *
1151  * ****************************************************************/
1152 uint8_t BuildRrcVer(RRC_Version_t *rrcVer)
1153 {
1154    uint8_t rrcExt;
1155    uint8_t rrcLatest;
1156    rrcVer->latest_RRC_Version.size = sizeof(uint8_t);
1157    DU_ALLOC(rrcVer->latest_RRC_Version.buf,sizeof(uint8_t));
1158    if(rrcVer->latest_RRC_Version.buf == NULLP)
1159    {
1160       return RFAILED;
1161    }
1162    rrcVer->latest_RRC_Version.buf[0] = 0;
1163    rrcVer->latest_RRC_Version.bits_unused = 5;
1164    DU_ALLOC(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1165    if(rrcVer->iE_Extensions == NULLP)
1166    {  
1167       return RFAILED;
1168    }
1169    rrcVer->iE_Extensions->list.count = 1;
1170    rrcVer->iE_Extensions->list.size = sizeof(RRC_Version_ExtIEs_t *);
1171    DU_ALLOC(rrcVer->iE_Extensions->list.array,rrcVer->iE_Extensions->list.size);
1172    if(rrcVer->iE_Extensions->list.array == NULLP)
1173    {
1174       return RFAILED;
1175    }
1176    rrcExt = 0;
1177    DU_ALLOC(rrcVer->iE_Extensions->list.array[0],\
1178          sizeof(RRC_Version_ExtIEs_t));
1179    if(rrcVer->iE_Extensions->list.array[0] == NULLP)
1180    {
1181       return RFAILED;
1182    }
1183    rrcVer->iE_Extensions->list.array[rrcExt]->id = \
1184                                                    ProtocolIE_ID_id_latest_RRC_Version_Enhanced;
1185    rrcVer->iE_Extensions->list.array[rrcExt]->criticality = Criticality_reject;
1186    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.present =\
1187                                                                       RRC_Version_ExtIEs__extensionValue_PR_Latest_RRC_Version_Enhanced;
1188    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1189       .Latest_RRC_Version_Enhanced.size = 3*sizeof(uint8_t);
1190    DU_ALLOC(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1191          .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1192          array[rrcExt]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1193    if(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1194          .Latest_RRC_Version_Enhanced.buf == NULLP)
1195    {
1196       return RFAILED;
1197    }
1198    rrcLatest = 0;
1199    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1200       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 15;
1201    rrcLatest++;
1202    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1203       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 5;
1204    rrcLatest++;
1205    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1206       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 0;
1207    return ROK;
1208 }
1209 /*******************************************************************
1210  *
1211  * @brief Sends F1 msg over SCTP
1212  *
1213  * @details
1214  *
1215  *    Function : sendF1APMsg
1216  *
1217  *    Functionality: Sends F1 msg over SCTP
1218  *
1219  * @params[in] Region region
1220  *             Pool pool
1221  * @return ROK     - success
1222  *         RFAILED - failure
1223  *
1224  * ****************************************************************/
1225 uint8_t sendF1APMsg()
1226 {
1227    Buffer *mBuf = NULLP;
1228   
1229    if(ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) == ROK)
1230    {
1231       if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
1232       {
1233             ODU_PRINT_MSG(mBuf, 0,0);
1234
1235             if(sctpSend(mBuf, F1_INTERFACE) != ROK)
1236             {
1237                DU_LOG("\nERROR  -->  F1AP : SCTP Send failed");
1238                ODU_PUT_MSG_BUF(mBuf);
1239                return RFAILED;
1240             }
1241       }
1242       else
1243       {
1244          DU_LOG("\nERROR  -->  F1AP : ODU_ADD_POST_MSG_MULT failed");
1245          ODU_PUT_MSG_BUF(mBuf);
1246          return RFAILED;
1247       }
1248       ODU_PUT_MSG_BUF(mBuf);
1249    }
1250    else
1251    {
1252       DU_LOG("\nERROR  -->  F1AP : Failed to allocate memory");
1253       return RFAILED;
1254    }
1255    return ROK; 
1256 } /* sendF1APMsg */
1257
1258 /*******************************************************************
1259  *
1260  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1261  *
1262  * @details
1263  *
1264  *    Function :  FreeRrcVer
1265  *
1266  *    Functionality: deallocating the memory of function BuildRrcVer
1267  *
1268  * @params[in] RRC_Version_t *rrcVer
1269  * 
1270  * @return void
1271  *
1272  *****************************************************************/
1273 void FreeRrcVer(RRC_Version_t *rrcVer)
1274 {
1275    if(rrcVer->latest_RRC_Version.buf != NULLP)
1276    {
1277       if(rrcVer->iE_Extensions != NULLP)
1278       {
1279          if(rrcVer->iE_Extensions->list.array != NULLP)
1280          {
1281             if(rrcVer->iE_Extensions->list.array[0] != NULLP)
1282             {
1283                if(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf
1284                      != NULLP)
1285                {
1286                   DU_FREE(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice\
1287                         .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1288                         array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1289                }
1290                DU_FREE(rrcVer->iE_Extensions->list.array[0],sizeof(RRC_Version_ExtIEs_t));
1291             }
1292             DU_FREE(rrcVer->iE_Extensions->list.array,sizeof(RRC_Version_ExtIEs_t*));
1293          }
1294          DU_FREE(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1295       }
1296       DU_FREE(rrcVer->latest_RRC_Version.buf,rrcVer->latest_RRC_Version.size);
1297    }
1298 }
1299
1300 /*******************************************************************
1301  *
1302  * @brief Deallocating memory of TDD NrFreqInfo 
1303  *
1304  * @details
1305  *
1306  *    Function : freeTddNrFreqInfo 
1307  *
1308  *    Functionality: freeTddNrFreqInfo 
1309  *
1310  * @params[in]  F1AP_PDU_t *f1apDuCfg
1311  *
1312  * @return ROK     - void
1313  *
1314  * ****************************************************************/
1315 void freeTddNrFreqInfo(NRFreqInfo_t *freqInfo)
1316 {
1317    uint8_t freqBandListIdx = 0, supportedBandIdx = 0;
1318
1319    if(freqInfo->freqBandListNr.list.array)
1320    {
1321       for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
1322       {
1323          if(freqInfo->freqBandListNr.list.array[freqBandListIdx])
1324          {
1325             if(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
1326             {
1327                for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
1328                {
1329                   DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
1330                         sizeof(SupportedSULFreqBandItem_t));
1331                }
1332                DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
1333                      freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
1334
1335             }
1336             DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
1337          }
1338       }
1339       DU_FREE(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
1340    }
1341 }
1342
1343 /*******************************************************************
1344  *
1345  * @brief Deallocating memory allocated for Nr fdd frequencey mode 
1346  *
1347  * @details
1348  *
1349  *    Function : freeFddNrFreqInfo 
1350  *
1351  *    Functionality:Free memory allocated for Nr fdd frequencey mode 
1352  *
1353  * @params[in]  
1354  *
1355  * @return ROK     - void
1356  *
1357  * ****************************************************************/
1358 void freeFddNrFreqInfo(FDD_Info_t *fDD)
1359 {
1360    uint8_t arrIdx =0;
1361
1362    if(fDD != NULLP)
1363    {
1364       if(fDD->uL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1365       {
1366          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.\
1367                array[arrIdx], sizeof(FreqBandNrItem_t));
1368          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.array, \
1369                fDD->uL_NRFreqInfo.freqBandListNr.list.size);
1370       }
1371
1372       if(fDD->dL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1373       {
1374          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.\
1375                array[arrIdx], sizeof(FreqBandNrItem_t));
1376          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.array,\
1377                fDD->dL_NRFreqInfo.freqBandListNr.list.size);
1378       }
1379       DU_FREE(fDD,sizeof(FDD_Info_t));
1380    }
1381 }
1382
1383 /*******************************************************************
1384  *
1385  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1386  *
1387  * @details
1388  *
1389  *    Function :  FreeServedCellList
1390  *
1391  *    Functionality:  deallocating the memory of function BuildServedCellList
1392
1393  *
1394  * @params[in] GNB_DU_Served_Cells_List_t *duServedCell
1395  *
1396  * @return void
1397  *
1398  * ****************************************************************/
1399 void FreeServedCellList( GNB_DU_Served_Cells_List_t *duServedCell)
1400 {
1401    uint8_t   plmnCnt= 1;
1402    uint8_t  extensionCnt=IE_EXTENSION_LIST_COUNT;
1403    uint8_t  plmnIdx=0, sliceIdx=0;
1404    GNB_DU_Served_Cells_Item_t *srvCellItem;
1405    ServedPLMNs_Item_t  *servedPlmnItem;
1406    SliceSupportItem_t  *sliceSupportItem;
1407
1408    if(duServedCell->list.array!=NULLP)
1409    {
1410       if(duServedCell->list.array[0]!=NULLP)
1411       {
1412          srvCellItem= &duServedCell->list.array[0]->value.choice.GNB_DU_Served_Cells_Item;
1413
1414          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1415                srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.size * sizeof(uint8_t));
1416          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1417                srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.size * sizeof(uint8_t));
1418
1419          if(srvCellItem->served_Cell_Information.fiveGS_TAC!=NULLP)
1420          {
1421             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC->buf,\
1422                   sizeof(srvCellItem->served_Cell_Information.fiveGS_TAC->size));
1423             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC,sizeof(FiveGS_TAC_t));
1424          }
1425
1426          if(srvCellItem->served_Cell_Information.servedPLMNs.list.array!=NULLP)
1427          {
1428             if(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx] != NULLP)
1429             {
1430                servedPlmnItem = srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx];
1431                DU_FREE(servedPlmnItem->pLMN_Identity.buf, servedPlmnItem->pLMN_Identity.size);
1432
1433                if(servedPlmnItem->iE_Extensions != NULLP)
1434                {
1435                   if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1436                   {
1437                      if(servedPlmnItem->iE_Extensions->list.array[0] != NULLP)
1438                      {
1439                         if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1440                               SliceSupportList.list.array != NULLP)
1441                         {
1442                            for(sliceIdx =0; sliceIdx<servedPlmnItem->iE_Extensions->list.array[0]->\
1443                                  extensionValue.choice.SliceSupportList.list.count; sliceIdx++)
1444                            {
1445                               if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1446                                     SliceSupportList.list.array[sliceIdx] != NULLP)
1447                               {
1448                                  sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[0]->\
1449                                                     extensionValue.choice.SliceSupportList.list.array[sliceIdx];
1450
1451                                  DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sizeof(uint8_t));
1452
1453                                  if(sliceSupportItem->sNSSAI.sD != NULLP)
1454                                  {
1455                                     DU_FREE(sliceSupportItem->sNSSAI.sD->buf,\
1456                                           sliceSupportItem->sNSSAI.sD->size);
1457                                     DU_FREE(sliceSupportItem->sNSSAI.sD, sizeof(OCTET_STRING_t));
1458                                  }
1459
1460                                  DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.\
1461                                        choice.SliceSupportList.list.array[sliceIdx], sizeof(SliceSupportItem_t));
1462                               }
1463                            }
1464                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1465                                  SliceSupportList.list.array, servedPlmnItem->iE_Extensions->list.array[0]->\
1466                                  extensionValue.choice.SliceSupportList.list.size);
1467                         }
1468                         DU_FREE(servedPlmnItem->iE_Extensions->list.array[0],\
1469                               sizeof(ServedPLMNs_ItemExtIEs_t));
1470                      }
1471                      DU_FREE(servedPlmnItem->iE_Extensions->list.array,\
1472                            extensionCnt*sizeof(ServedPLMNs_ItemExtIEs_t*));
1473                   }
1474                   DU_FREE(servedPlmnItem->iE_Extensions, sizeof(ProtocolExtensionContainer_4624P3_t));
1475                }
1476                DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx],\
1477                      sizeof(ServedPLMNs_Item_t));
1478             }
1479             DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array,\
1480                   sizeof(ServedPLMNs_Item_t *));
1481          }
1482
1483          if(srvCellItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1484          {
1485             freeFddNrFreqInfo(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1486          }
1487          else   
1488          {
1489             if(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD != NULLP)
1490             {
1491                freeTddNrFreqInfo(&srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1492                DU_FREE(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1493             }
1494          }
1495          
1496          DU_FREE(srvCellItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1497                srvCellItem->served_Cell_Information.measurementTimingConfiguration.size);
1498
1499          if(srvCellItem->gNB_DU_System_Information != NULLP)
1500          {
1501             if(srvCellItem->gNB_DU_System_Information->mIB_message.buf != NULLP)
1502             {
1503                DU_FREE(srvCellItem->gNB_DU_System_Information->mIB_message.buf,\
1504                      srvCellItem->gNB_DU_System_Information->mIB_message.size);
1505             }
1506
1507             if(srvCellItem->gNB_DU_System_Information->sIB1_message.buf != NULLP)
1508             { 
1509                DU_FREE(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,\
1510                      srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1511             }
1512
1513             DU_FREE(srvCellItem->gNB_DU_System_Information, sizeof(GNB_DU_System_Information_t));
1514          }
1515
1516          DU_FREE(duServedCell->list.array[0], sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1517       }
1518       DU_FREE(duServedCell->list.array, plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t*));
1519    }
1520 }
1521
1522 /*******************************************************************
1523  *
1524  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1525  *
1526  * @details
1527  *
1528  *    Function :  FreeF1SetupReq
1529  *
1530  *    Functionality:  deallocating the memory of function BuildAndSendF1SetupReq
1531  *
1532  * @params[in] F1AP_PDU_t *f1apMsg
1533  *
1534  * @return void
1535  *
1536  * ****************************************************************/
1537 void FreeF1SetupReq(F1AP_PDU_t *f1apMsg)
1538 {
1539    uint8_t ieIdx, ieIdx2;
1540    F1SetupRequest_t *f1SetupReq=NULLP;
1541
1542    if(f1apMsg != NULLP)
1543    {
1544       if(f1apMsg->choice.initiatingMessage != NULLP)
1545       {
1546          f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1547          if(f1SetupReq->protocolIEs.list.array != NULLP)
1548          {
1549             for(ieIdx = 0; ieIdx < f1SetupReq->protocolIEs.list.count; ieIdx++)
1550             {
1551                if(f1SetupReq->protocolIEs.list.array[ieIdx] != NULLP)
1552                {
1553                   switch(f1SetupReq->protocolIEs.list.array[ieIdx]->id)
1554                   {
1555                      case ProtocolIE_ID_id_TransactionID:
1556                         break;
1557                      case ProtocolIE_ID_id_gNB_DU_ID:
1558                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1559                               f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1560                         break;
1561                      case ProtocolIE_ID_id_gNB_DU_Name:
1562                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,\
1563                               strlen((char *)duCfgParam.duName));
1564                         break;
1565                      case ProtocolIE_ID_id_gNB_DU_Served_Cells_List:
1566                         FreeServedCellList(&f1SetupReq->protocolIEs.list.\
1567                               array[ieIdx]->value.choice.GNB_DU_Served_Cells_List);
1568                         break;
1569                      case ProtocolIE_ID_id_GNB_DU_RRC_Version:
1570                         FreeRrcVer(&f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version);
1571                         break;
1572                      default:
1573                         DU_LOG("\nERROR  -->  Invalid Event Type %ld", f1SetupReq->protocolIEs.list.array[ieIdx]->id);
1574                         break;
1575                   }
1576                }
1577             }
1578             for(ieIdx2=0; ieIdx2< ieIdx; ieIdx2++)
1579             {
1580                DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx2],sizeof(F1SetupRequestIEs_t));
1581             }
1582             DU_FREE(f1SetupReq->protocolIEs.list.array,\
1583                   f1SetupReq->protocolIEs.list.size);
1584          }
1585          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1586       }
1587       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
1588    }
1589 }
1590
1591 /*******************************************************************
1592  *
1593  * @brief Builds and Send the F1SetupRequest
1594  *
1595  * @details
1596  *
1597  *    Function : BuildAndSendF1SetupReq
1598  *
1599  * Functionality:Fills the F1SetupRequest
1600  *
1601  * @return ROK     - success
1602  *         RFAILED - failure
1603  *
1604  ******************************************************************/
1605 uint8_t BuildAndSendF1SetupReq()
1606 {
1607    uint8_t   ret, ieIdx, elementCnt;
1608    F1AP_PDU_t                 *f1apMsg = NULLP;
1609    F1SetupRequest_t           *f1SetupReq=NULLP;
1610    GNB_DU_Served_Cells_List_t *duServedCell=NULLP;
1611    RRC_Version_t              *rrcVer=NULLP;
1612    asn_enc_rval_t             encRetVal;        /* Encoder return value */
1613    ret= RFAILED;
1614
1615    DU_LOG("\nINFO   -->  F1AP : Building F1 Setup Request\n");
1616    do
1617    {
1618       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
1619       if(f1apMsg == NULLP)
1620       {
1621          break;
1622       }
1623       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
1624       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1625       if(f1apMsg->choice.initiatingMessage == NULLP)
1626       {
1627          break;
1628       }
1629       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_F1Setup;
1630       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
1631       f1apMsg->choice.initiatingMessage->value.present = \
1632                                                          InitiatingMessage__value_PR_F1SetupRequest;
1633
1634       f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1635
1636       elementCnt = 5;
1637
1638       f1SetupReq->protocolIEs.list.count = elementCnt;
1639       f1SetupReq->protocolIEs.list.size = elementCnt * sizeof(F1SetupRequestIEs_t *);
1640
1641       /* Initialize the F1Setup members */
1642       DU_ALLOC(f1SetupReq->protocolIEs.list.array,f1SetupReq->protocolIEs.list.size);
1643       if(f1SetupReq->protocolIEs.list.array == NULLP)
1644       {
1645          break;
1646       }
1647       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
1648       {
1649          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx],\
1650                sizeof(F1SetupRequestIEs_t));
1651          if(f1SetupReq->protocolIEs.list.array[ieIdx] == NULLP)
1652          {
1653             break;
1654          }
1655       }
1656
1657       ieIdx = 0;
1658       /*TransactionID*/
1659       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_TransactionID;
1660       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1661       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present =\
1662                                                                 F1SetupRequestIEs__value_PR_TransactionID;
1663       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = \
1664                                                                               TRANS_ID;
1665
1666       /*DU ID*/
1667       ieIdx++;
1668       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
1669       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1670       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1671                                                                  F1SetupRequestIEs__value_PR_GNB_DU_ID;
1672       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size =\
1673                                                                               sizeof(uint8_t);
1674
1675       DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1676             f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1677       if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == \
1678             NULLP)
1679       {
1680          break;
1681       }
1682
1683       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] =\
1684                                                                                 duCfgParam.duId;
1685       /* DU name IE is of type printableString_t which wireshark is unable to decode.
1686        * However this string is decoded successfully on online decoders.
1687        * Since this is an optional IE and the value received in it are not
1688        * used as of now, eliminating this IE for now to avoid wireshark error.
1689        */
1690       /*DU Name*/
1691       if(duCfgParam.duName != NULL)
1692       {
1693          ieIdx++;
1694          f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_Name;
1695          f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_ignore;
1696          f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = F1SetupRequestIEs__value_PR_GNB_DU_Name;
1697          f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size = strlen((char *)duCfgParam.duName);
1698          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf, \
1699                f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size);
1700          if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf == NULLP)
1701          {
1702             break;
1703          }
1704          strcpy((char*)f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,
1705                (char*)duCfgParam.duName);
1706       }
1707
1708       /*Served Cell list */
1709       ieIdx++;
1710       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1711                                                       ProtocolIE_ID_id_gNB_DU_Served_Cells_List;
1712       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1713       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1714                                                                  F1SetupRequestIEs__value_PR_GNB_DU_Served_Cells_List;
1715       duServedCell = &f1SetupReq->protocolIEs.list.\
1716                      array[ieIdx]->value.choice.GNB_DU_Served_Cells_List;
1717       if(BuildServedCellList(duServedCell))
1718       {
1719          break;
1720       }
1721
1722       /*RRC Version*/
1723       ieIdx++;
1724       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1725                                                       ProtocolIE_ID_id_GNB_DU_RRC_Version ;
1726       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1727       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1728                                                                  F1SetupRequestIEs__value_PR_RRC_Version;
1729       rrcVer = &f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
1730       if(BuildRrcVer(rrcVer))
1731       {
1732          break;
1733       }
1734
1735       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
1736
1737       /* Encode the F1SetupRequest type as APER */
1738       memset(encBuf, 0, ENC_BUF_MAX_LEN);
1739       encBufSize = 0;
1740       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
1741             encBuf);
1742
1743       /* Encode results */
1744       if(encRetVal.encoded == ENCODE_FAIL)
1745       {
1746          DU_LOG("\nERROR  -->  F1AP : Could not encode F1SetupRequest structure (at %s)\n",\
1747                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1748          break;
1749       }
1750       else
1751       {
1752          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1SetupRequest\n");
1753 #ifdef DEBUG_ASN_PRINT
1754          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
1755          {
1756             printf("%x",encBuf[ieIdx]);
1757          }
1758 #endif
1759          
1760
1761       }
1762       if(addOrModifyE2NodeComponent(F1, E2_NODE_COMPONENT_ADD, true, encBufSize, encBuf) !=ROK)
1763       {
1764          DU_LOG("\nERROR  -->  F1AP : Failed to add the e2 node in the list");
1765          break;
1766       }
1767       /* Sending msg */
1768       if(sendF1APMsg() != ROK)
1769       {
1770          DU_LOG("\nERROR  -->  F1AP : Sending F1 Setup request failed");
1771          break;
1772       }
1773
1774       ret=ROK;
1775       break;
1776    }while(true);
1777
1778    FreeF1SetupReq(f1apMsg);
1779
1780    return ret;
1781 }/* End of BuildAndSendF1SetupReq */
1782
1783 /*******************************************************************
1784  *
1785  * @brief Deallocating memory allocated for Served_Cells_To_Modify_Item_t
1786  *
1787  * @details
1788  *
1789  *    Function : freeCellsToModifyItem 
1790  *
1791  *    Functionality: Deallocating memory of variables allocated in
1792  *                    BuildAndSendDUConfigUpdate function
1793  *
1794  * @params[in]  Served_Cells_To_Modify_Item_t *modifyItem
1795  *
1796  * @return ROK     - void
1797  *
1798  * ****************************************************************/
1799
1800 void freeCellsToModifyItem(Served_Cells_To_Modify_Item_t *modifyItem)
1801 {
1802    uint8_t arrIdx=0, servedPlmnIdx=0, sliceLstIdx=0;
1803    ServedPLMNs_Item_t *servedPlmnItem = NULLP;
1804    SliceSupportItem_t *sliceSupportItem = NULLP;
1805
1806    DU_FREE(modifyItem->oldNRCGI.pLMN_Identity.buf, modifyItem->oldNRCGI.pLMN_Identity.size);
1807    DU_FREE(modifyItem->oldNRCGI.nRCellIdentity.buf, modifyItem->oldNRCGI.nRCellIdentity.size);
1808
1809    DU_FREE(modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1810            modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.size);
1811    DU_FREE(modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1812          modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.size);
1813
1814    if(modifyItem->served_Cell_Information.servedPLMNs.list.array != NULLP)
1815    {
1816       if(modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx] != NULLP)
1817       {
1818          servedPlmnItem = modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx];
1819
1820          DU_FREE(servedPlmnItem->pLMN_Identity.buf,servedPlmnItem->pLMN_Identity.size);
1821
1822          if(servedPlmnItem->iE_Extensions != NULLP)
1823          {
1824             if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1825             {
1826                if(servedPlmnItem->iE_Extensions->list.array[arrIdx] != NULLP)
1827                {
1828                   if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1829                         list.array != NULLP)
1830                   {
1831                      for(sliceLstIdx =0; sliceLstIdx<servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1832                            extensionValue.choice.SliceSupportList.list.count; sliceLstIdx++)
1833                      {
1834                         if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1835                               list.array[sliceLstIdx] != NULLP)
1836                         {
1837
1838                            sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1839                                               SliceSupportList.list.array[sliceLstIdx];
1840
1841                            DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sliceSupportItem->sNSSAI.sST.size);
1842                            if(sliceSupportItem->sNSSAI.sD != NULLP)
1843                            {
1844                               DU_FREE(sliceSupportItem->sNSSAI.sD->buf, sliceSupportItem->sNSSAI.sD->size);
1845                               DU_FREE(sliceSupportItem->sNSSAI.sD,sizeof(OCTET_STRING_t));
1846                            }
1847                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1848                                  SliceSupportList.list.array[sliceLstIdx], sizeof(SliceSupportItem_t));
1849                         }
1850                      }
1851                      DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.\
1852                            choice.SliceSupportList.list.array,\
1853                            servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1854                            extensionValue.choice.SliceSupportList.list.size);
1855                   }
1856                }
1857                for(servedPlmnIdx=0; servedPlmnIdx< servedPlmnItem->iE_Extensions->list.count ; servedPlmnIdx++)
1858                {
1859                   DU_FREE(servedPlmnItem->iE_Extensions->list.array[servedPlmnIdx], sizeof(ServedPLMNs_ItemExtIEs_t ));
1860                }
1861                DU_FREE(servedPlmnItem->iE_Extensions->list.array, servedPlmnItem->iE_Extensions->list.size);
1862             }
1863             DU_FREE(servedPlmnItem->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1864          }
1865       }
1866       for(servedPlmnIdx=0; servedPlmnIdx<modifyItem->served_Cell_Information.servedPLMNs.list.count; servedPlmnIdx++)
1867       {
1868          DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array[servedPlmnIdx], sizeof(ServedPLMNs_Item_t));
1869       }
1870       DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array,\
1871          modifyItem->served_Cell_Information.servedPLMNs.list.size);
1872    }
1873    
1874    if(modifyItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1875    {
1876       freeFddNrFreqInfo(modifyItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1877    }  
1878    else
1879    {
1880       if(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD)
1881       {
1882          freeTddNrFreqInfo(&modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1883          DU_FREE(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1884       }
1885    }
1886    DU_FREE(modifyItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1887          modifyItem->served_Cell_Information.measurementTimingConfiguration.size);
1888 }
1889
1890 /*******************************************************************
1891  *
1892  * @brief Deallocating memory of BuildAndSendDUConfigUpdate
1893  *
1894  * @details
1895  *
1896  *    Function : FreeDUConfigUpdate
1897  *
1898  *    Functionality: Deallocating memory of variables allocated in
1899  *                    BuildAndSendDUConfigUpdate function
1900  *
1901  * @params[in]  F1AP_PDU_t *f1apDuCfg
1902  *
1903  * @return ROK     - void
1904  *
1905  * ****************************************************************/
1906 void FreeDUConfigUpdate(F1AP_PDU_t *f1apDuCfg)
1907 {
1908    uint8_t  idx=0,ieIdx=0, cellModifyIdx=0, cellDeleteIdx=0;
1909    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
1910    Served_Cells_To_Modify_List_t  *cellsToModify=NULLP;
1911    Served_Cells_To_Delete_List_t  *cellsToDelete=NULLP;
1912    Served_Cells_To_Delete_Item_t  *deleteItem = NULLP;
1913    Served_Cells_To_Delete_ItemIEs_t *deleteItemIe = NULLP;
1914    Cells_Status_ItemIEs_t *cellStatusItemIE;
1915
1916    if(f1apDuCfg != NULLP)
1917    {
1918       if(f1apDuCfg->choice.initiatingMessage != NULLP)
1919       {
1920          duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->\
1921                        value.choice.GNBDUConfigurationUpdate;
1922          if(duCfgUpdate->protocolIEs.list.array != NULLP)
1923          {
1924             for(ieIdx=0; ieIdx<duCfgUpdate->protocolIEs.list.count; ieIdx++)
1925             {
1926                if(duCfgUpdate->protocolIEs.list.array[ieIdx] != NULLP)
1927                {
1928                   switch(duCfgUpdate->protocolIEs.list.array[ieIdx]->id)
1929                   {
1930                      case ProtocolIE_ID_id_Served_Cells_To_Modify_List:
1931                         {
1932                            cellsToModify = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1933                                            value.choice.Served_Cells_To_Modify_List;
1934                            if(cellsToModify->list.array != NULLP)
1935                            {
1936                               for(cellModifyIdx=0; cellModifyIdx<cellsToModify->list.count ;cellModifyIdx++)
1937                               {
1938                                  if(cellsToModify->list.array[cellModifyIdx] != NULLP)
1939                                  {
1940                                     freeCellsToModifyItem(&cellsToModify->list.array[cellModifyIdx]->value.choice.\
1941                                           Served_Cells_To_Modify_Item);
1942                                     DU_FREE(cellsToModify->list.array[cellModifyIdx],\
1943                                           sizeof(Served_Cells_To_Modify_ItemIEs_t));
1944                                  }
1945                               }
1946                               DU_FREE(cellsToModify->list.array,cellsToModify->list.size);
1947                            }
1948                            break;
1949                         }
1950                      case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
1951                         {
1952                            cellsToDelete = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1953                                            value.choice.Served_Cells_To_Delete_List;
1954                            if(cellsToDelete->list.array != NULLP)
1955                            {
1956                               for(cellDeleteIdx=0; cellDeleteIdx<cellsToDelete->list.count ;cellDeleteIdx++)
1957                               {
1958                                  if(cellsToDelete->list.array[cellDeleteIdx] != NULLP)
1959                                  {
1960                                     deleteItemIe = ((Served_Cells_To_Delete_ItemIEs_t*)\
1961                                           cellsToDelete->list.array[cellDeleteIdx]);
1962                                     deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
1963                                     DU_FREE(deleteItem->oldNRCGI.pLMN_Identity.buf,\
1964                                           deleteItem->oldNRCGI.pLMN_Identity.size); 
1965                                     DU_FREE(deleteItem->oldNRCGI.nRCellIdentity.buf,\
1966                                           deleteItem->oldNRCGI.nRCellIdentity.size);
1967                                     DU_FREE(cellsToDelete->list.array[cellDeleteIdx],\
1968                                           sizeof(Served_Cells_To_Delete_ItemIEs_t));
1969                                  }
1970                               }
1971                               DU_FREE(cellsToDelete->list.array,cellsToDelete->list.size);
1972                            }
1973
1974                            break;
1975                         }
1976                      case ProtocolIE_ID_id_gNB_DU_ID:
1977                         {
1978                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1979                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1980                            break;
1981                         }
1982                      case ProtocolIE_ID_id_Cells_Status_List:
1983                         {
1984                            for(idx = 0; idx < duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.count; idx++)
1985                            {
1986                               cellStatusItemIE = (Cells_Status_ItemIEs_t *)duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array[idx];
1987                               DU_FREE(cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.nRCellIdentity.buf, cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.nRCellIdentity.size);
1988                               DU_FREE(cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.pLMN_Identity.buf, cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.pLMN_Identity.size);
1989                               DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array[idx],sizeof(Cells_Status_ItemIEs_t));
1990                            }
1991                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array,\
1992                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.size);
1993                         }
1994                   }
1995                   DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx],\
1996                         sizeof(GNBDUConfigurationUpdateIEs_t));
1997                }
1998             }
1999             DU_FREE(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2000          }
2001          DU_FREE(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2002       }
2003       DU_FREE(f1apDuCfg, (Size)sizeof(F1AP_PDU_t));
2004    }
2005 }
2006
2007 /*******************************************************************
2008  *
2009  * @brief Fills Served Plmns required in ServCellInfo IE
2010  *
2011  * @details
2012  *
2013  *    Function : fillServedPlmns
2014  *
2015  *    Functionality: Fills Served Plmns required in ServCellInfo IE
2016  *
2017  * @params[in] Pointer to ServedPLMNs_List_t *
2018  *
2019  * @return ROK     - success
2020  *         RFAILED - failure
2021  *
2022  *****************************************************************/
2023
2024 uint8_t fillServedPlmns(ServedPLMNs_List_t *servedPlmn)
2025 {
2026    uint8_t ieIdx=0, arrayIdx=0, ieListCnt=0, elementCnt=0, sliceLstIdx=0;
2027
2028    servedPlmn->list.array[arrayIdx]->pLMN_Identity.size = 3*sizeof(uint8_t);
2029    DU_ALLOC(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf, servedPlmn->list.\
2030          array[arrayIdx]->pLMN_Identity.size);
2031    if(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf == NULLP)
2032    {
2033       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2034       return RFAILED;
2035    }
2036    buildPlmnId(duCfgParam.srvdCellLst[arrayIdx].duCellInfo.cellInfo.srvdPlmn[arrayIdx].plmn,\
2037          servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf);
2038    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
2039    if(servedPlmn->list.array[arrayIdx]->iE_Extensions == NULLP)
2040    {
2041       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2042       return RFAILED;
2043    }
2044
2045    ieListCnt=1;
2046    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.count = ieListCnt;
2047    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.size = ieListCnt *sizeof(ServedPLMNs_ItemExtIEs_t *);
2048    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array,servedPlmn->list.array[arrayIdx]->\
2049          iE_Extensions->list.size);
2050    if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array == NULLP)
2051    {
2052       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2053       return RFAILED;
2054    }
2055    for(ieIdx=arrayIdx;ieIdx<ieListCnt;ieIdx++)
2056    {
2057       DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx],\
2058             sizeof(ServedPLMNs_ItemExtIEs_t));
2059       if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx] == NULLP)
2060       {
2061          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2062          return RFAILED;
2063       }
2064    }
2065    
2066    ieIdx = 0;
2067    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices; 
2068    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->id =ProtocolIE_ID_id_TAISliceSupportList;
2069    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->criticality = Criticality_ignore;
2070    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.present = \
2071    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
2072    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2073       list.count = elementCnt;
2074    servedPlmn->list.array[arrayIdx]->\
2075       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2076       list.size = elementCnt * sizeof(SliceSupportItem_t *);
2077    DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2078          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2079          list.array,servedPlmn->list.array[arrayIdx]->\
2080          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.size);
2081    if(servedPlmn->list.array[arrayIdx]->\
2082          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2083          list.array == NULLP)
2084    {
2085       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2086       return RFAILED;
2087    }
2088
2089    for(sliceLstIdx =0; sliceLstIdx< elementCnt; sliceLstIdx++)
2090    {
2091       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2092       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2093       list.array[sliceLstIdx],sizeof( SliceSupportItem_t));
2094       if(servedPlmn->list.array[arrayIdx]->\
2095       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2096       list.array[sliceLstIdx] == NULLP)
2097       {   
2098          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2099          return RFAILED;
2100       }
2101       
2102       servedPlmn->list.array[arrayIdx]->\
2103       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2104       list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
2105       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2106       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2107       list.array[sliceLstIdx]->sNSSAI.sST.buf,servedPlmn->list.array[arrayIdx]->\
2108       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->\
2109       sNSSAI.sST.size);
2110       
2111       if(servedPlmn->list.array[arrayIdx]->\
2112       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2113       list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
2114       {
2115          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2116          return RFAILED;
2117       }
2118       servedPlmn->list.array[arrayIdx]->\
2119       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2120       list.array[sliceLstIdx]->sNSSAI.sST.buf[arrayIdx] =  duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
2121       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
2122
2123       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2124       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2125       list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
2126       if(servedPlmn->list.array[arrayIdx]->\
2127       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2128       list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
2129       {
2130          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2131          return RFAILED;
2132       }
2133       servedPlmn->list.array[arrayIdx]->\
2134       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2135       list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
2136       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2137       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2138       list.array[sliceLstIdx]->sNSSAI.sD->buf,servedPlmn->list.array[arrayIdx]->\
2139       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2140       list.array[sliceLstIdx]->sNSSAI.sD->size);
2141       if(servedPlmn->list.array[arrayIdx]->\
2142       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2143       list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
2144       {
2145          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2146          return RFAILED;
2147       }
2148       memcpy(servedPlmn->list.array[arrayIdx]->\
2149       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2150       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
2151       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sd,\
2152       servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2153       list.array[sliceLstIdx]->sNSSAI.sD->size);
2154    }
2155    return ROK;
2156 }
2157
2158 /*******************************************************************
2159  *
2160  * @brief Fills Nr Fdd Info required in ServCellInfo IE
2161  *
2162  * @details
2163  *
2164  *    Function : fillNrFddInfo
2165  *
2166  *    Functionality: Fills Nr Fdd Info required in ServCellInfo IE
2167  *
2168  * @params[in] FDD_Info_t *fDD
2169  *
2170  * @return ROK     - success
2171  *         RFAILED - failure
2172  *
2173  *****************************************************************/
2174
2175 uint8_t fillNrFddInfo(FDD_Info_t *fDD)
2176 {
2177    fDD->uL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.\
2178       f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn;
2179    fDD->uL_NRFreqInfo.freqBandListNr.list.count = 1;
2180    fDD->uL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t*);
2181    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.\
2182          array, fDD->uL_NRFreqInfo.freqBandListNr.list.size);
2183    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array == NULLP)
2184    {
2185       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2186       return RFAILED;
2187    }
2188
2189    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0], \
2190       sizeof(FreqBandNrItem_t));
2191    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2192    {
2193       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2194       return RFAILED;
2195    }
2196    
2197    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2198       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
2199       freqBand[0].nrFreqBand;
2200    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2201    fDD->dL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.\
2202       dlNrFreqInfo.nrArfcn;
2203    fDD->dL_NRFreqInfo.freqBandListNr.list.count = 1;
2204    fDD->dL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
2205    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array, fDD->dL_NRFreqInfo.freqBandListNr.list.size);
2206    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array == NULLP)
2207    {
2208       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2209       return RFAILED;
2210    }
2211    
2212    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0],  sizeof(FreqBandNrItem_t));
2213    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2214    {
2215       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2216       return RFAILED;
2217    }
2218
2219    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2220       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
2221       freqBand[0].nrFreqBand;
2222    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2223    
2224    /*Transmission Bandwidth*/
2225    fDD->uL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2226       f1Mode.mode.fdd.ulTxBw.nrScs;
2227    fDD->uL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2228       f1Mode.mode.fdd.ulTxBw.nrb;
2229    fDD->dL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2230       f1Mode.mode.fdd.dlTxBw.nrScs;
2231    fDD->dL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2232       f1Mode.mode.fdd.dlTxBw.nrb;
2233
2234    return ROK;
2235 }
2236
2237 /*******************************************************************
2238  *
2239  * @brief Fills ServCellInfo IE
2240  *
2241  * @details
2242  *
2243  *    Function : fillServedCellInfo
2244  *
2245  *    Functionality: Fills ServCellInfo
2246  *
2247  * @params[in] Pointer to Served_Cell_Information_t *
2248  *
2249  * @return ROK     - success
2250  *         RFAILED - failure
2251  *
2252  *****************************************************************/
2253
2254 uint8_t fillServedCellInfo(Served_Cell_Information_t *srvCellInfo)
2255 {
2256    uint8_t ieIdx, ieListCnt;
2257
2258    /*nRCGI*/
2259    srvCellInfo->nRCGI.pLMN_Identity.size =3*sizeof(uint8_t);
2260    DU_ALLOC(srvCellInfo->nRCGI.pLMN_Identity.buf,\
2261          srvCellInfo->nRCGI.pLMN_Identity.size);
2262    if(srvCellInfo->nRCGI.pLMN_Identity.buf == NULLP)
2263    {
2264       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2265       return RFAILED;
2266    }
2267    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2268          srvCellInfo->nRCGI.pLMN_Identity.buf);
2269    srvCellInfo->nRCGI.nRCellIdentity.size =5*sizeof(uint8_t);
2270    DU_ALLOC(srvCellInfo->nRCGI.nRCellIdentity.buf,\
2271          srvCellInfo->nRCGI.nRCellIdentity.size);
2272    if(srvCellInfo->nRCGI.nRCellIdentity.buf == NULLP)
2273    {   
2274       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2275       return RFAILED;
2276    }
2277    
2278    fillBitString(&srvCellInfo->nRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2279    /*nRPCI*/
2280    srvCellInfo->nRPCI = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
2281
2282    /*servedPLMNs*/
2283    ieListCnt = 1;
2284    srvCellInfo->servedPLMNs.list.count = ieListCnt;
2285    srvCellInfo->servedPLMNs.list.size = ieListCnt*sizeof(ServedPLMNs_Item_t *);
2286    DU_ALLOC(srvCellInfo->servedPLMNs.list.array, srvCellInfo->servedPLMNs.list.size);
2287    if(srvCellInfo->servedPLMNs.list.array == NULLP)
2288    {
2289       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2290       return RFAILED;
2291    }
2292    for(ieIdx=0; ieIdx < ieListCnt; ieIdx++)
2293    {
2294       DU_ALLOC(srvCellInfo->servedPLMNs.list.array[ieIdx], sizeof(ServedPLMNs_Item_t));
2295       if(srvCellInfo->servedPLMNs.list.array[ieIdx]== NULLP)
2296       {
2297          DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2298          return RFAILED;
2299       }
2300    }
2301    if(fillServedPlmns(&srvCellInfo->servedPLMNs))
2302    {
2303       DU_LOG("\nERROR  --> Failed to fill Served Plmn info");
2304       return RFAILED;
2305    }
2306
2307 #ifndef NR_TDD
2308    /*nR Mode Info with FDD*/
2309    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_fDD;
2310    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.fDD, sizeof(FDD_Info_t));
2311    if(srvCellInfo->nR_Mode_Info.choice.fDD == NULLP)
2312    {
2313       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2314       return RFAILED;
2315    }
2316    if(fillNrFddInfo(srvCellInfo->nR_Mode_Info.choice.fDD))
2317    {
2318        DU_LOG("\nERROR  --> Failed to fill the Nr FDD information");
2319       return RFAILED;
2320    }
2321 #else
2322    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_tDD;   
2323    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
2324    if(srvCellInfo->nR_Mode_Info.choice.tDD == NULLP)
2325    {
2326       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2327       return RFAILED;
2328    }
2329    if(fillNrTddInfo(srvCellInfo->nR_Mode_Info.choice.tDD) != ROK)
2330    {
2331       DU_LOG("\nERROR  --> Failed to fill the Nr TDD information");
2332       return RFAILED;
2333    }
2334 #endif
2335
2336    /*Measurement timing Config*/
2337    if(BuildMeasTimingConf(&srvCellInfo->measurementTimingConfiguration) != ROK)
2338       return RFAILED;
2339
2340    return ROK;
2341 }
2342
2343 /*******************************************************************
2344  *
2345  * @brief Fills ServCellToModItem IE
2346  *
2347  * @details
2348  *
2349  *    Function : fillServCellToModItem
2350  *
2351  *    Functionality: Fills ServCellToModItem IE
2352  *
2353  * @params[in] Pointer to Served_Cells_To_Modify_Item_t *
2354  *
2355  * @return ROK     - success
2356  *         RFAILED - failure
2357  *
2358  *****************************************************************/
2359
2360 uint8_t fillServCellToModItem(Served_Cells_To_Modify_Item_t *modifyItem)
2361 {
2362    /*pLMN_Identity*/
2363    modifyItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2364    DU_ALLOC(modifyItem->oldNRCGI.pLMN_Identity.buf,modifyItem->oldNRCGI.pLMN_Identity.size);
2365    if(modifyItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2366    {
2367       return RFAILED;
2368    }
2369    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2370          modifyItem->oldNRCGI.pLMN_Identity.buf);
2371
2372    /*nRCellIdentity*/
2373    modifyItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2374    DU_ALLOC(modifyItem->oldNRCGI.nRCellIdentity.buf,\
2375          modifyItem->oldNRCGI.nRCellIdentity.size);
2376    if(modifyItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2377    {
2378       return RFAILED;
2379    }
2380    fillBitString(&modifyItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2381
2382    if(fillServedCellInfo(&modifyItem->served_Cell_Information))
2383       return RFAILED;
2384    else
2385       return ROK;
2386 }
2387
2388 /*******************************************************************
2389  *
2390  * @brief Builds ServCellToModList
2391  *
2392  * @details
2393  *
2394  *    Function : buildServCellToModList
2395  *
2396  *    Functionality: Builds the serv cell to Mod List
2397  *
2398  * @params[in] Pointer to Served_Cells_To_Modify_List_t *
2399  *
2400  * @return ROK     - success
2401  *         RFAILED - failure
2402  *
2403  *****************************************************************/
2404
2405 uint8_t buildServCellToModList(Served_Cells_To_Modify_List_t *cellsToModify)
2406 {
2407    uint8_t ieListCnt, ieIdx;
2408    Served_Cells_To_Modify_Item_t *modifyItem = NULLP;
2409
2410    ieListCnt = 1;
2411    cellsToModify->list.count = ieListCnt;
2412    cellsToModify->list.size = ieListCnt*sizeof(Served_Cells_To_Modify_ItemIEs_t *);
2413    DU_ALLOC(cellsToModify->list.array,cellsToModify->list.size);
2414    if(cellsToModify->list.array == NULLP)
2415    {
2416       return RFAILED;
2417    }
2418    for(ieIdx=0; ieIdx< ieListCnt; ieIdx++)
2419    {
2420       DU_ALLOC(cellsToModify->list.array[ieIdx],sizeof(Served_Cells_To_Modify_ItemIEs_t));
2421       if(cellsToModify->list.array[ieIdx] == NULLP)
2422       {
2423          return RFAILED;
2424       }
2425    }
2426    cellsToModify->list.array[0]->id = ProtocolIE_ID_id_Served_Cells_To_Modify_Item;
2427    cellsToModify->list.array[0]->criticality = Criticality_reject;
2428    cellsToModify->list.array[0]->value.present =\
2429       Served_Cells_To_Modify_ItemIEs__value_PR_Served_Cells_To_Modify_Item;
2430    modifyItem=&cellsToModify->list.array[0]->value.choice.Served_Cells_To_Modify_Item;
2431
2432    if(fillServCellToModItem(modifyItem))
2433       return RFAILED;
2434    else
2435       return ROK;
2436 }
2437 /*******************************************************************
2438  *
2439  * @brief filling the DeleteItemList
2440  *
2441  * @details
2442  *
2443  *    Function : fillCellToDeleteItem 
2444  *
2445  *    Functionality: Filling the DeleteItemIe 
2446  *
2447  * @params[in] Pointer to Served_Cells_To_Delete_ItemIEs_t 
2448  *
2449  * @return ROK     - success
2450  *         RFAILED - failure
2451  *
2452  *****************************************************************/
2453 uint8_t fillCellToDeleteItem(struct Served_Cells_To_Delete_ItemIEs *deleteItemIe)
2454 {
2455    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
2456    
2457    deleteItemIe->id = ProtocolIE_ID_id_Served_Cells_To_Delete_Item;
2458    deleteItemIe->criticality = Criticality_reject;
2459    deleteItemIe->value.present =\
2460    Served_Cells_To_Delete_ItemIEs__value_PR_Served_Cells_To_Delete_Item;
2461    deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
2462
2463    /*pLMN_Identity*/
2464    deleteItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2465    DU_ALLOC(deleteItem->oldNRCGI.pLMN_Identity.buf,deleteItem->oldNRCGI.pLMN_Identity.size);
2466    if(deleteItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2467    {
2468       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2469       return RFAILED;
2470    }
2471    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2472          deleteItem->oldNRCGI.pLMN_Identity.buf);
2473
2474    /*nRCellIdentity*/
2475    deleteItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2476    DU_ALLOC(deleteItem->oldNRCGI.nRCellIdentity.buf,\
2477          deleteItem->oldNRCGI.nRCellIdentity.size);
2478    if(deleteItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2479    {
2480       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2481       return RFAILED;
2482    }
2483    fillBitString(&deleteItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2484    return ROK;
2485
2486
2487 /*******************************************************************
2488  *
2489  * @brief Builds ServCellToDeleteList
2490  *
2491  * @details
2492  *
2493  *    Function : buildServCellToDeleteList
2494  *
2495  *    Functionality: Builds the serv cell to delete List
2496  *
2497  * @params[in] Pointer to Served_Cells_To_Delete_List_t *
2498  *
2499  * @return ROK     - success
2500  *         RFAILED - failure
2501  *
2502  *****************************************************************/
2503  
2504 uint8_t buildServCellToDeleteList(Served_Cells_To_Delete_List_t *cellsToDelete)
2505 {
2506    uint8_t ieListCnt, arrIdx;
2507    
2508    ieListCnt = 1;
2509    cellsToDelete->list.count = ieListCnt;
2510    cellsToDelete->list.size = ieListCnt*sizeof(Served_Cells_To_Delete_ItemIEs_t *);
2511    
2512    DU_ALLOC(cellsToDelete->list.array,cellsToDelete->list.size);
2513    if(cellsToDelete->list.array == NULLP)
2514    {
2515       DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2516       return RFAILED;
2517    }
2518    
2519    for(arrIdx=0; arrIdx< ieListCnt; arrIdx++)
2520    {
2521       DU_ALLOC(cellsToDelete->list.array[arrIdx],sizeof(Served_Cells_To_Delete_ItemIEs_t));
2522       if(cellsToDelete->list.array[arrIdx] == NULLP)
2523       {
2524          DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2525          return RFAILED;
2526       }
2527    }
2528    
2529    arrIdx=0;
2530    if(fillCellToDeleteItem((Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx]) !=ROK)
2531    {
2532       DU_LOG("\nERROR  -->  F1AP: buildServCellToDeleteList(): failed to fill Served_Cells_To_Delete_ItemIEs");
2533       return RFAILED;
2534    }
2535    return ROK;
2536 }
2537
2538 /*******************************************************************
2539  *
2540  * @brief Builds CellsStatusList
2541  *
2542  * @details
2543  *
2544  *    Function : buildCellsStatusList
2545  *
2546  *    Functionality: Builds the Cell Status List
2547  *
2548  * @params[in] Pointer to Cells_Status_List_t *
2549  *
2550  * @return ROK     - success
2551  *         RFAILED - failure
2552  *
2553  *****************************************************************/
2554 uint8_t buildCellsStatusList(Cells_Status_List_t *cellStatusList)
2555 {
2556    uint8_t elementCnt = 0, idx = 0, ret = ROK;
2557    Cells_Status_ItemIEs_t *cellStatusItemIE;
2558
2559    elementCnt = 1;
2560    cellStatusList->list.count = elementCnt;
2561    cellStatusList->list.size = elementCnt * sizeof(Cells_Status_ItemIEs_t *);
2562    DU_ALLOC(cellStatusList->list.array, cellStatusList->list.size);
2563
2564    for(idx = 0; idx < elementCnt; idx++)
2565    {
2566       DU_ALLOC(cellStatusList->list.array[idx], sizeof(Cells_Status_ItemIEs_t));
2567       if(!cellStatusList->list.array[idx])
2568       {
2569          DU_LOG("ERROR  --> F1AP: buildCellsStatusList() memory allocation failure");
2570          return RFAILED;
2571       }
2572    }
2573    idx = 0;
2574    cellStatusItemIE = (Cells_Status_ItemIEs_t *)cellStatusList->list.array[idx];
2575    cellStatusItemIE->id = ProtocolIE_ID_id_Cells_Status_Item;
2576    cellStatusItemIE->criticality = Criticality_reject;
2577    cellStatusItemIE->value.present = Cells_Status_ItemIEs__value_PR_Cells_Status_Item;
2578    ret = BuildNrcgi(&cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI);
2579    if(ret == RFAILED)
2580    {
2581          DU_LOG("ERROR  --> F1AP: buildCellsStatusList() NRCGI failed");
2582          return RFAILED;
2583    }
2584    cellStatusItemIE->value.choice.Cells_Status_Item.service_status.service_state = Service_State_in_service;
2585    return ROK;
2586 }
2587
2588 /*******************************************************************
2589  *
2590  * @brief Builds and sends the DUConfigUpdate
2591  *
2592  * @details
2593  *
2594  *    Function : BuildAndSendDUConfigUpdate
2595  *
2596  *    Functionality: Constructs the DU Update message and sends
2597  *                   it to the CU through SCTP.
2598  *
2599  * @params[in] void **buf,Buffer to which encoded pattern is written into
2600  * @params[in] int *size,size of buffer
2601  *
2602  * @return ROK     - success
2603  *         RFAILED - failure
2604  *
2605  * ****************************************************************/
2606 uint8_t BuildAndSendDUConfigUpdate(ServCellAction servCellAction)
2607 {
2608    uint8_t ret =0, ieIdx=0, elementCnt=0;
2609    bool memAlloctionFailure = false;
2610    F1AP_PDU_t                 *f1apDuCfg = NULLP;
2611    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
2612    asn_enc_rval_t encRetVal;     /* Encoder return value */
2613    
2614    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2615    ret= RFAILED;
2616
2617    while(true)
2618    {
2619       DU_LOG("\nINFO   -->  F1AP : Building DU config update\n");
2620       /* Allocate the memory for F1DuCfg */
2621       DU_ALLOC(f1apDuCfg, sizeof(F1AP_PDU_t));
2622       if(f1apDuCfg == NULLP)
2623       {
2624          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2625          break;
2626       }
2627
2628       f1apDuCfg->present = F1AP_PDU_PR_initiatingMessage;
2629       DU_ALLOC(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2630       if(f1apDuCfg->choice.initiatingMessage == NULLP)
2631       {
2632          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2633          break;
2634       }
2635
2636       f1apDuCfg->choice.initiatingMessage->procedureCode = \
2637                                                            ProcedureCode_id_gNBDUConfigurationUpdate;
2638       f1apDuCfg->choice.initiatingMessage->criticality = Criticality_reject;
2639       f1apDuCfg->choice.initiatingMessage->value.present = \
2640                                                            InitiatingMessage__value_PR_GNBDUConfigurationUpdate;
2641       duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->value.\
2642                     choice.GNBDUConfigurationUpdate;
2643       elementCnt = 4;
2644       duCfgUpdate->protocolIEs.list.count = elementCnt;
2645       duCfgUpdate->protocolIEs.list.size = \
2646                                            elementCnt * sizeof(GNBDUConfigurationUpdateIEs_t*);
2647
2648       /* Initialize the F1Setup members */
2649       DU_ALLOC(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2650       if(duCfgUpdate->protocolIEs.list.array == NULLP)
2651       {
2652          DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2653          break;
2654       }
2655       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
2656       {
2657          DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx],sizeof(GNBDUConfigurationUpdateIEs_t));
2658          if(duCfgUpdate->protocolIEs.list.array[ieIdx] == NULLP)
2659          {
2660             DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2661             memAlloctionFailure = true;
2662             break;
2663          }
2664       }
2665       
2666       if(memAlloctionFailure == true)
2667       {
2668          break;
2669       }
2670       /*TransactionID*/
2671       ieIdx = 0;
2672       duCfgUpdate->protocolIEs.list.array[ieIdx]->id=ProtocolIE_ID_id_TransactionID;
2673       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
2674       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2675       GNBDUConfigurationUpdateIEs__value_PR_TransactionID;
2676       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = TRANS_ID;
2677       
2678       ieIdx++;
2679       if(servCellAction == SERV_CELL_TO_MODIFY)
2680       {
2681          /*Served Cell to Modify */
2682          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2683          ProtocolIE_ID_id_Served_Cells_To_Modify_List;
2684          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2685          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2686          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Modify_List;
2687          if(buildServCellToModList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2688                   Served_Cells_To_Modify_List))
2689          {
2690             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToModList");
2691             break;
2692          }
2693       }
2694       else
2695       {
2696          /*Served Cell to Delete */ 
2697          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2698          ProtocolIE_ID_id_Served_Cells_To_Delete_List;
2699          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2700          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2701          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Delete_List;
2702          if(buildServCellToDeleteList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2703          Served_Cells_To_Delete_List)!=ROK)
2704          {
2705             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToDeleteList");
2706             break;
2707          }
2708          
2709       }
2710       // TODO :GNB DU SYS INFO:MIB AND SIB1 INFORMATION TO BE BUILT AND FILLED HERE
2711       
2712       /*Cell Status List*/
2713       ieIdx++;
2714       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_Cells_Status_List;
2715       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2716       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2717            GNBDUConfigurationUpdateIEs__value_PR_Cells_Status_List;
2718       ret = buildCellsStatusList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List);
2719       if(ret == RFAILED)
2720       {
2721          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Cell Status List building failed");
2722          break;
2723       }
2724
2725       /*GNB DU ID */
2726       ieIdx++;
2727       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
2728       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2729       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2730       GNBDUConfigurationUpdateIEs__value_PR_GNB_DU_ID;
2731       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size = sizeof(uint8_t);
2732       DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
2733             duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
2734       if(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == NULLP)
2735       {
2736          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Memory allocation failed for GNB_DU_ID");
2737          break;
2738       }
2739       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] = duCfgParam.duId;
2740
2741       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apDuCfg);
2742
2743       /* Encode the DU Config Update type as APER */
2744       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
2745       encBufSize = 0;
2746       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apDuCfg, PrepFinalEncBuf, encBuf);
2747
2748       /* Checking encode results */
2749       if(encRetVal.encoded == ENCODE_FAIL)
2750       {
2751          DU_LOG("ERROR  -->  F1AP : Could not encode DUConfigUpdate structure (at %s)\n",\
2752                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2753          break;
2754       }
2755       else
2756       {
2757          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DUConfigUpdate\n");
2758 #ifdef DEBUG_ASN_PRINT
2759          for(ieIdx =0; ieIdx < encBufSize; ieIdx++)
2760          {
2761             printf("%x",encBuf[ieIdx]);
2762          }
2763 #endif
2764       }
2765       if(addOrModifyE2NodeComponent(F1, E2_NODE_COMPONENT_UPDATE, true, encBufSize, encBuf)!=ROK)
2766       {
2767          DU_LOG("\nERROR  -->  F1AP : Failed to update the e2 node in the list");
2768          break;
2769       }
2770       /* Sending msg */
2771       if(sendF1APMsg() != ROK)
2772       {
2773          DU_LOG("\nERROR  -->  F1AP : Sending GNB-DU Config Update failed");
2774          break;
2775       }
2776
2777       ret = ROK;
2778       break;
2779    }
2780   
2781    addToReservedF1apPduList(TRANS_ID,f1apDuCfg);
2782    return ret;
2783 }
2784
2785
2786 /*******************************************************************
2787  *
2788  * @brief free the ULRRCMessageTransfer
2789  *
2790  * @details
2791  *
2792  *    Function : FreeULRRCMessageTransfer
2793  *
2794  *    Functionality: Deallocating the memory of variable allocated in
2795  *                      FreeULRRCMessageTransfer
2796  *
2797  * @params[in]
2798  *
2799  * @return ROK     - void
2800  *
2801  ******************************************************************/
2802 void FreeULRRCMessageTransfer( F1AP_PDU_t *f1apMsg)
2803 {
2804    uint8_t idx1;
2805    ULRRCMessageTransfer_t  *ulRRCMsg;
2806
2807    if(f1apMsg != NULLP)
2808    { 
2809       if(f1apMsg->choice.initiatingMessage != NULLP)
2810       {
2811          ulRRCMsg = &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2812          if(ulRRCMsg->protocolIEs.list.array != NULLP)
2813          {
2814             for(idx1=0;idx1<ulRRCMsg->protocolIEs.list.count;idx1++)
2815             {
2816                if(ulRRCMsg->protocolIEs.list.array[idx1] != NULLP)
2817                {
2818                   if(ulRRCMsg->protocolIEs.list.array[idx1]->value.present ==
2819                         ULRRCMessageTransferIEs__value_PR_RRCContainer)
2820                   {
2821                      DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2822                            ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2823                   }
2824                   DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1],sizeof(ULRRCMessageTransferIEs_t));
2825                }
2826             }
2827             DU_FREE(ulRRCMsg->protocolIEs.list.array,ulRRCMsg->protocolIEs.list.size );
2828          }
2829          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2830       }
2831       DU_FREE(f1apMsg,sizeof(F1AP_PDU_t));
2832    }
2833 }
2834 /*******************************************************************
2835  *
2836  * @brief Builds and sends the ULRRCMessageTransfer 
2837  *
2838  * @details
2839  *
2840  *    Function : BuildAndSendULRRCMessageTransfer
2841  *
2842  *    Functionality: Constructs the UL RRC Message Transfer and sends
2843  *                   it to the CU through SCTP.
2844  *
2845  * @params[in] 
2846  *
2847  * @return ROK     - success
2848  *         RFAILED - failure
2849  *
2850  * ****************************************************************/
2851 uint8_t BuildAndSendULRRCMessageTransfer(DuUeCb  *ueCb, uint8_t lcId, \
2852       uint16_t msgLen, uint8_t *rrcMsg)
2853 {
2854    uint8_t                 elementCnt=0, idx1=0, idx=0;
2855    uint8_t                 ret = RFAILED;
2856    F1AP_PDU_t              *f1apMsg = NULLP;
2857    ULRRCMessageTransfer_t  *ulRRCMsg = NULLP;
2858    asn_enc_rval_t          encRetVal;        /* Encoder return value */
2859    
2860    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2861
2862    while(true)
2863    {
2864       DU_LOG("\nINFO   -->  F1AP : Building UL RRC Message Transfer Message\n");
2865
2866       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
2867       if(f1apMsg == NULLP)
2868       {
2869          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
2870          break;
2871       }
2872       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
2873       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2874       if(f1apMsg->choice.initiatingMessage == NULLP)
2875       {
2876          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
2877          break;
2878       }
2879       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_ULRRCMessageTransfer;
2880       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
2881       f1apMsg->choice.initiatingMessage->value.present = \
2882                                                          InitiatingMessage__value_PR_ULRRCMessageTransfer;
2883       ulRRCMsg =
2884          &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2885       elementCnt = 4;
2886       ulRRCMsg->protocolIEs.list.count = elementCnt;
2887       ulRRCMsg->protocolIEs.list.size = \
2888                                         elementCnt * sizeof(ULRRCMessageTransferIEs_t *);
2889
2890       /* Initialize the F1Setup members */
2891       DU_ALLOC(ulRRCMsg->protocolIEs.list.array, ulRRCMsg->protocolIEs.list.size);
2892       if(ulRRCMsg->protocolIEs.list.array == NULLP)
2893       {
2894          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UL RRC MessageTransferIEs failed");
2895          break;
2896       }
2897       for(idx=0; idx<elementCnt; idx++)
2898       {
2899          DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx],sizeof(ULRRCMessageTransferIEs_t));
2900          if(ulRRCMsg->protocolIEs.list.array[idx] == NULLP)
2901          {
2902             break;
2903          }
2904       }
2905
2906       idx1 = 0;
2907
2908       /*GNB CU UE F1AP ID*/
2909       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
2910       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2911       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2912                                                               ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
2913       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
2914
2915       /*GNB DU UE F1AP ID*/
2916       idx1++;
2917       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
2918       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2919       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2920                                                               ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
2921       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
2922
2923       /*SRBID*/
2924       idx1++;
2925       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
2926       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2927       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2928                                                               ULRRCMessageTransferIEs__value_PR_SRBID;
2929       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.SRBID = lcId;
2930
2931       /*RRCContainer*/
2932       idx1++;
2933       ulRRCMsg->protocolIEs.list.array[idx1]->id  = ProtocolIE_ID_id_RRCContainer;
2934       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2935       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2936                                                               ULRRCMessageTransferIEs__value_PR_RRCContainer;
2937       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size = msgLen;
2938       DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2939             ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size)
2940       if(!ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf)
2941       {
2942          DU_LOG(" ERROR  -->  F1AP : Memory allocation for BuildAndSendULRRCMessageTransfer failed");
2943          break;
2944       }
2945       memset(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, 0, msgLen);
2946       memcpy(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, \
2947             rrcMsg, ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2948
2949       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
2950
2951       /* Encode the F1SetupRequest type as APER */
2952       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2953       encBufSize = 0;
2954       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
2955             encBuf);
2956       /* Encode results */
2957       if(encRetVal.encoded == ENCODE_FAIL)
2958       {
2959          DU_LOG( "\nERROR  -->  F1AP : Could not encode ULRRCMessageTransfer structure (at %s)\n",\
2960                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2961          break;
2962       }
2963       else
2964       {
2965          DU_LOG("\nDEBUG  -->  F1AP : Created APER encoded buffer for ULRRCMessageTransfer\n");
2966 #ifdef DEBUG_ASN_PRINT
2967          for(int i=0; i< encBufSize; i++)
2968          {
2969             printf("%x",encBuf[i]);
2970          }
2971 #endif
2972       }
2973
2974       /* Sending  msg  */
2975       if(sendF1APMsg()  !=      ROK)
2976       {
2977          DU_LOG("\nERROR  -->   F1AP : Sending  UL RRC Message Transfer Failed");
2978          break;
2979       }
2980       ret = ROK;
2981       break;
2982    }
2983    FreeULRRCMessageTransfer(f1apMsg);
2984
2985    return ret;
2986 }/* End of BuildAndSendULRRCMessageTransfer*/
2987
2988 /*******************************************************************
2989  *
2990  * @brief Builds tag config 
2991  *
2992  * @details
2993  *
2994  *    Function : BuildTagConfig 
2995  *
2996  *    Functionality: Builds tag config in MacCellGroupConfig
2997  *
2998  * @params[in] TAG_Config *tag_Config
2999  *
3000  * @return ROK     - success
3001  *         RFAILED - failure
3002  *
3003  * ****************************************************************/
3004 uint8_t BuildTagConfig(DuUeCb *ueCb, struct TAG_Config *tagConfig)
3005 {
3006    struct TAG_Config__tag_ToAddModList *tagList;
3007    uint8_t                     idx, elementCnt;
3008
3009    tagConfig->tag_ToReleaseList = NULLP;
3010    tagConfig->tag_ToAddModList = NULLP;
3011    DU_ALLOC(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
3012    if(!tagConfig->tag_ToAddModList)
3013    {
3014       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3015       return RFAILED;
3016    }
3017
3018    if(ueCb == NULLP)
3019       elementCnt = ODU_VALUE_ONE;
3020    else
3021       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModListCount;
3022
3023    tagList = tagConfig->tag_ToAddModList;
3024    tagList->list.count = elementCnt;
3025    tagList->list.size  =  elementCnt * sizeof(struct TAG *);
3026
3027    tagList->list.array = NULLP;
3028    DU_ALLOC(tagList->list.array, tagList->list.size);
3029    if(!tagList->list.array)
3030    {
3031       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3032       return RFAILED;
3033    }
3034
3035    for(idx=0; idx<tagList->list.count; idx++)
3036    {
3037       tagList->list.array[idx] = NULLP;
3038       DU_ALLOC(tagList->list.array[idx], sizeof(struct TAG));
3039       if(!tagList->list.array[idx])
3040       {
3041          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3042          return RFAILED;
3043       }
3044    }
3045
3046    if(ueCb == NULLP)
3047    {
3048       idx = 0;
3049       tagList->list.array[idx]->tag_Id = TAG_ID;
3050       tagList->list.array[idx]->timeAlignmentTimer = TIME_ALIGNMENT_TMR;
3051    }
3052    else
3053    {
3054       for(idx=0; idx<tagList->list.count; idx++)
3055       {
3056          tagList->list.array[idx]->tag_Id = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].tagId;
3057          tagList->list.array[idx]->timeAlignmentTimer = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].timeAlignTimer;
3058       }
3059    }
3060
3061    return ROK;
3062 }
3063
3064 /*******************************************************************
3065  *
3066  * @brief Builds PHR Config 
3067  *
3068  * @details
3069  *
3070  *    Function : BuildPhrConfig
3071  *
3072  *    Functionality: Builds phrConfig in MacCellGroupConfig
3073  *
3074  * @params[in] PHR Config *
3075  *
3076  * @return ROK     - success
3077  *         RFAILED - failure
3078  *
3079  * ****************************************************************/
3080 uint8_t BuildPhrConfig(DuUeCb *ueCb, struct MAC_CellGroupConfig__phr_Config *phrConfig)
3081 {
3082
3083    phrConfig->present = MAC_CellGroupConfig__phr_Config_PR_setup;
3084    phrConfig->choice.setup = NULLP;
3085    DU_ALLOC(phrConfig->choice.setup, sizeof(struct PHR_Config));
3086    if(!phrConfig->choice.setup)
3087    {
3088       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhrConfig");
3089       return RFAILED;
3090    }
3091
3092    if(ueCb == NULLP)
3093    {
3094       phrConfig->choice.setup->phr_PeriodicTimer        = PHR_PERIODIC_TMR;
3095       phrConfig->choice.setup->phr_ProhibitTimer        = PHR_PROHIBHIT_TMR;
3096       phrConfig->choice.setup->phr_Tx_PowerFactorChange = PHR_PWR_FACTOR_CHANGE;
3097       phrConfig->choice.setup->multiplePHR              = false;
3098       phrConfig->choice.setup->dummy                    = false;
3099       phrConfig->choice.setup->phr_Type2OtherCell       = false;
3100       phrConfig->choice.setup->phr_ModeOtherCG          = PHR_MODE_OTHER_CG;
3101    }
3102    else
3103    {
3104       phrConfig->choice.setup->phr_PeriodicTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.periodicTimer;
3105       phrConfig->choice.setup->phr_ProhibitTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.prohibitTimer;
3106       phrConfig->choice.setup->phr_Tx_PowerFactorChange = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.txPowerFactor;
3107       phrConfig->choice.setup->multiplePHR              = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.multiplePHR;
3108       phrConfig->choice.setup->dummy                    = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.dummy;
3109       phrConfig->choice.setup->phr_Type2OtherCell       = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrType2OtherCell;
3110       phrConfig->choice.setup->phr_ModeOtherCG          = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrOtherCG;
3111    }
3112
3113    return ROK;
3114 }
3115
3116 /*******************************************************************
3117  *
3118  * @brief Builds BSR Config 
3119  *
3120  * @details
3121  *
3122  *    Function : BuildBsrConfig
3123  *
3124  *    Functionality: Builds BuildBsrConfig in MacCellGroupConfig
3125  *
3126  * @params[in] BSR_Config *bsrConfig
3127  *
3128  * @return ROK     - success
3129  *         RFAILED - failure
3130  *
3131  * ****************************************************************/
3132 uint8_t BuildBsrConfig(DuUeCb *ueCb, struct BSR_Config *bsrConfig)
3133 {
3134    if(ueCb == NULLP)
3135    {
3136       bsrConfig->periodicBSR_Timer = PERIODIC_BSR_TMR;
3137       bsrConfig->retxBSR_Timer     = RETX_BSR_TMR;
3138       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
3139    }
3140    else
3141    {
3142       bsrConfig->periodicBSR_Timer = convertBsrPeriodicTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.periodicTimer);
3143       bsrConfig->retxBSR_Timer     = convertBsrRetxTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.retxTimer);
3144
3145       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
3146       DU_ALLOC(bsrConfig->logicalChannelSR_DelayTimer, sizeof(long));
3147       if(bsrConfig->logicalChannelSR_DelayTimer == NULLP)
3148       {
3149          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildBsrConfig");
3150          return RFAILED;
3151       }
3152       *(bsrConfig->logicalChannelSR_DelayTimer) = convertLcSrDelayTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.srDelayTimer);
3153    }
3154
3155    return ROK;
3156 }
3157
3158 /*******************************************************************
3159  *
3160  * @brief Builds scheduling request config 
3161  *
3162  * @details
3163  *
3164  *    Function : BuildSchedulingReqConfig 
3165  *
3166  *    Functionality: Builds BuildSchedulingReqConfig in MacCellGroupConfig
3167  *
3168  * @params[in] SchedulingRequestConfig *schedulingRequestConfig
3169  *
3170  * @return ROK     - success
3171  *         RFAILED - failure
3172  *
3173  * ****************************************************************/
3174 uint8_t BuildSchedulingReqConfig(DuUeCb *ueCb, struct SchedulingRequestConfig *schedulingRequestConfig)
3175 {
3176    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList;
3177    uint8_t                     idx, elementCnt;
3178
3179    schedulingRequestConfig->schedulingRequestToAddModList = NULLP;
3180    DU_ALLOC(schedulingRequestConfig->schedulingRequestToAddModList,
3181          sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));
3182    if(!schedulingRequestConfig->schedulingRequestToAddModList)
3183    {
3184       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3185       return RFAILED;
3186    }
3187
3188    if(ueCb == NULLP)
3189       elementCnt = ODU_VALUE_ONE;
3190    else
3191       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModListCount;
3192
3193    schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
3194    schReqList->list.count = elementCnt;
3195    schReqList->list.size  = elementCnt * sizeof(struct SchedulingRequestToAddMod *);
3196
3197    schReqList->list.array = NULLP;
3198    DU_ALLOC(schReqList->list.array, schReqList->list.size);
3199    if(!schReqList->list.array)
3200    {
3201       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3202       return RFAILED;
3203    }
3204
3205    for(idx=0; idx<schReqList->list.count; idx++)
3206    {
3207       schReqList->list.array[idx] = NULLP;
3208       DU_ALLOC(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
3209       if(!schReqList->list.array[idx])
3210       {
3211          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3212          return RFAILED;
3213       }
3214    }
3215
3216    if(ueCb == NULLP)
3217    {
3218       idx = 0;
3219       schReqList->list.array[idx]->schedulingRequestId = SCH_REQ_ID;
3220
3221       schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
3222       DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
3223       if(!schReqList->list.array[idx]->sr_ProhibitTimer)
3224       {
3225          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3226          return RFAILED;
3227       }
3228       *(schReqList->list.array[idx]->sr_ProhibitTimer) = SR_PROHIBIT_TMR;
3229       schReqList->list.array[idx]->sr_TransMax = SR_TRANS_MAX;
3230    }
3231    else
3232    {
3233       for(idx=0; idx<schReqList->list.count; idx++)
3234       {
3235          schReqList->list.array[idx]->schedulingRequestId = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].schedReqId;
3236
3237          schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
3238          DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
3239          if(!schReqList->list.array[idx]->sr_ProhibitTimer)
3240          {
3241             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3242             return RFAILED;
3243          }
3244          *(schReqList->list.array[idx]->sr_ProhibitTimer) = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srProhibitTmr;
3245          schReqList->list.array[idx]->sr_TransMax = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srTransMax;
3246       }
3247    }
3248
3249    schedulingRequestConfig->schedulingRequestToReleaseList = NULLP;
3250
3251    return ROK;
3252 }
3253
3254 /*******************************************************************
3255  *
3256  * @brief Builds RLC Configuration for AM mode
3257  *
3258  * @details
3259  *
3260  *    Function : BuildRlcConfigAm
3261  *
3262  *    Functionality: 
3263  *       Builds AM mode RLC Config in BuildRlcBearerToAddModList
3264  *
3265  * @params[in] AmBearerCfg *amCfg
3266  *             RLC_Config_t  *rlcConfig
3267  *
3268  * @return ROK     - success
3269  *         RFAILED - failure
3270  *
3271  * ****************************************************************/
3272 uint8_t BuildRlcConfigAm(AmBearerCfg *amCfg, struct RLC_Config *rlcConfig)
3273 {
3274    rlcConfig->choice.am = NULLP;
3275    DU_ALLOC(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
3276    if(!rlcConfig->choice.am)
3277    {
3278       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3279       return RFAILED;
3280    }
3281
3282    /* Fill AM UL configuration */
3283    rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength = NULLP;
3284    DU_ALLOC(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
3285    if(!rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength)
3286    {
3287       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3288       return RFAILED;
3289    }
3290
3291    /* Fill default AM UL configuration if input pointer to DU database is NULL */
3292    if(amCfg == NULLP)
3293    {
3294       
3295       *(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"*/
3296       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = T_POLL_RETRANSMIT;
3297       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = POLL_PDU;
3298       rlcConfig->choice.am->ul_AM_RLC.pollByte          = POLL_BYTE;
3299       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = MAX_RETX_THRESHOLD;
3300    }
3301    else
3302    {
3303       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->dlAmCfg.snLenDl);
3304       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = covertPollRetxTmrValueToEnum(amCfg->dlAmCfg.pollRetxTmr);
3305       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = covertPollPduValueToEnum(amCfg->dlAmCfg.pollPdu);
3306       rlcConfig->choice.am->ul_AM_RLC.pollByte          = covertPollByteValueToEnum(amCfg->dlAmCfg.pollByte);
3307       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = covertMaxRetxValueToEnum(amCfg->dlAmCfg.maxRetxTh);
3308    }
3309
3310    /* Fill AM DL configuraion */
3311    rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength = NULLP;
3312    DU_ALLOC(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
3313    if(!rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength)
3314    {
3315       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3316       return RFAILED;
3317    }
3318
3319    /* Fill default AM DL configuration if input pointer to DU database is NULL */
3320    if(amCfg == NULLP)
3321    {
3322       *(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"*/
3323       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = T_REASSEMBLY;
3324       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = T_STATUS_PROHIBHIT;
3325    }
3326    else /* Fill AM configuration from DU database */
3327    {
3328       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->ulAmCfg.snLenUl);
3329       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = convertReasmblTmrValueToEnum(amCfg->ulAmCfg.reAssemTmr);
3330       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = convertProhibitTmrValueToEnum(amCfg->ulAmCfg.statProhTmr);
3331    }
3332    return ROK;
3333 }
3334
3335 /*******************************************************************
3336  *
3337  * @brief Builds RLC Config for UM Bidirection
3338  *
3339  * @details
3340  *
3341  *    Function : BuildRlcConfig UmBiDir
3342  *
3343  *    Functionality: 
3344  *       Builds RLC Config for UM Bidirection in BuildRlcBearerToAddModList 
3345  *
3346  * @params[in] UmBiDirBearerCfg *umBiDirCfg
3347  *             RLC_Config_t *rlcConfig
3348  *
3349  * @return ROK     - success
3350  *         RFAILED - failure
3351  *
3352  * ****************************************************************/
3353 uint8_t BuildRlcConfigUmBiDir(UmBiDirBearerCfg *umBiDirCfg, struct RLC_Config *rlcConfig)
3354 {
3355    rlcConfig->choice.um_Bi_Directional = NULLP;
3356    DU_ALLOC(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
3357    if(rlcConfig->choice.um_Bi_Directional == NULLP)
3358    {
3359       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3360       return RFAILED;
3361    }
3362
3363    /* Fill UM Bidirectional UL configuration */
3364    rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength = NULLP;
3365    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3366    if(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength == NULLP)
3367    {
3368       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3369       return RFAILED;
3370    }
3371
3372    if(umBiDirCfg != NULLP)
3373    {
3374       *(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->dlUmCfg.snLenDlUm);     
3375    }
3376
3377    /* Fill UM Bidirectional DL configuration */
3378    rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength = NULLP;
3379    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3380    if(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength == NULLP)
3381    {
3382       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3383       return RFAILED;
3384    }
3385
3386    if(umBiDirCfg != NULLP)
3387    {
3388       *(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->ulUmCfg.snLenUlUm);     
3389       rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umBiDirCfg->ulUmCfg.reAssemTmr);
3390    }
3391
3392    return ROK;
3393 }
3394
3395 /*******************************************************************
3396  *
3397  * @brief Builds RLC Config for UM Uni directional UL
3398  *
3399  * @details
3400  *
3401  *    Function : BuildRlcConfigUmUniDirUl
3402  *
3403  *    Functionality: 
3404  *       Builds RLC Config for UM Unidirection UL in BuildRlcBearerToAddModList 
3405  *
3406  * @params[in] UmUniDirDlBearerCfg *umUniDirDlCfg
3407  *             RLC_Config_t *rlcConfig
3408  *
3409  * @return ROK     - success
3410  *         RFAILED - failure
3411  *
3412  * ****************************************************************/
3413 uint8_t BuildRlcConfigUmUniDirUl(UmUniDirDlBearerCfg *umUniDirDlCfg, RLC_Config_t *rlcConfig)
3414 {
3415    rlcConfig->choice.um_Uni_Directional_UL = NULLP;
3416    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
3417    if(rlcConfig->choice.um_Uni_Directional_UL == NULLP)
3418    {
3419       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3420       return RFAILED;
3421    }
3422
3423    rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength = NULLP;
3424    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3425    if(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength == NULLP)
3426    {
3427       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3428       return RFAILED;
3429    }
3430
3431    if(umUniDirDlCfg != NULLP)
3432    {
3433       *(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirDlCfg->dlUmCfg.snLenDlUm);
3434    }
3435
3436    return ROK;
3437 }
3438
3439 /*******************************************************************
3440  *
3441  * @brief Builds RLC Config for UM Uni directional DL
3442  *
3443  * @details
3444  *
3445  *    Function : BuildRlcConfigUmUniDirDl
3446  *
3447  *    Functionality: 
3448  *       Builds RLC Config for UM Unidirection DL in BuildRlcBearerToAddModList 
3449  *
3450  * @params[in] UmUniDirUlBearerCfg *umUniDirUlCfg
3451  *             RLC_Config_t *rlcConfig
3452  *
3453  * @return ROK     - success
3454  *         RFAILED - failure
3455  *
3456  * ****************************************************************/
3457 uint8_t BuildRlcConfigUmUniDirDl(UmUniDirUlBearerCfg *umUniDirUlCfg, RLC_Config_t *rlcConfig)
3458 {
3459    rlcConfig->choice.um_Uni_Directional_DL = NULLP;
3460    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
3461    if(rlcConfig->choice.um_Uni_Directional_DL == NULLP)
3462    {
3463       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3464       return RFAILED;
3465    }
3466
3467    rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength = NULLP;
3468    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3469    if(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength == NULLP)
3470    {
3471       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3472       return RFAILED;
3473    }
3474
3475    if(umUniDirUlCfg != NULLP)
3476    {
3477       *(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirUlCfg->ulUmCfg.snLenUlUm);
3478       rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umUniDirUlCfg->ulUmCfg.reAssemTmr);
3479    }
3480
3481    return ROK;
3482 }
3483
3484 /*******************************************************************
3485  *
3486  * @brief Builds RLC Config
3487  *
3488  * @details
3489  *
3490  *    Function : BuildRlcConfig
3491  *
3492  *    Functionality: Builds RLC Config in BuildRlcBearerToAddModList 
3493  *
3494  * @params[in] RLC_Config_t *rlcConfig
3495  *
3496  * @return ROK     - success
3497  *         RFAILED - failure
3498  *
3499  * ****************************************************************/
3500 uint8_t BuildRlcConfig(RlcBearerCfg *rbCfg, struct RLC_Config *rlcConfig)
3501 {
3502    
3503    /* Fill default values if rbCfg is NULL */
3504    if(rbCfg == NULLP)
3505    {
3506       rlcConfig->present = RLC_Config_PR_am;
3507       BuildRlcConfigAm(NULLP, rlcConfig);
3508    }
3509    /* If RbCfg is present, fill RLC configurations from DU Database */
3510    else
3511    {
3512       rlcConfig->present = covertRlcModeFromIntEnumToRrcEnum(rbCfg->rlcMode);
3513       switch(rlcConfig->present)
3514       {
3515          case RLC_Config_PR_am:
3516             BuildRlcConfigAm(rbCfg->u.amCfg, rlcConfig);
3517             break;
3518          case RLC_Config_PR_um_Bi_Directional:
3519             BuildRlcConfigUmBiDir(rbCfg->u.umBiDirCfg, rlcConfig);
3520             break;
3521          case RLC_Config_PR_um_Uni_Directional_UL:
3522             BuildRlcConfigUmUniDirUl(rbCfg->u.umUniDirDlCfg, rlcConfig);
3523             break;
3524          case RLC_Config_PR_um_Uni_Directional_DL:
3525             BuildRlcConfigUmUniDirDl(rbCfg->u.umUniDirUlCfg, rlcConfig);
3526             break;
3527          case RLC_Config_PR_NOTHING:
3528          default:
3529             break;
3530       }
3531    }
3532
3533    return ROK;
3534 }
3535
3536 /*******************************************************************
3537  *
3538  * @brief Builds MAC LC Config
3539  *
3540  * @details
3541  *
3542  *    Function : BuildMacLCConfig 
3543  *
3544  *    Functionality: Builds MAC LC Config in BuildRlcBearerToAddModList 
3545  *
3546  * @params[in] struct LogicalChannelConfig macLcConfig
3547  *
3548  * @return ROK     - success
3549  *         RFAILED - failure
3550  *
3551  * ****************************************************************/
3552 uint8_t BuildMacLCConfig(LcCfg *lcCfgDb, struct LogicalChannelConfig *macLcConfig)
3553 {
3554    macLcConfig->ul_SpecificParameters = NULLP;
3555    DU_ALLOC(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
3556    if(!macLcConfig->ul_SpecificParameters)
3557    {
3558       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3559       return RFAILED;
3560    }
3561
3562    if(lcCfgDb == NULLP)
3563    {
3564       macLcConfig->ul_SpecificParameters->priority = MAC_LC_PRIORITY;
3565       macLcConfig->ul_SpecificParameters->prioritisedBitRate =  PRIORTISIED_BIT_RATE;
3566       macLcConfig->ul_SpecificParameters->bucketSizeDuration =  BUCKET_SIZE_DURATION;
3567    }
3568    else
3569    {
3570       macLcConfig->ul_SpecificParameters->priority = lcCfgDb->ulLcCfg.priority;
3571       macLcConfig->ul_SpecificParameters->prioritisedBitRate = lcCfgDb->ulLcCfg.pbr;
3572       macLcConfig->ul_SpecificParameters->bucketSizeDuration = lcCfgDb->ulLcCfg.bsd;
3573    }
3574
3575    macLcConfig->ul_SpecificParameters->allowedServingCells = NULLP;
3576    macLcConfig->ul_SpecificParameters->allowedSCS_List = NULLP;
3577    macLcConfig->ul_SpecificParameters->maxPUSCH_Duration = NULLP;
3578    macLcConfig->ul_SpecificParameters->configuredGrantType1Allowed = NULLP;
3579
3580    macLcConfig->ul_SpecificParameters->logicalChannelGroup = NULLP;
3581    DU_ALLOC(macLcConfig->ul_SpecificParameters->logicalChannelGroup,    sizeof(long));
3582    if(!macLcConfig->ul_SpecificParameters->logicalChannelGroup)
3583    {
3584       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3585       return RFAILED;
3586    }
3587
3588    if(lcCfgDb == NULLP)
3589       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = LC_GRP;
3590    else
3591       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = lcCfgDb->ulLcCfg.lcGroup;
3592
3593    macLcConfig->ul_SpecificParameters->schedulingRequestID = NULLP;
3594    DU_ALLOC(macLcConfig->ul_SpecificParameters->schedulingRequestID,    sizeof(SchedulingRequestId_t));
3595    if(!macLcConfig->ul_SpecificParameters->schedulingRequestID)
3596    {
3597       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3598       return RFAILED;
3599    }
3600
3601    if(lcCfgDb == NULLP)
3602       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = SCH_REQ_ID;
3603    else
3604       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = lcCfgDb->ulLcCfg.schReqId;
3605
3606    macLcConfig->ul_SpecificParameters->logicalChannelSR_Mask = false;
3607    macLcConfig->ul_SpecificParameters->logicalChannelSR_DelayTimerApplied = false;
3608    macLcConfig->ul_SpecificParameters->bitRateQueryProhibitTimer = NULLP;
3609
3610    return ROK;
3611 }
3612
3613 /*******************************************************************
3614  *
3615  * @brief Builds RLC Bearer to Add/Mod list
3616  *
3617  * @details
3618  *
3619  *    Function :BuildRlcBearerToAddModList 
3620  *
3621  *    Functionality: Builds RLC Bearer to Add/Mod list in DuToCuRrcContainer
3622  *
3623  * @params[in] rlc_BearerToAddModList
3624  *
3625  * @return ROK     - success
3626  *         RFAILED - failure
3627  *
3628  * ****************************************************************/
3629 uint8_t BuildRlcBearerToAddModList(DuUeCb *ueCb, struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList)
3630 {
3631    uint8_t  idx = 0, lcIdx=0, macLcIdx = 0, elementCnt = 0;
3632
3633    if(ueCb == NULLP)
3634       elementCnt = 1;
3635    else if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
3636       elementCnt = ueCb->duRlcUeCfg.numLcs;
3637    else
3638    {
3639       for(lcIdx = 0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3640       {
3641          if(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == false)
3642             elementCnt++;
3643       }
3644    }
3645    rlcBearerList->list.count = elementCnt;
3646    rlcBearerList->list.size  = elementCnt * sizeof(struct RLC_BearerConfig *);
3647
3648    rlcBearerList->list.array = NULLP;
3649    DU_ALLOC(rlcBearerList->list.array, rlcBearerList->list.size);
3650    if(!rlcBearerList->list.array)
3651    {
3652       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3653       return RFAILED;
3654    }
3655
3656    for(idx=0; idx<rlcBearerList->list.count; idx++)
3657    {
3658       rlcBearerList->list.array[idx] = NULLP;
3659       DU_ALLOC(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
3660       if(!rlcBearerList->list.array[idx])
3661       {
3662          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3663          return RFAILED;
3664       }
3665    }
3666
3667    if(ueCb == NULLP)
3668    {
3669       idx=0;
3670       rlcBearerList->list.array[idx]->logicalChannelIdentity = SRB1_LCID;
3671       DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3672       if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3673       {     
3674          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3675          return RFAILED;
3676       }     
3677       rlcBearerList->list.array[idx]->servedRadioBearer->present = RLC_BearerConfig__servedRadioBearer_PR_srb_Identity;
3678       rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = SRB1_LCID;
3679       rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3680
3681       /* Fill RLC related Configurations for this Radio Bearer */
3682       rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3683       DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3684       if(!rlcBearerList->list.array[idx]->rlc_Config)
3685       {
3686          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3687          return RFAILED;
3688       }
3689       if(BuildRlcConfig(NULLP, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3690       {
3691          DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3692          return RFAILED;
3693       }
3694
3695       /* Fill MAC related configurations for this Radio Bearer */
3696       rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3697       DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3698       if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3699       {
3700          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3701          return RFAILED;
3702       }
3703       if(BuildMacLCConfig(NULLP, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3704       {
3705          DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3706          return RFAILED;
3707       }
3708    }
3709    else
3710    {
3711       idx=0;
3712       for(lcIdx=0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3713       {
3714          if((ueCb->f1UeDb->actionType != UE_CTXT_CFG_QUERY) && (ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == true))
3715             continue;
3716
3717          /* Fill Logical channel identity */
3718          rlcBearerList->list.array[idx]->logicalChannelIdentity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId;
3719
3720          /* Fill Radio Bearer Id and type (DRB/SRB) for this logical channel */
3721          DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3722          if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3723          {
3724             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3725             return RFAILED;
3726          }
3727          rlcBearerList->list.array[idx]->servedRadioBearer->present = \
3728                                                                       covertRbTypeFromIntEnumToRrcEnum(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbType);
3729          switch(rlcBearerList->list.array[idx]->servedRadioBearer->present)
3730          {
3731             case RLC_BearerConfig__servedRadioBearer_PR_srb_Identity: 
3732                rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3733                break;
3734             case RLC_BearerConfig__servedRadioBearer_PR_drb_Identity:
3735                rlcBearerList->list.array[idx]->servedRadioBearer->choice.drb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3736                break;
3737             case RLC_BearerConfig__servedRadioBearer_PR_NOTHING:
3738             default:
3739                break;
3740          }
3741          ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent = true;
3742
3743          rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3744
3745          /* Fill RLC related Configurations for this Radio Bearer */
3746          rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3747          DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3748          if(!rlcBearerList->list.array[idx]->rlc_Config)
3749          {
3750             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3751             return RFAILED;
3752          }
3753          if(BuildRlcConfig(&ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3754          {
3755             DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3756             return RFAILED;
3757          }
3758
3759          /* Fill MAC related configurations for this Radio Bearer */
3760          rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3761          DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3762          if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3763          {
3764             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3765             return RFAILED;
3766          }
3767          for(macLcIdx = 0; macLcIdx < ueCb->duMacUeCfg.numLcs; macLcIdx++)
3768          {
3769             if(ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig.lcId == ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId)
3770             {
3771                if(BuildMacLCConfig(&ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3772                {
3773                   DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3774                   return RFAILED;
3775                }
3776                break;
3777             }
3778          }
3779
3780          idx++;
3781       }
3782    }
3783    return ROK;
3784 }
3785
3786 /*******************************************************************
3787  *
3788  * @brief Build Control resource set to add/modify list 
3789  *
3790  * @details
3791  *
3792  *    Function : BuildControlRSetToAddModList
3793  *
3794  *    Functionality: Build Control resource set to add/modify list
3795  *
3796  * @params[in] 
3797  * struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList
3798  *
3799  * @return ROK     - success
3800  *         RFAILED - failure
3801  *
3802  * ****************************************************************/
3803 uint8_t BuildControlRSetToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList)
3804 {
3805    uint8_t idx;
3806    uint8_t elementCnt;
3807    uint8_t numBytes, bitsUnused;
3808    struct ControlResourceSet *controlRSet;
3809    uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
3810    uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
3811
3812    if(pdcchCfg == NULLP)
3813       elementCnt = 1;
3814    else
3815       elementCnt = pdcchCfg->numCRsetToAddMod;
3816
3817    controlRSetList->list.count = elementCnt;
3818    controlRSetList->list.size = elementCnt * sizeof(struct ControlResourceSet *);
3819
3820    controlRSetList->list.array = NULLP;
3821    DU_ALLOC(controlRSetList->list.array, controlRSetList->list.size);
3822    if(!controlRSetList->list.array)
3823    {
3824       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3825       return RFAILED;
3826    }
3827
3828    for(idx = 0; idx < elementCnt; idx++)
3829    {
3830       controlRSetList->list.array[idx] = NULLP;
3831       DU_ALLOC(controlRSetList->list.array[idx], sizeof(struct ControlResourceSet));
3832       if(!controlRSetList->list.array[idx])
3833       {
3834          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3835          return RFAILED;
3836       }
3837    }
3838
3839    for(idx = 0; idx < elementCnt; idx++)
3840    {
3841       controlRSet = controlRSetList->list.array[idx];
3842
3843       if(pdcchCfg == NULLP)
3844          controlRSet->controlResourceSetId = PDCCH_CTRL_RSRC_SET_ONE_ID;
3845       else
3846          controlRSet->controlResourceSetId = pdcchCfg->cRSetToAddModList[idx].cRSetId;
3847
3848       /* size 6 bytes
3849        * 3 LSBs unsued
3850        * Bit string stored ff0000000000
3851        */
3852       numBytes = 6;
3853       bitsUnused = 3;
3854       controlRSet->frequencyDomainResources.size = numBytes * sizeof(uint8_t);
3855
3856       controlRSet->frequencyDomainResources.buf = NULLP;
3857       DU_ALLOC(controlRSet->frequencyDomainResources.buf, controlRSet->frequencyDomainResources.size);
3858       if(!controlRSet->frequencyDomainResources.buf)
3859       {
3860          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3861          return RFAILED;
3862       }
3863
3864       memset(controlRSet->frequencyDomainResources.buf, 0, FREQ_DOM_RSRC_SIZE);
3865
3866       if(pdcchCfg == NULLP)
3867       {
3868          coreset0EndPrb = CORESET0_END_PRB;
3869          coreset1StartPrb = coreset0EndPrb + 6;
3870          coreset1NumPrb = CORESET1_NUM_PRB;
3871          /* calculate the PRBs */
3872          fillCoresetFeqDomAllocMap(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
3873          memcpy(controlRSet->frequencyDomainResources.buf, freqDomainResource, FREQ_DOM_RSRC_SIZE);
3874          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3875
3876          controlRSet->duration = PDCCH_CTRL_RSRC_SET_ONE_DURATION;
3877          controlRSet->cce_REG_MappingType.present = ControlResourceSet__cce_REG_MappingType_PR_nonInterleaved;
3878          controlRSet->precoderGranularity = PDCCH_CTRL_RSRC_SET_ONE_PRECOD_GRANULARITY;
3879       }
3880       else
3881       {
3882          memcpy(controlRSet->frequencyDomainResources.buf, pdcchCfg->cRSetToAddModList[idx].freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
3883          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3884          controlRSet->duration = pdcchCfg->cRSetToAddModList[idx].duration;
3885          controlRSet->cce_REG_MappingType.present = pdcchCfg->cRSetToAddModList[idx].cceRegMappingType;
3886          controlRSet->precoderGranularity = pdcchCfg->cRSetToAddModList[idx].precoderGranularity;
3887       }
3888       controlRSet->tci_StatesPDCCH_ToAddList = NULLP;
3889       controlRSet->tci_StatesPDCCH_ToReleaseList = NULLP;
3890       controlRSet->tci_PresentInDCI = NULLP;
3891
3892 #if 0
3893       uint8_t tciStateIdx;
3894
3895       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList, \
3896             sizeof(struct ControlResourceSet__tci_StatesPDCCH_ToAddList));
3897       if(!controlRset->tci_StatesPDCCH_ToAddList)
3898       {
3899          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3900          return RFAILED;
3901       }
3902
3903       elementCnt = 1;
3904       controlRset->tci_StatesPDCCH_ToAddList->list.count = elementCnt;
3905       controlRset->tci_StatesPDCCH_ToAddList->list.size = elementCnt * sizeof(TCI_StateId_t *);
3906       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array, \
3907             controlRset->tci_StatesPDCCH_ToAddList->list.size)
3908          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array)
3909          {
3910             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3911             return RFAILED;
3912          }
3913
3914       for(tciStateIdx = 0; tciStateIdx <elementCntl; tciStateIdx++)
3915       {
3916          DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx], sizeof(TCI_StateId_t));
3917          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx])
3918          {
3919             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3920             return RFAILED;
3921          }
3922       }
3923
3924       tciStateIdx = 0;
3925       /* TODO */
3926       *(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx]);
3927
3928       DU_ALLOC(controlRset->tci_PresentInDCI, sizeof(long));
3929       if(!controlRset->tci_PresentInDCI)
3930       {
3931          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3932          return RFAILED;
3933       }
3934       /* TODO */
3935       *(controlRset->tci_PresentInDCI);
3936 #endif
3937
3938       controlRSet->pdcch_DMRS_ScramblingID = NULLP;
3939       DU_ALLOC(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
3940       if(!controlRSet->pdcch_DMRS_ScramblingID)
3941       {
3942          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3943          return RFAILED;
3944       }
3945       if(pdcchCfg == NULLP)
3946          *(controlRSet->pdcch_DMRS_ScramblingID) = SCRAMBLING_ID;
3947       else
3948          *(controlRSet->pdcch_DMRS_ScramblingID) = pdcchCfg->cRSetToAddModList[idx].dmrsScramblingId;
3949    }
3950    return ROK;
3951 } /* End BuildControlRSetToAddModList */
3952
3953 /*******************************************************************
3954  *
3955  * @brief Build search space to add/modify list
3956  *
3957  * @details
3958  *
3959  *    Function : BuildSearchSpcToAddModList
3960  *
3961  *    Functionality: Build search space to add/modify list
3962  *
3963  * @params[in] 
3964  * @return ROK     - success
3965  *         RFAILED - failure
3966  *
3967  * ****************************************************************/
3968 uint8_t BuildSearchSpcToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
3969 {
3970    uint8_t idx;
3971    uint8_t numBytes;
3972    uint8_t byteIdx;
3973    uint8_t bitsUnused;
3974    uint8_t elementCnt;
3975    struct SearchSpace *searchSpc;
3976
3977    if(pdcchCfg == NULLP)
3978       elementCnt = 1;
3979    else
3980       elementCnt = pdcchCfg->numSearchSpcToAddMod;
3981
3982    searchSpcList->list.count = elementCnt;
3983    searchSpcList->list.size = elementCnt * sizeof(struct SearchSpace *);
3984
3985    searchSpcList->list.array = NULLP;
3986    DU_ALLOC(searchSpcList->list.array, searchSpcList->list.size);
3987    if(!searchSpcList->list.array)
3988    {
3989       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3990       return RFAILED;
3991    }
3992
3993    for(idx = 0; idx < elementCnt; idx++)
3994    {
3995       searchSpcList->list.array[idx] = NULLP;
3996       DU_ALLOC(searchSpcList->list.array[idx], sizeof(struct SearchSpace));
3997       if(!searchSpcList->list.array[idx])
3998       {
3999          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4000          return RFAILED;
4001       }
4002    }
4003
4004    for(idx = 0; idx < elementCnt; idx++)
4005    {
4006       searchSpc = searchSpcList->list.array[idx];
4007
4008       if(pdcchCfg == NULLP)
4009          searchSpc->searchSpaceId = PDCCH_SRCH_SPC_TWO_ID;
4010       else
4011          searchSpc->searchSpaceId = pdcchCfg->searchSpcToAddModList[idx].searchSpaceId;
4012
4013       searchSpc->controlResourceSetId = NULLP;
4014       DU_ALLOC(searchSpc->controlResourceSetId, sizeof(ControlResourceSetId_t));
4015       if(!searchSpc->controlResourceSetId)
4016       {
4017          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4018          return RFAILED;
4019       }
4020       if(pdcchCfg == NULLP)
4021          *(searchSpc->controlResourceSetId) = PDCCH_CTRL_RSRC_SET_ONE_ID;
4022       else
4023          *(searchSpc->controlResourceSetId) = pdcchCfg->searchSpcToAddModList[idx].cRSetId;
4024
4025       searchSpc->monitoringSlotPeriodicityAndOffset = NULLP;
4026       DU_ALLOC(searchSpc->monitoringSlotPeriodicityAndOffset, sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
4027       if(!searchSpc->monitoringSlotPeriodicityAndOffset)
4028       {
4029          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4030          return RFAILED;
4031       }
4032       if(pdcchCfg == NULLP)
4033          searchSpc->monitoringSlotPeriodicityAndOffset->present = SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
4034       else
4035          searchSpc->monitoringSlotPeriodicityAndOffset->present = pdcchCfg->searchSpcToAddModList[idx].mSlotPeriodicityAndOffset;
4036
4037       searchSpc->duration = NULLP;
4038       searchSpc->monitoringSymbolsWithinSlot = NULLP;
4039       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot, sizeof(BIT_STRING_t));
4040       if(!searchSpc->monitoringSymbolsWithinSlot)
4041       {
4042          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4043          return RFAILED;
4044       }
4045
4046       /* Values taken from reference logs :
4047        * size 2 bytes
4048        * 2 LSBs unsued
4049        * Bit string stores 8000
4050        */
4051       numBytes = 2;
4052       bitsUnused = 2;
4053       searchSpc->monitoringSymbolsWithinSlot->size = numBytes * sizeof(uint8_t);
4054       searchSpc->monitoringSymbolsWithinSlot->buf = NULLP;
4055       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot->buf, searchSpc->monitoringSymbolsWithinSlot->size);
4056       if(!searchSpc->monitoringSymbolsWithinSlot->buf)
4057       {
4058          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4059          return RFAILED;
4060       }
4061       if(pdcchCfg == NULLP)
4062       {
4063          byteIdx = 0;
4064          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = PDCCH_SYMBOL_WITHIN_SLOT /* setting MSB to 128 i.e. 0x80 */;
4065          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = 0;
4066       }
4067       else
4068          memcpy(searchSpc->monitoringSymbolsWithinSlot->buf, pdcchCfg->searchSpcToAddModList[idx].mSymbolsWithinSlot, numBytes);
4069       searchSpc->monitoringSymbolsWithinSlot->bits_unused = bitsUnused;
4070
4071       searchSpc->nrofCandidates = NULLP;
4072       DU_ALLOC(searchSpc->nrofCandidates, sizeof(struct SearchSpace__nrofCandidates));
4073       if(!searchSpc->nrofCandidates)
4074       {
4075          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4076          return RFAILED;
4077       }
4078
4079       if(pdcchCfg == NULLP)
4080       {
4081          searchSpc->nrofCandidates->aggregationLevel1 = PDCCH_SRCH_SPC_TWO_AGG_LVL1_CANDIDATE;
4082          searchSpc->nrofCandidates->aggregationLevel2 = PDCCH_SRCH_SPC_TWO_AGG_LVL2_CANDIDATE;
4083          searchSpc->nrofCandidates->aggregationLevel4 = PDCCH_SRCH_SPC_TWO_AGG_LVL4_CANDIDATE;
4084          searchSpc->nrofCandidates->aggregationLevel8 = PDCCH_SRCH_SPC_TWO_AGG_LVL8_CANDIDATE;
4085          searchSpc->nrofCandidates->aggregationLevel16 = PDCCH_SRCH_SPC_TWO_AGG_LVL16_CANDIDATE;
4086       }
4087       else
4088       {
4089          searchSpc->nrofCandidates->aggregationLevel1 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel1;
4090          searchSpc->nrofCandidates->aggregationLevel2 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel2;
4091          searchSpc->nrofCandidates->aggregationLevel4 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel4;
4092          searchSpc->nrofCandidates->aggregationLevel8 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel8;
4093          searchSpc->nrofCandidates->aggregationLevel16 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel16;
4094       }
4095
4096       searchSpc->searchSpaceType = NULLP;
4097       DU_ALLOC(searchSpc->searchSpaceType, sizeof(struct SearchSpace__searchSpaceType));
4098       if(!searchSpc->searchSpaceType)
4099       {
4100          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4101          return RFAILED;
4102       }
4103       if(pdcchCfg == NULLP)
4104          searchSpc->searchSpaceType->present = SearchSpace__searchSpaceType_PR_ue_Specific;
4105       else
4106          searchSpc->searchSpaceType->present = pdcchCfg->searchSpcToAddModList[idx].searchSpaceType;
4107
4108       searchSpc->searchSpaceType->choice.ue_Specific = NULLP;
4109       DU_ALLOC(searchSpc->searchSpaceType->choice.ue_Specific, sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
4110       if(!searchSpc->searchSpaceType->choice.ue_Specific)
4111       {
4112          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4113          return RFAILED;
4114       }  
4115       if(pdcchCfg == NULLP)
4116          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
4117       else
4118          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = pdcchCfg->searchSpcToAddModList[idx].ueSpecificDciFormat;
4119    }
4120    return ROK;
4121 }/* End BuildSearchSpcToAddModList */
4122
4123 /*******************************************************************
4124  *
4125  * @brief Builds BWP DL dedicated PDCCH config
4126  *
4127  * @details
4128  *
4129  *    Function : BuildBWPDlDedPdcchCfg
4130  *
4131  *    Functionality: Builds BWP DL dedicated PDCCH config
4132  *
4133  * @params[in] struct PDCCH_Config *pdcchCfg
4134  *
4135  * @return ROK     - success
4136  *         RFAILED - failure
4137  *
4138  * ****************************************************************/
4139 uint8_t BuildBWPDlDedPdcchCfg(PdcchConfig *pdcchCfgDb, struct PDCCH_Config *pdcchCfg)
4140 {
4141    pdcchCfg->controlResourceSetToAddModList = NULLP;
4142    DU_ALLOC(pdcchCfg->controlResourceSetToAddModList, sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
4143    if(!pdcchCfg->controlResourceSetToAddModList)
4144    {
4145       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
4146       return RFAILED;
4147    }
4148
4149    if(BuildControlRSetToAddModList(pdcchCfgDb, pdcchCfg->controlResourceSetToAddModList) != ROK)
4150    {
4151       DU_LOG("\nERROR  --> F1AP : Failed in BuildControlRSetToAddModList()");
4152       return RFAILED;
4153    }
4154
4155    pdcchCfg->controlResourceSetToReleaseList = NULLP;
4156
4157    pdcchCfg->searchSpacesToAddModList = NULLP;
4158    DU_ALLOC(pdcchCfg->searchSpacesToAddModList, sizeof(struct PDCCH_Config__searchSpacesToAddModList));
4159    if(!pdcchCfg->searchSpacesToAddModList)
4160    {
4161       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
4162       return RFAILED;
4163    }
4164
4165    if(BuildSearchSpcToAddModList(pdcchCfgDb, pdcchCfg->searchSpacesToAddModList) != ROK)
4166    {
4167       DU_LOG("\nERROR  --> F1AP : Failed in BuildSearchSpcToAddModList()");
4168       return RFAILED;
4169    }
4170
4171    pdcchCfg->searchSpacesToReleaseList = NULLP;
4172    pdcchCfg->downlinkPreemption = NULLP;
4173    pdcchCfg->tpc_PUSCH = NULLP;
4174    pdcchCfg->tpc_PUCCH = NULLP;
4175    pdcchCfg->tpc_SRS = NULLP;
4176
4177    return ROK;
4178 }
4179
4180 /*******************************************************************
4181  *
4182  * @brief Builds DMRS DL PDSCH Mapping type A
4183  *
4184  * @details
4185  *
4186  *    Function : BuildDMRSDLPdschMapTypeA
4187  *
4188  *    Functionality: Builds DMRS DL PDSCH Mapping type A
4189  *
4190  * @params[in]
4191  * struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg
4192  * @return ROK     - success
4193  *         RFAILED - failure
4194  *
4195  * ****************************************************************/
4196 uint8_t BuildDMRSDLPdschMapTypeA(PdschConfig *pdschCfg, struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg)
4197 {
4198    dmrsDlCfg->present = PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup;
4199    dmrsDlCfg->choice.setup = NULLP;
4200    DU_ALLOC(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
4201    if(!dmrsDlCfg->choice.setup)
4202    {
4203       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
4204       return RFAILED;
4205    }
4206
4207    dmrsDlCfg->choice.setup->dmrs_Type = NULLP;
4208    dmrsDlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4209    DU_ALLOC(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4210    if(!dmrsDlCfg->choice.setup->dmrs_AdditionalPosition)
4211    {
4212       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
4213       return RFAILED;
4214    }
4215    if(pdschCfg == NULLP)
4216       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS;
4217    else
4218       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = pdschCfg->dmrsDlCfgForPdschMapTypeA.addPos;
4219
4220    dmrsDlCfg->choice.setup->maxLength = NULLP;
4221    dmrsDlCfg->choice.setup->scramblingID0 = NULLP;
4222    dmrsDlCfg->choice.setup->scramblingID1 = NULLP;
4223    dmrsDlCfg->choice.setup->phaseTrackingRS = NULLP;
4224
4225    return ROK;
4226 }
4227
4228 /*******************************************************************
4229  *
4230  * @brief Builds TCI states to add/modify list
4231  *
4232  * @details
4233  *
4234  *    Function : BuildTCIStatesToAddModList
4235  *
4236  *    Functionality:Builds TCI states to add/modify list
4237  *
4238  * @params[in] 
4239  * struct PDSCH_Config__tci_StatesToAddModList *tciStatesList
4240  *
4241  * @return ROK     - success
4242  *         RFAILED - failure
4243  *
4244  * ****************************************************************/
4245 uint8_t BuildTCIStatesToAddModList(struct PDSCH_Config__tci_StatesToAddModList *tciStatesList)
4246 {
4247    return ROK;
4248 }
4249
4250 /*******************************************************************
4251  *
4252  * @brief Builds PDSCH time domain allocation list
4253  *
4254  * @details
4255  *
4256  *    Function : BuildPdschTimeDomAllocList
4257  *
4258  *    Functionality: Builds PDSCH time domain allocation list
4259  *
4260  * @params[in] 
4261  * struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
4262  *
4263  * @return ROK     - success
4264  *         RFAILED - failure
4265  *
4266  * ****************************************************************/
4267 uint8_t BuildPdschTimeDomAllocList(PdschConfig *pdschCfg, struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
4268 {
4269    uint8_t idx;
4270    uint8_t elementCnt;
4271    struct PDSCH_TimeDomainResourceAllocation *timeDomAlloc;
4272
4273    timeDomAllocList->present = PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup;
4274
4275    timeDomAllocList->choice.setup = NULLP;
4276    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PDSCH_TimeDomainResourceAllocationList));
4277    if(!timeDomAllocList->choice.setup)
4278    {
4279       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4280       return RFAILED;
4281    }
4282
4283 if(pdschCfg == NULLP)
4284    elementCnt = 2;
4285 else
4286 elementCnt = pdschCfg->numTimeDomRsrcAlloc;
4287    timeDomAllocList->choice.setup->list.count = elementCnt;
4288    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(struct PDSCH_TimeDomainResourceAllocation *);
4289
4290    timeDomAllocList->choice.setup->list.array = NULLP;
4291    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4292    if(!timeDomAllocList->choice.setup->list.array)
4293    {
4294       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4295       return RFAILED;
4296    }
4297
4298    for(idx = 0; idx < elementCnt; idx++)
4299    {
4300       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4301       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], \
4302             sizeof(struct PDSCH_TimeDomainResourceAllocation));
4303       if(!timeDomAllocList->choice.setup->list.array[idx])
4304       {
4305          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4306          return RFAILED;
4307       }
4308    }
4309
4310    if(pdschCfg == NULLP)
4311    {
4312       idx = 0;
4313       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4314       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4315       if(!timeDomAlloc->k0)
4316       {
4317          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4318          return RFAILED;
4319       }
4320       *(timeDomAlloc->k0) = 0;
4321       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4322       timeDomAlloc->startSymbolAndLength = \
4323                                            calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4324
4325       idx++;
4326       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4327       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4328       if(!timeDomAlloc->k0)
4329       {
4330          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4331          return RFAILED;
4332       }
4333       *(timeDomAlloc->k0) = 1;
4334       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4335       timeDomAlloc->startSymbolAndLength = calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4336    }
4337    else
4338    {
4339       for(idx = 0; idx < elementCnt; idx++)
4340       {
4341          timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4342          if(pdschCfg->timeDomRsrcAllociList[idx].k0)
4343          {
4344             DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4345             if(!timeDomAlloc->k0)
4346             {
4347                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4348                return RFAILED;
4349             }
4350             *(timeDomAlloc->k0) = *(pdschCfg->timeDomRsrcAllociList[idx].k0);
4351          }
4352          timeDomAlloc->mappingType = pdschCfg->timeDomRsrcAllociList[idx].mappingType;
4353          timeDomAlloc->startSymbolAndLength = pdschCfg->timeDomRsrcAllociList[idx].startSymbolAndLength;
4354       }
4355    }
4356
4357    return ROK;
4358 }
4359
4360 /*******************************************************************
4361  *
4362  * @brief Builds PDSCH PRB Bundling type
4363  *
4364  * @details
4365  *
4366  *    Function : BuildPdschPrbBundlingType
4367  *
4368  *    Functionality: Builds PDSCH PRB Bundling type
4369  *
4370  * @params[in] 
4371  * struct PDSCH_Config__prb_BundlingType *prbBndlType
4372  *
4373  * @return ROK     - success
4374  *         RFAILED - failure
4375  *
4376  * ****************************************************************/
4377 uint8_t BuildPdschPrbBundlingType(PdschConfig *pdschCfg, struct PDSCH_Config__prb_BundlingType *prbBndlType)
4378 {
4379    if(pdschCfg == NULLP)
4380       prbBndlType->present = PDSCH_Config__prb_BundlingType_PR_staticBundling;
4381    else
4382       prbBndlType->present = pdschCfg->bundlingType;
4383
4384    prbBndlType->choice.staticBundling = NULLP;
4385    DU_ALLOC(prbBndlType->choice.staticBundling, \
4386          sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
4387    if(!prbBndlType->choice.staticBundling)
4388    {
4389       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschPrbBundlingType");
4390       return RFAILED;
4391    }
4392    prbBndlType->choice.staticBundling->bundleSize = NULLP;
4393
4394    return ROK;
4395 }
4396
4397 /*******************************************************************
4398  *
4399  * @brief Builds BWP DL dedicated PDSCH config 
4400  *
4401  * @details
4402  *
4403  *    Function : BuildBWPDlDedPdschCfg
4404  *
4405  *    Functionality: Builds BWP DL dedicated PDSCH config
4406  *
4407  * @params[in] struct PDSCH_Config *pdschCfg
4408  *
4409  * @return ROK     - success
4410  *         RFAILED - failure
4411  *
4412  * ****************************************************************/
4413 uint8_t BuildBWPDlDedPdschCfg(PdschConfig *pdschCfgDb, struct PDSCH_Config *pdschCfg)
4414 {
4415    pdschCfg->dataScramblingIdentityPDSCH = NULLP;
4416
4417    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA = NULLP;
4418    DU_ALLOC(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
4419    if(!pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
4420    {
4421       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4422       return RFAILED;
4423    }
4424
4425    if(BuildDMRSDLPdschMapTypeA(pdschCfgDb, pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA) != ROK)
4426    {
4427       return RFAILED;
4428    }
4429
4430    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeB = NULLP;
4431    pdschCfg->tci_StatesToAddModList = NULLP;
4432    pdschCfg->tci_StatesToReleaseList = NULLP;
4433    pdschCfg->vrb_ToPRB_Interleaver = NULLP;
4434 #if 0
4435    DU_ALLOC(pdschCfg->tci_StatesToAddModList, sizeof(struct PDSCH_Config__tci_StatesToAddModList));
4436    if(!pdschCfg->tci_StatesToAddModList)
4437    {
4438       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4439       return RFAILED;
4440    }
4441    if(BuildTCIStatesToAddModList(pdschCfg->tci_StatesToAddModList) != ROK)
4442    {
4443       return RFAILED;
4444    }
4445 #endif
4446
4447 if(pdschCfgDb == NULLP)
4448    pdschCfg->resourceAllocation = RES_ALLOC_TYPE;
4449 else
4450 pdschCfg->resourceAllocation = pdschCfgDb->resourceAllocType;
4451
4452    pdschCfg->pdsch_TimeDomainAllocationList = NULLP;
4453    DU_ALLOC(pdschCfg->pdsch_TimeDomainAllocationList, sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
4454    if(!pdschCfg->pdsch_TimeDomainAllocationList)
4455    {
4456       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4457       return RFAILED;
4458    }
4459    if(BuildPdschTimeDomAllocList(pdschCfgDb, pdschCfg->pdsch_TimeDomainAllocationList) != ROK)
4460    {
4461       return RFAILED;
4462    }
4463
4464    pdschCfg->pdsch_AggregationFactor = NULLP;
4465    pdschCfg->rateMatchPatternToAddModList = NULLP;
4466    pdschCfg->rateMatchPatternToReleaseList = NULLP;
4467    pdschCfg->rateMatchPatternGroup1 = NULLP;
4468    pdschCfg->rateMatchPatternGroup2 = NULLP;
4469    if(pdschCfgDb == NULLP)
4470       pdschCfg->rbg_Size = PDSCH_RBG_SIZE;
4471    else
4472       pdschCfg->rbg_Size = pdschCfgDb->rbgSize;
4473    pdschCfg->mcs_Table = NULLP;
4474
4475    pdschCfg->maxNrofCodeWordsScheduledByDCI = NULLP;
4476    DU_ALLOC(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
4477    if(!pdschCfg->maxNrofCodeWordsScheduledByDCI)
4478    {
4479       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4480       return RFAILED;
4481    }
4482    if(pdschCfgDb == NULLP)
4483       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = PDSCH_MAX_CODEWORD_SCH_BY_DCI;
4484    else
4485       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = pdschCfgDb->numCodeWordsSchByDci;
4486
4487    if(BuildPdschPrbBundlingType(pdschCfgDb, &pdschCfg->prb_BundlingType) != ROK)
4488    {
4489       return RFAILED;
4490    }
4491
4492    pdschCfg->zp_CSI_RS_ResourceToAddModList = NULLP;
4493    pdschCfg->zp_CSI_RS_ResourceToReleaseList = NULLP;
4494    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4495    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4496    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4497    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4498    pdschCfg->p_ZP_CSI_RS_ResourceSet = NULLP;
4499
4500    return ROK;
4501 }
4502
4503 /*******************************************************************
4504  *
4505  * @brief Builds intitial DL BWP
4506  * @details
4507  *
4508  *    Function : BuildInitialDlBWP 
4509  *
4510  *    Functionality: Builds intitial DL BWP in spCellCfgDed
4511  *
4512  * @params[in] BWP_DownlinkDedicated_t *dlBwp
4513  *
4514  * @return ROK     - success
4515  *         RFAILED - failure
4516  *
4517  * ****************************************************************/
4518 uint8_t BuildInitialDlBWP(InitialDlBwp *initiDlBwp, BWP_DownlinkDedicated_t *dlBwp)
4519 {
4520    PdcchConfig *pdcchCfg = NULLP;
4521    PdschConfig *pdschCfg = NULLP;
4522
4523    if(initiDlBwp)
4524    {
4525       if(initiDlBwp->pdcchPresent)
4526          pdcchCfg = &initiDlBwp->pdcchCfg;
4527       if(initiDlBwp->pdschPresent)
4528          pdschCfg = &initiDlBwp->pdschCfg;
4529    }
4530
4531    dlBwp->pdcch_Config = NULLP;
4532    DU_ALLOC(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
4533    if(!dlBwp->pdcch_Config)
4534    {
4535       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4536       return RFAILED;
4537    }
4538    dlBwp->pdcch_Config->present = BWP_DownlinkDedicated__pdcch_Config_PR_setup; 
4539
4540    dlBwp->pdcch_Config->choice.setup = NULLP;
4541    DU_ALLOC(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
4542    if(!dlBwp->pdcch_Config->choice.setup)
4543    {
4544       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4545       return RFAILED;
4546    }
4547    if(BuildBWPDlDedPdcchCfg(pdcchCfg, dlBwp->pdcch_Config->choice.setup) != ROK)
4548    {
4549       return RFAILED;
4550    }
4551
4552    dlBwp->pdsch_Config = NULLP;
4553    DU_ALLOC(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
4554    if(!dlBwp->pdsch_Config)
4555    {
4556       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4557       return RFAILED;
4558    }
4559    dlBwp->pdsch_Config->present = BWP_DownlinkDedicated__pdsch_Config_PR_setup;
4560
4561    dlBwp->pdsch_Config->choice.setup = NULLP;
4562    DU_ALLOC(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
4563    if(!dlBwp->pdsch_Config->choice.setup)
4564    {
4565       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4566       return RFAILED;
4567    }
4568
4569    if(BuildBWPDlDedPdschCfg(pdschCfg, dlBwp->pdsch_Config->choice.setup) != ROK)
4570    {
4571       return RFAILED;
4572    }
4573
4574    dlBwp->sps_Config = NULLP;
4575    dlBwp->radioLinkMonitoringConfig = NULLP; 
4576    return ROK;
4577 }
4578
4579 /*******************************************************************
4580  *
4581  * @brief Builds DMRS UL Pusch Mapping type A
4582  *
4583  * @details
4584  *
4585  *    Function : BuildDMRSULPuschMapTypeA
4586  *
4587  *    Functionality: Builds DMRS UL Pusch Mapping type A
4588  *
4589  * @params[in] 
4590  *    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg
4591  * @return ROK     - success
4592  *         RFAILED - failure
4593  *
4594  * ****************************************************************/
4595 uint8_t BuildDMRSULPuschMapTypeA(DmrsUlCfg *ulDmrsCfgDb, struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg)
4596 {
4597    dmrsUlCfg->present = PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup;
4598    dmrsUlCfg->choice.setup= NULLP;
4599    DU_ALLOC(dmrsUlCfg->choice.setup, sizeof(DMRS_UplinkConfig_t));
4600    if(!dmrsUlCfg->choice.setup)
4601    {
4602       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4603       return RFAILED;
4604    }
4605
4606    dmrsUlCfg->choice.setup->dmrs_Type = NULLP;
4607    dmrsUlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4608    DU_ALLOC(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4609    if(!dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
4610    {
4611       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4612       return RFAILED;
4613    }
4614    if(ulDmrsCfgDb == NULLP)
4615       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS; 
4616    else
4617       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = ulDmrsCfgDb->addPos;
4618
4619    dmrsUlCfg->choice.setup->phaseTrackingRS = NULLP;
4620    dmrsUlCfg->choice.setup->maxLength = NULLP;
4621    dmrsUlCfg->choice.setup->transformPrecodingDisabled = NULLP;
4622    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled, sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
4623    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled)
4624    {
4625       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4626       return RFAILED;
4627    }
4628
4629    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0 = NULLP;
4630    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
4631          sizeof(long));
4632    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0)
4633    {
4634       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4635       return RFAILED;
4636    }
4637    if(ulDmrsCfgDb == NULLP)
4638       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = SCRAMBLING_ID;
4639    else
4640       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = ulDmrsCfgDb->transPrecodDisabled.scramblingId0;
4641
4642    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID1 = NULLP;
4643    dmrsUlCfg->choice.setup->transformPrecodingEnabled = NULLP;
4644    return ROK;
4645 }
4646
4647 /*******************************************************************
4648  *
4649  * @brief Build PUSCH time domain allocation list
4650  *
4651  * @details
4652  *
4653  *    Function : BuildPuschTimeDomAllocList
4654  *
4655  *    Functionality: Build PUSCH time domain allocation list
4656  *
4657  * @params[in] 
4658  * struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList
4659  *
4660  * @return ROK     - success
4661  *         RFAILED - failure
4662  *
4663  * ****************************************************************/
4664 uint8_t BuildPuschTimeDomAllocList(PuschCfg *puschCfgDb, struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList)
4665 {
4666    uint8_t idx;
4667    uint8_t elementCnt;
4668    PUSCH_TimeDomainResourceAllocation_t  *timeDomAlloc;
4669
4670    timeDomAllocList->present = PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup;
4671    timeDomAllocList->choice.setup = NULLP;
4672    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PUSCH_TimeDomainResourceAllocationList));
4673    if(!timeDomAllocList->choice.setup)
4674    {
4675       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4676       return RFAILED;
4677    }
4678
4679    if(puschCfgDb == NULLP)
4680       elementCnt = 2;
4681    else
4682       elementCnt = puschCfgDb->numTimeDomRsrcAlloc;
4683
4684    timeDomAllocList->choice.setup->list.count = elementCnt;
4685    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(PUSCH_TimeDomainResourceAllocation_t *);
4686    timeDomAllocList->choice.setup->list.array = NULLP;
4687    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4688    if(!timeDomAllocList->choice.setup->list.array)
4689    {
4690       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4691       return RFAILED;
4692    }
4693
4694    for(idx = 0; idx < elementCnt; idx++)
4695    {
4696       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4697       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], sizeof(PUSCH_TimeDomainResourceAllocation_t));
4698       if(!timeDomAllocList->choice.setup->list.array[idx])
4699       {
4700          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4701          return RFAILED;
4702       }
4703    }
4704
4705    for(idx = 0; idx < elementCnt; idx++)
4706    {
4707       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4708       DU_ALLOC(timeDomAlloc->k2, sizeof(long));
4709       if(!timeDomAlloc->k2)
4710       {
4711          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4712          return RFAILED;
4713       }
4714       if(puschCfgDb == NULLP)
4715       {
4716          if(idx == 0)
4717             *(timeDomAlloc->k2) = PUSCH_K2_CFG1;
4718          else if(idx == 1)
4719             *(timeDomAlloc->k2) = PUSCH_K2_CFG2;
4720
4721          timeDomAlloc->mappingType = PUSCH_MAPPING_TYPE_A;
4722          timeDomAlloc->startSymbolAndLength = calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
4723       }
4724       else
4725       {
4726          *(timeDomAlloc->k2) = puschCfgDb->timeDomRsrcAllocList[idx].k2;
4727          timeDomAlloc->mappingType = puschCfgDb->timeDomRsrcAllocList[idx].mappingType;
4728          timeDomAlloc->startSymbolAndLength = puschCfgDb->timeDomRsrcAllocList[idx].startSymbolAndLength;
4729       }
4730    }
4731
4732    return ROK;
4733 }
4734
4735 /*******************************************************************
4736  *
4737  * @brief Builds BWP UL dedicated PUSCH Config
4738  *
4739  * @details
4740  *
4741  *    Function : BuildBWPUlDedPuschCfg
4742  *
4743  *    Functionality:
4744  *      Builds BWP UL dedicated PUSCH Config
4745  *
4746  * @params[in] : PUSCH_Config_t *puschCfg
4747  *    
4748  * @return ROK     - success
4749  *         RFAILED - failure
4750  *
4751  * ****************************************************************/
4752 uint8_t BuildBWPUlDedPuschCfg(PuschCfg *puschCfgDb, PUSCH_Config_t *puschCfg)
4753 {
4754    DmrsUlCfg *ulDmrsCfg = NULLP;
4755    
4756    if(puschCfgDb)
4757       ulDmrsCfg = &puschCfgDb->dmrsUlCfgForPuschMapTypeA;
4758
4759    puschCfg->dataScramblingIdentityPUSCH = NULLP;
4760    DU_ALLOC(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
4761    if(!puschCfg->dataScramblingIdentityPUSCH)
4762    {
4763       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4764       return RFAILED;
4765    }
4766    if(puschCfgDb == NULLP)
4767       *(puschCfg->dataScramblingIdentityPUSCH) = SCRAMBLING_ID;
4768    else
4769       *(puschCfg->dataScramblingIdentityPUSCH) = puschCfgDb->dataScramblingId;
4770
4771    puschCfg->txConfig = NULLP;
4772    puschCfg->dmrs_UplinkForPUSCH_MappingTypeA = NULLP;
4773    DU_ALLOC(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
4774    if(!puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
4775    {
4776       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4777       return RFAILED;
4778    }
4779
4780    if(BuildDMRSULPuschMapTypeA(ulDmrsCfg, puschCfg->dmrs_UplinkForPUSCH_MappingTypeA) != ROK)
4781    {
4782       return RFAILED;
4783    }
4784
4785    puschCfg->dmrs_UplinkForPUSCH_MappingTypeB = NULLP;
4786    puschCfg->pusch_PowerControl = NULLP;
4787    puschCfg->frequencyHopping = NULLP;
4788    puschCfg->frequencyHoppingOffsetLists = NULLP;
4789
4790    if(puschCfgDb == NULLP)
4791       puschCfg->resourceAllocation = RES_ALLOC_TYPE;
4792    else
4793       puschCfg->resourceAllocation = puschCfgDb->resourceAllocType;
4794
4795    puschCfg->pusch_TimeDomainAllocationList = NULLP;
4796    DU_ALLOC(puschCfg->pusch_TimeDomainAllocationList, sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
4797    if(!puschCfg->pusch_TimeDomainAllocationList)
4798    {
4799       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4800       return RFAILED;
4801    }
4802
4803    if(BuildPuschTimeDomAllocList(puschCfgDb, puschCfg->pusch_TimeDomainAllocationList) != ROK)
4804    {
4805       return RFAILED;
4806    }
4807
4808    puschCfg->pusch_AggregationFactor = NULLP;
4809    puschCfg->mcs_Table = NULLP;
4810    puschCfg->mcs_TableTransformPrecoder = NULLP;
4811    puschCfg->transformPrecoder = NULLP;
4812    DU_ALLOC(puschCfg->transformPrecoder, sizeof(long));
4813    if(!puschCfg->transformPrecoder)
4814    {
4815       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4816       return RFAILED;
4817    }
4818    if(puschCfgDb == NULLP)
4819       *(puschCfg->transformPrecoder) = PUSCH_TRANSFORM_PRECODER;
4820    else
4821       *(puschCfg->transformPrecoder) = puschCfgDb->transformPrecoder;
4822
4823    puschCfg->codebookSubset = NULLP;
4824    puschCfg->maxRank = NULLP;
4825    puschCfg->rbg_Size = NULLP;
4826    puschCfg->uci_OnPUSCH = NULLP;
4827    puschCfg->tp_pi2BPSK = NULLP;
4828
4829    return ROK;
4830 }
4831
4832 /*******************************************************************
4833  *
4834  * @brief Builds PUCCH resource set add/modify list
4835  *
4836  * @details
4837  *
4838  *    Function : BuildPucchRsrcSetAddModList
4839  *
4840  *    Functionality:
4841  *      Builds PUCCH resource set add/modify list
4842  *
4843  * @params[in] : PucchResrcSetCfg *rsrcSetCfgDb
4844  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4845  *
4846  * @return ROK     - success
4847  *         RFAILED - failure
4848  *
4849  * ****************************************************************/
4850 uint8_t BuildPucchRsrcSetAddModList(PucchResrcSetCfg *rsrcSetCfgDb, \
4851    struct PUCCH_Config__resourceSetToAddModList *resourceSetToAddModList)
4852 {
4853    uint8_t elementCnt = 0, rsrcSetIdx = 0, rsrcIdx = 0;
4854    PUCCH_ResourceSet_t *rsrcSet = NULLP;
4855
4856    if(rsrcSetCfgDb == NULLP)
4857       elementCnt = 1;
4858    else
4859       elementCnt = rsrcSetCfgDb->resrcSetToAddModListCount;
4860
4861    resourceSetToAddModList->list.count = elementCnt;
4862    resourceSetToAddModList->list.size = elementCnt * sizeof(PUCCH_ResourceSet_t *);
4863    DU_ALLOC(resourceSetToAddModList->list.array, resourceSetToAddModList->list.size);
4864    if(resourceSetToAddModList->list.array == NULLP)
4865    {
4866       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4867       return RFAILED;
4868    }
4869    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4870    {
4871       DU_ALLOC(resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
4872       if(resourceSetToAddModList->list.array[rsrcSetIdx] == NULLP)
4873       {
4874          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4875          return RFAILED;
4876       }
4877    }
4878
4879    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4880    {
4881       rsrcSet = resourceSetToAddModList->list.array[rsrcSetIdx];
4882
4883       /* Resource set Id */
4884       if(rsrcSetCfgDb == NULLP)
4885          rsrcSet->pucch_ResourceSetId = 1;
4886       else
4887          rsrcSet->pucch_ResourceSetId = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcSetId;
4888  
4889       /* Resource list of a resource set */
4890       if(rsrcSetCfgDb == NULLP)
4891          elementCnt = 1;
4892       else
4893          elementCnt = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcListCount;
4894       rsrcSet->resourceList.list.count = elementCnt;
4895       rsrcSet->resourceList.list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
4896       DU_ALLOC(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
4897       if(rsrcSet->resourceList.list.array == NULLP)
4898       {
4899          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4900          return RFAILED;
4901       }
4902
4903       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4904       {
4905          DU_ALLOC(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
4906          if(rsrcSet->resourceList.list.array[rsrcIdx] == NULLP)
4907          {
4908             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4909             return RFAILED;
4910          }
4911       }
4912       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4913       {
4914          if(rsrcSetCfgDb == NULLP)
4915             *(rsrcSet->resourceList.list.array[rsrcIdx]) = 1;
4916          else
4917             *(rsrcSet->resourceList.list.array[rsrcIdx]) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcList[rsrcIdx];
4918       }
4919
4920       /* Max payload size (minus 1) in a Resource set */
4921       rsrcSet->maxPayloadMinus1 = NULLP;
4922       if(rsrcSetCfgDb && rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize)
4923       {
4924          DU_ALLOC(rsrcSet->maxPayloadMinus1, sizeof(long));
4925          if(rsrcSet->maxPayloadMinus1 == NULLP)
4926          {
4927             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4928             return RFAILED;
4929          }
4930          *(rsrcSet->maxPayloadMinus1) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize;
4931       }
4932    }
4933    return ROK;
4934 }
4935
4936 /*******************************************************************
4937  *
4938  * @brief Builds PUCCH resource add/modify list
4939  *
4940  * @details
4941  *
4942  *    Function : BuildPucchRsrcAdddModList
4943  *
4944  *    Functionality:
4945  *      Builds PUCCH resource add/modify list
4946  *
4947  * @params[in] : PucchResrcCfg *rsrcSetCfgDb
4948  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4949  *
4950  * @return ROK     - success
4951  *         RFAILED - failure
4952  *
4953  * ****************************************************************/
4954 uint8_t BuildPucchRsrcAddModList(PucchResrcCfg *rsrcCfgDb, struct PUCCH_Config__resourceToAddModList  *resourceToAddModList)
4955 {
4956    uint8_t elementCnt = 0, rsrcIdx = 0;
4957    PUCCH_Resource_t *rsrc = NULLP;
4958
4959    if(rsrcCfgDb == NULLP)
4960       elementCnt = 1;
4961    else
4962       elementCnt = rsrcCfgDb->resrcToAddModListCount;
4963    resourceToAddModList->list.count = elementCnt;
4964    resourceToAddModList->list.size = elementCnt * sizeof(PUCCH_Resource_t *);
4965    DU_ALLOC(resourceToAddModList->list.array, resourceToAddModList->list.size);
4966    if(resourceToAddModList->list.array == NULLP)
4967    {
4968       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4969       return RFAILED;
4970    }
4971    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4972    {
4973       DU_ALLOC(resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
4974       if(resourceToAddModList->list.array[rsrcIdx] == NULLP)
4975       {
4976          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4977          return RFAILED;
4978       }
4979    }
4980
4981    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4982    {
4983       rsrc = resourceToAddModList->list.array[rsrcIdx];
4984
4985       if(rsrcCfgDb == NULLP)
4986       {
4987          rsrc->pucch_ResourceId = 1;
4988          rsrc->startingPRB = 0;
4989          rsrc->format.present = PUCCH_Resource__format_PR_format1; 
4990          DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4991          if(rsrc->format.choice.format1 == NULLP)
4992          {
4993             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4994             return RFAILED;
4995          }  
4996          rsrc->format.choice.format1->initialCyclicShift = 0;
4997          rsrc->format.choice.format1->nrofSymbols = 4;
4998          rsrc->format.choice.format1->startingSymbolIndex = 0;
4999          rsrc->format.choice.format1->timeDomainOCC = 0;
5000       }
5001       else
5002       {
5003          rsrc->pucch_ResourceId = rsrcCfgDb->resrcToAddModList[rsrcIdx].resrcId;
5004          rsrc->startingPRB = rsrcCfgDb->resrcToAddModList[rsrcIdx].startPrb;
5005          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop)
5006          {
5007             DU_ALLOC(rsrc->intraSlotFrequencyHopping, sizeof(long));
5008             if(rsrc->intraSlotFrequencyHopping == NULLP)
5009             {
5010                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5011                return RFAILED;
5012             }
5013             *(rsrc->intraSlotFrequencyHopping) = rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop;
5014          }
5015          else
5016             rsrc->intraSlotFrequencyHopping = NULLP;
5017
5018          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop)
5019          {
5020             DU_ALLOC(rsrc->secondHopPRB, sizeof(PRB_Id_t));
5021             if(rsrc->secondHopPRB == NULLP)
5022             {
5023                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5024                return RFAILED;
5025             }
5026             *(rsrc->secondHopPRB) = rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop;
5027          }
5028          else
5029             rsrc->secondHopPRB = NULLP;
5030          rsrc->format.present = covertPucchFormatIntEnumToRrcEnum(rsrcCfgDb->resrcToAddModList[rsrcIdx].pucchFormat); 
5031
5032          switch(rsrc->format.present)
5033          {
5034             case PUCCH_Resource__format_PR_NOTHING:
5035                break;
5036             case PUCCH_Resource__format_PR_format0:
5037                {
5038                   DU_ALLOC(rsrc->format.choice.format0, sizeof(PUCCH_format0_t));
5039                   if(rsrc->format.choice.format0 == NULLP)
5040                   {
5041                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5042                      return RFAILED;
5043                   }
5044                   rsrc->format.choice.format0->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->initialCyclicShift;
5045                   rsrc->format.choice.format0->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->numSymbols;
5046                   rsrc->format.choice.format0->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->startSymbolIdx;
5047                   break;
5048                }
5049
5050             case PUCCH_Resource__format_PR_format1:
5051                {
5052                   DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
5053                   if(rsrc->format.choice.format1 == NULLP)
5054                   {
5055                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5056                      return RFAILED;
5057                   }  
5058                   rsrc->format.choice.format1->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->initialCyclicShift;
5059                   rsrc->format.choice.format1->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->numSymbols;
5060                   rsrc->format.choice.format1->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->startSymbolIdx;
5061                   rsrc->format.choice.format1->timeDomainOCC = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->timeDomOCC;
5062                   break;
5063                }
5064
5065             case PUCCH_Resource__format_PR_format2:
5066                {
5067                   DU_ALLOC(rsrc->format.choice.format2, sizeof(PUCCH_format2_t));
5068                   if(rsrc->format.choice.format2 == NULLP)
5069                   {
5070                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5071                      return RFAILED;
5072                   } 
5073                   rsrc->format.choice.format2->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numPrbs;
5074                   rsrc->format.choice.format2->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numSymbols;
5075                   rsrc->format.choice.format2->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->startSymbolIdx;
5076                   break;
5077                }
5078
5079             case PUCCH_Resource__format_PR_format3:
5080                {
5081                   DU_ALLOC(rsrc->format.choice.format3, sizeof(PUCCH_format3_t));
5082                   if(rsrc->format.choice.format3 == NULLP)
5083                   {
5084                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5085                      return RFAILED;
5086                   }
5087                   rsrc->format.choice.format3->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numPrbs;
5088                   rsrc->format.choice.format3->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numSymbols;
5089                   rsrc->format.choice.format3->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->startSymbolIdx;
5090                   break;
5091                }
5092
5093             case PUCCH_Resource__format_PR_format4:
5094                {
5095                   DU_ALLOC(rsrc->format.choice.format4, sizeof(PUCCH_format4_t));
5096                   if(rsrc->format.choice.format4 == NULLP)
5097                   {
5098                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5099                      return RFAILED;
5100                   }
5101                   rsrc->format.choice.format4->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->numSymbols;
5102                   rsrc->format.choice.format4->occ_Length = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occLen;
5103                   rsrc->format.choice.format4->occ_Index = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occIdx;
5104                   rsrc->format.choice.format4->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->startSymbolIdx;
5105                   break;
5106                }
5107          }
5108       }
5109    }
5110    return ROK;
5111 }
5112
5113 /*******************************************************************
5114  *
5115  * @brief Builds PUCCH format  config
5116  *
5117  * @details
5118  *
5119  *    Function : BuildPucchFormat
5120  *
5121  *    Functionality: Builds PUCCH format  config
5122  *
5123  * @params[in] : PucchFormatCfg *formatDb
5124  *               PUCCH_FormatConfig_t *format
5125  *
5126  * @return ROK     - success
5127  *         RFAILED - failure
5128  *
5129  * ****************************************************************/
5130 uint8_t BuildPucchFormat(PucchFormatCfg *formatDb, PUCCH_FormatConfig_t *format)
5131 {
5132    /* Inter Slot Fequency hopping */
5133    format->interslotFrequencyHopping = NULLP;
5134    if((formatDb != NULLP) && (formatDb->interSlotFreqHop == true))
5135    {
5136       DU_ALLOC(format->interslotFrequencyHopping, sizeof(long));
5137       if(format->interslotFrequencyHopping)
5138       {
5139          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5140          return RFAILED;
5141       }
5142       *(format->interslotFrequencyHopping) = PUCCH_FormatConfig__interslotFrequencyHopping_enabled;
5143    }
5144
5145    /* Additional DMRS */
5146    format->additionalDMRS = NULLP;
5147    if((formatDb != NULLP) && (formatDb->addDmrs == true))
5148    {
5149       DU_ALLOC(format->additionalDMRS, sizeof(long));
5150       if(format->additionalDMRS)
5151       {
5152          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5153          return RFAILED;
5154       }
5155       *(format->additionalDMRS) = PUCCH_FormatConfig__additionalDMRS_true;
5156    }
5157
5158     /* Maximum code rate */
5159    format->maxCodeRate = NULLP;
5160    if((formatDb != NULLP) && (formatDb->maxCodeRate != 0))
5161    {
5162       DU_ALLOC(format->maxCodeRate, sizeof(long));
5163       if(format->maxCodeRate)
5164       {
5165          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5166          return RFAILED;
5167       }  
5168       *(format->maxCodeRate) = formatDb->maxCodeRate;
5169    }
5170  
5171    /* Number of slots */
5172    format->nrofSlots = NULLP;
5173    if((formatDb == NULLP) || ((formatDb != NULLP) && (formatDb->numSlots != 0)))
5174    {
5175       DU_ALLOC(format->nrofSlots, sizeof(long));
5176       if(format->nrofSlots == NULLP)
5177       {
5178          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5179          return RFAILED;
5180       }
5181       if(formatDb == NULLP)
5182          *(format->nrofSlots) = PUCCH_FormatConfig__nrofSlots_n4;
5183       else
5184          *(format->nrofSlots) = formatDb->numSlots;
5185    }
5186
5187    /* Pi2BPSK*/
5188    format->pi2BPSK = NULLP;
5189    if((formatDb != NULLP) && (formatDb->pi2BPSK == true))
5190    {
5191       DU_ALLOC(format->pi2BPSK, sizeof(long));
5192       if(format->pi2BPSK)
5193       {     
5194          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5195          return RFAILED;
5196       }     
5197       *(format->pi2BPSK) = PUCCH_FormatConfig__pi2BPSK_enabled;
5198    }
5199
5200    /* Simultaneous HARQ ACK and CSI */
5201    format->simultaneousHARQ_ACK_CSI = NULLP;
5202    if((formatDb != NULLP) && (formatDb->harqAckCSI == true))
5203    {
5204       DU_ALLOC(format->simultaneousHARQ_ACK_CSI, sizeof(long));
5205       if(format->simultaneousHARQ_ACK_CSI)
5206       {     
5207          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5208          return RFAILED;
5209       }     
5210       *(format->simultaneousHARQ_ACK_CSI) = PUCCH_FormatConfig__simultaneousHARQ_ACK_CSI_true;
5211    }
5212
5213    return ROK;
5214 }
5215
5216
5217 /*******************************************************************
5218  *
5219  * @brief Builds PUCCH scheduling request list
5220  *
5221  * @details
5222  *
5223  *    Function : BuildPucchSchReqAddModList
5224  *
5225  *    Functionality:
5226  *      Builds PUCCH scheduling request list
5227  *
5228  * @params[in] : PucchSchedReqCfg *schReqDb
5229  *               struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList
5230  *
5231  * @return ROK     - success
5232  *         RFAILED - failure
5233  *
5234  * ****************************************************************/
5235 uint8_t BuildPucchSchReqAddModList(PucchSchedReqCfg *schReqDb, \
5236    struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList)
5237 {
5238    uint8_t elementCnt = 0, schReqIdx = 0;
5239    SchedulingRequestResourceConfig_t *schReqRsrc;
5240
5241    elementCnt = schReqDb->schedAddModListCount;
5242    schReqRsrcToAddModList->list.count = elementCnt;
5243    schReqRsrcToAddModList->list.size = elementCnt *sizeof(struct SchedulingRequestResourceConfig *);
5244
5245    schReqRsrcToAddModList->list.array = NULLP;
5246    DU_ALLOC(schReqRsrcToAddModList->list.array, schReqRsrcToAddModList->list.size);
5247    if(schReqRsrcToAddModList->list.array == NULLP)
5248    {
5249       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5250       return RFAILED;
5251    }
5252
5253    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
5254    {
5255       DU_ALLOC(schReqRsrcToAddModList->list.array[schReqIdx], schReqRsrcToAddModList->list.size);
5256       if(schReqRsrcToAddModList->list.array[schReqIdx] == NULLP)
5257       {
5258          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5259          return RFAILED;
5260       }
5261    }
5262
5263    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
5264    {
5265       schReqRsrc = schReqRsrcToAddModList->list.array[schReqIdx];
5266       schReqRsrc->schedulingRequestResourceId = schReqDb->schedAddModList[schReqIdx].resrcId;
5267       schReqRsrc->schedulingRequestID = schReqDb->schedAddModList[schReqIdx].requestId;
5268
5269       if(schReqDb->schedAddModList[schReqIdx].periodicity)
5270       {
5271          schReqRsrc->periodicityAndOffset = NULLP;
5272          DU_ALLOC(schReqRsrc->periodicityAndOffset, sizeof(struct SchedulingRequestResourceConfig__periodicityAndOffset));
5273          if(schReqRsrc->periodicityAndOffset == NULLP)
5274          {
5275             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5276             return RFAILED;
5277          }
5278
5279          schReqRsrc->periodicityAndOffset->present = schReqDb->schedAddModList[schReqIdx].periodicity;
5280          switch(schReqRsrc->periodicityAndOffset->present)
5281          {
5282             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_NOTHING:
5283                break;
5284             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
5285                schReqRsrc->periodicityAndOffset->choice.sym2 = schReqDb->schedAddModList[schReqIdx].offset;
5286                break;
5287             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
5288                schReqRsrc->periodicityAndOffset->choice.sym6or7 = schReqDb->schedAddModList[schReqIdx].offset;
5289                break;
5290             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
5291                schReqRsrc->periodicityAndOffset->choice.sl1 = schReqDb->schedAddModList[schReqIdx].offset;
5292                break;
5293             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
5294                schReqRsrc->periodicityAndOffset->choice.sl2 = schReqDb->schedAddModList[schReqIdx].offset;
5295                break;
5296             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
5297                schReqRsrc->periodicityAndOffset->choice.sl4 = schReqDb->schedAddModList[schReqIdx].offset;
5298                break;
5299             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
5300                schReqRsrc->periodicityAndOffset->choice.sl5 = schReqDb->schedAddModList[schReqIdx].offset;
5301                break;
5302             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
5303                schReqRsrc->periodicityAndOffset->choice.sl8 = schReqDb->schedAddModList[schReqIdx].offset;
5304                break;
5305             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
5306                schReqRsrc->periodicityAndOffset->choice.sl10 = schReqDb->schedAddModList[schReqIdx].offset;
5307                break;
5308             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
5309                schReqRsrc->periodicityAndOffset->choice.sl16 = schReqDb->schedAddModList[schReqIdx].offset;
5310                break;
5311             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
5312                schReqRsrc->periodicityAndOffset->choice.sl20 = schReqDb->schedAddModList[schReqIdx].offset;
5313                break;
5314             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
5315                schReqRsrc->periodicityAndOffset->choice.sl40 = schReqDb->schedAddModList[schReqIdx].offset;
5316                break;
5317             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
5318                schReqRsrc->periodicityAndOffset->choice.sl80 = schReqDb->schedAddModList[schReqIdx].offset;
5319                break;
5320             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
5321                schReqRsrc->periodicityAndOffset->choice.sl160 = schReqDb->schedAddModList[schReqIdx].offset;
5322                break;
5323             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
5324                schReqRsrc->periodicityAndOffset->choice.sl320 = schReqDb->schedAddModList[schReqIdx].offset;
5325                break;
5326             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
5327                schReqRsrc->periodicityAndOffset->choice.sl640 = schReqDb->schedAddModList[schReqIdx].offset;
5328                break;
5329          }
5330       }
5331
5332       if(schReqDb->schedAddModList[schReqIdx].resrc)
5333       {
5334          schReqRsrc->resource = NULLP;
5335          DU_ALLOC(schReqRsrc->resource, sizeof(PUCCH_ResourceId_t));
5336          if(schReqRsrc->resource == NULLP)
5337          {
5338             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5339             return RFAILED;
5340          }
5341          *(schReqRsrc->resource) = schReqDb->schedAddModList[schReqIdx].resrc;
5342
5343       }
5344    }
5345    return ROK;
5346 }
5347
5348 /*******************************************************************
5349  *
5350  * @brief Builds PUCCH multi csi resource list
5351  *
5352  * @details
5353  *
5354  *    Function : BuildPucchMultiCsiRsrcList
5355  *
5356  *    Functionality:
5357  *      Builds PUCCH multi csi resource list
5358  *
5359  * @params[in] : PucchMultiCsiCfg *multiCsiDb
5360  *               struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList
5361  *
5362  * @return ROK     - success
5363  *         RFAILED - failure
5364  *
5365  * ****************************************************************/
5366 uint8_t BuildPucchMultiCsiRsrcList(PucchMultiCsiCfg *multiCsiDb, struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList)
5367 {
5368    uint8_t elementCnt = 0, rsrcIdx = 0;
5369
5370    elementCnt = multiCsiDb->multiCsiResrcListCount;
5371    multiCsiRsrcList->list.count = elementCnt;
5372    multiCsiRsrcList->list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
5373    multiCsiRsrcList->list.array = NULLP;
5374    DU_ALLOC(multiCsiRsrcList->list.array, multiCsiRsrcList->list.size);
5375    if(multiCsiRsrcList->list.array == NULLP)
5376    {
5377       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5378       return RFAILED;
5379    }
5380
5381    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5382    {
5383       DU_ALLOC(multiCsiRsrcList->list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
5384       if(multiCsiRsrcList->list.array[rsrcIdx] == NULLP)
5385       {
5386          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5387          return RFAILED;
5388       }
5389    }
5390
5391    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5392    {
5393       *(multiCsiRsrcList->list.array[rsrcIdx]) = multiCsiDb->multiCsiResrcList[rsrcIdx];
5394    }
5395    return ROK;
5396 }
5397
5398 /*******************************************************************
5399  *
5400  * @brief Builds DL data -to- Ul Ack list
5401  *
5402  * @details
5403  *
5404  *    Function : BuildDlDataToUlAckList
5405  *
5406  *    Functionality: Builds DL data -to- Ul Ack list
5407  *
5408  * @params[in] : PucchDlDataToUlAck *dlDataToUlAckDb
5409  *               struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList
5410  *
5411  * @return ROK     - success
5412  *         RFAILED - failure
5413  *
5414  * ****************************************************************/
5415 uint8_t BuildDlDataToUlAckList(PucchDlDataToUlAck *dlDataToUlAckDb, struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList)
5416 {
5417    uint8_t elementCnt = 0, arrIdx = 0;
5418
5419    if(dlDataToUlAckDb == NULLP)
5420       elementCnt = 2;
5421    else
5422       elementCnt = dlDataToUlAckDb->dlDataToUlAckListCount;
5423
5424    dlDataToUlACKList->list.count = elementCnt;
5425    dlDataToUlACKList->list.size = elementCnt * sizeof(long *);
5426    DU_ALLOC(dlDataToUlACKList->list.array, dlDataToUlACKList->list.size);
5427    if(dlDataToUlACKList->list.array == NULLP)
5428    {
5429       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5430       return RFAILED;
5431    }   
5432
5433    for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5434    {
5435       DU_ALLOC(dlDataToUlACKList->list.array[arrIdx], sizeof(long));
5436       if(dlDataToUlACKList->list.array[arrIdx] == NULLP)
5437       {
5438          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5439          return RFAILED;
5440       }   
5441    }
5442
5443    if(dlDataToUlAckDb == NULLP)
5444    {
5445       arrIdx = 0;
5446       *(dlDataToUlACKList->list.array[arrIdx++]) = 1;
5447       *(dlDataToUlACKList->list.array[arrIdx]) = 2;
5448    }
5449    else
5450    {
5451       for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5452       {
5453          *(dlDataToUlACKList->list.array[arrIdx]) = dlDataToUlAckDb->dlDataToUlAckList[arrIdx];
5454       }
5455    }
5456    return ROK;
5457 }
5458
5459 /*******************************************************************
5460  *
5461  * @brief Builds BWP UL dedicated PUCCH Config
5462  *
5463  * @details
5464  *
5465  *    Function : BuildBWPUlDedPucchCfg
5466  *
5467  *    Functionality:
5468  *      Builds BWP UL dedicated PUCCH Config
5469  *
5470  * @params[in] : PUCCH_Config_t *pucchCfg
5471  *
5472  * @return ROK     - success
5473  *         RFAILED - failure
5474  *
5475  * ****************************************************************/
5476 uint8_t BuildBWPUlDedPucchCfg(PucchCfg *pucchCfgDb, PUCCH_Config_t *pucchCfg)
5477 {
5478    PucchResrcSetCfg *rsrcSetCfgDb = NULLP;
5479    PucchResrcCfg *rsrcCfgDb = NULLP;
5480    PucchFormatCfg *format1Db = NULLP;
5481    PucchFormatCfg *format2Db = NULLP;
5482    PucchFormatCfg *format3Db = NULLP;
5483    PucchFormatCfg *format4Db = NULLP;
5484    PucchSchedReqCfg *schReqDb = NULLP;   
5485    PucchMultiCsiCfg  *multiCsiDb = NULLP;
5486    PucchDlDataToUlAck *dlDataToUlAckDb = NULLP;
5487
5488    if(pucchCfgDb)
5489    {
5490       rsrcSetCfgDb = pucchCfgDb->resrcSet;
5491       rsrcCfgDb = pucchCfgDb->resrc;
5492       format1Db = pucchCfgDb->format1;
5493       format2Db = pucchCfgDb->format2;
5494       format3Db = pucchCfgDb->format3;
5495       format4Db = pucchCfgDb->format4;
5496       schReqDb = pucchCfgDb->schedReq;
5497       multiCsiDb = pucchCfgDb->multiCsiCfg;
5498       dlDataToUlAckDb = pucchCfgDb->dlDataToUlAck;
5499    }
5500
5501    /* RESOURCE SET */
5502    DU_ALLOC(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
5503    if(pucchCfg->resourceSetToAddModList == NULL)
5504    {
5505       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5506       return RFAILED;
5507    }
5508
5509    if(BuildPucchRsrcSetAddModList(rsrcSetCfgDb, pucchCfg->resourceSetToAddModList) != ROK)
5510    {
5511       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5512       return RFAILED;
5513    }
5514
5515    /* PUCCH RESOURCE */
5516    DU_ALLOC(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
5517    if(pucchCfg->resourceToAddModList == NULLP)
5518    {
5519       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5520       return RFAILED;
5521    }
5522
5523    if(BuildPucchRsrcAddModList(rsrcCfgDb, pucchCfg->resourceToAddModList) != ROK)
5524    {
5525       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5526       return RFAILED;
5527    }
5528
5529    /* PUCCH Format 1 */
5530    DU_ALLOC(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
5531    if(pucchCfg->format1 == NULLP)
5532    {
5533       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5534       return RFAILED;
5535    }
5536    
5537    pucchCfg->format1->present = PUCCH_Config__format1_PR_setup;
5538    DU_ALLOC(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
5539    if(pucchCfg->format1->choice.setup == NULLP)
5540    {
5541       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5542       return RFAILED;
5543    }
5544
5545    if(BuildPucchFormat(format1Db, pucchCfg->format1->choice.setup) != ROK)
5546    {
5547       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5548       return RFAILED;
5549    }
5550
5551    /* PUCCH Format 2 */
5552    if(format2Db)
5553    {
5554       DU_ALLOC(pucchCfg->format2, sizeof(struct PUCCH_Config__format2));
5555       if(pucchCfg->format2 == NULLP)
5556       {
5557          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5558          return RFAILED;
5559       }
5560
5561       pucchCfg->format2->present = PUCCH_Config__format2_PR_setup;
5562       DU_ALLOC(pucchCfg->format2->choice.setup, sizeof(PUCCH_FormatConfig_t));
5563       if(pucchCfg->format2->choice.setup == NULLP)
5564       {
5565          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5566          return RFAILED;
5567       }
5568
5569       if(BuildPucchFormat(format2Db, pucchCfg->format2->choice.setup) != ROK)
5570       {
5571          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5572          return RFAILED;
5573       }
5574    }
5575
5576    /* PUCCH Format 3 */
5577    if(format3Db)
5578    {
5579       DU_ALLOC(pucchCfg->format3, sizeof(struct PUCCH_Config__format3));
5580       if(pucchCfg->format3 == NULLP)
5581       {
5582          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5583          return RFAILED;
5584       }
5585
5586       pucchCfg->format3->present = PUCCH_Config__format3_PR_setup;
5587       DU_ALLOC(pucchCfg->format3->choice.setup, sizeof(PUCCH_FormatConfig_t));
5588       if(pucchCfg->format3->choice.setup == NULLP)
5589       {
5590          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5591          return RFAILED;
5592       }
5593
5594       if(BuildPucchFormat(format3Db, pucchCfg->format3->choice.setup) != ROK)
5595       {
5596          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5597          return RFAILED;
5598       }
5599    }
5600
5601    /* PUCCH Format 4 */
5602    if(format4Db)
5603    {
5604       DU_ALLOC(pucchCfg->format4, sizeof(struct PUCCH_Config__format4));
5605       if(pucchCfg->format4 == NULLP)
5606       {
5607          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5608          return RFAILED;
5609       }
5610
5611       pucchCfg->format4->present = PUCCH_Config__format4_PR_setup;
5612       DU_ALLOC(pucchCfg->format4->choice.setup, sizeof(PUCCH_FormatConfig_t));
5613       if(pucchCfg->format4->choice.setup == NULLP)
5614       {
5615          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5616          return RFAILED;
5617       }
5618
5619       if(BuildPucchFormat(format4Db, pucchCfg->format4->choice.setup) != ROK)
5620       {
5621          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5622          return RFAILED;
5623       }
5624    }
5625
5626    /* Scheduling Request */
5627    if(schReqDb && (schReqDb->schedAddModListCount != 0))
5628    {
5629       pucchCfg->schedulingRequestResourceToAddModList = NULLP;
5630       DU_ALLOC(pucchCfg->schedulingRequestResourceToAddModList, sizeof(struct PUCCH_Config__schedulingRequestResourceToAddModList));
5631       if(pucchCfg->schedulingRequestResourceToAddModList == NULLP)
5632       {
5633          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5634          return RFAILED;
5635       }
5636
5637       if(BuildPucchSchReqAddModList(schReqDb, pucchCfg->schedulingRequestResourceToAddModList) != ROK)
5638       {
5639          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5640          return RFAILED;
5641       }
5642    }
5643
5644    /* Multi CSI */
5645    if(multiCsiDb && (multiCsiDb->multiCsiResrcListCount != 0))
5646    {
5647       pucchCfg->multi_CSI_PUCCH_ResourceList = NULLP;
5648       DU_ALLOC(pucchCfg->multi_CSI_PUCCH_ResourceList, sizeof(struct PUCCH_Config__multi_CSI_PUCCH_ResourceList));
5649       if(pucchCfg->multi_CSI_PUCCH_ResourceList == NULLP)
5650       {
5651          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5652          return RFAILED;
5653       }
5654
5655       if(BuildPucchMultiCsiRsrcList(multiCsiDb, pucchCfg->multi_CSI_PUCCH_ResourceList) != ROK)
5656       {
5657          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5658          return RFAILED;
5659       }
5660    }
5661
5662    /* DL DATA TO UL ACK */
5663    DU_ALLOC(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
5664    if(pucchCfg->dl_DataToUL_ACK == NULLP)
5665    {
5666       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5667       return RFAILED;
5668    }
5669
5670    if(BuildDlDataToUlAckList(dlDataToUlAckDb, pucchCfg->dl_DataToUL_ACK) != ROK)
5671    {
5672       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5673       return RFAILED;
5674    }
5675    
5676    /* TODO : spatial relation info add/mod list and power control*/
5677
5678    return ROK;
5679 }
5680
5681 /*******************************************************************
5682  *
5683  * @brief Fills SRS resource to add/modify list 
5684  *
5685  * @details
5686  *
5687  *    Function : BuildSrsRsrcAddModList
5688  *
5689  *    Functionality: Fills SRS resource to add/modify list
5690  *
5691  * @params[in] 
5692  * @return ROK     - success
5693  *         RFAILED - failure
5694  *
5695  * ****************************************************************/
5696 uint8_t BuildSrsRsrcAddModList(struct SRS_Config__srs_ResourceToAddModList *resourceList)
5697 {
5698    uint8_t   elementCnt;
5699    uint8_t   rsrcIdx;
5700
5701    elementCnt = 1;
5702    resourceList->list.count = elementCnt;
5703    resourceList->list.size = elementCnt * sizeof(SRS_Resource_t *);
5704    resourceList->list.array = NULLP;
5705    DU_ALLOC(resourceList->list.array, resourceList->list.size);
5706    if(!resourceList->list.array)
5707    {
5708       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5709       return RFAILED;
5710    }
5711
5712    for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
5713    {
5714       DU_ALLOC(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
5715       if(!resourceList->list.array[rsrcIdx])
5716       {
5717          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5718          return RFAILED;
5719       }
5720    }
5721
5722    rsrcIdx = 0;
5723    resourceList->list.array[rsrcIdx]->srs_ResourceId = SRS_RSRC_ID;
5724    resourceList->list.array[rsrcIdx]->nrofSRS_Ports = SRS_Resource__nrofSRS_Ports_port1;
5725    resourceList->list.array[rsrcIdx]->transmissionComb.present = SRS_Resource__transmissionComb_PR_n2;
5726
5727    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2 = NULLP;
5728    DU_ALLOC(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2, \
5729          sizeof(struct SRS_Resource__transmissionComb__n2));
5730    if(!resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2)
5731    {
5732       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5733       return RFAILED;
5734    }
5735    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->combOffset_n2\
5736       = SRS_COMB_OFFSET_N2;
5737    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->cyclicShift_n2\
5738       = SRS_CYCLIC_SHIFT_N2;
5739
5740    resourceList->list.array[rsrcIdx]->resourceMapping.startPosition = \
5741                                                                       PUSCH_START_SYMBOL;
5742    resourceList->list.array[rsrcIdx]->resourceMapping.nrofSymbols =  \
5743                                                                      SRS_Resource__resourceMapping__nrofSymbols_n1;
5744    resourceList->list.array[rsrcIdx]->resourceMapping.repetitionFactor = \
5745                                                                          SRS_Resource__resourceMapping__repetitionFactor_n1;
5746
5747    resourceList->list.array[rsrcIdx]->freqDomainPosition = SRS_FREQ_DOM_POS;
5748    resourceList->list.array[rsrcIdx]->freqDomainShift = SRS_FREQ_DOM_SHIFT;
5749    resourceList->list.array[rsrcIdx]->freqHopping.c_SRS = C_SRS;
5750    resourceList->list.array[rsrcIdx]->freqHopping.b_SRS = B_SRS;
5751    resourceList->list.array[rsrcIdx]->freqHopping.b_hop = B_HOP;
5752    resourceList->list.array[rsrcIdx]->groupOrSequenceHopping = \
5753                                                                SRS_Resource__groupOrSequenceHopping_neither;
5754
5755    /* Setting resource type to aperiodic for intergration purposes */
5756    resourceList->list.array[rsrcIdx]->resourceType.present = \
5757                                                              SRS_Resource__resourceType_PR_aperiodic;
5758    resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic = NULLP;
5759    DU_ALLOC(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,
5760          sizeof(struct SRS_Resource__resourceType__aperiodic));
5761    if(!resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic)
5762    {
5763       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5764       return RFAILED;
5765    }
5766
5767    resourceList->list.array[rsrcIdx]->sequenceId = SRS_SEQ_ID;
5768
5769    return ROK;
5770 }
5771
5772 /*******************************************************************
5773  *
5774  * @brief Build SRS resource set Add/mod list
5775  *
5776  * @details
5777  *
5778  *    Function : BuildSrsRsrcSetAddModList
5779  *
5780  *    Functionality: Build SRS resource set Add/mod list
5781  *
5782  * @params[in] 
5783  * @return ROK     - success
5784  *         RFAILED - failure
5785  *
5786  * ****************************************************************/
5787    uint8_t BuildSrsRsrcSetAddModList
5788 (
5789  struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList
5790  )
5791 {
5792    uint8_t  elementCnt;
5793    uint8_t  rSetIdx;
5794    uint8_t  rsrcIdx;
5795    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList;
5796
5797    elementCnt = 1;
5798    rsrcSetList->list.count = elementCnt;
5799    rsrcSetList->list.size = elementCnt * sizeof(SRS_ResourceSet_t *);
5800    rsrcSetList->list.array = NULLP;
5801    DU_ALLOC(rsrcSetList->list.array, rsrcSetList->list.size);
5802    if(!rsrcSetList->list.array)
5803    {
5804       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5805       return RFAILED;
5806    }
5807
5808    for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
5809    {
5810       DU_ALLOC(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
5811       if(!rsrcSetList->list.array[rSetIdx])
5812       {
5813          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5814          return RFAILED;
5815       }
5816    }
5817
5818    rSetIdx = 0;
5819    rsrcSetList->list.array[rSetIdx]->srs_ResourceSetId = SRS_RSET_ID;
5820
5821    /* Fill Resource Id list in resource set */
5822    rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList = NULLP;
5823    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
5824          sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
5825    if(!rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
5826    {
5827       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5828       return RFAILED;
5829    }
5830
5831    elementCnt = 1;
5832    rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
5833    rsrcIdList->list.count = elementCnt;
5834    rsrcIdList->list.size = elementCnt * sizeof(SRS_ResourceId_t *);
5835    rsrcIdList->list.array = NULLP;
5836    DU_ALLOC(rsrcIdList->list.array, rsrcIdList->list.size);
5837    if(!rsrcIdList->list.array)
5838    {
5839       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5840       return RFAILED;
5841    }
5842
5843    for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
5844    {
5845       DU_ALLOC(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
5846       if(!rsrcIdList->list.array[rsrcIdx])
5847       {
5848          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5849          return RFAILED;
5850       }
5851    }
5852
5853    rsrcIdx = 0;
5854    *rsrcIdList->list.array[rsrcIdx] = SRS_RSRC_ID;
5855
5856    /* Fill resource type */
5857    rsrcSetList->list.array[rSetIdx]->resourceType.present = \
5858                                                             SRS_ResourceSet__resourceType_PR_aperiodic;
5859
5860    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic = NULLP;
5861    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
5862          sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
5863    if(!rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic)
5864    {
5865       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5866       return RFAILED;
5867    }
5868    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->aperiodicSRS_ResourceTrigger \
5869       = APERIODIC_SRS_RESRC_TRIGGER;
5870
5871    /* TODO : Fill values for below IEs as expected by Viavi */
5872    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->csi_RS = NULLP;
5873    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->slotOffset = NULLP;
5874
5875
5876    rsrcSetList->list.array[rSetIdx]->usage = SRS_ResourceSet__usage_codebook;
5877    rsrcSetList->list.array[rSetIdx]->alpha = NULLP;
5878    rsrcSetList->list.array[rSetIdx]->p0 = NULLP;
5879    rsrcSetList->list.array[rSetIdx]->pathlossReferenceRS = NULLP;
5880    rsrcSetList->list.array[rSetIdx]->srs_PowerControlAdjustmentStates = NULLP;
5881
5882    return ROK;
5883 }
5884
5885 /*******************************************************************
5886  *
5887  * @brief Builds BWP UL dedicated SRS Config
5888  *
5889  * @details
5890  *
5891  *    Function : BuildBWPUlDedSrsCfg
5892  *
5893  *    Functionality: Builds BWP UL dedicated SRS Config
5894  *
5895  * @params[in] SRS Config 
5896  * @return ROK     - success
5897  *         RFAILED - failure
5898  *
5899  * ****************************************************************/
5900 uint8_t BuildBWPUlDedSrsCfg(SRS_Config_t *srsCfg)
5901 {
5902    srsCfg->srs_ResourceSetToReleaseList = NULLP;
5903    srsCfg->srs_ResourceSetToAddModList = NULLP;
5904    DU_ALLOC(srsCfg->srs_ResourceSetToAddModList, \
5905          sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
5906    if(!srsCfg->srs_ResourceSetToAddModList)
5907    {
5908       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5909       return RFAILED;
5910    }
5911    if(BuildSrsRsrcSetAddModList(srsCfg->srs_ResourceSetToAddModList) != ROK)
5912    {
5913       return RFAILED;
5914    }
5915
5916    srsCfg->srs_ResourceToReleaseList = NULLP;
5917
5918    /* Resource to Add/Modify list */
5919    srsCfg->srs_ResourceToAddModList = NULLP;
5920    DU_ALLOC(srsCfg->srs_ResourceToAddModList, \
5921          sizeof(struct SRS_Config__srs_ResourceToAddModList));
5922    if(!srsCfg->srs_ResourceToAddModList)
5923    {
5924       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5925       return RFAILED;
5926    }
5927
5928    if(BuildSrsRsrcAddModList(srsCfg->srs_ResourceToAddModList) != ROK)
5929    {
5930       return RFAILED;
5931    }
5932    srsCfg->tpc_Accumulation = NULLP;
5933
5934    return ROK;
5935 }
5936
5937
5938
5939 /*******************************************************************
5940  *
5941  * @brief Builds Pusch Serving cell Config
5942  *
5943  * @details
5944  *
5945  *    Function : BuildPuschSrvCellCfg
5946  *
5947  *    Functionality: Builds Pusch Serving cell Config
5948  *
5949  * @params[in] struct UplinkConfig__pusch_ServingCellConfig *puschCfg
5950  *
5951  * @return ROK     - success
5952  *         RFAILED - failure
5953  *
5954  * ****************************************************************/
5955 uint8_t BuildPuschSrvCellCfg(struct UplinkConfig__pusch_ServingCellConfig *puschCfg)
5956 {
5957    puschCfg->present = UplinkConfig__pusch_ServingCellConfig_PR_setup;
5958    puschCfg->choice.setup = NULLP;
5959    DU_ALLOC(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
5960    if(!puschCfg->choice.setup)
5961    {
5962       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5963       return RFAILED;
5964    }
5965
5966    puschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5967    puschCfg->choice.setup->rateMatching = NULLP;
5968    puschCfg->choice.setup->xOverhead = NULLP;
5969    puschCfg->choice.setup->ext1 = NULLP;
5970
5971    DU_ALLOC(puschCfg->choice.setup->ext1, sizeof(struct PUSCH_ServingCellConfig__ext1));
5972    if(!puschCfg->choice.setup->ext1)
5973    {
5974       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5975       return RFAILED;
5976    }
5977
5978    puschCfg->choice.setup->ext1->maxMIMO_Layers = NULLP;
5979    DU_ALLOC(puschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5980    if(!puschCfg->choice.setup->ext1->maxMIMO_Layers)
5981    {
5982       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5983       return RFAILED;
5984    }
5985    *(puschCfg->choice.setup->ext1->maxMIMO_Layers) = PUSCH_MAX_MIMO_LAYERS;
5986
5987    puschCfg->choice.setup->ext1->processingType2Enabled= NULLP;
5988    DU_ALLOC(puschCfg->choice.setup->ext1->processingType2Enabled,sizeof(BOOLEAN_t));
5989    if(!puschCfg->choice.setup->ext1->processingType2Enabled)
5990    {
5991       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5992       return RFAILED;
5993    }
5994    *(puschCfg->choice.setup->ext1->processingType2Enabled) = PUSCH_PROCESS_TYPE2_ENABLED;
5995
5996    return ROK;
5997 }
5998
5999 /*******************************************************************
6000  *
6001  * @brief Builds inital UL BWP
6002  *
6003  * @details
6004  *
6005  *    Function : BuildInitialUlBWP
6006  *
6007  *    Functionality: Builds initial UL BWP
6008  *
6009  * @params[in] BWP_UplinkDedicated_t *ulBwp
6010  * @return ROK     - success
6011  *         RFAILED - failure
6012  *
6013  * ****************************************************************/
6014 uint8_t BuildInitialUlBWP(InitialUlBwp *initUlBwp, BWP_UplinkDedicated_t *ulBwp)
6015 {
6016    PucchCfg *pucchCfg = NULLP;
6017    PuschCfg *puschCfg = NULLP;
6018
6019    if(initUlBwp)
6020    {
6021       if(initUlBwp->pucchPresent)
6022          pucchCfg = &initUlBwp->pucchCfg;
6023       if(initUlBwp->puschPresent)
6024          puschCfg = &initUlBwp->puschCfg;
6025    }
6026
6027    ulBwp->pucch_Config = NULLP;
6028    DU_ALLOC(ulBwp->pucch_Config, sizeof(struct BWP_UplinkDedicated__pucch_Config));
6029    if(!ulBwp->pucch_Config)
6030    {
6031       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6032       return RFAILED;
6033    }
6034
6035    ulBwp->pucch_Config->present = BWP_UplinkDedicated__pucch_Config_PR_setup;
6036    ulBwp->pucch_Config->choice.setup = NULLP;
6037    DU_ALLOC(ulBwp->pucch_Config->choice.setup, sizeof(PUCCH_Config_t));
6038    if(!ulBwp->pucch_Config->choice.setup)
6039    {
6040       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6041       return RFAILED;
6042    }
6043
6044    if(BuildBWPUlDedPucchCfg(pucchCfg, ulBwp->pucch_Config->choice.setup) != ROK)
6045    {
6046       return RFAILED;
6047    }
6048
6049    /* Fill BWP UL dedicated PUSCH config */
6050    ulBwp->pusch_Config = NULLP;
6051    DU_ALLOC(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
6052    if(!ulBwp->pusch_Config)
6053    {
6054       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6055       return RFAILED;
6056    }
6057
6058    ulBwp->pusch_Config->present = BWP_UplinkDedicated__pusch_Config_PR_setup;
6059    ulBwp->pusch_Config->choice.setup = NULLP;
6060    DU_ALLOC(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
6061    if(!ulBwp->pusch_Config->choice.setup)
6062    {
6063       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6064       return RFAILED;
6065    }
6066
6067    if(BuildBWPUlDedPuschCfg(puschCfg, ulBwp->pusch_Config->choice.setup) != ROK)
6068    {
6069       return RFAILED;
6070    }
6071
6072    ulBwp->configuredGrantConfig = NULLP;
6073
6074    /* Fill BPW UL dedicated SRS config */
6075    ulBwp->srs_Config = NULLP;
6076    DU_ALLOC(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
6077    if(!ulBwp->srs_Config)
6078    {
6079       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6080       return RFAILED;
6081    }
6082
6083    ulBwp->srs_Config->present = BWP_UplinkDedicated__srs_Config_PR_setup;
6084    ulBwp->srs_Config->choice.setup = NULLP;
6085    DU_ALLOC(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
6086    if(!ulBwp->srs_Config->choice.setup)
6087    {
6088       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6089       return RFAILED;
6090    }
6091
6092    if(BuildBWPUlDedSrsCfg(ulBwp->srs_Config->choice.setup) != ROK)
6093    {
6094       return RFAILED;   
6095    }
6096
6097    ulBwp->beamFailureRecoveryConfig = NULLP;
6098
6099    return ROK;
6100 }
6101
6102 /*******************************************************************
6103  *
6104  * @brief Builds UL config
6105  * @details
6106  *
6107  *    Function : BuildUlCfg 
6108  *
6109  *    Functionality: Builds UL config in spCellCfgDed
6110  *
6111  * @params[in] UplinkConfig_t *ulCfg
6112  *
6113  * @return ROK     - success
6114  *         RFAILED - failure
6115  *
6116  * ****************************************************************/
6117 uint8_t BuildUlCfg(ServCellRecfgInfo *servCellRecfg, UplinkConfig_t *ulCfg)
6118 {
6119    InitialUlBwp *initUlBwp = NULLP;
6120
6121    if(servCellRecfg)
6122    {
6123       initUlBwp = &servCellRecfg->initUlBwp;
6124    }
6125
6126    ulCfg->initialUplinkBWP = NULLP;
6127    DU_ALLOC(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
6128    if(!ulCfg->initialUplinkBWP)
6129    {
6130       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6131       return RFAILED;
6132    }
6133
6134    if(BuildInitialUlBWP(initUlBwp, ulCfg->initialUplinkBWP) != ROK)
6135    {
6136       return RFAILED;
6137    }
6138
6139    ulCfg->uplinkBWP_ToReleaseList = NULLP;
6140    ulCfg->uplinkBWP_ToAddModList = NULLP;
6141    ulCfg->firstActiveUplinkBWP_Id = NULLP;
6142    DU_ALLOC(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
6143    if(!ulCfg->firstActiveUplinkBWP_Id)
6144    {
6145       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6146       return RFAILED;
6147    }
6148    if(servCellRecfg == NULLP)
6149       *(ulCfg->firstActiveUplinkBWP_Id) = ACTIVE_UL_BWP_ID;
6150    else
6151       *(ulCfg->firstActiveUplinkBWP_Id) = servCellRecfg->firstActvUlBwpId;
6152
6153    ulCfg->pusch_ServingCellConfig = NULLP;
6154    DU_ALLOC(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
6155    if(!ulCfg->pusch_ServingCellConfig)
6156    {
6157       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6158       return RFAILED;
6159    }
6160
6161    if(BuildPuschSrvCellCfg(ulCfg->pusch_ServingCellConfig) != ROK)
6162    {
6163       return RFAILED;
6164    }
6165
6166    ulCfg->carrierSwitching = NULLP;
6167    ulCfg->ext1 = NULLP;
6168    return ROK;
6169 }
6170
6171 /*******************************************************************
6172  *
6173  * @brief Builds PDSCH serving cell config
6174  * @details
6175  *
6176  *    Function : BuildPdschSrvCellCfg
6177  *
6178  *    Functionality: Builds PDSCH serving cell config in spCellCfgDed
6179  *
6180  * @params[in] struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg 
6181  *
6182  * @return ROK     - success
6183  *         RFAILED - failure
6184  *
6185  * ****************************************************************/
6186 uint8_t BuildPdschSrvCellCfg(PdschServCellCfg *pdschServCellDb, struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg)
6187 {
6188    pdschCfg->present =  ServingCellConfig__pdsch_ServingCellConfig_PR_setup;
6189    pdschCfg->choice.setup = NULLP;
6190    DU_ALLOC(pdschCfg->choice.setup, sizeof( struct PDSCH_ServingCellConfig));
6191    if(!pdschCfg->choice.setup)
6192    {
6193       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6194       return RFAILED;
6195    }
6196
6197    /* Code Block Group Transmission */
6198    pdschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
6199    if(pdschServCellDb && (pdschServCellDb->maxCodeBlkGrpPerTb || pdschServCellDb->codeBlkGrpFlushInd))
6200    {
6201       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission, sizeof(struct PDSCH_ServingCellConfig__codeBlockGroupTransmission));
6202       if(pdschCfg->choice.setup->codeBlockGroupTransmission == NULLP)
6203       {
6204          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6205          return RFAILED;
6206       }
6207
6208       pdschCfg->choice.setup->codeBlockGroupTransmission->present = PDSCH_ServingCellConfig__codeBlockGroupTransmission_PR_setup;
6209       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup = NULLP;
6210       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup, sizeof(struct PDSCH_CodeBlockGroupTransmission ));
6211       if(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup == NULLP)
6212       {
6213          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6214          return RFAILED;
6215       }
6216
6217       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock = \
6218          *(pdschServCellDb->maxCodeBlkGrpPerTb);
6219       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator = \
6220          *(pdschServCellDb->codeBlkGrpFlushInd);
6221    }
6222
6223    /* xOverhead */
6224    pdschCfg->choice.setup->xOverhead = NULLP;
6225    if(pdschServCellDb && pdschServCellDb->xOverhead)
6226    {
6227       DU_ALLOC(pdschCfg->choice.setup->xOverhead, sizeof(long));
6228       if(pdschCfg->choice.setup->xOverhead == NULLP)
6229       {
6230          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6231          return RFAILED;
6232       }
6233       *(pdschCfg->choice.setup->xOverhead) = *(pdschServCellDb->xOverhead);
6234    }
6235
6236    /* Number of HARQ processes */
6237    pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH = NULLP;
6238    DU_ALLOC(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH, sizeof(long));
6239    if(!pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH)
6240    {
6241       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6242       return RFAILED;
6243    }
6244
6245    if(pdschServCellDb == NULLP)
6246    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = PDSCH_NUM_HARQ_PROC;
6247    else
6248    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = pdschServCellDb->numHarqProcForPdsch;
6249
6250    pdschCfg->choice.setup->pucch_Cell = NULLP;
6251
6252    /* Extension */
6253    pdschCfg->choice.setup->ext1 = NULLP;
6254    if(pdschServCellDb && pdschServCellDb->maxMimoLayers)
6255    {
6256       DU_ALLOC(pdschCfg->choice.setup->ext1, sizeof(struct PDSCH_ServingCellConfig__ext1));
6257       if(pdschCfg->choice.setup->ext1 == NULLP)
6258       {
6259          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6260          return RFAILED;
6261       }
6262
6263       DU_ALLOC(pdschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
6264       if(pdschCfg->choice.setup->ext1->maxMIMO_Layers == NULLP)
6265       {
6266          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6267          return RFAILED;
6268       }
6269       *(pdschCfg->choice.setup->ext1->maxMIMO_Layers) = *(pdschServCellDb->maxMimoLayers);
6270    }
6271
6272    return ROK;
6273 }
6274
6275 /*******************************************************************
6276  *
6277  * @brief Builds CSI Meas config
6278  * @details
6279  *
6280  *    Function : BuildCsiMeasCfg 
6281  *
6282  *    Functionality: Builds CSI Meas config in spCellCfgDed
6283  *
6284  * @params[in] struct ServingCellConfig__csi_MeasConfig *csiMeasCfg
6285  *
6286  * @return ROK     - success
6287  *         RFAILED - failure
6288  *
6289  * ****************************************************************/
6290 uint8_t BuildCsiMeasCfg(struct ServingCellConfig__csi_MeasConfig *csiMeasCfg)
6291 {
6292
6293    return ROK;
6294 }
6295
6296 /*******************************************************************
6297  *
6298  * @brief Builds DL BWP to add/modify list
6299  * @details
6300  *
6301  *    Function : BuildDlBwpToAddModList
6302  *
6303  *    Functionality: Builds DL BWP to add/modify list
6304  *
6305  * @params[in] ServCellRecfgInfo *servCellRecfg, 
6306  *             struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList
6307  *
6308  * @return ROK     - success
6309  *         RFAILED - failure
6310  *
6311  * ****************************************************************/ 
6312 uint8_t BuildDlBwpToAddModList(ServCellRecfgInfo *servCellRecfg, struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList)
6313 {
6314    uint8_t elementCnt, idx;
6315
6316    elementCnt = servCellRecfg->numDlBwpToAddOrMod;
6317    dlBwpAddModList->list.count = elementCnt;
6318    dlBwpAddModList->list.size = elementCnt * sizeof(struct BWP_Downlink *);
6319    dlBwpAddModList->list.array = NULLP;
6320    DU_ALLOC(dlBwpAddModList->list.array, dlBwpAddModList->list.size);
6321    if(dlBwpAddModList->list.array == NULLP)
6322    {
6323       DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6324       return RFAILED;
6325    }
6326
6327    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6328    {
6329       DU_ALLOC(dlBwpAddModList->list.array[idx], sizeof(BWP_Downlink_t));
6330       if(dlBwpAddModList->list.array[idx] == NULLP)
6331       {
6332          DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6333          return RFAILED;
6334       }
6335    }
6336
6337    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6338    {
6339       dlBwpAddModList->list.array[idx]->bwp_Id = servCellRecfg->dlBwpToAddOrModList[idx].bwpId;
6340       dlBwpAddModList->list.array[idx]->bwp_Common = NULLP;
6341       dlBwpAddModList->list.array[idx]->bwp_Dedicated = NULLP;
6342    }
6343    return ROK;
6344 }
6345
6346 /*******************************************************************
6347  *
6348  * @brief Builds Spcell config dedicated
6349  * @details
6350  *
6351  *    Function : BuildSpCellCfgDed
6352  *
6353  *    Functionality: Builds sp cell config dedicated in spCellCfg
6354  *
6355  * @params[in] ServingCellConfig_t srvCellCfg
6356  *
6357  * @return ROK     - success
6358  *         RFAILED - failure
6359  *
6360  * ****************************************************************/
6361 uint8_t BuildSpCellCfgDed(DuUeCb *ueCb, ServingCellConfig_t *srvCellCfg)
6362 {
6363    ServCellRecfgInfo *servCellRecfg = NULLP;
6364    InitialDlBwp *initDlBwp = NULLP;
6365    PdschServCellCfg *pdschServCellDb = NULLP;
6366
6367    if(ueCb)
6368    {
6369       servCellRecfg = &ueCb->duMacUeCfg.spCellCfg.servCellCfg;
6370       initDlBwp = &servCellRecfg->initDlBwp;
6371       pdschServCellDb = &servCellRecfg->pdschServCellCfg;
6372    }
6373
6374    srvCellCfg->tdd_UL_DL_ConfigurationDedicated = NULLP;
6375
6376    srvCellCfg->initialDownlinkBWP = NULLP;
6377    DU_ALLOC(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
6378    if(!srvCellCfg->initialDownlinkBWP)
6379    {
6380       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6381       return RFAILED;
6382    }
6383
6384    if(BuildInitialDlBWP(initDlBwp, srvCellCfg->initialDownlinkBWP) != ROK)
6385    {
6386       DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6387       return RFAILED;
6388    }
6389
6390    srvCellCfg->downlinkBWP_ToReleaseList = NULLP;
6391
6392    srvCellCfg->downlinkBWP_ToAddModList = NULLP;
6393    if(ueCb && ueCb->duMacUeCfg.spCellCfg.servCellCfg.numDlBwpToAddOrMod)
6394    {
6395       DU_ALLOC(srvCellCfg->downlinkBWP_ToAddModList, sizeof(struct ServingCellConfig__downlinkBWP_ToAddModList));
6396       if(srvCellCfg->downlinkBWP_ToAddModList == NULLP)
6397       {
6398          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6399          return RFAILED;
6400       }
6401
6402       if(BuildDlBwpToAddModList(&ueCb->duMacUeCfg.spCellCfg.servCellCfg, srvCellCfg->downlinkBWP_ToAddModList) != ROK)
6403       {
6404          DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6405          return RFAILED;
6406       }
6407    }
6408
6409    srvCellCfg->firstActiveDownlinkBWP_Id = NULLP;
6410    DU_ALLOC(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
6411    if(!srvCellCfg->firstActiveDownlinkBWP_Id)
6412    {
6413       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6414       return RFAILED;
6415    }
6416    if(ueCb == NULLP)
6417       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6418    else
6419       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.firstActvDlBwpId;
6420
6421    srvCellCfg->bwp_InactivityTimer = NULLP;
6422
6423    srvCellCfg->defaultDownlinkBWP_Id = NULLP;
6424    DU_ALLOC(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
6425    if(!srvCellCfg->defaultDownlinkBWP_Id)
6426    {
6427       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6428       return RFAILED;
6429    }
6430    if(ueCb == NULLP)
6431       *(srvCellCfg->defaultDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6432    else
6433       *(srvCellCfg->defaultDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.defaultDlBwpId;
6434
6435    srvCellCfg->uplinkConfig = NULLP;
6436    DU_ALLOC(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));
6437    if(!srvCellCfg->uplinkConfig)
6438    {
6439       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6440       return RFAILED;
6441    }
6442
6443    if(BuildUlCfg(servCellRecfg, srvCellCfg->uplinkConfig) != ROK)
6444    {
6445       DU_LOG("\nERROR  -->  F1AP : BuildUlCfg failed");
6446       return RFAILED;
6447    }
6448    srvCellCfg->supplementaryUplink = NULLP;
6449    srvCellCfg->pdcch_ServingCellConfig = NULLP;
6450
6451    srvCellCfg->pdsch_ServingCellConfig = NULLP;
6452    DU_ALLOC(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct  ServingCellConfig__pdsch_ServingCellConfig));
6453    if(!srvCellCfg->pdsch_ServingCellConfig)
6454    {
6455       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6456       return RFAILED;
6457    }
6458
6459    if(BuildPdschSrvCellCfg(pdschServCellDb, srvCellCfg->pdsch_ServingCellConfig) != ROK)
6460    {
6461       DU_LOG("\nERROR  -->  F1AP : BuildPdschSrvCellCfg failed");
6462       return RFAILED;
6463    }
6464
6465    srvCellCfg->csi_MeasConfig = NULLP;
6466 #if 0
6467    DU_ALLOC(srvCellCfg->csi_MeasConfig, sizeof(struct   ServingCellConfig__csi_MeasConfig))
6468       if(!srvCellCfg->csi_MeasConfig)
6469       {
6470          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6471          return RFAILED;
6472       }
6473
6474    if(BuildCsiMeasCfg(srvCellCfg->csi_MeasConfig) != ROK)
6475    {
6476       DU_LOG("\nF1AP : BuildCsiMeasCfg failed");
6477       return RFAILED;
6478    }
6479 #endif
6480    srvCellCfg->sCellDeactivationTimer = NULLP;
6481    srvCellCfg->crossCarrierSchedulingConfig = NULLP;
6482    srvCellCfg->tag_Id = TAG_ID;
6483    srvCellCfg->dummy = NULLP;
6484    srvCellCfg->pathlossReferenceLinking = NULLP;
6485    srvCellCfg->servingCellMO = NULLP;
6486    srvCellCfg->ext1 = NULLP;
6487
6488    return ROK;
6489 }
6490
6491 /*******************************************************************
6492  *
6493  * @brief Fills SCS specific carrier list in DL frequency info
6494  *
6495  * @details
6496  *
6497  *    Function : BuildScsSpecificCarrierListDl
6498  *
6499  *    Functionality: Fills SCS specific carrier list in DL frequency info
6500  *
6501  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
6502  *
6503  * @return ROK     - success
6504  *         RFAILED - failure
6505  *
6506  * ****************************************************************/
6507 uint8_t BuildScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
6508 {
6509    uint8_t elementCnt = 0, listIdx = 0;
6510    ScsSpecCarrier duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.dlScsCarrier;
6511
6512    elementCnt = ODU_VALUE_ONE;
6513    scsCarrierList->list.count = elementCnt;
6514    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6515
6516    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6517    if(!scsCarrierList->list.array)
6518    {
6519       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for scs carrier list array \
6520          in BuildScsSpecificCarrierListDl()");
6521       return RFAILED;
6522    }
6523
6524    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6525    {
6526       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6527       if(!scsCarrierList->list.array[listIdx])
6528       {    
6529          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SCS Specific Carrier list array \
6530             element in BuildScsSpecificCarrierListDl()");
6531          return RFAILED;
6532       }    
6533    }
6534
6535    listIdx = 0;
6536    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6537    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6538    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6539
6540    return ROK;
6541 }
6542
6543 /*******************************************************************
6544  *
6545  * @brief Fills DL frequency info in DL config common
6546  *
6547  * @details
6548  *
6549  *    Function : BuildFreqInfoDl
6550  *
6551  *    Functionality: Fills DL frequency info in DL config common
6552  *
6553  * @params[in] Pointer to DownlinkConfigCommon_t
6554  *
6555  * @return ROK     - success
6556  *         RFAILED - failure
6557  *
6558  * ****************************************************************/
6559 uint8_t BuildFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
6560 {
6561    uint8_t freqBandIdx = 0, elementCnt = 0;
6562    DlCfgCommon  dlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg;
6563
6564    /* TODO : Fill SSB Absolute Frequency */
6565    /*
6566       DU_ALLOC(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
6567       if(!frequencyInfoDL->absoluteFrequencySSB)
6568       {
6569       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB Absolute Frequency in BuildFreqInfoDl()");
6570       return RFAILED;
6571       }
6572       frequencyInfoDL->absoluteFrequencySSB = ?;
6573       */
6574
6575    /* NR Multi Frequency Band List */
6576    elementCnt = ODU_VALUE_ONE;
6577    frequencyInfoDL->frequencyBandList.list.count = elementCnt;
6578    frequencyInfoDL->frequencyBandList.list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6579
6580    DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
6581    if(!frequencyInfoDL->frequencyBandList.list.array)
6582    {
6583       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for Frequency Band List array in BuildFreqInfoDl()");
6584       return RFAILED;
6585    }
6586
6587    for(freqBandIdx = 0; freqBandIdx < elementCnt; freqBandIdx++)
6588    {
6589       DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
6590       if(!frequencyInfoDL->frequencyBandList.list.array[freqBandIdx])
6591       {
6592          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoDl()");
6593          return RFAILED;
6594       }
6595    }
6596
6597    freqBandIdx = 0;
6598    *(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx]) = dlCfg.freqBandInd;
6599
6600    /* TODO : Absolute Frequency to Point A */
6601    //frequencyInfoDL->absoluteFrequencyPointA
6602
6603    /* Subcarrier Spacing specifc carrier List */
6604    if((BuildScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList)) != ROK)
6605    {
6606       DU_LOG("\nERROR  -->  DU APP : Failed to fill SCS specific carrier list DL in BuildFreqInfoDl()");
6607       return RFAILED;
6608    }
6609
6610    return ROK;
6611
6612 }
6613
6614 /*******************************************************************
6615  *
6616  * @brief Fills DL config common in Serving cell config common
6617  *
6618  * @details
6619  *
6620  *    Function : BuildDlConfigCommon
6621  *
6622  *    Functionality: Fills DL config common in Serving cell config common
6623  *
6624  * @params[in] Pointer to DownlinkConfigCommon_t
6625  *
6626  * @return ROK     - success
6627  *         RFAILED - failure
6628  *
6629  * ****************************************************************/
6630 uint8_t BuildDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
6631 {
6632    /* DL Frequency Info */
6633    DU_ALLOC(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
6634    if(!dlCfgCommon->frequencyInfoDL)
6635    {
6636       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL frequency info in BuildDlConfigCommon()");
6637       return RFAILED;
6638    }
6639    if((BuildFreqInfoDl(dlCfgCommon->frequencyInfoDL))!= ROK)
6640    {
6641       DU_LOG("\nERROR  --> DU APP : Failed to fill DL frequency info in BuildDlConfigCommon()");
6642       return RFAILED;
6643    }
6644
6645    /* DL BWP config common */
6646    DU_ALLOC(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
6647    if(!dlCfgCommon->initialDownlinkBWP)
6648    {
6649       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL BWP config common in BuildDlConfigCommon()");
6650       return RFAILED;
6651    }
6652    if((BuildBwpDlCommon(dlCfgCommon->initialDownlinkBWP)) != ROK)
6653    {
6654       DU_LOG("\nERROR  --> DU APP : Failed to fill DL DWP config common in BuildDlConfigCommon()");
6655       return RFAILED;
6656    }
6657
6658    return ROK;
6659 }
6660
6661 /*******************************************************************
6662  *
6663  * @brief Fills SCS specific carrier list in UL frequency Info
6664  *
6665  * @details
6666  *
6667  *    Function : BuildScsSpecificCarrierListUl
6668  *
6669  *    Functionality: Fills SCS specific carrier list in UL frequency Info
6670  *
6671  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
6672  *
6673  * @return ROK     - success
6674  *         RFAILED - failure
6675  *
6676  * ****************************************************************/
6677 uint8_t BuildScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
6678 {
6679    uint8_t elementCnt = 0, listIdx = 0; 
6680    ScsSpecCarrier   duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.ulScsCarrier;
6681
6682    elementCnt = ODU_VALUE_ONE;
6683    scsCarrierList->list.count = elementCnt;
6684    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6685
6686    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6687    if(!scsCarrierList->list.array)
6688    {
6689       DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6690       return RFAILED;
6691    }
6692
6693    for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
6694    {
6695       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6696       if(!scsCarrierList->list.array[listIdx])
6697       {    
6698          DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6699          return RFAILED;
6700       }    
6701    }
6702    listIdx = 0; 
6703    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6704    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6705    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6706
6707    return ROK;
6708 }
6709
6710 /*******************************************************************
6711  *
6712  * @brief Fills frequency info in UL config common
6713  *
6714  * @details
6715  *
6716  *    Function : BuildFreqInfoUl
6717  *
6718  *    Functionality: Fills frequency info in UL config common
6719  *
6720  * @params[in] Pointer to FrequencyInfoUL_t
6721  *
6722  * @return ROK     - success
6723  *         RFAILED - failure
6724  *
6725  * ****************************************************************/
6726 uint8_t BuildFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
6727 {
6728    uint8_t elementCnt = 0, listIdx= 0;
6729    UlCfgCommon  ulCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg;
6730
6731    /* NR Multi Frequency Band List */
6732    DU_ALLOC(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
6733    if(!frequencyInfoUL->frequencyBandList)
6734    {
6735       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band list in BuildFreqInfoUl()");
6736       return RFAILED;
6737    }
6738
6739    elementCnt = ODU_VALUE_ONE;
6740    frequencyInfoUL->frequencyBandList->list.count = elementCnt;
6741    frequencyInfoUL->frequencyBandList->list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6742
6743    DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
6744    if(!frequencyInfoUL->frequencyBandList->list.array)
6745    {
6746       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array in BuildFreqInfoUl()");
6747       return RFAILED;
6748    }
6749
6750    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6751    {
6752       DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
6753       if(!frequencyInfoUL->frequencyBandList->list.array[listIdx])
6754       {
6755          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoUl()");
6756          return RFAILED;
6757       }
6758    }
6759
6760    listIdx = 0;
6761    *(frequencyInfoUL->frequencyBandList->list.array[listIdx]) = ulCfg.freqBandInd;
6762
6763    /* TODO : Fill Absolute frequency point A */
6764    /*
6765       DU_ALLOC(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
6766       if(!frequencyInfoUL->absoluteFrequencyPointA)
6767       {
6768       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for absolute frequency point A in BuildFreqInfoUl()");
6769       return RFAILED;
6770       }
6771     *(frequencyInfoUL->absoluteFrequencyPointA) = ?;
6772     */
6773
6774    /* Subcarrier Spacing specifc carrier */
6775    if((BuildScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList)) != ROK) 
6776    {
6777       DU_LOG("\nERROR  --> DU APP : Failed to fill SCS Specific Carrier list UL in BuildFreqInfoUl()");
6778       return RFAILED;
6779    }
6780
6781    /* P-MAX */
6782    DU_ALLOC(frequencyInfoUL->p_Max, sizeof(P_Max_t));
6783    if(!frequencyInfoUL->p_Max)
6784    {
6785       DU_LOG("\nERROR  -->  DU APP : UL Frequency Infoo  memory allocation failure");
6786       return RFAILED;
6787    }
6788    *frequencyInfoUL->p_Max = ulCfg.pMax;
6789
6790    return ROK;
6791 }
6792
6793 /*******************************************************************
6794  *
6795  * @brief Fills UL config common in Serving cell config common
6796  *
6797  * @details
6798  *
6799  *    Function : BuildUlConfigCommon
6800  *
6801  *    Functionality: Fills UL config common in Serving cell config common
6802  *
6803  * @params[in] Pointer to UplinkConfigCommon_t
6804  *
6805  * @return ROK     - success
6806  *         RFAILED - failure
6807  *
6808  * ****************************************************************/
6809 uint8_t BuildUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
6810 {
6811    /* UL Frequency Info */
6812    DU_ALLOC(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
6813    if(!ulCfgCommon->frequencyInfoUL)
6814    {
6815       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for UL frequency info in BuildUlConfigCommon()");
6816       return RFAILED;
6817    }
6818
6819    if((BuildFreqInfoUl(ulCfgCommon->frequencyInfoUL)) != ROK)
6820    {
6821       DU_LOG("\nERROR  -->  DU APP : Failed to fill frequency info UL in BuildUlConfigCommon()");
6822       return RFAILED;
6823    }
6824
6825    /* UL BWP common */
6826    DU_ALLOC(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
6827    if(!ulCfgCommon->initialUplinkBWP)
6828    {
6829       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for initial UL BWP in BuildUlConfigCommon()");
6830       return RFAILED;
6831    }
6832
6833    if((BuildBwpUlCommon(ulCfgCommon->initialUplinkBWP)) != ROK)
6834    {
6835       DU_LOG("\nERROR  -->  DU APP : Failed to fill BWP UL common in BuildUlConfigCommon()");
6836       return RFAILED;
6837    }
6838
6839    /* Time Alignment timer */
6840    ulCfgCommon->dummy = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.timeAlignTimerComm;
6841
6842    return ROK;
6843 }
6844
6845 /*******************************************************************
6846  *
6847  * @brief Fills SSB position in burst in SP cell config common
6848  *
6849  * @details
6850  *
6851  *    Function : BuildSsbPosInBurst
6852  *
6853  *    Functionality: 
6854  *       Fills SSB position in burst in SP cell config common
6855  *
6856  * @params[in] Pointer to struct ServingCellConfigCommon__ssb_PositionsInBurst
6857  *
6858  * @return ROK     - success
6859  *         RFAILED - failure
6860  *
6861  * ****************************************************************/
6862 uint8_t BuildSsbPosInBurst(struct ServingCellConfigCommon__ssb_PositionsInBurst *ssbPosInBurst)
6863 {
6864    uint8_t bitStringSizeInBytes = 0;
6865
6866    ssbPosInBurst->present = ServingCellConfigCommon__ssb_PositionsInBurst_PR_mediumBitmap;
6867
6868    /* As per spec 38.331,in the definition of ServingCellConfigCommon */
6869    bitStringSizeInBytes = 1;
6870    ssbPosInBurst->choice.mediumBitmap.size = bitStringSizeInBytes * sizeof(uint8_t);
6871
6872    DU_ALLOC(ssbPosInBurst->choice.mediumBitmap.buf, ssbPosInBurst->choice.mediumBitmap.size);
6873    if(!ssbPosInBurst->choice.mediumBitmap.buf)
6874    {
6875       DU_LOG("\nERROR  -->  DU APP : Memory Allocation failed for medium bit map buffer in BuildSsbPosInBurst()");
6876       return RFAILED;
6877    }
6878
6879    if((fillBitString(&ssbPosInBurst->choice.mediumBitmap, 0, bitStringSizeInBytes, \
6880                duCfgParam.sib1Params.srvCellCfgCommSib.ssbPosInBurst)) != ROK)
6881    {
6882       DU_LOG("\nERROR  -->  DU APP : Failed to fill medium bit map in BuildSsbPosInBurst()");
6883       return RFAILED;
6884    }
6885
6886    return ROK;
6887 }
6888
6889 /*******************************************************************
6890  *
6891  * @brief Fills SP cell config common in Reconfig with Sync
6892  *
6893  * @details
6894  *
6895  *    Function : BuildSpCellConfigCommon
6896  *
6897  *    Functionality: Fills SP cell config common in Reconfig with Sync
6898  *
6899  * @params[in] Pointer to ServingCellConfigCommon_t
6900  *
6901  * @return ROK     - success
6902  *         RFAILED - failure
6903  *
6904  * ****************************************************************/
6905 uint8_t BuildSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
6906 {
6907    /* Physical Cell Identity */
6908    DU_ALLOC(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
6909    if(!spCellConfigCommon->physCellId)
6910    {
6911       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for physical cell id in BuildSpCellConfigCommon()");
6912       return RFAILED;
6913    } 
6914    *(spCellConfigCommon->physCellId) = NR_PCI;
6915
6916    /* Downlink Config Common */
6917    DU_ALLOC(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
6918    if(!spCellConfigCommon->downlinkConfigCommon)
6919    {
6920       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for DL Config Common in BuildSpCellConfigCommon()");
6921       return RFAILED;
6922    }
6923    if((BuildDlConfigCommon(spCellConfigCommon->downlinkConfigCommon)) != ROK)
6924    {
6925       DU_LOG("\nERROR  -->  DU APP : Failed to fill DL config commin in BuildSpCellConfigCommon()");
6926       return RFAILED;
6927    }
6928
6929    /* Uplinlink Config Common */
6930    DU_ALLOC(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
6931    if(!spCellConfigCommon->uplinkConfigCommon)
6932    {
6933       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for UL Config Common in BuildSpCellConfigCommon()");
6934       return RFAILED;
6935    }
6936    if((BuildUlConfigCommon(spCellConfigCommon->uplinkConfigCommon)) != ROK)
6937    {
6938       DU_LOG("\nERROR  -->  DU APP : Failed to fill UL config commin in BuildSpCellConfigCommon()");
6939       return RFAILED;
6940    }
6941
6942    /* Timing Advance offset */
6943    DU_ALLOC(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
6944    if(!spCellConfigCommon->n_TimingAdvanceOffset)
6945    {
6946       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for Timing Advance Offset in BuildSpCellConfigCommon()");
6947       return RFAILED;
6948    }
6949    *(spCellConfigCommon->n_TimingAdvanceOffset) = ServingCellConfigCommon__n_TimingAdvanceOffset_n0;
6950
6951    /* SSB Position In Burst */
6952    DU_ALLOC(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
6953    if(!spCellConfigCommon->ssb_PositionsInBurst)
6954    {
6955       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Position In Burst in BuildSpCellConfigCommon()");
6956       return RFAILED;
6957    }
6958    if((BuildSsbPosInBurst(spCellConfigCommon->ssb_PositionsInBurst)) != ROK)
6959    {
6960       DU_LOG("\nERROR  -->  DU APP : Failed to fill SSB Position In Burst in BuildSpCellConfigCommon()");
6961       return RFAILED;
6962    }
6963
6964    /* SSB Periodicity in Serving cell */
6965    DU_ALLOC(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
6966    if(!spCellConfigCommon->ssb_periodicityServingCell)
6967    {
6968       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Periodicity serving cell in \
6969          BuildSpCellConfigCommon()");
6970       return RFAILED;
6971    }
6972    *(spCellConfigCommon->ssb_periodicityServingCell) = \
6973       convertSsbPeriodicityValueToEnum(duCfgParam.sib1Params.srvCellCfgCommSib.ssbPrdServingCell);
6974
6975    /* DMRS Type A position */
6976    spCellConfigCommon->dmrs_TypeA_Position = convertDmrsTypeAPosValueToEnum(duCfgParam.macCellCfg.ssbCfg.dmrsTypeAPos);
6977
6978    /* SSB subcarrier spacing */
6979    DU_ALLOC(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
6980    if(!spCellConfigCommon->ssbSubcarrierSpacing)
6981    {
6982       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for sub-carrier spacing in BuildSpCellConfigCommon()");
6983       return RFAILED;
6984    }
6985    *(spCellConfigCommon->ssbSubcarrierSpacing) = duCfgParam.sib1Params.srvCellCfgCommSib.scs;
6986
6987    /* TDD UL-DL configuration common */
6988    DU_ALLOC(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
6989    if(!spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)
6990    {
6991       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for TDD UL-DL config common in BuildSpCellConfigCommon()");
6992       return RFAILED;
6993    }
6994    if((BuildTddUlDlCfgComm(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)) != ROK)
6995    {
6996       DU_LOG("\nERROR  -->  DU APP : Failed to fill TDD UL-DL config common in BuildSpCellConfigCommon()");
6997       return RFAILED;
6998    }
6999
7000    /* SS PBCH Block Power */
7001    spCellConfigCommon->ss_PBCH_BlockPower = duCfgParam.sib1Params.srvCellCfgCommSib.ssPbchBlockPwr;
7002
7003    return ROK;
7004 }
7005
7006 /*******************************************************************
7007  *
7008  * @brief Fills dedicated RACH configuration in Reconfiguration with sync
7009  *
7010  * @details
7011  *
7012  *    Function : BuildRecfgWithSync
7013  *
7014  *    Functionality: 
7015  *       Fills dedicated RACH configuration in Reconfiguration with sync
7016  *
7017  * @params[in] DU UE CB
7018  *             Pointer to Rach config dedicated struct
7019  *
7020  * @return ROK     - success
7021  *         RFAILED - failure
7022  *
7023  * ****************************************************************/
7024 uint8_t BuildRachConfigDedicated(DuUeCb *ueCb, struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
7025 {
7026    uint8_t elementCnt = 0, listIdx = 0;
7027    CFRA_t *cfra = NULLP;
7028    struct CFRA__resources__ssb *ssbResource = NULLP;
7029    RachCfgCommon duRachCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.rachCfg;
7030
7031    rachCfgDed->present = ReconfigurationWithSync__rach_ConfigDedicated_PR_uplink;
7032
7033    /* Uplink */
7034    DU_ALLOC(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
7035    if(!rachCfgDed->choice.uplink)
7036    {
7037       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for RACH uplink configuration in BuildRachConfigDedicated()");
7038       return RFAILED;
7039    }
7040
7041    /* CFRA : Contention free Random Access */
7042    DU_ALLOC(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
7043    if(!rachCfgDed->choice.uplink->cfra)
7044    {
7045       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA in BuildRachConfigDedicated()");
7046       return RFAILED;
7047    }
7048    cfra = rachCfgDed->choice.uplink->cfra;
7049
7050    /* CFRA occassions */
7051    DU_ALLOC(cfra->occasions, sizeof(struct CFRA__occasions));
7052    if(!cfra->occasions)
7053    {
7054       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA occassion in BuildRachConfigDedicated()");
7055       return RFAILED;
7056    }
7057
7058    /* CFRA occassions : RACH generic configuration */
7059    cfra->occasions->rach_ConfigGeneric.prach_ConfigurationIndex = duRachCfg.prachCfgIdx;
7060    cfra->occasions->rach_ConfigGeneric.msg1_FDM = duRachCfg.msg1Fdm;
7061    cfra->occasions->rach_ConfigGeneric.msg1_FrequencyStart = duRachCfg.msg1FreqStart;
7062    cfra->occasions->rach_ConfigGeneric.zeroCorrelationZoneConfig = duRachCfg.zeroCorrZoneCfg;
7063    cfra->occasions->rach_ConfigGeneric.preambleReceivedTargetPower = duRachCfg.preambleRcvdTgtPwr;
7064    cfra->occasions->rach_ConfigGeneric.preambleTransMax = duRachCfg.preambleTransMax;
7065    cfra->occasions->rach_ConfigGeneric.powerRampingStep = duRachCfg.pwrRampingStep;
7066    cfra->occasions->rach_ConfigGeneric.ra_ResponseWindow = duRachCfg.raRspWindow;
7067
7068    /* CFRA occassions : SSB per RACH occasion */
7069    DU_ALLOC(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
7070    if(!cfra->occasions->ssb_perRACH_Occasion)
7071    {
7072       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB per RACH occassion in BuildRachConfigDedicated()");
7073       return RFAILED;
7074    }
7075    *(cfra->occasions->ssb_perRACH_Occasion) = convertCFRASsbPerRachOccasionValueToEnum(duCfgParam.macCellCfg.prachCfg.ssbPerRach);
7076
7077    /* CFRA resource */
7078    cfra->resources.present = CFRA__resources_PR_ssb;
7079
7080    /* CFRA resource : SSB */
7081    DU_ALLOC(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
7082    if(!cfra->resources.choice.ssb)
7083    {
7084       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA resource - SSB in BuildRachConfigDedicated()");
7085       return RFAILED;
7086    }
7087    ssbResource = cfra->resources.choice.ssb;
7088
7089    /* CFRA SSB resource list */
7090    elementCnt = ueCb->cfraResource.numSsb;
7091    ssbResource->ssb_ResourceList.list.count = elementCnt;
7092    ssbResource->ssb_ResourceList.list.size = elementCnt * sizeof(CFRA_SSB_Resource_t *);
7093
7094    DU_ALLOC(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
7095    if(!ssbResource->ssb_ResourceList.list.array)
7096    {
7097       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list in BuildRachConfigDedicated()");
7098       return RFAILED;
7099    }
7100
7101    for(listIdx = 0; listIdx < elementCnt; listIdx++)
7102    {
7103       DU_ALLOC(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
7104       if(!ssbResource->ssb_ResourceList.list.array[listIdx])
7105       {
7106          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list element in BuildRachConfigDedicated()");  
7107          return RFAILED;
7108       }
7109       ssbResource->ssb_ResourceList.list.array[listIdx]->ssb = ueCb->cfraResource.ssbResource[listIdx].ssbIdx;
7110       ssbResource->ssb_ResourceList.list.array[listIdx]->ra_PreambleIndex = ueCb->cfraResource.ssbResource[listIdx].raPreambleIdx;
7111    }
7112
7113    return ROK;
7114 }
7115
7116 /*******************************************************************
7117  *
7118  * @brief Fills reconfiguration with sync in SP cell config
7119  *
7120  * @details
7121  *
7122  *    Function : BuildRecfgWithSync
7123  *
7124  *    Functionality: Fills reconfiguration with sync in SP cell config
7125  *
7126  * @params[in] DU UE CB
7127  *             Pointer to ReconfigurationWithSync_t
7128  *
7129  * @return ROK     - success
7130  *         RFAILED - failure
7131  *
7132  * ****************************************************************/
7133 uint8_t BuildRecfgWithSync(DuUeCb *ueCb, ReconfigurationWithSync_t *recfgWithSync)
7134 {
7135    /* SP Cell Config Common */  
7136    DU_ALLOC(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
7137    if(!recfgWithSync->spCellConfigCommon)
7138    {
7139       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for spCellConfigCommon in BuildRecfgWithSync()");
7140       return RFAILED;
7141    }
7142
7143    if((BuildSpCellConfigCommon(recfgWithSync->spCellConfigCommon)) != ROK)
7144    {
7145       DU_LOG("\nERROR  -->  DU APP : Failed to build SpCellConfigCommon in BuildRecfgWithSync()");
7146       return RFAILED;
7147    }
7148
7149    /* New UE Identity */
7150    recfgWithSync->newUE_Identity = ueCb->crnti;
7151
7152    /* T304 timer */
7153    recfgWithSync->t304 = ReconfigurationWithSync__t304_ms1000;
7154
7155    /* RACH configuration dedicated */
7156    DU_ALLOC(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
7157    if(!recfgWithSync->rach_ConfigDedicated)
7158    {
7159       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for RACH config dedicated in BuildRecfgWithSync()");
7160       return RFAILED;
7161    }
7162
7163    if((BuildRachConfigDedicated(ueCb, recfgWithSync->rach_ConfigDedicated)) != ROK)
7164    {
7165       DU_LOG("\nERROR  -->  DU APP : Failed to build RACH config dedicated in BuildRecfgWithSync()");
7166       return RFAILED;
7167    }
7168
7169    return ROK;
7170 }
7171
7172 /*******************************************************************
7173  *
7174  * @brief Builds Spcell config 
7175  *
7176  * @details
7177  *
7178  *    Function : BuildSpCellCfg 
7179  *
7180  *    Functionality: Builds sp cell config in DuToCuRrcContainer
7181  *
7182  * @params[in] SpCellConfig_t spCellCfg
7183  *
7184  * @return ROK     - success
7185  *         RFAILED - failure
7186  *
7187  * ****************************************************************/
7188 uint8_t BuildSpCellCfg(DuUeCb *ueCb, SpCellConfig_t *spCellCfg)
7189 {
7190    spCellCfg->servCellIndex = NULLP;
7191    DU_ALLOC(spCellCfg->servCellIndex, sizeof(long));
7192    if(!spCellCfg->servCellIndex)
7193    {
7194       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7195       return RFAILED;
7196    }
7197
7198    if(ueCb == NULLP)
7199       *(spCellCfg->servCellIndex) = SERV_CELL_IDX;
7200    else
7201       *(spCellCfg->servCellIndex) = ueCb->duMacUeCfg.spCellCfg.servCellIdx;
7202
7203    spCellCfg->reconfigurationWithSync = NULLP;
7204    if(ueCb && (ueCb->ueState == UE_HANDIN_IN_PROGRESS))
7205    {
7206       DU_ALLOC(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
7207       if(!spCellCfg->reconfigurationWithSync)
7208       {
7209          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7210          return RFAILED;
7211       }
7212
7213       if((BuildRecfgWithSync(ueCb, spCellCfg->reconfigurationWithSync)) != ROK)
7214       {
7215          DU_LOG("\nERROR  -->  F1AP : Building of reconfiguration with sync failed at BuildSpCellCfg");
7216          return RFAILED;
7217       }
7218    }
7219
7220    spCellCfg->rlf_TimersAndConstants = NULLP;
7221    spCellCfg->rlmInSyncOutOfSyncThreshold = NULLP;
7222
7223    DU_ALLOC(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
7224    if(!spCellCfg->rlmInSyncOutOfSyncThreshold)
7225    {
7226       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7227       return RFAILED;
7228    }
7229    *(spCellCfg->rlmInSyncOutOfSyncThreshold) = RLM_SYNC_OUT_SYNC_THRESHOLD;
7230
7231    spCellCfg->spCellConfigDedicated = NULLP;
7232    DU_ALLOC(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
7233    if(!spCellCfg->spCellConfigDedicated)
7234    {
7235       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7236       return RFAILED;
7237    }
7238    if(BuildSpCellCfgDed(ueCb, spCellCfg->spCellConfigDedicated) != ROK)
7239    {
7240       DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfgDed failed");
7241       return RFAILED;
7242    }
7243
7244    return ROK;
7245 }
7246
7247 /*******************************************************************
7248  *
7249  * @brief Builds Phy cell group config 
7250  *
7251  * @details
7252  *
7253  *    Function : BuildPhyCellGrpCfg 
7254  *
7255  *    Functionality: Builds Phy cell group config in DuToCuRrcContainer
7256  *
7257  * @params[in] PhysicalCellGroupConfig_t *phyCellGrpCfg 
7258  *
7259  * @return ROK     - success
7260  *         RFAILED - failure
7261  *
7262  * ****************************************************************/
7263 uint8_t BuildPhyCellGrpCfg(DuUeCb *ueCb, PhysicalCellGroupConfig_t *phyCellGrpCfg)
7264 {
7265    phyCellGrpCfg->harq_ACK_SpatialBundlingPUCCH = NULLP;
7266    phyCellGrpCfg->harq_ACK_SpatialBundlingPUSCH = NULLP;
7267
7268    phyCellGrpCfg->p_NR_FR1 = NULLP;
7269    DU_ALLOC(phyCellGrpCfg->p_NR_FR1, sizeof(long));
7270    if(!phyCellGrpCfg->p_NR_FR1)
7271    {
7272       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhyCellGrpCfg");
7273       return RFAILED;
7274    }
7275
7276    if(ueCb == NULLP)
7277    {
7278       *(phyCellGrpCfg->p_NR_FR1)             = P_NR_FR1;
7279       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = PDSCH_HARQ_ACK_CODEBOOK;
7280    }
7281    else
7282    {
7283       *(phyCellGrpCfg->p_NR_FR1) = ueCb->duMacUeCfg.phyCellGrpCfg.pNrFr1;
7284       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = ueCb->duMacUeCfg.phyCellGrpCfg.pdschHarqAckCodebook;
7285    }
7286
7287    phyCellGrpCfg->tpc_SRS_RNTI = NULLP;
7288    phyCellGrpCfg->tpc_PUCCH_RNTI = NULLP;
7289    phyCellGrpCfg->tpc_PUSCH_RNTI = NULLP;
7290    phyCellGrpCfg->sp_CSI_RNTI = NULLP;
7291    phyCellGrpCfg->cs_RNTI = NULLP;
7292    phyCellGrpCfg->ext1 = NULLP;
7293    phyCellGrpCfg->ext2 = NULLP;
7294
7295    return ROK;
7296 }
7297 #ifdef NR_DRX
7298 /*******************************************************************
7299  *
7300  * @brief fill long cycle offset value of drx
7301  *
7302  * @details
7303  *
7304  *    Function : fillLongCycleOffsetValFromDuCb 
7305  *
7306  *    Functionality: fill long cycle offset value of drx
7307  *
7308  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
7309  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
7310  *
7311  * @return ROK     - success
7312  *         RFAILED - failure
7313  *
7314  * ****************************************************************/
7315 void fillLongCycleOffsetValFromDuCb(DrxLongCycleStartOffset  drxLongCycleStartOffset,\
7316 struct DRX_ConfigRrc__drx_LongCycleStartOffset *drx_LongCycleStartOffset)
7317 {
7318    
7319    drx_LongCycleStartOffset->present = convertLongDrxCycleLengthValueToEnum(drxLongCycleStartOffset.drxLongCycleStartOffsetChoice); 
7320    switch(drx_LongCycleStartOffset->present)
7321    {
7322       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
7323          {
7324             drx_LongCycleStartOffset->choice.ms10 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7325             break;
7326          }
7327       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
7328          {
7329             drx_LongCycleStartOffset->choice.ms20 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7330             break;
7331          }
7332       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
7333          {
7334             drx_LongCycleStartOffset->choice.ms32 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7335             break;
7336          }
7337       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
7338          {
7339             drx_LongCycleStartOffset->choice.ms40 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7340             break;
7341          }
7342       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
7343          {
7344             drx_LongCycleStartOffset->choice.ms60 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7345             break;
7346          }
7347       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
7348          {
7349             drx_LongCycleStartOffset->choice.ms64 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7350             break;
7351          }
7352       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
7353          {
7354             drx_LongCycleStartOffset->choice.ms70 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7355             break;
7356          }
7357       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
7358          {
7359             drx_LongCycleStartOffset->choice.ms80 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7360             break;
7361          }
7362       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
7363          {
7364             drx_LongCycleStartOffset->choice.ms128 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7365             break;
7366          }
7367       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
7368          {
7369             drx_LongCycleStartOffset->choice.ms160 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7370             break;
7371          }
7372       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
7373          {
7374             drx_LongCycleStartOffset->choice.ms256 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7375             break;
7376          }
7377       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
7378          {
7379             drx_LongCycleStartOffset->choice.ms320 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7380             break;
7381          }
7382       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
7383          {
7384             drx_LongCycleStartOffset->choice.ms512 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7385             break;
7386          }
7387       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
7388          {
7389             drx_LongCycleStartOffset->choice.ms640 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7390             break;
7391          }
7392       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
7393          {
7394             drx_LongCycleStartOffset->choice.ms1024 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7395             break;
7396          }
7397       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
7398          {
7399             drx_LongCycleStartOffset->choice.ms1280 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7400             break;
7401          }
7402       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
7403          {
7404             drx_LongCycleStartOffset->choice.ms2048 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7405             break;
7406          }
7407       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
7408          {
7409             drx_LongCycleStartOffset->choice.ms2560 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7410             break;
7411          }
7412       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
7413          {
7414             drx_LongCycleStartOffset->choice.ms5120 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7415             break;
7416          }
7417       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
7418          {
7419             drx_LongCycleStartOffset->choice.ms10240 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7420             break;
7421          }
7422       default :
7423          break;
7424    }
7425 }
7426 /*******************************************************************
7427  *
7428  * @brief Builds drx config IE 
7429  *
7430  * @details
7431  *
7432  *    Function : BuildDrxConfigRrc 
7433  *
7434  *    Functionality: Build drx config in MacCellGrpCfg 
7435  *
7436  * @params[in] struct MAC_CellGroupConfig__drx_ConfigRrc 
7437  *
7438  * @return ROK     - success
7439  *         RFAILED - failure
7440  *
7441  * ****************************************************************/
7442 uint8_t BuildDrxConfigRrc(DuUeCb *ueCb, struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg)
7443 {
7444    drxCfg->present = MAC_CellGroupConfig__drx_ConfigRrc_PR_setup;
7445    DU_ALLOC(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
7446    if(!drxCfg->choice.setup)
7447    {
7448       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7449       return RFAILED;
7450    }
7451    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationTimerValInMs)
7452    {
7453       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds;
7454       drxCfg->choice.setup->drx_onDurationTimer.choice.milliSeconds = convertOnDurationTimerMilliSecondsValueToEnum(ueCb->duMacUeCfg.\
7455       macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationtimerValue.milliSeconds);
7456    }
7457    else
7458    {
7459       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds;
7460       drxCfg->choice.setup->drx_onDurationTimer.choice.subMilliSeconds = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7461       drxOnDurationTimer.onDurationtimerValue.subMilliSeconds;
7462    }
7463    drxCfg->choice.setup->drx_InactivityTimer = convertDrxInactivityTimerValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxInactivityTimer);
7464    drxCfg->choice.setup->drx_HARQ_RTT_TimerDL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerDl;
7465    drxCfg->choice.setup->drx_HARQ_RTT_TimerUL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerUl;
7466    drxCfg->choice.setup->drx_RetransmissionTimerDL = convertDrxRetransmissionTimerDlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7467    drxRetransmissionTimerDl);
7468    drxCfg->choice.setup->drx_RetransmissionTimerUL = convertDrxRetransmissionTimerUlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7469    drxRetransmissionTimerUl);
7470    drxCfg->choice.setup->drx_SlotOffset = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxSlotOffset;
7471    fillLongCycleOffsetValFromDuCb(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxLongCycleStartOffset, &drxCfg->choice.setup->drx_LongCycleStartOffset);
7472    
7473    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrxPres)
7474    {
7475       DU_ALLOC(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));
7476       if(drxCfg->choice.setup->shortDRX)
7477       {
7478          drxCfg->choice.setup->shortDRX->drx_ShortCycle = convertShortDrxCycleLengthValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7479          shortDrx.drxShortCycle);
7480          drxCfg->choice.setup->shortDRX->drx_ShortCycleTimer = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrx.drxShortCycleTimer;
7481       }
7482       else
7483       {
7484          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7485          return RFAILED;
7486       }
7487    }
7488    return ROK;
7489 }
7490 #endif
7491 /*******************************************************************
7492  *
7493  * @brief Builds Mac cell group config 
7494  *
7495  * @details
7496  *
7497  *    Function : BuildMacCellGrpCfg 
7498  *
7499  *    Functionality: Builds Mac cell group config in DuToCuRrcContainer
7500  *
7501  * @params[in] MAC_CellGroupConfig_t *macCellGrpCfg
7502  *
7503  * @return ROK     - success
7504  *         RFAILED - failure
7505  *
7506  * ****************************************************************/
7507 uint8_t BuildMacCellGrpCfg(DuUeCb *ueCb, MAC_CellGroupConfig_t *macCellGrpCfg)
7508 {
7509    macCellGrpCfg->drx_ConfigRrc = NULLP;
7510 #ifdef NR_DRX   
7511    if(ueCb)
7512    {
7513       DU_ALLOC(macCellGrpCfg->drx_ConfigRrc, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
7514       if(!macCellGrpCfg->drx_ConfigRrc)
7515       {
7516          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7517          return RFAILED;
7518       }
7519       if(BuildDrxConfigRrc(ueCb, macCellGrpCfg->drx_ConfigRrc) != ROK)
7520       {
7521          DU_LOG("\nERROR  -->  F1AP : failed to build drx config");
7522          return RFAILED;
7523       }
7524    }
7525 #endif
7526    macCellGrpCfg->schedulingRequestConfig = NULLP;
7527    DU_ALLOC(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
7528    if(!macCellGrpCfg->schedulingRequestConfig)
7529    {
7530       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7531       return RFAILED;
7532    }
7533
7534    if(BuildSchedulingReqConfig(ueCb, macCellGrpCfg->schedulingRequestConfig) != ROK)
7535    {
7536       DU_LOG("\nERROR  -->  F1AP : BuildSchedulingReqConfig failed");
7537       return RFAILED;
7538    }
7539
7540    macCellGrpCfg->bsr_Config = NULLP;
7541    DU_ALLOC(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
7542    if(!macCellGrpCfg->bsr_Config)
7543    {
7544       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7545       return RFAILED;
7546    }
7547
7548    if(BuildBsrConfig(ueCb, macCellGrpCfg->bsr_Config) != ROK)
7549    {
7550       DU_LOG("\nERROR  -->  F1AP : BuildBsrConfig failed");
7551       return RFAILED;
7552    }
7553
7554    macCellGrpCfg->tag_Config = NULLP;
7555    DU_ALLOC(macCellGrpCfg->tag_Config, sizeof(struct TAG_Config));
7556    if(!macCellGrpCfg->tag_Config)
7557    {
7558       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7559       return RFAILED;
7560    }
7561
7562    if(BuildTagConfig(ueCb, macCellGrpCfg->tag_Config) != ROK)
7563    {
7564       DU_LOG("\nERROR  -->  F1AP : BuildTagConfig failed");
7565       return RFAILED;
7566    }
7567
7568    macCellGrpCfg->phr_Config = NULLP;
7569    DU_ALLOC(macCellGrpCfg->phr_Config, sizeof(struct MAC_CellGroupConfig__phr_Config));
7570    if(!macCellGrpCfg->phr_Config)
7571    {
7572       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7573       return RFAILED;
7574    }
7575
7576    if(BuildPhrConfig(ueCb, macCellGrpCfg->phr_Config) != ROK)
7577    {
7578       DU_LOG("\nERROR  -->  F1AP : BuildPhrConfig failed");
7579       return RFAILED;
7580    }
7581
7582    macCellGrpCfg->skipUplinkTxDynamic = false;
7583    macCellGrpCfg->ext1 = NULLP;
7584
7585    return ROK;
7586 }
7587 /*******************************************************************
7588  *
7589  * @brief Frees memeory allocated for SearchSpcToAddModList
7590  *
7591  * @details
7592  *
7593  *    Function : FreeSearchSpcToAddModList
7594  *
7595  *    Functionality: Deallocating memory of SearchSpcToAddModList
7596  *
7597  * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
7598  *
7599  * @return void
7600  *
7601  4221 * ****************************************************************/
7602 void FreeSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
7603 {
7604    uint8_t idx1=0;
7605    uint8_t idx2=0;
7606    struct  SearchSpace *searchSpc=NULLP;
7607
7608    if(searchSpcList->list.array)
7609    {
7610       if(searchSpcList->list.array[idx2])
7611       {
7612          searchSpc = searchSpcList->list.array[idx2];
7613          if(searchSpc->controlResourceSetId)
7614          {
7615             if(searchSpc->monitoringSlotPeriodicityAndOffset)
7616             {
7617                if(searchSpc->monitoringSymbolsWithinSlot)
7618                {
7619                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
7620                   {
7621                      if(searchSpc->nrofCandidates)
7622                      {
7623                         if(searchSpc->searchSpaceType)
7624                         {
7625                            DU_FREE(searchSpc->searchSpaceType->choice.ue_Specific,\
7626                                  sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
7627                            DU_FREE(searchSpc->searchSpaceType, sizeof(struct
7628                                     SearchSpace__searchSpaceType));
7629                         }
7630                         DU_FREE(searchSpc->nrofCandidates,
7631                               sizeof(struct SearchSpace__nrofCandidates));
7632                      }
7633                      DU_FREE(searchSpc->monitoringSymbolsWithinSlot->buf, \
7634                            searchSpc->monitoringSymbolsWithinSlot->size);
7635                   }
7636                   DU_FREE(searchSpc->monitoringSymbolsWithinSlot,
7637                         sizeof(BIT_STRING_t));
7638                }
7639                DU_FREE(searchSpc->monitoringSlotPeriodicityAndOffset, \
7640                      sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
7641             }
7642             DU_FREE(searchSpc->controlResourceSetId,
7643                   sizeof(ControlResourceSetId_t));
7644          }
7645       }
7646       for(idx1 = 0; idx1 < searchSpcList->list.count; idx1++)
7647       {
7648          DU_FREE(searchSpcList->list.array[idx1],
7649                sizeof(struct SearchSpace));
7650       }
7651       DU_FREE(searchSpcList->list.array,searchSpcList->list.size);
7652    }
7653 }
7654 /*******************************************************************
7655  *
7656  * @brief Frees memory allocated for PdschTimeDomAllocList
7657  *
7658  * @details
7659  *
7660  *    Function : FreePdschTimeDomAllocList
7661  *
7662  *    Functionality: Deallocating memory of PdschTimeDomAllocList
7663  *
7664  * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
7665  *
7666  * @return void
7667  *
7668  * ****************************************************************/
7669 void FreePdschTimeDomAllocList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
7670 {
7671    uint8_t idx1=0;
7672
7673    if(timeDomAllocList->choice.setup)
7674    {
7675       if(timeDomAllocList->choice.setup->list.array)
7676       {
7677          for(idx1 = 0; idx1 <timeDomAllocList->choice.setup->list.count ; idx1++)
7678          {
7679             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1]->k0, sizeof(long));
7680             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1],
7681                   sizeof(struct PDSCH_TimeDomainResourceAllocation));
7682          }
7683          DU_FREE(timeDomAllocList->choice.setup->list.array, \
7684                timeDomAllocList->choice.setup->list.size);
7685       }
7686       DU_FREE(timeDomAllocList->choice.setup,\
7687             sizeof(struct PDSCH_TimeDomainResourceAllocationList));
7688    }
7689 }
7690 /*******************************************************************
7691  *
7692  * @brief Frees memory allocated for PuschTimeDomAllocList
7693  *
7694  *@details
7695  *
7696  *    Function : FreePuschTimeDomAllocList
7697  *
7698  *    Functionality: Deallocating memory of PuschTimeDomAllocList
7699  *
7700  * @params[in] PUSCH_Config_t *puschCfg
7701  *
7702  * @return void
7703  *
7704  * ****************************************************************/
7705 void FreePuschTimeDomAllocList(PUSCH_Config_t *puschCfg)
7706 {
7707    uint8_t rsrcListIdx=0;
7708    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
7709
7710    if(puschCfg->pusch_TimeDomainAllocationList)
7711    {
7712       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
7713       if(timeDomAllocList_t->choice.setup)
7714       {
7715          if(timeDomAllocList_t->choice.setup->list.array)
7716          {
7717             for(rsrcListIdx = 0; rsrcListIdx<timeDomAllocList_t->choice.setup->list.count; rsrcListIdx++)
7718             {
7719                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx]->k2, sizeof(long));
7720                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx],\
7721                      sizeof(PUSCH_TimeDomainResourceAllocation_t));
7722             }
7723             DU_FREE(timeDomAllocList_t->choice.setup->list.array, \
7724                   timeDomAllocList_t->choice.setup->list.size);
7725          }
7726          DU_FREE(timeDomAllocList_t->choice.setup, \
7727                sizeof(struct PUSCH_TimeDomainResourceAllocationList));
7728       }
7729       DU_FREE(puschCfg->transformPrecoder, sizeof(long));
7730       DU_FREE(puschCfg->pusch_TimeDomainAllocationList, \
7731             sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
7732    }
7733
7734 }
7735
7736 /*******************************************************************
7737  *
7738  * @brief Frees memory allocated for Dedicated PUCCH config
7739  *
7740  * @details
7741  *
7742  *    Function : FreeBWPUlDedPucchCfg
7743  *
7744  *    Functionality: Deallocating memory of Dedicated PUCCH cfg
7745  *
7746  * @params[in] BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg
7747  *
7748  * @return void
7749  *
7750  * ****************************************************************/
7751 void FreeBWPUlDedPucchCfg(struct BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg)
7752 {
7753    uint8_t k1Idx, rsrcIdx, rsrcSetIdx;
7754    PUCCH_Config_t *pucchCfg = NULLP;
7755    PUCCH_ResourceSet_t *rsrcSet = NULLP;
7756    PUCCH_Resource_t *rsrc = NULLP;
7757
7758    if(ulBwpPucchCfg)
7759    {
7760       if(ulBwpPucchCfg->choice.setup)
7761       {
7762          pucchCfg = ulBwpPucchCfg->choice.setup;
7763
7764          //Free resource set list
7765          if(pucchCfg->resourceSetToAddModList)
7766          {
7767             if(pucchCfg->resourceSetToAddModList->list.array)
7768             {
7769                for(rsrcSetIdx=0; rsrcSetIdx < pucchCfg->resourceSetToAddModList->list.count; rsrcSetIdx++)
7770                {
7771                   rsrcSet = pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx];
7772                   if(rsrcSet->resourceList.list.array)
7773                   {
7774                      for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
7775                      {
7776                         DU_FREE(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
7777                      }
7778                      DU_FREE(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
7779                   }
7780                   DU_FREE(pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
7781                }
7782                DU_FREE(pucchCfg->resourceSetToAddModList->list.array, pucchCfg->resourceSetToAddModList->list.size);
7783             }
7784             DU_FREE(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
7785          }
7786
7787          //Free resource list
7788          if(pucchCfg->resourceToAddModList)
7789          {
7790             if(pucchCfg->resourceToAddModList->list.array)
7791             {
7792                for(rsrcIdx=0; rsrcIdx < pucchCfg->resourceToAddModList->list.count; rsrcIdx++)
7793                {
7794                   rsrc = pucchCfg->resourceToAddModList->list.array[rsrcIdx];
7795                   DU_FREE(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
7796                   DU_FREE(pucchCfg->resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
7797                }
7798                DU_FREE(pucchCfg->resourceToAddModList->list.array, pucchCfg->resourceToAddModList->list.size);
7799             }
7800             DU_FREE(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
7801          }
7802
7803          //PUCCH Format 1
7804          if(pucchCfg->format1)
7805          {
7806             if(pucchCfg->format1->choice.setup)
7807             {
7808                DU_FREE(pucchCfg->format1->choice.setup->nrofSlots, sizeof(long));
7809                DU_FREE(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
7810             }
7811             DU_FREE(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
7812          }
7813          
7814          //DL DATA TO UL ACK
7815          if(pucchCfg->dl_DataToUL_ACK)
7816          {
7817             if(pucchCfg->dl_DataToUL_ACK->list.array)
7818             {
7819                for(k1Idx = 0; k1Idx <  pucchCfg->dl_DataToUL_ACK->list.count; k1Idx++)
7820                {
7821                   DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array[k1Idx], sizeof(long));
7822                }
7823                DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array, pucchCfg->dl_DataToUL_ACK->list.size);
7824             }
7825             DU_FREE(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
7826          }
7827
7828          DU_FREE(ulBwpPucchCfg->choice.setup, sizeof(PUCCH_Config_t));
7829       }
7830       DU_FREE(ulBwpPucchCfg, sizeof(struct BWP_UplinkDedicated__pucch_Config));
7831    }
7832 }
7833
7834 /*******************************************************************
7835  *
7836  * @brief Frees memory allocated for InitialUlBWP
7837  *
7838  * @details
7839  *
7840  *    Function : FreeInitialUlBWP
7841  *
7842  *    Functionality: Deallocating memory of InitialUlBWP
7843  *
7844  * @params[in] BWP_UplinkDedicated_t *ulBwp
7845  *
7846  * @return void
7847  *
7848  * ****************************************************************/
7849 void FreeInitialUlBWP(BWP_UplinkDedicated_t *ulBwp)
7850 {
7851    uint8_t  rSetIdx, rsrcIdx;
7852    SRS_Config_t   *srsCfg = NULLP;
7853    PUSCH_Config_t *puschCfg = NULLP;
7854    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
7855    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
7856    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
7857    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
7858
7859    FreeBWPUlDedPucchCfg(ulBwp->pucch_Config);
7860
7861    if(ulBwp->pusch_Config)
7862    {
7863       if(ulBwp->pusch_Config->choice.setup)
7864       {
7865          puschCfg=ulBwp->pusch_Config->choice.setup;
7866          if(puschCfg->dataScramblingIdentityPUSCH)
7867          {
7868             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
7869             {
7870                FreePuschTimeDomAllocList(puschCfg);
7871                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
7872                if(dmrsUlCfg->choice.setup)
7873                {
7874                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
7875                   {
7876                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
7877                      {
7878                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
7879                               sizeof(long));
7880                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled,
7881                               sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
7882                      }
7883                      DU_FREE(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition,
7884                            sizeof(long));
7885                   }
7886                   DU_FREE(dmrsUlCfg->choice.setup,sizeof(DMRS_UplinkConfig_t));
7887                }
7888                DU_FREE(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, \
7889                      sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
7890             }
7891             DU_FREE(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
7892          }
7893          DU_FREE(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
7894       }
7895       DU_FREE(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
7896
7897       /* Free SRS-Config */
7898       if(ulBwp->srs_Config)
7899       {
7900          if(ulBwp->srs_Config->choice.setup)
7901          {
7902             srsCfg = ulBwp->srs_Config->choice.setup;
7903
7904             /* Free Resource Set to add/mod list */
7905             if(srsCfg->srs_ResourceSetToAddModList)
7906             {
7907                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
7908                if(rsrcSetList->list.array)
7909                {
7910                   rSetIdx = 0;
7911
7912                   /* Free SRS resource Id list in this SRS resource set */
7913                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
7914                   {
7915                      rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
7916
7917                      if(rsrcIdList->list.array)
7918                      {
7919                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
7920                         {
7921                            DU_FREE(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
7922                         }
7923                         DU_FREE(rsrcIdList->list.array, rsrcIdList->list.size);
7924                      }
7925                      DU_FREE(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
7926                            sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
7927                   }
7928
7929                   /* Free resource type info for this SRS resource set */
7930                   DU_FREE(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
7931                         sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
7932
7933                   /* Free memory for each resource set */
7934                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
7935                   {
7936                      DU_FREE(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
7937                   }
7938                   DU_FREE(rsrcSetList->list.array, rsrcSetList->list.size); 
7939                }
7940                DU_FREE(srsCfg->srs_ResourceSetToAddModList, \
7941                      sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
7942             }
7943
7944             /* Free resource to add/modd list */
7945             if(srsCfg->srs_ResourceToAddModList)
7946             {
7947                resourceList = srsCfg->srs_ResourceToAddModList;
7948                if(resourceList->list.array)
7949                {
7950                   rsrcIdx = 0;
7951                   DU_FREE(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2,\
7952                         sizeof(struct SRS_Resource__transmissionComb__n2));
7953                   DU_FREE(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,\
7954                         sizeof(struct SRS_Resource__resourceType__aperiodic));
7955
7956                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
7957                   {
7958                      DU_FREE(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
7959                   }
7960                   DU_FREE(resourceList->list.array, resourceList->list.size);
7961                }
7962                DU_FREE(srsCfg->srs_ResourceToAddModList, \
7963                      sizeof(struct SRS_Config__srs_ResourceToAddModList));
7964             }
7965
7966             DU_FREE(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
7967          }
7968          DU_FREE(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
7969       }
7970    }
7971 }       
7972 /*******************************************************************
7973  *
7974  * @brief Frees memory allocated for initialUplinkBWP
7975  *
7976  * @details
7977  *
7978  *    Function : FreeinitialUplinkBWP
7979  *
7980  *    Functionality: Deallocating memory of initialUplinkBWP
7981  *
7982  * @params[in] UplinkConfig_t *ulCfg
7983  *
7984  * @return void
7985  *         
7986  *
7987  * ****************************************************************/
7988 void FreeinitialUplinkBWP(UplinkConfig_t *ulCfg)
7989 {
7990    BWP_UplinkDedicated_t *ulBwp=NULLP; 
7991    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
7992
7993    if(ulCfg->initialUplinkBWP)
7994    {
7995       ulBwp=ulCfg->initialUplinkBWP;
7996       if(ulCfg->firstActiveUplinkBWP_Id)
7997       {
7998          if(ulCfg->pusch_ServingCellConfig)
7999          {
8000             puschCfg=ulCfg->pusch_ServingCellConfig;
8001             if(puschCfg->choice.setup)
8002             {
8003                if(puschCfg->choice.setup->ext1)
8004                {
8005                   DU_FREE(puschCfg->choice.setup->ext1->\
8006                         processingType2Enabled,sizeof(BOOLEAN_t));
8007                   DU_FREE(puschCfg->choice.setup->ext1->\
8008                         maxMIMO_Layers,sizeof(long));
8009                   DU_FREE(puschCfg->choice.setup->ext1, \
8010                         sizeof(struct PUSCH_ServingCellConfig__ext1));
8011                }
8012                DU_FREE(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
8013             }
8014             DU_FREE(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
8015          }
8016          DU_FREE(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
8017       }
8018       FreeInitialUlBWP(ulBwp);
8019       DU_FREE(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
8020    }
8021 }
8022 /*******************************************************************
8023  *
8024  * @brief Frees emmory allocated for BWPDlDedPdschCfg
8025  *
8026  * @details
8027  *
8028  *    Function : FreeBWPDlDedPdschCfg
8029  *
8030  *    Functionality: Deallocating memory of BWPDlDedPdschCfg
8031  *
8032  * @params[in] BWP_DownlinkDedicated_t *dlBwp
8033  *
8034  * @return void
8035  *
8036  *
8037  * ****************************************************************/
8038 void FreeBWPDlDedPdschCfg(BWP_DownlinkDedicated_t *dlBwp)
8039 {
8040    struct PDSCH_Config *pdschCfg=NULLP;
8041    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
8042    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
8043    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
8044
8045    if(dlBwp->pdsch_Config->choice.setup)
8046    {
8047       pdschCfg=dlBwp->pdsch_Config->choice.setup;
8048       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
8049       {
8050          if(pdschCfg->pdsch_TimeDomainAllocationList)
8051          {
8052             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
8053             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
8054             {
8055                prbBndlType=&pdschCfg->prb_BundlingType;
8056                DU_FREE(prbBndlType->choice.staticBundling,\
8057                      sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
8058                DU_FREE(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
8059             }
8060             FreePdschTimeDomAllocList(timeDomAllocList);
8061             DU_FREE(pdschCfg->pdsch_TimeDomainAllocationList, \
8062                   sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
8063          }
8064          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
8065          if(dmrsDlCfg->choice.setup)
8066          {
8067             DU_FREE(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition,
8068                   sizeof(long));
8069             DU_FREE(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
8070          }
8071          DU_FREE(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, \
8072                sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
8073       }
8074       DU_FREE(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
8075    }
8076 }
8077 /*******************************************************************
8078  *
8079  * @brief Frees emmory allocated for BWPDlDedPdcchCfg
8080  *
8081  * @details
8082  *
8083  *    Function : FreeBWPDlDedPdcchCfg
8084  *
8085  *    Functionality: Deallocating memory of BWPDlDedPdcchCfg
8086  *
8087  * @params[in] BWP_DownlinkDedicated_t *dlBwp
8088  *
8089  * @return void
8090  *         
8091  *
8092  * ****************************************************************/
8093 void FreeBWPDlDedPdcchCfg(BWP_DownlinkDedicated_t *dlBwp)
8094 {
8095    uint8_t idx1=0;
8096    uint8_t idx2=0;
8097    struct PDCCH_Config *pdcchCfg=NULLP;
8098    struct ControlResourceSet *controlRSet=NULLP;
8099    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
8100
8101    if(dlBwp->pdcch_Config->choice.setup)
8102    {
8103       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
8104       if(pdcchCfg->controlResourceSetToAddModList)
8105       {
8106          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
8107          if(controlRSetList->list.array)
8108          {
8109             controlRSet = controlRSetList->list.array[idx2];
8110             if(controlRSet)
8111             {
8112                if(controlRSet->frequencyDomainResources.buf)
8113                {
8114                   if(controlRSet->pdcch_DMRS_ScramblingID)
8115                   {
8116                      if(pdcchCfg->searchSpacesToAddModList)
8117                      {
8118                         FreeSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
8119                         DU_FREE(pdcchCfg->searchSpacesToAddModList, \
8120                               sizeof(struct PDCCH_Config__searchSpacesToAddModList));
8121                      }
8122                      DU_FREE(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
8123                   }
8124                   DU_FREE(controlRSet->frequencyDomainResources.buf, \
8125                         controlRSet->frequencyDomainResources.size);
8126                }
8127             }
8128             for(idx1 = 0; idx1 <controlRSetList->list.count; idx1++)
8129             {
8130                DU_FREE(controlRSetList->list.array[idx1], sizeof(struct ControlResourceSet));
8131             }
8132             DU_FREE(controlRSetList->list.array, controlRSetList->list.size);
8133          }
8134          DU_FREE(pdcchCfg->controlResourceSetToAddModList, \
8135                sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
8136       }
8137       DU_FREE(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
8138    }
8139 }       
8140
8141 /*******************************************************************
8142  *
8143  * @brief Free SCS specific carrier list in DL frequency info
8144  *
8145  * @details
8146  *
8147  *    Function : FreeScsSpecificCarrierListDl
8148  *
8149  *    Functionality: Free SCS specific carrier list in DL frequency info
8150  *
8151  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
8152  *
8153  * @return void
8154  *
8155  * ****************************************************************/
8156 void FreeScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
8157 {
8158    uint8_t listIdx = 0;
8159
8160    if(!scsCarrierList->list.array)
8161    {
8162       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
8163       {
8164          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
8165       }
8166       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
8167    }
8168 }
8169
8170 /*******************************************************************
8171  *
8172  * @brief Free DL frequency info in DL config common
8173  *
8174  * @details
8175  *
8176  *    Function : FreeFreqInfoDl
8177  *
8178  *    Functionality: Free DL frequency info in DL config common
8179  *
8180  * @params[in] Pointer to DownlinkConfigCommon_t
8181  *
8182  * @return void
8183  *
8184  * ****************************************************************/
8185 void FreeFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
8186 {
8187    uint8_t freqBandIdx = 0;
8188
8189    /* SSB Absolute Frequency */
8190    DU_FREE(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
8191
8192    /* NR Multi Frequency Band List */
8193    if(frequencyInfoDL->frequencyBandList.list.array)
8194    {
8195       for(freqBandIdx = 0; freqBandIdx < frequencyInfoDL->frequencyBandList.list.count; freqBandIdx++)
8196       {
8197          DU_FREE(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
8198       }
8199       DU_FREE(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
8200    }
8201
8202    /* Subcarrier Spacing specifc carrier List */
8203    FreeScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList);
8204 }
8205
8206 /*******************************************************************
8207  *
8208  * @brief Free DL config common in Serving cell config common
8209  *
8210  * @details
8211  *
8212  *    Function : FreeDlConfigCommon
8213  *
8214  *    Functionality: Free DL config common in Serving cell config common
8215  *
8216  * @params[in] Pointer to DownlinkConfigCommon_t
8217  *
8218  * @return void
8219  *
8220  * ****************************************************************/
8221 void FreeDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
8222 {
8223    /* DL Frequency Info */
8224    if(dlCfgCommon->frequencyInfoDL)
8225    {
8226       FreeFreqInfoDl(dlCfgCommon->frequencyInfoDL);
8227       DU_FREE(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
8228    }
8229
8230    /* DL BWP config common */
8231    if(dlCfgCommon->initialDownlinkBWP)
8232    {
8233       FreeBwpDlCommon(dlCfgCommon->initialDownlinkBWP);
8234       DU_FREE(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
8235    }
8236 }
8237
8238 /*******************************************************************
8239  *
8240  * @brief Free SCS specific carrier list in UL frequency Info
8241  *
8242  * @details
8243  *
8244  *    Function : FreeScsSpecificCarrierListUl
8245  *
8246  *    Functionality: Free SCS specific carrier list in UL frequency Info
8247  *
8248  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
8249  *
8250  * @return void
8251  *
8252  * ****************************************************************/
8253 void FreeScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
8254 {
8255    uint8_t listIdx = 0;
8256
8257    if(scsCarrierList->list.array)
8258    {
8259       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
8260       {
8261          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
8262       }
8263       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
8264    }
8265 }
8266
8267 /*******************************************************************
8268  *
8269  * @brief Free frequency info in UL config common
8270  *
8271  * @details
8272  *
8273  *    Function : FreeFreqInfoUl
8274  *
8275  *    Functionality: Free frequency info in UL config common
8276  *
8277  * @params[in] Pointer to FrequencyInfoUL_t
8278  *
8279  * @return void
8280  *
8281  * ****************************************************************/
8282 void FreeFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
8283 {
8284    uint8_t listIdx= 0;
8285
8286    /* NR Multi Frequency Band List */
8287    if(!frequencyInfoUL->frequencyBandList)
8288    {
8289       if(frequencyInfoUL->frequencyBandList->list.array)
8290       {
8291          for(listIdx = 0; listIdx < frequencyInfoUL->frequencyBandList->list.count; listIdx++)
8292          {
8293             DU_FREE(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
8294          }
8295          DU_FREE(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
8296       }
8297       DU_FREE(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
8298    }
8299
8300    /* Absolute frequency point A */
8301    DU_FREE(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
8302
8303    /* Subcarrier Spacing specifc carrier */
8304    FreeScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList);
8305
8306    /* P-MAX */
8307    DU_FREE(frequencyInfoUL->p_Max, sizeof(P_Max_t));
8308 }
8309
8310 /*******************************************************************
8311  *
8312  * @brief Free UL config common in Serving cell config common
8313  *
8314  * @details
8315  *
8316  *    Function : FreeUlConfigCommon
8317  *
8318  *    Functionality: Free UL config common in Serving cell config common
8319  *
8320  * @params[in] Pointer to UplinkConfigCommon_t
8321  *
8322  * @return void
8323  *
8324  * ****************************************************************/
8325 void FreeUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
8326 {
8327    /* UL Frequency Info */
8328    if(ulCfgCommon->frequencyInfoUL)
8329    {
8330       FreeFreqInfoUl(ulCfgCommon->frequencyInfoUL);
8331       DU_FREE(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
8332    }
8333
8334    /* UL BWP common */
8335    if(ulCfgCommon->initialUplinkBWP)
8336    {
8337       FreeBwpUlCommon(ulCfgCommon->initialUplinkBWP);
8338       DU_FREE(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
8339    }
8340 }
8341
8342 /*******************************************************************
8343  *
8344  * @brief Free SP cell config common in Reconfig with Sync
8345  *
8346  * @details
8347  *
8348  *    Function : FreeSpCellConfigCommon
8349  *
8350  *    Functionality: Free SP cell config common in Reconfig with Sync
8351  *
8352  * @params[in] Pointer to ServingCellConfigCommon_t
8353  *
8354  * @return void
8355  *
8356  * ****************************************************************/
8357 void FreeSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
8358 {
8359    /* Free Physical cell identity */
8360    DU_FREE(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
8361
8362    /* Free Downlink Config common */
8363    if(spCellConfigCommon->downlinkConfigCommon)
8364    {
8365       FreeDlConfigCommon(spCellConfigCommon->downlinkConfigCommon);
8366       DU_FREE(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
8367    }
8368
8369    /* Free Uplink Config common */
8370    if(spCellConfigCommon->uplinkConfigCommon)
8371    {
8372       FreeUlConfigCommon(spCellConfigCommon->uplinkConfigCommon);
8373       DU_FREE(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
8374    }
8375
8376    /* Free Timing Advance offset */
8377    DU_FREE(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
8378
8379    /* Free SSB Position in Burst */
8380    if(spCellConfigCommon->ssb_PositionsInBurst)
8381    {
8382       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.buf, \
8383          spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.size);
8384       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
8385    }
8386
8387    /* Free SSB Periodicity in Serving cell */
8388    DU_FREE(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
8389
8390    /* Free SSB subcarrier spacing */
8391    DU_FREE(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
8392
8393    /* TDD UL-DL configuration common */
8394    DU_FREE(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
8395 }
8396
8397 /*******************************************************************
8398  *
8399  * @brief Free dedicated RACH configuration in Reconfiguration with sync
8400  *
8401  * @details
8402  *
8403  *    Function : FreeRecfgWithSync
8404  *
8405  *    Functionality:
8406  *       Free dedicated RACH configuration in Reconfiguration with sync
8407  *
8408  * @params[in] Pinter to Rach config dedicated struct
8409  *
8410  * @return void
8411  *
8412  * ****************************************************************/
8413 void FreeRachConfigDedicated(struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
8414 {
8415    uint8_t listIdx = 0;
8416    CFRA_t *cfra = NULLP;
8417    struct CFRA__resources__ssb *ssbResource = NULLP;
8418
8419    /* Uplink */
8420    if(rachCfgDed->choice.uplink)
8421    {
8422       /* CFRA : Contention free Random Access */
8423       if(rachCfgDed->choice.uplink->cfra)
8424       {
8425          cfra = rachCfgDed->choice.uplink->cfra;
8426
8427          /* CFRA occassions */
8428          if(cfra->occasions)
8429          {
8430             /* CFRA occassions : SSB per RACH occasion */
8431             DU_FREE(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
8432             DU_FREE(cfra->occasions, sizeof(struct CFRA__occasions));
8433          }
8434
8435          /* CFRA resource */
8436          cfra->resources.present = CFRA__resources_PR_ssb;
8437
8438          /* CFRA resource : SSB */
8439          if(cfra->resources.choice.ssb)
8440          {
8441             ssbResource = cfra->resources.choice.ssb;
8442
8443             /* CFRA SSB resource list */
8444             if(ssbResource->ssb_ResourceList.list.array)
8445             {
8446                for(listIdx = 0; listIdx < ssbResource->ssb_ResourceList.list.count; listIdx++)
8447                {
8448                   DU_FREE(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
8449                }
8450                DU_FREE(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
8451             }
8452             DU_FREE(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
8453          }
8454          DU_FREE(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
8455       }
8456       DU_FREE(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
8457    }
8458 }
8459
8460 /*******************************************************************
8461  *
8462  * @brief Frees reconfiguration with sync in SP cell config
8463  *
8464  * @details
8465  *
8466  *    Function : FreeRecfgWithSync
8467  *
8468  *    Functionality: Fress reconfiguration with sync in SP cell config
8469  *
8470  * @params[in] Pointer to ReconfigurationWithSync_t
8471  *
8472  * @return void
8473  *
8474  * ****************************************************************/
8475 void FreeRecfgWithSync(ReconfigurationWithSync_t *recfgWithSync)
8476 {
8477    /* Free SP Cell config common */
8478    if(recfgWithSync->spCellConfigCommon)
8479    {
8480       FreeSpCellConfigCommon(recfgWithSync->spCellConfigCommon);
8481       DU_FREE(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
8482    }
8483
8484    /* Free Dedicated RACH configuration */
8485    if(recfgWithSync->rach_ConfigDedicated)
8486    {
8487       FreeRachConfigDedicated(recfgWithSync->rach_ConfigDedicated);
8488       DU_FREE(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
8489    }
8490 }
8491
8492 /*******************************************************************
8493  *
8494  * @brief Frees emmory allocated for DUToCURRCContainer 
8495  *
8496  * @details
8497  *
8498  *    Function : FreeMemDuToCuRrcCont
8499  *
8500  *    Functionality: Deallocating memory of DuToCuRrcContainer
8501  *
8502  * @params[in] DuToCuRRCContainer, DuToCuRRCContainer
8503  *
8504  * @return ROK     - success
8505  *         RFAILED - failure
8506  *
8507  * ****************************************************************/
8508 uint8_t FreeMemDuToCuRrcCont(CellGroupConfigRrc_t *cellGrpCfg)
8509 {
8510    uint8_t idx=0;
8511    SpCellConfig_t *spCellCfg=NULLP;
8512    ServingCellConfig_t *srvCellCfg=NULLP;
8513    BWP_DownlinkDedicated_t *dlBwp=NULLP;
8514    MAC_CellGroupConfig_t *macCellGrpCfg=NULLP;
8515    PhysicalCellGroupConfig_t *phyCellGrpCfg=NULLP;
8516    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList=NULLP;
8517    struct RLC_Config *rlcConfig=NULLP;
8518    struct LogicalChannelConfig *macLcConfig=NULLP;
8519    struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg=NULLP;
8520    struct SchedulingRequestConfig *schedulingRequestConfig=NULLP;
8521    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList=NULLP;
8522    struct TAG_Config *tagConfig=NULLP;
8523    struct TAG_Config__tag_ToAddModList *tagList=NULLP;
8524    struct MAC_CellGroupConfig__phr_Config *phrConfig=NULLP;
8525    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg=NULLP;
8526
8527    rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
8528    if(rlcBearerList)
8529    {
8530       if(rlcBearerList->list.array)
8531       {
8532          for(idx=0; idx<rlcBearerList->list.count; idx++)
8533          {
8534             if(rlcBearerList->list.array[idx])
8535             {  
8536                rlcConfig   = rlcBearerList->list.array[idx]->rlc_Config;
8537                macLcConfig = rlcBearerList->list.array[idx]->mac_LogicalChannelConfig;
8538                if(rlcConfig)
8539                {
8540                   switch(rlcConfig->present)
8541                   {
8542                      case RLC_Config_PR_NOTHING:
8543                         break;
8544
8545                      case RLC_Config_PR_am:
8546                         {
8547                            if(rlcConfig->choice.am)
8548                            {
8549                               DU_FREE(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
8550                               DU_FREE(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
8551                               DU_FREE(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
8552                            }
8553                            break;
8554                         }
8555                      case RLC_Config_PR_um_Bi_Directional:
8556                         {
8557                            if(rlcConfig->choice.um_Bi_Directional)
8558                            {
8559                               DU_FREE(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t)); 
8560                               DU_FREE(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8561                               DU_FREE(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
8562                            }
8563                            break;
8564                         }
8565                      case RLC_Config_PR_um_Uni_Directional_UL:
8566                         {
8567                            if(rlcConfig->choice.um_Uni_Directional_UL)
8568                            {
8569                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8570                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
8571                            }
8572                            break;
8573                         }
8574                      case RLC_Config_PR_um_Uni_Directional_DL:
8575                         {
8576                            if(rlcConfig->choice.um_Uni_Directional_DL )
8577                            {
8578                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8579                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
8580                            }
8581                            break;
8582                         }
8583                   }     
8584                   DU_FREE(rlcConfig, sizeof(struct RLC_Config));
8585                }
8586                DU_FREE(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
8587                if(macLcConfig)
8588                {
8589                   if(macLcConfig->ul_SpecificParameters)
8590                   {
8591                      DU_FREE(macLcConfig->ul_SpecificParameters->schedulingRequestID,   sizeof(SchedulingRequestId_t));
8592                      DU_FREE(macLcConfig->ul_SpecificParameters->logicalChannelGroup,   sizeof(long));
8593                      DU_FREE(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
8594                   }
8595                   DU_FREE(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
8596                }
8597                DU_FREE(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
8598             }   
8599          }
8600          DU_FREE(rlcBearerList->list.array, rlcBearerList->list.size);
8601       }
8602       DU_FREE(cellGrpCfg->rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8603    }
8604
8605    macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
8606    if(macCellGrpCfg)
8607    {
8608       drxCfg = macCellGrpCfg->drx_ConfigRrc;
8609
8610       if(drxCfg)
8611       {
8612           switch(drxCfg->present)
8613           {
8614             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
8615                break;
8616             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
8617             {
8618                if(drxCfg->choice.setup)
8619                {
8620                   DU_FREE(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));  
8621                   DU_FREE(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
8622                }
8623             }
8624             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
8625                break;
8626           }
8627           DU_FREE(drxCfg, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
8628       }
8629       schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig; 
8630       if(schedulingRequestConfig)
8631       {
8632          schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
8633          if(schReqList)
8634          {
8635             if(schReqList->list.array)
8636             {
8637                for(idx=0;idx<schReqList->list.count; idx++)
8638                {
8639                   if(schReqList->list.array[idx])
8640                   {
8641                      DU_FREE(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
8642                      DU_FREE(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
8643                   }
8644                }
8645                DU_FREE(schReqList->list.array, schReqList->list.size);
8646             }
8647             DU_FREE(schedulingRequestConfig->schedulingRequestToAddModList,\
8648                   sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));    }
8649             DU_FREE(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
8650       }
8651       if(macCellGrpCfg->bsr_Config)
8652       {
8653          DU_FREE(macCellGrpCfg->bsr_Config->logicalChannelSR_DelayTimer, sizeof(long));
8654          DU_FREE(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
8655       }
8656       tagConfig = macCellGrpCfg->tag_Config;
8657       if(tagConfig)
8658       {
8659          tagList = tagConfig->tag_ToAddModList;
8660          if(tagList)
8661          {
8662             if(tagList->list.array)
8663             {
8664                for(idx=0; idx<tagList->list.count; idx++)
8665                {
8666                   DU_FREE(tagList->list.array[idx], sizeof(struct TAG));
8667                }
8668                DU_FREE(tagList->list.array, tagList->list.size);
8669             }
8670             DU_FREE(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
8671          }
8672          DU_FREE(tagConfig, sizeof(struct TAG_Config));
8673       }
8674
8675       phrConfig = macCellGrpCfg->phr_Config;
8676       if(phrConfig)
8677       {
8678          DU_FREE(phrConfig->choice.setup, sizeof(struct PHR_Config));
8679          DU_FREE(phrConfig, sizeof(struct MAC_CellGroupConfig__phr_Config));
8680       }
8681
8682       DU_FREE(macCellGrpCfg, sizeof(MAC_CellGroupConfig_t));
8683    }
8684
8685    phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
8686    if(phyCellGrpCfg)
8687    {
8688       DU_FREE(phyCellGrpCfg->p_NR_FR1, sizeof(long));
8689       DU_FREE(phyCellGrpCfg, sizeof(PhysicalCellGroupConfig_t));
8690    }
8691
8692    spCellCfg = cellGrpCfg->spCellConfig;
8693    if(spCellCfg)
8694    {
8695       /* Free serving cell index */
8696       DU_FREE(spCellCfg->servCellIndex, sizeof(long));
8697
8698       /* Free Reconfiguration with sync */
8699       if(spCellCfg->reconfigurationWithSync)
8700       {
8701          FreeRecfgWithSync(spCellCfg->reconfigurationWithSync);
8702          DU_FREE(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
8703       }
8704
8705       /* Free rlmInSyncOutOfSyncThreshold */
8706       DU_FREE(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
8707
8708       /* Free SP Cell config dedicated */
8709       if(spCellCfg->spCellConfigDedicated)
8710       {
8711          srvCellCfg = spCellCfg->spCellConfigDedicated;
8712
8713          /* Free TDD UL-DL config dedicated */
8714          DU_FREE(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
8715
8716          /* Free Initial Downlink BWP */
8717          if(srvCellCfg->initialDownlinkBWP)
8718          {
8719             dlBwp = srvCellCfg->initialDownlinkBWP;
8720
8721             /* Free DL BWP PDCCH Config */
8722             if(dlBwp->pdcch_Config)
8723             {
8724                FreeBWPDlDedPdcchCfg(dlBwp);
8725                DU_FREE(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
8726             }
8727
8728             /* Free DL BWP PDSCH config */
8729             if(dlBwp->pdsch_Config)
8730             {
8731                FreeBWPDlDedPdschCfg(dlBwp);
8732                DU_FREE(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
8733             }
8734             DU_FREE(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
8735          }
8736
8737          /* Free First Active Downlink BWP */
8738          DU_FREE(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
8739
8740          /* Free Default downlink BWP */
8741          DU_FREE(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
8742
8743          /* Free Uplink config */
8744          if(srvCellCfg->uplinkConfig)
8745          {
8746             FreeinitialUplinkBWP(srvCellCfg->uplinkConfig);
8747             DU_FREE(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));  
8748          }
8749
8750          /* Free PDSCH serving cell config */
8751          if(srvCellCfg->pdsch_ServingCellConfig)
8752          {
8753             pdschCfg= srvCellCfg->pdsch_ServingCellConfig;
8754             if(pdschCfg->choice.setup)
8755             {
8756                DU_FREE(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH,sizeof(long));
8757                DU_FREE(pdschCfg->choice.setup, sizeof(struct PDSCH_ServingCellConfig));
8758             }
8759             DU_FREE(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct ServingCellConfig__pdsch_ServingCellConfig));
8760          }
8761
8762          DU_FREE(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
8763       }
8764       DU_FREE(spCellCfg,sizeof(SpCellConfig_t));
8765    }
8766    return ROK;
8767 }
8768
8769 /*******************************************************************
8770  *
8771  * @brief Builds CellGroupConfigRrc for DU To CU RRC Container 
8772  *
8773  * @details
8774  *
8775  *    Function : BuildCellGroupConfigRrc
8776  *
8777  *    Functionality: Builds and copied Cell group config buffer into 
8778  *       DuToCuRrcContainer
8779  *
8780  * @params[in] idx, index in F1AP msg
8781  *             DuToCuRRCContainer, DuToCuRRCContainer
8782  *
8783  * @return ROK     - success
8784  *         RFAILED - failure
8785  *
8786  * ****************************************************************/
8787 uint8_t BuildCellGroupConfigRrc(DuUeCb *ueCb, OCTET_STRING_t *duToCuRrcContainer)
8788 {
8789    uint8_t  ret = ROK;
8790    CellGroupConfigRrc_t  cellGrpCfg;
8791    asn_enc_rval_t        encRetVal;
8792    memset(&cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
8793    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8794
8795    while(true)
8796    {
8797       cellGrpCfg.cellGroupId = CELL_GRP_ID;
8798
8799       cellGrpCfg.rlc_BearerToAddModList = NULLP;
8800       DU_ALLOC(cellGrpCfg.rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8801       if(!cellGrpCfg.rlc_BearerToAddModList)
8802       {
8803          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8804          ret = RFAILED;
8805          break;
8806       }
8807       if(BuildRlcBearerToAddModList(ueCb, cellGrpCfg.rlc_BearerToAddModList) != ROK)
8808       {
8809          DU_LOG("\nERROR  -->  F1AP : BuildRlcBearerToAddModList failed");
8810          ret = RFAILED;
8811          break;
8812       }
8813
8814       cellGrpCfg.rlc_BearerToReleaseList = NULLP;
8815       cellGrpCfg.mac_CellGroupConfig = NULLP;
8816       DU_ALLOC(cellGrpCfg.mac_CellGroupConfig, sizeof(MAC_CellGroupConfig_t));
8817       if(!cellGrpCfg.mac_CellGroupConfig)
8818       {
8819          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8820          ret = RFAILED;
8821          break;
8822       }
8823       if(BuildMacCellGrpCfg(ueCb, cellGrpCfg.mac_CellGroupConfig) != ROK)
8824       {
8825          DU_LOG("\nERROR  -->  F1AP : BuildMacCellGrpCfg failed");
8826          ret = RFAILED;
8827          break;
8828       }
8829
8830       cellGrpCfg.physicalCellGroupConfig = NULLP;
8831       DU_ALLOC(cellGrpCfg.physicalCellGroupConfig, sizeof(PhysicalCellGroupConfig_t));
8832       if(!cellGrpCfg.physicalCellGroupConfig)
8833       {
8834          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8835          ret = RFAILED;
8836          break;
8837       }
8838       if(BuildPhyCellGrpCfg(ueCb, cellGrpCfg.physicalCellGroupConfig) != ROK)
8839       {
8840          DU_LOG("\nERROR  -->  F1AP : BuildPhyCellGrpCfg failed");
8841          ret = RFAILED;
8842          break;
8843       }
8844
8845       cellGrpCfg.spCellConfig = NULLP;
8846       DU_ALLOC(cellGrpCfg.spCellConfig, sizeof(SpCellConfig_t));
8847       if(!cellGrpCfg.spCellConfig)
8848       {
8849          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8850          ret = RFAILED;
8851          break;
8852       }
8853       if(BuildSpCellCfg(ueCb, cellGrpCfg.spCellConfig) != ROK)
8854       {
8855          DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfg failed");
8856          ret = RFAILED;
8857          break;
8858       }
8859
8860       cellGrpCfg.sCellToAddModList = NULLP;
8861       cellGrpCfg.sCellToReleaseList = NULLP;
8862       cellGrpCfg.ext1 = NULLP;
8863
8864       /* encode cellGrpCfg into duToCuRrcContainer */
8865       xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, &cellGrpCfg);
8866       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8867       encBufSize = 0;
8868       encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, &cellGrpCfg, PrepFinalEncBuf, encBuf);
8869       /* Encode results */
8870       if(encRetVal.encoded == ENCODE_FAIL)
8871       {
8872          DU_LOG( "\nERROR  --> F1AP : Could not encode DuToCuRrcContainer (at %s)\n",\
8873                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
8874          ret = RFAILED;
8875          break;
8876       }
8877       else
8878       {
8879          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DuToCuRrcContainer\n");
8880 #ifdef DEBUG_ASN_PRINT
8881          for(int i=0; i< encBufSize; i++)
8882          {
8883             printf("%x",encBuf[i]);
8884          }
8885 #endif
8886       }
8887
8888       duToCuRrcContainer->size = encBufSize;
8889       DU_ALLOC(duToCuRrcContainer->buf, duToCuRrcContainer->size);
8890       if(!duToCuRrcContainer->buf)
8891       {
8892          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDuToCuRrcContainer");
8893          ret = RFAILED;
8894          break;
8895       }
8896       if(ret == ROK)
8897       {
8898          memcpy(duToCuRrcContainer->buf, encBuf, duToCuRrcContainer->size);
8899       }
8900       break;
8901    }
8902    FreeMemDuToCuRrcCont(&cellGrpCfg);
8903    return ret;
8904 }
8905
8906 /*******************************************************************
8907  *
8908  * @brief Free memory allocated in InitialULRRCMessage
8909  *
8910  * @details
8911  *
8912  *    Function : freeInitUlRrcMsgTransfer
8913  *
8914  *    Functionality: Free memory allocated in InitialULRRCMessage
8915  *
8916  * @params[in]F1AP_PDU_t  *f1apMsg)
8917  *
8918  * @return ROK     - success
8919  *         RFAILED - failure
8920  *
8921  * ****************************************************************/
8922
8923 uint8_t freeInitUlRrcMsgTransfer(F1AP_PDU_t  *f1apMsg)
8924 {
8925    uint8_t ieIdx, arrIdx;
8926    InitialULRRCMessageTransfer_t *initULRRCMsg=NULLP;
8927
8928    if(f1apMsg)
8929    {
8930       if(f1apMsg->choice.initiatingMessage)
8931       {
8932          initULRRCMsg = &f1apMsg->choice.initiatingMessage->value.\
8933             choice.InitialULRRCMessageTransfer;
8934          if(initULRRCMsg->protocolIEs.list.array)
8935          {
8936             for(ieIdx = 0; ieIdx < initULRRCMsg->protocolIEs.list.count; ieIdx++)
8937             {
8938                switch(initULRRCMsg->protocolIEs.list.array[ieIdx]->id)
8939                {
8940                   case ProtocolIE_ID_id_NRCGI:
8941                   {
8942                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf)
8943                      {
8944                         if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf)
8945                         {
8946                            DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf,\
8947                            initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.size);
8948                         }
8949                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf,\
8950                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.size);
8951                      }
8952                      break;
8953                   }
8954                   case ProtocolIE_ID_id_RRCContainer:
8955                   {
8956                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
8957                      {
8958                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,\
8959                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
8960                      }
8961                      break;
8962                   }
8963                   case ProtocolIE_ID_id_DUtoCURRCContainer:
8964                   {
8965                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf)
8966                      {
8967                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf,
8968                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.size);
8969                      }
8970                      break;
8971                   }
8972                   default:
8973                      break;
8974                }
8975              }
8976              for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
8977              {
8978                 if(initULRRCMsg->protocolIEs.list.array[arrIdx])
8979                 {
8980                    DU_FREE(initULRRCMsg->protocolIEs.list.array[arrIdx],\
8981                       sizeof(InitialULRRCMessageTransferIEs_t));
8982                 }
8983              }
8984              DU_FREE(initULRRCMsg->protocolIEs.list.array, initULRRCMsg->protocolIEs.list.size);
8985           }
8986          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8987       }
8988       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
8989    }
8990    else
8991    {
8992       DU_LOG("\nERROR  -->  DU_APP : Recevied F1ap Pdu is null at freeInitUlRrcMsgTransfer()");
8993       return RFAILED;
8994    }
8995    return ROK;
8996 }
8997
8998 /*******************************************************************
8999  *
9000  * @brief Builds and sends the InitialULRRCMessage 
9001  *
9002  * @details
9003  *
9004  *    Function : BuildAndSendInitialRrcMsgTransfer 
9005  *
9006  *    Functionality: Constructs the Initial UL RRC Message Transfer and sends
9007  *                   it to the CU through SCTP.
9008  *
9009  * @params[in] 
9010  *
9011  * @return ROK     - success
9012  *         RFAILED - failure
9013  *
9014  * ****************************************************************/
9015 uint8_t BuildAndSendInitialRrcMsgTransfer(uint32_t gnbDuUeF1apId, uint16_t crnti,
9016       uint16_t rrcContSize, uint8_t *rrcContainer)
9017 {
9018    uint8_t   ret;
9019    uint8_t   elementCnt;
9020    uint8_t   ieIdx, cellIdx, ueIdx;
9021    DuUeCb    *duUeCb = NULLP;
9022    asn_enc_rval_t  encRetVal;
9023    F1AP_PDU_t  *f1apMsg = NULLP;
9024    InitialULRRCMessageTransfer_t *initULRRCMsg = NULLP;
9025    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
9026
9027    while(true)
9028    {
9029       DU_LOG("\n INFO   -->  F1AP : Building RRC Setup Request\n");
9030       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
9031       if(f1apMsg == NULLP)
9032       {
9033          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
9034          break;
9035       }
9036       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
9037       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
9038       if(f1apMsg->choice.initiatingMessage == NULLP)
9039       {
9040          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU failed");
9041          break;
9042       }
9043       f1apMsg->choice.initiatingMessage->procedureCode =\
9044                                                         ProcedureCode_id_InitialULRRCMessageTransfer;
9045       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
9046       f1apMsg->choice.initiatingMessage->value.present = \
9047                                                          InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
9048       initULRRCMsg =\
9049                     &f1apMsg->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
9050       elementCnt = 5;
9051       initULRRCMsg->protocolIEs.list.count = elementCnt;
9052       initULRRCMsg->protocolIEs.list.size = \
9053                                             elementCnt * sizeof(InitialULRRCMessageTransferIEs_t *);
9054       /* Initialize the F1Setup members */
9055       DU_ALLOC(initULRRCMsg->protocolIEs.list.array,initULRRCMsg->protocolIEs.list.size);
9056       if(initULRRCMsg->protocolIEs.list.array == NULLP)
9057       {
9058          DU_LOG(" ERROR  -->  F1AP : Memory allocation for\
9059                RRCSetupRequestMessageTransferIEs failed");
9060          break;
9061       }
9062       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
9063       {
9064          DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx],\
9065                sizeof(InitialULRRCMessageTransferIEs_t));
9066          if(initULRRCMsg->protocolIEs.list.array[ieIdx] == NULLP)
9067          {
9068             break;
9069          }
9070       }
9071       ieIdx = 0;
9072       /*GNB DU UE F1AP ID*/
9073       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9074                                                         ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
9075       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  = Criticality_reject;
9076       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
9077                                                                   InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
9078       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
9079
9080
9081       /*NRCGI*/
9082       ieIdx++;
9083       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9084                                                         ProtocolIE_ID_id_NRCGI;
9085       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  =Criticality_reject;
9086       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
9087                                                                   InitialULRRCMessageTransferIEs__value_PR_NRCGI;
9088
9089       ret =\
9090            BuildNrcgi(&initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
9091       if(ret!=ROK)
9092       {
9093          break;
9094       }
9095
9096       /*CRNTI*/
9097       ieIdx++;
9098       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9099                                                         ProtocolIE_ID_id_C_RNTI;
9100       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9101       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9102                                                                  InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
9103       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.C_RNTI = crnti;
9104
9105       /*RRCContainer*/
9106       ieIdx++;
9107       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9108                                                         ProtocolIE_ID_id_RRCContainer;
9109       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9110       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9111                                                                  InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
9112
9113       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size = rrcContSize;
9114       DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,
9115             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size)
9116       if(!initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
9117       {
9118          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRCSetupRequestMessageTransferIEs failed");
9119          break;
9120       
9121       }
9122       memcpy(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, rrcContainer,
9123             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
9124
9125
9126       /*DUtoCURRCContainer*/
9127       ieIdx++;
9128       initULRRCMsg->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCContainer;
9129       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9130       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9131                                                                  InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
9132
9133       for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
9134       {
9135          for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
9136          {
9137             if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
9138                   (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti == crnti))
9139             {
9140                duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
9141             }
9142          }
9143       }
9144
9145       ret = BuildCellGroupConfigRrc(duUeCb, &initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer);
9146       if(ret != ROK)
9147       {
9148          break;
9149       }
9150
9151       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
9152
9153       /* Encode the Intial UL RRC Message transfer as APER */
9154       memset(encBuf, 0, ENC_BUF_MAX_LEN);
9155       encBufSize = 0;
9156       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
9157       /* Encode results */
9158       if(encRetVal.encoded == ENCODE_FAIL)
9159       {
9160          DU_LOG( "\nERROR  --> F1AP : Could not encode Initial UL RRC Message Transfer\
9161                structure (at %s)\n",encRetVal.failed_type ? \
9162                encRetVal.failed_type->name : "unknown");
9163          ret = RFAILED;
9164          break;
9165       }
9166       else
9167       {
9168
9169          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Initial UL RRC\
9170                Message transfer\n");
9171 #ifdef DEBUG_ASN_PRINT
9172          for(int i=0; i< encBufSize; i++)
9173          {
9174             printf("%x",encBuf[i]);
9175          }
9176 #endif
9177       }
9178       /* Sending  msg  */
9179       if(sendF1APMsg() != ROK)
9180       {
9181          DU_LOG("\nERROR  -->  F1AP : Sending Initial UL RRC Message Transfer Failed");
9182          ret = RFAILED;
9183          break;
9184       }
9185       break;
9186    }
9187    freeInitUlRrcMsgTransfer(f1apMsg);
9188    return ret;
9189 }/* End of BuildAndSendInitialRrcMsgTransfer*/
9190
9191 /*****  UE SETUP REQUEST *****/
9192
9193 /******************************************************************
9194 *
9195 * @brief Function to delete the RLC Lc cfg from UE APP DB
9196 *
9197 * @details
9198 *
9199 *  Function : freeRlcLcCfg
9200 *
9201 *  Functionality: Function to delete the RLC Lc cfg from UE APP DB
9202 *
9203 *
9204  *****************************************************************/
9205
9206 void freeRlcLcCfg(RlcBearerCfg *lcCfg)
9207 {
9208    switch(lcCfg->rlcMode)
9209    {
9210       case RLC_AM :
9211          {
9212             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
9213             break;
9214          }
9215       case RLC_UM_BI_DIRECTIONAL :
9216          {
9217             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
9218             break;
9219          }
9220       case RLC_UM_UNI_DIRECTIONAL_UL :
9221          {
9222             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
9223             break;
9224          }
9225       case RLC_UM_UNI_DIRECTIONAL_DL :
9226          {
9227             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
9228             break;
9229          }
9230       default:
9231          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at freeRlcLcCfg()", lcCfg->rlcMode);
9232          break;
9233    }
9234    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
9235 }
9236
9237 /*******************************************************************
9238  *
9239  * @brief Function to free MacLcCfg
9240  *
9241  * @details
9242  *
9243  *    Function : freeMacLcCfg
9244  *
9245  *    Functionality: Function to free MacLcCfg
9246  *
9247  * @params[in] LcCfg *lcCfg,
9248  * @return void
9249  *
9250  * ****************************************************************/
9251
9252 void freeMacLcCfg(LcCfg *lcCfg)
9253 {
9254     /* Deleting DRBQOS */
9255    if(lcCfg->drbQos)
9256    {
9257       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
9258    }
9259    /* Deleting SNSSAI */
9260    if(lcCfg->snssai)
9261    {
9262       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
9263    }
9264 }
9265 /*******************************************************************
9266  *
9267  * @brief Free UE NR Capability received in UE Context setup request
9268  *
9269  * @details
9270  *
9271  *    Function : freeAperDecodeUeNrCapability
9272  *
9273  *    Functionality:  
9274  *       Free UE NR Capability received in UE Context setup request
9275  *
9276  * @params[in] 
9277  * @return ROK     - success
9278  *         RFAILED - failure
9279  *
9280  * ****************************************************************/
9281 void freeAperDecodeUeNrCapability(void *ueNrCapability)
9282 {
9283    uint8_t arrIdx =0;
9284    FeatureSets_t *featureSets =NULLP;
9285    UE_NR_Capability_t *ueNrCap = (UE_NR_Capability_t *)ueNrCapability;
9286
9287    if(ueNrCap->rf_Parameters.supportedBandListNR.list.array)
9288    {
9289       for(arrIdx = 0; arrIdx < ueNrCap->rf_Parameters.supportedBandListNR.list.count; arrIdx++)
9290       {
9291          if(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx])
9292             free(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx]);
9293       }
9294       free(ueNrCap->rf_Parameters.supportedBandListNR.list.array);
9295    }
9296
9297    if(ueNrCap->featureSets)
9298    {
9299       featureSets = ueNrCap->featureSets;
9300       if(featureSets->featureSetsDownlinkPerCC)
9301       {
9302          if(featureSets->featureSetsDownlinkPerCC->list.array)
9303          {
9304             for(arrIdx = 0; arrIdx < featureSets->featureSetsDownlinkPerCC->list.count; arrIdx++)
9305             {
9306                if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx])
9307                {
9308                   if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL)
9309                      free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL);
9310                   free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]);
9311                }
9312             }
9313             free(featureSets->featureSetsDownlinkPerCC->list.array);
9314          }
9315          free(featureSets->featureSetsDownlinkPerCC);
9316       }
9317       if(featureSets->featureSetsUplinkPerCC)
9318       {
9319          if(featureSets->featureSetsUplinkPerCC->list.array)
9320          {
9321             for(arrIdx = 0; arrIdx < featureSets->featureSetsUplinkPerCC->list.count; arrIdx++)
9322             {
9323                if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx])
9324                {
9325                   if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL)
9326                      free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL);
9327                   free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]);
9328                }
9329             }
9330             free(featureSets->featureSetsUplinkPerCC->list.array);
9331          }
9332          free(featureSets->featureSetsUplinkPerCC);
9333       }
9334       free(ueNrCap->featureSets);
9335    }   
9336 }
9337
9338 /*******************************************************************
9339 *
9340 * @brief Function to free PdcchSearchSpcToAddModList
9341          where memory allocated by aper_decoder
9342 *
9343 * @details
9344 *
9345 *    Function : freeAperDecodePdcchSearchSpcToAddModList 
9346 *
9347 *    Functionality: Function to free PdcchSearchSpcToAddModList
9348 *
9349 * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
9350 * @return void
9351 *
9352 * ****************************************************************/
9353
9354 void freeAperDecodePdcchSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
9355 {
9356    uint8_t searchSpcArrIdx=0;
9357    uint8_t searchSpcArrIdx1=0;
9358    struct  SearchSpace *searchSpc=NULLP;
9359
9360
9361    if(searchSpcList->list.array)
9362    {
9363       if(searchSpcList->list.array[searchSpcArrIdx1])
9364       {
9365          searchSpc = searchSpcList->list.array[searchSpcArrIdx1];
9366          if(searchSpc->controlResourceSetId)
9367          {
9368             if(searchSpc->monitoringSlotPeriodicityAndOffset)
9369             {
9370                if(searchSpc->monitoringSymbolsWithinSlot)
9371                {
9372                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
9373                   {
9374                      if(searchSpc->nrofCandidates)
9375                      {
9376                         if(searchSpc->searchSpaceType)
9377                         {
9378                            free(searchSpc->searchSpaceType->choice.ue_Specific);
9379                            free(searchSpc->searchSpaceType);
9380                         }
9381                         free(searchSpc->nrofCandidates);
9382                      }
9383                      free(searchSpc->monitoringSymbolsWithinSlot->buf);
9384                   }
9385                   free(searchSpc->monitoringSymbolsWithinSlot);
9386                }
9387                free(searchSpc->monitoringSlotPeriodicityAndOffset);
9388             }
9389             free(searchSpc->controlResourceSetId);
9390          }
9391       }
9392       for(searchSpcArrIdx = 0; searchSpcArrIdx < searchSpcList->list.count; searchSpcArrIdx++)
9393       {
9394          free(searchSpcList->list.array[searchSpcArrIdx]);
9395       }
9396       free(searchSpcList->list.array);
9397    }
9398 }
9399 /*******************************************************************
9400 *
9401 * @brief Function for free part for the memory allocated by aper_decoder
9402
9403 * @details
9404 *
9405 *    Function : freeAperDecodeBWPDlDedPdcchConfig
9406 *
9407 *    Functionality: Function to free BWPDlDedPdcchConfig
9408 *
9409 * @params[in] 
9410 * @return void
9411 *
9412 * ****************************************************************/
9413
9414
9415 void freeAperDecodeBWPDlDedPdcchConfig(BWP_DownlinkDedicated_t *dlBwp)
9416 {
9417    uint8_t arrIdx1=0;
9418    uint8_t arrIdx2=0;
9419    struct PDCCH_Config *pdcchCfg=NULLP;
9420    struct ControlResourceSet *controlRSet=NULLP;
9421    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
9422    
9423    if(dlBwp->pdcch_Config->choice.setup)
9424    {
9425       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
9426       if(pdcchCfg->controlResourceSetToAddModList)
9427       {
9428          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
9429          if(controlRSetList->list.array)
9430          {
9431             controlRSet = controlRSetList->list.array[arrIdx2];
9432             if(controlRSet)
9433             {
9434                if(controlRSet->frequencyDomainResources.buf)
9435                {
9436                   if(controlRSet->pdcch_DMRS_ScramblingID)
9437                   {
9438                      if(pdcchCfg->searchSpacesToAddModList)
9439                      {
9440                         freeAperDecodePdcchSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
9441                         free(pdcchCfg->searchSpacesToAddModList);
9442                      }
9443                      free(controlRSet->pdcch_DMRS_ScramblingID);
9444                   }
9445                   free(controlRSet->frequencyDomainResources.buf);
9446                }
9447             }
9448             for(arrIdx1 = 0; arrIdx1 <controlRSetList->list.count; arrIdx1++)
9449             {
9450                free(controlRSetList->list.array[arrIdx1]);
9451             }
9452             free(controlRSetList->list.array);
9453          }
9454          free(pdcchCfg->controlResourceSetToAddModList);
9455       }
9456       free(dlBwp->pdcch_Config->choice.setup);
9457    }
9458 }
9459 /*******************************************************************
9460 *
9461 * @brief Function to free PdschTimeDomAllocationList 
9462 *     where the memory allocated by aper_decoder
9463
9464 * @details
9465 *
9466 *    Function : freeAperDecodePdschTimeDomAllocationList
9467 *
9468 *    Functionality: Function to free PdschTimeDomAllocationList
9469 *
9470 * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList 
9471 * @return void
9472 *
9473 * ****************************************************************/
9474
9475
9476 void freeAperDecodePdschTimeDomAllocationList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
9477 {
9478    uint8_t arrIdx=0;
9479
9480    if(timeDomAllocList->choice.setup)
9481    {
9482       if(timeDomAllocList->choice.setup->list.array)
9483       {
9484          for(arrIdx = 0; arrIdx <timeDomAllocList->choice.setup->list.count ; arrIdx++)
9485          {
9486             free(timeDomAllocList->choice.setup->list.array[arrIdx]);
9487          }
9488          free(timeDomAllocList->choice.setup->list.array);
9489       }
9490       free(timeDomAllocList->choice.setup);
9491    }
9492 }
9493
9494 /*******************************************************************
9495 *
9496 * @brief Function to free BWPDlDedPdschConfig 
9497 *        where the memory allocated by aper_decoder
9498 *  
9499 * @details
9500 *
9501 *    Function : freeAperDecodeBWPDlDedPdschConfig 
9502 *
9503 *    Functionality: Function to free BWPDlDedPdschConfig 
9504 *
9505 * @params[in] BWP_DownlinkDedicated_t *dlBwp 
9506 * @return void
9507 *
9508 * ****************************************************************/
9509
9510
9511 void freeAperDecodeBWPDlDedPdschConfig(BWP_DownlinkDedicated_t *dlBwp)
9512 {
9513    struct PDSCH_Config *pdschCfg=NULLP;
9514    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
9515    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
9516    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
9517
9518    if(dlBwp->pdsch_Config->choice.setup)
9519    {
9520       pdschCfg=dlBwp->pdsch_Config->choice.setup;
9521       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
9522       {
9523          if(pdschCfg->pdsch_TimeDomainAllocationList)
9524          {
9525             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
9526             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
9527             {
9528                prbBndlType=&pdschCfg->prb_BundlingType;
9529                free(prbBndlType->choice.staticBundling);
9530                free(pdschCfg->maxNrofCodeWordsScheduledByDCI);
9531             }
9532             freeAperDecodePdschTimeDomAllocationList(timeDomAllocList);
9533             free(pdschCfg->pdsch_TimeDomainAllocationList);
9534          }
9535          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
9536          if(dmrsDlCfg->choice.setup)
9537          {
9538             free(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition);
9539             free(dmrsDlCfg->choice.setup);
9540          }
9541          free(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA);
9542       }
9543       free(dlBwp->pdsch_Config->choice.setup);
9544    }
9545 }
9546 /*******************************************************************
9547 *
9548 * @brief Function to free PuschTimeDomAllocListCfg
9549                  where the memory allocated by aper_decoder
9550 *
9551 * @details
9552 *
9553 *    Function : freeAperDecodePuschTimeDomAllocListCfg
9554 *
9555 *    Functionality: Function to free PuschTimeDomAllocListCfg
9556 *
9557 * @params[in] PUSCH_Config_t *puschCfg 
9558 * @return void
9559 *
9560 * ****************************************************************/
9561
9562
9563 void freeAperDecodePuschTimeDomAllocListCfg(PUSCH_Config_t *puschCfg)
9564 {
9565    uint8_t arrIdx=0;
9566    uint8_t arrIdx1=0;
9567    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
9568
9569    if(puschCfg->pusch_TimeDomainAllocationList)
9570    {
9571       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
9572       if(timeDomAllocList_t->choice.setup)
9573       {
9574          if(timeDomAllocList_t->choice.setup->list.array)
9575          {
9576             free(timeDomAllocList_t->choice.setup->list.array[arrIdx1]->k2);
9577             for(arrIdx = 0; arrIdx<timeDomAllocList_t->choice.setup->list.count; arrIdx++)
9578             {
9579                free(timeDomAllocList_t->choice.setup->list.array[arrIdx]);
9580             }
9581             free(timeDomAllocList_t->choice.setup->list.array);
9582          }
9583          free(timeDomAllocList_t->choice.setup);
9584       }
9585       free(puschCfg->transformPrecoder);
9586       free(puschCfg->pusch_TimeDomainAllocationList);
9587    }
9588 }
9589 /*******************************************************************
9590 *
9591 * @brief Function to free InitialUlBWPConfig where memory allocated by aper_decoder
9592 *
9593 * @details
9594 *
9595 *    Function : freeAperDecodeInitialUlBWPConfig 
9596 *
9597 *    Functionality: Function to free InitialUlBWPConfig
9598 *
9599 * @params[in]  BWP_UplinkDedicated_t *ulBwp
9600 * @return void
9601 *
9602 * ****************************************************************/
9603
9604
9605 void freeAperDecodeInitialUlBWPConfig(BWP_UplinkDedicated_t *ulBwp)
9606 {
9607    uint8_t  rSetIdx =0;
9608    uint8_t  rsrcIdx =0;
9609    SRS_Config_t   *srsCfg = NULLP;
9610    PUSCH_Config_t *puschCfg = NULLP;
9611    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
9612    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
9613    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
9614    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
9615
9616    if(ulBwp->pusch_Config)
9617    {
9618       if(ulBwp->pusch_Config->choice.setup)
9619       {
9620          puschCfg=ulBwp->pusch_Config->choice.setup;
9621          if(puschCfg->dataScramblingIdentityPUSCH)
9622          {
9623             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
9624             {
9625                freeAperDecodePuschTimeDomAllocListCfg(puschCfg);
9626                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
9627                if(dmrsUlCfg->choice.setup)
9628                {
9629                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
9630                   {
9631                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
9632                      {
9633                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0);
9634                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled);
9635                      }
9636                      free(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition);
9637                   }
9638                   free(dmrsUlCfg->choice.setup);
9639                }
9640                free(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA);
9641             }
9642             free(puschCfg->dataScramblingIdentityPUSCH);
9643          }
9644          free(ulBwp->pusch_Config->choice.setup);
9645       }
9646       free(ulBwp->pusch_Config);
9647
9648       /* Free SRS-Config */
9649       if(ulBwp->srs_Config)
9650       {
9651          if(ulBwp->srs_Config->choice.setup)
9652          {
9653             srsCfg = ulBwp->srs_Config->choice.setup;
9654
9655             /* Free Resource Set to add/mod list */
9656             if(srsCfg->srs_ResourceSetToAddModList)
9657             {
9658                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
9659                if(rsrcSetList->list.array)
9660                {
9661                   rSetIdx = 0;
9662
9663                   /* Free SRS resource Id list in this SRS resource set */
9664                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
9665                   {
9666                      rsrcIdList =
9667                         rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
9668
9669                      if(rsrcIdList->list.array)
9670                      {
9671                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count;
9672                               rsrcIdx++)
9673                         {
9674                            free(rsrcIdList->list.array[rsrcIdx]);
9675                         }
9676                         free(rsrcIdList->list.array);
9677                      }
9678                      free(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList);
9679                   }
9680
9681                   /* Free resource type info for this SRS resource set */
9682
9683                   free(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic);
9684
9685                   /* Free memory for each resource set */
9686                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
9687                   {
9688                      free(rsrcSetList->list.array[rSetIdx]);
9689                   }
9690                   free(rsrcSetList->list.array);
9691                }
9692                free(srsCfg->srs_ResourceSetToAddModList);
9693             }
9694
9695             /* Free resource to add/modd list */
9696             if(srsCfg->srs_ResourceToAddModList)
9697             {
9698                resourceList = srsCfg->srs_ResourceToAddModList;
9699                if(resourceList->list.array)
9700                {
9701                   rsrcIdx = 0;
9702
9703                   free(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2);
9704                   free(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic);
9705
9706                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
9707                   {
9708                      free(resourceList->list.array[rsrcIdx]);
9709                   }
9710                   free(resourceList->list.array);
9711                }
9712                free(srsCfg->srs_ResourceToAddModList);
9713             }
9714
9715             free(ulBwp->srs_Config->choice.setup);
9716          }
9717          free(ulBwp->srs_Config);
9718       }
9719    }
9720 }
9721 /*******************************************************************
9722 *
9723 * @brief Function to free initialUplinkBWPConfig where memory allocated by aper_decoder
9724 *
9725 * @details
9726 *
9727 *    Function : freeAperDecodeinitialUplinkBWPConfig
9728 *
9729 *    Functionality: Function to free initialUplinkBWPConfig
9730 *
9731 * @params[in] UplinkConfig_t *ulCfg 
9732 * @return void
9733 *
9734 * ****************************************************************/
9735
9736
9737 void freeAperDecodeinitialUplinkBWPConfig(UplinkConfig_t *ulCfg)
9738 {
9739    BWP_UplinkDedicated_t *ulBwp=NULLP;
9740    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
9741    
9742    if(ulCfg->initialUplinkBWP)
9743    {
9744       ulBwp=ulCfg->initialUplinkBWP;
9745       if(ulCfg->firstActiveUplinkBWP_Id)
9746       {
9747          if(ulCfg->pusch_ServingCellConfig)
9748          {
9749             puschCfg=ulCfg->pusch_ServingCellConfig;
9750             if(puschCfg->choice.setup)
9751             {
9752                if(puschCfg->choice.setup->ext1)
9753                {
9754                   free(puschCfg->choice.setup->ext1->processingType2Enabled);
9755                   free(puschCfg->choice.setup->ext1->maxMIMO_Layers);
9756                   free(puschCfg->choice.setup->ext1);
9757                }
9758                free(puschCfg->choice.setup);
9759             }
9760             free(ulCfg->pusch_ServingCellConfig);
9761          }
9762          free(ulCfg->firstActiveUplinkBWP_Id);
9763       }
9764       freeAperDecodeInitialUlBWPConfig(ulBwp);
9765       free(ulCfg->initialUplinkBWP);
9766    }
9767 }
9768
9769 /*******************************************************************
9770  *
9771  * @brief Function to free DuUeCfg
9772  *
9773  * @details
9774  *
9775  *    Function : freeDuUeCfg
9776  *
9777  *    Functionality: Function to free DuUeCfg
9778  *
9779  * @params[in] DuUeCfg *ueCfg
9780  * @return void
9781  *
9782  * ****************************************************************/
9783 void freeDuUeCfg(UeCtxtActionType actionType, DuUeCfg *ueCfg)
9784 {
9785    uint8_t lcIdx = 0;
9786    uint8_t arrIdx = 0;
9787    SpCellConfig_t *spCellCfg = NULLP;
9788    ServingCellConfig_t *srvCellCfg = NULLP;
9789    BWP_DownlinkDedicated_t *dlBwp = NULLP;
9790    MAC_CellGroupConfig_t *macCellGrpCfg = NULLP;
9791    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
9792    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList = NULLP;
9793    struct RLC_Config *rlcConfig = NULLP;
9794    struct LogicalChannelConfig *macLcConfig = NULLP;
9795    struct SchedulingRequestConfig *schedulingRequestConfig = NULLP;
9796    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList = NULLP;
9797    struct TAG_Config *tagConfig = NULLP;
9798    struct TAG_Config__tag_ToAddModList *tagList = NULLP;
9799    struct MAC_CellGroupConfig__phr_Config *phrConfig = NULLP;
9800    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg = NULLP;
9801    CellGroupConfigRrc_t *cellGrpCfg = ueCfg->cellGrpCfg;
9802   
9803    if(ueCfg->ueNrCapability)
9804    {
9805       freeAperDecodeUeNrCapability(ueCfg->ueNrCapability);
9806       DU_FREE(ueCfg->ueNrCapability, sizeof(UE_NR_Capability_t));
9807       ueCfg->ueNrCapability = NULLP;
9808    }
9809
9810    if(ueCfg->cellGrpCfg)
9811    {
9812       rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
9813       if(rlcBearerList)
9814       {
9815          if(rlcBearerList->list.array)
9816          {
9817             for(arrIdx=0; arrIdx<rlcBearerList->list.count; arrIdx++)
9818             {
9819                if(rlcBearerList->list.array[arrIdx])
9820                {
9821                   rlcConfig   = rlcBearerList->list.array[arrIdx]->rlc_Config;
9822                   macLcConfig = rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig;
9823
9824                   if(rlcBearerList->list.array[arrIdx]->servedRadioBearer)
9825                   {
9826                      free(rlcBearerList->list.array[arrIdx]->servedRadioBearer);
9827                   }
9828                   if(rlcConfig)
9829                   {
9830                      if(rlcConfig->choice.am)
9831                      {
9832                         free(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength);
9833                         free(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength);
9834                         free(rlcConfig->choice.am);
9835                      }
9836                      free(rlcBearerList->list.array[arrIdx]->rlc_Config);
9837                   }
9838                   if(macLcConfig)
9839                   {
9840                      if(macLcConfig->ul_SpecificParameters)
9841                      {
9842                         free(macLcConfig->ul_SpecificParameters->schedulingRequestID);
9843                         free(macLcConfig->ul_SpecificParameters->logicalChannelGroup);
9844                         free(macLcConfig->ul_SpecificParameters);
9845                      }
9846                      free(rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig);
9847                   }
9848                   free(rlcBearerList->list.array[arrIdx]); 
9849                }
9850             }
9851             free(rlcBearerList->list.array);
9852          }
9853          free(cellGrpCfg->rlc_BearerToAddModList);
9854       }
9855
9856       macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
9857       if(macCellGrpCfg)
9858       {
9859          schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig;
9860          if(schedulingRequestConfig)
9861          {
9862             schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
9863             if(schReqList)
9864             {
9865                if(schReqList->list.array)
9866                {
9867                   for(arrIdx=0;arrIdx<schReqList->list.count; arrIdx++)
9868                   {
9869                      if(schReqList->list.array[arrIdx])
9870                      {
9871                         free(schReqList->list.array[arrIdx]->sr_ProhibitTimer); 
9872                         free(schReqList->list.array[arrIdx]);
9873                      }
9874                   }
9875                   free(schReqList->list.array);
9876                }
9877                free(schedulingRequestConfig->schedulingRequestToAddModList);
9878             }
9879             free(macCellGrpCfg->schedulingRequestConfig);
9880          }
9881          if(macCellGrpCfg->bsr_Config)
9882          {
9883             free(macCellGrpCfg->bsr_Config);
9884          }
9885          tagConfig = macCellGrpCfg->tag_Config;
9886          if(tagConfig)
9887          {
9888             tagList = tagConfig->tag_ToAddModList;
9889             if(tagList)
9890             {
9891                if(tagList->list.array)
9892                {
9893                   for(arrIdx=0; arrIdx<tagList->list.count; arrIdx++)
9894                   {
9895                      free(tagList->list.array[arrIdx]);
9896                   }
9897                   free(tagList->list.array);
9898                }
9899                free(tagConfig->tag_ToAddModList);
9900             }
9901             free(tagConfig); 
9902          }
9903
9904          phrConfig = macCellGrpCfg->phr_Config;
9905          if(phrConfig)
9906          {
9907             free(phrConfig->choice.setup); 
9908             free(phrConfig); 
9909          }
9910
9911          free(macCellGrpCfg); 
9912       }
9913
9914       phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
9915       if(phyCellGrpCfg)
9916       {
9917          free(phyCellGrpCfg->p_NR_FR1);
9918          free(phyCellGrpCfg); 
9919       }
9920
9921       spCellCfg = cellGrpCfg->spCellConfig;
9922       if(spCellCfg)
9923       {
9924          if(spCellCfg->servCellIndex)
9925          {
9926             if(spCellCfg->rlmInSyncOutOfSyncThreshold)
9927             {
9928                if(spCellCfg->spCellConfigDedicated)
9929                {
9930                   srvCellCfg = spCellCfg->spCellConfigDedicated;
9931                   if(srvCellCfg->initialDownlinkBWP)
9932                   {
9933                      dlBwp = srvCellCfg->initialDownlinkBWP;
9934                      if(srvCellCfg->firstActiveDownlinkBWP_Id)
9935                      {
9936                         if(srvCellCfg->defaultDownlinkBWP_Id)
9937                         {
9938                            if(srvCellCfg->uplinkConfig)
9939                            {
9940
9941                               if(srvCellCfg->pdsch_ServingCellConfig)
9942                               {
9943                                  pdschCfg=
9944                                     srvCellCfg->pdsch_ServingCellConfig;
9945                                  if(pdschCfg->choice.setup)
9946                                  {
9947
9948                                     free(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH);
9949                                     free(pdschCfg->choice.setup);
9950                                  }
9951
9952                                  free(srvCellCfg->pdsch_ServingCellConfig);
9953                               }
9954
9955                               freeAperDecodeinitialUplinkBWPConfig(srvCellCfg->uplinkConfig);
9956                               free(srvCellCfg->uplinkConfig);
9957                            }
9958                            free(srvCellCfg->defaultDownlinkBWP_Id);
9959                         }
9960
9961                         free(srvCellCfg->firstActiveDownlinkBWP_Id);
9962                      }
9963                      if(dlBwp->pdcch_Config)
9964                      {
9965                         if(dlBwp->pdsch_Config)
9966                         {
9967                            freeAperDecodeBWPDlDedPdschConfig(dlBwp);
9968                            free(dlBwp->pdsch_Config);
9969                         }
9970                         freeAperDecodeBWPDlDedPdcchConfig(dlBwp);
9971                         free(dlBwp->pdcch_Config);
9972                      }
9973                      free(srvCellCfg->initialDownlinkBWP);
9974                   }
9975
9976                   free(spCellCfg->spCellConfigDedicated);
9977                }
9978                free(spCellCfg->rlmInSyncOutOfSyncThreshold);
9979             }
9980             free(spCellCfg->servCellIndex); 
9981          }
9982          free(spCellCfg);
9983       }
9984       DU_FREE(ueCfg->cellGrpCfg, sizeof(CellGroupConfigRrc_t));
9985       ueCfg->cellGrpCfg = NULLP;
9986    }
9987
9988    if(ueCfg->ambrCfg)
9989    {
9990       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCfg->ambrCfg, sizeof(AmbrCfg));
9991    }
9992
9993    if(actionType != UE_CTXT_CFG_QUERY)
9994    {
9995       for(lcIdx = 0; lcIdx < ueCfg->numRlcLcs; lcIdx++)
9996       {
9997          freeRlcLcCfg(&ueCfg->rlcLcCfg[lcIdx].rlcBearerCfg);
9998       }
9999    }
10000
10001    for(lcIdx = 0; lcIdx < ueCfg->numMacLcs; lcIdx++)
10002    {
10003       freeMacLcCfg(&ueCfg->macLcCfg[lcIdx].lcConfig);
10004    }
10005
10006    for(lcIdx = 0; lcIdx < ueCfg->numDrb; lcIdx++)
10007    {
10008       DU_FREE(ueCfg->upTnlInfo[lcIdx].tnlCfg1, sizeof(GtpTnlCfg));
10009    }
10010 }
10011
10012 /*******************************************************************
10013  *
10014  * @brief Function to free UecontextSetupDb
10015  *
10016  * @details
10017  *
10018  *    Function : freeF1UeDb
10019  *
10020  *    Functionality: Function to free UecontextSetupDb
10021  *
10022  * @params[in] UecontextSetupDb *
10023  * @return void
10024  *
10025  * ****************************************************************/
10026
10027 void freeF1UeDb(F1UeContextSetupDb *f1UeDb)
10028 {
10029    
10030    if(f1UeDb->dlRrcMsg)
10031    {
10032       if(f1UeDb->dlRrcMsg->rrcMsgPdu)
10033       {
10034         //DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,\
10035                f1UeDb->dlRrcMsg->rrcMsgPdu, f1UeDb->dlRrcMsg->rrcMsgSize);
10036       }
10037       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
10038    }
10039    freeDuUeCfg(f1UeDb->actionType, &f1UeDb->duUeCfg);
10040    memset(f1UeDb, 0, sizeof(F1UeContextSetupDb));
10041    DU_FREE(f1UeDb, sizeof(F1UeContextSetupDb));
10042 }
10043
10044 /*******************************************************************
10045  *
10046  * @brief Function to build Am cfg Info
10047  *
10048  * @details
10049  *
10050  *    Function : extractRlcAmCfg
10051  *
10052  *    Functionality: Function to build Am cfg Info
10053  *
10054  * @params[in] AmBearerCfg *
10055  *             void *
10056  *
10057  * @return ROK/RFAILED
10058  *
10059  * ****************************************************************/
10060
10061 void extractRlcAmCfg(AmBearerCfg *amCfgToSet, struct RLC_Config__am *rlcAmCfg)
10062 {
10063    if(rlcAmCfg)
10064    {
10065       /* UL AM */
10066       if(rlcAmCfg->dl_AM_RLC.sn_FieldLength)
10067       {
10068          amCfgToSet->ulAmCfg.snLenUl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->dl_AM_RLC.sn_FieldLength));
10069          /*TODO: Check the timer value when sent by real CU */
10070          amCfgToSet->ulAmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_Reassembly); 
10071          amCfgToSet->ulAmCfg.statProhTmr = convertProhibitTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_StatusProhibit);
10072       }
10073
10074       /* DL AM */
10075       if(rlcAmCfg->ul_AM_RLC.sn_FieldLength)
10076       {
10077          amCfgToSet->dlAmCfg.snLenDl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->ul_AM_RLC.sn_FieldLength));
10078          amCfgToSet->dlAmCfg.pollRetxTmr = covertPollRetxTmrEnumToValue(rlcAmCfg->ul_AM_RLC.t_PollRetransmit);
10079          amCfgToSet->dlAmCfg.pollPdu   = covertPollPduEnumToValue(rlcAmCfg->ul_AM_RLC.pollPDU);
10080          amCfgToSet->dlAmCfg.pollByte  = covertPollByteEnumToValue(rlcAmCfg->ul_AM_RLC.pollByte);
10081          amCfgToSet->dlAmCfg.maxRetxTh = covertMaxRetxEnumToValue(rlcAmCfg->ul_AM_RLC.maxRetxThreshold);
10082       }
10083    }
10084 }
10085
10086 /*******************************************************************
10087  *
10088  * @brief Function to build Um Bi Info
10089  *
10090  * @details
10091  *
10092  *    Function : extractRlcUmBiCfg
10093  *
10094  *    Functionality: Function to build Um Bi Info
10095  *
10096  * @params[in] UmBiDirBearerCfg *
10097  *             void *
10098  *
10099  * @return ROK/RFAILED
10100  *
10101  * ****************************************************************/
10102
10103 void extractRlcUmBiCfg(UmBiDirBearerCfg *umBiCfgToSet, struct RLC_Config__um_Bi_Directional *rlcBiCfg)
10104 {
10105    if(rlcBiCfg)
10106    {
10107       /* UL UM BI DIR Cfg */
10108       if(rlcBiCfg->dl_UM_RLC.sn_FieldLength)
10109       {
10110          umBiCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->dl_UM_RLC.sn_FieldLength));
10111          umBiCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcBiCfg->dl_UM_RLC.t_Reassembly);
10112       }
10113
10114       /* DL UM BI DIR Cfg */
10115       if(rlcBiCfg->ul_UM_RLC.sn_FieldLength)
10116          umBiCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->ul_UM_RLC.sn_FieldLength));
10117    }
10118 }
10119
10120 /*******************************************************************
10121  *
10122  * @brief Function to build Um Ul Info
10123  *
10124  * @details
10125  *
10126  *    Function : extractRlcUmUlCfg
10127  *
10128  *    Functionality: Function to build Um Ul Info
10129  *
10130  * @params[in] UmUniDirUlBearerCfg *
10131  *             void *
10132  *
10133  * @return ROK/RFAILED
10134  *
10135  * ****************************************************************/
10136
10137 void extractRlcUmUlCfg(UmUniDirUlBearerCfg *umUlCfgToSet, struct RLC_Config__um_Uni_Directional_DL *umUlCfg)
10138 {
10139    if(umUlCfg)
10140    {
10141       if(umUlCfg->dl_UM_RLC.sn_FieldLength)
10142       {
10143          umUlCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umUlCfg->dl_UM_RLC.sn_FieldLength));
10144          umUlCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(umUlCfg->dl_UM_RLC.t_Reassembly);
10145       }
10146    }
10147 }
10148
10149 /*******************************************************************
10150  *
10151  * @brief Function to build Um Uni Dl Info
10152  *
10153  * @details
10154  *
10155  *    Function : extractRlcUmDlCfg
10156  *
10157  *    Functionality: Function to build Um Uni Dl Info
10158  *
10159  * @params[in] UmUniDirDlBearerCfg *
10160  *             void *
10161  *
10162  * @return ROK/RFAILED
10163  *
10164  * ****************************************************************/
10165 void extractRlcUmDlCfg(UmUniDirDlBearerCfg *umDlCfgToSet, struct RLC_Config__um_Uni_Directional_UL *umDlCfg)
10166 {
10167    if(umDlCfg)
10168    {
10169       if(umDlCfg->ul_UM_RLC.sn_FieldLength)
10170          umDlCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umDlCfg->ul_UM_RLC.sn_FieldLength));
10171    }
10172 }
10173
10174 /*******************************************************************
10175  *
10176  * @brief Function to extractRlcModeCfg
10177  *
10178  * @details
10179  *
10180  *    Function : extractRlcModeCfg
10181  *
10182  *    Functionality: Function to extractRlcModeCfg
10183  *
10184  * @params[in] RLC_Config_t *
10185  *             RlcBearerCfg *
10186  *             void  *    
10187  * @return ROK/RFAILED
10188  *
10189  * ****************************************************************/
10190 void extractRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *rlcDbCfg, RLC_Config_t *lcCfg)
10191 {
10192    if(lcCfg)
10193    {
10194       switch(rlcMode)
10195       {
10196          case RLC_AM :
10197             {
10198                if(lcCfg->choice.am)
10199                {
10200                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.amCfg, sizeof(AmBearerCfg));
10201                   if(rlcDbCfg->u.amCfg)
10202                      extractRlcAmCfg(rlcDbCfg->u.amCfg, lcCfg->choice.am);
10203                }
10204                break;
10205             }
10206          case RLC_UM_BI_DIRECTIONAL :
10207             {
10208                if(lcCfg->choice.um_Bi_Directional)
10209                {
10210                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
10211                   if(rlcDbCfg->u.umBiDirCfg)
10212                      extractRlcUmBiCfg(rlcDbCfg->u.umBiDirCfg, lcCfg->choice.um_Bi_Directional);
10213                }
10214                break;
10215             }
10216          case RLC_UM_UNI_DIRECTIONAL_UL :
10217             {
10218                if(lcCfg->choice.um_Uni_Directional_DL)
10219                {
10220                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
10221                   if(rlcDbCfg->u.umUniDirUlCfg)
10222                      extractRlcUmUlCfg(rlcDbCfg->u.umUniDirUlCfg, lcCfg->choice.um_Uni_Directional_DL);
10223                }
10224                break;
10225             }
10226          case RLC_UM_UNI_DIRECTIONAL_DL :
10227             {
10228                if(lcCfg->choice.um_Uni_Directional_UL)
10229                {
10230                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
10231                   if(rlcDbCfg->u.umUniDirDlCfg)
10232                      extractRlcUmDlCfg(rlcDbCfg->u.umUniDirDlCfg, lcCfg->choice.um_Uni_Directional_UL);
10233                }
10234                break;
10235             }
10236          default:
10237             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
10238             break;
10239       }
10240    }
10241 }
10242
10243 /*******************************************************************
10244  *
10245  * @brief Function to extract extractUlLcCfg
10246  *
10247  * @details
10248  *
10249  *    Function : extractUlLcCfg
10250  *
10251  *    Functionality: Function to extract extractUlLcCfg
10252  *
10253  * @params[in] UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg
10254  * @return void
10255  *
10256  * ****************************************************************/
10257
10258 void extractUlLcCfg(UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg)
10259 {
10260    if(ulLcCfg)
10261    {
10262       if(ulLcCfg->ul_SpecificParameters)
10263       {
10264          f1UlLcCfg->priority = \
10265             ulLcCfg->ul_SpecificParameters->priority;
10266       if(ulLcCfg->ul_SpecificParameters->logicalChannelGroup)
10267       {
10268          f1UlLcCfg->lcGroup = \
10269            *(ulLcCfg->ul_SpecificParameters->logicalChannelGroup);
10270       }
10271       if(ulLcCfg->ul_SpecificParameters->schedulingRequestID)
10272       {
10273          f1UlLcCfg->schReqId = \
10274            *(ulLcCfg->ul_SpecificParameters->schedulingRequestID);
10275       }
10276       f1UlLcCfg->pbr = \
10277          ulLcCfg->ul_SpecificParameters->prioritisedBitRate;
10278       f1UlLcCfg->bsd = \
10279          ulLcCfg->ul_SpecificParameters->bucketSizeDuration;
10280       }
10281    }
10282 }
10283
10284 /*******************************************************************
10285 *
10286 * @brief Function to extract Snssai Cfg Info from CU
10287 *
10288 * @details
10289 *
10290 *    Function : extractDrbSnssaiCfg
10291 *
10292 *    Functionality: Function to extract Drb Snssai Cfg Info from CU
10293 *
10294 * @params[in] DRB_Information_t *drbInfo, Snssai  *snssai
10295 * @return ROK/RFAILED
10296 *
10297 * ****************************************************************/
10298
10299 uint8_t extractDrbSnssaiCfg(SNSSAI_t *RecvSnssai, Snssai **snssaiToBeShared)
10300 {
10301    if(!(*snssaiToBeShared))
10302    {
10303       DU_ALLOC_SHRABL_BUF((*snssaiToBeShared), sizeof(Snssai));
10304       if(snssaiToBeShared == NULLP)
10305       {
10306          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Memory failed at allocating for SNSSAI ");
10307          return RFAILED;
10308       }
10309    }
10310    if(RecvSnssai)
10311    {
10312       memcpy(&(*snssaiToBeShared)->sst, RecvSnssai->sST.buf, RecvSnssai->sST.size);
10313       if(RecvSnssai->sD)
10314       {
10315          memcpy((*snssaiToBeShared)->sd, RecvSnssai->sD->buf,  RecvSnssai->sD->size);
10316       }
10317       else
10318       {
10319          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Received Null pointer of Snssai->SD");
10320          return RFAILED;
10321       }
10322    }
10323    return ROK;
10324 }
10325
10326 /*******************************************************************
10327  *
10328  * @brief Function to procRlcLcCfg
10329  *
10330  * @details
10331  *
10332  *    Function : procRlcLcCfg
10333  *
10334  *    Functionality: Function to procRlcLcCfg
10335  *
10336  * @params[in] rbId, lcId, rbType, rlcMod
10337  *             RLC_Config_t *, RlcBearerCfg * , 
10338  * @return void
10339  *
10340  * ****************************************************************/
10341
10342 void procRlcLcCfg(uint8_t rbId, uint8_t lcId, uint8_t rbType, uint8_t rlcMode,\
10343    uint8_t configType, RLC_Config_t *f1RlcCfg, DuRlcBearerCfg *lcCfg, QoSInformation_t *qoSInformation)
10344 {
10345    DRB_Information_t *drbInfo;
10346
10347    lcCfg->rlcBearerCfg.rbId   = rbId;
10348    lcCfg->configType = configType;
10349
10350    if(rbType == RB_TYPE_SRB)
10351    {
10352       lcCfg->rlcBearerCfg.rbType = RB_TYPE_SRB;
10353       lcCfg->rlcBearerCfg.lcId   = rbId;
10354       lcCfg->rlcBearerCfg.lcType = LCH_DCCH;
10355       lcCfg->rlcBearerCfg.rlcMode = RLC_AM;
10356    }
10357    else if(rbType == RB_TYPE_DRB)
10358    {
10359       lcCfg->rlcBearerCfg.rbType = RB_TYPE_DRB;
10360       lcCfg->rlcBearerCfg.lcId   = lcId;
10361       lcCfg->rlcBearerCfg.lcType = LCH_DTCH;
10362       lcCfg->rlcBearerCfg.rlcMode = rlcMode;
10363    }
10364    if(f1RlcCfg) /* rlc mode config recived */
10365    {
10366       extractRlcModeCfg(lcCfg->rlcBearerCfg.rlcMode, &lcCfg->rlcBearerCfg, f1RlcCfg);
10367    }
10368    if(qoSInformation != NULLP)
10369    {
10370       if(qoSInformation->present == QoSInformation_PR_choice_extension)
10371       {
10372          if(qoSInformation->choice.choice_extension->value.present ==\
10373                QoSInformation_ExtIEs__value_PR_DRB_Information)
10374          {
10375             drbInfo = &qoSInformation->choice.choice_extension->value.choice.DRB_Information; 
10376             if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &lcCfg->rlcBearerCfg.snssai) != ROK)
10377             {
10378                DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information at procRlcLcCfg()");
10379                return;
10380             }
10381          }
10382       }
10383    }
10384 }
10385
10386 /*******************************************************************
10387  *
10388  * @brief Fills DrbQos Info received by CU
10389  *
10390  * @details
10391  *
10392  *    Function : extractQosInfo
10393  *
10394  *    Functionality: Fills DrbQos Info received  by CU
10395  *
10396  * @params[in] DrbQosInfo *qosToAdd, 
10397  *             QoSFlowLevelQoSParameters_t *qosFlowCfg
10398  * @return void
10399  *
10400  * ****************************************************************/
10401
10402 void extractQosInfo(DrbQosInfo *qosToAdd, QoSFlowLevelQoSParameters_t *qosFlowCfg)
10403 {
10404    uint8_t qosCntIdx = 0;
10405    ProtocolExtensionContainer_4624P74_t *qosIeExt = NULLP;
10406
10407    qosToAdd->fiveQiType = qosFlowCfg->qoS_Characteristics.present;
10408    qosToAdd->u.nonDyn5Qi.fiveQi     =\
10409                                      qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->fiveQI;
10410    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow)
10411    {
10412       qosToAdd->u.nonDyn5Qi.avgWindow = \
10413                                         *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
10414    }
10415
10416    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume)
10417    {
10418       qosToAdd->u.nonDyn5Qi.maxDataBurstVol = \
10419                                               *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
10420    }
10421
10422    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel)
10423    {
10424       qosToAdd->u.nonDyn5Qi.priorLevel = \
10425                                          *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel);
10426    }
10427    qosToAdd->ngRanRetPri.priorityLevel = \
10428                                          qosFlowCfg->nGRANallocationRetentionPriority.priorityLevel; 
10429    qosToAdd->ngRanRetPri.preEmptionCap = \
10430                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionCapability;
10431    qosToAdd->ngRanRetPri.preEmptionVul = \
10432                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionVulnerability;
10433    if(qosFlowCfg->gBR_QoS_Flow_Information)
10434    {
10435       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateDl, \
10436             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.buf, \
10437             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.size);
10438       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateUl, \
10439             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.buf, \
10440             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.size);
10441       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateDl,\
10442             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.buf, \
10443             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.size);
10444       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateUl,\
10445             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.buf, \
10446             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.size);
10447    }
10448    /*Extracting PDU_SESSION_ID*/
10449    qosIeExt = (ProtocolExtensionContainer_4624P74_t *)qosFlowCfg->iE_Extensions;
10450    if(qosIeExt)
10451    {
10452       for(qosCntIdx = 0; qosCntIdx < qosIeExt->list.count; qosCntIdx++)
10453       {
10454          if(qosIeExt->list.array[qosCntIdx]->extensionValue.present == \
10455                QoSFlowLevelQoSParameters_ExtIEs__extensionValue_PR_PDUSessionID)
10456          {
10457             qosToAdd->pduSessionId = qosIeExt->list.array[qosCntIdx]->extensionValue.choice.PDUSessionID;
10458             DU_LOG("\nDEBUG -->  DU_F1AP : extractQosInfo: PDU SessionID:%d",qosToAdd->pduSessionId);
10459          }
10460       }  
10461    }
10462    qosToAdd->ulPduSessAggMaxBitRate = 0;
10463 }
10464
10465 /*******************************************************************
10466  *
10467  * @brief Function to extract GTP Tunnel Info from CU
10468  *
10469  * @details
10470  *
10471  *    Function : extractUpTnlInfo
10472  *
10473  *    Functionality: Function to extract GTP Tunnel Info from CU
10474  *
10475  * @params[in] F1AP message
10476  * @return ROK/RFAILED
10477  *
10478  * ****************************************************************/
10479
10480 uint8_t extractUpTnlInfo(uint8_t drbId, uint8_t configType,\
10481    ULUPTNLInformation_ToBeSetup_List_t *tnlInfo, UpTnlCfg *upTnlInfo)
10482 {
10483    uint8_t tnlIdx;
10484    uint32_t ipv4_du = 0;
10485    GTPTunnel_t *gtpTunnel = NULLP;
10486
10487    upTnlInfo->drbId = drbId; 
10488    upTnlInfo->configType = configType;
10489 #ifdef O1_ENABLE
10490    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
10491 #else
10492    cmInetAddr((char *)DU_IP_V4_ADDR, &ipv4_du);
10493 #endif
10494
10495    for(tnlIdx=0; tnlIdx < tnlInfo->list.count; tnlIdx++)
10496    {
10497       if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.present == UPTransportLayerInformation_PR_gTPTunnel)
10498       {
10499          if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel)
10500          {
10501             gtpTunnel = tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel;
10502             DU_ALLOC(upTnlInfo->tnlCfg1, sizeof(GtpTnlCfg));
10503             if(upTnlInfo->tnlCfg1 == NULLP)
10504             {
10505                DU_LOG("\nERROR  -->  F1AP : extractUpTnlInfo: Failed to allocate mmeory for tunnel cfg 1");
10506                return RFAILED;
10507             }
10508             bitStringToInt(&gtpTunnel->transportLayerAddress, &upTnlInfo->tnlCfg1->ulTnlAddress);
10509             upTnlInfo->tnlCfg1->dlTnlAddress = ipv4_du;
10510             if(gtpTunnel->gTP_TEID.size > 0)
10511             {
10512                teIdStringToInt(gtpTunnel->gTP_TEID.buf, &upTnlInfo->tnlCfg1->teId);
10513             }
10514          }
10515          break;
10516       }
10517    }
10518    return ROK;
10519 }
10520
10521 /*******************************************************************
10522 *
10523 * @brief Function to extract Drb Qos Cfg Info from CU
10524 *
10525 * @details
10526 *
10527 *    Function : extractDrbQosCfg 
10528 *
10529 *    Functionality: Function to extract Drb Qos Cfg Info from CU
10530 *
10531 * @params[in] DRB_Information_t *drbInfo, LcCfg *macLcToAdd
10532 * @return ROK/RFAILED
10533 *
10534 * ****************************************************************/
10535
10536 uint8_t extractDrbQosCfg(DRB_Information_t *drbInfo, LcCfg *macLcToAdd ) 
10537 {
10538    if(!macLcToAdd->drbQos)
10539    {
10540       DU_ALLOC_SHRABL_BUF(macLcToAdd->drbQos, sizeof(DrbQosInfo));
10541       if(macLcToAdd->drbQos == NULLP)
10542       {
10543          DU_LOG("\nERROR  -->  DUAPP:Memory failed at allocating DrbQos at extractDrbQosCfg()");
10544          return RFAILED;
10545       }
10546
10547    }
10548    if(drbInfo->dRB_QoS.qoS_Characteristics.present == QoS_Characteristics_PR_non_Dynamic_5QI)
10549    {
10550       extractQosInfo(macLcToAdd->drbQos, &drbInfo->dRB_QoS);
10551       macLcToAdd->dlLcCfg.lcp = macLcToAdd->drbQos->ngRanRetPri.priorityLevel;
10552    }
10553    if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &macLcToAdd->snssai) != ROK)
10554    {
10555       DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information  at extractDrbQosCfg()");
10556       return RFAILED;
10557    }
10558    return ROK;
10559 }
10560 /*******************************************************************
10561  *
10562  * @brief Function to extract DRB info received from CU
10563  *
10564  * @details
10565  *
10566  *    Function : extractDrbCfg
10567  *
10568  *    Functionality: Function to extract DRB info received from CU
10569  *
10570  * @params[in] F1AP message
10571  * @return void
10572  *
10573  * ****************************************************************/
10574 uint8_t extractDrbCfg(DRBs_ToBeSetup_Item_t *drbItem, DRBs_ToBeSetupMod_Item_t *drbSetupModItem,\
10575 DRBs_ToBeModified_Item_t *drbModItem,  DuLcCfg *lcCfgToAdd, UpTnlCfg *upTnlInfo)
10576 {
10577    DRB_Information_t *drbInfo = NULLP;
10578
10579    if(drbItem != NULLP)
10580    {
10581       if(extractUpTnlInfo(drbItem->dRBID, CONFIG_ADD, &drbItem->uLUPTNLInformation_ToBeSetup_List, upTnlInfo) != ROK)
10582       {
10583          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10584          return RFAILED;
10585       }
10586       if(drbItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10587       {
10588          if(drbItem->qoSInformation.choice.choice_extension->value.present == QoSInformation_ExtIEs__value_PR_DRB_Information)
10589          {
10590             drbInfo = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10591             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10592             {
10593                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");
10594                return RFAILED;
10595             }
10596          }
10597       }
10598    }
10599    else if(drbSetupModItem != NULLP)
10600    {
10601       if(extractUpTnlInfo(drbSetupModItem->dRBID, CONFIG_ADD, &drbSetupModItem->uLUPTNLInformation_ToBeSetup_List,\
10602       upTnlInfo) != ROK)
10603       {
10604          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10605          return RFAILED;
10606       }
10607       if(drbSetupModItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10608       {
10609          if(drbSetupModItem->qoSInformation.choice.choice_extension->value.present ==\
10610          QoSInformation_ExtIEs__value_PR_DRB_Information)
10611          {
10612             drbInfo = &drbSetupModItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10613             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10614             {
10615                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10616                return RFAILED;
10617             }
10618
10619          }
10620       }
10621    }
10622    else if(drbModItem != NULLP)
10623    {
10624       if(extractUpTnlInfo(drbModItem->dRBID, CONFIG_MOD, &drbModItem->uLUPTNLInformation_ToBeSetup_List,\
10625       upTnlInfo) != ROK)
10626       {
10627          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10628          return RFAILED;
10629       }
10630       if(drbModItem->qoSInformation != NULLP)
10631       {
10632          if(drbModItem->qoSInformation->present == QoSInformation_PR_choice_extension)
10633          {
10634             if(drbModItem->qoSInformation->choice.choice_extension->value.present ==\
10635                   QoSInformation_ExtIEs__value_PR_DRB_Information)
10636             {
10637                drbInfo = &drbModItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information;
10638                if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10639                {
10640                   DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10641                   return RFAILED;
10642                }
10643
10644             }
10645          }
10646       }
10647    }
10648    return ROK;
10649 }
10650
10651 /*******************************************************************
10652  *
10653  * @brief Function to extract RB info received from CU
10654  *
10655  * @details
10656  *
10657  *    Function : extractMacRbCfg
10658  *
10659  *    Functionality: Function to extract RB info received from CU
10660  *
10661  * @params[in] F1AP message
10662  * @return ROK/RFAILED
10663  *
10664  * ****************************************************************/
10665
10666 uint8_t extractMacRbCfg(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbCfg,\
10667 DRBs_ToBeSetupMod_Item_t *drbSetupModCfg,  DRBs_ToBeModified_Item_t *drbModCfg, LogicalChannelConfig_t *ulLcCfg, DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10668 {
10669    if(drbCfg != NULLP)
10670    {
10671       if(extractDrbCfg(drbCfg, NULL, NULL, lcCfg, upTnlInfo) != ROK)
10672       {
10673          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10674          return RFAILED;
10675       }
10676    }
10677    else if(drbSetupModCfg != NULLP)
10678    { 
10679       if(extractDrbCfg(NULL, drbSetupModCfg, NULL, lcCfg, upTnlInfo) != ROK)
10680       {
10681          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10682          return RFAILED;
10683       }
10684    }
10685    else if(drbModCfg != NULLP)
10686    { 
10687       if(extractDrbCfg(NULL, NULL, drbModCfg, lcCfg, upTnlInfo) != ROK)
10688       {
10689          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10690          return RFAILED;
10691       }
10692    }
10693    else
10694    {
10695       lcCfg->lcConfig.drbQos = NULLP;
10696       lcCfg->lcConfig.snssai = NULLP;
10697       if(lcCfg->lcConfig.lcId == SRB2_LCID)
10698          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_3;
10699       else
10700          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_1;
10701
10702    }
10703    if(ulLcCfg)
10704    {
10705       lcCfg->lcConfig.ulLcCfgPres = true;
10706       extractUlLcCfg(&lcCfg->lcConfig.ulLcCfg, ulLcCfg);
10707    }
10708    else
10709       lcCfg->lcConfig.ulLcCfgPres = false;
10710    return ROK;
10711 }
10712
10713 /*******************************************************************
10714  *
10715  * @brief Function processing LC config info received from CU
10716  *
10717  * @details
10718  *
10719  *    Function : procMacLcCfg
10720  *
10721  *    Functionality: Function processing LC config info received from CU
10722  *
10723  * @params[in] F1AP message
10724  * @return ROK/RFAILED
10725  *
10726  * ****************************************************************/
10727
10728 uint8_t procMacLcCfg(uint8_t lcId, uint8_t rbType, uint8_t configType, DRBs_ToBeSetup_Item_t *drbItem,\
10729 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LogicalChannelConfig_t *ulLcCfg,\
10730 DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10731 {
10732    uint8_t ret = ROK;
10733
10734    lcCfg->lcConfig.lcId = lcId;
10735    lcCfg->configType = configType;
10736    if(rbType == RB_TYPE_SRB)
10737    {
10738       ret = extractMacRbCfg(lcId, NULL, NULL, NULL, ulLcCfg, lcCfg, NULL);
10739    }
10740    else if(rbType == RB_TYPE_DRB && upTnlInfo != NULLP)
10741    {
10742       if(drbItem != NULL)
10743         ret = extractMacRbCfg(lcId, drbItem, NULL, NULL, ulLcCfg, lcCfg, upTnlInfo);
10744       else if(drbSetupModItem != NULL)
10745         ret = extractMacRbCfg(lcId, NULL, drbSetupModItem, NULL, ulLcCfg, lcCfg, upTnlInfo);
10746       else if(drbModItem != NULL)
10747         ret = extractMacRbCfg(lcId, NULL, NULL, drbModItem, ulLcCfg, lcCfg, upTnlInfo);
10748    }
10749    return ret;
10750 }
10751
10752 /*******************************************************************
10753  *
10754  * @brief Function to extract Rlc cfg To Add/Mod in CellGrp Info
10755  *
10756  * @details
10757  *
10758  *    Function : extractRlcCfgToAddMod
10759  *
10760  *    Functionality: Function to extract Rlc cfg To Add/Mod in CellGrp Info
10761  *
10762  * @params[in] CellGroupConfigRrc__rlc_BearerTo pointer
10763  *             DuUeCfg Pointer
10764  * @return ROK/RFAILED
10765  *
10766  * ****************************************************************/
10767
10768 uint8_t extractRlcCfgToAddMod(struct CellGroupConfigRrc__rlc_BearerToAddModList *lcCfg, DuUeCfg *ueCfgDb)
10769 {
10770   uint8_t idx, rbId, lcId, rlcMode, rbType;
10771   RLC_Config_t *f1RlcCfg = NULLP;
10772   LogicalChannelConfig_t *macUlLcCfg = NULLP;
10773
10774   for(idx = 0; idx < lcCfg->list.count; idx++)
10775   {
10776      lcId = lcCfg->list.array[idx]->logicalChannelIdentity;
10777      if(lcCfg->list.array[idx]->servedRadioBearer)
10778      {
10779         /* RadioBearer for SRB/DRB */
10780         if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10781         RLC_BearerConfig__servedRadioBearer_PR_srb_Identity)
10782         {
10783            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.srb_Identity;
10784            rbType = RB_TYPE_SRB;
10785         }
10786         else if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10787         RLC_BearerConfig__servedRadioBearer_PR_drb_Identity)
10788         {
10789            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.drb_Identity;
10790            rbType = RB_TYPE_DRB;
10791         }
10792         else
10793         {
10794            DU_LOG("\nERROR  -->  No components present in Bearer config to ADD/MOD");
10795            return RFAILED;
10796         }
10797         /* MAC UL LC Config */
10798         if(lcCfg->list.array[idx]->mac_LogicalChannelConfig)
10799         {
10800            macUlLcCfg = lcCfg->list.array[idx]->mac_LogicalChannelConfig;
10801         }
10802      }
10803      else
10804      {
10805         DU_LOG("\nERROR  -->  DUAPP: Received RadioBearer config is NULL");
10806         return RFAILED;
10807      }
10808      /* RLC Mode Config */
10809      if(lcCfg->list.array[idx]->rlc_Config)
10810      {
10811         rlcMode  = lcCfg->list.array[idx]->rlc_Config->present;
10812         f1RlcCfg = lcCfg->list.array[idx]->rlc_Config;
10813      }
10814      
10815      /* Filling RLC/MAC Config*/
10816      memset(&ueCfgDb->macLcCfg[idx], 0, sizeof(DuLcCfg));
10817      memset(&ueCfgDb->rlcLcCfg[idx], 0, sizeof(DuRlcBearerCfg));
10818      procRlcLcCfg(rbId, lcId, rbType, rlcMode, CONFIG_UNKNOWN, f1RlcCfg, &(ueCfgDb->rlcLcCfg[idx]), NULLP);
10819      if(procMacLcCfg(lcId, rbType, CONFIG_UNKNOWN, NULL, NULL, NULL, macUlLcCfg, &ueCfgDb->macLcCfg[idx], NULL) != ROK)
10820      {
10821         DU_LOG("\nERROR  -->  DU APP : Failed while filling MAC LC config at extractRlcCfgToAddMod()");
10822         return RFAILED;
10823      }
10824      (ueCfgDb->numRlcLcs)++;
10825      (ueCfgDb->numMacLcs)++;
10826      DU_LOG("\nDEBUG  -> DUAPP: extractRlcCfgToAddMod:RBType:%d, DrbID: %d,lcId:%d, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
10827         rbType, rbId, lcId, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
10828   }
10829   //TODO: To send the failure cause in UeContextSetupRsp 
10830   return ROK;
10831 }
10832
10833 /*******************************************************************
10834  *
10835  * @brief DeAlloc pdsch serv cell config info
10836  *
10837  * @details
10838  *
10839  *    Function : freeMacPdschServCellInfo
10840  *
10841  *    Functionality: DeAlloc pdsch serv cell config info
10842  *
10843  * @params[in] PdschServCellCfg pointer
10844  * @return void
10845  *
10846  * ****************************************************************/
10847
10848 void freeMacPdschServCellInfo(PdschServCellCfg *pdsch)
10849 {
10850    if(pdsch->xOverhead)
10851    {
10852       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->xOverhead, sizeof(PdschXOverhead));
10853    }
10854    if(pdsch->codeBlkGrpFlushInd)
10855    {
10856       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->codeBlkGrpFlushInd, sizeof(bool));
10857    }
10858    if(pdsch->maxCodeBlkGrpPerTb)
10859    {
10860       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10861    }
10862    if(pdsch->maxMimoLayers)
10863    {
10864       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxMimoLayers, sizeof(uint8_t));
10865    }
10866 }
10867
10868 /*******************************************************************
10869  *
10870  * @brief Free Serving cell Info
10871  *
10872  * @details
10873  *
10874  *    Function : freeMacServingCellInfo
10875  *
10876  *    Functionality: Free Serving cell Info
10877  *
10878  * @params[in] ServCellCfgInfo *srvCellCfg
10879  * @return void
10880  *
10881  * ****************************************************************/
10882 void freeMacServingCellInfo(ServCellRecfgInfo *srvCellCfg)
10883 {
10884    uint8_t timeDomRsrcIdx;
10885
10886    if(srvCellCfg->initDlBwp.pdschPresent)
10887    {
10888       for(timeDomRsrcIdx = 0; timeDomRsrcIdx < srvCellCfg->initDlBwp.pdschCfg.numTimeDomRsrcAlloc; timeDomRsrcIdx++)
10889       {
10890          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, \
10891             srvCellCfg->initDlBwp.pdschCfg.timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
10892       }
10893    }
10894
10895    freeMacPdschServCellInfo(&srvCellCfg->pdschServCellCfg);
10896    if(srvCellCfg->bwpInactivityTmr)
10897    {
10898       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
10899    }
10900
10901    if(srvCellCfg->initUlBwp.pucchPresent)
10902    {
10903       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->initUlBwp.pucchCfg.dlDataToUlAck, sizeof(PucchDlDataToUlAck));
10904    }
10905 }
10906
10907 /*******************************************************************
10908  *
10909  * @brief Free cell Grp Cfg Info
10910  *
10911  * @details
10912  *
10913  *    Function : freeUeRecfgCellGrpInfo
10914  *
10915  *    Functionality: Free cell Grp Cfg Info
10916  *
10917  * @params[in] DuMacUeCfg*  duUeCfg
10918  * @return void
10919  *
10920  * ****************************************************************/
10921
10922 void freeUeRecfgCellGrpInfo(DuMacUeCfg *macUeCfg)
10923 {
10924    freeMacServingCellInfo(&macUeCfg->spCellCfg.servCellCfg);
10925 }
10926
10927 /*******************************************************************
10928  *
10929  * @brief Fills Reconfig SchReqReConfig
10930  *
10931  * @details
10932  *
10933  *    Function : extractSchReqReConfig
10934  *
10935  *    Functionality: Fills Reconfig SchReqReConfig
10936  *
10937  * @params[in] SchedulingRequestConfig_t *cuSchedReq
10938  *             SchedReqCfg*  macSchedReq
10939  * @return void
10940  *
10941  * ****************************************************************/
10942 void extractSchReqReConfig(SchedulingRequestConfig_t *cuSchedReq, SchedReqCfg *macSchedReq)
10943 {
10944    uint8_t schReqIdx = 0;
10945    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqListToAdd = NULLP;
10946    struct SchedulingRequestConfig__schedulingRequestToReleaseList *schReqListToRel = NULLP;
10947
10948    if(cuSchedReq->schedulingRequestToAddModList)
10949    {
10950       schReqListToAdd = cuSchedReq->schedulingRequestToAddModList;
10951       if(schReqListToAdd->list.count)
10952       {
10953          macSchedReq->addModListCount = schReqListToAdd->list.count;
10954          for(schReqIdx = 0; schReqIdx < schReqListToAdd->list.count; schReqIdx++)
10955          {
10956             macSchedReq->addModList[schReqIdx].schedReqId = \
10957                schReqListToAdd->list.array[schReqIdx]->schedulingRequestId;
10958             macSchedReq->addModList[schReqIdx].srProhibitTmr = \
10959                *(schReqListToAdd->list.array[schReqIdx]->sr_ProhibitTimer);
10960             macSchedReq->addModList[schReqIdx].srTransMax    =\
10961                schReqListToAdd->list.array[schReqIdx]->sr_TransMax;
10962          }
10963       }
10964    }
10965    /* Scheduling Req To release */
10966    if(cuSchedReq->schedulingRequestToReleaseList)
10967    {
10968       schReqListToRel = cuSchedReq->schedulingRequestToReleaseList;
10969       if(schReqListToRel->list.count)
10970       {
10971          macSchedReq->relListCount = schReqListToRel->list.count;
10972          for(schReqIdx = 0; schReqIdx < schReqListToRel->list.count; schReqIdx++)
10973          {
10974             macSchedReq->relList[schReqIdx] = \
10975                *schReqListToRel->list.array[schReqIdx];
10976          }
10977       }
10978    }
10979 }
10980
10981 /*******************************************************************
10982  *
10983  * @brief Fills TagReconfig
10984  *
10985  * @details
10986  *
10987  *    Function : extractTagReconfig
10988  *
10989  *    Functionality: Fills extractTagReconfig
10990  *
10991  * @params[in] TAG_Config_t *cuTagCfg
10992  *             TagCfg *macTagCfg
10993  * @return void
10994  *
10995  * ****************************************************************/
10996
10997 void extractTagReconfig(TAG_Config_t *cuTagCfg, TagCfg *macTagCfg)
10998 {
10999   uint8_t tagIdx = 0;
11000   struct TAG_Config__tag_ToAddModList  *tagListToAddMod = NULLP;
11001   struct TAG_Config__tag_ToReleaseList *tagListToRel = NULLP;
11002
11003   /* Tag config to AddMod */
11004   if(cuTagCfg->tag_ToAddModList)
11005   {
11006      tagListToAddMod = cuTagCfg->tag_ToAddModList; 
11007      if(tagListToAddMod->list.count)
11008      {
11009         macTagCfg->addModListCount = tagListToAddMod->list.count;
11010         for(tagIdx = 0; tagIdx < tagListToAddMod->list.count; tagIdx++)
11011         {
11012            macTagCfg->addModList[tagIdx].tagId =\
11013               tagListToAddMod->list.array[tagIdx]->tag_Id;     
11014            macTagCfg->addModList[tagIdx].timeAlignTimer = \
11015
11016               tagListToAddMod->list.array[tagIdx]->timeAlignmentTimer;
11017         }
11018      }
11019   }
11020   /* Tag config to release */
11021   if(cuTagCfg->tag_ToReleaseList)
11022   {
11023      tagListToRel = cuTagCfg->tag_ToReleaseList;
11024      if(tagListToRel->list.count)
11025      {
11026         macTagCfg->relListCount = tagListToRel->list.count;
11027         for(tagIdx = 0; tagIdx < tagListToRel->list.count; tagIdx++)
11028         {
11029            macTagCfg->relList[tagIdx] = *tagListToRel->list.array[tagIdx];     
11030         }
11031      }
11032   }
11033 }
11034
11035 /*******************************************************************
11036  *
11037  * @brief Fills PdcchCfg received by CU
11038  *
11039  * @details
11040  *
11041  *    Function : extractPdcchCfg
11042  *
11043  *    Functionality: Fills PdcchCfg received  by CU
11044  *
11045  * @params[in] PDCCH_Config_t *cuPdcchCfg,
11046  *             PdcchConfig *duPdcchCfg
11047  * @return void
11048  *
11049  * ****************************************************************/
11050
11051 void extractPdcchCfg(PDCCH_Config_t *cuPdcchCfg, PdcchConfig *macPdcchCfg)
11052 {
11053    uint8_t cRsetIdx = 0;
11054    uint8_t srchSpcIdx = 0;
11055
11056    struct PDCCH_Config__controlResourceSetToAddModList *cRsetToAddModList = NULLP;
11057    struct PDCCH_Config__controlResourceSetToReleaseList *cRsetToRelList = NULLP;
11058    struct PDCCH_Config__searchSpacesToAddModList *srchSpcToAddModList = NULLP;
11059    struct PDCCH_Config__searchSpacesToReleaseList *srchSpcToRelList = NULLP;
11060
11061
11062    /* Control Resource Set To Add/Mod List */
11063    if(cuPdcchCfg->controlResourceSetToAddModList)
11064    {
11065       cRsetToAddModList = cuPdcchCfg->controlResourceSetToAddModList;
11066       if(cRsetToAddModList->list.count)
11067       {
11068          macPdcchCfg->numCRsetToAddMod = cRsetToAddModList->list.count;
11069          for(cRsetIdx = 0; cRsetIdx < cRsetToAddModList->list.count; cRsetIdx++)
11070          {
11071             macPdcchCfg->cRSetToAddModList[cRsetIdx].cRSetId = \
11072                cRsetToAddModList->list.array[cRsetIdx]->controlResourceSetId;
11073             //freqDomRsrcBitStringToInt(&cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources,\
11074                   macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc);
11075             memcpy(macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc, \
11076                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.buf,
11077                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.size);
11078
11079             macPdcchCfg->cRSetToAddModList[cRsetIdx].duration = \
11080                 cRsetToAddModList->list.array[cRsetIdx]->duration;
11081
11082             macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType = \
11083                cRsetToAddModList->list.array[cRsetIdx]->cce_REG_MappingType.present;   
11084             if(macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType == CCE_REG_MAPPINGTYPE_PR_INTERLEAVED)
11085             {
11086                //TODO: handle the case for Interleaved
11087             }
11088             macPdcchCfg->cRSetToAddModList[cRsetIdx].precoderGranularity = \
11089                 cRsetToAddModList->list.array[cRsetIdx]->precoderGranularity;
11090             if(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID)
11091             {
11092                macPdcchCfg->cRSetToAddModList[cRsetIdx].dmrsScramblingId= \
11093                   *(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID);
11094             }
11095          }
11096       }
11097    }
11098    /* Control Resource Set To Release List */
11099    if(cuPdcchCfg->controlResourceSetToReleaseList)
11100    {
11101       cRsetToRelList = cuPdcchCfg->controlResourceSetToReleaseList;
11102       if(cRsetToRelList->list.count)
11103       {
11104          macPdcchCfg->numCRsetToRel = cRsetToRelList->list.count;
11105          for(cRsetIdx = 0; cRsetIdx < cRsetToRelList->list.count; cRsetIdx++)
11106          {
11107             macPdcchCfg->cRSetToRelList[cRsetIdx] = *(cRsetToRelList->list.array[cRsetIdx]);
11108          }
11109       }
11110    }
11111
11112    /* Search space To Add/Mod List */
11113    if(cuPdcchCfg->searchSpacesToAddModList)
11114    {
11115       srchSpcToAddModList = cuPdcchCfg->searchSpacesToAddModList;
11116       if(srchSpcToAddModList->list.count)
11117       {
11118          macPdcchCfg->numSearchSpcToAddMod = srchSpcToAddModList->list.count;
11119          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToAddModList->list.count; srchSpcIdx++)
11120          {
11121             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceId =\
11122                                                                           srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceId;
11123             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].cRSetId =\
11124                                                                     *(srchSpcToAddModList->list.array[srchSpcIdx]->controlResourceSetId);
11125             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset)
11126             {
11127                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSlotPeriodicityAndOffset =\
11128                                                                                          srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset->present;
11129             }
11130             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot)
11131             {
11132                bitStringToInt(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot,\
11133                      macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSymbolsWithinSlot);
11134             }
11135             if(srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates)
11136             {
11137                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel1 = \
11138                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel1;
11139                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel2 = \
11140                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel2;
11141                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel4 = \
11142                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel4;
11143
11144                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel8 = \
11145                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel8;
11146
11147                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel16 = \
11148                                                                                         srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel16;
11149             }
11150             if(srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType)
11151             {
11152                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType =\
11153                                                                                srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->present;
11154                if(macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType == SEARCHSPACETYPE_PR_UE_SPECIFIC)
11155                {
11156                   macPdcchCfg->searchSpcToAddModList[srchSpcIdx].ueSpecificDciFormat =\
11157                                                                                       srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->choice.ue_Specific->dci_Formats;
11158                }
11159
11160             }
11161          }
11162       }
11163    }
11164    /* Search space To Rel List */
11165    if(cuPdcchCfg->searchSpacesToReleaseList)
11166    {
11167       srchSpcToRelList = cuPdcchCfg->searchSpacesToReleaseList;
11168       if(srchSpcToRelList->list.count)
11169       {
11170          macPdcchCfg->numSearchSpcToRel = srchSpcToRelList->list.count;
11171          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToRelList->list.count; srchSpcIdx++)
11172          {
11173             macPdcchCfg->searchSpcToRelList[srchSpcIdx] =\
11174                                                          *(srchSpcToRelList->list.array[srchSpcIdx]);
11175          }
11176       }
11177    }
11178 }
11179
11180 /*******************************************************************
11181  *
11182  * @brief Fills PdschCfg received by CU
11183  *
11184  * @details
11185  *
11186  *    Function : extractPdschCfg
11187  *
11188  *    Functionality: Fills PdschCfg received  by CU
11189  *
11190  * @params[in] PDSCH_Config_t *cuPdschCfg = Information which is send by CU,
11191  *                   which we have stored in F1UeContextSetupDb,
11192  *             PdschConfig *macPdschCfg = Used to Store the information which
11193  *                   needs to send in other layer, as well as this can be the variable
11194  *                   which stores the information in DuCb,
11195  *             PdschConfig *storedPdschCfg =  Null in case of sending the
11196  *                   information to other layer else it will have stored pdsch 
11197  *                   configuration in copyOfmacUeCfg.
11198  * @return void
11199  *
11200  * ****************************************************************/
11201
11202 void extractPdschCfg(PDSCH_Config_t *cuPdschCfg, PdschConfig *macPdschCfg, PdschConfig *storedPdschCfg)
11203 {
11204    uint8_t timeDomIdx;
11205    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAlloc = NULLP;
11206
11207    if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
11208    {
11209       if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->present == \
11210             PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup)
11211       {
11212          if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup)
11213          {
11214             macPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
11215                *(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_AdditionalPosition);
11216          }
11217       }
11218    }
11219    macPdschCfg->resourceAllocType = cuPdschCfg->resourceAllocation;
11220    if(cuPdschCfg->pdsch_TimeDomainAllocationList)
11221    {
11222       timeDomAlloc = cuPdschCfg->pdsch_TimeDomainAllocationList;
11223       if(timeDomAlloc->present ==\
11224             PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup)
11225       {
11226          if(timeDomAlloc->choice.setup)
11227          {
11228             macPdschCfg->numTimeDomRsrcAlloc  = timeDomAlloc->choice.setup->list.count;
11229             for(timeDomIdx = 0; timeDomIdx < timeDomAlloc->choice.setup->list.count; timeDomIdx++)
11230             {
11231                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 = NULLP;
11232                if(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0)
11233                {
11234                   if(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 == NULL)
11235                   {
11236                      if(storedPdschCfg)
11237                      {
11238                         if(storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
11239                         {
11240                            macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 =\
11241                            storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0;
11242                         }
11243                         else
11244                         {
11245                            DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
11246                         }
11247                      }
11248                      else
11249                      {
11250                         DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
11251                      }
11252                      if(!macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
11253                      {
11254                         DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for k0 at extractPdschCfg()");
11255                         return;
11256                      }
11257                   }
11258                   *(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0) = \
11259                   *(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0);
11260                }
11261                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].mappingType = \
11262                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->mappingType;
11263                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].startSymbolAndLength = \
11264                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11265             }
11266          }
11267       }
11268    }
11269    macPdschCfg->rbgSize = cuPdschCfg->rbg_Size;
11270    if(cuPdschCfg->maxNrofCodeWordsScheduledByDCI)
11271       macPdschCfg->numCodeWordsSchByDci = *(cuPdschCfg->maxNrofCodeWordsScheduledByDCI);
11272    if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_staticBundling)
11273    {
11274       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11275       if(cuPdschCfg->prb_BundlingType.choice.staticBundling)
11276       {
11277          if(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize)
11278          {
11279             macPdschCfg->bundlingInfo.StaticBundling.size = \
11280                *(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize);
11281          }
11282       }
11283    }
11284    else if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_dynamicBundling)
11285    {
11286       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11287    }
11288
11289 }
11290
11291 /*******************************************************************
11292  *
11293  * @brief Fills PdschServingCellCfg received by CU
11294  *
11295  * @details
11296  *
11297  *    Function : extractPdschServingCellCfg
11298  *
11299  *    Functionality: Fills PdschCfg received  by CU
11300  *
11301  * @params[in] PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg,
11302  *             PdschServCellCfg *macUePdschSrvCellCfg
11303  * @return ROK/RFAILED
11304  *
11305  * ****************************************************************/
11306
11307 uint8_t extractPdschServingCellCfg(PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg, PdschServCellCfg *macUePdschSrvCellCfg)
11308 {
11309    if(cuPdschSrvCellCfg->codeBlockGroupTransmission)
11310    {
11311       if(cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup)
11312       {
11313          if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11314          {
11315             *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11316                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11317          }
11318          else
11319          {
11320             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
11321             if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11322             {
11323                *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11324                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11325             }
11326             else
11327             {
11328                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxCodeBlkGrpPerTb at extractPdschServingCellCfg()");
11329                return RFAILED;
11330             }
11331          }
11332          if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11333          {
11334             *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11335                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11336          }
11337          else
11338          {
11339             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->codeBlkGrpFlushInd , sizeof(bool));
11340             if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11341             {
11342                *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11343                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11344             }
11345             else
11346             {
11347                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for codeBlkGrpFlushInd at extractPdschServingCellCfg()");
11348                return RFAILED;
11349             }
11350          }
11351       }
11352    }
11353    if(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH)
11354    {
11355       macUePdschSrvCellCfg->numHarqProcForPdsch = *(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH); 
11356    }
11357    if(cuPdschSrvCellCfg->ext1)
11358    {
11359       if(cuPdschSrvCellCfg->ext1->maxMIMO_Layers)
11360       {
11361         if(macUePdschSrvCellCfg->maxMimoLayers)
11362         {
11363            *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11364         }
11365         else
11366         {
11367            DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxMimoLayers, sizeof(uint8_t));
11368            if(macUePdschSrvCellCfg->maxMimoLayers)
11369            {
11370               *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11371            }
11372            else
11373            {
11374               DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxMimoLayers at extractPdschServingCellCfg()");
11375               return RFAILED;
11376            }
11377         }
11378       }
11379    }
11380    if(cuPdschSrvCellCfg->xOverhead)
11381    {
11382       if(macUePdschSrvCellCfg->xOverhead)
11383       {
11384          *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11385       }
11386       else
11387       {
11388          DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->xOverhead, sizeof(PdschXOverhead));
11389          if(macUePdschSrvCellCfg->xOverhead)
11390          {
11391             *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11392          }
11393          else
11394          {
11395             DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for xOverhead at extractPdschServingCellCfg()");
11396             return RFAILED;
11397          }
11398       }
11399    }
11400    return ROK;
11401 }
11402
11403 /*******************************************************************
11404  *
11405  * @brief Fills PuschCfg received by CU
11406  *
11407  * @details
11408  *
11409  *    Function : extractPuschCfg
11410  *
11411  *    Functionality: Fills PuschCfg received  by CU
11412  *
11413  * @params[in] BWP_UplinkDedicated__pusch_Config *cuPuschCfg,
11414  *             PuschCfg *macPuschCfg
11415  * @return void
11416  *
11417  * ****************************************************************/
11418
11419 void extractPuschCfg(struct BWP_UplinkDedicated__pusch_Config *cuPuschCfg, PuschCfg *macPuschCfg)
11420 {
11421    uint8_t timeDomIdx = 0;
11422    DMRS_UplinkConfig_t *dmrsUlCfg = NULLP;
11423    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList = NULLP;
11424
11425    if(cuPuschCfg->present == BWP_UplinkDedicated__pusch_Config_PR_setup)
11426    {
11427       if(cuPuschCfg->choice.setup)
11428       {
11429          if(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH)
11430          {
11431              macPuschCfg->dataScramblingId = \
11432                 *(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH);
11433          }
11434          if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA)
11435          {
11436             if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->present == PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup)
11437             {
11438                if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup)
11439                {
11440                   dmrsUlCfg = (cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup);
11441                   if(dmrsUlCfg->dmrs_AdditionalPosition)
11442                   {
11443                      macPuschCfg->dmrsUlCfgForPuschMapTypeA.addPos =\
11444                         *(dmrsUlCfg->dmrs_AdditionalPosition);
11445                   }
11446                   if(dmrsUlCfg->transformPrecodingDisabled)
11447                   {
11448                      if(dmrsUlCfg->transformPrecodingDisabled->scramblingID0)
11449                      {
11450                         macPuschCfg->dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0 = \
11451                            *(dmrsUlCfg->transformPrecodingDisabled->scramblingID0);
11452                      }
11453                   }
11454                }
11455             }
11456          }
11457          /*Res Alloc Type for UL */
11458          if(cuPuschCfg->choice.setup->resourceAllocation)
11459          {
11460             macPuschCfg->resourceAllocType = \
11461                cuPuschCfg->choice.setup->resourceAllocation;
11462          }
11463          if(cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList)
11464          {
11465             timeDomAllocList = cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList;
11466             if(timeDomAllocList->present == PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup)
11467             {
11468                if(timeDomAllocList->choice.setup)
11469                {
11470                   macPuschCfg->numTimeDomRsrcAlloc = timeDomAllocList->choice.setup->list.count;
11471                   for(timeDomIdx = 0; timeDomIdx <timeDomAllocList->choice.setup->list.count; timeDomIdx++)
11472                   {
11473                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].k2 = \
11474                         *(timeDomAllocList->choice.setup->list.array[timeDomIdx]->k2);
11475                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].mappingType = \
11476                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->mappingType;
11477                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].startSymbolAndLength = \
11478                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11479                   }
11480                }
11481             }
11482          }
11483          if(cuPuschCfg->choice.setup->transformPrecoder)
11484             macPuschCfg->transformPrecoder = *(cuPuschCfg->choice.setup->transformPrecoder);
11485       }
11486    }
11487 }
11488
11489 /*******************************************************************
11490  *
11491  * @brief Function to fill pucch Power Control
11492  *
11493  * @details
11494  *
11495  *    Function : extractPucchPowerControl
11496  *
11497  *    Functionality: Function to fill pucch Power Control
11498  *
11499  * @params[in] PucchPowerControl *pwrCtrl,
11500  *             struct PUCCH_PowerControl *cuPwrCtrlCfg
11501  * @return void
11502  *
11503  * ****************************************************************/
11504
11505 void extractPucchPowerControl(PucchPowerControl *pwrCtrl, struct PUCCH_PowerControl *cuPwrCtrlCfg)
11506 {
11507    uint8_t arrIdx;
11508
11509    if(cuPwrCtrlCfg->deltaF_PUCCH_f0)
11510       pwrCtrl->deltaF_Format0 = *cuPwrCtrlCfg->deltaF_PUCCH_f0;
11511    if(cuPwrCtrlCfg->deltaF_PUCCH_f1)
11512       pwrCtrl->deltaF_Format1 = *cuPwrCtrlCfg->deltaF_PUCCH_f1;
11513    if(cuPwrCtrlCfg->deltaF_PUCCH_f2)
11514       pwrCtrl->deltaF_Format2 = *cuPwrCtrlCfg->deltaF_PUCCH_f2;
11515    if(cuPwrCtrlCfg->deltaF_PUCCH_f3)
11516       pwrCtrl->deltaF_Format3 = *cuPwrCtrlCfg->deltaF_PUCCH_f3;
11517    if(cuPwrCtrlCfg->deltaF_PUCCH_f4)
11518       pwrCtrl->deltaF_Format4 = *cuPwrCtrlCfg->deltaF_PUCCH_f4;
11519    if(cuPwrCtrlCfg->p0_Set)
11520    {
11521       pwrCtrl->p0SetCount = cuPwrCtrlCfg->p0_Set->list.count;
11522       for(arrIdx=0; arrIdx < pwrCtrl->p0SetCount; arrIdx++)
11523       {
11524          pwrCtrl->p0Set[arrIdx].p0PucchId =\
11525             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Id;
11526          pwrCtrl->p0Set[arrIdx].p0PucchVal =\
11527             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Value;
11528       }
11529    }
11530    if(cuPwrCtrlCfg->pathlossReferenceRSs)
11531    {
11532       pwrCtrl->pathLossRefRSListCount = cuPwrCtrlCfg->pathlossReferenceRSs->list.count;
11533       for(arrIdx = 0; arrIdx < pwrCtrl->pathLossRefRSListCount; arrIdx++)
11534       {
11535          pwrCtrl->pathLossRefRSList[arrIdx].pathLossRefRSId =\
11536             cuPwrCtrlCfg->pathlossReferenceRSs->list.array[arrIdx]->pucch_PathlossReferenceRS_Id;
11537       }
11538    }
11539 }
11540  
11541  /*******************************************************************
11542  *
11543  * @brief Function to extractResrcSetToAddModList sent by CU
11544  *
11545  * @details
11546  *
11547  *    Function : extractResrcSetToAddModList
11548  *
11549  *    Functionality: Fucntion to extractResrcSetToAddModList
11550  *
11551  * @params[in] PucchResrcSetCfg pointer,
11552  *             struct PUCCH_Config__resourceSetToAddModList pointer
11553  * @return void
11554  *
11555  * ****************************************************************/
11556
11557 void extractResrcSetToAddModList(PucchResrcSetCfg *macRsrcSetList, struct PUCCH_Config__resourceSetToAddModList *cuRsrcSetList)
11558 {
11559    uint8_t arrIdx, rsrcListIdx;
11560
11561    macRsrcSetList->resrcSetToAddModListCount = cuRsrcSetList->list.count; 
11562    for(arrIdx = 0; arrIdx < macRsrcSetList->resrcSetToAddModListCount; arrIdx++)
11563    {
11564       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcSetId     =\
11565          cuRsrcSetList->list.array[arrIdx]->pucch_ResourceSetId;
11566       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount =\
11567          cuRsrcSetList->list.array[arrIdx]->resourceList.list.count;
11568       for(rsrcListIdx = 0; rsrcListIdx < macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount; rsrcListIdx++)
11569       {
11570          macRsrcSetList->resrcSetToAddModList[arrIdx].resrcList[rsrcListIdx] =\
11571             *cuRsrcSetList->list.array[arrIdx]->resourceList.list.array[rsrcListIdx];
11572       }
11573
11574       if(cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1)
11575       {
11576          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize =\
11577             *cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1;
11578       }
11579       else
11580       {
11581          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize = 0;
11582       }
11583    }
11584 }/* End of extractResrcSetToAddModList */
11585
11586 /*******************************************************************
11587  *
11588  * @brief Fills extractResrcToAddModList sent by CU
11589  *
11590  * @details
11591  *
11592  *    Function : extractResrcToAddModList
11593  *
11594  *    Functionality: Fills extractResrcToAddModList
11595  *
11596  * @params[in] PucchResrcCfg pointer,
11597  *             struct PUCCH_Config__resourceToAddModList pointer
11598  * @return ROk/RFAILED
11599  *
11600  * ****************************************************************/
11601
11602 uint8_t extractResrcToAddModList(PucchResrcCfg *macResrcList, struct PUCCH_Config__resourceToAddModList *cuResrcList)
11603 {
11604    uint8_t arrIdx;
11605    
11606    macResrcList->resrcToAddModListCount = cuResrcList->list.count;
11607    for(arrIdx = 0; arrIdx < macResrcList->resrcToAddModListCount; arrIdx++)
11608    {
11609       macResrcList->resrcToAddModList[arrIdx].resrcId      =\
11610         cuResrcList->list.array[arrIdx]->pucch_ResourceId; 
11611       macResrcList->resrcToAddModList[arrIdx].startPrb     =\
11612         cuResrcList->list.array[arrIdx]->startingPRB;
11613       if(cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping)
11614       {
11615          macResrcList->resrcToAddModList[arrIdx].intraFreqHop =\
11616            *cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping;
11617       }
11618       if(cuResrcList->list.array[arrIdx]->secondHopPRB)
11619       {
11620          macResrcList->resrcToAddModList[arrIdx].secondPrbHop =\
11621            *cuResrcList->list.array[arrIdx]->secondHopPRB;
11622       }
11623       /* PUCCH RSRC FORMAT */
11624       if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format0)
11625       {
11626          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_0;
11627          if(cuResrcList->list.array[arrIdx]->format.choice.format0)
11628          {
11629             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0, sizeof(PucchFormat0));
11630             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0 == NULLP)
11631             {
11632                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format0 in extractResrcToAddModList()");
11633                return RFAILED;
11634             }
11635             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->initialCyclicShift =\
11636                cuResrcList->list.array[arrIdx]->format.choice.format0->initialCyclicShift;
11637             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->numSymbols =\
11638                cuResrcList->list.array[arrIdx]->format.choice.format0->nrofSymbols;
11639             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->startSymbolIdx =\
11640                cuResrcList->list.array[arrIdx]->format.choice.format0->startingSymbolIndex;
11641          }
11642       }
11643       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format1)
11644       {
11645          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_1;
11646          if(cuResrcList->list.array[arrIdx]->format.choice.format1)
11647          {
11648             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1, sizeof(PucchFormat1));
11649             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1 == NULLP)
11650             {
11651                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format1 in extractResrcToAddModList()");
11652                return RFAILED;
11653             }
11654             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->initialCyclicShift =\
11655                 cuResrcList->list.array[arrIdx]->format.choice.format1->initialCyclicShift;
11656             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->numSymbols =\
11657                 cuResrcList->list.array[arrIdx]->format.choice.format1->nrofSymbols;
11658             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->startSymbolIdx =\
11659                 cuResrcList->list.array[arrIdx]->format.choice.format1->startingSymbolIndex;
11660             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->timeDomOCC =\
11661                 cuResrcList->list.array[arrIdx]->format.choice.format1->timeDomainOCC;
11662          }
11663       }
11664       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format2)
11665       {
11666          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_2;
11667          if(cuResrcList->list.array[arrIdx]->format.choice.format2)
11668          {
11669             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
11670             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2 == NULLP)
11671             {
11672                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format2 in extractResrcToAddModList()");
11673                return RFAILED;
11674             }
11675             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numPrbs =\
11676                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofPRBs;
11677             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numSymbols =\
11678                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofSymbols;
11679             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->startSymbolIdx =\
11680                 cuResrcList->list.array[arrIdx]->format.choice.format2->startingSymbolIndex;
11681          }
11682       }
11683       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format3)
11684       {
11685          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_3;
11686          if(cuResrcList->list.array[arrIdx]->format.choice.format3)
11687          {
11688             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
11689             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3 == NULLP)
11690             {
11691                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format3 in extractResrcToAddModList()");
11692                return RFAILED;
11693             }
11694             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numPrbs =\
11695                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofPRBs;
11696             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numSymbols =\
11697                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofSymbols;
11698             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->startSymbolIdx =\
11699                 cuResrcList->list.array[arrIdx]->format.choice.format3->startingSymbolIndex;
11700          }
11701       }
11702       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format4)
11703       {
11704          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_4;
11705          if(cuResrcList->list.array[arrIdx]->format.choice.format4)
11706          {
11707             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4, sizeof(PucchFormat4));
11708             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4 == NULLP)
11709             {
11710                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format4 in extractResrcToAddModList()");
11711                return RFAILED;
11712             }
11713             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->numSymbols =\
11714                 cuResrcList->list.array[arrIdx]->format.choice.format4->nrofSymbols;
11715             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occLen =\
11716                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Length;
11717             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occIdx =\
11718                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Index;
11719             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->startSymbolIdx =\
11720                 cuResrcList->list.array[arrIdx]->format.choice.format4->startingSymbolIndex;
11721          }
11722       }
11723    }
11724    return ROK;
11725
11726 }/* End of extractResrcToAddModList */
11727
11728 /*******************************************************************
11729  *
11730  * @brief Fills fillPucchSchedReqPeriodAndOffset sent by CU
11731  *
11732  * @details
11733  *
11734  *    Function : fillPucchSchedReqPeriodAndOffset
11735  *
11736  *    Functionality: To fillPucchSchedReqPeriodAndOffset
11737  *
11738  * @params[in] macPeriodicty,
11739  *     SchedulingRequestResourceConfig__periodicityAndOffset pointer
11740  * @return void
11741  *
11742  * ****************************************************************/
11743
11744 void fillPucchSchedReqPeriodAndOffset(uint8_t macPeriodicty, uint16_t  macOffset,\
11745    struct SchedulingRequestResourceConfig__periodicityAndOffset *cuPeriodicty)
11746 {
11747    macPeriodicty = cuPeriodicty->present;
11748    switch(macPeriodicty)
11749    {
11750       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
11751          {
11752             macOffset     = cuPeriodicty->choice.sym2;
11753             break;
11754          }
11755       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
11756          {
11757             macOffset     = cuPeriodicty->choice.sym6or7;
11758             break;
11759          }
11760       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
11761          {
11762             macOffset     = cuPeriodicty->choice.sl1;
11763             break;
11764          }
11765       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
11766          {
11767             macOffset = cuPeriodicty->choice.sl2;
11768             break;
11769          }
11770       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
11771          {
11772             macOffset = cuPeriodicty->choice.sl4;
11773             break;
11774          }
11775       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
11776          {
11777             macOffset = cuPeriodicty->choice.sl5;
11778             break;
11779          }
11780       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
11781          {
11782             macOffset = cuPeriodicty->choice.sl8;
11783             break;
11784          }
11785       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
11786          {
11787             macOffset = cuPeriodicty->choice.sl10;
11788             break;
11789          }
11790       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
11791          {
11792             macOffset = cuPeriodicty->choice.sl16;
11793             break;
11794          }
11795       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
11796          {
11797             macOffset = cuPeriodicty->choice.sl20;
11798             break;
11799          }
11800       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
11801          {
11802             macOffset = cuPeriodicty->choice.sl40;
11803             break;
11804          }
11805       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
11806          {
11807             macOffset = cuPeriodicty->choice.sl80;
11808             break;
11809          }
11810       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
11811          {
11812             macOffset = cuPeriodicty->choice.sl160;
11813             break;
11814          }
11815       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
11816          {
11817             macOffset = cuPeriodicty->choice.sl320;
11818             break;
11819          }
11820       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
11821          {
11822             macOffset = cuPeriodicty->choice.sl640;
11823             break;
11824          }
11825       default :
11826          DU_LOG("\nERROR  -->  F1AP : Invalid periodicity %d", macPeriodicty);
11827    }
11828 }
11829
11830 /*******************************************************************
11831  *
11832  * @brief Function to extractPucchFormatCfg sent by CU
11833  *
11834  * @details
11835  *
11836  *    Function : extractPucchFormatCfg
11837  *
11838  *    Functionality: Function to extractPucchFormatCfg
11839  *
11840  * @params[in] PucchFormatCfg pointer,
11841  *             PUCCH_FormatConfig_t pointer
11842  * @return void
11843  *
11844  * ****************************************************************/
11845
11846 void extractPucchFormatCfg(PucchFormatCfg *macFormatCfg, PUCCH_FormatConfig_t *cuFormatCfg)
11847  {
11848     if(cuFormatCfg->interslotFrequencyHopping)
11849        macFormatCfg->interSlotFreqHop = *cuFormatCfg->interslotFrequencyHopping;
11850     if(cuFormatCfg->additionalDMRS)  
11851        macFormatCfg->addDmrs = *cuFormatCfg->additionalDMRS;
11852     if(cuFormatCfg->maxCodeRate)
11853        macFormatCfg->maxCodeRate = *cuFormatCfg->maxCodeRate;
11854     if(cuFormatCfg->nrofSlots)  
11855        macFormatCfg->numSlots = *cuFormatCfg->nrofSlots;
11856     if(cuFormatCfg->pi2BPSK)  
11857        macFormatCfg->pi2BPSK = *cuFormatCfg->pi2BPSK;
11858     if(cuFormatCfg->simultaneousHARQ_ACK_CSI)  
11859        macFormatCfg->harqAckCSI = *cuFormatCfg->simultaneousHARQ_ACK_CSI;
11860  }/* End of extractPucchFormatCfg */
11861
11862 /*******************************************************************
11863  *
11864  * @brief Function to extractSchedReqCfgToAddMod sent by CU
11865  *
11866  * @details
11867  *
11868  *    Function : extractSchedReqCfgToAddMod
11869  *
11870  *    Functionality: Function to extractSchedReqCfgToAddMod
11871  *
11872  * @params[in] PucchSchedReqCfg pointer,
11873  *      PUCCH_Config__schedulingRequestResourceToAddModList pointer
11874  * @return void
11875  *
11876  * ****************************************************************/
11877
11878 void extractSchedReqCfgToAddMod(PucchSchedReqCfg *macSchedReqCfg, struct PUCCH_Config__schedulingRequestResourceToAddModList *cuSchedReqList)
11879 {
11880    uint8_t arrIdx;
11881
11882    macSchedReqCfg->schedAddModListCount = cuSchedReqList->list.count;
11883    for(arrIdx = 0; arrIdx <  macSchedReqCfg->schedAddModListCount; arrIdx++)
11884    {
11885       macSchedReqCfg->schedAddModList[arrIdx].resrcId =\
11886          cuSchedReqList->list.array[arrIdx]->schedulingRequestResourceId;
11887       macSchedReqCfg->schedAddModList[arrIdx].requestId =\
11888          cuSchedReqList->list.array[arrIdx]->schedulingRequestID;
11889       if(cuSchedReqList->list.array[arrIdx]->periodicityAndOffset)
11890       {
11891          fillPucchSchedReqPeriodAndOffset(macSchedReqCfg->schedAddModList[arrIdx].periodicity,\
11892             macSchedReqCfg->schedAddModList[arrIdx].offset, cuSchedReqList->list.array[arrIdx]->periodicityAndOffset);
11893       }
11894       if(cuSchedReqList->list.array[arrIdx]->resource)
11895       {
11896          macSchedReqCfg->schedAddModList[arrIdx].resrc =\
11897             *cuSchedReqList->list.array[arrIdx]->resource;
11898       }
11899    }
11900
11901 }/* End of extractSchedReqCfgToAddMod */
11902
11903  /*******************************************************************
11904  *
11905  * @brief Fills PucchCfg received by CU
11906  *
11907  * @details
11908  *
11909  *    Function : extractPucchCfg
11910  *
11911  *    Functionality: Fills PucchCfg received  by CU
11912  *
11913  * @params[in] BWP_UplinkDedicated__pucch_Config *cuPucchCfg = Information which
11914  *                is send by CU, which we have stored in F1UeContextSetupDb,
11915  *             PucchCfg *macPucchCfg = Used to Store the information which
11916  *                needs to send in other layer, as well as this can be the variable
11917  *                which stores the information in DuCb,
11918  *             PucchCfg *storedPucchCfg = Null in case of sending the
11919  *                information to other layer else it will have Pucch Cfg which
11920  *                we have stored in copyOfmacUeCfg.
11921  * @return ROK/RFAILED
11922  *
11923  * ****************************************************************/
11924
11925 uint8_t extractPucchCfg(struct BWP_UplinkDedicated__pucch_Config *cuPucchCfg, PucchCfg *macPucchCfg,\
11926 PucchCfg *storedPucchCfg)        
11927 {
11928    uint8_t arrIdx;
11929
11930    if(cuPucchCfg->present == BWP_UplinkDedicated__pucch_Config_PR_setup)
11931    {
11932       if(cuPucchCfg->choice.setup)
11933       {
11934          /* Resource Set Cfg */ 
11935          if(cuPucchCfg->choice.setup->resourceSetToAddModList)
11936          {
11937             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrcSet, sizeof(PucchResrcSetCfg));
11938             if(macPucchCfg->resrcSet == NULLP)
11939             {
11940                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc set List in extractPucchCfg()");
11941                return RFAILED;
11942             }
11943             memset(macPucchCfg->resrcSet, 0, sizeof(PucchResrcSetCfg));
11944             extractResrcSetToAddModList(macPucchCfg->resrcSet, cuPucchCfg->choice.setup->resourceSetToAddModList);
11945          }
11946          
11947          /* Resource Cfg */ 
11948          if(cuPucchCfg->choice.setup->resourceToAddModList)
11949          {
11950             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrc, sizeof(PucchResrcCfg));
11951             if(macPucchCfg->resrc == NULLP)
11952             {
11953                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc List in extractPucchCfg()");
11954                return RFAILED;
11955             }
11956             memset(macPucchCfg->resrc, 0, sizeof(PucchResrcCfg));
11957             extractResrcToAddModList(macPucchCfg->resrc, cuPucchCfg->choice.setup->resourceToAddModList);
11958          }
11959          
11960          /* Format 1 Cfg */ 
11961          if(cuPucchCfg->choice.setup->format1)
11962          {
11963             DU_ALLOC_SHRABL_BUF(macPucchCfg->format1, sizeof(PucchFormatCfg));
11964             if(macPucchCfg->format1 == NULLP)
11965             {
11966                DU_LOG("\nERROR --> F1AP : Failed to extract format 1 Cfg in  extractPucchCfg()");
11967                return RFAILED;
11968             }
11969             memset(macPucchCfg->format1, 0, sizeof(PucchFormatCfg));
11970             extractPucchFormatCfg(macPucchCfg->format1,\
11971                cuPucchCfg->choice.setup->format1->choice.setup);
11972          }
11973          
11974          /* Format 2 Cfg */
11975          if(cuPucchCfg->choice.setup->format2)
11976          {
11977             DU_ALLOC_SHRABL_BUF(macPucchCfg->format2, sizeof(PucchFormatCfg));
11978             if(macPucchCfg->format2 == NULLP)
11979             {
11980                DU_LOG("\nERROR --> F1AP : Failed to extract format 2 Cfg in  extractPucchCfg()");
11981                return RFAILED;
11982             }
11983             memset(macPucchCfg->format2, 0, sizeof(PucchFormatCfg));
11984             extractPucchFormatCfg(macPucchCfg->format2,\
11985                cuPucchCfg->choice.setup->format2->choice.setup);
11986          }
11987          
11988          /* Format 3 Cfg */
11989          if(cuPucchCfg->choice.setup->format3)
11990          {
11991             DU_ALLOC_SHRABL_BUF(macPucchCfg->format3, sizeof(PucchFormatCfg));
11992             if(macPucchCfg->format3 == NULLP)
11993             {
11994                DU_LOG("\nERROR --> F1AP : Failed to extract format 3 Cfg in  extractPucchCfg()");
11995                return RFAILED;
11996             }
11997             memset(macPucchCfg->format3, 0, sizeof(PucchFormatCfg));
11998             extractPucchFormatCfg(macPucchCfg->format3,\
11999                cuPucchCfg->choice.setup->format3->choice.setup);
12000          }
12001
12002          /* Format 4 Cfg */
12003          if(cuPucchCfg->choice.setup->format4)
12004          {
12005             DU_ALLOC_SHRABL_BUF(macPucchCfg->format4, sizeof(PucchFormatCfg));
12006             if(macPucchCfg->format4 == NULLP)
12007             {
12008                DU_LOG("\nERROR --> F1AP : Failed to extract format 4 Cfg in  extractPucchCfg()");
12009                return RFAILED;
12010             }
12011             memset(macPucchCfg->format4, 0, sizeof(PucchFormatCfg));
12012             extractPucchFormatCfg(macPucchCfg->format4,\
12013                cuPucchCfg->choice.setup->format4->choice.setup);
12014          }
12015
12016          /* Sched Req List */
12017          if(cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList)
12018          {
12019             DU_ALLOC_SHRABL_BUF(macPucchCfg->schedReq, sizeof(PucchSchedReqCfg));
12020             if(macPucchCfg->schedReq == NULLP)
12021             {
12022                DU_LOG("\nERROR --> F1AP : Failed to extract schedReqCfg in  extractPucchCfg()");
12023                return RFAILED;
12024             }
12025             memset(macPucchCfg->schedReq, 0, sizeof(PucchSchedReqCfg));
12026             extractSchedReqCfgToAddMod(macPucchCfg->schedReq,\
12027             cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList);
12028          }
12029
12030          /*TODO: Add support for  Spatial Info */
12031
12032          /* MultiCsiCfg */
12033          if(cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList)
12034          {
12035             DU_ALLOC_SHRABL_BUF(macPucchCfg->multiCsiCfg, sizeof(PucchMultiCsiCfg));
12036             if(macPucchCfg->multiCsiCfg == NULLP)
12037             {
12038                DU_LOG("\nERROR --> F1AP : Failed to extract multiCsiCfg in  extractPucchCfg()");
12039                return RFAILED;
12040             }
12041             memset(macPucchCfg->multiCsiCfg, 0, sizeof(PucchMultiCsiCfg));
12042             macPucchCfg->multiCsiCfg->multiCsiResrcListCount = cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.count;
12043             for(arrIdx =0; arrIdx < macPucchCfg->multiCsiCfg->multiCsiResrcListCount; arrIdx++)
12044             {
12045                macPucchCfg->multiCsiCfg->multiCsiResrcList[arrIdx] =\
12046                  *cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.array[arrIdx];
12047             }
12048          }
12049
12050          /* Dl_DataToUL_ACK */ 
12051          if(cuPucchCfg->choice.setup->dl_DataToUL_ACK)
12052     {
12053        if(storedPucchCfg)
12054        {
12055           if(storedPucchCfg->dlDataToUlAck)
12056           {
12057              macPucchCfg->dlDataToUlAck = storedPucchCfg->dlDataToUlAck; 
12058           }
12059           else
12060           {
12061             DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
12062           }
12063        }
12064        else
12065        {
12066           DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
12067        }
12068        if(macPucchCfg->dlDataToUlAck == NULLP)
12069        {
12070           DU_LOG("\nERROR --> F1AP : Failed to extract Dl_DataToUL_ACK in extractPucchCfg()");
12071           return RFAILED;
12072        }
12073        memset(macPucchCfg->dlDataToUlAck, 0, sizeof(PucchDlDataToUlAck));
12074        macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount = cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.count;
12075        for(arrIdx = 0; arrIdx < macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; arrIdx++)
12076        {
12077           macPucchCfg->dlDataToUlAck->dlDataToUlAckList[arrIdx] =\
12078           *cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.array[arrIdx];
12079        }
12080          }
12081
12082          /* Power Control */
12083          if(cuPucchCfg->choice.setup->pucch_PowerControl)
12084          {
12085             DU_ALLOC_SHRABL_BUF(macPucchCfg->powerControl, sizeof(PucchPowerControl));
12086             if(macPucchCfg->powerControl == NULLP)
12087             {
12088                DU_LOG("\nERROR --> F1AP : Failed to extract power control in extractPucchCfg()");
12089                return RFAILED;
12090             }
12091             extractPucchPowerControl(macPucchCfg->powerControl,\
12092                cuPucchCfg->choice.setup->pucch_PowerControl);
12093          }
12094       }
12095    }
12096    return ROK;
12097 }
12098
12099 /*******************************************************************
12100  *
12101  * @brief Fills ServingCellReconfig received by CU
12102  *
12103  * @details
12104  *
12105  *    Function : extractSpCellDedicatedCfg
12106  *
12107  *    Functionality: Fills ServingCellReconfig received  by CU
12108  *
12109  * @params[in] ServingCellConfig_t *cuSrvCellCfg = Information which is send by
12110  *                  CU, which we have stored in F1UeContextSetupDb,
12111  *             ServCellCfgInfo *macSrvCellCfg = Used to Store the information
12112  *                  which  needs to send in other layer, as well as this can be the
12113  *                  variable which stores the information in DuCb, 
12114  *             ServCellCfgInfo *storedSrvCellCfg = Null in case of sending the
12115  *                  information to other layer else it will have ServCellCfgInfo which
12116  *                  we have stored in copyOfmacUeCfg.
12117  * @return ROK/RFAILD
12118  *
12119  * ****************************************************************/
12120 uint8_t extractSpCellDedicatedCfg(ServingCellConfig_t *cuSrvCellCfg, ServCellRecfgInfo *macSrvCellCfg,\
12121 ServCellRecfgInfo *storedSrvCellCfg)
12122 {
12123    uint8_t ret = ROK;
12124    BWP_DownlinkDedicated_t *dlBwp = NULLP;
12125    BWP_UplinkDedicated_t   *ulBwp = NULLP;
12126
12127    if(cuSrvCellCfg->initialDownlinkBWP)
12128    {
12129       dlBwp = ((BWP_DownlinkDedicated_t *)(cuSrvCellCfg->initialDownlinkBWP));
12130       if(dlBwp->pdcch_Config)
12131       {
12132          if(dlBwp->pdcch_Config->choice.setup)
12133          {
12134             macSrvCellCfg->initDlBwp.pdcchPresent = true;
12135             if(storedSrvCellCfg)
12136             {
12137                if(!storedSrvCellCfg->initDlBwp.pdcchPresent)
12138                {
12139                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12140                }
12141                else
12142                {
12143                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12144                }
12145             }
12146             else
12147             {
12148                extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12149             }
12150          }
12151       }
12152       if(dlBwp->pdsch_Config)
12153       {
12154          if(dlBwp->pdsch_Config->choice.setup)
12155          {
12156             macSrvCellCfg->initDlBwp.pdschPresent = true;
12157             
12158             if(storedSrvCellCfg)
12159             {
12160                if(!storedSrvCellCfg->initDlBwp.pdschPresent)
12161                {
12162                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
12163                }
12164                else
12165                {
12166                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg,\
12167                         &storedSrvCellCfg->initDlBwp.pdschCfg);
12168                }
12169             }
12170             else
12171             {
12172                extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
12173             }
12174          }
12175       }
12176    }
12177    if(cuSrvCellCfg->firstActiveDownlinkBWP_Id)
12178       macSrvCellCfg->firstActvDlBwpId = *(cuSrvCellCfg->firstActiveDownlinkBWP_Id);
12179    if(cuSrvCellCfg->defaultDownlinkBWP_Id)
12180       macSrvCellCfg->defaultDlBwpId = *(cuSrvCellCfg->defaultDownlinkBWP_Id);
12181    if(cuSrvCellCfg->bwp_InactivityTimer)
12182    {
12183       if(macSrvCellCfg->bwpInactivityTmr)
12184       {
12185          memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
12186       }
12187       else
12188       {
12189          macSrvCellCfg->bwpInactivityTmr = NULLP;
12190          DU_ALLOC_SHRABL_BUF(macSrvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
12191          if(macSrvCellCfg->bwpInactivityTmr)
12192          {
12193             memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
12194          }
12195          else
12196          {
12197             DU_LOG("\nERROR  --> F1AP : Memory Alloc failed for bwpInactivityTmr at extractSpCellDedicatedCfg()");
12198             return RFAILED;
12199          }
12200       }
12201    }
12202    if(cuSrvCellCfg->pdsch_ServingCellConfig)
12203    {
12204       if(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup)
12205       {
12206          ret = extractPdschServingCellCfg(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup, &macSrvCellCfg->pdschServCellCfg);
12207          if(ret == RFAILED)
12208          {
12209             DU_LOG("\nERROR --> F1AP : Failed at extractPdschServingCellCfg()");
12210             return RFAILED;
12211          }
12212       }
12213    }
12214    if(cuSrvCellCfg->uplinkConfig)
12215    {
12216       if(cuSrvCellCfg->uplinkConfig->initialUplinkBWP)
12217       {
12218          ulBwp = ((BWP_UplinkDedicated_t *)(cuSrvCellCfg->uplinkConfig->initialUplinkBWP));
12219          if(ulBwp->pusch_Config)
12220          {
12221             macSrvCellCfg->initUlBwp.puschPresent = true;
12222             extractPuschCfg(ulBwp->pusch_Config, &macSrvCellCfg->initUlBwp.puschCfg);
12223          }
12224          if(ulBwp->pucch_Config)
12225          {
12226             macSrvCellCfg->initUlBwp.pucchPresent = true;
12227             memset(&macSrvCellCfg->initUlBwp.pucchCfg, 0, sizeof(PucchCfg));
12228             if(storedSrvCellCfg)
12229             {
12230                if(!storedSrvCellCfg->initUlBwp.pucchPresent)
12231                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
12232                else
12233                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg,\
12234                   &storedSrvCellCfg->initUlBwp.pucchCfg);
12235             }
12236             else
12237             {
12238                extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
12239             }
12240          }
12241       }
12242       if(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id)
12243          macSrvCellCfg->firstActvUlBwpId = *(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id);
12244    }
12245    return ret;
12246 }
12247
12248 #ifdef NR_DRX
12249
12250 /*******************************************************************
12251  *
12252  * @brief fill long cycle offset value of drx in UE structure
12253  *
12254  * @details
12255  *
12256  *    Function : fillLongCycleOffsetValueInUeDb
12257  *
12258  *    Functionality: fill long cycle offset value of drx in UE structure
12259  *
12260  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
12261  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
12262  *
12263  * @return ROK     - success
12264  *         RFAILED - failure
12265  *
12266  * ****************************************************************/
12267 void fillLongCycleOffsetValueInUeDb(DrxLongCycleStartOffset *drxLongCycleStartOffset, struct DRX_ConfigRrc__drx_LongCycleStartOffset  *drx_LongCycleStartOffset)
12268 {
12269
12270    drxLongCycleStartOffset->drxLongCycleStartOffsetChoice = convertLongDrxCycleLengthEnumToValue(drx_LongCycleStartOffset->present);
12271    switch(drx_LongCycleStartOffset->present)
12272    {
12273       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
12274          {
12275             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10;
12276             break;
12277          }
12278       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
12279          {
12280             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms20;
12281             break;
12282          }
12283       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
12284          {
12285             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms32;
12286             break;
12287          }
12288       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
12289         {
12290             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms40;
12291             break;
12292          }
12293       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
12294          {
12295             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms60;
12296             break;
12297          }
12298       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
12299          {
12300             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms64;
12301             break;
12302          }
12303       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
12304          {
12305             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms70;
12306             break;
12307          }
12308       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
12309          {
12310             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms80;
12311             break;
12312          }
12313       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
12314          {
12315             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms128;
12316             break;
12317          }
12318       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
12319          {
12320             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms160;
12321             break;
12322          }
12323       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
12324          {
12325             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms256;
12326             break;
12327          }
12328       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
12329          {
12330             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms320;
12331             break;
12332          }
12333       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
12334          {
12335             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms512;
12336             break;
12337          }
12338       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
12339          {
12340             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms640;
12341             break;
12342          }
12343       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
12344          {
12345             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1024;
12346             break;
12347          }
12348       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
12349          {
12350             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1280;
12351             break;
12352          }
12353       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
12354          {
12355             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2048;
12356             break;
12357          }
12358       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
12359          {
12360             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2560;
12361             break;
12362          }
12363        case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
12364          {
12365             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms5120;
12366             break;
12367          }
12368       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
12369          {
12370             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10240;
12371             break;
12372          }
12373       default :
12374          break;
12375    }
12376 }
12377
12378 /*******************************************************************
12379  *
12380  * @brief Fills drx configuration structure with the help of drx_ConfigRrc
12381  *which recive from CU or storedDrxCfg which is already stored
12382  *
12383  * @details
12384  *
12385  *    Function : extractDrxConfiguration 
12386  *
12387  *    Functionality: Fills Reconfig Cell group Info received by CU
12388  *   
12389  * @params[in] cuMacCellGrpDrxConfig  = MAC_CellGroupConfig__drx_ConfigRrc information which
12390  *                       is send by CU, which we have stored in F1UeContextSetupDb
12391  *             DrxCfg * drxCfg  = Used to Store the information,
12392  *                      which needs to send in other layer, as well as this can be
12393  *                      the variable which stores the information in DuCb,
12394  *             DrxCfg *storedDrxCfg = Null in case of sending the
12395  *                      information to other layer else it will have the drx information 
12396  *                      stored in the copyOfmacUeCfg which we have stored in F1UeContextSetupDb.
12397  *
12398  * @return void
12399  *
12400  * ****************************************************************/
12401 void extractDrxConfiguration(struct MAC_CellGroupConfig__drx_ConfigRrc *cuMacCellGrpDrxConfig, DrxCfg * drxCfg, DrxCfg *storedDrxCfg)
12402 {
12403    struct DRX_ConfigRrc *cuDrxConfig;
12404
12405    if(storedDrxCfg)
12406    {
12407       memcpy(drxCfg, storedDrxCfg, sizeof(DrxCfg));
12408    }
12409    else
12410    {
12411       if(cuMacCellGrpDrxConfig)
12412       {
12413          switch(cuMacCellGrpDrxConfig->present)
12414          {
12415             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
12416                break;
12417
12418             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
12419                {
12420                   cuDrxConfig = cuMacCellGrpDrxConfig->choice.setup;
12421                   if(cuDrxConfig)
12422                   {
12423                      switch(cuDrxConfig->drx_onDurationTimer.present)
12424                      {
12425                         case DRX_ConfigRrc__drx_onDurationTimer_PR_NOTHING:
12426                            break;
12427                         case DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds:
12428                            {
12429                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = true;
12430                               drxCfg->drxOnDurationTimer.onDurationtimerValue.milliSeconds=convertOnDurationTimerMilliSecondsEnumToValue(cuDrxConfig->\
12431                               drx_onDurationTimer.choice.milliSeconds);
12432                               break;
12433                            }
12434                         case DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds:
12435                            {
12436                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = false;
12437                               drxCfg->drxOnDurationTimer.onDurationtimerValue.subMilliSeconds = cuDrxConfig->drx_onDurationTimer.choice.subMilliSeconds;
12438                               break;
12439                            }
12440                      }
12441                   }
12442                   fillLongCycleOffsetValueInUeDb(&drxCfg->drxLongCycleStartOffset, &cuDrxConfig->drx_LongCycleStartOffset);
12443                   drxCfg->drxInactivityTimer = convertDrxInactivityTimerEnumToValue(cuDrxConfig->drx_InactivityTimer);
12444                   drxCfg->drxHarqRttTimerDl = cuDrxConfig->drx_HARQ_RTT_TimerDL;
12445                   drxCfg->drxHarqRttTimerUl = cuDrxConfig->drx_HARQ_RTT_TimerUL;
12446                   drxCfg->drxRetransmissionTimerDl = convertDrxRetransmissionTimerDlEnumToValue(cuDrxConfig->drx_RetransmissionTimerDL);
12447                   drxCfg->drxRetransmissionTimerUl = convertDrxRetransmissionTimerUlEnumToValue(cuDrxConfig->drx_RetransmissionTimerUL);
12448                   drxCfg->drxSlotOffset = cuDrxConfig->drx_SlotOffset;
12449                   if(cuDrxConfig->shortDRX)
12450                   {
12451                      drxCfg->shortDrxPres=true;
12452                      drxCfg->shortDrx.drxShortCycle = convertShortDrxCycleLengthEnumToValue(cuDrxConfig->shortDRX->drx_ShortCycle);
12453                      drxCfg->shortDrx.drxShortCycleTimer = cuDrxConfig->shortDRX->drx_ShortCycleTimer;
12454                   }
12455                   else
12456                      drxCfg->shortDrxPres=false;
12457
12458                   break;
12459                }
12460
12461             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
12462                break;
12463          }
12464       }
12465    }
12466 }
12467 #endif
12468
12469 /*******************************************************************
12470  *
12471  * @brief Fills Reconfig Cell group Info received by CU
12472  *
12473  * @details
12474  *
12475  *    Function : extractUeRecfgCellInfo
12476  *
12477  *    Functionality: Fills Reconfig Cell group Info received by CU
12478  *   
12479  * @params[in] CellGroupConfigRrc_t *cellGrp = CellGroupConfigRrc_t information which
12480  *                       is send by CU, which we have stored in F1UeContextSetupDb
12481  *             DuMacUeCfg *MacUeCfg = Used to Store the information,
12482  *                      which needs to send in other layer, as well as this can be
12483  *                      the variable which stores the information in DuCb,
12484  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
12485  *                      information to other layer else it will have copyOfmacUeCfg
12486  *                      which we have stored in F1UeContextSetupDb.
12487  *
12488  * @return ROK/RFAILED
12489  *
12490  * ****************************************************************/
12491 uint8_t extractUeRecfgCellInfo(CellGroupConfigRrc_t *cellGrp, DuMacUeCfg *macUeCfg, DuMacUeCfg *storedMacUeCfg)
12492 {
12493    uint8_t ret = ROK;
12494    MAC_CellGroupConfig_t     *macCellGroup = NULLP;
12495    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
12496    SpCellConfig_t            *spcellCfg = NULLP;
12497    ServingCellConfig_t       *servCellCfg = NULLP;
12498
12499    if(cellGrp)
12500    {
12501       /* Fill MacCell Group Reconfig  */
12502       if(cellGrp->mac_CellGroupConfig)
12503       {
12504          macUeCfg->macCellGrpCfgPres = true;
12505          macCellGroup = ((MAC_CellGroupConfig_t *)(cellGrp->mac_CellGroupConfig));
12506
12507 #ifdef NR_DRX         
12508          if(macCellGroup->drx_ConfigRrc)
12509          {
12510             if(storedMacUeCfg)
12511             {
12512                if(!storedMacUeCfg->macCellGrpCfgPres) 
12513                {
12514                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL);    
12515                }
12516                else
12517                {
12518                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg, &storedMacUeCfg->macCellGrpCfg.drxCfg);    
12519                }
12520             }
12521             else
12522             {
12523                extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL); 
12524             }
12525          }
12526 #endif
12527
12528          if(macCellGroup->schedulingRequestConfig)
12529          {
12530             extractSchReqReConfig(macCellGroup->schedulingRequestConfig, &macUeCfg->macCellGrpCfg.schReqCfg);
12531          }
12532          if(macCellGroup->tag_Config)
12533          {
12534             extractTagReconfig(macCellGroup->tag_Config, &macUeCfg->macCellGrpCfg.tagCfg);
12535          }
12536          if(macCellGroup->bsr_Config)
12537          {
12538             macUeCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer = macCellGroup->bsr_Config->periodicBSR_Timer;
12539             macUeCfg->macCellGrpCfg.bsrTmrCfg.retxTimer     = macCellGroup->bsr_Config->retxBSR_Timer;
12540             if(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer)
12541             {
12542                macUeCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer  =\
12543                *(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer);
12544             }
12545          }
12546          if(macCellGroup->phr_Config)
12547          {
12548             if(macCellGroup->phr_Config->present == MAC_CellGroupConfig__phr_Config_PR_setup)
12549             {
12550                macUeCfg->macCellGrpCfg.phrCfgSetupPres = true;
12551                if(macCellGroup->phr_Config->choice.setup)
12552                {
12553                   macUeCfg->macCellGrpCfg.phrCfg.periodicTimer     = \
12554                   macCellGroup->phr_Config->choice.setup->phr_PeriodicTimer;
12555                   macUeCfg->macCellGrpCfg.phrCfg.prohibitTimer     = \
12556                   macCellGroup->phr_Config->choice.setup->phr_ProhibitTimer;
12557                   macUeCfg->macCellGrpCfg.phrCfg.txPowerFactor     = \
12558                   macCellGroup->phr_Config->choice.setup->phr_Tx_PowerFactorChange;
12559                   macUeCfg->macCellGrpCfg.phrCfg.multiplePHR       = \
12560                   macCellGroup->phr_Config->choice.setup->multiplePHR;
12561                   macUeCfg->macCellGrpCfg.phrCfg.dummy             = \
12562                   macCellGroup->phr_Config->choice.setup->dummy;
12563                   macUeCfg->macCellGrpCfg.phrCfg.phrType2OtherCell = \
12564                   macCellGroup->phr_Config->choice.setup->phr_Type2OtherCell;
12565                   macUeCfg->macCellGrpCfg.phrCfg.phrOtherCG        = \
12566                   macCellGroup->phr_Config->choice.setup->phr_ModeOtherCG;
12567                }
12568             }
12569          }
12570       }
12571       /* Fill Physical Cell Group Reconfig */
12572       if(cellGrp->physicalCellGroupConfig)
12573       {
12574          macUeCfg->phyCellGrpCfgPres = true;
12575          phyCellGrpCfg = ((PhysicalCellGroupConfig_t *)(cellGrp->physicalCellGroupConfig));
12576          if(phyCellGrpCfg->p_NR_FR1)
12577          {
12578             if(*(phyCellGrpCfg->p_NR_FR1) != macUeCfg->phyCellGrpCfg.pNrFr1)
12579                macUeCfg->phyCellGrpCfg.pNrFr1 = *(phyCellGrpCfg->p_NR_FR1);
12580          }
12581          macUeCfg->phyCellGrpCfg.pdschHarqAckCodebook = phyCellGrpCfg->pdsch_HARQ_ACK_Codebook;
12582       }
12583       /* Fill SpCell Reconfig */
12584       if(cellGrp->spCellConfig)
12585       {
12586          macUeCfg->spCellCfgPres = true;
12587          spcellCfg = ((SpCellConfig_t *)(cellGrp->spCellConfig));  
12588          if(spcellCfg->servCellIndex)
12589          {
12590             macUeCfg->spCellCfg.servCellIdx = *(spcellCfg->servCellIndex);
12591          }
12592          /* Fill Serving cell Reconfig info */
12593          if(cellGrp->spCellConfig->spCellConfigDedicated)
12594          {
12595             servCellCfg = ((ServingCellConfig_t *)(cellGrp->spCellConfig->spCellConfigDedicated));
12596             if(storedMacUeCfg)
12597             {
12598                if(!storedMacUeCfg->spCellCfgPres)
12599                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12600                else
12601                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg,\
12602                         &storedMacUeCfg->spCellCfg.servCellCfg);
12603             }
12604             else
12605             {
12606                ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12607             }
12608             if(ret == RFAILED)
12609             {
12610                DU_LOG("\nERROR --> F1AP : Failed at extractSpCellDedicatedCfg()");
12611             }
12612          }
12613       }
12614    }
12615    return ret;
12616 }
12617 /*******************************************************************
12618 *
12619 * @brief free the memory allocated by decoder
12620 *
12621 * @details
12622 *
12623 *    Function : freeAperDecodeNrcgi 
12624 *
12625 *    Functionality: Free Nrcgi values
12626 *
12627 * @params[in] NRCGI_t *nrcgi
12628 * @return void
12629 *
12630 * ****************************************************************/
12631
12632
12633 void freeAperDecodeNrcgi(NRCGI_t *nrcgi)
12634 {
12635     if(nrcgi->pLMN_Identity.buf != NULLP)
12636     {
12637        free(nrcgi->pLMN_Identity.buf);
12638     }
12639     if(nrcgi->nRCellIdentity.buf != NULLP)
12640     {
12641        free(nrcgi->nRCellIdentity.buf);
12642     }
12643 }
12644 /*******************************************************************
12645 *
12646 * @brief free the memory allocated by decoder
12647 *
12648 * @details
12649 *
12650 *    Function : freeAperDecodeCuToDuInfo 
12651 *
12652 *    Functionality:  Free Cu To Du Information
12653 *
12654 * @params[in] CUtoDURRCInformation_t *rrcMsg
12655 * @return void
12656 *
12657 * ****************************************************************/
12658
12659
12660 void freeAperDecodeCuToDuInfo(CUtoDURRCInformation_t *rrcMsg)
12661 {
12662    uint8_t ieIdx =0;
12663    uint8_t arrIdx =0;
12664
12665    if(rrcMsg->uE_CapabilityRAT_ContainerList)
12666    {
12667       if(rrcMsg->uE_CapabilityRAT_ContainerList->buf)
12668          free(rrcMsg->uE_CapabilityRAT_ContainerList->buf);
12669       free(rrcMsg->uE_CapabilityRAT_ContainerList);
12670    }
12671
12672    if(rrcMsg->iE_Extensions)
12673    {
12674       if(rrcMsg->iE_Extensions->list.array)
12675       {
12676          for(ieIdx= 0; ieIdx < rrcMsg->iE_Extensions->list.count; ieIdx++)
12677          {
12678             if(rrcMsg->iE_Extensions->list.array[ieIdx])
12679             {
12680                switch(rrcMsg->iE_Extensions->list.array[ieIdx]->id)
12681                {
12682                   case ProtocolIE_ID_id_CellGroupConfig:
12683                      if(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf != NULLP)
12684                      {
12685                         free(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf);
12686                      }
12687                      break;
12688                   default:
12689                      DU_LOG("\nERROR  -->  F1AP : Invalid Event type %ld at FreeCuToDuInfo()", \
12690                            rrcMsg->iE_Extensions->list.array[ieIdx]->id);
12691                      break;
12692                }
12693             }
12694          }
12695          for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
12696          {
12697             free(rrcMsg->iE_Extensions->list.array[arrIdx]);
12698          }
12699          free(rrcMsg->iE_Extensions->list.array);
12700
12701       }
12702
12703       free(rrcMsg->iE_Extensions);
12704    }
12705 }
12706 /*******************************************************************
12707 *
12708 * @brief free the memory allocated by decoder
12709 *
12710 * @details 
12711 *
12712 *    Function : freeAperDecodeSplCellList
12713 *
12714 *    Functionality: Free Spl Cell List 
12715                     where memory allocated by aper_decoder
12716 *
12717 * @params[in]  SCell_ToBeSetup_List_t *spCellLst
12718 * @return void
12719 *
12720 * ****************************************************************/
12721
12722
12723 void freeAperDecodeSplCellList(SCell_ToBeSetup_List_t *spCellLst)
12724 {
12725     uint8_t  cellIdx =0;
12726
12727     if(spCellLst->list.array != NULLP)
12728     {
12729        for(cellIdx=0; cellIdx<spCellLst->list.count; cellIdx++)
12730        {
12731           if(cellIdx==0&&spCellLst->list.array[cellIdx]!=NULLP)
12732           {
12733              freeAperDecodeNrcgi(&spCellLst->list.array[cellIdx]->value.choice.SCell_ToBeSetup_Item.sCell_ID);
12734           }
12735           if(spCellLst->list.array[cellIdx]!=NULLP)
12736           {
12737              free(spCellLst->list.array[cellIdx]);
12738           }
12739        }
12740        free(spCellLst->list.array);
12741     }
12742 }
12743 /*******************************************************************
12744 *
12745 * @brief free the memory allocated by decoder
12746 *
12747 * @details
12748 *
12749 *    Function : freeAperDecodeSRBSetup 
12750 *
12751 *    Functionality: added free part for the memory allocated by aper_decoder
12752 *
12753 * @params[in] SRBs_ToBeSetup_List_t *srbSet
12754 * @return void
12755 *
12756 ****************************************************************/
12757
12758
12759 void freeAperDecodeSRBSetup(SRBs_ToBeSetup_List_t *srbSet)
12760 {
12761     uint8_t srbIdx =0;
12762     if(srbSet->list.array != NULLP)
12763     {
12764        for(srbIdx=0; srbIdx<srbSet->list.count; srbIdx++)
12765        {
12766           if(srbSet->list.array[srbIdx]!=NULLP)
12767           {
12768              free(srbSet->list.array[srbIdx]);
12769           }
12770        }
12771        free(srbSet->list.array);
12772     }
12773 }
12774
12775 /*******************************************************************
12776 *
12777 * @brief free the memory allocated by decoder
12778 *
12779 * @details
12780 *
12781 *    Function : freeAperDecodeULTnlInfo
12782 *
12783 *    Functionality: added free part for the memory allocated by aper_decoder
12784 *
12785 * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
12786 * @return void
12787 *
12788 * ****************************************************************/
12789
12790
12791 void freeAperDecodeULTnlInfo(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
12792 {
12793    uint8_t ulIdx=0;
12794    if(ulInfo->list.array != NULLP)
12795    {
12796       for(ulIdx=0; ulIdx<ulInfo->list.count; ulIdx++)
12797       {
12798          if(ulIdx==0&&ulInfo->list.array[ulIdx]!=NULLP)
12799          {
12800             if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel!=NULLP)
12801             {
12802                if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12803                      transportLayerAddress.buf != NULLP)
12804                {
12805                   if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf\
12806                         !=NULLP)
12807                   {
12808                      free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf);
12809                   }
12810                   free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12811                         transportLayerAddress.buf);
12812                }
12813                free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel);
12814             }
12815          }
12816          if(ulInfo->list.array[ulIdx]!=NULLP)
12817          {
12818             free(ulInfo->list.array[ulIdx]);
12819          }
12820       }
12821       free(ulInfo->list.array);
12822    }
12823 }
12824 /*******************************************************************
12825 *
12826 * @brief free the memory allocated by decoder
12827 *
12828 * @details
12829 *
12830 *    Function : freeAperDecodeDRBSetup  
12831 *
12832 *    Functionality: free DRBSetup which is allocated by decoder
12833 *
12834 * @params[in]  DRBs_ToBeSetup_List_t *drbSet
12835 * @return void
12836 *
12837 * ****************************************************************/
12838
12839 void freeAperDecodeDRBSetup(DRBs_ToBeSetup_List_t *drbSet)
12840 {
12841    DRBs_ToBeSetup_Item_t *drbSetItem = NULLP;
12842    uint8_t  flowIdx =0;
12843    uint8_t  drbIdx =0;
12844
12845    if(drbSet->list.array != NULLP)
12846    {
12847       for(drbIdx=0; drbIdx<drbSet->list.count; drbIdx++)
12848       {
12849          if(drbIdx==0&&drbSet->list.array[drbIdx] != NULLP)
12850          {
12851             drbSetItem =&drbSet->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12852             if(drbSetItem->qoSInformation.choice.choice_extension != NULLP)
12853             {
12854                if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12855                      qoS_Characteristics.choice.non_Dynamic_5QI !=NULLP)
12856                {
12857                   if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12858                         qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12859                   {
12860                      if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12861                            qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12862                      {
12863
12864                         if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf!=NULLP)
12865                         {
12866
12867                            if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD!=NULLP)
12868                            {
12869
12870                               if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD->\
12871                                     buf!=NULLP)
12872                               {
12873
12874                                  if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.\
12875                                        flows_Mapped_To_DRB_List.list.array != NULLP)
12876                                  {
12877
12878                                     for(flowIdx=0;flowIdx<drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12879                                           DRB_Information.flows_Mapped_To_DRB_List.list.count; flowIdx++)
12880                                     {
12881
12882                                        if(flowIdx==0&&drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12883                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12884                                        {
12885                                           if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12886                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12887                                                 qoSFlowLevelQoSParameters.\
12888                                                 qoS_Characteristics.choice.non_Dynamic_5QI!=NULLP)
12889                                           {
12890                                              if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12891                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12892                                                    qoSFlowLevelQoSParameters.\
12893                                                    qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12894                                              {
12895
12896                                                 if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12897                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12898                                                       qoSFlowLevelQoSParameters.\
12899                                                       qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12900                                                 {
12901
12902
12903                                                    free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12904                                                          DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12905                                                          qoSFlowLevelQoSParameters.\
12906                                                          qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12907                                                 }
12908
12909                                                 free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12910                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12911                                                       qoSFlowLevelQoSParameters.\
12912                                                       qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12913                                              }
12914
12915                                              free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12916
12917                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12918                                                    qoSFlowLevelQoSParameters.\
12919                                                    qoS_Characteristics.choice.non_Dynamic_5QI);
12920                                           }
12921                                        }
12922                                        if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12923                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12924                                        {
12925
12926                                           free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12927                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]);
12928                                        }
12929                                     }
12930
12931                                     free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12932                                           DRB_Information.flows_Mapped_To_DRB_List.list.array);
12933                                  }
12934
12935                                  free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12936                                        DRB_Information.sNSSAI.sD->buf);
12937                               }
12938
12939                               free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD);
12940                            }
12941
12942                            free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf);
12943
12944                         }
12945
12946                         free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12947
12948                               qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12949                      }
12950
12951                      free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12952                            qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12953                   }
12954
12955                   free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12956                         qoS_Characteristics.choice.non_Dynamic_5QI);
12957                }
12958                free(drbSetItem->qoSInformation.choice.choice_extension);
12959             }
12960             freeAperDecodeULTnlInfo(&drbSetItem->uLUPTNLInformation_ToBeSetup_List);
12961             if(drbSetItem->uLConfiguration)
12962             {
12963                free(drbSetItem->uLConfiguration);
12964             }
12965          }
12966          if(drbSet->list.array[drbIdx]!=NULLP)
12967          {
12968             free(drbSet->list.array[drbIdx]);
12969          }
12970       }
12971       free(drbSet->list.array);
12972    }
12973 }
12974
12975
12976 /*******************************************************************
12977  *
12978  * @brief builds Mac Cell Cfg
12979  *
12980  * @details
12981  *
12982  *    Function : procUeRecfgCellInfo
12983  *
12984  *    Functionality: builds Mac Cell Cfg
12985  *
12986  * @params[in] DuMacUeCfg *macUeCfgToSend = Used to Store the information which
12987  *                       needs to send in other layer, as well as this can be
12988  *                       the variable which stores the information in DuCb.
12989  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
12990  *                       information to other layer else it will have copyOfmacUeCfg  
12991  *                       which we have stored in F1UeContextSetupDb
12992  *             void *cellInfo = CellGroupConfigRrc_t information which is send
12993  *                        by CU, which we have stored in F1UeContextSetupDb 
12994  *
12995  * @return void 
12996  *
12997  * ****************************************************************/
12998 uint8_t procUeRecfgCellInfo(DuMacUeCfg *macUeCfgToSend, DuMacUeCfg *storedMacUeCfg, void *cellInfo)
12999 {
13000    uint8_t ret = ROK;
13001    CellGroupConfigRrc_t *cellGrp = NULLP;
13002
13003    if(cellInfo)
13004    {
13005       cellGrp = (CellGroupConfigRrc_t *)cellInfo;
13006       ret = extractUeRecfgCellInfo(cellGrp, macUeCfgToSend, storedMacUeCfg);
13007       if(ret == RFAILED)
13008          DU_LOG("\nERROR  -->  F1AP : Failed at procUeRecfgCellInfo()");
13009    }
13010    if(ret == RFAILED)
13011    {
13012       freeUeRecfgCellGrpInfo(macUeCfgToSend);
13013    }
13014    return ret;
13015 }
13016
13017 /*******************************************************************
13018  *
13019  * @brief Filling modulation info in mac ue cfg
13020  *
13021  * @details
13022  *
13023  *    Function : duFillModulationDetails
13024  *
13025  *    Functionality: Filling modulation info in mac ue cfg
13026  *
13027  * @params[in] MAC UE Config to be updated
13028  *             Current UE configuration
13029  *             UE NR capability from CU
13030  * @return ROK     - success
13031  *         RFAILED - failure
13032  *
13033  * ****************************************************************/
13034 void duFillModulationDetails(DuMacUeCfg *ueCfg, DuMacUeCfg *oldUeCfg, void *ueCap)
13035 {
13036    UE_NR_Capability_t *ueNrCap=NULLP;
13037
13038    if(!ueCap && oldUeCfg)
13039    {
13040       memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));     
13041       memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13042    }
13043    else
13044    {
13045       ueNrCap = (UE_NR_Capability_t *)ueCap;
13046
13047       /* Filling DL modulation info */
13048       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsDownlinkPerCC && \
13049          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0] && \
13050          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL)
13051       {
13052          switch(*(ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL))
13053          {
13054             case ModulationOrder_qpsk:
13055                {
13056                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
13057                   break;
13058                }
13059             case ModulationOrder_qam16:
13060                {
13061                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM16;
13062                   break;
13063                }
13064             case ModulationOrder_qam64:
13065                {
13066                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM64;
13067                   ueCfg->dlModInfo.mcsIndex = PDSCH_MCS_INDEX;
13068                   ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64;
13069                   break;
13070                }
13071             case ModulationOrder_qam256:
13072                {
13073                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM256;
13074                   break;
13075                }
13076             default:
13077                {
13078                   DU_LOG("\nERROR  -->  DU APP: Incorrect downlink modulation order received. Reatining old modulation configuration");
13079                   if(oldUeCfg)
13080                      memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
13081                   break;
13082                }
13083          }
13084       }
13085       else
13086       {
13087          if(oldUeCfg)
13088             memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
13089       }
13090
13091       /* Filling UL modulation info */
13092       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsUplinkPerCC && \
13093          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0] && \
13094          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL)
13095       {
13096          switch(*(ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL))
13097          {
13098             case ModulationOrder_qpsk:
13099                {
13100                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
13101                   break;
13102                }
13103             case ModulationOrder_qam16:
13104                {
13105                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM16;
13106                   ueCfg->ulModInfo.mcsIndex = PUSCH_MCS_INDEX;
13107                   ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64;
13108                   break;
13109                }
13110             case ModulationOrder_qam64:
13111                {
13112                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM64;
13113                   break;
13114                }
13115             case ModulationOrder_qam256:
13116                {
13117                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM256;
13118                   break;
13119                }
13120             default:
13121                {
13122                   DU_LOG("\nERROR  -->  DU APP: Incorrect uplink modulation order received. Reatining old modulation configuration");
13123                   if(oldUeCfg)
13124                      memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13125                   break;
13126                }
13127          }
13128       }
13129       else
13130       {
13131          if(oldUeCfg)
13132             memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13133       }
13134    }
13135 }
13136
13137 /*******************************************************************
13138  *
13139  * @brief Function to extract info from CU to DU RRC container extension
13140  *
13141  * @details
13142  *
13143  *    Function : extractCuToDuRrcInfoExt
13144  *
13145  *    Functionality: Function to extract info from CU to DU RRC container
13146  *    extension
13147  *
13148  * @params[in] ProtocolExtensionContainer_4624P16_t pointer
13149  *
13150  * @return ROK
13151  *         RFAILED
13152  *
13153  * ****************************************************************/
13154 uint8_t extractCuToDuRrcInfoExt(ProtocolExtensionContainer_4624P16_t *protocolIeExtn, DuUeCfg *ueCfgDb)
13155 {
13156    uint8_t ieIdx =0;
13157    uint16_t recvBufLen =0;
13158    CellGroupConfigRrc_t *cellGrpCfg = NULLP;
13159    CUtoDURRCInformation_ExtIEs_t *extIeInfo = NULLP;
13160    asn_dec_rval_t rval; /* Decoder return value */
13161    memset(&rval, 0, sizeof(asn_dec_rval_t));
13162
13163    if(protocolIeExtn)
13164    {
13165       for(ieIdx = 0; ieIdx < protocolIeExtn->list.count; ieIdx++)
13166       {
13167          extIeInfo = ((CUtoDURRCInformation_ExtIEs_t *)(protocolIeExtn->list.array[ieIdx]));
13168          switch(extIeInfo->id)
13169          {
13170             case ProtocolIE_ID_id_CellGroupConfig:
13171                {
13172                   /* decoding the CellGroup Buf received */
13173                   recvBufLen = extIeInfo->extensionValue.choice.CellGroupConfig.size;
13174                   DU_ALLOC(cellGrpCfg, sizeof(CellGroupConfigRrc_t));
13175                   if(cellGrpCfg)
13176                   {
13177                      memset(cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
13178                      rval = uper_decode(0, &asn_DEF_CellGroupConfigRrc, (void **)&cellGrpCfg,
13179                            extIeInfo->extensionValue.choice.CellGroupConfig.buf, recvBufLen, 0, 0);
13180                      if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13181                      {
13182                         DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13183                         return RFAILED;
13184                      }
13185                      xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, cellGrpCfg);
13186
13187                      if(extractRlcCfgToAddMod(cellGrpCfg->rlc_BearerToAddModList, ueCfgDb))
13188                         return NULLP;
13189                      ueCfgDb->cellGrpCfg = cellGrpCfg;
13190                   }
13191                   break;
13192                }
13193
13194             case ProtocolIE_ID_id_HandoverPreparationInformation:
13195                {
13196                   DU_LOG("\nINFO -->  F1AP : Received HANDOVER PREPARATION INFO in UE CONTEXT SETUP REQUEST");
13197                   break;
13198                }
13199
13200             default:
13201                DU_LOG("\nERROR  -->  F1AP : Invalid IE received CUtoDURRCInformation: %ld at decodeCellGrpCfg()", extIeInfo->id);
13202                break;
13203          }
13204       }
13205    }
13206    return ROK;
13207 }
13208
13209 /*******************************************************************
13210  *
13211  * @brief Fills Srb List received by CU
13212  *
13213  * @details
13214  *
13215  *    Function : procSrbListToSetup
13216  *
13217  *    Functionality: Fills Srb List received  by CU
13218  *
13219  * @params[in] SRBs_ToBeSetup_Item_t *cuSrbItem
13220  *             DuLcCfg pointer
13221  *             RlcBearerCfg pointer
13222  * @return void
13223  *
13224  * ****************************************************************/
13225 uint8_t procSrbListToSetup(SRBs_ToBeSetup_Item_t * srbItem, DuLcCfg *duMacLcToAdd, DuRlcBearerCfg *rlcLcToAdd)
13226 {
13227
13228    /* Filling RLC INFO */
13229    procRlcLcCfg(srbItem->sRBID, srbItem->sRBID, RB_TYPE_SRB, RLC_AM, CONFIG_ADD, NULL, rlcLcToAdd, NULL);
13230
13231    /* Filling MAC INFO */
13232    if(procMacLcCfg(srbItem->sRBID, RB_TYPE_SRB, CONFIG_ADD, NULL,NULL, NULL, NULL, duMacLcToAdd, NULL)  != ROK)
13233    { 
13234       DU_LOG("\nERROR  -->  F1AP : Failed at MAC LC Cfg in procSrbListToSetup()");
13235       return RFAILED;
13236    }
13237
13238    return ROK;
13239 }
13240
13241
13242
13243 /*******************************************************************
13244  *
13245  * @brief extract Srb List received by CU
13246  *
13247  * @details
13248  *
13249  *    Function : extractSrbListToSetup
13250  *
13251  *    Functionality: extract Srb List received by CU
13252  *                   for both MAC and RLC
13253  *
13254  * @params[in] SRBs_ToBeSetup_Item_t pointer
13255  *             DuUeCfg pointer
13256  * @return ROK/RFAIED
13257  *
13258  * ****************************************************************/
13259
13260 uint8_t extractSrbListToSetup(SRBs_ToBeSetup_List_t *srbCfg, DuUeCfg *ueCfgDb)
13261 {
13262    uint8_t ret = ROK, srbIdx = 0, rlcLcIdx = 0;
13263    SRBs_ToBeSetup_Item_t *srbItem = NULLP;
13264    DuLcCfg *macLcCtxt = NULLP;
13265    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13266
13267    if(srbCfg)
13268    {
13269       for(srbIdx = 0; srbIdx < srbCfg->list.count; srbIdx++)
13270       {
13271          macLcCtxt = NULL;
13272          rlcLcCtxt = NULL;
13273
13274          srbItem = &srbCfg->list.array[srbIdx]->value.choice.SRBs_ToBeSetup_Item;
13275          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13276          { 
13277             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in MAC");
13278             ret = RFAILED;
13279             break;
13280          }
13281          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13282          {
13283             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in RLC");
13284             ret = RFAILED;
13285             break;
13286          }
13287
13288          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numMacLcs; rlcLcIdx++)
13289          {
13290             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == srbItem->sRBID && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
13291             {
13292                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13293                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13294                break;
13295             }
13296          }
13297          if(!macLcCtxt)
13298          {
13299             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13300             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13301             ueCfgDb->numMacLcs++;
13302          }
13303          if(!rlcLcCtxt)
13304          {
13305             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13306             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13307             ueCfgDb->numRlcLcs++;
13308          }
13309
13310          ret = procSrbListToSetup(srbItem, macLcCtxt, rlcLcCtxt);
13311
13312          DU_LOG("\nDEBUG --> DUAPP: extractSrbListToSetup: SRBID: %ld [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13313                srbItem->sRBID, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13314          if(ret == RFAILED)
13315          {
13316             DU_LOG("\nERROR  -->  F1AP:  Failed at extractSrbListToSetup()");
13317             break;
13318          }
13319       }
13320    }
13321    else
13322       ret = RFAILED;
13323
13324    return ret;
13325 }
13326
13327 /*******************************************************************
13328  *
13329  * @brief Fills Drb List received by CU
13330  *
13331  * @details
13332  *
13333  *    Function : procDrbListToSetupMod
13334  *
13335  *    Functionality: Fills Drb List received by CU
13336  *                   for both MAC and RLC
13337  *
13338  * @params[in] DRBs_ToBeSetup_Item_t , DRBs_ToBeSetupMod_Item_t,
13339  *             DRBs_ToBeModified_Item_t , lcId, DuLcCfg pointer,
13340  *             RlcBearerCfg , UpTnlCfg, DuRlcUeCfg
13341  * @return void
13342  *
13343  * ****************************************************************/
13344
13345 uint8_t procDrbListToSetupMod(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbItem,\
13346 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, DuLcCfg *macLcToAdd, DuRlcBearerCfg *rlcLcToAdd, UpTnlCfg *upTnlInfo, DuRlcUeCfg *storedRlcUeCfg)
13347 {
13348    uint8_t cfgIdx = 0;
13349    RlcMode rlcModeInfo;
13350
13351    if(drbItem != NULLP)
13352    {
13353       /* Filling RLC INFO */
13354       procRlcLcCfg(drbItem->dRBID, lcId, RB_TYPE_DRB, drbItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, &drbItem->\
13355       qoSInformation);
13356
13357       /* Filling MAC INFO */
13358       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, drbItem, NULL, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13359       { 
13360          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13361          return RFAILED;
13362       }
13363    }
13364    else if(drbSetupModItem != NULLP)
13365    {
13366       procRlcLcCfg(drbSetupModItem->dRBID, lcId, RB_TYPE_DRB, drbSetupModItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, 
13367       &drbSetupModItem->qoSInformation);
13368
13369       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, NULL, drbSetupModItem, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13370       {
13371          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13372          return RFAILED;
13373       }
13374    }
13375    else if(drbModItem != NULLP)
13376    {
13377       /* Drb to Mod IEs doesnot have rlcMode to be modified
13378        * in ASN. Hence no change in RLC configurations */
13379       if(storedRlcUeCfg != NULLP)
13380       {
13381          for(cfgIdx = 0; cfgIdx < storedRlcUeCfg->numLcs; cfgIdx++)
13382          {
13383             if(storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.lcId == lcId)
13384             {
13385                rlcModeInfo = storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.rlcMode;
13386                break;
13387             }
13388          }
13389       }
13390
13391       procRlcLcCfg(drbModItem->dRBID, lcId, RB_TYPE_DRB, rlcModeInfo, CONFIG_MOD, NULL, rlcLcToAdd, drbModItem->qoSInformation);
13392       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_MOD, NULL, NULL, drbModItem, NULL, macLcToAdd, upTnlInfo) != ROK)
13393       {
13394          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13395          return RFAILED;
13396       }
13397    }
13398    return ROK;
13399 }
13400
13401 /*******************************************************************
13402  *
13403  * @brief extract Drb List received by CU
13404  *
13405  * @details
13406  *
13407  *    Function : extractDrbListToSetupMod
13408  *
13409  *    Functionality: extract Drb List received by CU
13410  *                   for both MAC and RLC
13411  *
13412  * @params[in] DRBs_ToBeSetup_Item_t pointer
13413  *             DuUeCfg pointer
13414  * @return ROK/RFAIED
13415  *
13416  * ****************************************************************/
13417
13418 uint8_t extractDrbListToSetupMod(DRBs_ToBeSetup_List_t *drbCfg, DRBs_ToBeSetupMod_List_t *drbSetupModCfg,\
13419  DRBs_ToBeModified_List_t *drbModCfg, uint8_t drbCount, DuUeCfg *ueCfgDb, uint32_t *drbBitMap, DuRlcUeCfg *rlcUeCfg)
13420 {
13421    uint8_t ret = ROK;
13422    uint8_t drbIdx = 0, rlcLcIdx = 0;
13423    uint8_t drbId = 0, lcId = 0;
13424    DRBs_ToBeSetup_Item_t *drbItem = NULLP;
13425    DRBs_ToBeSetupMod_ItemIEs_t *drbSetupModItem = NULLP;
13426    DRBs_ToBeModified_ItemIEs_t *drbModItem = NULLP;
13427    DuLcCfg *macLcCtxt = NULLP;
13428    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13429
13430    ret = ROK;
13431    if(drbCount > 0)
13432    {
13433       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13434       {
13435          macLcCtxt = NULL;
13436          rlcLcCtxt = NULL;
13437
13438          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13439          { 
13440             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in MAC at extractDrbListToSetupMod()");
13441             ret = RFAILED;
13442             break;
13443          }
13444          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13445          {
13446             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in RLC at extractDrbListToSetupMod()");
13447             ret = RFAILED;
13448             break;
13449          }
13450
13451          if(drbModCfg != NULLP)
13452          {
13453             drbModItem = (DRBs_ToBeModified_ItemIEs_t *) drbModCfg->list.array[drbIdx];
13454             drbId = drbModItem->value.choice.DRBs_ToBeModified_Item.dRBID;
13455          }
13456          else if(drbCfg != NULLP)
13457             drbId = drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item.dRBID;
13458          else if(drbSetupModCfg != NULL)
13459          {
13460             drbSetupModItem = (DRBs_ToBeSetupMod_ItemIEs_t *) drbSetupModCfg->list.array[drbIdx];
13461             drbId = drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item.dRBID;
13462          }
13463
13464          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13465          {
13466             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && \
13467                    ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13468             {
13469                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13470                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13471                break;
13472             }
13473          }
13474          if(!macLcCtxt)
13475          {
13476             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13477             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13478             ueCfgDb->numMacLcs++;
13479          }
13480          if(!rlcLcCtxt)
13481          {
13482             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
13483             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13484             ueCfgDb->numRlcLcs++;
13485          }
13486
13487          if(drbModCfg != NULLP)
13488          {
13489             lcId = fetchLcId(drbId);
13490             if(lcId < MIN_DRB_LCID)
13491             {
13492                DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToSetupMod() for Modified List", lcId);
13493                break;
13494             } 
13495             ret = procDrbListToSetupMod(lcId, NULL, NULL, &(drbModItem->value.choice.DRBs_ToBeModified_Item),\
13496             macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13497             if(ret == RFAILED)
13498             {
13499                DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for Modified List");
13500                break;
13501             }
13502             ueCfgDb->numDrbModified++;
13503          }
13504          else
13505          {
13506             lcId = getDrbLcId(drbBitMap);
13507             if(lcId == RFAILED)
13508             {
13509                DU_LOG("\nERROR  -->  F1AP :  InCorrect LCID extractDrbListToSetupMod()");
13510                ret = RFAILED;
13511                break;
13512             }
13513             if(drbCfg != NULL)
13514             {
13515                drbItem = &drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
13516                ret = procDrbListToSetupMod(lcId, drbItem, NULL, NULL, macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13517                if(ret == RFAILED)
13518                {
13519                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetup List");
13520                   break;
13521                }
13522             }
13523             else if(drbSetupModCfg != NULL)
13524             {
13525                ret = procDrbListToSetupMod(lcId, NULL, &(drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item), NULL,\
13526                      macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13527                if(ret == RFAILED)
13528                {
13529                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetupMod List");
13530                   break;
13531                }
13532                ueCfgDb->numDrbSetupMod++;
13533             }
13534          }
13535          ueCfgDb->numDrb++;
13536  
13537          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToSetupMod:lcId:%x ,BitMap:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13538                             lcId,*drbBitMap, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13539          if(ret == RFAILED)
13540          {
13541             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod()");
13542             break;
13543          }
13544       }
13545    }
13546    else
13547       ret = RFAILED;
13548
13549    return ret;
13550 }
13551
13552 /*******************************************************************
13553  *
13554  * @brief extract Drb List received from CU
13555  *
13556  * @details
13557  *
13558  *    Function : extractDrbListToRelease
13559  *
13560  *    Functionality: extract Drb List received from CU
13561  *                   for both MAC and RLC
13562  *
13563  * @params[in] DRBs_ToBeReleased_Item_t pointer
13564  *             DuUeCfg pointer
13565  * @return ROK/RFAIED
13566  *
13567  * ****************************************************************/
13568
13569 uint8_t extractDrbListToRelease(uint8_t ueId, DRBs_ToBeReleased_List_t *drbToRel, uint8_t drbCount, DuUeCfg *ueCfgDb, DuRlcUeCfg *rlcUeCfg)
13570 {
13571    uint8_t ret = ROK, teIdx = 0;
13572    uint8_t drbIdx = 0, rlcLcIdx = 0;
13573    uint8_t drbId = 0, lcId = 0;
13574    DRBs_ToBeReleased_ItemIEs_t *drbRelItem = NULLP;
13575    DuLcCfg *macLcCtxt = NULLP;
13576    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13577
13578    ret = ROK;
13579    if(drbCount > 0)
13580    {
13581       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13582       {
13583          macLcCtxt = NULL;
13584          rlcLcCtxt = NULL;
13585
13586          if(drbToRel != NULLP)
13587          {
13588             drbRelItem = (DRBs_ToBeReleased_ItemIEs_t *) drbToRel->list.array[drbIdx];
13589             drbId = drbRelItem->value.choice.DRBs_ToBeReleased_Item.dRBID;
13590          }
13591          else
13592          {
13593             DU_LOG("ERROR  --> DU APP : DrbToRelease pointer is NULL in extractDrbListToRelease");
13594             return RFAILED;
13595          }
13596
13597          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13598          {
13599             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13600             {
13601                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13602                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13603                break;
13604             }
13605          }
13606
13607          if(!macLcCtxt)
13608          {
13609             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13610             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13611             ueCfgDb->numMacLcs++;
13612          }
13613          if(!rlcLcCtxt)
13614          {
13615             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13616             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13617             ueCfgDb->numRlcLcs++;
13618          }
13619          lcId = fetchLcId(drbId);
13620          if(lcId < MIN_DRB_LCID)
13621          {
13622             DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToRelease() for Modified List", lcId);
13623             break;
13624          } 
13625
13626          /* Filling RLC INFO */
13627          procRlcLcCfg(drbId, lcId, RB_TYPE_DRB, rlcLcCtxt->rlcBearerCfg.rlcMode, CONFIG_DEL, NULL, rlcLcCtxt, NULLP);
13628          /* Filling MAC INFO */
13629          if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_DEL, NULL, NULL, NULL, NULL, macLcCtxt, NULLP) != ROK)
13630          { 
13631             DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in extractDrbListToRelease()");
13632             return RFAILED;
13633          }
13634          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].configType = CONFIG_DEL;
13635          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId = drbId;
13636          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId = ueId;
13637
13638          for(teIdx = 0; teIdx < duCb.numTeId; teIdx++)
13639          {
13640             if((duCb.upTnlCfg[teIdx]->ueId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId) && \
13641                   (duCb.upTnlCfg[teIdx]->drbId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId))
13642             {
13643                DU_ALLOC(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, sizeof(GtpTnlCfg)); 
13644                memcpy(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, duCb.upTnlCfg[teIdx]->tnlCfg1, sizeof(GtpTnlCfg));
13645                break;
13646             }
13647          }
13648
13649          ueCfgDb->numDrb++;
13650          if(ret == RFAILED)
13651          {
13652             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToRelease() for Modified List");
13653             break;
13654          }
13655
13656          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToRelease():lcId:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13657                lcId,ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13658       }
13659    }
13660    else
13661       ret = RFAILED;
13662
13663    return ret;
13664 }
13665
13666 /*******************************************************************
13667  *
13668  * @brief Function to extract Dl RRC Msg received from CU
13669  *
13670  * @details
13671  *
13672  *    Function : extractDlRrcMsg
13673  *
13674  *    Functionality: Function to extract Dl RRC Msg received from CU
13675  *
13676  * @params[in] F1AP message
13677  * @return ROK     - success
13678  *         RFAILED - failure
13679  *
13680  * ****************************************************************/
13681
13682 uint8_t extractDlRrcMsg(uint32_t gnbDuUeF1apId, uint32_t gnbCuUeF1apId, \
13683    F1DlRrcMsg *dlRrcMsg, RRCContainer_t *rrcContainer)
13684 {
13685    uint8_t ret = ROK;
13686    dlRrcMsg->rrcMsgSize = rrcContainer->size;
13687    if(dlRrcMsg->rrcMsgSize > 0)
13688    {
13689       DU_ALLOC_SHRABL_BUF(dlRrcMsg->rrcMsgPdu, dlRrcMsg->rrcMsgSize);
13690       if(!dlRrcMsg->rrcMsgPdu)
13691       {
13692          DU_LOG("\nERROR  --> DU APP : Memory allocation failed for RRC Msg in extractDlRrcMsg()");
13693          ret = RFAILED;
13694       }
13695       else
13696       {
13697          dlRrcMsg->gnbDuUeF1apId = gnbDuUeF1apId;
13698          dlRrcMsg->gnbCuUeF1apId = gnbCuUeF1apId;
13699          dlRrcMsg->srbId = SRB1_LCID;
13700          memcpy(dlRrcMsg->rrcMsgPdu, rrcContainer->buf, dlRrcMsg->rrcMsgSize);
13701       }
13702    }
13703    return ret;
13704 }
13705
13706 /*******************************************************************
13707  *
13708  * @brief Extract UE capability info 
13709  *
13710  * @details
13711  *
13712  *    Function : extractUeCapability
13713  *
13714  *    Functionality: Extract UE capability info and stores in ue Cb
13715  *
13716  * @params[in] Octet string of UE capability RAT container list
13717  * @return ROK     - success
13718  *         RFAILED - failure
13719  *
13720  * ****************************************************************/
13721 UE_NR_Capability_t *extractUeCapability(UE_CapabilityRAT_ContainerList_t *ueCapablityListBuf, DuUeCb *ueCb)
13722 {
13723    uint8_t  idx;
13724    uint16_t recvBufLen;
13725    asn_dec_rval_t rval;
13726    UE_NR_Capability_t  *ueNrCap = NULLP;
13727    UE_CapabilityRAT_ContainerListRRC_t  *ueCapRatContList = NULLP;
13728
13729    /* Decoding UE Capability RAT Container List */
13730    recvBufLen = ueCapablityListBuf->size;
13731    DU_ALLOC(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13732    if(!ueCapRatContList)
13733    {
13734       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13735       return NULLP;
13736    }
13737    memset(ueCapRatContList, 0, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13738    memset(&rval, 0, sizeof(asn_dec_rval_t));
13739    rval = uper_decode(0, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, (void **)&ueCapRatContList,
13740           ueCapablityListBuf->buf, recvBufLen, 0, 0);
13741    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13742    {
13743       DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13744       return NULLP;
13745    }
13746    xer_fprint(stdout, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, ueCapRatContList);
13747
13748    /* Free encoded buffer after decoding */
13749
13750    for(idx = 0; idx < ueCapRatContList->list.count; idx++)
13751    {
13752       if(ueCapRatContList->list.array[idx]->rat_Type == RAT_Type_nr)
13753       {
13754          /* Decoding UE NR Capability */
13755           recvBufLen = ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.size;
13756           DU_ALLOC(ueNrCap, sizeof(UE_NR_Capability_t));
13757           if(!ueNrCap)
13758           {
13759              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13760              DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13761              return NULLP;
13762           } 
13763           memset(ueNrCap, 0, sizeof(UE_NR_Capability_t));
13764           memset(&rval, 0, sizeof(asn_dec_rval_t));
13765           rval = uper_decode(0, &asn_DEF_UE_NR_Capability, (void **)&ueNrCap,
13766                  ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf, recvBufLen, 0, 0);
13767           if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13768           {
13769              DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13770              return NULLP;
13771           }
13772           xer_fprint(stdout, &asn_DEF_UE_NR_Capability, ueNrCap);
13773           
13774           /* Free encoded buffer after decoding */
13775           free(ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf);
13776       }
13777       free(ueCapRatContList->list.array[idx]);
13778    }
13779
13780    /* Free Memory*/
13781    free(ueCapRatContList->list.array);
13782    DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13783    return ueNrCap;
13784 }
13785  
13786 /*******************************************************************
13787 *
13788 * @brief free UE context setup request from CU
13789 *
13790 * @details
13791 *
13792 *    Function : freeAperDecodeF1UeContextSetupReq
13793 *
13794 *    Functionality: freeing part for the memory allocated by aper_decoder
13795 *
13796 * @params[in] F1AP message
13797 * @return ROK     - success
13798 *         RFAILED - failure
13799 *
13800 * ****************************************************************/
13801 void freeAperDecodeF1UeContextSetupReq(UEContextSetupRequest_t   *ueSetReq)
13802 {
13803    uint8_t ieIdx = 0;
13804
13805    if(ueSetReq->protocolIEs.list.array != NULLP)
13806    {
13807       for(ieIdx = 0; ieIdx < ueSetReq->protocolIEs.list.count; ieIdx++)
13808       {
13809          if(ueSetReq->protocolIEs.list.array[ieIdx])
13810          {
13811             switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13812             {
13813                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13814                   break;
13815                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13816                   break;
13817                case ProtocolIE_ID_id_SpCell_ID:
13818                   freeAperDecodeNrcgi(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
13819                   break;
13820                case ProtocolIE_ID_id_ServCellIndex:
13821                   break;
13822                case ProtocolIE_ID_id_SpCellULConfigured:
13823                   break;
13824                case ProtocolIE_ID_id_CUtoDURRCInformation:
13825
13826                   freeAperDecodeCuToDuInfo(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation);
13827                   break;
13828                case ProtocolIE_ID_id_SCell_ToBeSetup_List:
13829
13830                   freeAperDecodeSplCellList(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SCell_ToBeSetup_List);
13831                   break;
13832                case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
13833
13834                   freeAperDecodeSRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List);
13835                   break;
13836                case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
13837
13838                   freeAperDecodeDRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List);
13839                   break;
13840                case ProtocolIE_ID_id_RRCContainer:
13841                   {
13842
13843                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf != NULLP)
13844                      {
13845
13846                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
13847                      }
13848                      break;
13849                   }
13850                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13851                   break;
13852                case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
13853                   {
13854                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf)
13855                      {
13856                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf);
13857                      }
13858                      break;
13859                   }
13860 #ifdef NR_DRX
13861                case ProtocolIE_ID_id_DRXCycle:
13862                   {
13863                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength)
13864                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength);
13865                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer)
13866                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer);
13867                      break;
13868                   }
13869 #endif             
13870                 default:
13871                   DU_LOG("\nERROR  -->  F1AP: Invalid event type %ld " ,ueSetReq->protocolIEs.list.array[ieIdx]->id);
13872             } 
13873             free(ueSetReq->protocolIEs.list.array[ieIdx]);
13874          }
13875       }
13876       free(ueSetReq->protocolIEs.list.array);
13877    }
13878 }
13879 /*******************************************************************
13880  *
13881  * @brief Process UE context setup request from CU
13882  *
13883  * @details
13884  *
13885  *    Function : procF1UeContextSetupReq
13886  *
13887  *    Functionality: Process UE context setup request from CU
13888  *
13889  * @params[in] F1AP message
13890  * @return ROK     - success
13891  *         RFAILED - failure
13892  *
13893  * ****************************************************************/
13894 uint8_t procF1UeContextSetupReq(F1AP_PDU_t *f1apMsg)
13895 {
13896    int8_t ueIdx = -1;
13897    uint8_t  ret=0, ieIdx=0, ieExtIdx = 0;
13898    //uint8_t servCellIdx = 0;
13899    bool ueCbFound = false, hoInProgress = false;
13900    uint16_t cellIdx=0;
13901    uint64_t nrCellId = 0;
13902    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0, bitRateSize=0;
13903    DuUeCb   *duUeCb = NULL;
13904    UEContextSetupRequest_t   *ueSetReq = NULL;
13905    DRBs_ToBeSetup_List_t *drbCfg = NULL;
13906    CUtoDURRCInformation_t *rrcInfo = NULL;
13907 #ifdef NR_DRX
13908    DRXCycle_t *drxCycle;
13909 #endif
13910    ret = ROK;
13911
13912    ueSetReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextSetupRequest;
13913    for(ieIdx=0; (ieIdx < ueSetReq->protocolIEs.list.count && ret == ROK); ieIdx++)
13914    {
13915       switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13916       {
13917          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13918             {
13919                gnbCuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
13920                break;
13921             }
13922
13923          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13924             {
13925                gnbDuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
13926                break;
13927             }
13928
13929          case ProtocolIE_ID_id_SpCell_ID:
13930             {
13931                bitStringToInt(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity, &nrCellId);
13932
13933                GET_CELL_IDX(nrCellId, cellIdx);
13934                if(!duCb.actvCellLst[cellIdx])
13935                {
13936                   DU_LOG("\nERROR  -->  F1AP : Cell Id [%lu] not found", nrCellId);
13937                   ret = RFAILED;
13938                }
13939                break;
13940             }
13941
13942          case ProtocolIE_ID_id_ServCellIndex:
13943             {
13944                //servCellIdx = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.ServCellIndex;
13945                break;
13946             }
13947
13948          case ProtocolIE_ID_id_SpCellULConfigured:
13949             {
13950                /* Indicates whether the gNB-CU requests the gNB-DU to configure the uplink as no UL, 
13951                   UL, SUL or UL+SUL for the indicated cell for the UE */
13952                break;
13953             }
13954
13955          case ProtocolIE_ID_id_CUtoDURRCInformation:
13956             {
13957                rrcInfo = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation;
13958
13959                /* Search if UE context is present */
13960                for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
13961                {
13962                   if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId)
13963                   {
13964                      ueCbFound = true;
13965                      duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13966                      break;
13967                   }
13968                }
13969
13970                /* Check if UE Handover scenario */
13971                if(rrcInfo->iE_Extensions)
13972                {
13973                   for(ieExtIdx = 0; ieExtIdx < rrcInfo->iE_Extensions->list.count; ieExtIdx++)
13974                   {
13975                      if(rrcInfo->iE_Extensions->list.array[ieExtIdx]->id == ProtocolIE_ID_id_HandoverPreparationInformation)
13976                      {
13977                         hoInProgress = true;
13978                         break;
13979                      }
13980                   }
13981                }
13982                
13983                /* If UE context is not present, but UE is in handover */
13984                if(!ueCbFound && hoInProgress)
13985                {
13986                   ueIdx = getFreeBitFromUeBitMap(nrCellId);
13987                   if(ueIdx != -1)
13988                      gnbDuUeF1apId = ueIdx +1;
13989                   else
13990                   {
13991                      DU_LOG("\nERROR  -->  F1AP : No free UE IDX found in UE bit map of cell Id [%lu]", nrCellId);
13992                      ret = RFAILED;
13993                      break;
13994                   }
13995                   duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13996                   duUeCb->f1UeDb = NULL;
13997                   duUeCb->gnbCuUeF1apId = gnbCuUeF1apId;
13998                   duUeCb->gnbDuUeF1apId = gnbDuUeF1apId;
13999                   GET_CRNTI(duUeCb->crnti, duUeCb->gnbDuUeF1apId);
14000                   duUeCb->ueState = UE_HANDIN_IN_PROGRESS;
14001                }
14002
14003                if(duUeCb)
14004                {
14005                   DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
14006                   if(duUeCb->f1UeDb)
14007                   {
14008                      memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
14009                      duUeCb->f1UeDb->actionType = UE_CTXT_SETUP;
14010                      duUeCb->f1UeDb->cellIdx = cellIdx;
14011                   }
14012                   else
14013                   {
14014                      DU_LOG("\nERROR  -->  F1AP: Memory Alloc Failed at procF1UeContextSetupReq()");
14015                      ret = RFAILED;
14016                      break;
14017                   }
14018                }
14019                else
14020                {
14021                   DU_LOG("\nERROR  -->  F1AP: DuUeCb is not found at procF1UeContextSetupReq()");
14022                   ret = RFAILED;
14023                   break;
14024                }
14025                  
14026                /* Extract UE capability info */
14027                if(rrcInfo->uE_CapabilityRAT_ContainerList)
14028                {
14029                   duUeCb->f1UeDb->duUeCfg.ueNrCapability = extractUeCapability(rrcInfo->uE_CapabilityRAT_ContainerList, duUeCb);
14030                }
14031
14032                /* Extract IE extension */
14033                if(rrcInfo->iE_Extensions)
14034                {
14035                   if(extractCuToDuRrcInfoExt(rrcInfo->iE_Extensions, &duUeCb->f1UeDb->duUeCfg) != ROK)
14036                   {
14037                      DU_LOG("\nERROR  -->  F1AP: Failed to extract CU to DU RRC information extension IE");
14038                      //TODO: Update the failure cause in ue context Setup Response
14039                      ret = RFAILED;
14040                   }
14041                }
14042                break;
14043             } 
14044
14045 #ifdef NR_DRX
14046          case ProtocolIE_ID_id_DRXCycle:
14047             {
14048                duUeCb->f1UeDb->duUeCfg.drxCyclePres = true;
14049                drxCycle = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle;
14050                duUeCb->f1UeDb->duUeCfg.drxCycle.drxLongCycleLength =  convertLongDrxCycleLengthEnumToValue(drxCycle->longDRXCycleLength);
14051                if(drxCycle->shortDRXCycleLength)
14052                {
14053                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCyclePres = true;
14054                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycle = \
14055                   convertShortDrxCycleLengthEnumToValue(*(drxCycle->shortDRXCycleLength));
14056                }
14057                if(drxCycle->shortDRXCycleTimer)
14058                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycleTimer = *(drxCycle->shortDRXCycleTimer);   
14059
14060                break;
14061             }
14062
14063 #endif
14064          case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
14065             {
14066                if(extractSrbListToSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List,\
14067                         &duUeCb->f1UeDb->duUeCfg))
14068                {
14069                   DU_LOG("\nERROR  -->  DU APP : Failed at extractSrbListToSetup()");
14070                   //TODO: Update the failure cause in ue context Setup Response
14071                   ret = RFAILED;
14072                }
14073                break;
14074             }
14075
14076          case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
14077             {
14078                drbCfg = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List;
14079
14080                if(extractDrbListToSetupMod(drbCfg, NULL, NULL, drbCfg->list.count, &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULLP))
14081                {
14082                   DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod()");
14083                   //TODO: Update the failure cause in ue context Setup Response
14084                   ret = RFAILED;
14085                }
14086                break;
14087             }
14088          case ProtocolIE_ID_id_RRCContainer:
14089             {
14090                /* Filling Dl RRC Msg Info */
14091                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
14092                if(!duUeCb->f1UeDb->dlRrcMsg)
14093                {
14094                   DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for DL RRC Msg in procUeCtxtSetupReq()");
14095                   ret = RFAILED;
14096                }
14097                else
14098                {
14099                   duUeCb->f1UeDb->dlRrcMsgPres = true;
14100                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
14101                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
14102                         &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer);
14103                }          
14104                break;
14105             }
14106
14107          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
14108             {
14109                if(duUeCb->f1UeDb->dlRrcMsg)
14110                {
14111                   if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
14112                   {
14113                      duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
14114                   }
14115                   else
14116                   {
14117                      DU_LOG("\nERROR  -->  Ignoring delivery report, since rrcContainer is not present");
14118                   }
14119                }
14120                break;
14121             }
14122
14123          case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
14124             {
14125                /* MaximumBitRate Uplink */
14126                bitRateSize = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.size;
14127                if(bitRateSize > 0)
14128                {
14129                   DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->duUeCfg.ambrCfg, bitRateSize);
14130                   if(!duUeCb->f1UeDb->duUeCfg.ambrCfg)
14131                   {
14132                      DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for bitRate in procUeCtxtSetupReq");
14133                      ret = RFAILED;
14134                   }
14135                   else
14136                   {
14137                      memset(duUeCb->f1UeDb->duUeCfg.ambrCfg, 0, sizeof(AmbrCfg)); 
14138                      memcpy(&duUeCb->f1UeDb->duUeCfg.ambrCfg->ulBr,
14139                            ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf, bitRateSize);
14140                   }
14141                }
14142                else
14143                   ret = RFAILED;
14144                break;
14145             }
14146
14147          default:
14148             {
14149                break;
14150             }
14151       } /* End of switch */
14152
14153       /* In case of any failure in any IE */
14154       if(ret == RFAILED)
14155       {
14156          // BuildAndSendUeContextSetupRsp(cellId,ueId);
14157          DU_LOG("\nERROR  -->  F1AP: Failed to process UE CNTXT SETUP REQ at procF1UeContextSetupReq()"); 
14158          break;
14159       }
14160    } /* End of for loop of IEs */
14161
14162    if(ret == ROK)
14163       ret = duProcUeContextSetupRequest(duUeCb);
14164
14165    freeAperDecodeF1UeContextSetupReq(ueSetReq); 
14166    return ret;
14167
14168 }
14169 /*******************************************************************
14170  * @brief Free the memory allocated for Dl Tunnel Info
14171  *
14172  * @details
14173  *
14174  *    Function : freeDlTnlInfo
14175  *
14176  *    Functionality:
14177  *       Free the memory allocated for Dl Tunnel Info
14178  *
14179  * @params[in] DLUPTNLInformation_ToBeSetup_List_t *
14180  * @return void
14181  *
14182  * ****************************************************************/
14183
14184 void freeDlTnlInfo(DLUPTNLInformation_ToBeSetup_List_t *tnlInfo)
14185 {
14186    uint8_t arrIdx = 0;
14187
14188    if(tnlInfo)
14189    {
14190       for(arrIdx=0; arrIdx < tnlInfo->list.count; arrIdx++)
14191       {
14192          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf,\
14193                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.size);
14194          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf,\
14195                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.size);
14196          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14197          DU_FREE(tnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14198       }
14199       DU_FREE(tnlInfo->list.array, tnlInfo->list.size);
14200    }
14201 }
14202
14203 /*******************************************************************
14204  * @brief Free the memory allocated for DRB setup List
14205  *
14206  * @details
14207  *
14208  *    Function : freeDrbSetupList
14209  *
14210  *    Functionality:
14211  *       Free the memory allocated for DRB setup list
14212  *
14213  * @params[in] DRBs_Setup_List_t *
14214  * @return void
14215  *
14216  * ****************************************************************/
14217 void freeDrbSetupList(DRBs_Setup_List_t *drbSetupList)
14218 {
14219    uint8_t arrIdx = 0;
14220    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14221
14222    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
14223    {
14224       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14225       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List);
14226       DU_FREE(drbSetupList->list.array[arrIdx],  sizeof(DRBs_Setup_Item_t));
14227    }
14228    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
14229 }
14230
14231 /*******************************************************************
14232  * @brief Free the memory allocated for UE Setup response
14233  *
14234  * @details
14235  *
14236  *    Function : FreeUeContextSetupRsp
14237  *
14238  *    Functionality:
14239  *       Free the memory allocated for UE Setup response
14240  *
14241  * @params[in] F1AP PDU for UE setup response
14242  * @return ROK     - success
14243  *         RFAILED - failure
14244  *
14245  * ****************************************************************/
14246 void FreeUeContextSetupRsp(F1AP_PDU_t *f1apMsg)
14247 {
14248    uint8_t idx;
14249    UEContextSetupResponse_t *ueSetRsp = NULLP;
14250
14251    if(f1apMsg)
14252    {
14253       if(f1apMsg->choice.successfulOutcome)
14254       {
14255          ueSetRsp = &f1apMsg->choice.successfulOutcome->value.choice.\
14256                     UEContextSetupResponse;
14257          if(ueSetRsp->protocolIEs.list.array)
14258          {
14259             for(idx = 0; idx < ueSetRsp->protocolIEs.list.count; idx++)
14260             {
14261                if(ueSetRsp->protocolIEs.list.array[idx])
14262                {
14263                   switch(ueSetRsp->protocolIEs.list.array[idx]->id)
14264                   {
14265                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14266                         break;
14267                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14268                         break;
14269                      case ProtocolIE_ID_id_C_RNTI:
14270                         break;
14271                      case ProtocolIE_ID_id_DUtoCURRCInformation:
14272                         {
14273                            CellGroupConfig_t *cellGrpCfg = NULLP;
14274                            cellGrpCfg  = &ueSetRsp->protocolIEs.list.array[idx]->value.choice.\
14275                                          DUtoCURRCInformation.cellGroupConfig;
14276                            if(cellGrpCfg->buf != NULLP)
14277                            {
14278                               DU_FREE(cellGrpCfg->buf, cellGrpCfg->size);
14279                               cellGrpCfg = NULLP;
14280                            }
14281                            break;
14282                         }
14283                      case ProtocolIE_ID_id_DRBs_Setup_List:
14284                         {
14285                            freeDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List); 
14286                            break;
14287                         }
14288                      default:
14289                         DU_LOG("\nERROR  -->  DUAPP: Invalid Id %ld at FreeUeContextSetupRsp()",\
14290                               ueSetRsp->protocolIEs.list.array[idx]->id);
14291                         break;
14292                   }
14293                   DU_FREE(ueSetRsp->protocolIEs.list.array[idx],\
14294                         sizeof(UEContextSetupResponseIEs_t));
14295                }
14296             }
14297             DU_FREE(ueSetRsp->protocolIEs.list.array, \
14298                   ueSetRsp->protocolIEs.list.size);
14299          }
14300          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14301       }
14302       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14303    }
14304 }
14305
14306 /*******************************************************************
14307  *
14308  * @brief Builds Ue context Setup Rsp DU To CU Info
14309  *
14310  * @details
14311  *
14312  *    Function : EncodeUeCntxtDuToCuInfo
14313  *
14314  *    Functionality: Builds Ue context Setup Rsp DU To CU Info
14315  *
14316  * @params[in] CellGroupConfig_t *, CellGroupConfigRrc_t * 
14317  *
14318  * @return ROK     - success
14319  *         RFAILED - failure
14320  *
14321  ******************************************************************/
14322
14323 uint8_t EncodeUeCntxtDuToCuInfo(CellGroupConfig_t *duToCuCellGrp, CellGroupConfigRrc_t *duCellGrpCfg)
14324 {
14325    asn_enc_rval_t        encRetVal;
14326
14327    xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, duCellGrpCfg);
14328    memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14329    encBufSize = 0;
14330    encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, duCellGrpCfg, PrepFinalEncBuf, encBuf);
14331    /* Encode results */
14332    if(encRetVal.encoded == ENCODE_FAIL)
14333    {
14334       DU_LOG( "\nERROR  -->  F1AP : Could not encode UeCntxtDuToCuInfo (at %s)\n",\
14335             encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14336       return RFAILED;
14337    }
14338    else
14339    {
14340       DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UeCntxtDuToCuInfo\n");
14341 #ifdef DEBUG_ASN_PRINT
14342       for(int i=0; i< encBufSize; i++)
14343       {
14344          printf("%x",encBuf[i]);
14345       }
14346 #endif
14347    }
14348    duToCuCellGrp->size = encBufSize;
14349    DU_ALLOC(duToCuCellGrp->buf, duToCuCellGrp->size);
14350    if(!duToCuCellGrp->buf)
14351    {
14352       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in UeCntxtDuToCuInfo");
14353    }
14354    memcpy(duToCuCellGrp->buf, encBuf, duToCuCellGrp->size);
14355    return ROK;
14356 }
14357
14358 /*******************************************************************
14359  *
14360  * @brief Fills Dl Gtp tunnel Info
14361  *
14362  * @details
14363  *
14364  *    Function : fillGtpTunnelforDl
14365  *
14366  *    Functionality: Fills Dl Gtp tunnel Info
14367  *
14368  * @params[in] 
14369  *
14370  * @return ROK     - success
14371  *         RFAILED - failure
14372  *
14373  * ****************************************************************/
14374
14375 uint8_t fillGtpTunnelforDl(GTPTunnel_t *gtpDl, GtpTnlCfg *gtpUeCfg)
14376 {
14377    uint8_t bufSize = 0;
14378
14379    gtpDl->transportLayerAddress.size    = 4*sizeof(uint8_t);
14380    DU_ALLOC(gtpDl->transportLayerAddress.buf, gtpDl->transportLayerAddress.size);
14381    if(gtpDl->transportLayerAddress.buf == NULLP)
14382    {
14383       return RFAILED;
14384    }
14385    memcpy(gtpDl->transportLayerAddress.buf, &gtpUeCfg->dlTnlAddress, gtpDl->transportLayerAddress.size);
14386
14387    /*GTP TEID*/
14388    gtpDl->gTP_TEID.size = 4 * sizeof(uint8_t);
14389    DU_ALLOC(gtpDl->gTP_TEID.buf, gtpDl->gTP_TEID.size);
14390    if(gtpDl->gTP_TEID.buf == NULLP)
14391    {
14392       return RFAILED;
14393    }
14394    bufSize = 3; /*forming an Octect String*/
14395    fillTeIdString(bufSize, gtpUeCfg->teId, gtpDl->gTP_TEID.buf);
14396
14397    return ROK;
14398 }
14399
14400 /*******************************************************************
14401  *
14402  * @brief Fills DL Tunnel Setup List
14403  *
14404  * @details
14405  *
14406  *    Function : fillDlTnlSetupList
14407  *
14408  *    Functionality: Fills the DL Tunnel Setup List
14409  *
14410  * @params[in] 
14411  *
14412  * @return ROK     - success
14413  *         RFAILED - failure
14414  *
14415  * ****************************************************************/
14416
14417 uint8_t fillDlTnlSetupList(DLUPTNLInformation_ToBeSetup_List_t *dlTnlInfo, UpTnlCfg *tnlCfg)
14418 {
14419    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14420
14421    eleCount = 1;
14422    dlTnlInfo->list.count = eleCount; 
14423    dlTnlInfo->list.size = (eleCount * sizeof(DLUPTNLInformation_ToBeSetup_Item_t *));
14424
14425    /* Initialize the DL Tnl Setup List Members */
14426    DU_ALLOC(dlTnlInfo->list.array, dlTnlInfo->list.size);
14427    if(dlTnlInfo->list.array == NULLP)
14428    {
14429       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL Tnl Setup List in fillDlTnlSetupList()");
14430       ret = RFAILED;
14431    }
14432    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14433    {
14434       DU_ALLOC(dlTnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14435       if(dlTnlInfo->list.array[arrIdx] == NULLP)
14436       {
14437          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDlTnlSetupList()", arrIdx);
14438          return RFAILED;
14439       }
14440       dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.present = UPTransportLayerInformation_PR_gTPTunnel;
14441       DU_ALLOC(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14442       if(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel == NULLP)
14443       {
14444          DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL tunnel info in fillDlTnlSetupList()");
14445          return RFAILED;
14446       }
14447       ret = fillGtpTunnelforDl(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel,\
14448                tnlCfg->tnlCfg1);
14449       if(ret != ROK)
14450          break;
14451    }
14452    return ret;
14453 }
14454
14455 /*******************************************************************
14456  *
14457  * @brief Fills the Drb Setup List for Ue Context Setup Response
14458  *
14459  * @details
14460  *
14461  *    Function : fillDrbSetupList
14462  *
14463  *    Functionality: Fills the Drb Setup List for Ue Context Setup Response
14464  *
14465  * @params[in] 
14466  *
14467  * @return ROK     - success
14468  *         RFAILED - failure
14469  *
14470  * ****************************************************************/
14471 uint8_t fillDrbSetupList(DRBs_Setup_List_t *drbSetupList, DuUeCfg *ueCfg)
14472 {
14473    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14474    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14475
14476    eleCount = ueCfg->numDrb;
14477    drbSetupList->list.count = eleCount;
14478    drbSetupList->list.size = \
14479         (eleCount * sizeof(DRBs_Setup_Item_t *));
14480
14481    /* Initialize the Drb Setup List Members */
14482    DU_ALLOC(drbSetupList->list.array, drbSetupList->list.size);
14483    if(drbSetupList->list.array == NULLP)
14484    {
14485       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DRB Setup List in fillDrbSetupList()");
14486       ret = RFAILED;
14487    }
14488
14489    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14490    {
14491       DU_ALLOC(drbSetupList->list.array[arrIdx], sizeof(DRBs_Setup_Item_t));
14492       if(drbSetupList->list.array[arrIdx] == NULLP)
14493       {
14494          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDrbSetupList()", arrIdx);
14495          return RFAILED;
14496       }
14497       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14498       drbItemIe->id = ProtocolIE_ID_id_DRBs_Setup_Item;
14499       drbItemIe->criticality = Criticality_reject;
14500       drbItemIe->value.present = DRBs_Setup_ItemIEs__value_PR_DRBs_Setup_Item;
14501       drbItemIe->value.choice.DRBs_Setup_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
14502       ret = fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List,\
14503           &ueCfg->upTnlInfo[arrIdx]);
14504       if(ret != ROK)
14505          break;
14506    }
14507    return ret;
14508 }
14509
14510 /*******************************************************************
14511  *
14512  * @brief Builds and sends the UE Setup Response
14513  *
14514  * @details
14515  *
14516  *    Function : BuildAndSendUeContextSetupRsp
14517  *
14518  *    Functionality: Constructs the UE Setup Response and sends
14519  *                   it to the DU through SCTP.
14520  *
14521  * @params[in] uint8_t cellId,uint8_t ueId
14522  *
14523  * @return ROK     - success
14524  *         RFAILED - failure
14525  *
14526  * ****************************************************************/
14527 uint8_t BuildAndSendUeContextSetupRsp(uint8_t cellId,uint8_t ueId)
14528 {
14529    uint8_t   idx, ret, cellIdx, elementCnt;
14530    uint32_t  gnbCuUeF1apId;   /* gNB-CU UE F1AP Id */
14531    uint32_t  gnbDuUeF1apId;   /* gNB-DU UE F1AP Id */
14532    asn_enc_rval_t  encRetVal;        /* Encoder return value */
14533    F1AP_PDU_t               *f1apMsg = NULLP;
14534    UEContextSetupResponse_t *ueSetRsp = NULLP;
14535    DuUeCb                   *ueCb = NULLP;
14536
14537    DU_LOG("\n INFO   -->  F1AP : Building UE Context Setup Response for cellId %d, ueId %d\n", cellId, ueId);
14538
14539    while(true)
14540    {
14541       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14542       if(f1apMsg == NULLP)
14543       {
14544          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14545          ret = RFAILED;
14546          break;
14547       }
14548
14549       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
14550       DU_ALLOC(f1apMsg->choice.successfulOutcome,
14551             sizeof(SuccessfulOutcome_t));
14552       if(f1apMsg->choice.successfulOutcome == NULLP)
14553       {
14554          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
14555          ret = RFAILED;
14556          break;
14557       }
14558
14559       f1apMsg->choice.successfulOutcome->procedureCode = \
14560                                                          ProcedureCode_id_UEContextSetup;
14561       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
14562       f1apMsg->choice.successfulOutcome->value.present = \
14563                                                          SuccessfulOutcome__value_PR_UEContextSetupResponse;
14564
14565       ueSetRsp =
14566          &f1apMsg->choice.successfulOutcome->value.choice.UEContextSetupResponse;
14567       elementCnt = 5;
14568       ueSetRsp->protocolIEs.list.count = elementCnt;
14569       ueSetRsp->protocolIEs.list.size = \
14570                                         elementCnt * sizeof(UEContextSetupResponse_t *);
14571
14572       /* Initialize the UESetup members */
14573       DU_ALLOC(ueSetRsp->protocolIEs.list.array, \
14574             ueSetRsp->protocolIEs.list.size);
14575       if(ueSetRsp->protocolIEs.list.array == NULLP)
14576       {
14577          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14578          ret = RFAILED;
14579          break;
14580       }
14581
14582       for(idx=0; idx<elementCnt; idx++)
14583       {
14584          DU_ALLOC(ueSetRsp->protocolIEs.list.array[idx],\
14585                sizeof(UEContextSetupResponseIEs_t));
14586          if(ueSetRsp->protocolIEs.list.array[idx] == NULLP)
14587          {
14588             DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14589             ret = RFAILED;
14590             break;
14591          }
14592       }
14593       /* Fetching Ue Cb Info*/
14594       GET_CELL_IDX(cellId, cellIdx);
14595       gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
14596       gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
14597       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
14598
14599       idx = 0;
14600       /*GNB CU UE F1AP ID*/
14601       ueSetRsp->protocolIEs.list.array[idx]->id = \
14602                                                   ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
14603       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14604       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14605                                                              UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
14606       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
14607
14608       /*GNB DU UE F1AP ID*/
14609       idx++;
14610       ueSetRsp->protocolIEs.list.array[idx]->id = \
14611                                                   ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14612       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14613       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14614                                                              UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
14615       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
14616
14617
14618       /*DUtoCURRC Information */
14619       idx++;
14620       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14621                                                    ProtocolIE_ID_id_DUtoCURRCInformation;
14622       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14623       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14624                                                             UEContextSetupResponseIEs__value_PR_DUtoCURRCInformation;
14625       BuildCellGroupConfigRrc(ueCb, &ueSetRsp->protocolIEs.list.array[idx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
14626
14627       /* CRNTI */
14628       idx++;
14629       ueSetRsp->protocolIEs.list.array[idx]->id  = ProtocolIE_ID_id_C_RNTI;
14630       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14631       ueSetRsp->protocolIEs.list.array[idx]->value.present = UEContextSetupResponseIEs__value_PR_C_RNTI;
14632       ueSetRsp->protocolIEs.list.array[idx]->value.choice.C_RNTI = ueCb->crnti; 
14633
14634
14635       /* Drb Setup List */
14636       idx++;
14637       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14638                                                    ProtocolIE_ID_id_DRBs_Setup_List;
14639       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14640       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14641                                                             UEContextSetupResponseIEs__value_PR_DRBs_Setup_List;
14642       ret = fillDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List,\
14643             &ueCb->f1UeDb->duUeCfg);
14644       if(ret == RFAILED)
14645       {
14646          DU_LOG("\nERROR  -->  F1AP : Failed to fillDrbSetupList in BuildAndSendUeContextSetupRsp()");
14647          freeF1UeDb(ueCb->f1UeDb);
14648          ueCb->f1UeDb = NULLP;
14649          break;
14650       }
14651
14652       /* Free UeContext Db created during Ue context Req */
14653       freeF1UeDb(ueCb->f1UeDb);
14654       ueCb->f1UeDb = NULLP;
14655
14656       /* TODO: To send Drb list */
14657       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14658
14659       /* Encode the UE context setup response type as APER */
14660       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14661       encBufSize = 0;
14662       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14663             encBuf);
14664       /* Encode results */
14665       if(encRetVal.encoded == ENCODE_FAIL)
14666       {
14667          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Response structure (at %s)\n",\
14668                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14669          ret = RFAILED;
14670          break;
14671       }
14672       else
14673       {
14674          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Setup Response\n");
14675 #ifdef DEBUG_ASN_PRINT
14676          for(int i=0; i< encBufSize; i++)
14677          {
14678             printf("%x",encBuf[i]);
14679          }
14680 #endif
14681       }
14682
14683       /* Sending  msg  */
14684       if(sendF1APMsg()  != ROK)
14685       {
14686          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Response failed");
14687          ret = RFAILED;
14688          break;
14689       }
14690       break;
14691    }
14692    FreeUeContextSetupRsp(f1apMsg);
14693    return ret;
14694 }/* End of BuildAndSendUeContextSetupRsp */
14695
14696 /*******************************************************************
14697 *
14698 * @brief  Build And Send Ue Context Rsp 
14699 *
14700 * @details
14701 *
14702 *    Function : BuildAndSendUeCtxtRsp 
14703 *
14704 *    Functionality : Build And Send Ue Context Rsp
14705
14706 * @params[in]
14707 * @return sucess = ROK
14708 *         failure = RFAILED
14709 *
14710 * ****************************************************************/
14711 uint8_t BuildAndSendUeCtxtRsp(uint8_t cellId, uint8_t ueId)
14712 {
14713    uint8_t cellIdx = 0, actionType = 0; 
14714
14715    GET_CELL_IDX(cellId, cellIdx);
14716    actionType = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].f1UeDb->actionType;
14717
14718    switch(actionType)
14719    {
14720       case UE_CTXT_SETUP:
14721          {
14722             if((BuildAndSendUeContextSetupRsp(cellId,ueId)) != ROK)
14723             {
14724                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextSetupRsp()");
14725                return RFAILED;
14726             }
14727             break;
14728          }
14729       case UE_CTXT_MOD:
14730          {
14731             if((BuildAndSendUeContextModRsp(&duCb.actvCellLst[cellIdx]->ueCb[ueId-1])) != ROK)
14732             {
14733                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextModRsp");
14734                return RFAILED;
14735             }
14736             break;
14737          }
14738       default:
14739          DU_LOG("ERROR  -->  F1AP: Invalid Action Type %d at BuildAndSendUeCtxtRsp()", actionType);
14740          break;
14741
14742    }
14743    return ROK;
14744 }
14745
14746 /*******************************************************************
14747  *
14748  * @brief deallocating the memory of  F1reset msg
14749  *
14750  * @details
14751  *
14752  *    Function : FreeF1ResetReq
14753  *
14754  *    Functionality :
14755  *         - freeing memory of F1reset request msg
14756  *
14757  * @params[in]
14758  * @return void
14759  *
14760  *
14761  * ****************************************************************/
14762 void FreeF1ResetReq(F1AP_PDU_t *f1apMsg)
14763 {
14764    uint8_t idx =0 ;
14765    Reset_t *f1ResetMsg;
14766
14767    if(f1apMsg)
14768    {
14769       if(f1apMsg->choice.initiatingMessage)
14770       {
14771          f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14772
14773          if(f1ResetMsg->protocolIEs.list.array)
14774          {
14775             for(idx=0 ;idx < f1ResetMsg->protocolIEs.list.count ; idx++)
14776             {
14777                if(f1ResetMsg->protocolIEs.list.array[idx])
14778                {
14779                   DU_FREE(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14780                }
14781             }
14782             DU_FREE(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14783          }
14784          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14785       }
14786       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14787    }
14788 }
14789 /*******************************************************************
14790  *
14791  * @brief Build and Send F1reset request 
14792  *
14793  * @details
14794  *
14795  *    Function : BuildAndSendF1ResetReq
14796  *
14797  *    Functionality:
14798  *         - Build and Send F1reset request msg
14799  *
14800  * @params[in]
14801  * @return ROK     - success
14802  *         RFAILED - failure
14803  *
14804  * ****************************************************************/
14805 uint8_t BuildAndSendF1ResetReq()
14806 {
14807    uint8_t          elementCnt=0;
14808    uint8_t          idx=0;
14809    uint8_t          ret= RFAILED;
14810    Reset_t          *f1ResetMsg = NULLP;
14811    F1AP_PDU_t       *f1apMsg = NULLP;
14812    asn_enc_rval_t   encRetVal;
14813    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset request \n");
14814    do
14815    {
14816       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14817       if(f1apMsg == NULLP)
14818       {
14819          break;
14820       }
14821       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
14822       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14823       if(f1apMsg->choice.initiatingMessage == NULLP)
14824       {
14825          break;
14826       }
14827       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_Reset;
14828       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
14829       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_Reset;
14830
14831       f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14832
14833       elementCnt = 3;
14834       f1ResetMsg->protocolIEs.list.count = elementCnt;
14835       f1ResetMsg->protocolIEs.list.size = elementCnt * sizeof(ResetIEs_t *);
14836
14837       /* Initialize the F1Setup members */
14838       DU_ALLOC(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14839       if(f1ResetMsg->protocolIEs.list.array == NULLP)
14840       {
14841          break;
14842       }
14843       for(idx=0; idx<elementCnt; idx++)
14844       {
14845          DU_ALLOC(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14846          if(f1ResetMsg->protocolIEs.list.array[idx] == NULLP)
14847          {
14848             break;
14849          }
14850       }
14851
14852       /*TransactionID*/
14853       idx=0;
14854       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
14855       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14856       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_TransactionID;
14857       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.TransactionID = 1;
14858
14859       /*Cause*/
14860       idx++;
14861       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_Cause;
14862       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_ignore;
14863       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_Cause;
14864       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.present = Cause_PR_radioNetwork;
14865       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.choice.radioNetwork = CauseRadioNetwork_action_desirable_for_radio_reasons;
14866
14867       /*Reset Type*/
14868       idx++;
14869       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_ResetType;
14870       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14871       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_ResetType;
14872       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.present = ResetType_PR_f1_Interface;
14873       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.choice.f1_Interface = ResetAll_reset_all;
14874
14875       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14876
14877       /* Encode the F1SetupRequest type as APER */
14878       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14879       encBufSize = 0;
14880       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14881             encBuf);
14882
14883       /* Encode results */
14884       if(encRetVal.encoded == ENCODE_FAIL)
14885       {
14886          DU_LOG("\nERROR  -->  F1AP : Could not encode F1Reset structure (at %s)\n",\
14887                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14888          break;
14889       }
14890       else
14891       {
14892          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1Reset\n");
14893 #ifdef DEBUG_ASN_PRINT
14894          for(idx=0; idx< encBufSize; idx++)
14895          {
14896             printf("%x",encBuf[idx]);
14897          }
14898 #endif
14899       }
14900
14901       if(sendF1APMsg() != ROK)
14902       {
14903          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset request failed");
14904          break;
14905       }
14906
14907       ret = ROK;
14908       break;
14909    }while(true);
14910
14911    FreeF1ResetReq(f1apMsg);
14912    return ret;
14913 }
14914 /*******************************************************************
14915  *
14916  * @brief Build And Send F1ResetAck
14917  *
14918  * @details
14919  *
14920  *    Function : BuildAndSendF1ResetAck
14921  *
14922  *    Functionality:
14923  *         - Build And Send  F1ResetRSP
14924  *
14925  * @return ROK     - success
14926  *         RFAILED - failure
14927  *
14928  * ****************************************************************/
14929 void FreeF1ResetAck(F1AP_PDU_t *f1apMsg)
14930 {
14931    uint8_t idx;
14932    ResetAcknowledge_t *f1ResetAck;
14933
14934    if(f1apMsg)
14935    {
14936       if(f1apMsg->choice.successfulOutcome)
14937       {
14938          f1ResetAck= &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14939
14940          if(f1ResetAck->protocolIEs.list.array)
14941          {
14942             for(idx=0; idx<f1ResetAck->protocolIEs.list.count ; idx++)
14943             {
14944                if(f1ResetAck->protocolIEs.list.array[idx])
14945                {
14946                   DU_FREE(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14947                }
14948             }
14949             DU_FREE(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14950          }
14951          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14952       }
14953       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14954    }
14955 }
14956
14957 /*******************************************************************
14958  *
14959  * @brief Build And Send F1ResetAck
14960  *
14961  * @details
14962  *
14963  *    Function : BuildAndSendF1ResetAck
14964  *
14965  *    Functionality:
14966  *         - Build And Send  F1ResetRSP
14967  *
14968  *  @params[in]
14969  * @return ROK     - success
14970  *         RFAILED - failure
14971  *
14972  * ****************************************************************/
14973 uint8_t BuildAndSendF1ResetAck()
14974 {
14975    uint8_t                idx = 0;
14976    uint8_t                elementCnt = 0;
14977    uint8_t                ret = RFAILED;
14978    F1AP_PDU_t             *f1apMsg = NULL;
14979    ResetAcknowledge_t     *f1ResetAck = NULLP;
14980    asn_enc_rval_t         encRetVal;
14981    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset Acknowledgment \n");
14982
14983    do{
14984       /* Allocate the memory for F1ResetRequest_t */
14985       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14986       if(f1apMsg == NULLP)
14987       {
14988          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14989          break;
14990       }
14991
14992       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
14993
14994       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14995       if(f1apMsg->choice.successfulOutcome == NULLP)
14996       {
14997          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14998          break;
14999       }
15000       f1apMsg->choice.successfulOutcome->criticality   = Criticality_reject;
15001       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetAcknowledge;
15002       f1ResetAck = &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
15003
15004       elementCnt = 1;
15005
15006       f1ResetAck->protocolIEs.list.count = elementCnt;
15007       f1ResetAck->protocolIEs.list.size = elementCnt*sizeof(ResetAcknowledgeIEs_t *);
15008
15009       DU_ALLOC(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
15010       if(f1ResetAck->protocolIEs.list.array == NULLP)
15011       {
15012          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1ResetAckIEs failed");
15013          break;
15014       }
15015
15016       for(idx=0; idx<elementCnt; idx++)
15017       {
15018          DU_ALLOC(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
15019          if(f1ResetAck->protocolIEs.list.array[idx] == NULLP)
15020          {
15021             break;
15022          }
15023       }
15024       /*TransactionID*/
15025       idx = 0;
15026       f1ResetAck->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
15027       f1ResetAck->protocolIEs.list.array[idx]->criticality = Criticality_reject;
15028       f1ResetAck->protocolIEs.list.array[idx]->value.present = ResetAcknowledgeIEs__value_PR_TransactionID;
15029       f1ResetAck->protocolIEs.list.array[idx]->value.choice.TransactionID = TRANS_ID;
15030
15031       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15032
15033       /* Encode the F1SetupRequest type as UPER */
15034       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15035       encBufSize = 0;
15036       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
15037
15038       /* Check encode results */
15039       if(encRetVal.encoded == ENCODE_FAIL)
15040       {
15041          DU_LOG("\nERROR  -->  F1AP : Could not encode F1ResetAck structure (at %s)\n",\
15042                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15043          break;
15044       }
15045       else
15046       {
15047          DU_LOG("\nDUBUG   -->  F1AP : Created APER encoded buffer for F1ResetAck\n");
15048 #ifdef DEBUG_ASN_PRINT
15049          for(int i=0; i< encBufSize; i++)
15050          {
15051             printf("%x",encBuf[i]);
15052          }
15053 #endif
15054       }
15055       /* Sending msg */
15056       if(sendF1APMsg() != ROK)
15057       {
15058          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset Acknowledgement failed");
15059          break;
15060       }
15061
15062       ret = ROK;
15063       break;
15064    }while(true);
15065
15066    FreeF1ResetAck(f1apMsg);
15067    return ret;
15068 }
15069 /******************************************************************
15070 *
15071 * @brief free F1 reset msg allocated by aper_decoder 
15072 *
15073 * @details
15074 *
15075 *    Function : freeAperDecodeF1ResetMsg 
15076 *
15077 *    Functionality: free F1 reset msg allocated by aper_decoder 
15078 *
15079 * @params[in] Reset_t *f1ResetMsg 
15080 * @return void 
15081 *
15082 * ****************************************************************/
15083
15084 void freeAperDecodeF1ResetMsg(Reset_t *f1ResetMsg)
15085 {
15086    uint8_t ieIdx =0;
15087    if(f1ResetMsg->protocolIEs.list.array)
15088    {
15089       for(ieIdx=0 ;ieIdx < f1ResetMsg->protocolIEs.list.count ; ieIdx++)
15090       {
15091          if(f1ResetMsg->protocolIEs.list.array[ieIdx])
15092          {
15093             free(f1ResetMsg->protocolIEs.list.array[ieIdx]);
15094          }
15095       }
15096       free(f1ResetMsg->protocolIEs.list.array);
15097    }
15098 }
15099
15100 /******************************************************************
15101  *
15102  * @brief Processes DL RRC Message Transfer  sent by CU
15103  *
15104  * @details
15105  *
15106  *    Function : procF1ResetReq
15107  *
15108  *    Functionality: Processes DL RRC Message Transfer sent by CU
15109  *
15110  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15111  * @return ROK     - success
15112  *         RFAILED - failure
15113  *
15114  * ****************************************************************/
15115 uint8_t procF1ResetReq(F1AP_PDU_t *f1apMsg)
15116 {
15117    /* we are currently not supporting Ue release. right now we are supporting only init case of fireset */
15118    uint8_t       ieIdx = 0;
15119    uint8_t        ret = ROK;
15120    Reset_t       *f1ResetMsg = NULLP;
15121
15122    DU_LOG("\nINFO   -->  Processing F1 reset request");
15123    f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
15124
15125    for(ieIdx=0; ieIdx<f1ResetMsg->protocolIEs.list.count; ieIdx++)
15126    {
15127       switch(f1ResetMsg->protocolIEs.list.array[ieIdx]->id)
15128       {
15129          case ProtocolIE_ID_id_TransactionID:
15130             break;
15131
15132          case ProtocolIE_ID_id_Cause:
15133             break;
15134
15135          case ProtocolIE_ID_id_ResetType:
15136             {
15137                break;
15138             }
15139
15140          default:
15141             break;
15142       }
15143    }
15144    ret = BuildAndSendF1ResetAck();
15145    DU_LOG("\nINFO   -->  UE release is not supported for now");
15146
15147    freeAperDecodeF1ResetMsg(f1ResetMsg);
15148
15149    return ret;
15150 }
15151
15152 /*******************************************************************
15153  *
15154  * @brief free the RRC delivery report
15155  *
15156  * @details
15157  *
15158  *    Function : freeRrcDeliveryReport
15159  *
15160  *    Functionality: free the RRC delivery report
15161  *
15162  * @params[in]
15163  * @return ROK     - success
15164  *         RFAILED - failure
15165  *
15166  * ****************************************************************/
15167 void freeRrcDeliveryReport(F1AP_PDU_t  *f1apMsg )
15168 {
15169    uint8_t idx=0;
15170    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
15171
15172    if(f1apMsg)
15173    {
15174       if(f1apMsg->choice.initiatingMessage)
15175       {
15176          rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
15177          if(rrcDeliveryReport->protocolIEs.list.array)
15178          {
15179             for(idx =0 ;idx <rrcDeliveryReport->protocolIEs.list.count ;
15180                   idx++)
15181             {
15182                if(rrcDeliveryReport->protocolIEs.list.array[idx])
15183                {
15184                   DU_FREE(rrcDeliveryReport->protocolIEs.list.array[idx],
15185                         sizeof(RRCDeliveryReportIEs_t));
15186                }   
15187             }
15188             DU_FREE(rrcDeliveryReport->protocolIEs.list.array,
15189                   rrcDeliveryReport->protocolIEs.list.size);
15190          }
15191          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
15192       }
15193       DU_FREE(f1apMsg,
15194             sizeof(F1AP_PDU_t));
15195    }
15196 }
15197
15198 /*******************************************************************
15199 *
15200 * @brief Builds and sends the RRC delivery report
15201 *
15202 * @details
15203 *
15204 *    Function : BuildAndSendRrcDeliveryReport
15205 *
15206 *    Functionality: Builds and sends the RRC delivery report
15207 *
15208 * @params[in]
15209 *
15210 * @return ROK     - success
15211 *         RFAILED - failure
15212 *
15213 * ****************************************************************/
15214 uint8_t BuildAndSendRrcDeliveryReport(uint32_t gnbCuUeF1apId, \
15215    uint32_t gnbDuUeF1apId, RrcDeliveryReport *rrcDelivery)
15216 {
15217    uint8_t             ret = RFAILED;
15218    uint8_t             idx    = 0;
15219    uint8_t             idx1   = 0;
15220    uint8_t             elementCnt = 0;
15221    F1AP_PDU_t          *f1apMsg = NULLP;
15222    asn_enc_rval_t      encRetVal;  
15223    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
15224
15225    do{
15226
15227       DU_LOG("\nINFO   -->  F1AP : Building RRC delivery Message Transfer Message\n");
15228       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15229       if(f1apMsg == NULLP)
15230       {
15231          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
15232          break;
15233       }
15234       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
15235       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
15236       if(f1apMsg->choice.initiatingMessage == NULLP)
15237       {
15238          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU  failed");
15239          break;
15240       }
15241       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_RRCDeliveryReport;
15242       f1apMsg->choice.initiatingMessage->criticality   = Criticality_ignore;
15243       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_RRCDeliveryReport;
15244
15245       rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
15246       elementCnt = 4;
15247       rrcDeliveryReport->protocolIEs.list.count = elementCnt;
15248       rrcDeliveryReport->protocolIEs.list.size = elementCnt * sizeof(RRCDeliveryReportIEs_t *);
15249
15250       /* Initialize the F1Setup members */
15251       DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array, rrcDeliveryReport->protocolIEs.list.size);
15252       if(rrcDeliveryReport->protocolIEs.list.array == NULLP)
15253       {
15254          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRC Delivery  failed");
15255          break;
15256       }
15257       for(idx =0 ;idx <elementCnt; idx++)
15258       {
15259          DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array[idx], sizeof(RRCDeliveryReportIEs_t));
15260          if(rrcDeliveryReport->protocolIEs.list.array[idx] == NULLP)
15261          {
15262             break;
15263          }
15264       }
15265
15266       idx1 = 0;
15267
15268       /*GNB CU UE F1AP ID*/
15269       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
15270       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15271       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_CU_UE_F1AP_ID;
15272       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
15273
15274       /*GNB DU UE F1AP ID*/
15275       idx1++;
15276       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
15277       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15278       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_DU_UE_F1AP_ID;
15279       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
15280
15281       /*RRC delivery status*/
15282       idx1++;
15283       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_RRCDeliveryStatus;
15284       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15285       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_RRCDeliveryStatus;
15286       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.delivery_status =\
15287       rrcDelivery->rrcDeliveryStatus.deliveryStatus;
15288       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.triggering_message =\
15289       rrcDelivery->rrcDeliveryStatus.triggeringMessage;
15290
15291       /* SRB ID */ 
15292       idx1++;
15293       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
15294       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15295       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_SRBID;
15296       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.SRBID =  rrcDelivery->srbId;
15297
15298       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15299
15300       /* Encode the RRC DELIVERY REPORT type as APER */
15301       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15302       encBufSize = 0;
15303       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
15304             encBuf);
15305
15306       /* Encode results */
15307       if(encRetVal.encoded == ENCODE_FAIL)
15308       {
15309          DU_LOG("\nERROR  -->  F1AP : Could not encode RRC Delivery Msg structure (at %s)\n",\
15310                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15311          break;
15312       }
15313       else
15314       {
15315          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for RRC Delivery Msg \n");
15316 #ifdef DEBUG_ASN_PRINT
15317          for(idx=0; idx< encBufSize; idx++)
15318          {
15319             printf("%x",encBuf[idx]);
15320          }
15321 #endif
15322       }
15323
15324       /* Sending msg */
15325       if(sendF1APMsg() != ROK)
15326       {
15327          DU_LOG("\nERROR  -->  F1AP : Sending RRC delivery  msg request failed");
15328          break;
15329       }
15330       ret = ROK;
15331       break;
15332
15333    }while(true);
15334
15335    freeRrcDeliveryReport(f1apMsg);
15336    return ret;
15337 }
15338
15339 /*******************************************************************
15340  *
15341  * @brief Processes cells to be activated
15342  *
15343  * @details
15344  *
15345  *    Function : extractCellsToBeActivated
15346  *
15347  *    Functionality:
15348  *      - Processes cells to be activated list received in F1SetupRsp
15349  *
15350  * @params[in] void
15351  * @return ROK     - success
15352  *         RFAILED - failure
15353  *
15354  * ****************************************************************/
15355
15356 uint8_t extractCellsToBeActivated(Cells_to_be_Activated_List_t cellsToActivate)
15357 {
15358    uint8_t  ret = ROK;
15359    uint16_t idx, pci = 0;
15360    uint64_t nci;
15361    Cells_to_be_Activated_List_Item_t cell;
15362
15363    for(idx=0; idx<cellsToActivate.list.count; idx++)
15364    {
15365       nci = 0;
15366       cell = cellsToActivate.list.array[idx]->value.choice.Cells_to_be_Activated_List_Item;
15367       bitStringToInt(&cell.nRCGI.nRCellIdentity, &nci);
15368
15369       if(cell.nRPCI)
15370       {
15371          pci = *cell.nRPCI;
15372       }
15373       ret = duProcCellsToBeActivated(cell.nRCGI.pLMN_Identity.buf, nci, pci);
15374    }
15375    return ret;
15376 }
15377 /******************************************************************
15378 *
15379 * @brief Processes F1 Setup Response allocated by aper_decoder 
15380 *
15381 * @details
15382 *
15383 *    Function : freeF1SetupRsp 
15384 *
15385 *    Functionality: free F1 Setup Response allocated by aper_decoder 
15386 *
15387 * @params[in] F1SetupResponse_t *f1SetRspMsg 
15388 * @return void 
15389 *
15390 * ****************************************************************/
15391
15392 void freeAperDecodeF1SetupRsp(F1SetupResponse_t *f1SetRspMsg)
15393 {
15394    uint8_t ieIdx =0;
15395    uint8_t arrIdx =0;
15396    Cells_to_be_Activated_List_t *cellToActivate =NULLP;
15397    RRC_Version_t      *rrcVer =NULLP;
15398
15399    if(f1SetRspMsg->protocolIEs.list.array)
15400    {
15401       for(ieIdx=0; ieIdx<f1SetRspMsg->protocolIEs.list.count; ieIdx++)
15402       {
15403          if(f1SetRspMsg->protocolIEs.list.array[ieIdx])
15404          {
15405             switch(f1SetRspMsg->protocolIEs.list.array[ieIdx]->id)
15406             {
15407                case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15408                   {
15409                      cellToActivate =
15410                         &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.Cells_to_be_Activated_List;
15411                      if(cellToActivate->list.array)
15412                      {
15413                         for(arrIdx=0; arrIdx<cellToActivate->list.count ; arrIdx++)
15414                         {
15415                            if(cellToActivate->list.array[arrIdx])
15416                            {
15417
15418                               if(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.nRCGI.\
15419                               pLMN_Identity.buf)
15420                               {
15421                                  if(cellToActivate->list.array[0]->value.choice.\
15422                                        Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf)
15423                                  {
15424                                     free(cellToActivate->list.array[0]->value.choice.\
15425                                           Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf);
15426                                  }
15427
15428                                  free(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
15429                                        nRCGI.pLMN_Identity.buf);
15430                               }
15431                               free(cellToActivate->list.array[arrIdx]);
15432                            }
15433                         }
15434                         free(cellToActivate->list.array);
15435                      }
15436                      break;
15437                   }
15438                case ProtocolIE_ID_id_TransactionID:
15439                   {
15440                      break;
15441                   }
15442                case ProtocolIE_ID_id_gNB_CU_Name:
15443                   {
15444                      free(f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_Name.buf);
15445                      break;
15446                   }
15447                case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15448                   {
15449                      rrcVer = &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
15450                      if(rrcVer->latest_RRC_Version.buf)
15451                      {
15452                         if(rrcVer->iE_Extensions)
15453                         {
15454                            if(rrcVer->iE_Extensions->list.array)
15455                            {
15456                               if(rrcVer->iE_Extensions->list.array[0])
15457                               {
15458                                  if(rrcVer->iE_Extensions->list.\
15459                                        array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf)
15460                                  {
15461                                     free(rrcVer->iE_Extensions->list.\
15462                                           array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf);
15463                                  }
15464                                  free(rrcVer->iE_Extensions->list.array[0]);
15465                               }
15466                               free(rrcVer->iE_Extensions->list.array);
15467                            }
15468                            free(rrcVer->iE_Extensions);
15469                         }
15470                         free(rrcVer->latest_RRC_Version.buf);
15471                      }
15472                      break;
15473
15474                   }
15475                default:
15476                   {
15477                      DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15478                            f1SetRspMsg->protocolIEs.list.array[ieIdx]->id);
15479                   }
15480             }
15481             free(f1SetRspMsg->protocolIEs.list.array[ieIdx]);
15482          }
15483       }
15484       free(f1SetRspMsg->protocolIEs.list.array);
15485    }
15486 }
15487 /******************************************************************
15488  *
15489  * @brief Processes F1 Setup Response sent by CU
15490  *
15491  * @details
15492  *
15493  *    Function : procF1SetupRsp
15494  *
15495  *    Functionality: Processes F1 Setup Response sent by CU
15496  *
15497  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15498  * @return ROK     - success
15499  *         RFAILED - failure
15500  *
15501  * ****************************************************************/
15502 uint8_t procF1SetupRsp(F1AP_PDU_t *f1apMsg, MsgLen recvBufLen, char *recvBuf)
15503 {
15504    uint8_t ret = ROK;
15505    uint16_t idx =0;
15506    F1SetupResponse_t *f1SetRspMsg = NULLP;
15507    GNB_CU_Name_t     *cuName = NULLP;
15508    F1SetupRsp  f1SetRspDb;
15509    RRC_Version_t      *rrcVer =NULLP;
15510    
15511    memset(&f1SetRspDb, 0, sizeof(F1SetupRsp));
15512
15513    DU_LOG("\nINFO   -->  F1AP : F1 Setup Response received");
15514    f1SetRspMsg = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
15515
15516    for(idx=0; idx<f1SetRspMsg->protocolIEs.list.count; idx++)
15517    {
15518       switch(f1SetRspMsg->protocolIEs.list.array[idx]->id)
15519       {
15520          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15521             {
15522                extractCellsToBeActivated(f1SetRspMsg->protocolIEs.list.array[idx]->\
15523                      value.choice.Cells_to_be_Activated_List);
15524                break;
15525             }
15526          case ProtocolIE_ID_id_TransactionID:
15527             {
15528                f1SetRspDb.transId = f1SetRspMsg->protocolIEs.list.array[idx]->\
15529                                     value.choice.TransactionID;
15530                break;
15531             }
15532          case ProtocolIE_ID_id_gNB_CU_Name:
15533             {
15534                cuName = &f1SetRspMsg->protocolIEs.list.array[idx]->\
15535                         value.choice.GNB_CU_Name;
15536                strcpy(f1SetRspDb.cuName, (const char*)cuName->buf);
15537                break;
15538             }
15539          case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15540             {
15541                rrcVer = &f1SetRspMsg->protocolIEs.list.array[idx]->value.choice.RRC_Version;
15542                strcpy(f1SetRspDb.rrcVersion.rrcVer,
15543                      (const char*)rrcVer->latest_RRC_Version.buf);
15544                break;
15545             }
15546          default:
15547             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15548                   f1SetRspMsg->protocolIEs.list.array[idx]->id);
15549       }
15550    }
15551    
15552    duProcF1SetupRsp();
15553    freeAperDecodeF1SetupRsp(f1SetRspMsg);
15554    
15555    if(addOrModifyE2NodeComponent(F1, E2_NODE_COMPONENT_ADD, false, recvBufLen, recvBuf) !=ROK)
15556    {
15557       DU_LOG("\nERROR  -->  F1AP : Failed to add the e2 node in the list");
15558       return RFAILED;
15559    }
15560
15561    if(BuildAndSendE2SetupReq() != ROK)
15562    {
15563       DU_LOG("\nERROR  -->  F1AP : Failed to build and send E2 setup request ");
15564       return RFAILED;
15565    }
15566    return ret;
15567 }
15568 /*******************************************************************
15569 *
15570 * @brief free GNB DU config update ack
15571 *
15572 * @details
15573 *
15574 *    Function : freeAperDecodeGnbDuAck 
15575 *
15576 *    Functionality: Processes GNB DU config update ack And
15577 *                     added free part for the memory allocated by aper_decoder
15578 *
15579 * @params[in] F1AP_PDU_t ASN decoded F1AP message
15580 * @return ROK     - success
15581 *         RFAILED - failure
15582 *
15583 * ****************************************************************/
15584
15585 void freeAperDecodeGnbDuAck(GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck)
15586 {
15587    uint8_t ieIdx = 0;
15588
15589    if(gnbDuAck->protocolIEs.list.array)
15590    {
15591       for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15592       {
15593          if(gnbDuAck->protocolIEs.list.array[ieIdx])
15594          {
15595             free(gnbDuAck->protocolIEs.list.array[ieIdx]);
15596          }
15597       }
15598       free(gnbDuAck->protocolIEs.list.array);
15599    }
15600 }
15601
15602 /*******************************************************************
15603 *
15604 * @brief Building  result of gnb-du config update ack output
15605 *
15606 * @details
15607 *
15608 *    Function : duProcGnbDuCfgUpdAckMsg 
15609 *
15610 *    Functionality: 
15611 *        Building output of gnb-du config update ack 
15612 *
15613 * @params[in] transId
15614 * @return void
15615 *
15616 * ****************************************************************/
15617
15618 uint8_t duProcGnbDuCfgUpdAckMsg(uint8_t transId)
15619 {
15620    uint8_t  ieIdx=0, arrIdx=0,ret=ROK;
15621    uint8_t  ueId =0 , ueIdx =0, totalActiveUe = 0;
15622    uint16_t cellIdx =0, crnti=0;
15623    uint64_t cellId =0;
15624    CmLList *f1apPduNode = NULLP;
15625    ReservedF1apPduInfo *f1apPduInfo =NULLP;
15626    F1AP_PDU_t *f1apMsgPdu = NULLP;
15627    GNBDUConfigurationUpdate_t *gnbDuConfigUpdate = NULLP;
15628    BIT_STRING_t *cellIdentity=NULLP;
15629    struct Served_Cells_To_Delete_ItemIEs *deleteItemIe=NULLP;
15630    Served_Cells_To_Delete_List_t *cellsToDelete=NULLP;
15631    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
15632
15633    DU_LOG("\nINFO   -->  DU APP: GNB-DU config update Ack received ");
15634    f1apPduNode = searchFromReservedF1apPduList(transId);
15635    f1apPduInfo = (ReservedF1apPduInfo *)f1apPduNode->node;
15636    f1apMsgPdu = (F1AP_PDU_t *)f1apPduInfo->f1apMsg;
15637
15638    if(f1apMsgPdu)
15639    {
15640       if(f1apMsgPdu->choice.initiatingMessage)
15641       {
15642          gnbDuConfigUpdate = &f1apMsgPdu->choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
15643          for(ieIdx=0; ieIdx < gnbDuConfigUpdate->protocolIEs.list.count; ieIdx++)
15644          {
15645             switch(gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->id)
15646             {
15647                case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
15648                   {
15649                      cellsToDelete = &gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
15650                                      Served_Cells_To_Delete_List;
15651                      if(cellsToDelete->list.array)
15652                      {
15653                         if(cellsToDelete->list.array[arrIdx])
15654                         {
15655                            deleteItemIe = (Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx];
15656                            deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
15657                            if(deleteItem->oldNRCGI.nRCellIdentity.buf)
15658                            {
15659                               cellIdentity = &deleteItem->oldNRCGI.nRCellIdentity;
15660                               bitStringToInt(cellIdentity, &cellId);
15661
15662                               GET_CELL_IDX(cellId, cellIdx);
15663                               if(duCb.actvCellLst[cellIdx] != NULLP)
15664                               {
15665                                  duCb.actvCellLst[cellId-1]->cellStatus = DELETION_IN_PROGRESS;
15666                               }
15667                            }
15668                         }
15669                      }
15670
15671                      if(duCb.actvCellLst[cellIdx] != NULLP)
15672                      {
15673                         if(duCb.actvCellLst[cellIdx]->numActvUes == 0)
15674                         {
15675                            ret = duSendCellDeletReq(cellId);
15676                            if(ret == RFAILED)
15677                            {
15678                               DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to send cell delete\
15679                               request for cellId[%lu]", cellId);
15680                            }
15681                         }
15682                         else
15683                         {
15684                            totalActiveUe = duCb.actvCellLst[cellIdx]->numActvUes;
15685                            while(totalActiveUe)
15686                            {
15687                               if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState != UE_ACTIVE)
15688                               {
15689                                  ueIdx++;
15690                                  continue;
15691                               }
15692
15693                               crnti = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti;
15694                               GET_UE_ID(crnti,ueId);
15695                               /* Sending Ue Context release request only for maximum supporting UEs */
15696                               ret = BuildAndSendUeContextReleaseReq(cellId, ueId);
15697                               if(ret == RFAILED)
15698                               {
15699                                  DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to build and send UE delete\
15700                                  request for cellId[%lu]", cellId);
15701                               }
15702                               ueIdx++;
15703                               totalActiveUe--;
15704                            }
15705                         }
15706                      }
15707                      else
15708                      {
15709                         DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): CellId [%lu] not found", cellId);
15710                         ret = RFAILED;
15711                      }
15712                      break;
15713                   }
15714
15715                default:
15716                   break;
15717             }
15718          }
15719       }
15720    }
15721    
15722    FreeDUConfigUpdate(f1apMsgPdu);
15723    deleteFromReservedF1apPduList(f1apPduNode);
15724    return ret;
15725 }
15726
15727 /*******************************************************************
15728 *
15729 * @brief Processes GNB DU config update ack
15730 *
15731 * @details
15732 *
15733 *    Function : procF1GNBDUCfgUpdAck
15734 *
15735 *    Functionality: added free part for the memory allocated by aper_decoder
15736 *
15737 * @params[in] F1AP_PDU_t *f1apMsg,  MsgLen recvBufLen, char *recvBuf 
15738 * @return void 
15739 *
15740 * ****************************************************************/
15741
15742 uint8_t procF1GNBDUCfgUpdAck(F1AP_PDU_t *f1apMsg, MsgLen recvBufLen, char *recvBuf)
15743 {
15744    uint8_t ieIdx=0,transId=0;
15745    GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck = NULLP;
15746
15747    DU_LOG("\nINFO   -->  F1AP : GNB-DU config update acknowledgment");
15748    gnbDuAck = &f1apMsg->choice.successfulOutcome->value.choice.GNBDUConfigurationUpdateAcknowledge;
15749
15750    for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15751    {
15752       switch(gnbDuAck->protocolIEs.list.array[ieIdx]->id)
15753       {
15754          case ProtocolIE_ID_id_TransactionID:
15755             {
15756                transId = gnbDuAck->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
15757                break;
15758             }
15759          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15760             {
15761                break;
15762             }
15763          default :
15764             {
15765                DU_LOG("\nERROR  -->  F1AP: procF1GNBDUCfgUpdAck(): Invalid IE Received: %ld", \
15766                      gnbDuAck->protocolIEs.list.array[ieIdx]->id);
15767                break;
15768             }
15769       }
15770    }
15771    
15772    duProcGnbDuCfgUpdAckMsg(transId);
15773     
15774 #if 0
15775    /* presently we are not supporting F1 Reset from DU to CU , we are only
15776     * supporting F1 Reset from CU to DU */
15777
15778    if(BuildAndSendF1ResetReq() != ROK)
15779    {
15780       return RFAILED;
15781    }
15782 #endif
15783
15784    if(addOrModifyE2NodeComponent(F1, E2_NODE_COMPONENT_UPDATE, false, recvBufLen, recvBuf) !=ROK)
15785    {
15786       DU_LOG("\nERROR  -->  F1AP : Failed to update the e2 node in the list");
15787       return RFAILED;
15788    }
15789
15790    freeAperDecodeGnbDuAck(gnbDuAck);
15791    return ROK;
15792 }
15793 /******************************************************************
15794 *
15795 * @brief free DL RRC Message Transfer allocated by aper_decoder 
15796 *
15797 * @details
15798 *
15799 *    Function : freeAperDecodef1DlRrcMsg 
15800 *
15801 *    Functionality: free DL RRC Message Transfer allocated by aper_decoder 
15802 *
15803 * @params[in] DLRRCMessageTransfer_t *f1DlRrcMsg 
15804 * @return ROK     - success
15805 *         RFAILED - failure
15806 *
15807 * ****************************************************************/
15808
15809 void freeAperDecodef1DlRrcMsg(DLRRCMessageTransfer_t *f1DlRrcMsg)
15810 {
15811    uint8_t ieIdx =0;
15812    RRCContainer_t *rrcContainer = NULLP;
15813
15814    if(f1DlRrcMsg->protocolIEs.list.array)
15815    {
15816       for(ieIdx=0; ieIdx<f1DlRrcMsg->protocolIEs.list.count; ieIdx++)
15817       {
15818          if(f1DlRrcMsg->protocolIEs.list.array[ieIdx])
15819          {
15820             switch(f1DlRrcMsg->protocolIEs.list.array[ieIdx]->id)
15821             {
15822                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15823                   break;
15824                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15825                   break;
15826                case ProtocolIE_ID_id_SRBID:
15827                   break;
15828                case ProtocolIE_ID_id_RRCContainer:
15829                   {
15830                      rrcContainer =&f1DlRrcMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer;
15831                      free(rrcContainer->buf);
15832                   }
15833                case ProtocolIE_ID_id_ExecuteDuplication:
15834                   break;
15835                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15836                   break;
15837                   break;
15838             }
15839             free(f1DlRrcMsg->protocolIEs.list.array[ieIdx]);
15840          }
15841       }
15842       free(f1DlRrcMsg->protocolIEs.list.array);
15843    }
15844 }
15845 /******************************************************************
15846  *
15847  * @brief Processes DL RRC Message Transfer  sent by CU
15848  *
15849  * @details
15850  *
15851  *    Function : procF1DlRrcMsgTrans
15852  *
15853  *    Functionality: Processes DL RRC Message Transfer sent by CU
15854  *
15855  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15856  * @return ROK     - success
15857  *         RFAILED - failure
15858  *
15859  * ****************************************************************/
15860 uint8_t procF1DlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
15861 {
15862    uint8_t  idx, ret;
15863    DLRRCMessageTransfer_t *f1DlRrcMsg = NULLP;
15864    F1DlRrcMsg dlMsg;
15865    memset(&dlMsg, 0, sizeof(F1DlRrcMsg));
15866
15867    DU_LOG("\nINFO   -->  DU_APP : DL RRC message transfer Recevied");
15868    f1DlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
15869
15870    ret = ROK;
15871
15872    for(idx=0; idx<f1DlRrcMsg->protocolIEs.list.count; idx++)
15873    {
15874       switch(f1DlRrcMsg->protocolIEs.list.array[idx]->id)
15875       {
15876          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15877             {
15878                dlMsg.gnbCuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
15879                break;
15880             }
15881          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15882             {
15883                dlMsg.gnbDuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
15884                break;
15885             }
15886          case ProtocolIE_ID_id_SRBID:
15887             {
15888                dlMsg.srbId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
15889                break;
15890             }
15891          case ProtocolIE_ID_id_ExecuteDuplication:
15892             dlMsg.execDup = true;
15893             break;
15894
15895          case ProtocolIE_ID_id_RRCContainer:
15896             {
15897                if(f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
15898                {
15899              dlMsg.rrcMsgSize = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
15900              DU_ALLOC_SHRABL_BUF(dlMsg.rrcMsgPdu, dlMsg.rrcMsgSize);
15901              if(dlMsg.rrcMsgPdu)
15902              {
15903                 memcpy(dlMsg.rrcMsgPdu, f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf,\
15904                       dlMsg.rrcMsgSize);
15905              }
15906              else
15907              {
15908                 DU_LOG("\nERROR  -->  DU APP : Memory alloc Failed at RRC Container at procF1DlRrcMsgTrans()");
15909                 return RFAILED;
15910              }
15911           }
15912           else
15913           {
15914              DU_LOG("\nERROR  -->  DU_APP : RRC Container Size is invalid:%ld",\
15915                    f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
15916              return RFAILED;
15917           }
15918           break;
15919        }
15920     case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15921        {
15922           dlMsg.deliveryStatRpt = true;
15923           break;
15924        }
15925     default:
15926        DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
15927              f1DlRrcMsg->protocolIEs.list.array[idx]->id);
15928       }
15929    }
15930
15931    ret = duProcDlRrcMsg(&dlMsg);
15932
15933    freeAperDecodef1DlRrcMsg(f1DlRrcMsg);
15934    return ret;
15935 }
15936 /*******************************************************************
15937  *
15938 * @brief Builds the DRB to be Setup Mod list
15939 *
15940 * @details
15941 *
15942 *    Function : 
15943 *
15944 *    Functionality: Constructs the DRB to be Setup Mod list
15945 *
15946 * @params[in] DRBs_SetupMod_List_t *drbSet
15947 *
15948 * @return ROK     - success
15949 *         RFAILED - failure
15950 *
15951 * ****************************************************************/
15952 uint8_t BuildSrbSetupModList(SRBs_SetupMod_List_t *srbList, DuUeCfg *ueCfg)
15953 {
15954    uint8_t srbIdx = 0;
15955    struct SRBs_SetupMod_ItemIEs *srbItemIe;
15956
15957    srbList->list.count = ueCfg->numRlcLcs;
15958    srbList->list.size = srbList->list.count * sizeof(SRBs_SetupMod_ItemIEs_t *);
15959
15960    DU_ALLOC(srbList->list.array, srbList->list.size);
15961    if(srbList->list.array == NULLP)
15962    {
15963       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15964       return RFAILED;
15965    }
15966
15967    for(srbIdx = 0; srbIdx < srbList->list.count; srbIdx++)
15968    {
15969       DU_ALLOC(srbList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15970       if(srbList->list.array[srbIdx] == NULLP)
15971       {
15972          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15973          return RFAILED;
15974       }
15975    } 
15976
15977    for(srbIdx=0; srbIdx < srbList->list.count; srbIdx++)
15978    {
15979       srbItemIe = (struct SRBs_SetupMod_ItemIEs *)srbList->list.array[srbIdx];
15980       srbItemIe->id = ProtocolIE_ID_id_SRBs_SetupMod_Item;
15981       srbItemIe->criticality = Criticality_reject;
15982       srbItemIe->value.present = SRBs_SetupMod_ItemIEs__value_PR_SRBs_SetupMod_Item;
15983       srbItemIe->value.choice.SRBs_SetupMod_Item.sRBID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.rbId;
15984       srbItemIe->value.choice.SRBs_SetupMod_Item.lCID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.lcId;
15985    }
15986    return ROK;
15987 }
15988
15989 /*******************************************************************
15990  *
15991 * @brief Builds the DRB to be Setup Mod list
15992 *
15993 * @details
15994 *
15995 *    Function : 
15996 *
15997 *    Functionality: Constructs the DRB to be Setup Mod list
15998 *
15999 * @params[in] DRBs_SetupMod_List_t *drbSet
16000 *
16001 * @return ROK     - success
16002 *         RFAILED - failure
16003 *
16004 * ****************************************************************/
16005
16006 uint8_t BuildDrbSetupModList(DRBs_SetupMod_List_t *drbSet , DuUeCfg *ueCfg)
16007 {
16008    uint8_t arrIdx =0;
16009    uint8_t drbCnt =0;
16010    struct DRBs_SetupMod_ItemIEs *drbItemIe;
16011
16012    drbCnt = ueCfg->numDrbSetupMod;
16013
16014    drbSet->list.count = drbCnt;
16015    drbSet->list.size = drbCnt * sizeof(DRBs_SetupMod_ItemIEs_t *);
16016    DU_ALLOC(drbSet->list.array, drbSet->list.size);
16017    if(drbSet->list.array == NULLP)
16018    {
16019       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
16020       return  RFAILED;
16021    }
16022    for(arrIdx=0; arrIdx<drbCnt; arrIdx++)
16023    {
16024       DU_ALLOC(drbSet->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
16025       if(drbSet->list.array[arrIdx] == NULLP)
16026       {
16027               DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
16028               return  RFAILED;
16029       }
16030
16031       drbItemIe = (struct DRBs_SetupMod_ItemIEs *)drbSet->list.array[arrIdx];
16032       drbItemIe->id = ProtocolIE_ID_id_DRBs_SetupMod_Item;
16033       drbItemIe->criticality = Criticality_reject;
16034       drbItemIe->value.present = DRBs_SetupMod_ItemIEs__value_PR_DRBs_SetupMod_Item;
16035       drbItemIe->value.choice.DRBs_SetupMod_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
16036       if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List,\
16037       &ueCfg->upTnlInfo[arrIdx])!= ROK)
16038       {
16039          DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbToBeSetupModList");
16040          return RFAILED;
16041       }
16042       
16043    }
16044
16045    return ROK;
16046 }
16047 /*******************************************************************
16048 * @brief Free the memory allocated for DRB setup List
16049 *
16050 * @details
16051 *
16052 *    Function : FreeDrbSetupModList 
16053 *
16054 *    Functionality:
16055 *       Free the memory allocated for DRB setup list
16056 *
16057 * @params[in] DRBs_Setup_List_t *
16058 * @return void
16059 *
16060 * ****************************************************************/
16061 void FreeDrbSetupModList(DRBs_SetupMod_List_t *drbSetupList)
16062 {
16063    uint8_t arrIdx = 0;
16064    DRBs_SetupMod_ItemIEs_t *drbItemIe = NULLP;
16065
16066    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
16067    {
16068       drbItemIe = ((DRBs_SetupMod_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
16069       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List);
16070       DU_FREE(drbSetupList->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
16071    }
16072    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
16073 }
16074
16075 /*******************************************************************
16076 *
16077 * @brief Builds the DRB to be Mod list
16078 *
16079 * @details
16080 *
16081 *    Function : 
16082 *
16083 *    Functionality: Constructs the DRB to be Mod list
16084 *
16085 * @params[in] DRBs_Modified_List_t *drbModList
16086 *
16087 * @return ROK     - success
16088 *         RFAILED - failure
16089 *
16090 * ****************************************************************/
16091
16092 uint8_t BuildDrbModList(DRBs_Modified_List_t *drbModList, DuUeCfg *ueCfg)
16093 {
16094    uint8_t arrIdx =0, drbIdx = 0;
16095    uint8_t drbCnt =0;
16096    struct DRBs_Modified_ItemIEs *drbItemIe;
16097
16098    drbCnt = ueCfg->numDrbModified;
16099
16100    drbModList->list.count = drbCnt;
16101    drbModList->list.size = drbCnt * sizeof(DRBs_Modified_ItemIEs_t *);
16102    DU_ALLOC(drbModList->list.array, drbModList->list.size);
16103    if(drbModList->list.array == NULLP)
16104    {
16105       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList()");
16106       return  RFAILED;
16107    }
16108
16109    drbIdx = 0;
16110    for(arrIdx = 0; arrIdx < ueCfg->numMacLcs; arrIdx++)
16111    {
16112       if(ueCfg->macLcCfg[arrIdx].configType == CONFIG_MOD)
16113       {
16114          DU_ALLOC(drbModList->list.array[drbIdx], sizeof(DRBs_Modified_ItemIEs_t));
16115          if(drbModList->list.array[drbIdx] == NULLP)
16116          {
16117             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList");
16118             return  RFAILED;
16119          }
16120
16121          drbItemIe = (struct DRBs_Modified_ItemIEs *)drbModList->list.array[drbIdx];
16122          drbItemIe->id = ProtocolIE_ID_id_DRBs_Modified_Item;
16123          drbItemIe->criticality = Criticality_reject;
16124          drbItemIe->value.present = DRBs_Modified_ItemIEs__value_PR_DRBs_Modified_Item;
16125          drbItemIe->value.choice.DRBs_Modified_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
16126          if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List,\
16127                   &ueCfg->upTnlInfo[arrIdx])!= ROK)
16128          {
16129             DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbModList");
16130             return RFAILED;
16131          }
16132          drbIdx++;
16133       } 
16134    }
16135
16136    return ROK;
16137 }
16138
16139 /*******************************************************************
16140 * @brief Free the memory allocated for DRB Mod List
16141 *
16142 * @details
16143 *
16144 *    Function : FreeDrbModList 
16145 *
16146 *    Functionality:
16147 *       Free the memory allocated for DRB modified list
16148 *
16149 * @params[in] DRBs_Modified_List_t *
16150 * @return void
16151 *
16152 * ****************************************************************/
16153 void FreeDrbModList(DRBs_Modified_List_t *drbModList)
16154 {
16155    uint8_t arrIdx = 0;
16156    DRBs_Modified_ItemIEs_t *drbItemIe = NULLP;
16157
16158    for(arrIdx = 0; arrIdx < drbModList->list.count; arrIdx++)
16159    {
16160       drbItemIe = ((DRBs_Modified_ItemIEs_t *)drbModList->list.array[arrIdx]);
16161       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List);
16162       DU_FREE(drbModList->list.array[arrIdx], sizeof(DRBs_Modified_ItemIEs_t));
16163    }
16164    DU_FREE(drbModList->list.array, drbModList->list.size);
16165 }
16166
16167 /*******************************************************************
16168 * @brief Free the memory allocated for SRB setup List
16169 *
16170 * @details
16171 *
16172 *    Function : FreeSrbSetupModList 
16173 *
16174 *    Functionality:
16175 *       Free the memory allocated for SRB setup list
16176 *
16177 * @params[in] SRBs_Setup_List_t *
16178 * @return void
16179 *
16180 * ****************************************************************/
16181 void FreeSrbSetupModList(SRBs_SetupMod_List_t *srbSetupList)
16182 {
16183    uint8_t srbIdx = 0;
16184    
16185    for(srbIdx = 0; srbIdx < srbSetupList->list.count; srbIdx++)
16186       DU_FREE(srbSetupList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
16187    DU_FREE(srbSetupList->list.array, srbSetupList->list.size);
16188 }
16189
16190 /*******************************************************************
16191 * @brief Free the memory allocated for UE Context Mod Response
16192 *
16193 * @details
16194 *
16195 *    Function : FreeUeContextModResp 
16196 *
16197 *    Functionality:
16198 *       Free the memory allocated for UE Context Mod Response
16199 *
16200 * @params[in] F1AP_PDU_t *f1apMsg
16201 * @return void
16202 *
16203 * ****************************************************************/
16204
16205 void FreeUeContextModResp(F1AP_PDU_t *f1apMsg)
16206 {
16207    uint8_t ieIdx;
16208    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
16209    if(f1apMsg)
16210    {
16211       if(f1apMsg->choice.successfulOutcome)
16212       {
16213          ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
16214          if(ueContextModifyRes->protocolIEs.list.array)
16215          {
16216             for(ieIdx=0 ; ieIdx<ueContextModifyRes->protocolIEs.list.count; ieIdx++)
16217             {
16218                if(ueContextModifyRes->protocolIEs.list.array[ieIdx])
16219                {
16220                   switch(ueContextModifyRes->protocolIEs.list.array[ieIdx]->id)
16221                   {
16222                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16223                         break;
16224                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16225                         break;
16226                      case ProtocolIE_ID_id_DUtoCURRCInformation:
16227                         {
16228                            DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.\
16229                               cellGroupConfig.buf, ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
16230                               DUtoCURRCInformation.cellGroupConfig.size);
16231                            break;
16232                         }
16233                      case ProtocolIE_ID_id_DRBs_SetupMod_List:
16234                         {
16235                             FreeDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16236                             value.choice.DRBs_SetupMod_List));
16237                             break;
16238                         }
16239                      case ProtocolIE_ID_id_DRBs_Modified_List:
16240                         {
16241                             FreeDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16242                             value.choice.DRBs_Modified_List));
16243                             break;
16244                         }
16245                      case ProtocolIE_ID_id_SRBs_SetupMod_List:
16246                         {
16247                            FreeSrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
16248                               SRBs_SetupMod_List));
16249                            break; 
16250                         }
16251                   }
16252                   DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
16253                }
16254
16255             }
16256             DU_FREE(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
16257          }
16258          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16259       }
16260       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
16261    }
16262 }
16263
16264 /*****************************************************************i
16265 *
16266 * @brief Creating the ue context modifcation response and sending
16267 *
16268 * @details
16269 *
16270 *    Function : BuildAndSendUeContextModRsp 
16271 *
16272 *    Functionality:
16273 *         - Creating the ue context modifcation response 
16274 *
16275 * @params[in] uint8_t cellId,uint8_t ueId
16276 * @return ROK     - success
16277 *         RFAILED - failure
16278 *
16279 * ****************************************************************/
16280 uint8_t BuildAndSendUeContextModRsp(DuUeCb *ueCb)
16281 {
16282    uint8_t   ieIdx = 0, tnlIdx = 0, rbIdx = 0;
16283    uint8_t   elementCnt = 0;
16284    uint8_t   ret = RFAILED;
16285    F1AP_PDU_t *f1apMsg = NULLP;
16286    asn_enc_rval_t  encRetVal;
16287    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
16288
16289    DU_LOG("\nINFO  -->  F1AP : Building UE context modification response\n");
16290
16291    while(true)
16292    {
16293       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
16294       if(f1apMsg == NULLP)
16295       {
16296          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16297          break;
16298       }
16299
16300       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
16301
16302       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16303       if(f1apMsg->choice.successfulOutcome == NULLP)
16304       {
16305          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16306          break;
16307       }
16308       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextModification;
16309       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
16310       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_UEContextModificationResponse;
16311
16312       ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
16313   
16314       if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
16315       {
16316          elementCnt = 2;
16317          if(ueCb->f1UeDb->duUeCfg.numDrbSetupMod)
16318             elementCnt++;
16319          if(ueCb->f1UeDb->duUeCfg.numDrbModified)
16320             elementCnt++; 
16321       }
16322       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16323       {
16324          elementCnt = 5;
16325       }
16326       if(ueCb->f1UeDb->actionType == UE_CTXT_RRC_RECFG_COMPLETE)
16327          elementCnt = 2;
16328       ueContextModifyRes->protocolIEs.list.count = elementCnt;
16329       ueContextModifyRes->protocolIEs.list.size = elementCnt*sizeof(UEContextModificationResponse_t*);
16330
16331       /* Initialize the UE context modification members */
16332       DU_ALLOC(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
16333       if(ueContextModifyRes->protocolIEs.list.array == NULLP)
16334       {
16335          DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16336          break;
16337       }
16338
16339       for(ieIdx=0 ; ieIdx<elementCnt; ieIdx++)
16340       {
16341          DU_ALLOC(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
16342          if(ueContextModifyRes->protocolIEs.list.array[ieIdx] == NULLP)
16343          {
16344             DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16345             break;
16346          }
16347       }
16348
16349       ieIdx=0;
16350       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
16351       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16352       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16353       UEContextModificationResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
16354       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
16355
16356       ieIdx++;
16357       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16358       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16359       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present=\
16360       UEContextModificationResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
16361       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
16362
16363       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16364       {
16365          ieIdx++;
16366          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCInformation;
16367          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16368          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16369          UEContextModificationResponseIEs__value_PR_DUtoCURRCInformation;
16370          BuildCellGroupConfigRrc(ueCb, &ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
16371       }
16372
16373       if((ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY) || \
16374            ((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbSetupMod)))
16375       { 
16376          ieIdx++;
16377          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_SetupMod_List;
16378          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16379          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16380                                                                            UEContextModificationResponseIEs__value_PR_DRBs_SetupMod_List;
16381          if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16382          {
16383             for(tnlIdx = 0; tnlIdx < duCb.numTeId; tnlIdx++)
16384             {
16385                if(duCb.upTnlCfg[tnlIdx]->ueId == ueCb->gnbDuUeF1apId)
16386                {
16387                   memcpy(&ueCb->f1UeDb->duUeCfg.upTnlInfo[ueCb->f1UeDb->duUeCfg.numDrbSetupMod++], duCb.upTnlCfg[tnlIdx], sizeof(UpTnlCfg));
16388                }
16389             }
16390          }
16391          ret = BuildDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16392                   value.choice.DRBs_SetupMod_List) , &ueCb->f1UeDb->duUeCfg);
16393          if(ret != ROK)
16394          {
16395             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB setupmod List ");
16396             break;
16397          }
16398       }
16399
16400       if((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbModified))
16401       { 
16402          ieIdx++;
16403          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_Modified_List;
16404          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16405          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16406                                                                     UEContextModificationResponseIEs__value_PR_DRBs_Modified_List;
16407          ret = BuildDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16408                                  value.choice.DRBs_Modified_List) , &ueCb->f1UeDb->duUeCfg);
16409          if(ret != ROK)
16410          {
16411             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB Modified List ");
16412             break;
16413          }
16414       }
16415
16416       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16417       {
16418          ieIdx++;
16419          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_SRBs_SetupMod_List;
16420          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16421          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16422                                                                             UEContextModificationResponseIEs__value_PR_SRBs_SetupMod_List;
16423          for(rbIdx = 0; rbIdx < ueCb->duRlcUeCfg.numLcs; rbIdx++)
16424          {
16425             if(ueCb->duRlcUeCfg.rlcLcCfg[rbIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
16426             {
16427                memcpy(&ueCb->f1UeDb->duUeCfg.rlcLcCfg[ueCb->f1UeDb->duUeCfg.numRlcLcs++], &ueCb->duRlcUeCfg.rlcLcCfg[rbIdx],\
16428                      sizeof(DuRlcBearerCfg));
16429             }
16430          }
16431          ret = BuildSrbSetupModList(&ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.SRBs_SetupMod_List, \
16432                &ueCb->f1UeDb->duUeCfg);
16433          if(ret != ROK)
16434          {
16435             DU_LOG( "\nERROR  -->  F1AP : Failed to build SRB setupmod List ");
16436             break;
16437          }
16438       }
16439
16440       freeF1UeDb(ueCb->f1UeDb);
16441       ueCb->f1UeDb = NULLP;
16442
16443       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16444
16445       /* Encode the F1SetupRequest type as APER */
16446       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16447       encBufSize = 0;
16448       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,encBuf);
16449
16450       /* Encode results */
16451       if(encRetVal.encoded == ENCODE_FAIL)
16452       {
16453          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Modification Response structure (at %s)\n",\
16454                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16455          ret = RFAILED;
16456          break;
16457       }
16458       else
16459       {
16460          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Modification Response\n");
16461 #ifdef DEBUG_ASN_PRINT
16462          for(int i=0; i< encBufSize; i++)
16463          {
16464             printf("%x",encBuf[i]);
16465          }
16466 #endif
16467       }
16468
16469       /* Sending  msg  */
16470       if(sendF1APMsg() != ROK && (ret == ROK))
16471       {
16472          DU_LOG("\nERROR  -->  F1AP : Sending UE Modification Res Failed");
16473          ret = RFAILED;
16474          break;
16475       }
16476
16477       ret = ROK;
16478       break;
16479    }
16480
16481    FreeUeContextModResp(f1apMsg);
16482    return ret;
16483 }
16484
16485 /*******************************************************************
16486  *
16487  * @brief Deallocating the memory allocated by the aper decoder
16488  *          for QOSInfo
16489  *
16490  * @details
16491  *
16492  *    Function : freeAperDecodeQosInfo
16493  *
16494  *    Functionality:  Deallocating the memory allocated for QOSInfo
16495  *
16496  * @params[in] QoSFlowLevelQoSParameters_t *drbQos
16497  *
16498  * @return void
16499  *
16500  * ****************************************************************/
16501
16502 void freeAperDecodeQosInfo(QoSFlowLevelQoSParameters_t *drbQos)
16503 {
16504    if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI != NULLP)
16505    {
16506       if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
16507       {
16508          if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
16509          {
16510             free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
16511          }
16512          free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
16513       }
16514       free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI);
16515    }
16516 }
16517 /*******************************************************************
16518  *
16519  * @brief Deallocating the memory allocated by the aper decoder
16520  *          for UlTnlInfoforDrb
16521  *
16522  * @details
16523  *
16524  *    Function : freeAperDecodeUlTnlInfoforDrbSetupMod 
16525  *
16526  *    Functionality:  Deallocating memory allocated for UlTnlInfoforDrb
16527  *
16528  * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
16529  *
16530  * @return void
16531  *
16532  * ****************************************************************/
16533 void freeAperDecodeUlTnlInfoforDrbSetupMod(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
16534 {
16535    uint8_t arrIdx =0;
16536
16537    if(ulInfo->list.array)
16538    {
16539       for(arrIdx=0; arrIdx<ulInfo->list.count ; arrIdx++)
16540       {
16541          if(ulInfo->list.array[arrIdx])
16542          {
16543             if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel )
16544             {
16545                if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf)
16546                {
16547                   if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf)
16548                   {
16549                      free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16550                            gTP_TEID.buf);
16551                   }
16552                   free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16553                         transportLayerAddress.buf);
16554                }
16555                free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel);
16556             }
16557             free(ulInfo->list.array[arrIdx]);
16558          }
16559       }
16560       free(ulInfo->list.array);
16561    }
16562 }
16563
16564 /*******************************************************************
16565  *
16566  * @brief Deallocating the memory allocated by the aper decoder
16567  *          for DrbSetupModItem  
16568  *
16569  * @details
16570  *
16571  *    Function : freeAperDecodeDrbSetupModItem 
16572  *
16573  *    Functionality:  Deallocating memory allocated for DrbSetupModItem
16574  *
16575  * @params[in] DRBs_ToBeSetupMod_Item_t *drbItem
16576  *
16577  * @return void
16578  *
16579  * ****************************************************************/
16580
16581 void freeAperDecodeDrbSetupModItem(DRBs_ToBeSetupMod_Item_t *drbItem)
16582 {
16583    uint8_t arrIdx =0;
16584    SNSSAI_t *snssai =NULLP;
16585    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16586
16587    drbItem->qoSInformation.present = QoSInformation_PR_choice_extension;
16588    switch(drbItem->qoSInformation.present)
16589    {
16590       case QoSInformation_PR_NOTHING:
16591          break;
16592       case QoSInformation_PR_eUTRANQoS:
16593          {
16594             if(drbItem->qoSInformation.choice.eUTRANQoS)
16595             {
16596                free(drbItem->qoSInformation.choice.eUTRANQoS);
16597             }
16598             break;
16599          }
16600       case QoSInformation_PR_choice_extension:
16601          {
16602             if(drbItem->qoSInformation.choice.choice_extension)
16603             {
16604                freeAperDecodeQosInfo(&drbItem->qoSInformation.choice.choice_extension->value.choice.\
16605                      DRB_Information.dRB_QoS);
16606                snssai = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16607                if(snssai->sST.buf)
16608                {
16609                   free(snssai->sST.buf);
16610                }
16611                if(snssai->sD)
16612                {
16613                   if(snssai->sD->buf)
16614                   {
16615                      free(snssai->sD->buf);
16616                   }
16617                   free(snssai->sD);
16618                }
16619
16620                flowMap = &drbItem->qoSInformation.choice.choice_extension->value.choice.\
16621                          DRB_Information.flows_Mapped_To_DRB_List;
16622                if(flowMap->list.array)
16623                {
16624                   for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16625                   {
16626                      if(flowMap->list.array[arrIdx] )
16627                      {
16628                         freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16629                         free(flowMap->list.array[arrIdx]);
16630                      }
16631                   }
16632                   free(flowMap->list.array);
16633                }
16634
16635                free(drbItem->qoSInformation.choice.choice_extension);
16636             }
16637             break;
16638          }
16639
16640    }
16641    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16642    if(drbItem->uLConfiguration)
16643    {
16644       free(drbItem->uLConfiguration);
16645    }
16646 }
16647
16648 /*******************************************************************
16649  *
16650  * @brief Deallocating the memory allocated by the aper decoder
16651  *          for DrbToBeSetupModList
16652  *
16653  * @details
16654  *
16655  *    Function : freeAperDecodeDrbToBeSetupModList
16656  *
16657  *    Functionality:  Deallocating memory allocated for DrbToBeSetupModList
16658  *
16659  * @params[in] DRBs_ToBeSetupMod_List_t *drbSet
16660  *
16661  * @return void
16662  *
16663  * ****************************************************************/
16664
16665 void freeAperDecodeDrbToBeSetupModList(DRBs_ToBeSetupMod_List_t *drbSet)
16666 {
16667    uint8_t arrIdx =0;
16668    struct DRBs_ToBeSetupMod_ItemIEs *drbItemIe;
16669
16670    if(drbSet->list.array)
16671    {
16672       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16673       {
16674          if(drbSet->list.array[arrIdx] != NULLP)
16675          {
16676             if(arrIdx == 0)
16677             {
16678                drbItemIe = (DRBs_ToBeSetupMod_ItemIEs_t *)drbSet->list.array[arrIdx];
16679                freeAperDecodeDrbSetupModItem(&(drbItemIe->value.choice.DRBs_ToBeSetupMod_Item));
16680             }
16681             free(drbSet->list.array[arrIdx]);
16682          }
16683       }
16684       free(drbSet->list.array);
16685    }
16686
16687 }
16688
16689 /*******************************************************************
16690  *
16691  * @brief Deallocating the memory allocated by the aper decoder
16692  *          for DrbSetupModItem  
16693  *
16694  * @details
16695  *
16696  *    Function : freeAperDecodeDrbModifiedItem 
16697  *
16698  *    Functionality:  Deallocating memory allocated for DrbModifedItem
16699  *
16700  * @params[in] DRBs_ToBeModified_Item_t *drbItem
16701  *
16702  * @return void
16703  *
16704  * ****************************************************************/
16705
16706 void freeAperDecodeDrbModifiedItem(DRBs_ToBeModified_Item_t *drbItem)
16707 {
16708    uint8_t arrIdx =0;
16709    SNSSAI_t *snssai =NULLP;
16710    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16711
16712    if(drbItem->qoSInformation != NULLP)
16713    {
16714       drbItem->qoSInformation->present = QoSInformation_PR_choice_extension;
16715       switch(drbItem->qoSInformation->present)
16716       {
16717          case QoSInformation_PR_NOTHING:
16718             break;
16719          case QoSInformation_PR_eUTRANQoS:
16720             {
16721                if(drbItem->qoSInformation->choice.eUTRANQoS)
16722                {
16723                   free(drbItem->qoSInformation->choice.eUTRANQoS);
16724                }
16725                break;
16726             }
16727          case QoSInformation_PR_choice_extension:
16728             {
16729                if(drbItem->qoSInformation->choice.choice_extension)
16730                {
16731                   freeAperDecodeQosInfo(&drbItem->qoSInformation->choice.choice_extension->value.choice.\
16732                         DRB_Information.dRB_QoS);
16733                   snssai = &drbItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16734                   if(snssai->sST.buf)
16735                   {
16736                      free(snssai->sST.buf);
16737                   }
16738                   if(snssai->sD)
16739                   {
16740                      if(snssai->sD->buf)
16741                      {
16742                         free(snssai->sD->buf);
16743                      }
16744                      free(snssai->sD);
16745                   }
16746
16747                   flowMap = &drbItem->qoSInformation->choice.choice_extension->value.choice.\
16748                             DRB_Information.flows_Mapped_To_DRB_List;
16749                   if(flowMap->list.array)
16750                   {
16751                      for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16752                      {
16753                         if(flowMap->list.array[arrIdx] )
16754                         {
16755                            freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16756                            free(flowMap->list.array[arrIdx]);
16757                         }
16758                      }
16759                      free(flowMap->list.array);
16760                   }
16761
16762                   free(drbItem->qoSInformation->choice.choice_extension);
16763                }
16764                break;
16765             }
16766       }
16767       free(drbItem->qoSInformation);
16768    }
16769    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16770    if(drbItem->uLConfiguration)
16771    {
16772       free(drbItem->uLConfiguration);
16773    }
16774 }
16775
16776 /*******************************************************************
16777  *
16778  * @brief Deallocating the memory allocated by the aper decoder
16779  *          for DrbToBeSetupModList
16780  *
16781  * @details
16782  *
16783  *    Function : freeAperDecodeDrbToBeModifiedList
16784  *
16785  *    Functionality:  Deallocating memory allocated for DrbToBeModifiedList
16786  *
16787  * @params[in] DRBs_ToBeModified_List_t *drbSet
16788  *
16789  * @return void
16790  *
16791  * ****************************************************************/
16792
16793 void freeAperDecodeDrbToBeModifiedList(DRBs_ToBeModified_List_t *drbSet)
16794 {
16795    uint8_t arrIdx =0;
16796    struct DRBs_ToBeModified_ItemIEs *drbItemIe;
16797
16798    if(drbSet->list.array)
16799    {
16800       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16801       {
16802          if(drbSet->list.array[arrIdx] != NULLP)
16803          {
16804             if(arrIdx == 0)
16805             {
16806                drbItemIe = (DRBs_ToBeModified_ItemIEs_t *)drbSet->list.array[arrIdx];
16807                freeAperDecodeDrbModifiedItem(&(drbItemIe->value.choice.DRBs_ToBeModified_Item));
16808             }
16809             free(drbSet->list.array[arrIdx]);
16810          }
16811       }
16812       free(drbSet->list.array);
16813    }
16814
16815 }
16816
16817 /*******************************************************************
16818  *
16819  * @brief Deallocating the memory allocated by the aper decoder
16820  *          for DrbToBeSetupModList
16821  *
16822  * @details
16823  *
16824  *    Function : freeAperDecodeDrbToBeReleasedList
16825  *
16826  *    Functionality:  Deallocating memory allocated for DrbToBeReleasedList
16827  *
16828  * @params[in] DRBs_ToBeReleased_List_t *drbSet
16829  *
16830  * @return void
16831  *
16832  * ****************************************************************/
16833
16834 void freeAperDecodeDrbToBeReleasedList(DRBs_ToBeReleased_List_t *drbSet)
16835 {
16836    uint8_t arrIdx =0;
16837
16838    if(drbSet->list.array)
16839    {
16840       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16841       {
16842          if(drbSet->list.array[arrIdx] != NULLP)
16843          {
16844             free(drbSet->list.array[arrIdx]);
16845          }
16846       }
16847       free(drbSet->list.array);
16848    }
16849
16850 }
16851 /*******************************************************************
16852  *
16853  * @brief Deallocating the memory allocated by the aper decoder
16854  *          for UeContextModificationReqMsg
16855  *
16856  * @details
16857  *
16858  *    Function : freeAperDecodeUeContextModificationReqMsg
16859  *
16860  *    Functionality:  Deallocating memory allocated for
16861  *                  UeContextModificationReqMsg
16862  *
16863  * @params[in] UEContextModificationRequest_t *UeContextModifyReq
16864  *
16865  * @return void
16866  *
16867  * ****************************************************************/
16868 void freeAperDecodeUeContextModificationReqMsg(UEContextModificationRequest_t *ueContextModifyReq )
16869 {
16870    uint8_t arrIdx, ieId;
16871
16872    if(ueContextModifyReq->protocolIEs.list.array)
16873    {
16874       for( arrIdx = 0 ; arrIdx<ueContextModifyReq->protocolIEs.list.count ; arrIdx++)
16875       {
16876          if(ueContextModifyReq->protocolIEs.list.array[arrIdx])
16877          {
16878             ieId = ueContextModifyReq->protocolIEs.list.array[arrIdx]->id;
16879             switch(ieId)
16880             {
16881                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16882                   break;
16883                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16884                   break;
16885                case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
16886                   {
16887                      freeAperDecodeDrbToBeSetupModList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16888                            value.choice.DRBs_ToBeSetupMod_List);
16889                      break;
16890                   }
16891                case ProtocolIE_ID_id_DRBs_ToBeModified_List:
16892                   {
16893                      freeAperDecodeDrbToBeModifiedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16894                            value.choice.DRBs_ToBeModified_List);
16895                      break;
16896                   }
16897                case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
16898                   {
16899                      freeAperDecodeDrbToBeReleasedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16900                            value.choice.DRBs_ToBeReleased_List);
16901                      break;
16902                   }
16903                case ProtocolIE_ID_id_TransmissionActionIndicator:
16904                   break;
16905                case ProtocolIE_ID_id_RRCContainer:
16906                   {
16907                      free(ueContextModifyReq->protocolIEs.list.array[arrIdx]->value.choice.RRCContainer.buf);
16908                   }
16909             }
16910             free(ueContextModifyReq->protocolIEs.list.array[arrIdx]);
16911          }
16912       }
16913       free(ueContextModifyReq->protocolIEs.list.array);
16914    }
16915 }
16916 /*******************************************************************
16917  *
16918  * @brief processing the F1 UeContextModificationReq
16919  *
16920  * @details
16921  *
16922  *    Function : procF1UeContextModificationReq
16923  *
16924  *    Functionality:  processing the F1 UeContextModificationReq
16925  *
16926  * @params[in] F1AP_PDU_t *f1apMsg
16927  *
16928  * @return
16929  * ****************************************************************/
16930 uint8_t procF1UeContextModificationReq(F1AP_PDU_t *f1apMsg)
16931 {
16932    UEContextModificationRequest_t *ueContextModifyReq = NULLP;
16933    uint8_t  ret = ROK, ieIdx = 0, cellIdx=0;
16934    DuUeCb   *duUeCb = NULLP;
16935    DRBs_ToBeSetupMod_List_t *drbSetupModCfg = NULLP;
16936    DRBs_ToBeModified_List_t *drbModifiedCfg = NULLP;
16937    DRBs_ToBeReleased_List_t *drbToRelease = NULLP;
16938    uint32_t gnbCuUeF1apId, gnbDuUeF1apId;
16939
16940    ueContextModifyReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextModificationRequest;
16941    for(ieIdx=0; (ieIdx < ueContextModifyReq->protocolIEs.list.count && ret == ROK); ieIdx++)
16942    {
16943       switch(ueContextModifyReq->protocolIEs.list.array[ieIdx]->id)
16944       {
16945          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16946             {
16947                gnbCuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
16948                break;
16949             }
16950          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16951             {
16952                gnbDuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
16953                for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
16954                {
16955                   if(duCb.actvCellLst[cellIdx])
16956                   {
16957                      if((duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbDuUeF1apId == gnbDuUeF1apId)&&\
16958                            (duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbCuUeF1apId == gnbCuUeF1apId))
16959                      {
16960                         duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1];
16961                         if(duUeCb->f1UeDb == NULLP)
16962                         {
16963                            DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
16964                            duUeCb->f1UeDb->cellIdx = cellIdx;
16965                            duUeCb->f1UeDb->actionType = UE_CTXT_MOD;
16966                         }
16967                         break;
16968                      }
16969                   }
16970                }
16971                if(duUeCb == NULLP)
16972                {
16973                   DU_LOG("\nERROR  -->  DU APP : wrong values of gnbCuUeF1apId and gnbDuUeF1apId ");
16974                   ret = RFAILED;
16975                }
16976                break;
16977             }
16978
16979          case ProtocolIE_ID_id_RRCContainer:
16980             {
16981                /* Filling Dl RRC Msg Info */
16982                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
16983                if(!duUeCb->f1UeDb->dlRrcMsg)
16984                {
16985                   DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16986                         Memory allocation failed ");
16987                   ret = RFAILED;
16988                }
16989                else
16990                {
16991                   duUeCb->f1UeDb->dlRrcMsgPres = true;
16992                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
16993                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
16994                         &ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
16995                         value.choice.RRCContainer);
16996                }
16997
16998                break;
16999             }
17000
17001          case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
17002          case ProtocolIE_ID_id_DRBs_ToBeModified_List:
17003          case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
17004             {
17005                if(duUeCb->f1UeDb)
17006                {
17007                   /*DRBs to be Added*/
17008                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present ==\
17009                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List)
17010                   {
17011                      drbSetupModCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17012                                       choice.DRBs_ToBeSetupMod_List;
17013
17014                      if(extractDrbListToSetupMod(NULL, drbSetupModCfg, NULL, drbSetupModCfg->list.count,\
17015                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULL))
17016                      {
17017                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbSetupModList");
17018                         ret = RFAILED;
17019                      }
17020                   }
17021
17022                   /*DRBs to be Modified*/
17023                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
17024                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List)
17025
17026                   {
17027                      drbModifiedCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17028                                       choice.DRBs_ToBeModified_List;
17029                      if(extractDrbListToSetupMod(NULL, NULL, drbModifiedCfg, drbModifiedCfg->list.count,\
17030                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, &duUeCb->duRlcUeCfg))
17031                      {
17032                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
17033                         ret = RFAILED;
17034                      }
17035                   }
17036                   /*DRBs to be Released*/
17037                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
17038                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeReleased_List)
17039
17040                   {
17041                      drbToRelease = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17042                                       choice.DRBs_ToBeReleased_List;
17043                      if(extractDrbListToRelease(gnbDuUeF1apId, drbToRelease, drbToRelease->list.count,\
17044                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->duRlcUeCfg))
17045                      {
17046                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
17047                         ret = RFAILED;
17048                      }
17049                   }
17050                }
17051                break;
17052             }
17053
17054          case ProtocolIE_ID_id_GNB_DUConfigurationQuery:
17055             {
17056                DU_LOG("\nINFO  -->  DU APP : Received GNB DU Configuration Query in UE Context Modification Request from CU");
17057                if(duUeCb->f1UeDb)
17058                {
17059                   duUeCb->f1UeDb->actionType = UE_CTXT_CFG_QUERY;
17060                }
17061                break;
17062             }
17063
17064          case ProtocolIE_ID_id_RRCReconfigurationCompleteIndicator:
17065             {
17066                if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.RRCReconfigurationCompleteIndicator == \
17067                   RRCReconfigurationCompleteIndicator_true)
17068                {
17069                   duUeCb->f1UeDb->actionType = UE_CTXT_RRC_RECFG_COMPLETE;
17070                }
17071                break;
17072             }
17073          case ProtocolIE_ID_id_TransmissionActionIndicator:
17074             {
17075                if(duUeCb->f1UeDb)
17076                {
17077                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.TransmissionActionIndicator  == TransmissionActionIndicator_stop)
17078                   {
17079                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = STOP_TRANSMISSION; 
17080                   }
17081                   else 
17082                   {
17083                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = RESTART_TRANSMISSION; 
17084                   }
17085                }
17086                break;
17087             }
17088
17089          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
17090             {
17091                if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
17092                {
17093                   duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
17094                }
17095                break;
17096             }
17097 #ifdef NR_DRX
17098          case ProtocolIE_ID_id_DRXConfigurationIndicator:
17099             {
17100                duUeCb->f1UeDb->duUeCfg.drxConfigIndicatorRelease = true;
17101                break;
17102             }
17103 #endif
17104               
17105       }
17106    }
17107
17108    if(ret != RFAILED) 
17109    {
17110       ret = duProcUeContextModReq(duUeCb);
17111    }
17112    freeAperDecodeUeContextModificationReqMsg(ueContextModifyReq);
17113    return ret; 
17114 }
17115
17116 /*****************************************************************i
17117 *
17118 * @brief Free memory allocated for UE Context Release Request
17119 *
17120 * @details
17121 *
17122 *    Function : FreeUeContextReleaseReq
17123 *
17124 *    Functionality:
17125 *         - Free memory allocated for UE Context Release Request
17126 *
17127 * @params[in] F1AP_PDU_t *f1apMsg
17128 * @return void 
17129 *
17130 * *************************************************************/
17131 void FreeUeContextReleaseReq(F1AP_PDU_t *f1apMsg)
17132 {
17133    uint8_t ieIdx;
17134    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
17135    
17136    if(f1apMsg)
17137    {
17138       if(f1apMsg->choice.initiatingMessage)
17139       {
17140          ueReleaseReq =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
17141          if(ueReleaseReq->protocolIEs.list.array)
17142          {
17143             for(ieIdx=0 ; ieIdx<ueReleaseReq->protocolIEs.list.count; ieIdx++)
17144             {
17145                DU_FREE(ueReleaseReq->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseRequest_t));
17146             }
17147             DU_FREE(ueReleaseReq->protocolIEs.list.array, ueReleaseReq->protocolIEs.list.size);
17148          }
17149          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
17150       }
17151       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
17152    }
17153
17154 }
17155 /*****************************************************************i
17156 *
17157 * @brief Build and Send UE Context Release Request  
17158 *
17159 * @details
17160 *
17161 *    Function : BuildAndSendUeContextReleaseReq
17162 *
17163 *    Functionality:
17164 *         - Build and Send UE Context Release Request 
17165 *
17166 * @params[in]
17167 * @return ROK     - success
17168 *         RFAILED - failure
17169 *
17170 * *************************************************************/
17171 uint8_t BuildAndSendUeContextReleaseReq(uint16_t cellId, uint8_t ueId)
17172 {
17173    bool memAllocFail = false;
17174    uint8_t ieIdx =0;
17175    uint8_t ret = RFAILED;
17176    uint16_t cellIdx =0;
17177    uint16_t crnti = 0;
17178    uint8_t  elementCnt = 0;
17179    uint32_t  gnbCuUeF1apId =0;   /* gNB-CU UE F1AP Id */
17180    uint32_t  gnbDuUeF1apId =0;   /* gNB-DU UE F1AP Id */
17181    asn_enc_rval_t encRetVal; 
17182    F1AP_PDU_t *f1apMsg = NULLP;
17183    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
17184
17185    DU_LOG("\nINFO  --> Building the UE Context Release Request");
17186    do
17187    {
17188       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
17189       if(f1apMsg == NULLP)
17190       {
17191          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for f1apMsg");
17192          break;
17193       }
17194
17195       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
17196       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
17197       if(f1apMsg->choice.initiatingMessage == NULLP)
17198       {
17199          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for\
17200          initiatingMessage");   
17201          break;
17202       }
17203       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_UEContextReleaseRequest;
17204       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
17205       f1apMsg->choice.initiatingMessage->value.present = \
17206       InitiatingMessage__value_PR_UEContextReleaseRequest;
17207
17208       ueReleaseReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
17209
17210       elementCnt = 2;
17211
17212       ueReleaseReq->protocolIEs.list.count = elementCnt;
17213       ueReleaseReq->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseRequest_t *);
17214
17215       /* Initialize the F1Setup members */
17216       DU_ALLOC(ueReleaseReq->protocolIEs.list.array,ueReleaseReq->protocolIEs.list.size);
17217       if(ueReleaseReq->protocolIEs.list.array == NULLP)
17218       {
17219          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE array");
17220          break;
17221       }
17222       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
17223       {
17224          DU_ALLOC(ueReleaseReq->protocolIEs.list.array[ieIdx],\
17225                sizeof(UEContextReleaseRequest_t));
17226          if(ueReleaseReq->protocolIEs.list.array[ieIdx] == NULLP)
17227          {
17228             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE elements");
17229             memAllocFail = true;  
17230             break;
17231          }
17232       }
17233       if(memAllocFail == true)
17234          break;
17235
17236       /* Fetching Ue Cb Info*/
17237       GET_CELL_IDX(cellId, cellIdx);
17238       if(duCb.actvCellLst[cellIdx] == NULLP)
17239       {
17240          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): CellId[%d] does not exist", cellId);
17241          break;
17242       }
17243       else
17244       {
17245          GET_CRNTI(crnti, ueId);
17246          if(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].crnti != crnti)
17247          {
17248             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): crnti[%d] does not exist", crnti);
17249             break;
17250          }
17251          gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
17252          gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
17253       }
17254
17255       ieIdx=0; 
17256       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID; 
17257       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17258       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present = \
17259       UEContextReleaseRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
17260       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
17261       
17262       ieIdx++;
17263       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
17264       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17265       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present =\
17266       UEContextReleaseRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
17267       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17268       
17269       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17270
17271       /* Encode the F1SetupRequest type as APER */
17272       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17273       encBufSize = 0;
17274       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17275       /* Encode results */
17276       if(encRetVal.encoded == ENCODE_FAIL)
17277       {
17278          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseRequest structure (at %s)\n",\
17279                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17280          break;
17281       }
17282       else
17283       {
17284          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseRequest\n");
17285 #ifdef DEBUG_ASN_PRINT
17286          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17287          {
17288             printf("%x",encBuf[ieIdx]);
17289          }
17290 #endif
17291       }
17292
17293       /* Sending msg */
17294       if(sendF1APMsg() != ROK)
17295       {
17296          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Request failed");
17297          break;
17298       }
17299       ret = ROK;
17300       break;
17301    }while(true);
17302
17303    FreeUeContextReleaseReq(f1apMsg);
17304    return ret;
17305 }
17306 /*****************************************************************i
17307  *
17308  * @brief Free memory allocated for UE Context Release Complete
17309  *
17310  * @details
17311  *
17312  *    Function : FreeUeContextReleaseComplete
17313  *
17314  *    Functionality:
17315  *         - Free memory allocated for UE Context Release Complete
17316  *
17317  * @params[in] F1AP_PDU_t *f1apMsg
17318  * @return void
17319  *
17320  * *************************************************************/
17321 void FreeUeContextReleaseComplete(F1AP_PDU_t *f1apMsg)
17322 {
17323    uint8_t ieIdx;
17324    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17325
17326    if(f1apMsg)
17327    {
17328       if(f1apMsg->choice.successfulOutcome)
17329       {
17330          ueReleaseComplete =&f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17331          if(ueReleaseComplete->protocolIEs.list.array)
17332          {
17333             for(ieIdx=0 ; ieIdx<ueReleaseComplete->protocolIEs.list.count; ieIdx++)
17334             {
17335                DU_FREE(ueReleaseComplete->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseComplete_t));
17336             }
17337             DU_FREE(ueReleaseComplete->protocolIEs.list.array, ueReleaseComplete->protocolIEs.list.size);
17338          }
17339          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17340       }
17341       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
17342    }
17343
17344 }
17345 /*****************************************************************i
17346  *
17347  * @brief Build and Send UE Context Release Complete
17348  *
17349  * @details
17350  *
17351  *    Function : BuildAndSendUeContextReleaseComplete
17352  *
17353  *    Functionality:
17354  *         - Build and Send UE Context Release Complete
17355  *
17356  * @params[in]  cellId,  gnbCuUeF1apId, gnbDuUeF1apId
17357  * @return ROK     - success
17358  *         RFAILED - failure
17359  *
17360  * *************************************************************/
17361 uint8_t BuildAndSendUeContextReleaseComplete(uint16_t cellId, uint32_t gnbCuUeF1apId, uint32_t gnbDuUeF1apId)
17362 {
17363    bool memAllocFail = false;
17364    uint8_t ieIdx =0, ret = RFAILED, elementCnt = 0;
17365    asn_enc_rval_t encRetVal;
17366    F1AP_PDU_t *f1apMsg = NULLP;
17367    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17368
17369    DU_LOG("\nINFO  --> Building the UE Context Release Complete");
17370    do
17371    {
17372       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
17373       if(f1apMsg == NULLP)
17374       {
17375          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for f1apMsg");
17376          break;
17377       }
17378
17379       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
17380       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17381       if(f1apMsg->choice.successfulOutcome == NULLP)
17382       {
17383          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for\
17384                successfulOutcome");
17385          break;
17386       }
17387       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextRelease;
17388       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
17389       f1apMsg->choice.successfulOutcome->value.present = \
17390       SuccessfulOutcome__value_PR_UEContextReleaseComplete;
17391
17392       ueReleaseComplete = &f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17393
17394       elementCnt = 2;
17395       ueReleaseComplete->protocolIEs.list.count = elementCnt;
17396       ueReleaseComplete->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseComplete_t *);
17397
17398       /* Initialize the UE Release Complete members */
17399       DU_ALLOC(ueReleaseComplete->protocolIEs.list.array,ueReleaseComplete->protocolIEs.list.size);
17400       if(ueReleaseComplete->protocolIEs.list.array == NULLP)
17401       {
17402          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE array");
17403          break;
17404       }
17405       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
17406       {
17407          DU_ALLOC(ueReleaseComplete->protocolIEs.list.array[ieIdx],\
17408                sizeof(UEContextReleaseComplete_t));
17409          if(ueReleaseComplete->protocolIEs.list.array[ieIdx] == NULLP)
17410          {
17411             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE\
17412             elements");
17413             memAllocFail = true;
17414             break;
17415          }
17416       }
17417       if(memAllocFail == true)
17418          break;
17419
17420
17421       ieIdx=0;
17422       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
17423       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17424       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present = \
17425       UEContextReleaseCompleteIEs__value_PR_GNB_CU_UE_F1AP_ID;
17426       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
17427
17428       ieIdx++;
17429       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
17430       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17431       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present =\
17432       UEContextReleaseCompleteIEs__value_PR_GNB_DU_UE_F1AP_ID;
17433       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17434
17435       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17436
17437       /* Encode the F1SetupComplete type as APER */
17438       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17439       encBufSize = 0;
17440       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17441       /* Encode results */
17442       if(encRetVal.encoded == ENCODE_FAIL)
17443       {
17444          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseComplete structure (at %s)\n",\
17445                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17446          break;
17447       }
17448       else
17449       {
17450          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseComplete\n");
17451 #ifdef DEBUG_ASN_PRINT
17452          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17453          {
17454             printf("%x",encBuf[ieIdx]);
17455          }
17456 #endif
17457       }
17458
17459       /* Sending msg */
17460       if(sendF1APMsg() != ROK)
17461       {
17462          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Complete failed");
17463          break;
17464       }
17465       ret = ROK;
17466       break;
17467    }while(true);
17468    
17469    if((ret == ROK) && (duCb.actvCellLst[cellId-1]) && (duCb.actvCellLst[cellId-1]->cellStatus == DELETION_IN_PROGRESS) 
17470          && (duCb.actvCellLst[cellId-1]->numActvUes == 0))
17471    {
17472       ret = duSendCellDeletReq(cellId);
17473       if(ret != ROK)
17474       {
17475          DU_LOG("\nERROR  -->  F1AP: BuildAndSendUeContextReleaseComplete(): Failed to process cell\
17476                Delete req for CellId");
17477       }
17478    }
17479    FreeUeContextReleaseComplete(f1apMsg);
17480    return ret;
17481
17482 }
17483
17484 /*******************************************************************
17485 *
17486 * @brief added free part for the memory allocated by aper_decoder 
17487 *
17488 * @details
17489 *
17490 *    Function : freeAperDecodeUeContextReleaseCommand 
17491 *
17492 *    Functionality: added free part for the memory allocated by aper_decoder
17493 *
17494 * @params[in] F1AP_PDU_t *f1apMsg
17495 * @return void
17496 *
17497 * ****************************************************************/
17498 void freeAperDecodeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17499 {
17500    uint8_t ieIdx=0;
17501    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17502
17503    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17504    
17505    if(ueContextReleaseCommand->protocolIEs.list.array)
17506    {
17507       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17508       {
17509          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17510          {
17511             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17512             {
17513                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17514                   break;
17515                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17516                   break;
17517                case ProtocolIE_ID_id_Cause:
17518                   break;
17519                case ProtocolIE_ID_id_RRCContainer:
17520                {
17521                   if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
17522                   {
17523                      free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
17524                   }
17525                   break;
17526                }
17527                default :
17528                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17529                        ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17530                   break;
17531             }
17532          }
17533          free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]);
17534       }
17535       free(ueContextReleaseCommand->protocolIEs.list.array);
17536    }
17537 }
17538 /*******************************************************************
17539 *
17540 * @brief processing of UE Context Release Command
17541 *
17542 * @details
17543 *
17544 *    Function : procF1UeContextReleaseCommand 
17545 *
17546 *    Functionality: processing of UE Context Release Command
17547 *
17548 * @params[in] F1AP_PDU_t *f1apMsg
17549 * @return void
17550 *
17551 * ****************************************************************/
17552 uint8_t procF1UeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17553 {
17554    uint8_t  ieIdx=0, ret=ROK, ueIdx=0;
17555    uint16_t cellIdx =0, cellId = 0;
17556    bool ueIdxFound = false;
17557    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0;
17558    DuUeCb   *duUeCb = NULLP;
17559    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17560
17561    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17562
17563    if(ueContextReleaseCommand->protocolIEs.list.array)
17564    {
17565       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17566       {
17567          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17568          {
17569             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17570             {
17571                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17572                   {
17573                      gnbCuUeF1apId= ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17574                                     value.choice.GNB_CU_UE_F1AP_ID;
17575                      break;
17576                   }
17577
17578                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17579                   {
17580                      gnbDuUeF1apId = ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17581                                      value.choice.GNB_DU_UE_F1AP_ID;
17582                      break;
17583                   }
17584
17585                case ProtocolIE_ID_id_Cause:
17586                   {
17587                      for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
17588                      {
17589                         for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
17590                         {
17591                            if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
17592                                  (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId))
17593                            {
17594                               cellId = duCb.actvCellLst[cellIdx]->cellId;
17595                               duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
17596                               ueIdxFound = true;
17597                               break;
17598                            }
17599                         }
17600                         if(ueIdxFound == true)
17601                         {
17602                            break;
17603                         }
17604                      }
17605                      
17606                      if(!ueIdxFound)
17607                      {
17608                         DU_LOG("\nERROR  -->  F1AP: procF1UeContextReleaseCommand(): Ue Information is not available");
17609                         ret = RFAILED;
17610                      }
17611                      break;
17612                   }
17613
17614                case ProtocolIE_ID_id_RRCContainer:
17615                   {
17616                      if(ueIdxFound == true)  
17617                      {
17618                         DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
17619                         if(duUeCb->f1UeDb)
17620                         {
17621                            memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
17622                            duUeCb->f1UeDb->actionType = UE_CTXT_RELEASE;
17623                            duUeCb->f1UeDb->cellIdx = cellIdx;
17624                            /* Filling Dl RRC Msg Info */
17625                            DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
17626                            if(!duUeCb->f1UeDb->dlRrcMsg)
17627                            {
17628                               DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17629                                     Memory allocation failed ");
17630                               ret = RFAILED;
17631                            }
17632                            else
17633                            {
17634                               duUeCb->f1UeDb->dlRrcMsgPres = true;
17635                               memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
17636                               ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
17637                                     &ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17638                                     value.choice.RRCContainer);
17639                            }
17640
17641                         }
17642                         else
17643                         {
17644                            DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17645                                  Memory allocation failed ");
17646                            ret = RFAILED;
17647
17648                         }
17649                      }
17650                      break;
17651                   }
17652                default :
17653                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17654                         ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17655                   break;
17656             }
17657          }
17658       }
17659    }
17660    if(ret != RFAILED)
17661    {
17662       duProcUeContextReleaseCommand(cellId, duUeCb);
17663    }
17664    freeAperDecodeUeContextReleaseCommand(f1apMsg);
17665    return ret;
17666 }
17667
17668 /**************************************************************
17669  *
17670  * @brief free the memory allocated by aper decoder for paging
17671  *
17672  * @details
17673  *
17674  *    Function : freeAperDecodePagingMsg
17675  *
17676  *    Functionality:
17677  *         - free the memory allocated by aper decoder for
17678  *         the paging f1ap msg
17679  *
17680  * @params[in] Paging_t   *paging
17681  * @return ROK     - success
17682  *         RFAILED - failure
17683  *
17684  ****************************************************************/
17685 void freeAperDecodePagingMsg(Paging_t   *paging)
17686 {
17687    uint8_t ieIdx, cellIdx;
17688    PagingCell_ItemIEs_t *pagingCellItemIes;
17689    PagingCell_Item_t *pagingCellItem;
17690    PagingCell_list_t  *pagingCelllist;
17691
17692    if(paging)
17693    {
17694       if(paging->protocolIEs.list.array)
17695       {
17696          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17697          {
17698             if(paging->protocolIEs.list.array[ieIdx])
17699             {
17700                switch(paging->protocolIEs.list.array[ieIdx]->id)
17701                {
17702                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17703                      {
17704                         free(paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10.buf);
17705                         break;
17706                      }
17707                   case ProtocolIE_ID_id_PagingIdentity:
17708                      {
17709                         if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present == PagingIdentity_PR_cNUEPagingIdentity)
17710                         {
17711                            if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)
17712                            {
17713                               if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->present == \
17714                                     CNUEPagingIdentity_PR_fiveG_S_TMSI)
17715                               {
17716                                  free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->choice.fiveG_S_TMSI.buf);
17717                               }
17718                               free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity);
17719                            }
17720                         }
17721                         break;
17722                      }
17723                   case ProtocolIE_ID_id_PagingCell_List:
17724                      {
17725                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list;
17726                         if(pagingCelllist->list.array)
17727                         {
17728                            for(cellIdx = 0; cellIdx < pagingCelllist->list.count; cellIdx++)
17729                            {
17730                               if(pagingCelllist->list.array[cellIdx])
17731                               {
17732                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellIdx];
17733                                  if(pagingCellItemIes->id == ProtocolIE_ID_id_PagingCell_Item)
17734                                  {
17735                                     pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17736                                     free(pagingCellItem->nRCGI.pLMN_Identity.buf);
17737                                     free(pagingCellItem->nRCGI.nRCellIdentity.buf);
17738                                  }
17739                                  free(pagingCelllist->list.array[cellIdx]);
17740                               }
17741                            }
17742                            free(pagingCelllist->list.array);
17743                         }
17744                         break;
17745                      }
17746                }
17747                free(paging->protocolIEs.list.array[ieIdx]);
17748             }
17749          }
17750          free(paging->protocolIEs.list.array);
17751
17752       }
17753    }
17754 }
17755
17756 /**************************************************************
17757  *
17758  * @brief processing the paging f1ap msg received from CU 
17759  *
17760  * @details
17761  *
17762  *    Function : procPagingMsg
17763  *
17764  *    Functionality:
17765  *         - processing the paging f1ap msg received from CU
17766  *
17767  * @params[in] F1AP_PDU_t *f1apMsg
17768  * @return ROK     - success
17769  *         RFAILED - failure
17770  *
17771  *
17772  ****************************************************************/
17773 uint8_t procPagingMsg(F1AP_PDU_t *f1apMsg) 
17774 {
17775    uint8_t ieIdx = 0, cellListIdx = 0;
17776    uint64_t cellId = 0;
17777    Paging_t   *paging = NULLP;
17778    PagingCell_list_t  *pagingCelllist = NULLP;
17779    PagingCell_ItemIEs_t *pagingCellItemIes = NULLP;
17780    PagingCell_Item_t *pagingCellItem = NULLP;
17781    DuPagingMsg *tmpPagingParam = NULLP;
17782
17783    paging = &f1apMsg->choice.initiatingMessage->value.choice.Paging;
17784    if(paging)
17785    {
17786       if(paging->protocolIEs.list.array)
17787       {
17788          DU_ALLOC(tmpPagingParam, sizeof(DuPagingMsg));
17789          if(tmpPagingParam == NULLP)
17790          {
17791             DU_LOG("\nERROR  --> DU APP : Memory Allocation Failure in procPagingMsg");
17792             freeAperDecodePagingMsg(paging);
17793             return RFAILED;
17794          }
17795          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17796          {
17797             if(paging->protocolIEs.list.array[ieIdx])
17798             {
17799                switch(paging->protocolIEs.list.array[ieIdx]->id)
17800                {
17801                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17802                      {
17803                         bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10,\
17804                                          &tmpPagingParam->pagUeId);
17805                         break;
17806                      }
17807
17808                   case ProtocolIE_ID_id_PagingIdentity:
17809                      {
17810                         switch(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present)
17811                         {
17812                            case PagingIdentity_PR_cNUEPagingIdentity: 
17813                               {
17814                                  if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)  
17815                                  {
17816                                     bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.\
17817                                           cNUEPagingIdentity->choice.fiveG_S_TMSI, &tmpPagingParam->sTmsi);
17818
17819                                  }
17820                                  break;
17821                               }
17822                             case PagingIdentity_PR_rANUEPagingIdentity:
17823                                {
17824                                   /*TODO: This Identifier is specific to RAN Initiated Paging â€“ Connected Mode Paging*/
17825                                   break;
17826                                }
17827                             default:
17828                                {
17829                                   DU_LOG("ERROR  -->  DU APP: Invalid UE Paging Identity, Skipping this Paging Message:");
17830                                   continue;
17831                                }
17832                         }
17833                      }
17834
17835                   case ProtocolIE_ID_id_PagingDRX:
17836                      {
17837                         tmpPagingParam->pagingDrxPres = TRUE;
17838                         tmpPagingParam->pagingDrx = convertPagingCycleEnumToValue(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingDRX);
17839                         break;
17840                      }
17841
17842                   case ProtocolIE_ID_id_PagingPriority:
17843                      {
17844                         tmpPagingParam->pagPriority = paging->protocolIEs.list.array[ieIdx]->value.choice.PagingPriority;
17845                         break;
17846                      }
17847
17848                   case ProtocolIE_ID_id_PagingCell_List:
17849                      {
17850                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list; 
17851                         if(pagingCelllist->list.array)
17852                         {
17853                            for(cellListIdx = 0; cellListIdx < pagingCelllist->list.count; cellListIdx++)
17854                            {
17855                               if(pagingCelllist->list.array[cellListIdx])
17856                               {
17857                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellListIdx];
17858                                  pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17859                                  bitStringToInt(&pagingCellItem->nRCGI.nRCellIdentity, &cellId);
17860                                  if(processPagingMsg(cellId, tmpPagingParam) != ROK)
17861                                  {
17862                                     DU_LOG("\nERROR  --> DU APP : Paging Processing Failed at CellId:%lu",cellId);
17863                                     continue;
17864                                  }
17865                               }
17866                            }
17867                         }
17868                         break;
17869                      }
17870                    default:
17871                      {
17872                          DU_LOG("\nERROR  --> F1AP : Incorrect Paging IE option");
17873                          break;
17874                      }
17875                }
17876             }
17877          }
17878       }
17879    }
17880    DU_FREE(tmpPagingParam, sizeof(DuPagingMsg));
17881    freeAperDecodePagingMsg(paging);
17882   
17883    return ROK;
17884 }
17885
17886 /**************************************************************
17887  *
17888  * @brief Handles received F1AP message and sends back response  
17889  *
17890  * @details
17891  *
17892  *    Function : F1APMsgHdlr
17893  *
17894  *    Functionality:
17895  *         - Decodes received F1AP control message
17896  *         - Prepares response message, encodes and sends to SCTP
17897  *
17898  * @params[in] 
17899  * @return ROK     - success
17900  *         RFAILED - failure
17901  *
17902  * ****************************************************************/
17903 void F1APMsgHdlr(Buffer *mBuf)
17904 {
17905    int i =0;
17906    char *recvBuf =NULLP;
17907    MsgLen copyCnt =0;
17908    MsgLen recvBufLen =0;
17909    F1AP_PDU_t *f1apMsg =NULLP;
17910    asn_dec_rval_t rval; /* Decoder return value */
17911    F1AP_PDU_t f1apasnmsg ;
17912    DU_LOG("\nINFO  -->  F1AP : Received F1AP message buffer");
17913    ODU_PRINT_MSG(mBuf, 0,0);
17914
17915    /* Copy mBuf into char array to decode it */
17916    ODU_GET_MSG_LEN(mBuf, &recvBufLen);
17917    DU_ALLOC(recvBuf, (Size)recvBufLen);
17918
17919    if(recvBuf == NULLP)
17920    {
17921       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed");
17922       return;
17923    }
17924    if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
17925    {
17926       DU_LOG("\nERROR   -->  F1AP : Failed while copying %d", copyCnt);
17927       return;
17928    }
17929
17930 #ifdef DEBUG_ASN_PRINT
17931    printf("\nDEBUG   -->  F1AP : Received flat buffer to be decoded : ");
17932    for(i=0; i< recvBufLen; i++)
17933    {
17934       printf("%x",recvBuf[i]);
17935    }
17936 #endif
17937
17938    /* Decoding flat buffer into F1AP messsage */
17939    f1apMsg = &f1apasnmsg;
17940    memset(f1apMsg, 0, sizeof(F1AP_PDU_t));
17941
17942    rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0);
17943
17944    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
17945    {
17946       DU_LOG("\nERROR  -->  F1AP : ASN decode failed");
17947       return;
17948    }
17949    printf("\n");
17950    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17951
17952    switch(f1apMsg->present)
17953    {
17954       case F1AP_PDU_PR_successfulOutcome:
17955          {
17956             switch(f1apMsg->choice.successfulOutcome->value.present)
17957             {
17958                case SuccessfulOutcome__value_PR_ResetAcknowledge:
17959                   {
17960                      DU_LOG("\nINFO   -->  F1AP : F1ResetAcknowledge is received successfully ");
17961                      break;
17962                   }
17963                case SuccessfulOutcome__value_PR_F1SetupResponse:
17964                   {                             
17965 #ifndef ODU_TEST_STUB
17966                      procF1SetupRsp(f1apMsg, recvBufLen, recvBuf);
17967 #endif
17968                      break;
17969                   }
17970
17971                case SuccessfulOutcome__value_PR_GNBDUConfigurationUpdateAcknowledge:
17972                   {
17973                      procF1GNBDUCfgUpdAck(f1apMsg, recvBufLen, recvBuf);
17974                      break;
17975                   }
17976
17977                default:
17978                   {
17979                      DU_LOG("\nERROR  -->  F1AP : Invalid type of SuccessfulOutcome__value_PR_ResetAcknowledge [%d]",\
17980                            f1apMsg->choice.successfulOutcome->value.present);
17981                      return;
17982                   }
17983             }/* End of switch(successfulOutcome) */
17984             free(f1apMsg->choice.successfulOutcome);
17985             break;
17986          }
17987       case F1AP_PDU_PR_initiatingMessage:
17988          {
17989             switch(f1apMsg->choice.initiatingMessage->value.present)
17990             {
17991                case InitiatingMessage__value_PR_Reset:
17992                   {
17993                      procF1ResetReq(f1apMsg);
17994                      break;
17995                   }
17996                case InitiatingMessage__value_PR_DLRRCMessageTransfer:
17997                   {
17998                      procF1DlRrcMsgTrans(f1apMsg);
17999                      break;
18000                   }
18001                case InitiatingMessage__value_PR_UEContextSetupRequest:
18002                   {
18003                      procF1UeContextSetupReq(f1apMsg);
18004                      break;
18005                   }
18006                case InitiatingMessage__value_PR_UEContextModificationRequest:
18007                   {
18008                      procF1UeContextModificationReq(f1apMsg);
18009                      break;
18010                   }
18011                case InitiatingMessage__value_PR_UEContextReleaseCommand:
18012                   {
18013                       procF1UeContextReleaseCommand(f1apMsg);
18014                       break;
18015                   }
18016                case InitiatingMessage__value_PR_Paging:
18017                   {
18018                      procPagingMsg(f1apMsg);
18019                      break;
18020                   }
18021                default:
18022                   {
18023                      DU_LOG("\nERROR  -->  F1AP : Invalid type of F1AP_PDU_PR_initiatingMessage [%d]",
18024                            f1apMsg->choice.initiatingMessage->value.present);
18025                      return;
18026                   }
18027             }/* End of switch(initiatingMessage) */
18028             free(f1apMsg->choice.initiatingMessage);
18029             break;
18030          }
18031
18032       default:
18033          {
18034             DU_LOG("\nERROR  -->  F1AP : Invalid type of f1apMsg->present [%d]",f1apMsg->present);
18035             return;
18036          }
18037          free(f1apMsg);
18038
18039    }/* End of switch(f1apMsg->present) */
18040    
18041    DU_FREE(recvBuf, (Size)recvBufLen);
18042 } /* End of F1APMsgHdlr */
18043
18044 /**********************************************************************
18045   End of file
18046  **********************************************************************/