b9a8f34953c726fcc0ce74a5834df13cd8ca60fe
[o-du/l2.git] / src / du_app / du_f1ap_msg_hdl.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /* This file contains F1AP message handler functions */
20 #include "common_def.h"
21 #include "ckw.h"
22 #include "ckw.x"
23 #include "kwu.h"
24 #include "kwu.x"
25 #include "lkw.h"
26 #include "lrg.h"
27 #include "legtp.h"
28 #include "lkw.x"
29 #include "lrg.x"
30 #include "F1AP-PDU.h"
31 #include "InitiatingMessage.h"
32 #include "SuccessfulOutcome.h"
33 #include "du_app_mac_inf.h"
34 #include "du_cfg.h"
35 #include "du_app_rlc_inf.h"
36 #include "du_mgr_main.h"
37 #include "du_mgr.h"
38 #include "du_utils.h"
39 #include "du_ue_mgr.h"
40 #include "RAT-Type.h"
41 #include "NRFreqInfo.h"
42 #include "NRCGI.h"
43 #include "TDD-Info.h"
44 #include "NR-Mode-Info.h"
45 #include "ServedPLMNs-List.h"
46 #include "GNB-DU-Served-Cells-List.h"
47 #include "Served-Cell-Information.h"
48 #include "ProtocolExtensionContainer.h"
49 #include "RRC-Version.h"
50 #include "FDD-Info.h"
51 #include "FreqBandNrItem.h"
52 #include "ServedPLMNs-Item.h"
53 #include "GNB-DU-Served-Cells-Item.h"
54 #include "SliceSupportItem.h"
55 #include "FeatureSetUplinkPerCC.h"
56 #include "SliceSupportItem.h"
57 #include "Served-Cells-To-Modify-Item.h"
58 #include "Served-Cells-To-Delete-List.h"
59 #include "Served-Cells-To-Delete-Item.h"
60 #include "QoSInformation.h"
61 #include "ULUPTNLInformation-ToBeSetup-List.h"
62 #include "DRB-Information.h"
63 #include "DRBs-ToBeSetup-Item.h"
64 #include "DRBs-ToBeSetupMod-Item.h"
65 #include "DRBs-ToBeModified-Item.h"
66 #include "CUtoDURRCInformation.h"
67 #include "SCell-ToBeSetup-List.h"
68 #include "SRBs-ToBeSetup-List.h"
69 #include "DRBs-ToBeSetup-List.h"
70 #include "SRBs-ToBeSetup-Item.h"
71 #include "DRBs-ToBeModified-List.h"
72 #include "RRCContainer.h"
73 #include "UE-CapabilityRAT-ContainerList.h"
74 #include "DRBs-Setup-List.h"
75 #include "CellGroupConfig.h"
76 #include "ResetAll.h"
77 #include "ResetType.h"
78 #include "Cells-to-be-Activated-List.h"
79 #include "GNB-CU-Name.h"
80 #include "SRBs-SetupMod-List.h"
81 #include "DRBs-SetupMod-List.h"
82 #include "DRBs-ToBeSetupMod-List.h"
83 #include "PagingCell-Item.h"
84 #include "PagingCell-list.h"
85 #include "QoS-Characteristics.h"
86 #include "ULUPTNLInformation-ToBeSetup-Item.h"
87 #include "Flows-Mapped-To-DRB-Item.h"
88 #include "NonDynamic5QIDescriptor.h"
89 #include "Dynamic5QIDescriptor.h"
90 #include "FeatureSetDownlinkPerCC.h"
91 #include "FeatureSets.h"
92 #include "UE-NR-Capability.h"
93 #include "UE-CapabilityRAT-Container.h"
94 #include "UE-CapabilityRAT-ContainerListRRC.h"
95 #include "GNB-DU-System-Information.h"
96 #include "CellGroupConfigRrc.h"
97 #include "MAC-CellGroupConfig.h"
98 #include "SchedulingRequestConfig.h"
99 #include "SchedulingRequestToAddMod.h"
100 #include "BSR-Config.h"
101 #include "TAG-Config.h"
102 #include "TAG.h"
103 #include "PHR-Config.h"
104 #include "RLC-Config.h"
105 #include "UL-AM-RLC.h"
106 #include "DL-AM-RLC.h"
107 #include "LogicalChannelConfig.h"
108 #include "RLC-BearerConfig.h"
109 #include "PhysicalCellGroupConfig.h"
110 #include "SpCellConfig.h"
111 #include "TDD-UL-DL-ConfigDedicated.h"
112 #include "ServingCellConfig.h"
113 #include "ControlResourceSet.h"
114 #include "SearchSpace.h"
115 #include "PDCCH-Config.h"
116 #include "PDSCH-TimeDomainResourceAllocation.h"
117 #include "PDSCH-TimeDomainResourceAllocationList.h"
118 #include "PDSCH-CodeBlockGroupTransmission.h"
119 #include "PDSCH-ServingCellConfig.h"
120 #include "DMRS-DownlinkConfig.h"
121 #include "PDSCH-Config.h"
122 #include "BWP-DownlinkDedicated.h"
123 #include "BWP-Downlink.h"
124 #include "PUSCH-TimeDomainResourceAllocation.h"
125 #include "PUSCH-TimeDomainResourceAllocationList.h"
126 #include "DMRS-UplinkConfig.h"
127 #include "PUSCH-Config.h"
128 #include "SRS-ResourceId.h"
129 #include "SRS-Resource.h"
130 #include "SRS-ResourceSet.h"
131 #include "SRS-Config.h"
132 #include "BWP-UplinkDedicated.h"
133 #include "PUSCH-ServingCellConfig.h"
134 #include "UplinkConfig.h"
135 #include "DUtoCURRCContainer.h"
136 #include "GBR-QoSFlowInformation.h"
137 #include "QoSFlowLevelQoSParameters.h"
138 #include "PUCCH-Config.h"
139 #include "PUCCH-ResourceSet.h"
140 #include "PUCCH-Resource.h"
141 #include "PUCCH-PowerControl.h"
142 #include "P0-PUCCH.h"
143 #include "PUCCH-PathlossReferenceRS.h"
144 #include "PUCCH-format0.h"
145 #include "PUCCH-format1.h"
146 #include "PUCCH-format2.h"
147 #include "PUCCH-format3.h"
148 #include "PUCCH-format4.h"
149 #include "PUCCH-FormatConfig.h"
150 #include "SchedulingRequestResourceConfig.h"
151 #include<ProtocolIE-Field.h>
152 #include "ProtocolExtensionField.h"
153 #include "odu_common_codec.h"
154 #include "du_mgr.h"
155 #include "du_cell_mgr.h"
156 #include "du_f1ap_msg_hdl.h"
157 #include "DRBs-Setup-Item.h"
158 #include "DLUPTNLInformation-ToBeSetup-List.h"
159 #include "DLUPTNLInformation-ToBeSetup-Item.h"
160 #include "UPTransportLayerInformation.h"
161 #include "GTPTunnel.h"
162 #include "SupportedSULFreqBandItem.h"
163 #include "du_e2ap_msg_hdl.h"
164 #include "du_f1ap_conversions.h"
165 #include "CNUEPagingIdentity.h"
166 #include "PCCH-Config.h"
167 #include "SCS-SpecificCarrier.h"
168 #include "FrequencyInfoDL.h"
169 #include "DownlinkConfigCommon.h"
170 #include "FrequencyInfoUL.h"
171 #include "UplinkConfigCommon.h"
172 #include "TDD-UL-DL-ConfigCommon.h"
173 #include "RACH-ConfigDedicated.h"
174 #include "CFRA-SSB-Resource.h"
175 #include "BWP-UplinkCommon.h"
176 #include "ReconfigurationWithSync.h"
177 #include "BCCH-DL-SCH-Message.h"
178 #include "du_sys_info_hdl.h"
179 #include "DRX-ConfigRrc.h"
180 #include "MeasurementTimingConfigurationRrc.h"
181 #include "MeasurementTimingConfigurationRrc-IEs.h"
182 #include "MeasTimingList.h"
183 #include "MeasTiming.h"
184 #include "Cells-Status-List.h"
185 #include "Cells-Status-Item.h"
186
187 #ifdef O1_ENABLE
188 #include "CmInterface.h"
189 extern StartupConfig g_cfg;
190 #endif
191
192 DuCfgParams duCfgParam;
193
194 /******************************************************************
195  *
196  * @brief Function to fetch lcId based on DRB Id
197  *
198  * @details
199  *
200  *    Function : fetchLcId
201  *
202  *    @params[in] drbId
203  *
204  *    Functionality: Function to fetch lcId based on DRB Id
205  *
206  * Returns: lcId - SUCCESS
207  *          RFAILED - FAILURE
208  *****************************************************************/
209
210 uint8_t fetchLcId(uint8_t drbId)
211 {
212    uint8_t cellIdx = 0, ueIdx = 0, lcIdx = 0, numLcs = 0, lcId = 0;
213
214    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
215    {
216       for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
217       {
218          if(duCb.actvCellLst[cellIdx] != NULLP)
219          {
220             numLcs = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.numLcs;
221             for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
222             {
223                if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId == drbId && \
224                   duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
225                {
226                   lcId = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId;
227                   return lcId;
228                }
229             }
230          }
231       }
232    }
233    DU_LOG("\nERROR   -->  DU_APP: fetchLcId() failed for drbId %d", drbId);
234    return RFAILED;
235 }
236
237 /*******************************************************************
238 *
239 * @brief Adding F1AP pdu to reserved pdu list
240 *
241 * @details
242 *
243 *    Function : addToReservedF1apPduList 
244 *
245 *    Functionality: Adding F1AP pdu to reserved pdu list.
246 *     These pdu are awaiting aknowledgment from CU
247 *
248 * @params[in] uint8_t transId, F1AP_PDU_t *f1apMsg
249 *
250 * @return ROK - success
251 *         RFAILED - failure
252 *
253 * ****************************************************************/
254 void addToReservedF1apPduList(uint8_t transId, F1AP_PDU_t *f1apPdu)
255 {
256    CmLList         *node = NULLP;
257    ReservedF1apPduInfo *pduInfo = NULLP;
258    DU_ALLOC(pduInfo, sizeof(ReservedF1apPduInfo));
259    if(pduInfo)
260    {
261       DU_ALLOC(node, sizeof(CmLList));
262       if(node)
263       {
264          pduInfo->transId = transId;
265          pduInfo->f1apMsg = (void*) f1apPdu;
266
267          node->node = (PTR)pduInfo;
268          cmLListAdd2Tail(&duCb.reservedF1apPduList, node);
269       }
270    }
271 }
272
273 /*******************************************************************
274 *
275 * @brief searching for F1AP pdu from ReservedF1apPduList 
276 *
277 * @details
278 *
279 *    Function : searchFromReservedF1apPduList 
280 *
281 *    Functionality: searching for F1AP pdu information
282 *
283 * @params[in] uint8_t transId
284 *
285 * @return pointer to F1AP_PDU_t
286 *
287 * ****************************************************************/
288
289 CmLList *searchFromReservedF1apPduList(uint8_t transId)
290 {
291    CmLList         *node;
292    ReservedF1apPduInfo *f1apPdu;
293    if(duCb.reservedF1apPduList.count)
294    {
295       CM_LLIST_FIRST_NODE(&duCb.reservedF1apPduList, node);
296       while(node)
297       {
298          f1apPdu = (ReservedF1apPduInfo*)node->node;
299          if(f1apPdu->transId == transId)
300          {
301             return node;
302          }
303          node = node->next;
304       }
305    }
306    return NULL;
307 }
308
309 /*******************************************************************
310 *
311 * @brief deleting F1AP pdu information from ReservedF1apPduList
312 *
313 * @details
314 *
315 *    Function : deleteFromReservedF1apPduList 
316 *
317 *    Functionality: deleting pdu information from ReservedF1apPduList
318 *
319 * @params[in] CmLList *node 
320 *
321 * @return void 
322 *
323 * ****************************************************************/
324
325 void deleteFromReservedF1apPduList(CmLList *node)
326 {
327    ReservedF1apPduInfo *f1apPdu;
328
329    if(node != NULL)
330    {
331       f1apPdu = (ReservedF1apPduInfo *)node->node;
332       cmLListDelFrm(&duCb.reservedF1apPduList, node);
333       DU_FREE(f1apPdu, sizeof(ReservedF1apPduInfo));
334       DU_FREE(node, sizeof(CmLList));
335       node = NULL;
336    }
337 }
338
339 /*******************************************************************
340  *
341  * @brief Builds Uplink Info for NR 
342  *
343  * @details
344  *
345  *    Function : BuildULNRInfo
346  *
347  *    Functionality: Building NR Uplink Info
348  *
349  * @params[in] NRFreqInfo_t *ulnrfreq
350  * @return ROK     - success
351  *         RFAILED - failure
352  *
353  * ****************************************************************/
354 uint8_t BuildULNRInfo(NRFreqInfo_t *ulnrfreq)
355 {
356    uint8_t idx=0;
357    ulnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
358                        fdd.ulNrFreqInfo.nrArfcn;
359    ulnrfreq->freqBandListNr.list.count = 1;
360    ulnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
361    DU_ALLOC(ulnrfreq->freqBandListNr.list.array,ulnrfreq->freqBandListNr.list.size);
362    if(ulnrfreq->freqBandListNr.list.array == NULLP)
363    {
364       return RFAILED;
365    }
366    for(idx=0;idx<ulnrfreq->freqBandListNr.list.count;idx++)
367    {
368       DU_ALLOC(ulnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
369       if(ulnrfreq->freqBandListNr.list.array[idx] == NULLP)
370       {
371          return RFAILED;
372       }
373    }
374    ulnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
375                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
376                                                                  freqBand[0].nrFreqBand;
377    ulnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
378    return ROK;
379 }
380 /*******************************************************************
381  *
382  * @brief Builds Downlink NR Info 
383  *
384  * @details
385  *
386  *    Function : BuildDLNRInfo
387  *
388  *    Functionality: Building Downlink NR Info
389  *    
390  * @params[in] NRFreqInfo_t *dlnrfreq
391  * @return ROK     - success
392  *         RFAILED - failure
393  *
394  * ****************************************************************/
395 uint8_t BuildDLNRInfo(NRFreqInfo_t *dlnrfreq)
396 {
397    uint8_t idx=0;
398    dlnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
399                        fdd.dlNrFreqInfo.nrArfcn;
400    dlnrfreq->freqBandListNr.list.count = 1;
401    dlnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
402    DU_ALLOC(dlnrfreq->freqBandListNr.list.array,dlnrfreq->freqBandListNr.list.size);
403    if(dlnrfreq->freqBandListNr.list.array == NULLP)
404    {
405       return RFAILED;   
406    }
407    for(idx=0;idx< dlnrfreq->freqBandListNr.list.count;idx++)
408    {
409       DU_ALLOC(dlnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
410       if(dlnrfreq->freqBandListNr.list.array[idx] == NULLP)
411       {
412          return RFAILED;
413       }
414    }   
415    dlnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
416                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
417                                                                  freqBand[0].nrFreqBand;
418    dlnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
419
420    return ROK;
421 }
422
423 /*******************************************************************
424  *
425  * @brief Builds Nrcgi 
426  *
427  * @details
428  *
429  *    Function : BuildNrcgi
430  *
431  *    Functionality: Building the PLMN ID and NR Cell id
432  *
433  * @params[in] NRCGI_t *nrcgi
434  * @return ROK     - success
435  *         RFAILED - failure
436  *
437  * ****************************************************************/
438 uint8_t BuildNrcgi(NRCGI_t *nrcgi)
439 {
440    uint8_t ret;
441    uint8_t byteSize = 5;
442    /* Allocate Buffer Memory */
443    nrcgi->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
444    DU_ALLOC(nrcgi->pLMN_Identity.buf, nrcgi->pLMN_Identity.size);
445    if(nrcgi->pLMN_Identity.buf == NULLP)
446    {
447       return RFAILED;
448    }
449    ret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
450          nrcgi->pLMN_Identity.buf); // Building PLMN function
451    if(ret != ROK)
452    {
453       return RFAILED;
454    }
455    /*nrCellIdentity*/
456    nrcgi->nRCellIdentity.size = byteSize * sizeof(uint8_t);
457    DU_ALLOC(nrcgi->nRCellIdentity.buf, nrcgi->nRCellIdentity.size); 
458    if(nrcgi->nRCellIdentity.buf == NULLP)
459    {
460       return RFAILED;
461    }
462    fillBitString(&nrcgi->nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
463
464    return ROK;
465 }
466 /*******************************************************************
467  *
468  * @brief Builds FiveGStac 
469  *
470  * @details
471  *
472  *    Function : BuildFiveGSTac
473  *
474  *    Functionality: Building the FiveGSTac
475  *
476  * @params[in] OCTET_STRING_t *fivegsTac
477  * @return ROK     - success
478  *         RFAILED - failure
479  *
480  * ****************************************************************/
481 uint8_t BuildFiveGSTac(Served_Cell_Information_t *servcell)
482 {
483    DU_ALLOC(servcell->fiveGS_TAC,sizeof(FiveGS_TAC_t));
484    if(servcell->fiveGS_TAC == NULLP)
485    {
486       return RFAILED;
487    }
488    servcell->fiveGS_TAC->size = 3 * sizeof(uint8_t);
489    DU_ALLOC(servcell->fiveGS_TAC->buf,\
490          sizeof(servcell->fiveGS_TAC->size));
491    if(servcell->fiveGS_TAC->buf == NULLP)
492    {
493       return RFAILED;
494    }
495    servcell->fiveGS_TAC->buf[0] = 0;
496    servcell->fiveGS_TAC->buf[1] = 0;
497    servcell->fiveGS_TAC->buf[2] = duCfgParam.srvdCellLst[0].duCellInfo.tac;
498    return ROK;  
499 }
500
501 /*******************************************************************
502  *
503  * @brief fill nr frequency information
504  *
505  * @details
506  *
507  *    Function : fillNrTddInfo 
508  *
509  *    Functionality: fill nr frequency information
510  *
511  * @params[in] NRFreqInfo_t freqInfo
512  * @return ROK     - success
513  *         RFAILED - failure
514  *
515  * ****************************************************************/
516 uint8_t fillNrTddInfo(TDD_Info_t *tddInfo)
517 {
518    uint8_t elementCnt = 1, freqBandListIdx = 0, supportedBandIdx = 0;
519    NRFreqInfo_t *freqInfo = NULLP;
520
521    if(tddInfo == NULLP)
522    {
523       DU_LOG("\nERROR  --> DU APP : Null pointer received at fillNrTddInfo");
524       return RFAILED;
525    }
526    
527    freqInfo = &tddInfo->nRFreqInfo;
528    freqInfo->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.nrArfcn; 
529
530    freqInfo->freqBandListNr.list.count = elementCnt; 
531    freqInfo->freqBandListNr.list.size = freqInfo->freqBandListNr.list.count  * sizeof(FreqBandNrItem_t *);
532    DU_ALLOC(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
533    if(!freqInfo->freqBandListNr.list.array)
534    {
535       DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
536       return RFAILED;
537    }
538
539    for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
540    {
541       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
542       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx])
543       {
544          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
545          return RFAILED;
546       }
547
548       freqInfo->freqBandListNr.list.array[freqBandListIdx]->freqBandIndicatorNr = duCfgParam.srvdCellLst[0].duCellInfo.\
549       f1Mode.mode.tdd.nrFreqInfo.freqBand[0].nrFreqBand;
550
551       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count = elementCnt;
552       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size = freqInfo->freqBandListNr.list.array[freqBandListIdx]->\
553       supportedSULBandList.list.count * sizeof(SupportedSULFreqBandItem_t*);
554
555       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
556             freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
557       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
558       {
559          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
560          return RFAILED;
561       }
562
563       for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
564       {
565          DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
566                sizeof(SupportedSULFreqBandItem_t));
567          if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx])
568          {
569             DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
570             return RFAILED;
571          }
572
573          freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx]->freqBandIndicatorNr =\
574          duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[0].sulBand[0];
575       }
576    }
577
578    tddInfo->transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrScs;
579    tddInfo->transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrb;
580
581    return ROK;
582 }
583
584 /*******************************************************************
585  *
586  * @brief Builds NR Mode 
587  *
588  * @details
589  *
590  *    Function : BuildNrMode
591  *
592  *    Functionality: Building the NR Mode
593  *
594  * @params[in] NR_Mode_Info_t *fdd
595  * @return ROK     - success
596  *         RFAILED - failure
597  *
598  * ****************************************************************/
599 uint8_t BuildNrMode(NR_Mode_Info_t *mode)
600 {
601    uint8_t BuildDLNRInforet=0;
602    uint8_t BuildULNRInforet=0; 
603    
604 #ifdef NR_TDD
605    mode->present = NR_Mode_Info_PR_tDD;
606 #else
607    mode->present = NR_Mode_Info_PR_fDD;
608 #endif   
609    
610    if(mode->present == NR_Mode_Info_PR_fDD)
611    {
612       DU_ALLOC(mode->choice.fDD,sizeof(FDD_Info_t));
613       if(mode->choice.fDD == NULLP)
614       {
615          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
616          return RFAILED;
617       }
618       BuildULNRInforet = BuildULNRInfo(&mode->choice.fDD->uL_NRFreqInfo);
619       if(BuildULNRInforet != ROK)
620       {
621          DU_LOG("\nERROR  --> Failed to build UlNrFreqInfo");
622          return RFAILED;    
623       }
624       BuildDLNRInforet = BuildDLNRInfo(&mode->choice.fDD->dL_NRFreqInfo);
625       if(BuildDLNRInforet != ROK)
626       {
627          DU_LOG("\nERROR  --> Failed to build DlNrFreqInfo");
628          return RFAILED;
629       }
630       mode->choice.fDD->uL_Transmission_Bandwidth.nRSCS = \
631                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
632                                                           f1Mode.mode.fdd.ulTxBw.nrScs;
633       mode->choice.fDD->uL_Transmission_Bandwidth.nRNRB = \
634                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
635                                                           f1Mode.mode.fdd.ulTxBw.nrb;
636       mode->choice.fDD->dL_Transmission_Bandwidth.nRSCS = \
637                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
638                                                           f1Mode.mode.fdd.dlTxBw.nrScs;
639       mode->choice.fDD->dL_Transmission_Bandwidth.nRNRB = \
640                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
641                                                           f1Mode.mode.fdd.dlTxBw.nrb;
642    }
643    else if(mode->present == NR_Mode_Info_PR_tDD) 
644    {
645       DU_ALLOC(mode->choice.tDD,sizeof(TDD_Info_t));
646       if(mode->choice.tDD == NULLP)
647       {
648          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
649          return RFAILED;
650       }
651
652       if(fillNrTddInfo(mode->choice.tDD) != ROK)
653       {
654          DU_LOG("\nERROR  --> Failed to fill Nr TDD information");
655          return RFAILED;
656       }
657
658    }
659
660    return ROK;
661 }
662 /*******************************************************************
663  *
664  * @brief Builds IE Extensions for Served PLMNs 
665  *
666  * @details
667  *
668  *    Function : BuildExtensions
669  *
670  *    Functionality: Building the IE Extensions
671  *
672  * @params[in] struct ProtocolExtensionContainer_4624P3 *buildextend
673  * @return ROK     - success
674  *         RFAILED - failure
675  *
676  * ****************************************************************/
677 uint8_t BuildExtensions(ProtocolExtensionContainer_4624P3_t **ieExtend)
678 {
679    uint8_t idx=0, plmnidx=0, sliceLstIdx=0;
680    uint8_t elementCnt=0, extensionCnt=0;
681
682    extensionCnt=IE_EXTENSION_LIST_COUNT;
683    DU_ALLOC(*ieExtend,sizeof(ProtocolExtensionContainer_4624P3_t));
684    if((*ieExtend) == NULLP)
685    {
686       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
687       return RFAILED;
688    }
689    (*ieExtend)->list.count = extensionCnt;
690    (*ieExtend)->list.size = \
691                             extensionCnt * sizeof(ServedPLMNs_ItemExtIEs_t *);
692    DU_ALLOC((*ieExtend)->list.array,(*ieExtend)->list.size);
693    if((*ieExtend)->list.array == NULLP)
694    {
695       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
696       return RFAILED;
697    }
698    for(plmnidx=0;plmnidx<extensionCnt;plmnidx++)
699    {
700       DU_ALLOC((*ieExtend)->list.array[plmnidx],\
701             sizeof(ServedPLMNs_ItemExtIEs_t));
702       if((*ieExtend)->list.array[plmnidx] == NULLP)
703       {
704          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
705          return RFAILED;
706       }
707    }
708    
709    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices;
710    idx = 0;
711    (*ieExtend)->list.array[idx]->id = ProtocolIE_ID_id_TAISliceSupportList;
712    (*ieExtend)->list.array[idx]->criticality = Criticality_ignore;
713    (*ieExtend)->list.array[idx]->extensionValue.present = \
714    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
715    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
716       list.count = elementCnt;
717    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
718       list.size = (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
719       list.count * sizeof(SliceSupportItem_t *);
720
721    DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
722          list.array, elementCnt * sizeof(SliceSupportItem_t *));
723    if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
724          list.array == NULLP)
725    {
726       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
727       return RFAILED;
728    }
729
730    for(sliceLstIdx =0; sliceLstIdx<elementCnt; sliceLstIdx++)
731    {
732       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
733             list.array[sliceLstIdx],sizeof(SliceSupportItem_t));
734       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
735             list.array[sliceLstIdx] == NULLP) 
736       {
737          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
738          return RFAILED;
739       }
740       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
741          list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
742       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
743             .list.array[sliceLstIdx]->sNSSAI.sST.buf,(*ieExtend)->list.array[idx]->\
744             extensionValue.choice.SliceSupportList.\
745             list.array[sliceLstIdx]->sNSSAI.sST.size);
746       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
747             .list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
748       {
749          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
750          return RFAILED;
751       }
752       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
753          list.array[sliceLstIdx]->sNSSAI.sST.buf[0] = duCfgParam.srvdCellLst[0].duCellInfo.\
754          cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
755       
756       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
757             list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
758       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
759             list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
760       {
761          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
762          return RFAILED;
763       }
764       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
765          list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
766       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
767             list.array[sliceLstIdx]->sNSSAI.sD->buf, (*ieExtend)->list.array[idx]->extensionValue.choice.\
768             SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
769       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
770             list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
771       {
772          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
773          return RFAILED;
774       }
775       memcpy((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
776       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[0].duCellInfo.\
777       cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sd, (*ieExtend)->list.array[idx]->\
778       extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
779    }
780    return ROK;
781 }
782 /*******************************************************************
783  *
784  * @brief Builds Served PLMN 
785  *
786  * @details
787  *
788  *    Function : BuildServedPlmn
789  *
790  *    Functionality: Building the Served PLMN
791  *
792  * @params[in] GNB_DU_Served_Cells_Item_t *srvCellItem
793  * @return ROK     - success
794  *         RFAILED - failure
795  *
796  * ****************************************************************/
797 uint8_t  BuildServedPlmn(ServedPLMNs_List_t *srvplmn)
798 {  
799    uint8_t  plmnidx;
800    uint8_t  servPlmnCnt=1;
801    uint8_t buildPlmnIdret=0;
802    uint8_t BuildExtensionsret=0;
803    srvplmn->list.count = servPlmnCnt;
804    srvplmn->list.size = \
805                         servPlmnCnt*sizeof(ServedPLMNs_Item_t *);
806    DU_ALLOC(srvplmn->list.array,srvplmn->list.size);
807    if(srvplmn->list.array == NULLP)
808    {
809       return RFAILED;
810    }
811    for(plmnidx=0; plmnidx<servPlmnCnt; plmnidx++)
812    {   
813       DU_ALLOC(srvplmn->list.array[plmnidx],\
814             sizeof(ServedPLMNs_Item_t));
815       if(srvplmn->list.array[plmnidx] == NULLP)
816       {
817          return RFAILED;
818       }  
819    }
820    srvplmn->list.array[0]->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
821    DU_ALLOC(srvplmn->list.array[0]->pLMN_Identity.buf, srvplmn->list.array[0]->pLMN_Identity.size);
822    buildPlmnIdret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
823          srvplmn->list.array[0]->pLMN_Identity.buf);
824    if(buildPlmnIdret!= ROK)
825    {
826       return RFAILED;
827    }
828    BuildExtensionsret = BuildExtensions(&srvplmn->list.array[0]->iE_Extensions);
829    if(BuildExtensionsret!= ROK)
830    {
831       return RFAILED;
832    }
833    return ROK;
834 }
835
836 /*******************************************************************
837  *
838  * @brief Frees Measurement Timing configuration 
839  *
840  * @details
841  *
842  *    Function : FreeMeasTimingConf
843  *
844  *    Functionality: Frees Timing Configuration
845  *
846  * @params[in] MeasurementTimingConfigurationRrc_t measTimingConfRrc
847  * @return ROK     - success
848  *         RFAILED - failure
849  *
850  * ****************************************************************/
851 void FreeMeasTimingConf(MeasurementTimingConfigurationRrc_t   measTimingConfRrc)
852 {
853    uint8_t measIeIdx = 0;
854    MeasurementTimingConfigurationRrc_IEs_t  *measTimingConfIEs = NULLP;
855
856    if(measTimingConfRrc.criticalExtensions.choice.c1)
857    {
858       if(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf)
859       {
860          measTimingConfIEs = measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf;
861          if(measTimingConfIEs->measTiming)
862          {
863             if(measTimingConfIEs->measTiming->list.array)
864             {
865                for(measIeIdx = 0; measIeIdx < measTimingConfIEs->measTiming->list.count; measIeIdx++)
866                {
867                   if(measTimingConfIEs->measTiming->list.array[measIeIdx])
868                   {
869                      DU_FREE(measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming, sizeof(struct MeasTiming__frequencyAndTiming));
870                      DU_FREE(measTimingConfIEs->measTiming->list.array[measIeIdx], sizeof(MeasTiming_t));
871                   }
872                }
873                DU_FREE(measTimingConfIEs->measTiming->list.array, measTimingConfIEs->measTiming->list.size);
874             }
875             DU_FREE(measTimingConfIEs->measTiming, sizeof(MeasTimingList_t));
876          }
877          DU_FREE(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf, sizeof(MeasurementTimingConfigurationRrc_IEs_t));
878       }
879       DU_FREE(measTimingConfRrc.criticalExtensions.choice.c1, sizeof(struct MeasurementTimingConfigurationRrc__criticalExtensions__c1));
880    }
881 }
882
883 /*******************************************************************
884  *
885  * @brief Builds MEasuerment Timing Configuration
886  *
887  * @details
888  *
889  *    Function : BuildMeasTimingConf
890  *
891  *    Functionality: Building Measurement Timing Configuration
892  *
893  * @params[in] Pointer to octet string to store Measurement timing
894  *             Configuration
895  * @return ROK     - success
896  *         RFAILED - failure
897  *
898  * ****************************************************************/
899 uint8_t BuildMeasTimingConf(OCTET_STRING_t *measTimingConf)
900 {
901    uint8_t ret = RFAILED;
902    uint8_t elementCnt = 0;
903    uint8_t measIeIdx = 0;
904    asn_enc_rval_t encRetVal;
905    MeasurementTimingConfigurationRrc_t   measTimingConfRrc;
906    MeasurementTimingConfigurationRrc_IEs_t  *measTimingConfIEs = NULLP;
907    struct MeasTiming__frequencyAndTiming  *freqAndTiming = NULLP;
908
909    while(true)
910    {
911       measTimingConfRrc.criticalExtensions.present = MeasurementTimingConfigurationRrc__criticalExtensions_PR_c1;
912       DU_ALLOC(measTimingConfRrc.criticalExtensions.choice.c1, sizeof(struct MeasurementTimingConfigurationRrc__criticalExtensions__c1));
913       if(!measTimingConfRrc.criticalExtensions.choice.c1)
914       {
915          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for critical extension choice C1");
916          break;
917       }
918       measTimingConfRrc.criticalExtensions.choice.c1->present = MeasurementTimingConfigurationRrc__criticalExtensions__c1_PR_measTimingConf;
919
920       DU_ALLOC(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf, sizeof(MeasurementTimingConfigurationRrc_IEs_t));
921       if(!measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf)
922       {
923          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for measTimingConf");
924          break;
925       }
926       measTimingConfIEs = measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf;
927
928       DU_ALLOC(measTimingConfIEs->measTiming, sizeof(MeasTimingList_t));
929       if(!measTimingConfIEs->measTiming)
930       {
931          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList");
932          break;
933       }
934
935       elementCnt = 1;  
936       measTimingConfIEs->measTiming->list.count = elementCnt;
937       measTimingConfIEs->measTiming->list.size = elementCnt * sizeof(MeasTiming_t *);
938       DU_ALLOC(measTimingConfIEs->measTiming->list.array, measTimingConfIEs->measTiming->list.size);
939       if(!measTimingConfIEs->measTiming->list.array)
940       {
941          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList array");
942          break;
943       }
944
945       for(measIeIdx = 0; measIeIdx < elementCnt; measIeIdx++)
946       {
947          DU_ALLOC(measTimingConfIEs->measTiming->list.array[measIeIdx], sizeof(MeasTiming_t));
948          if(!measTimingConfIEs->measTiming->list.array[measIeIdx])
949          {
950             DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList array index %d", measIeIdx);
951             break;
952          }
953       }
954       if(measIeIdx < elementCnt)
955       {
956          break;
957       }
958
959       measIeIdx = 0;
960       DU_ALLOC(measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming, sizeof(struct MeasTiming__frequencyAndTiming));
961       if(!measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming)
962       {
963          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for frequencyAndTiming");
964          break;
965       }
966       freqAndTiming = measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming;
967       freqAndTiming->carrierFreq = MEAS_TIMING_ARFCN;
968       freqAndTiming->ssbSubcarrierSpacing = duCfgParam.macCellCfg.ssbCfg.scsCmn;
969       freqAndTiming->ssb_MeasurementTimingConfiguration.periodicityAndOffset.present = duCfgParam.macCellCfg.ssbCfg.ssbPeriod + 1;
970       freqAndTiming->ssb_MeasurementTimingConfiguration.periodicityAndOffset.choice.sf20 = duCfgParam.macCellCfg.ssbCfg.ssbScOffset;
971       freqAndTiming->ssb_MeasurementTimingConfiguration.duration = duCfgParam.srvdCellLst[0].duCellInfo.measTimeCfgDuration;
972
973       /* Encode the F1SetupRequest type as APER */
974       xer_fprint(stdout, &asn_DEF_MeasurementTimingConfigurationRrc, &measTimingConfRrc);
975
976       memset(encBuf, 0, ENC_BUF_MAX_LEN);
977       encBufSize = 0;
978       encRetVal = uper_encode(&asn_DEF_MeasurementTimingConfigurationRrc, 0, &measTimingConfRrc, PrepFinalEncBuf, encBuf);
979
980       /* Encode results */
981       if(encRetVal.encoded == ENCODE_FAIL)
982       {     
983          DU_LOG("\nERROR  -->  F1AP : Could not encode Measurement Timing Configuration structure (at %s)\n",\
984                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
985          break;
986       }     
987       else  
988       {     
989          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Measurement Timing Configuration \n");
990 #ifdef DEBUG_ASN_PRINT
991          for(measIeIdx=0; measIeIdx< encBufSize; measIeIdx++)
992          {
993             printf("%x",encBuf[measIeIdx]);
994          }
995 #endif
996
997          measTimingConf->size = encBufSize;
998          DU_ALLOC(measTimingConf->buf, encBufSize);
999          if(measTimingConf->buf == NULLP)
1000          {
1001             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed for MeasurementTimingConfiguration buffer");
1002             return RFAILED;
1003          }
1004          memcpy(measTimingConf->buf, &encBuf, encBufSize);
1005
1006          FreeMeasTimingConf(measTimingConfRrc);
1007
1008          ret = ROK;
1009          break;
1010       }
1011    }
1012    return ret;
1013 }
1014
1015 /*******************************************************************
1016  *
1017  * @brief Builds Served Cell List
1018  *
1019  * @details
1020  *
1021  *    Function : BuildServedCellList
1022  *
1023  *    Functionality: Building Served Cell List
1024  *
1025  * @params[in] PLMNID plmn
1026  * @return ROK     - success
1027  *         RFAILED - failure
1028  *
1029  * ****************************************************************/
1030
1031 uint8_t BuildServedCellList(GNB_DU_Served_Cells_List_t *duServedCell)
1032 {
1033    uint8_t  BuildNrcgiret=0;
1034    uint8_t  BuildFiveGSTacret=0;
1035    uint8_t  BuildServedPlmnret=0;
1036    uint8_t  BuildNrModeret=0;
1037    uint8_t  idx;
1038    uint8_t  plmnidx;
1039    uint8_t  plmnCnt=1;
1040    GNB_DU_Served_Cells_Item_t *srvCellItem;
1041    duServedCell->list.size = plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t *);
1042    duServedCell->list.count = plmnCnt;
1043
1044    DU_ALLOC(duServedCell->list.array, duServedCell->list.size);
1045    if(duServedCell->list.array == NULLP)
1046    {
1047       return RFAILED;
1048    }
1049    for(plmnidx=0; plmnidx<plmnCnt; plmnidx++)
1050    {
1051       DU_ALLOC(duServedCell->list.array[plmnidx],\
1052             sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1053       if(duServedCell->list.array[plmnidx] == NULLP)
1054       {
1055          return RFAILED;
1056       }
1057    }
1058    idx = 0;
1059    duServedCell->list.array[idx]->id = ProtocolIE_ID_id_GNB_DU_Served_Cells_Item;
1060    duServedCell->list.array[idx]->criticality = Criticality_reject;
1061    duServedCell->list.array[idx]->value.present = \
1062                                                   GNB_DU_Served_Cells_ItemIEs__value_PR_GNB_DU_Served_Cells_Item;
1063    srvCellItem = \
1064                  &duServedCell->list.array[idx]->value.choice.GNB_DU_Served_Cells_Item;
1065    /*nRCGI*/
1066    BuildNrcgiret = BuildNrcgi(&srvCellItem->served_Cell_Information.nRCGI);
1067    if(BuildNrcgiret != ROK)
1068    {
1069       return RFAILED;
1070    }
1071    /*nRPCI*/
1072    srvCellItem->served_Cell_Information.nRPCI = \
1073                                                 duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
1074
1075    /* fiveGS_TAC */
1076    BuildFiveGSTacret = BuildFiveGSTac(&srvCellItem->served_Cell_Information);
1077    if(BuildFiveGSTacret != ROK)
1078    {
1079       return RFAILED;
1080    }
1081
1082    /* Served PLMNs */
1083    BuildServedPlmnret = BuildServedPlmn(&srvCellItem->served_Cell_Information.servedPLMNs);
1084    if(BuildServedPlmnret !=ROK)
1085    {
1086       return RFAILED;
1087    }
1088
1089    /* nR Mode Info with FDD/TDD */
1090    BuildNrModeret = BuildNrMode(&srvCellItem->served_Cell_Information.nR_Mode_Info);
1091    if(BuildNrModeret != ROK)
1092    {
1093       return RFAILED;
1094    }
1095
1096    /*Measurement timing Config*/
1097    if(BuildMeasTimingConf(&srvCellItem->served_Cell_Information.measurementTimingConfiguration) != ROK)
1098       return RFAILED;
1099
1100    /* GNB DU System Information */
1101    DU_ALLOC(srvCellItem->gNB_DU_System_Information,
1102          sizeof(GNB_DU_System_Information_t));
1103    if(!srvCellItem->gNB_DU_System_Information)
1104    {
1105       return RFAILED;
1106    }
1107    /* MIB */
1108    srvCellItem->gNB_DU_System_Information->mIB_message.size = duCfgParam.srvdCellLst[0].duSysInfo.mibLen;
1109    DU_ALLOC(srvCellItem->gNB_DU_System_Information->mIB_message.buf,
1110          srvCellItem->gNB_DU_System_Information->mIB_message.size);
1111    if(!srvCellItem->gNB_DU_System_Information->mIB_message.buf)
1112    {
1113       return RFAILED;
1114    }
1115    memcpy(srvCellItem->gNB_DU_System_Information->mIB_message.buf, duCfgParam.srvdCellLst[0].duSysInfo.mibMsg, \
1116          srvCellItem->gNB_DU_System_Information->mIB_message.size);
1117
1118    /* SIB1 */
1119    srvCellItem->gNB_DU_System_Information->sIB1_message.size =\
1120                                                               duCfgParam.srvdCellLst[0].duSysInfo.sib1Len;
1121
1122    DU_ALLOC(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,
1123          srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1124    if(!srvCellItem->gNB_DU_System_Information->sIB1_message.buf)
1125    {
1126       return RFAILED;
1127    }
1128    for(int x=0; x<srvCellItem->gNB_DU_System_Information->sIB1_message.size; x++)
1129    {
1130       srvCellItem->gNB_DU_System_Information->sIB1_message.buf[x]=\
1131                                                                   duCfgParam.srvdCellLst[0].duSysInfo.sib1Msg[x];
1132    }
1133    return ROK; 
1134 }                                                                                                                  
1135 /*******************************************************************
1136  *
1137  * @brief Builds RRC Version 
1138  *
1139  * @details
1140  *
1141  *    Function : BuildRrcVer
1142  *
1143  *    Functionality: Building RRC Version
1144  *
1145  * @params[in] int idx,int elementCnt,RRC_Version_t *rrcver
1146  * @return ROK     - success
1147  *         RFAILED - failure
1148  *
1149  * ****************************************************************/
1150 uint8_t BuildRrcVer(RRC_Version_t *rrcVer)
1151 {
1152    uint8_t rrcExt;
1153    uint8_t rrcLatest;
1154    rrcVer->latest_RRC_Version.size = sizeof(uint8_t);
1155    DU_ALLOC(rrcVer->latest_RRC_Version.buf,sizeof(uint8_t));
1156    if(rrcVer->latest_RRC_Version.buf == NULLP)
1157    {
1158       return RFAILED;
1159    }
1160    rrcVer->latest_RRC_Version.buf[0] = 0;
1161    rrcVer->latest_RRC_Version.bits_unused = 5;
1162    DU_ALLOC(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1163    if(rrcVer->iE_Extensions == NULLP)
1164    {  
1165       return RFAILED;
1166    }
1167    rrcVer->iE_Extensions->list.count = 1;
1168    rrcVer->iE_Extensions->list.size = sizeof(RRC_Version_ExtIEs_t *);
1169    DU_ALLOC(rrcVer->iE_Extensions->list.array,rrcVer->iE_Extensions->list.size);
1170    if(rrcVer->iE_Extensions->list.array == NULLP)
1171    {
1172       return RFAILED;
1173    }
1174    rrcExt = 0;
1175    DU_ALLOC(rrcVer->iE_Extensions->list.array[0],\
1176          sizeof(RRC_Version_ExtIEs_t));
1177    if(rrcVer->iE_Extensions->list.array[0] == NULLP)
1178    {
1179       return RFAILED;
1180    }
1181    rrcVer->iE_Extensions->list.array[rrcExt]->id = \
1182                                                    ProtocolIE_ID_id_latest_RRC_Version_Enhanced;
1183    rrcVer->iE_Extensions->list.array[rrcExt]->criticality = Criticality_reject;
1184    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.present =\
1185                                                                       RRC_Version_ExtIEs__extensionValue_PR_Latest_RRC_Version_Enhanced;
1186    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1187       .Latest_RRC_Version_Enhanced.size = 3*sizeof(uint8_t);
1188    DU_ALLOC(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1189          .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1190          array[rrcExt]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1191    if(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1192          .Latest_RRC_Version_Enhanced.buf == NULLP)
1193    {
1194       return RFAILED;
1195    }
1196    rrcLatest = 0;
1197    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1198       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 15;
1199    rrcLatest++;
1200    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1201       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 5;
1202    rrcLatest++;
1203    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1204       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 0;
1205    return ROK;
1206 }
1207 /*******************************************************************
1208  *
1209  * @brief Sends F1 msg over SCTP
1210  *
1211  * @details
1212  *
1213  *    Function : sendF1APMsg
1214  *
1215  *    Functionality: Sends F1 msg over SCTP
1216  *
1217  * @params[in] Region region
1218  *             Pool pool
1219  * @return ROK     - success
1220  *         RFAILED - failure
1221  *
1222  * ****************************************************************/
1223 uint8_t sendF1APMsg()
1224 {
1225    Buffer *mBuf = NULLP;
1226   
1227    if(ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) == ROK)
1228    {
1229       if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
1230       {
1231             ODU_PRINT_MSG(mBuf, 0,0);
1232
1233             if(sctpSend(mBuf, F1_INTERFACE) != ROK)
1234             {
1235                DU_LOG("\nERROR  -->  F1AP : SCTP Send failed");
1236                ODU_PUT_MSG_BUF(mBuf);
1237                return RFAILED;
1238             }
1239       }
1240       else
1241       {
1242          DU_LOG("\nERROR  -->  F1AP : ODU_ADD_POST_MSG_MULT failed");
1243          ODU_PUT_MSG_BUF(mBuf);
1244          return RFAILED;
1245       }
1246       ODU_PUT_MSG_BUF(mBuf);
1247    }
1248    else
1249    {
1250       DU_LOG("\nERROR  -->  F1AP : Failed to allocate memory");
1251       return RFAILED;
1252    }
1253    return ROK; 
1254 } /* sendF1APMsg */
1255
1256 /*******************************************************************
1257  *
1258  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1259  *
1260  * @details
1261  *
1262  *    Function :  FreeRrcVer
1263  *
1264  *    Functionality: deallocating the memory of function BuildRrcVer
1265  *
1266  * @params[in] RRC_Version_t *rrcVer
1267  * 
1268  * @return void
1269  *
1270  *****************************************************************/
1271 void FreeRrcVer(RRC_Version_t *rrcVer)
1272 {
1273    if(rrcVer->latest_RRC_Version.buf != NULLP)
1274    {
1275       if(rrcVer->iE_Extensions != NULLP)
1276       {
1277          if(rrcVer->iE_Extensions->list.array != NULLP)
1278          {
1279             if(rrcVer->iE_Extensions->list.array[0] != NULLP)
1280             {
1281                if(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf
1282                      != NULLP)
1283                {
1284                   DU_FREE(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice\
1285                         .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1286                         array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1287                }
1288                DU_FREE(rrcVer->iE_Extensions->list.array[0],sizeof(RRC_Version_ExtIEs_t));
1289             }
1290             DU_FREE(rrcVer->iE_Extensions->list.array,sizeof(RRC_Version_ExtIEs_t*));
1291          }
1292          DU_FREE(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1293       }
1294       DU_FREE(rrcVer->latest_RRC_Version.buf,rrcVer->latest_RRC_Version.size);
1295    }
1296 }
1297
1298 /*******************************************************************
1299  *
1300  * @brief Deallocating memory of TDD NrFreqInfo 
1301  *
1302  * @details
1303  *
1304  *    Function : freeTddNrFreqInfo 
1305  *
1306  *    Functionality: freeTddNrFreqInfo 
1307  *
1308  * @params[in]  F1AP_PDU_t *f1apDuCfg
1309  *
1310  * @return ROK     - void
1311  *
1312  * ****************************************************************/
1313 void freeTddNrFreqInfo(NRFreqInfo_t *freqInfo)
1314 {
1315    uint8_t freqBandListIdx = 0, supportedBandIdx = 0;
1316
1317    if(freqInfo->freqBandListNr.list.array)
1318    {
1319       for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
1320       {
1321          if(freqInfo->freqBandListNr.list.array[freqBandListIdx])
1322          {
1323             if(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
1324             {
1325                for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
1326                {
1327                   DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
1328                         sizeof(SupportedSULFreqBandItem_t));
1329                }
1330                DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
1331                      freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
1332
1333             }
1334             DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
1335          }
1336       }
1337       DU_FREE(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
1338    }
1339 }
1340
1341 /*******************************************************************
1342  *
1343  * @brief Deallocating memory allocated for Nr fdd frequencey mode 
1344  *
1345  * @details
1346  *
1347  *    Function : freeFddNrFreqInfo 
1348  *
1349  *    Functionality:Free memory allocated for Nr fdd frequencey mode 
1350  *
1351  * @params[in]  
1352  *
1353  * @return ROK     - void
1354  *
1355  * ****************************************************************/
1356 void freeFddNrFreqInfo(FDD_Info_t *fDD)
1357 {
1358    uint8_t arrIdx =0;
1359
1360    if(fDD != NULLP)
1361    {
1362       if(fDD->uL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1363       {
1364          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.\
1365                array[arrIdx], sizeof(FreqBandNrItem_t));
1366          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.array, \
1367                fDD->uL_NRFreqInfo.freqBandListNr.list.size);
1368       }
1369
1370       if(fDD->dL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1371       {
1372          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.\
1373                array[arrIdx], sizeof(FreqBandNrItem_t));
1374          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.array,\
1375                fDD->dL_NRFreqInfo.freqBandListNr.list.size);
1376       }
1377       DU_FREE(fDD,sizeof(FDD_Info_t));
1378    }
1379 }
1380
1381 /*******************************************************************
1382  *
1383  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1384  *
1385  * @details
1386  *
1387  *    Function :  FreeServedCellList
1388  *
1389  *    Functionality:  deallocating the memory of function BuildServedCellList
1390
1391  *
1392  * @params[in] GNB_DU_Served_Cells_List_t *duServedCell
1393  *
1394  * @return void
1395  *
1396  * ****************************************************************/
1397 void FreeServedCellList( GNB_DU_Served_Cells_List_t *duServedCell)
1398 {
1399    uint8_t   plmnCnt= 1;
1400    uint8_t  extensionCnt=IE_EXTENSION_LIST_COUNT;
1401    uint8_t  plmnIdx=0, sliceIdx=0;
1402    GNB_DU_Served_Cells_Item_t *srvCellItem;
1403    ServedPLMNs_Item_t  *servedPlmnItem;
1404    SliceSupportItem_t  *sliceSupportItem;
1405
1406    if(duServedCell->list.array!=NULLP)
1407    {
1408       if(duServedCell->list.array[0]!=NULLP)
1409       {
1410          srvCellItem= &duServedCell->list.array[0]->value.choice.GNB_DU_Served_Cells_Item;
1411
1412          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1413                srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.size * sizeof(uint8_t));
1414          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1415                srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.size * sizeof(uint8_t));
1416
1417          if(srvCellItem->served_Cell_Information.fiveGS_TAC!=NULLP)
1418          {
1419             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC->buf,\
1420                   sizeof(srvCellItem->served_Cell_Information.fiveGS_TAC->size));
1421             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC,sizeof(FiveGS_TAC_t));
1422          }
1423
1424          if(srvCellItem->served_Cell_Information.servedPLMNs.list.array!=NULLP)
1425          {
1426             if(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx] != NULLP)
1427             {
1428                servedPlmnItem = srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx];
1429                DU_FREE(servedPlmnItem->pLMN_Identity.buf, servedPlmnItem->pLMN_Identity.size);
1430
1431                if(servedPlmnItem->iE_Extensions != NULLP)
1432                {
1433                   if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1434                   {
1435                      if(servedPlmnItem->iE_Extensions->list.array[0] != NULLP)
1436                      {
1437                         if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1438                               SliceSupportList.list.array != NULLP)
1439                         {
1440                            for(sliceIdx =0; sliceIdx<servedPlmnItem->iE_Extensions->list.array[0]->\
1441                                  extensionValue.choice.SliceSupportList.list.count; sliceIdx++)
1442                            {
1443                               if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1444                                     SliceSupportList.list.array[sliceIdx] != NULLP)
1445                               {
1446                                  sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[0]->\
1447                                                     extensionValue.choice.SliceSupportList.list.array[sliceIdx];
1448
1449                                  DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sizeof(uint8_t));
1450
1451                                  if(sliceSupportItem->sNSSAI.sD != NULLP)
1452                                  {
1453                                     DU_FREE(sliceSupportItem->sNSSAI.sD->buf,\
1454                                           sliceSupportItem->sNSSAI.sD->size);
1455                                     DU_FREE(sliceSupportItem->sNSSAI.sD, sizeof(OCTET_STRING_t));
1456                                  }
1457
1458                                  DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.\
1459                                        choice.SliceSupportList.list.array[sliceIdx], sizeof(SliceSupportItem_t));
1460                               }
1461                            }
1462                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1463                                  SliceSupportList.list.array, servedPlmnItem->iE_Extensions->list.array[0]->\
1464                                  extensionValue.choice.SliceSupportList.list.size);
1465                         }
1466                         DU_FREE(servedPlmnItem->iE_Extensions->list.array[0],\
1467                               sizeof(ServedPLMNs_ItemExtIEs_t));
1468                      }
1469                      DU_FREE(servedPlmnItem->iE_Extensions->list.array,\
1470                            extensionCnt*sizeof(ServedPLMNs_ItemExtIEs_t*));
1471                   }
1472                   DU_FREE(servedPlmnItem->iE_Extensions, sizeof(ProtocolExtensionContainer_4624P3_t));
1473                }
1474                DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx],\
1475                      sizeof(ServedPLMNs_Item_t));
1476             }
1477             DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array,\
1478                   sizeof(ServedPLMNs_Item_t *));
1479          }
1480
1481          if(srvCellItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1482          {
1483             freeFddNrFreqInfo(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1484          }
1485          else   
1486          {
1487             if(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD != NULLP)
1488             {
1489                freeTddNrFreqInfo(&srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1490                DU_FREE(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1491             }
1492          }
1493          
1494          DU_FREE(srvCellItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1495                srvCellItem->served_Cell_Information.measurementTimingConfiguration.size);
1496
1497          if(srvCellItem->gNB_DU_System_Information != NULLP)
1498          {
1499             if(srvCellItem->gNB_DU_System_Information->mIB_message.buf != NULLP)
1500             {
1501                DU_FREE(srvCellItem->gNB_DU_System_Information->mIB_message.buf,\
1502                      srvCellItem->gNB_DU_System_Information->mIB_message.size);
1503             }
1504
1505             if(srvCellItem->gNB_DU_System_Information->sIB1_message.buf != NULLP)
1506             { 
1507                DU_FREE(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,\
1508                      srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1509             }
1510
1511             DU_FREE(srvCellItem->gNB_DU_System_Information, sizeof(GNB_DU_System_Information_t));
1512          }
1513
1514          DU_FREE(duServedCell->list.array[0], sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1515       }
1516       DU_FREE(duServedCell->list.array, plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t*));
1517    }
1518 }
1519
1520 /*******************************************************************
1521  *
1522  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1523  *
1524  * @details
1525  *
1526  *    Function :  FreeF1SetupReq
1527  *
1528  *    Functionality:  deallocating the memory of function BuildAndSendF1SetupReq
1529  *
1530  * @params[in] F1AP_PDU_t *f1apMsg
1531  *
1532  * @return void
1533  *
1534  * ****************************************************************/
1535 void FreeF1SetupReq(F1AP_PDU_t *f1apMsg)
1536 {
1537    uint8_t ieIdx, ieIdx2;
1538    F1SetupRequest_t *f1SetupReq=NULLP;
1539
1540    if(f1apMsg != NULLP)
1541    {
1542       if(f1apMsg->choice.initiatingMessage != NULLP)
1543       {
1544          f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1545          if(f1SetupReq->protocolIEs.list.array != NULLP)
1546          {
1547             for(ieIdx = 0; ieIdx < f1SetupReq->protocolIEs.list.count; ieIdx++)
1548             {
1549                if(f1SetupReq->protocolIEs.list.array[ieIdx] != NULLP)
1550                {
1551                   switch(f1SetupReq->protocolIEs.list.array[ieIdx]->id)
1552                   {
1553                      case ProtocolIE_ID_id_TransactionID:
1554                         break;
1555                      case ProtocolIE_ID_id_gNB_DU_ID:
1556                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1557                               f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1558                         break;
1559                      case ProtocolIE_ID_id_gNB_DU_Name:
1560                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,\
1561                               strlen((char *)duCfgParam.duName));
1562                         break;
1563                      case ProtocolIE_ID_id_gNB_DU_Served_Cells_List:
1564                         FreeServedCellList(&f1SetupReq->protocolIEs.list.\
1565                               array[ieIdx]->value.choice.GNB_DU_Served_Cells_List);
1566                         break;
1567                      case ProtocolIE_ID_id_GNB_DU_RRC_Version:
1568                         FreeRrcVer(&f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version);
1569                         break;
1570                      default:
1571                         DU_LOG("\nERROR  -->  Invalid Event Type %ld", f1SetupReq->protocolIEs.list.array[ieIdx]->id);
1572                         break;
1573                   }
1574                }
1575             }
1576             for(ieIdx2=0; ieIdx2< ieIdx; ieIdx2++)
1577             {
1578                DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx2],sizeof(F1SetupRequestIEs_t));
1579             }
1580             DU_FREE(f1SetupReq->protocolIEs.list.array,\
1581                   f1SetupReq->protocolIEs.list.size);
1582          }
1583          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1584       }
1585       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
1586    }
1587 }
1588
1589 /*******************************************************************
1590  *
1591  * @brief Builds and Send the F1SetupRequest
1592  *
1593  * @details
1594  *
1595  *    Function : BuildAndSendF1SetupReq
1596  *
1597  * Functionality:Fills the F1SetupRequest
1598  *
1599  * @return ROK     - success
1600  *         RFAILED - failure
1601  *
1602  ******************************************************************/
1603 uint8_t BuildAndSendF1SetupReq()
1604 {
1605    uint8_t   ret, ieIdx, elementCnt;
1606    F1AP_PDU_t                 *f1apMsg = NULLP;
1607    F1SetupRequest_t           *f1SetupReq=NULLP;
1608    GNB_DU_Served_Cells_List_t *duServedCell=NULLP;
1609    RRC_Version_t              *rrcVer=NULLP;
1610    asn_enc_rval_t             encRetVal;        /* Encoder return value */
1611    ret= RFAILED;
1612
1613    DU_LOG("\nINFO   -->  F1AP : Building F1 Setup Request\n");
1614    do
1615    {
1616       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
1617       if(f1apMsg == NULLP)
1618       {
1619          break;
1620       }
1621       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
1622       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1623       if(f1apMsg->choice.initiatingMessage == NULLP)
1624       {
1625          break;
1626       }
1627       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_F1Setup;
1628       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
1629       f1apMsg->choice.initiatingMessage->value.present = \
1630                                                          InitiatingMessage__value_PR_F1SetupRequest;
1631
1632       f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1633
1634       elementCnt = 5;
1635
1636       f1SetupReq->protocolIEs.list.count = elementCnt;
1637       f1SetupReq->protocolIEs.list.size = elementCnt * sizeof(F1SetupRequestIEs_t *);
1638
1639       /* Initialize the F1Setup members */
1640       DU_ALLOC(f1SetupReq->protocolIEs.list.array,f1SetupReq->protocolIEs.list.size);
1641       if(f1SetupReq->protocolIEs.list.array == NULLP)
1642       {
1643          break;
1644       }
1645       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
1646       {
1647          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx],\
1648                sizeof(F1SetupRequestIEs_t));
1649          if(f1SetupReq->protocolIEs.list.array[ieIdx] == NULLP)
1650          {
1651             break;
1652          }
1653       }
1654
1655       ieIdx = 0;
1656       /*TransactionID*/
1657       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_TransactionID;
1658       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1659       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present =\
1660                                                                 F1SetupRequestIEs__value_PR_TransactionID;
1661       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = \
1662                                                                               TRANS_ID;
1663
1664       /*DU ID*/
1665       ieIdx++;
1666       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
1667       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1668       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1669                                                                  F1SetupRequestIEs__value_PR_GNB_DU_ID;
1670       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size =\
1671                                                                               sizeof(uint8_t);
1672
1673       DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1674             f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1675       if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == \
1676             NULLP)
1677       {
1678          break;
1679       }
1680
1681       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] =\
1682                                                                                 duCfgParam.duId;
1683       /* DU name IE is of type printableString_t which wireshark is unable to decode.
1684        * However this string is decoded successfully on online decoders.
1685        * Since this is an optional IE and the value received in it are not
1686        * used as of now, eliminating this IE for now to avoid wireshark error.
1687        */
1688       /*DU Name*/
1689       if(duCfgParam.duName != NULL)
1690       {
1691          ieIdx++;
1692          f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_Name;
1693          f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_ignore;
1694          f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = F1SetupRequestIEs__value_PR_GNB_DU_Name;
1695          f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size = strlen((char *)duCfgParam.duName);
1696          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf, \
1697                f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size);
1698          if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf == NULLP)
1699          {
1700             break;
1701          }
1702          strcpy((char*)f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,
1703                (char*)duCfgParam.duName);
1704       }
1705
1706       /*Served Cell list */
1707       ieIdx++;
1708       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1709                                                       ProtocolIE_ID_id_gNB_DU_Served_Cells_List;
1710       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1711       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1712                                                                  F1SetupRequestIEs__value_PR_GNB_DU_Served_Cells_List;
1713       duServedCell = &f1SetupReq->protocolIEs.list.\
1714                      array[ieIdx]->value.choice.GNB_DU_Served_Cells_List;
1715       if(BuildServedCellList(duServedCell))
1716       {
1717          break;
1718       }
1719
1720       /*RRC Version*/
1721       ieIdx++;
1722       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1723                                                       ProtocolIE_ID_id_GNB_DU_RRC_Version ;
1724       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1725       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1726                                                                  F1SetupRequestIEs__value_PR_RRC_Version;
1727       rrcVer = &f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
1728       if(BuildRrcVer(rrcVer))
1729       {
1730          break;
1731       }
1732
1733       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
1734
1735       /* Encode the F1SetupRequest type as APER */
1736       memset(encBuf, 0, ENC_BUF_MAX_LEN);
1737       encBufSize = 0;
1738       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
1739             encBuf);
1740
1741       /* Encode results */
1742       if(encRetVal.encoded == ENCODE_FAIL)
1743       {
1744          DU_LOG("\nERROR  -->  F1AP : Could not encode F1SetupRequest structure (at %s)\n",\
1745                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1746          break;
1747       }
1748       else
1749       {
1750          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1SetupRequest\n");
1751 #ifdef DEBUG_ASN_PRINT
1752          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
1753          {
1754             printf("%x",encBuf[ieIdx]);
1755          }
1756 #endif
1757
1758          duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize = encBufSize;
1759          DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, encBufSize);
1760          if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
1761          {
1762             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the encoding of f1setup req");
1763             return RFAILED;
1764          }
1765          memcpy(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, &encBuf, duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize);
1766       }
1767
1768       /* Sending msg */
1769       if(sendF1APMsg() != ROK)
1770       {
1771          DU_LOG("\nERROR  -->  F1AP : Sending F1 Setup request failed");
1772          break;
1773       }
1774
1775       ret=ROK;
1776       break;
1777    }while(true);
1778
1779    FreeF1SetupReq(f1apMsg);
1780
1781    return ret;
1782 }/* End of BuildAndSendF1SetupReq */
1783
1784 /*******************************************************************
1785  *
1786  * @brief Deallocating memory allocated for Served_Cells_To_Modify_Item_t
1787  *
1788  * @details
1789  *
1790  *    Function : freeCellsToModifyItem 
1791  *
1792  *    Functionality: Deallocating memory of variables allocated in
1793  *                    BuildAndSendDUConfigUpdate function
1794  *
1795  * @params[in]  Served_Cells_To_Modify_Item_t *modifyItem
1796  *
1797  * @return ROK     - void
1798  *
1799  * ****************************************************************/
1800
1801 void freeCellsToModifyItem(Served_Cells_To_Modify_Item_t *modifyItem)
1802 {
1803    uint8_t arrIdx=0, servedPlmnIdx=0, sliceLstIdx=0;
1804    ServedPLMNs_Item_t *servedPlmnItem = NULLP;
1805    SliceSupportItem_t *sliceSupportItem = NULLP;
1806
1807    DU_FREE(modifyItem->oldNRCGI.pLMN_Identity.buf, modifyItem->oldNRCGI.pLMN_Identity.size);
1808    DU_FREE(modifyItem->oldNRCGI.nRCellIdentity.buf, modifyItem->oldNRCGI.nRCellIdentity.size);
1809
1810    DU_FREE(modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1811            modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.size);
1812    DU_FREE(modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1813          modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.size);
1814
1815    if(modifyItem->served_Cell_Information.servedPLMNs.list.array != NULLP)
1816    {
1817       if(modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx] != NULLP)
1818       {
1819          servedPlmnItem = modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx];
1820
1821          DU_FREE(servedPlmnItem->pLMN_Identity.buf,servedPlmnItem->pLMN_Identity.size);
1822
1823          if(servedPlmnItem->iE_Extensions != NULLP)
1824          {
1825             if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1826             {
1827                if(servedPlmnItem->iE_Extensions->list.array[arrIdx] != NULLP)
1828                {
1829                   if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1830                         list.array != NULLP)
1831                   {
1832                      for(sliceLstIdx =0; sliceLstIdx<servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1833                            extensionValue.choice.SliceSupportList.list.count; sliceLstIdx++)
1834                      {
1835                         if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1836                               list.array[sliceLstIdx] != NULLP)
1837                         {
1838
1839                            sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1840                                               SliceSupportList.list.array[sliceLstIdx];
1841
1842                            DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sliceSupportItem->sNSSAI.sST.size);
1843                            if(sliceSupportItem->sNSSAI.sD != NULLP)
1844                            {
1845                               DU_FREE(sliceSupportItem->sNSSAI.sD->buf, sliceSupportItem->sNSSAI.sD->size);
1846                               DU_FREE(sliceSupportItem->sNSSAI.sD,sizeof(OCTET_STRING_t));
1847                            }
1848                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1849                                  SliceSupportList.list.array[sliceLstIdx], sizeof(SliceSupportItem_t));
1850                         }
1851                      }
1852                      DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.\
1853                            choice.SliceSupportList.list.array,\
1854                            servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1855                            extensionValue.choice.SliceSupportList.list.size);
1856                   }
1857                }
1858                for(servedPlmnIdx=0; servedPlmnIdx< servedPlmnItem->iE_Extensions->list.count ; servedPlmnIdx++)
1859                {
1860                   DU_FREE(servedPlmnItem->iE_Extensions->list.array[servedPlmnIdx], sizeof(ServedPLMNs_ItemExtIEs_t ));
1861                }
1862                DU_FREE(servedPlmnItem->iE_Extensions->list.array, servedPlmnItem->iE_Extensions->list.size);
1863             }
1864             DU_FREE(servedPlmnItem->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1865          }
1866       }
1867       for(servedPlmnIdx=0; servedPlmnIdx<modifyItem->served_Cell_Information.servedPLMNs.list.count; servedPlmnIdx++)
1868       {
1869          DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array[servedPlmnIdx], sizeof(ServedPLMNs_Item_t));
1870       }
1871       DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array,\
1872          modifyItem->served_Cell_Information.servedPLMNs.list.size);
1873    }
1874    
1875    if(modifyItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1876    {
1877       freeFddNrFreqInfo(modifyItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1878    }  
1879    else
1880    {
1881       if(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD)
1882       {
1883          freeTddNrFreqInfo(&modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1884          DU_FREE(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1885       }
1886    }
1887    DU_FREE(modifyItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1888          modifyItem->served_Cell_Information.measurementTimingConfiguration.size);
1889 }
1890
1891 /*******************************************************************
1892  *
1893  * @brief Deallocating memory of BuildAndSendDUConfigUpdate
1894  *
1895  * @details
1896  *
1897  *    Function : FreeDUConfigUpdate
1898  *
1899  *    Functionality: Deallocating memory of variables allocated in
1900  *                    BuildAndSendDUConfigUpdate function
1901  *
1902  * @params[in]  F1AP_PDU_t *f1apDuCfg
1903  *
1904  * @return ROK     - void
1905  *
1906  * ****************************************************************/
1907 void FreeDUConfigUpdate(F1AP_PDU_t *f1apDuCfg)
1908 {
1909    uint8_t  idx=0,ieIdx=0, cellModifyIdx=0, cellDeleteIdx=0;
1910    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
1911    Served_Cells_To_Modify_List_t  *cellsToModify=NULLP;
1912    Served_Cells_To_Delete_List_t  *cellsToDelete=NULLP;
1913    Served_Cells_To_Delete_Item_t  *deleteItem = NULLP;
1914    Served_Cells_To_Delete_ItemIEs_t *deleteItemIe = NULLP;
1915    Cells_Status_ItemIEs_t *cellStatusItemIE;
1916
1917    if(f1apDuCfg != NULLP)
1918    {
1919       if(f1apDuCfg->choice.initiatingMessage != NULLP)
1920       {
1921          duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->\
1922                        value.choice.GNBDUConfigurationUpdate;
1923          if(duCfgUpdate->protocolIEs.list.array != NULLP)
1924          {
1925             for(ieIdx=0; ieIdx<duCfgUpdate->protocolIEs.list.count; ieIdx++)
1926             {
1927                if(duCfgUpdate->protocolIEs.list.array[ieIdx] != NULLP)
1928                {
1929                   switch(duCfgUpdate->protocolIEs.list.array[ieIdx]->id)
1930                   {
1931                      case ProtocolIE_ID_id_Served_Cells_To_Modify_List:
1932                         {
1933                            cellsToModify = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1934                                            value.choice.Served_Cells_To_Modify_List;
1935                            if(cellsToModify->list.array != NULLP)
1936                            {
1937                               for(cellModifyIdx=0; cellModifyIdx<cellsToModify->list.count ;cellModifyIdx++)
1938                               {
1939                                  if(cellsToModify->list.array[cellModifyIdx] != NULLP)
1940                                  {
1941                                     freeCellsToModifyItem(&cellsToModify->list.array[cellModifyIdx]->value.choice.\
1942                                           Served_Cells_To_Modify_Item);
1943                                     DU_FREE(cellsToModify->list.array[cellModifyIdx],\
1944                                           sizeof(Served_Cells_To_Modify_ItemIEs_t));
1945                                  }
1946                               }
1947                               DU_FREE(cellsToModify->list.array,cellsToModify->list.size);
1948                            }
1949                            break;
1950                         }
1951                      case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
1952                         {
1953                            cellsToDelete = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1954                                            value.choice.Served_Cells_To_Delete_List;
1955                            if(cellsToDelete->list.array != NULLP)
1956                            {
1957                               for(cellDeleteIdx=0; cellDeleteIdx<cellsToDelete->list.count ;cellDeleteIdx++)
1958                               {
1959                                  if(cellsToDelete->list.array[cellDeleteIdx] != NULLP)
1960                                  {
1961                                     deleteItemIe = ((Served_Cells_To_Delete_ItemIEs_t*)\
1962                                           cellsToDelete->list.array[cellDeleteIdx]);
1963                                     deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
1964                                     DU_FREE(deleteItem->oldNRCGI.pLMN_Identity.buf,\
1965                                           deleteItem->oldNRCGI.pLMN_Identity.size); 
1966                                     DU_FREE(deleteItem->oldNRCGI.nRCellIdentity.buf,\
1967                                           deleteItem->oldNRCGI.nRCellIdentity.size);
1968                                     DU_FREE(cellsToDelete->list.array[cellDeleteIdx],\
1969                                           sizeof(Served_Cells_To_Delete_ItemIEs_t));
1970                                  }
1971                               }
1972                               DU_FREE(cellsToDelete->list.array,cellsToDelete->list.size);
1973                            }
1974
1975                            break;
1976                         }
1977                      case ProtocolIE_ID_id_gNB_DU_ID:
1978                         {
1979                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1980                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1981                            break;
1982                         }
1983                      case ProtocolIE_ID_id_Cells_Status_List:
1984                         {
1985                            for(idx = 0; idx < duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.count; idx++)
1986                            {
1987                               cellStatusItemIE = (Cells_Status_ItemIEs_t *)duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array[idx];
1988                               DU_FREE(cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.nRCellIdentity.buf, cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.nRCellIdentity.size);
1989                               DU_FREE(cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.pLMN_Identity.buf, cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.pLMN_Identity.size);
1990                               DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array[idx],sizeof(Cells_Status_ItemIEs_t));
1991                            }
1992                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array,\
1993                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.size);
1994                         }
1995                   }
1996                   DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx],\
1997                         sizeof(GNBDUConfigurationUpdateIEs_t));
1998                }
1999             }
2000             DU_FREE(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2001          }
2002          DU_FREE(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2003       }
2004       DU_FREE(f1apDuCfg, (Size)sizeof(F1AP_PDU_t));
2005    }
2006 }
2007
2008 /*******************************************************************
2009  *
2010  * @brief Fills Served Plmns required in ServCellInfo IE
2011  *
2012  * @details
2013  *
2014  *    Function : fillServedPlmns
2015  *
2016  *    Functionality: Fills Served Plmns required in ServCellInfo IE
2017  *
2018  * @params[in] Pointer to ServedPLMNs_List_t *
2019  *
2020  * @return ROK     - success
2021  *         RFAILED - failure
2022  *
2023  *****************************************************************/
2024
2025 uint8_t fillServedPlmns(ServedPLMNs_List_t *servedPlmn)
2026 {
2027    uint8_t ieIdx=0, arrayIdx=0, ieListCnt=0, elementCnt=0, sliceLstIdx=0;
2028
2029    servedPlmn->list.array[arrayIdx]->pLMN_Identity.size = 3*sizeof(uint8_t);
2030    DU_ALLOC(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf, servedPlmn->list.\
2031          array[arrayIdx]->pLMN_Identity.size);
2032    if(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf == NULLP)
2033    {
2034       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2035       return RFAILED;
2036    }
2037    buildPlmnId(duCfgParam.srvdCellLst[arrayIdx].duCellInfo.cellInfo.srvdPlmn[arrayIdx].plmn,\
2038          servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf);
2039    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
2040    if(servedPlmn->list.array[arrayIdx]->iE_Extensions == NULLP)
2041    {
2042       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2043       return RFAILED;
2044    }
2045
2046    ieListCnt=1;
2047    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.count = ieListCnt;
2048    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.size = ieListCnt *sizeof(ServedPLMNs_ItemExtIEs_t *);
2049    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array,servedPlmn->list.array[arrayIdx]->\
2050          iE_Extensions->list.size);
2051    if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array == NULLP)
2052    {
2053       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2054       return RFAILED;
2055    }
2056    for(ieIdx=arrayIdx;ieIdx<ieListCnt;ieIdx++)
2057    {
2058       DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx],\
2059             sizeof(ServedPLMNs_ItemExtIEs_t));
2060       if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx] == NULLP)
2061       {
2062          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2063          return RFAILED;
2064       }
2065    }
2066    
2067    ieIdx = 0;
2068    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices; 
2069    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->id =ProtocolIE_ID_id_TAISliceSupportList;
2070    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->criticality = Criticality_ignore;
2071    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.present = \
2072    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
2073    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2074       list.count = elementCnt;
2075    servedPlmn->list.array[arrayIdx]->\
2076       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2077       list.size = elementCnt * sizeof(SliceSupportItem_t *);
2078    DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2079          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2080          list.array,servedPlmn->list.array[arrayIdx]->\
2081          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.size);
2082    if(servedPlmn->list.array[arrayIdx]->\
2083          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2084          list.array == NULLP)
2085    {
2086       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2087       return RFAILED;
2088    }
2089
2090    for(sliceLstIdx =0; sliceLstIdx< elementCnt; sliceLstIdx++)
2091    {
2092       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2093       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2094       list.array[sliceLstIdx],sizeof( SliceSupportItem_t));
2095       if(servedPlmn->list.array[arrayIdx]->\
2096       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2097       list.array[sliceLstIdx] == NULLP)
2098       {   
2099          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2100          return RFAILED;
2101       }
2102       
2103       servedPlmn->list.array[arrayIdx]->\
2104       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2105       list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
2106       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2107       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2108       list.array[sliceLstIdx]->sNSSAI.sST.buf,servedPlmn->list.array[arrayIdx]->\
2109       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->\
2110       sNSSAI.sST.size);
2111       
2112       if(servedPlmn->list.array[arrayIdx]->\
2113       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2114       list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
2115       {
2116          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2117          return RFAILED;
2118       }
2119       servedPlmn->list.array[arrayIdx]->\
2120       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2121       list.array[sliceLstIdx]->sNSSAI.sST.buf[arrayIdx] =  duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
2122       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
2123
2124       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2125       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2126       list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
2127       if(servedPlmn->list.array[arrayIdx]->\
2128       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2129       list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
2130       {
2131          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2132          return RFAILED;
2133       }
2134       servedPlmn->list.array[arrayIdx]->\
2135       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2136       list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
2137       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2138       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2139       list.array[sliceLstIdx]->sNSSAI.sD->buf,servedPlmn->list.array[arrayIdx]->\
2140       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2141       list.array[sliceLstIdx]->sNSSAI.sD->size);
2142       if(servedPlmn->list.array[arrayIdx]->\
2143       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2144       list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
2145       {
2146          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2147          return RFAILED;
2148       }
2149       memcpy(servedPlmn->list.array[arrayIdx]->\
2150       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2151       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
2152       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sd,\
2153       servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2154       list.array[sliceLstIdx]->sNSSAI.sD->size);
2155    }
2156    return ROK;
2157 }
2158
2159 /*******************************************************************
2160  *
2161  * @brief Fills Nr Fdd Info required in ServCellInfo IE
2162  *
2163  * @details
2164  *
2165  *    Function : fillNrFddInfo
2166  *
2167  *    Functionality: Fills Nr Fdd Info required in ServCellInfo IE
2168  *
2169  * @params[in] FDD_Info_t *fDD
2170  *
2171  * @return ROK     - success
2172  *         RFAILED - failure
2173  *
2174  *****************************************************************/
2175
2176 uint8_t fillNrFddInfo(FDD_Info_t *fDD)
2177 {
2178    fDD->uL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.\
2179       f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn;
2180    fDD->uL_NRFreqInfo.freqBandListNr.list.count = 1;
2181    fDD->uL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t*);
2182    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.\
2183          array, fDD->uL_NRFreqInfo.freqBandListNr.list.size);
2184    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array == NULLP)
2185    {
2186       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2187       return RFAILED;
2188    }
2189
2190    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0], \
2191       sizeof(FreqBandNrItem_t));
2192    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2193    {
2194       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2195       return RFAILED;
2196    }
2197    
2198    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2199       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
2200       freqBand[0].nrFreqBand;
2201    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2202    fDD->dL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.\
2203       dlNrFreqInfo.nrArfcn;
2204    fDD->dL_NRFreqInfo.freqBandListNr.list.count = 1;
2205    fDD->dL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
2206    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array, fDD->dL_NRFreqInfo.freqBandListNr.list.size);
2207    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array == NULLP)
2208    {
2209       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2210       return RFAILED;
2211    }
2212    
2213    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0],  sizeof(FreqBandNrItem_t));
2214    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2215    {
2216       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2217       return RFAILED;
2218    }
2219
2220    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2221       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
2222       freqBand[0].nrFreqBand;
2223    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2224    
2225    /*Transmission Bandwidth*/
2226    fDD->uL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2227       f1Mode.mode.fdd.ulTxBw.nrScs;
2228    fDD->uL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2229       f1Mode.mode.fdd.ulTxBw.nrb;
2230    fDD->dL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2231       f1Mode.mode.fdd.dlTxBw.nrScs;
2232    fDD->dL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2233       f1Mode.mode.fdd.dlTxBw.nrb;
2234
2235    return ROK;
2236 }
2237
2238 /*******************************************************************
2239  *
2240  * @brief Fills ServCellInfo IE
2241  *
2242  * @details
2243  *
2244  *    Function : fillServedCellInfo
2245  *
2246  *    Functionality: Fills ServCellInfo
2247  *
2248  * @params[in] Pointer to Served_Cell_Information_t *
2249  *
2250  * @return ROK     - success
2251  *         RFAILED - failure
2252  *
2253  *****************************************************************/
2254
2255 uint8_t fillServedCellInfo(Served_Cell_Information_t *srvCellInfo)
2256 {
2257    uint8_t ieIdx, ieListCnt;
2258
2259    /*nRCGI*/
2260    srvCellInfo->nRCGI.pLMN_Identity.size =3*sizeof(uint8_t);
2261    DU_ALLOC(srvCellInfo->nRCGI.pLMN_Identity.buf,\
2262          srvCellInfo->nRCGI.pLMN_Identity.size);
2263    if(srvCellInfo->nRCGI.pLMN_Identity.buf == NULLP)
2264    {
2265       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2266       return RFAILED;
2267    }
2268    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2269          srvCellInfo->nRCGI.pLMN_Identity.buf);
2270    srvCellInfo->nRCGI.nRCellIdentity.size =5*sizeof(uint8_t);
2271    DU_ALLOC(srvCellInfo->nRCGI.nRCellIdentity.buf,\
2272          srvCellInfo->nRCGI.nRCellIdentity.size);
2273    if(srvCellInfo->nRCGI.nRCellIdentity.buf == NULLP)
2274    {   
2275       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2276       return RFAILED;
2277    }
2278    
2279    fillBitString(&srvCellInfo->nRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2280    /*nRPCI*/
2281    srvCellInfo->nRPCI = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
2282
2283    /*servedPLMNs*/
2284    ieListCnt = 1;
2285    srvCellInfo->servedPLMNs.list.count = ieListCnt;
2286    srvCellInfo->servedPLMNs.list.size = ieListCnt*sizeof(ServedPLMNs_Item_t *);
2287    DU_ALLOC(srvCellInfo->servedPLMNs.list.array, srvCellInfo->servedPLMNs.list.size);
2288    if(srvCellInfo->servedPLMNs.list.array == NULLP)
2289    {
2290       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2291       return RFAILED;
2292    }
2293    for(ieIdx=0; ieIdx < ieListCnt; ieIdx++)
2294    {
2295       DU_ALLOC(srvCellInfo->servedPLMNs.list.array[ieIdx], sizeof(ServedPLMNs_Item_t));
2296       if(srvCellInfo->servedPLMNs.list.array[ieIdx]== NULLP)
2297       {
2298          DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2299          return RFAILED;
2300       }
2301    }
2302    if(fillServedPlmns(&srvCellInfo->servedPLMNs))
2303    {
2304       DU_LOG("\nERROR  --> Failed to fill Served Plmn info");
2305       return RFAILED;
2306    }
2307
2308 #ifndef NR_TDD
2309    /*nR Mode Info with FDD*/
2310    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_fDD;
2311    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.fDD, sizeof(FDD_Info_t));
2312    if(srvCellInfo->nR_Mode_Info.choice.fDD == NULLP)
2313    {
2314       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2315       return RFAILED;
2316    }
2317    if(fillNrFddInfo(srvCellInfo->nR_Mode_Info.choice.fDD))
2318    {
2319        DU_LOG("\nERROR  --> Failed to fill the Nr FDD information");
2320       return RFAILED;
2321    }
2322 #else
2323    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_tDD;   
2324    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
2325    if(srvCellInfo->nR_Mode_Info.choice.tDD == NULLP)
2326    {
2327       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2328       return RFAILED;
2329    }
2330    if(fillNrTddInfo(srvCellInfo->nR_Mode_Info.choice.tDD) != ROK)
2331    {
2332       DU_LOG("\nERROR  --> Failed to fill the Nr TDD information");
2333       return RFAILED;
2334    }
2335 #endif
2336
2337    /*Measurement timing Config*/
2338    if(BuildMeasTimingConf(&srvCellInfo->measurementTimingConfiguration) != ROK)
2339       return RFAILED;
2340
2341    return ROK;
2342 }
2343
2344 /*******************************************************************
2345  *
2346  * @brief Fills ServCellToModItem IE
2347  *
2348  * @details
2349  *
2350  *    Function : fillServCellToModItem
2351  *
2352  *    Functionality: Fills ServCellToModItem IE
2353  *
2354  * @params[in] Pointer to Served_Cells_To_Modify_Item_t *
2355  *
2356  * @return ROK     - success
2357  *         RFAILED - failure
2358  *
2359  *****************************************************************/
2360
2361 uint8_t fillServCellToModItem(Served_Cells_To_Modify_Item_t *modifyItem)
2362 {
2363    /*pLMN_Identity*/
2364    modifyItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2365    DU_ALLOC(modifyItem->oldNRCGI.pLMN_Identity.buf,modifyItem->oldNRCGI.pLMN_Identity.size);
2366    if(modifyItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2367    {
2368       return RFAILED;
2369    }
2370    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2371          modifyItem->oldNRCGI.pLMN_Identity.buf);
2372
2373    /*nRCellIdentity*/
2374    modifyItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2375    DU_ALLOC(modifyItem->oldNRCGI.nRCellIdentity.buf,\
2376          modifyItem->oldNRCGI.nRCellIdentity.size);
2377    if(modifyItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2378    {
2379       return RFAILED;
2380    }
2381    fillBitString(&modifyItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2382
2383    if(fillServedCellInfo(&modifyItem->served_Cell_Information))
2384       return RFAILED;
2385    else
2386       return ROK;
2387 }
2388
2389 /*******************************************************************
2390  *
2391  * @brief Builds ServCellToModList
2392  *
2393  * @details
2394  *
2395  *    Function : buildServCellToModList
2396  *
2397  *    Functionality: Builds the serv cell to Mod List
2398  *
2399  * @params[in] Pointer to Served_Cells_To_Modify_List_t *
2400  *
2401  * @return ROK     - success
2402  *         RFAILED - failure
2403  *
2404  *****************************************************************/
2405
2406 uint8_t buildServCellToModList(Served_Cells_To_Modify_List_t *cellsToModify)
2407 {
2408    uint8_t ieListCnt, ieIdx;
2409    Served_Cells_To_Modify_Item_t *modifyItem = NULLP;
2410
2411    ieListCnt = 1;
2412    cellsToModify->list.count = ieListCnt;
2413    cellsToModify->list.size = ieListCnt*sizeof(Served_Cells_To_Modify_ItemIEs_t *);
2414    DU_ALLOC(cellsToModify->list.array,cellsToModify->list.size);
2415    if(cellsToModify->list.array == NULLP)
2416    {
2417       return RFAILED;
2418    }
2419    for(ieIdx=0; ieIdx< ieListCnt; ieIdx++)
2420    {
2421       DU_ALLOC(cellsToModify->list.array[ieIdx],sizeof(Served_Cells_To_Modify_ItemIEs_t));
2422       if(cellsToModify->list.array[ieIdx] == NULLP)
2423       {
2424          return RFAILED;
2425       }
2426    }
2427    cellsToModify->list.array[0]->id = ProtocolIE_ID_id_Served_Cells_To_Modify_Item;
2428    cellsToModify->list.array[0]->criticality = Criticality_reject;
2429    cellsToModify->list.array[0]->value.present =\
2430       Served_Cells_To_Modify_ItemIEs__value_PR_Served_Cells_To_Modify_Item;
2431    modifyItem=&cellsToModify->list.array[0]->value.choice.Served_Cells_To_Modify_Item;
2432
2433    if(fillServCellToModItem(modifyItem))
2434       return RFAILED;
2435    else
2436       return ROK;
2437 }
2438 /*******************************************************************
2439  *
2440  * @brief filling the DeleteItemList
2441  *
2442  * @details
2443  *
2444  *    Function : fillCellToDeleteItem 
2445  *
2446  *    Functionality: Filling the DeleteItemIe 
2447  *
2448  * @params[in] Pointer to Served_Cells_To_Delete_ItemIEs_t 
2449  *
2450  * @return ROK     - success
2451  *         RFAILED - failure
2452  *
2453  *****************************************************************/
2454 uint8_t fillCellToDeleteItem(struct Served_Cells_To_Delete_ItemIEs *deleteItemIe)
2455 {
2456    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
2457    
2458    deleteItemIe->id = ProtocolIE_ID_id_Served_Cells_To_Delete_Item;
2459    deleteItemIe->criticality = Criticality_reject;
2460    deleteItemIe->value.present =\
2461    Served_Cells_To_Delete_ItemIEs__value_PR_Served_Cells_To_Delete_Item;
2462    deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
2463
2464    /*pLMN_Identity*/
2465    deleteItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2466    DU_ALLOC(deleteItem->oldNRCGI.pLMN_Identity.buf,deleteItem->oldNRCGI.pLMN_Identity.size);
2467    if(deleteItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2468    {
2469       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2470       return RFAILED;
2471    }
2472    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2473          deleteItem->oldNRCGI.pLMN_Identity.buf);
2474
2475    /*nRCellIdentity*/
2476    deleteItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2477    DU_ALLOC(deleteItem->oldNRCGI.nRCellIdentity.buf,\
2478          deleteItem->oldNRCGI.nRCellIdentity.size);
2479    if(deleteItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2480    {
2481       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2482       return RFAILED;
2483    }
2484    fillBitString(&deleteItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2485    return ROK;
2486
2487
2488 /*******************************************************************
2489  *
2490  * @brief Builds ServCellToDeleteList
2491  *
2492  * @details
2493  *
2494  *    Function : buildServCellToDeleteList
2495  *
2496  *    Functionality: Builds the serv cell to delete List
2497  *
2498  * @params[in] Pointer to Served_Cells_To_Delete_List_t *
2499  *
2500  * @return ROK     - success
2501  *         RFAILED - failure
2502  *
2503  *****************************************************************/
2504  
2505 uint8_t buildServCellToDeleteList(Served_Cells_To_Delete_List_t *cellsToDelete)
2506 {
2507    uint8_t ieListCnt, arrIdx;
2508    
2509    ieListCnt = 1;
2510    cellsToDelete->list.count = ieListCnt;
2511    cellsToDelete->list.size = ieListCnt*sizeof(Served_Cells_To_Delete_ItemIEs_t *);
2512    
2513    DU_ALLOC(cellsToDelete->list.array,cellsToDelete->list.size);
2514    if(cellsToDelete->list.array == NULLP)
2515    {
2516       DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2517       return RFAILED;
2518    }
2519    
2520    for(arrIdx=0; arrIdx< ieListCnt; arrIdx++)
2521    {
2522       DU_ALLOC(cellsToDelete->list.array[arrIdx],sizeof(Served_Cells_To_Delete_ItemIEs_t));
2523       if(cellsToDelete->list.array[arrIdx] == NULLP)
2524       {
2525          DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2526          return RFAILED;
2527       }
2528    }
2529    
2530    arrIdx=0;
2531    if(fillCellToDeleteItem((Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx]) !=ROK)
2532    {
2533       DU_LOG("\nERROR  -->  F1AP: buildServCellToDeleteList(): failed to fill Served_Cells_To_Delete_ItemIEs");
2534       return RFAILED;
2535    }
2536    return ROK;
2537 }
2538
2539 /*******************************************************************
2540  *
2541  * @brief Builds CellsStatusList
2542  *
2543  * @details
2544  *
2545  *    Function : buildCellsStatusList
2546  *
2547  *    Functionality: Builds the Cell Status List
2548  *
2549  * @params[in] Pointer to Cells_Status_List_t *
2550  *
2551  * @return ROK     - success
2552  *         RFAILED - failure
2553  *
2554  *****************************************************************/
2555 uint8_t buildCellsStatusList(Cells_Status_List_t *cellStatusList)
2556 {
2557    uint8_t elementCnt = 0, idx = 0, ret = ROK;
2558    Cells_Status_ItemIEs_t *cellStatusItemIE;
2559
2560    elementCnt = 1;
2561    cellStatusList->list.count = elementCnt;
2562    cellStatusList->list.size = elementCnt * sizeof(Cells_Status_ItemIEs_t *);
2563    DU_ALLOC(cellStatusList->list.array, cellStatusList->list.size);
2564
2565    for(idx = 0; idx < elementCnt; idx++)
2566    {
2567       DU_ALLOC(cellStatusList->list.array[idx], sizeof(Cells_Status_ItemIEs_t));
2568       if(!cellStatusList->list.array[idx])
2569       {
2570          DU_LOG("ERROR  --> F1AP: buildCellsStatusList() memory allocation failure");
2571          return RFAILED;
2572       }
2573    }
2574    idx = 0;
2575    cellStatusItemIE = (Cells_Status_ItemIEs_t *)cellStatusList->list.array[idx];
2576    cellStatusItemIE->id = ProtocolIE_ID_id_Cells_Status_Item;
2577    cellStatusItemIE->criticality = Criticality_reject;
2578    cellStatusItemIE->value.present = Cells_Status_ItemIEs__value_PR_Cells_Status_Item;
2579    ret = BuildNrcgi(&cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI);
2580    if(ret == RFAILED)
2581    {
2582          DU_LOG("ERROR  --> F1AP: buildCellsStatusList() NRCGI failed");
2583          return RFAILED;
2584    }
2585    cellStatusItemIE->value.choice.Cells_Status_Item.service_status.service_state = Service_State_in_service;
2586    return ROK;
2587 }
2588
2589 /*******************************************************************
2590  *
2591  * @brief Builds and sends the DUConfigUpdate
2592  *
2593  * @details
2594  *
2595  *    Function : BuildAndSendDUConfigUpdate
2596  *
2597  *    Functionality: Constructs the DU Update message and sends
2598  *                   it to the CU through SCTP.
2599  *
2600  * @params[in] void **buf,Buffer to which encoded pattern is written into
2601  * @params[in] int *size,size of buffer
2602  *
2603  * @return ROK     - success
2604  *         RFAILED - failure
2605  *
2606  * ****************************************************************/
2607 uint8_t BuildAndSendDUConfigUpdate(ServCellAction servCellAction)
2608 {
2609    uint8_t ret =0, ieIdx=0, elementCnt=0;
2610    bool memAlloctionFailure = false;
2611    F1AP_PDU_t                 *f1apDuCfg = NULLP;
2612    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
2613    asn_enc_rval_t encRetVal;     /* Encoder return value */
2614    
2615    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2616    ret= RFAILED;
2617
2618    while(true)
2619    {
2620       DU_LOG("\nINFO   -->  F1AP : Building DU config update\n");
2621       /* Allocate the memory for F1DuCfg */
2622       DU_ALLOC(f1apDuCfg, sizeof(F1AP_PDU_t));
2623       if(f1apDuCfg == NULLP)
2624       {
2625          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2626          break;
2627       }
2628
2629       f1apDuCfg->present = F1AP_PDU_PR_initiatingMessage;
2630       DU_ALLOC(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2631       if(f1apDuCfg->choice.initiatingMessage == NULLP)
2632       {
2633          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2634          break;
2635       }
2636
2637       f1apDuCfg->choice.initiatingMessage->procedureCode = \
2638                                                            ProcedureCode_id_gNBDUConfigurationUpdate;
2639       f1apDuCfg->choice.initiatingMessage->criticality = Criticality_reject;
2640       f1apDuCfg->choice.initiatingMessage->value.present = \
2641                                                            InitiatingMessage__value_PR_GNBDUConfigurationUpdate;
2642       duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->value.\
2643                     choice.GNBDUConfigurationUpdate;
2644       elementCnt = 4;
2645       duCfgUpdate->protocolIEs.list.count = elementCnt;
2646       duCfgUpdate->protocolIEs.list.size = \
2647                                            elementCnt * sizeof(GNBDUConfigurationUpdateIEs_t*);
2648
2649       /* Initialize the F1Setup members */
2650       DU_ALLOC(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2651       if(duCfgUpdate->protocolIEs.list.array == NULLP)
2652       {
2653          DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2654          break;
2655       }
2656       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
2657       {
2658          DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx],sizeof(GNBDUConfigurationUpdateIEs_t));
2659          if(duCfgUpdate->protocolIEs.list.array[ieIdx] == NULLP)
2660          {
2661             DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2662             memAlloctionFailure = true;
2663             break;
2664          }
2665       }
2666       
2667       if(memAlloctionFailure == true)
2668       {
2669          break;
2670       }
2671       /*TransactionID*/
2672       ieIdx = 0;
2673       duCfgUpdate->protocolIEs.list.array[ieIdx]->id=ProtocolIE_ID_id_TransactionID;
2674       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
2675       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2676       GNBDUConfigurationUpdateIEs__value_PR_TransactionID;
2677       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = TRANS_ID;
2678       
2679       ieIdx++;
2680       if(servCellAction == SERV_CELL_TO_MODIFY)
2681       {
2682          /*Served Cell to Modify */
2683          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2684          ProtocolIE_ID_id_Served_Cells_To_Modify_List;
2685          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2686          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2687          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Modify_List;
2688          if(buildServCellToModList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2689                   Served_Cells_To_Modify_List))
2690          {
2691             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToModList");
2692             break;
2693          }
2694       }
2695       else
2696       {
2697          /*Served Cell to Delete */ 
2698          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2699          ProtocolIE_ID_id_Served_Cells_To_Delete_List;
2700          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2701          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2702          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Delete_List;
2703          if(buildServCellToDeleteList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2704          Served_Cells_To_Delete_List)!=ROK)
2705          {
2706             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToDeleteList");
2707             break;
2708          }
2709          
2710       }
2711       // TODO :GNB DU SYS INFO:MIB AND SIB1 INFORMATION TO BE BUILT AND FILLED HERE
2712       
2713       /*Cell Status List*/
2714       ieIdx++;
2715       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_Cells_Status_List;
2716       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2717       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2718            GNBDUConfigurationUpdateIEs__value_PR_Cells_Status_List;
2719       ret = buildCellsStatusList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List);
2720       if(ret == RFAILED)
2721       {
2722          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Cell Status List building failed");
2723          break;
2724       }
2725
2726       /*GNB DU ID */
2727       ieIdx++;
2728       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
2729       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2730       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2731       GNBDUConfigurationUpdateIEs__value_PR_GNB_DU_ID;
2732       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size = sizeof(uint8_t);
2733       DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
2734             duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
2735       if(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == NULLP)
2736       {
2737          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Memory allocation failed for GNB_DU_ID");
2738          break;
2739       }
2740       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] = duCfgParam.duId;
2741
2742       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apDuCfg);
2743
2744       /* Encode the DU Config Update type as APER */
2745       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
2746       encBufSize = 0;
2747       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apDuCfg, PrepFinalEncBuf, encBuf);
2748
2749       /* Checking encode results */
2750       if(encRetVal.encoded == ENCODE_FAIL)
2751       {
2752          DU_LOG("ERROR  -->  F1AP : Could not encode DUConfigUpdate structure (at %s)\n",\
2753                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2754          break;
2755       }
2756       else
2757       {
2758          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DUConfigUpdate\n");
2759 #ifdef DEBUG_ASN_PRINT
2760          for(ieIdx =0; ieIdx < encBufSize; ieIdx++)
2761          {
2762             printf("%x",encBuf[ieIdx]);
2763          }
2764 #endif
2765       }
2766       /* Sending msg */
2767       if(sendF1APMsg() != ROK)
2768       {
2769          DU_LOG("\nERROR  -->  F1AP : Sending GNB-DU Config Update failed");
2770          break;
2771       }
2772
2773       ret = ROK;
2774       break;
2775    }
2776   
2777    addToReservedF1apPduList(TRANS_ID,f1apDuCfg);
2778    return ret;
2779 }
2780
2781
2782 /*******************************************************************
2783  *
2784  * @brief free the ULRRCMessageTransfer
2785  *
2786  * @details
2787  *
2788  *    Function : FreeULRRCMessageTransfer
2789  *
2790  *    Functionality: Deallocating the memory of variable allocated in
2791  *                      FreeULRRCMessageTransfer
2792  *
2793  * @params[in]
2794  *
2795  * @return ROK     - void
2796  *
2797  ******************************************************************/
2798 void FreeULRRCMessageTransfer( F1AP_PDU_t *f1apMsg)
2799 {
2800    uint8_t idx1;
2801    ULRRCMessageTransfer_t  *ulRRCMsg;
2802
2803    if(f1apMsg != NULLP)
2804    { 
2805       if(f1apMsg->choice.initiatingMessage != NULLP)
2806       {
2807          ulRRCMsg = &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2808          if(ulRRCMsg->protocolIEs.list.array != NULLP)
2809          {
2810             for(idx1=0;idx1<ulRRCMsg->protocolIEs.list.count;idx1++)
2811             {
2812                if(ulRRCMsg->protocolIEs.list.array[idx1] != NULLP)
2813                {
2814                   if(ulRRCMsg->protocolIEs.list.array[idx1]->value.present ==
2815                         ULRRCMessageTransferIEs__value_PR_RRCContainer)
2816                   {
2817                      DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2818                            ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2819                   }
2820                   DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1],sizeof(ULRRCMessageTransferIEs_t));
2821                }
2822             }
2823             DU_FREE(ulRRCMsg->protocolIEs.list.array,ulRRCMsg->protocolIEs.list.size );
2824          }
2825          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2826       }
2827       DU_FREE(f1apMsg,sizeof(F1AP_PDU_t));
2828    }
2829 }
2830 /*******************************************************************
2831  *
2832  * @brief Builds and sends the ULRRCMessageTransfer 
2833  *
2834  * @details
2835  *
2836  *    Function : BuildAndSendULRRCMessageTransfer
2837  *
2838  *    Functionality: Constructs the UL RRC Message Transfer and sends
2839  *                   it to the CU through SCTP.
2840  *
2841  * @params[in] 
2842  *
2843  * @return ROK     - success
2844  *         RFAILED - failure
2845  *
2846  * ****************************************************************/
2847 uint8_t BuildAndSendULRRCMessageTransfer(DuUeCb  *ueCb, uint8_t lcId, \
2848       uint16_t msgLen, uint8_t *rrcMsg)
2849 {
2850    uint8_t                 elementCnt=0, idx1=0, idx=0;
2851    uint8_t                 ret = RFAILED;
2852    F1AP_PDU_t              *f1apMsg = NULLP;
2853    ULRRCMessageTransfer_t  *ulRRCMsg = NULLP;
2854    asn_enc_rval_t          encRetVal;        /* Encoder return value */
2855    
2856    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2857
2858    while(true)
2859    {
2860       DU_LOG("\nINFO   -->  F1AP : Building UL RRC Message Transfer Message\n");
2861
2862       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
2863       if(f1apMsg == NULLP)
2864       {
2865          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
2866          break;
2867       }
2868       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
2869       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2870       if(f1apMsg->choice.initiatingMessage == NULLP)
2871       {
2872          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
2873          break;
2874       }
2875       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_ULRRCMessageTransfer;
2876       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
2877       f1apMsg->choice.initiatingMessage->value.present = \
2878                                                          InitiatingMessage__value_PR_ULRRCMessageTransfer;
2879       ulRRCMsg =
2880          &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2881       elementCnt = 4;
2882       ulRRCMsg->protocolIEs.list.count = elementCnt;
2883       ulRRCMsg->protocolIEs.list.size = \
2884                                         elementCnt * sizeof(ULRRCMessageTransferIEs_t *);
2885
2886       /* Initialize the F1Setup members */
2887       DU_ALLOC(ulRRCMsg->protocolIEs.list.array, ulRRCMsg->protocolIEs.list.size);
2888       if(ulRRCMsg->protocolIEs.list.array == NULLP)
2889       {
2890          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UL RRC MessageTransferIEs failed");
2891          break;
2892       }
2893       for(idx=0; idx<elementCnt; idx++)
2894       {
2895          DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx],sizeof(ULRRCMessageTransferIEs_t));
2896          if(ulRRCMsg->protocolIEs.list.array[idx] == NULLP)
2897          {
2898             break;
2899          }
2900       }
2901
2902       idx1 = 0;
2903
2904       /*GNB CU UE F1AP ID*/
2905       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
2906       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2907       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2908                                                               ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
2909       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
2910
2911       /*GNB DU UE F1AP ID*/
2912       idx1++;
2913       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
2914       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2915       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2916                                                               ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
2917       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
2918
2919       /*SRBID*/
2920       idx1++;
2921       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
2922       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2923       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2924                                                               ULRRCMessageTransferIEs__value_PR_SRBID;
2925       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.SRBID = lcId;
2926
2927       /*RRCContainer*/
2928       idx1++;
2929       ulRRCMsg->protocolIEs.list.array[idx1]->id  = ProtocolIE_ID_id_RRCContainer;
2930       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2931       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2932                                                               ULRRCMessageTransferIEs__value_PR_RRCContainer;
2933       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size = msgLen;
2934       DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2935             ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size)
2936       if(!ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf)
2937       {
2938          DU_LOG(" ERROR  -->  F1AP : Memory allocation for BuildAndSendULRRCMessageTransfer failed");
2939          break;
2940       }
2941       memset(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, 0, msgLen);
2942       memcpy(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, \
2943             rrcMsg, ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2944
2945       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
2946
2947       /* Encode the F1SetupRequest type as APER */
2948       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2949       encBufSize = 0;
2950       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
2951             encBuf);
2952       /* Encode results */
2953       if(encRetVal.encoded == ENCODE_FAIL)
2954       {
2955          DU_LOG( "\nERROR  -->  F1AP : Could not encode ULRRCMessageTransfer structure (at %s)\n",\
2956                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2957          break;
2958       }
2959       else
2960       {
2961          DU_LOG("\nDEBUG  -->  F1AP : Created APER encoded buffer for ULRRCMessageTransfer\n");
2962 #ifdef DEBUG_ASN_PRINT
2963          for(int i=0; i< encBufSize; i++)
2964          {
2965             printf("%x",encBuf[i]);
2966          }
2967 #endif
2968       }
2969
2970       /* Sending  msg  */
2971       if(sendF1APMsg()  !=      ROK)
2972       {
2973          DU_LOG("\nERROR  -->   F1AP : Sending  UL RRC Message Transfer Failed");
2974          break;
2975       }
2976       ret = ROK;
2977       break;
2978    }
2979    FreeULRRCMessageTransfer(f1apMsg);
2980
2981    return ret;
2982 }/* End of BuildAndSendULRRCMessageTransfer*/
2983
2984 /*******************************************************************
2985  *
2986  * @brief Builds tag config 
2987  *
2988  * @details
2989  *
2990  *    Function : BuildTagConfig 
2991  *
2992  *    Functionality: Builds tag config in MacCellGroupConfig
2993  *
2994  * @params[in] TAG_Config *tag_Config
2995  *
2996  * @return ROK     - success
2997  *         RFAILED - failure
2998  *
2999  * ****************************************************************/
3000 uint8_t BuildTagConfig(DuUeCb *ueCb, struct TAG_Config *tagConfig)
3001 {
3002    struct TAG_Config__tag_ToAddModList *tagList;
3003    uint8_t                     idx, elementCnt;
3004
3005    tagConfig->tag_ToReleaseList = NULLP;
3006    tagConfig->tag_ToAddModList = NULLP;
3007    DU_ALLOC(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
3008    if(!tagConfig->tag_ToAddModList)
3009    {
3010       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3011       return RFAILED;
3012    }
3013
3014    if(ueCb == NULLP)
3015       elementCnt = ODU_VALUE_ONE;
3016    else
3017       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModListCount;
3018
3019    tagList = tagConfig->tag_ToAddModList;
3020    tagList->list.count = elementCnt;
3021    tagList->list.size  =  elementCnt * sizeof(struct TAG *);
3022
3023    tagList->list.array = NULLP;
3024    DU_ALLOC(tagList->list.array, tagList->list.size);
3025    if(!tagList->list.array)
3026    {
3027       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3028       return RFAILED;
3029    }
3030
3031    for(idx=0; idx<tagList->list.count; idx++)
3032    {
3033       tagList->list.array[idx] = NULLP;
3034       DU_ALLOC(tagList->list.array[idx], sizeof(struct TAG));
3035       if(!tagList->list.array[idx])
3036       {
3037          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3038          return RFAILED;
3039       }
3040    }
3041
3042    if(ueCb == NULLP)
3043    {
3044       idx = 0;
3045       tagList->list.array[idx]->tag_Id = TAG_ID;
3046       tagList->list.array[idx]->timeAlignmentTimer = TIME_ALIGNMENT_TMR;
3047    }
3048    else
3049    {
3050       for(idx=0; idx<tagList->list.count; idx++)
3051       {
3052          tagList->list.array[idx]->tag_Id = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].tagId;
3053          tagList->list.array[idx]->timeAlignmentTimer = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].timeAlignTimer;
3054       }
3055    }
3056
3057    return ROK;
3058 }
3059
3060 /*******************************************************************
3061  *
3062  * @brief Builds PHR Config 
3063  *
3064  * @details
3065  *
3066  *    Function : BuildPhrConfig
3067  *
3068  *    Functionality: Builds phrConfig in MacCellGroupConfig
3069  *
3070  * @params[in] PHR Config *
3071  *
3072  * @return ROK     - success
3073  *         RFAILED - failure
3074  *
3075  * ****************************************************************/
3076 uint8_t BuildPhrConfig(DuUeCb *ueCb, struct MAC_CellGroupConfig__phr_Config *phrConfig)
3077 {
3078
3079    phrConfig->present = MAC_CellGroupConfig__phr_Config_PR_setup;
3080    phrConfig->choice.setup = NULLP;
3081    DU_ALLOC(phrConfig->choice.setup, sizeof(struct PHR_Config));
3082    if(!phrConfig->choice.setup)
3083    {
3084       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhrConfig");
3085       return RFAILED;
3086    }
3087
3088    if(ueCb == NULLP)
3089    {
3090       phrConfig->choice.setup->phr_PeriodicTimer        = PHR_PERIODIC_TMR;
3091       phrConfig->choice.setup->phr_ProhibitTimer        = PHR_PROHIBHIT_TMR;
3092       phrConfig->choice.setup->phr_Tx_PowerFactorChange = PHR_PWR_FACTOR_CHANGE;
3093       phrConfig->choice.setup->multiplePHR              = false;
3094       phrConfig->choice.setup->dummy                    = false;
3095       phrConfig->choice.setup->phr_Type2OtherCell       = false;
3096       phrConfig->choice.setup->phr_ModeOtherCG          = PHR_MODE_OTHER_CG;
3097    }
3098    else
3099    {
3100       phrConfig->choice.setup->phr_PeriodicTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.periodicTimer;
3101       phrConfig->choice.setup->phr_ProhibitTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.prohibitTimer;
3102       phrConfig->choice.setup->phr_Tx_PowerFactorChange = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.txPowerFactor;
3103       phrConfig->choice.setup->multiplePHR              = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.multiplePHR;
3104       phrConfig->choice.setup->dummy                    = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.dummy;
3105       phrConfig->choice.setup->phr_Type2OtherCell       = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrType2OtherCell;
3106       phrConfig->choice.setup->phr_ModeOtherCG          = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrOtherCG;
3107    }
3108
3109    return ROK;
3110 }
3111
3112 /*******************************************************************
3113  *
3114  * @brief Builds BSR Config 
3115  *
3116  * @details
3117  *
3118  *    Function : BuildBsrConfig
3119  *
3120  *    Functionality: Builds BuildBsrConfig in MacCellGroupConfig
3121  *
3122  * @params[in] BSR_Config *bsrConfig
3123  *
3124  * @return ROK     - success
3125  *         RFAILED - failure
3126  *
3127  * ****************************************************************/
3128 uint8_t BuildBsrConfig(DuUeCb *ueCb, struct BSR_Config *bsrConfig)
3129 {
3130    if(ueCb == NULLP)
3131    {
3132       bsrConfig->periodicBSR_Timer = PERIODIC_BSR_TMR;
3133       bsrConfig->retxBSR_Timer     = RETX_BSR_TMR;
3134       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
3135    }
3136    else
3137    {
3138       bsrConfig->periodicBSR_Timer = convertBsrPeriodicTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.periodicTimer);
3139       bsrConfig->retxBSR_Timer     = convertBsrRetxTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.retxTimer);
3140
3141       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
3142       DU_ALLOC(bsrConfig->logicalChannelSR_DelayTimer, sizeof(long));
3143       if(bsrConfig->logicalChannelSR_DelayTimer == NULLP)
3144       {
3145          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildBsrConfig");
3146          return RFAILED;
3147       }
3148       *(bsrConfig->logicalChannelSR_DelayTimer) = convertLcSrDelayTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.srDelayTimer);
3149    }
3150
3151    return ROK;
3152 }
3153
3154 /*******************************************************************
3155  *
3156  * @brief Builds scheduling request config 
3157  *
3158  * @details
3159  *
3160  *    Function : BuildSchedulingReqConfig 
3161  *
3162  *    Functionality: Builds BuildSchedulingReqConfig in MacCellGroupConfig
3163  *
3164  * @params[in] SchedulingRequestConfig *schedulingRequestConfig
3165  *
3166  * @return ROK     - success
3167  *         RFAILED - failure
3168  *
3169  * ****************************************************************/
3170 uint8_t BuildSchedulingReqConfig(DuUeCb *ueCb, struct SchedulingRequestConfig *schedulingRequestConfig)
3171 {
3172    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList;
3173    uint8_t                     idx, elementCnt;
3174
3175    schedulingRequestConfig->schedulingRequestToAddModList = NULLP;
3176    DU_ALLOC(schedulingRequestConfig->schedulingRequestToAddModList,
3177          sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));
3178    if(!schedulingRequestConfig->schedulingRequestToAddModList)
3179    {
3180       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3181       return RFAILED;
3182    }
3183
3184    if(ueCb == NULLP)
3185       elementCnt = ODU_VALUE_ONE;
3186    else
3187       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModListCount;
3188
3189    schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
3190    schReqList->list.count = elementCnt;
3191    schReqList->list.size  = elementCnt * sizeof(struct SchedulingRequestToAddMod *);
3192
3193    schReqList->list.array = NULLP;
3194    DU_ALLOC(schReqList->list.array, schReqList->list.size);
3195    if(!schReqList->list.array)
3196    {
3197       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3198       return RFAILED;
3199    }
3200
3201    for(idx=0; idx<schReqList->list.count; idx++)
3202    {
3203       schReqList->list.array[idx] = NULLP;
3204       DU_ALLOC(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
3205       if(!schReqList->list.array[idx])
3206       {
3207          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3208          return RFAILED;
3209       }
3210    }
3211
3212    if(ueCb == NULLP)
3213    {
3214       idx = 0;
3215       schReqList->list.array[idx]->schedulingRequestId = SCH_REQ_ID;
3216
3217       schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
3218       DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
3219       if(!schReqList->list.array[idx]->sr_ProhibitTimer)
3220       {
3221          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3222          return RFAILED;
3223       }
3224       *(schReqList->list.array[idx]->sr_ProhibitTimer) = SR_PROHIBIT_TMR;
3225       schReqList->list.array[idx]->sr_TransMax = SR_TRANS_MAX;
3226    }
3227    else
3228    {
3229       for(idx=0; idx<schReqList->list.count; idx++)
3230       {
3231          schReqList->list.array[idx]->schedulingRequestId = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].schedReqId;
3232
3233          schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
3234          DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
3235          if(!schReqList->list.array[idx]->sr_ProhibitTimer)
3236          {
3237             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3238             return RFAILED;
3239          }
3240          *(schReqList->list.array[idx]->sr_ProhibitTimer) = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srProhibitTmr;
3241          schReqList->list.array[idx]->sr_TransMax = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srTransMax;
3242       }
3243    }
3244
3245    schedulingRequestConfig->schedulingRequestToReleaseList = NULLP;
3246
3247    return ROK;
3248 }
3249
3250 /*******************************************************************
3251  *
3252  * @brief Builds RLC Configuration for AM mode
3253  *
3254  * @details
3255  *
3256  *    Function : BuildRlcConfigAm
3257  *
3258  *    Functionality: 
3259  *       Builds AM mode RLC Config in BuildRlcBearerToAddModList
3260  *
3261  * @params[in] AmBearerCfg *amCfg
3262  *             RLC_Config_t  *rlcConfig
3263  *
3264  * @return ROK     - success
3265  *         RFAILED - failure
3266  *
3267  * ****************************************************************/
3268 uint8_t BuildRlcConfigAm(AmBearerCfg *amCfg, struct RLC_Config *rlcConfig)
3269 {
3270    rlcConfig->choice.am = NULLP;
3271    DU_ALLOC(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
3272    if(!rlcConfig->choice.am)
3273    {
3274       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3275       return RFAILED;
3276    }
3277
3278    /* Fill AM UL configuration */
3279    rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength = NULLP;
3280    DU_ALLOC(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
3281    if(!rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength)
3282    {
3283       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3284       return RFAILED;
3285    }
3286
3287    /* Fill default AM UL configuration if input pointer to DU database is NULL */
3288    if(amCfg == NULLP)
3289    {
3290       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = SN_FIELD_LEN;
3291       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = T_POLL_RETRANSMIT;
3292       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = POLL_PDU;
3293       rlcConfig->choice.am->ul_AM_RLC.pollByte          = POLL_BYTE;
3294       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = MAX_RETX_THRESHOLD;
3295    }
3296    else
3297    {
3298       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->dlAmCfg.snLenDl);
3299       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = covertPollRetxTmrValueToEnum(amCfg->dlAmCfg.pollRetxTmr);
3300       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = covertPollPduValueToEnum(amCfg->dlAmCfg.pollPdu);
3301       rlcConfig->choice.am->ul_AM_RLC.pollByte          = covertPollByteValueToEnum(amCfg->dlAmCfg.pollByte);
3302       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = covertMaxRetxValueToEnum(amCfg->dlAmCfg.maxRetxTh);
3303    }
3304
3305    /* Fill AM DL configuraion */
3306    rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength = NULLP;
3307    DU_ALLOC(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
3308    if(!rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength)
3309    {
3310       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3311       return RFAILED;
3312    }
3313
3314    /* Fill default AM DL configuration if input pointer to DU database is NULL */
3315    if(amCfg == NULLP)
3316    {
3317       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = SN_FIELD_LEN;
3318       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = T_REASSEMBLY;
3319       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = T_STATUS_PROHIBHIT;
3320    }
3321    else /* Fill AM configuration from DU database */
3322    {
3323       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->ulAmCfg.snLenUl);
3324       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = convertReasmblTmrValueToEnum(amCfg->ulAmCfg.reAssemTmr);
3325       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = convertProhibitTmrValueToEnum(amCfg->ulAmCfg.statProhTmr);
3326    }
3327    return ROK;
3328 }
3329
3330 /*******************************************************************
3331  *
3332  * @brief Builds RLC Config for UM Bidirection
3333  *
3334  * @details
3335  *
3336  *    Function : BuildRlcConfig UmBiDir
3337  *
3338  *    Functionality: 
3339  *       Builds RLC Config for UM Bidirection in BuildRlcBearerToAddModList 
3340  *
3341  * @params[in] UmBiDirBearerCfg *umBiDirCfg
3342  *             RLC_Config_t *rlcConfig
3343  *
3344  * @return ROK     - success
3345  *         RFAILED - failure
3346  *
3347  * ****************************************************************/
3348 uint8_t BuildRlcConfigUmBiDir(UmBiDirBearerCfg *umBiDirCfg, struct RLC_Config *rlcConfig)
3349 {
3350    rlcConfig->choice.um_Bi_Directional = NULLP;
3351    DU_ALLOC(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
3352    if(rlcConfig->choice.um_Bi_Directional == NULLP)
3353    {
3354       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3355       return RFAILED;
3356    }
3357
3358    /* Fill UM Bidirectional UL configuration */
3359    rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength = NULLP;
3360    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3361    if(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength == NULLP)
3362    {
3363       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3364       return RFAILED;
3365    }
3366
3367    if(umBiDirCfg != NULLP)
3368    {
3369       *(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->dlUmCfg.snLenDlUm);     
3370    }
3371
3372    /* Fill UM Bidirectional DL configuration */
3373    rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength = NULLP;
3374    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3375    if(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength == NULLP)
3376    {
3377       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3378       return RFAILED;
3379    }
3380
3381    if(umBiDirCfg != NULLP)
3382    {
3383       *(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->ulUmCfg.snLenUlUm);     
3384       rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umBiDirCfg->ulUmCfg.reAssemTmr);
3385    }
3386
3387    return ROK;
3388 }
3389
3390 /*******************************************************************
3391  *
3392  * @brief Builds RLC Config for UM Uni directional UL
3393  *
3394  * @details
3395  *
3396  *    Function : BuildRlcConfigUmUniDirUl
3397  *
3398  *    Functionality: 
3399  *       Builds RLC Config for UM Unidirection UL in BuildRlcBearerToAddModList 
3400  *
3401  * @params[in] UmUniDirDlBearerCfg *umUniDirDlCfg
3402  *             RLC_Config_t *rlcConfig
3403  *
3404  * @return ROK     - success
3405  *         RFAILED - failure
3406  *
3407  * ****************************************************************/
3408 uint8_t BuildRlcConfigUmUniDirUl(UmUniDirDlBearerCfg *umUniDirDlCfg, RLC_Config_t *rlcConfig)
3409 {
3410    rlcConfig->choice.um_Uni_Directional_UL = NULLP;
3411    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
3412    if(rlcConfig->choice.um_Uni_Directional_UL == NULLP)
3413    {
3414       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3415       return RFAILED;
3416    }
3417
3418    rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength = NULLP;
3419    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3420    if(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength == NULLP)
3421    {
3422       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3423       return RFAILED;
3424    }
3425
3426    if(umUniDirDlCfg != NULLP)
3427    {
3428       *(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirDlCfg->dlUmCfg.snLenDlUm);
3429    }
3430
3431    return ROK;
3432 }
3433
3434 /*******************************************************************
3435  *
3436  * @brief Builds RLC Config for UM Uni directional DL
3437  *
3438  * @details
3439  *
3440  *    Function : BuildRlcConfigUmUniDirDl
3441  *
3442  *    Functionality: 
3443  *       Builds RLC Config for UM Unidirection DL in BuildRlcBearerToAddModList 
3444  *
3445  * @params[in] UmUniDirUlBearerCfg *umUniDirUlCfg
3446  *             RLC_Config_t *rlcConfig
3447  *
3448  * @return ROK     - success
3449  *         RFAILED - failure
3450  *
3451  * ****************************************************************/
3452 uint8_t BuildRlcConfigUmUniDirDl(UmUniDirUlBearerCfg *umUniDirUlCfg, RLC_Config_t *rlcConfig)
3453 {
3454    rlcConfig->choice.um_Uni_Directional_DL = NULLP;
3455    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
3456    if(rlcConfig->choice.um_Uni_Directional_DL == NULLP)
3457    {
3458       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3459       return RFAILED;
3460    }
3461
3462    rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength = NULLP;
3463    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3464    if(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength == NULLP)
3465    {
3466       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3467       return RFAILED;
3468    }
3469
3470    if(umUniDirUlCfg != NULLP)
3471    {
3472       *(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirUlCfg->ulUmCfg.snLenUlUm);
3473       rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umUniDirUlCfg->ulUmCfg.reAssemTmr);
3474    }
3475
3476    return ROK;
3477 }
3478
3479 /*******************************************************************
3480  *
3481  * @brief Builds RLC Config
3482  *
3483  * @details
3484  *
3485  *    Function : BuildRlcConfig
3486  *
3487  *    Functionality: Builds RLC Config in BuildRlcBearerToAddModList 
3488  *
3489  * @params[in] RLC_Config_t *rlcConfig
3490  *
3491  * @return ROK     - success
3492  *         RFAILED - failure
3493  *
3494  * ****************************************************************/
3495 uint8_t BuildRlcConfig(RlcBearerCfg *rbCfg, struct RLC_Config *rlcConfig)
3496 {
3497    
3498    /* Fill default values if rbCfg is NULL */
3499    if(rbCfg == NULLP)
3500    {
3501       rlcConfig->present = RLC_Config_PR_am;
3502       BuildRlcConfigAm(NULLP, rlcConfig);
3503    }
3504    /* If RbCfg is present, fill RLC configurations from DU Database */
3505    else
3506    {
3507       rlcConfig->present = covertRlcModeFromIntEnumToRrcEnum(rbCfg->rlcMode);
3508       switch(rlcConfig->present)
3509       {
3510          case RLC_Config_PR_am:
3511             BuildRlcConfigAm(rbCfg->u.amCfg, rlcConfig);
3512             break;
3513          case RLC_Config_PR_um_Bi_Directional:
3514             BuildRlcConfigUmBiDir(rbCfg->u.umBiDirCfg, rlcConfig);
3515             break;
3516          case RLC_Config_PR_um_Uni_Directional_UL:
3517             BuildRlcConfigUmUniDirUl(rbCfg->u.umUniDirDlCfg, rlcConfig);
3518             break;
3519          case RLC_Config_PR_um_Uni_Directional_DL:
3520             BuildRlcConfigUmUniDirDl(rbCfg->u.umUniDirUlCfg, rlcConfig);
3521             break;
3522          case RLC_Config_PR_NOTHING:
3523          default:
3524             break;
3525       }
3526    }
3527
3528    return ROK;
3529 }
3530
3531 /*******************************************************************
3532  *
3533  * @brief Builds MAC LC Config
3534  *
3535  * @details
3536  *
3537  *    Function : BuildMacLCConfig 
3538  *
3539  *    Functionality: Builds MAC LC Config in BuildRlcBearerToAddModList 
3540  *
3541  * @params[in] struct LogicalChannelConfig macLcConfig
3542  *
3543  * @return ROK     - success
3544  *         RFAILED - failure
3545  *
3546  * ****************************************************************/
3547 uint8_t BuildMacLCConfig(LcCfg *lcCfgDb, struct LogicalChannelConfig *macLcConfig)
3548 {
3549    macLcConfig->ul_SpecificParameters = NULLP;
3550    DU_ALLOC(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
3551    if(!macLcConfig->ul_SpecificParameters)
3552    {
3553       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3554       return RFAILED;
3555    }
3556
3557    if(lcCfgDb == NULLP)
3558    {
3559       macLcConfig->ul_SpecificParameters->priority = MAC_LC_PRIORITY;
3560       macLcConfig->ul_SpecificParameters->prioritisedBitRate =  PRIORTISIED_BIT_RATE;
3561       macLcConfig->ul_SpecificParameters->bucketSizeDuration =  BUCKET_SIZE_DURATION;
3562    }
3563    else
3564    {
3565       macLcConfig->ul_SpecificParameters->priority = lcCfgDb->ulLcCfg.priority;
3566       macLcConfig->ul_SpecificParameters->prioritisedBitRate = lcCfgDb->ulLcCfg.pbr;
3567       macLcConfig->ul_SpecificParameters->bucketSizeDuration = lcCfgDb->ulLcCfg.bsd;
3568    }
3569
3570    macLcConfig->ul_SpecificParameters->allowedServingCells = NULLP;
3571    macLcConfig->ul_SpecificParameters->allowedSCS_List = NULLP;
3572    macLcConfig->ul_SpecificParameters->maxPUSCH_Duration = NULLP;
3573    macLcConfig->ul_SpecificParameters->configuredGrantType1Allowed = NULLP;
3574
3575    macLcConfig->ul_SpecificParameters->logicalChannelGroup = NULLP;
3576    DU_ALLOC(macLcConfig->ul_SpecificParameters->logicalChannelGroup,    sizeof(long));
3577    if(!macLcConfig->ul_SpecificParameters->logicalChannelGroup)
3578    {
3579       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3580       return RFAILED;
3581    }
3582
3583    if(lcCfgDb == NULLP)
3584       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = LC_GRP;
3585    else
3586       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = lcCfgDb->ulLcCfg.lcGroup;
3587
3588    macLcConfig->ul_SpecificParameters->schedulingRequestID = NULLP;
3589    DU_ALLOC(macLcConfig->ul_SpecificParameters->schedulingRequestID,    sizeof(SchedulingRequestId_t));
3590    if(!macLcConfig->ul_SpecificParameters->schedulingRequestID)
3591    {
3592       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3593       return RFAILED;
3594    }
3595
3596    if(lcCfgDb == NULLP)
3597       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = SCH_REQ_ID;
3598    else
3599       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = lcCfgDb->ulLcCfg.schReqId;
3600
3601    macLcConfig->ul_SpecificParameters->logicalChannelSR_Mask = false;
3602    macLcConfig->ul_SpecificParameters->logicalChannelSR_DelayTimerApplied = false;
3603    macLcConfig->ul_SpecificParameters->bitRateQueryProhibitTimer = NULLP;
3604
3605    return ROK;
3606 }
3607
3608 /*******************************************************************
3609  *
3610  * @brief Builds RLC Bearer to Add/Mod list
3611  *
3612  * @details
3613  *
3614  *    Function :BuildRlcBearerToAddModList 
3615  *
3616  *    Functionality: Builds RLC Bearer to Add/Mod list in DuToCuRrcContainer
3617  *
3618  * @params[in] rlc_BearerToAddModList
3619  *
3620  * @return ROK     - success
3621  *         RFAILED - failure
3622  *
3623  * ****************************************************************/
3624 uint8_t BuildRlcBearerToAddModList(DuUeCb *ueCb, struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList)
3625 {
3626    uint8_t  idx = 0, lcIdx=0, macLcIdx = 0, elementCnt = 0;
3627
3628    if(ueCb == NULLP)
3629       elementCnt = 1;
3630    else if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
3631       elementCnt = ueCb->duRlcUeCfg.numLcs;
3632    else
3633    {
3634       for(lcIdx = 0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3635       {
3636          if(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == false)
3637             elementCnt++;
3638       }
3639    }
3640    rlcBearerList->list.count = elementCnt;
3641    rlcBearerList->list.size  = elementCnt * sizeof(struct RLC_BearerConfig *);
3642
3643    rlcBearerList->list.array = NULLP;
3644    DU_ALLOC(rlcBearerList->list.array, rlcBearerList->list.size);
3645    if(!rlcBearerList->list.array)
3646    {
3647       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3648       return RFAILED;
3649    }
3650
3651    for(idx=0; idx<rlcBearerList->list.count; idx++)
3652    {
3653       rlcBearerList->list.array[idx] = NULLP;
3654       DU_ALLOC(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
3655       if(!rlcBearerList->list.array[idx])
3656       {
3657          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3658          return RFAILED;
3659       }
3660    }
3661
3662    if(ueCb == NULLP)
3663    {
3664       idx=0;
3665       rlcBearerList->list.array[idx]->logicalChannelIdentity = SRB1_LCID;
3666       DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3667       if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3668       {     
3669          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3670          return RFAILED;
3671       }     
3672       rlcBearerList->list.array[idx]->servedRadioBearer->present = RLC_BearerConfig__servedRadioBearer_PR_srb_Identity;
3673       rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = SRB1_LCID;
3674       rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3675
3676       /* Fill RLC related Configurations for this Radio Bearer */
3677       rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3678       DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3679       if(!rlcBearerList->list.array[idx]->rlc_Config)
3680       {
3681          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3682          return RFAILED;
3683       }
3684       if(BuildRlcConfig(NULLP, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3685       {
3686          DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3687          return RFAILED;
3688       }
3689
3690       /* Fill MAC related configurations for this Radio Bearer */
3691       rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3692       DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3693       if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3694       {
3695          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3696          return RFAILED;
3697       }
3698       if(BuildMacLCConfig(NULLP, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3699       {
3700          DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3701          return RFAILED;
3702       }
3703    }
3704    else
3705    {
3706       idx=0;
3707       for(lcIdx=0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3708       {
3709          if((ueCb->f1UeDb->actionType != UE_CTXT_CFG_QUERY) && (ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == true))
3710             continue;
3711
3712          /* Fill Logical channel identity */
3713          rlcBearerList->list.array[idx]->logicalChannelIdentity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId;
3714
3715          /* Fill Radio Bearer Id and type (DRB/SRB) for this logical channel */
3716          DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3717          if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3718          {
3719             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3720             return RFAILED;
3721          }
3722          rlcBearerList->list.array[idx]->servedRadioBearer->present = \
3723                                                                       covertRbTypeFromIntEnumToRrcEnum(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbType);
3724          switch(rlcBearerList->list.array[idx]->servedRadioBearer->present)
3725          {
3726             case RLC_BearerConfig__servedRadioBearer_PR_srb_Identity: 
3727                rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3728                break;
3729             case RLC_BearerConfig__servedRadioBearer_PR_drb_Identity:
3730                rlcBearerList->list.array[idx]->servedRadioBearer->choice.drb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3731                break;
3732             case RLC_BearerConfig__servedRadioBearer_PR_NOTHING:
3733             default:
3734                break;
3735          }
3736          ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent = true;
3737
3738          rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3739
3740          /* Fill RLC related Configurations for this Radio Bearer */
3741          rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3742          DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3743          if(!rlcBearerList->list.array[idx]->rlc_Config)
3744          {
3745             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3746             return RFAILED;
3747          }
3748          if(BuildRlcConfig(&ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3749          {
3750             DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3751             return RFAILED;
3752          }
3753
3754          /* Fill MAC related configurations for this Radio Bearer */
3755          rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3756          DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3757          if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3758          {
3759             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3760             return RFAILED;
3761          }
3762          for(macLcIdx = 0; macLcIdx < ueCb->duMacUeCfg.numLcs; macLcIdx++)
3763          {
3764             if(ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig.lcId == ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId)
3765             {
3766                if(BuildMacLCConfig(&ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3767                {
3768                   DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3769                   return RFAILED;
3770                }
3771                break;
3772             }
3773          }
3774
3775          idx++;
3776       }
3777    }
3778    return ROK;
3779 }
3780
3781 /*******************************************************************
3782  *
3783  * @brief Build Control resource set to add/modify list 
3784  *
3785  * @details
3786  *
3787  *    Function : BuildControlRSetToAddModList
3788  *
3789  *    Functionality: Build Control resource set to add/modify list
3790  *
3791  * @params[in] 
3792  * struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList
3793  *
3794  * @return ROK     - success
3795  *         RFAILED - failure
3796  *
3797  * ****************************************************************/
3798 uint8_t BuildControlRSetToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList)
3799 {
3800    uint8_t idx;
3801    uint8_t elementCnt;
3802    uint8_t numBytes, bitsUnused;
3803    struct ControlResourceSet *controlRSet;
3804    uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
3805    uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
3806
3807    if(pdcchCfg == NULLP)
3808       elementCnt = 1;
3809    else
3810       elementCnt = pdcchCfg->numCRsetToAddMod;
3811
3812    controlRSetList->list.count = elementCnt;
3813    controlRSetList->list.size = elementCnt * sizeof(struct ControlResourceSet *);
3814
3815    controlRSetList->list.array = NULLP;
3816    DU_ALLOC(controlRSetList->list.array, controlRSetList->list.size);
3817    if(!controlRSetList->list.array)
3818    {
3819       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3820       return RFAILED;
3821    }
3822
3823    for(idx = 0; idx < elementCnt; idx++)
3824    {
3825       controlRSetList->list.array[idx] = NULLP;
3826       DU_ALLOC(controlRSetList->list.array[idx], sizeof(struct ControlResourceSet));
3827       if(!controlRSetList->list.array[idx])
3828       {
3829          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3830          return RFAILED;
3831       }
3832    }
3833
3834    for(idx = 0; idx < elementCnt; idx++)
3835    {
3836       controlRSet = controlRSetList->list.array[idx];
3837
3838       if(pdcchCfg == NULLP)
3839          controlRSet->controlResourceSetId = PDCCH_CTRL_RSRC_SET_ONE_ID;
3840       else
3841          controlRSet->controlResourceSetId = pdcchCfg->cRSetToAddModList[idx].cRSetId;
3842
3843       /* size 6 bytes
3844        * 3 LSBs unsued
3845        * Bit string stored ff0000000000
3846        */
3847       numBytes = 6;
3848       bitsUnused = 3;
3849       controlRSet->frequencyDomainResources.size = numBytes * sizeof(uint8_t);
3850
3851       controlRSet->frequencyDomainResources.buf = NULLP;
3852       DU_ALLOC(controlRSet->frequencyDomainResources.buf, controlRSet->frequencyDomainResources.size);
3853       if(!controlRSet->frequencyDomainResources.buf)
3854       {
3855          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3856          return RFAILED;
3857       }
3858
3859       memset(controlRSet->frequencyDomainResources.buf, 0, FREQ_DOM_RSRC_SIZE);
3860
3861       if(pdcchCfg == NULLP)
3862       {
3863          coreset0EndPrb = CORESET0_END_PRB;
3864          coreset1StartPrb = coreset0EndPrb + 6;
3865          coreset1NumPrb = CORESET1_NUM_PRB;
3866          /* calculate the PRBs */
3867          fillCoresetFeqDomAllocMap(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
3868          memcpy(controlRSet->frequencyDomainResources.buf, freqDomainResource, FREQ_DOM_RSRC_SIZE);
3869          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3870
3871          controlRSet->duration = PDCCH_CTRL_RSRC_SET_ONE_DURATION;
3872          controlRSet->cce_REG_MappingType.present = ControlResourceSet__cce_REG_MappingType_PR_nonInterleaved;
3873          controlRSet->precoderGranularity = PDCCH_CTRL_RSRC_SET_ONE_PRECOD_GRANULARITY;
3874       }
3875       else
3876       {
3877          memcpy(controlRSet->frequencyDomainResources.buf, pdcchCfg->cRSetToAddModList[idx].freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
3878          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3879          controlRSet->duration = pdcchCfg->cRSetToAddModList[idx].duration;
3880          controlRSet->cce_REG_MappingType.present = pdcchCfg->cRSetToAddModList[idx].cceRegMappingType;
3881          controlRSet->precoderGranularity = pdcchCfg->cRSetToAddModList[idx].precoderGranularity;
3882       }
3883       controlRSet->tci_StatesPDCCH_ToAddList = NULLP;
3884       controlRSet->tci_StatesPDCCH_ToReleaseList = NULLP;
3885       controlRSet->tci_PresentInDCI = NULLP;
3886
3887 #if 0
3888       uint8_t tciStateIdx;
3889
3890       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList, \
3891             sizeof(struct ControlResourceSet__tci_StatesPDCCH_ToAddList));
3892       if(!controlRset->tci_StatesPDCCH_ToAddList)
3893       {
3894          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3895          return RFAILED;
3896       }
3897
3898       elementCnt = 1;
3899       controlRset->tci_StatesPDCCH_ToAddList->list.count = elementCnt;
3900       controlRset->tci_StatesPDCCH_ToAddList->list.size = elementCnt * sizeof(TCI_StateId_t *);
3901       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array, \
3902             controlRset->tci_StatesPDCCH_ToAddList->list.size)
3903          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array)
3904          {
3905             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3906             return RFAILED;
3907          }
3908
3909       for(tciStateIdx = 0; tciStateIdx <elementCntl; tciStateIdx++)
3910       {
3911          DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx], sizeof(TCI_StateId_t));
3912          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx])
3913          {
3914             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3915             return RFAILED;
3916          }
3917       }
3918
3919       tciStateIdx = 0;
3920       /* TODO */
3921       *(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx]);
3922
3923       DU_ALLOC(controlRset->tci_PresentInDCI, sizeof(long));
3924       if(!controlRset->tci_PresentInDCI)
3925       {
3926          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3927          return RFAILED;
3928       }
3929       /* TODO */
3930       *(controlRset->tci_PresentInDCI);
3931 #endif
3932
3933       controlRSet->pdcch_DMRS_ScramblingID = NULLP;
3934       DU_ALLOC(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
3935       if(!controlRSet->pdcch_DMRS_ScramblingID)
3936       {
3937          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3938          return RFAILED;
3939       }
3940       if(pdcchCfg == NULLP)
3941          *(controlRSet->pdcch_DMRS_ScramblingID) = SCRAMBLING_ID;
3942       else
3943          *(controlRSet->pdcch_DMRS_ScramblingID) = pdcchCfg->cRSetToAddModList[idx].dmrsScramblingId;
3944    }
3945    return ROK;
3946 } /* End BuildControlRSetToAddModList */
3947
3948 /*******************************************************************
3949  *
3950  * @brief Build search space to add/modify list
3951  *
3952  * @details
3953  *
3954  *    Function : BuildSearchSpcToAddModList
3955  *
3956  *    Functionality: Build search space to add/modify list
3957  *
3958  * @params[in] 
3959  * @return ROK     - success
3960  *         RFAILED - failure
3961  *
3962  * ****************************************************************/
3963 uint8_t BuildSearchSpcToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
3964 {
3965    uint8_t idx;
3966    uint8_t numBytes;
3967    uint8_t byteIdx;
3968    uint8_t bitsUnused;
3969    uint8_t elementCnt;
3970    struct SearchSpace *searchSpc;
3971
3972    if(pdcchCfg == NULLP)
3973       elementCnt = 1;
3974    else
3975       elementCnt = pdcchCfg->numSearchSpcToAddMod;
3976
3977    searchSpcList->list.count = elementCnt;
3978    searchSpcList->list.size = elementCnt * sizeof(struct SearchSpace *);
3979
3980    searchSpcList->list.array = NULLP;
3981    DU_ALLOC(searchSpcList->list.array, searchSpcList->list.size);
3982    if(!searchSpcList->list.array)
3983    {
3984       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3985       return RFAILED;
3986    }
3987
3988    for(idx = 0; idx < elementCnt; idx++)
3989    {
3990       searchSpcList->list.array[idx] = NULLP;
3991       DU_ALLOC(searchSpcList->list.array[idx], sizeof(struct SearchSpace));
3992       if(!searchSpcList->list.array[idx])
3993       {
3994          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3995          return RFAILED;
3996       }
3997    }
3998
3999    for(idx = 0; idx < elementCnt; idx++)
4000    {
4001       searchSpc = searchSpcList->list.array[idx];
4002
4003       if(pdcchCfg == NULLP)
4004          searchSpc->searchSpaceId = PDCCH_SRCH_SPC_TWO_ID;
4005       else
4006          searchSpc->searchSpaceId = pdcchCfg->searchSpcToAddModList[idx].searchSpaceId;
4007
4008       searchSpc->controlResourceSetId = NULLP;
4009       DU_ALLOC(searchSpc->controlResourceSetId, sizeof(ControlResourceSetId_t));
4010       if(!searchSpc->controlResourceSetId)
4011       {
4012          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4013          return RFAILED;
4014       }
4015       if(pdcchCfg == NULLP)
4016          *(searchSpc->controlResourceSetId) = PDCCH_CTRL_RSRC_SET_ONE_ID;
4017       else
4018          *(searchSpc->controlResourceSetId) = pdcchCfg->searchSpcToAddModList[idx].cRSetId;
4019
4020       searchSpc->monitoringSlotPeriodicityAndOffset = NULLP;
4021       DU_ALLOC(searchSpc->monitoringSlotPeriodicityAndOffset, sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
4022       if(!searchSpc->monitoringSlotPeriodicityAndOffset)
4023       {
4024          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4025          return RFAILED;
4026       }
4027       if(pdcchCfg == NULLP)
4028          searchSpc->monitoringSlotPeriodicityAndOffset->present = SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
4029       else
4030          searchSpc->monitoringSlotPeriodicityAndOffset->present = pdcchCfg->searchSpcToAddModList[idx].mSlotPeriodicityAndOffset;
4031
4032       searchSpc->duration = NULLP;
4033       searchSpc->monitoringSymbolsWithinSlot = NULLP;
4034       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot, sizeof(BIT_STRING_t));
4035       if(!searchSpc->monitoringSymbolsWithinSlot)
4036       {
4037          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4038          return RFAILED;
4039       }
4040
4041       /* Values taken from reference logs :
4042        * size 2 bytes
4043        * 2 LSBs unsued
4044        * Bit string stores 8000
4045        */
4046       numBytes = 2;
4047       bitsUnused = 2;
4048       searchSpc->monitoringSymbolsWithinSlot->size = numBytes * sizeof(uint8_t);
4049       searchSpc->monitoringSymbolsWithinSlot->buf = NULLP;
4050       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot->buf, searchSpc->monitoringSymbolsWithinSlot->size);
4051       if(!searchSpc->monitoringSymbolsWithinSlot->buf)
4052       {
4053          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4054          return RFAILED;
4055       }
4056       if(pdcchCfg == NULLP)
4057       {
4058          byteIdx = 0;
4059          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = PDCCH_SYMBOL_WITHIN_SLOT /* setting MSB to 128 i.e. 0x80 */;
4060          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = 0;
4061       }
4062       else
4063          memcpy(searchSpc->monitoringSymbolsWithinSlot->buf, pdcchCfg->searchSpcToAddModList[idx].mSymbolsWithinSlot, numBytes);
4064       searchSpc->monitoringSymbolsWithinSlot->bits_unused = bitsUnused;
4065
4066       searchSpc->nrofCandidates = NULLP;
4067       DU_ALLOC(searchSpc->nrofCandidates, sizeof(struct SearchSpace__nrofCandidates));
4068       if(!searchSpc->nrofCandidates)
4069       {
4070          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4071          return RFAILED;
4072       }
4073
4074       if(pdcchCfg == NULLP)
4075       {
4076          searchSpc->nrofCandidates->aggregationLevel1 = PDCCH_SRCH_SPC_TWO_AGG_LVL1_CANDIDATE;
4077          searchSpc->nrofCandidates->aggregationLevel2 = PDCCH_SRCH_SPC_TWO_AGG_LVL2_CANDIDATE;
4078          searchSpc->nrofCandidates->aggregationLevel4 = PDCCH_SRCH_SPC_TWO_AGG_LVL4_CANDIDATE;
4079          searchSpc->nrofCandidates->aggregationLevel8 = PDCCH_SRCH_SPC_TWO_AGG_LVL8_CANDIDATE;
4080          searchSpc->nrofCandidates->aggregationLevel16 = PDCCH_SRCH_SPC_TWO_AGG_LVL16_CANDIDATE;
4081       }
4082       else
4083       {
4084          searchSpc->nrofCandidates->aggregationLevel1 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel1;
4085          searchSpc->nrofCandidates->aggregationLevel2 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel2;
4086          searchSpc->nrofCandidates->aggregationLevel4 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel4;
4087          searchSpc->nrofCandidates->aggregationLevel8 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel8;
4088          searchSpc->nrofCandidates->aggregationLevel16 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel16;
4089       }
4090
4091       searchSpc->searchSpaceType = NULLP;
4092       DU_ALLOC(searchSpc->searchSpaceType, sizeof(struct SearchSpace__searchSpaceType));
4093       if(!searchSpc->searchSpaceType)
4094       {
4095          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4096          return RFAILED;
4097       }
4098       if(pdcchCfg == NULLP)
4099          searchSpc->searchSpaceType->present = SearchSpace__searchSpaceType_PR_ue_Specific;
4100       else
4101          searchSpc->searchSpaceType->present = pdcchCfg->searchSpcToAddModList[idx].searchSpaceType;
4102
4103       searchSpc->searchSpaceType->choice.ue_Specific = NULLP;
4104       DU_ALLOC(searchSpc->searchSpaceType->choice.ue_Specific, sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
4105       if(!searchSpc->searchSpaceType->choice.ue_Specific)
4106       {
4107          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4108          return RFAILED;
4109       }  
4110       if(pdcchCfg == NULLP)
4111          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
4112       else
4113          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = pdcchCfg->searchSpcToAddModList[idx].ueSpecificDciFormat;
4114    }
4115    return ROK;
4116 }/* End BuildSearchSpcToAddModList */
4117
4118 /*******************************************************************
4119  *
4120  * @brief Builds BWP DL dedicated PDCCH config
4121  *
4122  * @details
4123  *
4124  *    Function : BuildBWPDlDedPdcchCfg
4125  *
4126  *    Functionality: Builds BWP DL dedicated PDCCH config
4127  *
4128  * @params[in] struct PDCCH_Config *pdcchCfg
4129  *
4130  * @return ROK     - success
4131  *         RFAILED - failure
4132  *
4133  * ****************************************************************/
4134 uint8_t BuildBWPDlDedPdcchCfg(PdcchConfig *pdcchCfgDb, struct PDCCH_Config *pdcchCfg)
4135 {
4136    pdcchCfg->controlResourceSetToAddModList = NULLP;
4137    DU_ALLOC(pdcchCfg->controlResourceSetToAddModList, sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
4138    if(!pdcchCfg->controlResourceSetToAddModList)
4139    {
4140       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
4141       return RFAILED;
4142    }
4143
4144    if(BuildControlRSetToAddModList(pdcchCfgDb, pdcchCfg->controlResourceSetToAddModList) != ROK)
4145    {
4146       DU_LOG("\nERROR  --> F1AP : Failed in BuildControlRSetToAddModList()");
4147       return RFAILED;
4148    }
4149
4150    pdcchCfg->controlResourceSetToReleaseList = NULLP;
4151
4152    pdcchCfg->searchSpacesToAddModList = NULLP;
4153    DU_ALLOC(pdcchCfg->searchSpacesToAddModList, sizeof(struct PDCCH_Config__searchSpacesToAddModList));
4154    if(!pdcchCfg->searchSpacesToAddModList)
4155    {
4156       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
4157       return RFAILED;
4158    }
4159
4160    if(BuildSearchSpcToAddModList(pdcchCfgDb, pdcchCfg->searchSpacesToAddModList) != ROK)
4161    {
4162       DU_LOG("\nERROR  --> F1AP : Failed in BuildSearchSpcToAddModList()");
4163       return RFAILED;
4164    }
4165
4166    pdcchCfg->searchSpacesToReleaseList = NULLP;
4167    pdcchCfg->downlinkPreemption = NULLP;
4168    pdcchCfg->tpc_PUSCH = NULLP;
4169    pdcchCfg->tpc_PUCCH = NULLP;
4170    pdcchCfg->tpc_SRS = NULLP;
4171
4172    return ROK;
4173 }
4174
4175 /*******************************************************************
4176  *
4177  * @brief Builds DMRS DL PDSCH Mapping type A
4178  *
4179  * @details
4180  *
4181  *    Function : BuildDMRSDLPdschMapTypeA
4182  *
4183  *    Functionality: Builds DMRS DL PDSCH Mapping type A
4184  *
4185  * @params[in]
4186  * struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg
4187  * @return ROK     - success
4188  *         RFAILED - failure
4189  *
4190  * ****************************************************************/
4191 uint8_t BuildDMRSDLPdschMapTypeA(PdschConfig *pdschCfg, struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg)
4192 {
4193    dmrsDlCfg->present = PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup;
4194    dmrsDlCfg->choice.setup = NULLP;
4195    DU_ALLOC(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
4196    if(!dmrsDlCfg->choice.setup)
4197    {
4198       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
4199       return RFAILED;
4200    }
4201
4202    dmrsDlCfg->choice.setup->dmrs_Type = NULLP;
4203    dmrsDlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4204    DU_ALLOC(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4205    if(!dmrsDlCfg->choice.setup->dmrs_AdditionalPosition)
4206    {
4207       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
4208       return RFAILED;
4209    }
4210    if(pdschCfg == NULLP)
4211       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS;
4212    else
4213       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = pdschCfg->dmrsDlCfgForPdschMapTypeA.addPos;
4214
4215    dmrsDlCfg->choice.setup->maxLength = NULLP;
4216    dmrsDlCfg->choice.setup->scramblingID0 = NULLP;
4217    dmrsDlCfg->choice.setup->scramblingID1 = NULLP;
4218    dmrsDlCfg->choice.setup->phaseTrackingRS = NULLP;
4219
4220    return ROK;
4221 }
4222
4223 /*******************************************************************
4224  *
4225  * @brief Builds TCI states to add/modify list
4226  *
4227  * @details
4228  *
4229  *    Function : BuildTCIStatesToAddModList
4230  *
4231  *    Functionality:Builds TCI states to add/modify list
4232  *
4233  * @params[in] 
4234  * struct PDSCH_Config__tci_StatesToAddModList *tciStatesList
4235  *
4236  * @return ROK     - success
4237  *         RFAILED - failure
4238  *
4239  * ****************************************************************/
4240 uint8_t BuildTCIStatesToAddModList(struct PDSCH_Config__tci_StatesToAddModList *tciStatesList)
4241 {
4242    return ROK;
4243 }
4244
4245 /*******************************************************************
4246  *
4247  * @brief Builds PDSCH time domain allocation list
4248  *
4249  * @details
4250  *
4251  *    Function : BuildPdschTimeDomAllocList
4252  *
4253  *    Functionality: Builds PDSCH time domain allocation list
4254  *
4255  * @params[in] 
4256  * struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
4257  *
4258  * @return ROK     - success
4259  *         RFAILED - failure
4260  *
4261  * ****************************************************************/
4262 uint8_t BuildPdschTimeDomAllocList(PdschConfig *pdschCfg, struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
4263 {
4264    uint8_t idx;
4265    uint8_t elementCnt;
4266    struct PDSCH_TimeDomainResourceAllocation *timeDomAlloc;
4267
4268    timeDomAllocList->present = PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup;
4269
4270    timeDomAllocList->choice.setup = NULLP;
4271    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PDSCH_TimeDomainResourceAllocationList));
4272    if(!timeDomAllocList->choice.setup)
4273    {
4274       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4275       return RFAILED;
4276    }
4277
4278 if(pdschCfg == NULLP)
4279    elementCnt = 2;
4280 else
4281 elementCnt = pdschCfg->numTimeDomRsrcAlloc;
4282    timeDomAllocList->choice.setup->list.count = elementCnt;
4283    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(struct PDSCH_TimeDomainResourceAllocation *);
4284
4285    timeDomAllocList->choice.setup->list.array = NULLP;
4286    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4287    if(!timeDomAllocList->choice.setup->list.array)
4288    {
4289       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4290       return RFAILED;
4291    }
4292
4293    for(idx = 0; idx < elementCnt; idx++)
4294    {
4295       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4296       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], \
4297             sizeof(struct PDSCH_TimeDomainResourceAllocation));
4298       if(!timeDomAllocList->choice.setup->list.array[idx])
4299       {
4300          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4301          return RFAILED;
4302       }
4303    }
4304
4305    if(pdschCfg == NULLP)
4306    {
4307       idx = 0;
4308       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4309       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4310       if(!timeDomAlloc->k0)
4311       {
4312          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4313          return RFAILED;
4314       }
4315       *(timeDomAlloc->k0) = 0;
4316       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4317       timeDomAlloc->startSymbolAndLength = \
4318                                            calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4319
4320       idx++;
4321       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4322       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4323       if(!timeDomAlloc->k0)
4324       {
4325          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4326          return RFAILED;
4327       }
4328       *(timeDomAlloc->k0) = 1;
4329       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4330       timeDomAlloc->startSymbolAndLength = calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4331    }
4332    else
4333    {
4334       for(idx = 0; idx < elementCnt; idx++)
4335       {
4336          timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4337          if(pdschCfg->timeDomRsrcAllociList[idx].k0)
4338          {
4339             DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4340             if(!timeDomAlloc->k0)
4341             {
4342                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4343                return RFAILED;
4344             }
4345             *(timeDomAlloc->k0) = *(pdschCfg->timeDomRsrcAllociList[idx].k0);
4346          }
4347          timeDomAlloc->mappingType = pdschCfg->timeDomRsrcAllociList[idx].mappingType;
4348          timeDomAlloc->startSymbolAndLength = pdschCfg->timeDomRsrcAllociList[idx].startSymbolAndLength;
4349       }
4350    }
4351
4352    return ROK;
4353 }
4354
4355 /*******************************************************************
4356  *
4357  * @brief Builds PDSCH PRB Bundling type
4358  *
4359  * @details
4360  *
4361  *    Function : BuildPdschPrbBundlingType
4362  *
4363  *    Functionality: Builds PDSCH PRB Bundling type
4364  *
4365  * @params[in] 
4366  * struct PDSCH_Config__prb_BundlingType *prbBndlType
4367  *
4368  * @return ROK     - success
4369  *         RFAILED - failure
4370  *
4371  * ****************************************************************/
4372 uint8_t BuildPdschPrbBundlingType(PdschConfig *pdschCfg, struct PDSCH_Config__prb_BundlingType *prbBndlType)
4373 {
4374    if(pdschCfg == NULLP)
4375       prbBndlType->present = PDSCH_Config__prb_BundlingType_PR_staticBundling;
4376    else
4377       prbBndlType->present = pdschCfg->bundlingType;
4378
4379    prbBndlType->choice.staticBundling = NULLP;
4380    DU_ALLOC(prbBndlType->choice.staticBundling, \
4381          sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
4382    if(!prbBndlType->choice.staticBundling)
4383    {
4384       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschPrbBundlingType");
4385       return RFAILED;
4386    }
4387    prbBndlType->choice.staticBundling->bundleSize = NULLP;
4388
4389    return ROK;
4390 }
4391
4392 /*******************************************************************
4393  *
4394  * @brief Builds BWP DL dedicated PDSCH config 
4395  *
4396  * @details
4397  *
4398  *    Function : BuildBWPDlDedPdschCfg
4399  *
4400  *    Functionality: Builds BWP DL dedicated PDSCH config
4401  *
4402  * @params[in] struct PDSCH_Config *pdschCfg
4403  *
4404  * @return ROK     - success
4405  *         RFAILED - failure
4406  *
4407  * ****************************************************************/
4408 uint8_t BuildBWPDlDedPdschCfg(PdschConfig *pdschCfgDb, struct PDSCH_Config *pdschCfg)
4409 {
4410    pdschCfg->dataScramblingIdentityPDSCH = NULLP;
4411
4412    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA = NULLP;
4413    DU_ALLOC(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
4414    if(!pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
4415    {
4416       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4417       return RFAILED;
4418    }
4419
4420    if(BuildDMRSDLPdschMapTypeA(pdschCfgDb, pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA) != ROK)
4421    {
4422       return RFAILED;
4423    }
4424
4425    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeB = NULLP;
4426    pdschCfg->tci_StatesToAddModList = NULLP;
4427    pdschCfg->tci_StatesToReleaseList = NULLP;
4428    pdschCfg->vrb_ToPRB_Interleaver = NULLP;
4429 #if 0
4430    DU_ALLOC(pdschCfg->tci_StatesToAddModList, sizeof(struct PDSCH_Config__tci_StatesToAddModList));
4431    if(!pdschCfg->tci_StatesToAddModList)
4432    {
4433       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4434       return RFAILED;
4435    }
4436    if(BuildTCIStatesToAddModList(pdschCfg->tci_StatesToAddModList) != ROK)
4437    {
4438       return RFAILED;
4439    }
4440 #endif
4441
4442 if(pdschCfgDb == NULLP)
4443    pdschCfg->resourceAllocation = RES_ALLOC_TYPE;
4444 else
4445 pdschCfg->resourceAllocation = pdschCfgDb->resourceAllocType;
4446
4447    pdschCfg->pdsch_TimeDomainAllocationList = NULLP;
4448    DU_ALLOC(pdschCfg->pdsch_TimeDomainAllocationList, sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
4449    if(!pdschCfg->pdsch_TimeDomainAllocationList)
4450    {
4451       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4452       return RFAILED;
4453    }
4454    if(BuildPdschTimeDomAllocList(pdschCfgDb, pdschCfg->pdsch_TimeDomainAllocationList) != ROK)
4455    {
4456       return RFAILED;
4457    }
4458
4459    pdschCfg->pdsch_AggregationFactor = NULLP;
4460    pdschCfg->rateMatchPatternToAddModList = NULLP;
4461    pdschCfg->rateMatchPatternToReleaseList = NULLP;
4462    pdschCfg->rateMatchPatternGroup1 = NULLP;
4463    pdschCfg->rateMatchPatternGroup2 = NULLP;
4464    if(pdschCfgDb == NULLP)
4465       pdschCfg->rbg_Size = PDSCH_RBG_SIZE;
4466    else
4467       pdschCfg->rbg_Size = pdschCfgDb->rbgSize;
4468    pdschCfg->mcs_Table = NULLP;
4469
4470    pdschCfg->maxNrofCodeWordsScheduledByDCI = NULLP;
4471    DU_ALLOC(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
4472    if(!pdschCfg->maxNrofCodeWordsScheduledByDCI)
4473    {
4474       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4475       return RFAILED;
4476    }
4477    if(pdschCfgDb == NULLP)
4478       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = PDSCH_MAX_CODEWORD_SCH_BY_DCI;
4479    else
4480       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = pdschCfgDb->numCodeWordsSchByDci;
4481
4482    if(BuildPdschPrbBundlingType(pdschCfgDb, &pdschCfg->prb_BundlingType) != ROK)
4483    {
4484       return RFAILED;
4485    }
4486
4487    pdschCfg->zp_CSI_RS_ResourceToAddModList = NULLP;
4488    pdschCfg->zp_CSI_RS_ResourceToReleaseList = NULLP;
4489    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4490    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4491    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4492    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4493    pdschCfg->p_ZP_CSI_RS_ResourceSet = NULLP;
4494
4495    return ROK;
4496 }
4497
4498 /*******************************************************************
4499  *
4500  * @brief Builds intitial DL BWP
4501  * @details
4502  *
4503  *    Function : BuildInitialDlBWP 
4504  *
4505  *    Functionality: Builds intitial DL BWP in spCellCfgDed
4506  *
4507  * @params[in] BWP_DownlinkDedicated_t *dlBwp
4508  *
4509  * @return ROK     - success
4510  *         RFAILED - failure
4511  *
4512  * ****************************************************************/
4513 uint8_t BuildInitialDlBWP(InitialDlBwp *initiDlBwp, BWP_DownlinkDedicated_t *dlBwp)
4514 {
4515    PdcchConfig *pdcchCfg = NULLP;
4516    PdschConfig *pdschCfg = NULLP;
4517
4518    if(initiDlBwp)
4519    {
4520       if(initiDlBwp->pdcchPresent)
4521          pdcchCfg = &initiDlBwp->pdcchCfg;
4522       if(initiDlBwp->pdschPresent)
4523          pdschCfg = &initiDlBwp->pdschCfg;
4524    }
4525
4526    dlBwp->pdcch_Config = NULLP;
4527    DU_ALLOC(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
4528    if(!dlBwp->pdcch_Config)
4529    {
4530       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4531       return RFAILED;
4532    }
4533    dlBwp->pdcch_Config->present = BWP_DownlinkDedicated__pdcch_Config_PR_setup; 
4534
4535    dlBwp->pdcch_Config->choice.setup = NULLP;
4536    DU_ALLOC(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
4537    if(!dlBwp->pdcch_Config->choice.setup)
4538    {
4539       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4540       return RFAILED;
4541    }
4542    if(BuildBWPDlDedPdcchCfg(pdcchCfg, dlBwp->pdcch_Config->choice.setup) != ROK)
4543    {
4544       return RFAILED;
4545    }
4546
4547    dlBwp->pdsch_Config = NULLP;
4548    DU_ALLOC(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
4549    if(!dlBwp->pdsch_Config)
4550    {
4551       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4552       return RFAILED;
4553    }
4554    dlBwp->pdsch_Config->present = BWP_DownlinkDedicated__pdsch_Config_PR_setup;
4555
4556    dlBwp->pdsch_Config->choice.setup = NULLP;
4557    DU_ALLOC(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
4558    if(!dlBwp->pdsch_Config->choice.setup)
4559    {
4560       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4561       return RFAILED;
4562    }
4563
4564    if(BuildBWPDlDedPdschCfg(pdschCfg, dlBwp->pdsch_Config->choice.setup) != ROK)
4565    {
4566       return RFAILED;
4567    }
4568
4569    dlBwp->sps_Config = NULLP;
4570    dlBwp->radioLinkMonitoringConfig = NULLP; 
4571    return ROK;
4572 }
4573
4574 /*******************************************************************
4575  *
4576  * @brief Builds DMRS UL Pusch Mapping type A
4577  *
4578  * @details
4579  *
4580  *    Function : BuildDMRSULPuschMapTypeA
4581  *
4582  *    Functionality: Builds DMRS UL Pusch Mapping type A
4583  *
4584  * @params[in] 
4585  *    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg
4586  * @return ROK     - success
4587  *         RFAILED - failure
4588  *
4589  * ****************************************************************/
4590 uint8_t BuildDMRSULPuschMapTypeA(DmrsUlCfg *ulDmrsCfgDb, struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg)
4591 {
4592    dmrsUlCfg->present = PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup;
4593    dmrsUlCfg->choice.setup= NULLP;
4594    DU_ALLOC(dmrsUlCfg->choice.setup, sizeof(DMRS_UplinkConfig_t));
4595    if(!dmrsUlCfg->choice.setup)
4596    {
4597       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4598       return RFAILED;
4599    }
4600
4601    dmrsUlCfg->choice.setup->dmrs_Type = NULLP;
4602    dmrsUlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4603    DU_ALLOC(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4604    if(!dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
4605    {
4606       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4607       return RFAILED;
4608    }
4609    if(ulDmrsCfgDb == NULLP)
4610       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS; 
4611    else
4612       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = ulDmrsCfgDb->addPos;
4613
4614    dmrsUlCfg->choice.setup->phaseTrackingRS = NULLP;
4615    dmrsUlCfg->choice.setup->maxLength = NULLP;
4616    dmrsUlCfg->choice.setup->transformPrecodingDisabled = NULLP;
4617    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled, sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
4618    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled)
4619    {
4620       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4621       return RFAILED;
4622    }
4623
4624    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0 = NULLP;
4625    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
4626          sizeof(long));
4627    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0)
4628    {
4629       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4630       return RFAILED;
4631    }
4632    if(ulDmrsCfgDb == NULLP)
4633       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = SCRAMBLING_ID;
4634    else
4635       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = ulDmrsCfgDb->transPrecodDisabled.scramblingId0;
4636
4637    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID1 = NULLP;
4638    dmrsUlCfg->choice.setup->transformPrecodingEnabled = NULLP;
4639    return ROK;
4640 }
4641
4642 /*******************************************************************
4643  *
4644  * @brief Build PUSCH time domain allocation list
4645  *
4646  * @details
4647  *
4648  *    Function : BuildPuschTimeDomAllocList
4649  *
4650  *    Functionality: Build PUSCH time domain allocation list
4651  *
4652  * @params[in] 
4653  * struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList
4654  *
4655  * @return ROK     - success
4656  *         RFAILED - failure
4657  *
4658  * ****************************************************************/
4659 uint8_t BuildPuschTimeDomAllocList(PuschCfg *puschCfgDb, struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList)
4660 {
4661    uint8_t idx;
4662    uint8_t elementCnt;
4663    PUSCH_TimeDomainResourceAllocation_t  *timeDomAlloc;
4664
4665    timeDomAllocList->present = PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup;
4666    timeDomAllocList->choice.setup = NULLP;
4667    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PUSCH_TimeDomainResourceAllocationList));
4668    if(!timeDomAllocList->choice.setup)
4669    {
4670       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4671       return RFAILED;
4672    }
4673
4674    if(puschCfgDb == NULLP)
4675       elementCnt = 2;
4676    else
4677       elementCnt = puschCfgDb->numTimeDomRsrcAlloc;
4678
4679    timeDomAllocList->choice.setup->list.count = elementCnt;
4680    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(PUSCH_TimeDomainResourceAllocation_t *);
4681    timeDomAllocList->choice.setup->list.array = NULLP;
4682    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4683    if(!timeDomAllocList->choice.setup->list.array)
4684    {
4685       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4686       return RFAILED;
4687    }
4688
4689    for(idx = 0; idx < elementCnt; idx++)
4690    {
4691       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4692       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], sizeof(PUSCH_TimeDomainResourceAllocation_t));
4693       if(!timeDomAllocList->choice.setup->list.array[idx])
4694       {
4695          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4696          return RFAILED;
4697       }
4698    }
4699
4700    for(idx = 0; idx < elementCnt; idx++)
4701    {
4702       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4703       DU_ALLOC(timeDomAlloc->k2, sizeof(long));
4704       if(!timeDomAlloc->k2)
4705       {
4706          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4707          return RFAILED;
4708       }
4709       if(puschCfgDb == NULLP)
4710       {
4711          if(idx == 0)
4712             *(timeDomAlloc->k2) = PUSCH_K2_CFG1;
4713          else if(idx == 1)
4714             *(timeDomAlloc->k2) = PUSCH_K2_CFG2;
4715
4716          timeDomAlloc->mappingType = PUSCH_MAPPING_TYPE_A;
4717          timeDomAlloc->startSymbolAndLength = calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
4718       }
4719       else
4720       {
4721          *(timeDomAlloc->k2) = puschCfgDb->timeDomRsrcAllocList[idx].k2;
4722          timeDomAlloc->mappingType = puschCfgDb->timeDomRsrcAllocList[idx].mappingType;
4723          timeDomAlloc->startSymbolAndLength = puschCfgDb->timeDomRsrcAllocList[idx].startSymbolAndLength;
4724       }
4725    }
4726
4727    return ROK;
4728 }
4729
4730 /*******************************************************************
4731  *
4732  * @brief Builds BWP UL dedicated PUSCH Config
4733  *
4734  * @details
4735  *
4736  *    Function : BuildBWPUlDedPuschCfg
4737  *
4738  *    Functionality:
4739  *      Builds BWP UL dedicated PUSCH Config
4740  *
4741  * @params[in] : PUSCH_Config_t *puschCfg
4742  *    
4743  * @return ROK     - success
4744  *         RFAILED - failure
4745  *
4746  * ****************************************************************/
4747 uint8_t BuildBWPUlDedPuschCfg(PuschCfg *puschCfgDb, PUSCH_Config_t *puschCfg)
4748 {
4749    DmrsUlCfg *ulDmrsCfg = NULLP;
4750    
4751    if(puschCfgDb)
4752       ulDmrsCfg = &puschCfgDb->dmrsUlCfgForPuschMapTypeA;
4753
4754    puschCfg->dataScramblingIdentityPUSCH = NULLP;
4755    DU_ALLOC(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
4756    if(!puschCfg->dataScramblingIdentityPUSCH)
4757    {
4758       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4759       return RFAILED;
4760    }
4761    if(puschCfgDb == NULLP)
4762       *(puschCfg->dataScramblingIdentityPUSCH) = SCRAMBLING_ID;
4763    else
4764       *(puschCfg->dataScramblingIdentityPUSCH) = puschCfgDb->dataScramblingId;
4765
4766    puschCfg->txConfig = NULLP;
4767    puschCfg->dmrs_UplinkForPUSCH_MappingTypeA = NULLP;
4768    DU_ALLOC(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
4769    if(!puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
4770    {
4771       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4772       return RFAILED;
4773    }
4774
4775    if(BuildDMRSULPuschMapTypeA(ulDmrsCfg, puschCfg->dmrs_UplinkForPUSCH_MappingTypeA) != ROK)
4776    {
4777       return RFAILED;
4778    }
4779
4780    puschCfg->dmrs_UplinkForPUSCH_MappingTypeB = NULLP;
4781    puschCfg->pusch_PowerControl = NULLP;
4782    puschCfg->frequencyHopping = NULLP;
4783    puschCfg->frequencyHoppingOffsetLists = NULLP;
4784
4785    if(puschCfgDb == NULLP)
4786       puschCfg->resourceAllocation = RES_ALLOC_TYPE;
4787    else
4788       puschCfg->resourceAllocation = puschCfgDb->resourceAllocType;
4789
4790    puschCfg->pusch_TimeDomainAllocationList = NULLP;
4791    DU_ALLOC(puschCfg->pusch_TimeDomainAllocationList, sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
4792    if(!puschCfg->pusch_TimeDomainAllocationList)
4793    {
4794       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4795       return RFAILED;
4796    }
4797
4798    if(BuildPuschTimeDomAllocList(puschCfgDb, puschCfg->pusch_TimeDomainAllocationList) != ROK)
4799    {
4800       return RFAILED;
4801    }
4802
4803    puschCfg->pusch_AggregationFactor = NULLP;
4804    puschCfg->mcs_Table = NULLP;
4805    puschCfg->mcs_TableTransformPrecoder = NULLP;
4806    puschCfg->transformPrecoder = NULLP;
4807    DU_ALLOC(puschCfg->transformPrecoder, sizeof(long));
4808    if(!puschCfg->transformPrecoder)
4809    {
4810       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4811       return RFAILED;
4812    }
4813    if(puschCfgDb == NULLP)
4814       *(puschCfg->transformPrecoder) = PUSCH_TRANSFORM_PRECODER;
4815    else
4816       *(puschCfg->transformPrecoder) = puschCfgDb->transformPrecoder;
4817
4818    puschCfg->codebookSubset = NULLP;
4819    puschCfg->maxRank = NULLP;
4820    puschCfg->rbg_Size = NULLP;
4821    puschCfg->uci_OnPUSCH = NULLP;
4822    puschCfg->tp_pi2BPSK = NULLP;
4823
4824    return ROK;
4825 }
4826
4827 /*******************************************************************
4828  *
4829  * @brief Builds PUCCH resource set add/modify list
4830  *
4831  * @details
4832  *
4833  *    Function : BuildPucchRsrcSetAddModList
4834  *
4835  *    Functionality:
4836  *      Builds PUCCH resource set add/modify list
4837  *
4838  * @params[in] : PucchResrcSetCfg *rsrcSetCfgDb
4839  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4840  *
4841  * @return ROK     - success
4842  *         RFAILED - failure
4843  *
4844  * ****************************************************************/
4845 uint8_t BuildPucchRsrcSetAddModList(PucchResrcSetCfg *rsrcSetCfgDb, \
4846    struct PUCCH_Config__resourceSetToAddModList *resourceSetToAddModList)
4847 {
4848    uint8_t elementCnt = 0, rsrcSetIdx = 0, rsrcIdx = 0;
4849    PUCCH_ResourceSet_t *rsrcSet = NULLP;
4850
4851    if(rsrcSetCfgDb == NULLP)
4852       elementCnt = 1;
4853    else
4854       elementCnt = rsrcSetCfgDb->resrcSetToAddModListCount;
4855
4856    resourceSetToAddModList->list.count = elementCnt;
4857    resourceSetToAddModList->list.size = elementCnt * sizeof(PUCCH_ResourceSet_t *);
4858    DU_ALLOC(resourceSetToAddModList->list.array, resourceSetToAddModList->list.size);
4859    if(resourceSetToAddModList->list.array == NULLP)
4860    {
4861       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4862       return RFAILED;
4863    }
4864    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4865    {
4866       DU_ALLOC(resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
4867       if(resourceSetToAddModList->list.array[rsrcSetIdx] == NULLP)
4868       {
4869          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4870          return RFAILED;
4871       }
4872    }
4873
4874    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4875    {
4876       rsrcSet = resourceSetToAddModList->list.array[rsrcSetIdx];
4877
4878       /* Resource set Id */
4879       if(rsrcSetCfgDb == NULLP)
4880          rsrcSet->pucch_ResourceSetId = 1;
4881       else
4882          rsrcSet->pucch_ResourceSetId = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcSetId;
4883  
4884       /* Resource list of a resource set */
4885       if(rsrcSetCfgDb == NULLP)
4886          elementCnt = 1;
4887       else
4888          elementCnt = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcListCount;
4889       rsrcSet->resourceList.list.count = elementCnt;
4890       rsrcSet->resourceList.list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
4891       DU_ALLOC(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
4892       if(rsrcSet->resourceList.list.array == NULLP)
4893       {
4894          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4895          return RFAILED;
4896       }
4897
4898       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4899       {
4900          DU_ALLOC(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
4901          if(rsrcSet->resourceList.list.array[rsrcIdx] == NULLP)
4902          {
4903             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4904             return RFAILED;
4905          }
4906       }
4907       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4908       {
4909          if(rsrcSetCfgDb == NULLP)
4910             *(rsrcSet->resourceList.list.array[rsrcIdx]) = 1;
4911          else
4912             *(rsrcSet->resourceList.list.array[rsrcIdx]) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcList[rsrcIdx];
4913       }
4914
4915       /* Max payload size (minus 1) in a Resource set */
4916       rsrcSet->maxPayloadMinus1 = NULLP;
4917       if(rsrcSetCfgDb && rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize)
4918       {
4919          DU_ALLOC(rsrcSet->maxPayloadMinus1, sizeof(long));
4920          if(rsrcSet->maxPayloadMinus1 == NULLP)
4921          {
4922             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4923             return RFAILED;
4924          }
4925          *(rsrcSet->maxPayloadMinus1) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize;
4926       }
4927    }
4928    return ROK;
4929 }
4930
4931 /*******************************************************************
4932  *
4933  * @brief Builds PUCCH resource add/modify list
4934  *
4935  * @details
4936  *
4937  *    Function : BuildPucchRsrcAdddModList
4938  *
4939  *    Functionality:
4940  *      Builds PUCCH resource add/modify list
4941  *
4942  * @params[in] : PucchResrcCfg *rsrcSetCfgDb
4943  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4944  *
4945  * @return ROK     - success
4946  *         RFAILED - failure
4947  *
4948  * ****************************************************************/
4949 uint8_t BuildPucchRsrcAddModList(PucchResrcCfg *rsrcCfgDb, struct PUCCH_Config__resourceToAddModList  *resourceToAddModList)
4950 {
4951    uint8_t elementCnt = 0, rsrcIdx = 0;
4952    PUCCH_Resource_t *rsrc = NULLP;
4953
4954    if(rsrcCfgDb == NULLP)
4955       elementCnt = 1;
4956    else
4957       elementCnt = rsrcCfgDb->resrcToAddModListCount;
4958    resourceToAddModList->list.count = elementCnt;
4959    resourceToAddModList->list.size = elementCnt * sizeof(PUCCH_Resource_t *);
4960    DU_ALLOC(resourceToAddModList->list.array, resourceToAddModList->list.size);
4961    if(resourceToAddModList->list.array == NULLP)
4962    {
4963       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4964       return RFAILED;
4965    }
4966    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4967    {
4968       DU_ALLOC(resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
4969       if(resourceToAddModList->list.array[rsrcIdx] == NULLP)
4970       {
4971          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4972          return RFAILED;
4973       }
4974    }
4975
4976    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4977    {
4978       rsrc = resourceToAddModList->list.array[rsrcIdx];
4979
4980       if(rsrcCfgDb == NULLP)
4981       {
4982          rsrc->pucch_ResourceId = 1;
4983          rsrc->startingPRB = 0;
4984          rsrc->format.present = PUCCH_Resource__format_PR_format1; 
4985          DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4986          if(rsrc->format.choice.format1 == NULLP)
4987          {
4988             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4989             return RFAILED;
4990          }  
4991          rsrc->format.choice.format1->initialCyclicShift = 0;
4992          rsrc->format.choice.format1->nrofSymbols = 4;
4993          rsrc->format.choice.format1->startingSymbolIndex = 0;
4994          rsrc->format.choice.format1->timeDomainOCC = 0;
4995       }
4996       else
4997       {
4998          rsrc->pucch_ResourceId = rsrcCfgDb->resrcToAddModList[rsrcIdx].resrcId;
4999          rsrc->startingPRB = rsrcCfgDb->resrcToAddModList[rsrcIdx].startPrb;
5000          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop)
5001          {
5002             DU_ALLOC(rsrc->intraSlotFrequencyHopping, sizeof(long));
5003             if(rsrc->intraSlotFrequencyHopping == NULLP)
5004             {
5005                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5006                return RFAILED;
5007             }
5008             *(rsrc->intraSlotFrequencyHopping) = rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop;
5009          }
5010          else
5011             rsrc->intraSlotFrequencyHopping = NULLP;
5012
5013          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop)
5014          {
5015             DU_ALLOC(rsrc->secondHopPRB, sizeof(PRB_Id_t));
5016             if(rsrc->secondHopPRB == NULLP)
5017             {
5018                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5019                return RFAILED;
5020             }
5021             *(rsrc->secondHopPRB) = rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop;
5022          }
5023          else
5024             rsrc->secondHopPRB = NULLP;
5025          rsrc->format.present = covertPucchFormatIntEnumToRrcEnum(rsrcCfgDb->resrcToAddModList[rsrcIdx].pucchFormat); 
5026
5027          switch(rsrc->format.present)
5028          {
5029             case PUCCH_Resource__format_PR_NOTHING:
5030                break;
5031             case PUCCH_Resource__format_PR_format0:
5032                {
5033                   DU_ALLOC(rsrc->format.choice.format0, sizeof(PUCCH_format0_t));
5034                   if(rsrc->format.choice.format0 == NULLP)
5035                   {
5036                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5037                      return RFAILED;
5038                   }
5039                   rsrc->format.choice.format0->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->initialCyclicShift;
5040                   rsrc->format.choice.format0->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->numSymbols;
5041                   rsrc->format.choice.format0->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->startSymbolIdx;
5042                   break;
5043                }
5044
5045             case PUCCH_Resource__format_PR_format1:
5046                {
5047                   DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
5048                   if(rsrc->format.choice.format1 == NULLP)
5049                   {
5050                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5051                      return RFAILED;
5052                   }  
5053                   rsrc->format.choice.format1->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->initialCyclicShift;
5054                   rsrc->format.choice.format1->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->numSymbols;
5055                   rsrc->format.choice.format1->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->startSymbolIdx;
5056                   rsrc->format.choice.format1->timeDomainOCC = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->timeDomOCC;
5057                   break;
5058                }
5059
5060             case PUCCH_Resource__format_PR_format2:
5061                {
5062                   DU_ALLOC(rsrc->format.choice.format2, sizeof(PUCCH_format2_t));
5063                   if(rsrc->format.choice.format2 == NULLP)
5064                   {
5065                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5066                      return RFAILED;
5067                   } 
5068                   rsrc->format.choice.format2->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numPrbs;
5069                   rsrc->format.choice.format2->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numSymbols;
5070                   rsrc->format.choice.format2->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->startSymbolIdx;
5071                   break;
5072                }
5073
5074             case PUCCH_Resource__format_PR_format3:
5075                {
5076                   DU_ALLOC(rsrc->format.choice.format3, sizeof(PUCCH_format3_t));
5077                   if(rsrc->format.choice.format3 == NULLP)
5078                   {
5079                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5080                      return RFAILED;
5081                   }
5082                   rsrc->format.choice.format3->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numPrbs;
5083                   rsrc->format.choice.format3->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numSymbols;
5084                   rsrc->format.choice.format3->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->startSymbolIdx;
5085                   break;
5086                }
5087
5088             case PUCCH_Resource__format_PR_format4:
5089                {
5090                   DU_ALLOC(rsrc->format.choice.format4, sizeof(PUCCH_format4_t));
5091                   if(rsrc->format.choice.format4 == NULLP)
5092                   {
5093                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5094                      return RFAILED;
5095                   }
5096                   rsrc->format.choice.format4->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->numSymbols;
5097                   rsrc->format.choice.format4->occ_Length = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occLen;
5098                   rsrc->format.choice.format4->occ_Index = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occIdx;
5099                   rsrc->format.choice.format4->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->startSymbolIdx;
5100                   break;
5101                }
5102          }
5103       }
5104    }
5105    return ROK;
5106 }
5107
5108 /*******************************************************************
5109  *
5110  * @brief Builds PUCCH format  config
5111  *
5112  * @details
5113  *
5114  *    Function : BuildPucchFormat
5115  *
5116  *    Functionality: Builds PUCCH format  config
5117  *
5118  * @params[in] : PucchFormatCfg *formatDb
5119  *               PUCCH_FormatConfig_t *format
5120  *
5121  * @return ROK     - success
5122  *         RFAILED - failure
5123  *
5124  * ****************************************************************/
5125 uint8_t BuildPucchFormat(PucchFormatCfg *formatDb, PUCCH_FormatConfig_t *format)
5126 {
5127    /* Inter Slot Fequency hopping */
5128    format->interslotFrequencyHopping = NULLP;
5129    if((formatDb != NULLP) && (formatDb->interSlotFreqHop == true))
5130    {
5131       DU_ALLOC(format->interslotFrequencyHopping, sizeof(long));
5132       if(format->interslotFrequencyHopping)
5133       {
5134          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5135          return RFAILED;
5136       }
5137       *(format->interslotFrequencyHopping) = PUCCH_FormatConfig__interslotFrequencyHopping_enabled;
5138    }
5139
5140    /* Additional DMRS */
5141    format->additionalDMRS = NULLP;
5142    if((formatDb != NULLP) && (formatDb->addDmrs == true))
5143    {
5144       DU_ALLOC(format->additionalDMRS, sizeof(long));
5145       if(format->additionalDMRS)
5146       {
5147          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5148          return RFAILED;
5149       }
5150       *(format->additionalDMRS) = PUCCH_FormatConfig__additionalDMRS_true;
5151    }
5152
5153     /* Maximum code rate */
5154    format->maxCodeRate = NULLP;
5155    if((formatDb != NULLP) && (formatDb->maxCodeRate != 0))
5156    {
5157       DU_ALLOC(format->maxCodeRate, sizeof(long));
5158       if(format->maxCodeRate)
5159       {
5160          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5161          return RFAILED;
5162       }  
5163       *(format->maxCodeRate) = formatDb->maxCodeRate;
5164    }
5165  
5166    /* Number of slots */
5167    format->nrofSlots = NULLP;
5168    if((formatDb == NULLP) || ((formatDb != NULLP) && (formatDb->numSlots != 0)))
5169    {
5170       DU_ALLOC(format->nrofSlots, sizeof(long));
5171       if(format->nrofSlots == NULLP)
5172       {
5173          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5174          return RFAILED;
5175       }
5176       if(formatDb == NULLP)
5177          *(format->nrofSlots) = PUCCH_FormatConfig__nrofSlots_n4;
5178       else
5179          *(format->nrofSlots) = formatDb->numSlots;
5180    }
5181
5182    /* Pi2BPSK*/
5183    format->pi2BPSK = NULLP;
5184    if((formatDb != NULLP) && (formatDb->pi2BPSK == true))
5185    {
5186       DU_ALLOC(format->pi2BPSK, sizeof(long));
5187       if(format->pi2BPSK)
5188       {     
5189          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5190          return RFAILED;
5191       }     
5192       *(format->pi2BPSK) = PUCCH_FormatConfig__pi2BPSK_enabled;
5193    }
5194
5195    /* Simultaneous HARQ ACK and CSI */
5196    format->simultaneousHARQ_ACK_CSI = NULLP;
5197    if((formatDb != NULLP) && (formatDb->harqAckCSI == true))
5198    {
5199       DU_ALLOC(format->simultaneousHARQ_ACK_CSI, sizeof(long));
5200       if(format->simultaneousHARQ_ACK_CSI)
5201       {     
5202          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5203          return RFAILED;
5204       }     
5205       *(format->simultaneousHARQ_ACK_CSI) = PUCCH_FormatConfig__simultaneousHARQ_ACK_CSI_true;
5206    }
5207
5208    return ROK;
5209 }
5210
5211
5212 /*******************************************************************
5213  *
5214  * @brief Builds PUCCH scheduling request list
5215  *
5216  * @details
5217  *
5218  *    Function : BuildPucchSchReqAddModList
5219  *
5220  *    Functionality:
5221  *      Builds PUCCH scheduling request list
5222  *
5223  * @params[in] : PucchSchedReqCfg *schReqDb
5224  *               struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList
5225  *
5226  * @return ROK     - success
5227  *         RFAILED - failure
5228  *
5229  * ****************************************************************/
5230 uint8_t BuildPucchSchReqAddModList(PucchSchedReqCfg *schReqDb, \
5231    struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList)
5232 {
5233    uint8_t elementCnt = 0, schReqIdx = 0;
5234    SchedulingRequestResourceConfig_t *schReqRsrc;
5235
5236    elementCnt = schReqDb->schedAddModListCount;
5237    schReqRsrcToAddModList->list.count = elementCnt;
5238    schReqRsrcToAddModList->list.size = elementCnt *sizeof(struct SchedulingRequestResourceConfig *);
5239
5240    schReqRsrcToAddModList->list.array = NULLP;
5241    DU_ALLOC(schReqRsrcToAddModList->list.array, schReqRsrcToAddModList->list.size);
5242    if(schReqRsrcToAddModList->list.array == NULLP)
5243    {
5244       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5245       return RFAILED;
5246    }
5247
5248    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
5249    {
5250       DU_ALLOC(schReqRsrcToAddModList->list.array[schReqIdx], schReqRsrcToAddModList->list.size);
5251       if(schReqRsrcToAddModList->list.array[schReqIdx] == NULLP)
5252       {
5253          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5254          return RFAILED;
5255       }
5256    }
5257
5258    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
5259    {
5260       schReqRsrc = schReqRsrcToAddModList->list.array[schReqIdx];
5261       schReqRsrc->schedulingRequestResourceId = schReqDb->schedAddModList[schReqIdx].resrcId;
5262       schReqRsrc->schedulingRequestID = schReqDb->schedAddModList[schReqIdx].requestId;
5263
5264       if(schReqDb->schedAddModList[schReqIdx].periodicity)
5265       {
5266          schReqRsrc->periodicityAndOffset = NULLP;
5267          DU_ALLOC(schReqRsrc->periodicityAndOffset, sizeof(struct SchedulingRequestResourceConfig__periodicityAndOffset));
5268          if(schReqRsrc->periodicityAndOffset == NULLP)
5269          {
5270             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5271             return RFAILED;
5272          }
5273
5274          schReqRsrc->periodicityAndOffset->present = schReqDb->schedAddModList[schReqIdx].periodicity;
5275          switch(schReqRsrc->periodicityAndOffset->present)
5276          {
5277             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_NOTHING:
5278                break;
5279             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
5280                schReqRsrc->periodicityAndOffset->choice.sym2 = schReqDb->schedAddModList[schReqIdx].offset;
5281                break;
5282             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
5283                schReqRsrc->periodicityAndOffset->choice.sym6or7 = schReqDb->schedAddModList[schReqIdx].offset;
5284                break;
5285             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
5286                schReqRsrc->periodicityAndOffset->choice.sl1 = schReqDb->schedAddModList[schReqIdx].offset;
5287                break;
5288             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
5289                schReqRsrc->periodicityAndOffset->choice.sl2 = schReqDb->schedAddModList[schReqIdx].offset;
5290                break;
5291             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
5292                schReqRsrc->periodicityAndOffset->choice.sl4 = schReqDb->schedAddModList[schReqIdx].offset;
5293                break;
5294             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
5295                schReqRsrc->periodicityAndOffset->choice.sl5 = schReqDb->schedAddModList[schReqIdx].offset;
5296                break;
5297             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
5298                schReqRsrc->periodicityAndOffset->choice.sl8 = schReqDb->schedAddModList[schReqIdx].offset;
5299                break;
5300             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
5301                schReqRsrc->periodicityAndOffset->choice.sl10 = schReqDb->schedAddModList[schReqIdx].offset;
5302                break;
5303             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
5304                schReqRsrc->periodicityAndOffset->choice.sl16 = schReqDb->schedAddModList[schReqIdx].offset;
5305                break;
5306             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
5307                schReqRsrc->periodicityAndOffset->choice.sl20 = schReqDb->schedAddModList[schReqIdx].offset;
5308                break;
5309             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
5310                schReqRsrc->periodicityAndOffset->choice.sl40 = schReqDb->schedAddModList[schReqIdx].offset;
5311                break;
5312             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
5313                schReqRsrc->periodicityAndOffset->choice.sl80 = schReqDb->schedAddModList[schReqIdx].offset;
5314                break;
5315             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
5316                schReqRsrc->periodicityAndOffset->choice.sl160 = schReqDb->schedAddModList[schReqIdx].offset;
5317                break;
5318             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
5319                schReqRsrc->periodicityAndOffset->choice.sl320 = schReqDb->schedAddModList[schReqIdx].offset;
5320                break;
5321             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
5322                schReqRsrc->periodicityAndOffset->choice.sl640 = schReqDb->schedAddModList[schReqIdx].offset;
5323                break;
5324          }
5325       }
5326
5327       if(schReqDb->schedAddModList[schReqIdx].resrc)
5328       {
5329          schReqRsrc->resource = NULLP;
5330          DU_ALLOC(schReqRsrc->resource, sizeof(PUCCH_ResourceId_t));
5331          if(schReqRsrc->resource == NULLP)
5332          {
5333             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5334             return RFAILED;
5335          }
5336          *(schReqRsrc->resource) = schReqDb->schedAddModList[schReqIdx].resrc;
5337
5338       }
5339    }
5340    return ROK;
5341 }
5342
5343 /*******************************************************************
5344  *
5345  * @brief Builds PUCCH multi csi resource list
5346  *
5347  * @details
5348  *
5349  *    Function : BuildPucchMultiCsiRsrcList
5350  *
5351  *    Functionality:
5352  *      Builds PUCCH multi csi resource list
5353  *
5354  * @params[in] : PucchMultiCsiCfg *multiCsiDb
5355  *               struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList
5356  *
5357  * @return ROK     - success
5358  *         RFAILED - failure
5359  *
5360  * ****************************************************************/
5361 uint8_t BuildPucchMultiCsiRsrcList(PucchMultiCsiCfg *multiCsiDb, struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList)
5362 {
5363    uint8_t elementCnt = 0, rsrcIdx = 0;
5364
5365    elementCnt = multiCsiDb->multiCsiResrcListCount;
5366    multiCsiRsrcList->list.count = elementCnt;
5367    multiCsiRsrcList->list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
5368    multiCsiRsrcList->list.array = NULLP;
5369    DU_ALLOC(multiCsiRsrcList->list.array, multiCsiRsrcList->list.size);
5370    if(multiCsiRsrcList->list.array == NULLP)
5371    {
5372       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5373       return RFAILED;
5374    }
5375
5376    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5377    {
5378       DU_ALLOC(multiCsiRsrcList->list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
5379       if(multiCsiRsrcList->list.array[rsrcIdx] == NULLP)
5380       {
5381          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5382          return RFAILED;
5383       }
5384    }
5385
5386    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5387    {
5388       *(multiCsiRsrcList->list.array[rsrcIdx]) = multiCsiDb->multiCsiResrcList[rsrcIdx];
5389    }
5390    return ROK;
5391 }
5392
5393 /*******************************************************************
5394  *
5395  * @brief Builds DL data -to- Ul Ack list
5396  *
5397  * @details
5398  *
5399  *    Function : BuildDlDataToUlAckList
5400  *
5401  *    Functionality: Builds DL data -to- Ul Ack list
5402  *
5403  * @params[in] : PucchDlDataToUlAck *dlDataToUlAckDb
5404  *               struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList
5405  *
5406  * @return ROK     - success
5407  *         RFAILED - failure
5408  *
5409  * ****************************************************************/
5410 uint8_t BuildDlDataToUlAckList(PucchDlDataToUlAck *dlDataToUlAckDb, struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList)
5411 {
5412    uint8_t elementCnt = 0, arrIdx = 0;
5413
5414    if(dlDataToUlAckDb == NULLP)
5415       elementCnt = 2;
5416    else
5417       elementCnt = dlDataToUlAckDb->dlDataToUlAckListCount;
5418
5419    dlDataToUlACKList->list.count = elementCnt;
5420    dlDataToUlACKList->list.size = elementCnt * sizeof(long *);
5421    DU_ALLOC(dlDataToUlACKList->list.array, dlDataToUlACKList->list.size);
5422    if(dlDataToUlACKList->list.array == NULLP)
5423    {
5424       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5425       return RFAILED;
5426    }   
5427
5428    for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5429    {
5430       DU_ALLOC(dlDataToUlACKList->list.array[arrIdx], sizeof(long));
5431       if(dlDataToUlACKList->list.array[arrIdx] == NULLP)
5432       {
5433          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5434          return RFAILED;
5435       }   
5436    }
5437
5438    if(dlDataToUlAckDb == NULLP)
5439    {
5440       arrIdx = 0;
5441       *(dlDataToUlACKList->list.array[arrIdx++]) = 1;
5442       *(dlDataToUlACKList->list.array[arrIdx]) = 2;
5443    }
5444    else
5445    {
5446       for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5447       {
5448          *(dlDataToUlACKList->list.array[arrIdx]) = dlDataToUlAckDb->dlDataToUlAckList[arrIdx];
5449       }
5450    }
5451    return ROK;
5452 }
5453
5454 /*******************************************************************
5455  *
5456  * @brief Builds BWP UL dedicated PUCCH Config
5457  *
5458  * @details
5459  *
5460  *    Function : BuildBWPUlDedPucchCfg
5461  *
5462  *    Functionality:
5463  *      Builds BWP UL dedicated PUCCH Config
5464  *
5465  * @params[in] : PUCCH_Config_t *pucchCfg
5466  *
5467  * @return ROK     - success
5468  *         RFAILED - failure
5469  *
5470  * ****************************************************************/
5471 uint8_t BuildBWPUlDedPucchCfg(PucchCfg *pucchCfgDb, PUCCH_Config_t *pucchCfg)
5472 {
5473    PucchResrcSetCfg *rsrcSetCfgDb = NULLP;
5474    PucchResrcCfg *rsrcCfgDb = NULLP;
5475    PucchFormatCfg *format1Db = NULLP;
5476    PucchFormatCfg *format2Db = NULLP;
5477    PucchFormatCfg *format3Db = NULLP;
5478    PucchFormatCfg *format4Db = NULLP;
5479    PucchSchedReqCfg *schReqDb = NULLP;   
5480    PucchMultiCsiCfg  *multiCsiDb = NULLP;
5481    PucchDlDataToUlAck *dlDataToUlAckDb = NULLP;
5482
5483    if(pucchCfgDb)
5484    {
5485       rsrcSetCfgDb = pucchCfgDb->resrcSet;
5486       rsrcCfgDb = pucchCfgDb->resrc;
5487       format1Db = pucchCfgDb->format1;
5488       format2Db = pucchCfgDb->format2;
5489       format3Db = pucchCfgDb->format3;
5490       format4Db = pucchCfgDb->format4;
5491       schReqDb = pucchCfgDb->schedReq;
5492       multiCsiDb = pucchCfgDb->multiCsiCfg;
5493       dlDataToUlAckDb = pucchCfgDb->dlDataToUlAck;
5494    }
5495
5496    /* RESOURCE SET */
5497    DU_ALLOC(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
5498    if(pucchCfg->resourceSetToAddModList == NULL)
5499    {
5500       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5501       return RFAILED;
5502    }
5503
5504    if(BuildPucchRsrcSetAddModList(rsrcSetCfgDb, pucchCfg->resourceSetToAddModList) != ROK)
5505    {
5506       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5507       return RFAILED;
5508    }
5509
5510    /* PUCCH RESOURCE */
5511    DU_ALLOC(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
5512    if(pucchCfg->resourceToAddModList == NULLP)
5513    {
5514       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5515       return RFAILED;
5516    }
5517
5518    if(BuildPucchRsrcAddModList(rsrcCfgDb, pucchCfg->resourceToAddModList) != ROK)
5519    {
5520       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5521       return RFAILED;
5522    }
5523
5524    /* PUCCH Format 1 */
5525    DU_ALLOC(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
5526    if(pucchCfg->format1 == NULLP)
5527    {
5528       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5529       return RFAILED;
5530    }
5531    
5532    pucchCfg->format1->present = PUCCH_Config__format1_PR_setup;
5533    DU_ALLOC(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
5534    if(pucchCfg->format1->choice.setup == NULLP)
5535    {
5536       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5537       return RFAILED;
5538    }
5539
5540    if(BuildPucchFormat(format1Db, pucchCfg->format1->choice.setup) != ROK)
5541    {
5542       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5543       return RFAILED;
5544    }
5545
5546    /* PUCCH Format 2 */
5547    if(format2Db)
5548    {
5549       DU_ALLOC(pucchCfg->format2, sizeof(struct PUCCH_Config__format2));
5550       if(pucchCfg->format2 == NULLP)
5551       {
5552          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5553          return RFAILED;
5554       }
5555
5556       pucchCfg->format2->present = PUCCH_Config__format2_PR_setup;
5557       DU_ALLOC(pucchCfg->format2->choice.setup, sizeof(PUCCH_FormatConfig_t));
5558       if(pucchCfg->format2->choice.setup == NULLP)
5559       {
5560          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5561          return RFAILED;
5562       }
5563
5564       if(BuildPucchFormat(format2Db, pucchCfg->format2->choice.setup) != ROK)
5565       {
5566          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5567          return RFAILED;
5568       }
5569    }
5570
5571    /* PUCCH Format 3 */
5572    if(format3Db)
5573    {
5574       DU_ALLOC(pucchCfg->format3, sizeof(struct PUCCH_Config__format3));
5575       if(pucchCfg->format3 == NULLP)
5576       {
5577          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5578          return RFAILED;
5579       }
5580
5581       pucchCfg->format3->present = PUCCH_Config__format3_PR_setup;
5582       DU_ALLOC(pucchCfg->format3->choice.setup, sizeof(PUCCH_FormatConfig_t));
5583       if(pucchCfg->format3->choice.setup == NULLP)
5584       {
5585          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5586          return RFAILED;
5587       }
5588
5589       if(BuildPucchFormat(format3Db, pucchCfg->format3->choice.setup) != ROK)
5590       {
5591          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5592          return RFAILED;
5593       }
5594    }
5595
5596    /* PUCCH Format 4 */
5597    if(format4Db)
5598    {
5599       DU_ALLOC(pucchCfg->format4, sizeof(struct PUCCH_Config__format4));
5600       if(pucchCfg->format4 == NULLP)
5601       {
5602          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5603          return RFAILED;
5604       }
5605
5606       pucchCfg->format4->present = PUCCH_Config__format4_PR_setup;
5607       DU_ALLOC(pucchCfg->format4->choice.setup, sizeof(PUCCH_FormatConfig_t));
5608       if(pucchCfg->format4->choice.setup == NULLP)
5609       {
5610          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5611          return RFAILED;
5612       }
5613
5614       if(BuildPucchFormat(format4Db, pucchCfg->format4->choice.setup) != ROK)
5615       {
5616          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5617          return RFAILED;
5618       }
5619    }
5620
5621    /* Scheduling Request */
5622    if(schReqDb && (schReqDb->schedAddModListCount != 0))
5623    {
5624       pucchCfg->schedulingRequestResourceToAddModList = NULLP;
5625       DU_ALLOC(pucchCfg->schedulingRequestResourceToAddModList, sizeof(struct PUCCH_Config__schedulingRequestResourceToAddModList));
5626       if(pucchCfg->schedulingRequestResourceToAddModList == NULLP)
5627       {
5628          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5629          return RFAILED;
5630       }
5631
5632       if(BuildPucchSchReqAddModList(schReqDb, pucchCfg->schedulingRequestResourceToAddModList) != ROK)
5633       {
5634          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5635          return RFAILED;
5636       }
5637    }
5638
5639    /* Multi CSI */
5640    if(multiCsiDb && (multiCsiDb->multiCsiResrcListCount != 0))
5641    {
5642       pucchCfg->multi_CSI_PUCCH_ResourceList = NULLP;
5643       DU_ALLOC(pucchCfg->multi_CSI_PUCCH_ResourceList, sizeof(struct PUCCH_Config__multi_CSI_PUCCH_ResourceList));
5644       if(pucchCfg->multi_CSI_PUCCH_ResourceList == NULLP)
5645       {
5646          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5647          return RFAILED;
5648       }
5649
5650       if(BuildPucchMultiCsiRsrcList(multiCsiDb, pucchCfg->multi_CSI_PUCCH_ResourceList) != ROK)
5651       {
5652          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5653          return RFAILED;
5654       }
5655    }
5656
5657    /* DL DATA TO UL ACK */
5658    DU_ALLOC(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
5659    if(pucchCfg->dl_DataToUL_ACK == NULLP)
5660    {
5661       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5662       return RFAILED;
5663    }
5664
5665    if(BuildDlDataToUlAckList(dlDataToUlAckDb, pucchCfg->dl_DataToUL_ACK) != ROK)
5666    {
5667       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5668       return RFAILED;
5669    }
5670    
5671    /* TODO : spatial relation info add/mod list and power control*/
5672
5673    return ROK;
5674 }
5675
5676 /*******************************************************************
5677  *
5678  * @brief Fills SRS resource to add/modify list 
5679  *
5680  * @details
5681  *
5682  *    Function : BuildSrsRsrcAddModList
5683  *
5684  *    Functionality: Fills SRS resource to add/modify list
5685  *
5686  * @params[in] 
5687  * @return ROK     - success
5688  *         RFAILED - failure
5689  *
5690  * ****************************************************************/
5691 uint8_t BuildSrsRsrcAddModList(struct SRS_Config__srs_ResourceToAddModList *resourceList)
5692 {
5693    uint8_t   elementCnt;
5694    uint8_t   rsrcIdx;
5695
5696    elementCnt = 1;
5697    resourceList->list.count = elementCnt;
5698    resourceList->list.size = elementCnt * sizeof(SRS_Resource_t *);
5699    resourceList->list.array = NULLP;
5700    DU_ALLOC(resourceList->list.array, resourceList->list.size);
5701    if(!resourceList->list.array)
5702    {
5703       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5704       return RFAILED;
5705    }
5706
5707    for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
5708    {
5709       DU_ALLOC(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
5710       if(!resourceList->list.array[rsrcIdx])
5711       {
5712          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5713          return RFAILED;
5714       }
5715    }
5716
5717    rsrcIdx = 0;
5718    resourceList->list.array[rsrcIdx]->srs_ResourceId = SRS_RSRC_ID;
5719    resourceList->list.array[rsrcIdx]->nrofSRS_Ports = SRS_Resource__nrofSRS_Ports_port1;
5720    resourceList->list.array[rsrcIdx]->transmissionComb.present = SRS_Resource__transmissionComb_PR_n2;
5721
5722    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2 = NULLP;
5723    DU_ALLOC(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2, \
5724          sizeof(struct SRS_Resource__transmissionComb__n2));
5725    if(!resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2)
5726    {
5727       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5728       return RFAILED;
5729    }
5730    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->combOffset_n2\
5731       = SRS_COMB_OFFSET_N2;
5732    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->cyclicShift_n2\
5733       = SRS_CYCLIC_SHIFT_N2;
5734
5735    resourceList->list.array[rsrcIdx]->resourceMapping.startPosition = \
5736                                                                       PUSCH_START_SYMBOL;
5737    resourceList->list.array[rsrcIdx]->resourceMapping.nrofSymbols =  \
5738                                                                      SRS_Resource__resourceMapping__nrofSymbols_n1;
5739    resourceList->list.array[rsrcIdx]->resourceMapping.repetitionFactor = \
5740                                                                          SRS_Resource__resourceMapping__repetitionFactor_n1;
5741
5742    resourceList->list.array[rsrcIdx]->freqDomainPosition = SRS_FREQ_DOM_POS;
5743    resourceList->list.array[rsrcIdx]->freqDomainShift = SRS_FREQ_DOM_SHIFT;
5744    resourceList->list.array[rsrcIdx]->freqHopping.c_SRS = C_SRS;
5745    resourceList->list.array[rsrcIdx]->freqHopping.b_SRS = B_SRS;
5746    resourceList->list.array[rsrcIdx]->freqHopping.b_hop = B_HOP;
5747    resourceList->list.array[rsrcIdx]->groupOrSequenceHopping = \
5748                                                                SRS_Resource__groupOrSequenceHopping_neither;
5749
5750    /* Setting resource type to aperiodic for intergration purposes */
5751    resourceList->list.array[rsrcIdx]->resourceType.present = \
5752                                                              SRS_Resource__resourceType_PR_aperiodic;
5753    resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic = NULLP;
5754    DU_ALLOC(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,
5755          sizeof(struct SRS_Resource__resourceType__aperiodic));
5756    if(!resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic)
5757    {
5758       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5759       return RFAILED;
5760    }
5761
5762    resourceList->list.array[rsrcIdx]->sequenceId = SRS_SEQ_ID;
5763
5764    return ROK;
5765 }
5766
5767 /*******************************************************************
5768  *
5769  * @brief Build SRS resource set Add/mod list
5770  *
5771  * @details
5772  *
5773  *    Function : BuildSrsRsrcSetAddModList
5774  *
5775  *    Functionality: Build SRS resource set Add/mod list
5776  *
5777  * @params[in] 
5778  * @return ROK     - success
5779  *         RFAILED - failure
5780  *
5781  * ****************************************************************/
5782    uint8_t BuildSrsRsrcSetAddModList
5783 (
5784  struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList
5785  )
5786 {
5787    uint8_t  elementCnt;
5788    uint8_t  rSetIdx;
5789    uint8_t  rsrcIdx;
5790    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList;
5791
5792    elementCnt = 1;
5793    rsrcSetList->list.count = elementCnt;
5794    rsrcSetList->list.size = elementCnt * sizeof(SRS_ResourceSet_t *);
5795    rsrcSetList->list.array = NULLP;
5796    DU_ALLOC(rsrcSetList->list.array, rsrcSetList->list.size);
5797    if(!rsrcSetList->list.array)
5798    {
5799       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5800       return RFAILED;
5801    }
5802
5803    for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
5804    {
5805       DU_ALLOC(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
5806       if(!rsrcSetList->list.array[rSetIdx])
5807       {
5808          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5809          return RFAILED;
5810       }
5811    }
5812
5813    rSetIdx = 0;
5814    rsrcSetList->list.array[rSetIdx]->srs_ResourceSetId = SRS_RSET_ID;
5815
5816    /* Fill Resource Id list in resource set */
5817    rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList = NULLP;
5818    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
5819          sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
5820    if(!rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
5821    {
5822       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5823       return RFAILED;
5824    }
5825
5826    elementCnt = 1;
5827    rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
5828    rsrcIdList->list.count = elementCnt;
5829    rsrcIdList->list.size = elementCnt * sizeof(SRS_ResourceId_t *);
5830    rsrcIdList->list.array = NULLP;
5831    DU_ALLOC(rsrcIdList->list.array, rsrcIdList->list.size);
5832    if(!rsrcIdList->list.array)
5833    {
5834       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5835       return RFAILED;
5836    }
5837
5838    for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
5839    {
5840       DU_ALLOC(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
5841       if(!rsrcIdList->list.array[rsrcIdx])
5842       {
5843          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5844          return RFAILED;
5845       }
5846    }
5847
5848    rsrcIdx = 0;
5849    *rsrcIdList->list.array[rsrcIdx] = SRS_RSRC_ID;
5850
5851    /* Fill resource type */
5852    rsrcSetList->list.array[rSetIdx]->resourceType.present = \
5853                                                             SRS_ResourceSet__resourceType_PR_aperiodic;
5854
5855    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic = NULLP;
5856    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
5857          sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
5858    if(!rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic)
5859    {
5860       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5861       return RFAILED;
5862    }
5863    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->aperiodicSRS_ResourceTrigger \
5864       = APERIODIC_SRS_RESRC_TRIGGER;
5865
5866    /* TODO : Fill values for below IEs as expected by Viavi */
5867    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->csi_RS = NULLP;
5868    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->slotOffset = NULLP;
5869
5870
5871    rsrcSetList->list.array[rSetIdx]->usage = SRS_ResourceSet__usage_codebook;
5872    rsrcSetList->list.array[rSetIdx]->alpha = NULLP;
5873    rsrcSetList->list.array[rSetIdx]->p0 = NULLP;
5874    rsrcSetList->list.array[rSetIdx]->pathlossReferenceRS = NULLP;
5875    rsrcSetList->list.array[rSetIdx]->srs_PowerControlAdjustmentStates = NULLP;
5876
5877    return ROK;
5878 }
5879
5880 /*******************************************************************
5881  *
5882  * @brief Builds BWP UL dedicated SRS Config
5883  *
5884  * @details
5885  *
5886  *    Function : BuildBWPUlDedSrsCfg
5887  *
5888  *    Functionality: Builds BWP UL dedicated SRS Config
5889  *
5890  * @params[in] SRS Config 
5891  * @return ROK     - success
5892  *         RFAILED - failure
5893  *
5894  * ****************************************************************/
5895 uint8_t BuildBWPUlDedSrsCfg(SRS_Config_t *srsCfg)
5896 {
5897    srsCfg->srs_ResourceSetToReleaseList = NULLP;
5898    srsCfg->srs_ResourceSetToAddModList = NULLP;
5899    DU_ALLOC(srsCfg->srs_ResourceSetToAddModList, \
5900          sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
5901    if(!srsCfg->srs_ResourceSetToAddModList)
5902    {
5903       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5904       return RFAILED;
5905    }
5906    if(BuildSrsRsrcSetAddModList(srsCfg->srs_ResourceSetToAddModList) != ROK)
5907    {
5908       return RFAILED;
5909    }
5910
5911    srsCfg->srs_ResourceToReleaseList = NULLP;
5912
5913    /* Resource to Add/Modify list */
5914    srsCfg->srs_ResourceToAddModList = NULLP;
5915    DU_ALLOC(srsCfg->srs_ResourceToAddModList, \
5916          sizeof(struct SRS_Config__srs_ResourceToAddModList));
5917    if(!srsCfg->srs_ResourceToAddModList)
5918    {
5919       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5920       return RFAILED;
5921    }
5922
5923    if(BuildSrsRsrcAddModList(srsCfg->srs_ResourceToAddModList) != ROK)
5924    {
5925       return RFAILED;
5926    }
5927    srsCfg->tpc_Accumulation = NULLP;
5928
5929    return ROK;
5930 }
5931
5932
5933
5934 /*******************************************************************
5935  *
5936  * @brief Builds Pusch Serving cell Config
5937  *
5938  * @details
5939  *
5940  *    Function : BuildPuschSrvCellCfg
5941  *
5942  *    Functionality: Builds Pusch Serving cell Config
5943  *
5944  * @params[in] struct UplinkConfig__pusch_ServingCellConfig *puschCfg
5945  *
5946  * @return ROK     - success
5947  *         RFAILED - failure
5948  *
5949  * ****************************************************************/
5950 uint8_t BuildPuschSrvCellCfg(struct UplinkConfig__pusch_ServingCellConfig *puschCfg)
5951 {
5952    puschCfg->present = UplinkConfig__pusch_ServingCellConfig_PR_setup;
5953    puschCfg->choice.setup = NULLP;
5954    DU_ALLOC(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
5955    if(!puschCfg->choice.setup)
5956    {
5957       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5958       return RFAILED;
5959    }
5960
5961    puschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5962    puschCfg->choice.setup->rateMatching = NULLP;
5963    puschCfg->choice.setup->xOverhead = NULLP;
5964    puschCfg->choice.setup->ext1 = NULLP;
5965
5966    DU_ALLOC(puschCfg->choice.setup->ext1, sizeof(struct PUSCH_ServingCellConfig__ext1));
5967    if(!puschCfg->choice.setup->ext1)
5968    {
5969       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5970       return RFAILED;
5971    }
5972
5973    puschCfg->choice.setup->ext1->maxMIMO_Layers = NULLP;
5974    DU_ALLOC(puschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5975    if(!puschCfg->choice.setup->ext1->maxMIMO_Layers)
5976    {
5977       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5978       return RFAILED;
5979    }
5980    *(puschCfg->choice.setup->ext1->maxMIMO_Layers) = PUSCH_MAX_MIMO_LAYERS;
5981
5982    puschCfg->choice.setup->ext1->processingType2Enabled= NULLP;
5983    DU_ALLOC(puschCfg->choice.setup->ext1->processingType2Enabled,sizeof(BOOLEAN_t));
5984    if(!puschCfg->choice.setup->ext1->processingType2Enabled)
5985    {
5986       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5987       return RFAILED;
5988    }
5989    *(puschCfg->choice.setup->ext1->processingType2Enabled) = PUSCH_PROCESS_TYPE2_ENABLED;
5990
5991    return ROK;
5992 }
5993
5994 /*******************************************************************
5995  *
5996  * @brief Builds inital UL BWP
5997  *
5998  * @details
5999  *
6000  *    Function : BuildInitialUlBWP
6001  *
6002  *    Functionality: Builds initial UL BWP
6003  *
6004  * @params[in] BWP_UplinkDedicated_t *ulBwp
6005  * @return ROK     - success
6006  *         RFAILED - failure
6007  *
6008  * ****************************************************************/
6009 uint8_t BuildInitialUlBWP(InitialUlBwp *initUlBwp, BWP_UplinkDedicated_t *ulBwp)
6010 {
6011    PucchCfg *pucchCfg = NULLP;
6012    PuschCfg *puschCfg = NULLP;
6013
6014    if(initUlBwp)
6015    {
6016       if(initUlBwp->pucchPresent)
6017          pucchCfg = &initUlBwp->pucchCfg;
6018       if(initUlBwp->puschPresent)
6019          puschCfg = &initUlBwp->puschCfg;
6020    }
6021
6022    ulBwp->pucch_Config = NULLP;
6023    DU_ALLOC(ulBwp->pucch_Config, sizeof(struct BWP_UplinkDedicated__pucch_Config));
6024    if(!ulBwp->pucch_Config)
6025    {
6026       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6027       return RFAILED;
6028    }
6029
6030    ulBwp->pucch_Config->present = BWP_UplinkDedicated__pucch_Config_PR_setup;
6031    ulBwp->pucch_Config->choice.setup = NULLP;
6032    DU_ALLOC(ulBwp->pucch_Config->choice.setup, sizeof(PUCCH_Config_t));
6033    if(!ulBwp->pucch_Config->choice.setup)
6034    {
6035       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6036       return RFAILED;
6037    }
6038
6039    if(BuildBWPUlDedPucchCfg(pucchCfg, ulBwp->pucch_Config->choice.setup) != ROK)
6040    {
6041       return RFAILED;
6042    }
6043
6044    /* Fill BWP UL dedicated PUSCH config */
6045    ulBwp->pusch_Config = NULLP;
6046    DU_ALLOC(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
6047    if(!ulBwp->pusch_Config)
6048    {
6049       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6050       return RFAILED;
6051    }
6052
6053    ulBwp->pusch_Config->present = BWP_UplinkDedicated__pusch_Config_PR_setup;
6054    ulBwp->pusch_Config->choice.setup = NULLP;
6055    DU_ALLOC(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
6056    if(!ulBwp->pusch_Config->choice.setup)
6057    {
6058       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6059       return RFAILED;
6060    }
6061
6062    if(BuildBWPUlDedPuschCfg(puschCfg, ulBwp->pusch_Config->choice.setup) != ROK)
6063    {
6064       return RFAILED;
6065    }
6066
6067    ulBwp->configuredGrantConfig = NULLP;
6068
6069    /* Fill BPW UL dedicated SRS config */
6070    ulBwp->srs_Config = NULLP;
6071    DU_ALLOC(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
6072    if(!ulBwp->srs_Config)
6073    {
6074       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6075       return RFAILED;
6076    }
6077
6078    ulBwp->srs_Config->present = BWP_UplinkDedicated__srs_Config_PR_setup;
6079    ulBwp->srs_Config->choice.setup = NULLP;
6080    DU_ALLOC(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
6081    if(!ulBwp->srs_Config->choice.setup)
6082    {
6083       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6084       return RFAILED;
6085    }
6086
6087    if(BuildBWPUlDedSrsCfg(ulBwp->srs_Config->choice.setup) != ROK)
6088    {
6089       return RFAILED;   
6090    }
6091
6092    ulBwp->beamFailureRecoveryConfig = NULLP;
6093
6094    return ROK;
6095 }
6096
6097 /*******************************************************************
6098  *
6099  * @brief Builds UL config
6100  * @details
6101  *
6102  *    Function : BuildUlCfg 
6103  *
6104  *    Functionality: Builds UL config in spCellCfgDed
6105  *
6106  * @params[in] UplinkConfig_t *ulCfg
6107  *
6108  * @return ROK     - success
6109  *         RFAILED - failure
6110  *
6111  * ****************************************************************/
6112 uint8_t BuildUlCfg(ServCellRecfgInfo *servCellRecfg, UplinkConfig_t *ulCfg)
6113 {
6114    InitialUlBwp *initUlBwp = NULLP;
6115
6116    if(servCellRecfg)
6117    {
6118       initUlBwp = &servCellRecfg->initUlBwp;
6119    }
6120
6121    ulCfg->initialUplinkBWP = NULLP;
6122    DU_ALLOC(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
6123    if(!ulCfg->initialUplinkBWP)
6124    {
6125       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6126       return RFAILED;
6127    }
6128
6129    if(BuildInitialUlBWP(initUlBwp, ulCfg->initialUplinkBWP) != ROK)
6130    {
6131       return RFAILED;
6132    }
6133
6134    ulCfg->uplinkBWP_ToReleaseList = NULLP;
6135    ulCfg->uplinkBWP_ToAddModList = NULLP;
6136    ulCfg->firstActiveUplinkBWP_Id = NULLP;
6137    DU_ALLOC(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
6138    if(!ulCfg->firstActiveUplinkBWP_Id)
6139    {
6140       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6141       return RFAILED;
6142    }
6143    if(servCellRecfg == NULLP)
6144       *(ulCfg->firstActiveUplinkBWP_Id) = ACTIVE_UL_BWP_ID;
6145    else
6146       *(ulCfg->firstActiveUplinkBWP_Id) = servCellRecfg->firstActvUlBwpId;
6147
6148    ulCfg->pusch_ServingCellConfig = NULLP;
6149    DU_ALLOC(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
6150    if(!ulCfg->pusch_ServingCellConfig)
6151    {
6152       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6153       return RFAILED;
6154    }
6155
6156    if(BuildPuschSrvCellCfg(ulCfg->pusch_ServingCellConfig) != ROK)
6157    {
6158       return RFAILED;
6159    }
6160
6161    ulCfg->carrierSwitching = NULLP;
6162    ulCfg->ext1 = NULLP;
6163    return ROK;
6164 }
6165
6166 /*******************************************************************
6167  *
6168  * @brief Builds PDSCH serving cell config
6169  * @details
6170  *
6171  *    Function : BuildPdschSrvCellCfg
6172  *
6173  *    Functionality: Builds PDSCH serving cell config in spCellCfgDed
6174  *
6175  * @params[in] struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg 
6176  *
6177  * @return ROK     - success
6178  *         RFAILED - failure
6179  *
6180  * ****************************************************************/
6181 uint8_t BuildPdschSrvCellCfg(PdschServCellCfg *pdschServCellDb, struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg)
6182 {
6183    pdschCfg->present =  ServingCellConfig__pdsch_ServingCellConfig_PR_setup;
6184    pdschCfg->choice.setup = NULLP;
6185    DU_ALLOC(pdschCfg->choice.setup, sizeof( struct PDSCH_ServingCellConfig));
6186    if(!pdschCfg->choice.setup)
6187    {
6188       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6189       return RFAILED;
6190    }
6191
6192    /* Code Block Group Transmission */
6193    pdschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
6194    if(pdschServCellDb && (pdschServCellDb->maxCodeBlkGrpPerTb || pdschServCellDb->codeBlkGrpFlushInd))
6195    {
6196       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission, sizeof(struct PDSCH_ServingCellConfig__codeBlockGroupTransmission));
6197       if(pdschCfg->choice.setup->codeBlockGroupTransmission == NULLP)
6198       {
6199          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6200          return RFAILED;
6201       }
6202
6203       pdschCfg->choice.setup->codeBlockGroupTransmission->present = PDSCH_ServingCellConfig__codeBlockGroupTransmission_PR_setup;
6204       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup = NULLP;
6205       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup, sizeof(struct PDSCH_CodeBlockGroupTransmission ));
6206       if(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup == NULLP)
6207       {
6208          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6209          return RFAILED;
6210       }
6211
6212       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock = \
6213          *(pdschServCellDb->maxCodeBlkGrpPerTb);
6214       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator = \
6215          *(pdschServCellDb->codeBlkGrpFlushInd);
6216    }
6217
6218    /* xOverhead */
6219    pdschCfg->choice.setup->xOverhead = NULLP;
6220    if(pdschServCellDb && pdschServCellDb->xOverhead)
6221    {
6222       DU_ALLOC(pdschCfg->choice.setup->xOverhead, sizeof(long));
6223       if(pdschCfg->choice.setup->xOverhead == NULLP)
6224       {
6225          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6226          return RFAILED;
6227       }
6228       *(pdschCfg->choice.setup->xOverhead) = *(pdschServCellDb->xOverhead);
6229    }
6230
6231    /* Number of HARQ processes */
6232    pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH = NULLP;
6233    DU_ALLOC(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH, sizeof(long));
6234    if(!pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH)
6235    {
6236       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6237       return RFAILED;
6238    }
6239
6240    if(pdschServCellDb == NULLP)
6241    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = PDSCH_NUM_HARQ_PROC;
6242    else
6243    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = pdschServCellDb->numHarqProcForPdsch;
6244
6245    pdschCfg->choice.setup->pucch_Cell = NULLP;
6246
6247    /* Extension */
6248    pdschCfg->choice.setup->ext1 = NULLP;
6249    if(pdschServCellDb && pdschServCellDb->maxMimoLayers)
6250    {
6251       DU_ALLOC(pdschCfg->choice.setup->ext1, sizeof(struct PDSCH_ServingCellConfig__ext1));
6252       if(pdschCfg->choice.setup->ext1 == NULLP)
6253       {
6254          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6255          return RFAILED;
6256       }
6257
6258       DU_ALLOC(pdschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
6259       if(pdschCfg->choice.setup->ext1->maxMIMO_Layers == NULLP)
6260       {
6261          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6262          return RFAILED;
6263       }
6264       *(pdschCfg->choice.setup->ext1->maxMIMO_Layers) = *(pdschServCellDb->maxMimoLayers);
6265    }
6266
6267    return ROK;
6268 }
6269
6270 /*******************************************************************
6271  *
6272  * @brief Builds CSI Meas config
6273  * @details
6274  *
6275  *    Function : BuildCsiMeasCfg 
6276  *
6277  *    Functionality: Builds CSI Meas config in spCellCfgDed
6278  *
6279  * @params[in] struct ServingCellConfig__csi_MeasConfig *csiMeasCfg
6280  *
6281  * @return ROK     - success
6282  *         RFAILED - failure
6283  *
6284  * ****************************************************************/
6285 uint8_t BuildCsiMeasCfg(struct ServingCellConfig__csi_MeasConfig *csiMeasCfg)
6286 {
6287
6288    return ROK;
6289 }
6290
6291 /*******************************************************************
6292  *
6293  * @brief Builds DL BWP to add/modify list
6294  * @details
6295  *
6296  *    Function : BuildDlBwpToAddModList
6297  *
6298  *    Functionality: Builds DL BWP to add/modify list
6299  *
6300  * @params[in] ServCellRecfgInfo *servCellRecfg, 
6301  *             struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList
6302  *
6303  * @return ROK     - success
6304  *         RFAILED - failure
6305  *
6306  * ****************************************************************/ 
6307 uint8_t BuildDlBwpToAddModList(ServCellRecfgInfo *servCellRecfg, struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList)
6308 {
6309    uint8_t elementCnt, idx;
6310
6311    elementCnt = servCellRecfg->numDlBwpToAddOrMod;
6312    dlBwpAddModList->list.count = elementCnt;
6313    dlBwpAddModList->list.size = elementCnt * sizeof(struct BWP_Downlink *);
6314    dlBwpAddModList->list.array = NULLP;
6315    DU_ALLOC(dlBwpAddModList->list.array, dlBwpAddModList->list.size);
6316    if(dlBwpAddModList->list.array == NULLP)
6317    {
6318       DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6319       return RFAILED;
6320    }
6321
6322    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6323    {
6324       DU_ALLOC(dlBwpAddModList->list.array[idx], sizeof(BWP_Downlink_t));
6325       if(dlBwpAddModList->list.array[idx] == NULLP)
6326       {
6327          DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6328          return RFAILED;
6329       }
6330    }
6331
6332    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6333    {
6334       dlBwpAddModList->list.array[idx]->bwp_Id = servCellRecfg->dlBwpToAddOrModList[idx].bwpId;
6335       dlBwpAddModList->list.array[idx]->bwp_Common = NULLP;
6336       dlBwpAddModList->list.array[idx]->bwp_Dedicated = NULLP;
6337    }
6338    return ROK;
6339 }
6340
6341 /*******************************************************************
6342  *
6343  * @brief Builds Spcell config dedicated
6344  * @details
6345  *
6346  *    Function : BuildSpCellCfgDed
6347  *
6348  *    Functionality: Builds sp cell config dedicated in spCellCfg
6349  *
6350  * @params[in] ServingCellConfig_t srvCellCfg
6351  *
6352  * @return ROK     - success
6353  *         RFAILED - failure
6354  *
6355  * ****************************************************************/
6356 uint8_t BuildSpCellCfgDed(DuUeCb *ueCb, ServingCellConfig_t *srvCellCfg)
6357 {
6358    ServCellRecfgInfo *servCellRecfg = NULLP;
6359    InitialDlBwp *initDlBwp = NULLP;
6360    PdschServCellCfg *pdschServCellDb = NULLP;
6361
6362    if(ueCb)
6363    {
6364       servCellRecfg = &ueCb->duMacUeCfg.spCellCfg.servCellCfg;
6365       initDlBwp = &servCellRecfg->initDlBwp;
6366       pdschServCellDb = &servCellRecfg->pdschServCellCfg;
6367    }
6368
6369    srvCellCfg->tdd_UL_DL_ConfigurationDedicated = NULLP;
6370
6371    srvCellCfg->initialDownlinkBWP = NULLP;
6372    DU_ALLOC(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
6373    if(!srvCellCfg->initialDownlinkBWP)
6374    {
6375       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6376       return RFAILED;
6377    }
6378
6379    if(BuildInitialDlBWP(initDlBwp, srvCellCfg->initialDownlinkBWP) != ROK)
6380    {
6381       DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6382       return RFAILED;
6383    }
6384
6385    srvCellCfg->downlinkBWP_ToReleaseList = NULLP;
6386
6387    srvCellCfg->downlinkBWP_ToAddModList = NULLP;
6388    if(ueCb && ueCb->duMacUeCfg.spCellCfg.servCellCfg.numDlBwpToAddOrMod)
6389    {
6390       DU_ALLOC(srvCellCfg->downlinkBWP_ToAddModList, sizeof(struct ServingCellConfig__downlinkBWP_ToAddModList));
6391       if(srvCellCfg->downlinkBWP_ToAddModList == NULLP)
6392       {
6393          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6394          return RFAILED;
6395       }
6396
6397       if(BuildDlBwpToAddModList(&ueCb->duMacUeCfg.spCellCfg.servCellCfg, srvCellCfg->downlinkBWP_ToAddModList) != ROK)
6398       {
6399          DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6400          return RFAILED;
6401       }
6402    }
6403
6404    srvCellCfg->firstActiveDownlinkBWP_Id = NULLP;
6405    DU_ALLOC(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
6406    if(!srvCellCfg->firstActiveDownlinkBWP_Id)
6407    {
6408       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6409       return RFAILED;
6410    }
6411    if(ueCb == NULLP)
6412       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6413    else
6414       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.firstActvDlBwpId;
6415
6416    srvCellCfg->bwp_InactivityTimer = NULLP;
6417
6418    srvCellCfg->defaultDownlinkBWP_Id = NULLP;
6419    DU_ALLOC(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
6420    if(!srvCellCfg->defaultDownlinkBWP_Id)
6421    {
6422       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6423       return RFAILED;
6424    }
6425    if(ueCb == NULLP)
6426       *(srvCellCfg->defaultDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6427    else
6428       *(srvCellCfg->defaultDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.defaultDlBwpId;
6429
6430    srvCellCfg->uplinkConfig = NULLP;
6431    DU_ALLOC(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));
6432    if(!srvCellCfg->uplinkConfig)
6433    {
6434       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6435       return RFAILED;
6436    }
6437
6438    if(BuildUlCfg(servCellRecfg, srvCellCfg->uplinkConfig) != ROK)
6439    {
6440       DU_LOG("\nERROR  -->  F1AP : BuildUlCfg failed");
6441       return RFAILED;
6442    }
6443    srvCellCfg->supplementaryUplink = NULLP;
6444    srvCellCfg->pdcch_ServingCellConfig = NULLP;
6445
6446    srvCellCfg->pdsch_ServingCellConfig = NULLP;
6447    DU_ALLOC(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct  ServingCellConfig__pdsch_ServingCellConfig));
6448    if(!srvCellCfg->pdsch_ServingCellConfig)
6449    {
6450       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6451       return RFAILED;
6452    }
6453
6454    if(BuildPdschSrvCellCfg(pdschServCellDb, srvCellCfg->pdsch_ServingCellConfig) != ROK)
6455    {
6456       DU_LOG("\nERROR  -->  F1AP : BuildPdschSrvCellCfg failed");
6457       return RFAILED;
6458    }
6459
6460    srvCellCfg->csi_MeasConfig = NULLP;
6461 #if 0
6462    DU_ALLOC(srvCellCfg->csi_MeasConfig, sizeof(struct   ServingCellConfig__csi_MeasConfig))
6463       if(!srvCellCfg->csi_MeasConfig)
6464       {
6465          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6466          return RFAILED;
6467       }
6468
6469    if(BuildCsiMeasCfg(srvCellCfg->csi_MeasConfig) != ROK)
6470    {
6471       DU_LOG("\nF1AP : BuildCsiMeasCfg failed");
6472       return RFAILED;
6473    }
6474 #endif
6475    srvCellCfg->sCellDeactivationTimer = NULLP;
6476    srvCellCfg->crossCarrierSchedulingConfig = NULLP;
6477    srvCellCfg->tag_Id = TAG_ID;
6478    srvCellCfg->dummy = NULLP;
6479    srvCellCfg->pathlossReferenceLinking = NULLP;
6480    srvCellCfg->servingCellMO = NULLP;
6481    srvCellCfg->ext1 = NULLP;
6482
6483    return ROK;
6484 }
6485
6486 /*******************************************************************
6487  *
6488  * @brief Fills SCS specific carrier list in DL frequency info
6489  *
6490  * @details
6491  *
6492  *    Function : BuildScsSpecificCarrierListDl
6493  *
6494  *    Functionality: Fills SCS specific carrier list in DL frequency info
6495  *
6496  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
6497  *
6498  * @return ROK     - success
6499  *         RFAILED - failure
6500  *
6501  * ****************************************************************/
6502 uint8_t BuildScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
6503 {
6504    uint8_t elementCnt = 0, listIdx = 0;
6505    ScsSpecCarrier duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.dlScsCarrier;
6506
6507    elementCnt = ODU_VALUE_ONE;
6508    scsCarrierList->list.count = elementCnt;
6509    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6510
6511    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6512    if(!scsCarrierList->list.array)
6513    {
6514       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for scs carrier list array \
6515          in BuildScsSpecificCarrierListDl()");
6516       return RFAILED;
6517    }
6518
6519    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6520    {
6521       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6522       if(!scsCarrierList->list.array[listIdx])
6523       {    
6524          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SCS Specific Carrier list array \
6525             element in BuildScsSpecificCarrierListDl()");
6526          return RFAILED;
6527       }    
6528    }
6529
6530    listIdx = 0;
6531    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6532    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6533    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6534
6535    return ROK;
6536 }
6537
6538 /*******************************************************************
6539  *
6540  * @brief Fills DL frequency info in DL config common
6541  *
6542  * @details
6543  *
6544  *    Function : BuildFreqInfoDl
6545  *
6546  *    Functionality: Fills DL frequency info in DL config common
6547  *
6548  * @params[in] Pointer to DownlinkConfigCommon_t
6549  *
6550  * @return ROK     - success
6551  *         RFAILED - failure
6552  *
6553  * ****************************************************************/
6554 uint8_t BuildFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
6555 {
6556    uint8_t freqBandIdx = 0, elementCnt = 0;
6557    DlCfgCommon  dlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg;
6558
6559    /* TODO : Fill SSB Absolute Frequency */
6560    /*
6561       DU_ALLOC(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
6562       if(!frequencyInfoDL->absoluteFrequencySSB)
6563       {
6564       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB Absolute Frequency in BuildFreqInfoDl()");
6565       return RFAILED;
6566       }
6567       frequencyInfoDL->absoluteFrequencySSB = ?;
6568       */
6569
6570    /* NR Multi Frequency Band List */
6571    elementCnt = ODU_VALUE_ONE;
6572    frequencyInfoDL->frequencyBandList.list.count = elementCnt;
6573    frequencyInfoDL->frequencyBandList.list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6574
6575    DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
6576    if(!frequencyInfoDL->frequencyBandList.list.array)
6577    {
6578       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for Frequency Band List array in BuildFreqInfoDl()");
6579       return RFAILED;
6580    }
6581
6582    for(freqBandIdx = 0; freqBandIdx < elementCnt; freqBandIdx++)
6583    {
6584       DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
6585       if(!frequencyInfoDL->frequencyBandList.list.array[freqBandIdx])
6586       {
6587          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoDl()");
6588          return RFAILED;
6589       }
6590    }
6591
6592    freqBandIdx = 0;
6593    *(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx]) = dlCfg.freqBandInd;
6594
6595    /* TODO : Absolute Frequency to Point A */
6596    //frequencyInfoDL->absoluteFrequencyPointA
6597
6598    /* Subcarrier Spacing specifc carrier List */
6599    if((BuildScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList)) != ROK)
6600    {
6601       DU_LOG("\nERROR  -->  DU APP : Failed to fill SCS specific carrier list DL in BuildFreqInfoDl()");
6602       return RFAILED;
6603    }
6604
6605    return ROK;
6606
6607 }
6608
6609 /*******************************************************************
6610  *
6611  * @brief Fills DL config common in Serving cell config common
6612  *
6613  * @details
6614  *
6615  *    Function : BuildDlConfigCommon
6616  *
6617  *    Functionality: Fills DL config common in Serving cell config common
6618  *
6619  * @params[in] Pointer to DownlinkConfigCommon_t
6620  *
6621  * @return ROK     - success
6622  *         RFAILED - failure
6623  *
6624  * ****************************************************************/
6625 uint8_t BuildDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
6626 {
6627    /* DL Frequency Info */
6628    DU_ALLOC(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
6629    if(!dlCfgCommon->frequencyInfoDL)
6630    {
6631       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL frequency info in BuildDlConfigCommon()");
6632       return RFAILED;
6633    }
6634    if((BuildFreqInfoDl(dlCfgCommon->frequencyInfoDL))!= ROK)
6635    {
6636       DU_LOG("\nERROR  --> DU APP : Failed to fill DL frequency info in BuildDlConfigCommon()");
6637       return RFAILED;
6638    }
6639
6640    /* DL BWP config common */
6641    DU_ALLOC(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
6642    if(!dlCfgCommon->initialDownlinkBWP)
6643    {
6644       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL BWP config common in BuildDlConfigCommon()");
6645       return RFAILED;
6646    }
6647    if((BuildBwpDlCommon(dlCfgCommon->initialDownlinkBWP)) != ROK)
6648    {
6649       DU_LOG("\nERROR  --> DU APP : Failed to fill DL DWP config common in BuildDlConfigCommon()");
6650       return RFAILED;
6651    }
6652
6653    return ROK;
6654 }
6655
6656 /*******************************************************************
6657  *
6658  * @brief Fills SCS specific carrier list in UL frequency Info
6659  *
6660  * @details
6661  *
6662  *    Function : BuildScsSpecificCarrierListUl
6663  *
6664  *    Functionality: Fills SCS specific carrier list in UL frequency Info
6665  *
6666  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
6667  *
6668  * @return ROK     - success
6669  *         RFAILED - failure
6670  *
6671  * ****************************************************************/
6672 uint8_t BuildScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
6673 {
6674    uint8_t elementCnt = 0, listIdx = 0; 
6675    ScsSpecCarrier   duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.ulScsCarrier;
6676
6677    elementCnt = ODU_VALUE_ONE;
6678    scsCarrierList->list.count = elementCnt;
6679    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6680
6681    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6682    if(!scsCarrierList->list.array)
6683    {
6684       DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6685       return RFAILED;
6686    }
6687
6688    for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
6689    {
6690       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6691       if(!scsCarrierList->list.array[listIdx])
6692       {    
6693          DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6694          return RFAILED;
6695       }    
6696    }
6697    listIdx = 0; 
6698    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6699    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6700    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6701
6702    return ROK;
6703 }
6704
6705 /*******************************************************************
6706  *
6707  * @brief Fills frequency info in UL config common
6708  *
6709  * @details
6710  *
6711  *    Function : BuildFreqInfoUl
6712  *
6713  *    Functionality: Fills frequency info in UL config common
6714  *
6715  * @params[in] Pointer to FrequencyInfoUL_t
6716  *
6717  * @return ROK     - success
6718  *         RFAILED - failure
6719  *
6720  * ****************************************************************/
6721 uint8_t BuildFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
6722 {
6723    uint8_t elementCnt = 0, listIdx= 0;
6724    UlCfgCommon  ulCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg;
6725
6726    /* NR Multi Frequency Band List */
6727    DU_ALLOC(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
6728    if(!frequencyInfoUL->frequencyBandList)
6729    {
6730       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band list in BuildFreqInfoUl()");
6731       return RFAILED;
6732    }
6733
6734    elementCnt = ODU_VALUE_ONE;
6735    frequencyInfoUL->frequencyBandList->list.count = elementCnt;
6736    frequencyInfoUL->frequencyBandList->list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6737
6738    DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
6739    if(!frequencyInfoUL->frequencyBandList->list.array)
6740    {
6741       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array in BuildFreqInfoUl()");
6742       return RFAILED;
6743    }
6744
6745    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6746    {
6747       DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
6748       if(!frequencyInfoUL->frequencyBandList->list.array[listIdx])
6749       {
6750          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoUl()");
6751          return RFAILED;
6752       }
6753    }
6754
6755    listIdx = 0;
6756    *(frequencyInfoUL->frequencyBandList->list.array[listIdx]) = ulCfg.freqBandInd;
6757
6758    /* TODO : Fill Absolute frequency point A */
6759    /*
6760       DU_ALLOC(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
6761       if(!frequencyInfoUL->absoluteFrequencyPointA)
6762       {
6763       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for absolute frequency point A in BuildFreqInfoUl()");
6764       return RFAILED;
6765       }
6766     *(frequencyInfoUL->absoluteFrequencyPointA) = ?;
6767     */
6768
6769    /* Subcarrier Spacing specifc carrier */
6770    if((BuildScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList)) != ROK) 
6771    {
6772       DU_LOG("\nERROR  --> DU APP : Failed to fill SCS Specific Carrier list UL in BuildFreqInfoUl()");
6773       return RFAILED;
6774    }
6775
6776    /* P-MAX */
6777    DU_ALLOC(frequencyInfoUL->p_Max, sizeof(P_Max_t));
6778    if(!frequencyInfoUL->p_Max)
6779    {
6780       DU_LOG("\nERROR  -->  DU APP : UL Frequency Infoo  memory allocation failure");
6781       return RFAILED;
6782    }
6783    *frequencyInfoUL->p_Max = ulCfg.pMax;
6784
6785    return ROK;
6786 }
6787
6788 /*******************************************************************
6789  *
6790  * @brief Fills UL config common in Serving cell config common
6791  *
6792  * @details
6793  *
6794  *    Function : BuildUlConfigCommon
6795  *
6796  *    Functionality: Fills UL config common in Serving cell config common
6797  *
6798  * @params[in] Pointer to UplinkConfigCommon_t
6799  *
6800  * @return ROK     - success
6801  *         RFAILED - failure
6802  *
6803  * ****************************************************************/
6804 uint8_t BuildUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
6805 {
6806    /* UL Frequency Info */
6807    DU_ALLOC(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
6808    if(!ulCfgCommon->frequencyInfoUL)
6809    {
6810       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for UL frequency info in BuildUlConfigCommon()");
6811       return RFAILED;
6812    }
6813
6814    if((BuildFreqInfoUl(ulCfgCommon->frequencyInfoUL)) != ROK)
6815    {
6816       DU_LOG("\nERROR  -->  DU APP : Failed to fill frequency info UL in BuildUlConfigCommon()");
6817       return RFAILED;
6818    }
6819
6820    /* UL BWP common */
6821    DU_ALLOC(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
6822    if(!ulCfgCommon->initialUplinkBWP)
6823    {
6824       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for initial UL BWP in BuildUlConfigCommon()");
6825       return RFAILED;
6826    }
6827
6828    if((BuildBwpUlCommon(ulCfgCommon->initialUplinkBWP)) != ROK)
6829    {
6830       DU_LOG("\nERROR  -->  DU APP : Failed to fill BWP UL common in BuildUlConfigCommon()");
6831       return RFAILED;
6832    }
6833
6834    /* Time Alignment timer */
6835    ulCfgCommon->dummy = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.timeAlignTimerComm;
6836
6837    return ROK;
6838 }
6839
6840 /*******************************************************************
6841  *
6842  * @brief Fills SSB position in burst in SP cell config common
6843  *
6844  * @details
6845  *
6846  *    Function : BuildSsbPosInBurst
6847  *
6848  *    Functionality: 
6849  *       Fills SSB position in burst in SP cell config common
6850  *
6851  * @params[in] Pointer to struct ServingCellConfigCommon__ssb_PositionsInBurst
6852  *
6853  * @return ROK     - success
6854  *         RFAILED - failure
6855  *
6856  * ****************************************************************/
6857 uint8_t BuildSsbPosInBurst(struct ServingCellConfigCommon__ssb_PositionsInBurst *ssbPosInBurst)
6858 {
6859    uint8_t bitStringSizeInBytes = 0;
6860
6861    ssbPosInBurst->present = ServingCellConfigCommon__ssb_PositionsInBurst_PR_mediumBitmap;
6862
6863    /* As per spec 38.331,in the definition of ServingCellConfigCommon */
6864    bitStringSizeInBytes = 1;
6865    ssbPosInBurst->choice.mediumBitmap.size = bitStringSizeInBytes * sizeof(uint8_t);
6866
6867    DU_ALLOC(ssbPosInBurst->choice.mediumBitmap.buf, ssbPosInBurst->choice.mediumBitmap.size);
6868    if(!ssbPosInBurst->choice.mediumBitmap.buf)
6869    {
6870       DU_LOG("\nERROR  -->  DU APP : Memory Allocation failed for medium bit map buffer in BuildSsbPosInBurst()");
6871       return RFAILED;
6872    }
6873
6874    if((fillBitString(&ssbPosInBurst->choice.mediumBitmap, 0, bitStringSizeInBytes, \
6875                duCfgParam.sib1Params.srvCellCfgCommSib.ssbPosInBurst)) != ROK)
6876    {
6877       DU_LOG("\nERROR  -->  DU APP : Failed to fill medium bit map in BuildSsbPosInBurst()");
6878       return RFAILED;
6879    }
6880
6881    return ROK;
6882 }
6883
6884 /*******************************************************************
6885  *
6886  * @brief Fills SP cell config common in Reconfig with Sync
6887  *
6888  * @details
6889  *
6890  *    Function : BuildSpCellConfigCommon
6891  *
6892  *    Functionality: Fills SP cell config common in Reconfig with Sync
6893  *
6894  * @params[in] Pointer to ServingCellConfigCommon_t
6895  *
6896  * @return ROK     - success
6897  *         RFAILED - failure
6898  *
6899  * ****************************************************************/
6900 uint8_t BuildSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
6901 {
6902    /* Physical Cell Identity */
6903    DU_ALLOC(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
6904    if(!spCellConfigCommon->physCellId)
6905    {
6906       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for physical cell id in BuildSpCellConfigCommon()");
6907       return RFAILED;
6908    } 
6909    *(spCellConfigCommon->physCellId) = NR_PCI;
6910
6911    /* Downlink Config Common */
6912    DU_ALLOC(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
6913    if(!spCellConfigCommon->downlinkConfigCommon)
6914    {
6915       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for DL Config Common in BuildSpCellConfigCommon()");
6916       return RFAILED;
6917    }
6918    if((BuildDlConfigCommon(spCellConfigCommon->downlinkConfigCommon)) != ROK)
6919    {
6920       DU_LOG("\nERROR  -->  DU APP : Failed to fill DL config commin in BuildSpCellConfigCommon()");
6921       return RFAILED;
6922    }
6923
6924    /* Uplinlink Config Common */
6925    DU_ALLOC(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
6926    if(!spCellConfigCommon->uplinkConfigCommon)
6927    {
6928       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for UL Config Common in BuildSpCellConfigCommon()");
6929       return RFAILED;
6930    }
6931    if((BuildUlConfigCommon(spCellConfigCommon->uplinkConfigCommon)) != ROK)
6932    {
6933       DU_LOG("\nERROR  -->  DU APP : Failed to fill UL config commin in BuildSpCellConfigCommon()");
6934       return RFAILED;
6935    }
6936
6937    /* Timing Advance offset */
6938    DU_ALLOC(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
6939    if(!spCellConfigCommon->n_TimingAdvanceOffset)
6940    {
6941       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for Timing Advance Offset in BuildSpCellConfigCommon()");
6942       return RFAILED;
6943    }
6944    *(spCellConfigCommon->n_TimingAdvanceOffset) = ServingCellConfigCommon__n_TimingAdvanceOffset_n0;
6945
6946    /* SSB Position In Burst */
6947    DU_ALLOC(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
6948    if(!spCellConfigCommon->ssb_PositionsInBurst)
6949    {
6950       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Position In Burst in BuildSpCellConfigCommon()");
6951       return RFAILED;
6952    }
6953    if((BuildSsbPosInBurst(spCellConfigCommon->ssb_PositionsInBurst)) != ROK)
6954    {
6955       DU_LOG("\nERROR  -->  DU APP : Failed to fill SSB Position In Burst in BuildSpCellConfigCommon()");
6956       return RFAILED;
6957    }
6958
6959    /* SSB Periodicity in Serving cell */
6960    DU_ALLOC(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
6961    if(!spCellConfigCommon->ssb_periodicityServingCell)
6962    {
6963       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Periodicity serving cell in \
6964          BuildSpCellConfigCommon()");
6965       return RFAILED;
6966    }
6967    *(spCellConfigCommon->ssb_periodicityServingCell) = \
6968       convertSsbPeriodicityValueToEnum(duCfgParam.sib1Params.srvCellCfgCommSib.ssbPrdServingCell);
6969
6970    /* DMRS Type A position */
6971    spCellConfigCommon->dmrs_TypeA_Position = convertDmrsTypeAPosValueToEnum(duCfgParam.macCellCfg.ssbCfg.dmrsTypeAPos);
6972
6973    /* SSB subcarrier spacing */
6974    DU_ALLOC(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
6975    if(!spCellConfigCommon->ssbSubcarrierSpacing)
6976    {
6977       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for sub-carrier spacing in BuildSpCellConfigCommon()");
6978       return RFAILED;
6979    }
6980    *(spCellConfigCommon->ssbSubcarrierSpacing) = duCfgParam.sib1Params.srvCellCfgCommSib.scs;
6981
6982    /* TDD UL-DL configuration common */
6983    DU_ALLOC(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
6984    if(!spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)
6985    {
6986       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for TDD UL-DL config common in BuildSpCellConfigCommon()");
6987       return RFAILED;
6988    }
6989    if((BuildTddUlDlCfgComm(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)) != ROK)
6990    {
6991       DU_LOG("\nERROR  -->  DU APP : Failed to fill TDD UL-DL config common in BuildSpCellConfigCommon()");
6992       return RFAILED;
6993    }
6994
6995    /* SS PBCH Block Power */
6996    spCellConfigCommon->ss_PBCH_BlockPower = duCfgParam.sib1Params.srvCellCfgCommSib.ssPbchBlockPwr;
6997
6998    return ROK;
6999 }
7000
7001 /*******************************************************************
7002  *
7003  * @brief Fills dedicated RACH configuration in Reconfiguration with sync
7004  *
7005  * @details
7006  *
7007  *    Function : BuildRecfgWithSync
7008  *
7009  *    Functionality: 
7010  *       Fills dedicated RACH configuration in Reconfiguration with sync
7011  *
7012  * @params[in] DU UE CB
7013  *             Pointer to Rach config dedicated struct
7014  *
7015  * @return ROK     - success
7016  *         RFAILED - failure
7017  *
7018  * ****************************************************************/
7019 uint8_t BuildRachConfigDedicated(DuUeCb *ueCb, struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
7020 {
7021    uint8_t elementCnt = 0, listIdx = 0;
7022    CFRA_t *cfra = NULLP;
7023    struct CFRA__resources__ssb *ssbResource = NULLP;
7024    RachCfgCommon duRachCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.rachCfg;
7025
7026    rachCfgDed->present = ReconfigurationWithSync__rach_ConfigDedicated_PR_uplink;
7027
7028    /* Uplink */
7029    DU_ALLOC(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
7030    if(!rachCfgDed->choice.uplink)
7031    {
7032       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for RACH uplink configuration in BuildRachConfigDedicated()");
7033       return RFAILED;
7034    }
7035
7036    /* CFRA : Contention free Random Access */
7037    DU_ALLOC(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
7038    if(!rachCfgDed->choice.uplink->cfra)
7039    {
7040       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA in BuildRachConfigDedicated()");
7041       return RFAILED;
7042    }
7043    cfra = rachCfgDed->choice.uplink->cfra;
7044
7045    /* CFRA occassions */
7046    DU_ALLOC(cfra->occasions, sizeof(struct CFRA__occasions));
7047    if(!cfra->occasions)
7048    {
7049       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA occassion in BuildRachConfigDedicated()");
7050       return RFAILED;
7051    }
7052
7053    /* CFRA occassions : RACH generic configuration */
7054    cfra->occasions->rach_ConfigGeneric.prach_ConfigurationIndex = duRachCfg.prachCfgIdx;
7055    cfra->occasions->rach_ConfigGeneric.msg1_FDM = duRachCfg.msg1Fdm;
7056    cfra->occasions->rach_ConfigGeneric.msg1_FrequencyStart = duRachCfg.msg1FreqStart;
7057    cfra->occasions->rach_ConfigGeneric.zeroCorrelationZoneConfig = duRachCfg.zeroCorrZoneCfg;
7058    cfra->occasions->rach_ConfigGeneric.preambleReceivedTargetPower = duRachCfg.preambleRcvdTgtPwr;
7059    cfra->occasions->rach_ConfigGeneric.preambleTransMax = duRachCfg.preambleTransMax;
7060    cfra->occasions->rach_ConfigGeneric.powerRampingStep = duRachCfg.pwrRampingStep;
7061    cfra->occasions->rach_ConfigGeneric.ra_ResponseWindow = duRachCfg.raRspWindow;
7062
7063    /* CFRA occassions : SSB per RACH occasion */
7064    DU_ALLOC(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
7065    if(!cfra->occasions->ssb_perRACH_Occasion)
7066    {
7067       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB per RACH occassion in BuildRachConfigDedicated()");
7068       return RFAILED;
7069    }
7070    *(cfra->occasions->ssb_perRACH_Occasion) = convertCFRASsbPerRachOccasionValueToEnum(duCfgParam.macCellCfg.prachCfg.ssbPerRach);
7071
7072    /* CFRA resource */
7073    cfra->resources.present = CFRA__resources_PR_ssb;
7074
7075    /* CFRA resource : SSB */
7076    DU_ALLOC(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
7077    if(!cfra->resources.choice.ssb)
7078    {
7079       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA resource - SSB in BuildRachConfigDedicated()");
7080       return RFAILED;
7081    }
7082    ssbResource = cfra->resources.choice.ssb;
7083
7084    /* CFRA SSB resource list */
7085    elementCnt = ueCb->cfraResource.numSsb;
7086    ssbResource->ssb_ResourceList.list.count = elementCnt;
7087    ssbResource->ssb_ResourceList.list.size = elementCnt * sizeof(CFRA_SSB_Resource_t *);
7088
7089    DU_ALLOC(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
7090    if(!ssbResource->ssb_ResourceList.list.array)
7091    {
7092       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list in BuildRachConfigDedicated()");
7093       return RFAILED;
7094    }
7095
7096    for(listIdx = 0; listIdx < elementCnt; listIdx++)
7097    {
7098       DU_ALLOC(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
7099       if(!ssbResource->ssb_ResourceList.list.array[listIdx])
7100       {
7101          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list element in BuildRachConfigDedicated()");  
7102          return RFAILED;
7103       }
7104       ssbResource->ssb_ResourceList.list.array[listIdx]->ssb = ueCb->cfraResource.ssbResource[listIdx].ssbIdx;
7105       ssbResource->ssb_ResourceList.list.array[listIdx]->ra_PreambleIndex = ueCb->cfraResource.ssbResource[listIdx].raPreambleIdx;
7106    }
7107
7108    return ROK;
7109 }
7110
7111 /*******************************************************************
7112  *
7113  * @brief Fills reconfiguration with sync in SP cell config
7114  *
7115  * @details
7116  *
7117  *    Function : BuildRecfgWithSync
7118  *
7119  *    Functionality: Fills reconfiguration with sync in SP cell config
7120  *
7121  * @params[in] DU UE CB
7122  *             Pointer to ReconfigurationWithSync_t
7123  *
7124  * @return ROK     - success
7125  *         RFAILED - failure
7126  *
7127  * ****************************************************************/
7128 uint8_t BuildRecfgWithSync(DuUeCb *ueCb, ReconfigurationWithSync_t *recfgWithSync)
7129 {
7130    /* SP Cell Config Common */  
7131    DU_ALLOC(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
7132    if(!recfgWithSync->spCellConfigCommon)
7133    {
7134       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for spCellConfigCommon in BuildRecfgWithSync()");
7135       return RFAILED;
7136    }
7137
7138    if((BuildSpCellConfigCommon(recfgWithSync->spCellConfigCommon)) != ROK)
7139    {
7140       DU_LOG("\nERROR  -->  DU APP : Failed to build SpCellConfigCommon in BuildRecfgWithSync()");
7141       return RFAILED;
7142    }
7143
7144    /* New UE Identity */
7145    recfgWithSync->newUE_Identity = ueCb->crnti;
7146
7147    /* T304 timer */
7148    recfgWithSync->t304 = ReconfigurationWithSync__t304_ms1000;
7149
7150    /* RACH configuration dedicated */
7151    DU_ALLOC(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
7152    if(!recfgWithSync->rach_ConfigDedicated)
7153    {
7154       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for RACH config dedicated in BuildRecfgWithSync()");
7155       return RFAILED;
7156    }
7157
7158    if((BuildRachConfigDedicated(ueCb, recfgWithSync->rach_ConfigDedicated)) != ROK)
7159    {
7160       DU_LOG("\nERROR  -->  DU APP : Failed to build RACH config dedicated in BuildRecfgWithSync()");
7161       return RFAILED;
7162    }
7163
7164    return ROK;
7165 }
7166
7167 /*******************************************************************
7168  *
7169  * @brief Builds Spcell config 
7170  *
7171  * @details
7172  *
7173  *    Function : BuildSpCellCfg 
7174  *
7175  *    Functionality: Builds sp cell config in DuToCuRrcContainer
7176  *
7177  * @params[in] SpCellConfig_t spCellCfg
7178  *
7179  * @return ROK     - success
7180  *         RFAILED - failure
7181  *
7182  * ****************************************************************/
7183 uint8_t BuildSpCellCfg(DuUeCb *ueCb, SpCellConfig_t *spCellCfg)
7184 {
7185    spCellCfg->servCellIndex = NULLP;
7186    DU_ALLOC(spCellCfg->servCellIndex, sizeof(long));
7187    if(!spCellCfg->servCellIndex)
7188    {
7189       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7190       return RFAILED;
7191    }
7192
7193    if(ueCb == NULLP)
7194       *(spCellCfg->servCellIndex) = SERV_CELL_IDX;
7195    else
7196       *(spCellCfg->servCellIndex) = ueCb->duMacUeCfg.spCellCfg.servCellIdx;
7197
7198    spCellCfg->reconfigurationWithSync = NULLP;
7199    if(ueCb && (ueCb->ueState == UE_HANDIN_IN_PROGRESS))
7200    {
7201       DU_ALLOC(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
7202       if(!spCellCfg->reconfigurationWithSync)
7203       {
7204          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7205          return RFAILED;
7206       }
7207
7208       if((BuildRecfgWithSync(ueCb, spCellCfg->reconfigurationWithSync)) != ROK)
7209       {
7210          DU_LOG("\nERROR  -->  F1AP : Building of reconfiguration with sync failed at BuildSpCellCfg");
7211          return RFAILED;
7212       }
7213    }
7214
7215    spCellCfg->rlf_TimersAndConstants = NULLP;
7216    spCellCfg->rlmInSyncOutOfSyncThreshold = NULLP;
7217
7218    DU_ALLOC(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
7219    if(!spCellCfg->rlmInSyncOutOfSyncThreshold)
7220    {
7221       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7222       return RFAILED;
7223    }
7224    *(spCellCfg->rlmInSyncOutOfSyncThreshold) = RLM_SYNC_OUT_SYNC_THRESHOLD;
7225
7226    spCellCfg->spCellConfigDedicated = NULLP;
7227    DU_ALLOC(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
7228    if(!spCellCfg->spCellConfigDedicated)
7229    {
7230       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7231       return RFAILED;
7232    }
7233    if(BuildSpCellCfgDed(ueCb, spCellCfg->spCellConfigDedicated) != ROK)
7234    {
7235       DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfgDed failed");
7236       return RFAILED;
7237    }
7238
7239    return ROK;
7240 }
7241
7242 /*******************************************************************
7243  *
7244  * @brief Builds Phy cell group config 
7245  *
7246  * @details
7247  *
7248  *    Function : BuildPhyCellGrpCfg 
7249  *
7250  *    Functionality: Builds Phy cell group config in DuToCuRrcContainer
7251  *
7252  * @params[in] PhysicalCellGroupConfig_t *phyCellGrpCfg 
7253  *
7254  * @return ROK     - success
7255  *         RFAILED - failure
7256  *
7257  * ****************************************************************/
7258 uint8_t BuildPhyCellGrpCfg(DuUeCb *ueCb, PhysicalCellGroupConfig_t *phyCellGrpCfg)
7259 {
7260    phyCellGrpCfg->harq_ACK_SpatialBundlingPUCCH = NULLP;
7261    phyCellGrpCfg->harq_ACK_SpatialBundlingPUSCH = NULLP;
7262
7263    phyCellGrpCfg->p_NR_FR1 = NULLP;
7264    DU_ALLOC(phyCellGrpCfg->p_NR_FR1, sizeof(long));
7265    if(!phyCellGrpCfg->p_NR_FR1)
7266    {
7267       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhyCellGrpCfg");
7268       return RFAILED;
7269    }
7270
7271    if(ueCb == NULLP)
7272    {
7273       *(phyCellGrpCfg->p_NR_FR1)             = P_NR_FR1;
7274       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = PDSCH_HARQ_ACK_CODEBOOK;
7275    }
7276    else
7277    {
7278       *(phyCellGrpCfg->p_NR_FR1) = ueCb->duMacUeCfg.phyCellGrpCfg.pNrFr1;
7279       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = ueCb->duMacUeCfg.phyCellGrpCfg.pdschHarqAckCodebook;
7280    }
7281
7282    phyCellGrpCfg->tpc_SRS_RNTI = NULLP;
7283    phyCellGrpCfg->tpc_PUCCH_RNTI = NULLP;
7284    phyCellGrpCfg->tpc_PUSCH_RNTI = NULLP;
7285    phyCellGrpCfg->sp_CSI_RNTI = NULLP;
7286    phyCellGrpCfg->cs_RNTI = NULLP;
7287    phyCellGrpCfg->ext1 = NULLP;
7288    phyCellGrpCfg->ext2 = NULLP;
7289
7290    return ROK;
7291 }
7292 #ifdef NR_DRX
7293 /*******************************************************************
7294  *
7295  * @brief fill long cycle offset value of drx
7296  *
7297  * @details
7298  *
7299  *    Function : fillLongCycleOffsetValFromDuCb 
7300  *
7301  *    Functionality: fill long cycle offset value of drx
7302  *
7303  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
7304  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
7305  *
7306  * @return ROK     - success
7307  *         RFAILED - failure
7308  *
7309  * ****************************************************************/
7310 void fillLongCycleOffsetValFromDuCb(DrxLongCycleStartOffset  drxLongCycleStartOffset,\
7311 struct DRX_ConfigRrc__drx_LongCycleStartOffset *drx_LongCycleStartOffset)
7312 {
7313    
7314    drx_LongCycleStartOffset->present = convertLongDrxCycleLengthValueToEnum(drxLongCycleStartOffset.drxLongCycleStartOffsetChoice); 
7315    switch(drx_LongCycleStartOffset->present)
7316    {
7317       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
7318          {
7319             drx_LongCycleStartOffset->choice.ms10 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7320             break;
7321          }
7322       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
7323          {
7324             drx_LongCycleStartOffset->choice.ms20 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7325             break;
7326          }
7327       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
7328          {
7329             drx_LongCycleStartOffset->choice.ms32 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7330             break;
7331          }
7332       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
7333          {
7334             drx_LongCycleStartOffset->choice.ms40 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7335             break;
7336          }
7337       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
7338          {
7339             drx_LongCycleStartOffset->choice.ms60 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7340             break;
7341          }
7342       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
7343          {
7344             drx_LongCycleStartOffset->choice.ms64 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7345             break;
7346          }
7347       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
7348          {
7349             drx_LongCycleStartOffset->choice.ms70 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7350             break;
7351          }
7352       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
7353          {
7354             drx_LongCycleStartOffset->choice.ms80 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7355             break;
7356          }
7357       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
7358          {
7359             drx_LongCycleStartOffset->choice.ms128 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7360             break;
7361          }
7362       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
7363          {
7364             drx_LongCycleStartOffset->choice.ms160 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7365             break;
7366          }
7367       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
7368          {
7369             drx_LongCycleStartOffset->choice.ms256 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7370             break;
7371          }
7372       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
7373          {
7374             drx_LongCycleStartOffset->choice.ms320 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7375             break;
7376          }
7377       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
7378          {
7379             drx_LongCycleStartOffset->choice.ms512 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7380             break;
7381          }
7382       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
7383          {
7384             drx_LongCycleStartOffset->choice.ms640 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7385             break;
7386          }
7387       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
7388          {
7389             drx_LongCycleStartOffset->choice.ms1024 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7390             break;
7391          }
7392       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
7393          {
7394             drx_LongCycleStartOffset->choice.ms1280 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7395             break;
7396          }
7397       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
7398          {
7399             drx_LongCycleStartOffset->choice.ms2048 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7400             break;
7401          }
7402       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
7403          {
7404             drx_LongCycleStartOffset->choice.ms2560 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7405             break;
7406          }
7407       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
7408          {
7409             drx_LongCycleStartOffset->choice.ms5120 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7410             break;
7411          }
7412       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
7413          {
7414             drx_LongCycleStartOffset->choice.ms10240 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7415             break;
7416          }
7417       default :
7418          break;
7419    }
7420 }
7421 /*******************************************************************
7422  *
7423  * @brief Builds drx config IE 
7424  *
7425  * @details
7426  *
7427  *    Function : BuildDrxConfigRrc 
7428  *
7429  *    Functionality: Build drx config in MacCellGrpCfg 
7430  *
7431  * @params[in] struct MAC_CellGroupConfig__drx_ConfigRrc 
7432  *
7433  * @return ROK     - success
7434  *         RFAILED - failure
7435  *
7436  * ****************************************************************/
7437 uint8_t BuildDrxConfigRrc(DuUeCb *ueCb, struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg)
7438 {
7439    drxCfg->present = MAC_CellGroupConfig__drx_ConfigRrc_PR_setup;
7440    DU_ALLOC(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
7441    if(!drxCfg->choice.setup)
7442    {
7443       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7444       return RFAILED;
7445    }
7446    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationTimerValInMs)
7447    {
7448       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds;
7449       drxCfg->choice.setup->drx_onDurationTimer.choice.milliSeconds = convertOnDurationTimerMilliSecondsValueToEnum(ueCb->duMacUeCfg.\
7450       macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationtimerValue.milliSeconds);
7451    }
7452    else
7453    {
7454       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds;
7455       drxCfg->choice.setup->drx_onDurationTimer.choice.subMilliSeconds = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7456       drxOnDurationTimer.onDurationtimerValue.subMilliSeconds;
7457    }
7458    drxCfg->choice.setup->drx_InactivityTimer = convertDrxInactivityTimerValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxInactivityTimer);
7459    drxCfg->choice.setup->drx_HARQ_RTT_TimerDL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerDl;
7460    drxCfg->choice.setup->drx_HARQ_RTT_TimerUL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerUl;
7461    drxCfg->choice.setup->drx_RetransmissionTimerDL = convertDrxRetransmissionTimerDlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7462    drxRetransmissionTimerDl);
7463    drxCfg->choice.setup->drx_RetransmissionTimerUL = convertDrxRetransmissionTimerUlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7464    drxRetransmissionTimerUl);
7465    drxCfg->choice.setup->drx_SlotOffset = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxSlotOffset;
7466    fillLongCycleOffsetValFromDuCb(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxLongCycleStartOffset, &drxCfg->choice.setup->drx_LongCycleStartOffset);
7467    
7468    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrxPres)
7469    {
7470       DU_ALLOC(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));
7471       if(drxCfg->choice.setup->shortDRX)
7472       {
7473          drxCfg->choice.setup->shortDRX->drx_ShortCycle = convertShortDrxCycleLengthValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7474          shortDrx.drxShortCycle);
7475          drxCfg->choice.setup->shortDRX->drx_ShortCycleTimer = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrx.drxShortCycleTimer;
7476       }
7477       else
7478       {
7479          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7480          return RFAILED;
7481       }
7482    }
7483    return ROK;
7484 }
7485 #endif
7486 /*******************************************************************
7487  *
7488  * @brief Builds Mac cell group config 
7489  *
7490  * @details
7491  *
7492  *    Function : BuildMacCellGrpCfg 
7493  *
7494  *    Functionality: Builds Mac cell group config in DuToCuRrcContainer
7495  *
7496  * @params[in] MAC_CellGroupConfig_t *macCellGrpCfg
7497  *
7498  * @return ROK     - success
7499  *         RFAILED - failure
7500  *
7501  * ****************************************************************/
7502 uint8_t BuildMacCellGrpCfg(DuUeCb *ueCb, MAC_CellGroupConfig_t *macCellGrpCfg)
7503 {
7504    macCellGrpCfg->drx_ConfigRrc = NULLP;
7505 #ifdef NR_DRX   
7506    if(ueCb)
7507    {
7508       DU_ALLOC(macCellGrpCfg->drx_ConfigRrc, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
7509       if(!macCellGrpCfg->drx_ConfigRrc)
7510       {
7511          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7512          return RFAILED;
7513       }
7514       if(BuildDrxConfigRrc(ueCb, macCellGrpCfg->drx_ConfigRrc) != ROK)
7515       {
7516          DU_LOG("\nERROR  -->  F1AP : failed to build drx config");
7517          return RFAILED;
7518       }
7519    }
7520 #endif
7521    macCellGrpCfg->schedulingRequestConfig = NULLP;
7522    DU_ALLOC(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
7523    if(!macCellGrpCfg->schedulingRequestConfig)
7524    {
7525       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7526       return RFAILED;
7527    }
7528
7529    if(BuildSchedulingReqConfig(ueCb, macCellGrpCfg->schedulingRequestConfig) != ROK)
7530    {
7531       DU_LOG("\nERROR  -->  F1AP : BuildSchedulingReqConfig failed");
7532       return RFAILED;
7533    }
7534
7535    macCellGrpCfg->bsr_Config = NULLP;
7536    DU_ALLOC(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
7537    if(!macCellGrpCfg->bsr_Config)
7538    {
7539       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7540       return RFAILED;
7541    }
7542
7543    if(BuildBsrConfig(ueCb, macCellGrpCfg->bsr_Config) != ROK)
7544    {
7545       DU_LOG("\nERROR  -->  F1AP : BuildBsrConfig failed");
7546       return RFAILED;
7547    }
7548
7549    macCellGrpCfg->tag_Config = NULLP;
7550    DU_ALLOC(macCellGrpCfg->tag_Config, sizeof(struct TAG_Config));
7551    if(!macCellGrpCfg->tag_Config)
7552    {
7553       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7554       return RFAILED;
7555    }
7556
7557    if(BuildTagConfig(ueCb, macCellGrpCfg->tag_Config) != ROK)
7558    {
7559       DU_LOG("\nERROR  -->  F1AP : BuildTagConfig failed");
7560       return RFAILED;
7561    }
7562
7563    macCellGrpCfg->phr_Config = NULLP;
7564    DU_ALLOC(macCellGrpCfg->phr_Config, sizeof(struct MAC_CellGroupConfig__phr_Config));
7565    if(!macCellGrpCfg->phr_Config)
7566    {
7567       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7568       return RFAILED;
7569    }
7570
7571    if(BuildPhrConfig(ueCb, macCellGrpCfg->phr_Config) != ROK)
7572    {
7573       DU_LOG("\nERROR  -->  F1AP : BuildPhrConfig failed");
7574       return RFAILED;
7575    }
7576
7577    macCellGrpCfg->skipUplinkTxDynamic = false;
7578    macCellGrpCfg->ext1 = NULLP;
7579
7580    return ROK;
7581 }
7582 /*******************************************************************
7583  *
7584  * @brief Frees memeory allocated for SearchSpcToAddModList
7585  *
7586  * @details
7587  *
7588  *    Function : FreeSearchSpcToAddModList
7589  *
7590  *    Functionality: Deallocating memory of SearchSpcToAddModList
7591  *
7592  * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
7593  *
7594  * @return void
7595  *
7596  4221 * ****************************************************************/
7597 void FreeSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
7598 {
7599    uint8_t idx1=0;
7600    uint8_t idx2=0;
7601    struct  SearchSpace *searchSpc=NULLP;
7602
7603    if(searchSpcList->list.array)
7604    {
7605       if(searchSpcList->list.array[idx2])
7606       {
7607          searchSpc = searchSpcList->list.array[idx2];
7608          if(searchSpc->controlResourceSetId)
7609          {
7610             if(searchSpc->monitoringSlotPeriodicityAndOffset)
7611             {
7612                if(searchSpc->monitoringSymbolsWithinSlot)
7613                {
7614                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
7615                   {
7616                      if(searchSpc->nrofCandidates)
7617                      {
7618                         if(searchSpc->searchSpaceType)
7619                         {
7620                            DU_FREE(searchSpc->searchSpaceType->choice.ue_Specific,\
7621                                  sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
7622                            DU_FREE(searchSpc->searchSpaceType, sizeof(struct
7623                                     SearchSpace__searchSpaceType));
7624                         }
7625                         DU_FREE(searchSpc->nrofCandidates,
7626                               sizeof(struct SearchSpace__nrofCandidates));
7627                      }
7628                      DU_FREE(searchSpc->monitoringSymbolsWithinSlot->buf, \
7629                            searchSpc->monitoringSymbolsWithinSlot->size);
7630                   }
7631                   DU_FREE(searchSpc->monitoringSymbolsWithinSlot,
7632                         sizeof(BIT_STRING_t));
7633                }
7634                DU_FREE(searchSpc->monitoringSlotPeriodicityAndOffset, \
7635                      sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
7636             }
7637             DU_FREE(searchSpc->controlResourceSetId,
7638                   sizeof(ControlResourceSetId_t));
7639          }
7640       }
7641       for(idx1 = 0; idx1 < searchSpcList->list.count; idx1++)
7642       {
7643          DU_FREE(searchSpcList->list.array[idx1],
7644                sizeof(struct SearchSpace));
7645       }
7646       DU_FREE(searchSpcList->list.array,searchSpcList->list.size);
7647    }
7648 }
7649 /*******************************************************************
7650  *
7651  * @brief Frees memory allocated for PdschTimeDomAllocList
7652  *
7653  * @details
7654  *
7655  *    Function : FreePdschTimeDomAllocList
7656  *
7657  *    Functionality: Deallocating memory of PdschTimeDomAllocList
7658  *
7659  * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
7660  *
7661  * @return void
7662  *
7663  * ****************************************************************/
7664 void FreePdschTimeDomAllocList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
7665 {
7666    uint8_t idx1=0;
7667
7668    if(timeDomAllocList->choice.setup)
7669    {
7670       if(timeDomAllocList->choice.setup->list.array)
7671       {
7672          for(idx1 = 0; idx1 <timeDomAllocList->choice.setup->list.count ; idx1++)
7673          {
7674             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1]->k0, sizeof(long));
7675             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1],
7676                   sizeof(struct PDSCH_TimeDomainResourceAllocation));
7677          }
7678          DU_FREE(timeDomAllocList->choice.setup->list.array, \
7679                timeDomAllocList->choice.setup->list.size);
7680       }
7681       DU_FREE(timeDomAllocList->choice.setup,\
7682             sizeof(struct PDSCH_TimeDomainResourceAllocationList));
7683    }
7684 }
7685 /*******************************************************************
7686  *
7687  * @brief Frees memory allocated for PuschTimeDomAllocList
7688  *
7689  *@details
7690  *
7691  *    Function : FreePuschTimeDomAllocList
7692  *
7693  *    Functionality: Deallocating memory of PuschTimeDomAllocList
7694  *
7695  * @params[in] PUSCH_Config_t *puschCfg
7696  *
7697  * @return void
7698  *
7699  * ****************************************************************/
7700 void FreePuschTimeDomAllocList(PUSCH_Config_t *puschCfg)
7701 {
7702    uint8_t rsrcListIdx=0;
7703    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
7704
7705    if(puschCfg->pusch_TimeDomainAllocationList)
7706    {
7707       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
7708       if(timeDomAllocList_t->choice.setup)
7709       {
7710          if(timeDomAllocList_t->choice.setup->list.array)
7711          {
7712             for(rsrcListIdx = 0; rsrcListIdx<timeDomAllocList_t->choice.setup->list.count; rsrcListIdx++)
7713             {
7714                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx]->k2, sizeof(long));
7715                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx],\
7716                      sizeof(PUSCH_TimeDomainResourceAllocation_t));
7717             }
7718             DU_FREE(timeDomAllocList_t->choice.setup->list.array, \
7719                   timeDomAllocList_t->choice.setup->list.size);
7720          }
7721          DU_FREE(timeDomAllocList_t->choice.setup, \
7722                sizeof(struct PUSCH_TimeDomainResourceAllocationList));
7723       }
7724       DU_FREE(puschCfg->transformPrecoder, sizeof(long));
7725       DU_FREE(puschCfg->pusch_TimeDomainAllocationList, \
7726             sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
7727    }
7728
7729 }
7730
7731 /*******************************************************************
7732  *
7733  * @brief Frees memory allocated for Dedicated PUCCH config
7734  *
7735  * @details
7736  *
7737  *    Function : FreeBWPUlDedPucchCfg
7738  *
7739  *    Functionality: Deallocating memory of Dedicated PUCCH cfg
7740  *
7741  * @params[in] BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg
7742  *
7743  * @return void
7744  *
7745  * ****************************************************************/
7746 void FreeBWPUlDedPucchCfg(struct BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg)
7747 {
7748    uint8_t k1Idx, rsrcIdx, rsrcSetIdx;
7749    PUCCH_Config_t *pucchCfg = NULLP;
7750    PUCCH_ResourceSet_t *rsrcSet = NULLP;
7751    PUCCH_Resource_t *rsrc = NULLP;
7752
7753    if(ulBwpPucchCfg)
7754    {
7755       if(ulBwpPucchCfg->choice.setup)
7756       {
7757          pucchCfg = ulBwpPucchCfg->choice.setup;
7758
7759          //Free resource set list
7760          if(pucchCfg->resourceSetToAddModList)
7761          {
7762             if(pucchCfg->resourceSetToAddModList->list.array)
7763             {
7764                for(rsrcSetIdx=0; rsrcSetIdx < pucchCfg->resourceSetToAddModList->list.count; rsrcSetIdx++)
7765                {
7766                   rsrcSet = pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx];
7767                   if(rsrcSet->resourceList.list.array)
7768                   {
7769                      for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
7770                      {
7771                         DU_FREE(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
7772                      }
7773                      DU_FREE(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
7774                   }
7775                   DU_FREE(pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
7776                }
7777                DU_FREE(pucchCfg->resourceSetToAddModList->list.array, pucchCfg->resourceSetToAddModList->list.size);
7778             }
7779             DU_FREE(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
7780          }
7781
7782          //Free resource list
7783          if(pucchCfg->resourceToAddModList)
7784          {
7785             if(pucchCfg->resourceToAddModList->list.array)
7786             {
7787                for(rsrcIdx=0; rsrcIdx < pucchCfg->resourceToAddModList->list.count; rsrcIdx++)
7788                {
7789                   rsrc = pucchCfg->resourceToAddModList->list.array[rsrcIdx];
7790                   DU_FREE(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
7791                   DU_FREE(pucchCfg->resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
7792                }
7793                DU_FREE(pucchCfg->resourceToAddModList->list.array, pucchCfg->resourceToAddModList->list.size);
7794             }
7795             DU_FREE(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
7796          }
7797
7798          //PUCCH Format 1
7799          if(pucchCfg->format1)
7800          {
7801             if(pucchCfg->format1->choice.setup)
7802             {
7803                DU_FREE(pucchCfg->format1->choice.setup->nrofSlots, sizeof(long));
7804                DU_FREE(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
7805             }
7806             DU_FREE(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
7807          }
7808          
7809          //DL DATA TO UL ACK
7810          if(pucchCfg->dl_DataToUL_ACK)
7811          {
7812             if(pucchCfg->dl_DataToUL_ACK->list.array)
7813             {
7814                for(k1Idx = 0; k1Idx <  pucchCfg->dl_DataToUL_ACK->list.count; k1Idx++)
7815                {
7816                   DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array[k1Idx], sizeof(long));
7817                }
7818                DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array, pucchCfg->dl_DataToUL_ACK->list.size);
7819             }
7820             DU_FREE(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
7821          }
7822
7823          DU_FREE(ulBwpPucchCfg->choice.setup, sizeof(PUCCH_Config_t));
7824       }
7825       DU_FREE(ulBwpPucchCfg, sizeof(struct BWP_UplinkDedicated__pucch_Config));
7826    }
7827 }
7828
7829 /*******************************************************************
7830  *
7831  * @brief Frees memory allocated for InitialUlBWP
7832  *
7833  * @details
7834  *
7835  *    Function : FreeInitialUlBWP
7836  *
7837  *    Functionality: Deallocating memory of InitialUlBWP
7838  *
7839  * @params[in] BWP_UplinkDedicated_t *ulBwp
7840  *
7841  * @return void
7842  *
7843  * ****************************************************************/
7844 void FreeInitialUlBWP(BWP_UplinkDedicated_t *ulBwp)
7845 {
7846    uint8_t  rSetIdx, rsrcIdx;
7847    SRS_Config_t   *srsCfg = NULLP;
7848    PUSCH_Config_t *puschCfg = NULLP;
7849    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
7850    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
7851    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
7852    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
7853
7854    FreeBWPUlDedPucchCfg(ulBwp->pucch_Config);
7855
7856    if(ulBwp->pusch_Config)
7857    {
7858       if(ulBwp->pusch_Config->choice.setup)
7859       {
7860          puschCfg=ulBwp->pusch_Config->choice.setup;
7861          if(puschCfg->dataScramblingIdentityPUSCH)
7862          {
7863             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
7864             {
7865                FreePuschTimeDomAllocList(puschCfg);
7866                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
7867                if(dmrsUlCfg->choice.setup)
7868                {
7869                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
7870                   {
7871                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
7872                      {
7873                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
7874                               sizeof(long));
7875                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled,
7876                               sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
7877                      }
7878                      DU_FREE(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition,
7879                            sizeof(long));
7880                   }
7881                   DU_FREE(dmrsUlCfg->choice.setup,sizeof(DMRS_UplinkConfig_t));
7882                }
7883                DU_FREE(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, \
7884                      sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
7885             }
7886             DU_FREE(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
7887          }
7888          DU_FREE(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
7889       }
7890       DU_FREE(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
7891
7892       /* Free SRS-Config */
7893       if(ulBwp->srs_Config)
7894       {
7895          if(ulBwp->srs_Config->choice.setup)
7896          {
7897             srsCfg = ulBwp->srs_Config->choice.setup;
7898
7899             /* Free Resource Set to add/mod list */
7900             if(srsCfg->srs_ResourceSetToAddModList)
7901             {
7902                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
7903                if(rsrcSetList->list.array)
7904                {
7905                   rSetIdx = 0;
7906
7907                   /* Free SRS resource Id list in this SRS resource set */
7908                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
7909                   {
7910                      rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
7911
7912                      if(rsrcIdList->list.array)
7913                      {
7914                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
7915                         {
7916                            DU_FREE(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
7917                         }
7918                         DU_FREE(rsrcIdList->list.array, rsrcIdList->list.size);
7919                      }
7920                      DU_FREE(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
7921                            sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
7922                   }
7923
7924                   /* Free resource type info for this SRS resource set */
7925                   DU_FREE(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
7926                         sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
7927
7928                   /* Free memory for each resource set */
7929                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
7930                   {
7931                      DU_FREE(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
7932                   }
7933                   DU_FREE(rsrcSetList->list.array, rsrcSetList->list.size); 
7934                }
7935                DU_FREE(srsCfg->srs_ResourceSetToAddModList, \
7936                      sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
7937             }
7938
7939             /* Free resource to add/modd list */
7940             if(srsCfg->srs_ResourceToAddModList)
7941             {
7942                resourceList = srsCfg->srs_ResourceToAddModList;
7943                if(resourceList->list.array)
7944                {
7945                   rsrcIdx = 0;
7946                   DU_FREE(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2,\
7947                         sizeof(struct SRS_Resource__transmissionComb__n2));
7948                   DU_FREE(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,\
7949                         sizeof(struct SRS_Resource__resourceType__aperiodic));
7950
7951                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
7952                   {
7953                      DU_FREE(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
7954                   }
7955                   DU_FREE(resourceList->list.array, resourceList->list.size);
7956                }
7957                DU_FREE(srsCfg->srs_ResourceToAddModList, \
7958                      sizeof(struct SRS_Config__srs_ResourceToAddModList));
7959             }
7960
7961             DU_FREE(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
7962          }
7963          DU_FREE(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
7964       }
7965    }
7966 }       
7967 /*******************************************************************
7968  *
7969  * @brief Frees memory allocated for initialUplinkBWP
7970  *
7971  * @details
7972  *
7973  *    Function : FreeinitialUplinkBWP
7974  *
7975  *    Functionality: Deallocating memory of initialUplinkBWP
7976  *
7977  * @params[in] UplinkConfig_t *ulCfg
7978  *
7979  * @return void
7980  *         
7981  *
7982  * ****************************************************************/
7983 void FreeinitialUplinkBWP(UplinkConfig_t *ulCfg)
7984 {
7985    BWP_UplinkDedicated_t *ulBwp=NULLP; 
7986    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
7987
7988    if(ulCfg->initialUplinkBWP)
7989    {
7990       ulBwp=ulCfg->initialUplinkBWP;
7991       if(ulCfg->firstActiveUplinkBWP_Id)
7992       {
7993          if(ulCfg->pusch_ServingCellConfig)
7994          {
7995             puschCfg=ulCfg->pusch_ServingCellConfig;
7996             if(puschCfg->choice.setup)
7997             {
7998                if(puschCfg->choice.setup->ext1)
7999                {
8000                   DU_FREE(puschCfg->choice.setup->ext1->\
8001                         processingType2Enabled,sizeof(BOOLEAN_t));
8002                   DU_FREE(puschCfg->choice.setup->ext1->\
8003                         maxMIMO_Layers,sizeof(long));
8004                   DU_FREE(puschCfg->choice.setup->ext1, \
8005                         sizeof(struct PUSCH_ServingCellConfig__ext1));
8006                }
8007                DU_FREE(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
8008             }
8009             DU_FREE(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
8010          }
8011          DU_FREE(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
8012       }
8013       FreeInitialUlBWP(ulBwp);
8014       DU_FREE(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
8015    }
8016 }
8017 /*******************************************************************
8018  *
8019  * @brief Frees emmory allocated for BWPDlDedPdschCfg
8020  *
8021  * @details
8022  *
8023  *    Function : FreeBWPDlDedPdschCfg
8024  *
8025  *    Functionality: Deallocating memory of BWPDlDedPdschCfg
8026  *
8027  * @params[in] BWP_DownlinkDedicated_t *dlBwp
8028  *
8029  * @return void
8030  *
8031  *
8032  * ****************************************************************/
8033 void FreeBWPDlDedPdschCfg(BWP_DownlinkDedicated_t *dlBwp)
8034 {
8035    struct PDSCH_Config *pdschCfg=NULLP;
8036    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
8037    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
8038    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
8039
8040    if(dlBwp->pdsch_Config->choice.setup)
8041    {
8042       pdschCfg=dlBwp->pdsch_Config->choice.setup;
8043       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
8044       {
8045          if(pdschCfg->pdsch_TimeDomainAllocationList)
8046          {
8047             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
8048             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
8049             {
8050                prbBndlType=&pdschCfg->prb_BundlingType;
8051                DU_FREE(prbBndlType->choice.staticBundling,\
8052                      sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
8053                DU_FREE(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
8054             }
8055             FreePdschTimeDomAllocList(timeDomAllocList);
8056             DU_FREE(pdschCfg->pdsch_TimeDomainAllocationList, \
8057                   sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
8058          }
8059          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
8060          if(dmrsDlCfg->choice.setup)
8061          {
8062             DU_FREE(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition,
8063                   sizeof(long));
8064             DU_FREE(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
8065          }
8066          DU_FREE(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, \
8067                sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
8068       }
8069       DU_FREE(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
8070    }
8071 }
8072 /*******************************************************************
8073  *
8074  * @brief Frees emmory allocated for BWPDlDedPdcchCfg
8075  *
8076  * @details
8077  *
8078  *    Function : FreeBWPDlDedPdcchCfg
8079  *
8080  *    Functionality: Deallocating memory of BWPDlDedPdcchCfg
8081  *
8082  * @params[in] BWP_DownlinkDedicated_t *dlBwp
8083  *
8084  * @return void
8085  *         
8086  *
8087  * ****************************************************************/
8088 void FreeBWPDlDedPdcchCfg(BWP_DownlinkDedicated_t *dlBwp)
8089 {
8090    uint8_t idx1=0;
8091    uint8_t idx2=0;
8092    struct PDCCH_Config *pdcchCfg=NULLP;
8093    struct ControlResourceSet *controlRSet=NULLP;
8094    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
8095
8096    if(dlBwp->pdcch_Config->choice.setup)
8097    {
8098       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
8099       if(pdcchCfg->controlResourceSetToAddModList)
8100       {
8101          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
8102          if(controlRSetList->list.array)
8103          {
8104             controlRSet = controlRSetList->list.array[idx2];
8105             if(controlRSet)
8106             {
8107                if(controlRSet->frequencyDomainResources.buf)
8108                {
8109                   if(controlRSet->pdcch_DMRS_ScramblingID)
8110                   {
8111                      if(pdcchCfg->searchSpacesToAddModList)
8112                      {
8113                         FreeSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
8114                         DU_FREE(pdcchCfg->searchSpacesToAddModList, \
8115                               sizeof(struct PDCCH_Config__searchSpacesToAddModList));
8116                      }
8117                      DU_FREE(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
8118                   }
8119                   DU_FREE(controlRSet->frequencyDomainResources.buf, \
8120                         controlRSet->frequencyDomainResources.size);
8121                }
8122             }
8123             for(idx1 = 0; idx1 <controlRSetList->list.count; idx1++)
8124             {
8125                DU_FREE(controlRSetList->list.array[idx1], sizeof(struct ControlResourceSet));
8126             }
8127             DU_FREE(controlRSetList->list.array, controlRSetList->list.size);
8128          }
8129          DU_FREE(pdcchCfg->controlResourceSetToAddModList, \
8130                sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
8131       }
8132       DU_FREE(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
8133    }
8134 }       
8135
8136 /*******************************************************************
8137  *
8138  * @brief Free SCS specific carrier list in DL frequency info
8139  *
8140  * @details
8141  *
8142  *    Function : FreeScsSpecificCarrierListDl
8143  *
8144  *    Functionality: Free SCS specific carrier list in DL frequency info
8145  *
8146  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
8147  *
8148  * @return void
8149  *
8150  * ****************************************************************/
8151 void FreeScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
8152 {
8153    uint8_t listIdx = 0;
8154
8155    if(!scsCarrierList->list.array)
8156    {
8157       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
8158       {
8159          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
8160       }
8161       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
8162    }
8163 }
8164
8165 /*******************************************************************
8166  *
8167  * @brief Free DL frequency info in DL config common
8168  *
8169  * @details
8170  *
8171  *    Function : FreeFreqInfoDl
8172  *
8173  *    Functionality: Free DL frequency info in DL config common
8174  *
8175  * @params[in] Pointer to DownlinkConfigCommon_t
8176  *
8177  * @return void
8178  *
8179  * ****************************************************************/
8180 void FreeFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
8181 {
8182    uint8_t freqBandIdx = 0;
8183
8184    /* SSB Absolute Frequency */
8185    DU_FREE(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
8186
8187    /* NR Multi Frequency Band List */
8188    if(frequencyInfoDL->frequencyBandList.list.array)
8189    {
8190       for(freqBandIdx = 0; freqBandIdx < frequencyInfoDL->frequencyBandList.list.count; freqBandIdx++)
8191       {
8192          DU_FREE(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
8193       }
8194       DU_FREE(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
8195    }
8196
8197    /* Subcarrier Spacing specifc carrier List */
8198    FreeScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList);
8199 }
8200
8201 /*******************************************************************
8202  *
8203  * @brief Free DL config common in Serving cell config common
8204  *
8205  * @details
8206  *
8207  *    Function : FreeDlConfigCommon
8208  *
8209  *    Functionality: Free DL config common in Serving cell config common
8210  *
8211  * @params[in] Pointer to DownlinkConfigCommon_t
8212  *
8213  * @return void
8214  *
8215  * ****************************************************************/
8216 void FreeDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
8217 {
8218    /* DL Frequency Info */
8219    if(dlCfgCommon->frequencyInfoDL)
8220    {
8221       FreeFreqInfoDl(dlCfgCommon->frequencyInfoDL);
8222       DU_FREE(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
8223    }
8224
8225    /* DL BWP config common */
8226    if(dlCfgCommon->initialDownlinkBWP)
8227    {
8228       FreeBwpDlCommon(dlCfgCommon->initialDownlinkBWP);
8229       DU_FREE(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
8230    }
8231 }
8232
8233 /*******************************************************************
8234  *
8235  * @brief Free SCS specific carrier list in UL frequency Info
8236  *
8237  * @details
8238  *
8239  *    Function : FreeScsSpecificCarrierListUl
8240  *
8241  *    Functionality: Free SCS specific carrier list in UL frequency Info
8242  *
8243  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
8244  *
8245  * @return void
8246  *
8247  * ****************************************************************/
8248 void FreeScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
8249 {
8250    uint8_t listIdx = 0;
8251
8252    if(scsCarrierList->list.array)
8253    {
8254       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
8255       {
8256          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
8257       }
8258       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
8259    }
8260 }
8261
8262 /*******************************************************************
8263  *
8264  * @brief Free frequency info in UL config common
8265  *
8266  * @details
8267  *
8268  *    Function : FreeFreqInfoUl
8269  *
8270  *    Functionality: Free frequency info in UL config common
8271  *
8272  * @params[in] Pointer to FrequencyInfoUL_t
8273  *
8274  * @return void
8275  *
8276  * ****************************************************************/
8277 void FreeFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
8278 {
8279    uint8_t listIdx= 0;
8280
8281    /* NR Multi Frequency Band List */
8282    if(!frequencyInfoUL->frequencyBandList)
8283    {
8284       if(frequencyInfoUL->frequencyBandList->list.array)
8285       {
8286          for(listIdx = 0; listIdx < frequencyInfoUL->frequencyBandList->list.count; listIdx++)
8287          {
8288             DU_FREE(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
8289          }
8290          DU_FREE(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
8291       }
8292       DU_FREE(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
8293    }
8294
8295    /* Absolute frequency point A */
8296    DU_FREE(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
8297
8298    /* Subcarrier Spacing specifc carrier */
8299    FreeScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList);
8300
8301    /* P-MAX */
8302    DU_FREE(frequencyInfoUL->p_Max, sizeof(P_Max_t));
8303 }
8304
8305 /*******************************************************************
8306  *
8307  * @brief Free UL config common in Serving cell config common
8308  *
8309  * @details
8310  *
8311  *    Function : FreeUlConfigCommon
8312  *
8313  *    Functionality: Free UL config common in Serving cell config common
8314  *
8315  * @params[in] Pointer to UplinkConfigCommon_t
8316  *
8317  * @return void
8318  *
8319  * ****************************************************************/
8320 void FreeUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
8321 {
8322    /* UL Frequency Info */
8323    if(ulCfgCommon->frequencyInfoUL)
8324    {
8325       FreeFreqInfoUl(ulCfgCommon->frequencyInfoUL);
8326       DU_FREE(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
8327    }
8328
8329    /* UL BWP common */
8330    if(ulCfgCommon->initialUplinkBWP)
8331    {
8332       FreeBwpUlCommon(ulCfgCommon->initialUplinkBWP);
8333       DU_FREE(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
8334    }
8335 }
8336
8337 /*******************************************************************
8338  *
8339  * @brief Free SP cell config common in Reconfig with Sync
8340  *
8341  * @details
8342  *
8343  *    Function : FreeSpCellConfigCommon
8344  *
8345  *    Functionality: Free SP cell config common in Reconfig with Sync
8346  *
8347  * @params[in] Pointer to ServingCellConfigCommon_t
8348  *
8349  * @return void
8350  *
8351  * ****************************************************************/
8352 void FreeSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
8353 {
8354    /* Free Physical cell identity */
8355    DU_FREE(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
8356
8357    /* Free Downlink Config common */
8358    if(spCellConfigCommon->downlinkConfigCommon)
8359    {
8360       FreeDlConfigCommon(spCellConfigCommon->downlinkConfigCommon);
8361       DU_FREE(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
8362    }
8363
8364    /* Free Uplink Config common */
8365    if(spCellConfigCommon->uplinkConfigCommon)
8366    {
8367       FreeUlConfigCommon(spCellConfigCommon->uplinkConfigCommon);
8368       DU_FREE(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
8369    }
8370
8371    /* Free Timing Advance offset */
8372    DU_FREE(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
8373
8374    /* Free SSB Position in Burst */
8375    if(spCellConfigCommon->ssb_PositionsInBurst)
8376    {
8377       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.buf, \
8378          spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.size);
8379       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
8380    }
8381
8382    /* Free SSB Periodicity in Serving cell */
8383    DU_FREE(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
8384
8385    /* Free SSB subcarrier spacing */
8386    DU_FREE(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
8387
8388    /* TDD UL-DL configuration common */
8389    DU_FREE(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
8390 }
8391
8392 /*******************************************************************
8393  *
8394  * @brief Free dedicated RACH configuration in Reconfiguration with sync
8395  *
8396  * @details
8397  *
8398  *    Function : FreeRecfgWithSync
8399  *
8400  *    Functionality:
8401  *       Free dedicated RACH configuration in Reconfiguration with sync
8402  *
8403  * @params[in] Pinter to Rach config dedicated struct
8404  *
8405  * @return void
8406  *
8407  * ****************************************************************/
8408 void FreeRachConfigDedicated(struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
8409 {
8410    uint8_t listIdx = 0;
8411    CFRA_t *cfra = NULLP;
8412    struct CFRA__resources__ssb *ssbResource = NULLP;
8413
8414    /* Uplink */
8415    if(rachCfgDed->choice.uplink)
8416    {
8417       /* CFRA : Contention free Random Access */
8418       if(rachCfgDed->choice.uplink->cfra)
8419       {
8420          cfra = rachCfgDed->choice.uplink->cfra;
8421
8422          /* CFRA occassions */
8423          if(cfra->occasions)
8424          {
8425             /* CFRA occassions : SSB per RACH occasion */
8426             DU_FREE(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
8427             DU_FREE(cfra->occasions, sizeof(struct CFRA__occasions));
8428          }
8429
8430          /* CFRA resource */
8431          cfra->resources.present = CFRA__resources_PR_ssb;
8432
8433          /* CFRA resource : SSB */
8434          if(cfra->resources.choice.ssb)
8435          {
8436             ssbResource = cfra->resources.choice.ssb;
8437
8438             /* CFRA SSB resource list */
8439             if(ssbResource->ssb_ResourceList.list.array)
8440             {
8441                for(listIdx = 0; listIdx < ssbResource->ssb_ResourceList.list.count; listIdx++)
8442                {
8443                   DU_FREE(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
8444                }
8445                DU_FREE(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
8446             }
8447             DU_FREE(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
8448          }
8449          DU_FREE(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
8450       }
8451       DU_FREE(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
8452    }
8453 }
8454
8455 /*******************************************************************
8456  *
8457  * @brief Frees reconfiguration with sync in SP cell config
8458  *
8459  * @details
8460  *
8461  *    Function : FreeRecfgWithSync
8462  *
8463  *    Functionality: Fress reconfiguration with sync in SP cell config
8464  *
8465  * @params[in] Pointer to ReconfigurationWithSync_t
8466  *
8467  * @return void
8468  *
8469  * ****************************************************************/
8470 void FreeRecfgWithSync(ReconfigurationWithSync_t *recfgWithSync)
8471 {
8472    /* Free SP Cell config common */
8473    if(recfgWithSync->spCellConfigCommon)
8474    {
8475       FreeSpCellConfigCommon(recfgWithSync->spCellConfigCommon);
8476       DU_FREE(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
8477    }
8478
8479    /* Free Dedicated RACH configuration */
8480    if(recfgWithSync->rach_ConfigDedicated)
8481    {
8482       FreeRachConfigDedicated(recfgWithSync->rach_ConfigDedicated);
8483       DU_FREE(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
8484    }
8485 }
8486
8487 /*******************************************************************
8488  *
8489  * @brief Frees emmory allocated for DUToCURRCContainer 
8490  *
8491  * @details
8492  *
8493  *    Function : FreeMemDuToCuRrcCont
8494  *
8495  *    Functionality: Deallocating memory of DuToCuRrcContainer
8496  *
8497  * @params[in] DuToCuRRCContainer, DuToCuRRCContainer
8498  *
8499  * @return ROK     - success
8500  *         RFAILED - failure
8501  *
8502  * ****************************************************************/
8503 uint8_t FreeMemDuToCuRrcCont(CellGroupConfigRrc_t *cellGrpCfg)
8504 {
8505    uint8_t idx=0;
8506    SpCellConfig_t *spCellCfg=NULLP;
8507    ServingCellConfig_t *srvCellCfg=NULLP;
8508    BWP_DownlinkDedicated_t *dlBwp=NULLP;
8509    MAC_CellGroupConfig_t *macCellGrpCfg=NULLP;
8510    PhysicalCellGroupConfig_t *phyCellGrpCfg=NULLP;
8511    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList=NULLP;
8512    struct RLC_Config *rlcConfig=NULLP;
8513    struct LogicalChannelConfig *macLcConfig=NULLP;
8514    struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg=NULLP;
8515    struct SchedulingRequestConfig *schedulingRequestConfig=NULLP;
8516    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList=NULLP;
8517    struct TAG_Config *tagConfig=NULLP;
8518    struct TAG_Config__tag_ToAddModList *tagList=NULLP;
8519    struct MAC_CellGroupConfig__phr_Config *phrConfig=NULLP;
8520    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg=NULLP;
8521
8522    rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
8523    if(rlcBearerList)
8524    {
8525       if(rlcBearerList->list.array)
8526       {
8527          for(idx=0; idx<rlcBearerList->list.count; idx++)
8528          {
8529             if(rlcBearerList->list.array[idx])
8530             {  
8531                rlcConfig   = rlcBearerList->list.array[idx]->rlc_Config;
8532                macLcConfig = rlcBearerList->list.array[idx]->mac_LogicalChannelConfig;
8533                if(rlcConfig)
8534                {
8535                   switch(rlcConfig->present)
8536                   {
8537                      case RLC_Config_PR_NOTHING:
8538                         break;
8539
8540                      case RLC_Config_PR_am:
8541                         {
8542                            if(rlcConfig->choice.am)
8543                            {
8544                               DU_FREE(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
8545                               DU_FREE(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
8546                               DU_FREE(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
8547                            }
8548                            break;
8549                         }
8550                      case RLC_Config_PR_um_Bi_Directional:
8551                         {
8552                            if(rlcConfig->choice.um_Bi_Directional)
8553                            {
8554                               DU_FREE(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t)); 
8555                               DU_FREE(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8556                               DU_FREE(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
8557                            }
8558                            break;
8559                         }
8560                      case RLC_Config_PR_um_Uni_Directional_UL:
8561                         {
8562                            if(rlcConfig->choice.um_Uni_Directional_UL)
8563                            {
8564                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8565                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
8566                            }
8567                            break;
8568                         }
8569                      case RLC_Config_PR_um_Uni_Directional_DL:
8570                         {
8571                            if(rlcConfig->choice.um_Uni_Directional_DL )
8572                            {
8573                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8574                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
8575                            }
8576                            break;
8577                         }
8578                   }     
8579                   DU_FREE(rlcConfig, sizeof(struct RLC_Config));
8580                }
8581                DU_FREE(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
8582                if(macLcConfig)
8583                {
8584                   if(macLcConfig->ul_SpecificParameters)
8585                   {
8586                      DU_FREE(macLcConfig->ul_SpecificParameters->schedulingRequestID,   sizeof(SchedulingRequestId_t));
8587                      DU_FREE(macLcConfig->ul_SpecificParameters->logicalChannelGroup,   sizeof(long));
8588                      DU_FREE(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
8589                   }
8590                   DU_FREE(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
8591                }
8592                DU_FREE(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
8593             }   
8594          }
8595          DU_FREE(rlcBearerList->list.array, rlcBearerList->list.size);
8596       }
8597       DU_FREE(cellGrpCfg->rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8598    }
8599
8600    macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
8601    if(macCellGrpCfg)
8602    {
8603       drxCfg = macCellGrpCfg->drx_ConfigRrc;
8604
8605       if(drxCfg)
8606       {
8607           switch(drxCfg->present)
8608           {
8609             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
8610                break;
8611             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
8612             {
8613                if(drxCfg->choice.setup)
8614                {
8615                   DU_FREE(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));  
8616                   DU_FREE(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
8617                }
8618             }
8619             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
8620                break;
8621           }
8622           DU_FREE(drxCfg, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
8623       }
8624       schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig; 
8625       if(schedulingRequestConfig)
8626       {
8627          schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
8628          if(schReqList)
8629          {
8630             if(schReqList->list.array)
8631             {
8632                for(idx=0;idx<schReqList->list.count; idx++)
8633                {
8634                   if(schReqList->list.array[idx])
8635                   {
8636                      DU_FREE(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
8637                      DU_FREE(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
8638                   }
8639                }
8640                DU_FREE(schReqList->list.array, schReqList->list.size);
8641             }
8642             DU_FREE(schedulingRequestConfig->schedulingRequestToAddModList,\
8643                   sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));    }
8644             DU_FREE(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
8645       }
8646       if(macCellGrpCfg->bsr_Config)
8647       {
8648          DU_FREE(macCellGrpCfg->bsr_Config->logicalChannelSR_DelayTimer, sizeof(long));
8649          DU_FREE(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
8650       }
8651       tagConfig = macCellGrpCfg->tag_Config;
8652       if(tagConfig)
8653       {
8654          tagList = tagConfig->tag_ToAddModList;
8655          if(tagList)
8656          {
8657             if(tagList->list.array)
8658             {
8659                for(idx=0; idx<tagList->list.count; idx++)
8660                {
8661                   DU_FREE(tagList->list.array[idx], sizeof(struct TAG));
8662                }
8663                DU_FREE(tagList->list.array, tagList->list.size);
8664             }
8665             DU_FREE(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
8666          }
8667          DU_FREE(tagConfig, sizeof(struct TAG_Config));
8668       }
8669
8670       phrConfig = macCellGrpCfg->phr_Config;
8671       if(phrConfig)
8672       {
8673          DU_FREE(phrConfig->choice.setup, sizeof(struct PHR_Config));
8674          DU_FREE(phrConfig, sizeof(struct MAC_CellGroupConfig__phr_Config));
8675       }
8676
8677       DU_FREE(macCellGrpCfg, sizeof(MAC_CellGroupConfig_t));
8678    }
8679
8680    phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
8681    if(phyCellGrpCfg)
8682    {
8683       DU_FREE(phyCellGrpCfg->p_NR_FR1, sizeof(long));
8684       DU_FREE(phyCellGrpCfg, sizeof(PhysicalCellGroupConfig_t));
8685    }
8686
8687    spCellCfg = cellGrpCfg->spCellConfig;
8688    if(spCellCfg)
8689    {
8690       /* Free serving cell index */
8691       DU_FREE(spCellCfg->servCellIndex, sizeof(long));
8692
8693       /* Free Reconfiguration with sync */
8694       if(spCellCfg->reconfigurationWithSync)
8695       {
8696          FreeRecfgWithSync(spCellCfg->reconfigurationWithSync);
8697          DU_FREE(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
8698       }
8699
8700       /* Free rlmInSyncOutOfSyncThreshold */
8701       DU_FREE(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
8702
8703       /* Free SP Cell config dedicated */
8704       if(spCellCfg->spCellConfigDedicated)
8705       {
8706          srvCellCfg = spCellCfg->spCellConfigDedicated;
8707
8708          /* Free TDD UL-DL config dedicated */
8709          DU_FREE(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
8710
8711          /* Free Initial Downlink BWP */
8712          if(srvCellCfg->initialDownlinkBWP)
8713          {
8714             dlBwp = srvCellCfg->initialDownlinkBWP;
8715
8716             /* Free DL BWP PDCCH Config */
8717             if(dlBwp->pdcch_Config)
8718             {
8719                FreeBWPDlDedPdcchCfg(dlBwp);
8720                DU_FREE(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
8721             }
8722
8723             /* Free DL BWP PDSCH config */
8724             if(dlBwp->pdsch_Config)
8725             {
8726                FreeBWPDlDedPdschCfg(dlBwp);
8727                DU_FREE(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
8728             }
8729             DU_FREE(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
8730          }
8731
8732          /* Free First Active Downlink BWP */
8733          DU_FREE(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
8734
8735          /* Free Default downlink BWP */
8736          DU_FREE(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
8737
8738          /* Free Uplink config */
8739          if(srvCellCfg->uplinkConfig)
8740          {
8741             FreeinitialUplinkBWP(srvCellCfg->uplinkConfig);
8742             DU_FREE(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));  
8743          }
8744
8745          /* Free PDSCH serving cell config */
8746          if(srvCellCfg->pdsch_ServingCellConfig)
8747          {
8748             pdschCfg= srvCellCfg->pdsch_ServingCellConfig;
8749             if(pdschCfg->choice.setup)
8750             {
8751                DU_FREE(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH,sizeof(long));
8752                DU_FREE(pdschCfg->choice.setup, sizeof(struct PDSCH_ServingCellConfig));
8753             }
8754             DU_FREE(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct ServingCellConfig__pdsch_ServingCellConfig));
8755          }
8756
8757          DU_FREE(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
8758       }
8759       DU_FREE(spCellCfg,sizeof(SpCellConfig_t));
8760    }
8761    return ROK;
8762 }
8763
8764 /*******************************************************************
8765  *
8766  * @brief Builds CellGroupConfigRrc for DU To CU RRC Container 
8767  *
8768  * @details
8769  *
8770  *    Function : BuildCellGroupConfigRrc
8771  *
8772  *    Functionality: Builds and copied Cell group config buffer into 
8773  *       DuToCuRrcContainer
8774  *
8775  * @params[in] idx, index in F1AP msg
8776  *             DuToCuRRCContainer, DuToCuRRCContainer
8777  *
8778  * @return ROK     - success
8779  *         RFAILED - failure
8780  *
8781  * ****************************************************************/
8782 uint8_t BuildCellGroupConfigRrc(DuUeCb *ueCb, OCTET_STRING_t *duToCuRrcContainer)
8783 {
8784    uint8_t  ret = ROK;
8785    CellGroupConfigRrc_t  cellGrpCfg;
8786    asn_enc_rval_t        encRetVal;
8787    memset(&cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
8788    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8789
8790    while(true)
8791    {
8792       cellGrpCfg.cellGroupId = CELL_GRP_ID;
8793
8794       cellGrpCfg.rlc_BearerToAddModList = NULLP;
8795       DU_ALLOC(cellGrpCfg.rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8796       if(!cellGrpCfg.rlc_BearerToAddModList)
8797       {
8798          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8799          ret = RFAILED;
8800          break;
8801       }
8802       if(BuildRlcBearerToAddModList(ueCb, cellGrpCfg.rlc_BearerToAddModList) != ROK)
8803       {
8804          DU_LOG("\nERROR  -->  F1AP : BuildRlcBearerToAddModList failed");
8805          ret = RFAILED;
8806          break;
8807       }
8808
8809       cellGrpCfg.rlc_BearerToReleaseList = NULLP;
8810       cellGrpCfg.mac_CellGroupConfig = NULLP;
8811       DU_ALLOC(cellGrpCfg.mac_CellGroupConfig, sizeof(MAC_CellGroupConfig_t));
8812       if(!cellGrpCfg.mac_CellGroupConfig)
8813       {
8814          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8815          ret = RFAILED;
8816          break;
8817       }
8818       if(BuildMacCellGrpCfg(ueCb, cellGrpCfg.mac_CellGroupConfig) != ROK)
8819       {
8820          DU_LOG("\nERROR  -->  F1AP : BuildMacCellGrpCfg failed");
8821          ret = RFAILED;
8822          break;
8823       }
8824
8825       cellGrpCfg.physicalCellGroupConfig = NULLP;
8826       DU_ALLOC(cellGrpCfg.physicalCellGroupConfig, sizeof(PhysicalCellGroupConfig_t));
8827       if(!cellGrpCfg.physicalCellGroupConfig)
8828       {
8829          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8830          ret = RFAILED;
8831          break;
8832       }
8833       if(BuildPhyCellGrpCfg(ueCb, cellGrpCfg.physicalCellGroupConfig) != ROK)
8834       {
8835          DU_LOG("\nERROR  -->  F1AP : BuildPhyCellGrpCfg failed");
8836          ret = RFAILED;
8837          break;
8838       }
8839
8840       cellGrpCfg.spCellConfig = NULLP;
8841       DU_ALLOC(cellGrpCfg.spCellConfig, sizeof(SpCellConfig_t));
8842       if(!cellGrpCfg.spCellConfig)
8843       {
8844          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8845          ret = RFAILED;
8846          break;
8847       }
8848       if(BuildSpCellCfg(ueCb, cellGrpCfg.spCellConfig) != ROK)
8849       {
8850          DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfg failed");
8851          ret = RFAILED;
8852          break;
8853       }
8854
8855       cellGrpCfg.sCellToAddModList = NULLP;
8856       cellGrpCfg.sCellToReleaseList = NULLP;
8857       cellGrpCfg.ext1 = NULLP;
8858
8859       /* encode cellGrpCfg into duToCuRrcContainer */
8860       xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, &cellGrpCfg);
8861       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8862       encBufSize = 0;
8863       encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, &cellGrpCfg, PrepFinalEncBuf, encBuf);
8864       /* Encode results */
8865       if(encRetVal.encoded == ENCODE_FAIL)
8866       {
8867          DU_LOG( "\nERROR  --> F1AP : Could not encode DuToCuRrcContainer (at %s)\n",\
8868                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
8869          ret = RFAILED;
8870          break;
8871       }
8872       else
8873       {
8874          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DuToCuRrcContainer\n");
8875 #ifdef DEBUG_ASN_PRINT
8876          for(int i=0; i< encBufSize; i++)
8877          {
8878             printf("%x",encBuf[i]);
8879          }
8880 #endif
8881       }
8882
8883       duToCuRrcContainer->size = encBufSize;
8884       DU_ALLOC(duToCuRrcContainer->buf, duToCuRrcContainer->size);
8885       if(!duToCuRrcContainer->buf)
8886       {
8887          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDuToCuRrcContainer");
8888          ret = RFAILED;
8889          break;
8890       }
8891       if(ret == ROK)
8892       {
8893          memcpy(duToCuRrcContainer->buf, encBuf, duToCuRrcContainer->size);
8894       }
8895       break;
8896    }
8897    FreeMemDuToCuRrcCont(&cellGrpCfg);
8898    return ret;
8899 }
8900
8901 /*******************************************************************
8902  *
8903  * @brief Free memory allocated in InitialULRRCMessage
8904  *
8905  * @details
8906  *
8907  *    Function : freeInitUlRrcMsgTransfer
8908  *
8909  *    Functionality: Free memory allocated in InitialULRRCMessage
8910  *
8911  * @params[in]F1AP_PDU_t  *f1apMsg)
8912  *
8913  * @return ROK     - success
8914  *         RFAILED - failure
8915  *
8916  * ****************************************************************/
8917
8918 uint8_t freeInitUlRrcMsgTransfer(F1AP_PDU_t  *f1apMsg)
8919 {
8920    uint8_t ieIdx, arrIdx;
8921    InitialULRRCMessageTransfer_t *initULRRCMsg=NULLP;
8922
8923    if(f1apMsg)
8924    {
8925       if(f1apMsg->choice.initiatingMessage)
8926       {
8927          initULRRCMsg = &f1apMsg->choice.initiatingMessage->value.\
8928             choice.InitialULRRCMessageTransfer;
8929          if(initULRRCMsg->protocolIEs.list.array)
8930          {
8931             for(ieIdx = 0; ieIdx < initULRRCMsg->protocolIEs.list.count; ieIdx++)
8932             {
8933                switch(initULRRCMsg->protocolIEs.list.array[ieIdx]->id)
8934                {
8935                   case ProtocolIE_ID_id_NRCGI:
8936                   {
8937                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf)
8938                      {
8939                         if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf)
8940                         {
8941                            DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf,\
8942                            initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.size);
8943                         }
8944                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf,\
8945                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.size);
8946                      }
8947                      break;
8948                   }
8949                   case ProtocolIE_ID_id_RRCContainer:
8950                   {
8951                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
8952                      {
8953                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,\
8954                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
8955                      }
8956                      break;
8957                   }
8958                   case ProtocolIE_ID_id_DUtoCURRCContainer:
8959                   {
8960                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf)
8961                      {
8962                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf,
8963                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.size);
8964                      }
8965                      break;
8966                   }
8967                   default:
8968                      break;
8969                }
8970              }
8971              for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
8972              {
8973                 if(initULRRCMsg->protocolIEs.list.array[arrIdx])
8974                 {
8975                    DU_FREE(initULRRCMsg->protocolIEs.list.array[arrIdx],\
8976                       sizeof(InitialULRRCMessageTransferIEs_t));
8977                 }
8978              }
8979              DU_FREE(initULRRCMsg->protocolIEs.list.array, initULRRCMsg->protocolIEs.list.size);
8980           }
8981          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8982       }
8983       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
8984    }
8985    else
8986    {
8987       DU_LOG("\nERROR  -->  DU_APP : Recevied F1ap Pdu is null at freeInitUlRrcMsgTransfer()");
8988       return RFAILED;
8989    }
8990    return ROK;
8991 }
8992
8993 /*******************************************************************
8994  *
8995  * @brief Builds and sends the InitialULRRCMessage 
8996  *
8997  * @details
8998  *
8999  *    Function : BuildAndSendInitialRrcMsgTransfer 
9000  *
9001  *    Functionality: Constructs the Initial UL RRC Message Transfer and sends
9002  *                   it to the CU through SCTP.
9003  *
9004  * @params[in] 
9005  *
9006  * @return ROK     - success
9007  *         RFAILED - failure
9008  *
9009  * ****************************************************************/
9010 uint8_t BuildAndSendInitialRrcMsgTransfer(uint32_t gnbDuUeF1apId, uint16_t crnti,
9011       uint16_t rrcContSize, uint8_t *rrcContainer)
9012 {
9013    uint8_t   ret;
9014    uint8_t   elementCnt;
9015    uint8_t   ieIdx, cellIdx, ueIdx;
9016    DuUeCb    *duUeCb = NULLP;
9017    asn_enc_rval_t  encRetVal;
9018    F1AP_PDU_t  *f1apMsg = NULLP;
9019    InitialULRRCMessageTransfer_t *initULRRCMsg = NULLP;
9020    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
9021
9022    while(true)
9023    {
9024       DU_LOG("\n INFO   -->  F1AP : Building RRC Setup Request\n");
9025       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
9026       if(f1apMsg == NULLP)
9027       {
9028          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
9029          break;
9030       }
9031       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
9032       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
9033       if(f1apMsg->choice.initiatingMessage == NULLP)
9034       {
9035          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU failed");
9036          break;
9037       }
9038       f1apMsg->choice.initiatingMessage->procedureCode =\
9039                                                         ProcedureCode_id_InitialULRRCMessageTransfer;
9040       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
9041       f1apMsg->choice.initiatingMessage->value.present = \
9042                                                          InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
9043       initULRRCMsg =\
9044                     &f1apMsg->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
9045       elementCnt = 5;
9046       initULRRCMsg->protocolIEs.list.count = elementCnt;
9047       initULRRCMsg->protocolIEs.list.size = \
9048                                             elementCnt * sizeof(InitialULRRCMessageTransferIEs_t *);
9049       /* Initialize the F1Setup members */
9050       DU_ALLOC(initULRRCMsg->protocolIEs.list.array,initULRRCMsg->protocolIEs.list.size);
9051       if(initULRRCMsg->protocolIEs.list.array == NULLP)
9052       {
9053          DU_LOG(" ERROR  -->  F1AP : Memory allocation for\
9054                RRCSetupRequestMessageTransferIEs failed");
9055          break;
9056       }
9057       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
9058       {
9059          DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx],\
9060                sizeof(InitialULRRCMessageTransferIEs_t));
9061          if(initULRRCMsg->protocolIEs.list.array[ieIdx] == NULLP)
9062          {
9063             break;
9064          }
9065       }
9066       ieIdx = 0;
9067       /*GNB DU UE F1AP ID*/
9068       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9069                                                         ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
9070       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  = Criticality_reject;
9071       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
9072                                                                   InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
9073       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
9074
9075
9076       /*NRCGI*/
9077       ieIdx++;
9078       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9079                                                         ProtocolIE_ID_id_NRCGI;
9080       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  =Criticality_reject;
9081       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
9082                                                                   InitialULRRCMessageTransferIEs__value_PR_NRCGI;
9083
9084       ret =\
9085            BuildNrcgi(&initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
9086       if(ret!=ROK)
9087       {
9088          break;
9089       }
9090
9091       /*CRNTI*/
9092       ieIdx++;
9093       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9094                                                         ProtocolIE_ID_id_C_RNTI;
9095       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9096       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9097                                                                  InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
9098       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.C_RNTI = crnti;
9099
9100       /*RRCContainer*/
9101       ieIdx++;
9102       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9103                                                         ProtocolIE_ID_id_RRCContainer;
9104       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9105       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9106                                                                  InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
9107
9108       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size = rrcContSize;
9109       DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,
9110             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size)
9111       if(!initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
9112       {
9113          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRCSetupRequestMessageTransferIEs failed");
9114          break;
9115       
9116       }
9117       memcpy(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, rrcContainer,
9118             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
9119
9120
9121       /*DUtoCURRCContainer*/
9122       ieIdx++;
9123       initULRRCMsg->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCContainer;
9124       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9125       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9126                                                                  InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
9127
9128       for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
9129       {
9130          for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
9131          {
9132             if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
9133                   (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti == crnti))
9134             {
9135                duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
9136             }
9137          }
9138       }
9139
9140       ret = BuildCellGroupConfigRrc(duUeCb, &initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer);
9141       if(ret != ROK)
9142       {
9143          break;
9144       }
9145
9146       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
9147
9148       /* Encode the Intial UL RRC Message transfer as APER */
9149       memset(encBuf, 0, ENC_BUF_MAX_LEN);
9150       encBufSize = 0;
9151       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
9152       /* Encode results */
9153       if(encRetVal.encoded == ENCODE_FAIL)
9154       {
9155          DU_LOG( "\nERROR  --> F1AP : Could not encode Initial UL RRC Message Transfer\
9156                structure (at %s)\n",encRetVal.failed_type ? \
9157                encRetVal.failed_type->name : "unknown");
9158          ret = RFAILED;
9159          break;
9160       }
9161       else
9162       {
9163
9164          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Initial UL RRC\
9165                Message transfer\n");
9166 #ifdef DEBUG_ASN_PRINT
9167          for(int i=0; i< encBufSize; i++)
9168          {
9169             printf("%x",encBuf[i]);
9170          }
9171 #endif
9172       }
9173       /* Sending  msg  */
9174       if(sendF1APMsg() != ROK)
9175       {
9176          DU_LOG("\nERROR  -->  F1AP : Sending Initial UL RRC Message Transfer Failed");
9177          ret = RFAILED;
9178          break;
9179       }
9180       break;
9181    }
9182    freeInitUlRrcMsgTransfer(f1apMsg);
9183    return ret;
9184 }/* End of BuildAndSendInitialRrcMsgTransfer*/
9185
9186 /*****  UE SETUP REQUEST *****/
9187
9188 /******************************************************************
9189 *
9190 * @brief Function to delete the RLC Lc cfg from UE APP DB
9191 *
9192 * @details
9193 *
9194 *  Function : freeRlcLcCfg
9195 *
9196 *  Functionality: Function to delete the RLC Lc cfg from UE APP DB
9197 *
9198 *
9199  *****************************************************************/
9200
9201 void freeRlcLcCfg(RlcBearerCfg *lcCfg)
9202 {
9203    switch(lcCfg->rlcMode)
9204    {
9205       case RLC_AM :
9206          {
9207             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
9208             break;
9209          }
9210       case RLC_UM_BI_DIRECTIONAL :
9211          {
9212             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
9213             break;
9214          }
9215       case RLC_UM_UNI_DIRECTIONAL_UL :
9216          {
9217             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
9218             break;
9219          }
9220       case RLC_UM_UNI_DIRECTIONAL_DL :
9221          {
9222             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
9223             break;
9224          }
9225       default:
9226          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at freeRlcLcCfg()", lcCfg->rlcMode);
9227          break;
9228    }
9229    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
9230 }
9231
9232 /*******************************************************************
9233  *
9234  * @brief Function to free MacLcCfg
9235  *
9236  * @details
9237  *
9238  *    Function : freeMacLcCfg
9239  *
9240  *    Functionality: Function to free MacLcCfg
9241  *
9242  * @params[in] LcCfg *lcCfg,
9243  * @return void
9244  *
9245  * ****************************************************************/
9246
9247 void freeMacLcCfg(LcCfg *lcCfg)
9248 {
9249     /* Deleting DRBQOS */
9250    if(lcCfg->drbQos)
9251    {
9252       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
9253    }
9254    /* Deleting SNSSAI */
9255    if(lcCfg->snssai)
9256    {
9257       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
9258    }
9259 }
9260 /*******************************************************************
9261  *
9262  * @brief Free UE NR Capability received in UE Context setup request
9263  *
9264  * @details
9265  *
9266  *    Function : freeAperDecodeUeNrCapability
9267  *
9268  *    Functionality:  
9269  *       Free UE NR Capability received in UE Context setup request
9270  *
9271  * @params[in] 
9272  * @return ROK     - success
9273  *         RFAILED - failure
9274  *
9275  * ****************************************************************/
9276 void freeAperDecodeUeNrCapability(void *ueNrCapability)
9277 {
9278    uint8_t arrIdx =0;
9279    FeatureSets_t *featureSets =NULLP;
9280    UE_NR_Capability_t *ueNrCap = (UE_NR_Capability_t *)ueNrCapability;
9281
9282    if(ueNrCap->rf_Parameters.supportedBandListNR.list.array)
9283    {
9284       for(arrIdx = 0; arrIdx < ueNrCap->rf_Parameters.supportedBandListNR.list.count; arrIdx++)
9285       {
9286          if(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx])
9287             free(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx]);
9288       }
9289       free(ueNrCap->rf_Parameters.supportedBandListNR.list.array);
9290    }
9291
9292    if(ueNrCap->featureSets)
9293    {
9294       featureSets = ueNrCap->featureSets;
9295       if(featureSets->featureSetsDownlinkPerCC)
9296       {
9297          if(featureSets->featureSetsDownlinkPerCC->list.array)
9298          {
9299             for(arrIdx = 0; arrIdx < featureSets->featureSetsDownlinkPerCC->list.count; arrIdx++)
9300             {
9301                if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx])
9302                {
9303                   if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL)
9304                      free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL);
9305                   free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]);
9306                }
9307             }
9308             free(featureSets->featureSetsDownlinkPerCC->list.array);
9309          }
9310          free(featureSets->featureSetsDownlinkPerCC);
9311       }
9312       if(featureSets->featureSetsUplinkPerCC)
9313       {
9314          if(featureSets->featureSetsUplinkPerCC->list.array)
9315          {
9316             for(arrIdx = 0; arrIdx < featureSets->featureSetsUplinkPerCC->list.count; arrIdx++)
9317             {
9318                if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx])
9319                {
9320                   if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL)
9321                      free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL);
9322                   free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]);
9323                }
9324             }
9325             free(featureSets->featureSetsUplinkPerCC->list.array);
9326          }
9327          free(featureSets->featureSetsUplinkPerCC);
9328       }
9329       free(ueNrCap->featureSets);
9330    }   
9331 }
9332
9333 /*******************************************************************
9334 *
9335 * @brief Function to free PdcchSearchSpcToAddModList
9336          where memory allocated by aper_decoder
9337 *
9338 * @details
9339 *
9340 *    Function : freeAperDecodePdcchSearchSpcToAddModList 
9341 *
9342 *    Functionality: Function to free PdcchSearchSpcToAddModList
9343 *
9344 * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
9345 * @return void
9346 *
9347 * ****************************************************************/
9348
9349 void freeAperDecodePdcchSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
9350 {
9351    uint8_t searchSpcArrIdx=0;
9352    uint8_t searchSpcArrIdx1=0;
9353    struct  SearchSpace *searchSpc=NULLP;
9354
9355
9356    if(searchSpcList->list.array)
9357    {
9358       if(searchSpcList->list.array[searchSpcArrIdx1])
9359       {
9360          searchSpc = searchSpcList->list.array[searchSpcArrIdx1];
9361          if(searchSpc->controlResourceSetId)
9362          {
9363             if(searchSpc->monitoringSlotPeriodicityAndOffset)
9364             {
9365                if(searchSpc->monitoringSymbolsWithinSlot)
9366                {
9367                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
9368                   {
9369                      if(searchSpc->nrofCandidates)
9370                      {
9371                         if(searchSpc->searchSpaceType)
9372                         {
9373                            free(searchSpc->searchSpaceType->choice.ue_Specific);
9374                            free(searchSpc->searchSpaceType);
9375                         }
9376                         free(searchSpc->nrofCandidates);
9377                      }
9378                      free(searchSpc->monitoringSymbolsWithinSlot->buf);
9379                   }
9380                   free(searchSpc->monitoringSymbolsWithinSlot);
9381                }
9382                free(searchSpc->monitoringSlotPeriodicityAndOffset);
9383             }
9384             free(searchSpc->controlResourceSetId);
9385          }
9386       }
9387       for(searchSpcArrIdx = 0; searchSpcArrIdx < searchSpcList->list.count; searchSpcArrIdx++)
9388       {
9389          free(searchSpcList->list.array[searchSpcArrIdx]);
9390       }
9391       free(searchSpcList->list.array);
9392    }
9393 }
9394 /*******************************************************************
9395 *
9396 * @brief Function for free part for the memory allocated by aper_decoder
9397
9398 * @details
9399 *
9400 *    Function : freeAperDecodeBWPDlDedPdcchConfig
9401 *
9402 *    Functionality: Function to free BWPDlDedPdcchConfig
9403 *
9404 * @params[in] 
9405 * @return void
9406 *
9407 * ****************************************************************/
9408
9409
9410 void freeAperDecodeBWPDlDedPdcchConfig(BWP_DownlinkDedicated_t *dlBwp)
9411 {
9412    uint8_t arrIdx1=0;
9413    uint8_t arrIdx2=0;
9414    struct PDCCH_Config *pdcchCfg=NULLP;
9415    struct ControlResourceSet *controlRSet=NULLP;
9416    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
9417    
9418    if(dlBwp->pdcch_Config->choice.setup)
9419    {
9420       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
9421       if(pdcchCfg->controlResourceSetToAddModList)
9422       {
9423          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
9424          if(controlRSetList->list.array)
9425          {
9426             controlRSet = controlRSetList->list.array[arrIdx2];
9427             if(controlRSet)
9428             {
9429                if(controlRSet->frequencyDomainResources.buf)
9430                {
9431                   if(controlRSet->pdcch_DMRS_ScramblingID)
9432                   {
9433                      if(pdcchCfg->searchSpacesToAddModList)
9434                      {
9435                         freeAperDecodePdcchSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
9436                         free(pdcchCfg->searchSpacesToAddModList);
9437                      }
9438                      free(controlRSet->pdcch_DMRS_ScramblingID);
9439                   }
9440                   free(controlRSet->frequencyDomainResources.buf);
9441                }
9442             }
9443             for(arrIdx1 = 0; arrIdx1 <controlRSetList->list.count; arrIdx1++)
9444             {
9445                free(controlRSetList->list.array[arrIdx1]);
9446             }
9447             free(controlRSetList->list.array);
9448          }
9449          free(pdcchCfg->controlResourceSetToAddModList);
9450       }
9451       free(dlBwp->pdcch_Config->choice.setup);
9452    }
9453 }
9454 /*******************************************************************
9455 *
9456 * @brief Function to free PdschTimeDomAllocationList 
9457 *     where the memory allocated by aper_decoder
9458
9459 * @details
9460 *
9461 *    Function : freeAperDecodePdschTimeDomAllocationList
9462 *
9463 *    Functionality: Function to free PdschTimeDomAllocationList
9464 *
9465 * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList 
9466 * @return void
9467 *
9468 * ****************************************************************/
9469
9470
9471 void freeAperDecodePdschTimeDomAllocationList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
9472 {
9473    uint8_t arrIdx=0;
9474
9475    if(timeDomAllocList->choice.setup)
9476    {
9477       if(timeDomAllocList->choice.setup->list.array)
9478       {
9479          for(arrIdx = 0; arrIdx <timeDomAllocList->choice.setup->list.count ; arrIdx++)
9480          {
9481             free(timeDomAllocList->choice.setup->list.array[arrIdx]);
9482          }
9483          free(timeDomAllocList->choice.setup->list.array);
9484       }
9485       free(timeDomAllocList->choice.setup);
9486    }
9487 }
9488
9489 /*******************************************************************
9490 *
9491 * @brief Function to free BWPDlDedPdschConfig 
9492 *        where the memory allocated by aper_decoder
9493 *  
9494 * @details
9495 *
9496 *    Function : freeAperDecodeBWPDlDedPdschConfig 
9497 *
9498 *    Functionality: Function to free BWPDlDedPdschConfig 
9499 *
9500 * @params[in] BWP_DownlinkDedicated_t *dlBwp 
9501 * @return void
9502 *
9503 * ****************************************************************/
9504
9505
9506 void freeAperDecodeBWPDlDedPdschConfig(BWP_DownlinkDedicated_t *dlBwp)
9507 {
9508    struct PDSCH_Config *pdschCfg=NULLP;
9509    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
9510    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
9511    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
9512
9513    if(dlBwp->pdsch_Config->choice.setup)
9514    {
9515       pdschCfg=dlBwp->pdsch_Config->choice.setup;
9516       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
9517       {
9518          if(pdschCfg->pdsch_TimeDomainAllocationList)
9519          {
9520             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
9521             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
9522             {
9523                prbBndlType=&pdschCfg->prb_BundlingType;
9524                free(prbBndlType->choice.staticBundling);
9525                free(pdschCfg->maxNrofCodeWordsScheduledByDCI);
9526             }
9527             freeAperDecodePdschTimeDomAllocationList(timeDomAllocList);
9528             free(pdschCfg->pdsch_TimeDomainAllocationList);
9529          }
9530          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
9531          if(dmrsDlCfg->choice.setup)
9532          {
9533             free(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition);
9534             free(dmrsDlCfg->choice.setup);
9535          }
9536          free(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA);
9537       }
9538       free(dlBwp->pdsch_Config->choice.setup);
9539    }
9540 }
9541 /*******************************************************************
9542 *
9543 * @brief Function to free PuschTimeDomAllocListCfg
9544                  where the memory allocated by aper_decoder
9545 *
9546 * @details
9547 *
9548 *    Function : freeAperDecodePuschTimeDomAllocListCfg
9549 *
9550 *    Functionality: Function to free PuschTimeDomAllocListCfg
9551 *
9552 * @params[in] PUSCH_Config_t *puschCfg 
9553 * @return void
9554 *
9555 * ****************************************************************/
9556
9557
9558 void freeAperDecodePuschTimeDomAllocListCfg(PUSCH_Config_t *puschCfg)
9559 {
9560    uint8_t arrIdx=0;
9561    uint8_t arrIdx1=0;
9562    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
9563
9564    if(puschCfg->pusch_TimeDomainAllocationList)
9565    {
9566       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
9567       if(timeDomAllocList_t->choice.setup)
9568       {
9569          if(timeDomAllocList_t->choice.setup->list.array)
9570          {
9571             free(timeDomAllocList_t->choice.setup->list.array[arrIdx1]->k2);
9572             for(arrIdx = 0; arrIdx<timeDomAllocList_t->choice.setup->list.count; arrIdx++)
9573             {
9574                free(timeDomAllocList_t->choice.setup->list.array[arrIdx]);
9575             }
9576             free(timeDomAllocList_t->choice.setup->list.array);
9577          }
9578          free(timeDomAllocList_t->choice.setup);
9579       }
9580       free(puschCfg->transformPrecoder);
9581       free(puschCfg->pusch_TimeDomainAllocationList);
9582    }
9583 }
9584 /*******************************************************************
9585 *
9586 * @brief Function to free InitialUlBWPConfig where memory allocated by aper_decoder
9587 *
9588 * @details
9589 *
9590 *    Function : freeAperDecodeInitialUlBWPConfig 
9591 *
9592 *    Functionality: Function to free InitialUlBWPConfig
9593 *
9594 * @params[in]  BWP_UplinkDedicated_t *ulBwp
9595 * @return void
9596 *
9597 * ****************************************************************/
9598
9599
9600 void freeAperDecodeInitialUlBWPConfig(BWP_UplinkDedicated_t *ulBwp)
9601 {
9602    uint8_t  rSetIdx =0;
9603    uint8_t  rsrcIdx =0;
9604    SRS_Config_t   *srsCfg = NULLP;
9605    PUSCH_Config_t *puschCfg = NULLP;
9606    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
9607    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
9608    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
9609    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
9610
9611    if(ulBwp->pusch_Config)
9612    {
9613       if(ulBwp->pusch_Config->choice.setup)
9614       {
9615          puschCfg=ulBwp->pusch_Config->choice.setup;
9616          if(puschCfg->dataScramblingIdentityPUSCH)
9617          {
9618             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
9619             {
9620                freeAperDecodePuschTimeDomAllocListCfg(puschCfg);
9621                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
9622                if(dmrsUlCfg->choice.setup)
9623                {
9624                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
9625                   {
9626                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
9627                      {
9628                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0);
9629                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled);
9630                      }
9631                      free(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition);
9632                   }
9633                   free(dmrsUlCfg->choice.setup);
9634                }
9635                free(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA);
9636             }
9637             free(puschCfg->dataScramblingIdentityPUSCH);
9638          }
9639          free(ulBwp->pusch_Config->choice.setup);
9640       }
9641       free(ulBwp->pusch_Config);
9642
9643       /* Free SRS-Config */
9644       if(ulBwp->srs_Config)
9645       {
9646          if(ulBwp->srs_Config->choice.setup)
9647          {
9648             srsCfg = ulBwp->srs_Config->choice.setup;
9649
9650             /* Free Resource Set to add/mod list */
9651             if(srsCfg->srs_ResourceSetToAddModList)
9652             {
9653                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
9654                if(rsrcSetList->list.array)
9655                {
9656                   rSetIdx = 0;
9657
9658                   /* Free SRS resource Id list in this SRS resource set */
9659                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
9660                   {
9661                      rsrcIdList =
9662                         rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
9663
9664                      if(rsrcIdList->list.array)
9665                      {
9666                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count;
9667                               rsrcIdx++)
9668                         {
9669                            free(rsrcIdList->list.array[rsrcIdx]);
9670                         }
9671                         free(rsrcIdList->list.array);
9672                      }
9673                      free(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList);
9674                   }
9675
9676                   /* Free resource type info for this SRS resource set */
9677
9678                   free(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic);
9679
9680                   /* Free memory for each resource set */
9681                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
9682                   {
9683                      free(rsrcSetList->list.array[rSetIdx]);
9684                   }
9685                   free(rsrcSetList->list.array);
9686                }
9687                free(srsCfg->srs_ResourceSetToAddModList);
9688             }
9689
9690             /* Free resource to add/modd list */
9691             if(srsCfg->srs_ResourceToAddModList)
9692             {
9693                resourceList = srsCfg->srs_ResourceToAddModList;
9694                if(resourceList->list.array)
9695                {
9696                   rsrcIdx = 0;
9697
9698                   free(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2);
9699                   free(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic);
9700
9701                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
9702                   {
9703                      free(resourceList->list.array[rsrcIdx]);
9704                   }
9705                   free(resourceList->list.array);
9706                }
9707                free(srsCfg->srs_ResourceToAddModList);
9708             }
9709
9710             free(ulBwp->srs_Config->choice.setup);
9711          }
9712          free(ulBwp->srs_Config);
9713       }
9714    }
9715 }
9716 /*******************************************************************
9717 *
9718 * @brief Function to free initialUplinkBWPConfig where memory allocated by aper_decoder
9719 *
9720 * @details
9721 *
9722 *    Function : freeAperDecodeinitialUplinkBWPConfig
9723 *
9724 *    Functionality: Function to free initialUplinkBWPConfig
9725 *
9726 * @params[in] UplinkConfig_t *ulCfg 
9727 * @return void
9728 *
9729 * ****************************************************************/
9730
9731
9732 void freeAperDecodeinitialUplinkBWPConfig(UplinkConfig_t *ulCfg)
9733 {
9734    BWP_UplinkDedicated_t *ulBwp=NULLP;
9735    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
9736    
9737    if(ulCfg->initialUplinkBWP)
9738    {
9739       ulBwp=ulCfg->initialUplinkBWP;
9740       if(ulCfg->firstActiveUplinkBWP_Id)
9741       {
9742          if(ulCfg->pusch_ServingCellConfig)
9743          {
9744             puschCfg=ulCfg->pusch_ServingCellConfig;
9745             if(puschCfg->choice.setup)
9746             {
9747                if(puschCfg->choice.setup->ext1)
9748                {
9749                   free(puschCfg->choice.setup->ext1->processingType2Enabled);
9750                   free(puschCfg->choice.setup->ext1->maxMIMO_Layers);
9751                   free(puschCfg->choice.setup->ext1);
9752                }
9753                free(puschCfg->choice.setup);
9754             }
9755             free(ulCfg->pusch_ServingCellConfig);
9756          }
9757          free(ulCfg->firstActiveUplinkBWP_Id);
9758       }
9759       freeAperDecodeInitialUlBWPConfig(ulBwp);
9760       free(ulCfg->initialUplinkBWP);
9761    }
9762 }
9763
9764 /*******************************************************************
9765  *
9766  * @brief Function to free DuUeCfg
9767  *
9768  * @details
9769  *
9770  *    Function : freeDuUeCfg
9771  *
9772  *    Functionality: Function to free DuUeCfg
9773  *
9774  * @params[in] DuUeCfg *ueCfg
9775  * @return void
9776  *
9777  * ****************************************************************/
9778 void freeDuUeCfg(UeCtxtActionType actionType, DuUeCfg *ueCfg)
9779 {
9780    uint8_t lcIdx = 0;
9781    uint8_t arrIdx = 0;
9782    SpCellConfig_t *spCellCfg = NULLP;
9783    ServingCellConfig_t *srvCellCfg = NULLP;
9784    BWP_DownlinkDedicated_t *dlBwp = NULLP;
9785    MAC_CellGroupConfig_t *macCellGrpCfg = NULLP;
9786    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
9787    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList = NULLP;
9788    struct RLC_Config *rlcConfig = NULLP;
9789    struct LogicalChannelConfig *macLcConfig = NULLP;
9790    struct SchedulingRequestConfig *schedulingRequestConfig = NULLP;
9791    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList = NULLP;
9792    struct TAG_Config *tagConfig = NULLP;
9793    struct TAG_Config__tag_ToAddModList *tagList = NULLP;
9794    struct MAC_CellGroupConfig__phr_Config *phrConfig = NULLP;
9795    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg = NULLP;
9796    CellGroupConfigRrc_t *cellGrpCfg = ueCfg->cellGrpCfg;
9797   
9798    if(ueCfg->ueNrCapability)
9799    {
9800       freeAperDecodeUeNrCapability(ueCfg->ueNrCapability);
9801       DU_FREE(ueCfg->ueNrCapability, sizeof(UE_NR_Capability_t));
9802       ueCfg->ueNrCapability = NULLP;
9803    }
9804
9805    if(ueCfg->cellGrpCfg)
9806    {
9807       rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
9808       if(rlcBearerList)
9809       {
9810          if(rlcBearerList->list.array)
9811          {
9812             for(arrIdx=0; arrIdx<rlcBearerList->list.count; arrIdx++)
9813             {
9814                if(rlcBearerList->list.array[arrIdx])
9815                {
9816                   rlcConfig   = rlcBearerList->list.array[arrIdx]->rlc_Config;
9817                   macLcConfig = rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig;
9818
9819                   if(rlcBearerList->list.array[arrIdx]->servedRadioBearer)
9820                   {
9821                      free(rlcBearerList->list.array[arrIdx]->servedRadioBearer);
9822                   }
9823                   if(rlcConfig)
9824                   {
9825                      if(rlcConfig->choice.am)
9826                      {
9827                         free(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength);
9828                         free(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength);
9829                         free(rlcConfig->choice.am);
9830                      }
9831                      free(rlcBearerList->list.array[arrIdx]->rlc_Config);
9832                   }
9833                   if(macLcConfig)
9834                   {
9835                      if(macLcConfig->ul_SpecificParameters)
9836                      {
9837                         free(macLcConfig->ul_SpecificParameters->schedulingRequestID);
9838                         free(macLcConfig->ul_SpecificParameters->logicalChannelGroup);
9839                         free(macLcConfig->ul_SpecificParameters);
9840                      }
9841                      free(rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig);
9842                   }
9843                   free(rlcBearerList->list.array[arrIdx]); 
9844                }
9845             }
9846             free(rlcBearerList->list.array);
9847          }
9848          free(cellGrpCfg->rlc_BearerToAddModList);
9849       }
9850
9851       macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
9852       if(macCellGrpCfg)
9853       {
9854          schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig;
9855          if(schedulingRequestConfig)
9856          {
9857             schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
9858             if(schReqList)
9859             {
9860                if(schReqList->list.array)
9861                {
9862                   for(arrIdx=0;arrIdx<schReqList->list.count; arrIdx++)
9863                   {
9864                      if(schReqList->list.array[arrIdx])
9865                      {
9866                         free(schReqList->list.array[arrIdx]->sr_ProhibitTimer); 
9867                         free(schReqList->list.array[arrIdx]);
9868                      }
9869                   }
9870                   free(schReqList->list.array);
9871                }
9872                free(schedulingRequestConfig->schedulingRequestToAddModList);
9873             }
9874             free(macCellGrpCfg->schedulingRequestConfig);
9875          }
9876          if(macCellGrpCfg->bsr_Config)
9877          {
9878             free(macCellGrpCfg->bsr_Config);
9879          }
9880          tagConfig = macCellGrpCfg->tag_Config;
9881          if(tagConfig)
9882          {
9883             tagList = tagConfig->tag_ToAddModList;
9884             if(tagList)
9885             {
9886                if(tagList->list.array)
9887                {
9888                   for(arrIdx=0; arrIdx<tagList->list.count; arrIdx++)
9889                   {
9890                      free(tagList->list.array[arrIdx]);
9891                   }
9892                   free(tagList->list.array);
9893                }
9894                free(tagConfig->tag_ToAddModList);
9895             }
9896             free(tagConfig); 
9897          }
9898
9899          phrConfig = macCellGrpCfg->phr_Config;
9900          if(phrConfig)
9901          {
9902             free(phrConfig->choice.setup); 
9903             free(phrConfig); 
9904          }
9905
9906          free(macCellGrpCfg); 
9907       }
9908
9909       phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
9910       if(phyCellGrpCfg)
9911       {
9912          free(phyCellGrpCfg->p_NR_FR1);
9913          free(phyCellGrpCfg); 
9914       }
9915
9916       spCellCfg = cellGrpCfg->spCellConfig;
9917       if(spCellCfg)
9918       {
9919          if(spCellCfg->servCellIndex)
9920          {
9921             if(spCellCfg->rlmInSyncOutOfSyncThreshold)
9922             {
9923                if(spCellCfg->spCellConfigDedicated)
9924                {
9925                   srvCellCfg = spCellCfg->spCellConfigDedicated;
9926                   if(srvCellCfg->initialDownlinkBWP)
9927                   {
9928                      dlBwp = srvCellCfg->initialDownlinkBWP;
9929                      if(srvCellCfg->firstActiveDownlinkBWP_Id)
9930                      {
9931                         if(srvCellCfg->defaultDownlinkBWP_Id)
9932                         {
9933                            if(srvCellCfg->uplinkConfig)
9934                            {
9935
9936                               if(srvCellCfg->pdsch_ServingCellConfig)
9937                               {
9938                                  pdschCfg=
9939                                     srvCellCfg->pdsch_ServingCellConfig;
9940                                  if(pdschCfg->choice.setup)
9941                                  {
9942
9943                                     free(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH);
9944                                     free(pdschCfg->choice.setup);
9945                                  }
9946
9947                                  free(srvCellCfg->pdsch_ServingCellConfig);
9948                               }
9949
9950                               freeAperDecodeinitialUplinkBWPConfig(srvCellCfg->uplinkConfig);
9951                               free(srvCellCfg->uplinkConfig);
9952                            }
9953                            free(srvCellCfg->defaultDownlinkBWP_Id);
9954                         }
9955
9956                         free(srvCellCfg->firstActiveDownlinkBWP_Id);
9957                      }
9958                      if(dlBwp->pdcch_Config)
9959                      {
9960                         if(dlBwp->pdsch_Config)
9961                         {
9962                            freeAperDecodeBWPDlDedPdschConfig(dlBwp);
9963                            free(dlBwp->pdsch_Config);
9964                         }
9965                         freeAperDecodeBWPDlDedPdcchConfig(dlBwp);
9966                         free(dlBwp->pdcch_Config);
9967                      }
9968                      free(srvCellCfg->initialDownlinkBWP);
9969                   }
9970
9971                   free(spCellCfg->spCellConfigDedicated);
9972                }
9973                free(spCellCfg->rlmInSyncOutOfSyncThreshold);
9974             }
9975             free(spCellCfg->servCellIndex); 
9976          }
9977          free(spCellCfg);
9978       }
9979       DU_FREE(ueCfg->cellGrpCfg, sizeof(CellGroupConfigRrc_t));
9980       ueCfg->cellGrpCfg = NULLP;
9981    }
9982
9983    if(ueCfg->ambrCfg)
9984    {
9985       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCfg->ambrCfg, sizeof(AmbrCfg));
9986    }
9987
9988    if(actionType != UE_CTXT_CFG_QUERY)
9989    {
9990       for(lcIdx = 0; lcIdx < ueCfg->numRlcLcs; lcIdx++)
9991       {
9992          freeRlcLcCfg(&ueCfg->rlcLcCfg[lcIdx].rlcBearerCfg);
9993       }
9994    }
9995
9996    for(lcIdx = 0; lcIdx < ueCfg->numMacLcs; lcIdx++)
9997    {
9998       freeMacLcCfg(&ueCfg->macLcCfg[lcIdx].lcConfig);
9999    }
10000
10001    for(lcIdx = 0; lcIdx < ueCfg->numDrb; lcIdx++)
10002    {
10003       DU_FREE(ueCfg->upTnlInfo[lcIdx].tnlCfg1, sizeof(GtpTnlCfg));
10004    }
10005 }
10006
10007 /*******************************************************************
10008  *
10009  * @brief Function to free UecontextSetupDb
10010  *
10011  * @details
10012  *
10013  *    Function : freeF1UeDb
10014  *
10015  *    Functionality: Function to free UecontextSetupDb
10016  *
10017  * @params[in] UecontextSetupDb *
10018  * @return void
10019  *
10020  * ****************************************************************/
10021
10022 void freeF1UeDb(F1UeContextSetupDb *f1UeDb)
10023 {
10024    
10025    if(f1UeDb->dlRrcMsg)
10026    {
10027       if(f1UeDb->dlRrcMsg->rrcMsgPdu)
10028       {
10029         //DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,\
10030                f1UeDb->dlRrcMsg->rrcMsgPdu, f1UeDb->dlRrcMsg->rrcMsgSize);
10031       }
10032       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
10033    }
10034    freeDuUeCfg(f1UeDb->actionType, &f1UeDb->duUeCfg);
10035    memset(f1UeDb, 0, sizeof(F1UeContextSetupDb));
10036    DU_FREE(f1UeDb, sizeof(F1UeContextSetupDb));
10037 }
10038
10039 /*******************************************************************
10040  *
10041  * @brief Function to build Am cfg Info
10042  *
10043  * @details
10044  *
10045  *    Function : extractRlcAmCfg
10046  *
10047  *    Functionality: Function to build Am cfg Info
10048  *
10049  * @params[in] AmBearerCfg *
10050  *             void *
10051  *
10052  * @return ROK/RFAILED
10053  *
10054  * ****************************************************************/
10055
10056 void extractRlcAmCfg(AmBearerCfg *amCfgToSet, struct RLC_Config__am *rlcAmCfg)
10057 {
10058    if(rlcAmCfg)
10059    {
10060       /* UL AM */
10061       if(rlcAmCfg->dl_AM_RLC.sn_FieldLength)
10062       {
10063          amCfgToSet->ulAmCfg.snLenUl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->dl_AM_RLC.sn_FieldLength));
10064          /*TODO: Check the timer value when sent by real CU */
10065          amCfgToSet->ulAmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_Reassembly); 
10066          amCfgToSet->ulAmCfg.statProhTmr = convertProhibitTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_StatusProhibit);
10067       }
10068
10069       /* DL AM */
10070       if(rlcAmCfg->ul_AM_RLC.sn_FieldLength)
10071       {
10072          amCfgToSet->dlAmCfg.snLenDl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->ul_AM_RLC.sn_FieldLength));
10073          amCfgToSet->dlAmCfg.pollRetxTmr = covertPollRetxTmrEnumToValue(rlcAmCfg->ul_AM_RLC.t_PollRetransmit);
10074          amCfgToSet->dlAmCfg.pollPdu   = covertPollPduEnumToValue(rlcAmCfg->ul_AM_RLC.pollPDU);
10075          amCfgToSet->dlAmCfg.pollByte  = covertPollByteEnumToValue(rlcAmCfg->ul_AM_RLC.pollByte);
10076          amCfgToSet->dlAmCfg.maxRetxTh = covertMaxRetxEnumToValue(rlcAmCfg->ul_AM_RLC.maxRetxThreshold);
10077       }
10078    }
10079 }
10080
10081 /*******************************************************************
10082  *
10083  * @brief Function to build Um Bi Info
10084  *
10085  * @details
10086  *
10087  *    Function : extractRlcUmBiCfg
10088  *
10089  *    Functionality: Function to build Um Bi Info
10090  *
10091  * @params[in] UmBiDirBearerCfg *
10092  *             void *
10093  *
10094  * @return ROK/RFAILED
10095  *
10096  * ****************************************************************/
10097
10098 void extractRlcUmBiCfg(UmBiDirBearerCfg *umBiCfgToSet, struct RLC_Config__um_Bi_Directional *rlcBiCfg)
10099 {
10100    if(rlcBiCfg)
10101    {
10102       /* UL UM BI DIR Cfg */
10103       if(rlcBiCfg->dl_UM_RLC.sn_FieldLength)
10104       {
10105          umBiCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->dl_UM_RLC.sn_FieldLength));
10106          umBiCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcBiCfg->dl_UM_RLC.t_Reassembly);
10107       }
10108
10109       /* DL UM BI DIR Cfg */
10110       if(rlcBiCfg->ul_UM_RLC.sn_FieldLength)
10111          umBiCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->ul_UM_RLC.sn_FieldLength));
10112    }
10113 }
10114
10115 /*******************************************************************
10116  *
10117  * @brief Function to build Um Ul Info
10118  *
10119  * @details
10120  *
10121  *    Function : extractRlcUmUlCfg
10122  *
10123  *    Functionality: Function to build Um Ul Info
10124  *
10125  * @params[in] UmUniDirUlBearerCfg *
10126  *             void *
10127  *
10128  * @return ROK/RFAILED
10129  *
10130  * ****************************************************************/
10131
10132 void extractRlcUmUlCfg(UmUniDirUlBearerCfg *umUlCfgToSet, struct RLC_Config__um_Uni_Directional_DL *umUlCfg)
10133 {
10134    if(umUlCfg)
10135    {
10136       if(umUlCfg->dl_UM_RLC.sn_FieldLength)
10137       {
10138          umUlCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umUlCfg->dl_UM_RLC.sn_FieldLength));
10139          umUlCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(umUlCfg->dl_UM_RLC.t_Reassembly);
10140       }
10141    }
10142 }
10143
10144 /*******************************************************************
10145  *
10146  * @brief Function to build Um Uni Dl Info
10147  *
10148  * @details
10149  *
10150  *    Function : extractRlcUmDlCfg
10151  *
10152  *    Functionality: Function to build Um Uni Dl Info
10153  *
10154  * @params[in] UmUniDirDlBearerCfg *
10155  *             void *
10156  *
10157  * @return ROK/RFAILED
10158  *
10159  * ****************************************************************/
10160 void extractRlcUmDlCfg(UmUniDirDlBearerCfg *umDlCfgToSet, struct RLC_Config__um_Uni_Directional_UL *umDlCfg)
10161 {
10162    if(umDlCfg)
10163    {
10164       if(umDlCfg->ul_UM_RLC.sn_FieldLength)
10165          umDlCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umDlCfg->ul_UM_RLC.sn_FieldLength));
10166    }
10167 }
10168
10169 /*******************************************************************
10170  *
10171  * @brief Function to extractRlcModeCfg
10172  *
10173  * @details
10174  *
10175  *    Function : extractRlcModeCfg
10176  *
10177  *    Functionality: Function to extractRlcModeCfg
10178  *
10179  * @params[in] RLC_Config_t *
10180  *             RlcBearerCfg *
10181  *             void  *    
10182  * @return ROK/RFAILED
10183  *
10184  * ****************************************************************/
10185 void extractRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *rlcDbCfg, RLC_Config_t *lcCfg)
10186 {
10187    if(lcCfg)
10188    {
10189       switch(rlcMode)
10190       {
10191          case RLC_AM :
10192             {
10193                if(lcCfg->choice.am)
10194                {
10195                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.amCfg, sizeof(AmBearerCfg));
10196                   if(rlcDbCfg->u.amCfg)
10197                      extractRlcAmCfg(rlcDbCfg->u.amCfg, lcCfg->choice.am);
10198                }
10199                break;
10200             }
10201          case RLC_UM_BI_DIRECTIONAL :
10202             {
10203                if(lcCfg->choice.um_Bi_Directional)
10204                {
10205                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
10206                   if(rlcDbCfg->u.umBiDirCfg)
10207                      extractRlcUmBiCfg(rlcDbCfg->u.umBiDirCfg, lcCfg->choice.um_Bi_Directional);
10208                }
10209                break;
10210             }
10211          case RLC_UM_UNI_DIRECTIONAL_UL :
10212             {
10213                if(lcCfg->choice.um_Uni_Directional_DL)
10214                {
10215                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
10216                   if(rlcDbCfg->u.umUniDirUlCfg)
10217                      extractRlcUmUlCfg(rlcDbCfg->u.umUniDirUlCfg, lcCfg->choice.um_Uni_Directional_DL);
10218                }
10219                break;
10220             }
10221          case RLC_UM_UNI_DIRECTIONAL_DL :
10222             {
10223                if(lcCfg->choice.um_Uni_Directional_UL)
10224                {
10225                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
10226                   if(rlcDbCfg->u.umUniDirDlCfg)
10227                      extractRlcUmDlCfg(rlcDbCfg->u.umUniDirDlCfg, lcCfg->choice.um_Uni_Directional_UL);
10228                }
10229                break;
10230             }
10231          default:
10232             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
10233             break;
10234       }
10235    }
10236 }
10237
10238 /*******************************************************************
10239  *
10240  * @brief Function to extract extractUlLcCfg
10241  *
10242  * @details
10243  *
10244  *    Function : extractUlLcCfg
10245  *
10246  *    Functionality: Function to extract extractUlLcCfg
10247  *
10248  * @params[in] UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg
10249  * @return void
10250  *
10251  * ****************************************************************/
10252
10253 void extractUlLcCfg(UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg)
10254 {
10255    if(ulLcCfg)
10256    {
10257       if(ulLcCfg->ul_SpecificParameters)
10258       {
10259          f1UlLcCfg->priority = \
10260             ulLcCfg->ul_SpecificParameters->priority;
10261       if(ulLcCfg->ul_SpecificParameters->logicalChannelGroup)
10262       {
10263          f1UlLcCfg->lcGroup = \
10264            *(ulLcCfg->ul_SpecificParameters->logicalChannelGroup);
10265       }
10266       if(ulLcCfg->ul_SpecificParameters->schedulingRequestID)
10267       {
10268          f1UlLcCfg->schReqId = \
10269            *(ulLcCfg->ul_SpecificParameters->schedulingRequestID);
10270       }
10271       f1UlLcCfg->pbr = \
10272          ulLcCfg->ul_SpecificParameters->prioritisedBitRate;
10273       f1UlLcCfg->bsd = \
10274          ulLcCfg->ul_SpecificParameters->bucketSizeDuration;
10275       }
10276    }
10277 }
10278
10279 /*******************************************************************
10280 *
10281 * @brief Function to extract Snssai Cfg Info from CU
10282 *
10283 * @details
10284 *
10285 *    Function : extractDrbSnssaiCfg
10286 *
10287 *    Functionality: Function to extract Drb Snssai Cfg Info from CU
10288 *
10289 * @params[in] DRB_Information_t *drbInfo, Snssai  *snssai
10290 * @return ROK/RFAILED
10291 *
10292 * ****************************************************************/
10293
10294 uint8_t extractDrbSnssaiCfg(SNSSAI_t *RecvSnssai, Snssai **snssaiToBeShared)
10295 {
10296    if(!(*snssaiToBeShared))
10297    {
10298       DU_ALLOC_SHRABL_BUF((*snssaiToBeShared), sizeof(Snssai));
10299       if(snssaiToBeShared == NULLP)
10300       {
10301          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Memory failed at allocating for SNSSAI ");
10302          return RFAILED;
10303       }
10304    }
10305    if(RecvSnssai)
10306    {
10307       memcpy(&(*snssaiToBeShared)->sst, RecvSnssai->sST.buf, RecvSnssai->sST.size);
10308       if(RecvSnssai->sD)
10309       {
10310          memcpy((*snssaiToBeShared)->sd, RecvSnssai->sD->buf,  RecvSnssai->sD->size);
10311       }
10312       else
10313       {
10314          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Received Null pointer of Snssai->SD");
10315          return RFAILED;
10316       }
10317    }
10318    return ROK;
10319 }
10320
10321 /*******************************************************************
10322  *
10323  * @brief Function to procRlcLcCfg
10324  *
10325  * @details
10326  *
10327  *    Function : procRlcLcCfg
10328  *
10329  *    Functionality: Function to procRlcLcCfg
10330  *
10331  * @params[in] rbId, lcId, rbType, rlcMod
10332  *             RLC_Config_t *, RlcBearerCfg * , 
10333  * @return void
10334  *
10335  * ****************************************************************/
10336
10337 void procRlcLcCfg(uint8_t rbId, uint8_t lcId, uint8_t rbType, uint8_t rlcMode,\
10338    uint8_t configType, RLC_Config_t *f1RlcCfg, DuRlcBearerCfg *lcCfg, QoSInformation_t *qoSInformation)
10339 {
10340    DRB_Information_t *drbInfo;
10341
10342    lcCfg->rlcBearerCfg.rbId   = rbId;
10343    lcCfg->configType = configType;
10344
10345    if(rbType == RB_TYPE_SRB)
10346    {
10347       lcCfg->rlcBearerCfg.rbType = RB_TYPE_SRB;
10348       lcCfg->rlcBearerCfg.lcId   = rbId;
10349       lcCfg->rlcBearerCfg.lcType = LCH_DCCH;
10350       lcCfg->rlcBearerCfg.rlcMode = RLC_AM;
10351    }
10352    else if(rbType == RB_TYPE_DRB)
10353    {
10354       lcCfg->rlcBearerCfg.rbType = RB_TYPE_DRB;
10355       lcCfg->rlcBearerCfg.lcId   = lcId;
10356       lcCfg->rlcBearerCfg.lcType = LCH_DTCH;
10357       lcCfg->rlcBearerCfg.rlcMode = rlcMode;
10358    }
10359    if(f1RlcCfg) /* rlc mode config recived */
10360    {
10361       extractRlcModeCfg(lcCfg->rlcBearerCfg.rlcMode, &lcCfg->rlcBearerCfg, f1RlcCfg);
10362    }
10363    if(qoSInformation != NULLP)
10364    {
10365       if(qoSInformation->present == QoSInformation_PR_choice_extension)
10366       {
10367          if(qoSInformation->choice.choice_extension->value.present ==\
10368                QoSInformation_ExtIEs__value_PR_DRB_Information)
10369          {
10370             drbInfo = &qoSInformation->choice.choice_extension->value.choice.DRB_Information; 
10371             if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &lcCfg->rlcBearerCfg.snssai) != ROK)
10372             {
10373                DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information at procRlcLcCfg()");
10374                return;
10375             }
10376          }
10377       }
10378    }
10379 }
10380
10381 /*******************************************************************
10382  *
10383  * @brief Fills DrbQos Info received by CU
10384  *
10385  * @details
10386  *
10387  *    Function : extractQosInfo
10388  *
10389  *    Functionality: Fills DrbQos Info received  by CU
10390  *
10391  * @params[in] DrbQosInfo *qosToAdd, 
10392  *             QoSFlowLevelQoSParameters_t *qosFlowCfg
10393  * @return void
10394  *
10395  * ****************************************************************/
10396
10397 void extractQosInfo(DrbQosInfo *qosToAdd, QoSFlowLevelQoSParameters_t *qosFlowCfg)
10398 {
10399    uint8_t qosCntIdx = 0;
10400    ProtocolExtensionContainer_4624P74_t *qosIeExt = NULLP;
10401
10402    qosToAdd->fiveQiType = qosFlowCfg->qoS_Characteristics.present;
10403    qosToAdd->u.nonDyn5Qi.fiveQi     =\
10404                                      qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->fiveQI;
10405    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow)
10406    {
10407       qosToAdd->u.nonDyn5Qi.avgWindow = \
10408                                         *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
10409    }
10410
10411    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume)
10412    {
10413       qosToAdd->u.nonDyn5Qi.maxDataBurstVol = \
10414                                               *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
10415    }
10416
10417    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel)
10418    {
10419       qosToAdd->u.nonDyn5Qi.priorLevel = \
10420                                          *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel);
10421    }
10422    qosToAdd->ngRanRetPri.priorityLevel = \
10423                                          qosFlowCfg->nGRANallocationRetentionPriority.priorityLevel; 
10424    qosToAdd->ngRanRetPri.preEmptionCap = \
10425                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionCapability;
10426    qosToAdd->ngRanRetPri.preEmptionVul = \
10427                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionVulnerability;
10428    if(qosFlowCfg->gBR_QoS_Flow_Information)
10429    {
10430       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateDl, \
10431             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.buf, \
10432             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.size);
10433       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateUl, \
10434             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.buf, \
10435             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.size);
10436       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateDl,\
10437             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.buf, \
10438             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.size);
10439       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateUl,\
10440             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.buf, \
10441             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.size);
10442    }
10443    /*Extracting PDU_SESSION_ID*/
10444    qosIeExt = (ProtocolExtensionContainer_4624P74_t *)qosFlowCfg->iE_Extensions;
10445    if(qosIeExt)
10446    {
10447       for(qosCntIdx = 0; qosCntIdx < qosIeExt->list.count; qosCntIdx++)
10448       {
10449          if(qosIeExt->list.array[qosCntIdx]->extensionValue.present == \
10450                QoSFlowLevelQoSParameters_ExtIEs__extensionValue_PR_PDUSessionID)
10451          {
10452             qosToAdd->pduSessionId = qosIeExt->list.array[qosCntIdx]->extensionValue.choice.PDUSessionID;
10453             DU_LOG("\nDEBUG -->  DU_F1AP : extractQosInfo: PDU SessionID:%d",qosToAdd->pduSessionId);
10454          }
10455       }  
10456    }
10457    qosToAdd->ulPduSessAggMaxBitRate = 0;
10458 }
10459
10460 /*******************************************************************
10461  *
10462  * @brief Function to extract GTP Tunnel Info from CU
10463  *
10464  * @details
10465  *
10466  *    Function : extractUpTnlInfo
10467  *
10468  *    Functionality: Function to extract GTP Tunnel Info from CU
10469  *
10470  * @params[in] F1AP message
10471  * @return ROK/RFAILED
10472  *
10473  * ****************************************************************/
10474
10475 uint8_t extractUpTnlInfo(uint8_t drbId, uint8_t configType,\
10476    ULUPTNLInformation_ToBeSetup_List_t *tnlInfo, UpTnlCfg *upTnlInfo)
10477 {
10478    uint8_t tnlIdx;
10479    uint32_t ipv4_du = 0;
10480    GTPTunnel_t *gtpTunnel = NULLP;
10481
10482    upTnlInfo->drbId = drbId; 
10483    upTnlInfo->configType = configType;
10484 #ifdef O1_ENABLE
10485    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
10486 #else
10487    cmInetAddr((char *)DU_IP_V4_ADDR, &ipv4_du);
10488 #endif
10489
10490    for(tnlIdx=0; tnlIdx < tnlInfo->list.count; tnlIdx++)
10491    {
10492       if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.present == UPTransportLayerInformation_PR_gTPTunnel)
10493       {
10494          if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel)
10495          {
10496             gtpTunnel = tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel;
10497             DU_ALLOC(upTnlInfo->tnlCfg1, sizeof(GtpTnlCfg));
10498             if(upTnlInfo->tnlCfg1 == NULLP)
10499             {
10500                DU_LOG("\nERROR  -->  F1AP : extractUpTnlInfo: Failed to allocate mmeory for tunnel cfg 1");
10501                return RFAILED;
10502             }
10503             bitStringToInt(&gtpTunnel->transportLayerAddress, &upTnlInfo->tnlCfg1->ulTnlAddress);
10504             upTnlInfo->tnlCfg1->dlTnlAddress = ipv4_du;
10505             if(gtpTunnel->gTP_TEID.size > 0)
10506             {
10507                teIdStringToInt(gtpTunnel->gTP_TEID.buf, &upTnlInfo->tnlCfg1->teId);
10508             }
10509          }
10510          break;
10511       }
10512    }
10513    return ROK;
10514 }
10515
10516 /*******************************************************************
10517 *
10518 * @brief Function to extract Drb Qos Cfg Info from CU
10519 *
10520 * @details
10521 *
10522 *    Function : extractDrbQosCfg 
10523 *
10524 *    Functionality: Function to extract Drb Qos Cfg Info from CU
10525 *
10526 * @params[in] DRB_Information_t *drbInfo, LcCfg *macLcToAdd
10527 * @return ROK/RFAILED
10528 *
10529 * ****************************************************************/
10530
10531 uint8_t extractDrbQosCfg(DRB_Information_t *drbInfo, LcCfg *macLcToAdd ) 
10532 {
10533    if(!macLcToAdd->drbQos)
10534    {
10535       DU_ALLOC_SHRABL_BUF(macLcToAdd->drbQos, sizeof(DrbQosInfo));
10536       if(macLcToAdd->drbQos == NULLP)
10537       {
10538          DU_LOG("\nERROR  -->  DUAPP:Memory failed at allocating DrbQos at extractDrbQosCfg()");
10539          return RFAILED;
10540       }
10541
10542    }
10543    if(drbInfo->dRB_QoS.qoS_Characteristics.present == QoS_Characteristics_PR_non_Dynamic_5QI)
10544    {
10545       extractQosInfo(macLcToAdd->drbQos, &drbInfo->dRB_QoS);
10546       macLcToAdd->dlLcCfg.lcp = macLcToAdd->drbQos->ngRanRetPri.priorityLevel;
10547    }
10548    if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &macLcToAdd->snssai) != ROK)
10549    {
10550       DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information  at extractDrbQosCfg()");
10551       return RFAILED;
10552    }
10553    return ROK;
10554 }
10555 /*******************************************************************
10556  *
10557  * @brief Function to extract DRB info received from CU
10558  *
10559  * @details
10560  *
10561  *    Function : extractDrbCfg
10562  *
10563  *    Functionality: Function to extract DRB info received from CU
10564  *
10565  * @params[in] F1AP message
10566  * @return void
10567  *
10568  * ****************************************************************/
10569 uint8_t extractDrbCfg(DRBs_ToBeSetup_Item_t *drbItem, DRBs_ToBeSetupMod_Item_t *drbSetupModItem,\
10570 DRBs_ToBeModified_Item_t *drbModItem,  DuLcCfg *lcCfgToAdd, UpTnlCfg *upTnlInfo)
10571 {
10572    DRB_Information_t *drbInfo = NULLP;
10573
10574    if(drbItem != NULLP)
10575    {
10576       if(extractUpTnlInfo(drbItem->dRBID, CONFIG_ADD, &drbItem->uLUPTNLInformation_ToBeSetup_List, upTnlInfo) != ROK)
10577       {
10578          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10579          return RFAILED;
10580       }
10581       if(drbItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10582       {
10583          if(drbItem->qoSInformation.choice.choice_extension->value.present == QoSInformation_ExtIEs__value_PR_DRB_Information)
10584          {
10585             drbInfo = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10586             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10587             {
10588                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");
10589                return RFAILED;
10590             }
10591          }
10592       }
10593    }
10594    else if(drbSetupModItem != NULLP)
10595    {
10596       if(extractUpTnlInfo(drbSetupModItem->dRBID, CONFIG_ADD, &drbSetupModItem->uLUPTNLInformation_ToBeSetup_List,\
10597       upTnlInfo) != ROK)
10598       {
10599          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10600          return RFAILED;
10601       }
10602       if(drbSetupModItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10603       {
10604          if(drbSetupModItem->qoSInformation.choice.choice_extension->value.present ==\
10605          QoSInformation_ExtIEs__value_PR_DRB_Information)
10606          {
10607             drbInfo = &drbSetupModItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10608             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10609             {
10610                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10611                return RFAILED;
10612             }
10613
10614          }
10615       }
10616    }
10617    else if(drbModItem != NULLP)
10618    {
10619       if(extractUpTnlInfo(drbModItem->dRBID, CONFIG_MOD, &drbModItem->uLUPTNLInformation_ToBeSetup_List,\
10620       upTnlInfo) != ROK)
10621       {
10622          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10623          return RFAILED;
10624       }
10625       if(drbModItem->qoSInformation != NULLP)
10626       {
10627          if(drbModItem->qoSInformation->present == QoSInformation_PR_choice_extension)
10628          {
10629             if(drbModItem->qoSInformation->choice.choice_extension->value.present ==\
10630                   QoSInformation_ExtIEs__value_PR_DRB_Information)
10631             {
10632                drbInfo = &drbModItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information;
10633                if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10634                {
10635                   DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10636                   return RFAILED;
10637                }
10638
10639             }
10640          }
10641       }
10642    }
10643    return ROK;
10644 }
10645
10646 /*******************************************************************
10647  *
10648  * @brief Function to extract RB info received from CU
10649  *
10650  * @details
10651  *
10652  *    Function : extractMacRbCfg
10653  *
10654  *    Functionality: Function to extract RB info received from CU
10655  *
10656  * @params[in] F1AP message
10657  * @return ROK/RFAILED
10658  *
10659  * ****************************************************************/
10660
10661 uint8_t extractMacRbCfg(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbCfg,\
10662 DRBs_ToBeSetupMod_Item_t *drbSetupModCfg,  DRBs_ToBeModified_Item_t *drbModCfg, LogicalChannelConfig_t *ulLcCfg, DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10663 {
10664    if(drbCfg != NULLP)
10665    {
10666       if(extractDrbCfg(drbCfg, NULL, NULL, lcCfg, upTnlInfo) != ROK)
10667       {
10668          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10669          return RFAILED;
10670       }
10671    }
10672    else if(drbSetupModCfg != NULLP)
10673    { 
10674       if(extractDrbCfg(NULL, drbSetupModCfg, NULL, lcCfg, upTnlInfo) != ROK)
10675       {
10676          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10677          return RFAILED;
10678       }
10679    }
10680    else if(drbModCfg != NULLP)
10681    { 
10682       if(extractDrbCfg(NULL, NULL, drbModCfg, lcCfg, upTnlInfo) != ROK)
10683       {
10684          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10685          return RFAILED;
10686       }
10687    }
10688    else
10689    {
10690       lcCfg->lcConfig.drbQos = NULLP;
10691       lcCfg->lcConfig.snssai = NULLP;
10692       if(lcCfg->lcConfig.lcId == SRB2_LCID)
10693          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_3;
10694       else
10695          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_1;
10696
10697    }
10698    if(ulLcCfg)
10699    {
10700       lcCfg->lcConfig.ulLcCfgPres = true;
10701       extractUlLcCfg(&lcCfg->lcConfig.ulLcCfg, ulLcCfg);
10702    }
10703    else
10704       lcCfg->lcConfig.ulLcCfgPres = false;
10705    return ROK;
10706 }
10707
10708 /*******************************************************************
10709  *
10710  * @brief Function processing LC config info received from CU
10711  *
10712  * @details
10713  *
10714  *    Function : procMacLcCfg
10715  *
10716  *    Functionality: Function processing LC config info received from CU
10717  *
10718  * @params[in] F1AP message
10719  * @return ROK/RFAILED
10720  *
10721  * ****************************************************************/
10722
10723 uint8_t procMacLcCfg(uint8_t lcId, uint8_t rbType, uint8_t configType, DRBs_ToBeSetup_Item_t *drbItem,\
10724 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LogicalChannelConfig_t *ulLcCfg,\
10725 DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10726 {
10727    uint8_t ret = ROK;
10728
10729    lcCfg->lcConfig.lcId = lcId;
10730    lcCfg->configType = configType;
10731    if(rbType == RB_TYPE_SRB)
10732    {
10733       ret = extractMacRbCfg(lcId, NULL, NULL, NULL, ulLcCfg, lcCfg, NULL);
10734    }
10735    else if(rbType == RB_TYPE_DRB && upTnlInfo != NULLP)
10736    {
10737       if(drbItem != NULL)
10738         ret = extractMacRbCfg(lcId, drbItem, NULL, NULL, ulLcCfg, lcCfg, upTnlInfo);
10739       else if(drbSetupModItem != NULL)
10740         ret = extractMacRbCfg(lcId, NULL, drbSetupModItem, NULL, ulLcCfg, lcCfg, upTnlInfo);
10741       else if(drbModItem != NULL)
10742         ret = extractMacRbCfg(lcId, NULL, NULL, drbModItem, ulLcCfg, lcCfg, upTnlInfo);
10743    }
10744    return ret;
10745 }
10746
10747 /*******************************************************************
10748  *
10749  * @brief Function to extract Rlc cfg To Add/Mod in CellGrp Info
10750  *
10751  * @details
10752  *
10753  *    Function : extractRlcCfgToAddMod
10754  *
10755  *    Functionality: Function to extract Rlc cfg To Add/Mod in CellGrp Info
10756  *
10757  * @params[in] CellGroupConfigRrc__rlc_BearerTo pointer
10758  *             DuUeCfg Pointer
10759  * @return ROK/RFAILED
10760  *
10761  * ****************************************************************/
10762
10763 uint8_t extractRlcCfgToAddMod(struct CellGroupConfigRrc__rlc_BearerToAddModList *lcCfg, DuUeCfg *ueCfgDb)
10764 {
10765   uint8_t idx, rbId, lcId, rlcMode, rbType;
10766   RLC_Config_t *f1RlcCfg = NULLP;
10767   LogicalChannelConfig_t *macUlLcCfg = NULLP;
10768
10769   for(idx = 0; idx < lcCfg->list.count; idx++)
10770   {
10771      lcId = lcCfg->list.array[idx]->logicalChannelIdentity;
10772      if(lcCfg->list.array[idx]->servedRadioBearer)
10773      {
10774         /* RadioBearer for SRB/DRB */
10775         if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10776         RLC_BearerConfig__servedRadioBearer_PR_srb_Identity)
10777         {
10778            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.srb_Identity;
10779            rbType = RB_TYPE_SRB;
10780         }
10781         else if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10782         RLC_BearerConfig__servedRadioBearer_PR_drb_Identity)
10783         {
10784            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.drb_Identity;
10785            rbType = RB_TYPE_DRB;
10786         }
10787         else
10788         {
10789            DU_LOG("\nERROR  -->  No components present in Bearer config to ADD/MOD");
10790            return RFAILED;
10791         }
10792         /* MAC UL LC Config */
10793         if(lcCfg->list.array[idx]->mac_LogicalChannelConfig)
10794         {
10795            macUlLcCfg = lcCfg->list.array[idx]->mac_LogicalChannelConfig;
10796         }
10797      }
10798      else
10799      {
10800         DU_LOG("\nERROR  -->  DUAPP: Received RadioBearer config is NULL");
10801         return RFAILED;
10802      }
10803      /* RLC Mode Config */
10804      if(lcCfg->list.array[idx]->rlc_Config)
10805      {
10806         rlcMode  = lcCfg->list.array[idx]->rlc_Config->present;
10807         f1RlcCfg = lcCfg->list.array[idx]->rlc_Config;
10808      }
10809      
10810      /* Filling RLC/MAC Config*/
10811      memset(&ueCfgDb->macLcCfg[idx], 0, sizeof(DuLcCfg));
10812      memset(&ueCfgDb->rlcLcCfg[idx], 0, sizeof(DuRlcBearerCfg));
10813      procRlcLcCfg(rbId, lcId, rbType, rlcMode, CONFIG_UNKNOWN, f1RlcCfg, &(ueCfgDb->rlcLcCfg[idx]), NULLP);
10814      if(procMacLcCfg(lcId, rbType, CONFIG_UNKNOWN, NULL, NULL, NULL, macUlLcCfg, &ueCfgDb->macLcCfg[idx], NULL) != ROK)
10815      {
10816         DU_LOG("\nERROR  -->  DU APP : Failed while filling MAC LC config at extractRlcCfgToAddMod()");
10817         return RFAILED;
10818      }
10819      (ueCfgDb->numRlcLcs)++;
10820      (ueCfgDb->numMacLcs)++;
10821      DU_LOG("\nDEBUG  -> DUAPP: extractRlcCfgToAddMod:RBType:%d, DrbID: %d,lcId:%d, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
10822         rbType, rbId, lcId, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
10823   }
10824   //TODO: To send the failure cause in UeContextSetupRsp 
10825   return ROK;
10826 }
10827
10828 /*******************************************************************
10829  *
10830  * @brief DeAlloc pdsch serv cell config info
10831  *
10832  * @details
10833  *
10834  *    Function : freeMacPdschServCellInfo
10835  *
10836  *    Functionality: DeAlloc pdsch serv cell config info
10837  *
10838  * @params[in] PdschServCellCfg pointer
10839  * @return void
10840  *
10841  * ****************************************************************/
10842
10843 void freeMacPdschServCellInfo(PdschServCellCfg *pdsch)
10844 {
10845    if(pdsch->xOverhead)
10846    {
10847       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->xOverhead, sizeof(PdschXOverhead));
10848    }
10849    if(pdsch->codeBlkGrpFlushInd)
10850    {
10851       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->codeBlkGrpFlushInd, sizeof(bool));
10852    }
10853    if(pdsch->maxCodeBlkGrpPerTb)
10854    {
10855       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10856    }
10857    if(pdsch->maxMimoLayers)
10858    {
10859       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxMimoLayers, sizeof(uint8_t));
10860    }
10861 }
10862
10863 /*******************************************************************
10864  *
10865  * @brief Free Serving cell Info
10866  *
10867  * @details
10868  *
10869  *    Function : freeMacServingCellInfo
10870  *
10871  *    Functionality: Free Serving cell Info
10872  *
10873  * @params[in] ServCellCfgInfo *srvCellCfg
10874  * @return void
10875  *
10876  * ****************************************************************/
10877 void freeMacServingCellInfo(ServCellRecfgInfo *srvCellCfg)
10878 {
10879    uint8_t timeDomRsrcIdx;
10880
10881    if(srvCellCfg->initDlBwp.pdschPresent)
10882    {
10883       for(timeDomRsrcIdx = 0; timeDomRsrcIdx < srvCellCfg->initDlBwp.pdschCfg.numTimeDomRsrcAlloc; timeDomRsrcIdx++)
10884       {
10885          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, \
10886             srvCellCfg->initDlBwp.pdschCfg.timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
10887       }
10888    }
10889
10890    freeMacPdschServCellInfo(&srvCellCfg->pdschServCellCfg);
10891    if(srvCellCfg->bwpInactivityTmr)
10892    {
10893       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
10894    }
10895
10896    if(srvCellCfg->initUlBwp.pucchPresent)
10897    {
10898       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->initUlBwp.pucchCfg.dlDataToUlAck, sizeof(PucchDlDataToUlAck));
10899    }
10900 }
10901
10902 /*******************************************************************
10903  *
10904  * @brief Free cell Grp Cfg Info
10905  *
10906  * @details
10907  *
10908  *    Function : freeUeRecfgCellGrpInfo
10909  *
10910  *    Functionality: Free cell Grp Cfg Info
10911  *
10912  * @params[in] DuMacUeCfg*  duUeCfg
10913  * @return void
10914  *
10915  * ****************************************************************/
10916
10917 void freeUeRecfgCellGrpInfo(DuMacUeCfg *macUeCfg)
10918 {
10919    freeMacServingCellInfo(&macUeCfg->spCellCfg.servCellCfg);
10920 }
10921
10922 /*******************************************************************
10923  *
10924  * @brief Fills Reconfig SchReqReConfig
10925  *
10926  * @details
10927  *
10928  *    Function : extractSchReqReConfig
10929  *
10930  *    Functionality: Fills Reconfig SchReqReConfig
10931  *
10932  * @params[in] SchedulingRequestConfig_t *cuSchedReq
10933  *             SchedReqCfg*  macSchedReq
10934  * @return void
10935  *
10936  * ****************************************************************/
10937 void extractSchReqReConfig(SchedulingRequestConfig_t *cuSchedReq, SchedReqCfg *macSchedReq)
10938 {
10939    uint8_t schReqIdx = 0;
10940    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqListToAdd = NULLP;
10941    struct SchedulingRequestConfig__schedulingRequestToReleaseList *schReqListToRel = NULLP;
10942
10943    if(cuSchedReq->schedulingRequestToAddModList)
10944    {
10945       schReqListToAdd = cuSchedReq->schedulingRequestToAddModList;
10946       if(schReqListToAdd->list.count)
10947       {
10948          macSchedReq->addModListCount = schReqListToAdd->list.count;
10949          for(schReqIdx = 0; schReqIdx < schReqListToAdd->list.count; schReqIdx++)
10950          {
10951             macSchedReq->addModList[schReqIdx].schedReqId = \
10952                schReqListToAdd->list.array[schReqIdx]->schedulingRequestId;
10953             macSchedReq->addModList[schReqIdx].srProhibitTmr = \
10954                *(schReqListToAdd->list.array[schReqIdx]->sr_ProhibitTimer);
10955             macSchedReq->addModList[schReqIdx].srTransMax    =\
10956                schReqListToAdd->list.array[schReqIdx]->sr_TransMax;
10957          }
10958       }
10959    }
10960    /* Scheduling Req To release */
10961    if(cuSchedReq->schedulingRequestToReleaseList)
10962    {
10963       schReqListToRel = cuSchedReq->schedulingRequestToReleaseList;
10964       if(schReqListToRel->list.count)
10965       {
10966          macSchedReq->relListCount = schReqListToRel->list.count;
10967          for(schReqIdx = 0; schReqIdx < schReqListToRel->list.count; schReqIdx++)
10968          {
10969             macSchedReq->relList[schReqIdx] = \
10970                *schReqListToRel->list.array[schReqIdx];
10971          }
10972       }
10973    }
10974 }
10975
10976 /*******************************************************************
10977  *
10978  * @brief Fills TagReconfig
10979  *
10980  * @details
10981  *
10982  *    Function : extractTagReconfig
10983  *
10984  *    Functionality: Fills extractTagReconfig
10985  *
10986  * @params[in] TAG_Config_t *cuTagCfg
10987  *             TagCfg *macTagCfg
10988  * @return void
10989  *
10990  * ****************************************************************/
10991
10992 void extractTagReconfig(TAG_Config_t *cuTagCfg, TagCfg *macTagCfg)
10993 {
10994   uint8_t tagIdx = 0;
10995   struct TAG_Config__tag_ToAddModList  *tagListToAddMod = NULLP;
10996   struct TAG_Config__tag_ToReleaseList *tagListToRel = NULLP;
10997
10998   /* Tag config to AddMod */
10999   if(cuTagCfg->tag_ToAddModList)
11000   {
11001      tagListToAddMod = cuTagCfg->tag_ToAddModList; 
11002      if(tagListToAddMod->list.count)
11003      {
11004         macTagCfg->addModListCount = tagListToAddMod->list.count;
11005         for(tagIdx = 0; tagIdx < tagListToAddMod->list.count; tagIdx++)
11006         {
11007            macTagCfg->addModList[tagIdx].tagId =\
11008               tagListToAddMod->list.array[tagIdx]->tag_Id;     
11009            macTagCfg->addModList[tagIdx].timeAlignTimer = \
11010
11011               tagListToAddMod->list.array[tagIdx]->timeAlignmentTimer;
11012         }
11013      }
11014   }
11015   /* Tag config to release */
11016   if(cuTagCfg->tag_ToReleaseList)
11017   {
11018      tagListToRel = cuTagCfg->tag_ToReleaseList;
11019      if(tagListToRel->list.count)
11020      {
11021         macTagCfg->relListCount = tagListToRel->list.count;
11022         for(tagIdx = 0; tagIdx < tagListToRel->list.count; tagIdx++)
11023         {
11024            macTagCfg->relList[tagIdx] = *tagListToRel->list.array[tagIdx];     
11025         }
11026      }
11027   }
11028 }
11029
11030 /*******************************************************************
11031  *
11032  * @brief Fills PdcchCfg received by CU
11033  *
11034  * @details
11035  *
11036  *    Function : extractPdcchCfg
11037  *
11038  *    Functionality: Fills PdcchCfg received  by CU
11039  *
11040  * @params[in] PDCCH_Config_t *cuPdcchCfg,
11041  *             PdcchConfig *duPdcchCfg
11042  * @return void
11043  *
11044  * ****************************************************************/
11045
11046 void extractPdcchCfg(PDCCH_Config_t *cuPdcchCfg, PdcchConfig *macPdcchCfg)
11047 {
11048    uint8_t cRsetIdx = 0;
11049    uint8_t srchSpcIdx = 0;
11050
11051    struct PDCCH_Config__controlResourceSetToAddModList *cRsetToAddModList = NULLP;
11052    struct PDCCH_Config__controlResourceSetToReleaseList *cRsetToRelList = NULLP;
11053    struct PDCCH_Config__searchSpacesToAddModList *srchSpcToAddModList = NULLP;
11054    struct PDCCH_Config__searchSpacesToReleaseList *srchSpcToRelList = NULLP;
11055
11056
11057    /* Control Resource Set To Add/Mod List */
11058    if(cuPdcchCfg->controlResourceSetToAddModList)
11059    {
11060       cRsetToAddModList = cuPdcchCfg->controlResourceSetToAddModList;
11061       if(cRsetToAddModList->list.count)
11062       {
11063          macPdcchCfg->numCRsetToAddMod = cRsetToAddModList->list.count;
11064          for(cRsetIdx = 0; cRsetIdx < cRsetToAddModList->list.count; cRsetIdx++)
11065          {
11066             macPdcchCfg->cRSetToAddModList[cRsetIdx].cRSetId = \
11067                cRsetToAddModList->list.array[cRsetIdx]->controlResourceSetId;
11068             //freqDomRsrcBitStringToInt(&cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources,\
11069                   macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc);
11070             memcpy(macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc, \
11071                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.buf,
11072                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.size);
11073
11074             macPdcchCfg->cRSetToAddModList[cRsetIdx].duration = \
11075                 cRsetToAddModList->list.array[cRsetIdx]->duration;
11076
11077             macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType = \
11078                cRsetToAddModList->list.array[cRsetIdx]->cce_REG_MappingType.present;   
11079             if(macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType == CCE_REG_MAPPINGTYPE_PR_INTERLEAVED)
11080             {
11081                //TODO: handle the case for Interleaved
11082             }
11083             macPdcchCfg->cRSetToAddModList[cRsetIdx].precoderGranularity = \
11084                 cRsetToAddModList->list.array[cRsetIdx]->precoderGranularity;
11085             if(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID)
11086             {
11087                macPdcchCfg->cRSetToAddModList[cRsetIdx].dmrsScramblingId= \
11088                   *(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID);
11089             }
11090          }
11091       }
11092    }
11093    /* Control Resource Set To Release List */
11094    if(cuPdcchCfg->controlResourceSetToReleaseList)
11095    {
11096       cRsetToRelList = cuPdcchCfg->controlResourceSetToReleaseList;
11097       if(cRsetToRelList->list.count)
11098       {
11099          macPdcchCfg->numCRsetToRel = cRsetToRelList->list.count;
11100          for(cRsetIdx = 0; cRsetIdx < cRsetToRelList->list.count; cRsetIdx++)
11101          {
11102             macPdcchCfg->cRSetToRelList[cRsetIdx] = *(cRsetToRelList->list.array[cRsetIdx]);
11103          }
11104       }
11105    }
11106
11107    /* Search space To Add/Mod List */
11108    if(cuPdcchCfg->searchSpacesToAddModList)
11109    {
11110       srchSpcToAddModList = cuPdcchCfg->searchSpacesToAddModList;
11111       if(srchSpcToAddModList->list.count)
11112       {
11113          macPdcchCfg->numSearchSpcToAddMod = srchSpcToAddModList->list.count;
11114          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToAddModList->list.count; srchSpcIdx++)
11115          {
11116             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceId =\
11117                                                                           srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceId;
11118             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].cRSetId =\
11119                                                                     *(srchSpcToAddModList->list.array[srchSpcIdx]->controlResourceSetId);
11120             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset)
11121             {
11122                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSlotPeriodicityAndOffset =\
11123                                                                                          srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset->present;
11124             }
11125             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot)
11126             {
11127                bitStringToInt(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot,\
11128                      macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSymbolsWithinSlot);
11129             }
11130             if(srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates)
11131             {
11132                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel1 = \
11133                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel1;
11134                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel2 = \
11135                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel2;
11136                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel4 = \
11137                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel4;
11138
11139                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel8 = \
11140                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel8;
11141
11142                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel16 = \
11143                                                                                         srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel16;
11144             }
11145             if(srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType)
11146             {
11147                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType =\
11148                                                                                srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->present;
11149                if(macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType == SEARCHSPACETYPE_PR_UE_SPECIFIC)
11150                {
11151                   macPdcchCfg->searchSpcToAddModList[srchSpcIdx].ueSpecificDciFormat =\
11152                                                                                       srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->choice.ue_Specific->dci_Formats;
11153                }
11154
11155             }
11156          }
11157       }
11158    }
11159    /* Search space To Rel List */
11160    if(cuPdcchCfg->searchSpacesToReleaseList)
11161    {
11162       srchSpcToRelList = cuPdcchCfg->searchSpacesToReleaseList;
11163       if(srchSpcToRelList->list.count)
11164       {
11165          macPdcchCfg->numSearchSpcToRel = srchSpcToRelList->list.count;
11166          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToRelList->list.count; srchSpcIdx++)
11167          {
11168             macPdcchCfg->searchSpcToRelList[srchSpcIdx] =\
11169                                                          *(srchSpcToRelList->list.array[srchSpcIdx]);
11170          }
11171       }
11172    }
11173 }
11174
11175 /*******************************************************************
11176  *
11177  * @brief Fills PdschCfg received by CU
11178  *
11179  * @details
11180  *
11181  *    Function : extractPdschCfg
11182  *
11183  *    Functionality: Fills PdschCfg received  by CU
11184  *
11185  * @params[in] PDSCH_Config_t *cuPdschCfg = Information which is send by CU,
11186  *                   which we have stored in F1UeContextSetupDb,
11187  *             PdschConfig *macPdschCfg = Used to Store the information which
11188  *                   needs to send in other layer, as well as this can be the variable
11189  *                   which stores the information in DuCb,
11190  *             PdschConfig *storedPdschCfg =  Null in case of sending the
11191  *                   information to other layer else it will have stored pdsch 
11192  *                   configuration in copyOfmacUeCfg.
11193  * @return void
11194  *
11195  * ****************************************************************/
11196
11197 void extractPdschCfg(PDSCH_Config_t *cuPdschCfg, PdschConfig *macPdschCfg, PdschConfig *storedPdschCfg)
11198 {
11199    uint8_t timeDomIdx;
11200    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAlloc = NULLP;
11201
11202    if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
11203    {
11204       if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->present == \
11205             PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup)
11206       {
11207          if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup)
11208          {
11209             macPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
11210                *(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_AdditionalPosition);
11211          }
11212       }
11213    }
11214    macPdschCfg->resourceAllocType = cuPdschCfg->resourceAllocation;
11215    if(cuPdschCfg->pdsch_TimeDomainAllocationList)
11216    {
11217       timeDomAlloc = cuPdschCfg->pdsch_TimeDomainAllocationList;
11218       if(timeDomAlloc->present ==\
11219             PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup)
11220       {
11221          if(timeDomAlloc->choice.setup)
11222          {
11223             macPdschCfg->numTimeDomRsrcAlloc  = timeDomAlloc->choice.setup->list.count;
11224             for(timeDomIdx = 0; timeDomIdx < timeDomAlloc->choice.setup->list.count; timeDomIdx++)
11225             {
11226                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 = NULLP;
11227                if(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0)
11228                {
11229                   if(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 == NULL)
11230                   {
11231                      if(storedPdschCfg)
11232                      {
11233                         if(storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
11234                         {
11235                            macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 =\
11236                            storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0;
11237                         }
11238                         else
11239                         {
11240                            DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
11241                         }
11242                      }
11243                      else
11244                      {
11245                         DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
11246                      }
11247                      if(!macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
11248                      {
11249                         DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for k0 at extractPdschCfg()");
11250                         return;
11251                      }
11252                   }
11253                   *(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0) = \
11254                   *(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0);
11255                }
11256                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].mappingType = \
11257                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->mappingType;
11258                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].startSymbolAndLength = \
11259                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11260             }
11261          }
11262       }
11263    }
11264    macPdschCfg->rbgSize = cuPdschCfg->rbg_Size;
11265    if(cuPdschCfg->maxNrofCodeWordsScheduledByDCI)
11266       macPdschCfg->numCodeWordsSchByDci = *(cuPdschCfg->maxNrofCodeWordsScheduledByDCI);
11267    if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_staticBundling)
11268    {
11269       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11270       if(cuPdschCfg->prb_BundlingType.choice.staticBundling)
11271       {
11272          if(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize)
11273          {
11274             macPdschCfg->bundlingInfo.StaticBundling.size = \
11275                *(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize);
11276          }
11277       }
11278    }
11279    else if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_dynamicBundling)
11280    {
11281       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11282    }
11283
11284 }
11285
11286 /*******************************************************************
11287  *
11288  * @brief Fills PdschServingCellCfg received by CU
11289  *
11290  * @details
11291  *
11292  *    Function : extractPdschServingCellCfg
11293  *
11294  *    Functionality: Fills PdschCfg received  by CU
11295  *
11296  * @params[in] PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg,
11297  *             PdschServCellCfg *macUePdschSrvCellCfg
11298  * @return ROK/RFAILED
11299  *
11300  * ****************************************************************/
11301
11302 uint8_t extractPdschServingCellCfg(PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg, PdschServCellCfg *macUePdschSrvCellCfg)
11303 {
11304    if(cuPdschSrvCellCfg->codeBlockGroupTransmission)
11305    {
11306       if(cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup)
11307       {
11308          if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11309          {
11310             *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11311                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11312          }
11313          else
11314          {
11315             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
11316             if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11317             {
11318                *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11319                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11320             }
11321             else
11322             {
11323                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxCodeBlkGrpPerTb at extractPdschServingCellCfg()");
11324                return RFAILED;
11325             }
11326          }
11327          if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11328          {
11329             *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11330                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11331          }
11332          else
11333          {
11334             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->codeBlkGrpFlushInd , sizeof(bool));
11335             if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11336             {
11337                *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11338                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11339             }
11340             else
11341             {
11342                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for codeBlkGrpFlushInd at extractPdschServingCellCfg()");
11343                return RFAILED;
11344             }
11345          }
11346       }
11347    }
11348    if(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH)
11349    {
11350       macUePdschSrvCellCfg->numHarqProcForPdsch = *(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH); 
11351    }
11352    if(cuPdschSrvCellCfg->ext1)
11353    {
11354       if(cuPdschSrvCellCfg->ext1->maxMIMO_Layers)
11355       {
11356         if(macUePdschSrvCellCfg->maxMimoLayers)
11357         {
11358            *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11359         }
11360         else
11361         {
11362            DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxMimoLayers, sizeof(uint8_t));
11363            if(macUePdschSrvCellCfg->maxMimoLayers)
11364            {
11365               *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11366            }
11367            else
11368            {
11369               DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxMimoLayers at extractPdschServingCellCfg()");
11370               return RFAILED;
11371            }
11372         }
11373       }
11374    }
11375    if(cuPdschSrvCellCfg->xOverhead)
11376    {
11377       if(macUePdschSrvCellCfg->xOverhead)
11378       {
11379          *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11380       }
11381       else
11382       {
11383          DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->xOverhead, sizeof(PdschXOverhead));
11384          if(macUePdschSrvCellCfg->xOverhead)
11385          {
11386             *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11387          }
11388          else
11389          {
11390             DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for xOverhead at extractPdschServingCellCfg()");
11391             return RFAILED;
11392          }
11393       }
11394    }
11395    return ROK;
11396 }
11397
11398 /*******************************************************************
11399  *
11400  * @brief Fills PuschCfg received by CU
11401  *
11402  * @details
11403  *
11404  *    Function : extractPuschCfg
11405  *
11406  *    Functionality: Fills PuschCfg received  by CU
11407  *
11408  * @params[in] BWP_UplinkDedicated__pusch_Config *cuPuschCfg,
11409  *             PuschCfg *macPuschCfg
11410  * @return void
11411  *
11412  * ****************************************************************/
11413
11414 void extractPuschCfg(struct BWP_UplinkDedicated__pusch_Config *cuPuschCfg, PuschCfg *macPuschCfg)
11415 {
11416    uint8_t timeDomIdx = 0;
11417    DMRS_UplinkConfig_t *dmrsUlCfg = NULLP;
11418    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList = NULLP;
11419
11420    if(cuPuschCfg->present == BWP_UplinkDedicated__pusch_Config_PR_setup)
11421    {
11422       if(cuPuschCfg->choice.setup)
11423       {
11424          if(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH)
11425          {
11426              macPuschCfg->dataScramblingId = \
11427                 *(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH);
11428          }
11429          if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA)
11430          {
11431             if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->present == PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup)
11432             {
11433                if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup)
11434                {
11435                   dmrsUlCfg = (cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup);
11436                   if(dmrsUlCfg->dmrs_AdditionalPosition)
11437                   {
11438                      macPuschCfg->dmrsUlCfgForPuschMapTypeA.addPos =\
11439                         *(dmrsUlCfg->dmrs_AdditionalPosition);
11440                   }
11441                   if(dmrsUlCfg->transformPrecodingDisabled)
11442                   {
11443                      if(dmrsUlCfg->transformPrecodingDisabled->scramblingID0)
11444                      {
11445                         macPuschCfg->dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0 = \
11446                            *(dmrsUlCfg->transformPrecodingDisabled->scramblingID0);
11447                      }
11448                   }
11449                }
11450             }
11451          }
11452          /*Res Alloc Type for UL */
11453          if(cuPuschCfg->choice.setup->resourceAllocation)
11454          {
11455             macPuschCfg->resourceAllocType = \
11456                cuPuschCfg->choice.setup->resourceAllocation;
11457          }
11458          if(cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList)
11459          {
11460             timeDomAllocList = cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList;
11461             if(timeDomAllocList->present == PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup)
11462             {
11463                if(timeDomAllocList->choice.setup)
11464                {
11465                   macPuschCfg->numTimeDomRsrcAlloc = timeDomAllocList->choice.setup->list.count;
11466                   for(timeDomIdx = 0; timeDomIdx <timeDomAllocList->choice.setup->list.count; timeDomIdx++)
11467                   {
11468                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].k2 = \
11469                         *(timeDomAllocList->choice.setup->list.array[timeDomIdx]->k2);
11470                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].mappingType = \
11471                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->mappingType;
11472                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].startSymbolAndLength = \
11473                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11474                   }
11475                }
11476             }
11477          }
11478          if(cuPuschCfg->choice.setup->transformPrecoder)
11479             macPuschCfg->transformPrecoder = *(cuPuschCfg->choice.setup->transformPrecoder);
11480       }
11481    }
11482 }
11483
11484 /*******************************************************************
11485  *
11486  * @brief Function to fill pucch Power Control
11487  *
11488  * @details
11489  *
11490  *    Function : extractPucchPowerControl
11491  *
11492  *    Functionality: Function to fill pucch Power Control
11493  *
11494  * @params[in] PucchPowerControl *pwrCtrl,
11495  *             struct PUCCH_PowerControl *cuPwrCtrlCfg
11496  * @return void
11497  *
11498  * ****************************************************************/
11499
11500 void extractPucchPowerControl(PucchPowerControl *pwrCtrl, struct PUCCH_PowerControl *cuPwrCtrlCfg)
11501 {
11502    uint8_t arrIdx;
11503
11504    if(cuPwrCtrlCfg->deltaF_PUCCH_f0)
11505       pwrCtrl->deltaF_Format0 = *cuPwrCtrlCfg->deltaF_PUCCH_f0;
11506    if(cuPwrCtrlCfg->deltaF_PUCCH_f1)
11507       pwrCtrl->deltaF_Format1 = *cuPwrCtrlCfg->deltaF_PUCCH_f1;
11508    if(cuPwrCtrlCfg->deltaF_PUCCH_f2)
11509       pwrCtrl->deltaF_Format2 = *cuPwrCtrlCfg->deltaF_PUCCH_f2;
11510    if(cuPwrCtrlCfg->deltaF_PUCCH_f3)
11511       pwrCtrl->deltaF_Format3 = *cuPwrCtrlCfg->deltaF_PUCCH_f3;
11512    if(cuPwrCtrlCfg->deltaF_PUCCH_f4)
11513       pwrCtrl->deltaF_Format4 = *cuPwrCtrlCfg->deltaF_PUCCH_f4;
11514    if(cuPwrCtrlCfg->p0_Set)
11515    {
11516       pwrCtrl->p0SetCount = cuPwrCtrlCfg->p0_Set->list.count;
11517       for(arrIdx=0; arrIdx < pwrCtrl->p0SetCount; arrIdx++)
11518       {
11519          pwrCtrl->p0Set[arrIdx].p0PucchId =\
11520             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Id;
11521          pwrCtrl->p0Set[arrIdx].p0PucchVal =\
11522             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Value;
11523       }
11524    }
11525    if(cuPwrCtrlCfg->pathlossReferenceRSs)
11526    {
11527       pwrCtrl->pathLossRefRSListCount = cuPwrCtrlCfg->pathlossReferenceRSs->list.count;
11528       for(arrIdx = 0; arrIdx < pwrCtrl->pathLossRefRSListCount; arrIdx++)
11529       {
11530          pwrCtrl->pathLossRefRSList[arrIdx].pathLossRefRSId =\
11531             cuPwrCtrlCfg->pathlossReferenceRSs->list.array[arrIdx]->pucch_PathlossReferenceRS_Id;
11532       }
11533    }
11534 }
11535  
11536  /*******************************************************************
11537  *
11538  * @brief Function to extractResrcSetToAddModList sent by CU
11539  *
11540  * @details
11541  *
11542  *    Function : extractResrcSetToAddModList
11543  *
11544  *    Functionality: Fucntion to extractResrcSetToAddModList
11545  *
11546  * @params[in] PucchResrcSetCfg pointer,
11547  *             struct PUCCH_Config__resourceSetToAddModList pointer
11548  * @return void
11549  *
11550  * ****************************************************************/
11551
11552 void extractResrcSetToAddModList(PucchResrcSetCfg *macRsrcSetList, struct PUCCH_Config__resourceSetToAddModList *cuRsrcSetList)
11553 {
11554    uint8_t arrIdx, rsrcListIdx;
11555
11556    macRsrcSetList->resrcSetToAddModListCount = cuRsrcSetList->list.count; 
11557    for(arrIdx = 0; arrIdx < macRsrcSetList->resrcSetToAddModListCount; arrIdx++)
11558    {
11559       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcSetId     =\
11560          cuRsrcSetList->list.array[arrIdx]->pucch_ResourceSetId;
11561       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount =\
11562          cuRsrcSetList->list.array[arrIdx]->resourceList.list.count;
11563       for(rsrcListIdx = 0; rsrcListIdx < macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount; rsrcListIdx++)
11564       {
11565          macRsrcSetList->resrcSetToAddModList[arrIdx].resrcList[rsrcListIdx] =\
11566             *cuRsrcSetList->list.array[arrIdx]->resourceList.list.array[rsrcListIdx];
11567       }
11568
11569       if(cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1)
11570       {
11571          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize =\
11572             *cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1;
11573       }
11574       else
11575       {
11576          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize = 0;
11577       }
11578    }
11579 }/* End of extractResrcSetToAddModList */
11580
11581 /*******************************************************************
11582  *
11583  * @brief Fills extractResrcToAddModList sent by CU
11584  *
11585  * @details
11586  *
11587  *    Function : extractResrcToAddModList
11588  *
11589  *    Functionality: Fills extractResrcToAddModList
11590  *
11591  * @params[in] PucchResrcCfg pointer,
11592  *             struct PUCCH_Config__resourceToAddModList pointer
11593  * @return ROk/RFAILED
11594  *
11595  * ****************************************************************/
11596
11597 uint8_t extractResrcToAddModList(PucchResrcCfg *macResrcList, struct PUCCH_Config__resourceToAddModList *cuResrcList)
11598 {
11599    uint8_t arrIdx;
11600    
11601    macResrcList->resrcToAddModListCount = cuResrcList->list.count;
11602    for(arrIdx = 0; arrIdx < macResrcList->resrcToAddModListCount; arrIdx++)
11603    {
11604       macResrcList->resrcToAddModList[arrIdx].resrcId      =\
11605         cuResrcList->list.array[arrIdx]->pucch_ResourceId; 
11606       macResrcList->resrcToAddModList[arrIdx].startPrb     =\
11607         cuResrcList->list.array[arrIdx]->startingPRB;
11608       if(cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping)
11609       {
11610          macResrcList->resrcToAddModList[arrIdx].intraFreqHop =\
11611            *cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping;
11612       }
11613       if(cuResrcList->list.array[arrIdx]->secondHopPRB)
11614       {
11615          macResrcList->resrcToAddModList[arrIdx].secondPrbHop =\
11616            *cuResrcList->list.array[arrIdx]->secondHopPRB;
11617       }
11618       /* PUCCH RSRC FORMAT */
11619       if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format0)
11620       {
11621          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_0;
11622          if(cuResrcList->list.array[arrIdx]->format.choice.format0)
11623          {
11624             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0, sizeof(PucchFormat0));
11625             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0 == NULLP)
11626             {
11627                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format0 in extractResrcToAddModList()");
11628                return RFAILED;
11629             }
11630             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->initialCyclicShift =\
11631                cuResrcList->list.array[arrIdx]->format.choice.format0->initialCyclicShift;
11632             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->numSymbols =\
11633                cuResrcList->list.array[arrIdx]->format.choice.format0->nrofSymbols;
11634             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->startSymbolIdx =\
11635                cuResrcList->list.array[arrIdx]->format.choice.format0->startingSymbolIndex;
11636          }
11637       }
11638       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format1)
11639       {
11640          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_1;
11641          if(cuResrcList->list.array[arrIdx]->format.choice.format1)
11642          {
11643             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1, sizeof(PucchFormat1));
11644             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1 == NULLP)
11645             {
11646                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format1 in extractResrcToAddModList()");
11647                return RFAILED;
11648             }
11649             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->initialCyclicShift =\
11650                 cuResrcList->list.array[arrIdx]->format.choice.format1->initialCyclicShift;
11651             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->numSymbols =\
11652                 cuResrcList->list.array[arrIdx]->format.choice.format1->nrofSymbols;
11653             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->startSymbolIdx =\
11654                 cuResrcList->list.array[arrIdx]->format.choice.format1->startingSymbolIndex;
11655             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->timeDomOCC =\
11656                 cuResrcList->list.array[arrIdx]->format.choice.format1->timeDomainOCC;
11657          }
11658       }
11659       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format2)
11660       {
11661          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_2;
11662          if(cuResrcList->list.array[arrIdx]->format.choice.format2)
11663          {
11664             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
11665             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2 == NULLP)
11666             {
11667                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format2 in extractResrcToAddModList()");
11668                return RFAILED;
11669             }
11670             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numPrbs =\
11671                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofPRBs;
11672             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numSymbols =\
11673                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofSymbols;
11674             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->startSymbolIdx =\
11675                 cuResrcList->list.array[arrIdx]->format.choice.format2->startingSymbolIndex;
11676          }
11677       }
11678       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format3)
11679       {
11680          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_3;
11681          if(cuResrcList->list.array[arrIdx]->format.choice.format3)
11682          {
11683             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
11684             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3 == NULLP)
11685             {
11686                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format3 in extractResrcToAddModList()");
11687                return RFAILED;
11688             }
11689             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numPrbs =\
11690                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofPRBs;
11691             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numSymbols =\
11692                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofSymbols;
11693             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->startSymbolIdx =\
11694                 cuResrcList->list.array[arrIdx]->format.choice.format3->startingSymbolIndex;
11695          }
11696       }
11697       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format4)
11698       {
11699          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_4;
11700          if(cuResrcList->list.array[arrIdx]->format.choice.format4)
11701          {
11702             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4, sizeof(PucchFormat4));
11703             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4 == NULLP)
11704             {
11705                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format4 in extractResrcToAddModList()");
11706                return RFAILED;
11707             }
11708             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->numSymbols =\
11709                 cuResrcList->list.array[arrIdx]->format.choice.format4->nrofSymbols;
11710             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occLen =\
11711                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Length;
11712             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occIdx =\
11713                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Index;
11714             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->startSymbolIdx =\
11715                 cuResrcList->list.array[arrIdx]->format.choice.format4->startingSymbolIndex;
11716          }
11717       }
11718    }
11719    return ROK;
11720
11721 }/* End of extractResrcToAddModList */
11722
11723 /*******************************************************************
11724  *
11725  * @brief Fills fillPucchSchedReqPeriodAndOffset sent by CU
11726  *
11727  * @details
11728  *
11729  *    Function : fillPucchSchedReqPeriodAndOffset
11730  *
11731  *    Functionality: To fillPucchSchedReqPeriodAndOffset
11732  *
11733  * @params[in] macPeriodicty,
11734  *     SchedulingRequestResourceConfig__periodicityAndOffset pointer
11735  * @return void
11736  *
11737  * ****************************************************************/
11738
11739 void fillPucchSchedReqPeriodAndOffset(uint8_t macPeriodicty, uint16_t  macOffset,\
11740    struct SchedulingRequestResourceConfig__periodicityAndOffset *cuPeriodicty)
11741 {
11742    macPeriodicty = cuPeriodicty->present;
11743    switch(macPeriodicty)
11744    {
11745       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
11746          {
11747             macOffset     = cuPeriodicty->choice.sym2;
11748             break;
11749          }
11750       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
11751          {
11752             macOffset     = cuPeriodicty->choice.sym6or7;
11753             break;
11754          }
11755       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
11756          {
11757             macOffset     = cuPeriodicty->choice.sl1;
11758             break;
11759          }
11760       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
11761          {
11762             macOffset = cuPeriodicty->choice.sl2;
11763             break;
11764          }
11765       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
11766          {
11767             macOffset = cuPeriodicty->choice.sl4;
11768             break;
11769          }
11770       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
11771          {
11772             macOffset = cuPeriodicty->choice.sl5;
11773             break;
11774          }
11775       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
11776          {
11777             macOffset = cuPeriodicty->choice.sl8;
11778             break;
11779          }
11780       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
11781          {
11782             macOffset = cuPeriodicty->choice.sl10;
11783             break;
11784          }
11785       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
11786          {
11787             macOffset = cuPeriodicty->choice.sl16;
11788             break;
11789          }
11790       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
11791          {
11792             macOffset = cuPeriodicty->choice.sl20;
11793             break;
11794          }
11795       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
11796          {
11797             macOffset = cuPeriodicty->choice.sl40;
11798             break;
11799          }
11800       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
11801          {
11802             macOffset = cuPeriodicty->choice.sl80;
11803             break;
11804          }
11805       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
11806          {
11807             macOffset = cuPeriodicty->choice.sl160;
11808             break;
11809          }
11810       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
11811          {
11812             macOffset = cuPeriodicty->choice.sl320;
11813             break;
11814          }
11815       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
11816          {
11817             macOffset = cuPeriodicty->choice.sl640;
11818             break;
11819          }
11820       default :
11821          DU_LOG("\nERROR  -->  F1AP : Invalid periodicity %d", macPeriodicty);
11822    }
11823 }
11824
11825 /*******************************************************************
11826  *
11827  * @brief Function to extractPucchFormatCfg sent by CU
11828  *
11829  * @details
11830  *
11831  *    Function : extractPucchFormatCfg
11832  *
11833  *    Functionality: Function to extractPucchFormatCfg
11834  *
11835  * @params[in] PucchFormatCfg pointer,
11836  *             PUCCH_FormatConfig_t pointer
11837  * @return void
11838  *
11839  * ****************************************************************/
11840
11841 void extractPucchFormatCfg(PucchFormatCfg *macFormatCfg, PUCCH_FormatConfig_t *cuFormatCfg)
11842  {
11843     if(cuFormatCfg->interslotFrequencyHopping)
11844        macFormatCfg->interSlotFreqHop = *cuFormatCfg->interslotFrequencyHopping;
11845     if(cuFormatCfg->additionalDMRS)  
11846        macFormatCfg->addDmrs = *cuFormatCfg->additionalDMRS;
11847     if(cuFormatCfg->maxCodeRate)
11848        macFormatCfg->maxCodeRate = *cuFormatCfg->maxCodeRate;
11849     if(cuFormatCfg->nrofSlots)  
11850        macFormatCfg->numSlots = *cuFormatCfg->nrofSlots;
11851     if(cuFormatCfg->pi2BPSK)  
11852        macFormatCfg->pi2BPSK = *cuFormatCfg->pi2BPSK;
11853     if(cuFormatCfg->simultaneousHARQ_ACK_CSI)  
11854        macFormatCfg->harqAckCSI = *cuFormatCfg->simultaneousHARQ_ACK_CSI;
11855  }/* End of extractPucchFormatCfg */
11856
11857 /*******************************************************************
11858  *
11859  * @brief Function to extractSchedReqCfgToAddMod sent by CU
11860  *
11861  * @details
11862  *
11863  *    Function : extractSchedReqCfgToAddMod
11864  *
11865  *    Functionality: Function to extractSchedReqCfgToAddMod
11866  *
11867  * @params[in] PucchSchedReqCfg pointer,
11868  *      PUCCH_Config__schedulingRequestResourceToAddModList pointer
11869  * @return void
11870  *
11871  * ****************************************************************/
11872
11873 void extractSchedReqCfgToAddMod(PucchSchedReqCfg *macSchedReqCfg, struct PUCCH_Config__schedulingRequestResourceToAddModList *cuSchedReqList)
11874 {
11875    uint8_t arrIdx;
11876
11877    macSchedReqCfg->schedAddModListCount = cuSchedReqList->list.count;
11878    for(arrIdx = 0; arrIdx <  macSchedReqCfg->schedAddModListCount; arrIdx++)
11879    {
11880       macSchedReqCfg->schedAddModList[arrIdx].resrcId =\
11881          cuSchedReqList->list.array[arrIdx]->schedulingRequestResourceId;
11882       macSchedReqCfg->schedAddModList[arrIdx].requestId =\
11883          cuSchedReqList->list.array[arrIdx]->schedulingRequestID;
11884       if(cuSchedReqList->list.array[arrIdx]->periodicityAndOffset)
11885       {
11886          fillPucchSchedReqPeriodAndOffset(macSchedReqCfg->schedAddModList[arrIdx].periodicity,\
11887             macSchedReqCfg->schedAddModList[arrIdx].offset, cuSchedReqList->list.array[arrIdx]->periodicityAndOffset);
11888       }
11889       if(cuSchedReqList->list.array[arrIdx]->resource)
11890       {
11891          macSchedReqCfg->schedAddModList[arrIdx].resrc =\
11892             *cuSchedReqList->list.array[arrIdx]->resource;
11893       }
11894    }
11895
11896 }/* End of extractSchedReqCfgToAddMod */
11897
11898  /*******************************************************************
11899  *
11900  * @brief Fills PucchCfg received by CU
11901  *
11902  * @details
11903  *
11904  *    Function : extractPucchCfg
11905  *
11906  *    Functionality: Fills PucchCfg received  by CU
11907  *
11908  * @params[in] BWP_UplinkDedicated__pucch_Config *cuPucchCfg = Information which
11909  *                is send by CU, which we have stored in F1UeContextSetupDb,
11910  *             PucchCfg *macPucchCfg = Used to Store the information which
11911  *                needs to send in other layer, as well as this can be the variable
11912  *                which stores the information in DuCb,
11913  *             PucchCfg *storedPucchCfg = Null in case of sending the
11914  *                information to other layer else it will have Pucch Cfg which
11915  *                we have stored in copyOfmacUeCfg.
11916  * @return ROK/RFAILED
11917  *
11918  * ****************************************************************/
11919
11920 uint8_t extractPucchCfg(struct BWP_UplinkDedicated__pucch_Config *cuPucchCfg, PucchCfg *macPucchCfg,\
11921 PucchCfg *storedPucchCfg)        
11922 {
11923    uint8_t arrIdx;
11924
11925    if(cuPucchCfg->present == BWP_UplinkDedicated__pucch_Config_PR_setup)
11926    {
11927       if(cuPucchCfg->choice.setup)
11928       {
11929          /* Resource Set Cfg */ 
11930          if(cuPucchCfg->choice.setup->resourceSetToAddModList)
11931          {
11932             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrcSet, sizeof(PucchResrcSetCfg));
11933             if(macPucchCfg->resrcSet == NULLP)
11934             {
11935                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc set List in extractPucchCfg()");
11936                return RFAILED;
11937             }
11938             memset(macPucchCfg->resrcSet, 0, sizeof(PucchResrcSetCfg));
11939             extractResrcSetToAddModList(macPucchCfg->resrcSet, cuPucchCfg->choice.setup->resourceSetToAddModList);
11940          }
11941          
11942          /* Resource Cfg */ 
11943          if(cuPucchCfg->choice.setup->resourceToAddModList)
11944          {
11945             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrc, sizeof(PucchResrcCfg));
11946             if(macPucchCfg->resrc == NULLP)
11947             {
11948                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc List in extractPucchCfg()");
11949                return RFAILED;
11950             }
11951             memset(macPucchCfg->resrc, 0, sizeof(PucchResrcCfg));
11952             extractResrcToAddModList(macPucchCfg->resrc, cuPucchCfg->choice.setup->resourceToAddModList);
11953          }
11954          
11955          /* Format 1 Cfg */ 
11956          if(cuPucchCfg->choice.setup->format1)
11957          {
11958             DU_ALLOC_SHRABL_BUF(macPucchCfg->format1, sizeof(PucchFormatCfg));
11959             if(macPucchCfg->format1 == NULLP)
11960             {
11961                DU_LOG("\nERROR --> F1AP : Failed to extract format 1 Cfg in  extractPucchCfg()");
11962                return RFAILED;
11963             }
11964             memset(macPucchCfg->format1, 0, sizeof(PucchFormatCfg));
11965             extractPucchFormatCfg(macPucchCfg->format1,\
11966                cuPucchCfg->choice.setup->format1->choice.setup);
11967          }
11968          
11969          /* Format 2 Cfg */
11970          if(cuPucchCfg->choice.setup->format2)
11971          {
11972             DU_ALLOC_SHRABL_BUF(macPucchCfg->format2, sizeof(PucchFormatCfg));
11973             if(macPucchCfg->format2 == NULLP)
11974             {
11975                DU_LOG("\nERROR --> F1AP : Failed to extract format 2 Cfg in  extractPucchCfg()");
11976                return RFAILED;
11977             }
11978             memset(macPucchCfg->format2, 0, sizeof(PucchFormatCfg));
11979             extractPucchFormatCfg(macPucchCfg->format2,\
11980                cuPucchCfg->choice.setup->format2->choice.setup);
11981          }
11982          
11983          /* Format 3 Cfg */
11984          if(cuPucchCfg->choice.setup->format3)
11985          {
11986             DU_ALLOC_SHRABL_BUF(macPucchCfg->format3, sizeof(PucchFormatCfg));
11987             if(macPucchCfg->format3 == NULLP)
11988             {
11989                DU_LOG("\nERROR --> F1AP : Failed to extract format 3 Cfg in  extractPucchCfg()");
11990                return RFAILED;
11991             }
11992             memset(macPucchCfg->format3, 0, sizeof(PucchFormatCfg));
11993             extractPucchFormatCfg(macPucchCfg->format3,\
11994                cuPucchCfg->choice.setup->format3->choice.setup);
11995          }
11996
11997          /* Format 4 Cfg */
11998          if(cuPucchCfg->choice.setup->format4)
11999          {
12000             DU_ALLOC_SHRABL_BUF(macPucchCfg->format4, sizeof(PucchFormatCfg));
12001             if(macPucchCfg->format4 == NULLP)
12002             {
12003                DU_LOG("\nERROR --> F1AP : Failed to extract format 4 Cfg in  extractPucchCfg()");
12004                return RFAILED;
12005             }
12006             memset(macPucchCfg->format4, 0, sizeof(PucchFormatCfg));
12007             extractPucchFormatCfg(macPucchCfg->format4,\
12008                cuPucchCfg->choice.setup->format4->choice.setup);
12009          }
12010
12011          /* Sched Req List */
12012          if(cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList)
12013          {
12014             DU_ALLOC_SHRABL_BUF(macPucchCfg->schedReq, sizeof(PucchSchedReqCfg));
12015             if(macPucchCfg->schedReq == NULLP)
12016             {
12017                DU_LOG("\nERROR --> F1AP : Failed to extract schedReqCfg in  extractPucchCfg()");
12018                return RFAILED;
12019             }
12020             memset(macPucchCfg->schedReq, 0, sizeof(PucchSchedReqCfg));
12021             extractSchedReqCfgToAddMod(macPucchCfg->schedReq,\
12022             cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList);
12023          }
12024
12025          /*TODO: Add support for  Spatial Info */
12026
12027          /* MultiCsiCfg */
12028          if(cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList)
12029          {
12030             DU_ALLOC_SHRABL_BUF(macPucchCfg->multiCsiCfg, sizeof(PucchMultiCsiCfg));
12031             if(macPucchCfg->multiCsiCfg == NULLP)
12032             {
12033                DU_LOG("\nERROR --> F1AP : Failed to extract multiCsiCfg in  extractPucchCfg()");
12034                return RFAILED;
12035             }
12036             memset(macPucchCfg->multiCsiCfg, 0, sizeof(PucchMultiCsiCfg));
12037             macPucchCfg->multiCsiCfg->multiCsiResrcListCount = cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.count;
12038             for(arrIdx =0; arrIdx < macPucchCfg->multiCsiCfg->multiCsiResrcListCount; arrIdx++)
12039             {
12040                macPucchCfg->multiCsiCfg->multiCsiResrcList[arrIdx] =\
12041                  *cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.array[arrIdx];
12042             }
12043          }
12044
12045          /* Dl_DataToUL_ACK */ 
12046          if(cuPucchCfg->choice.setup->dl_DataToUL_ACK)
12047     {
12048        if(storedPucchCfg)
12049        {
12050           if(storedPucchCfg->dlDataToUlAck)
12051           {
12052              macPucchCfg->dlDataToUlAck = storedPucchCfg->dlDataToUlAck; 
12053           }
12054           else
12055           {
12056             DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
12057           }
12058        }
12059        else
12060        {
12061           DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
12062        }
12063        if(macPucchCfg->dlDataToUlAck == NULLP)
12064        {
12065           DU_LOG("\nERROR --> F1AP : Failed to extract Dl_DataToUL_ACK in extractPucchCfg()");
12066           return RFAILED;
12067        }
12068        memset(macPucchCfg->dlDataToUlAck, 0, sizeof(PucchDlDataToUlAck));
12069        macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount = cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.count;
12070        for(arrIdx = 0; arrIdx < macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; arrIdx++)
12071        {
12072           macPucchCfg->dlDataToUlAck->dlDataToUlAckList[arrIdx] =\
12073           *cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.array[arrIdx];
12074        }
12075          }
12076
12077          /* Power Control */
12078          if(cuPucchCfg->choice.setup->pucch_PowerControl)
12079          {
12080             DU_ALLOC_SHRABL_BUF(macPucchCfg->powerControl, sizeof(PucchPowerControl));
12081             if(macPucchCfg->powerControl == NULLP)
12082             {
12083                DU_LOG("\nERROR --> F1AP : Failed to extract power control in extractPucchCfg()");
12084                return RFAILED;
12085             }
12086             extractPucchPowerControl(macPucchCfg->powerControl,\
12087                cuPucchCfg->choice.setup->pucch_PowerControl);
12088          }
12089       }
12090    }
12091    return ROK;
12092 }
12093
12094 /*******************************************************************
12095  *
12096  * @brief Fills ServingCellReconfig received by CU
12097  *
12098  * @details
12099  *
12100  *    Function : extractSpCellDedicatedCfg
12101  *
12102  *    Functionality: Fills ServingCellReconfig received  by CU
12103  *
12104  * @params[in] ServingCellConfig_t *cuSrvCellCfg = Information which is send by
12105  *                  CU, which we have stored in F1UeContextSetupDb,
12106  *             ServCellCfgInfo *macSrvCellCfg = Used to Store the information
12107  *                  which  needs to send in other layer, as well as this can be the
12108  *                  variable which stores the information in DuCb, 
12109  *             ServCellCfgInfo *storedSrvCellCfg = Null in case of sending the
12110  *                  information to other layer else it will have ServCellCfgInfo which
12111  *                  we have stored in copyOfmacUeCfg.
12112  * @return ROK/RFAILD
12113  *
12114  * ****************************************************************/
12115 uint8_t extractSpCellDedicatedCfg(ServingCellConfig_t *cuSrvCellCfg, ServCellRecfgInfo *macSrvCellCfg,\
12116 ServCellRecfgInfo *storedSrvCellCfg)
12117 {
12118    uint8_t ret = ROK;
12119    BWP_DownlinkDedicated_t *dlBwp = NULLP;
12120    BWP_UplinkDedicated_t   *ulBwp = NULLP;
12121
12122    if(cuSrvCellCfg->initialDownlinkBWP)
12123    {
12124       dlBwp = ((BWP_DownlinkDedicated_t *)(cuSrvCellCfg->initialDownlinkBWP));
12125       if(dlBwp->pdcch_Config)
12126       {
12127          if(dlBwp->pdcch_Config->choice.setup)
12128          {
12129             macSrvCellCfg->initDlBwp.pdcchPresent = true;
12130             if(storedSrvCellCfg)
12131             {
12132                if(!storedSrvCellCfg->initDlBwp.pdcchPresent)
12133                {
12134                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12135                }
12136                else
12137                {
12138                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12139                }
12140             }
12141             else
12142             {
12143                extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12144             }
12145          }
12146       }
12147       if(dlBwp->pdsch_Config)
12148       {
12149          if(dlBwp->pdsch_Config->choice.setup)
12150          {
12151             macSrvCellCfg->initDlBwp.pdschPresent = true;
12152             
12153             if(storedSrvCellCfg)
12154             {
12155                if(!storedSrvCellCfg->initDlBwp.pdschPresent)
12156                {
12157                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
12158                }
12159                else
12160                {
12161                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg,\
12162                         &storedSrvCellCfg->initDlBwp.pdschCfg);
12163                }
12164             }
12165             else
12166             {
12167                extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
12168             }
12169          }
12170       }
12171    }
12172    if(cuSrvCellCfg->firstActiveDownlinkBWP_Id)
12173       macSrvCellCfg->firstActvDlBwpId = *(cuSrvCellCfg->firstActiveDownlinkBWP_Id);
12174    if(cuSrvCellCfg->defaultDownlinkBWP_Id)
12175       macSrvCellCfg->defaultDlBwpId = *(cuSrvCellCfg->defaultDownlinkBWP_Id);
12176    if(cuSrvCellCfg->bwp_InactivityTimer)
12177    {
12178       if(macSrvCellCfg->bwpInactivityTmr)
12179       {
12180          memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
12181       }
12182       else
12183       {
12184          macSrvCellCfg->bwpInactivityTmr = NULLP;
12185          DU_ALLOC_SHRABL_BUF(macSrvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
12186          if(macSrvCellCfg->bwpInactivityTmr)
12187          {
12188             memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
12189          }
12190          else
12191          {
12192             DU_LOG("\nERROR  --> F1AP : Memory Alloc failed for bwpInactivityTmr at extractSpCellDedicatedCfg()");
12193             return RFAILED;
12194          }
12195       }
12196    }
12197    if(cuSrvCellCfg->pdsch_ServingCellConfig)
12198    {
12199       if(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup)
12200       {
12201          ret = extractPdschServingCellCfg(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup, &macSrvCellCfg->pdschServCellCfg);
12202          if(ret == RFAILED)
12203          {
12204             DU_LOG("\nERROR --> F1AP : Failed at extractPdschServingCellCfg()");
12205             return RFAILED;
12206          }
12207       }
12208    }
12209    if(cuSrvCellCfg->uplinkConfig)
12210    {
12211       if(cuSrvCellCfg->uplinkConfig->initialUplinkBWP)
12212       {
12213          ulBwp = ((BWP_UplinkDedicated_t *)(cuSrvCellCfg->uplinkConfig->initialUplinkBWP));
12214          if(ulBwp->pusch_Config)
12215          {
12216             macSrvCellCfg->initUlBwp.puschPresent = true;
12217             extractPuschCfg(ulBwp->pusch_Config, &macSrvCellCfg->initUlBwp.puschCfg);
12218          }
12219          if(ulBwp->pucch_Config)
12220          {
12221             macSrvCellCfg->initUlBwp.pucchPresent = true;
12222             memset(&macSrvCellCfg->initUlBwp.pucchCfg, 0, sizeof(PucchCfg));
12223             if(storedSrvCellCfg)
12224             {
12225                if(!storedSrvCellCfg->initUlBwp.pucchPresent)
12226                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
12227                else
12228                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg,\
12229                   &storedSrvCellCfg->initUlBwp.pucchCfg);
12230             }
12231             else
12232             {
12233                extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
12234             }
12235          }
12236       }
12237       if(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id)
12238          macSrvCellCfg->firstActvUlBwpId = *(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id);
12239    }
12240    return ret;
12241 }
12242
12243 #ifdef NR_DRX
12244
12245 /*******************************************************************
12246  *
12247  * @brief fill long cycle offset value of drx in UE structure
12248  *
12249  * @details
12250  *
12251  *    Function : fillLongCycleOffsetValueInUeDb
12252  *
12253  *    Functionality: fill long cycle offset value of drx in UE structure
12254  *
12255  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
12256  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
12257  *
12258  * @return ROK     - success
12259  *         RFAILED - failure
12260  *
12261  * ****************************************************************/
12262 void fillLongCycleOffsetValueInUeDb(DrxLongCycleStartOffset *drxLongCycleStartOffset, struct DRX_ConfigRrc__drx_LongCycleStartOffset  *drx_LongCycleStartOffset)
12263 {
12264
12265    drxLongCycleStartOffset->drxLongCycleStartOffsetChoice = convertLongDrxCycleLengthEnumToValue(drx_LongCycleStartOffset->present);
12266    switch(drx_LongCycleStartOffset->present)
12267    {
12268       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
12269          {
12270             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10;
12271             break;
12272          }
12273       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
12274          {
12275             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms20;
12276             break;
12277          }
12278       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
12279          {
12280             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms32;
12281             break;
12282          }
12283       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
12284         {
12285             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms40;
12286             break;
12287          }
12288       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
12289          {
12290             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms60;
12291             break;
12292          }
12293       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
12294          {
12295             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms64;
12296             break;
12297          }
12298       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
12299          {
12300             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms70;
12301             break;
12302          }
12303       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
12304          {
12305             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms80;
12306             break;
12307          }
12308       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
12309          {
12310             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms128;
12311             break;
12312          }
12313       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
12314          {
12315             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms160;
12316             break;
12317          }
12318       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
12319          {
12320             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms256;
12321             break;
12322          }
12323       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
12324          {
12325             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms320;
12326             break;
12327          }
12328       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
12329          {
12330             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms512;
12331             break;
12332          }
12333       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
12334          {
12335             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms640;
12336             break;
12337          }
12338       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
12339          {
12340             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1024;
12341             break;
12342          }
12343       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
12344          {
12345             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1280;
12346             break;
12347          }
12348       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
12349          {
12350             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2048;
12351             break;
12352          }
12353       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
12354          {
12355             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2560;
12356             break;
12357          }
12358        case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
12359          {
12360             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms5120;
12361             break;
12362          }
12363       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
12364          {
12365             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10240;
12366             break;
12367          }
12368       default :
12369          break;
12370    }
12371 }
12372
12373 /*******************************************************************
12374  *
12375  * @brief Fills drx configuration structure with the help of drx_ConfigRrc
12376  *which recive from CU or storedDrxCfg which is already stored
12377  *
12378  * @details
12379  *
12380  *    Function : extractDrxConfiguration 
12381  *
12382  *    Functionality: Fills Reconfig Cell group Info received by CU
12383  *   
12384  * @params[in] cuMacCellGrpDrxConfig  = MAC_CellGroupConfig__drx_ConfigRrc information which
12385  *                       is send by CU, which we have stored in F1UeContextSetupDb
12386  *             DrxCfg * drxCfg  = Used to Store the information,
12387  *                      which needs to send in other layer, as well as this can be
12388  *                      the variable which stores the information in DuCb,
12389  *             DrxCfg *storedDrxCfg = Null in case of sending the
12390  *                      information to other layer else it will have the drx information 
12391  *                      stored in the copyOfmacUeCfg which we have stored in F1UeContextSetupDb.
12392  *
12393  * @return void
12394  *
12395  * ****************************************************************/
12396 void extractDrxConfiguration(struct MAC_CellGroupConfig__drx_ConfigRrc *cuMacCellGrpDrxConfig, DrxCfg * drxCfg, DrxCfg *storedDrxCfg)
12397 {
12398    struct DRX_ConfigRrc *cuDrxConfig;
12399
12400    if(storedDrxCfg)
12401    {
12402       memcpy(drxCfg, storedDrxCfg, sizeof(DrxCfg));
12403    }
12404    else
12405    {
12406       if(cuMacCellGrpDrxConfig)
12407       {
12408          switch(cuMacCellGrpDrxConfig->present)
12409          {
12410             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
12411                break;
12412
12413             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
12414                {
12415                   cuDrxConfig = cuMacCellGrpDrxConfig->choice.setup;
12416                   if(cuDrxConfig)
12417                   {
12418                      switch(cuDrxConfig->drx_onDurationTimer.present)
12419                      {
12420                         case DRX_ConfigRrc__drx_onDurationTimer_PR_NOTHING:
12421                            break;
12422                         case DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds:
12423                            {
12424                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = true;
12425                               drxCfg->drxOnDurationTimer.onDurationtimerValue.milliSeconds=convertOnDurationTimerMilliSecondsEnumToValue(cuDrxConfig->\
12426                               drx_onDurationTimer.choice.milliSeconds);
12427                               break;
12428                            }
12429                         case DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds:
12430                            {
12431                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = false;
12432                               drxCfg->drxOnDurationTimer.onDurationtimerValue.subMilliSeconds = cuDrxConfig->drx_onDurationTimer.choice.subMilliSeconds;
12433                               break;
12434                            }
12435                      }
12436                   }
12437                   fillLongCycleOffsetValueInUeDb(&drxCfg->drxLongCycleStartOffset, &cuDrxConfig->drx_LongCycleStartOffset);
12438                   drxCfg->drxInactivityTimer = convertDrxInactivityTimerEnumToValue(cuDrxConfig->drx_InactivityTimer);
12439                   drxCfg->drxHarqRttTimerDl = cuDrxConfig->drx_HARQ_RTT_TimerDL;
12440                   drxCfg->drxHarqRttTimerUl = cuDrxConfig->drx_HARQ_RTT_TimerUL;
12441                   drxCfg->drxRetransmissionTimerDl = convertDrxRetransmissionTimerDlEnumToValue(cuDrxConfig->drx_RetransmissionTimerDL);
12442                   drxCfg->drxRetransmissionTimerUl = convertDrxRetransmissionTimerUlEnumToValue(cuDrxConfig->drx_RetransmissionTimerUL);
12443                   drxCfg->drxSlotOffset = cuDrxConfig->drx_SlotOffset;
12444                   if(cuDrxConfig->shortDRX)
12445                   {
12446                      drxCfg->shortDrxPres=true;
12447                      drxCfg->shortDrx.drxShortCycle = convertShortDrxCycleLengthEnumToValue(cuDrxConfig->shortDRX->drx_ShortCycle);
12448                      drxCfg->shortDrx.drxShortCycleTimer = cuDrxConfig->shortDRX->drx_ShortCycleTimer;
12449                   }
12450                   else
12451                      drxCfg->shortDrxPres=false;
12452
12453                   break;
12454                }
12455
12456             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
12457                break;
12458          }
12459       }
12460    }
12461 }
12462 #endif
12463
12464 /*******************************************************************
12465  *
12466  * @brief Fills Reconfig Cell group Info received by CU
12467  *
12468  * @details
12469  *
12470  *    Function : extractUeRecfgCellInfo
12471  *
12472  *    Functionality: Fills Reconfig Cell group Info received by CU
12473  *   
12474  * @params[in] CellGroupConfigRrc_t *cellGrp = CellGroupConfigRrc_t information which
12475  *                       is send by CU, which we have stored in F1UeContextSetupDb
12476  *             DuMacUeCfg *MacUeCfg = Used to Store the information,
12477  *                      which needs to send in other layer, as well as this can be
12478  *                      the variable which stores the information in DuCb,
12479  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
12480  *                      information to other layer else it will have copyOfmacUeCfg
12481  *                      which we have stored in F1UeContextSetupDb.
12482  *
12483  * @return ROK/RFAILED
12484  *
12485  * ****************************************************************/
12486 uint8_t extractUeRecfgCellInfo(CellGroupConfigRrc_t *cellGrp, DuMacUeCfg *macUeCfg, DuMacUeCfg *storedMacUeCfg)
12487 {
12488    uint8_t ret = ROK;
12489    MAC_CellGroupConfig_t     *macCellGroup = NULLP;
12490    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
12491    SpCellConfig_t            *spcellCfg = NULLP;
12492    ServingCellConfig_t       *servCellCfg = NULLP;
12493
12494    if(cellGrp)
12495    {
12496       /* Fill MacCell Group Reconfig  */
12497       if(cellGrp->mac_CellGroupConfig)
12498       {
12499          macUeCfg->macCellGrpCfgPres = true;
12500          macCellGroup = ((MAC_CellGroupConfig_t *)(cellGrp->mac_CellGroupConfig));
12501
12502 #ifdef NR_DRX         
12503          if(macCellGroup->drx_ConfigRrc)
12504          {
12505             if(storedMacUeCfg)
12506             {
12507                if(!storedMacUeCfg->macCellGrpCfgPres) 
12508                {
12509                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL);    
12510                }
12511                else
12512                {
12513                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg, &storedMacUeCfg->macCellGrpCfg.drxCfg);    
12514                }
12515             }
12516             else
12517             {
12518                extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL); 
12519             }
12520          }
12521 #endif
12522
12523          if(macCellGroup->schedulingRequestConfig)
12524          {
12525             extractSchReqReConfig(macCellGroup->schedulingRequestConfig, &macUeCfg->macCellGrpCfg.schReqCfg);
12526          }
12527          if(macCellGroup->tag_Config)
12528          {
12529             extractTagReconfig(macCellGroup->tag_Config, &macUeCfg->macCellGrpCfg.tagCfg);
12530          }
12531          if(macCellGroup->bsr_Config)
12532          {
12533             macUeCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer = macCellGroup->bsr_Config->periodicBSR_Timer;
12534             macUeCfg->macCellGrpCfg.bsrTmrCfg.retxTimer     = macCellGroup->bsr_Config->retxBSR_Timer;
12535             if(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer)
12536             {
12537                macUeCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer  =\
12538                *(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer);
12539             }
12540          }
12541          if(macCellGroup->phr_Config)
12542          {
12543             if(macCellGroup->phr_Config->present == MAC_CellGroupConfig__phr_Config_PR_setup)
12544             {
12545                macUeCfg->macCellGrpCfg.phrCfgSetupPres = true;
12546                if(macCellGroup->phr_Config->choice.setup)
12547                {
12548                   macUeCfg->macCellGrpCfg.phrCfg.periodicTimer     = \
12549                   macCellGroup->phr_Config->choice.setup->phr_PeriodicTimer;
12550                   macUeCfg->macCellGrpCfg.phrCfg.prohibitTimer     = \
12551                   macCellGroup->phr_Config->choice.setup->phr_ProhibitTimer;
12552                   macUeCfg->macCellGrpCfg.phrCfg.txPowerFactor     = \
12553                   macCellGroup->phr_Config->choice.setup->phr_Tx_PowerFactorChange;
12554                   macUeCfg->macCellGrpCfg.phrCfg.multiplePHR       = \
12555                   macCellGroup->phr_Config->choice.setup->multiplePHR;
12556                   macUeCfg->macCellGrpCfg.phrCfg.dummy             = \
12557                   macCellGroup->phr_Config->choice.setup->dummy;
12558                   macUeCfg->macCellGrpCfg.phrCfg.phrType2OtherCell = \
12559                   macCellGroup->phr_Config->choice.setup->phr_Type2OtherCell;
12560                   macUeCfg->macCellGrpCfg.phrCfg.phrOtherCG        = \
12561                   macCellGroup->phr_Config->choice.setup->phr_ModeOtherCG;
12562                }
12563             }
12564          }
12565       }
12566       /* Fill Physical Cell Group Reconfig */
12567       if(cellGrp->physicalCellGroupConfig)
12568       {
12569          macUeCfg->phyCellGrpCfgPres = true;
12570          phyCellGrpCfg = ((PhysicalCellGroupConfig_t *)(cellGrp->physicalCellGroupConfig));
12571          if(phyCellGrpCfg->p_NR_FR1)
12572          {
12573             if(*(phyCellGrpCfg->p_NR_FR1) != macUeCfg->phyCellGrpCfg.pNrFr1)
12574                macUeCfg->phyCellGrpCfg.pNrFr1 = *(phyCellGrpCfg->p_NR_FR1);
12575          }
12576          macUeCfg->phyCellGrpCfg.pdschHarqAckCodebook = phyCellGrpCfg->pdsch_HARQ_ACK_Codebook;
12577       }
12578       /* Fill SpCell Reconfig */
12579       if(cellGrp->spCellConfig)
12580       {
12581          macUeCfg->spCellCfgPres = true;
12582          spcellCfg = ((SpCellConfig_t *)(cellGrp->spCellConfig));  
12583          if(spcellCfg->servCellIndex)
12584          {
12585             macUeCfg->spCellCfg.servCellIdx = *(spcellCfg->servCellIndex);
12586          }
12587          /* Fill Serving cell Reconfig info */
12588          if(cellGrp->spCellConfig->spCellConfigDedicated)
12589          {
12590             servCellCfg = ((ServingCellConfig_t *)(cellGrp->spCellConfig->spCellConfigDedicated));
12591             if(storedMacUeCfg)
12592             {
12593                if(!storedMacUeCfg->spCellCfgPres)
12594                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12595                else
12596                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg,\
12597                         &storedMacUeCfg->spCellCfg.servCellCfg);
12598             }
12599             else
12600             {
12601                ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12602             }
12603             if(ret == RFAILED)
12604             {
12605                DU_LOG("\nERROR --> F1AP : Failed at extractSpCellDedicatedCfg()");
12606             }
12607          }
12608       }
12609    }
12610    return ret;
12611 }
12612 /*******************************************************************
12613 *
12614 * @brief free the memory allocated by decoder
12615 *
12616 * @details
12617 *
12618 *    Function : freeAperDecodeNrcgi 
12619 *
12620 *    Functionality: Free Nrcgi values
12621 *
12622 * @params[in] NRCGI_t *nrcgi
12623 * @return void
12624 *
12625 * ****************************************************************/
12626
12627
12628 void freeAperDecodeNrcgi(NRCGI_t *nrcgi)
12629 {
12630     if(nrcgi->pLMN_Identity.buf != NULLP)
12631     {
12632        free(nrcgi->pLMN_Identity.buf);
12633     }
12634     if(nrcgi->nRCellIdentity.buf != NULLP)
12635     {
12636        free(nrcgi->nRCellIdentity.buf);
12637     }
12638 }
12639 /*******************************************************************
12640 *
12641 * @brief free the memory allocated by decoder
12642 *
12643 * @details
12644 *
12645 *    Function : freeAperDecodeCuToDuInfo 
12646 *
12647 *    Functionality:  Free Cu To Du Information
12648 *
12649 * @params[in] CUtoDURRCInformation_t *rrcMsg
12650 * @return void
12651 *
12652 * ****************************************************************/
12653
12654
12655 void freeAperDecodeCuToDuInfo(CUtoDURRCInformation_t *rrcMsg)
12656 {
12657    uint8_t ieIdx =0;
12658    uint8_t arrIdx =0;
12659
12660    if(rrcMsg->uE_CapabilityRAT_ContainerList)
12661    {
12662       if(rrcMsg->uE_CapabilityRAT_ContainerList->buf)
12663          free(rrcMsg->uE_CapabilityRAT_ContainerList->buf);
12664       free(rrcMsg->uE_CapabilityRAT_ContainerList);
12665    }
12666
12667    if(rrcMsg->iE_Extensions)
12668    {
12669       if(rrcMsg->iE_Extensions->list.array)
12670       {
12671          for(ieIdx= 0; ieIdx < rrcMsg->iE_Extensions->list.count; ieIdx++)
12672          {
12673             if(rrcMsg->iE_Extensions->list.array[ieIdx])
12674             {
12675                switch(rrcMsg->iE_Extensions->list.array[ieIdx]->id)
12676                {
12677                   case ProtocolIE_ID_id_CellGroupConfig:
12678                      if(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf != NULLP)
12679                      {
12680                         free(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf);
12681                      }
12682                      break;
12683                   default:
12684                      DU_LOG("\nERROR  -->  F1AP : Invalid Event type %ld at FreeCuToDuInfo()", \
12685                            rrcMsg->iE_Extensions->list.array[ieIdx]->id);
12686                      break;
12687                }
12688             }
12689          }
12690          for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
12691          {
12692             free(rrcMsg->iE_Extensions->list.array[arrIdx]);
12693          }
12694          free(rrcMsg->iE_Extensions->list.array);
12695
12696       }
12697
12698       free(rrcMsg->iE_Extensions);
12699    }
12700 }
12701 /*******************************************************************
12702 *
12703 * @brief free the memory allocated by decoder
12704 *
12705 * @details 
12706 *
12707 *    Function : freeAperDecodeSplCellList
12708 *
12709 *    Functionality: Free Spl Cell List 
12710                     where memory allocated by aper_decoder
12711 *
12712 * @params[in]  SCell_ToBeSetup_List_t *spCellLst
12713 * @return void
12714 *
12715 * ****************************************************************/
12716
12717
12718 void freeAperDecodeSplCellList(SCell_ToBeSetup_List_t *spCellLst)
12719 {
12720     uint8_t  cellIdx =0;
12721
12722     if(spCellLst->list.array != NULLP)
12723     {
12724        for(cellIdx=0; cellIdx<spCellLst->list.count; cellIdx++)
12725        {
12726           if(cellIdx==0&&spCellLst->list.array[cellIdx]!=NULLP)
12727           {
12728              freeAperDecodeNrcgi(&spCellLst->list.array[cellIdx]->value.choice.SCell_ToBeSetup_Item.sCell_ID);
12729           }
12730           if(spCellLst->list.array[cellIdx]!=NULLP)
12731           {
12732              free(spCellLst->list.array[cellIdx]);
12733           }
12734        }
12735        free(spCellLst->list.array);
12736     }
12737 }
12738 /*******************************************************************
12739 *
12740 * @brief free the memory allocated by decoder
12741 *
12742 * @details
12743 *
12744 *    Function : freeAperDecodeSRBSetup 
12745 *
12746 *    Functionality: added free part for the memory allocated by aper_decoder
12747 *
12748 * @params[in] SRBs_ToBeSetup_List_t *srbSet
12749 * @return void
12750 *
12751 ****************************************************************/
12752
12753
12754 void freeAperDecodeSRBSetup(SRBs_ToBeSetup_List_t *srbSet)
12755 {
12756     uint8_t srbIdx =0;
12757     if(srbSet->list.array != NULLP)
12758     {
12759        for(srbIdx=0; srbIdx<srbSet->list.count; srbIdx++)
12760        {
12761           if(srbSet->list.array[srbIdx]!=NULLP)
12762           {
12763              free(srbSet->list.array[srbIdx]);
12764           }
12765        }
12766        free(srbSet->list.array);
12767     }
12768 }
12769
12770 /*******************************************************************
12771 *
12772 * @brief free the memory allocated by decoder
12773 *
12774 * @details
12775 *
12776 *    Function : freeAperDecodeULTnlInfo
12777 *
12778 *    Functionality: added free part for the memory allocated by aper_decoder
12779 *
12780 * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
12781 * @return void
12782 *
12783 * ****************************************************************/
12784
12785
12786 void freeAperDecodeULTnlInfo(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
12787 {
12788    uint8_t ulIdx=0;
12789    if(ulInfo->list.array != NULLP)
12790    {
12791       for(ulIdx=0; ulIdx<ulInfo->list.count; ulIdx++)
12792       {
12793          if(ulIdx==0&&ulInfo->list.array[ulIdx]!=NULLP)
12794          {
12795             if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel!=NULLP)
12796             {
12797                if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12798                      transportLayerAddress.buf != NULLP)
12799                {
12800                   if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf\
12801                         !=NULLP)
12802                   {
12803                      free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf);
12804                   }
12805                   free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12806                         transportLayerAddress.buf);
12807                }
12808                free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel);
12809             }
12810          }
12811          if(ulInfo->list.array[ulIdx]!=NULLP)
12812          {
12813             free(ulInfo->list.array[ulIdx]);
12814          }
12815       }
12816       free(ulInfo->list.array);
12817    }
12818 }
12819 /*******************************************************************
12820 *
12821 * @brief free the memory allocated by decoder
12822 *
12823 * @details
12824 *
12825 *    Function : freeAperDecodeDRBSetup  
12826 *
12827 *    Functionality: free DRBSetup which is allocated by decoder
12828 *
12829 * @params[in]  DRBs_ToBeSetup_List_t *drbSet
12830 * @return void
12831 *
12832 * ****************************************************************/
12833
12834 void freeAperDecodeDRBSetup(DRBs_ToBeSetup_List_t *drbSet)
12835 {
12836    DRBs_ToBeSetup_Item_t *drbSetItem = NULLP;
12837    uint8_t  flowIdx =0;
12838    uint8_t  drbIdx =0;
12839
12840    if(drbSet->list.array != NULLP)
12841    {
12842       for(drbIdx=0; drbIdx<drbSet->list.count; drbIdx++)
12843       {
12844          if(drbIdx==0&&drbSet->list.array[drbIdx] != NULLP)
12845          {
12846             drbSetItem =&drbSet->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12847             if(drbSetItem->qoSInformation.choice.choice_extension != NULLP)
12848             {
12849                if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12850                      qoS_Characteristics.choice.non_Dynamic_5QI !=NULLP)
12851                {
12852                   if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12853                         qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12854                   {
12855                      if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12856                            qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12857                      {
12858
12859                         if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf!=NULLP)
12860                         {
12861
12862                            if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD!=NULLP)
12863                            {
12864
12865                               if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD->\
12866                                     buf!=NULLP)
12867                               {
12868
12869                                  if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.\
12870                                        flows_Mapped_To_DRB_List.list.array != NULLP)
12871                                  {
12872
12873                                     for(flowIdx=0;flowIdx<drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12874                                           DRB_Information.flows_Mapped_To_DRB_List.list.count; flowIdx++)
12875                                     {
12876
12877                                        if(flowIdx==0&&drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12878                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12879                                        {
12880                                           if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12881                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12882                                                 qoSFlowLevelQoSParameters.\
12883                                                 qoS_Characteristics.choice.non_Dynamic_5QI!=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->averagingWindow!=NULLP)
12889                                              {
12890
12891                                                 if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12892                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12893                                                       qoSFlowLevelQoSParameters.\
12894                                                       qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12895                                                 {
12896
12897
12898                                                    free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12899                                                          DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12900                                                          qoSFlowLevelQoSParameters.\
12901                                                          qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12902                                                 }
12903
12904                                                 free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12905                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12906                                                       qoSFlowLevelQoSParameters.\
12907                                                       qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12908                                              }
12909
12910                                              free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12911
12912                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12913                                                    qoSFlowLevelQoSParameters.\
12914                                                    qoS_Characteristics.choice.non_Dynamic_5QI);
12915                                           }
12916                                        }
12917                                        if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12918                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12919                                        {
12920
12921                                           free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12922                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]);
12923                                        }
12924                                     }
12925
12926                                     free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12927                                           DRB_Information.flows_Mapped_To_DRB_List.list.array);
12928                                  }
12929
12930                                  free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12931                                        DRB_Information.sNSSAI.sD->buf);
12932                               }
12933
12934                               free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD);
12935                            }
12936
12937                            free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf);
12938
12939                         }
12940
12941                         free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12942
12943                               qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12944                      }
12945
12946                      free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12947                            qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12948                   }
12949
12950                   free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12951                         qoS_Characteristics.choice.non_Dynamic_5QI);
12952                }
12953                free(drbSetItem->qoSInformation.choice.choice_extension);
12954             }
12955             freeAperDecodeULTnlInfo(&drbSetItem->uLUPTNLInformation_ToBeSetup_List);
12956             if(drbSetItem->uLConfiguration)
12957             {
12958                free(drbSetItem->uLConfiguration);
12959             }
12960          }
12961          if(drbSet->list.array[drbIdx]!=NULLP)
12962          {
12963             free(drbSet->list.array[drbIdx]);
12964          }
12965       }
12966       free(drbSet->list.array);
12967    }
12968 }
12969
12970
12971 /*******************************************************************
12972  *
12973  * @brief builds Mac Cell Cfg
12974  *
12975  * @details
12976  *
12977  *    Function : procUeRecfgCellInfo
12978  *
12979  *    Functionality: builds Mac Cell Cfg
12980  *
12981  * @params[in] DuMacUeCfg *macUeCfgToSend = Used to Store the information which
12982  *                       needs to send in other layer, as well as this can be
12983  *                       the variable which stores the information in DuCb.
12984  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
12985  *                       information to other layer else it will have copyOfmacUeCfg  
12986  *                       which we have stored in F1UeContextSetupDb
12987  *             void *cellInfo = CellGroupConfigRrc_t information which is send
12988  *                        by CU, which we have stored in F1UeContextSetupDb 
12989  *
12990  * @return void 
12991  *
12992  * ****************************************************************/
12993 uint8_t procUeRecfgCellInfo(DuMacUeCfg *macUeCfgToSend, DuMacUeCfg *storedMacUeCfg, void *cellInfo)
12994 {
12995    uint8_t ret = ROK;
12996    CellGroupConfigRrc_t *cellGrp = NULLP;
12997
12998    if(cellInfo)
12999    {
13000       cellGrp = (CellGroupConfigRrc_t *)cellInfo;
13001       ret = extractUeRecfgCellInfo(cellGrp, macUeCfgToSend, storedMacUeCfg);
13002       if(ret == RFAILED)
13003          DU_LOG("\nERROR  -->  F1AP : Failed at procUeRecfgCellInfo()");
13004    }
13005    if(ret == RFAILED)
13006    {
13007       freeUeRecfgCellGrpInfo(macUeCfgToSend);
13008    }
13009    return ret;
13010 }
13011
13012 /*******************************************************************
13013  *
13014  * @brief Filling modulation info in mac ue cfg
13015  *
13016  * @details
13017  *
13018  *    Function : duFillModulationDetails
13019  *
13020  *    Functionality: Filling modulation info in mac ue cfg
13021  *
13022  * @params[in] MAC UE Config to be updated
13023  *             Current UE configuration
13024  *             UE NR capability from CU
13025  * @return ROK     - success
13026  *         RFAILED - failure
13027  *
13028  * ****************************************************************/
13029 void duFillModulationDetails(DuMacUeCfg *ueCfg, DuMacUeCfg *oldUeCfg, void *ueCap)
13030 {
13031    UE_NR_Capability_t *ueNrCap=NULLP;
13032
13033    if(!ueCap && oldUeCfg)
13034    {
13035       memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));     
13036       memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13037    }
13038    else
13039    {
13040       ueNrCap = (UE_NR_Capability_t *)ueCap;
13041
13042       /* Filling DL modulation info */
13043       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsDownlinkPerCC && \
13044          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0] && \
13045          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL)
13046       {
13047          switch(*(ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL))
13048          {
13049             case ModulationOrder_qpsk:
13050                {
13051                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
13052                   break;
13053                }
13054             case ModulationOrder_qam16:
13055                {
13056                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM16;
13057                   break;
13058                }
13059             case ModulationOrder_qam64:
13060                {
13061                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM64;
13062                   ueCfg->dlModInfo.mcsIndex = PDSCH_MCS_INDEX;
13063                   ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64;
13064                   break;
13065                }
13066             case ModulationOrder_qam256:
13067                {
13068                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM256;
13069                   break;
13070                }
13071             default:
13072                {
13073                   DU_LOG("\nERROR  -->  DU APP: Incorrect downlink modulation order received. Reatining old modulation configuration");
13074                   if(oldUeCfg)
13075                      memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
13076                   break;
13077                }
13078          }
13079       }
13080       else
13081       {
13082          if(oldUeCfg)
13083             memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
13084       }
13085
13086       /* Filling UL modulation info */
13087       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsUplinkPerCC && \
13088          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0] && \
13089          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL)
13090       {
13091          switch(*(ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL))
13092          {
13093             case ModulationOrder_qpsk:
13094                {
13095                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
13096                   break;
13097                }
13098             case ModulationOrder_qam16:
13099                {
13100                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM16;
13101                   ueCfg->ulModInfo.mcsIndex = PUSCH_MCS_INDEX;
13102                   ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64;
13103                   break;
13104                }
13105             case ModulationOrder_qam64:
13106                {
13107                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM64;
13108                   break;
13109                }
13110             case ModulationOrder_qam256:
13111                {
13112                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM256;
13113                   break;
13114                }
13115             default:
13116                {
13117                   DU_LOG("\nERROR  -->  DU APP: Incorrect uplink modulation order received. Reatining old modulation configuration");
13118                   if(oldUeCfg)
13119                      memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13120                   break;
13121                }
13122          }
13123       }
13124       else
13125       {
13126          if(oldUeCfg)
13127             memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13128       }
13129    }
13130 }
13131
13132 /*******************************************************************
13133  *
13134  * @brief Function to extract info from CU to DU RRC container extension
13135  *
13136  * @details
13137  *
13138  *    Function : extractCuToDuRrcInfoExt
13139  *
13140  *    Functionality: Function to extract info from CU to DU RRC container
13141  *    extension
13142  *
13143  * @params[in] ProtocolExtensionContainer_4624P16_t pointer
13144  *
13145  * @return ROK
13146  *         RFAILED
13147  *
13148  * ****************************************************************/
13149 uint8_t extractCuToDuRrcInfoExt(ProtocolExtensionContainer_4624P16_t *protocolIeExtn, DuUeCfg *ueCfgDb)
13150 {
13151    uint8_t ieIdx =0;
13152    uint16_t recvBufLen =0;
13153    CellGroupConfigRrc_t *cellGrpCfg = NULLP;
13154    CUtoDURRCInformation_ExtIEs_t *extIeInfo = NULLP;
13155    asn_dec_rval_t rval; /* Decoder return value */
13156    memset(&rval, 0, sizeof(asn_dec_rval_t));
13157
13158    if(protocolIeExtn)
13159    {
13160       for(ieIdx = 0; ieIdx < protocolIeExtn->list.count; ieIdx++)
13161       {
13162          extIeInfo = ((CUtoDURRCInformation_ExtIEs_t *)(protocolIeExtn->list.array[ieIdx]));
13163          switch(extIeInfo->id)
13164          {
13165             case ProtocolIE_ID_id_CellGroupConfig:
13166                {
13167                   /* decoding the CellGroup Buf received */
13168                   recvBufLen = extIeInfo->extensionValue.choice.CellGroupConfig.size;
13169                   DU_ALLOC(cellGrpCfg, sizeof(CellGroupConfigRrc_t));
13170                   if(cellGrpCfg)
13171                   {
13172                      memset(cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
13173                      rval = uper_decode(0, &asn_DEF_CellGroupConfigRrc, (void **)&cellGrpCfg,
13174                            extIeInfo->extensionValue.choice.CellGroupConfig.buf, recvBufLen, 0, 0);
13175                      if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13176                      {
13177                         DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13178                         return RFAILED;
13179                      }
13180                      xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, cellGrpCfg);
13181
13182                      if(extractRlcCfgToAddMod(cellGrpCfg->rlc_BearerToAddModList, ueCfgDb))
13183                         return NULLP;
13184                      ueCfgDb->cellGrpCfg = cellGrpCfg;
13185                   }
13186                   break;
13187                }
13188
13189             case ProtocolIE_ID_id_HandoverPreparationInformation:
13190                {
13191                   DU_LOG("\nINFO -->  F1AP : Received HANDOVER PREPARATION INFO in UE CONTEXT SETUP REQUEST");
13192                   break;
13193                }
13194
13195             default:
13196                DU_LOG("\nERROR  -->  F1AP : Invalid IE received CUtoDURRCInformation: %ld at decodeCellGrpCfg()", extIeInfo->id);
13197                break;
13198          }
13199       }
13200    }
13201    return ROK;
13202 }
13203
13204 /*******************************************************************
13205  *
13206  * @brief Fills Srb List received by CU
13207  *
13208  * @details
13209  *
13210  *    Function : procSrbListToSetup
13211  *
13212  *    Functionality: Fills Srb List received  by CU
13213  *
13214  * @params[in] SRBs_ToBeSetup_Item_t *cuSrbItem
13215  *             DuLcCfg pointer
13216  *             RlcBearerCfg pointer
13217  * @return void
13218  *
13219  * ****************************************************************/
13220 uint8_t procSrbListToSetup(SRBs_ToBeSetup_Item_t * srbItem, DuLcCfg *duMacLcToAdd, DuRlcBearerCfg *rlcLcToAdd)
13221 {
13222
13223    /* Filling RLC INFO */
13224    procRlcLcCfg(srbItem->sRBID, srbItem->sRBID, RB_TYPE_SRB, RLC_AM, CONFIG_ADD, NULL, rlcLcToAdd, NULL);
13225
13226    /* Filling MAC INFO */
13227    if(procMacLcCfg(srbItem->sRBID, RB_TYPE_SRB, CONFIG_ADD, NULL,NULL, NULL, NULL, duMacLcToAdd, NULL)  != ROK)
13228    { 
13229       DU_LOG("\nERROR  -->  F1AP : Failed at MAC LC Cfg in procSrbListToSetup()");
13230       return RFAILED;
13231    }
13232
13233    return ROK;
13234 }
13235
13236
13237
13238 /*******************************************************************
13239  *
13240  * @brief extract Srb List received by CU
13241  *
13242  * @details
13243  *
13244  *    Function : extractSrbListToSetup
13245  *
13246  *    Functionality: extract Srb List received by CU
13247  *                   for both MAC and RLC
13248  *
13249  * @params[in] SRBs_ToBeSetup_Item_t pointer
13250  *             DuUeCfg pointer
13251  * @return ROK/RFAIED
13252  *
13253  * ****************************************************************/
13254
13255 uint8_t extractSrbListToSetup(SRBs_ToBeSetup_List_t *srbCfg, DuUeCfg *ueCfgDb)
13256 {
13257    uint8_t ret = ROK, srbIdx = 0, rlcLcIdx = 0;
13258    SRBs_ToBeSetup_Item_t *srbItem = NULLP;
13259    DuLcCfg *macLcCtxt = NULLP;
13260    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13261
13262    if(srbCfg)
13263    {
13264       for(srbIdx = 0; srbIdx < srbCfg->list.count; srbIdx++)
13265       {
13266          macLcCtxt = NULL;
13267          rlcLcCtxt = NULL;
13268
13269          srbItem = &srbCfg->list.array[srbIdx]->value.choice.SRBs_ToBeSetup_Item;
13270          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13271          { 
13272             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in MAC");
13273             ret = RFAILED;
13274             break;
13275          }
13276          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13277          {
13278             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in RLC");
13279             ret = RFAILED;
13280             break;
13281          }
13282
13283          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numMacLcs; rlcLcIdx++)
13284          {
13285             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == srbItem->sRBID && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
13286             {
13287                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13288                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13289                break;
13290             }
13291          }
13292          if(!macLcCtxt)
13293          {
13294             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13295             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13296             ueCfgDb->numMacLcs++;
13297          }
13298          if(!rlcLcCtxt)
13299          {
13300             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13301             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13302             ueCfgDb->numRlcLcs++;
13303          }
13304
13305          ret = procSrbListToSetup(srbItem, macLcCtxt, rlcLcCtxt);
13306
13307          DU_LOG("\nDEBUG --> DUAPP: extractSrbListToSetup: SRBID: %ld [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13308                srbItem->sRBID, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13309          if(ret == RFAILED)
13310          {
13311             DU_LOG("\nERROR  -->  F1AP:  Failed at extractSrbListToSetup()");
13312             break;
13313          }
13314       }
13315    }
13316    else
13317       ret = RFAILED;
13318
13319    return ret;
13320 }
13321
13322 /*******************************************************************
13323  *
13324  * @brief Fills Drb List received by CU
13325  *
13326  * @details
13327  *
13328  *    Function : procDrbListToSetupMod
13329  *
13330  *    Functionality: Fills Drb List received by CU
13331  *                   for both MAC and RLC
13332  *
13333  * @params[in] DRBs_ToBeSetup_Item_t , DRBs_ToBeSetupMod_Item_t,
13334  *             DRBs_ToBeModified_Item_t , lcId, DuLcCfg pointer,
13335  *             RlcBearerCfg , UpTnlCfg, DuRlcUeCfg
13336  * @return void
13337  *
13338  * ****************************************************************/
13339
13340 uint8_t procDrbListToSetupMod(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbItem,\
13341 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, DuLcCfg *macLcToAdd, DuRlcBearerCfg *rlcLcToAdd, UpTnlCfg *upTnlInfo, DuRlcUeCfg *storedRlcUeCfg)
13342 {
13343    uint8_t cfgIdx = 0;
13344    RlcMode rlcModeInfo;
13345
13346    if(drbItem != NULLP)
13347    {
13348       /* Filling RLC INFO */
13349       procRlcLcCfg(drbItem->dRBID, lcId, RB_TYPE_DRB, drbItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, &drbItem->\
13350       qoSInformation);
13351
13352       /* Filling MAC INFO */
13353       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, drbItem, NULL, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13354       { 
13355          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13356          return RFAILED;
13357       }
13358    }
13359    else if(drbSetupModItem != NULLP)
13360    {
13361       procRlcLcCfg(drbSetupModItem->dRBID, lcId, RB_TYPE_DRB, drbSetupModItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, 
13362       &drbSetupModItem->qoSInformation);
13363
13364       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, NULL, drbSetupModItem, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13365       {
13366          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13367          return RFAILED;
13368       }
13369    }
13370    else if(drbModItem != NULLP)
13371    {
13372       /* Drb to Mod IEs doesnot have rlcMode to be modified
13373        * in ASN. Hence no change in RLC configurations */
13374       if(storedRlcUeCfg != NULLP)
13375       {
13376          for(cfgIdx = 0; cfgIdx < storedRlcUeCfg->numLcs; cfgIdx++)
13377          {
13378             if(storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.lcId == lcId)
13379             {
13380                rlcModeInfo = storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.rlcMode;
13381                break;
13382             }
13383          }
13384       }
13385
13386       procRlcLcCfg(drbModItem->dRBID, lcId, RB_TYPE_DRB, rlcModeInfo, CONFIG_MOD, NULL, rlcLcToAdd, drbModItem->qoSInformation);
13387       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_MOD, NULL, NULL, drbModItem, NULL, macLcToAdd, upTnlInfo) != ROK)
13388       {
13389          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13390          return RFAILED;
13391       }
13392    }
13393    return ROK;
13394 }
13395
13396 /*******************************************************************
13397  *
13398  * @brief extract Drb List received by CU
13399  *
13400  * @details
13401  *
13402  *    Function : extractDrbListToSetupMod
13403  *
13404  *    Functionality: extract Drb List received by CU
13405  *                   for both MAC and RLC
13406  *
13407  * @params[in] DRBs_ToBeSetup_Item_t pointer
13408  *             DuUeCfg pointer
13409  * @return ROK/RFAIED
13410  *
13411  * ****************************************************************/
13412
13413 uint8_t extractDrbListToSetupMod(DRBs_ToBeSetup_List_t *drbCfg, DRBs_ToBeSetupMod_List_t *drbSetupModCfg,\
13414  DRBs_ToBeModified_List_t *drbModCfg, uint8_t drbCount, DuUeCfg *ueCfgDb, uint32_t *drbBitMap, DuRlcUeCfg *rlcUeCfg)
13415 {
13416    uint8_t ret = ROK;
13417    uint8_t drbIdx = 0, rlcLcIdx = 0;
13418    uint8_t drbId = 0, lcId = 0;
13419    DRBs_ToBeSetup_Item_t *drbItem = NULLP;
13420    DRBs_ToBeSetupMod_ItemIEs_t *drbSetupModItem = NULLP;
13421    DRBs_ToBeModified_ItemIEs_t *drbModItem = NULLP;
13422    DuLcCfg *macLcCtxt = NULLP;
13423    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13424
13425    ret = ROK;
13426    if(drbCount > 0)
13427    {
13428       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13429       {
13430          macLcCtxt = NULL;
13431          rlcLcCtxt = NULL;
13432
13433          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13434          { 
13435             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in MAC at extractDrbListToSetupMod()");
13436             ret = RFAILED;
13437             break;
13438          }
13439          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13440          {
13441             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in RLC at extractDrbListToSetupMod()");
13442             ret = RFAILED;
13443             break;
13444          }
13445
13446          if(drbModCfg != NULLP)
13447          {
13448             drbModItem = (DRBs_ToBeModified_ItemIEs_t *) drbModCfg->list.array[drbIdx];
13449             drbId = drbModItem->value.choice.DRBs_ToBeModified_Item.dRBID;
13450          }
13451          else if(drbCfg != NULLP)
13452             drbId = drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item.dRBID;
13453          else if(drbSetupModCfg != NULL)
13454          {
13455             drbSetupModItem = (DRBs_ToBeSetupMod_ItemIEs_t *) drbSetupModCfg->list.array[drbIdx];
13456             drbId = drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item.dRBID;
13457          }
13458
13459          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13460          {
13461             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && \
13462                    ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13463             {
13464                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13465                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13466                break;
13467             }
13468          }
13469          if(!macLcCtxt)
13470          {
13471             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13472             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13473             ueCfgDb->numMacLcs++;
13474          }
13475          if(!rlcLcCtxt)
13476          {
13477             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
13478             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13479             ueCfgDb->numRlcLcs++;
13480          }
13481
13482          if(drbModCfg != NULLP)
13483          {
13484             lcId = fetchLcId(drbId);
13485             if(lcId < MIN_DRB_LCID)
13486             {
13487                DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToSetupMod() for Modified List", lcId);
13488                break;
13489             } 
13490             ret = procDrbListToSetupMod(lcId, NULL, NULL, &(drbModItem->value.choice.DRBs_ToBeModified_Item),\
13491             macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13492             if(ret == RFAILED)
13493             {
13494                DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for Modified List");
13495                break;
13496             }
13497             ueCfgDb->numDrbModified++;
13498          }
13499          else
13500          {
13501             lcId = getDrbLcId(drbBitMap);
13502             if(lcId == RFAILED)
13503             {
13504                DU_LOG("\nERROR  -->  F1AP :  InCorrect LCID extractDrbListToSetupMod()");
13505                ret = RFAILED;
13506                break;
13507             }
13508             if(drbCfg != NULL)
13509             {
13510                drbItem = &drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
13511                ret = procDrbListToSetupMod(lcId, drbItem, NULL, NULL, macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13512                if(ret == RFAILED)
13513                {
13514                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetup List");
13515                   break;
13516                }
13517             }
13518             else if(drbSetupModCfg != NULL)
13519             {
13520                ret = procDrbListToSetupMod(lcId, NULL, &(drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item), NULL,\
13521                      macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13522                if(ret == RFAILED)
13523                {
13524                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetupMod List");
13525                   break;
13526                }
13527                ueCfgDb->numDrbSetupMod++;
13528             }
13529          }
13530          ueCfgDb->numDrb++;
13531  
13532          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToSetupMod:lcId:%x ,BitMap:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13533                             lcId,*drbBitMap, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13534          if(ret == RFAILED)
13535          {
13536             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod()");
13537             break;
13538          }
13539       }
13540    }
13541    else
13542       ret = RFAILED;
13543
13544    return ret;
13545 }
13546
13547 /*******************************************************************
13548  *
13549  * @brief extract Drb List received from CU
13550  *
13551  * @details
13552  *
13553  *    Function : extractDrbListToRelease
13554  *
13555  *    Functionality: extract Drb List received from CU
13556  *                   for both MAC and RLC
13557  *
13558  * @params[in] DRBs_ToBeReleased_Item_t pointer
13559  *             DuUeCfg pointer
13560  * @return ROK/RFAIED
13561  *
13562  * ****************************************************************/
13563
13564 uint8_t extractDrbListToRelease(uint8_t ueId, DRBs_ToBeReleased_List_t *drbToRel, uint8_t drbCount, DuUeCfg *ueCfgDb, DuRlcUeCfg *rlcUeCfg)
13565 {
13566    uint8_t ret = ROK, teIdx = 0;
13567    uint8_t drbIdx = 0, rlcLcIdx = 0;
13568    uint8_t drbId = 0, lcId = 0;
13569    DRBs_ToBeReleased_ItemIEs_t *drbRelItem = NULLP;
13570    DuLcCfg *macLcCtxt = NULLP;
13571    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13572
13573    ret = ROK;
13574    if(drbCount > 0)
13575    {
13576       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13577       {
13578          macLcCtxt = NULL;
13579          rlcLcCtxt = NULL;
13580
13581          if(drbToRel != NULLP)
13582          {
13583             drbRelItem = (DRBs_ToBeReleased_ItemIEs_t *) drbToRel->list.array[drbIdx];
13584             drbId = drbRelItem->value.choice.DRBs_ToBeReleased_Item.dRBID;
13585          }
13586          else
13587          {
13588             DU_LOG("ERROR  --> DU APP : DrbToRelease pointer is NULL in extractDrbListToRelease");
13589             return RFAILED;
13590          }
13591
13592          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13593          {
13594             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13595             {
13596                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13597                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13598                break;
13599             }
13600          }
13601
13602          if(!macLcCtxt)
13603          {
13604             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13605             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13606             ueCfgDb->numMacLcs++;
13607          }
13608          if(!rlcLcCtxt)
13609          {
13610             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13611             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13612             ueCfgDb->numRlcLcs++;
13613          }
13614          lcId = fetchLcId(drbId);
13615          if(lcId < MIN_DRB_LCID)
13616          {
13617             DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToRelease() for Modified List", lcId);
13618             break;
13619          } 
13620
13621          /* Filling RLC INFO */
13622          procRlcLcCfg(drbId, lcId, RB_TYPE_DRB, rlcLcCtxt->rlcBearerCfg.rlcMode, CONFIG_DEL, NULL, rlcLcCtxt, NULLP);
13623          /* Filling MAC INFO */
13624          if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_DEL, NULL, NULL, NULL, NULL, macLcCtxt, NULLP) != ROK)
13625          { 
13626             DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in extractDrbListToRelease()");
13627             return RFAILED;
13628          }
13629          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].configType = CONFIG_DEL;
13630          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId = drbId;
13631          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId = ueId;
13632
13633          for(teIdx = 0; teIdx < duCb.numTeId; teIdx++)
13634          {
13635             if((duCb.upTnlCfg[teIdx]->ueId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId) && \
13636                   (duCb.upTnlCfg[teIdx]->drbId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId))
13637             {
13638                DU_ALLOC(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, sizeof(GtpTnlCfg)); 
13639                memcpy(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, duCb.upTnlCfg[teIdx]->tnlCfg1, sizeof(GtpTnlCfg));
13640                break;
13641             }
13642          }
13643
13644          ueCfgDb->numDrb++;
13645          if(ret == RFAILED)
13646          {
13647             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToRelease() for Modified List");
13648             break;
13649          }
13650
13651          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToRelease():lcId:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13652                lcId,ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13653       }
13654    }
13655    else
13656       ret = RFAILED;
13657
13658    return ret;
13659 }
13660
13661 /*******************************************************************
13662  *
13663  * @brief Function to extract Dl RRC Msg received from CU
13664  *
13665  * @details
13666  *
13667  *    Function : extractDlRrcMsg
13668  *
13669  *    Functionality: Function to extract Dl RRC Msg received from CU
13670  *
13671  * @params[in] F1AP message
13672  * @return ROK     - success
13673  *         RFAILED - failure
13674  *
13675  * ****************************************************************/
13676
13677 uint8_t extractDlRrcMsg(uint32_t gnbDuUeF1apId, uint32_t gnbCuUeF1apId, \
13678    F1DlRrcMsg *dlRrcMsg, RRCContainer_t *rrcContainer)
13679 {
13680    uint8_t ret = ROK;
13681    dlRrcMsg->rrcMsgSize = rrcContainer->size;
13682    if(dlRrcMsg->rrcMsgSize > 0)
13683    {
13684       DU_ALLOC_SHRABL_BUF(dlRrcMsg->rrcMsgPdu, dlRrcMsg->rrcMsgSize);
13685       if(!dlRrcMsg->rrcMsgPdu)
13686       {
13687          DU_LOG("\nERROR  --> DU APP : Memory allocation failed for RRC Msg in extractDlRrcMsg()");
13688          ret = RFAILED;
13689       }
13690       else
13691       {
13692          dlRrcMsg->gnbDuUeF1apId = gnbDuUeF1apId;
13693          dlRrcMsg->gnbCuUeF1apId = gnbCuUeF1apId;
13694          dlRrcMsg->srbId = SRB1_LCID;
13695          memcpy(dlRrcMsg->rrcMsgPdu, rrcContainer->buf, dlRrcMsg->rrcMsgSize);
13696       }
13697    }
13698    return ret;
13699 }
13700
13701 /*******************************************************************
13702  *
13703  * @brief Extract UE capability info 
13704  *
13705  * @details
13706  *
13707  *    Function : extractUeCapability
13708  *
13709  *    Functionality: Extract UE capability info and stores in ue Cb
13710  *
13711  * @params[in] Octet string of UE capability RAT container list
13712  * @return ROK     - success
13713  *         RFAILED - failure
13714  *
13715  * ****************************************************************/
13716 UE_NR_Capability_t *extractUeCapability(UE_CapabilityRAT_ContainerList_t *ueCapablityListBuf, DuUeCb *ueCb)
13717 {
13718    uint8_t  idx;
13719    uint16_t recvBufLen;
13720    asn_dec_rval_t rval;
13721    UE_NR_Capability_t  *ueNrCap = NULLP;
13722    UE_CapabilityRAT_ContainerListRRC_t  *ueCapRatContList = NULLP;
13723
13724    /* Decoding UE Capability RAT Container List */
13725    recvBufLen = ueCapablityListBuf->size;
13726    DU_ALLOC(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13727    if(!ueCapRatContList)
13728    {
13729       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13730       return NULLP;
13731    }
13732    memset(ueCapRatContList, 0, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13733    memset(&rval, 0, sizeof(asn_dec_rval_t));
13734    rval = uper_decode(0, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, (void **)&ueCapRatContList,
13735           ueCapablityListBuf->buf, recvBufLen, 0, 0);
13736    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13737    {
13738       DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13739       return NULLP;
13740    }
13741    xer_fprint(stdout, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, ueCapRatContList);
13742
13743    /* Free encoded buffer after decoding */
13744
13745    for(idx = 0; idx < ueCapRatContList->list.count; idx++)
13746    {
13747       if(ueCapRatContList->list.array[idx]->rat_Type == RAT_Type_nr)
13748       {
13749          /* Decoding UE NR Capability */
13750           recvBufLen = ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.size;
13751           DU_ALLOC(ueNrCap, sizeof(UE_NR_Capability_t));
13752           if(!ueNrCap)
13753           {
13754              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13755              DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13756              return NULLP;
13757           } 
13758           memset(ueNrCap, 0, sizeof(UE_NR_Capability_t));
13759           memset(&rval, 0, sizeof(asn_dec_rval_t));
13760           rval = uper_decode(0, &asn_DEF_UE_NR_Capability, (void **)&ueNrCap,
13761                  ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf, recvBufLen, 0, 0);
13762           if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13763           {
13764              DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13765              return NULLP;
13766           }
13767           xer_fprint(stdout, &asn_DEF_UE_NR_Capability, ueNrCap);
13768           
13769           /* Free encoded buffer after decoding */
13770           free(ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf);
13771       }
13772       free(ueCapRatContList->list.array[idx]);
13773    }
13774
13775    /* Free Memory*/
13776    free(ueCapRatContList->list.array);
13777    DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13778    return ueNrCap;
13779 }
13780  
13781 /*******************************************************************
13782 *
13783 * @brief free UE context setup request from CU
13784 *
13785 * @details
13786 *
13787 *    Function : freeAperDecodeF1UeContextSetupReq
13788 *
13789 *    Functionality: freeing part for the memory allocated by aper_decoder
13790 *
13791 * @params[in] F1AP message
13792 * @return ROK     - success
13793 *         RFAILED - failure
13794 *
13795 * ****************************************************************/
13796 void freeAperDecodeF1UeContextSetupReq(UEContextSetupRequest_t   *ueSetReq)
13797 {
13798    uint8_t ieIdx = 0;
13799
13800    if(ueSetReq->protocolIEs.list.array != NULLP)
13801    {
13802       for(ieIdx = 0; ieIdx < ueSetReq->protocolIEs.list.count; ieIdx++)
13803       {
13804          if(ueSetReq->protocolIEs.list.array[ieIdx])
13805          {
13806             switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13807             {
13808                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13809                   break;
13810                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13811                   break;
13812                case ProtocolIE_ID_id_SpCell_ID:
13813                   freeAperDecodeNrcgi(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
13814                   break;
13815                case ProtocolIE_ID_id_ServCellIndex:
13816                   break;
13817                case ProtocolIE_ID_id_SpCellULConfigured:
13818                   break;
13819                case ProtocolIE_ID_id_CUtoDURRCInformation:
13820
13821                   freeAperDecodeCuToDuInfo(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation);
13822                   break;
13823                case ProtocolIE_ID_id_SCell_ToBeSetup_List:
13824
13825                   freeAperDecodeSplCellList(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SCell_ToBeSetup_List);
13826                   break;
13827                case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
13828
13829                   freeAperDecodeSRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List);
13830                   break;
13831                case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
13832
13833                   freeAperDecodeDRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List);
13834                   break;
13835                case ProtocolIE_ID_id_RRCContainer:
13836                   {
13837
13838                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf != NULLP)
13839                      {
13840
13841                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
13842                      }
13843                      break;
13844                   }
13845                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13846                   break;
13847                case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
13848                   {
13849                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf)
13850                      {
13851                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf);
13852                      }
13853                      break;
13854                   }
13855 #ifdef NR_DRX
13856                case ProtocolIE_ID_id_DRXCycle:
13857                   {
13858                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength)
13859                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength);
13860                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer)
13861                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer);
13862                      break;
13863                   }
13864 #endif             
13865                 default:
13866                   DU_LOG("\nERROR  -->  F1AP: Invalid event type %ld " ,ueSetReq->protocolIEs.list.array[ieIdx]->id);
13867             } 
13868             free(ueSetReq->protocolIEs.list.array[ieIdx]);
13869          }
13870       }
13871       free(ueSetReq->protocolIEs.list.array);
13872    }
13873 }
13874 /*******************************************************************
13875  *
13876  * @brief Process UE context setup request from CU
13877  *
13878  * @details
13879  *
13880  *    Function : procF1UeContextSetupReq
13881  *
13882  *    Functionality: Process UE context setup request from CU
13883  *
13884  * @params[in] F1AP message
13885  * @return ROK     - success
13886  *         RFAILED - failure
13887  *
13888  * ****************************************************************/
13889 uint8_t procF1UeContextSetupReq(F1AP_PDU_t *f1apMsg)
13890 {
13891    int8_t ueIdx = -1;
13892    uint8_t  ret=0, ieIdx=0, ieExtIdx = 0;
13893    //uint8_t servCellIdx = 0;
13894    bool ueCbFound = false, hoInProgress = false;
13895    uint16_t cellIdx=0;
13896    uint64_t nrCellId = 0;
13897    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0, bitRateSize=0;
13898    DuUeCb   *duUeCb = NULL;
13899    UEContextSetupRequest_t   *ueSetReq = NULL;
13900    DRBs_ToBeSetup_List_t *drbCfg = NULL;
13901    CUtoDURRCInformation_t *rrcInfo = NULL;
13902 #ifdef NR_DRX
13903    DRXCycle_t *drxCycle;
13904 #endif
13905    ret = ROK;
13906
13907    ueSetReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextSetupRequest;
13908    for(ieIdx=0; (ieIdx < ueSetReq->protocolIEs.list.count && ret == ROK); ieIdx++)
13909    {
13910       switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13911       {
13912          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13913             {
13914                gnbCuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
13915                break;
13916             }
13917
13918          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13919             {
13920                gnbDuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
13921                break;
13922             }
13923
13924          case ProtocolIE_ID_id_SpCell_ID:
13925             {
13926                bitStringToInt(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity, &nrCellId);
13927
13928                GET_CELL_IDX(nrCellId, cellIdx);
13929                if(!duCb.actvCellLst[cellIdx])
13930                {
13931                   DU_LOG("\nERROR  -->  F1AP : Cell Id [%lu] not found", nrCellId);
13932                   ret = RFAILED;
13933                }
13934                break;
13935             }
13936
13937          case ProtocolIE_ID_id_ServCellIndex:
13938             {
13939                //servCellIdx = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.ServCellIndex;
13940                break;
13941             }
13942
13943          case ProtocolIE_ID_id_SpCellULConfigured:
13944             {
13945                /* Indicates whether the gNB-CU requests the gNB-DU to configure the uplink as no UL, 
13946                   UL, SUL or UL+SUL for the indicated cell for the UE */
13947                break;
13948             }
13949
13950          case ProtocolIE_ID_id_CUtoDURRCInformation:
13951             {
13952                rrcInfo = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation;
13953
13954                /* Search if UE context is present */
13955                for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
13956                {
13957                   if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId)
13958                   {
13959                      ueCbFound = true;
13960                      duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13961                      break;
13962                   }
13963                }
13964
13965                /* Check if UE Handover scenario */
13966                if(rrcInfo->iE_Extensions)
13967                {
13968                   for(ieExtIdx = 0; ieExtIdx < rrcInfo->iE_Extensions->list.count; ieExtIdx++)
13969                   {
13970                      if(rrcInfo->iE_Extensions->list.array[ieExtIdx]->id == ProtocolIE_ID_id_HandoverPreparationInformation)
13971                      {
13972                         hoInProgress = true;
13973                         break;
13974                      }
13975                   }
13976                }
13977                
13978                /* If UE context is not present, but UE is in handover */
13979                if(!ueCbFound && hoInProgress)
13980                {
13981                   ueIdx = getFreeBitFromUeBitMap(nrCellId);
13982                   if(ueIdx != -1)
13983                      gnbDuUeF1apId = ueIdx +1;
13984                   else
13985                   {
13986                      DU_LOG("\nERROR  -->  F1AP : No free UE IDX found in UE bit map of cell Id [%lu]", nrCellId);
13987                      ret = RFAILED;
13988                      break;
13989                   }
13990                   duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13991                   duUeCb->f1UeDb = NULL;
13992                   duUeCb->gnbCuUeF1apId = gnbCuUeF1apId;
13993                   duUeCb->gnbDuUeF1apId = gnbDuUeF1apId;
13994                   GET_CRNTI(duUeCb->crnti, duUeCb->gnbDuUeF1apId);
13995                   duUeCb->ueState = UE_HANDIN_IN_PROGRESS;
13996                }
13997
13998                if(duUeCb)
13999                {
14000                   DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
14001                   if(duUeCb->f1UeDb)
14002                   {
14003                      memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
14004                      duUeCb->f1UeDb->actionType = UE_CTXT_SETUP;
14005                      duUeCb->f1UeDb->cellIdx = cellIdx;
14006                   }
14007                   else
14008                   {
14009                      DU_LOG("\nERROR  -->  F1AP: Memory Alloc Failed at procF1UeContextSetupReq()");
14010                      ret = RFAILED;
14011                      break;
14012                   }
14013                }
14014                else
14015                {
14016                   DU_LOG("\nERROR  -->  F1AP: DuUeCb is not found at procF1UeContextSetupReq()");
14017                   ret = RFAILED;
14018                   break;
14019                }
14020                  
14021                /* Extract UE capability info */
14022                if(rrcInfo->uE_CapabilityRAT_ContainerList)
14023                {
14024                   duUeCb->f1UeDb->duUeCfg.ueNrCapability = extractUeCapability(rrcInfo->uE_CapabilityRAT_ContainerList, duUeCb);
14025                }
14026
14027                /* Extract IE extension */
14028                if(rrcInfo->iE_Extensions)
14029                {
14030                   if(extractCuToDuRrcInfoExt(rrcInfo->iE_Extensions, &duUeCb->f1UeDb->duUeCfg) != ROK)
14031                   {
14032                      DU_LOG("\nERROR  -->  F1AP: Failed to extract CU to DU RRC information extension IE");
14033                      //TODO: Update the failure cause in ue context Setup Response
14034                      ret = RFAILED;
14035                   }
14036                }
14037                break;
14038             } 
14039
14040 #ifdef NR_DRX
14041          case ProtocolIE_ID_id_DRXCycle:
14042             {
14043                duUeCb->f1UeDb->duUeCfg.drxCyclePres = true;
14044                drxCycle = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle;
14045                duUeCb->f1UeDb->duUeCfg.drxCycle.drxLongCycleLength =  convertLongDrxCycleLengthEnumToValue(drxCycle->longDRXCycleLength);
14046                if(drxCycle->shortDRXCycleLength)
14047                {
14048                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCyclePres = true;
14049                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycle = \
14050                   convertShortDrxCycleLengthEnumToValue(*(drxCycle->shortDRXCycleLength));
14051                }
14052                if(drxCycle->shortDRXCycleTimer)
14053                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycleTimer = *(drxCycle->shortDRXCycleTimer);   
14054
14055                break;
14056             }
14057
14058 #endif
14059          case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
14060             {
14061                if(extractSrbListToSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List,\
14062                         &duUeCb->f1UeDb->duUeCfg))
14063                {
14064                   DU_LOG("\nERROR  -->  DU APP : Failed at extractSrbListToSetup()");
14065                   //TODO: Update the failure cause in ue context Setup Response
14066                   ret = RFAILED;
14067                }
14068                break;
14069             }
14070
14071          case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
14072             {
14073                drbCfg = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List;
14074
14075                if(extractDrbListToSetupMod(drbCfg, NULL, NULL, drbCfg->list.count, &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULLP))
14076                {
14077                   DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod()");
14078                   //TODO: Update the failure cause in ue context Setup Response
14079                   ret = RFAILED;
14080                }
14081                break;
14082             }
14083          case ProtocolIE_ID_id_RRCContainer:
14084             {
14085                /* Filling Dl RRC Msg Info */
14086                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
14087                if(!duUeCb->f1UeDb->dlRrcMsg)
14088                {
14089                   DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for DL RRC Msg in procUeCtxtSetupReq()");
14090                   ret = RFAILED;
14091                }
14092                else
14093                {
14094                   duUeCb->f1UeDb->dlRrcMsgPres = true;
14095                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
14096                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
14097                         &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer);
14098                }          
14099                break;
14100             }
14101
14102          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
14103             {
14104                if(duUeCb->f1UeDb->dlRrcMsg)
14105                {
14106                   if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
14107                   {
14108                      duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
14109                   }
14110                   else
14111                   {
14112                      DU_LOG("\nERROR  -->  Ignoring delivery report, since rrcContainer is not present");
14113                   }
14114                }
14115                break;
14116             }
14117
14118          case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
14119             {
14120                /* MaximumBitRate Uplink */
14121                bitRateSize = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.size;
14122                if(bitRateSize > 0)
14123                {
14124                   DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->duUeCfg.ambrCfg, bitRateSize);
14125                   if(!duUeCb->f1UeDb->duUeCfg.ambrCfg)
14126                   {
14127                      DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for bitRate in procUeCtxtSetupReq");
14128                      ret = RFAILED;
14129                   }
14130                   else
14131                   {
14132                      memset(duUeCb->f1UeDb->duUeCfg.ambrCfg, 0, sizeof(AmbrCfg)); 
14133                      memcpy(&duUeCb->f1UeDb->duUeCfg.ambrCfg->ulBr,
14134                            ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf, bitRateSize);
14135                   }
14136                }
14137                else
14138                   ret = RFAILED;
14139                break;
14140             }
14141
14142          default:
14143             {
14144                break;
14145             }
14146       } /* End of switch */
14147
14148       /* In case of any failure in any IE */
14149       if(ret == RFAILED)
14150       {
14151          // BuildAndSendUeContextSetupRsp(cellId,ueId);
14152          DU_LOG("\nERROR  -->  F1AP: Failed to process UE CNTXT SETUP REQ at procF1UeContextSetupReq()"); 
14153          break;
14154       }
14155    } /* End of for loop of IEs */
14156
14157    if(ret == ROK)
14158       ret = duProcUeContextSetupRequest(duUeCb);
14159
14160    freeAperDecodeF1UeContextSetupReq(ueSetReq); 
14161    return ret;
14162
14163 }
14164 /*******************************************************************
14165  * @brief Free the memory allocated for Dl Tunnel Info
14166  *
14167  * @details
14168  *
14169  *    Function : freeDlTnlInfo
14170  *
14171  *    Functionality:
14172  *       Free the memory allocated for Dl Tunnel Info
14173  *
14174  * @params[in] DLUPTNLInformation_ToBeSetup_List_t *
14175  * @return void
14176  *
14177  * ****************************************************************/
14178
14179 void freeDlTnlInfo(DLUPTNLInformation_ToBeSetup_List_t *tnlInfo)
14180 {
14181    uint8_t arrIdx = 0;
14182
14183    if(tnlInfo)
14184    {
14185       for(arrIdx=0; arrIdx < tnlInfo->list.count; arrIdx++)
14186       {
14187          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf,\
14188                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.size);
14189          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf,\
14190                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.size);
14191          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14192          DU_FREE(tnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14193       }
14194       DU_FREE(tnlInfo->list.array, tnlInfo->list.size);
14195    }
14196 }
14197
14198 /*******************************************************************
14199  * @brief Free the memory allocated for DRB setup List
14200  *
14201  * @details
14202  *
14203  *    Function : freeDrbSetupList
14204  *
14205  *    Functionality:
14206  *       Free the memory allocated for DRB setup list
14207  *
14208  * @params[in] DRBs_Setup_List_t *
14209  * @return void
14210  *
14211  * ****************************************************************/
14212 void freeDrbSetupList(DRBs_Setup_List_t *drbSetupList)
14213 {
14214    uint8_t arrIdx = 0;
14215    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14216
14217    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
14218    {
14219       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14220       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List);
14221       DU_FREE(drbSetupList->list.array[arrIdx],  sizeof(DRBs_Setup_Item_t));
14222    }
14223    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
14224 }
14225
14226 /*******************************************************************
14227  * @brief Free the memory allocated for UE Setup response
14228  *
14229  * @details
14230  *
14231  *    Function : FreeUeContextSetupRsp
14232  *
14233  *    Functionality:
14234  *       Free the memory allocated for UE Setup response
14235  *
14236  * @params[in] F1AP PDU for UE setup response
14237  * @return ROK     - success
14238  *         RFAILED - failure
14239  *
14240  * ****************************************************************/
14241 void FreeUeContextSetupRsp(F1AP_PDU_t *f1apMsg)
14242 {
14243    uint8_t idx;
14244    UEContextSetupResponse_t *ueSetRsp = NULLP;
14245
14246    if(f1apMsg)
14247    {
14248       if(f1apMsg->choice.successfulOutcome)
14249       {
14250          ueSetRsp = &f1apMsg->choice.successfulOutcome->value.choice.\
14251                     UEContextSetupResponse;
14252          if(ueSetRsp->protocolIEs.list.array)
14253          {
14254             for(idx = 0; idx < ueSetRsp->protocolIEs.list.count; idx++)
14255             {
14256                if(ueSetRsp->protocolIEs.list.array[idx])
14257                {
14258                   switch(ueSetRsp->protocolIEs.list.array[idx]->id)
14259                   {
14260                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14261                         break;
14262                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14263                         break;
14264                      case ProtocolIE_ID_id_C_RNTI:
14265                         break;
14266                      case ProtocolIE_ID_id_DUtoCURRCInformation:
14267                         {
14268                            CellGroupConfig_t *cellGrpCfg = NULLP;
14269                            cellGrpCfg  = &ueSetRsp->protocolIEs.list.array[idx]->value.choice.\
14270                                          DUtoCURRCInformation.cellGroupConfig;
14271                            if(cellGrpCfg->buf != NULLP)
14272                            {
14273                               DU_FREE(cellGrpCfg->buf, cellGrpCfg->size);
14274                               cellGrpCfg = NULLP;
14275                            }
14276                            break;
14277                         }
14278                      case ProtocolIE_ID_id_DRBs_Setup_List:
14279                         {
14280                            freeDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List); 
14281                            break;
14282                         }
14283                      default:
14284                         DU_LOG("\nERROR  -->  DUAPP: Invalid Id %ld at FreeUeContextSetupRsp()",\
14285                               ueSetRsp->protocolIEs.list.array[idx]->id);
14286                         break;
14287                   }
14288                   DU_FREE(ueSetRsp->protocolIEs.list.array[idx],\
14289                         sizeof(UEContextSetupResponseIEs_t));
14290                }
14291             }
14292             DU_FREE(ueSetRsp->protocolIEs.list.array, \
14293                   ueSetRsp->protocolIEs.list.size);
14294          }
14295          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14296       }
14297       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14298    }
14299 }
14300
14301 /*******************************************************************
14302  *
14303  * @brief Builds Ue context Setup Rsp DU To CU Info
14304  *
14305  * @details
14306  *
14307  *    Function : EncodeUeCntxtDuToCuInfo
14308  *
14309  *    Functionality: Builds Ue context Setup Rsp DU To CU Info
14310  *
14311  * @params[in] CellGroupConfig_t *, CellGroupConfigRrc_t * 
14312  *
14313  * @return ROK     - success
14314  *         RFAILED - failure
14315  *
14316  ******************************************************************/
14317
14318 uint8_t EncodeUeCntxtDuToCuInfo(CellGroupConfig_t *duToCuCellGrp, CellGroupConfigRrc_t *duCellGrpCfg)
14319 {
14320    asn_enc_rval_t        encRetVal;
14321
14322    xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, duCellGrpCfg);
14323    memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14324    encBufSize = 0;
14325    encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, duCellGrpCfg, PrepFinalEncBuf, encBuf);
14326    /* Encode results */
14327    if(encRetVal.encoded == ENCODE_FAIL)
14328    {
14329       DU_LOG( "\nERROR  -->  F1AP : Could not encode UeCntxtDuToCuInfo (at %s)\n",\
14330             encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14331       return RFAILED;
14332    }
14333    else
14334    {
14335       DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UeCntxtDuToCuInfo\n");
14336 #ifdef DEBUG_ASN_PRINT
14337       for(int i=0; i< encBufSize; i++)
14338       {
14339          printf("%x",encBuf[i]);
14340       }
14341 #endif
14342    }
14343    duToCuCellGrp->size = encBufSize;
14344    DU_ALLOC(duToCuCellGrp->buf, duToCuCellGrp->size);
14345    if(!duToCuCellGrp->buf)
14346    {
14347       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in UeCntxtDuToCuInfo");
14348    }
14349    memcpy(duToCuCellGrp->buf, encBuf, duToCuCellGrp->size);
14350    return ROK;
14351 }
14352
14353 /*******************************************************************
14354  *
14355  * @brief Fills Dl Gtp tunnel Info
14356  *
14357  * @details
14358  *
14359  *    Function : fillGtpTunnelforDl
14360  *
14361  *    Functionality: Fills Dl Gtp tunnel Info
14362  *
14363  * @params[in] 
14364  *
14365  * @return ROK     - success
14366  *         RFAILED - failure
14367  *
14368  * ****************************************************************/
14369
14370 uint8_t fillGtpTunnelforDl(GTPTunnel_t *gtpDl, GtpTnlCfg *gtpUeCfg)
14371 {
14372    uint8_t bufSize = 0;
14373
14374    gtpDl->transportLayerAddress.size    = 4*sizeof(uint8_t);
14375    DU_ALLOC(gtpDl->transportLayerAddress.buf, gtpDl->transportLayerAddress.size);
14376    if(gtpDl->transportLayerAddress.buf == NULLP)
14377    {
14378       return RFAILED;
14379    }
14380    memcpy(gtpDl->transportLayerAddress.buf, &gtpUeCfg->dlTnlAddress, gtpDl->transportLayerAddress.size);
14381
14382    /*GTP TEID*/
14383    gtpDl->gTP_TEID.size = 4 * sizeof(uint8_t);
14384    DU_ALLOC(gtpDl->gTP_TEID.buf, gtpDl->gTP_TEID.size);
14385    if(gtpDl->gTP_TEID.buf == NULLP)
14386    {
14387       return RFAILED;
14388    }
14389    bufSize = 3; /*forming an Octect String*/
14390    fillTeIdString(bufSize, gtpUeCfg->teId, gtpDl->gTP_TEID.buf);
14391
14392    return ROK;
14393 }
14394
14395 /*******************************************************************
14396  *
14397  * @brief Fills DL Tunnel Setup List
14398  *
14399  * @details
14400  *
14401  *    Function : fillDlTnlSetupList
14402  *
14403  *    Functionality: Fills the DL Tunnel Setup List
14404  *
14405  * @params[in] 
14406  *
14407  * @return ROK     - success
14408  *         RFAILED - failure
14409  *
14410  * ****************************************************************/
14411
14412 uint8_t fillDlTnlSetupList(DLUPTNLInformation_ToBeSetup_List_t *dlTnlInfo, UpTnlCfg *tnlCfg)
14413 {
14414    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14415
14416    eleCount = 1;
14417    dlTnlInfo->list.count = eleCount; 
14418    dlTnlInfo->list.size = (eleCount * sizeof(DLUPTNLInformation_ToBeSetup_Item_t *));
14419
14420    /* Initialize the DL Tnl Setup List Members */
14421    DU_ALLOC(dlTnlInfo->list.array, dlTnlInfo->list.size);
14422    if(dlTnlInfo->list.array == NULLP)
14423    {
14424       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL Tnl Setup List in fillDlTnlSetupList()");
14425       ret = RFAILED;
14426    }
14427    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14428    {
14429       DU_ALLOC(dlTnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14430       if(dlTnlInfo->list.array[arrIdx] == NULLP)
14431       {
14432          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDlTnlSetupList()", arrIdx);
14433          return RFAILED;
14434       }
14435       dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.present = UPTransportLayerInformation_PR_gTPTunnel;
14436       DU_ALLOC(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14437       if(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel == NULLP)
14438       {
14439          DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL tunnel info in fillDlTnlSetupList()");
14440          return RFAILED;
14441       }
14442       ret = fillGtpTunnelforDl(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel,\
14443                tnlCfg->tnlCfg1);
14444       if(ret != ROK)
14445          break;
14446    }
14447    return ret;
14448 }
14449
14450 /*******************************************************************
14451  *
14452  * @brief Fills the Drb Setup List for Ue Context Setup Response
14453  *
14454  * @details
14455  *
14456  *    Function : fillDrbSetupList
14457  *
14458  *    Functionality: Fills the Drb Setup List for Ue Context Setup Response
14459  *
14460  * @params[in] 
14461  *
14462  * @return ROK     - success
14463  *         RFAILED - failure
14464  *
14465  * ****************************************************************/
14466 uint8_t fillDrbSetupList(DRBs_Setup_List_t *drbSetupList, DuUeCfg *ueCfg)
14467 {
14468    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14469    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14470
14471    eleCount = ueCfg->numDrb;
14472    drbSetupList->list.count = eleCount;
14473    drbSetupList->list.size = \
14474         (eleCount * sizeof(DRBs_Setup_Item_t *));
14475
14476    /* Initialize the Drb Setup List Members */
14477    DU_ALLOC(drbSetupList->list.array, drbSetupList->list.size);
14478    if(drbSetupList->list.array == NULLP)
14479    {
14480       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DRB Setup List in fillDrbSetupList()");
14481       ret = RFAILED;
14482    }
14483
14484    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14485    {
14486       DU_ALLOC(drbSetupList->list.array[arrIdx], sizeof(DRBs_Setup_Item_t));
14487       if(drbSetupList->list.array[arrIdx] == NULLP)
14488       {
14489          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDrbSetupList()", arrIdx);
14490          return RFAILED;
14491       }
14492       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14493       drbItemIe->id = ProtocolIE_ID_id_DRBs_Setup_Item;
14494       drbItemIe->criticality = Criticality_reject;
14495       drbItemIe->value.present = DRBs_Setup_ItemIEs__value_PR_DRBs_Setup_Item;
14496       drbItemIe->value.choice.DRBs_Setup_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
14497       ret = fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List,\
14498           &ueCfg->upTnlInfo[arrIdx]);
14499       if(ret != ROK)
14500          break;
14501    }
14502    return ret;
14503 }
14504
14505 /*******************************************************************
14506  *
14507  * @brief Builds and sends the UE Setup Response
14508  *
14509  * @details
14510  *
14511  *    Function : BuildAndSendUeContextSetupRsp
14512  *
14513  *    Functionality: Constructs the UE Setup Response and sends
14514  *                   it to the DU through SCTP.
14515  *
14516  * @params[in] uint8_t cellId,uint8_t ueId
14517  *
14518  * @return ROK     - success
14519  *         RFAILED - failure
14520  *
14521  * ****************************************************************/
14522 uint8_t BuildAndSendUeContextSetupRsp(uint8_t cellId,uint8_t ueId)
14523 {
14524    uint8_t   idx, ret, cellIdx, elementCnt;
14525    uint32_t  gnbCuUeF1apId;   /* gNB-CU UE F1AP Id */
14526    uint32_t  gnbDuUeF1apId;   /* gNB-DU UE F1AP Id */
14527    asn_enc_rval_t  encRetVal;        /* Encoder return value */
14528    F1AP_PDU_t               *f1apMsg = NULLP;
14529    UEContextSetupResponse_t *ueSetRsp = NULLP;
14530    DuUeCb                   *ueCb = NULLP;
14531
14532    DU_LOG("\n INFO   -->  F1AP : Building UE Context Setup Response for cellId %d, ueId %d\n", cellId, ueId);
14533
14534    while(true)
14535    {
14536       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14537       if(f1apMsg == NULLP)
14538       {
14539          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14540          ret = RFAILED;
14541          break;
14542       }
14543
14544       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
14545       DU_ALLOC(f1apMsg->choice.successfulOutcome,
14546             sizeof(SuccessfulOutcome_t));
14547       if(f1apMsg->choice.successfulOutcome == NULLP)
14548       {
14549          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
14550          ret = RFAILED;
14551          break;
14552       }
14553
14554       f1apMsg->choice.successfulOutcome->procedureCode = \
14555                                                          ProcedureCode_id_UEContextSetup;
14556       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
14557       f1apMsg->choice.successfulOutcome->value.present = \
14558                                                          SuccessfulOutcome__value_PR_UEContextSetupResponse;
14559
14560       ueSetRsp =
14561          &f1apMsg->choice.successfulOutcome->value.choice.UEContextSetupResponse;
14562       elementCnt = 5;
14563       ueSetRsp->protocolIEs.list.count = elementCnt;
14564       ueSetRsp->protocolIEs.list.size = \
14565                                         elementCnt * sizeof(UEContextSetupResponse_t *);
14566
14567       /* Initialize the UESetup members */
14568       DU_ALLOC(ueSetRsp->protocolIEs.list.array, \
14569             ueSetRsp->protocolIEs.list.size);
14570       if(ueSetRsp->protocolIEs.list.array == NULLP)
14571       {
14572          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14573          ret = RFAILED;
14574          break;
14575       }
14576
14577       for(idx=0; idx<elementCnt; idx++)
14578       {
14579          DU_ALLOC(ueSetRsp->protocolIEs.list.array[idx],\
14580                sizeof(UEContextSetupResponseIEs_t));
14581          if(ueSetRsp->protocolIEs.list.array[idx] == NULLP)
14582          {
14583             DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14584             ret = RFAILED;
14585             break;
14586          }
14587       }
14588       /* Fetching Ue Cb Info*/
14589       GET_CELL_IDX(cellId, cellIdx);
14590       gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
14591       gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
14592       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
14593
14594       idx = 0;
14595       /*GNB CU UE F1AP ID*/
14596       ueSetRsp->protocolIEs.list.array[idx]->id = \
14597                                                   ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
14598       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14599       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14600                                                              UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
14601       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
14602
14603       /*GNB DU UE F1AP ID*/
14604       idx++;
14605       ueSetRsp->protocolIEs.list.array[idx]->id = \
14606                                                   ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14607       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14608       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14609                                                              UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
14610       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
14611
14612
14613       /*DUtoCURRC Information */
14614       idx++;
14615       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14616                                                    ProtocolIE_ID_id_DUtoCURRCInformation;
14617       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14618       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14619                                                             UEContextSetupResponseIEs__value_PR_DUtoCURRCInformation;
14620       BuildCellGroupConfigRrc(ueCb, &ueSetRsp->protocolIEs.list.array[idx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
14621
14622       /* CRNTI */
14623       idx++;
14624       ueSetRsp->protocolIEs.list.array[idx]->id  = ProtocolIE_ID_id_C_RNTI;
14625       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14626       ueSetRsp->protocolIEs.list.array[idx]->value.present = UEContextSetupResponseIEs__value_PR_C_RNTI;
14627       ueSetRsp->protocolIEs.list.array[idx]->value.choice.C_RNTI = ueCb->crnti; 
14628
14629
14630       /* Drb Setup List */
14631       idx++;
14632       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14633                                                    ProtocolIE_ID_id_DRBs_Setup_List;
14634       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14635       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14636                                                             UEContextSetupResponseIEs__value_PR_DRBs_Setup_List;
14637       ret = fillDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List,\
14638             &ueCb->f1UeDb->duUeCfg);
14639       if(ret == RFAILED)
14640       {
14641          DU_LOG("\nERROR  -->  F1AP : Failed to fillDrbSetupList in BuildAndSendUeContextSetupRsp()");
14642          freeF1UeDb(ueCb->f1UeDb);
14643          ueCb->f1UeDb = NULLP;
14644          break;
14645       }
14646
14647       /* Free UeContext Db created during Ue context Req */
14648       freeF1UeDb(ueCb->f1UeDb);
14649       ueCb->f1UeDb = NULLP;
14650
14651       /* TODO: To send Drb list */
14652       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14653
14654       /* Encode the UE context setup response type as APER */
14655       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14656       encBufSize = 0;
14657       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14658             encBuf);
14659       /* Encode results */
14660       if(encRetVal.encoded == ENCODE_FAIL)
14661       {
14662          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Response structure (at %s)\n",\
14663                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14664          ret = RFAILED;
14665          break;
14666       }
14667       else
14668       {
14669          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Setup Response\n");
14670 #ifdef DEBUG_ASN_PRINT
14671          for(int i=0; i< encBufSize; i++)
14672          {
14673             printf("%x",encBuf[i]);
14674          }
14675 #endif
14676       }
14677
14678       /* Sending  msg  */
14679       if(sendF1APMsg()  != ROK)
14680       {
14681          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Response failed");
14682          ret = RFAILED;
14683          break;
14684       }
14685       break;
14686    }
14687    FreeUeContextSetupRsp(f1apMsg);
14688    return ret;
14689 }/* End of BuildAndSendUeContextSetupRsp */
14690
14691 /*******************************************************************
14692 *
14693 * @brief  Build And Send Ue Context Rsp 
14694 *
14695 * @details
14696 *
14697 *    Function : BuildAndSendUeCtxtRsp 
14698 *
14699 *    Functionality : Build And Send Ue Context Rsp
14700
14701 * @params[in]
14702 * @return sucess = ROK
14703 *         failure = RFAILED
14704 *
14705 * ****************************************************************/
14706 uint8_t BuildAndSendUeCtxtRsp(uint8_t cellId, uint8_t ueId)
14707 {
14708    uint8_t cellIdx = 0, actionType = 0; 
14709
14710    GET_CELL_IDX(cellId, cellIdx);
14711    actionType = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].f1UeDb->actionType;
14712
14713    switch(actionType)
14714    {
14715       case UE_CTXT_SETUP:
14716          {
14717             if((BuildAndSendUeContextSetupRsp(cellId,ueId)) != ROK)
14718             {
14719                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextSetupRsp()");
14720                return RFAILED;
14721             }
14722             break;
14723          }
14724       case UE_CTXT_MOD:
14725          {
14726             if((BuildAndSendUeContextModRsp(&duCb.actvCellLst[cellIdx]->ueCb[ueId-1])) != ROK)
14727             {
14728                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextModRsp");
14729                return RFAILED;
14730             }
14731             break;
14732          }
14733       default:
14734          DU_LOG("ERROR  -->  F1AP: Invalid Action Type %d at BuildAndSendUeCtxtRsp()", actionType);
14735          break;
14736
14737    }
14738    return ROK;
14739 }
14740
14741 /*******************************************************************
14742  *
14743  * @brief deallocating the memory of  F1reset msg
14744  *
14745  * @details
14746  *
14747  *    Function : FreeF1ResetReq
14748  *
14749  *    Functionality :
14750  *         - freeing memory of F1reset request msg
14751  *
14752  * @params[in]
14753  * @return void
14754  *
14755  *
14756  * ****************************************************************/
14757 void FreeF1ResetReq(F1AP_PDU_t *f1apMsg)
14758 {
14759    uint8_t idx =0 ;
14760    Reset_t *f1ResetMsg;
14761
14762    if(f1apMsg)
14763    {
14764       if(f1apMsg->choice.initiatingMessage)
14765       {
14766          f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14767
14768          if(f1ResetMsg->protocolIEs.list.array)
14769          {
14770             for(idx=0 ;idx < f1ResetMsg->protocolIEs.list.count ; idx++)
14771             {
14772                if(f1ResetMsg->protocolIEs.list.array[idx])
14773                {
14774                   DU_FREE(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14775                }
14776             }
14777             DU_FREE(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14778          }
14779          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14780       }
14781       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14782    }
14783 }
14784 /*******************************************************************
14785  *
14786  * @brief Build and Send F1reset request 
14787  *
14788  * @details
14789  *
14790  *    Function : BuildAndSendF1ResetReq
14791  *
14792  *    Functionality:
14793  *         - Build and Send F1reset request msg
14794  *
14795  * @params[in]
14796  * @return ROK     - success
14797  *         RFAILED - failure
14798  *
14799  * ****************************************************************/
14800 uint8_t BuildAndSendF1ResetReq()
14801 {
14802    uint8_t          elementCnt=0;
14803    uint8_t          idx=0;
14804    uint8_t          ret= RFAILED;
14805    Reset_t          *f1ResetMsg = NULLP;
14806    F1AP_PDU_t       *f1apMsg = NULLP;
14807    asn_enc_rval_t   encRetVal;
14808    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset request \n");
14809    do
14810    {
14811       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14812       if(f1apMsg == NULLP)
14813       {
14814          break;
14815       }
14816       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
14817       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14818       if(f1apMsg->choice.initiatingMessage == NULLP)
14819       {
14820          break;
14821       }
14822       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_Reset;
14823       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
14824       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_Reset;
14825
14826       f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14827
14828       elementCnt = 3;
14829       f1ResetMsg->protocolIEs.list.count = elementCnt;
14830       f1ResetMsg->protocolIEs.list.size = elementCnt * sizeof(ResetIEs_t *);
14831
14832       /* Initialize the F1Setup members */
14833       DU_ALLOC(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14834       if(f1ResetMsg->protocolIEs.list.array == NULLP)
14835       {
14836          break;
14837       }
14838       for(idx=0; idx<elementCnt; idx++)
14839       {
14840          DU_ALLOC(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14841          if(f1ResetMsg->protocolIEs.list.array[idx] == NULLP)
14842          {
14843             break;
14844          }
14845       }
14846
14847       /*TransactionID*/
14848       idx=0;
14849       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
14850       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14851       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_TransactionID;
14852       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.TransactionID = 1;
14853
14854       /*Cause*/
14855       idx++;
14856       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_Cause;
14857       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_ignore;
14858       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_Cause;
14859       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.present = Cause_PR_radioNetwork;
14860       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.choice.radioNetwork = CauseRadioNetwork_action_desirable_for_radio_reasons;
14861
14862       /*Reset Type*/
14863       idx++;
14864       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_ResetType;
14865       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14866       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_ResetType;
14867       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.present = ResetType_PR_f1_Interface;
14868       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.choice.f1_Interface = ResetAll_reset_all;
14869
14870       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14871
14872       /* Encode the F1SetupRequest type as APER */
14873       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14874       encBufSize = 0;
14875       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14876             encBuf);
14877
14878       /* Encode results */
14879       if(encRetVal.encoded == ENCODE_FAIL)
14880       {
14881          DU_LOG("\nERROR  -->  F1AP : Could not encode F1Reset structure (at %s)\n",\
14882                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14883          break;
14884       }
14885       else
14886       {
14887          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1Reset\n");
14888 #ifdef DEBUG_ASN_PRINT
14889          for(idx=0; idx< encBufSize; idx++)
14890          {
14891             printf("%x",encBuf[idx]);
14892          }
14893 #endif
14894       }
14895
14896       if(sendF1APMsg() != ROK)
14897       {
14898          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset request failed");
14899          break;
14900       }
14901
14902       ret = ROK;
14903       break;
14904    }while(true);
14905
14906    FreeF1ResetReq(f1apMsg);
14907    return ret;
14908 }
14909 /*******************************************************************
14910  *
14911  * @brief Build And Send F1ResetAck
14912  *
14913  * @details
14914  *
14915  *    Function : BuildAndSendF1ResetAck
14916  *
14917  *    Functionality:
14918  *         - Build And Send  F1ResetRSP
14919  *
14920  * @return ROK     - success
14921  *         RFAILED - failure
14922  *
14923  * ****************************************************************/
14924 void FreeF1ResetAck(F1AP_PDU_t *f1apMsg)
14925 {
14926    uint8_t idx;
14927    ResetAcknowledge_t *f1ResetAck;
14928
14929    if(f1apMsg)
14930    {
14931       if(f1apMsg->choice.successfulOutcome)
14932       {
14933          f1ResetAck= &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14934
14935          if(f1ResetAck->protocolIEs.list.array)
14936          {
14937             for(idx=0; idx<f1ResetAck->protocolIEs.list.count ; idx++)
14938             {
14939                if(f1ResetAck->protocolIEs.list.array[idx])
14940                {
14941                   DU_FREE(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14942                }
14943             }
14944             DU_FREE(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14945          }
14946          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14947       }
14948       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14949    }
14950 }
14951
14952 /*******************************************************************
14953  *
14954  * @brief Build And Send F1ResetAck
14955  *
14956  * @details
14957  *
14958  *    Function : BuildAndSendF1ResetAck
14959  *
14960  *    Functionality:
14961  *         - Build And Send  F1ResetRSP
14962  *
14963  *  @params[in]
14964  * @return ROK     - success
14965  *         RFAILED - failure
14966  *
14967  * ****************************************************************/
14968 uint8_t BuildAndSendF1ResetAck()
14969 {
14970    uint8_t                idx = 0;
14971    uint8_t                elementCnt = 0;
14972    uint8_t                ret = RFAILED;
14973    F1AP_PDU_t             *f1apMsg = NULL;
14974    ResetAcknowledge_t     *f1ResetAck = NULLP;
14975    asn_enc_rval_t         encRetVal;
14976    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset Acknowledgment \n");
14977
14978    do{
14979       /* Allocate the memory for F1ResetRequest_t */
14980       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14981       if(f1apMsg == NULLP)
14982       {
14983          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14984          break;
14985       }
14986
14987       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
14988
14989       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14990       if(f1apMsg->choice.successfulOutcome == NULLP)
14991       {
14992          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14993          break;
14994       }
14995       f1apMsg->choice.successfulOutcome->criticality   = Criticality_reject;
14996       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetAcknowledge;
14997       f1ResetAck = &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14998
14999       elementCnt = 1;
15000
15001       f1ResetAck->protocolIEs.list.count = elementCnt;
15002       f1ResetAck->protocolIEs.list.size = elementCnt*sizeof(ResetAcknowledgeIEs_t *);
15003
15004       DU_ALLOC(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
15005       if(f1ResetAck->protocolIEs.list.array == NULLP)
15006       {
15007          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1ResetAckIEs failed");
15008          break;
15009       }
15010
15011       for(idx=0; idx<elementCnt; idx++)
15012       {
15013          DU_ALLOC(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
15014          if(f1ResetAck->protocolIEs.list.array[idx] == NULLP)
15015          {
15016             break;
15017          }
15018       }
15019       /*TransactionID*/
15020       idx = 0;
15021       f1ResetAck->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
15022       f1ResetAck->protocolIEs.list.array[idx]->criticality = Criticality_reject;
15023       f1ResetAck->protocolIEs.list.array[idx]->value.present = ResetAcknowledgeIEs__value_PR_TransactionID;
15024       f1ResetAck->protocolIEs.list.array[idx]->value.choice.TransactionID = TRANS_ID;
15025
15026       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15027
15028       /* Encode the F1SetupRequest type as UPER */
15029       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15030       encBufSize = 0;
15031       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
15032
15033       /* Check encode results */
15034       if(encRetVal.encoded == ENCODE_FAIL)
15035       {
15036          DU_LOG("\nERROR  -->  F1AP : Could not encode F1ResetAck structure (at %s)\n",\
15037                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15038          break;
15039       }
15040       else
15041       {
15042          DU_LOG("\nDUBUG   -->  F1AP : Created APER encoded buffer for F1ResetAck\n");
15043 #ifdef DEBUG_ASN_PRINT
15044          for(int i=0; i< encBufSize; i++)
15045          {
15046             printf("%x",encBuf[i]);
15047          }
15048 #endif
15049       }
15050       /* Sending msg */
15051       if(sendF1APMsg() != ROK)
15052       {
15053          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset Acknowledgement failed");
15054          break;
15055       }
15056
15057       ret = ROK;
15058       break;
15059    }while(true);
15060
15061    FreeF1ResetAck(f1apMsg);
15062    return ret;
15063 }
15064 /******************************************************************
15065 *
15066 * @brief free F1 reset msg allocated by aper_decoder 
15067 *
15068 * @details
15069 *
15070 *    Function : freeAperDecodeF1ResetMsg 
15071 *
15072 *    Functionality: free F1 reset msg allocated by aper_decoder 
15073 *
15074 * @params[in] Reset_t *f1ResetMsg 
15075 * @return void 
15076 *
15077 * ****************************************************************/
15078
15079 void freeAperDecodeF1ResetMsg(Reset_t *f1ResetMsg)
15080 {
15081    uint8_t ieIdx =0;
15082    if(f1ResetMsg->protocolIEs.list.array)
15083    {
15084       for(ieIdx=0 ;ieIdx < f1ResetMsg->protocolIEs.list.count ; ieIdx++)
15085       {
15086          if(f1ResetMsg->protocolIEs.list.array[ieIdx])
15087          {
15088             free(f1ResetMsg->protocolIEs.list.array[ieIdx]);
15089          }
15090       }
15091       free(f1ResetMsg->protocolIEs.list.array);
15092    }
15093 }
15094
15095 /******************************************************************
15096  *
15097  * @brief Processes DL RRC Message Transfer  sent by CU
15098  *
15099  * @details
15100  *
15101  *    Function : procF1ResetReq
15102  *
15103  *    Functionality: Processes DL RRC Message Transfer sent by CU
15104  *
15105  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15106  * @return ROK     - success
15107  *         RFAILED - failure
15108  *
15109  * ****************************************************************/
15110 uint8_t procF1ResetReq(F1AP_PDU_t *f1apMsg)
15111 {
15112    /* we are currently not supporting Ue release. right now we are supporting only init case of fireset */
15113    uint8_t       ieIdx = 0;
15114    uint8_t        ret = ROK;
15115    Reset_t       *f1ResetMsg = NULLP;
15116
15117    DU_LOG("\nINFO   -->  Processing F1 reset request");
15118    f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
15119
15120    for(ieIdx=0; ieIdx<f1ResetMsg->protocolIEs.list.count; ieIdx++)
15121    {
15122       switch(f1ResetMsg->protocolIEs.list.array[ieIdx]->id)
15123       {
15124          case ProtocolIE_ID_id_TransactionID:
15125             break;
15126
15127          case ProtocolIE_ID_id_Cause:
15128             break;
15129
15130          case ProtocolIE_ID_id_ResetType:
15131             {
15132                break;
15133             }
15134
15135          default:
15136             break;
15137       }
15138    }
15139    ret = BuildAndSendF1ResetAck();
15140    DU_LOG("\nINFO   -->  UE release is not supported for now");
15141
15142    freeAperDecodeF1ResetMsg(f1ResetMsg);
15143
15144    return ret;
15145 }
15146
15147 /*******************************************************************
15148  *
15149  * @brief free the RRC delivery report
15150  *
15151  * @details
15152  *
15153  *    Function : freeRrcDeliveryReport
15154  *
15155  *    Functionality: free the RRC delivery report
15156  *
15157  * @params[in]
15158  * @return ROK     - success
15159  *         RFAILED - failure
15160  *
15161  * ****************************************************************/
15162 void freeRrcDeliveryReport(F1AP_PDU_t  *f1apMsg )
15163 {
15164    uint8_t idx=0;
15165    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
15166
15167    if(f1apMsg)
15168    {
15169       if(f1apMsg->choice.initiatingMessage)
15170       {
15171          rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
15172          if(rrcDeliveryReport->protocolIEs.list.array)
15173          {
15174             for(idx =0 ;idx <rrcDeliveryReport->protocolIEs.list.count ;
15175                   idx++)
15176             {
15177                if(rrcDeliveryReport->protocolIEs.list.array[idx])
15178                {
15179                   DU_FREE(rrcDeliveryReport->protocolIEs.list.array[idx],
15180                         sizeof(RRCDeliveryReportIEs_t));
15181                }   
15182             }
15183             DU_FREE(rrcDeliveryReport->protocolIEs.list.array,
15184                   rrcDeliveryReport->protocolIEs.list.size);
15185          }
15186          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
15187       }
15188       DU_FREE(f1apMsg,
15189             sizeof(F1AP_PDU_t));
15190    }
15191 }
15192
15193 /*******************************************************************
15194 *
15195 * @brief Builds and sends the RRC delivery report
15196 *
15197 * @details
15198 *
15199 *    Function : BuildAndSendRrcDeliveryReport
15200 *
15201 *    Functionality: Builds and sends the RRC delivery report
15202 *
15203 * @params[in]
15204 *
15205 * @return ROK     - success
15206 *         RFAILED - failure
15207 *
15208 * ****************************************************************/
15209 uint8_t BuildAndSendRrcDeliveryReport(uint32_t gnbCuUeF1apId, \
15210    uint32_t gnbDuUeF1apId, RrcDeliveryReport *rrcDelivery)
15211 {
15212    uint8_t             ret = RFAILED;
15213    uint8_t             idx    = 0;
15214    uint8_t             idx1   = 0;
15215    uint8_t             elementCnt = 0;
15216    F1AP_PDU_t          *f1apMsg = NULLP;
15217    asn_enc_rval_t      encRetVal;  
15218    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
15219
15220    do{
15221
15222       DU_LOG("\nINFO   -->  F1AP : Building RRC delivery Message Transfer Message\n");
15223       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15224       if(f1apMsg == NULLP)
15225       {
15226          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
15227          break;
15228       }
15229       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
15230       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
15231       if(f1apMsg->choice.initiatingMessage == NULLP)
15232       {
15233          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU  failed");
15234          break;
15235       }
15236       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_RRCDeliveryReport;
15237       f1apMsg->choice.initiatingMessage->criticality   = Criticality_ignore;
15238       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_RRCDeliveryReport;
15239
15240       rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
15241       elementCnt = 4;
15242       rrcDeliveryReport->protocolIEs.list.count = elementCnt;
15243       rrcDeliveryReport->protocolIEs.list.size = elementCnt * sizeof(RRCDeliveryReportIEs_t *);
15244
15245       /* Initialize the F1Setup members */
15246       DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array, rrcDeliveryReport->protocolIEs.list.size);
15247       if(rrcDeliveryReport->protocolIEs.list.array == NULLP)
15248       {
15249          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRC Delivery  failed");
15250          break;
15251       }
15252       for(idx =0 ;idx <elementCnt; idx++)
15253       {
15254          DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array[idx], sizeof(RRCDeliveryReportIEs_t));
15255          if(rrcDeliveryReport->protocolIEs.list.array[idx] == NULLP)
15256          {
15257             break;
15258          }
15259       }
15260
15261       idx1 = 0;
15262
15263       /*GNB CU UE F1AP ID*/
15264       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
15265       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15266       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_CU_UE_F1AP_ID;
15267       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
15268
15269       /*GNB DU UE F1AP ID*/
15270       idx1++;
15271       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
15272       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15273       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_DU_UE_F1AP_ID;
15274       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
15275
15276       /*RRC delivery status*/
15277       idx1++;
15278       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_RRCDeliveryStatus;
15279       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15280       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_RRCDeliveryStatus;
15281       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.delivery_status =\
15282       rrcDelivery->rrcDeliveryStatus.deliveryStatus;
15283       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.triggering_message =\
15284       rrcDelivery->rrcDeliveryStatus.triggeringMessage;
15285
15286       /* SRB ID */ 
15287       idx1++;
15288       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
15289       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15290       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_SRBID;
15291       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.SRBID =  rrcDelivery->srbId;
15292
15293       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15294
15295       /* Encode the RRC DELIVERY REPORT type as APER */
15296       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15297       encBufSize = 0;
15298       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
15299             encBuf);
15300
15301       /* Encode results */
15302       if(encRetVal.encoded == ENCODE_FAIL)
15303       {
15304          DU_LOG("\nERROR  -->  F1AP : Could not encode RRC Delivery Msg structure (at %s)\n",\
15305                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15306          break;
15307       }
15308       else
15309       {
15310          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for RRC Delivery Msg \n");
15311 #ifdef DEBUG_ASN_PRINT
15312          for(idx=0; idx< encBufSize; idx++)
15313          {
15314             printf("%x",encBuf[idx]);
15315          }
15316 #endif
15317       }
15318
15319       /* Sending msg */
15320       if(sendF1APMsg() != ROK)
15321       {
15322          DU_LOG("\nERROR  -->  F1AP : Sending RRC delivery  msg request failed");
15323          break;
15324       }
15325       ret = ROK;
15326       break;
15327
15328    }while(true);
15329
15330    freeRrcDeliveryReport(f1apMsg);
15331    return ret;
15332 }
15333
15334 /*******************************************************************
15335  *
15336  * @brief Processes cells to be activated
15337  *
15338  * @details
15339  *
15340  *    Function : extractCellsToBeActivated
15341  *
15342  *    Functionality:
15343  *      - Processes cells to be activated list received in F1SetupRsp
15344  *
15345  * @params[in] void
15346  * @return ROK     - success
15347  *         RFAILED - failure
15348  *
15349  * ****************************************************************/
15350
15351 uint8_t extractCellsToBeActivated(Cells_to_be_Activated_List_t cellsToActivate)
15352 {
15353    uint8_t  ret = ROK;
15354    uint16_t idx, pci = 0;
15355    uint64_t nci;
15356    Cells_to_be_Activated_List_Item_t cell;
15357
15358    for(idx=0; idx<cellsToActivate.list.count; idx++)
15359    {
15360       nci = 0;
15361       cell = cellsToActivate.list.array[idx]->value.choice.Cells_to_be_Activated_List_Item;
15362       bitStringToInt(&cell.nRCGI.nRCellIdentity, &nci);
15363
15364       if(cell.nRPCI)
15365       {
15366          pci = *cell.nRPCI;
15367       }
15368       ret = duProcCellsToBeActivated(cell.nRCGI.pLMN_Identity.buf, nci, pci);
15369    }
15370    return ret;
15371 }
15372 /******************************************************************
15373 *
15374 * @brief Processes F1 Setup Response allocated by aper_decoder 
15375 *
15376 * @details
15377 *
15378 *    Function : freeF1SetupRsp 
15379 *
15380 *    Functionality: free F1 Setup Response allocated by aper_decoder 
15381 *
15382 * @params[in] F1SetupResponse_t *f1SetRspMsg 
15383 * @return void 
15384 *
15385 * ****************************************************************/
15386
15387 void freeAperDecodeF1SetupRsp(F1SetupResponse_t *f1SetRspMsg)
15388 {
15389    uint8_t ieIdx =0;
15390    uint8_t arrIdx =0;
15391    Cells_to_be_Activated_List_t *cellToActivate =NULLP;
15392    RRC_Version_t      *rrcVer =NULLP;
15393
15394    if(f1SetRspMsg->protocolIEs.list.array)
15395    {
15396       for(ieIdx=0; ieIdx<f1SetRspMsg->protocolIEs.list.count; ieIdx++)
15397       {
15398          if(f1SetRspMsg->protocolIEs.list.array[ieIdx])
15399          {
15400             switch(f1SetRspMsg->protocolIEs.list.array[ieIdx]->id)
15401             {
15402                case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15403                   {
15404                      cellToActivate =
15405                         &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.Cells_to_be_Activated_List;
15406                      if(cellToActivate->list.array)
15407                      {
15408                         for(arrIdx=0; arrIdx<cellToActivate->list.count ; arrIdx++)
15409                         {
15410                            if(cellToActivate->list.array[arrIdx])
15411                            {
15412
15413                               if(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.nRCGI.\
15414                               pLMN_Identity.buf)
15415                               {
15416                                  if(cellToActivate->list.array[0]->value.choice.\
15417                                        Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf)
15418                                  {
15419                                     free(cellToActivate->list.array[0]->value.choice.\
15420                                           Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf);
15421                                  }
15422
15423                                  free(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
15424                                        nRCGI.pLMN_Identity.buf);
15425                               }
15426                               free(cellToActivate->list.array[arrIdx]);
15427                            }
15428                         }
15429                         free(cellToActivate->list.array);
15430                      }
15431                      break;
15432                   }
15433                case ProtocolIE_ID_id_TransactionID:
15434                   {
15435                      break;
15436                   }
15437                case ProtocolIE_ID_id_gNB_CU_Name:
15438                   {
15439                      free(f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_Name.buf);
15440                      break;
15441                   }
15442                case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15443                   {
15444                      rrcVer = &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
15445                      if(rrcVer->latest_RRC_Version.buf)
15446                      {
15447                         if(rrcVer->iE_Extensions)
15448                         {
15449                            if(rrcVer->iE_Extensions->list.array)
15450                            {
15451                               if(rrcVer->iE_Extensions->list.array[0])
15452                               {
15453                                  if(rrcVer->iE_Extensions->list.\
15454                                        array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf)
15455                                  {
15456                                     free(rrcVer->iE_Extensions->list.\
15457                                           array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf);
15458                                  }
15459                                  free(rrcVer->iE_Extensions->list.array[0]);
15460                               }
15461                               free(rrcVer->iE_Extensions->list.array);
15462                            }
15463                            free(rrcVer->iE_Extensions);
15464                         }
15465                         free(rrcVer->latest_RRC_Version.buf);
15466                      }
15467                      break;
15468
15469                   }
15470                default:
15471                   {
15472                      DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15473                            f1SetRspMsg->protocolIEs.list.array[ieIdx]->id);
15474                   }
15475             }
15476             free(f1SetRspMsg->protocolIEs.list.array[ieIdx]);
15477          }
15478       }
15479       free(f1SetRspMsg->protocolIEs.list.array);
15480    }
15481 }
15482 /******************************************************************
15483  *
15484  * @brief Processes F1 Setup Response sent by CU
15485  *
15486  * @details
15487  *
15488  *    Function : procF1SetupRsp
15489  *
15490  *    Functionality: Processes F1 Setup Response sent by CU
15491  *
15492  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15493  * @return ROK     - success
15494  *         RFAILED - failure
15495  *
15496  * ****************************************************************/
15497 uint8_t procF1SetupRsp(F1AP_PDU_t *f1apMsg, MsgLen recvBufLen, char *recvBuf)
15498 {
15499    uint8_t ret = ROK;
15500    uint16_t idx =0;
15501    F1SetupResponse_t *f1SetRspMsg = NULLP;
15502    GNB_CU_Name_t     *cuName = NULLP;
15503    F1SetupRsp  f1SetRspDb;
15504    RRC_Version_t      *rrcVer =NULLP;
15505    
15506    memset(&f1SetRspDb, 0, sizeof(F1SetupRsp));
15507
15508    DU_LOG("\nINFO   -->  F1AP : F1 Setup Response received");
15509    f1SetRspMsg = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
15510
15511    for(idx=0; idx<f1SetRspMsg->protocolIEs.list.count; idx++)
15512    {
15513       switch(f1SetRspMsg->protocolIEs.list.array[idx]->id)
15514       {
15515          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15516             {
15517                extractCellsToBeActivated(f1SetRspMsg->protocolIEs.list.array[idx]->\
15518                      value.choice.Cells_to_be_Activated_List);
15519                break;
15520             }
15521          case ProtocolIE_ID_id_TransactionID:
15522             {
15523                f1SetRspDb.transId = f1SetRspMsg->protocolIEs.list.array[idx]->\
15524                                     value.choice.TransactionID;
15525                break;
15526             }
15527          case ProtocolIE_ID_id_gNB_CU_Name:
15528             {
15529                cuName = &f1SetRspMsg->protocolIEs.list.array[idx]->\
15530                         value.choice.GNB_CU_Name;
15531                strcpy(f1SetRspDb.cuName, (const char*)cuName->buf);
15532                break;
15533             }
15534          case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15535             {
15536                rrcVer = &f1SetRspMsg->protocolIEs.list.array[idx]->value.choice.RRC_Version;
15537                strcpy(f1SetRspDb.rrcVersion.rrcVer,
15538                      (const char*)rrcVer->latest_RRC_Version.buf);
15539                break;
15540             }
15541          default:
15542             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15543                   f1SetRspMsg->protocolIEs.list.array[idx]->id);
15544       }
15545    }
15546    
15547    duProcF1SetupRsp();
15548    freeAperDecodeF1SetupRsp(f1SetRspMsg);
15549
15550    duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize = recvBufLen;
15551    DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize);
15552    if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
15553    {
15554       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the buf of F1setup response");
15555       return RFAILED;
15556    }
15557    memcpy(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, recvBuf, recvBufLen);
15558
15559    if(BuildAndSendE2SetupReq() != ROK)
15560    {
15561       DU_LOG("\nERROR  -->  F1AP : Failed to build and send E2 setup request ");
15562       return RFAILED;
15563    }
15564    return ret;
15565 }
15566 /*******************************************************************
15567 *
15568 * @brief free GNB DU config update ack
15569 *
15570 * @details
15571 *
15572 *    Function : freeAperDecodeGnbDuAck 
15573 *
15574 *    Functionality: Processes GNB DU config update ack And
15575 *                     added free part for the memory allocated by aper_decoder
15576 *
15577 * @params[in] F1AP_PDU_t ASN decoded F1AP message
15578 * @return ROK     - success
15579 *         RFAILED - failure
15580 *
15581 * ****************************************************************/
15582
15583 void freeAperDecodeGnbDuAck(GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck)
15584 {
15585    uint8_t ieIdx = 0;
15586
15587    if(gnbDuAck->protocolIEs.list.array)
15588    {
15589       for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15590       {
15591          if(gnbDuAck->protocolIEs.list.array[ieIdx])
15592          {
15593             free(gnbDuAck->protocolIEs.list.array[ieIdx]);
15594          }
15595       }
15596       free(gnbDuAck->protocolIEs.list.array);
15597    }
15598 }
15599
15600 /*******************************************************************
15601 *
15602 * @brief Building  result of gnb-du config update ack output
15603 *
15604 * @details
15605 *
15606 *    Function : duProcGnbDuCfgUpdAckMsg 
15607 *
15608 *    Functionality: 
15609 *        Building output of gnb-du config update ack 
15610 *
15611 * @params[in] transId
15612 * @return void
15613 *
15614 * ****************************************************************/
15615
15616 uint8_t duProcGnbDuCfgUpdAckMsg(uint8_t transId)
15617 {
15618    uint8_t  ieIdx=0, arrIdx=0,ret=ROK;
15619    uint8_t  ueId =0 , ueIdx =0, totalActiveUe = 0;
15620    uint16_t cellIdx =0, crnti=0;
15621    uint64_t cellId =0;
15622    CmLList *f1apPduNode = NULLP;
15623    ReservedF1apPduInfo *f1apPduInfo =NULLP;
15624    F1AP_PDU_t *f1apMsgPdu = NULLP;
15625    GNBDUConfigurationUpdate_t *gnbDuConfigUpdate = NULLP;
15626    BIT_STRING_t *cellIdentity=NULLP;
15627    struct Served_Cells_To_Delete_ItemIEs *deleteItemIe=NULLP;
15628    Served_Cells_To_Delete_List_t *cellsToDelete=NULLP;
15629    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
15630
15631    DU_LOG("\nINFO   -->  DU APP: GNB-DU config update Ack received ");
15632    f1apPduNode = searchFromReservedF1apPduList(transId);
15633    f1apPduInfo = (ReservedF1apPduInfo *)f1apPduNode->node;
15634    f1apMsgPdu = (F1AP_PDU_t *)f1apPduInfo->f1apMsg;
15635
15636    if(f1apMsgPdu)
15637    {
15638       if(f1apMsgPdu->choice.initiatingMessage)
15639       {
15640          gnbDuConfigUpdate = &f1apMsgPdu->choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
15641          for(ieIdx=0; ieIdx < gnbDuConfigUpdate->protocolIEs.list.count; ieIdx++)
15642          {
15643             switch(gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->id)
15644             {
15645                case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
15646                   {
15647                      cellsToDelete = &gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
15648                                      Served_Cells_To_Delete_List;
15649                      if(cellsToDelete->list.array)
15650                      {
15651                         if(cellsToDelete->list.array[arrIdx])
15652                         {
15653                            deleteItemIe = (Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx];
15654                            deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
15655                            if(deleteItem->oldNRCGI.nRCellIdentity.buf)
15656                            {
15657                               cellIdentity = &deleteItem->oldNRCGI.nRCellIdentity;
15658                               bitStringToInt(cellIdentity, &cellId);
15659
15660                               GET_CELL_IDX(cellId, cellIdx);
15661                               if(duCb.actvCellLst[cellIdx] != NULLP)
15662                               {
15663                                  duCb.actvCellLst[cellId-1]->cellStatus = DELETION_IN_PROGRESS;
15664                               }
15665                            }
15666                         }
15667                      }
15668
15669                      if(duCb.actvCellLst[cellIdx] != NULLP)
15670                      {
15671                         if(duCb.actvCellLst[cellIdx]->numActvUes == 0)
15672                         {
15673                            ret = duSendCellDeletReq(cellId);
15674                            if(ret == RFAILED)
15675                            {
15676                               DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to send cell delete\
15677                               request for cellId[%lu]", cellId);
15678                            }
15679                         }
15680                         else
15681                         {
15682                            totalActiveUe = duCb.actvCellLst[cellIdx]->numActvUes;
15683                            while(totalActiveUe)
15684                            {
15685                               if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState != UE_ACTIVE)
15686                               {
15687                                  ueIdx++;
15688                                  continue;
15689                               }
15690
15691                               crnti = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti;
15692                               GET_UE_ID(crnti,ueId);
15693                               /* Sending Ue Context release request only for maximum supporting UEs */
15694                               ret = BuildAndSendUeContextReleaseReq(cellId, ueId);
15695                               if(ret == RFAILED)
15696                               {
15697                                  DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to build and send UE delete\
15698                                  request for cellId[%lu]", cellId);
15699                               }
15700                               ueIdx++;
15701                               totalActiveUe--;
15702                            }
15703                         }
15704                      }
15705                      else
15706                      {
15707                         DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): CellId [%lu] not found", cellId);
15708                         ret = RFAILED;
15709                      }
15710                      break;
15711                   }
15712
15713                default:
15714                   break;
15715             }
15716          }
15717       }
15718    }
15719    
15720    FreeDUConfigUpdate(f1apMsgPdu);
15721    deleteFromReservedF1apPduList(f1apPduNode);
15722    return ret;
15723 }
15724
15725 /*******************************************************************
15726 *
15727 * @brief Processes GNB DU config update ack
15728 *
15729 * @details
15730 *
15731 *    Function : procF1GNBDUCfgUpdAck
15732 *
15733 *    Functionality: added free part for the memory allocated by aper_decoder
15734 *
15735 * @params[in] F1AP_PDU_t *f1apMsg 
15736 * @return void 
15737 *
15738 * ****************************************************************/
15739 uint8_t procF1GNBDUCfgUpdAck(F1AP_PDU_t *f1apMsg)
15740 {
15741    uint8_t ieIdx=0,transId=0;
15742    GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck = NULLP;
15743
15744    DU_LOG("\nINFO   -->  F1AP : GNB-DU config update acknowledgment");
15745    gnbDuAck = &f1apMsg->choice.successfulOutcome->value.choice.GNBDUConfigurationUpdateAcknowledge;
15746
15747    for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15748    {
15749       switch(gnbDuAck->protocolIEs.list.array[ieIdx]->id)
15750       {
15751          case ProtocolIE_ID_id_TransactionID:
15752             {
15753                transId = gnbDuAck->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
15754                break;
15755             }
15756          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15757             {
15758                break;
15759             }
15760          default :
15761             {
15762                DU_LOG("\nERROR  -->  F1AP: procF1GNBDUCfgUpdAck(): Invalid IE Received: %ld", \
15763                      gnbDuAck->protocolIEs.list.array[ieIdx]->id);
15764                break;
15765             }
15766       }
15767    }
15768    
15769    duProcGnbDuCfgUpdAckMsg(transId);
15770     
15771 #if 0
15772    /* presently we are not supporting F1 Reset from DU to CU , we are only
15773     * supporting F1 Reset from CU to DU */
15774
15775    if(BuildAndSendF1ResetReq() != ROK)
15776    {
15777       return RFAILED;
15778    }
15779 #endif
15780
15781    freeAperDecodeGnbDuAck(gnbDuAck);
15782    return ROK;
15783 }
15784 /******************************************************************
15785 *
15786 * @brief free DL RRC Message Transfer allocated by aper_decoder 
15787 *
15788 * @details
15789 *
15790 *    Function : freeAperDecodef1DlRrcMsg 
15791 *
15792 *    Functionality: free DL RRC Message Transfer allocated by aper_decoder 
15793 *
15794 * @params[in] DLRRCMessageTransfer_t *f1DlRrcMsg 
15795 * @return ROK     - success
15796 *         RFAILED - failure
15797 *
15798 * ****************************************************************/
15799
15800 void freeAperDecodef1DlRrcMsg(DLRRCMessageTransfer_t *f1DlRrcMsg)
15801 {
15802    uint8_t ieIdx =0;
15803    RRCContainer_t *rrcContainer = NULLP;
15804
15805    if(f1DlRrcMsg->protocolIEs.list.array)
15806    {
15807       for(ieIdx=0; ieIdx<f1DlRrcMsg->protocolIEs.list.count; ieIdx++)
15808       {
15809          if(f1DlRrcMsg->protocolIEs.list.array[ieIdx])
15810          {
15811             switch(f1DlRrcMsg->protocolIEs.list.array[ieIdx]->id)
15812             {
15813                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15814                   break;
15815                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15816                   break;
15817                case ProtocolIE_ID_id_SRBID:
15818                   break;
15819                case ProtocolIE_ID_id_RRCContainer:
15820                   {
15821                      rrcContainer =&f1DlRrcMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer;
15822                      free(rrcContainer->buf);
15823                   }
15824                case ProtocolIE_ID_id_ExecuteDuplication:
15825                   break;
15826                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15827                   break;
15828                   break;
15829             }
15830             free(f1DlRrcMsg->protocolIEs.list.array[ieIdx]);
15831          }
15832       }
15833       free(f1DlRrcMsg->protocolIEs.list.array);
15834    }
15835 }
15836 /******************************************************************
15837  *
15838  * @brief Processes DL RRC Message Transfer  sent by CU
15839  *
15840  * @details
15841  *
15842  *    Function : procF1DlRrcMsgTrans
15843  *
15844  *    Functionality: Processes DL RRC Message Transfer sent by CU
15845  *
15846  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15847  * @return ROK     - success
15848  *         RFAILED - failure
15849  *
15850  * ****************************************************************/
15851 uint8_t procF1DlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
15852 {
15853    uint8_t  idx, ret;
15854    DLRRCMessageTransfer_t *f1DlRrcMsg = NULLP;
15855    F1DlRrcMsg dlMsg;
15856    memset(&dlMsg, 0, sizeof(F1DlRrcMsg));
15857
15858    DU_LOG("\nINFO   -->  DU_APP : DL RRC message transfer Recevied");
15859    f1DlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
15860
15861    ret = ROK;
15862
15863    for(idx=0; idx<f1DlRrcMsg->protocolIEs.list.count; idx++)
15864    {
15865       switch(f1DlRrcMsg->protocolIEs.list.array[idx]->id)
15866       {
15867          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15868             {
15869                dlMsg.gnbCuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
15870                break;
15871             }
15872          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15873             {
15874                dlMsg.gnbDuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
15875                break;
15876             }
15877          case ProtocolIE_ID_id_SRBID:
15878             {
15879                dlMsg.srbId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
15880                break;
15881             }
15882          case ProtocolIE_ID_id_ExecuteDuplication:
15883             dlMsg.execDup = true;
15884             break;
15885
15886          case ProtocolIE_ID_id_RRCContainer:
15887             {
15888                if(f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
15889                {
15890              dlMsg.rrcMsgSize = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
15891              DU_ALLOC_SHRABL_BUF(dlMsg.rrcMsgPdu, dlMsg.rrcMsgSize);
15892              if(dlMsg.rrcMsgPdu)
15893              {
15894                 memcpy(dlMsg.rrcMsgPdu, f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf,\
15895                       dlMsg.rrcMsgSize);
15896              }
15897              else
15898              {
15899                 DU_LOG("\nERROR  -->  DU APP : Memory alloc Failed at RRC Container at procF1DlRrcMsgTrans()");
15900                 return RFAILED;
15901              }
15902           }
15903           else
15904           {
15905              DU_LOG("\nERROR  -->  DU_APP : RRC Container Size is invalid:%ld",\
15906                    f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
15907              return RFAILED;
15908           }
15909           break;
15910        }
15911     case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15912        {
15913           dlMsg.deliveryStatRpt = true;
15914           break;
15915        }
15916     default:
15917        DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
15918              f1DlRrcMsg->protocolIEs.list.array[idx]->id);
15919       }
15920    }
15921
15922    ret = duProcDlRrcMsg(&dlMsg);
15923
15924    freeAperDecodef1DlRrcMsg(f1DlRrcMsg);
15925    return ret;
15926 }
15927 /*******************************************************************
15928  *
15929 * @brief Builds the DRB to be Setup Mod list
15930 *
15931 * @details
15932 *
15933 *    Function : 
15934 *
15935 *    Functionality: Constructs the DRB to be Setup Mod list
15936 *
15937 * @params[in] DRBs_SetupMod_List_t *drbSet
15938 *
15939 * @return ROK     - success
15940 *         RFAILED - failure
15941 *
15942 * ****************************************************************/
15943 uint8_t BuildSrbSetupModList(SRBs_SetupMod_List_t *srbList, DuUeCfg *ueCfg)
15944 {
15945    uint8_t srbIdx = 0;
15946    struct SRBs_SetupMod_ItemIEs *srbItemIe;
15947
15948    srbList->list.count = ueCfg->numRlcLcs;
15949    srbList->list.size = srbList->list.count * sizeof(SRBs_SetupMod_ItemIEs_t *);
15950
15951    DU_ALLOC(srbList->list.array, srbList->list.size);
15952    if(srbList->list.array == NULLP)
15953    {
15954       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15955       return RFAILED;
15956    }
15957
15958    for(srbIdx = 0; srbIdx < srbList->list.count; srbIdx++)
15959    {
15960       DU_ALLOC(srbList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15961       if(srbList->list.array[srbIdx] == NULLP)
15962       {
15963          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15964          return RFAILED;
15965       }
15966    } 
15967
15968    for(srbIdx=0; srbIdx < srbList->list.count; srbIdx++)
15969    {
15970       srbItemIe = (struct SRBs_SetupMod_ItemIEs *)srbList->list.array[srbIdx];
15971       srbItemIe->id = ProtocolIE_ID_id_SRBs_SetupMod_Item;
15972       srbItemIe->criticality = Criticality_reject;
15973       srbItemIe->value.present = SRBs_SetupMod_ItemIEs__value_PR_SRBs_SetupMod_Item;
15974       srbItemIe->value.choice.SRBs_SetupMod_Item.sRBID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.rbId;
15975       srbItemIe->value.choice.SRBs_SetupMod_Item.lCID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.lcId;
15976    }
15977    return ROK;
15978 }
15979
15980 /*******************************************************************
15981  *
15982 * @brief Builds the DRB to be Setup Mod list
15983 *
15984 * @details
15985 *
15986 *    Function : 
15987 *
15988 *    Functionality: Constructs the DRB to be Setup Mod list
15989 *
15990 * @params[in] DRBs_SetupMod_List_t *drbSet
15991 *
15992 * @return ROK     - success
15993 *         RFAILED - failure
15994 *
15995 * ****************************************************************/
15996
15997 uint8_t BuildDrbSetupModList(DRBs_SetupMod_List_t *drbSet , DuUeCfg *ueCfg)
15998 {
15999    uint8_t arrIdx =0;
16000    uint8_t drbCnt =0;
16001    struct DRBs_SetupMod_ItemIEs *drbItemIe;
16002
16003    drbCnt = ueCfg->numDrbSetupMod;
16004
16005    drbSet->list.count = drbCnt;
16006    drbSet->list.size = drbCnt * sizeof(DRBs_SetupMod_ItemIEs_t *);
16007    DU_ALLOC(drbSet->list.array, drbSet->list.size);
16008    if(drbSet->list.array == NULLP)
16009    {
16010       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
16011       return  RFAILED;
16012    }
16013    for(arrIdx=0; arrIdx<drbCnt; arrIdx++)
16014    {
16015       DU_ALLOC(drbSet->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
16016       if(drbSet->list.array[arrIdx] == NULLP)
16017       {
16018               DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
16019               return  RFAILED;
16020       }
16021
16022       drbItemIe = (struct DRBs_SetupMod_ItemIEs *)drbSet->list.array[arrIdx];
16023       drbItemIe->id = ProtocolIE_ID_id_DRBs_SetupMod_Item;
16024       drbItemIe->criticality = Criticality_reject;
16025       drbItemIe->value.present = DRBs_SetupMod_ItemIEs__value_PR_DRBs_SetupMod_Item;
16026       drbItemIe->value.choice.DRBs_SetupMod_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
16027       if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List,\
16028       &ueCfg->upTnlInfo[arrIdx])!= ROK)
16029       {
16030          DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbToBeSetupModList");
16031          return RFAILED;
16032       }
16033       
16034    }
16035
16036    return ROK;
16037 }
16038 /*******************************************************************
16039 * @brief Free the memory allocated for DRB setup List
16040 *
16041 * @details
16042 *
16043 *    Function : FreeDrbSetupModList 
16044 *
16045 *    Functionality:
16046 *       Free the memory allocated for DRB setup list
16047 *
16048 * @params[in] DRBs_Setup_List_t *
16049 * @return void
16050 *
16051 * ****************************************************************/
16052 void FreeDrbSetupModList(DRBs_SetupMod_List_t *drbSetupList)
16053 {
16054    uint8_t arrIdx = 0;
16055    DRBs_SetupMod_ItemIEs_t *drbItemIe = NULLP;
16056
16057    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
16058    {
16059       drbItemIe = ((DRBs_SetupMod_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
16060       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List);
16061       DU_FREE(drbSetupList->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
16062    }
16063    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
16064 }
16065
16066 /*******************************************************************
16067 *
16068 * @brief Builds the DRB to be Mod list
16069 *
16070 * @details
16071 *
16072 *    Function : 
16073 *
16074 *    Functionality: Constructs the DRB to be Mod list
16075 *
16076 * @params[in] DRBs_Modified_List_t *drbModList
16077 *
16078 * @return ROK     - success
16079 *         RFAILED - failure
16080 *
16081 * ****************************************************************/
16082
16083 uint8_t BuildDrbModList(DRBs_Modified_List_t *drbModList, DuUeCfg *ueCfg)
16084 {
16085    uint8_t arrIdx =0, drbIdx = 0;
16086    uint8_t drbCnt =0;
16087    struct DRBs_Modified_ItemIEs *drbItemIe;
16088
16089    drbCnt = ueCfg->numDrbModified;
16090
16091    drbModList->list.count = drbCnt;
16092    drbModList->list.size = drbCnt * sizeof(DRBs_Modified_ItemIEs_t *);
16093    DU_ALLOC(drbModList->list.array, drbModList->list.size);
16094    if(drbModList->list.array == NULLP)
16095    {
16096       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList()");
16097       return  RFAILED;
16098    }
16099
16100    drbIdx = 0;
16101    for(arrIdx = 0; arrIdx < ueCfg->numMacLcs; arrIdx++)
16102    {
16103       if(ueCfg->macLcCfg[arrIdx].configType == CONFIG_MOD)
16104       {
16105          DU_ALLOC(drbModList->list.array[drbIdx], sizeof(DRBs_Modified_ItemIEs_t));
16106          if(drbModList->list.array[drbIdx] == NULLP)
16107          {
16108             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList");
16109             return  RFAILED;
16110          }
16111
16112          drbItemIe = (struct DRBs_Modified_ItemIEs *)drbModList->list.array[drbIdx];
16113          drbItemIe->id = ProtocolIE_ID_id_DRBs_Modified_Item;
16114          drbItemIe->criticality = Criticality_reject;
16115          drbItemIe->value.present = DRBs_Modified_ItemIEs__value_PR_DRBs_Modified_Item;
16116          drbItemIe->value.choice.DRBs_Modified_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
16117          if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List,\
16118                   &ueCfg->upTnlInfo[arrIdx])!= ROK)
16119          {
16120             DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbModList");
16121             return RFAILED;
16122          }
16123          drbIdx++;
16124       } 
16125    }
16126
16127    return ROK;
16128 }
16129
16130 /*******************************************************************
16131 * @brief Free the memory allocated for DRB Mod List
16132 *
16133 * @details
16134 *
16135 *    Function : FreeDrbModList 
16136 *
16137 *    Functionality:
16138 *       Free the memory allocated for DRB modified list
16139 *
16140 * @params[in] DRBs_Modified_List_t *
16141 * @return void
16142 *
16143 * ****************************************************************/
16144 void FreeDrbModList(DRBs_Modified_List_t *drbModList)
16145 {
16146    uint8_t arrIdx = 0;
16147    DRBs_Modified_ItemIEs_t *drbItemIe = NULLP;
16148
16149    for(arrIdx = 0; arrIdx < drbModList->list.count; arrIdx++)
16150    {
16151       drbItemIe = ((DRBs_Modified_ItemIEs_t *)drbModList->list.array[arrIdx]);
16152       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List);
16153       DU_FREE(drbModList->list.array[arrIdx], sizeof(DRBs_Modified_ItemIEs_t));
16154    }
16155    DU_FREE(drbModList->list.array, drbModList->list.size);
16156 }
16157
16158 /*******************************************************************
16159 * @brief Free the memory allocated for SRB setup List
16160 *
16161 * @details
16162 *
16163 *    Function : FreeSrbSetupModList 
16164 *
16165 *    Functionality:
16166 *       Free the memory allocated for SRB setup list
16167 *
16168 * @params[in] SRBs_Setup_List_t *
16169 * @return void
16170 *
16171 * ****************************************************************/
16172 void FreeSrbSetupModList(SRBs_SetupMod_List_t *srbSetupList)
16173 {
16174    uint8_t srbIdx = 0;
16175    
16176    for(srbIdx = 0; srbIdx < srbSetupList->list.count; srbIdx++)
16177       DU_FREE(srbSetupList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
16178    DU_FREE(srbSetupList->list.array, srbSetupList->list.size);
16179 }
16180
16181 /*******************************************************************
16182 * @brief Free the memory allocated for UE Context Mod Response
16183 *
16184 * @details
16185 *
16186 *    Function : FreeUeContextModResp 
16187 *
16188 *    Functionality:
16189 *       Free the memory allocated for UE Context Mod Response
16190 *
16191 * @params[in] F1AP_PDU_t *f1apMsg
16192 * @return void
16193 *
16194 * ****************************************************************/
16195
16196 void FreeUeContextModResp(F1AP_PDU_t *f1apMsg)
16197 {
16198    uint8_t ieIdx;
16199    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
16200    if(f1apMsg)
16201    {
16202       if(f1apMsg->choice.successfulOutcome)
16203       {
16204          ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
16205          if(ueContextModifyRes->protocolIEs.list.array)
16206          {
16207             for(ieIdx=0 ; ieIdx<ueContextModifyRes->protocolIEs.list.count; ieIdx++)
16208             {
16209                if(ueContextModifyRes->protocolIEs.list.array[ieIdx])
16210                {
16211                   switch(ueContextModifyRes->protocolIEs.list.array[ieIdx]->id)
16212                   {
16213                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16214                         break;
16215                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16216                         break;
16217                      case ProtocolIE_ID_id_DRBs_SetupMod_List:
16218                         {
16219                             FreeDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16220                             value.choice.DRBs_SetupMod_List));
16221                             break;
16222                         }
16223                      case ProtocolIE_ID_id_DRBs_Modified_List:
16224                         {
16225                             FreeDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16226                             value.choice.DRBs_Modified_List));
16227                             break;
16228                         }
16229                      case ProtocolIE_ID_id_SRBs_SetupMod_List:
16230                         {
16231                            FreeSrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
16232                               SRBs_SetupMod_List));
16233                            break; 
16234                         }
16235                   }
16236                   DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
16237                }
16238
16239             }
16240             DU_FREE(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
16241          }
16242          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16243       }
16244       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
16245    }
16246 }
16247
16248 /*****************************************************************i
16249 *
16250 * @brief Creating the ue context modifcation response and sending
16251 *
16252 * @details
16253 *
16254 *    Function : BuildAndSendUeContextModRsp 
16255 *
16256 *    Functionality:
16257 *         - Creating the ue context modifcation response 
16258 *
16259 * @params[in] uint8_t cellId,uint8_t ueId
16260 * @return ROK     - success
16261 *         RFAILED - failure
16262 *
16263 * ****************************************************************/
16264 uint8_t BuildAndSendUeContextModRsp(DuUeCb *ueCb)
16265 {
16266    uint8_t   ieIdx = 0, tnlIdx = 0, rbIdx = 0;
16267    uint8_t   elementCnt = 0;
16268    uint8_t   ret = RFAILED;
16269    F1AP_PDU_t *f1apMsg = NULLP;
16270    asn_enc_rval_t  encRetVal;
16271    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
16272
16273    DU_LOG("\nINFO  -->  F1AP : Building UE context modification response\n");
16274
16275    while(true)
16276    {
16277       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
16278       if(f1apMsg == NULLP)
16279       {
16280          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16281          break;
16282       }
16283
16284       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
16285
16286       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16287       if(f1apMsg->choice.successfulOutcome == NULLP)
16288       {
16289          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16290          break;
16291       }
16292       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextModification;
16293       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
16294       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_UEContextModificationResponse;
16295
16296       ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
16297   
16298       if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
16299       {
16300          elementCnt = 2;
16301          if(ueCb->f1UeDb->duUeCfg.numDrbSetupMod)
16302             elementCnt++;
16303          if(ueCb->f1UeDb->duUeCfg.numDrbModified)
16304             elementCnt++; 
16305       }
16306       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16307       {
16308          elementCnt = 5;
16309       }
16310       if(ueCb->f1UeDb->actionType == UE_CTXT_RRC_RECFG_COMPLETE)
16311          elementCnt = 2;
16312       ueContextModifyRes->protocolIEs.list.count = elementCnt;
16313       ueContextModifyRes->protocolIEs.list.size = elementCnt*sizeof(UEContextModificationResponse_t*);
16314
16315       /* Initialize the UE context modification members */
16316       DU_ALLOC(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
16317       if(ueContextModifyRes->protocolIEs.list.array == NULLP)
16318       {
16319          DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16320          break;
16321       }
16322
16323       for(ieIdx=0 ; ieIdx<elementCnt; ieIdx++)
16324       {
16325          DU_ALLOC(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
16326          if(ueContextModifyRes->protocolIEs.list.array[ieIdx] == NULLP)
16327          {
16328             DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16329             break;
16330          }
16331       }
16332
16333       ieIdx=0;
16334       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
16335       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16336       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16337       UEContextModificationResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
16338       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
16339
16340       ieIdx++;
16341       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16342       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16343       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present=\
16344       UEContextModificationResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
16345       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
16346
16347       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16348       {
16349          ieIdx++;
16350          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCInformation;
16351          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16352          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16353          UEContextModificationResponseIEs__value_PR_DUtoCURRCInformation;
16354          BuildCellGroupConfigRrc(ueCb, &ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
16355       }
16356
16357       if((ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY) || \
16358            ((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbSetupMod)))
16359       { 
16360          ieIdx++;
16361          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_SetupMod_List;
16362          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16363          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16364                                                                            UEContextModificationResponseIEs__value_PR_DRBs_SetupMod_List;
16365          if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16366          {
16367             for(tnlIdx = 0; tnlIdx < duCb.numTeId; tnlIdx++)
16368             {
16369                if(duCb.upTnlCfg[tnlIdx]->ueId == ueCb->gnbDuUeF1apId)
16370                {
16371                   memcpy(&ueCb->f1UeDb->duUeCfg.upTnlInfo[ueCb->f1UeDb->duUeCfg.numDrbSetupMod++], duCb.upTnlCfg[tnlIdx], sizeof(UpTnlCfg));
16372                }
16373             }
16374          }
16375          ret = BuildDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16376                   value.choice.DRBs_SetupMod_List) , &ueCb->f1UeDb->duUeCfg);
16377          if(ret != ROK)
16378          {
16379             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB setupmod List ");
16380             break;
16381          }
16382       }
16383
16384       if((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbModified))
16385       { 
16386          ieIdx++;
16387          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_Modified_List;
16388          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16389          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16390                                                                     UEContextModificationResponseIEs__value_PR_DRBs_Modified_List;
16391          ret = BuildDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16392                                  value.choice.DRBs_Modified_List) , &ueCb->f1UeDb->duUeCfg);
16393          if(ret != ROK)
16394          {
16395             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB Modified List ");
16396             break;
16397          }
16398       }
16399
16400       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16401       {
16402          ieIdx++;
16403          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_SRBs_SetupMod_List;
16404          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16405          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16406                                                                             UEContextModificationResponseIEs__value_PR_SRBs_SetupMod_List;
16407          for(rbIdx = 0; rbIdx < ueCb->duRlcUeCfg.numLcs; rbIdx++)
16408          {
16409             if(ueCb->duRlcUeCfg.rlcLcCfg[rbIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
16410             {
16411                memcpy(&ueCb->f1UeDb->duUeCfg.rlcLcCfg[ueCb->f1UeDb->duUeCfg.numRlcLcs++], &ueCb->duRlcUeCfg.rlcLcCfg[rbIdx],\
16412                      sizeof(DuRlcBearerCfg));
16413             }
16414          }
16415          ret = BuildSrbSetupModList(&ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.SRBs_SetupMod_List, \
16416                &ueCb->f1UeDb->duUeCfg);
16417          if(ret != ROK)
16418          {
16419             DU_LOG( "\nERROR  -->  F1AP : Failed to build SRB setupmod List ");
16420             break;
16421          }
16422       }
16423
16424       freeF1UeDb(ueCb->f1UeDb);
16425       ueCb->f1UeDb = NULLP;
16426
16427       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16428
16429       /* Encode the F1SetupRequest type as APER */
16430       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16431       encBufSize = 0;
16432       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,encBuf);
16433
16434       /* Encode results */
16435       if(encRetVal.encoded == ENCODE_FAIL)
16436       {
16437          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Modification Response structure (at %s)\n",\
16438                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16439          ret = RFAILED;
16440          break;
16441       }
16442       else
16443       {
16444          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Modification Response\n");
16445 #ifdef DEBUG_ASN_PRINT
16446          for(int i=0; i< encBufSize; i++)
16447          {
16448             printf("%x",encBuf[i]);
16449          }
16450 #endif
16451       }
16452
16453       /* Sending  msg  */
16454       if(sendF1APMsg() != ROK && (ret == ROK))
16455       {
16456          DU_LOG("\nERROR  -->  F1AP : Sending UE Modification Res Failed");
16457          ret = RFAILED;
16458          break;
16459       }
16460
16461       ret = ROK;
16462       break;
16463    }
16464    FreeUeContextModResp(f1apMsg);
16465    return ret;
16466 }
16467
16468 /*******************************************************************
16469  *
16470  * @brief Deallocating the memory allocated by the aper decoder
16471  *          for QOSInfo
16472  *
16473  * @details
16474  *
16475  *    Function : freeAperDecodeQosInfo
16476  *
16477  *    Functionality:  Deallocating the memory allocated for QOSInfo
16478  *
16479  * @params[in] QoSFlowLevelQoSParameters_t *drbQos
16480  *
16481  * @return void
16482  *
16483  * ****************************************************************/
16484
16485 void freeAperDecodeQosInfo(QoSFlowLevelQoSParameters_t *drbQos)
16486 {
16487    if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI != NULLP)
16488    {
16489       if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
16490       {
16491          if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
16492          {
16493             free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
16494          }
16495          free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
16496       }
16497       free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI);
16498    }
16499 }
16500 /*******************************************************************
16501  *
16502  * @brief Deallocating the memory allocated by the aper decoder
16503  *          for UlTnlInfoforDrb
16504  *
16505  * @details
16506  *
16507  *    Function : freeAperDecodeUlTnlInfoforDrbSetupMod 
16508  *
16509  *    Functionality:  Deallocating memory allocated for UlTnlInfoforDrb
16510  *
16511  * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
16512  *
16513  * @return void
16514  *
16515  * ****************************************************************/
16516 void freeAperDecodeUlTnlInfoforDrbSetupMod(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
16517 {
16518    uint8_t arrIdx =0;
16519
16520    if(ulInfo->list.array)
16521    {
16522       for(arrIdx=0; arrIdx<ulInfo->list.count ; arrIdx++)
16523       {
16524          if(ulInfo->list.array[arrIdx])
16525          {
16526             if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel )
16527             {
16528                if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf)
16529                {
16530                   if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf)
16531                   {
16532                      free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16533                            gTP_TEID.buf);
16534                   }
16535                   free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16536                         transportLayerAddress.buf);
16537                }
16538                free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel);
16539             }
16540             free(ulInfo->list.array[arrIdx]);
16541          }
16542       }
16543       free(ulInfo->list.array);
16544    }
16545 }
16546
16547 /*******************************************************************
16548  *
16549  * @brief Deallocating the memory allocated by the aper decoder
16550  *          for DrbSetupModItem  
16551  *
16552  * @details
16553  *
16554  *    Function : freeAperDecodeDrbSetupModItem 
16555  *
16556  *    Functionality:  Deallocating memory allocated for DrbSetupModItem
16557  *
16558  * @params[in] DRBs_ToBeSetupMod_Item_t *drbItem
16559  *
16560  * @return void
16561  *
16562  * ****************************************************************/
16563
16564 void freeAperDecodeDrbSetupModItem(DRBs_ToBeSetupMod_Item_t *drbItem)
16565 {
16566    uint8_t arrIdx =0;
16567    SNSSAI_t *snssai =NULLP;
16568    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16569
16570    drbItem->qoSInformation.present = QoSInformation_PR_choice_extension;
16571    switch(drbItem->qoSInformation.present)
16572    {
16573       case QoSInformation_PR_NOTHING:
16574          break;
16575       case QoSInformation_PR_eUTRANQoS:
16576          {
16577             if(drbItem->qoSInformation.choice.eUTRANQoS)
16578             {
16579                free(drbItem->qoSInformation.choice.eUTRANQoS);
16580             }
16581             break;
16582          }
16583       case QoSInformation_PR_choice_extension:
16584          {
16585             if(drbItem->qoSInformation.choice.choice_extension)
16586             {
16587                freeAperDecodeQosInfo(&drbItem->qoSInformation.choice.choice_extension->value.choice.\
16588                      DRB_Information.dRB_QoS);
16589                snssai = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16590                if(snssai->sST.buf)
16591                {
16592                   free(snssai->sST.buf);
16593                }
16594                if(snssai->sD)
16595                {
16596                   if(snssai->sD->buf)
16597                   {
16598                      free(snssai->sD->buf);
16599                   }
16600                   free(snssai->sD);
16601                }
16602
16603                flowMap = &drbItem->qoSInformation.choice.choice_extension->value.choice.\
16604                          DRB_Information.flows_Mapped_To_DRB_List;
16605                if(flowMap->list.array)
16606                {
16607                   for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16608                   {
16609                      if(flowMap->list.array[arrIdx] )
16610                      {
16611                         freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16612                         free(flowMap->list.array[arrIdx]);
16613                      }
16614                   }
16615                   free(flowMap->list.array);
16616                }
16617
16618                free(drbItem->qoSInformation.choice.choice_extension);
16619             }
16620             break;
16621          }
16622
16623    }
16624    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16625    if(drbItem->uLConfiguration)
16626    {
16627       free(drbItem->uLConfiguration);
16628    }
16629 }
16630
16631 /*******************************************************************
16632  *
16633  * @brief Deallocating the memory allocated by the aper decoder
16634  *          for DrbToBeSetupModList
16635  *
16636  * @details
16637  *
16638  *    Function : freeAperDecodeDrbToBeSetupModList
16639  *
16640  *    Functionality:  Deallocating memory allocated for DrbToBeSetupModList
16641  *
16642  * @params[in] DRBs_ToBeSetupMod_List_t *drbSet
16643  *
16644  * @return void
16645  *
16646  * ****************************************************************/
16647
16648 void freeAperDecodeDrbToBeSetupModList(DRBs_ToBeSetupMod_List_t *drbSet)
16649 {
16650    uint8_t arrIdx =0;
16651    struct DRBs_ToBeSetupMod_ItemIEs *drbItemIe;
16652
16653    if(drbSet->list.array)
16654    {
16655       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16656       {
16657          if(drbSet->list.array[arrIdx] != NULLP)
16658          {
16659             if(arrIdx == 0)
16660             {
16661                drbItemIe = (DRBs_ToBeSetupMod_ItemIEs_t *)drbSet->list.array[arrIdx];
16662                freeAperDecodeDrbSetupModItem(&(drbItemIe->value.choice.DRBs_ToBeSetupMod_Item));
16663             }
16664             free(drbSet->list.array[arrIdx]);
16665          }
16666       }
16667       free(drbSet->list.array);
16668    }
16669
16670 }
16671
16672 /*******************************************************************
16673  *
16674  * @brief Deallocating the memory allocated by the aper decoder
16675  *          for DrbSetupModItem  
16676  *
16677  * @details
16678  *
16679  *    Function : freeAperDecodeDrbModifiedItem 
16680  *
16681  *    Functionality:  Deallocating memory allocated for DrbModifedItem
16682  *
16683  * @params[in] DRBs_ToBeModified_Item_t *drbItem
16684  *
16685  * @return void
16686  *
16687  * ****************************************************************/
16688
16689 void freeAperDecodeDrbModifiedItem(DRBs_ToBeModified_Item_t *drbItem)
16690 {
16691    uint8_t arrIdx =0;
16692    SNSSAI_t *snssai =NULLP;
16693    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16694
16695    if(drbItem->qoSInformation != NULLP)
16696    {
16697       drbItem->qoSInformation->present = QoSInformation_PR_choice_extension;
16698       switch(drbItem->qoSInformation->present)
16699       {
16700          case QoSInformation_PR_NOTHING:
16701             break;
16702          case QoSInformation_PR_eUTRANQoS:
16703             {
16704                if(drbItem->qoSInformation->choice.eUTRANQoS)
16705                {
16706                   free(drbItem->qoSInformation->choice.eUTRANQoS);
16707                }
16708                break;
16709             }
16710          case QoSInformation_PR_choice_extension:
16711             {
16712                if(drbItem->qoSInformation->choice.choice_extension)
16713                {
16714                   freeAperDecodeQosInfo(&drbItem->qoSInformation->choice.choice_extension->value.choice.\
16715                         DRB_Information.dRB_QoS);
16716                   snssai = &drbItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16717                   if(snssai->sST.buf)
16718                   {
16719                      free(snssai->sST.buf);
16720                   }
16721                   if(snssai->sD)
16722                   {
16723                      if(snssai->sD->buf)
16724                      {
16725                         free(snssai->sD->buf);
16726                      }
16727                      free(snssai->sD);
16728                   }
16729
16730                   flowMap = &drbItem->qoSInformation->choice.choice_extension->value.choice.\
16731                             DRB_Information.flows_Mapped_To_DRB_List;
16732                   if(flowMap->list.array)
16733                   {
16734                      for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16735                      {
16736                         if(flowMap->list.array[arrIdx] )
16737                         {
16738                            freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16739                            free(flowMap->list.array[arrIdx]);
16740                         }
16741                      }
16742                      free(flowMap->list.array);
16743                   }
16744
16745                   free(drbItem->qoSInformation->choice.choice_extension);
16746                }
16747                break;
16748             }
16749       }
16750       free(drbItem->qoSInformation);
16751    }
16752    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16753    if(drbItem->uLConfiguration)
16754    {
16755       free(drbItem->uLConfiguration);
16756    }
16757 }
16758
16759 /*******************************************************************
16760  *
16761  * @brief Deallocating the memory allocated by the aper decoder
16762  *          for DrbToBeSetupModList
16763  *
16764  * @details
16765  *
16766  *    Function : freeAperDecodeDrbToBeModifiedList
16767  *
16768  *    Functionality:  Deallocating memory allocated for DrbToBeModifiedList
16769  *
16770  * @params[in] DRBs_ToBeModified_List_t *drbSet
16771  *
16772  * @return void
16773  *
16774  * ****************************************************************/
16775
16776 void freeAperDecodeDrbToBeModifiedList(DRBs_ToBeModified_List_t *drbSet)
16777 {
16778    uint8_t arrIdx =0;
16779    struct DRBs_ToBeModified_ItemIEs *drbItemIe;
16780
16781    if(drbSet->list.array)
16782    {
16783       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16784       {
16785          if(drbSet->list.array[arrIdx] != NULLP)
16786          {
16787             if(arrIdx == 0)
16788             {
16789                drbItemIe = (DRBs_ToBeModified_ItemIEs_t *)drbSet->list.array[arrIdx];
16790                freeAperDecodeDrbModifiedItem(&(drbItemIe->value.choice.DRBs_ToBeModified_Item));
16791             }
16792             free(drbSet->list.array[arrIdx]);
16793          }
16794       }
16795       free(drbSet->list.array);
16796    }
16797
16798 }
16799
16800 /*******************************************************************
16801  *
16802  * @brief Deallocating the memory allocated by the aper decoder
16803  *          for DrbToBeSetupModList
16804  *
16805  * @details
16806  *
16807  *    Function : freeAperDecodeDrbToBeReleasedList
16808  *
16809  *    Functionality:  Deallocating memory allocated for DrbToBeReleasedList
16810  *
16811  * @params[in] DRBs_ToBeReleased_List_t *drbSet
16812  *
16813  * @return void
16814  *
16815  * ****************************************************************/
16816
16817 void freeAperDecodeDrbToBeReleasedList(DRBs_ToBeReleased_List_t *drbSet)
16818 {
16819    uint8_t arrIdx =0;
16820
16821    if(drbSet->list.array)
16822    {
16823       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16824       {
16825          if(drbSet->list.array[arrIdx] != NULLP)
16826          {
16827             free(drbSet->list.array[arrIdx]);
16828          }
16829       }
16830       free(drbSet->list.array);
16831    }
16832
16833 }
16834 /*******************************************************************
16835  *
16836  * @brief Deallocating the memory allocated by the aper decoder
16837  *          for UeContextModificationReqMsg
16838  *
16839  * @details
16840  *
16841  *    Function : freeAperDecodeUeContextModificationReqMsg
16842  *
16843  *    Functionality:  Deallocating memory allocated for
16844  *                  UeContextModificationReqMsg
16845  *
16846  * @params[in] UEContextModificationRequest_t *UeContextModifyReq
16847  *
16848  * @return void
16849  *
16850  * ****************************************************************/
16851 void freeAperDecodeUeContextModificationReqMsg(UEContextModificationRequest_t *ueContextModifyReq )
16852 {
16853    uint8_t arrIdx, ieId;
16854
16855    if(ueContextModifyReq->protocolIEs.list.array)
16856    {
16857       for( arrIdx = 0 ; arrIdx<ueContextModifyReq->protocolIEs.list.count ; arrIdx++)
16858       {
16859          if(ueContextModifyReq->protocolIEs.list.array[arrIdx])
16860          {
16861             ieId = ueContextModifyReq->protocolIEs.list.array[arrIdx]->id;
16862             switch(ieId)
16863             {
16864                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16865                   break;
16866                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16867                   break;
16868                case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
16869                   {
16870                      freeAperDecodeDrbToBeSetupModList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16871                            value.choice.DRBs_ToBeSetupMod_List);
16872                      break;
16873                   }
16874                case ProtocolIE_ID_id_DRBs_ToBeModified_List:
16875                   {
16876                      freeAperDecodeDrbToBeModifiedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16877                            value.choice.DRBs_ToBeModified_List);
16878                      break;
16879                   }
16880                case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
16881                   {
16882                      freeAperDecodeDrbToBeReleasedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16883                            value.choice.DRBs_ToBeReleased_List);
16884                      break;
16885                   }
16886                case ProtocolIE_ID_id_TransmissionActionIndicator:
16887                   break;
16888                case ProtocolIE_ID_id_RRCContainer:
16889                   {
16890                      free(ueContextModifyReq->protocolIEs.list.array[arrIdx]->value.choice.RRCContainer.buf);
16891                   }
16892             }
16893             free(ueContextModifyReq->protocolIEs.list.array[arrIdx]);
16894          }
16895       }
16896       free(ueContextModifyReq->protocolIEs.list.array);
16897    }
16898 }
16899 /*******************************************************************
16900  *
16901  * @brief processing the F1 UeContextModificationReq
16902  *
16903  * @details
16904  *
16905  *    Function : procF1UeContextModificationReq
16906  *
16907  *    Functionality:  processing the F1 UeContextModificationReq
16908  *
16909  * @params[in] F1AP_PDU_t *f1apMsg
16910  *
16911  * @return
16912  * ****************************************************************/
16913 uint8_t procF1UeContextModificationReq(F1AP_PDU_t *f1apMsg)
16914 {
16915    UEContextModificationRequest_t *ueContextModifyReq = NULLP;
16916    uint8_t  ret = ROK, ieIdx = 0, cellIdx=0;
16917    DuUeCb   *duUeCb = NULLP;
16918    DRBs_ToBeSetupMod_List_t *drbSetupModCfg = NULLP;
16919    DRBs_ToBeModified_List_t *drbModifiedCfg = NULLP;
16920    DRBs_ToBeReleased_List_t *drbToRelease = NULLP;
16921    uint32_t gnbCuUeF1apId, gnbDuUeF1apId;
16922
16923    ueContextModifyReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextModificationRequest;
16924    for(ieIdx=0; (ieIdx < ueContextModifyReq->protocolIEs.list.count && ret == ROK); ieIdx++)
16925    {
16926       switch(ueContextModifyReq->protocolIEs.list.array[ieIdx]->id)
16927       {
16928          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16929             {
16930                gnbCuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
16931                break;
16932             }
16933          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16934             {
16935                gnbDuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
16936                for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
16937                {
16938                   if(duCb.actvCellLst[cellIdx])
16939                   {
16940                      if((duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbDuUeF1apId == gnbDuUeF1apId)&&\
16941                            (duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbCuUeF1apId == gnbCuUeF1apId))
16942                      {
16943                         duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1];
16944                         if(duUeCb->f1UeDb == NULLP)
16945                         {
16946                            DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
16947                            duUeCb->f1UeDb->cellIdx = cellIdx;
16948                            duUeCb->f1UeDb->actionType = UE_CTXT_MOD;
16949                         }
16950                         break;
16951                      }
16952                   }
16953                }
16954                if(duUeCb == NULLP)
16955                {
16956                   DU_LOG("\nERROR  -->  DU APP : wrong values of gnbCuUeF1apId and gnbDuUeF1apId ");
16957                   ret = RFAILED;
16958                }
16959                break;
16960             }
16961
16962          case ProtocolIE_ID_id_RRCContainer:
16963             {
16964                /* Filling Dl RRC Msg Info */
16965                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
16966                if(!duUeCb->f1UeDb->dlRrcMsg)
16967                {
16968                   DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16969                         Memory allocation failed ");
16970                   ret = RFAILED;
16971                }
16972                else
16973                {
16974                   duUeCb->f1UeDb->dlRrcMsgPres = true;
16975                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
16976                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
16977                         &ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
16978                         value.choice.RRCContainer);
16979                }
16980
16981                break;
16982             }
16983
16984          case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
16985          case ProtocolIE_ID_id_DRBs_ToBeModified_List:
16986          case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
16987             {
16988                if(duUeCb->f1UeDb)
16989                {
16990                   /*DRBs to be Added*/
16991                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present ==\
16992                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List)
16993                   {
16994                      drbSetupModCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
16995                                       choice.DRBs_ToBeSetupMod_List;
16996
16997                      if(extractDrbListToSetupMod(NULL, drbSetupModCfg, NULL, drbSetupModCfg->list.count,\
16998                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULL))
16999                      {
17000                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbSetupModList");
17001                         ret = RFAILED;
17002                      }
17003                   }
17004
17005                   /*DRBs to be Modified*/
17006                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
17007                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List)
17008
17009                   {
17010                      drbModifiedCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17011                                       choice.DRBs_ToBeModified_List;
17012                      if(extractDrbListToSetupMod(NULL, NULL, drbModifiedCfg, drbModifiedCfg->list.count,\
17013                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, &duUeCb->duRlcUeCfg))
17014                      {
17015                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
17016                         ret = RFAILED;
17017                      }
17018                   }
17019                   /*DRBs to be Released*/
17020                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
17021                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeReleased_List)
17022
17023                   {
17024                      drbToRelease = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17025                                       choice.DRBs_ToBeReleased_List;
17026                      if(extractDrbListToRelease(gnbDuUeF1apId, drbToRelease, drbToRelease->list.count,\
17027                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->duRlcUeCfg))
17028                      {
17029                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
17030                         ret = RFAILED;
17031                      }
17032                   }
17033                }
17034                break;
17035             }
17036
17037          case ProtocolIE_ID_id_GNB_DUConfigurationQuery:
17038             {
17039                DU_LOG("\nINFO  -->  DU APP : Received GNB DU Configuration Query in UE Context Modification Request from CU");
17040                if(duUeCb->f1UeDb)
17041                {
17042                   duUeCb->f1UeDb->actionType = UE_CTXT_CFG_QUERY;
17043                }
17044                break;
17045             }
17046
17047          case ProtocolIE_ID_id_RRCReconfigurationCompleteIndicator:
17048             {
17049                if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.RRCReconfigurationCompleteIndicator == \
17050                   RRCReconfigurationCompleteIndicator_true)
17051                {
17052                   duUeCb->f1UeDb->actionType = UE_CTXT_RRC_RECFG_COMPLETE;
17053                }
17054                break;
17055             }
17056          case ProtocolIE_ID_id_TransmissionActionIndicator:
17057             {
17058                if(duUeCb->f1UeDb)
17059                {
17060                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.TransmissionActionIndicator  == TransmissionActionIndicator_stop)
17061                   {
17062                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = STOP_TRANSMISSION; 
17063                   }
17064                   else 
17065                   {
17066                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = RESTART_TRANSMISSION; 
17067                   }
17068                }
17069                break;
17070             }
17071
17072          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
17073             {
17074                if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
17075                {
17076                   duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
17077                }
17078                break;
17079             }
17080 #ifdef NR_DRX
17081          case ProtocolIE_ID_id_DRXConfigurationIndicator:
17082             {
17083                duUeCb->f1UeDb->duUeCfg.drxConfigIndicatorRelease = true;
17084                break;
17085             }
17086 #endif
17087               
17088       }
17089    }
17090
17091    if(ret != RFAILED) 
17092    {
17093       ret = duProcUeContextModReq(duUeCb);
17094    }
17095    freeAperDecodeUeContextModificationReqMsg(ueContextModifyReq);
17096    return ret; 
17097 }
17098
17099 /*****************************************************************i
17100 *
17101 * @brief Free memory allocated for UE Context Release Request
17102 *
17103 * @details
17104 *
17105 *    Function : FreeUeContextReleaseReq
17106 *
17107 *    Functionality:
17108 *         - Free memory allocated for UE Context Release Request
17109 *
17110 * @params[in] F1AP_PDU_t *f1apMsg
17111 * @return void 
17112 *
17113 * *************************************************************/
17114 void FreeUeContextReleaseReq(F1AP_PDU_t *f1apMsg)
17115 {
17116    uint8_t ieIdx;
17117    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
17118    
17119    if(f1apMsg)
17120    {
17121       if(f1apMsg->choice.initiatingMessage)
17122       {
17123          ueReleaseReq =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
17124          if(ueReleaseReq->protocolIEs.list.array)
17125          {
17126             for(ieIdx=0 ; ieIdx<ueReleaseReq->protocolIEs.list.count; ieIdx++)
17127             {
17128                DU_FREE(ueReleaseReq->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseRequest_t));
17129             }
17130             DU_FREE(ueReleaseReq->protocolIEs.list.array, ueReleaseReq->protocolIEs.list.size);
17131          }
17132          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
17133       }
17134       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
17135    }
17136
17137 }
17138 /*****************************************************************i
17139 *
17140 * @brief Build and Send UE Context Release Request  
17141 *
17142 * @details
17143 *
17144 *    Function : BuildAndSendUeContextReleaseReq
17145 *
17146 *    Functionality:
17147 *         - Build and Send UE Context Release Request 
17148 *
17149 * @params[in]
17150 * @return ROK     - success
17151 *         RFAILED - failure
17152 *
17153 * *************************************************************/
17154 uint8_t BuildAndSendUeContextReleaseReq(uint16_t cellId, uint8_t ueId)
17155 {
17156    bool memAllocFail = false;
17157    uint8_t ieIdx =0;
17158    uint8_t ret = RFAILED;
17159    uint16_t cellIdx =0;
17160    uint16_t crnti = 0;
17161    uint8_t  elementCnt = 0;
17162    uint32_t  gnbCuUeF1apId =0;   /* gNB-CU UE F1AP Id */
17163    uint32_t  gnbDuUeF1apId =0;   /* gNB-DU UE F1AP Id */
17164    asn_enc_rval_t encRetVal; 
17165    F1AP_PDU_t *f1apMsg = NULLP;
17166    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
17167
17168    DU_LOG("\nINFO  --> Building the UE Context Release Request");
17169    do
17170    {
17171       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
17172       if(f1apMsg == NULLP)
17173       {
17174          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for f1apMsg");
17175          break;
17176       }
17177
17178       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
17179       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
17180       if(f1apMsg->choice.initiatingMessage == NULLP)
17181       {
17182          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for\
17183          initiatingMessage");   
17184          break;
17185       }
17186       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_UEContextReleaseRequest;
17187       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
17188       f1apMsg->choice.initiatingMessage->value.present = \
17189       InitiatingMessage__value_PR_UEContextReleaseRequest;
17190
17191       ueReleaseReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
17192
17193       elementCnt = 2;
17194
17195       ueReleaseReq->protocolIEs.list.count = elementCnt;
17196       ueReleaseReq->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseRequest_t *);
17197
17198       /* Initialize the F1Setup members */
17199       DU_ALLOC(ueReleaseReq->protocolIEs.list.array,ueReleaseReq->protocolIEs.list.size);
17200       if(ueReleaseReq->protocolIEs.list.array == NULLP)
17201       {
17202          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE array");
17203          break;
17204       }
17205       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
17206       {
17207          DU_ALLOC(ueReleaseReq->protocolIEs.list.array[ieIdx],\
17208                sizeof(UEContextReleaseRequest_t));
17209          if(ueReleaseReq->protocolIEs.list.array[ieIdx] == NULLP)
17210          {
17211             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE elements");
17212             memAllocFail = true;  
17213             break;
17214          }
17215       }
17216       if(memAllocFail == true)
17217          break;
17218
17219       /* Fetching Ue Cb Info*/
17220       GET_CELL_IDX(cellId, cellIdx);
17221       if(duCb.actvCellLst[cellIdx] == NULLP)
17222       {
17223          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): CellId[%d] does not exist", cellId);
17224          break;
17225       }
17226       else
17227       {
17228          GET_CRNTI(crnti, ueId);
17229          if(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].crnti != crnti)
17230          {
17231             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): crnti[%d] does not exist", crnti);
17232             break;
17233          }
17234          gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
17235          gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
17236       }
17237
17238       ieIdx=0; 
17239       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID; 
17240       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17241       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present = \
17242       UEContextReleaseRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
17243       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
17244       
17245       ieIdx++;
17246       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
17247       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17248       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present =\
17249       UEContextReleaseRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
17250       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17251       
17252       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17253
17254       /* Encode the F1SetupRequest type as APER */
17255       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17256       encBufSize = 0;
17257       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17258       /* Encode results */
17259       if(encRetVal.encoded == ENCODE_FAIL)
17260       {
17261          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseRequest structure (at %s)\n",\
17262                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17263          break;
17264       }
17265       else
17266       {
17267          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseRequest\n");
17268 #ifdef DEBUG_ASN_PRINT
17269          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17270          {
17271             printf("%x",encBuf[ieIdx]);
17272          }
17273 #endif
17274       }
17275
17276       /* Sending msg */
17277       if(sendF1APMsg() != ROK)
17278       {
17279          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Request failed");
17280          break;
17281       }
17282       ret = ROK;
17283       break;
17284    }while(true);
17285
17286    FreeUeContextReleaseReq(f1apMsg);
17287    return ret;
17288 }
17289 /*****************************************************************i
17290  *
17291  * @brief Free memory allocated for UE Context Release Complete
17292  *
17293  * @details
17294  *
17295  *    Function : FreeUeContextReleaseComplete
17296  *
17297  *    Functionality:
17298  *         - Free memory allocated for UE Context Release Complete
17299  *
17300  * @params[in] F1AP_PDU_t *f1apMsg
17301  * @return void
17302  *
17303  * *************************************************************/
17304 void FreeUeContextReleaseComplete(F1AP_PDU_t *f1apMsg)
17305 {
17306    uint8_t ieIdx;
17307    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17308
17309    if(f1apMsg)
17310    {
17311       if(f1apMsg->choice.successfulOutcome)
17312       {
17313          ueReleaseComplete =&f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17314          if(ueReleaseComplete->protocolIEs.list.array)
17315          {
17316             for(ieIdx=0 ; ieIdx<ueReleaseComplete->protocolIEs.list.count; ieIdx++)
17317             {
17318                DU_FREE(ueReleaseComplete->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseComplete_t));
17319             }
17320             DU_FREE(ueReleaseComplete->protocolIEs.list.array, ueReleaseComplete->protocolIEs.list.size);
17321          }
17322          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17323       }
17324       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
17325    }
17326
17327 }
17328 /*****************************************************************i
17329  *
17330  * @brief Build and Send UE Context Release Complete
17331  *
17332  * @details
17333  *
17334  *    Function : BuildAndSendUeContextReleaseComplete
17335  *
17336  *    Functionality:
17337  *         - Build and Send UE Context Release Complete
17338  *
17339  * @params[in]  cellId,  gnbCuUeF1apId, gnbDuUeF1apId
17340  * @return ROK     - success
17341  *         RFAILED - failure
17342  *
17343  * *************************************************************/
17344 uint8_t BuildAndSendUeContextReleaseComplete(uint16_t cellId, uint32_t gnbCuUeF1apId, uint32_t gnbDuUeF1apId)
17345 {
17346    bool memAllocFail = false;
17347    uint8_t ieIdx =0, ret = RFAILED, elementCnt = 0;
17348    asn_enc_rval_t encRetVal;
17349    F1AP_PDU_t *f1apMsg = NULLP;
17350    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17351
17352    DU_LOG("\nINFO  --> Building the UE Context Release Complete");
17353    do
17354    {
17355       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
17356       if(f1apMsg == NULLP)
17357       {
17358          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for f1apMsg");
17359          break;
17360       }
17361
17362       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
17363       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17364       if(f1apMsg->choice.successfulOutcome == NULLP)
17365       {
17366          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for\
17367                successfulOutcome");
17368          break;
17369       }
17370       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextRelease;
17371       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
17372       f1apMsg->choice.successfulOutcome->value.present = \
17373       SuccessfulOutcome__value_PR_UEContextReleaseComplete;
17374
17375       ueReleaseComplete = &f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17376
17377       elementCnt = 2;
17378       ueReleaseComplete->protocolIEs.list.count = elementCnt;
17379       ueReleaseComplete->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseComplete_t *);
17380
17381       /* Initialize the UE Release Complete members */
17382       DU_ALLOC(ueReleaseComplete->protocolIEs.list.array,ueReleaseComplete->protocolIEs.list.size);
17383       if(ueReleaseComplete->protocolIEs.list.array == NULLP)
17384       {
17385          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE array");
17386          break;
17387       }
17388       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
17389       {
17390          DU_ALLOC(ueReleaseComplete->protocolIEs.list.array[ieIdx],\
17391                sizeof(UEContextReleaseComplete_t));
17392          if(ueReleaseComplete->protocolIEs.list.array[ieIdx] == NULLP)
17393          {
17394             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE\
17395             elements");
17396             memAllocFail = true;
17397             break;
17398          }
17399       }
17400       if(memAllocFail == true)
17401          break;
17402
17403
17404       ieIdx=0;
17405       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
17406       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17407       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present = \
17408       UEContextReleaseCompleteIEs__value_PR_GNB_CU_UE_F1AP_ID;
17409       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
17410
17411       ieIdx++;
17412       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
17413       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17414       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present =\
17415       UEContextReleaseCompleteIEs__value_PR_GNB_DU_UE_F1AP_ID;
17416       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17417
17418       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17419
17420       /* Encode the F1SetupComplete type as APER */
17421       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17422       encBufSize = 0;
17423       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17424       /* Encode results */
17425       if(encRetVal.encoded == ENCODE_FAIL)
17426       {
17427          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseComplete structure (at %s)\n",\
17428                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17429          break;
17430       }
17431       else
17432       {
17433          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseComplete\n");
17434 #ifdef DEBUG_ASN_PRINT
17435          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17436          {
17437             printf("%x",encBuf[ieIdx]);
17438          }
17439 #endif
17440       }
17441
17442       /* Sending msg */
17443       if(sendF1APMsg() != ROK)
17444       {
17445          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Complete failed");
17446          break;
17447       }
17448       ret = ROK;
17449       break;
17450    }while(true);
17451    
17452    if((ret == ROK) && (duCb.actvCellLst[cellId-1]) && (duCb.actvCellLst[cellId-1]->cellStatus == DELETION_IN_PROGRESS) 
17453          && (duCb.actvCellLst[cellId-1]->numActvUes == 0))
17454    {
17455       ret = duSendCellDeletReq(cellId);
17456       if(ret != ROK)
17457       {
17458          DU_LOG("\nERROR  -->  F1AP: BuildAndSendUeContextReleaseComplete(): Failed to process cell\
17459                Delete req for CellId");
17460       }
17461    }
17462    FreeUeContextReleaseComplete(f1apMsg);
17463    return ret;
17464
17465 }
17466
17467 /*******************************************************************
17468 *
17469 * @brief added free part for the memory allocated by aper_decoder 
17470 *
17471 * @details
17472 *
17473 *    Function : freeAperDecodeUeContextReleaseCommand 
17474 *
17475 *    Functionality: added free part for the memory allocated by aper_decoder
17476 *
17477 * @params[in] F1AP_PDU_t *f1apMsg
17478 * @return void
17479 *
17480 * ****************************************************************/
17481 void freeAperDecodeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17482 {
17483    uint8_t ieIdx=0;
17484    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17485
17486    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17487    
17488    if(ueContextReleaseCommand->protocolIEs.list.array)
17489    {
17490       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17491       {
17492          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17493          {
17494             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17495             {
17496                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17497                   break;
17498                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17499                   break;
17500                case ProtocolIE_ID_id_Cause:
17501                   break;
17502                case ProtocolIE_ID_id_RRCContainer:
17503                {
17504                   if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
17505                   {
17506                      free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
17507                   }
17508                   break;
17509                }
17510                default :
17511                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17512                        ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17513                   break;
17514             }
17515          }
17516          free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]);
17517       }
17518       free(ueContextReleaseCommand->protocolIEs.list.array);
17519    }
17520 }
17521 /*******************************************************************
17522 *
17523 * @brief processing of UE Context Release Command
17524 *
17525 * @details
17526 *
17527 *    Function : procF1UeContextReleaseCommand 
17528 *
17529 *    Functionality: processing of UE Context Release Command
17530 *
17531 * @params[in] F1AP_PDU_t *f1apMsg
17532 * @return void
17533 *
17534 * ****************************************************************/
17535 uint8_t procF1UeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17536 {
17537    uint8_t  ieIdx=0, ret=ROK, ueIdx=0;
17538    uint16_t cellIdx =0, cellId = 0;
17539    bool ueIdxFound = false;
17540    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0;
17541    DuUeCb   *duUeCb = NULLP;
17542    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17543
17544    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17545
17546    if(ueContextReleaseCommand->protocolIEs.list.array)
17547    {
17548       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17549       {
17550          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17551          {
17552             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17553             {
17554                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17555                   {
17556                      gnbCuUeF1apId= ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17557                                     value.choice.GNB_CU_UE_F1AP_ID;
17558                      break;
17559                   }
17560
17561                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17562                   {
17563                      gnbDuUeF1apId = ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17564                                      value.choice.GNB_DU_UE_F1AP_ID;
17565                      break;
17566                   }
17567
17568                case ProtocolIE_ID_id_Cause:
17569                   {
17570                      for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
17571                      {
17572                         for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
17573                         {
17574                            if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
17575                                  (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId))
17576                            {
17577                               cellId = duCb.actvCellLst[cellIdx]->cellId;
17578                               duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
17579                               ueIdxFound = true;
17580                               break;
17581                            }
17582                         }
17583                         if(ueIdxFound == true)
17584                         {
17585                            break;
17586                         }
17587                      }
17588                      
17589                      if(!ueIdxFound)
17590                      {
17591                         DU_LOG("\nERROR  -->  F1AP: procF1UeContextReleaseCommand(): Ue Information is not available");
17592                         ret = RFAILED;
17593                      }
17594                      break;
17595                   }
17596
17597                case ProtocolIE_ID_id_RRCContainer:
17598                   {
17599                      if(ueIdxFound == true)  
17600                      {
17601                         DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
17602                         if(duUeCb->f1UeDb)
17603                         {
17604                            memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
17605                            duUeCb->f1UeDb->actionType = UE_CTXT_RELEASE;
17606                            duUeCb->f1UeDb->cellIdx = cellIdx;
17607                            /* Filling Dl RRC Msg Info */
17608                            DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
17609                            if(!duUeCb->f1UeDb->dlRrcMsg)
17610                            {
17611                               DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17612                                     Memory allocation failed ");
17613                               ret = RFAILED;
17614                            }
17615                            else
17616                            {
17617                               duUeCb->f1UeDb->dlRrcMsgPres = true;
17618                               memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
17619                               ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
17620                                     &ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17621                                     value.choice.RRCContainer);
17622                            }
17623
17624                         }
17625                         else
17626                         {
17627                            DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17628                                  Memory allocation failed ");
17629                            ret = RFAILED;
17630
17631                         }
17632                      }
17633                      break;
17634                   }
17635                default :
17636                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17637                         ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17638                   break;
17639             }
17640          }
17641       }
17642    }
17643    if(ret != RFAILED)
17644    {
17645       duProcUeContextReleaseCommand(cellId, duUeCb);
17646    }
17647    freeAperDecodeUeContextReleaseCommand(f1apMsg);
17648    return ret;
17649 }
17650
17651 /**************************************************************
17652  *
17653  * @brief free the memory allocated by aper decoder for paging
17654  *
17655  * @details
17656  *
17657  *    Function : freeAperDecodePagingMsg
17658  *
17659  *    Functionality:
17660  *         - free the memory allocated by aper decoder for
17661  *         the paging f1ap msg
17662  *
17663  * @params[in] Paging_t   *paging
17664  * @return ROK     - success
17665  *         RFAILED - failure
17666  *
17667  ****************************************************************/
17668 void freeAperDecodePagingMsg(Paging_t   *paging)
17669 {
17670    uint8_t ieIdx, cellIdx;
17671    PagingCell_ItemIEs_t *pagingCellItemIes;
17672    PagingCell_Item_t *pagingCellItem;
17673    PagingCell_list_t  *pagingCelllist;
17674
17675    if(paging)
17676    {
17677       if(paging->protocolIEs.list.array)
17678       {
17679          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17680          {
17681             if(paging->protocolIEs.list.array[ieIdx])
17682             {
17683                switch(paging->protocolIEs.list.array[ieIdx]->id)
17684                {
17685                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17686                      {
17687                         free(paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10.buf);
17688                         break;
17689                      }
17690                   case ProtocolIE_ID_id_PagingIdentity:
17691                      {
17692                         if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present == PagingIdentity_PR_cNUEPagingIdentity)
17693                         {
17694                            if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)
17695                            {
17696                               if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->present == \
17697                                     CNUEPagingIdentity_PR_fiveG_S_TMSI)
17698                               {
17699                                  free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->choice.fiveG_S_TMSI.buf);
17700                               }
17701                               free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity);
17702                            }
17703                         }
17704                         break;
17705                      }
17706                   case ProtocolIE_ID_id_PagingCell_List:
17707                      {
17708                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list;
17709                         if(pagingCelllist->list.array)
17710                         {
17711                            for(cellIdx = 0; cellIdx < pagingCelllist->list.count; cellIdx++)
17712                            {
17713                               if(pagingCelllist->list.array[cellIdx])
17714                               {
17715                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellIdx];
17716                                  if(pagingCellItemIes->id == ProtocolIE_ID_id_PagingCell_Item)
17717                                  {
17718                                     pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17719                                     free(pagingCellItem->nRCGI.pLMN_Identity.buf);
17720                                     free(pagingCellItem->nRCGI.nRCellIdentity.buf);
17721                                  }
17722                                  free(pagingCelllist->list.array[cellIdx]);
17723                               }
17724                            }
17725                            free(pagingCelllist->list.array);
17726                         }
17727                         break;
17728                      }
17729                }
17730                free(paging->protocolIEs.list.array[ieIdx]);
17731             }
17732          }
17733          free(paging->protocolIEs.list.array);
17734
17735       }
17736    }
17737 }
17738
17739 /**************************************************************
17740  *
17741  * @brief processing the paging f1ap msg received from CU 
17742  *
17743  * @details
17744  *
17745  *    Function : procPagingMsg
17746  *
17747  *    Functionality:
17748  *         - processing the paging f1ap msg received from CU
17749  *
17750  * @params[in] F1AP_PDU_t *f1apMsg
17751  * @return ROK     - success
17752  *         RFAILED - failure
17753  *
17754  *
17755  ****************************************************************/
17756 uint8_t procPagingMsg(F1AP_PDU_t *f1apMsg) 
17757 {
17758    uint8_t ieIdx = 0, cellListIdx = 0;
17759    uint64_t cellId = 0;
17760    Paging_t   *paging = NULLP;
17761    PagingCell_list_t  *pagingCelllist = NULLP;
17762    PagingCell_ItemIEs_t *pagingCellItemIes = NULLP;
17763    PagingCell_Item_t *pagingCellItem = NULLP;
17764    DuPagingMsg *tmpPagingParam = NULLP;
17765
17766    paging = &f1apMsg->choice.initiatingMessage->value.choice.Paging;
17767    if(paging)
17768    {
17769       if(paging->protocolIEs.list.array)
17770       {
17771          DU_ALLOC(tmpPagingParam, sizeof(DuPagingMsg));
17772          if(tmpPagingParam == NULLP)
17773          {
17774             DU_LOG("\nERROR  --> DU APP : Memory Allocation Failure in procPagingMsg");
17775             freeAperDecodePagingMsg(paging);
17776             return RFAILED;
17777          }
17778          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17779          {
17780             if(paging->protocolIEs.list.array[ieIdx])
17781             {
17782                switch(paging->protocolIEs.list.array[ieIdx]->id)
17783                {
17784                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17785                      {
17786                         bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10,\
17787                                          &tmpPagingParam->pagUeId);
17788                         break;
17789                      }
17790
17791                   case ProtocolIE_ID_id_PagingIdentity:
17792                      {
17793                         switch(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present)
17794                         {
17795                            case PagingIdentity_PR_cNUEPagingIdentity: 
17796                               {
17797                                  if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)  
17798                                  {
17799                                     bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.\
17800                                           cNUEPagingIdentity->choice.fiveG_S_TMSI, &tmpPagingParam->sTmsi);
17801
17802                                  }
17803                                  break;
17804                               }
17805                             case PagingIdentity_PR_rANUEPagingIdentity:
17806                                {
17807                                   /*TODO: This Identifier is specific to RAN Initiated Paging – Connected Mode Paging*/
17808                                   break;
17809                                }
17810                             default:
17811                                {
17812                                   DU_LOG("ERROR  -->  DU APP: Invalid UE Paging Identity, Skipping this Paging Message:");
17813                                   continue;
17814                                }
17815                         }
17816                      }
17817
17818                   case ProtocolIE_ID_id_PagingDRX:
17819                      {
17820                         tmpPagingParam->pagingDrxPres = TRUE;
17821                         tmpPagingParam->pagingDrx = convertPagingCycleEnumToValue(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingDRX);
17822                         break;
17823                      }
17824
17825                   case ProtocolIE_ID_id_PagingPriority:
17826                      {
17827                         tmpPagingParam->pagPriority = paging->protocolIEs.list.array[ieIdx]->value.choice.PagingPriority;
17828                         break;
17829                      }
17830
17831                   case ProtocolIE_ID_id_PagingCell_List:
17832                      {
17833                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list; 
17834                         if(pagingCelllist->list.array)
17835                         {
17836                            for(cellListIdx = 0; cellListIdx < pagingCelllist->list.count; cellListIdx++)
17837                            {
17838                               if(pagingCelllist->list.array[cellListIdx])
17839                               {
17840                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellListIdx];
17841                                  pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17842                                  bitStringToInt(&pagingCellItem->nRCGI.nRCellIdentity, &cellId);
17843                                  if(processPagingMsg(cellId, tmpPagingParam) != ROK)
17844                                  {
17845                                     DU_LOG("\nERROR  --> DU APP : Paging Processing Failed at CellId:%lu",cellId);
17846                                     continue;
17847                                  }
17848                               }
17849                            }
17850                         }
17851                         break;
17852                      }
17853                    default:
17854                      {
17855                          DU_LOG("\nERROR  --> F1AP : Incorrect Paging IE option");
17856                          break;
17857                      }
17858                }
17859             }
17860          }
17861       }
17862    }
17863    DU_FREE(tmpPagingParam, sizeof(DuPagingMsg));
17864    freeAperDecodePagingMsg(paging);
17865   
17866    return ROK;
17867 }
17868
17869 /**************************************************************
17870  *
17871  * @brief Handles received F1AP message and sends back response  
17872  *
17873  * @details
17874  *
17875  *    Function : F1APMsgHdlr
17876  *
17877  *    Functionality:
17878  *         - Decodes received F1AP control message
17879  *         - Prepares response message, encodes and sends to SCTP
17880  *
17881  * @params[in] 
17882  * @return ROK     - success
17883  *         RFAILED - failure
17884  *
17885  * ****************************************************************/
17886 void F1APMsgHdlr(Buffer *mBuf)
17887 {
17888    int i =0;
17889    char *recvBuf =NULLP;
17890    MsgLen copyCnt =0;
17891    MsgLen recvBufLen =0;
17892    F1AP_PDU_t *f1apMsg =NULLP;
17893    asn_dec_rval_t rval; /* Decoder return value */
17894    F1AP_PDU_t f1apasnmsg ;
17895    DU_LOG("\nINFO  -->  F1AP : Received F1AP message buffer");
17896    ODU_PRINT_MSG(mBuf, 0,0);
17897
17898    /* Copy mBuf into char array to decode it */
17899    ODU_GET_MSG_LEN(mBuf, &recvBufLen);
17900    DU_ALLOC(recvBuf, (Size)recvBufLen);
17901
17902    if(recvBuf == NULLP)
17903    {
17904       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed");
17905       return;
17906    }
17907    if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
17908    {
17909       DU_LOG("\nERROR   -->  F1AP : Failed while copying %d", copyCnt);
17910       return;
17911    }
17912
17913 #ifdef DEBUG_ASN_PRINT
17914    printf("\nDEBUG   -->  F1AP : Received flat buffer to be decoded : ");
17915    for(i=0; i< recvBufLen; i++)
17916    {
17917       printf("%x",recvBuf[i]);
17918    }
17919 #endif
17920
17921    /* Decoding flat buffer into F1AP messsage */
17922    f1apMsg = &f1apasnmsg;
17923    memset(f1apMsg, 0, sizeof(F1AP_PDU_t));
17924
17925    rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0);
17926
17927    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
17928    {
17929       DU_LOG("\nERROR  -->  F1AP : ASN decode failed");
17930       return;
17931    }
17932    printf("\n");
17933    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17934
17935    switch(f1apMsg->present)
17936    {
17937       case F1AP_PDU_PR_successfulOutcome:
17938          {
17939             switch(f1apMsg->choice.successfulOutcome->value.present)
17940             {
17941                case SuccessfulOutcome__value_PR_ResetAcknowledge:
17942                   {
17943                      DU_LOG("\nINFO   -->  F1AP : F1ResetAcknowledge is received successfully ");
17944                      break;
17945                   }
17946                case SuccessfulOutcome__value_PR_F1SetupResponse:
17947                   {                             
17948 #ifndef ODU_TEST_STUB
17949                      procF1SetupRsp(f1apMsg, recvBufLen, recvBuf);
17950 #endif
17951                      break;
17952                   }
17953
17954                case SuccessfulOutcome__value_PR_GNBDUConfigurationUpdateAcknowledge:
17955                   {
17956                      procF1GNBDUCfgUpdAck(f1apMsg);
17957                      break;
17958                   }
17959
17960                default:
17961                   {
17962                      DU_LOG("\nERROR  -->  F1AP : Invalid type of SuccessfulOutcome__value_PR_ResetAcknowledge [%d]",\
17963                            f1apMsg->choice.successfulOutcome->value.present);
17964                      return;
17965                   }
17966             }/* End of switch(successfulOutcome) */
17967             free(f1apMsg->choice.successfulOutcome);
17968             break;
17969          }
17970       case F1AP_PDU_PR_initiatingMessage:
17971          {
17972             switch(f1apMsg->choice.initiatingMessage->value.present)
17973             {
17974                case InitiatingMessage__value_PR_Reset:
17975                   {
17976                      procF1ResetReq(f1apMsg);
17977                      break;
17978                   }
17979                case InitiatingMessage__value_PR_DLRRCMessageTransfer:
17980                   {
17981                      procF1DlRrcMsgTrans(f1apMsg);
17982                      break;
17983                   }
17984                case InitiatingMessage__value_PR_UEContextSetupRequest:
17985                   {
17986                      procF1UeContextSetupReq(f1apMsg);
17987                      break;
17988                   }
17989                case InitiatingMessage__value_PR_UEContextModificationRequest:
17990                   {
17991                      procF1UeContextModificationReq(f1apMsg);
17992                      break;
17993                   }
17994                case InitiatingMessage__value_PR_UEContextReleaseCommand:
17995                   {
17996                       procF1UeContextReleaseCommand(f1apMsg);
17997                       break;
17998                   }
17999                case InitiatingMessage__value_PR_Paging:
18000                   {
18001                      procPagingMsg(f1apMsg);
18002                      break;
18003                   }
18004                default:
18005                   {
18006                      DU_LOG("\nERROR  -->  F1AP : Invalid type of F1AP_PDU_PR_initiatingMessage [%d]",
18007                            f1apMsg->choice.initiatingMessage->value.present);
18008                      return;
18009                   }
18010             }/* End of switch(initiatingMessage) */
18011             free(f1apMsg->choice.initiatingMessage);
18012             break;
18013          }
18014
18015       default:
18016          {
18017             DU_LOG("\nERROR  -->  F1AP : Invalid type of f1apMsg->present [%d]",f1apMsg->present);
18018             return;
18019          }
18020          free(f1apMsg);
18021
18022    }/* End of switch(f1apMsg->present) */
18023    
18024    DU_FREE(recvBuf, (Size)recvBufLen);
18025 } /* End of F1APMsgHdlr */
18026
18027 /**********************************************************************
18028   End of file
18029  **********************************************************************/