[Epic-ID: ODUHIGH-510][Task-ID: ODUHIGH-512] Implementation of E2 setup failure
[o-du/l2.git] / src / du_app / du_f1ap_msg_hdl.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /* This file contains F1AP message handler functions */
20 #include "common_def.h"
21 #include "du_tmr.h"
22 #include "ckw.h"
23 #include "ckw.x"
24 #include "kwu.h"
25 #include "kwu.x"
26 #include "lkw.h"
27 #include "lrg.h"
28 #include "legtp.h"
29 #include "lkw.x"
30 #include "lrg.x"
31 #include "F1AP-PDU.h"
32 #include "InitiatingMessage.h"
33 #include "SuccessfulOutcome.h"
34 #include "du_app_mac_inf.h"
35 #include "du_cfg.h"
36 #include "du_app_rlc_inf.h"
37 #include "du_e2ap_mgr.h"
38 #include "du_e2ap_msg_hdl.h"
39 #include "du_mgr_main.h"
40 #include "du_mgr.h"
41 #include "du_utils.h"
42 #include "du_ue_mgr.h"
43 #include "RAT-Type.h"
44 #include "NRFreqInfo.h"
45 #include "NRCGI.h"
46 #include "TDD-Info.h"
47 #include "NR-Mode-Info.h"
48 #include "ServedPLMNs-List.h"
49 #include "GNB-DU-Served-Cells-List.h"
50 #include "Served-Cell-Information.h"
51 #include "ProtocolExtensionContainer.h"
52 #include "RRC-Version.h"
53 #include "FDD-Info.h"
54 #include "FreqBandNrItem.h"
55 #include "ServedPLMNs-Item.h"
56 #include "GNB-DU-Served-Cells-Item.h"
57 #include "SliceSupportItem.h"
58 #include "FeatureSetUplinkPerCC.h"
59 #include "SliceSupportItem.h"
60 #include "Served-Cells-To-Modify-Item.h"
61 #include "Served-Cells-To-Delete-List.h"
62 #include "Served-Cells-To-Delete-Item.h"
63 #include "QoSInformation.h"
64 #include "ULUPTNLInformation-ToBeSetup-List.h"
65 #include "DRB-Information.h"
66 #include "DRBs-ToBeSetup-Item.h"
67 #include "DRBs-ToBeSetupMod-Item.h"
68 #include "DRBs-ToBeModified-Item.h"
69 #include "CUtoDURRCInformation.h"
70 #include "SCell-ToBeSetup-List.h"
71 #include "SRBs-ToBeSetup-List.h"
72 #include "DRBs-ToBeSetup-List.h"
73 #include "SRBs-ToBeSetup-Item.h"
74 #include "DRBs-ToBeModified-List.h"
75 #include "RRCContainer.h"
76 #include "UE-CapabilityRAT-ContainerList.h"
77 #include "DRBs-Setup-List.h"
78 #include "CellGroupConfig.h"
79 #include "ResetAll.h"
80 #include "ResetType.h"
81 #include "Cells-to-be-Activated-List.h"
82 #include "GNB-CU-Name.h"
83 #include "SRBs-SetupMod-List.h"
84 #include "DRBs-SetupMod-List.h"
85 #include "DRBs-ToBeSetupMod-List.h"
86 #include "PagingCell-Item.h"
87 #include "PagingCell-list.h"
88 #include "QoS-Characteristics.h"
89 #include "ULUPTNLInformation-ToBeSetup-Item.h"
90 #include "Flows-Mapped-To-DRB-Item.h"
91 #include "NonDynamic5QIDescriptor.h"
92 #include "Dynamic5QIDescriptor.h"
93 #include "FeatureSetDownlinkPerCC.h"
94 #include "FeatureSets.h"
95 #include "UE-NR-Capability.h"
96 #include "UE-CapabilityRAT-Container.h"
97 #include "UE-CapabilityRAT-ContainerListRRC.h"
98 #include "GNB-DU-System-Information.h"
99 #include "CellGroupConfigRrc.h"
100 #include "MAC-CellGroupConfig.h"
101 #include "SchedulingRequestConfig.h"
102 #include "SchedulingRequestToAddMod.h"
103 #include "BSR-Config.h"
104 #include "TAG-Config.h"
105 #include "TAG.h"
106 #include "PHR-Config.h"
107 #include "RLC-Config.h"
108 #include "UL-AM-RLC.h"
109 #include "DL-AM-RLC.h"
110 #include "LogicalChannelConfig.h"
111 #include "RLC-BearerConfig.h"
112 #include "PhysicalCellGroupConfig.h"
113 #include "SpCellConfig.h"
114 #include "TDD-UL-DL-ConfigDedicated.h"
115 #include "ServingCellConfig.h"
116 #include "ControlResourceSet.h"
117 #include "SearchSpace.h"
118 #include "PDCCH-Config.h"
119 #include "PDSCH-TimeDomainResourceAllocation.h"
120 #include "PDSCH-TimeDomainResourceAllocationList.h"
121 #include "PDSCH-CodeBlockGroupTransmission.h"
122 #include "PDSCH-ServingCellConfig.h"
123 #include "DMRS-DownlinkConfig.h"
124 #include "PDSCH-Config.h"
125 #include "BWP-DownlinkDedicated.h"
126 #include "BWP-Downlink.h"
127 #include "PUSCH-TimeDomainResourceAllocation.h"
128 #include "PUSCH-TimeDomainResourceAllocationList.h"
129 #include "DMRS-UplinkConfig.h"
130 #include "PUSCH-Config.h"
131 #include "SRS-ResourceId.h"
132 #include "SRS-Resource.h"
133 #include "SRS-ResourceSet.h"
134 #include "SRS-Config.h"
135 #include "BWP-UplinkDedicated.h"
136 #include "PUSCH-ServingCellConfig.h"
137 #include "UplinkConfig.h"
138 #include "DUtoCURRCContainer.h"
139 #include "GBR-QoSFlowInformation.h"
140 #include "QoSFlowLevelQoSParameters.h"
141 #include "PUCCH-Config.h"
142 #include "PUCCH-ResourceSet.h"
143 #include "PUCCH-Resource.h"
144 #include "PUCCH-PowerControl.h"
145 #include "P0-PUCCH.h"
146 #include "PUCCH-PathlossReferenceRS.h"
147 #include "PUCCH-format0.h"
148 #include "PUCCH-format1.h"
149 #include "PUCCH-format2.h"
150 #include "PUCCH-format3.h"
151 #include "PUCCH-format4.h"
152 #include "PUCCH-FormatConfig.h"
153 #include "SchedulingRequestResourceConfig.h"
154 #include<ProtocolIE-Field.h>
155 #include "ProtocolExtensionField.h"
156 #include "odu_common_codec.h"
157 #include "du_mgr.h"
158 #include "du_cell_mgr.h"
159 #include "du_f1ap_msg_hdl.h"
160 #include "DRBs-Setup-Item.h"
161 #include "DLUPTNLInformation-ToBeSetup-List.h"
162 #include "DLUPTNLInformation-ToBeSetup-Item.h"
163 #include "UPTransportLayerInformation.h"
164 #include "GTPTunnel.h"
165 #include "SupportedSULFreqBandItem.h"
166 #include "du_f1ap_conversions.h"
167 #include "CNUEPagingIdentity.h"
168 #include "PCCH-Config.h"
169 #include "SCS-SpecificCarrier.h"
170 #include "FrequencyInfoDL.h"
171 #include "DownlinkConfigCommon.h"
172 #include "FrequencyInfoUL.h"
173 #include "UplinkConfigCommon.h"
174 #include "TDD-UL-DL-ConfigCommon.h"
175 #include "RACH-ConfigDedicated.h"
176 #include "CFRA-SSB-Resource.h"
177 #include "BWP-UplinkCommon.h"
178 #include "ReconfigurationWithSync.h"
179 #include "BCCH-DL-SCH-Message.h"
180 #include "du_sys_info_hdl.h"
181 #include "DRX-ConfigRrc.h"
182 #include "MeasurementTimingConfigurationRrc.h"
183 #include "MeasurementTimingConfigurationRrc-IEs.h"
184 #include "MeasTimingList.h"
185 #include "MeasTiming.h"
186 #include "Cells-Status-List.h"
187 #include "Cells-Status-Item.h"
188
189 #ifdef O1_ENABLE
190 #include "CmInterface.h"
191 extern StartupConfig g_cfg;
192 #endif
193
194 DuCfgParams duCfgParam;
195
196 /******************************************************************
197  *
198  * @brief Function to fetch lcId based on DRB Id
199  *
200  * @details
201  *
202  *    Function : fetchLcId
203  *
204  *    @params[in] drbId
205  *
206  *    Functionality: Function to fetch lcId based on DRB Id
207  *
208  * Returns: lcId - SUCCESS
209  *          RFAILED - FAILURE
210  *****************************************************************/
211
212 uint8_t fetchLcId(uint8_t drbId)
213 {
214    uint8_t cellIdx = 0, ueIdx = 0, lcIdx = 0, numLcs = 0, lcId = 0;
215
216    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
217    {
218       for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
219       {
220          if(duCb.actvCellLst[cellIdx] != NULLP)
221          {
222             numLcs = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.numLcs;
223             for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
224             {
225                if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId == drbId && \
226                   duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
227                {
228                   lcId = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId;
229                   return lcId;
230                }
231             }
232          }
233       }
234    }
235    DU_LOG("\nERROR   -->  DU_APP: fetchLcId() failed for drbId %d", drbId);
236    return RFAILED;
237 }
238
239 /*******************************************************************
240 *
241 * @brief Adding F1AP pdu to reserved pdu list
242 *
243 * @details
244 *
245 *    Function : addToReservedF1apPduList 
246 *
247 *    Functionality: Adding F1AP pdu to reserved pdu list.
248 *     These pdu are awaiting aknowledgment from CU
249 *
250 * @params[in] uint8_t transId, F1AP_PDU_t *f1apMsg
251 *
252 * @return ROK - success
253 *         RFAILED - failure
254 *
255 * ****************************************************************/
256 void addToReservedF1apPduList(uint8_t transId, F1AP_PDU_t *f1apPdu)
257 {
258    CmLList         *node = NULLP;
259    ReservedF1apPduInfo *pduInfo = NULLP;
260    DU_ALLOC(pduInfo, sizeof(ReservedF1apPduInfo));
261    if(pduInfo)
262    {
263       DU_ALLOC(node, sizeof(CmLList));
264       if(node)
265       {
266          pduInfo->transId = transId;
267          pduInfo->f1apMsg = (void*) f1apPdu;
268
269          node->node = (PTR)pduInfo;
270          cmLListAdd2Tail(&duCb.reservedF1apPduList, node);
271       }
272    }
273 }
274
275 /*******************************************************************
276 *
277 * @brief searching for F1AP pdu from ReservedF1apPduList 
278 *
279 * @details
280 *
281 *    Function : searchFromReservedF1apPduList 
282 *
283 *    Functionality: searching for F1AP pdu information
284 *
285 * @params[in] uint8_t transId
286 *
287 * @return pointer to F1AP_PDU_t
288 *
289 * ****************************************************************/
290
291 CmLList *searchFromReservedF1apPduList(uint8_t transId)
292 {
293    CmLList         *node;
294    ReservedF1apPduInfo *f1apPdu;
295    if(duCb.reservedF1apPduList.count)
296    {
297       CM_LLIST_FIRST_NODE(&duCb.reservedF1apPduList, node);
298       while(node)
299       {
300          f1apPdu = (ReservedF1apPduInfo*)node->node;
301          if(f1apPdu->transId == transId)
302          {
303             return node;
304          }
305          node = node->next;
306       }
307    }
308    return NULL;
309 }
310
311 /*******************************************************************
312 *
313 * @brief deleting F1AP pdu information from ReservedF1apPduList
314 *
315 * @details
316 *
317 *    Function : deleteFromReservedF1apPduList 
318 *
319 *    Functionality: deleting pdu information from ReservedF1apPduList
320 *
321 * @params[in] CmLList *node 
322 *
323 * @return void 
324 *
325 * ****************************************************************/
326
327 void deleteFromReservedF1apPduList(CmLList *node)
328 {
329    ReservedF1apPduInfo *f1apPdu;
330
331    if(node != NULL)
332    {
333       f1apPdu = (ReservedF1apPduInfo *)node->node;
334       cmLListDelFrm(&duCb.reservedF1apPduList, node);
335       DU_FREE(f1apPdu, sizeof(ReservedF1apPduInfo));
336       DU_FREE(node, sizeof(CmLList));
337       node = NULL;
338    }
339 }
340
341 /*******************************************************************
342  *
343  * @brief Builds Uplink Info for NR 
344  *
345  * @details
346  *
347  *    Function : BuildULNRInfo
348  *
349  *    Functionality: Building NR Uplink Info
350  *
351  * @params[in] NRFreqInfo_t *ulnrfreq
352  * @return ROK     - success
353  *         RFAILED - failure
354  *
355  * ****************************************************************/
356 uint8_t BuildULNRInfo(NRFreqInfo_t *ulnrfreq)
357 {
358    uint8_t idx=0;
359    ulnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
360                        fdd.ulNrFreqInfo.nrArfcn;
361    ulnrfreq->freqBandListNr.list.count = 1;
362    ulnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
363    DU_ALLOC(ulnrfreq->freqBandListNr.list.array,ulnrfreq->freqBandListNr.list.size);
364    if(ulnrfreq->freqBandListNr.list.array == NULLP)
365    {
366       return RFAILED;
367    }
368    for(idx=0;idx<ulnrfreq->freqBandListNr.list.count;idx++)
369    {
370       DU_ALLOC(ulnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
371       if(ulnrfreq->freqBandListNr.list.array[idx] == NULLP)
372       {
373          return RFAILED;
374       }
375    }
376    ulnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
377                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
378                                                                  freqBand[0].nrFreqBand;
379    ulnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
380    return ROK;
381 }
382 /*******************************************************************
383  *
384  * @brief Builds Downlink NR Info 
385  *
386  * @details
387  *
388  *    Function : BuildDLNRInfo
389  *
390  *    Functionality: Building Downlink NR Info
391  *    
392  * @params[in] NRFreqInfo_t *dlnrfreq
393  * @return ROK     - success
394  *         RFAILED - failure
395  *
396  * ****************************************************************/
397 uint8_t BuildDLNRInfo(NRFreqInfo_t *dlnrfreq)
398 {
399    uint8_t idx=0;
400    dlnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
401                        fdd.dlNrFreqInfo.nrArfcn;
402    dlnrfreq->freqBandListNr.list.count = 1;
403    dlnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
404    DU_ALLOC(dlnrfreq->freqBandListNr.list.array,dlnrfreq->freqBandListNr.list.size);
405    if(dlnrfreq->freqBandListNr.list.array == NULLP)
406    {
407       return RFAILED;   
408    }
409    for(idx=0;idx< dlnrfreq->freqBandListNr.list.count;idx++)
410    {
411       DU_ALLOC(dlnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
412       if(dlnrfreq->freqBandListNr.list.array[idx] == NULLP)
413       {
414          return RFAILED;
415       }
416    }   
417    dlnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
418                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
419                                                                  freqBand[0].nrFreqBand;
420    dlnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
421
422    return ROK;
423 }
424
425 /*******************************************************************
426  *
427  * @brief Builds Nrcgi 
428  *
429  * @details
430  *
431  *    Function : BuildNrcgi
432  *
433  *    Functionality: Building the PLMN ID and NR Cell id
434  *
435  * @params[in] NRCGI_t *nrcgi
436  * @return ROK     - success
437  *         RFAILED - failure
438  *
439  * ****************************************************************/
440 uint8_t BuildNrcgi(NRCGI_t *nrcgi)
441 {
442    uint8_t ret;
443    uint8_t byteSize = 5;
444    /* Allocate Buffer Memory */
445    nrcgi->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
446    DU_ALLOC(nrcgi->pLMN_Identity.buf, nrcgi->pLMN_Identity.size);
447    if(nrcgi->pLMN_Identity.buf == NULLP)
448    {
449       return RFAILED;
450    }
451    ret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
452          nrcgi->pLMN_Identity.buf); // Building PLMN function
453    if(ret != ROK)
454    {
455       return RFAILED;
456    }
457    /*nrCellIdentity*/
458    nrcgi->nRCellIdentity.size = byteSize * sizeof(uint8_t);
459    DU_ALLOC(nrcgi->nRCellIdentity.buf, nrcgi->nRCellIdentity.size); 
460    if(nrcgi->nRCellIdentity.buf == NULLP)
461    {
462       return RFAILED;
463    }
464    fillBitString(&nrcgi->nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
465
466    return ROK;
467 }
468 /*******************************************************************
469  *
470  * @brief Builds FiveGStac 
471  *
472  * @details
473  *
474  *    Function : BuildFiveGSTac
475  *
476  *    Functionality: Building the FiveGSTac
477  *
478  * @params[in] OCTET_STRING_t *fivegsTac
479  * @return ROK     - success
480  *         RFAILED - failure
481  *
482  * ****************************************************************/
483 uint8_t BuildFiveGSTac(Served_Cell_Information_t *servcell)
484 {
485    DU_ALLOC(servcell->fiveGS_TAC,sizeof(FiveGS_TAC_t));
486    if(servcell->fiveGS_TAC == NULLP)
487    {
488       return RFAILED;
489    }
490    servcell->fiveGS_TAC->size = 3 * sizeof(uint8_t);
491    DU_ALLOC(servcell->fiveGS_TAC->buf,\
492          sizeof(servcell->fiveGS_TAC->size));
493    if(servcell->fiveGS_TAC->buf == NULLP)
494    {
495       return RFAILED;
496    }
497    servcell->fiveGS_TAC->buf[0] = 0;
498    servcell->fiveGS_TAC->buf[1] = 0;
499    servcell->fiveGS_TAC->buf[2] = duCfgParam.srvdCellLst[0].duCellInfo.tac;
500    return ROK;  
501 }
502
503 /*******************************************************************
504  *
505  * @brief fill nr frequency information
506  *
507  * @details
508  *
509  *    Function : fillNrTddInfo 
510  *
511  *    Functionality: fill nr frequency information
512  *
513  * @params[in] NRFreqInfo_t freqInfo
514  * @return ROK     - success
515  *         RFAILED - failure
516  *
517  * ****************************************************************/
518 uint8_t fillNrTddInfo(TDD_Info_t *tddInfo)
519 {
520    uint8_t elementCnt = 1, freqBandListIdx = 0, supportedBandIdx = 0;
521    NRFreqInfo_t *freqInfo = NULLP;
522
523    if(tddInfo == NULLP)
524    {
525       DU_LOG("\nERROR  --> DU APP : Null pointer received at fillNrTddInfo");
526       return RFAILED;
527    }
528    
529    freqInfo = &tddInfo->nRFreqInfo;
530    freqInfo->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.nrArfcn; 
531
532    freqInfo->freqBandListNr.list.count = elementCnt; 
533    freqInfo->freqBandListNr.list.size = freqInfo->freqBandListNr.list.count  * sizeof(FreqBandNrItem_t *);
534    DU_ALLOC(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
535    if(!freqInfo->freqBandListNr.list.array)
536    {
537       DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
538       return RFAILED;
539    }
540
541    for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
542    {
543       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
544       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx])
545       {
546          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
547          return RFAILED;
548       }
549
550       freqInfo->freqBandListNr.list.array[freqBandListIdx]->freqBandIndicatorNr = duCfgParam.srvdCellLst[0].duCellInfo.\
551       f1Mode.mode.tdd.nrFreqInfo.freqBand[0].nrFreqBand;
552
553       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count = elementCnt;
554       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size = freqInfo->freqBandListNr.list.array[freqBandListIdx]->\
555       supportedSULBandList.list.count * sizeof(SupportedSULFreqBandItem_t*);
556
557       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
558             freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
559       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
560       {
561          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
562          return RFAILED;
563       }
564
565       for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
566       {
567          DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
568                sizeof(SupportedSULFreqBandItem_t));
569          if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx])
570          {
571             DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
572             return RFAILED;
573          }
574
575          freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx]->freqBandIndicatorNr =\
576          duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[0].sulBand[0];
577       }
578    }
579
580    tddInfo->transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrScs;
581    tddInfo->transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrb;
582
583    return ROK;
584 }
585
586 /*******************************************************************
587  *
588  * @brief Builds NR Mode 
589  *
590  * @details
591  *
592  *    Function : BuildNrMode
593  *
594  *    Functionality: Building the NR Mode
595  *
596  * @params[in] NR_Mode_Info_t *fdd
597  * @return ROK     - success
598  *         RFAILED - failure
599  *
600  * ****************************************************************/
601 uint8_t BuildNrMode(NR_Mode_Info_t *mode)
602 {
603    uint8_t BuildDLNRInforet=0;
604    uint8_t BuildULNRInforet=0; 
605    
606 #ifdef NR_TDD
607    mode->present = NR_Mode_Info_PR_tDD;
608 #else
609    mode->present = NR_Mode_Info_PR_fDD;
610 #endif   
611    
612    if(mode->present == NR_Mode_Info_PR_fDD)
613    {
614       DU_ALLOC(mode->choice.fDD,sizeof(FDD_Info_t));
615       if(mode->choice.fDD == NULLP)
616       {
617          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
618          return RFAILED;
619       }
620       BuildULNRInforet = BuildULNRInfo(&mode->choice.fDD->uL_NRFreqInfo);
621       if(BuildULNRInforet != ROK)
622       {
623          DU_LOG("\nERROR  --> Failed to build UlNrFreqInfo");
624          return RFAILED;    
625       }
626       BuildDLNRInforet = BuildDLNRInfo(&mode->choice.fDD->dL_NRFreqInfo);
627       if(BuildDLNRInforet != ROK)
628       {
629          DU_LOG("\nERROR  --> Failed to build DlNrFreqInfo");
630          return RFAILED;
631       }
632       mode->choice.fDD->uL_Transmission_Bandwidth.nRSCS = \
633                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
634                                                           f1Mode.mode.fdd.ulTxBw.nrScs;
635       mode->choice.fDD->uL_Transmission_Bandwidth.nRNRB = \
636                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
637                                                           f1Mode.mode.fdd.ulTxBw.nrb;
638       mode->choice.fDD->dL_Transmission_Bandwidth.nRSCS = \
639                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
640                                                           f1Mode.mode.fdd.dlTxBw.nrScs;
641       mode->choice.fDD->dL_Transmission_Bandwidth.nRNRB = \
642                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
643                                                           f1Mode.mode.fdd.dlTxBw.nrb;
644    }
645    else if(mode->present == NR_Mode_Info_PR_tDD) 
646    {
647       DU_ALLOC(mode->choice.tDD,sizeof(TDD_Info_t));
648       if(mode->choice.tDD == NULLP)
649       {
650          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
651          return RFAILED;
652       }
653
654       if(fillNrTddInfo(mode->choice.tDD) != ROK)
655       {
656          DU_LOG("\nERROR  --> Failed to fill Nr TDD information");
657          return RFAILED;
658       }
659
660    }
661
662    return ROK;
663 }
664 /*******************************************************************
665  *
666  * @brief Builds IE Extensions for Served PLMNs 
667  *
668  * @details
669  *
670  *    Function : BuildExtensions
671  *
672  *    Functionality: Building the IE Extensions
673  *
674  * @params[in] struct ProtocolExtensionContainer_4624P3 *buildextend
675  * @return ROK     - success
676  *         RFAILED - failure
677  *
678  * ****************************************************************/
679 uint8_t BuildExtensions(ProtocolExtensionContainer_4624P3_t **ieExtend)
680 {
681    uint8_t idx=0, plmnidx=0, sliceLstIdx=0;
682    uint8_t elementCnt=0, extensionCnt=0;
683
684    extensionCnt=IE_EXTENSION_LIST_COUNT;
685    DU_ALLOC(*ieExtend,sizeof(ProtocolExtensionContainer_4624P3_t));
686    if((*ieExtend) == NULLP)
687    {
688       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
689       return RFAILED;
690    }
691    (*ieExtend)->list.count = extensionCnt;
692    (*ieExtend)->list.size = \
693                             extensionCnt * sizeof(ServedPLMNs_ItemExtIEs_t *);
694    DU_ALLOC((*ieExtend)->list.array,(*ieExtend)->list.size);
695    if((*ieExtend)->list.array == NULLP)
696    {
697       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
698       return RFAILED;
699    }
700    for(plmnidx=0;plmnidx<extensionCnt;plmnidx++)
701    {
702       DU_ALLOC((*ieExtend)->list.array[plmnidx],\
703             sizeof(ServedPLMNs_ItemExtIEs_t));
704       if((*ieExtend)->list.array[plmnidx] == NULLP)
705       {
706          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
707          return RFAILED;
708       }
709    }
710    
711    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices;
712    idx = 0;
713    (*ieExtend)->list.array[idx]->id = ProtocolIE_ID_id_TAISliceSupportList;
714    (*ieExtend)->list.array[idx]->criticality = Criticality_ignore;
715    (*ieExtend)->list.array[idx]->extensionValue.present = \
716    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
717    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
718       list.count = elementCnt;
719    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
720       list.size = (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
721       list.count * sizeof(SliceSupportItem_t *);
722
723    DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
724          list.array, elementCnt * sizeof(SliceSupportItem_t *));
725    if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
726          list.array == NULLP)
727    {
728       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
729       return RFAILED;
730    }
731
732    for(sliceLstIdx =0; sliceLstIdx<elementCnt; sliceLstIdx++)
733    {
734       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
735             list.array[sliceLstIdx],sizeof(SliceSupportItem_t));
736       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
737             list.array[sliceLstIdx] == NULLP) 
738       {
739          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
740          return RFAILED;
741       }
742       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
743          list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
744       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
745             .list.array[sliceLstIdx]->sNSSAI.sST.buf,(*ieExtend)->list.array[idx]->\
746             extensionValue.choice.SliceSupportList.\
747             list.array[sliceLstIdx]->sNSSAI.sST.size);
748       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
749             .list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
750       {
751          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
752          return RFAILED;
753       }
754       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
755          list.array[sliceLstIdx]->sNSSAI.sST.buf[0] = duCfgParam.srvdCellLst[0].duCellInfo.\
756          cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
757       
758       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
759             list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
760       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
761             list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
762       {
763          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
764          return RFAILED;
765       }
766       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
767          list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
768       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
769             list.array[sliceLstIdx]->sNSSAI.sD->buf, (*ieExtend)->list.array[idx]->extensionValue.choice.\
770             SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
771       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
772             list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
773       {
774          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
775          return RFAILED;
776       }
777       memcpy((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
778       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[0].duCellInfo.\
779       cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sd, (*ieExtend)->list.array[idx]->\
780       extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
781    }
782    return ROK;
783 }
784 /*******************************************************************
785  *
786  * @brief Builds Served PLMN 
787  *
788  * @details
789  *
790  *    Function : BuildServedPlmn
791  *
792  *    Functionality: Building the Served PLMN
793  *
794  * @params[in] GNB_DU_Served_Cells_Item_t *srvCellItem
795  * @return ROK     - success
796  *         RFAILED - failure
797  *
798  * ****************************************************************/
799 uint8_t  BuildServedPlmn(ServedPLMNs_List_t *srvplmn)
800 {  
801    uint8_t  plmnidx;
802    uint8_t  servPlmnCnt=1;
803    uint8_t buildPlmnIdret=0;
804    uint8_t BuildExtensionsret=0;
805    srvplmn->list.count = servPlmnCnt;
806    srvplmn->list.size = \
807                         servPlmnCnt*sizeof(ServedPLMNs_Item_t *);
808    DU_ALLOC(srvplmn->list.array,srvplmn->list.size);
809    if(srvplmn->list.array == NULLP)
810    {
811       return RFAILED;
812    }
813    for(plmnidx=0; plmnidx<servPlmnCnt; plmnidx++)
814    {   
815       DU_ALLOC(srvplmn->list.array[plmnidx],\
816             sizeof(ServedPLMNs_Item_t));
817       if(srvplmn->list.array[plmnidx] == NULLP)
818       {
819          return RFAILED;
820       }  
821    }
822    srvplmn->list.array[0]->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
823    DU_ALLOC(srvplmn->list.array[0]->pLMN_Identity.buf, srvplmn->list.array[0]->pLMN_Identity.size);
824    buildPlmnIdret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
825          srvplmn->list.array[0]->pLMN_Identity.buf);
826    if(buildPlmnIdret!= ROK)
827    {
828       return RFAILED;
829    }
830    BuildExtensionsret = BuildExtensions(&srvplmn->list.array[0]->iE_Extensions);
831    if(BuildExtensionsret!= ROK)
832    {
833       return RFAILED;
834    }
835    return ROK;
836 }
837
838 /*******************************************************************
839  *
840  * @brief Frees Measurement Timing configuration 
841  *
842  * @details
843  *
844  *    Function : FreeMeasTimingConf
845  *
846  *    Functionality: Frees Timing Configuration
847  *
848  * @params[in] MeasurementTimingConfigurationRrc_t measTimingConfRrc
849  * @return ROK     - success
850  *         RFAILED - failure
851  *
852  * ****************************************************************/
853 void FreeMeasTimingConf(MeasurementTimingConfigurationRrc_t   measTimingConfRrc)
854 {
855    uint8_t measIeIdx = 0;
856    MeasurementTimingConfigurationRrc_IEs_t  *measTimingConfIEs = NULLP;
857
858    if(measTimingConfRrc.criticalExtensions.choice.c1)
859    {
860       if(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf)
861       {
862          measTimingConfIEs = measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf;
863          if(measTimingConfIEs->measTiming)
864          {
865             if(measTimingConfIEs->measTiming->list.array)
866             {
867                for(measIeIdx = 0; measIeIdx < measTimingConfIEs->measTiming->list.count; measIeIdx++)
868                {
869                   if(measTimingConfIEs->measTiming->list.array[measIeIdx])
870                   {
871                      DU_FREE(measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming, sizeof(struct MeasTiming__frequencyAndTiming));
872                      DU_FREE(measTimingConfIEs->measTiming->list.array[measIeIdx], sizeof(MeasTiming_t));
873                   }
874                }
875                DU_FREE(measTimingConfIEs->measTiming->list.array, measTimingConfIEs->measTiming->list.size);
876             }
877             DU_FREE(measTimingConfIEs->measTiming, sizeof(MeasTimingList_t));
878          }
879          DU_FREE(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf, sizeof(MeasurementTimingConfigurationRrc_IEs_t));
880       }
881       DU_FREE(measTimingConfRrc.criticalExtensions.choice.c1, sizeof(struct MeasurementTimingConfigurationRrc__criticalExtensions__c1));
882    }
883 }
884
885 /*******************************************************************
886  *
887  * @brief Builds MEasuerment Timing Configuration
888  *
889  * @details
890  *
891  *    Function : BuildMeasTimingConf
892  *
893  *    Functionality: Building Measurement Timing Configuration
894  *
895  * @params[in] Pointer to octet string to store Measurement timing
896  *             Configuration
897  * @return ROK     - success
898  *         RFAILED - failure
899  *
900  * ****************************************************************/
901 uint8_t BuildMeasTimingConf(OCTET_STRING_t *measTimingConf)
902 {
903    uint8_t ret = RFAILED;
904    uint8_t elementCnt = 0;
905    uint8_t measIeIdx = 0;
906    asn_enc_rval_t encRetVal;
907    MeasurementTimingConfigurationRrc_t   measTimingConfRrc;
908    MeasurementTimingConfigurationRrc_IEs_t  *measTimingConfIEs = NULLP;
909    struct MeasTiming__frequencyAndTiming  *freqAndTiming = NULLP;
910
911    while(true)
912    {
913       measTimingConfRrc.criticalExtensions.present = MeasurementTimingConfigurationRrc__criticalExtensions_PR_c1;
914       DU_ALLOC(measTimingConfRrc.criticalExtensions.choice.c1, sizeof(struct MeasurementTimingConfigurationRrc__criticalExtensions__c1));
915       if(!measTimingConfRrc.criticalExtensions.choice.c1)
916       {
917          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for critical extension choice C1");
918          break;
919       }
920       measTimingConfRrc.criticalExtensions.choice.c1->present = MeasurementTimingConfigurationRrc__criticalExtensions__c1_PR_measTimingConf;
921
922       DU_ALLOC(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf, sizeof(MeasurementTimingConfigurationRrc_IEs_t));
923       if(!measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf)
924       {
925          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for measTimingConf");
926          break;
927       }
928       measTimingConfIEs = measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf;
929
930       DU_ALLOC(measTimingConfIEs->measTiming, sizeof(MeasTimingList_t));
931       if(!measTimingConfIEs->measTiming)
932       {
933          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList");
934          break;
935       }
936
937       elementCnt = 1;  
938       measTimingConfIEs->measTiming->list.count = elementCnt;
939       measTimingConfIEs->measTiming->list.size = elementCnt * sizeof(MeasTiming_t *);
940       DU_ALLOC(measTimingConfIEs->measTiming->list.array, measTimingConfIEs->measTiming->list.size);
941       if(!measTimingConfIEs->measTiming->list.array)
942       {
943          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList array");
944          break;
945       }
946
947       for(measIeIdx = 0; measIeIdx < elementCnt; measIeIdx++)
948       {
949          DU_ALLOC(measTimingConfIEs->measTiming->list.array[measIeIdx], sizeof(MeasTiming_t));
950          if(!measTimingConfIEs->measTiming->list.array[measIeIdx])
951          {
952             DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList array index %d", measIeIdx);
953             break;
954          }
955       }
956       if(measIeIdx < elementCnt)
957       {
958          break;
959       }
960
961       measIeIdx = 0;
962       DU_ALLOC(measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming, sizeof(struct MeasTiming__frequencyAndTiming));
963       if(!measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming)
964       {
965          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for frequencyAndTiming");
966          break;
967       }
968       freqAndTiming = measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming;
969       freqAndTiming->carrierFreq = MEAS_TIMING_ARFCN;
970       freqAndTiming->ssbSubcarrierSpacing = duCfgParam.macCellCfg.ssbCfg.scsCmn;
971       freqAndTiming->ssb_MeasurementTimingConfiguration.periodicityAndOffset.present = duCfgParam.macCellCfg.ssbCfg.ssbPeriod + 1;
972       freqAndTiming->ssb_MeasurementTimingConfiguration.periodicityAndOffset.choice.sf20 = duCfgParam.macCellCfg.ssbCfg.ssbScOffset;
973       freqAndTiming->ssb_MeasurementTimingConfiguration.duration = duCfgParam.srvdCellLst[0].duCellInfo.measTimeCfgDuration;
974
975       /* Encode the F1SetupRequest type as APER */
976       xer_fprint(stdout, &asn_DEF_MeasurementTimingConfigurationRrc, &measTimingConfRrc);
977
978       memset(encBuf, 0, ENC_BUF_MAX_LEN);
979       encBufSize = 0;
980       encRetVal = uper_encode(&asn_DEF_MeasurementTimingConfigurationRrc, 0, &measTimingConfRrc, PrepFinalEncBuf, encBuf);
981
982       /* Encode results */
983       if(encRetVal.encoded == ENCODE_FAIL)
984       {     
985          DU_LOG("\nERROR  -->  F1AP : Could not encode Measurement Timing Configuration structure (at %s)\n",\
986                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
987          break;
988       }     
989       else  
990       {     
991          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Measurement Timing Configuration \n");
992 #ifdef DEBUG_ASN_PRINT
993          for(measIeIdx=0; measIeIdx< encBufSize; measIeIdx++)
994          {
995             printf("%x",encBuf[measIeIdx]);
996          }
997 #endif
998
999          measTimingConf->size = encBufSize;
1000          DU_ALLOC(measTimingConf->buf, encBufSize);
1001          if(measTimingConf->buf == NULLP)
1002          {
1003             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed for MeasurementTimingConfiguration buffer");
1004             return RFAILED;
1005          }
1006          memcpy(measTimingConf->buf, &encBuf, encBufSize);
1007
1008          FreeMeasTimingConf(measTimingConfRrc);
1009
1010          ret = ROK;
1011          break;
1012       }
1013    }
1014    return ret;
1015 }
1016
1017 /*******************************************************************
1018  *
1019  * @brief Builds Served Cell List
1020  *
1021  * @details
1022  *
1023  *    Function : BuildServedCellList
1024  *
1025  *    Functionality: Building Served Cell List
1026  *
1027  * @params[in] PLMNID plmn
1028  * @return ROK     - success
1029  *         RFAILED - failure
1030  *
1031  * ****************************************************************/
1032
1033 uint8_t BuildServedCellList(GNB_DU_Served_Cells_List_t *duServedCell)
1034 {
1035    uint8_t  BuildNrcgiret=0;
1036    uint8_t  BuildFiveGSTacret=0;
1037    uint8_t  BuildServedPlmnret=0;
1038    uint8_t  BuildNrModeret=0;
1039    uint8_t  idx;
1040    uint8_t  plmnidx;
1041    uint8_t  plmnCnt=1;
1042    GNB_DU_Served_Cells_Item_t *srvCellItem;
1043    duServedCell->list.size = plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t *);
1044    duServedCell->list.count = plmnCnt;
1045
1046    DU_ALLOC(duServedCell->list.array, duServedCell->list.size);
1047    if(duServedCell->list.array == NULLP)
1048    {
1049       return RFAILED;
1050    }
1051    for(plmnidx=0; plmnidx<plmnCnt; plmnidx++)
1052    {
1053       DU_ALLOC(duServedCell->list.array[plmnidx],\
1054             sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1055       if(duServedCell->list.array[plmnidx] == NULLP)
1056       {
1057          return RFAILED;
1058       }
1059    }
1060    idx = 0;
1061    duServedCell->list.array[idx]->id = ProtocolIE_ID_id_GNB_DU_Served_Cells_Item;
1062    duServedCell->list.array[idx]->criticality = Criticality_reject;
1063    duServedCell->list.array[idx]->value.present = \
1064                                                   GNB_DU_Served_Cells_ItemIEs__value_PR_GNB_DU_Served_Cells_Item;
1065    srvCellItem = \
1066                  &duServedCell->list.array[idx]->value.choice.GNB_DU_Served_Cells_Item;
1067    /*nRCGI*/
1068    BuildNrcgiret = BuildNrcgi(&srvCellItem->served_Cell_Information.nRCGI);
1069    if(BuildNrcgiret != ROK)
1070    {
1071       return RFAILED;
1072    }
1073    /*nRPCI*/
1074    srvCellItem->served_Cell_Information.nRPCI = \
1075                                                 duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
1076
1077    /* fiveGS_TAC */
1078    BuildFiveGSTacret = BuildFiveGSTac(&srvCellItem->served_Cell_Information);
1079    if(BuildFiveGSTacret != ROK)
1080    {
1081       return RFAILED;
1082    }
1083
1084    /* Served PLMNs */
1085    BuildServedPlmnret = BuildServedPlmn(&srvCellItem->served_Cell_Information.servedPLMNs);
1086    if(BuildServedPlmnret !=ROK)
1087    {
1088       return RFAILED;
1089    }
1090
1091    /* nR Mode Info with FDD/TDD */
1092    BuildNrModeret = BuildNrMode(&srvCellItem->served_Cell_Information.nR_Mode_Info);
1093    if(BuildNrModeret != ROK)
1094    {
1095       return RFAILED;
1096    }
1097
1098    /*Measurement timing Config*/
1099    if(BuildMeasTimingConf(&srvCellItem->served_Cell_Information.measurementTimingConfiguration) != ROK)
1100       return RFAILED;
1101
1102    /* GNB DU System Information */
1103    DU_ALLOC(srvCellItem->gNB_DU_System_Information,
1104          sizeof(GNB_DU_System_Information_t));
1105    if(!srvCellItem->gNB_DU_System_Information)
1106    {
1107       return RFAILED;
1108    }
1109    /* MIB */
1110    srvCellItem->gNB_DU_System_Information->mIB_message.size = duCfgParam.srvdCellLst[0].duSysInfo.mibLen;
1111    DU_ALLOC(srvCellItem->gNB_DU_System_Information->mIB_message.buf,
1112          srvCellItem->gNB_DU_System_Information->mIB_message.size);
1113    if(!srvCellItem->gNB_DU_System_Information->mIB_message.buf)
1114    {
1115       return RFAILED;
1116    }
1117    memcpy(srvCellItem->gNB_DU_System_Information->mIB_message.buf, duCfgParam.srvdCellLst[0].duSysInfo.mibMsg, \
1118          srvCellItem->gNB_DU_System_Information->mIB_message.size);
1119
1120    /* SIB1 */
1121    srvCellItem->gNB_DU_System_Information->sIB1_message.size =\
1122                                                               duCfgParam.srvdCellLst[0].duSysInfo.sib1Len;
1123
1124    DU_ALLOC(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,
1125          srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1126    if(!srvCellItem->gNB_DU_System_Information->sIB1_message.buf)
1127    {
1128       return RFAILED;
1129    }
1130    for(int x=0; x<srvCellItem->gNB_DU_System_Information->sIB1_message.size; x++)
1131    {
1132       srvCellItem->gNB_DU_System_Information->sIB1_message.buf[x]=\
1133                                                                   duCfgParam.srvdCellLst[0].duSysInfo.sib1Msg[x];
1134    }
1135    return ROK; 
1136 }                                                                                                                  
1137 /*******************************************************************
1138  *
1139  * @brief Builds RRC Version 
1140  *
1141  * @details
1142  *
1143  *    Function : BuildRrcVer
1144  *
1145  *    Functionality: Building RRC Version
1146  *
1147  * @params[in] int idx,int elementCnt,RRC_Version_t *rrcver
1148  * @return ROK     - success
1149  *         RFAILED - failure
1150  *
1151  * ****************************************************************/
1152 uint8_t BuildRrcVer(RRC_Version_t *rrcVer)
1153 {
1154    uint8_t rrcExt;
1155    uint8_t rrcLatest;
1156    rrcVer->latest_RRC_Version.size = sizeof(uint8_t);
1157    DU_ALLOC(rrcVer->latest_RRC_Version.buf,sizeof(uint8_t));
1158    if(rrcVer->latest_RRC_Version.buf == NULLP)
1159    {
1160       return RFAILED;
1161    }
1162    rrcVer->latest_RRC_Version.buf[0] = 0;
1163    rrcVer->latest_RRC_Version.bits_unused = 5;
1164    DU_ALLOC(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1165    if(rrcVer->iE_Extensions == NULLP)
1166    {  
1167       return RFAILED;
1168    }
1169    rrcVer->iE_Extensions->list.count = 1;
1170    rrcVer->iE_Extensions->list.size = sizeof(RRC_Version_ExtIEs_t *);
1171    DU_ALLOC(rrcVer->iE_Extensions->list.array,rrcVer->iE_Extensions->list.size);
1172    if(rrcVer->iE_Extensions->list.array == NULLP)
1173    {
1174       return RFAILED;
1175    }
1176    rrcExt = 0;
1177    DU_ALLOC(rrcVer->iE_Extensions->list.array[0],\
1178          sizeof(RRC_Version_ExtIEs_t));
1179    if(rrcVer->iE_Extensions->list.array[0] == NULLP)
1180    {
1181       return RFAILED;
1182    }
1183    rrcVer->iE_Extensions->list.array[rrcExt]->id = \
1184                                                    ProtocolIE_ID_id_latest_RRC_Version_Enhanced;
1185    rrcVer->iE_Extensions->list.array[rrcExt]->criticality = Criticality_reject;
1186    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.present =\
1187                                                                       RRC_Version_ExtIEs__extensionValue_PR_Latest_RRC_Version_Enhanced;
1188    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1189       .Latest_RRC_Version_Enhanced.size = 3*sizeof(uint8_t);
1190    DU_ALLOC(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1191          .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1192          array[rrcExt]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1193    if(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1194          .Latest_RRC_Version_Enhanced.buf == NULLP)
1195    {
1196       return RFAILED;
1197    }
1198    rrcLatest = 0;
1199    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1200       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 15;
1201    rrcLatest++;
1202    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1203       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 5;
1204    rrcLatest++;
1205    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1206       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 0;
1207    return ROK;
1208 }
1209 /*******************************************************************
1210  *
1211  * @brief Sends F1 msg over SCTP
1212  *
1213  * @details
1214  *
1215  *    Function : sendF1APMsg
1216  *
1217  *    Functionality: Sends F1 msg over SCTP
1218  *
1219  * @params[in] Region region
1220  *             Pool pool
1221  * @return ROK     - success
1222  *         RFAILED - failure
1223  *
1224  * ****************************************************************/
1225 uint8_t sendF1APMsg()
1226 {
1227    Buffer *mBuf = NULLP;
1228   
1229    if(ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) == ROK)
1230    {
1231       if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
1232       {
1233             ODU_PRINT_MSG(mBuf, 0,0);
1234
1235             if(sctpSend(mBuf, F1_INTERFACE) != ROK)
1236             {
1237                DU_LOG("\nERROR  -->  F1AP : SCTP Send failed");
1238                ODU_PUT_MSG_BUF(mBuf);
1239                return RFAILED;
1240             }
1241       }
1242       else
1243       {
1244          DU_LOG("\nERROR  -->  F1AP : ODU_ADD_POST_MSG_MULT failed");
1245          ODU_PUT_MSG_BUF(mBuf);
1246          return RFAILED;
1247       }
1248       ODU_PUT_MSG_BUF(mBuf);
1249    }
1250    else
1251    {
1252       DU_LOG("\nERROR  -->  F1AP : Failed to allocate memory");
1253       return RFAILED;
1254    }
1255    return ROK; 
1256 } /* sendF1APMsg */
1257
1258 /*******************************************************************
1259  *
1260  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1261  *
1262  * @details
1263  *
1264  *    Function :  FreeRrcVer
1265  *
1266  *    Functionality: deallocating the memory of function BuildRrcVer
1267  *
1268  * @params[in] RRC_Version_t *rrcVer
1269  * 
1270  * @return void
1271  *
1272  *****************************************************************/
1273 void FreeRrcVer(RRC_Version_t *rrcVer)
1274 {
1275    if(rrcVer->latest_RRC_Version.buf != NULLP)
1276    {
1277       if(rrcVer->iE_Extensions != NULLP)
1278       {
1279          if(rrcVer->iE_Extensions->list.array != NULLP)
1280          {
1281             if(rrcVer->iE_Extensions->list.array[0] != NULLP)
1282             {
1283                if(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf
1284                      != NULLP)
1285                {
1286                   DU_FREE(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice\
1287                         .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1288                         array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1289                }
1290                DU_FREE(rrcVer->iE_Extensions->list.array[0],sizeof(RRC_Version_ExtIEs_t));
1291             }
1292             DU_FREE(rrcVer->iE_Extensions->list.array,sizeof(RRC_Version_ExtIEs_t*));
1293          }
1294          DU_FREE(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1295       }
1296       DU_FREE(rrcVer->latest_RRC_Version.buf,rrcVer->latest_RRC_Version.size);
1297    }
1298 }
1299
1300 /*******************************************************************
1301  *
1302  * @brief Deallocating memory of TDD NrFreqInfo 
1303  *
1304  * @details
1305  *
1306  *    Function : freeTddNrFreqInfo 
1307  *
1308  *    Functionality: freeTddNrFreqInfo 
1309  *
1310  * @params[in]  F1AP_PDU_t *f1apDuCfg
1311  *
1312  * @return ROK     - void
1313  *
1314  * ****************************************************************/
1315 void freeTddNrFreqInfo(NRFreqInfo_t *freqInfo)
1316 {
1317    uint8_t freqBandListIdx = 0, supportedBandIdx = 0;
1318
1319    if(freqInfo->freqBandListNr.list.array)
1320    {
1321       for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
1322       {
1323          if(freqInfo->freqBandListNr.list.array[freqBandListIdx])
1324          {
1325             if(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
1326             {
1327                for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
1328                {
1329                   DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
1330                         sizeof(SupportedSULFreqBandItem_t));
1331                }
1332                DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
1333                      freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
1334
1335             }
1336             DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
1337          }
1338       }
1339       DU_FREE(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
1340    }
1341 }
1342
1343 /*******************************************************************
1344  *
1345  * @brief Deallocating memory allocated for Nr fdd frequencey mode 
1346  *
1347  * @details
1348  *
1349  *    Function : freeFddNrFreqInfo 
1350  *
1351  *    Functionality:Free memory allocated for Nr fdd frequencey mode 
1352  *
1353  * @params[in]  
1354  *
1355  * @return ROK     - void
1356  *
1357  * ****************************************************************/
1358 void freeFddNrFreqInfo(FDD_Info_t *fDD)
1359 {
1360    uint8_t arrIdx =0;
1361
1362    if(fDD != NULLP)
1363    {
1364       if(fDD->uL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1365       {
1366          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.\
1367                array[arrIdx], sizeof(FreqBandNrItem_t));
1368          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.array, \
1369                fDD->uL_NRFreqInfo.freqBandListNr.list.size);
1370       }
1371
1372       if(fDD->dL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1373       {
1374          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.\
1375                array[arrIdx], sizeof(FreqBandNrItem_t));
1376          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.array,\
1377                fDD->dL_NRFreqInfo.freqBandListNr.list.size);
1378       }
1379       DU_FREE(fDD,sizeof(FDD_Info_t));
1380    }
1381 }
1382
1383 /*******************************************************************
1384  *
1385  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1386  *
1387  * @details
1388  *
1389  *    Function :  FreeServedCellList
1390  *
1391  *    Functionality:  deallocating the memory of function BuildServedCellList
1392
1393  *
1394  * @params[in] GNB_DU_Served_Cells_List_t *duServedCell
1395  *
1396  * @return void
1397  *
1398  * ****************************************************************/
1399 void FreeServedCellList( GNB_DU_Served_Cells_List_t *duServedCell)
1400 {
1401    uint8_t   plmnCnt= 1;
1402    uint8_t  extensionCnt=IE_EXTENSION_LIST_COUNT;
1403    uint8_t  plmnIdx=0, sliceIdx=0;
1404    GNB_DU_Served_Cells_Item_t *srvCellItem;
1405    ServedPLMNs_Item_t  *servedPlmnItem;
1406    SliceSupportItem_t  *sliceSupportItem;
1407
1408    if(duServedCell->list.array!=NULLP)
1409    {
1410       if(duServedCell->list.array[0]!=NULLP)
1411       {
1412          srvCellItem= &duServedCell->list.array[0]->value.choice.GNB_DU_Served_Cells_Item;
1413
1414          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1415                srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.size * sizeof(uint8_t));
1416          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1417                srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.size * sizeof(uint8_t));
1418
1419          if(srvCellItem->served_Cell_Information.fiveGS_TAC!=NULLP)
1420          {
1421             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC->buf,\
1422                   sizeof(srvCellItem->served_Cell_Information.fiveGS_TAC->size));
1423             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC,sizeof(FiveGS_TAC_t));
1424          }
1425
1426          if(srvCellItem->served_Cell_Information.servedPLMNs.list.array!=NULLP)
1427          {
1428             if(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx] != NULLP)
1429             {
1430                servedPlmnItem = srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx];
1431                DU_FREE(servedPlmnItem->pLMN_Identity.buf, servedPlmnItem->pLMN_Identity.size);
1432
1433                if(servedPlmnItem->iE_Extensions != NULLP)
1434                {
1435                   if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1436                   {
1437                      if(servedPlmnItem->iE_Extensions->list.array[0] != NULLP)
1438                      {
1439                         if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1440                               SliceSupportList.list.array != NULLP)
1441                         {
1442                            for(sliceIdx =0; sliceIdx<servedPlmnItem->iE_Extensions->list.array[0]->\
1443                                  extensionValue.choice.SliceSupportList.list.count; sliceIdx++)
1444                            {
1445                               if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1446                                     SliceSupportList.list.array[sliceIdx] != NULLP)
1447                               {
1448                                  sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[0]->\
1449                                                     extensionValue.choice.SliceSupportList.list.array[sliceIdx];
1450
1451                                  DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sizeof(uint8_t));
1452
1453                                  if(sliceSupportItem->sNSSAI.sD != NULLP)
1454                                  {
1455                                     DU_FREE(sliceSupportItem->sNSSAI.sD->buf,\
1456                                           sliceSupportItem->sNSSAI.sD->size);
1457                                     DU_FREE(sliceSupportItem->sNSSAI.sD, sizeof(OCTET_STRING_t));
1458                                  }
1459
1460                                  DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.\
1461                                        choice.SliceSupportList.list.array[sliceIdx], sizeof(SliceSupportItem_t));
1462                               }
1463                            }
1464                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1465                                  SliceSupportList.list.array, servedPlmnItem->iE_Extensions->list.array[0]->\
1466                                  extensionValue.choice.SliceSupportList.list.size);
1467                         }
1468                         DU_FREE(servedPlmnItem->iE_Extensions->list.array[0],\
1469                               sizeof(ServedPLMNs_ItemExtIEs_t));
1470                      }
1471                      DU_FREE(servedPlmnItem->iE_Extensions->list.array,\
1472                            extensionCnt*sizeof(ServedPLMNs_ItemExtIEs_t*));
1473                   }
1474                   DU_FREE(servedPlmnItem->iE_Extensions, sizeof(ProtocolExtensionContainer_4624P3_t));
1475                }
1476                DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx],\
1477                      sizeof(ServedPLMNs_Item_t));
1478             }
1479             DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array,\
1480                   sizeof(ServedPLMNs_Item_t *));
1481          }
1482
1483          if(srvCellItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1484          {
1485             freeFddNrFreqInfo(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1486          }
1487          else   
1488          {
1489             if(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD != NULLP)
1490             {
1491                freeTddNrFreqInfo(&srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1492                DU_FREE(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1493             }
1494          }
1495          
1496          DU_FREE(srvCellItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1497                srvCellItem->served_Cell_Information.measurementTimingConfiguration.size);
1498
1499          if(srvCellItem->gNB_DU_System_Information != NULLP)
1500          {
1501             if(srvCellItem->gNB_DU_System_Information->mIB_message.buf != NULLP)
1502             {
1503                DU_FREE(srvCellItem->gNB_DU_System_Information->mIB_message.buf,\
1504                      srvCellItem->gNB_DU_System_Information->mIB_message.size);
1505             }
1506
1507             if(srvCellItem->gNB_DU_System_Information->sIB1_message.buf != NULLP)
1508             { 
1509                DU_FREE(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,\
1510                      srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1511             }
1512
1513             DU_FREE(srvCellItem->gNB_DU_System_Information, sizeof(GNB_DU_System_Information_t));
1514          }
1515
1516          DU_FREE(duServedCell->list.array[0], sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1517       }
1518       DU_FREE(duServedCell->list.array, plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t*));
1519    }
1520 }
1521
1522 /*******************************************************************
1523  *
1524  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1525  *
1526  * @details
1527  *
1528  *    Function :  FreeF1SetupReq
1529  *
1530  *    Functionality:  deallocating the memory of function BuildAndSendF1SetupReq
1531  *
1532  * @params[in] F1AP_PDU_t *f1apMsg
1533  *
1534  * @return void
1535  *
1536  * ****************************************************************/
1537 void FreeF1SetupReq(F1AP_PDU_t *f1apMsg)
1538 {
1539    uint8_t ieIdx, ieIdx2;
1540    F1SetupRequest_t *f1SetupReq=NULLP;
1541
1542    if(f1apMsg != NULLP)
1543    {
1544       if(f1apMsg->choice.initiatingMessage != NULLP)
1545       {
1546          f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1547          if(f1SetupReq->protocolIEs.list.array != NULLP)
1548          {
1549             for(ieIdx = 0; ieIdx < f1SetupReq->protocolIEs.list.count; ieIdx++)
1550             {
1551                if(f1SetupReq->protocolIEs.list.array[ieIdx] != NULLP)
1552                {
1553                   switch(f1SetupReq->protocolIEs.list.array[ieIdx]->id)
1554                   {
1555                      case ProtocolIE_ID_id_TransactionID:
1556                         break;
1557                      case ProtocolIE_ID_id_gNB_DU_ID:
1558                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1559                               f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1560                         break;
1561                      case ProtocolIE_ID_id_gNB_DU_Name:
1562                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,\
1563                               strlen((char *)duCfgParam.duName));
1564                         break;
1565                      case ProtocolIE_ID_id_gNB_DU_Served_Cells_List:
1566                         FreeServedCellList(&f1SetupReq->protocolIEs.list.\
1567                               array[ieIdx]->value.choice.GNB_DU_Served_Cells_List);
1568                         break;
1569                      case ProtocolIE_ID_id_GNB_DU_RRC_Version:
1570                         FreeRrcVer(&f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version);
1571                         break;
1572                      default:
1573                         DU_LOG("\nERROR  -->  Invalid Event Type %ld", f1SetupReq->protocolIEs.list.array[ieIdx]->id);
1574                         break;
1575                   }
1576                }
1577             }
1578             for(ieIdx2=0; ieIdx2< ieIdx; ieIdx2++)
1579             {
1580                DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx2],sizeof(F1SetupRequestIEs_t));
1581             }
1582             DU_FREE(f1SetupReq->protocolIEs.list.array,\
1583                   f1SetupReq->protocolIEs.list.size);
1584          }
1585          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1586       }
1587       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
1588    }
1589 }
1590
1591 /*******************************************************************
1592  *
1593  * @brief Builds and Send the F1SetupRequest
1594  *
1595  * @details
1596  *
1597  *    Function : BuildAndSendF1SetupReq
1598  *
1599  * Functionality:Fills the F1SetupRequest
1600  *
1601  * @return ROK     - success
1602  *         RFAILED - failure
1603  *
1604  ******************************************************************/
1605 uint8_t BuildAndSendF1SetupReq()
1606 {
1607    uint8_t   ret, ieIdx, elementCnt;
1608    F1AP_PDU_t                 *f1apMsg = NULLP;
1609    F1SetupRequest_t           *f1SetupReq=NULLP;
1610    GNB_DU_Served_Cells_List_t *duServedCell=NULLP;
1611    RRC_Version_t              *rrcVer=NULLP;
1612    asn_enc_rval_t             encRetVal;        /* Encoder return value */
1613    ret= RFAILED;
1614
1615    DU_LOG("\nINFO   -->  F1AP : Building F1 Setup Request\n");
1616    do
1617    {
1618       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
1619       if(f1apMsg == NULLP)
1620       {
1621          break;
1622       }
1623       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
1624       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1625       if(f1apMsg->choice.initiatingMessage == NULLP)
1626       {
1627          break;
1628       }
1629       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_F1Setup;
1630       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
1631       f1apMsg->choice.initiatingMessage->value.present = \
1632                                                          InitiatingMessage__value_PR_F1SetupRequest;
1633
1634       f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1635
1636       elementCnt = 5;
1637
1638       f1SetupReq->protocolIEs.list.count = elementCnt;
1639       f1SetupReq->protocolIEs.list.size = elementCnt * sizeof(F1SetupRequestIEs_t *);
1640
1641       /* Initialize the F1Setup members */
1642       DU_ALLOC(f1SetupReq->protocolIEs.list.array,f1SetupReq->protocolIEs.list.size);
1643       if(f1SetupReq->protocolIEs.list.array == NULLP)
1644       {
1645          break;
1646       }
1647       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
1648       {
1649          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx],\
1650                sizeof(F1SetupRequestIEs_t));
1651          if(f1SetupReq->protocolIEs.list.array[ieIdx] == NULLP)
1652          {
1653             break;
1654          }
1655       }
1656
1657       ieIdx = 0;
1658       /*TransactionID*/
1659       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_TransactionID;
1660       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1661       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present =\
1662                                                                 F1SetupRequestIEs__value_PR_TransactionID;
1663       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = \
1664                                                                               TRANS_ID;
1665
1666       /*DU ID*/
1667       ieIdx++;
1668       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
1669       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1670       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1671                                                                  F1SetupRequestIEs__value_PR_GNB_DU_ID;
1672       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size =\
1673                                                                               sizeof(uint8_t);
1674
1675       DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1676             f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1677       if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == \
1678             NULLP)
1679       {
1680          break;
1681       }
1682
1683       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] =\
1684                                                                                 duCfgParam.duId;
1685       /* DU name IE is of type printableString_t which wireshark is unable to decode.
1686        * However this string is decoded successfully on online decoders.
1687        * Since this is an optional IE and the value received in it are not
1688        * used as of now, eliminating this IE for now to avoid wireshark error.
1689        */
1690       /*DU Name*/
1691       if(duCfgParam.duName != NULL)
1692       {
1693          ieIdx++;
1694          f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_Name;
1695          f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_ignore;
1696          f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = F1SetupRequestIEs__value_PR_GNB_DU_Name;
1697          f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size = strlen((char *)duCfgParam.duName);
1698          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf, \
1699                f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size);
1700          if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf == NULLP)
1701          {
1702             break;
1703          }
1704          strcpy((char*)f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,
1705                (char*)duCfgParam.duName);
1706       }
1707
1708       /*Served Cell list */
1709       ieIdx++;
1710       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1711                                                       ProtocolIE_ID_id_gNB_DU_Served_Cells_List;
1712       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1713       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1714                                                                  F1SetupRequestIEs__value_PR_GNB_DU_Served_Cells_List;
1715       duServedCell = &f1SetupReq->protocolIEs.list.\
1716                      array[ieIdx]->value.choice.GNB_DU_Served_Cells_List;
1717       if(BuildServedCellList(duServedCell))
1718       {
1719          break;
1720       }
1721
1722       /*RRC Version*/
1723       ieIdx++;
1724       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1725                                                       ProtocolIE_ID_id_GNB_DU_RRC_Version ;
1726       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1727       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1728                                                                  F1SetupRequestIEs__value_PR_RRC_Version;
1729       rrcVer = &f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
1730       if(BuildRrcVer(rrcVer))
1731       {
1732          break;
1733       }
1734
1735       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
1736
1737       /* Encode the F1SetupRequest type as APER */
1738       memset(encBuf, 0, ENC_BUF_MAX_LEN);
1739       encBufSize = 0;
1740       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
1741             encBuf);
1742
1743       /* Encode results */
1744       if(encRetVal.encoded == ENCODE_FAIL)
1745       {
1746          DU_LOG("\nERROR  -->  F1AP : Could not encode F1SetupRequest structure (at %s)\n",\
1747                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1748          break;
1749       }
1750       else
1751       {
1752          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1SetupRequest\n");
1753 #ifdef DEBUG_ASN_PRINT
1754          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
1755          {
1756             printf("%x",encBuf[ieIdx]);
1757          }
1758 #endif
1759
1760          duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize = encBufSize;
1761          DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, encBufSize);
1762          if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
1763          {
1764             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the encoding of f1setup req");
1765             return RFAILED;
1766          }
1767          memcpy(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, &encBuf, duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize);
1768       }
1769
1770       /* Sending msg */
1771       if(sendF1APMsg() != ROK)
1772       {
1773          DU_LOG("\nERROR  -->  F1AP : Sending F1 Setup request failed");
1774          break;
1775       }
1776
1777       ret=ROK;
1778       break;
1779    }while(true);
1780
1781    FreeF1SetupReq(f1apMsg);
1782
1783    return ret;
1784 }/* End of BuildAndSendF1SetupReq */
1785
1786 /*******************************************************************
1787  *
1788  * @brief Deallocating memory allocated for Served_Cells_To_Modify_Item_t
1789  *
1790  * @details
1791  *
1792  *    Function : freeCellsToModifyItem 
1793  *
1794  *    Functionality: Deallocating memory of variables allocated in
1795  *                    BuildAndSendDUConfigUpdate function
1796  *
1797  * @params[in]  Served_Cells_To_Modify_Item_t *modifyItem
1798  *
1799  * @return ROK     - void
1800  *
1801  * ****************************************************************/
1802
1803 void freeCellsToModifyItem(Served_Cells_To_Modify_Item_t *modifyItem)
1804 {
1805    uint8_t arrIdx=0, servedPlmnIdx=0, sliceLstIdx=0;
1806    ServedPLMNs_Item_t *servedPlmnItem = NULLP;
1807    SliceSupportItem_t *sliceSupportItem = NULLP;
1808
1809    DU_FREE(modifyItem->oldNRCGI.pLMN_Identity.buf, modifyItem->oldNRCGI.pLMN_Identity.size);
1810    DU_FREE(modifyItem->oldNRCGI.nRCellIdentity.buf, modifyItem->oldNRCGI.nRCellIdentity.size);
1811
1812    DU_FREE(modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1813            modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.size);
1814    DU_FREE(modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1815          modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.size);
1816
1817    if(modifyItem->served_Cell_Information.servedPLMNs.list.array != NULLP)
1818    {
1819       if(modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx] != NULLP)
1820       {
1821          servedPlmnItem = modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx];
1822
1823          DU_FREE(servedPlmnItem->pLMN_Identity.buf,servedPlmnItem->pLMN_Identity.size);
1824
1825          if(servedPlmnItem->iE_Extensions != NULLP)
1826          {
1827             if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1828             {
1829                if(servedPlmnItem->iE_Extensions->list.array[arrIdx] != NULLP)
1830                {
1831                   if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1832                         list.array != NULLP)
1833                   {
1834                      for(sliceLstIdx =0; sliceLstIdx<servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1835                            extensionValue.choice.SliceSupportList.list.count; sliceLstIdx++)
1836                      {
1837                         if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1838                               list.array[sliceLstIdx] != NULLP)
1839                         {
1840
1841                            sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1842                                               SliceSupportList.list.array[sliceLstIdx];
1843
1844                            DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sliceSupportItem->sNSSAI.sST.size);
1845                            if(sliceSupportItem->sNSSAI.sD != NULLP)
1846                            {
1847                               DU_FREE(sliceSupportItem->sNSSAI.sD->buf, sliceSupportItem->sNSSAI.sD->size);
1848                               DU_FREE(sliceSupportItem->sNSSAI.sD,sizeof(OCTET_STRING_t));
1849                            }
1850                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1851                                  SliceSupportList.list.array[sliceLstIdx], sizeof(SliceSupportItem_t));
1852                         }
1853                      }
1854                      DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.\
1855                            choice.SliceSupportList.list.array,\
1856                            servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1857                            extensionValue.choice.SliceSupportList.list.size);
1858                   }
1859                }
1860                for(servedPlmnIdx=0; servedPlmnIdx< servedPlmnItem->iE_Extensions->list.count ; servedPlmnIdx++)
1861                {
1862                   DU_FREE(servedPlmnItem->iE_Extensions->list.array[servedPlmnIdx], sizeof(ServedPLMNs_ItemExtIEs_t ));
1863                }
1864                DU_FREE(servedPlmnItem->iE_Extensions->list.array, servedPlmnItem->iE_Extensions->list.size);
1865             }
1866             DU_FREE(servedPlmnItem->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1867          }
1868       }
1869       for(servedPlmnIdx=0; servedPlmnIdx<modifyItem->served_Cell_Information.servedPLMNs.list.count; servedPlmnIdx++)
1870       {
1871          DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array[servedPlmnIdx], sizeof(ServedPLMNs_Item_t));
1872       }
1873       DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array,\
1874          modifyItem->served_Cell_Information.servedPLMNs.list.size);
1875    }
1876    
1877    if(modifyItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1878    {
1879       freeFddNrFreqInfo(modifyItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1880    }  
1881    else
1882    {
1883       if(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD)
1884       {
1885          freeTddNrFreqInfo(&modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1886          DU_FREE(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1887       }
1888    }
1889    DU_FREE(modifyItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1890          modifyItem->served_Cell_Information.measurementTimingConfiguration.size);
1891 }
1892
1893 /*******************************************************************
1894  *
1895  * @brief Deallocating memory of BuildAndSendDUConfigUpdate
1896  *
1897  * @details
1898  *
1899  *    Function : FreeDUConfigUpdate
1900  *
1901  *    Functionality: Deallocating memory of variables allocated in
1902  *                    BuildAndSendDUConfigUpdate function
1903  *
1904  * @params[in]  F1AP_PDU_t *f1apDuCfg
1905  *
1906  * @return ROK     - void
1907  *
1908  * ****************************************************************/
1909 void FreeDUConfigUpdate(F1AP_PDU_t *f1apDuCfg)
1910 {
1911    uint8_t  idx=0,ieIdx=0, cellModifyIdx=0, cellDeleteIdx=0;
1912    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
1913    Served_Cells_To_Modify_List_t  *cellsToModify=NULLP;
1914    Served_Cells_To_Delete_List_t  *cellsToDelete=NULLP;
1915    Served_Cells_To_Delete_Item_t  *deleteItem = NULLP;
1916    Served_Cells_To_Delete_ItemIEs_t *deleteItemIe = NULLP;
1917    Cells_Status_ItemIEs_t *cellStatusItemIE;
1918
1919    if(f1apDuCfg != NULLP)
1920    {
1921       if(f1apDuCfg->choice.initiatingMessage != NULLP)
1922       {
1923          duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->\
1924                        value.choice.GNBDUConfigurationUpdate;
1925          if(duCfgUpdate->protocolIEs.list.array != NULLP)
1926          {
1927             for(ieIdx=0; ieIdx<duCfgUpdate->protocolIEs.list.count; ieIdx++)
1928             {
1929                if(duCfgUpdate->protocolIEs.list.array[ieIdx] != NULLP)
1930                {
1931                   switch(duCfgUpdate->protocolIEs.list.array[ieIdx]->id)
1932                   {
1933                      case ProtocolIE_ID_id_Served_Cells_To_Modify_List:
1934                         {
1935                            cellsToModify = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1936                                            value.choice.Served_Cells_To_Modify_List;
1937                            if(cellsToModify->list.array != NULLP)
1938                            {
1939                               for(cellModifyIdx=0; cellModifyIdx<cellsToModify->list.count ;cellModifyIdx++)
1940                               {
1941                                  if(cellsToModify->list.array[cellModifyIdx] != NULLP)
1942                                  {
1943                                     freeCellsToModifyItem(&cellsToModify->list.array[cellModifyIdx]->value.choice.\
1944                                           Served_Cells_To_Modify_Item);
1945                                     DU_FREE(cellsToModify->list.array[cellModifyIdx],\
1946                                           sizeof(Served_Cells_To_Modify_ItemIEs_t));
1947                                  }
1948                               }
1949                               DU_FREE(cellsToModify->list.array,cellsToModify->list.size);
1950                            }
1951                            break;
1952                         }
1953                      case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
1954                         {
1955                            cellsToDelete = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1956                                            value.choice.Served_Cells_To_Delete_List;
1957                            if(cellsToDelete->list.array != NULLP)
1958                            {
1959                               for(cellDeleteIdx=0; cellDeleteIdx<cellsToDelete->list.count ;cellDeleteIdx++)
1960                               {
1961                                  if(cellsToDelete->list.array[cellDeleteIdx] != NULLP)
1962                                  {
1963                                     deleteItemIe = ((Served_Cells_To_Delete_ItemIEs_t*)\
1964                                           cellsToDelete->list.array[cellDeleteIdx]);
1965                                     deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
1966                                     DU_FREE(deleteItem->oldNRCGI.pLMN_Identity.buf,\
1967                                           deleteItem->oldNRCGI.pLMN_Identity.size); 
1968                                     DU_FREE(deleteItem->oldNRCGI.nRCellIdentity.buf,\
1969                                           deleteItem->oldNRCGI.nRCellIdentity.size);
1970                                     DU_FREE(cellsToDelete->list.array[cellDeleteIdx],\
1971                                           sizeof(Served_Cells_To_Delete_ItemIEs_t));
1972                                  }
1973                               }
1974                               DU_FREE(cellsToDelete->list.array,cellsToDelete->list.size);
1975                            }
1976
1977                            break;
1978                         }
1979                      case ProtocolIE_ID_id_gNB_DU_ID:
1980                         {
1981                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1982                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1983                            break;
1984                         }
1985                      case ProtocolIE_ID_id_Cells_Status_List:
1986                         {
1987                            for(idx = 0; idx < duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.count; idx++)
1988                            {
1989                               cellStatusItemIE = (Cells_Status_ItemIEs_t *)duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array[idx];
1990                               DU_FREE(cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.nRCellIdentity.buf, cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.nRCellIdentity.size);
1991                               DU_FREE(cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.pLMN_Identity.buf, cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.pLMN_Identity.size);
1992                               DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array[idx],sizeof(Cells_Status_ItemIEs_t));
1993                            }
1994                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array,\
1995                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.size);
1996                         }
1997                   }
1998                   DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx],\
1999                         sizeof(GNBDUConfigurationUpdateIEs_t));
2000                }
2001             }
2002             DU_FREE(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2003          }
2004          DU_FREE(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2005       }
2006       DU_FREE(f1apDuCfg, (Size)sizeof(F1AP_PDU_t));
2007    }
2008 }
2009
2010 /*******************************************************************
2011  *
2012  * @brief Fills Served Plmns required in ServCellInfo IE
2013  *
2014  * @details
2015  *
2016  *    Function : fillServedPlmns
2017  *
2018  *    Functionality: Fills Served Plmns required in ServCellInfo IE
2019  *
2020  * @params[in] Pointer to ServedPLMNs_List_t *
2021  *
2022  * @return ROK     - success
2023  *         RFAILED - failure
2024  *
2025  *****************************************************************/
2026
2027 uint8_t fillServedPlmns(ServedPLMNs_List_t *servedPlmn)
2028 {
2029    uint8_t ieIdx=0, arrayIdx=0, ieListCnt=0, elementCnt=0, sliceLstIdx=0;
2030
2031    servedPlmn->list.array[arrayIdx]->pLMN_Identity.size = 3*sizeof(uint8_t);
2032    DU_ALLOC(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf, servedPlmn->list.\
2033          array[arrayIdx]->pLMN_Identity.size);
2034    if(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf == NULLP)
2035    {
2036       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2037       return RFAILED;
2038    }
2039    buildPlmnId(duCfgParam.srvdCellLst[arrayIdx].duCellInfo.cellInfo.srvdPlmn[arrayIdx].plmn,\
2040          servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf);
2041    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
2042    if(servedPlmn->list.array[arrayIdx]->iE_Extensions == NULLP)
2043    {
2044       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2045       return RFAILED;
2046    }
2047
2048    ieListCnt=1;
2049    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.count = ieListCnt;
2050    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.size = ieListCnt *sizeof(ServedPLMNs_ItemExtIEs_t *);
2051    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array,servedPlmn->list.array[arrayIdx]->\
2052          iE_Extensions->list.size);
2053    if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array == NULLP)
2054    {
2055       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2056       return RFAILED;
2057    }
2058    for(ieIdx=arrayIdx;ieIdx<ieListCnt;ieIdx++)
2059    {
2060       DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx],\
2061             sizeof(ServedPLMNs_ItemExtIEs_t));
2062       if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx] == NULLP)
2063       {
2064          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2065          return RFAILED;
2066       }
2067    }
2068    
2069    ieIdx = 0;
2070    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices; 
2071    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->id =ProtocolIE_ID_id_TAISliceSupportList;
2072    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->criticality = Criticality_ignore;
2073    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.present = \
2074    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
2075    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2076       list.count = elementCnt;
2077    servedPlmn->list.array[arrayIdx]->\
2078       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2079       list.size = elementCnt * sizeof(SliceSupportItem_t *);
2080    DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2081          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2082          list.array,servedPlmn->list.array[arrayIdx]->\
2083          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.size);
2084    if(servedPlmn->list.array[arrayIdx]->\
2085          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2086          list.array == NULLP)
2087    {
2088       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2089       return RFAILED;
2090    }
2091
2092    for(sliceLstIdx =0; sliceLstIdx< elementCnt; sliceLstIdx++)
2093    {
2094       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2095       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2096       list.array[sliceLstIdx],sizeof( SliceSupportItem_t));
2097       if(servedPlmn->list.array[arrayIdx]->\
2098       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2099       list.array[sliceLstIdx] == NULLP)
2100       {   
2101          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2102          return RFAILED;
2103       }
2104       
2105       servedPlmn->list.array[arrayIdx]->\
2106       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2107       list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
2108       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2109       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2110       list.array[sliceLstIdx]->sNSSAI.sST.buf,servedPlmn->list.array[arrayIdx]->\
2111       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->\
2112       sNSSAI.sST.size);
2113       
2114       if(servedPlmn->list.array[arrayIdx]->\
2115       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2116       list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
2117       {
2118          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2119          return RFAILED;
2120       }
2121       servedPlmn->list.array[arrayIdx]->\
2122       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2123       list.array[sliceLstIdx]->sNSSAI.sST.buf[arrayIdx] =  duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
2124       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
2125
2126       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2127       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2128       list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
2129       if(servedPlmn->list.array[arrayIdx]->\
2130       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2131       list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
2132       {
2133          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2134          return RFAILED;
2135       }
2136       servedPlmn->list.array[arrayIdx]->\
2137       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2138       list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
2139       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2140       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2141       list.array[sliceLstIdx]->sNSSAI.sD->buf,servedPlmn->list.array[arrayIdx]->\
2142       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2143       list.array[sliceLstIdx]->sNSSAI.sD->size);
2144       if(servedPlmn->list.array[arrayIdx]->\
2145       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2146       list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
2147       {
2148          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2149          return RFAILED;
2150       }
2151       memcpy(servedPlmn->list.array[arrayIdx]->\
2152       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2153       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
2154       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sd,\
2155       servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2156       list.array[sliceLstIdx]->sNSSAI.sD->size);
2157    }
2158    return ROK;
2159 }
2160
2161 /*******************************************************************
2162  *
2163  * @brief Fills Nr Fdd Info required in ServCellInfo IE
2164  *
2165  * @details
2166  *
2167  *    Function : fillNrFddInfo
2168  *
2169  *    Functionality: Fills Nr Fdd Info required in ServCellInfo IE
2170  *
2171  * @params[in] FDD_Info_t *fDD
2172  *
2173  * @return ROK     - success
2174  *         RFAILED - failure
2175  *
2176  *****************************************************************/
2177
2178 uint8_t fillNrFddInfo(FDD_Info_t *fDD)
2179 {
2180    fDD->uL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.\
2181       f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn;
2182    fDD->uL_NRFreqInfo.freqBandListNr.list.count = 1;
2183    fDD->uL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t*);
2184    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.\
2185          array, fDD->uL_NRFreqInfo.freqBandListNr.list.size);
2186    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array == NULLP)
2187    {
2188       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2189       return RFAILED;
2190    }
2191
2192    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0], \
2193       sizeof(FreqBandNrItem_t));
2194    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2195    {
2196       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2197       return RFAILED;
2198    }
2199    
2200    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2201       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
2202       freqBand[0].nrFreqBand;
2203    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2204    fDD->dL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.\
2205       dlNrFreqInfo.nrArfcn;
2206    fDD->dL_NRFreqInfo.freqBandListNr.list.count = 1;
2207    fDD->dL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
2208    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array, fDD->dL_NRFreqInfo.freqBandListNr.list.size);
2209    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array == NULLP)
2210    {
2211       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2212       return RFAILED;
2213    }
2214    
2215    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0],  sizeof(FreqBandNrItem_t));
2216    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2217    {
2218       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2219       return RFAILED;
2220    }
2221
2222    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2223       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
2224       freqBand[0].nrFreqBand;
2225    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2226    
2227    /*Transmission Bandwidth*/
2228    fDD->uL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2229       f1Mode.mode.fdd.ulTxBw.nrScs;
2230    fDD->uL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2231       f1Mode.mode.fdd.ulTxBw.nrb;
2232    fDD->dL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2233       f1Mode.mode.fdd.dlTxBw.nrScs;
2234    fDD->dL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2235       f1Mode.mode.fdd.dlTxBw.nrb;
2236
2237    return ROK;
2238 }
2239
2240 /*******************************************************************
2241  *
2242  * @brief Fills ServCellInfo IE
2243  *
2244  * @details
2245  *
2246  *    Function : fillServedCellInfo
2247  *
2248  *    Functionality: Fills ServCellInfo
2249  *
2250  * @params[in] Pointer to Served_Cell_Information_t *
2251  *
2252  * @return ROK     - success
2253  *         RFAILED - failure
2254  *
2255  *****************************************************************/
2256
2257 uint8_t fillServedCellInfo(Served_Cell_Information_t *srvCellInfo)
2258 {
2259    uint8_t ieIdx, ieListCnt;
2260
2261    /*nRCGI*/
2262    srvCellInfo->nRCGI.pLMN_Identity.size =3*sizeof(uint8_t);
2263    DU_ALLOC(srvCellInfo->nRCGI.pLMN_Identity.buf,\
2264          srvCellInfo->nRCGI.pLMN_Identity.size);
2265    if(srvCellInfo->nRCGI.pLMN_Identity.buf == NULLP)
2266    {
2267       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2268       return RFAILED;
2269    }
2270    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2271          srvCellInfo->nRCGI.pLMN_Identity.buf);
2272    srvCellInfo->nRCGI.nRCellIdentity.size =5*sizeof(uint8_t);
2273    DU_ALLOC(srvCellInfo->nRCGI.nRCellIdentity.buf,\
2274          srvCellInfo->nRCGI.nRCellIdentity.size);
2275    if(srvCellInfo->nRCGI.nRCellIdentity.buf == NULLP)
2276    {   
2277       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2278       return RFAILED;
2279    }
2280    
2281    fillBitString(&srvCellInfo->nRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2282    /*nRPCI*/
2283    srvCellInfo->nRPCI = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
2284
2285    /*servedPLMNs*/
2286    ieListCnt = 1;
2287    srvCellInfo->servedPLMNs.list.count = ieListCnt;
2288    srvCellInfo->servedPLMNs.list.size = ieListCnt*sizeof(ServedPLMNs_Item_t *);
2289    DU_ALLOC(srvCellInfo->servedPLMNs.list.array, srvCellInfo->servedPLMNs.list.size);
2290    if(srvCellInfo->servedPLMNs.list.array == NULLP)
2291    {
2292       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2293       return RFAILED;
2294    }
2295    for(ieIdx=0; ieIdx < ieListCnt; ieIdx++)
2296    {
2297       DU_ALLOC(srvCellInfo->servedPLMNs.list.array[ieIdx], sizeof(ServedPLMNs_Item_t));
2298       if(srvCellInfo->servedPLMNs.list.array[ieIdx]== NULLP)
2299       {
2300          DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2301          return RFAILED;
2302       }
2303    }
2304    if(fillServedPlmns(&srvCellInfo->servedPLMNs))
2305    {
2306       DU_LOG("\nERROR  --> Failed to fill Served Plmn info");
2307       return RFAILED;
2308    }
2309
2310 #ifndef NR_TDD
2311    /*nR Mode Info with FDD*/
2312    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_fDD;
2313    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.fDD, sizeof(FDD_Info_t));
2314    if(srvCellInfo->nR_Mode_Info.choice.fDD == NULLP)
2315    {
2316       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2317       return RFAILED;
2318    }
2319    if(fillNrFddInfo(srvCellInfo->nR_Mode_Info.choice.fDD))
2320    {
2321        DU_LOG("\nERROR  --> Failed to fill the Nr FDD information");
2322       return RFAILED;
2323    }
2324 #else
2325    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_tDD;   
2326    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
2327    if(srvCellInfo->nR_Mode_Info.choice.tDD == NULLP)
2328    {
2329       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2330       return RFAILED;
2331    }
2332    if(fillNrTddInfo(srvCellInfo->nR_Mode_Info.choice.tDD) != ROK)
2333    {
2334       DU_LOG("\nERROR  --> Failed to fill the Nr TDD information");
2335       return RFAILED;
2336    }
2337 #endif
2338
2339    /*Measurement timing Config*/
2340    if(BuildMeasTimingConf(&srvCellInfo->measurementTimingConfiguration) != ROK)
2341       return RFAILED;
2342
2343    return ROK;
2344 }
2345
2346 /*******************************************************************
2347  *
2348  * @brief Fills ServCellToModItem IE
2349  *
2350  * @details
2351  *
2352  *    Function : fillServCellToModItem
2353  *
2354  *    Functionality: Fills ServCellToModItem IE
2355  *
2356  * @params[in] Pointer to Served_Cells_To_Modify_Item_t *
2357  *
2358  * @return ROK     - success
2359  *         RFAILED - failure
2360  *
2361  *****************************************************************/
2362
2363 uint8_t fillServCellToModItem(Served_Cells_To_Modify_Item_t *modifyItem)
2364 {
2365    /*pLMN_Identity*/
2366    modifyItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2367    DU_ALLOC(modifyItem->oldNRCGI.pLMN_Identity.buf,modifyItem->oldNRCGI.pLMN_Identity.size);
2368    if(modifyItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2369    {
2370       return RFAILED;
2371    }
2372    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2373          modifyItem->oldNRCGI.pLMN_Identity.buf);
2374
2375    /*nRCellIdentity*/
2376    modifyItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2377    DU_ALLOC(modifyItem->oldNRCGI.nRCellIdentity.buf,\
2378          modifyItem->oldNRCGI.nRCellIdentity.size);
2379    if(modifyItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2380    {
2381       return RFAILED;
2382    }
2383    fillBitString(&modifyItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2384
2385    if(fillServedCellInfo(&modifyItem->served_Cell_Information))
2386       return RFAILED;
2387    else
2388       return ROK;
2389 }
2390
2391 /*******************************************************************
2392  *
2393  * @brief Builds ServCellToModList
2394  *
2395  * @details
2396  *
2397  *    Function : buildServCellToModList
2398  *
2399  *    Functionality: Builds the serv cell to Mod List
2400  *
2401  * @params[in] Pointer to Served_Cells_To_Modify_List_t *
2402  *
2403  * @return ROK     - success
2404  *         RFAILED - failure
2405  *
2406  *****************************************************************/
2407
2408 uint8_t buildServCellToModList(Served_Cells_To_Modify_List_t *cellsToModify)
2409 {
2410    uint8_t ieListCnt, ieIdx;
2411    Served_Cells_To_Modify_Item_t *modifyItem = NULLP;
2412
2413    ieListCnt = 1;
2414    cellsToModify->list.count = ieListCnt;
2415    cellsToModify->list.size = ieListCnt*sizeof(Served_Cells_To_Modify_ItemIEs_t *);
2416    DU_ALLOC(cellsToModify->list.array,cellsToModify->list.size);
2417    if(cellsToModify->list.array == NULLP)
2418    {
2419       return RFAILED;
2420    }
2421    for(ieIdx=0; ieIdx< ieListCnt; ieIdx++)
2422    {
2423       DU_ALLOC(cellsToModify->list.array[ieIdx],sizeof(Served_Cells_To_Modify_ItemIEs_t));
2424       if(cellsToModify->list.array[ieIdx] == NULLP)
2425       {
2426          return RFAILED;
2427       }
2428    }
2429    cellsToModify->list.array[0]->id = ProtocolIE_ID_id_Served_Cells_To_Modify_Item;
2430    cellsToModify->list.array[0]->criticality = Criticality_reject;
2431    cellsToModify->list.array[0]->value.present =\
2432       Served_Cells_To_Modify_ItemIEs__value_PR_Served_Cells_To_Modify_Item;
2433    modifyItem=&cellsToModify->list.array[0]->value.choice.Served_Cells_To_Modify_Item;
2434
2435    if(fillServCellToModItem(modifyItem))
2436       return RFAILED;
2437    else
2438       return ROK;
2439 }
2440 /*******************************************************************
2441  *
2442  * @brief filling the DeleteItemList
2443  *
2444  * @details
2445  *
2446  *    Function : fillCellToDeleteItem 
2447  *
2448  *    Functionality: Filling the DeleteItemIe 
2449  *
2450  * @params[in] Pointer to Served_Cells_To_Delete_ItemIEs_t 
2451  *
2452  * @return ROK     - success
2453  *         RFAILED - failure
2454  *
2455  *****************************************************************/
2456 uint8_t fillCellToDeleteItem(struct Served_Cells_To_Delete_ItemIEs *deleteItemIe)
2457 {
2458    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
2459    
2460    deleteItemIe->id = ProtocolIE_ID_id_Served_Cells_To_Delete_Item;
2461    deleteItemIe->criticality = Criticality_reject;
2462    deleteItemIe->value.present =\
2463    Served_Cells_To_Delete_ItemIEs__value_PR_Served_Cells_To_Delete_Item;
2464    deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
2465
2466    /*pLMN_Identity*/
2467    deleteItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2468    DU_ALLOC(deleteItem->oldNRCGI.pLMN_Identity.buf,deleteItem->oldNRCGI.pLMN_Identity.size);
2469    if(deleteItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2470    {
2471       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2472       return RFAILED;
2473    }
2474    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2475          deleteItem->oldNRCGI.pLMN_Identity.buf);
2476
2477    /*nRCellIdentity*/
2478    deleteItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2479    DU_ALLOC(deleteItem->oldNRCGI.nRCellIdentity.buf,\
2480          deleteItem->oldNRCGI.nRCellIdentity.size);
2481    if(deleteItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2482    {
2483       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2484       return RFAILED;
2485    }
2486    fillBitString(&deleteItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2487    return ROK;
2488
2489
2490 /*******************************************************************
2491  *
2492  * @brief Builds ServCellToDeleteList
2493  *
2494  * @details
2495  *
2496  *    Function : buildServCellToDeleteList
2497  *
2498  *    Functionality: Builds the serv cell to delete List
2499  *
2500  * @params[in] Pointer to Served_Cells_To_Delete_List_t *
2501  *
2502  * @return ROK     - success
2503  *         RFAILED - failure
2504  *
2505  *****************************************************************/
2506  
2507 uint8_t buildServCellToDeleteList(Served_Cells_To_Delete_List_t *cellsToDelete)
2508 {
2509    uint8_t ieListCnt, arrIdx;
2510    
2511    ieListCnt = 1;
2512    cellsToDelete->list.count = ieListCnt;
2513    cellsToDelete->list.size = ieListCnt*sizeof(Served_Cells_To_Delete_ItemIEs_t *);
2514    
2515    DU_ALLOC(cellsToDelete->list.array,cellsToDelete->list.size);
2516    if(cellsToDelete->list.array == NULLP)
2517    {
2518       DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2519       return RFAILED;
2520    }
2521    
2522    for(arrIdx=0; arrIdx< ieListCnt; arrIdx++)
2523    {
2524       DU_ALLOC(cellsToDelete->list.array[arrIdx],sizeof(Served_Cells_To_Delete_ItemIEs_t));
2525       if(cellsToDelete->list.array[arrIdx] == NULLP)
2526       {
2527          DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2528          return RFAILED;
2529       }
2530    }
2531    
2532    arrIdx=0;
2533    if(fillCellToDeleteItem((Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx]) !=ROK)
2534    {
2535       DU_LOG("\nERROR  -->  F1AP: buildServCellToDeleteList(): failed to fill Served_Cells_To_Delete_ItemIEs");
2536       return RFAILED;
2537    }
2538    return ROK;
2539 }
2540
2541 /*******************************************************************
2542  *
2543  * @brief Builds CellsStatusList
2544  *
2545  * @details
2546  *
2547  *    Function : buildCellsStatusList
2548  *
2549  *    Functionality: Builds the Cell Status List
2550  *
2551  * @params[in] Pointer to Cells_Status_List_t *
2552  *
2553  * @return ROK     - success
2554  *         RFAILED - failure
2555  *
2556  *****************************************************************/
2557 uint8_t buildCellsStatusList(Cells_Status_List_t *cellStatusList)
2558 {
2559    uint8_t elementCnt = 0, idx = 0, ret = ROK;
2560    Cells_Status_ItemIEs_t *cellStatusItemIE;
2561
2562    elementCnt = 1;
2563    cellStatusList->list.count = elementCnt;
2564    cellStatusList->list.size = elementCnt * sizeof(Cells_Status_ItemIEs_t *);
2565    DU_ALLOC(cellStatusList->list.array, cellStatusList->list.size);
2566
2567    for(idx = 0; idx < elementCnt; idx++)
2568    {
2569       DU_ALLOC(cellStatusList->list.array[idx], sizeof(Cells_Status_ItemIEs_t));
2570       if(!cellStatusList->list.array[idx])
2571       {
2572          DU_LOG("ERROR  --> F1AP: buildCellsStatusList() memory allocation failure");
2573          return RFAILED;
2574       }
2575    }
2576    idx = 0;
2577    cellStatusItemIE = (Cells_Status_ItemIEs_t *)cellStatusList->list.array[idx];
2578    cellStatusItemIE->id = ProtocolIE_ID_id_Cells_Status_Item;
2579    cellStatusItemIE->criticality = Criticality_reject;
2580    cellStatusItemIE->value.present = Cells_Status_ItemIEs__value_PR_Cells_Status_Item;
2581    ret = BuildNrcgi(&cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI);
2582    if(ret == RFAILED)
2583    {
2584          DU_LOG("ERROR  --> F1AP: buildCellsStatusList() NRCGI failed");
2585          return RFAILED;
2586    }
2587    cellStatusItemIE->value.choice.Cells_Status_Item.service_status.service_state = Service_State_in_service;
2588    return ROK;
2589 }
2590
2591 /*******************************************************************
2592  *
2593  * @brief Builds and sends the DUConfigUpdate
2594  *
2595  * @details
2596  *
2597  *    Function : BuildAndSendDUConfigUpdate
2598  *
2599  *    Functionality: Constructs the DU Update message and sends
2600  *                   it to the CU through SCTP.
2601  *
2602  * @params[in] void **buf,Buffer to which encoded pattern is written into
2603  * @params[in] int *size,size of buffer
2604  *
2605  * @return ROK     - success
2606  *         RFAILED - failure
2607  *
2608  * ****************************************************************/
2609 uint8_t BuildAndSendDUConfigUpdate(ServCellAction servCellAction)
2610 {
2611    uint8_t ret =0, ieIdx=0, elementCnt=0;
2612    bool memAlloctionFailure = false;
2613    F1AP_PDU_t                 *f1apDuCfg = NULLP;
2614    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
2615    asn_enc_rval_t encRetVal;     /* Encoder return value */
2616    
2617    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2618    ret= RFAILED;
2619
2620    while(true)
2621    {
2622       DU_LOG("\nINFO   -->  F1AP : Building DU config update\n");
2623       /* Allocate the memory for F1DuCfg */
2624       DU_ALLOC(f1apDuCfg, sizeof(F1AP_PDU_t));
2625       if(f1apDuCfg == NULLP)
2626       {
2627          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2628          break;
2629       }
2630
2631       f1apDuCfg->present = F1AP_PDU_PR_initiatingMessage;
2632       DU_ALLOC(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2633       if(f1apDuCfg->choice.initiatingMessage == NULLP)
2634       {
2635          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2636          break;
2637       }
2638
2639       f1apDuCfg->choice.initiatingMessage->procedureCode = \
2640                                                            ProcedureCode_id_gNBDUConfigurationUpdate;
2641       f1apDuCfg->choice.initiatingMessage->criticality = Criticality_reject;
2642       f1apDuCfg->choice.initiatingMessage->value.present = \
2643                                                            InitiatingMessage__value_PR_GNBDUConfigurationUpdate;
2644       duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->value.\
2645                     choice.GNBDUConfigurationUpdate;
2646       elementCnt = 4;
2647       duCfgUpdate->protocolIEs.list.count = elementCnt;
2648       duCfgUpdate->protocolIEs.list.size = \
2649                                            elementCnt * sizeof(GNBDUConfigurationUpdateIEs_t*);
2650
2651       /* Initialize the F1Setup members */
2652       DU_ALLOC(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2653       if(duCfgUpdate->protocolIEs.list.array == NULLP)
2654       {
2655          DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2656          break;
2657       }
2658       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
2659       {
2660          DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx],sizeof(GNBDUConfigurationUpdateIEs_t));
2661          if(duCfgUpdate->protocolIEs.list.array[ieIdx] == NULLP)
2662          {
2663             DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2664             memAlloctionFailure = true;
2665             break;
2666          }
2667       }
2668       
2669       if(memAlloctionFailure == true)
2670       {
2671          break;
2672       }
2673       /*TransactionID*/
2674       ieIdx = 0;
2675       duCfgUpdate->protocolIEs.list.array[ieIdx]->id=ProtocolIE_ID_id_TransactionID;
2676       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
2677       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2678       GNBDUConfigurationUpdateIEs__value_PR_TransactionID;
2679       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = TRANS_ID;
2680       
2681       ieIdx++;
2682       if(servCellAction == SERV_CELL_TO_MODIFY)
2683       {
2684          /*Served Cell to Modify */
2685          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2686          ProtocolIE_ID_id_Served_Cells_To_Modify_List;
2687          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2688          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2689          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Modify_List;
2690          if(buildServCellToModList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2691                   Served_Cells_To_Modify_List))
2692          {
2693             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToModList");
2694             break;
2695          }
2696       }
2697       else
2698       {
2699          /*Served Cell to Delete */ 
2700          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2701          ProtocolIE_ID_id_Served_Cells_To_Delete_List;
2702          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2703          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2704          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Delete_List;
2705          if(buildServCellToDeleteList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2706          Served_Cells_To_Delete_List)!=ROK)
2707          {
2708             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToDeleteList");
2709             break;
2710          }
2711          
2712       }
2713       // TODO :GNB DU SYS INFO:MIB AND SIB1 INFORMATION TO BE BUILT AND FILLED HERE
2714       
2715       /*Cell Status List*/
2716       ieIdx++;
2717       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_Cells_Status_List;
2718       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2719       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2720            GNBDUConfigurationUpdateIEs__value_PR_Cells_Status_List;
2721       ret = buildCellsStatusList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List);
2722       if(ret == RFAILED)
2723       {
2724          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Cell Status List building failed");
2725          break;
2726       }
2727
2728       /*GNB DU ID */
2729       ieIdx++;
2730       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
2731       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2732       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2733       GNBDUConfigurationUpdateIEs__value_PR_GNB_DU_ID;
2734       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size = sizeof(uint8_t);
2735       DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
2736             duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
2737       if(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == NULLP)
2738       {
2739          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Memory allocation failed for GNB_DU_ID");
2740          break;
2741       }
2742       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] = duCfgParam.duId;
2743
2744       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apDuCfg);
2745
2746       /* Encode the DU Config Update type as APER */
2747       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
2748       encBufSize = 0;
2749       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apDuCfg, PrepFinalEncBuf, encBuf);
2750
2751       /* Checking encode results */
2752       if(encRetVal.encoded == ENCODE_FAIL)
2753       {
2754          DU_LOG("ERROR  -->  F1AP : Could not encode DUConfigUpdate structure (at %s)\n",\
2755                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2756          break;
2757       }
2758       else
2759       {
2760          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DUConfigUpdate\n");
2761 #ifdef DEBUG_ASN_PRINT
2762          for(ieIdx =0; ieIdx < encBufSize; ieIdx++)
2763          {
2764             printf("%x",encBuf[ieIdx]);
2765          }
2766 #endif
2767       }
2768       /* Sending msg */
2769       if(sendF1APMsg() != ROK)
2770       {
2771          DU_LOG("\nERROR  -->  F1AP : Sending GNB-DU Config Update failed");
2772          break;
2773       }
2774
2775       ret = ROK;
2776       break;
2777    }
2778   
2779    addToReservedF1apPduList(TRANS_ID,f1apDuCfg);
2780    return ret;
2781 }
2782
2783
2784 /*******************************************************************
2785  *
2786  * @brief free the ULRRCMessageTransfer
2787  *
2788  * @details
2789  *
2790  *    Function : FreeULRRCMessageTransfer
2791  *
2792  *    Functionality: Deallocating the memory of variable allocated in
2793  *                      FreeULRRCMessageTransfer
2794  *
2795  * @params[in]
2796  *
2797  * @return ROK     - void
2798  *
2799  ******************************************************************/
2800 void FreeULRRCMessageTransfer( F1AP_PDU_t *f1apMsg)
2801 {
2802    uint8_t idx1;
2803    ULRRCMessageTransfer_t  *ulRRCMsg;
2804
2805    if(f1apMsg != NULLP)
2806    { 
2807       if(f1apMsg->choice.initiatingMessage != NULLP)
2808       {
2809          ulRRCMsg = &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2810          if(ulRRCMsg->protocolIEs.list.array != NULLP)
2811          {
2812             for(idx1=0;idx1<ulRRCMsg->protocolIEs.list.count;idx1++)
2813             {
2814                if(ulRRCMsg->protocolIEs.list.array[idx1] != NULLP)
2815                {
2816                   if(ulRRCMsg->protocolIEs.list.array[idx1]->value.present ==
2817                         ULRRCMessageTransferIEs__value_PR_RRCContainer)
2818                   {
2819                      DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2820                            ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2821                   }
2822                   DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1],sizeof(ULRRCMessageTransferIEs_t));
2823                }
2824             }
2825             DU_FREE(ulRRCMsg->protocolIEs.list.array,ulRRCMsg->protocolIEs.list.size );
2826          }
2827          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2828       }
2829       DU_FREE(f1apMsg,sizeof(F1AP_PDU_t));
2830    }
2831 }
2832 /*******************************************************************
2833  *
2834  * @brief Builds and sends the ULRRCMessageTransfer 
2835  *
2836  * @details
2837  *
2838  *    Function : BuildAndSendULRRCMessageTransfer
2839  *
2840  *    Functionality: Constructs the UL RRC Message Transfer and sends
2841  *                   it to the CU through SCTP.
2842  *
2843  * @params[in] 
2844  *
2845  * @return ROK     - success
2846  *         RFAILED - failure
2847  *
2848  * ****************************************************************/
2849 uint8_t BuildAndSendULRRCMessageTransfer(DuUeCb  *ueCb, uint8_t lcId, \
2850       uint16_t msgLen, uint8_t *rrcMsg)
2851 {
2852    uint8_t                 elementCnt=0, idx1=0, idx=0;
2853    uint8_t                 ret = RFAILED;
2854    F1AP_PDU_t              *f1apMsg = NULLP;
2855    ULRRCMessageTransfer_t  *ulRRCMsg = NULLP;
2856    asn_enc_rval_t          encRetVal;        /* Encoder return value */
2857    
2858    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2859
2860    while(true)
2861    {
2862       DU_LOG("\nINFO   -->  F1AP : Building UL RRC Message Transfer Message\n");
2863
2864       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
2865       if(f1apMsg == NULLP)
2866       {
2867          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
2868          break;
2869       }
2870       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
2871       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2872       if(f1apMsg->choice.initiatingMessage == NULLP)
2873       {
2874          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
2875          break;
2876       }
2877       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_ULRRCMessageTransfer;
2878       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
2879       f1apMsg->choice.initiatingMessage->value.present = \
2880                                                          InitiatingMessage__value_PR_ULRRCMessageTransfer;
2881       ulRRCMsg =
2882          &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2883       elementCnt = 4;
2884       ulRRCMsg->protocolIEs.list.count = elementCnt;
2885       ulRRCMsg->protocolIEs.list.size = \
2886                                         elementCnt * sizeof(ULRRCMessageTransferIEs_t *);
2887
2888       /* Initialize the F1Setup members */
2889       DU_ALLOC(ulRRCMsg->protocolIEs.list.array, ulRRCMsg->protocolIEs.list.size);
2890       if(ulRRCMsg->protocolIEs.list.array == NULLP)
2891       {
2892          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UL RRC MessageTransferIEs failed");
2893          break;
2894       }
2895       for(idx=0; idx<elementCnt; idx++)
2896       {
2897          DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx],sizeof(ULRRCMessageTransferIEs_t));
2898          if(ulRRCMsg->protocolIEs.list.array[idx] == NULLP)
2899          {
2900             break;
2901          }
2902       }
2903
2904       idx1 = 0;
2905
2906       /*GNB CU UE F1AP ID*/
2907       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
2908       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2909       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2910                                                               ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
2911       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
2912
2913       /*GNB DU UE F1AP ID*/
2914       idx1++;
2915       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
2916       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2917       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2918                                                               ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
2919       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
2920
2921       /*SRBID*/
2922       idx1++;
2923       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
2924       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2925       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2926                                                               ULRRCMessageTransferIEs__value_PR_SRBID;
2927       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.SRBID = lcId;
2928
2929       /*RRCContainer*/
2930       idx1++;
2931       ulRRCMsg->protocolIEs.list.array[idx1]->id  = ProtocolIE_ID_id_RRCContainer;
2932       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2933       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2934                                                               ULRRCMessageTransferIEs__value_PR_RRCContainer;
2935       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size = msgLen;
2936       DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2937             ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size)
2938       if(!ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf)
2939       {
2940          DU_LOG(" ERROR  -->  F1AP : Memory allocation for BuildAndSendULRRCMessageTransfer failed");
2941          break;
2942       }
2943       memset(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, 0, msgLen);
2944       memcpy(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, \
2945             rrcMsg, ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2946
2947       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
2948
2949       /* Encode the F1SetupRequest type as APER */
2950       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2951       encBufSize = 0;
2952       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
2953             encBuf);
2954       /* Encode results */
2955       if(encRetVal.encoded == ENCODE_FAIL)
2956       {
2957          DU_LOG( "\nERROR  -->  F1AP : Could not encode ULRRCMessageTransfer structure (at %s)\n",\
2958                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2959          break;
2960       }
2961       else
2962       {
2963          DU_LOG("\nDEBUG  -->  F1AP : Created APER encoded buffer for ULRRCMessageTransfer\n");
2964 #ifdef DEBUG_ASN_PRINT
2965          for(int i=0; i< encBufSize; i++)
2966          {
2967             printf("%x",encBuf[i]);
2968          }
2969 #endif
2970       }
2971
2972       /* Sending  msg  */
2973       if(sendF1APMsg()  !=      ROK)
2974       {
2975          DU_LOG("\nERROR  -->   F1AP : Sending  UL RRC Message Transfer Failed");
2976          break;
2977       }
2978       ret = ROK;
2979       break;
2980    }
2981    FreeULRRCMessageTransfer(f1apMsg);
2982
2983    return ret;
2984 }/* End of BuildAndSendULRRCMessageTransfer*/
2985
2986 /*******************************************************************
2987  *
2988  * @brief Builds tag config 
2989  *
2990  * @details
2991  *
2992  *    Function : BuildTagConfig 
2993  *
2994  *    Functionality: Builds tag config in MacCellGroupConfig
2995  *
2996  * @params[in] TAG_Config *tag_Config
2997  *
2998  * @return ROK     - success
2999  *         RFAILED - failure
3000  *
3001  * ****************************************************************/
3002 uint8_t BuildTagConfig(DuUeCb *ueCb, struct TAG_Config *tagConfig)
3003 {
3004    struct TAG_Config__tag_ToAddModList *tagList;
3005    uint8_t                     idx, elementCnt;
3006
3007    tagConfig->tag_ToReleaseList = NULLP;
3008    tagConfig->tag_ToAddModList = NULLP;
3009    DU_ALLOC(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
3010    if(!tagConfig->tag_ToAddModList)
3011    {
3012       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3013       return RFAILED;
3014    }
3015
3016    if(ueCb == NULLP)
3017       elementCnt = ODU_VALUE_ONE;
3018    else
3019       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModListCount;
3020
3021    tagList = tagConfig->tag_ToAddModList;
3022    tagList->list.count = elementCnt;
3023    tagList->list.size  =  elementCnt * sizeof(struct TAG *);
3024
3025    tagList->list.array = NULLP;
3026    DU_ALLOC(tagList->list.array, tagList->list.size);
3027    if(!tagList->list.array)
3028    {
3029       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3030       return RFAILED;
3031    }
3032
3033    for(idx=0; idx<tagList->list.count; idx++)
3034    {
3035       tagList->list.array[idx] = NULLP;
3036       DU_ALLOC(tagList->list.array[idx], sizeof(struct TAG));
3037       if(!tagList->list.array[idx])
3038       {
3039          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3040          return RFAILED;
3041       }
3042    }
3043
3044    if(ueCb == NULLP)
3045    {
3046       idx = 0;
3047       tagList->list.array[idx]->tag_Id = TAG_ID;
3048       tagList->list.array[idx]->timeAlignmentTimer = TIME_ALIGNMENT_TMR;
3049    }
3050    else
3051    {
3052       for(idx=0; idx<tagList->list.count; idx++)
3053       {
3054          tagList->list.array[idx]->tag_Id = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].tagId;
3055          tagList->list.array[idx]->timeAlignmentTimer = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].timeAlignTimer;
3056       }
3057    }
3058
3059    return ROK;
3060 }
3061
3062 /*******************************************************************
3063  *
3064  * @brief Builds PHR Config 
3065  *
3066  * @details
3067  *
3068  *    Function : BuildPhrConfig
3069  *
3070  *    Functionality: Builds phrConfig in MacCellGroupConfig
3071  *
3072  * @params[in] PHR Config *
3073  *
3074  * @return ROK     - success
3075  *         RFAILED - failure
3076  *
3077  * ****************************************************************/
3078 uint8_t BuildPhrConfig(DuUeCb *ueCb, struct MAC_CellGroupConfig__phr_Config *phrConfig)
3079 {
3080
3081    phrConfig->present = MAC_CellGroupConfig__phr_Config_PR_setup;
3082    phrConfig->choice.setup = NULLP;
3083    DU_ALLOC(phrConfig->choice.setup, sizeof(struct PHR_Config));
3084    if(!phrConfig->choice.setup)
3085    {
3086       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhrConfig");
3087       return RFAILED;
3088    }
3089
3090    if(ueCb == NULLP)
3091    {
3092       phrConfig->choice.setup->phr_PeriodicTimer        = PHR_PERIODIC_TMR;
3093       phrConfig->choice.setup->phr_ProhibitTimer        = PHR_PROHIBHIT_TMR;
3094       phrConfig->choice.setup->phr_Tx_PowerFactorChange = PHR_PWR_FACTOR_CHANGE;
3095       phrConfig->choice.setup->multiplePHR              = false;
3096       phrConfig->choice.setup->dummy                    = false;
3097       phrConfig->choice.setup->phr_Type2OtherCell       = false;
3098       phrConfig->choice.setup->phr_ModeOtherCG          = PHR_MODE_OTHER_CG;
3099    }
3100    else
3101    {
3102       phrConfig->choice.setup->phr_PeriodicTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.periodicTimer;
3103       phrConfig->choice.setup->phr_ProhibitTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.prohibitTimer;
3104       phrConfig->choice.setup->phr_Tx_PowerFactorChange = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.txPowerFactor;
3105       phrConfig->choice.setup->multiplePHR              = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.multiplePHR;
3106       phrConfig->choice.setup->dummy                    = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.dummy;
3107       phrConfig->choice.setup->phr_Type2OtherCell       = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrType2OtherCell;
3108       phrConfig->choice.setup->phr_ModeOtherCG          = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrOtherCG;
3109    }
3110
3111    return ROK;
3112 }
3113
3114 /*******************************************************************
3115  *
3116  * @brief Builds BSR Config 
3117  *
3118  * @details
3119  *
3120  *    Function : BuildBsrConfig
3121  *
3122  *    Functionality: Builds BuildBsrConfig in MacCellGroupConfig
3123  *
3124  * @params[in] BSR_Config *bsrConfig
3125  *
3126  * @return ROK     - success
3127  *         RFAILED - failure
3128  *
3129  * ****************************************************************/
3130 uint8_t BuildBsrConfig(DuUeCb *ueCb, struct BSR_Config *bsrConfig)
3131 {
3132    if(ueCb == NULLP)
3133    {
3134       bsrConfig->periodicBSR_Timer = PERIODIC_BSR_TMR;
3135       bsrConfig->retxBSR_Timer     = RETX_BSR_TMR;
3136       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
3137    }
3138    else
3139    {
3140       bsrConfig->periodicBSR_Timer = convertBsrPeriodicTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.periodicTimer);
3141       bsrConfig->retxBSR_Timer     = convertBsrRetxTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.retxTimer);
3142
3143       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
3144       DU_ALLOC(bsrConfig->logicalChannelSR_DelayTimer, sizeof(long));
3145       if(bsrConfig->logicalChannelSR_DelayTimer == NULLP)
3146       {
3147          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildBsrConfig");
3148          return RFAILED;
3149       }
3150       *(bsrConfig->logicalChannelSR_DelayTimer) = convertLcSrDelayTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.srDelayTimer);
3151    }
3152
3153    return ROK;
3154 }
3155
3156 /*******************************************************************
3157  *
3158  * @brief Builds scheduling request config 
3159  *
3160  * @details
3161  *
3162  *    Function : BuildSchedulingReqConfig 
3163  *
3164  *    Functionality: Builds BuildSchedulingReqConfig in MacCellGroupConfig
3165  *
3166  * @params[in] SchedulingRequestConfig *schedulingRequestConfig
3167  *
3168  * @return ROK     - success
3169  *         RFAILED - failure
3170  *
3171  * ****************************************************************/
3172 uint8_t BuildSchedulingReqConfig(DuUeCb *ueCb, struct SchedulingRequestConfig *schedulingRequestConfig)
3173 {
3174    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList;
3175    uint8_t                     idx, elementCnt;
3176
3177    schedulingRequestConfig->schedulingRequestToAddModList = NULLP;
3178    DU_ALLOC(schedulingRequestConfig->schedulingRequestToAddModList,
3179          sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));
3180    if(!schedulingRequestConfig->schedulingRequestToAddModList)
3181    {
3182       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3183       return RFAILED;
3184    }
3185
3186    if(ueCb == NULLP)
3187       elementCnt = ODU_VALUE_ONE;
3188    else
3189       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModListCount;
3190
3191    schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
3192    schReqList->list.count = elementCnt;
3193    schReqList->list.size  = elementCnt * sizeof(struct SchedulingRequestToAddMod *);
3194
3195    schReqList->list.array = NULLP;
3196    DU_ALLOC(schReqList->list.array, schReqList->list.size);
3197    if(!schReqList->list.array)
3198    {
3199       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3200       return RFAILED;
3201    }
3202
3203    for(idx=0; idx<schReqList->list.count; idx++)
3204    {
3205       schReqList->list.array[idx] = NULLP;
3206       DU_ALLOC(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
3207       if(!schReqList->list.array[idx])
3208       {
3209          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3210          return RFAILED;
3211       }
3212    }
3213
3214    if(ueCb == NULLP)
3215    {
3216       idx = 0;
3217       schReqList->list.array[idx]->schedulingRequestId = SCH_REQ_ID;
3218
3219       schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
3220       DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
3221       if(!schReqList->list.array[idx]->sr_ProhibitTimer)
3222       {
3223          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3224          return RFAILED;
3225       }
3226       *(schReqList->list.array[idx]->sr_ProhibitTimer) = SR_PROHIBIT_TMR;
3227       schReqList->list.array[idx]->sr_TransMax = SR_TRANS_MAX;
3228    }
3229    else
3230    {
3231       for(idx=0; idx<schReqList->list.count; idx++)
3232       {
3233          schReqList->list.array[idx]->schedulingRequestId = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].schedReqId;
3234
3235          schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
3236          DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
3237          if(!schReqList->list.array[idx]->sr_ProhibitTimer)
3238          {
3239             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3240             return RFAILED;
3241          }
3242          *(schReqList->list.array[idx]->sr_ProhibitTimer) = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srProhibitTmr;
3243          schReqList->list.array[idx]->sr_TransMax = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srTransMax;
3244       }
3245    }
3246
3247    schedulingRequestConfig->schedulingRequestToReleaseList = NULLP;
3248
3249    return ROK;
3250 }
3251
3252 /*******************************************************************
3253  *
3254  * @brief Builds RLC Configuration for AM mode
3255  *
3256  * @details
3257  *
3258  *    Function : BuildRlcConfigAm
3259  *
3260  *    Functionality: 
3261  *       Builds AM mode RLC Config in BuildRlcBearerToAddModList
3262  *
3263  * @params[in] AmBearerCfg *amCfg
3264  *             RLC_Config_t  *rlcConfig
3265  *
3266  * @return ROK     - success
3267  *         RFAILED - failure
3268  *
3269  * ****************************************************************/
3270 uint8_t BuildRlcConfigAm(AmBearerCfg *amCfg, struct RLC_Config *rlcConfig)
3271 {
3272    rlcConfig->choice.am = NULLP;
3273    DU_ALLOC(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
3274    if(!rlcConfig->choice.am)
3275    {
3276       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3277       return RFAILED;
3278    }
3279
3280    /* Fill AM UL configuration */
3281    rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength = NULLP;
3282    DU_ALLOC(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
3283    if(!rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength)
3284    {
3285       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3286       return RFAILED;
3287    }
3288
3289    /* Fill default AM UL configuration if input pointer to DU database is NULL */
3290    if(amCfg == NULLP)
3291    {
3292       
3293       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = SN_FIELD_LEN_12BIT; /*As per Spec 38.331, "Network configures only value size12 in SN-FieldLengthAM for SRB"*/
3294       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = T_POLL_RETRANSMIT;
3295       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = POLL_PDU;
3296       rlcConfig->choice.am->ul_AM_RLC.pollByte          = POLL_BYTE;
3297       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = MAX_RETX_THRESHOLD;
3298    }
3299    else
3300    {
3301       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->dlAmCfg.snLenDl);
3302       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = covertPollRetxTmrValueToEnum(amCfg->dlAmCfg.pollRetxTmr);
3303       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = covertPollPduValueToEnum(amCfg->dlAmCfg.pollPdu);
3304       rlcConfig->choice.am->ul_AM_RLC.pollByte          = covertPollByteValueToEnum(amCfg->dlAmCfg.pollByte);
3305       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = covertMaxRetxValueToEnum(amCfg->dlAmCfg.maxRetxTh);
3306    }
3307
3308    /* Fill AM DL configuraion */
3309    rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength = NULLP;
3310    DU_ALLOC(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
3311    if(!rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength)
3312    {
3313       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3314       return RFAILED;
3315    }
3316
3317    /* Fill default AM DL configuration if input pointer to DU database is NULL */
3318    if(amCfg == NULLP)
3319    {
3320       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = SN_FIELD_LEN_12BIT; /*As per Spec 38.331, "Network configures only value size12 in SN-FieldLengthAM for SRB"*/
3321       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = T_REASSEMBLY;
3322       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = T_STATUS_PROHIBHIT;
3323    }
3324    else /* Fill AM configuration from DU database */
3325    {
3326       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->ulAmCfg.snLenUl);
3327       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = convertReasmblTmrValueToEnum(amCfg->ulAmCfg.reAssemTmr);
3328       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = convertProhibitTmrValueToEnum(amCfg->ulAmCfg.statProhTmr);
3329    }
3330    return ROK;
3331 }
3332
3333 /*******************************************************************
3334  *
3335  * @brief Builds RLC Config for UM Bidirection
3336  *
3337  * @details
3338  *
3339  *    Function : BuildRlcConfig UmBiDir
3340  *
3341  *    Functionality: 
3342  *       Builds RLC Config for UM Bidirection in BuildRlcBearerToAddModList 
3343  *
3344  * @params[in] UmBiDirBearerCfg *umBiDirCfg
3345  *             RLC_Config_t *rlcConfig
3346  *
3347  * @return ROK     - success
3348  *         RFAILED - failure
3349  *
3350  * ****************************************************************/
3351 uint8_t BuildRlcConfigUmBiDir(UmBiDirBearerCfg *umBiDirCfg, struct RLC_Config *rlcConfig)
3352 {
3353    rlcConfig->choice.um_Bi_Directional = NULLP;
3354    DU_ALLOC(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
3355    if(rlcConfig->choice.um_Bi_Directional == NULLP)
3356    {
3357       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3358       return RFAILED;
3359    }
3360
3361    /* Fill UM Bidirectional UL configuration */
3362    rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength = NULLP;
3363    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3364    if(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength == NULLP)
3365    {
3366       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3367       return RFAILED;
3368    }
3369
3370    if(umBiDirCfg != NULLP)
3371    {
3372       *(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->dlUmCfg.snLenDlUm);     
3373    }
3374
3375    /* Fill UM Bidirectional DL configuration */
3376    rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength = NULLP;
3377    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3378    if(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength == NULLP)
3379    {
3380       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3381       return RFAILED;
3382    }
3383
3384    if(umBiDirCfg != NULLP)
3385    {
3386       *(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->ulUmCfg.snLenUlUm);     
3387       rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umBiDirCfg->ulUmCfg.reAssemTmr);
3388    }
3389
3390    return ROK;
3391 }
3392
3393 /*******************************************************************
3394  *
3395  * @brief Builds RLC Config for UM Uni directional UL
3396  *
3397  * @details
3398  *
3399  *    Function : BuildRlcConfigUmUniDirUl
3400  *
3401  *    Functionality: 
3402  *       Builds RLC Config for UM Unidirection UL in BuildRlcBearerToAddModList 
3403  *
3404  * @params[in] UmUniDirDlBearerCfg *umUniDirDlCfg
3405  *             RLC_Config_t *rlcConfig
3406  *
3407  * @return ROK     - success
3408  *         RFAILED - failure
3409  *
3410  * ****************************************************************/
3411 uint8_t BuildRlcConfigUmUniDirUl(UmUniDirDlBearerCfg *umUniDirDlCfg, RLC_Config_t *rlcConfig)
3412 {
3413    rlcConfig->choice.um_Uni_Directional_UL = NULLP;
3414    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
3415    if(rlcConfig->choice.um_Uni_Directional_UL == NULLP)
3416    {
3417       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3418       return RFAILED;
3419    }
3420
3421    rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength = NULLP;
3422    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3423    if(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength == NULLP)
3424    {
3425       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3426       return RFAILED;
3427    }
3428
3429    if(umUniDirDlCfg != NULLP)
3430    {
3431       *(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirDlCfg->dlUmCfg.snLenDlUm);
3432    }
3433
3434    return ROK;
3435 }
3436
3437 /*******************************************************************
3438  *
3439  * @brief Builds RLC Config for UM Uni directional DL
3440  *
3441  * @details
3442  *
3443  *    Function : BuildRlcConfigUmUniDirDl
3444  *
3445  *    Functionality: 
3446  *       Builds RLC Config for UM Unidirection DL in BuildRlcBearerToAddModList 
3447  *
3448  * @params[in] UmUniDirUlBearerCfg *umUniDirUlCfg
3449  *             RLC_Config_t *rlcConfig
3450  *
3451  * @return ROK     - success
3452  *         RFAILED - failure
3453  *
3454  * ****************************************************************/
3455 uint8_t BuildRlcConfigUmUniDirDl(UmUniDirUlBearerCfg *umUniDirUlCfg, RLC_Config_t *rlcConfig)
3456 {
3457    rlcConfig->choice.um_Uni_Directional_DL = NULLP;
3458    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
3459    if(rlcConfig->choice.um_Uni_Directional_DL == NULLP)
3460    {
3461       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3462       return RFAILED;
3463    }
3464
3465    rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength = NULLP;
3466    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3467    if(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength == NULLP)
3468    {
3469       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3470       return RFAILED;
3471    }
3472
3473    if(umUniDirUlCfg != NULLP)
3474    {
3475       *(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirUlCfg->ulUmCfg.snLenUlUm);
3476       rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umUniDirUlCfg->ulUmCfg.reAssemTmr);
3477    }
3478
3479    return ROK;
3480 }
3481
3482 /*******************************************************************
3483  *
3484  * @brief Builds RLC Config
3485  *
3486  * @details
3487  *
3488  *    Function : BuildRlcConfig
3489  *
3490  *    Functionality: Builds RLC Config in BuildRlcBearerToAddModList 
3491  *
3492  * @params[in] RLC_Config_t *rlcConfig
3493  *
3494  * @return ROK     - success
3495  *         RFAILED - failure
3496  *
3497  * ****************************************************************/
3498 uint8_t BuildRlcConfig(RlcBearerCfg *rbCfg, struct RLC_Config *rlcConfig)
3499 {
3500    
3501    /* Fill default values if rbCfg is NULL */
3502    if(rbCfg == NULLP)
3503    {
3504       rlcConfig->present = RLC_Config_PR_am;
3505       BuildRlcConfigAm(NULLP, rlcConfig);
3506    }
3507    /* If RbCfg is present, fill RLC configurations from DU Database */
3508    else
3509    {
3510       rlcConfig->present = covertRlcModeFromIntEnumToRrcEnum(rbCfg->rlcMode);
3511       switch(rlcConfig->present)
3512       {
3513          case RLC_Config_PR_am:
3514             BuildRlcConfigAm(rbCfg->u.amCfg, rlcConfig);
3515             break;
3516          case RLC_Config_PR_um_Bi_Directional:
3517             BuildRlcConfigUmBiDir(rbCfg->u.umBiDirCfg, rlcConfig);
3518             break;
3519          case RLC_Config_PR_um_Uni_Directional_UL:
3520             BuildRlcConfigUmUniDirUl(rbCfg->u.umUniDirDlCfg, rlcConfig);
3521             break;
3522          case RLC_Config_PR_um_Uni_Directional_DL:
3523             BuildRlcConfigUmUniDirDl(rbCfg->u.umUniDirUlCfg, rlcConfig);
3524             break;
3525          case RLC_Config_PR_NOTHING:
3526          default:
3527             break;
3528       }
3529    }
3530
3531    return ROK;
3532 }
3533
3534 /*******************************************************************
3535  *
3536  * @brief Builds MAC LC Config
3537  *
3538  * @details
3539  *
3540  *    Function : BuildMacLCConfig 
3541  *
3542  *    Functionality: Builds MAC LC Config in BuildRlcBearerToAddModList 
3543  *
3544  * @params[in] struct LogicalChannelConfig macLcConfig
3545  *
3546  * @return ROK     - success
3547  *         RFAILED - failure
3548  *
3549  * ****************************************************************/
3550 uint8_t BuildMacLCConfig(LcCfg *lcCfgDb, struct LogicalChannelConfig *macLcConfig)
3551 {
3552    macLcConfig->ul_SpecificParameters = NULLP;
3553    DU_ALLOC(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
3554    if(!macLcConfig->ul_SpecificParameters)
3555    {
3556       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3557       return RFAILED;
3558    }
3559
3560    if(lcCfgDb == NULLP)
3561    {
3562       macLcConfig->ul_SpecificParameters->priority = MAC_LC_PRIORITY;
3563       macLcConfig->ul_SpecificParameters->prioritisedBitRate =  PRIORTISIED_BIT_RATE;
3564       macLcConfig->ul_SpecificParameters->bucketSizeDuration =  BUCKET_SIZE_DURATION;
3565    }
3566    else
3567    {
3568       macLcConfig->ul_SpecificParameters->priority = lcCfgDb->ulLcCfg.priority;
3569       macLcConfig->ul_SpecificParameters->prioritisedBitRate = lcCfgDb->ulLcCfg.pbr;
3570       macLcConfig->ul_SpecificParameters->bucketSizeDuration = lcCfgDb->ulLcCfg.bsd;
3571    }
3572
3573    macLcConfig->ul_SpecificParameters->allowedServingCells = NULLP;
3574    macLcConfig->ul_SpecificParameters->allowedSCS_List = NULLP;
3575    macLcConfig->ul_SpecificParameters->maxPUSCH_Duration = NULLP;
3576    macLcConfig->ul_SpecificParameters->configuredGrantType1Allowed = NULLP;
3577
3578    macLcConfig->ul_SpecificParameters->logicalChannelGroup = NULLP;
3579    DU_ALLOC(macLcConfig->ul_SpecificParameters->logicalChannelGroup,    sizeof(long));
3580    if(!macLcConfig->ul_SpecificParameters->logicalChannelGroup)
3581    {
3582       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3583       return RFAILED;
3584    }
3585
3586    if(lcCfgDb == NULLP)
3587       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = LC_GRP;
3588    else
3589       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = lcCfgDb->ulLcCfg.lcGroup;
3590
3591    macLcConfig->ul_SpecificParameters->schedulingRequestID = NULLP;
3592    DU_ALLOC(macLcConfig->ul_SpecificParameters->schedulingRequestID,    sizeof(SchedulingRequestId_t));
3593    if(!macLcConfig->ul_SpecificParameters->schedulingRequestID)
3594    {
3595       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3596       return RFAILED;
3597    }
3598
3599    if(lcCfgDb == NULLP)
3600       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = SCH_REQ_ID;
3601    else
3602       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = lcCfgDb->ulLcCfg.schReqId;
3603
3604    macLcConfig->ul_SpecificParameters->logicalChannelSR_Mask = false;
3605    macLcConfig->ul_SpecificParameters->logicalChannelSR_DelayTimerApplied = false;
3606    macLcConfig->ul_SpecificParameters->bitRateQueryProhibitTimer = NULLP;
3607
3608    return ROK;
3609 }
3610
3611 /*******************************************************************
3612  *
3613  * @brief Builds RLC Bearer to Add/Mod list
3614  *
3615  * @details
3616  *
3617  *    Function :BuildRlcBearerToAddModList 
3618  *
3619  *    Functionality: Builds RLC Bearer to Add/Mod list in DuToCuRrcContainer
3620  *
3621  * @params[in] rlc_BearerToAddModList
3622  *
3623  * @return ROK     - success
3624  *         RFAILED - failure
3625  *
3626  * ****************************************************************/
3627 uint8_t BuildRlcBearerToAddModList(DuUeCb *ueCb, struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList)
3628 {
3629    uint8_t  idx = 0, lcIdx=0, macLcIdx = 0, elementCnt = 0;
3630
3631    if(ueCb == NULLP)
3632       elementCnt = 1;
3633    else if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
3634       elementCnt = ueCb->duRlcUeCfg.numLcs;
3635    else
3636    {
3637       for(lcIdx = 0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3638       {
3639          if(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == false)
3640             elementCnt++;
3641       }
3642    }
3643    rlcBearerList->list.count = elementCnt;
3644    rlcBearerList->list.size  = elementCnt * sizeof(struct RLC_BearerConfig *);
3645
3646    rlcBearerList->list.array = NULLP;
3647    DU_ALLOC(rlcBearerList->list.array, rlcBearerList->list.size);
3648    if(!rlcBearerList->list.array)
3649    {
3650       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3651       return RFAILED;
3652    }
3653
3654    for(idx=0; idx<rlcBearerList->list.count; idx++)
3655    {
3656       rlcBearerList->list.array[idx] = NULLP;
3657       DU_ALLOC(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
3658       if(!rlcBearerList->list.array[idx])
3659       {
3660          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3661          return RFAILED;
3662       }
3663    }
3664
3665    if(ueCb == NULLP)
3666    {
3667       idx=0;
3668       rlcBearerList->list.array[idx]->logicalChannelIdentity = SRB1_LCID;
3669       DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3670       if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3671       {     
3672          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3673          return RFAILED;
3674       }     
3675       rlcBearerList->list.array[idx]->servedRadioBearer->present = RLC_BearerConfig__servedRadioBearer_PR_srb_Identity;
3676       rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = SRB1_LCID;
3677       rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3678
3679       /* Fill RLC related Configurations for this Radio Bearer */
3680       rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3681       DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3682       if(!rlcBearerList->list.array[idx]->rlc_Config)
3683       {
3684          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3685          return RFAILED;
3686       }
3687       if(BuildRlcConfig(NULLP, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3688       {
3689          DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3690          return RFAILED;
3691       }
3692
3693       /* Fill MAC related configurations for this Radio Bearer */
3694       rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3695       DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3696       if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3697       {
3698          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3699          return RFAILED;
3700       }
3701       if(BuildMacLCConfig(NULLP, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3702       {
3703          DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3704          return RFAILED;
3705       }
3706    }
3707    else
3708    {
3709       idx=0;
3710       for(lcIdx=0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3711       {
3712          if((ueCb->f1UeDb->actionType != UE_CTXT_CFG_QUERY) && (ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == true))
3713             continue;
3714
3715          /* Fill Logical channel identity */
3716          rlcBearerList->list.array[idx]->logicalChannelIdentity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId;
3717
3718          /* Fill Radio Bearer Id and type (DRB/SRB) for this logical channel */
3719          DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3720          if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3721          {
3722             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3723             return RFAILED;
3724          }
3725          rlcBearerList->list.array[idx]->servedRadioBearer->present = \
3726                                                                       covertRbTypeFromIntEnumToRrcEnum(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbType);
3727          switch(rlcBearerList->list.array[idx]->servedRadioBearer->present)
3728          {
3729             case RLC_BearerConfig__servedRadioBearer_PR_srb_Identity: 
3730                rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3731                break;
3732             case RLC_BearerConfig__servedRadioBearer_PR_drb_Identity:
3733                rlcBearerList->list.array[idx]->servedRadioBearer->choice.drb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3734                break;
3735             case RLC_BearerConfig__servedRadioBearer_PR_NOTHING:
3736             default:
3737                break;
3738          }
3739          ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent = true;
3740
3741          rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3742
3743          /* Fill RLC related Configurations for this Radio Bearer */
3744          rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3745          DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3746          if(!rlcBearerList->list.array[idx]->rlc_Config)
3747          {
3748             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3749             return RFAILED;
3750          }
3751          if(BuildRlcConfig(&ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3752          {
3753             DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3754             return RFAILED;
3755          }
3756
3757          /* Fill MAC related configurations for this Radio Bearer */
3758          rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3759          DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3760          if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3761          {
3762             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3763             return RFAILED;
3764          }
3765          for(macLcIdx = 0; macLcIdx < ueCb->duMacUeCfg.numLcs; macLcIdx++)
3766          {
3767             if(ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig.lcId == ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId)
3768             {
3769                if(BuildMacLCConfig(&ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3770                {
3771                   DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3772                   return RFAILED;
3773                }
3774                break;
3775             }
3776          }
3777
3778          idx++;
3779       }
3780    }
3781    return ROK;
3782 }
3783
3784 /*******************************************************************
3785  *
3786  * @brief Build Control resource set to add/modify list 
3787  *
3788  * @details
3789  *
3790  *    Function : BuildControlRSetToAddModList
3791  *
3792  *    Functionality: Build Control resource set to add/modify list
3793  *
3794  * @params[in] 
3795  * struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList
3796  *
3797  * @return ROK     - success
3798  *         RFAILED - failure
3799  *
3800  * ****************************************************************/
3801 uint8_t BuildControlRSetToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList)
3802 {
3803    uint8_t idx;
3804    uint8_t elementCnt;
3805    uint8_t numBytes, bitsUnused;
3806    struct ControlResourceSet *controlRSet;
3807    uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
3808    uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
3809
3810    if(pdcchCfg == NULLP)
3811       elementCnt = 1;
3812    else
3813       elementCnt = pdcchCfg->numCRsetToAddMod;
3814
3815    controlRSetList->list.count = elementCnt;
3816    controlRSetList->list.size = elementCnt * sizeof(struct ControlResourceSet *);
3817
3818    controlRSetList->list.array = NULLP;
3819    DU_ALLOC(controlRSetList->list.array, controlRSetList->list.size);
3820    if(!controlRSetList->list.array)
3821    {
3822       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3823       return RFAILED;
3824    }
3825
3826    for(idx = 0; idx < elementCnt; idx++)
3827    {
3828       controlRSetList->list.array[idx] = NULLP;
3829       DU_ALLOC(controlRSetList->list.array[idx], sizeof(struct ControlResourceSet));
3830       if(!controlRSetList->list.array[idx])
3831       {
3832          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3833          return RFAILED;
3834       }
3835    }
3836
3837    for(idx = 0; idx < elementCnt; idx++)
3838    {
3839       controlRSet = controlRSetList->list.array[idx];
3840
3841       if(pdcchCfg == NULLP)
3842          controlRSet->controlResourceSetId = PDCCH_CTRL_RSRC_SET_ONE_ID;
3843       else
3844          controlRSet->controlResourceSetId = pdcchCfg->cRSetToAddModList[idx].cRSetId;
3845
3846       /* size 6 bytes
3847        * 3 LSBs unsued
3848        * Bit string stored ff0000000000
3849        */
3850       numBytes = 6;
3851       bitsUnused = 3;
3852       controlRSet->frequencyDomainResources.size = numBytes * sizeof(uint8_t);
3853
3854       controlRSet->frequencyDomainResources.buf = NULLP;
3855       DU_ALLOC(controlRSet->frequencyDomainResources.buf, controlRSet->frequencyDomainResources.size);
3856       if(!controlRSet->frequencyDomainResources.buf)
3857       {
3858          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3859          return RFAILED;
3860       }
3861
3862       memset(controlRSet->frequencyDomainResources.buf, 0, FREQ_DOM_RSRC_SIZE);
3863
3864       if(pdcchCfg == NULLP)
3865       {
3866          coreset0EndPrb = CORESET0_END_PRB;
3867          coreset1StartPrb = coreset0EndPrb + 6;
3868          coreset1NumPrb = CORESET1_NUM_PRB;
3869          /* calculate the PRBs */
3870          fillCoresetFeqDomAllocMap(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
3871          memcpy(controlRSet->frequencyDomainResources.buf, freqDomainResource, FREQ_DOM_RSRC_SIZE);
3872          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3873
3874          controlRSet->duration = PDCCH_CTRL_RSRC_SET_ONE_DURATION;
3875          controlRSet->cce_REG_MappingType.present = ControlResourceSet__cce_REG_MappingType_PR_nonInterleaved;
3876          controlRSet->precoderGranularity = PDCCH_CTRL_RSRC_SET_ONE_PRECOD_GRANULARITY;
3877       }
3878       else
3879       {
3880          memcpy(controlRSet->frequencyDomainResources.buf, pdcchCfg->cRSetToAddModList[idx].freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
3881          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3882          controlRSet->duration = pdcchCfg->cRSetToAddModList[idx].duration;
3883          controlRSet->cce_REG_MappingType.present = pdcchCfg->cRSetToAddModList[idx].cceRegMappingType;
3884          controlRSet->precoderGranularity = pdcchCfg->cRSetToAddModList[idx].precoderGranularity;
3885       }
3886       controlRSet->tci_StatesPDCCH_ToAddList = NULLP;
3887       controlRSet->tci_StatesPDCCH_ToReleaseList = NULLP;
3888       controlRSet->tci_PresentInDCI = NULLP;
3889
3890 #if 0
3891       uint8_t tciStateIdx;
3892
3893       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList, \
3894             sizeof(struct ControlResourceSet__tci_StatesPDCCH_ToAddList));
3895       if(!controlRset->tci_StatesPDCCH_ToAddList)
3896       {
3897          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3898          return RFAILED;
3899       }
3900
3901       elementCnt = 1;
3902       controlRset->tci_StatesPDCCH_ToAddList->list.count = elementCnt;
3903       controlRset->tci_StatesPDCCH_ToAddList->list.size = elementCnt * sizeof(TCI_StateId_t *);
3904       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array, \
3905             controlRset->tci_StatesPDCCH_ToAddList->list.size)
3906          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array)
3907          {
3908             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3909             return RFAILED;
3910          }
3911
3912       for(tciStateIdx = 0; tciStateIdx <elementCntl; tciStateIdx++)
3913       {
3914          DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx], sizeof(TCI_StateId_t));
3915          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx])
3916          {
3917             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3918             return RFAILED;
3919          }
3920       }
3921
3922       tciStateIdx = 0;
3923       /* TODO */
3924       *(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx]);
3925
3926       DU_ALLOC(controlRset->tci_PresentInDCI, sizeof(long));
3927       if(!controlRset->tci_PresentInDCI)
3928       {
3929          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3930          return RFAILED;
3931       }
3932       /* TODO */
3933       *(controlRset->tci_PresentInDCI);
3934 #endif
3935
3936       controlRSet->pdcch_DMRS_ScramblingID = NULLP;
3937       DU_ALLOC(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
3938       if(!controlRSet->pdcch_DMRS_ScramblingID)
3939       {
3940          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3941          return RFAILED;
3942       }
3943       if(pdcchCfg == NULLP)
3944          *(controlRSet->pdcch_DMRS_ScramblingID) = SCRAMBLING_ID;
3945       else
3946          *(controlRSet->pdcch_DMRS_ScramblingID) = pdcchCfg->cRSetToAddModList[idx].dmrsScramblingId;
3947    }
3948    return ROK;
3949 } /* End BuildControlRSetToAddModList */
3950
3951 /*******************************************************************
3952  *
3953  * @brief Build search space to add/modify list
3954  *
3955  * @details
3956  *
3957  *    Function : BuildSearchSpcToAddModList
3958  *
3959  *    Functionality: Build search space to add/modify list
3960  *
3961  * @params[in] 
3962  * @return ROK     - success
3963  *         RFAILED - failure
3964  *
3965  * ****************************************************************/
3966 uint8_t BuildSearchSpcToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
3967 {
3968    uint8_t idx;
3969    uint8_t numBytes;
3970    uint8_t byteIdx;
3971    uint8_t bitsUnused;
3972    uint8_t elementCnt;
3973    struct SearchSpace *searchSpc;
3974
3975    if(pdcchCfg == NULLP)
3976       elementCnt = 1;
3977    else
3978       elementCnt = pdcchCfg->numSearchSpcToAddMod;
3979
3980    searchSpcList->list.count = elementCnt;
3981    searchSpcList->list.size = elementCnt * sizeof(struct SearchSpace *);
3982
3983    searchSpcList->list.array = NULLP;
3984    DU_ALLOC(searchSpcList->list.array, searchSpcList->list.size);
3985    if(!searchSpcList->list.array)
3986    {
3987       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3988       return RFAILED;
3989    }
3990
3991    for(idx = 0; idx < elementCnt; idx++)
3992    {
3993       searchSpcList->list.array[idx] = NULLP;
3994       DU_ALLOC(searchSpcList->list.array[idx], sizeof(struct SearchSpace));
3995       if(!searchSpcList->list.array[idx])
3996       {
3997          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3998          return RFAILED;
3999       }
4000    }
4001
4002    for(idx = 0; idx < elementCnt; idx++)
4003    {
4004       searchSpc = searchSpcList->list.array[idx];
4005
4006       if(pdcchCfg == NULLP)
4007          searchSpc->searchSpaceId = PDCCH_SRCH_SPC_TWO_ID;
4008       else
4009          searchSpc->searchSpaceId = pdcchCfg->searchSpcToAddModList[idx].searchSpaceId;
4010
4011       searchSpc->controlResourceSetId = NULLP;
4012       DU_ALLOC(searchSpc->controlResourceSetId, sizeof(ControlResourceSetId_t));
4013       if(!searchSpc->controlResourceSetId)
4014       {
4015          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4016          return RFAILED;
4017       }
4018       if(pdcchCfg == NULLP)
4019          *(searchSpc->controlResourceSetId) = PDCCH_CTRL_RSRC_SET_ONE_ID;
4020       else
4021          *(searchSpc->controlResourceSetId) = pdcchCfg->searchSpcToAddModList[idx].cRSetId;
4022
4023       searchSpc->monitoringSlotPeriodicityAndOffset = NULLP;
4024       DU_ALLOC(searchSpc->monitoringSlotPeriodicityAndOffset, sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
4025       if(!searchSpc->monitoringSlotPeriodicityAndOffset)
4026       {
4027          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4028          return RFAILED;
4029       }
4030       if(pdcchCfg == NULLP)
4031          searchSpc->monitoringSlotPeriodicityAndOffset->present = SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
4032       else
4033          searchSpc->monitoringSlotPeriodicityAndOffset->present = pdcchCfg->searchSpcToAddModList[idx].mSlotPeriodicityAndOffset;
4034
4035       searchSpc->duration = NULLP;
4036       searchSpc->monitoringSymbolsWithinSlot = NULLP;
4037       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot, sizeof(BIT_STRING_t));
4038       if(!searchSpc->monitoringSymbolsWithinSlot)
4039       {
4040          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4041          return RFAILED;
4042       }
4043
4044       /* Values taken from reference logs :
4045        * size 2 bytes
4046        * 2 LSBs unsued
4047        * Bit string stores 8000
4048        */
4049       numBytes = 2;
4050       bitsUnused = 2;
4051       searchSpc->monitoringSymbolsWithinSlot->size = numBytes * sizeof(uint8_t);
4052       searchSpc->monitoringSymbolsWithinSlot->buf = NULLP;
4053       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot->buf, searchSpc->monitoringSymbolsWithinSlot->size);
4054       if(!searchSpc->monitoringSymbolsWithinSlot->buf)
4055       {
4056          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4057          return RFAILED;
4058       }
4059       if(pdcchCfg == NULLP)
4060       {
4061          byteIdx = 0;
4062          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = PDCCH_SYMBOL_WITHIN_SLOT /* setting MSB to 128 i.e. 0x80 */;
4063          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = 0;
4064       }
4065       else
4066          memcpy(searchSpc->monitoringSymbolsWithinSlot->buf, pdcchCfg->searchSpcToAddModList[idx].mSymbolsWithinSlot, numBytes);
4067       searchSpc->monitoringSymbolsWithinSlot->bits_unused = bitsUnused;
4068
4069       searchSpc->nrofCandidates = NULLP;
4070       DU_ALLOC(searchSpc->nrofCandidates, sizeof(struct SearchSpace__nrofCandidates));
4071       if(!searchSpc->nrofCandidates)
4072       {
4073          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4074          return RFAILED;
4075       }
4076
4077       if(pdcchCfg == NULLP)
4078       {
4079          searchSpc->nrofCandidates->aggregationLevel1 = PDCCH_SRCH_SPC_TWO_AGG_LVL1_CANDIDATE;
4080          searchSpc->nrofCandidates->aggregationLevel2 = PDCCH_SRCH_SPC_TWO_AGG_LVL2_CANDIDATE;
4081          searchSpc->nrofCandidates->aggregationLevel4 = PDCCH_SRCH_SPC_TWO_AGG_LVL4_CANDIDATE;
4082          searchSpc->nrofCandidates->aggregationLevel8 = PDCCH_SRCH_SPC_TWO_AGG_LVL8_CANDIDATE;
4083          searchSpc->nrofCandidates->aggregationLevel16 = PDCCH_SRCH_SPC_TWO_AGG_LVL16_CANDIDATE;
4084       }
4085       else
4086       {
4087          searchSpc->nrofCandidates->aggregationLevel1 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel1;
4088          searchSpc->nrofCandidates->aggregationLevel2 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel2;
4089          searchSpc->nrofCandidates->aggregationLevel4 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel4;
4090          searchSpc->nrofCandidates->aggregationLevel8 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel8;
4091          searchSpc->nrofCandidates->aggregationLevel16 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel16;
4092       }
4093
4094       searchSpc->searchSpaceType = NULLP;
4095       DU_ALLOC(searchSpc->searchSpaceType, sizeof(struct SearchSpace__searchSpaceType));
4096       if(!searchSpc->searchSpaceType)
4097       {
4098          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4099          return RFAILED;
4100       }
4101       if(pdcchCfg == NULLP)
4102          searchSpc->searchSpaceType->present = SearchSpace__searchSpaceType_PR_ue_Specific;
4103       else
4104          searchSpc->searchSpaceType->present = pdcchCfg->searchSpcToAddModList[idx].searchSpaceType;
4105
4106       searchSpc->searchSpaceType->choice.ue_Specific = NULLP;
4107       DU_ALLOC(searchSpc->searchSpaceType->choice.ue_Specific, sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
4108       if(!searchSpc->searchSpaceType->choice.ue_Specific)
4109       {
4110          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4111          return RFAILED;
4112       }  
4113       if(pdcchCfg == NULLP)
4114          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
4115       else
4116          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = pdcchCfg->searchSpcToAddModList[idx].ueSpecificDciFormat;
4117    }
4118    return ROK;
4119 }/* End BuildSearchSpcToAddModList */
4120
4121 /*******************************************************************
4122  *
4123  * @brief Builds BWP DL dedicated PDCCH config
4124  *
4125  * @details
4126  *
4127  *    Function : BuildBWPDlDedPdcchCfg
4128  *
4129  *    Functionality: Builds BWP DL dedicated PDCCH config
4130  *
4131  * @params[in] struct PDCCH_Config *pdcchCfg
4132  *
4133  * @return ROK     - success
4134  *         RFAILED - failure
4135  *
4136  * ****************************************************************/
4137 uint8_t BuildBWPDlDedPdcchCfg(PdcchConfig *pdcchCfgDb, struct PDCCH_Config *pdcchCfg)
4138 {
4139    pdcchCfg->controlResourceSetToAddModList = NULLP;
4140    DU_ALLOC(pdcchCfg->controlResourceSetToAddModList, sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
4141    if(!pdcchCfg->controlResourceSetToAddModList)
4142    {
4143       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
4144       return RFAILED;
4145    }
4146
4147    if(BuildControlRSetToAddModList(pdcchCfgDb, pdcchCfg->controlResourceSetToAddModList) != ROK)
4148    {
4149       DU_LOG("\nERROR  --> F1AP : Failed in BuildControlRSetToAddModList()");
4150       return RFAILED;
4151    }
4152
4153    pdcchCfg->controlResourceSetToReleaseList = NULLP;
4154
4155    pdcchCfg->searchSpacesToAddModList = NULLP;
4156    DU_ALLOC(pdcchCfg->searchSpacesToAddModList, sizeof(struct PDCCH_Config__searchSpacesToAddModList));
4157    if(!pdcchCfg->searchSpacesToAddModList)
4158    {
4159       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
4160       return RFAILED;
4161    }
4162
4163    if(BuildSearchSpcToAddModList(pdcchCfgDb, pdcchCfg->searchSpacesToAddModList) != ROK)
4164    {
4165       DU_LOG("\nERROR  --> F1AP : Failed in BuildSearchSpcToAddModList()");
4166       return RFAILED;
4167    }
4168
4169    pdcchCfg->searchSpacesToReleaseList = NULLP;
4170    pdcchCfg->downlinkPreemption = NULLP;
4171    pdcchCfg->tpc_PUSCH = NULLP;
4172    pdcchCfg->tpc_PUCCH = NULLP;
4173    pdcchCfg->tpc_SRS = NULLP;
4174
4175    return ROK;
4176 }
4177
4178 /*******************************************************************
4179  *
4180  * @brief Builds DMRS DL PDSCH Mapping type A
4181  *
4182  * @details
4183  *
4184  *    Function : BuildDMRSDLPdschMapTypeA
4185  *
4186  *    Functionality: Builds DMRS DL PDSCH Mapping type A
4187  *
4188  * @params[in]
4189  * struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg
4190  * @return ROK     - success
4191  *         RFAILED - failure
4192  *
4193  * ****************************************************************/
4194 uint8_t BuildDMRSDLPdschMapTypeA(PdschConfig *pdschCfg, struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg)
4195 {
4196    dmrsDlCfg->present = PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup;
4197    dmrsDlCfg->choice.setup = NULLP;
4198    DU_ALLOC(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
4199    if(!dmrsDlCfg->choice.setup)
4200    {
4201       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
4202       return RFAILED;
4203    }
4204
4205    dmrsDlCfg->choice.setup->dmrs_Type = NULLP;
4206    dmrsDlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4207    DU_ALLOC(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4208    if(!dmrsDlCfg->choice.setup->dmrs_AdditionalPosition)
4209    {
4210       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
4211       return RFAILED;
4212    }
4213    if(pdschCfg == NULLP)
4214       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS;
4215    else
4216       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = pdschCfg->dmrsDlCfgForPdschMapTypeA.addPos;
4217
4218    dmrsDlCfg->choice.setup->maxLength = NULLP;
4219    dmrsDlCfg->choice.setup->scramblingID0 = NULLP;
4220    dmrsDlCfg->choice.setup->scramblingID1 = NULLP;
4221    dmrsDlCfg->choice.setup->phaseTrackingRS = NULLP;
4222
4223    return ROK;
4224 }
4225
4226 /*******************************************************************
4227  *
4228  * @brief Builds TCI states to add/modify list
4229  *
4230  * @details
4231  *
4232  *    Function : BuildTCIStatesToAddModList
4233  *
4234  *    Functionality:Builds TCI states to add/modify list
4235  *
4236  * @params[in] 
4237  * struct PDSCH_Config__tci_StatesToAddModList *tciStatesList
4238  *
4239  * @return ROK     - success
4240  *         RFAILED - failure
4241  *
4242  * ****************************************************************/
4243 uint8_t BuildTCIStatesToAddModList(struct PDSCH_Config__tci_StatesToAddModList *tciStatesList)
4244 {
4245    return ROK;
4246 }
4247
4248 /*******************************************************************
4249  *
4250  * @brief Builds PDSCH time domain allocation list
4251  *
4252  * @details
4253  *
4254  *    Function : BuildPdschTimeDomAllocList
4255  *
4256  *    Functionality: Builds PDSCH time domain allocation list
4257  *
4258  * @params[in] 
4259  * struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
4260  *
4261  * @return ROK     - success
4262  *         RFAILED - failure
4263  *
4264  * ****************************************************************/
4265 uint8_t BuildPdschTimeDomAllocList(PdschConfig *pdschCfg, struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
4266 {
4267    uint8_t idx;
4268    uint8_t elementCnt;
4269    struct PDSCH_TimeDomainResourceAllocation *timeDomAlloc;
4270
4271    timeDomAllocList->present = PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup;
4272
4273    timeDomAllocList->choice.setup = NULLP;
4274    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PDSCH_TimeDomainResourceAllocationList));
4275    if(!timeDomAllocList->choice.setup)
4276    {
4277       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4278       return RFAILED;
4279    }
4280
4281 if(pdschCfg == NULLP)
4282    elementCnt = 2;
4283 else
4284 elementCnt = pdschCfg->numTimeDomRsrcAlloc;
4285    timeDomAllocList->choice.setup->list.count = elementCnt;
4286    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(struct PDSCH_TimeDomainResourceAllocation *);
4287
4288    timeDomAllocList->choice.setup->list.array = NULLP;
4289    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4290    if(!timeDomAllocList->choice.setup->list.array)
4291    {
4292       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4293       return RFAILED;
4294    }
4295
4296    for(idx = 0; idx < elementCnt; idx++)
4297    {
4298       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4299       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], \
4300             sizeof(struct PDSCH_TimeDomainResourceAllocation));
4301       if(!timeDomAllocList->choice.setup->list.array[idx])
4302       {
4303          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4304          return RFAILED;
4305       }
4306    }
4307
4308    if(pdschCfg == NULLP)
4309    {
4310       idx = 0;
4311       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4312       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4313       if(!timeDomAlloc->k0)
4314       {
4315          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4316          return RFAILED;
4317       }
4318       *(timeDomAlloc->k0) = 0;
4319       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4320       timeDomAlloc->startSymbolAndLength = \
4321                                            calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4322
4323       idx++;
4324       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4325       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4326       if(!timeDomAlloc->k0)
4327       {
4328          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4329          return RFAILED;
4330       }
4331       *(timeDomAlloc->k0) = 1;
4332       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4333       timeDomAlloc->startSymbolAndLength = calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4334    }
4335    else
4336    {
4337       for(idx = 0; idx < elementCnt; idx++)
4338       {
4339          timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4340          if(pdschCfg->timeDomRsrcAllociList[idx].k0)
4341          {
4342             DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4343             if(!timeDomAlloc->k0)
4344             {
4345                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4346                return RFAILED;
4347             }
4348             *(timeDomAlloc->k0) = *(pdschCfg->timeDomRsrcAllociList[idx].k0);
4349          }
4350          timeDomAlloc->mappingType = pdschCfg->timeDomRsrcAllociList[idx].mappingType;
4351          timeDomAlloc->startSymbolAndLength = pdschCfg->timeDomRsrcAllociList[idx].startSymbolAndLength;
4352       }
4353    }
4354
4355    return ROK;
4356 }
4357
4358 /*******************************************************************
4359  *
4360  * @brief Builds PDSCH PRB Bundling type
4361  *
4362  * @details
4363  *
4364  *    Function : BuildPdschPrbBundlingType
4365  *
4366  *    Functionality: Builds PDSCH PRB Bundling type
4367  *
4368  * @params[in] 
4369  * struct PDSCH_Config__prb_BundlingType *prbBndlType
4370  *
4371  * @return ROK     - success
4372  *         RFAILED - failure
4373  *
4374  * ****************************************************************/
4375 uint8_t BuildPdschPrbBundlingType(PdschConfig *pdschCfg, struct PDSCH_Config__prb_BundlingType *prbBndlType)
4376 {
4377    if(pdschCfg == NULLP)
4378       prbBndlType->present = PDSCH_Config__prb_BundlingType_PR_staticBundling;
4379    else
4380       prbBndlType->present = pdschCfg->bundlingType;
4381
4382    prbBndlType->choice.staticBundling = NULLP;
4383    DU_ALLOC(prbBndlType->choice.staticBundling, \
4384          sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
4385    if(!prbBndlType->choice.staticBundling)
4386    {
4387       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschPrbBundlingType");
4388       return RFAILED;
4389    }
4390    prbBndlType->choice.staticBundling->bundleSize = NULLP;
4391
4392    return ROK;
4393 }
4394
4395 /*******************************************************************
4396  *
4397  * @brief Builds BWP DL dedicated PDSCH config 
4398  *
4399  * @details
4400  *
4401  *    Function : BuildBWPDlDedPdschCfg
4402  *
4403  *    Functionality: Builds BWP DL dedicated PDSCH config
4404  *
4405  * @params[in] struct PDSCH_Config *pdschCfg
4406  *
4407  * @return ROK     - success
4408  *         RFAILED - failure
4409  *
4410  * ****************************************************************/
4411 uint8_t BuildBWPDlDedPdschCfg(PdschConfig *pdschCfgDb, struct PDSCH_Config *pdschCfg)
4412 {
4413    pdschCfg->dataScramblingIdentityPDSCH = NULLP;
4414
4415    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA = NULLP;
4416    DU_ALLOC(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
4417    if(!pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
4418    {
4419       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4420       return RFAILED;
4421    }
4422
4423    if(BuildDMRSDLPdschMapTypeA(pdschCfgDb, pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA) != ROK)
4424    {
4425       return RFAILED;
4426    }
4427
4428    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeB = NULLP;
4429    pdschCfg->tci_StatesToAddModList = NULLP;
4430    pdschCfg->tci_StatesToReleaseList = NULLP;
4431    pdschCfg->vrb_ToPRB_Interleaver = NULLP;
4432 #if 0
4433    DU_ALLOC(pdschCfg->tci_StatesToAddModList, sizeof(struct PDSCH_Config__tci_StatesToAddModList));
4434    if(!pdschCfg->tci_StatesToAddModList)
4435    {
4436       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4437       return RFAILED;
4438    }
4439    if(BuildTCIStatesToAddModList(pdschCfg->tci_StatesToAddModList) != ROK)
4440    {
4441       return RFAILED;
4442    }
4443 #endif
4444
4445 if(pdschCfgDb == NULLP)
4446    pdschCfg->resourceAllocation = RES_ALLOC_TYPE;
4447 else
4448 pdschCfg->resourceAllocation = pdschCfgDb->resourceAllocType;
4449
4450    pdschCfg->pdsch_TimeDomainAllocationList = NULLP;
4451    DU_ALLOC(pdschCfg->pdsch_TimeDomainAllocationList, sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
4452    if(!pdschCfg->pdsch_TimeDomainAllocationList)
4453    {
4454       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4455       return RFAILED;
4456    }
4457    if(BuildPdschTimeDomAllocList(pdschCfgDb, pdschCfg->pdsch_TimeDomainAllocationList) != ROK)
4458    {
4459       return RFAILED;
4460    }
4461
4462    pdschCfg->pdsch_AggregationFactor = NULLP;
4463    pdschCfg->rateMatchPatternToAddModList = NULLP;
4464    pdschCfg->rateMatchPatternToReleaseList = NULLP;
4465    pdschCfg->rateMatchPatternGroup1 = NULLP;
4466    pdschCfg->rateMatchPatternGroup2 = NULLP;
4467    if(pdschCfgDb == NULLP)
4468       pdschCfg->rbg_Size = PDSCH_RBG_SIZE;
4469    else
4470       pdschCfg->rbg_Size = pdschCfgDb->rbgSize;
4471    pdschCfg->mcs_Table = NULLP;
4472
4473    pdschCfg->maxNrofCodeWordsScheduledByDCI = NULLP;
4474    DU_ALLOC(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
4475    if(!pdschCfg->maxNrofCodeWordsScheduledByDCI)
4476    {
4477       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4478       return RFAILED;
4479    }
4480    if(pdschCfgDb == NULLP)
4481       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = PDSCH_MAX_CODEWORD_SCH_BY_DCI;
4482    else
4483       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = pdschCfgDb->numCodeWordsSchByDci;
4484
4485    if(BuildPdschPrbBundlingType(pdschCfgDb, &pdschCfg->prb_BundlingType) != ROK)
4486    {
4487       return RFAILED;
4488    }
4489
4490    pdschCfg->zp_CSI_RS_ResourceToAddModList = NULLP;
4491    pdschCfg->zp_CSI_RS_ResourceToReleaseList = NULLP;
4492    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4493    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4494    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4495    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4496    pdschCfg->p_ZP_CSI_RS_ResourceSet = NULLP;
4497
4498    return ROK;
4499 }
4500
4501 /*******************************************************************
4502  *
4503  * @brief Builds intitial DL BWP
4504  * @details
4505  *
4506  *    Function : BuildInitialDlBWP 
4507  *
4508  *    Functionality: Builds intitial DL BWP in spCellCfgDed
4509  *
4510  * @params[in] BWP_DownlinkDedicated_t *dlBwp
4511  *
4512  * @return ROK     - success
4513  *         RFAILED - failure
4514  *
4515  * ****************************************************************/
4516 uint8_t BuildInitialDlBWP(InitialDlBwp *initiDlBwp, BWP_DownlinkDedicated_t *dlBwp)
4517 {
4518    PdcchConfig *pdcchCfg = NULLP;
4519    PdschConfig *pdschCfg = NULLP;
4520
4521    if(initiDlBwp)
4522    {
4523       if(initiDlBwp->pdcchPresent)
4524          pdcchCfg = &initiDlBwp->pdcchCfg;
4525       if(initiDlBwp->pdschPresent)
4526          pdschCfg = &initiDlBwp->pdschCfg;
4527    }
4528
4529    dlBwp->pdcch_Config = NULLP;
4530    DU_ALLOC(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
4531    if(!dlBwp->pdcch_Config)
4532    {
4533       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4534       return RFAILED;
4535    }
4536    dlBwp->pdcch_Config->present = BWP_DownlinkDedicated__pdcch_Config_PR_setup; 
4537
4538    dlBwp->pdcch_Config->choice.setup = NULLP;
4539    DU_ALLOC(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
4540    if(!dlBwp->pdcch_Config->choice.setup)
4541    {
4542       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4543       return RFAILED;
4544    }
4545    if(BuildBWPDlDedPdcchCfg(pdcchCfg, dlBwp->pdcch_Config->choice.setup) != ROK)
4546    {
4547       return RFAILED;
4548    }
4549
4550    dlBwp->pdsch_Config = NULLP;
4551    DU_ALLOC(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
4552    if(!dlBwp->pdsch_Config)
4553    {
4554       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4555       return RFAILED;
4556    }
4557    dlBwp->pdsch_Config->present = BWP_DownlinkDedicated__pdsch_Config_PR_setup;
4558
4559    dlBwp->pdsch_Config->choice.setup = NULLP;
4560    DU_ALLOC(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
4561    if(!dlBwp->pdsch_Config->choice.setup)
4562    {
4563       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4564       return RFAILED;
4565    }
4566
4567    if(BuildBWPDlDedPdschCfg(pdschCfg, dlBwp->pdsch_Config->choice.setup) != ROK)
4568    {
4569       return RFAILED;
4570    }
4571
4572    dlBwp->sps_Config = NULLP;
4573    dlBwp->radioLinkMonitoringConfig = NULLP; 
4574    return ROK;
4575 }
4576
4577 /*******************************************************************
4578  *
4579  * @brief Builds DMRS UL Pusch Mapping type A
4580  *
4581  * @details
4582  *
4583  *    Function : BuildDMRSULPuschMapTypeA
4584  *
4585  *    Functionality: Builds DMRS UL Pusch Mapping type A
4586  *
4587  * @params[in] 
4588  *    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg
4589  * @return ROK     - success
4590  *         RFAILED - failure
4591  *
4592  * ****************************************************************/
4593 uint8_t BuildDMRSULPuschMapTypeA(DmrsUlCfg *ulDmrsCfgDb, struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg)
4594 {
4595    dmrsUlCfg->present = PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup;
4596    dmrsUlCfg->choice.setup= NULLP;
4597    DU_ALLOC(dmrsUlCfg->choice.setup, sizeof(DMRS_UplinkConfig_t));
4598    if(!dmrsUlCfg->choice.setup)
4599    {
4600       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4601       return RFAILED;
4602    }
4603
4604    dmrsUlCfg->choice.setup->dmrs_Type = NULLP;
4605    dmrsUlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4606    DU_ALLOC(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4607    if(!dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
4608    {
4609       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4610       return RFAILED;
4611    }
4612    if(ulDmrsCfgDb == NULLP)
4613       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS; 
4614    else
4615       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = ulDmrsCfgDb->addPos;
4616
4617    dmrsUlCfg->choice.setup->phaseTrackingRS = NULLP;
4618    dmrsUlCfg->choice.setup->maxLength = NULLP;
4619    dmrsUlCfg->choice.setup->transformPrecodingDisabled = NULLP;
4620    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled, sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
4621    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled)
4622    {
4623       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4624       return RFAILED;
4625    }
4626
4627    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0 = NULLP;
4628    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
4629          sizeof(long));
4630    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0)
4631    {
4632       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4633       return RFAILED;
4634    }
4635    if(ulDmrsCfgDb == NULLP)
4636       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = SCRAMBLING_ID;
4637    else
4638       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = ulDmrsCfgDb->transPrecodDisabled.scramblingId0;
4639
4640    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID1 = NULLP;
4641    dmrsUlCfg->choice.setup->transformPrecodingEnabled = NULLP;
4642    return ROK;
4643 }
4644
4645 /*******************************************************************
4646  *
4647  * @brief Build PUSCH time domain allocation list
4648  *
4649  * @details
4650  *
4651  *    Function : BuildPuschTimeDomAllocList
4652  *
4653  *    Functionality: Build PUSCH time domain allocation list
4654  *
4655  * @params[in] 
4656  * struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList
4657  *
4658  * @return ROK     - success
4659  *         RFAILED - failure
4660  *
4661  * ****************************************************************/
4662 uint8_t BuildPuschTimeDomAllocList(PuschCfg *puschCfgDb, struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList)
4663 {
4664    uint8_t idx;
4665    uint8_t elementCnt;
4666    PUSCH_TimeDomainResourceAllocation_t  *timeDomAlloc;
4667
4668    timeDomAllocList->present = PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup;
4669    timeDomAllocList->choice.setup = NULLP;
4670    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PUSCH_TimeDomainResourceAllocationList));
4671    if(!timeDomAllocList->choice.setup)
4672    {
4673       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4674       return RFAILED;
4675    }
4676
4677    if(puschCfgDb == NULLP)
4678       elementCnt = 2;
4679    else
4680       elementCnt = puschCfgDb->numTimeDomRsrcAlloc;
4681
4682    timeDomAllocList->choice.setup->list.count = elementCnt;
4683    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(PUSCH_TimeDomainResourceAllocation_t *);
4684    timeDomAllocList->choice.setup->list.array = NULLP;
4685    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4686    if(!timeDomAllocList->choice.setup->list.array)
4687    {
4688       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4689       return RFAILED;
4690    }
4691
4692    for(idx = 0; idx < elementCnt; idx++)
4693    {
4694       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4695       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], sizeof(PUSCH_TimeDomainResourceAllocation_t));
4696       if(!timeDomAllocList->choice.setup->list.array[idx])
4697       {
4698          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4699          return RFAILED;
4700       }
4701    }
4702
4703    for(idx = 0; idx < elementCnt; idx++)
4704    {
4705       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4706       DU_ALLOC(timeDomAlloc->k2, sizeof(long));
4707       if(!timeDomAlloc->k2)
4708       {
4709          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4710          return RFAILED;
4711       }
4712       if(puschCfgDb == NULLP)
4713       {
4714          if(idx == 0)
4715             *(timeDomAlloc->k2) = PUSCH_K2_CFG1;
4716          else if(idx == 1)
4717             *(timeDomAlloc->k2) = PUSCH_K2_CFG2;
4718
4719          timeDomAlloc->mappingType = PUSCH_MAPPING_TYPE_A;
4720          timeDomAlloc->startSymbolAndLength = calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
4721       }
4722       else
4723       {
4724          *(timeDomAlloc->k2) = puschCfgDb->timeDomRsrcAllocList[idx].k2;
4725          timeDomAlloc->mappingType = puschCfgDb->timeDomRsrcAllocList[idx].mappingType;
4726          timeDomAlloc->startSymbolAndLength = puschCfgDb->timeDomRsrcAllocList[idx].startSymbolAndLength;
4727       }
4728    }
4729
4730    return ROK;
4731 }
4732
4733 /*******************************************************************
4734  *
4735  * @brief Builds BWP UL dedicated PUSCH Config
4736  *
4737  * @details
4738  *
4739  *    Function : BuildBWPUlDedPuschCfg
4740  *
4741  *    Functionality:
4742  *      Builds BWP UL dedicated PUSCH Config
4743  *
4744  * @params[in] : PUSCH_Config_t *puschCfg
4745  *    
4746  * @return ROK     - success
4747  *         RFAILED - failure
4748  *
4749  * ****************************************************************/
4750 uint8_t BuildBWPUlDedPuschCfg(PuschCfg *puschCfgDb, PUSCH_Config_t *puschCfg)
4751 {
4752    DmrsUlCfg *ulDmrsCfg = NULLP;
4753    
4754    if(puschCfgDb)
4755       ulDmrsCfg = &puschCfgDb->dmrsUlCfgForPuschMapTypeA;
4756
4757    puschCfg->dataScramblingIdentityPUSCH = NULLP;
4758    DU_ALLOC(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
4759    if(!puschCfg->dataScramblingIdentityPUSCH)
4760    {
4761       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4762       return RFAILED;
4763    }
4764    if(puschCfgDb == NULLP)
4765       *(puschCfg->dataScramblingIdentityPUSCH) = SCRAMBLING_ID;
4766    else
4767       *(puschCfg->dataScramblingIdentityPUSCH) = puschCfgDb->dataScramblingId;
4768
4769    puschCfg->txConfig = NULLP;
4770    puschCfg->dmrs_UplinkForPUSCH_MappingTypeA = NULLP;
4771    DU_ALLOC(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
4772    if(!puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
4773    {
4774       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4775       return RFAILED;
4776    }
4777
4778    if(BuildDMRSULPuschMapTypeA(ulDmrsCfg, puschCfg->dmrs_UplinkForPUSCH_MappingTypeA) != ROK)
4779    {
4780       return RFAILED;
4781    }
4782
4783    puschCfg->dmrs_UplinkForPUSCH_MappingTypeB = NULLP;
4784    puschCfg->pusch_PowerControl = NULLP;
4785    puschCfg->frequencyHopping = NULLP;
4786    puschCfg->frequencyHoppingOffsetLists = NULLP;
4787
4788    if(puschCfgDb == NULLP)
4789       puschCfg->resourceAllocation = RES_ALLOC_TYPE;
4790    else
4791       puschCfg->resourceAllocation = puschCfgDb->resourceAllocType;
4792
4793    puschCfg->pusch_TimeDomainAllocationList = NULLP;
4794    DU_ALLOC(puschCfg->pusch_TimeDomainAllocationList, sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
4795    if(!puschCfg->pusch_TimeDomainAllocationList)
4796    {
4797       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4798       return RFAILED;
4799    }
4800
4801    if(BuildPuschTimeDomAllocList(puschCfgDb, puschCfg->pusch_TimeDomainAllocationList) != ROK)
4802    {
4803       return RFAILED;
4804    }
4805
4806    puschCfg->pusch_AggregationFactor = NULLP;
4807    puschCfg->mcs_Table = NULLP;
4808    puschCfg->mcs_TableTransformPrecoder = NULLP;
4809    puschCfg->transformPrecoder = NULLP;
4810    DU_ALLOC(puschCfg->transformPrecoder, sizeof(long));
4811    if(!puschCfg->transformPrecoder)
4812    {
4813       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4814       return RFAILED;
4815    }
4816    if(puschCfgDb == NULLP)
4817       *(puschCfg->transformPrecoder) = PUSCH_TRANSFORM_PRECODER;
4818    else
4819       *(puschCfg->transformPrecoder) = puschCfgDb->transformPrecoder;
4820
4821    puschCfg->codebookSubset = NULLP;
4822    puschCfg->maxRank = NULLP;
4823    puschCfg->rbg_Size = NULLP;
4824    puschCfg->uci_OnPUSCH = NULLP;
4825    puschCfg->tp_pi2BPSK = NULLP;
4826
4827    return ROK;
4828 }
4829
4830 /*******************************************************************
4831  *
4832  * @brief Builds PUCCH resource set add/modify list
4833  *
4834  * @details
4835  *
4836  *    Function : BuildPucchRsrcSetAddModList
4837  *
4838  *    Functionality:
4839  *      Builds PUCCH resource set add/modify list
4840  *
4841  * @params[in] : PucchResrcSetCfg *rsrcSetCfgDb
4842  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4843  *
4844  * @return ROK     - success
4845  *         RFAILED - failure
4846  *
4847  * ****************************************************************/
4848 uint8_t BuildPucchRsrcSetAddModList(PucchResrcSetCfg *rsrcSetCfgDb, \
4849    struct PUCCH_Config__resourceSetToAddModList *resourceSetToAddModList)
4850 {
4851    uint8_t elementCnt = 0, rsrcSetIdx = 0, rsrcIdx = 0;
4852    PUCCH_ResourceSet_t *rsrcSet = NULLP;
4853
4854    if(rsrcSetCfgDb == NULLP)
4855       elementCnt = 1;
4856    else
4857       elementCnt = rsrcSetCfgDb->resrcSetToAddModListCount;
4858
4859    resourceSetToAddModList->list.count = elementCnt;
4860    resourceSetToAddModList->list.size = elementCnt * sizeof(PUCCH_ResourceSet_t *);
4861    DU_ALLOC(resourceSetToAddModList->list.array, resourceSetToAddModList->list.size);
4862    if(resourceSetToAddModList->list.array == NULLP)
4863    {
4864       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4865       return RFAILED;
4866    }
4867    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4868    {
4869       DU_ALLOC(resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
4870       if(resourceSetToAddModList->list.array[rsrcSetIdx] == NULLP)
4871       {
4872          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4873          return RFAILED;
4874       }
4875    }
4876
4877    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4878    {
4879       rsrcSet = resourceSetToAddModList->list.array[rsrcSetIdx];
4880
4881       /* Resource set Id */
4882       if(rsrcSetCfgDb == NULLP)
4883          rsrcSet->pucch_ResourceSetId = 1;
4884       else
4885          rsrcSet->pucch_ResourceSetId = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcSetId;
4886  
4887       /* Resource list of a resource set */
4888       if(rsrcSetCfgDb == NULLP)
4889          elementCnt = 1;
4890       else
4891          elementCnt = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcListCount;
4892       rsrcSet->resourceList.list.count = elementCnt;
4893       rsrcSet->resourceList.list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
4894       DU_ALLOC(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
4895       if(rsrcSet->resourceList.list.array == NULLP)
4896       {
4897          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4898          return RFAILED;
4899       }
4900
4901       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4902       {
4903          DU_ALLOC(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
4904          if(rsrcSet->resourceList.list.array[rsrcIdx] == NULLP)
4905          {
4906             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4907             return RFAILED;
4908          }
4909       }
4910       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4911       {
4912          if(rsrcSetCfgDb == NULLP)
4913             *(rsrcSet->resourceList.list.array[rsrcIdx]) = 1;
4914          else
4915             *(rsrcSet->resourceList.list.array[rsrcIdx]) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcList[rsrcIdx];
4916       }
4917
4918       /* Max payload size (minus 1) in a Resource set */
4919       rsrcSet->maxPayloadMinus1 = NULLP;
4920       if(rsrcSetCfgDb && rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize)
4921       {
4922          DU_ALLOC(rsrcSet->maxPayloadMinus1, sizeof(long));
4923          if(rsrcSet->maxPayloadMinus1 == NULLP)
4924          {
4925             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4926             return RFAILED;
4927          }
4928          *(rsrcSet->maxPayloadMinus1) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize;
4929       }
4930    }
4931    return ROK;
4932 }
4933
4934 /*******************************************************************
4935  *
4936  * @brief Builds PUCCH resource add/modify list
4937  *
4938  * @details
4939  *
4940  *    Function : BuildPucchRsrcAdddModList
4941  *
4942  *    Functionality:
4943  *      Builds PUCCH resource add/modify list
4944  *
4945  * @params[in] : PucchResrcCfg *rsrcSetCfgDb
4946  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4947  *
4948  * @return ROK     - success
4949  *         RFAILED - failure
4950  *
4951  * ****************************************************************/
4952 uint8_t BuildPucchRsrcAddModList(PucchResrcCfg *rsrcCfgDb, struct PUCCH_Config__resourceToAddModList  *resourceToAddModList)
4953 {
4954    uint8_t elementCnt = 0, rsrcIdx = 0;
4955    PUCCH_Resource_t *rsrc = NULLP;
4956
4957    if(rsrcCfgDb == NULLP)
4958       elementCnt = 1;
4959    else
4960       elementCnt = rsrcCfgDb->resrcToAddModListCount;
4961    resourceToAddModList->list.count = elementCnt;
4962    resourceToAddModList->list.size = elementCnt * sizeof(PUCCH_Resource_t *);
4963    DU_ALLOC(resourceToAddModList->list.array, resourceToAddModList->list.size);
4964    if(resourceToAddModList->list.array == NULLP)
4965    {
4966       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4967       return RFAILED;
4968    }
4969    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4970    {
4971       DU_ALLOC(resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
4972       if(resourceToAddModList->list.array[rsrcIdx] == NULLP)
4973       {
4974          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4975          return RFAILED;
4976       }
4977    }
4978
4979    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4980    {
4981       rsrc = resourceToAddModList->list.array[rsrcIdx];
4982
4983       if(rsrcCfgDb == NULLP)
4984       {
4985          rsrc->pucch_ResourceId = 1;
4986          rsrc->startingPRB = 0;
4987          rsrc->format.present = PUCCH_Resource__format_PR_format1; 
4988          DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4989          if(rsrc->format.choice.format1 == NULLP)
4990          {
4991             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4992             return RFAILED;
4993          }  
4994          rsrc->format.choice.format1->initialCyclicShift = 0;
4995          rsrc->format.choice.format1->nrofSymbols = 4;
4996          rsrc->format.choice.format1->startingSymbolIndex = 0;
4997          rsrc->format.choice.format1->timeDomainOCC = 0;
4998       }
4999       else
5000       {
5001          rsrc->pucch_ResourceId = rsrcCfgDb->resrcToAddModList[rsrcIdx].resrcId;
5002          rsrc->startingPRB = rsrcCfgDb->resrcToAddModList[rsrcIdx].startPrb;
5003          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop)
5004          {
5005             DU_ALLOC(rsrc->intraSlotFrequencyHopping, sizeof(long));
5006             if(rsrc->intraSlotFrequencyHopping == NULLP)
5007             {
5008                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5009                return RFAILED;
5010             }
5011             *(rsrc->intraSlotFrequencyHopping) = rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop;
5012          }
5013          else
5014             rsrc->intraSlotFrequencyHopping = NULLP;
5015
5016          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop)
5017          {
5018             DU_ALLOC(rsrc->secondHopPRB, sizeof(PRB_Id_t));
5019             if(rsrc->secondHopPRB == NULLP)
5020             {
5021                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5022                return RFAILED;
5023             }
5024             *(rsrc->secondHopPRB) = rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop;
5025          }
5026          else
5027             rsrc->secondHopPRB = NULLP;
5028          rsrc->format.present = covertPucchFormatIntEnumToRrcEnum(rsrcCfgDb->resrcToAddModList[rsrcIdx].pucchFormat); 
5029
5030          switch(rsrc->format.present)
5031          {
5032             case PUCCH_Resource__format_PR_NOTHING:
5033                break;
5034             case PUCCH_Resource__format_PR_format0:
5035                {
5036                   DU_ALLOC(rsrc->format.choice.format0, sizeof(PUCCH_format0_t));
5037                   if(rsrc->format.choice.format0 == NULLP)
5038                   {
5039                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5040                      return RFAILED;
5041                   }
5042                   rsrc->format.choice.format0->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->initialCyclicShift;
5043                   rsrc->format.choice.format0->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->numSymbols;
5044                   rsrc->format.choice.format0->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->startSymbolIdx;
5045                   break;
5046                }
5047
5048             case PUCCH_Resource__format_PR_format1:
5049                {
5050                   DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
5051                   if(rsrc->format.choice.format1 == NULLP)
5052                   {
5053                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5054                      return RFAILED;
5055                   }  
5056                   rsrc->format.choice.format1->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->initialCyclicShift;
5057                   rsrc->format.choice.format1->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->numSymbols;
5058                   rsrc->format.choice.format1->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->startSymbolIdx;
5059                   rsrc->format.choice.format1->timeDomainOCC = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->timeDomOCC;
5060                   break;
5061                }
5062
5063             case PUCCH_Resource__format_PR_format2:
5064                {
5065                   DU_ALLOC(rsrc->format.choice.format2, sizeof(PUCCH_format2_t));
5066                   if(rsrc->format.choice.format2 == NULLP)
5067                   {
5068                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5069                      return RFAILED;
5070                   } 
5071                   rsrc->format.choice.format2->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numPrbs;
5072                   rsrc->format.choice.format2->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numSymbols;
5073                   rsrc->format.choice.format2->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->startSymbolIdx;
5074                   break;
5075                }
5076
5077             case PUCCH_Resource__format_PR_format3:
5078                {
5079                   DU_ALLOC(rsrc->format.choice.format3, sizeof(PUCCH_format3_t));
5080                   if(rsrc->format.choice.format3 == NULLP)
5081                   {
5082                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5083                      return RFAILED;
5084                   }
5085                   rsrc->format.choice.format3->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numPrbs;
5086                   rsrc->format.choice.format3->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numSymbols;
5087                   rsrc->format.choice.format3->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->startSymbolIdx;
5088                   break;
5089                }
5090
5091             case PUCCH_Resource__format_PR_format4:
5092                {
5093                   DU_ALLOC(rsrc->format.choice.format4, sizeof(PUCCH_format4_t));
5094                   if(rsrc->format.choice.format4 == NULLP)
5095                   {
5096                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5097                      return RFAILED;
5098                   }
5099                   rsrc->format.choice.format4->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->numSymbols;
5100                   rsrc->format.choice.format4->occ_Length = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occLen;
5101                   rsrc->format.choice.format4->occ_Index = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occIdx;
5102                   rsrc->format.choice.format4->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->startSymbolIdx;
5103                   break;
5104                }
5105          }
5106       }
5107    }
5108    return ROK;
5109 }
5110
5111 /*******************************************************************
5112  *
5113  * @brief Builds PUCCH format  config
5114  *
5115  * @details
5116  *
5117  *    Function : BuildPucchFormat
5118  *
5119  *    Functionality: Builds PUCCH format  config
5120  *
5121  * @params[in] : PucchFormatCfg *formatDb
5122  *               PUCCH_FormatConfig_t *format
5123  *
5124  * @return ROK     - success
5125  *         RFAILED - failure
5126  *
5127  * ****************************************************************/
5128 uint8_t BuildPucchFormat(PucchFormatCfg *formatDb, PUCCH_FormatConfig_t *format)
5129 {
5130    /* Inter Slot Fequency hopping */
5131    format->interslotFrequencyHopping = NULLP;
5132    if((formatDb != NULLP) && (formatDb->interSlotFreqHop == true))
5133    {
5134       DU_ALLOC(format->interslotFrequencyHopping, sizeof(long));
5135       if(format->interslotFrequencyHopping)
5136       {
5137          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5138          return RFAILED;
5139       }
5140       *(format->interslotFrequencyHopping) = PUCCH_FormatConfig__interslotFrequencyHopping_enabled;
5141    }
5142
5143    /* Additional DMRS */
5144    format->additionalDMRS = NULLP;
5145    if((formatDb != NULLP) && (formatDb->addDmrs == true))
5146    {
5147       DU_ALLOC(format->additionalDMRS, sizeof(long));
5148       if(format->additionalDMRS)
5149       {
5150          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5151          return RFAILED;
5152       }
5153       *(format->additionalDMRS) = PUCCH_FormatConfig__additionalDMRS_true;
5154    }
5155
5156     /* Maximum code rate */
5157    format->maxCodeRate = NULLP;
5158    if((formatDb != NULLP) && (formatDb->maxCodeRate != 0))
5159    {
5160       DU_ALLOC(format->maxCodeRate, sizeof(long));
5161       if(format->maxCodeRate)
5162       {
5163          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5164          return RFAILED;
5165       }  
5166       *(format->maxCodeRate) = formatDb->maxCodeRate;
5167    }
5168  
5169    /* Number of slots */
5170    format->nrofSlots = NULLP;
5171    if((formatDb == NULLP) || ((formatDb != NULLP) && (formatDb->numSlots != 0)))
5172    {
5173       DU_ALLOC(format->nrofSlots, sizeof(long));
5174       if(format->nrofSlots == NULLP)
5175       {
5176          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5177          return RFAILED;
5178       }
5179       if(formatDb == NULLP)
5180          *(format->nrofSlots) = PUCCH_FormatConfig__nrofSlots_n4;
5181       else
5182          *(format->nrofSlots) = formatDb->numSlots;
5183    }
5184
5185    /* Pi2BPSK*/
5186    format->pi2BPSK = NULLP;
5187    if((formatDb != NULLP) && (formatDb->pi2BPSK == true))
5188    {
5189       DU_ALLOC(format->pi2BPSK, sizeof(long));
5190       if(format->pi2BPSK)
5191       {     
5192          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5193          return RFAILED;
5194       }     
5195       *(format->pi2BPSK) = PUCCH_FormatConfig__pi2BPSK_enabled;
5196    }
5197
5198    /* Simultaneous HARQ ACK and CSI */
5199    format->simultaneousHARQ_ACK_CSI = NULLP;
5200    if((formatDb != NULLP) && (formatDb->harqAckCSI == true))
5201    {
5202       DU_ALLOC(format->simultaneousHARQ_ACK_CSI, sizeof(long));
5203       if(format->simultaneousHARQ_ACK_CSI)
5204       {     
5205          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5206          return RFAILED;
5207       }     
5208       *(format->simultaneousHARQ_ACK_CSI) = PUCCH_FormatConfig__simultaneousHARQ_ACK_CSI_true;
5209    }
5210
5211    return ROK;
5212 }
5213
5214
5215 /*******************************************************************
5216  *
5217  * @brief Builds PUCCH scheduling request list
5218  *
5219  * @details
5220  *
5221  *    Function : BuildPucchSchReqAddModList
5222  *
5223  *    Functionality:
5224  *      Builds PUCCH scheduling request list
5225  *
5226  * @params[in] : PucchSchedReqCfg *schReqDb
5227  *               struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList
5228  *
5229  * @return ROK     - success
5230  *         RFAILED - failure
5231  *
5232  * ****************************************************************/
5233 uint8_t BuildPucchSchReqAddModList(PucchSchedReqCfg *schReqDb, \
5234    struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList)
5235 {
5236    uint8_t elementCnt = 0, schReqIdx = 0;
5237    SchedulingRequestResourceConfig_t *schReqRsrc;
5238
5239    elementCnt = schReqDb->schedAddModListCount;
5240    schReqRsrcToAddModList->list.count = elementCnt;
5241    schReqRsrcToAddModList->list.size = elementCnt *sizeof(struct SchedulingRequestResourceConfig *);
5242
5243    schReqRsrcToAddModList->list.array = NULLP;
5244    DU_ALLOC(schReqRsrcToAddModList->list.array, schReqRsrcToAddModList->list.size);
5245    if(schReqRsrcToAddModList->list.array == NULLP)
5246    {
5247       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5248       return RFAILED;
5249    }
5250
5251    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
5252    {
5253       DU_ALLOC(schReqRsrcToAddModList->list.array[schReqIdx], schReqRsrcToAddModList->list.size);
5254       if(schReqRsrcToAddModList->list.array[schReqIdx] == NULLP)
5255       {
5256          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5257          return RFAILED;
5258       }
5259    }
5260
5261    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
5262    {
5263       schReqRsrc = schReqRsrcToAddModList->list.array[schReqIdx];
5264       schReqRsrc->schedulingRequestResourceId = schReqDb->schedAddModList[schReqIdx].resrcId;
5265       schReqRsrc->schedulingRequestID = schReqDb->schedAddModList[schReqIdx].requestId;
5266
5267       if(schReqDb->schedAddModList[schReqIdx].periodicity)
5268       {
5269          schReqRsrc->periodicityAndOffset = NULLP;
5270          DU_ALLOC(schReqRsrc->periodicityAndOffset, sizeof(struct SchedulingRequestResourceConfig__periodicityAndOffset));
5271          if(schReqRsrc->periodicityAndOffset == NULLP)
5272          {
5273             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5274             return RFAILED;
5275          }
5276
5277          schReqRsrc->periodicityAndOffset->present = schReqDb->schedAddModList[schReqIdx].periodicity;
5278          switch(schReqRsrc->periodicityAndOffset->present)
5279          {
5280             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_NOTHING:
5281                break;
5282             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
5283                schReqRsrc->periodicityAndOffset->choice.sym2 = schReqDb->schedAddModList[schReqIdx].offset;
5284                break;
5285             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
5286                schReqRsrc->periodicityAndOffset->choice.sym6or7 = schReqDb->schedAddModList[schReqIdx].offset;
5287                break;
5288             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
5289                schReqRsrc->periodicityAndOffset->choice.sl1 = schReqDb->schedAddModList[schReqIdx].offset;
5290                break;
5291             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
5292                schReqRsrc->periodicityAndOffset->choice.sl2 = schReqDb->schedAddModList[schReqIdx].offset;
5293                break;
5294             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
5295                schReqRsrc->periodicityAndOffset->choice.sl4 = schReqDb->schedAddModList[schReqIdx].offset;
5296                break;
5297             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
5298                schReqRsrc->periodicityAndOffset->choice.sl5 = schReqDb->schedAddModList[schReqIdx].offset;
5299                break;
5300             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
5301                schReqRsrc->periodicityAndOffset->choice.sl8 = schReqDb->schedAddModList[schReqIdx].offset;
5302                break;
5303             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
5304                schReqRsrc->periodicityAndOffset->choice.sl10 = schReqDb->schedAddModList[schReqIdx].offset;
5305                break;
5306             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
5307                schReqRsrc->periodicityAndOffset->choice.sl16 = schReqDb->schedAddModList[schReqIdx].offset;
5308                break;
5309             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
5310                schReqRsrc->periodicityAndOffset->choice.sl20 = schReqDb->schedAddModList[schReqIdx].offset;
5311                break;
5312             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
5313                schReqRsrc->periodicityAndOffset->choice.sl40 = schReqDb->schedAddModList[schReqIdx].offset;
5314                break;
5315             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
5316                schReqRsrc->periodicityAndOffset->choice.sl80 = schReqDb->schedAddModList[schReqIdx].offset;
5317                break;
5318             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
5319                schReqRsrc->periodicityAndOffset->choice.sl160 = schReqDb->schedAddModList[schReqIdx].offset;
5320                break;
5321             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
5322                schReqRsrc->periodicityAndOffset->choice.sl320 = schReqDb->schedAddModList[schReqIdx].offset;
5323                break;
5324             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
5325                schReqRsrc->periodicityAndOffset->choice.sl640 = schReqDb->schedAddModList[schReqIdx].offset;
5326                break;
5327          }
5328       }
5329
5330       if(schReqDb->schedAddModList[schReqIdx].resrc)
5331       {
5332          schReqRsrc->resource = NULLP;
5333          DU_ALLOC(schReqRsrc->resource, sizeof(PUCCH_ResourceId_t));
5334          if(schReqRsrc->resource == NULLP)
5335          {
5336             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5337             return RFAILED;
5338          }
5339          *(schReqRsrc->resource) = schReqDb->schedAddModList[schReqIdx].resrc;
5340
5341       }
5342    }
5343    return ROK;
5344 }
5345
5346 /*******************************************************************
5347  *
5348  * @brief Builds PUCCH multi csi resource list
5349  *
5350  * @details
5351  *
5352  *    Function : BuildPucchMultiCsiRsrcList
5353  *
5354  *    Functionality:
5355  *      Builds PUCCH multi csi resource list
5356  *
5357  * @params[in] : PucchMultiCsiCfg *multiCsiDb
5358  *               struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList
5359  *
5360  * @return ROK     - success
5361  *         RFAILED - failure
5362  *
5363  * ****************************************************************/
5364 uint8_t BuildPucchMultiCsiRsrcList(PucchMultiCsiCfg *multiCsiDb, struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList)
5365 {
5366    uint8_t elementCnt = 0, rsrcIdx = 0;
5367
5368    elementCnt = multiCsiDb->multiCsiResrcListCount;
5369    multiCsiRsrcList->list.count = elementCnt;
5370    multiCsiRsrcList->list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
5371    multiCsiRsrcList->list.array = NULLP;
5372    DU_ALLOC(multiCsiRsrcList->list.array, multiCsiRsrcList->list.size);
5373    if(multiCsiRsrcList->list.array == NULLP)
5374    {
5375       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5376       return RFAILED;
5377    }
5378
5379    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5380    {
5381       DU_ALLOC(multiCsiRsrcList->list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
5382       if(multiCsiRsrcList->list.array[rsrcIdx] == NULLP)
5383       {
5384          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5385          return RFAILED;
5386       }
5387    }
5388
5389    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5390    {
5391       *(multiCsiRsrcList->list.array[rsrcIdx]) = multiCsiDb->multiCsiResrcList[rsrcIdx];
5392    }
5393    return ROK;
5394 }
5395
5396 /*******************************************************************
5397  *
5398  * @brief Builds DL data -to- Ul Ack list
5399  *
5400  * @details
5401  *
5402  *    Function : BuildDlDataToUlAckList
5403  *
5404  *    Functionality: Builds DL data -to- Ul Ack list
5405  *
5406  * @params[in] : PucchDlDataToUlAck *dlDataToUlAckDb
5407  *               struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList
5408  *
5409  * @return ROK     - success
5410  *         RFAILED - failure
5411  *
5412  * ****************************************************************/
5413 uint8_t BuildDlDataToUlAckList(PucchDlDataToUlAck *dlDataToUlAckDb, struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList)
5414 {
5415    uint8_t elementCnt = 0, arrIdx = 0;
5416
5417    if(dlDataToUlAckDb == NULLP)
5418       elementCnt = 2;
5419    else
5420       elementCnt = dlDataToUlAckDb->dlDataToUlAckListCount;
5421
5422    dlDataToUlACKList->list.count = elementCnt;
5423    dlDataToUlACKList->list.size = elementCnt * sizeof(long *);
5424    DU_ALLOC(dlDataToUlACKList->list.array, dlDataToUlACKList->list.size);
5425    if(dlDataToUlACKList->list.array == NULLP)
5426    {
5427       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5428       return RFAILED;
5429    }   
5430
5431    for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5432    {
5433       DU_ALLOC(dlDataToUlACKList->list.array[arrIdx], sizeof(long));
5434       if(dlDataToUlACKList->list.array[arrIdx] == NULLP)
5435       {
5436          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5437          return RFAILED;
5438       }   
5439    }
5440
5441    if(dlDataToUlAckDb == NULLP)
5442    {
5443       arrIdx = 0;
5444       *(dlDataToUlACKList->list.array[arrIdx++]) = 1;
5445       *(dlDataToUlACKList->list.array[arrIdx]) = 2;
5446    }
5447    else
5448    {
5449       for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5450       {
5451          *(dlDataToUlACKList->list.array[arrIdx]) = dlDataToUlAckDb->dlDataToUlAckList[arrIdx];
5452       }
5453    }
5454    return ROK;
5455 }
5456
5457 /*******************************************************************
5458  *
5459  * @brief Builds BWP UL dedicated PUCCH Config
5460  *
5461  * @details
5462  *
5463  *    Function : BuildBWPUlDedPucchCfg
5464  *
5465  *    Functionality:
5466  *      Builds BWP UL dedicated PUCCH Config
5467  *
5468  * @params[in] : PUCCH_Config_t *pucchCfg
5469  *
5470  * @return ROK     - success
5471  *         RFAILED - failure
5472  *
5473  * ****************************************************************/
5474 uint8_t BuildBWPUlDedPucchCfg(PucchCfg *pucchCfgDb, PUCCH_Config_t *pucchCfg)
5475 {
5476    PucchResrcSetCfg *rsrcSetCfgDb = NULLP;
5477    PucchResrcCfg *rsrcCfgDb = NULLP;
5478    PucchFormatCfg *format1Db = NULLP;
5479    PucchFormatCfg *format2Db = NULLP;
5480    PucchFormatCfg *format3Db = NULLP;
5481    PucchFormatCfg *format4Db = NULLP;
5482    PucchSchedReqCfg *schReqDb = NULLP;   
5483    PucchMultiCsiCfg  *multiCsiDb = NULLP;
5484    PucchDlDataToUlAck *dlDataToUlAckDb = NULLP;
5485
5486    if(pucchCfgDb)
5487    {
5488       rsrcSetCfgDb = pucchCfgDb->resrcSet;
5489       rsrcCfgDb = pucchCfgDb->resrc;
5490       format1Db = pucchCfgDb->format1;
5491       format2Db = pucchCfgDb->format2;
5492       format3Db = pucchCfgDb->format3;
5493       format4Db = pucchCfgDb->format4;
5494       schReqDb = pucchCfgDb->schedReq;
5495       multiCsiDb = pucchCfgDb->multiCsiCfg;
5496       dlDataToUlAckDb = pucchCfgDb->dlDataToUlAck;
5497    }
5498
5499    /* RESOURCE SET */
5500    DU_ALLOC(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
5501    if(pucchCfg->resourceSetToAddModList == NULL)
5502    {
5503       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5504       return RFAILED;
5505    }
5506
5507    if(BuildPucchRsrcSetAddModList(rsrcSetCfgDb, pucchCfg->resourceSetToAddModList) != ROK)
5508    {
5509       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5510       return RFAILED;
5511    }
5512
5513    /* PUCCH RESOURCE */
5514    DU_ALLOC(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
5515    if(pucchCfg->resourceToAddModList == NULLP)
5516    {
5517       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5518       return RFAILED;
5519    }
5520
5521    if(BuildPucchRsrcAddModList(rsrcCfgDb, pucchCfg->resourceToAddModList) != ROK)
5522    {
5523       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5524       return RFAILED;
5525    }
5526
5527    /* PUCCH Format 1 */
5528    DU_ALLOC(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
5529    if(pucchCfg->format1 == NULLP)
5530    {
5531       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5532       return RFAILED;
5533    }
5534    
5535    pucchCfg->format1->present = PUCCH_Config__format1_PR_setup;
5536    DU_ALLOC(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
5537    if(pucchCfg->format1->choice.setup == NULLP)
5538    {
5539       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5540       return RFAILED;
5541    }
5542
5543    if(BuildPucchFormat(format1Db, pucchCfg->format1->choice.setup) != ROK)
5544    {
5545       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5546       return RFAILED;
5547    }
5548
5549    /* PUCCH Format 2 */
5550    if(format2Db)
5551    {
5552       DU_ALLOC(pucchCfg->format2, sizeof(struct PUCCH_Config__format2));
5553       if(pucchCfg->format2 == NULLP)
5554       {
5555          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5556          return RFAILED;
5557       }
5558
5559       pucchCfg->format2->present = PUCCH_Config__format2_PR_setup;
5560       DU_ALLOC(pucchCfg->format2->choice.setup, sizeof(PUCCH_FormatConfig_t));
5561       if(pucchCfg->format2->choice.setup == NULLP)
5562       {
5563          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5564          return RFAILED;
5565       }
5566
5567       if(BuildPucchFormat(format2Db, pucchCfg->format2->choice.setup) != ROK)
5568       {
5569          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5570          return RFAILED;
5571       }
5572    }
5573
5574    /* PUCCH Format 3 */
5575    if(format3Db)
5576    {
5577       DU_ALLOC(pucchCfg->format3, sizeof(struct PUCCH_Config__format3));
5578       if(pucchCfg->format3 == NULLP)
5579       {
5580          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5581          return RFAILED;
5582       }
5583
5584       pucchCfg->format3->present = PUCCH_Config__format3_PR_setup;
5585       DU_ALLOC(pucchCfg->format3->choice.setup, sizeof(PUCCH_FormatConfig_t));
5586       if(pucchCfg->format3->choice.setup == NULLP)
5587       {
5588          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5589          return RFAILED;
5590       }
5591
5592       if(BuildPucchFormat(format3Db, pucchCfg->format3->choice.setup) != ROK)
5593       {
5594          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5595          return RFAILED;
5596       }
5597    }
5598
5599    /* PUCCH Format 4 */
5600    if(format4Db)
5601    {
5602       DU_ALLOC(pucchCfg->format4, sizeof(struct PUCCH_Config__format4));
5603       if(pucchCfg->format4 == NULLP)
5604       {
5605          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5606          return RFAILED;
5607       }
5608
5609       pucchCfg->format4->present = PUCCH_Config__format4_PR_setup;
5610       DU_ALLOC(pucchCfg->format4->choice.setup, sizeof(PUCCH_FormatConfig_t));
5611       if(pucchCfg->format4->choice.setup == NULLP)
5612       {
5613          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5614          return RFAILED;
5615       }
5616
5617       if(BuildPucchFormat(format4Db, pucchCfg->format4->choice.setup) != ROK)
5618       {
5619          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5620          return RFAILED;
5621       }
5622    }
5623
5624    /* Scheduling Request */
5625    if(schReqDb && (schReqDb->schedAddModListCount != 0))
5626    {
5627       pucchCfg->schedulingRequestResourceToAddModList = NULLP;
5628       DU_ALLOC(pucchCfg->schedulingRequestResourceToAddModList, sizeof(struct PUCCH_Config__schedulingRequestResourceToAddModList));
5629       if(pucchCfg->schedulingRequestResourceToAddModList == NULLP)
5630       {
5631          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5632          return RFAILED;
5633       }
5634
5635       if(BuildPucchSchReqAddModList(schReqDb, pucchCfg->schedulingRequestResourceToAddModList) != ROK)
5636       {
5637          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5638          return RFAILED;
5639       }
5640    }
5641
5642    /* Multi CSI */
5643    if(multiCsiDb && (multiCsiDb->multiCsiResrcListCount != 0))
5644    {
5645       pucchCfg->multi_CSI_PUCCH_ResourceList = NULLP;
5646       DU_ALLOC(pucchCfg->multi_CSI_PUCCH_ResourceList, sizeof(struct PUCCH_Config__multi_CSI_PUCCH_ResourceList));
5647       if(pucchCfg->multi_CSI_PUCCH_ResourceList == NULLP)
5648       {
5649          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5650          return RFAILED;
5651       }
5652
5653       if(BuildPucchMultiCsiRsrcList(multiCsiDb, pucchCfg->multi_CSI_PUCCH_ResourceList) != ROK)
5654       {
5655          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5656          return RFAILED;
5657       }
5658    }
5659
5660    /* DL DATA TO UL ACK */
5661    DU_ALLOC(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
5662    if(pucchCfg->dl_DataToUL_ACK == NULLP)
5663    {
5664       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5665       return RFAILED;
5666    }
5667
5668    if(BuildDlDataToUlAckList(dlDataToUlAckDb, pucchCfg->dl_DataToUL_ACK) != ROK)
5669    {
5670       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5671       return RFAILED;
5672    }
5673    
5674    /* TODO : spatial relation info add/mod list and power control*/
5675
5676    return ROK;
5677 }
5678
5679 /*******************************************************************
5680  *
5681  * @brief Fills SRS resource to add/modify list 
5682  *
5683  * @details
5684  *
5685  *    Function : BuildSrsRsrcAddModList
5686  *
5687  *    Functionality: Fills SRS resource to add/modify list
5688  *
5689  * @params[in] 
5690  * @return ROK     - success
5691  *         RFAILED - failure
5692  *
5693  * ****************************************************************/
5694 uint8_t BuildSrsRsrcAddModList(struct SRS_Config__srs_ResourceToAddModList *resourceList)
5695 {
5696    uint8_t   elementCnt;
5697    uint8_t   rsrcIdx;
5698
5699    elementCnt = 1;
5700    resourceList->list.count = elementCnt;
5701    resourceList->list.size = elementCnt * sizeof(SRS_Resource_t *);
5702    resourceList->list.array = NULLP;
5703    DU_ALLOC(resourceList->list.array, resourceList->list.size);
5704    if(!resourceList->list.array)
5705    {
5706       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5707       return RFAILED;
5708    }
5709
5710    for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
5711    {
5712       DU_ALLOC(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
5713       if(!resourceList->list.array[rsrcIdx])
5714       {
5715          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5716          return RFAILED;
5717       }
5718    }
5719
5720    rsrcIdx = 0;
5721    resourceList->list.array[rsrcIdx]->srs_ResourceId = SRS_RSRC_ID;
5722    resourceList->list.array[rsrcIdx]->nrofSRS_Ports = SRS_Resource__nrofSRS_Ports_port1;
5723    resourceList->list.array[rsrcIdx]->transmissionComb.present = SRS_Resource__transmissionComb_PR_n2;
5724
5725    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2 = NULLP;
5726    DU_ALLOC(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2, \
5727          sizeof(struct SRS_Resource__transmissionComb__n2));
5728    if(!resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2)
5729    {
5730       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5731       return RFAILED;
5732    }
5733    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->combOffset_n2\
5734       = SRS_COMB_OFFSET_N2;
5735    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->cyclicShift_n2\
5736       = SRS_CYCLIC_SHIFT_N2;
5737
5738    resourceList->list.array[rsrcIdx]->resourceMapping.startPosition = \
5739                                                                       PUSCH_START_SYMBOL;
5740    resourceList->list.array[rsrcIdx]->resourceMapping.nrofSymbols =  \
5741                                                                      SRS_Resource__resourceMapping__nrofSymbols_n1;
5742    resourceList->list.array[rsrcIdx]->resourceMapping.repetitionFactor = \
5743                                                                          SRS_Resource__resourceMapping__repetitionFactor_n1;
5744
5745    resourceList->list.array[rsrcIdx]->freqDomainPosition = SRS_FREQ_DOM_POS;
5746    resourceList->list.array[rsrcIdx]->freqDomainShift = SRS_FREQ_DOM_SHIFT;
5747    resourceList->list.array[rsrcIdx]->freqHopping.c_SRS = C_SRS;
5748    resourceList->list.array[rsrcIdx]->freqHopping.b_SRS = B_SRS;
5749    resourceList->list.array[rsrcIdx]->freqHopping.b_hop = B_HOP;
5750    resourceList->list.array[rsrcIdx]->groupOrSequenceHopping = \
5751                                                                SRS_Resource__groupOrSequenceHopping_neither;
5752
5753    /* Setting resource type to aperiodic for intergration purposes */
5754    resourceList->list.array[rsrcIdx]->resourceType.present = \
5755                                                              SRS_Resource__resourceType_PR_aperiodic;
5756    resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic = NULLP;
5757    DU_ALLOC(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,
5758          sizeof(struct SRS_Resource__resourceType__aperiodic));
5759    if(!resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic)
5760    {
5761       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5762       return RFAILED;
5763    }
5764
5765    resourceList->list.array[rsrcIdx]->sequenceId = SRS_SEQ_ID;
5766
5767    return ROK;
5768 }
5769
5770 /*******************************************************************
5771  *
5772  * @brief Build SRS resource set Add/mod list
5773  *
5774  * @details
5775  *
5776  *    Function : BuildSrsRsrcSetAddModList
5777  *
5778  *    Functionality: Build SRS resource set Add/mod list
5779  *
5780  * @params[in] 
5781  * @return ROK     - success
5782  *         RFAILED - failure
5783  *
5784  * ****************************************************************/
5785    uint8_t BuildSrsRsrcSetAddModList
5786 (
5787  struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList
5788  )
5789 {
5790    uint8_t  elementCnt;
5791    uint8_t  rSetIdx;
5792    uint8_t  rsrcIdx;
5793    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList;
5794
5795    elementCnt = 1;
5796    rsrcSetList->list.count = elementCnt;
5797    rsrcSetList->list.size = elementCnt * sizeof(SRS_ResourceSet_t *);
5798    rsrcSetList->list.array = NULLP;
5799    DU_ALLOC(rsrcSetList->list.array, rsrcSetList->list.size);
5800    if(!rsrcSetList->list.array)
5801    {
5802       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5803       return RFAILED;
5804    }
5805
5806    for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
5807    {
5808       DU_ALLOC(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
5809       if(!rsrcSetList->list.array[rSetIdx])
5810       {
5811          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5812          return RFAILED;
5813       }
5814    }
5815
5816    rSetIdx = 0;
5817    rsrcSetList->list.array[rSetIdx]->srs_ResourceSetId = SRS_RSET_ID;
5818
5819    /* Fill Resource Id list in resource set */
5820    rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList = NULLP;
5821    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
5822          sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
5823    if(!rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
5824    {
5825       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5826       return RFAILED;
5827    }
5828
5829    elementCnt = 1;
5830    rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
5831    rsrcIdList->list.count = elementCnt;
5832    rsrcIdList->list.size = elementCnt * sizeof(SRS_ResourceId_t *);
5833    rsrcIdList->list.array = NULLP;
5834    DU_ALLOC(rsrcIdList->list.array, rsrcIdList->list.size);
5835    if(!rsrcIdList->list.array)
5836    {
5837       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5838       return RFAILED;
5839    }
5840
5841    for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
5842    {
5843       DU_ALLOC(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
5844       if(!rsrcIdList->list.array[rsrcIdx])
5845       {
5846          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5847          return RFAILED;
5848       }
5849    }
5850
5851    rsrcIdx = 0;
5852    *rsrcIdList->list.array[rsrcIdx] = SRS_RSRC_ID;
5853
5854    /* Fill resource type */
5855    rsrcSetList->list.array[rSetIdx]->resourceType.present = \
5856                                                             SRS_ResourceSet__resourceType_PR_aperiodic;
5857
5858    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic = NULLP;
5859    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
5860          sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
5861    if(!rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic)
5862    {
5863       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5864       return RFAILED;
5865    }
5866    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->aperiodicSRS_ResourceTrigger \
5867       = APERIODIC_SRS_RESRC_TRIGGER;
5868
5869    /* TODO : Fill values for below IEs as expected by Viavi */
5870    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->csi_RS = NULLP;
5871    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->slotOffset = NULLP;
5872
5873
5874    rsrcSetList->list.array[rSetIdx]->usage = SRS_ResourceSet__usage_codebook;
5875    rsrcSetList->list.array[rSetIdx]->alpha = NULLP;
5876    rsrcSetList->list.array[rSetIdx]->p0 = NULLP;
5877    rsrcSetList->list.array[rSetIdx]->pathlossReferenceRS = NULLP;
5878    rsrcSetList->list.array[rSetIdx]->srs_PowerControlAdjustmentStates = NULLP;
5879
5880    return ROK;
5881 }
5882
5883 /*******************************************************************
5884  *
5885  * @brief Builds BWP UL dedicated SRS Config
5886  *
5887  * @details
5888  *
5889  *    Function : BuildBWPUlDedSrsCfg
5890  *
5891  *    Functionality: Builds BWP UL dedicated SRS Config
5892  *
5893  * @params[in] SRS Config 
5894  * @return ROK     - success
5895  *         RFAILED - failure
5896  *
5897  * ****************************************************************/
5898 uint8_t BuildBWPUlDedSrsCfg(SRS_Config_t *srsCfg)
5899 {
5900    srsCfg->srs_ResourceSetToReleaseList = NULLP;
5901    srsCfg->srs_ResourceSetToAddModList = NULLP;
5902    DU_ALLOC(srsCfg->srs_ResourceSetToAddModList, \
5903          sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
5904    if(!srsCfg->srs_ResourceSetToAddModList)
5905    {
5906       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5907       return RFAILED;
5908    }
5909    if(BuildSrsRsrcSetAddModList(srsCfg->srs_ResourceSetToAddModList) != ROK)
5910    {
5911       return RFAILED;
5912    }
5913
5914    srsCfg->srs_ResourceToReleaseList = NULLP;
5915
5916    /* Resource to Add/Modify list */
5917    srsCfg->srs_ResourceToAddModList = NULLP;
5918    DU_ALLOC(srsCfg->srs_ResourceToAddModList, \
5919          sizeof(struct SRS_Config__srs_ResourceToAddModList));
5920    if(!srsCfg->srs_ResourceToAddModList)
5921    {
5922       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5923       return RFAILED;
5924    }
5925
5926    if(BuildSrsRsrcAddModList(srsCfg->srs_ResourceToAddModList) != ROK)
5927    {
5928       return RFAILED;
5929    }
5930    srsCfg->tpc_Accumulation = NULLP;
5931
5932    return ROK;
5933 }
5934
5935
5936
5937 /*******************************************************************
5938  *
5939  * @brief Builds Pusch Serving cell Config
5940  *
5941  * @details
5942  *
5943  *    Function : BuildPuschSrvCellCfg
5944  *
5945  *    Functionality: Builds Pusch Serving cell Config
5946  *
5947  * @params[in] struct UplinkConfig__pusch_ServingCellConfig *puschCfg
5948  *
5949  * @return ROK     - success
5950  *         RFAILED - failure
5951  *
5952  * ****************************************************************/
5953 uint8_t BuildPuschSrvCellCfg(struct UplinkConfig__pusch_ServingCellConfig *puschCfg)
5954 {
5955    puschCfg->present = UplinkConfig__pusch_ServingCellConfig_PR_setup;
5956    puschCfg->choice.setup = NULLP;
5957    DU_ALLOC(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
5958    if(!puschCfg->choice.setup)
5959    {
5960       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5961       return RFAILED;
5962    }
5963
5964    puschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5965    puschCfg->choice.setup->rateMatching = NULLP;
5966    puschCfg->choice.setup->xOverhead = NULLP;
5967    puschCfg->choice.setup->ext1 = NULLP;
5968
5969    DU_ALLOC(puschCfg->choice.setup->ext1, sizeof(struct PUSCH_ServingCellConfig__ext1));
5970    if(!puschCfg->choice.setup->ext1)
5971    {
5972       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5973       return RFAILED;
5974    }
5975
5976    puschCfg->choice.setup->ext1->maxMIMO_Layers = NULLP;
5977    DU_ALLOC(puschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5978    if(!puschCfg->choice.setup->ext1->maxMIMO_Layers)
5979    {
5980       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5981       return RFAILED;
5982    }
5983    *(puschCfg->choice.setup->ext1->maxMIMO_Layers) = PUSCH_MAX_MIMO_LAYERS;
5984
5985    puschCfg->choice.setup->ext1->processingType2Enabled= NULLP;
5986    DU_ALLOC(puschCfg->choice.setup->ext1->processingType2Enabled,sizeof(BOOLEAN_t));
5987    if(!puschCfg->choice.setup->ext1->processingType2Enabled)
5988    {
5989       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5990       return RFAILED;
5991    }
5992    *(puschCfg->choice.setup->ext1->processingType2Enabled) = PUSCH_PROCESS_TYPE2_ENABLED;
5993
5994    return ROK;
5995 }
5996
5997 /*******************************************************************
5998  *
5999  * @brief Builds inital UL BWP
6000  *
6001  * @details
6002  *
6003  *    Function : BuildInitialUlBWP
6004  *
6005  *    Functionality: Builds initial UL BWP
6006  *
6007  * @params[in] BWP_UplinkDedicated_t *ulBwp
6008  * @return ROK     - success
6009  *         RFAILED - failure
6010  *
6011  * ****************************************************************/
6012 uint8_t BuildInitialUlBWP(InitialUlBwp *initUlBwp, BWP_UplinkDedicated_t *ulBwp)
6013 {
6014    PucchCfg *pucchCfg = NULLP;
6015    PuschCfg *puschCfg = NULLP;
6016
6017    if(initUlBwp)
6018    {
6019       if(initUlBwp->pucchPresent)
6020          pucchCfg = &initUlBwp->pucchCfg;
6021       if(initUlBwp->puschPresent)
6022          puschCfg = &initUlBwp->puschCfg;
6023    }
6024
6025    ulBwp->pucch_Config = NULLP;
6026    DU_ALLOC(ulBwp->pucch_Config, sizeof(struct BWP_UplinkDedicated__pucch_Config));
6027    if(!ulBwp->pucch_Config)
6028    {
6029       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6030       return RFAILED;
6031    }
6032
6033    ulBwp->pucch_Config->present = BWP_UplinkDedicated__pucch_Config_PR_setup;
6034    ulBwp->pucch_Config->choice.setup = NULLP;
6035    DU_ALLOC(ulBwp->pucch_Config->choice.setup, sizeof(PUCCH_Config_t));
6036    if(!ulBwp->pucch_Config->choice.setup)
6037    {
6038       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6039       return RFAILED;
6040    }
6041
6042    if(BuildBWPUlDedPucchCfg(pucchCfg, ulBwp->pucch_Config->choice.setup) != ROK)
6043    {
6044       return RFAILED;
6045    }
6046
6047    /* Fill BWP UL dedicated PUSCH config */
6048    ulBwp->pusch_Config = NULLP;
6049    DU_ALLOC(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
6050    if(!ulBwp->pusch_Config)
6051    {
6052       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6053       return RFAILED;
6054    }
6055
6056    ulBwp->pusch_Config->present = BWP_UplinkDedicated__pusch_Config_PR_setup;
6057    ulBwp->pusch_Config->choice.setup = NULLP;
6058    DU_ALLOC(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
6059    if(!ulBwp->pusch_Config->choice.setup)
6060    {
6061       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6062       return RFAILED;
6063    }
6064
6065    if(BuildBWPUlDedPuschCfg(puschCfg, ulBwp->pusch_Config->choice.setup) != ROK)
6066    {
6067       return RFAILED;
6068    }
6069
6070    ulBwp->configuredGrantConfig = NULLP;
6071
6072    /* Fill BPW UL dedicated SRS config */
6073    ulBwp->srs_Config = NULLP;
6074    DU_ALLOC(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
6075    if(!ulBwp->srs_Config)
6076    {
6077       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6078       return RFAILED;
6079    }
6080
6081    ulBwp->srs_Config->present = BWP_UplinkDedicated__srs_Config_PR_setup;
6082    ulBwp->srs_Config->choice.setup = NULLP;
6083    DU_ALLOC(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
6084    if(!ulBwp->srs_Config->choice.setup)
6085    {
6086       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6087       return RFAILED;
6088    }
6089
6090    if(BuildBWPUlDedSrsCfg(ulBwp->srs_Config->choice.setup) != ROK)
6091    {
6092       return RFAILED;   
6093    }
6094
6095    ulBwp->beamFailureRecoveryConfig = NULLP;
6096
6097    return ROK;
6098 }
6099
6100 /*******************************************************************
6101  *
6102  * @brief Builds UL config
6103  * @details
6104  *
6105  *    Function : BuildUlCfg 
6106  *
6107  *    Functionality: Builds UL config in spCellCfgDed
6108  *
6109  * @params[in] UplinkConfig_t *ulCfg
6110  *
6111  * @return ROK     - success
6112  *         RFAILED - failure
6113  *
6114  * ****************************************************************/
6115 uint8_t BuildUlCfg(ServCellRecfgInfo *servCellRecfg, UplinkConfig_t *ulCfg)
6116 {
6117    InitialUlBwp *initUlBwp = NULLP;
6118
6119    if(servCellRecfg)
6120    {
6121       initUlBwp = &servCellRecfg->initUlBwp;
6122    }
6123
6124    ulCfg->initialUplinkBWP = NULLP;
6125    DU_ALLOC(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
6126    if(!ulCfg->initialUplinkBWP)
6127    {
6128       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6129       return RFAILED;
6130    }
6131
6132    if(BuildInitialUlBWP(initUlBwp, ulCfg->initialUplinkBWP) != ROK)
6133    {
6134       return RFAILED;
6135    }
6136
6137    ulCfg->uplinkBWP_ToReleaseList = NULLP;
6138    ulCfg->uplinkBWP_ToAddModList = NULLP;
6139    ulCfg->firstActiveUplinkBWP_Id = NULLP;
6140    DU_ALLOC(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
6141    if(!ulCfg->firstActiveUplinkBWP_Id)
6142    {
6143       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6144       return RFAILED;
6145    }
6146    if(servCellRecfg == NULLP)
6147       *(ulCfg->firstActiveUplinkBWP_Id) = ACTIVE_UL_BWP_ID;
6148    else
6149       *(ulCfg->firstActiveUplinkBWP_Id) = servCellRecfg->firstActvUlBwpId;
6150
6151    ulCfg->pusch_ServingCellConfig = NULLP;
6152    DU_ALLOC(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
6153    if(!ulCfg->pusch_ServingCellConfig)
6154    {
6155       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6156       return RFAILED;
6157    }
6158
6159    if(BuildPuschSrvCellCfg(ulCfg->pusch_ServingCellConfig) != ROK)
6160    {
6161       return RFAILED;
6162    }
6163
6164    ulCfg->carrierSwitching = NULLP;
6165    ulCfg->ext1 = NULLP;
6166    return ROK;
6167 }
6168
6169 /*******************************************************************
6170  *
6171  * @brief Builds PDSCH serving cell config
6172  * @details
6173  *
6174  *    Function : BuildPdschSrvCellCfg
6175  *
6176  *    Functionality: Builds PDSCH serving cell config in spCellCfgDed
6177  *
6178  * @params[in] struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg 
6179  *
6180  * @return ROK     - success
6181  *         RFAILED - failure
6182  *
6183  * ****************************************************************/
6184 uint8_t BuildPdschSrvCellCfg(PdschServCellCfg *pdschServCellDb, struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg)
6185 {
6186    pdschCfg->present =  ServingCellConfig__pdsch_ServingCellConfig_PR_setup;
6187    pdschCfg->choice.setup = NULLP;
6188    DU_ALLOC(pdschCfg->choice.setup, sizeof( struct PDSCH_ServingCellConfig));
6189    if(!pdschCfg->choice.setup)
6190    {
6191       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6192       return RFAILED;
6193    }
6194
6195    /* Code Block Group Transmission */
6196    pdschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
6197    if(pdschServCellDb && (pdschServCellDb->maxCodeBlkGrpPerTb || pdschServCellDb->codeBlkGrpFlushInd))
6198    {
6199       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission, sizeof(struct PDSCH_ServingCellConfig__codeBlockGroupTransmission));
6200       if(pdschCfg->choice.setup->codeBlockGroupTransmission == NULLP)
6201       {
6202          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6203          return RFAILED;
6204       }
6205
6206       pdschCfg->choice.setup->codeBlockGroupTransmission->present = PDSCH_ServingCellConfig__codeBlockGroupTransmission_PR_setup;
6207       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup = NULLP;
6208       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup, sizeof(struct PDSCH_CodeBlockGroupTransmission ));
6209       if(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup == NULLP)
6210       {
6211          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6212          return RFAILED;
6213       }
6214
6215       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock = \
6216          *(pdschServCellDb->maxCodeBlkGrpPerTb);
6217       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator = \
6218          *(pdschServCellDb->codeBlkGrpFlushInd);
6219    }
6220
6221    /* xOverhead */
6222    pdschCfg->choice.setup->xOverhead = NULLP;
6223    if(pdschServCellDb && pdschServCellDb->xOverhead)
6224    {
6225       DU_ALLOC(pdschCfg->choice.setup->xOverhead, sizeof(long));
6226       if(pdschCfg->choice.setup->xOverhead == NULLP)
6227       {
6228          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6229          return RFAILED;
6230       }
6231       *(pdschCfg->choice.setup->xOverhead) = *(pdschServCellDb->xOverhead);
6232    }
6233
6234    /* Number of HARQ processes */
6235    pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH = NULLP;
6236    DU_ALLOC(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH, sizeof(long));
6237    if(!pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH)
6238    {
6239       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6240       return RFAILED;
6241    }
6242
6243    if(pdschServCellDb == NULLP)
6244    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = PDSCH_NUM_HARQ_PROC;
6245    else
6246    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = pdschServCellDb->numHarqProcForPdsch;
6247
6248    pdschCfg->choice.setup->pucch_Cell = NULLP;
6249
6250    /* Extension */
6251    pdschCfg->choice.setup->ext1 = NULLP;
6252    if(pdschServCellDb && pdschServCellDb->maxMimoLayers)
6253    {
6254       DU_ALLOC(pdschCfg->choice.setup->ext1, sizeof(struct PDSCH_ServingCellConfig__ext1));
6255       if(pdschCfg->choice.setup->ext1 == NULLP)
6256       {
6257          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6258          return RFAILED;
6259       }
6260
6261       DU_ALLOC(pdschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
6262       if(pdschCfg->choice.setup->ext1->maxMIMO_Layers == NULLP)
6263       {
6264          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6265          return RFAILED;
6266       }
6267       *(pdschCfg->choice.setup->ext1->maxMIMO_Layers) = *(pdschServCellDb->maxMimoLayers);
6268    }
6269
6270    return ROK;
6271 }
6272
6273 /*******************************************************************
6274  *
6275  * @brief Builds CSI Meas config
6276  * @details
6277  *
6278  *    Function : BuildCsiMeasCfg 
6279  *
6280  *    Functionality: Builds CSI Meas config in spCellCfgDed
6281  *
6282  * @params[in] struct ServingCellConfig__csi_MeasConfig *csiMeasCfg
6283  *
6284  * @return ROK     - success
6285  *         RFAILED - failure
6286  *
6287  * ****************************************************************/
6288 uint8_t BuildCsiMeasCfg(struct ServingCellConfig__csi_MeasConfig *csiMeasCfg)
6289 {
6290
6291    return ROK;
6292 }
6293
6294 /*******************************************************************
6295  *
6296  * @brief Builds DL BWP to add/modify list
6297  * @details
6298  *
6299  *    Function : BuildDlBwpToAddModList
6300  *
6301  *    Functionality: Builds DL BWP to add/modify list
6302  *
6303  * @params[in] ServCellRecfgInfo *servCellRecfg, 
6304  *             struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList
6305  *
6306  * @return ROK     - success
6307  *         RFAILED - failure
6308  *
6309  * ****************************************************************/ 
6310 uint8_t BuildDlBwpToAddModList(ServCellRecfgInfo *servCellRecfg, struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList)
6311 {
6312    uint8_t elementCnt, idx;
6313
6314    elementCnt = servCellRecfg->numDlBwpToAddOrMod;
6315    dlBwpAddModList->list.count = elementCnt;
6316    dlBwpAddModList->list.size = elementCnt * sizeof(struct BWP_Downlink *);
6317    dlBwpAddModList->list.array = NULLP;
6318    DU_ALLOC(dlBwpAddModList->list.array, dlBwpAddModList->list.size);
6319    if(dlBwpAddModList->list.array == NULLP)
6320    {
6321       DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6322       return RFAILED;
6323    }
6324
6325    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6326    {
6327       DU_ALLOC(dlBwpAddModList->list.array[idx], sizeof(BWP_Downlink_t));
6328       if(dlBwpAddModList->list.array[idx] == NULLP)
6329       {
6330          DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6331          return RFAILED;
6332       }
6333    }
6334
6335    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6336    {
6337       dlBwpAddModList->list.array[idx]->bwp_Id = servCellRecfg->dlBwpToAddOrModList[idx].bwpId;
6338       dlBwpAddModList->list.array[idx]->bwp_Common = NULLP;
6339       dlBwpAddModList->list.array[idx]->bwp_Dedicated = NULLP;
6340    }
6341    return ROK;
6342 }
6343
6344 /*******************************************************************
6345  *
6346  * @brief Builds Spcell config dedicated
6347  * @details
6348  *
6349  *    Function : BuildSpCellCfgDed
6350  *
6351  *    Functionality: Builds sp cell config dedicated in spCellCfg
6352  *
6353  * @params[in] ServingCellConfig_t srvCellCfg
6354  *
6355  * @return ROK     - success
6356  *         RFAILED - failure
6357  *
6358  * ****************************************************************/
6359 uint8_t BuildSpCellCfgDed(DuUeCb *ueCb, ServingCellConfig_t *srvCellCfg)
6360 {
6361    ServCellRecfgInfo *servCellRecfg = NULLP;
6362    InitialDlBwp *initDlBwp = NULLP;
6363    PdschServCellCfg *pdschServCellDb = NULLP;
6364
6365    if(ueCb)
6366    {
6367       servCellRecfg = &ueCb->duMacUeCfg.spCellCfg.servCellCfg;
6368       initDlBwp = &servCellRecfg->initDlBwp;
6369       pdschServCellDb = &servCellRecfg->pdschServCellCfg;
6370    }
6371
6372    srvCellCfg->tdd_UL_DL_ConfigurationDedicated = NULLP;
6373
6374    srvCellCfg->initialDownlinkBWP = NULLP;
6375    DU_ALLOC(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
6376    if(!srvCellCfg->initialDownlinkBWP)
6377    {
6378       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6379       return RFAILED;
6380    }
6381
6382    if(BuildInitialDlBWP(initDlBwp, srvCellCfg->initialDownlinkBWP) != ROK)
6383    {
6384       DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6385       return RFAILED;
6386    }
6387
6388    srvCellCfg->downlinkBWP_ToReleaseList = NULLP;
6389
6390    srvCellCfg->downlinkBWP_ToAddModList = NULLP;
6391    if(ueCb && ueCb->duMacUeCfg.spCellCfg.servCellCfg.numDlBwpToAddOrMod)
6392    {
6393       DU_ALLOC(srvCellCfg->downlinkBWP_ToAddModList, sizeof(struct ServingCellConfig__downlinkBWP_ToAddModList));
6394       if(srvCellCfg->downlinkBWP_ToAddModList == NULLP)
6395       {
6396          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6397          return RFAILED;
6398       }
6399
6400       if(BuildDlBwpToAddModList(&ueCb->duMacUeCfg.spCellCfg.servCellCfg, srvCellCfg->downlinkBWP_ToAddModList) != ROK)
6401       {
6402          DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6403          return RFAILED;
6404       }
6405    }
6406
6407    srvCellCfg->firstActiveDownlinkBWP_Id = NULLP;
6408    DU_ALLOC(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
6409    if(!srvCellCfg->firstActiveDownlinkBWP_Id)
6410    {
6411       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6412       return RFAILED;
6413    }
6414    if(ueCb == NULLP)
6415       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6416    else
6417       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.firstActvDlBwpId;
6418
6419    srvCellCfg->bwp_InactivityTimer = NULLP;
6420
6421    srvCellCfg->defaultDownlinkBWP_Id = NULLP;
6422    DU_ALLOC(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
6423    if(!srvCellCfg->defaultDownlinkBWP_Id)
6424    {
6425       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6426       return RFAILED;
6427    }
6428    if(ueCb == NULLP)
6429       *(srvCellCfg->defaultDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6430    else
6431       *(srvCellCfg->defaultDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.defaultDlBwpId;
6432
6433    srvCellCfg->uplinkConfig = NULLP;
6434    DU_ALLOC(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));
6435    if(!srvCellCfg->uplinkConfig)
6436    {
6437       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6438       return RFAILED;
6439    }
6440
6441    if(BuildUlCfg(servCellRecfg, srvCellCfg->uplinkConfig) != ROK)
6442    {
6443       DU_LOG("\nERROR  -->  F1AP : BuildUlCfg failed");
6444       return RFAILED;
6445    }
6446    srvCellCfg->supplementaryUplink = NULLP;
6447    srvCellCfg->pdcch_ServingCellConfig = NULLP;
6448
6449    srvCellCfg->pdsch_ServingCellConfig = NULLP;
6450    DU_ALLOC(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct  ServingCellConfig__pdsch_ServingCellConfig));
6451    if(!srvCellCfg->pdsch_ServingCellConfig)
6452    {
6453       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6454       return RFAILED;
6455    }
6456
6457    if(BuildPdschSrvCellCfg(pdschServCellDb, srvCellCfg->pdsch_ServingCellConfig) != ROK)
6458    {
6459       DU_LOG("\nERROR  -->  F1AP : BuildPdschSrvCellCfg failed");
6460       return RFAILED;
6461    }
6462
6463    srvCellCfg->csi_MeasConfig = NULLP;
6464 #if 0
6465    DU_ALLOC(srvCellCfg->csi_MeasConfig, sizeof(struct   ServingCellConfig__csi_MeasConfig))
6466       if(!srvCellCfg->csi_MeasConfig)
6467       {
6468          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6469          return RFAILED;
6470       }
6471
6472    if(BuildCsiMeasCfg(srvCellCfg->csi_MeasConfig) != ROK)
6473    {
6474       DU_LOG("\nF1AP : BuildCsiMeasCfg failed");
6475       return RFAILED;
6476    }
6477 #endif
6478    srvCellCfg->sCellDeactivationTimer = NULLP;
6479    srvCellCfg->crossCarrierSchedulingConfig = NULLP;
6480    srvCellCfg->tag_Id = TAG_ID;
6481    srvCellCfg->dummy = NULLP;
6482    srvCellCfg->pathlossReferenceLinking = NULLP;
6483    srvCellCfg->servingCellMO = NULLP;
6484    srvCellCfg->ext1 = NULLP;
6485
6486    return ROK;
6487 }
6488
6489 /*******************************************************************
6490  *
6491  * @brief Fills SCS specific carrier list in DL frequency info
6492  *
6493  * @details
6494  *
6495  *    Function : BuildScsSpecificCarrierListDl
6496  *
6497  *    Functionality: Fills SCS specific carrier list in DL frequency info
6498  *
6499  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
6500  *
6501  * @return ROK     - success
6502  *         RFAILED - failure
6503  *
6504  * ****************************************************************/
6505 uint8_t BuildScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
6506 {
6507    uint8_t elementCnt = 0, listIdx = 0;
6508    ScsSpecCarrier duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.dlScsCarrier;
6509
6510    elementCnt = ODU_VALUE_ONE;
6511    scsCarrierList->list.count = elementCnt;
6512    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6513
6514    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6515    if(!scsCarrierList->list.array)
6516    {
6517       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for scs carrier list array \
6518          in BuildScsSpecificCarrierListDl()");
6519       return RFAILED;
6520    }
6521
6522    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6523    {
6524       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6525       if(!scsCarrierList->list.array[listIdx])
6526       {    
6527          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SCS Specific Carrier list array \
6528             element in BuildScsSpecificCarrierListDl()");
6529          return RFAILED;
6530       }    
6531    }
6532
6533    listIdx = 0;
6534    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6535    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6536    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6537
6538    return ROK;
6539 }
6540
6541 /*******************************************************************
6542  *
6543  * @brief Fills DL frequency info in DL config common
6544  *
6545  * @details
6546  *
6547  *    Function : BuildFreqInfoDl
6548  *
6549  *    Functionality: Fills DL frequency info in DL config common
6550  *
6551  * @params[in] Pointer to DownlinkConfigCommon_t
6552  *
6553  * @return ROK     - success
6554  *         RFAILED - failure
6555  *
6556  * ****************************************************************/
6557 uint8_t BuildFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
6558 {
6559    uint8_t freqBandIdx = 0, elementCnt = 0;
6560    DlCfgCommon  dlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg;
6561
6562    /* TODO : Fill SSB Absolute Frequency */
6563    /*
6564       DU_ALLOC(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
6565       if(!frequencyInfoDL->absoluteFrequencySSB)
6566       {
6567       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB Absolute Frequency in BuildFreqInfoDl()");
6568       return RFAILED;
6569       }
6570       frequencyInfoDL->absoluteFrequencySSB = ?;
6571       */
6572
6573    /* NR Multi Frequency Band List */
6574    elementCnt = ODU_VALUE_ONE;
6575    frequencyInfoDL->frequencyBandList.list.count = elementCnt;
6576    frequencyInfoDL->frequencyBandList.list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6577
6578    DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
6579    if(!frequencyInfoDL->frequencyBandList.list.array)
6580    {
6581       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for Frequency Band List array in BuildFreqInfoDl()");
6582       return RFAILED;
6583    }
6584
6585    for(freqBandIdx = 0; freqBandIdx < elementCnt; freqBandIdx++)
6586    {
6587       DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
6588       if(!frequencyInfoDL->frequencyBandList.list.array[freqBandIdx])
6589       {
6590          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoDl()");
6591          return RFAILED;
6592       }
6593    }
6594
6595    freqBandIdx = 0;
6596    *(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx]) = dlCfg.freqBandInd;
6597
6598    /* TODO : Absolute Frequency to Point A */
6599    //frequencyInfoDL->absoluteFrequencyPointA
6600
6601    /* Subcarrier Spacing specifc carrier List */
6602    if((BuildScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList)) != ROK)
6603    {
6604       DU_LOG("\nERROR  -->  DU APP : Failed to fill SCS specific carrier list DL in BuildFreqInfoDl()");
6605       return RFAILED;
6606    }
6607
6608    return ROK;
6609
6610 }
6611
6612 /*******************************************************************
6613  *
6614  * @brief Fills DL config common in Serving cell config common
6615  *
6616  * @details
6617  *
6618  *    Function : BuildDlConfigCommon
6619  *
6620  *    Functionality: Fills DL config common in Serving cell config common
6621  *
6622  * @params[in] Pointer to DownlinkConfigCommon_t
6623  *
6624  * @return ROK     - success
6625  *         RFAILED - failure
6626  *
6627  * ****************************************************************/
6628 uint8_t BuildDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
6629 {
6630    /* DL Frequency Info */
6631    DU_ALLOC(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
6632    if(!dlCfgCommon->frequencyInfoDL)
6633    {
6634       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL frequency info in BuildDlConfigCommon()");
6635       return RFAILED;
6636    }
6637    if((BuildFreqInfoDl(dlCfgCommon->frequencyInfoDL))!= ROK)
6638    {
6639       DU_LOG("\nERROR  --> DU APP : Failed to fill DL frequency info in BuildDlConfigCommon()");
6640       return RFAILED;
6641    }
6642
6643    /* DL BWP config common */
6644    DU_ALLOC(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
6645    if(!dlCfgCommon->initialDownlinkBWP)
6646    {
6647       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL BWP config common in BuildDlConfigCommon()");
6648       return RFAILED;
6649    }
6650    if((BuildBwpDlCommon(dlCfgCommon->initialDownlinkBWP)) != ROK)
6651    {
6652       DU_LOG("\nERROR  --> DU APP : Failed to fill DL DWP config common in BuildDlConfigCommon()");
6653       return RFAILED;
6654    }
6655
6656    return ROK;
6657 }
6658
6659 /*******************************************************************
6660  *
6661  * @brief Fills SCS specific carrier list in UL frequency Info
6662  *
6663  * @details
6664  *
6665  *    Function : BuildScsSpecificCarrierListUl
6666  *
6667  *    Functionality: Fills SCS specific carrier list in UL frequency Info
6668  *
6669  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
6670  *
6671  * @return ROK     - success
6672  *         RFAILED - failure
6673  *
6674  * ****************************************************************/
6675 uint8_t BuildScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
6676 {
6677    uint8_t elementCnt = 0, listIdx = 0; 
6678    ScsSpecCarrier   duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.ulScsCarrier;
6679
6680    elementCnt = ODU_VALUE_ONE;
6681    scsCarrierList->list.count = elementCnt;
6682    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6683
6684    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6685    if(!scsCarrierList->list.array)
6686    {
6687       DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6688       return RFAILED;
6689    }
6690
6691    for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
6692    {
6693       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6694       if(!scsCarrierList->list.array[listIdx])
6695       {    
6696          DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6697          return RFAILED;
6698       }    
6699    }
6700    listIdx = 0; 
6701    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6702    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6703    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6704
6705    return ROK;
6706 }
6707
6708 /*******************************************************************
6709  *
6710  * @brief Fills frequency info in UL config common
6711  *
6712  * @details
6713  *
6714  *    Function : BuildFreqInfoUl
6715  *
6716  *    Functionality: Fills frequency info in UL config common
6717  *
6718  * @params[in] Pointer to FrequencyInfoUL_t
6719  *
6720  * @return ROK     - success
6721  *         RFAILED - failure
6722  *
6723  * ****************************************************************/
6724 uint8_t BuildFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
6725 {
6726    uint8_t elementCnt = 0, listIdx= 0;
6727    UlCfgCommon  ulCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg;
6728
6729    /* NR Multi Frequency Band List */
6730    DU_ALLOC(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
6731    if(!frequencyInfoUL->frequencyBandList)
6732    {
6733       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band list in BuildFreqInfoUl()");
6734       return RFAILED;
6735    }
6736
6737    elementCnt = ODU_VALUE_ONE;
6738    frequencyInfoUL->frequencyBandList->list.count = elementCnt;
6739    frequencyInfoUL->frequencyBandList->list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6740
6741    DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
6742    if(!frequencyInfoUL->frequencyBandList->list.array)
6743    {
6744       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array in BuildFreqInfoUl()");
6745       return RFAILED;
6746    }
6747
6748    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6749    {
6750       DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
6751       if(!frequencyInfoUL->frequencyBandList->list.array[listIdx])
6752       {
6753          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoUl()");
6754          return RFAILED;
6755       }
6756    }
6757
6758    listIdx = 0;
6759    *(frequencyInfoUL->frequencyBandList->list.array[listIdx]) = ulCfg.freqBandInd;
6760
6761    /* TODO : Fill Absolute frequency point A */
6762    /*
6763       DU_ALLOC(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
6764       if(!frequencyInfoUL->absoluteFrequencyPointA)
6765       {
6766       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for absolute frequency point A in BuildFreqInfoUl()");
6767       return RFAILED;
6768       }
6769     *(frequencyInfoUL->absoluteFrequencyPointA) = ?;
6770     */
6771
6772    /* Subcarrier Spacing specifc carrier */
6773    if((BuildScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList)) != ROK) 
6774    {
6775       DU_LOG("\nERROR  --> DU APP : Failed to fill SCS Specific Carrier list UL in BuildFreqInfoUl()");
6776       return RFAILED;
6777    }
6778
6779    /* P-MAX */
6780    DU_ALLOC(frequencyInfoUL->p_Max, sizeof(P_Max_t));
6781    if(!frequencyInfoUL->p_Max)
6782    {
6783       DU_LOG("\nERROR  -->  DU APP : UL Frequency Infoo  memory allocation failure");
6784       return RFAILED;
6785    }
6786    *frequencyInfoUL->p_Max = ulCfg.pMax;
6787
6788    return ROK;
6789 }
6790
6791 /*******************************************************************
6792  *
6793  * @brief Fills UL config common in Serving cell config common
6794  *
6795  * @details
6796  *
6797  *    Function : BuildUlConfigCommon
6798  *
6799  *    Functionality: Fills UL config common in Serving cell config common
6800  *
6801  * @params[in] Pointer to UplinkConfigCommon_t
6802  *
6803  * @return ROK     - success
6804  *         RFAILED - failure
6805  *
6806  * ****************************************************************/
6807 uint8_t BuildUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
6808 {
6809    /* UL Frequency Info */
6810    DU_ALLOC(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
6811    if(!ulCfgCommon->frequencyInfoUL)
6812    {
6813       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for UL frequency info in BuildUlConfigCommon()");
6814       return RFAILED;
6815    }
6816
6817    if((BuildFreqInfoUl(ulCfgCommon->frequencyInfoUL)) != ROK)
6818    {
6819       DU_LOG("\nERROR  -->  DU APP : Failed to fill frequency info UL in BuildUlConfigCommon()");
6820       return RFAILED;
6821    }
6822
6823    /* UL BWP common */
6824    DU_ALLOC(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
6825    if(!ulCfgCommon->initialUplinkBWP)
6826    {
6827       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for initial UL BWP in BuildUlConfigCommon()");
6828       return RFAILED;
6829    }
6830
6831    if((BuildBwpUlCommon(ulCfgCommon->initialUplinkBWP)) != ROK)
6832    {
6833       DU_LOG("\nERROR  -->  DU APP : Failed to fill BWP UL common in BuildUlConfigCommon()");
6834       return RFAILED;
6835    }
6836
6837    /* Time Alignment timer */
6838    ulCfgCommon->dummy = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.timeAlignTimerComm;
6839
6840    return ROK;
6841 }
6842
6843 /*******************************************************************
6844  *
6845  * @brief Fills SSB position in burst in SP cell config common
6846  *
6847  * @details
6848  *
6849  *    Function : BuildSsbPosInBurst
6850  *
6851  *    Functionality: 
6852  *       Fills SSB position in burst in SP cell config common
6853  *
6854  * @params[in] Pointer to struct ServingCellConfigCommon__ssb_PositionsInBurst
6855  *
6856  * @return ROK     - success
6857  *         RFAILED - failure
6858  *
6859  * ****************************************************************/
6860 uint8_t BuildSsbPosInBurst(struct ServingCellConfigCommon__ssb_PositionsInBurst *ssbPosInBurst)
6861 {
6862    uint8_t bitStringSizeInBytes = 0;
6863
6864    ssbPosInBurst->present = ServingCellConfigCommon__ssb_PositionsInBurst_PR_mediumBitmap;
6865
6866    /* As per spec 38.331,in the definition of ServingCellConfigCommon */
6867    bitStringSizeInBytes = 1;
6868    ssbPosInBurst->choice.mediumBitmap.size = bitStringSizeInBytes * sizeof(uint8_t);
6869
6870    DU_ALLOC(ssbPosInBurst->choice.mediumBitmap.buf, ssbPosInBurst->choice.mediumBitmap.size);
6871    if(!ssbPosInBurst->choice.mediumBitmap.buf)
6872    {
6873       DU_LOG("\nERROR  -->  DU APP : Memory Allocation failed for medium bit map buffer in BuildSsbPosInBurst()");
6874       return RFAILED;
6875    }
6876
6877    if((fillBitString(&ssbPosInBurst->choice.mediumBitmap, 0, bitStringSizeInBytes, \
6878                duCfgParam.sib1Params.srvCellCfgCommSib.ssbPosInBurst)) != ROK)
6879    {
6880       DU_LOG("\nERROR  -->  DU APP : Failed to fill medium bit map in BuildSsbPosInBurst()");
6881       return RFAILED;
6882    }
6883
6884    return ROK;
6885 }
6886
6887 /*******************************************************************
6888  *
6889  * @brief Fills SP cell config common in Reconfig with Sync
6890  *
6891  * @details
6892  *
6893  *    Function : BuildSpCellConfigCommon
6894  *
6895  *    Functionality: Fills SP cell config common in Reconfig with Sync
6896  *
6897  * @params[in] Pointer to ServingCellConfigCommon_t
6898  *
6899  * @return ROK     - success
6900  *         RFAILED - failure
6901  *
6902  * ****************************************************************/
6903 uint8_t BuildSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
6904 {
6905    /* Physical Cell Identity */
6906    DU_ALLOC(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
6907    if(!spCellConfigCommon->physCellId)
6908    {
6909       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for physical cell id in BuildSpCellConfigCommon()");
6910       return RFAILED;
6911    } 
6912    *(spCellConfigCommon->physCellId) = NR_PCI;
6913
6914    /* Downlink Config Common */
6915    DU_ALLOC(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
6916    if(!spCellConfigCommon->downlinkConfigCommon)
6917    {
6918       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for DL Config Common in BuildSpCellConfigCommon()");
6919       return RFAILED;
6920    }
6921    if((BuildDlConfigCommon(spCellConfigCommon->downlinkConfigCommon)) != ROK)
6922    {
6923       DU_LOG("\nERROR  -->  DU APP : Failed to fill DL config commin in BuildSpCellConfigCommon()");
6924       return RFAILED;
6925    }
6926
6927    /* Uplinlink Config Common */
6928    DU_ALLOC(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
6929    if(!spCellConfigCommon->uplinkConfigCommon)
6930    {
6931       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for UL Config Common in BuildSpCellConfigCommon()");
6932       return RFAILED;
6933    }
6934    if((BuildUlConfigCommon(spCellConfigCommon->uplinkConfigCommon)) != ROK)
6935    {
6936       DU_LOG("\nERROR  -->  DU APP : Failed to fill UL config commin in BuildSpCellConfigCommon()");
6937       return RFAILED;
6938    }
6939
6940    /* Timing Advance offset */
6941    DU_ALLOC(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
6942    if(!spCellConfigCommon->n_TimingAdvanceOffset)
6943    {
6944       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for Timing Advance Offset in BuildSpCellConfigCommon()");
6945       return RFAILED;
6946    }
6947    *(spCellConfigCommon->n_TimingAdvanceOffset) = ServingCellConfigCommon__n_TimingAdvanceOffset_n0;
6948
6949    /* SSB Position In Burst */
6950    DU_ALLOC(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
6951    if(!spCellConfigCommon->ssb_PositionsInBurst)
6952    {
6953       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Position In Burst in BuildSpCellConfigCommon()");
6954       return RFAILED;
6955    }
6956    if((BuildSsbPosInBurst(spCellConfigCommon->ssb_PositionsInBurst)) != ROK)
6957    {
6958       DU_LOG("\nERROR  -->  DU APP : Failed to fill SSB Position In Burst in BuildSpCellConfigCommon()");
6959       return RFAILED;
6960    }
6961
6962    /* SSB Periodicity in Serving cell */
6963    DU_ALLOC(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
6964    if(!spCellConfigCommon->ssb_periodicityServingCell)
6965    {
6966       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Periodicity serving cell in \
6967          BuildSpCellConfigCommon()");
6968       return RFAILED;
6969    }
6970    *(spCellConfigCommon->ssb_periodicityServingCell) = \
6971       convertSsbPeriodicityValueToEnum(duCfgParam.sib1Params.srvCellCfgCommSib.ssbPrdServingCell);
6972
6973    /* DMRS Type A position */
6974    spCellConfigCommon->dmrs_TypeA_Position = convertDmrsTypeAPosValueToEnum(duCfgParam.macCellCfg.ssbCfg.dmrsTypeAPos);
6975
6976    /* SSB subcarrier spacing */
6977    DU_ALLOC(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
6978    if(!spCellConfigCommon->ssbSubcarrierSpacing)
6979    {
6980       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for sub-carrier spacing in BuildSpCellConfigCommon()");
6981       return RFAILED;
6982    }
6983    *(spCellConfigCommon->ssbSubcarrierSpacing) = duCfgParam.sib1Params.srvCellCfgCommSib.scs;
6984
6985    /* TDD UL-DL configuration common */
6986    DU_ALLOC(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
6987    if(!spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)
6988    {
6989       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for TDD UL-DL config common in BuildSpCellConfigCommon()");
6990       return RFAILED;
6991    }
6992    if((BuildTddUlDlCfgComm(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)) != ROK)
6993    {
6994       DU_LOG("\nERROR  -->  DU APP : Failed to fill TDD UL-DL config common in BuildSpCellConfigCommon()");
6995       return RFAILED;
6996    }
6997
6998    /* SS PBCH Block Power */
6999    spCellConfigCommon->ss_PBCH_BlockPower = duCfgParam.sib1Params.srvCellCfgCommSib.ssPbchBlockPwr;
7000
7001    return ROK;
7002 }
7003
7004 /*******************************************************************
7005  *
7006  * @brief Fills dedicated RACH configuration in Reconfiguration with sync
7007  *
7008  * @details
7009  *
7010  *    Function : BuildRecfgWithSync
7011  *
7012  *    Functionality: 
7013  *       Fills dedicated RACH configuration in Reconfiguration with sync
7014  *
7015  * @params[in] DU UE CB
7016  *             Pointer to Rach config dedicated struct
7017  *
7018  * @return ROK     - success
7019  *         RFAILED - failure
7020  *
7021  * ****************************************************************/
7022 uint8_t BuildRachConfigDedicated(DuUeCb *ueCb, struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
7023 {
7024    uint8_t elementCnt = 0, listIdx = 0;
7025    CFRA_t *cfra = NULLP;
7026    struct CFRA__resources__ssb *ssbResource = NULLP;
7027    RachCfgCommon duRachCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.rachCfg;
7028
7029    rachCfgDed->present = ReconfigurationWithSync__rach_ConfigDedicated_PR_uplink;
7030
7031    /* Uplink */
7032    DU_ALLOC(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
7033    if(!rachCfgDed->choice.uplink)
7034    {
7035       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for RACH uplink configuration in BuildRachConfigDedicated()");
7036       return RFAILED;
7037    }
7038
7039    /* CFRA : Contention free Random Access */
7040    DU_ALLOC(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
7041    if(!rachCfgDed->choice.uplink->cfra)
7042    {
7043       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA in BuildRachConfigDedicated()");
7044       return RFAILED;
7045    }
7046    cfra = rachCfgDed->choice.uplink->cfra;
7047
7048    /* CFRA occassions */
7049    DU_ALLOC(cfra->occasions, sizeof(struct CFRA__occasions));
7050    if(!cfra->occasions)
7051    {
7052       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA occassion in BuildRachConfigDedicated()");
7053       return RFAILED;
7054    }
7055
7056    /* CFRA occassions : RACH generic configuration */
7057    cfra->occasions->rach_ConfigGeneric.prach_ConfigurationIndex = duRachCfg.prachCfgIdx;
7058    cfra->occasions->rach_ConfigGeneric.msg1_FDM = duRachCfg.msg1Fdm;
7059    cfra->occasions->rach_ConfigGeneric.msg1_FrequencyStart = duRachCfg.msg1FreqStart;
7060    cfra->occasions->rach_ConfigGeneric.zeroCorrelationZoneConfig = duRachCfg.zeroCorrZoneCfg;
7061    cfra->occasions->rach_ConfigGeneric.preambleReceivedTargetPower = duRachCfg.preambleRcvdTgtPwr;
7062    cfra->occasions->rach_ConfigGeneric.preambleTransMax = duRachCfg.preambleTransMax;
7063    cfra->occasions->rach_ConfigGeneric.powerRampingStep = duRachCfg.pwrRampingStep;
7064    cfra->occasions->rach_ConfigGeneric.ra_ResponseWindow = duRachCfg.raRspWindow;
7065
7066    /* CFRA occassions : SSB per RACH occasion */
7067    DU_ALLOC(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
7068    if(!cfra->occasions->ssb_perRACH_Occasion)
7069    {
7070       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB per RACH occassion in BuildRachConfigDedicated()");
7071       return RFAILED;
7072    }
7073    *(cfra->occasions->ssb_perRACH_Occasion) = convertCFRASsbPerRachOccasionValueToEnum(duCfgParam.macCellCfg.prachCfg.ssbPerRach);
7074
7075    /* CFRA resource */
7076    cfra->resources.present = CFRA__resources_PR_ssb;
7077
7078    /* CFRA resource : SSB */
7079    DU_ALLOC(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
7080    if(!cfra->resources.choice.ssb)
7081    {
7082       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA resource - SSB in BuildRachConfigDedicated()");
7083       return RFAILED;
7084    }
7085    ssbResource = cfra->resources.choice.ssb;
7086
7087    /* CFRA SSB resource list */
7088    elementCnt = ueCb->cfraResource.numSsb;
7089    ssbResource->ssb_ResourceList.list.count = elementCnt;
7090    ssbResource->ssb_ResourceList.list.size = elementCnt * sizeof(CFRA_SSB_Resource_t *);
7091
7092    DU_ALLOC(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
7093    if(!ssbResource->ssb_ResourceList.list.array)
7094    {
7095       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list in BuildRachConfigDedicated()");
7096       return RFAILED;
7097    }
7098
7099    for(listIdx = 0; listIdx < elementCnt; listIdx++)
7100    {
7101       DU_ALLOC(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
7102       if(!ssbResource->ssb_ResourceList.list.array[listIdx])
7103       {
7104          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list element in BuildRachConfigDedicated()");  
7105          return RFAILED;
7106       }
7107       ssbResource->ssb_ResourceList.list.array[listIdx]->ssb = ueCb->cfraResource.ssbResource[listIdx].ssbIdx;
7108       ssbResource->ssb_ResourceList.list.array[listIdx]->ra_PreambleIndex = ueCb->cfraResource.ssbResource[listIdx].raPreambleIdx;
7109    }
7110
7111    return ROK;
7112 }
7113
7114 /*******************************************************************
7115  *
7116  * @brief Fills reconfiguration with sync in SP cell config
7117  *
7118  * @details
7119  *
7120  *    Function : BuildRecfgWithSync
7121  *
7122  *    Functionality: Fills reconfiguration with sync in SP cell config
7123  *
7124  * @params[in] DU UE CB
7125  *             Pointer to ReconfigurationWithSync_t
7126  *
7127  * @return ROK     - success
7128  *         RFAILED - failure
7129  *
7130  * ****************************************************************/
7131 uint8_t BuildRecfgWithSync(DuUeCb *ueCb, ReconfigurationWithSync_t *recfgWithSync)
7132 {
7133    /* SP Cell Config Common */  
7134    DU_ALLOC(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
7135    if(!recfgWithSync->spCellConfigCommon)
7136    {
7137       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for spCellConfigCommon in BuildRecfgWithSync()");
7138       return RFAILED;
7139    }
7140
7141    if((BuildSpCellConfigCommon(recfgWithSync->spCellConfigCommon)) != ROK)
7142    {
7143       DU_LOG("\nERROR  -->  DU APP : Failed to build SpCellConfigCommon in BuildRecfgWithSync()");
7144       return RFAILED;
7145    }
7146
7147    /* New UE Identity */
7148    recfgWithSync->newUE_Identity = ueCb->crnti;
7149
7150    /* T304 timer */
7151    recfgWithSync->t304 = ReconfigurationWithSync__t304_ms1000;
7152
7153    /* RACH configuration dedicated */
7154    DU_ALLOC(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
7155    if(!recfgWithSync->rach_ConfigDedicated)
7156    {
7157       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for RACH config dedicated in BuildRecfgWithSync()");
7158       return RFAILED;
7159    }
7160
7161    if((BuildRachConfigDedicated(ueCb, recfgWithSync->rach_ConfigDedicated)) != ROK)
7162    {
7163       DU_LOG("\nERROR  -->  DU APP : Failed to build RACH config dedicated in BuildRecfgWithSync()");
7164       return RFAILED;
7165    }
7166
7167    return ROK;
7168 }
7169
7170 /*******************************************************************
7171  *
7172  * @brief Builds Spcell config 
7173  *
7174  * @details
7175  *
7176  *    Function : BuildSpCellCfg 
7177  *
7178  *    Functionality: Builds sp cell config in DuToCuRrcContainer
7179  *
7180  * @params[in] SpCellConfig_t spCellCfg
7181  *
7182  * @return ROK     - success
7183  *         RFAILED - failure
7184  *
7185  * ****************************************************************/
7186 uint8_t BuildSpCellCfg(DuUeCb *ueCb, SpCellConfig_t *spCellCfg)
7187 {
7188    spCellCfg->servCellIndex = NULLP;
7189    DU_ALLOC(spCellCfg->servCellIndex, sizeof(long));
7190    if(!spCellCfg->servCellIndex)
7191    {
7192       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7193       return RFAILED;
7194    }
7195
7196    if(ueCb == NULLP)
7197       *(spCellCfg->servCellIndex) = SERV_CELL_IDX;
7198    else
7199       *(spCellCfg->servCellIndex) = ueCb->duMacUeCfg.spCellCfg.servCellIdx;
7200
7201    spCellCfg->reconfigurationWithSync = NULLP;
7202    if(ueCb && (ueCb->ueState == UE_HANDIN_IN_PROGRESS))
7203    {
7204       DU_ALLOC(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
7205       if(!spCellCfg->reconfigurationWithSync)
7206       {
7207          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7208          return RFAILED;
7209       }
7210
7211       if((BuildRecfgWithSync(ueCb, spCellCfg->reconfigurationWithSync)) != ROK)
7212       {
7213          DU_LOG("\nERROR  -->  F1AP : Building of reconfiguration with sync failed at BuildSpCellCfg");
7214          return RFAILED;
7215       }
7216    }
7217
7218    spCellCfg->rlf_TimersAndConstants = NULLP;
7219    spCellCfg->rlmInSyncOutOfSyncThreshold = NULLP;
7220
7221    DU_ALLOC(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
7222    if(!spCellCfg->rlmInSyncOutOfSyncThreshold)
7223    {
7224       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7225       return RFAILED;
7226    }
7227    *(spCellCfg->rlmInSyncOutOfSyncThreshold) = RLM_SYNC_OUT_SYNC_THRESHOLD;
7228
7229    spCellCfg->spCellConfigDedicated = NULLP;
7230    DU_ALLOC(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
7231    if(!spCellCfg->spCellConfigDedicated)
7232    {
7233       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7234       return RFAILED;
7235    }
7236    if(BuildSpCellCfgDed(ueCb, spCellCfg->spCellConfigDedicated) != ROK)
7237    {
7238       DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfgDed failed");
7239       return RFAILED;
7240    }
7241
7242    return ROK;
7243 }
7244
7245 /*******************************************************************
7246  *
7247  * @brief Builds Phy cell group config 
7248  *
7249  * @details
7250  *
7251  *    Function : BuildPhyCellGrpCfg 
7252  *
7253  *    Functionality: Builds Phy cell group config in DuToCuRrcContainer
7254  *
7255  * @params[in] PhysicalCellGroupConfig_t *phyCellGrpCfg 
7256  *
7257  * @return ROK     - success
7258  *         RFAILED - failure
7259  *
7260  * ****************************************************************/
7261 uint8_t BuildPhyCellGrpCfg(DuUeCb *ueCb, PhysicalCellGroupConfig_t *phyCellGrpCfg)
7262 {
7263    phyCellGrpCfg->harq_ACK_SpatialBundlingPUCCH = NULLP;
7264    phyCellGrpCfg->harq_ACK_SpatialBundlingPUSCH = NULLP;
7265
7266    phyCellGrpCfg->p_NR_FR1 = NULLP;
7267    DU_ALLOC(phyCellGrpCfg->p_NR_FR1, sizeof(long));
7268    if(!phyCellGrpCfg->p_NR_FR1)
7269    {
7270       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhyCellGrpCfg");
7271       return RFAILED;
7272    }
7273
7274    if(ueCb == NULLP)
7275    {
7276       *(phyCellGrpCfg->p_NR_FR1)             = P_NR_FR1;
7277       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = PDSCH_HARQ_ACK_CODEBOOK;
7278    }
7279    else
7280    {
7281       *(phyCellGrpCfg->p_NR_FR1) = ueCb->duMacUeCfg.phyCellGrpCfg.pNrFr1;
7282       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = ueCb->duMacUeCfg.phyCellGrpCfg.pdschHarqAckCodebook;
7283    }
7284
7285    phyCellGrpCfg->tpc_SRS_RNTI = NULLP;
7286    phyCellGrpCfg->tpc_PUCCH_RNTI = NULLP;
7287    phyCellGrpCfg->tpc_PUSCH_RNTI = NULLP;
7288    phyCellGrpCfg->sp_CSI_RNTI = NULLP;
7289    phyCellGrpCfg->cs_RNTI = NULLP;
7290    phyCellGrpCfg->ext1 = NULLP;
7291    phyCellGrpCfg->ext2 = NULLP;
7292
7293    return ROK;
7294 }
7295 #ifdef NR_DRX
7296 /*******************************************************************
7297  *
7298  * @brief fill long cycle offset value of drx
7299  *
7300  * @details
7301  *
7302  *    Function : fillLongCycleOffsetValFromDuCb 
7303  *
7304  *    Functionality: fill long cycle offset value of drx
7305  *
7306  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
7307  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
7308  *
7309  * @return ROK     - success
7310  *         RFAILED - failure
7311  *
7312  * ****************************************************************/
7313 void fillLongCycleOffsetValFromDuCb(DrxLongCycleStartOffset  drxLongCycleStartOffset,\
7314 struct DRX_ConfigRrc__drx_LongCycleStartOffset *drx_LongCycleStartOffset)
7315 {
7316    
7317    drx_LongCycleStartOffset->present = convertLongDrxCycleLengthValueToEnum(drxLongCycleStartOffset.drxLongCycleStartOffsetChoice); 
7318    switch(drx_LongCycleStartOffset->present)
7319    {
7320       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
7321          {
7322             drx_LongCycleStartOffset->choice.ms10 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7323             break;
7324          }
7325       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
7326          {
7327             drx_LongCycleStartOffset->choice.ms20 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7328             break;
7329          }
7330       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
7331          {
7332             drx_LongCycleStartOffset->choice.ms32 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7333             break;
7334          }
7335       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
7336          {
7337             drx_LongCycleStartOffset->choice.ms40 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7338             break;
7339          }
7340       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
7341          {
7342             drx_LongCycleStartOffset->choice.ms60 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7343             break;
7344          }
7345       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
7346          {
7347             drx_LongCycleStartOffset->choice.ms64 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7348             break;
7349          }
7350       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
7351          {
7352             drx_LongCycleStartOffset->choice.ms70 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7353             break;
7354          }
7355       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
7356          {
7357             drx_LongCycleStartOffset->choice.ms80 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7358             break;
7359          }
7360       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
7361          {
7362             drx_LongCycleStartOffset->choice.ms128 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7363             break;
7364          }
7365       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
7366          {
7367             drx_LongCycleStartOffset->choice.ms160 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7368             break;
7369          }
7370       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
7371          {
7372             drx_LongCycleStartOffset->choice.ms256 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7373             break;
7374          }
7375       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
7376          {
7377             drx_LongCycleStartOffset->choice.ms320 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7378             break;
7379          }
7380       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
7381          {
7382             drx_LongCycleStartOffset->choice.ms512 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7383             break;
7384          }
7385       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
7386          {
7387             drx_LongCycleStartOffset->choice.ms640 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7388             break;
7389          }
7390       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
7391          {
7392             drx_LongCycleStartOffset->choice.ms1024 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7393             break;
7394          }
7395       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
7396          {
7397             drx_LongCycleStartOffset->choice.ms1280 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7398             break;
7399          }
7400       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
7401          {
7402             drx_LongCycleStartOffset->choice.ms2048 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7403             break;
7404          }
7405       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
7406          {
7407             drx_LongCycleStartOffset->choice.ms2560 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7408             break;
7409          }
7410       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
7411          {
7412             drx_LongCycleStartOffset->choice.ms5120 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7413             break;
7414          }
7415       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
7416          {
7417             drx_LongCycleStartOffset->choice.ms10240 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7418             break;
7419          }
7420       default :
7421          break;
7422    }
7423 }
7424 /*******************************************************************
7425  *
7426  * @brief Builds drx config IE 
7427  *
7428  * @details
7429  *
7430  *    Function : BuildDrxConfigRrc 
7431  *
7432  *    Functionality: Build drx config in MacCellGrpCfg 
7433  *
7434  * @params[in] struct MAC_CellGroupConfig__drx_ConfigRrc 
7435  *
7436  * @return ROK     - success
7437  *         RFAILED - failure
7438  *
7439  * ****************************************************************/
7440 uint8_t BuildDrxConfigRrc(DuUeCb *ueCb, struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg)
7441 {
7442    drxCfg->present = MAC_CellGroupConfig__drx_ConfigRrc_PR_setup;
7443    DU_ALLOC(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
7444    if(!drxCfg->choice.setup)
7445    {
7446       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7447       return RFAILED;
7448    }
7449    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationTimerValInMs)
7450    {
7451       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds;
7452       drxCfg->choice.setup->drx_onDurationTimer.choice.milliSeconds = convertOnDurationTimerMilliSecondsValueToEnum(ueCb->duMacUeCfg.\
7453       macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationtimerValue.milliSeconds);
7454    }
7455    else
7456    {
7457       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds;
7458       drxCfg->choice.setup->drx_onDurationTimer.choice.subMilliSeconds = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7459       drxOnDurationTimer.onDurationtimerValue.subMilliSeconds;
7460    }
7461    drxCfg->choice.setup->drx_InactivityTimer = convertDrxInactivityTimerValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxInactivityTimer);
7462    drxCfg->choice.setup->drx_HARQ_RTT_TimerDL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerDl;
7463    drxCfg->choice.setup->drx_HARQ_RTT_TimerUL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerUl;
7464    drxCfg->choice.setup->drx_RetransmissionTimerDL = convertDrxRetransmissionTimerDlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7465    drxRetransmissionTimerDl);
7466    drxCfg->choice.setup->drx_RetransmissionTimerUL = convertDrxRetransmissionTimerUlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7467    drxRetransmissionTimerUl);
7468    drxCfg->choice.setup->drx_SlotOffset = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxSlotOffset;
7469    fillLongCycleOffsetValFromDuCb(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxLongCycleStartOffset, &drxCfg->choice.setup->drx_LongCycleStartOffset);
7470    
7471    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrxPres)
7472    {
7473       DU_ALLOC(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));
7474       if(drxCfg->choice.setup->shortDRX)
7475       {
7476          drxCfg->choice.setup->shortDRX->drx_ShortCycle = convertShortDrxCycleLengthValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7477          shortDrx.drxShortCycle);
7478          drxCfg->choice.setup->shortDRX->drx_ShortCycleTimer = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrx.drxShortCycleTimer;
7479       }
7480       else
7481       {
7482          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7483          return RFAILED;
7484       }
7485    }
7486    return ROK;
7487 }
7488 #endif
7489 /*******************************************************************
7490  *
7491  * @brief Builds Mac cell group config 
7492  *
7493  * @details
7494  *
7495  *    Function : BuildMacCellGrpCfg 
7496  *
7497  *    Functionality: Builds Mac cell group config in DuToCuRrcContainer
7498  *
7499  * @params[in] MAC_CellGroupConfig_t *macCellGrpCfg
7500  *
7501  * @return ROK     - success
7502  *         RFAILED - failure
7503  *
7504  * ****************************************************************/
7505 uint8_t BuildMacCellGrpCfg(DuUeCb *ueCb, MAC_CellGroupConfig_t *macCellGrpCfg)
7506 {
7507    macCellGrpCfg->drx_ConfigRrc = NULLP;
7508 #ifdef NR_DRX   
7509    if(ueCb)
7510    {
7511       DU_ALLOC(macCellGrpCfg->drx_ConfigRrc, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
7512       if(!macCellGrpCfg->drx_ConfigRrc)
7513       {
7514          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7515          return RFAILED;
7516       }
7517       if(BuildDrxConfigRrc(ueCb, macCellGrpCfg->drx_ConfigRrc) != ROK)
7518       {
7519          DU_LOG("\nERROR  -->  F1AP : failed to build drx config");
7520          return RFAILED;
7521       }
7522    }
7523 #endif
7524    macCellGrpCfg->schedulingRequestConfig = NULLP;
7525    DU_ALLOC(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
7526    if(!macCellGrpCfg->schedulingRequestConfig)
7527    {
7528       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7529       return RFAILED;
7530    }
7531
7532    if(BuildSchedulingReqConfig(ueCb, macCellGrpCfg->schedulingRequestConfig) != ROK)
7533    {
7534       DU_LOG("\nERROR  -->  F1AP : BuildSchedulingReqConfig failed");
7535       return RFAILED;
7536    }
7537
7538    macCellGrpCfg->bsr_Config = NULLP;
7539    DU_ALLOC(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
7540    if(!macCellGrpCfg->bsr_Config)
7541    {
7542       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7543       return RFAILED;
7544    }
7545
7546    if(BuildBsrConfig(ueCb, macCellGrpCfg->bsr_Config) != ROK)
7547    {
7548       DU_LOG("\nERROR  -->  F1AP : BuildBsrConfig failed");
7549       return RFAILED;
7550    }
7551
7552    macCellGrpCfg->tag_Config = NULLP;
7553    DU_ALLOC(macCellGrpCfg->tag_Config, sizeof(struct TAG_Config));
7554    if(!macCellGrpCfg->tag_Config)
7555    {
7556       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7557       return RFAILED;
7558    }
7559
7560    if(BuildTagConfig(ueCb, macCellGrpCfg->tag_Config) != ROK)
7561    {
7562       DU_LOG("\nERROR  -->  F1AP : BuildTagConfig failed");
7563       return RFAILED;
7564    }
7565
7566    macCellGrpCfg->phr_Config = NULLP;
7567    DU_ALLOC(macCellGrpCfg->phr_Config, sizeof(struct MAC_CellGroupConfig__phr_Config));
7568    if(!macCellGrpCfg->phr_Config)
7569    {
7570       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7571       return RFAILED;
7572    }
7573
7574    if(BuildPhrConfig(ueCb, macCellGrpCfg->phr_Config) != ROK)
7575    {
7576       DU_LOG("\nERROR  -->  F1AP : BuildPhrConfig failed");
7577       return RFAILED;
7578    }
7579
7580    macCellGrpCfg->skipUplinkTxDynamic = false;
7581    macCellGrpCfg->ext1 = NULLP;
7582
7583    return ROK;
7584 }
7585 /*******************************************************************
7586  *
7587  * @brief Frees memeory allocated for SearchSpcToAddModList
7588  *
7589  * @details
7590  *
7591  *    Function : FreeSearchSpcToAddModList
7592  *
7593  *    Functionality: Deallocating memory of SearchSpcToAddModList
7594  *
7595  * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
7596  *
7597  * @return void
7598  *
7599  4221 * ****************************************************************/
7600 void FreeSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
7601 {
7602    uint8_t idx1=0;
7603    uint8_t idx2=0;
7604    struct  SearchSpace *searchSpc=NULLP;
7605
7606    if(searchSpcList->list.array)
7607    {
7608       if(searchSpcList->list.array[idx2])
7609       {
7610          searchSpc = searchSpcList->list.array[idx2];
7611          if(searchSpc->controlResourceSetId)
7612          {
7613             if(searchSpc->monitoringSlotPeriodicityAndOffset)
7614             {
7615                if(searchSpc->monitoringSymbolsWithinSlot)
7616                {
7617                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
7618                   {
7619                      if(searchSpc->nrofCandidates)
7620                      {
7621                         if(searchSpc->searchSpaceType)
7622                         {
7623                            DU_FREE(searchSpc->searchSpaceType->choice.ue_Specific,\
7624                                  sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
7625                            DU_FREE(searchSpc->searchSpaceType, sizeof(struct
7626                                     SearchSpace__searchSpaceType));
7627                         }
7628                         DU_FREE(searchSpc->nrofCandidates,
7629                               sizeof(struct SearchSpace__nrofCandidates));
7630                      }
7631                      DU_FREE(searchSpc->monitoringSymbolsWithinSlot->buf, \
7632                            searchSpc->monitoringSymbolsWithinSlot->size);
7633                   }
7634                   DU_FREE(searchSpc->monitoringSymbolsWithinSlot,
7635                         sizeof(BIT_STRING_t));
7636                }
7637                DU_FREE(searchSpc->monitoringSlotPeriodicityAndOffset, \
7638                      sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
7639             }
7640             DU_FREE(searchSpc->controlResourceSetId,
7641                   sizeof(ControlResourceSetId_t));
7642          }
7643       }
7644       for(idx1 = 0; idx1 < searchSpcList->list.count; idx1++)
7645       {
7646          DU_FREE(searchSpcList->list.array[idx1],
7647                sizeof(struct SearchSpace));
7648       }
7649       DU_FREE(searchSpcList->list.array,searchSpcList->list.size);
7650    }
7651 }
7652 /*******************************************************************
7653  *
7654  * @brief Frees memory allocated for PdschTimeDomAllocList
7655  *
7656  * @details
7657  *
7658  *    Function : FreePdschTimeDomAllocList
7659  *
7660  *    Functionality: Deallocating memory of PdschTimeDomAllocList
7661  *
7662  * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
7663  *
7664  * @return void
7665  *
7666  * ****************************************************************/
7667 void FreePdschTimeDomAllocList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
7668 {
7669    uint8_t idx1=0;
7670
7671    if(timeDomAllocList->choice.setup)
7672    {
7673       if(timeDomAllocList->choice.setup->list.array)
7674       {
7675          for(idx1 = 0; idx1 <timeDomAllocList->choice.setup->list.count ; idx1++)
7676          {
7677             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1]->k0, sizeof(long));
7678             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1],
7679                   sizeof(struct PDSCH_TimeDomainResourceAllocation));
7680          }
7681          DU_FREE(timeDomAllocList->choice.setup->list.array, \
7682                timeDomAllocList->choice.setup->list.size);
7683       }
7684       DU_FREE(timeDomAllocList->choice.setup,\
7685             sizeof(struct PDSCH_TimeDomainResourceAllocationList));
7686    }
7687 }
7688 /*******************************************************************
7689  *
7690  * @brief Frees memory allocated for PuschTimeDomAllocList
7691  *
7692  *@details
7693  *
7694  *    Function : FreePuschTimeDomAllocList
7695  *
7696  *    Functionality: Deallocating memory of PuschTimeDomAllocList
7697  *
7698  * @params[in] PUSCH_Config_t *puschCfg
7699  *
7700  * @return void
7701  *
7702  * ****************************************************************/
7703 void FreePuschTimeDomAllocList(PUSCH_Config_t *puschCfg)
7704 {
7705    uint8_t rsrcListIdx=0;
7706    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
7707
7708    if(puschCfg->pusch_TimeDomainAllocationList)
7709    {
7710       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
7711       if(timeDomAllocList_t->choice.setup)
7712       {
7713          if(timeDomAllocList_t->choice.setup->list.array)
7714          {
7715             for(rsrcListIdx = 0; rsrcListIdx<timeDomAllocList_t->choice.setup->list.count; rsrcListIdx++)
7716             {
7717                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx]->k2, sizeof(long));
7718                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx],\
7719                      sizeof(PUSCH_TimeDomainResourceAllocation_t));
7720             }
7721             DU_FREE(timeDomAllocList_t->choice.setup->list.array, \
7722                   timeDomAllocList_t->choice.setup->list.size);
7723          }
7724          DU_FREE(timeDomAllocList_t->choice.setup, \
7725                sizeof(struct PUSCH_TimeDomainResourceAllocationList));
7726       }
7727       DU_FREE(puschCfg->transformPrecoder, sizeof(long));
7728       DU_FREE(puschCfg->pusch_TimeDomainAllocationList, \
7729             sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
7730    }
7731
7732 }
7733
7734 /*******************************************************************
7735  *
7736  * @brief Frees memory allocated for Dedicated PUCCH config
7737  *
7738  * @details
7739  *
7740  *    Function : FreeBWPUlDedPucchCfg
7741  *
7742  *    Functionality: Deallocating memory of Dedicated PUCCH cfg
7743  *
7744  * @params[in] BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg
7745  *
7746  * @return void
7747  *
7748  * ****************************************************************/
7749 void FreeBWPUlDedPucchCfg(struct BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg)
7750 {
7751    uint8_t k1Idx, rsrcIdx, rsrcSetIdx;
7752    PUCCH_Config_t *pucchCfg = NULLP;
7753    PUCCH_ResourceSet_t *rsrcSet = NULLP;
7754    PUCCH_Resource_t *rsrc = NULLP;
7755
7756    if(ulBwpPucchCfg)
7757    {
7758       if(ulBwpPucchCfg->choice.setup)
7759       {
7760          pucchCfg = ulBwpPucchCfg->choice.setup;
7761
7762          //Free resource set list
7763          if(pucchCfg->resourceSetToAddModList)
7764          {
7765             if(pucchCfg->resourceSetToAddModList->list.array)
7766             {
7767                for(rsrcSetIdx=0; rsrcSetIdx < pucchCfg->resourceSetToAddModList->list.count; rsrcSetIdx++)
7768                {
7769                   rsrcSet = pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx];
7770                   if(rsrcSet->resourceList.list.array)
7771                   {
7772                      for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
7773                      {
7774                         DU_FREE(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
7775                      }
7776                      DU_FREE(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
7777                   }
7778                   DU_FREE(pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
7779                }
7780                DU_FREE(pucchCfg->resourceSetToAddModList->list.array, pucchCfg->resourceSetToAddModList->list.size);
7781             }
7782             DU_FREE(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
7783          }
7784
7785          //Free resource list
7786          if(pucchCfg->resourceToAddModList)
7787          {
7788             if(pucchCfg->resourceToAddModList->list.array)
7789             {
7790                for(rsrcIdx=0; rsrcIdx < pucchCfg->resourceToAddModList->list.count; rsrcIdx++)
7791                {
7792                   rsrc = pucchCfg->resourceToAddModList->list.array[rsrcIdx];
7793                   DU_FREE(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
7794                   DU_FREE(pucchCfg->resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
7795                }
7796                DU_FREE(pucchCfg->resourceToAddModList->list.array, pucchCfg->resourceToAddModList->list.size);
7797             }
7798             DU_FREE(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
7799          }
7800
7801          //PUCCH Format 1
7802          if(pucchCfg->format1)
7803          {
7804             if(pucchCfg->format1->choice.setup)
7805             {
7806                DU_FREE(pucchCfg->format1->choice.setup->nrofSlots, sizeof(long));
7807                DU_FREE(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
7808             }
7809             DU_FREE(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
7810          }
7811          
7812          //DL DATA TO UL ACK
7813          if(pucchCfg->dl_DataToUL_ACK)
7814          {
7815             if(pucchCfg->dl_DataToUL_ACK->list.array)
7816             {
7817                for(k1Idx = 0; k1Idx <  pucchCfg->dl_DataToUL_ACK->list.count; k1Idx++)
7818                {
7819                   DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array[k1Idx], sizeof(long));
7820                }
7821                DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array, pucchCfg->dl_DataToUL_ACK->list.size);
7822             }
7823             DU_FREE(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
7824          }
7825
7826          DU_FREE(ulBwpPucchCfg->choice.setup, sizeof(PUCCH_Config_t));
7827       }
7828       DU_FREE(ulBwpPucchCfg, sizeof(struct BWP_UplinkDedicated__pucch_Config));
7829    }
7830 }
7831
7832 /*******************************************************************
7833  *
7834  * @brief Frees memory allocated for InitialUlBWP
7835  *
7836  * @details
7837  *
7838  *    Function : FreeInitialUlBWP
7839  *
7840  *    Functionality: Deallocating memory of InitialUlBWP
7841  *
7842  * @params[in] BWP_UplinkDedicated_t *ulBwp
7843  *
7844  * @return void
7845  *
7846  * ****************************************************************/
7847 void FreeInitialUlBWP(BWP_UplinkDedicated_t *ulBwp)
7848 {
7849    uint8_t  rSetIdx, rsrcIdx;
7850    SRS_Config_t   *srsCfg = NULLP;
7851    PUSCH_Config_t *puschCfg = NULLP;
7852    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
7853    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
7854    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
7855    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
7856
7857    FreeBWPUlDedPucchCfg(ulBwp->pucch_Config);
7858
7859    if(ulBwp->pusch_Config)
7860    {
7861       if(ulBwp->pusch_Config->choice.setup)
7862       {
7863          puschCfg=ulBwp->pusch_Config->choice.setup;
7864          if(puschCfg->dataScramblingIdentityPUSCH)
7865          {
7866             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
7867             {
7868                FreePuschTimeDomAllocList(puschCfg);
7869                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
7870                if(dmrsUlCfg->choice.setup)
7871                {
7872                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
7873                   {
7874                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
7875                      {
7876                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
7877                               sizeof(long));
7878                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled,
7879                               sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
7880                      }
7881                      DU_FREE(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition,
7882                            sizeof(long));
7883                   }
7884                   DU_FREE(dmrsUlCfg->choice.setup,sizeof(DMRS_UplinkConfig_t));
7885                }
7886                DU_FREE(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, \
7887                      sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
7888             }
7889             DU_FREE(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
7890          }
7891          DU_FREE(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
7892       }
7893       DU_FREE(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
7894
7895       /* Free SRS-Config */
7896       if(ulBwp->srs_Config)
7897       {
7898          if(ulBwp->srs_Config->choice.setup)
7899          {
7900             srsCfg = ulBwp->srs_Config->choice.setup;
7901
7902             /* Free Resource Set to add/mod list */
7903             if(srsCfg->srs_ResourceSetToAddModList)
7904             {
7905                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
7906                if(rsrcSetList->list.array)
7907                {
7908                   rSetIdx = 0;
7909
7910                   /* Free SRS resource Id list in this SRS resource set */
7911                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
7912                   {
7913                      rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
7914
7915                      if(rsrcIdList->list.array)
7916                      {
7917                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
7918                         {
7919                            DU_FREE(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
7920                         }
7921                         DU_FREE(rsrcIdList->list.array, rsrcIdList->list.size);
7922                      }
7923                      DU_FREE(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
7924                            sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
7925                   }
7926
7927                   /* Free resource type info for this SRS resource set */
7928                   DU_FREE(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
7929                         sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
7930
7931                   /* Free memory for each resource set */
7932                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
7933                   {
7934                      DU_FREE(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
7935                   }
7936                   DU_FREE(rsrcSetList->list.array, rsrcSetList->list.size); 
7937                }
7938                DU_FREE(srsCfg->srs_ResourceSetToAddModList, \
7939                      sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
7940             }
7941
7942             /* Free resource to add/modd list */
7943             if(srsCfg->srs_ResourceToAddModList)
7944             {
7945                resourceList = srsCfg->srs_ResourceToAddModList;
7946                if(resourceList->list.array)
7947                {
7948                   rsrcIdx = 0;
7949                   DU_FREE(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2,\
7950                         sizeof(struct SRS_Resource__transmissionComb__n2));
7951                   DU_FREE(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,\
7952                         sizeof(struct SRS_Resource__resourceType__aperiodic));
7953
7954                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
7955                   {
7956                      DU_FREE(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
7957                   }
7958                   DU_FREE(resourceList->list.array, resourceList->list.size);
7959                }
7960                DU_FREE(srsCfg->srs_ResourceToAddModList, \
7961                      sizeof(struct SRS_Config__srs_ResourceToAddModList));
7962             }
7963
7964             DU_FREE(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
7965          }
7966          DU_FREE(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
7967       }
7968    }
7969 }       
7970 /*******************************************************************
7971  *
7972  * @brief Frees memory allocated for initialUplinkBWP
7973  *
7974  * @details
7975  *
7976  *    Function : FreeinitialUplinkBWP
7977  *
7978  *    Functionality: Deallocating memory of initialUplinkBWP
7979  *
7980  * @params[in] UplinkConfig_t *ulCfg
7981  *
7982  * @return void
7983  *         
7984  *
7985  * ****************************************************************/
7986 void FreeinitialUplinkBWP(UplinkConfig_t *ulCfg)
7987 {
7988    BWP_UplinkDedicated_t *ulBwp=NULLP; 
7989    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
7990
7991    if(ulCfg->initialUplinkBWP)
7992    {
7993       ulBwp=ulCfg->initialUplinkBWP;
7994       if(ulCfg->firstActiveUplinkBWP_Id)
7995       {
7996          if(ulCfg->pusch_ServingCellConfig)
7997          {
7998             puschCfg=ulCfg->pusch_ServingCellConfig;
7999             if(puschCfg->choice.setup)
8000             {
8001                if(puschCfg->choice.setup->ext1)
8002                {
8003                   DU_FREE(puschCfg->choice.setup->ext1->\
8004                         processingType2Enabled,sizeof(BOOLEAN_t));
8005                   DU_FREE(puschCfg->choice.setup->ext1->\
8006                         maxMIMO_Layers,sizeof(long));
8007                   DU_FREE(puschCfg->choice.setup->ext1, \
8008                         sizeof(struct PUSCH_ServingCellConfig__ext1));
8009                }
8010                DU_FREE(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
8011             }
8012             DU_FREE(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
8013          }
8014          DU_FREE(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
8015       }
8016       FreeInitialUlBWP(ulBwp);
8017       DU_FREE(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
8018    }
8019 }
8020 /*******************************************************************
8021  *
8022  * @brief Frees emmory allocated for BWPDlDedPdschCfg
8023  *
8024  * @details
8025  *
8026  *    Function : FreeBWPDlDedPdschCfg
8027  *
8028  *    Functionality: Deallocating memory of BWPDlDedPdschCfg
8029  *
8030  * @params[in] BWP_DownlinkDedicated_t *dlBwp
8031  *
8032  * @return void
8033  *
8034  *
8035  * ****************************************************************/
8036 void FreeBWPDlDedPdschCfg(BWP_DownlinkDedicated_t *dlBwp)
8037 {
8038    struct PDSCH_Config *pdschCfg=NULLP;
8039    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
8040    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
8041    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
8042
8043    if(dlBwp->pdsch_Config->choice.setup)
8044    {
8045       pdschCfg=dlBwp->pdsch_Config->choice.setup;
8046       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
8047       {
8048          if(pdschCfg->pdsch_TimeDomainAllocationList)
8049          {
8050             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
8051             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
8052             {
8053                prbBndlType=&pdschCfg->prb_BundlingType;
8054                DU_FREE(prbBndlType->choice.staticBundling,\
8055                      sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
8056                DU_FREE(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
8057             }
8058             FreePdschTimeDomAllocList(timeDomAllocList);
8059             DU_FREE(pdschCfg->pdsch_TimeDomainAllocationList, \
8060                   sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
8061          }
8062          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
8063          if(dmrsDlCfg->choice.setup)
8064          {
8065             DU_FREE(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition,
8066                   sizeof(long));
8067             DU_FREE(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
8068          }
8069          DU_FREE(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, \
8070                sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
8071       }
8072       DU_FREE(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
8073    }
8074 }
8075 /*******************************************************************
8076  *
8077  * @brief Frees emmory allocated for BWPDlDedPdcchCfg
8078  *
8079  * @details
8080  *
8081  *    Function : FreeBWPDlDedPdcchCfg
8082  *
8083  *    Functionality: Deallocating memory of BWPDlDedPdcchCfg
8084  *
8085  * @params[in] BWP_DownlinkDedicated_t *dlBwp
8086  *
8087  * @return void
8088  *         
8089  *
8090  * ****************************************************************/
8091 void FreeBWPDlDedPdcchCfg(BWP_DownlinkDedicated_t *dlBwp)
8092 {
8093    uint8_t idx1=0;
8094    uint8_t idx2=0;
8095    struct PDCCH_Config *pdcchCfg=NULLP;
8096    struct ControlResourceSet *controlRSet=NULLP;
8097    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
8098
8099    if(dlBwp->pdcch_Config->choice.setup)
8100    {
8101       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
8102       if(pdcchCfg->controlResourceSetToAddModList)
8103       {
8104          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
8105          if(controlRSetList->list.array)
8106          {
8107             controlRSet = controlRSetList->list.array[idx2];
8108             if(controlRSet)
8109             {
8110                if(controlRSet->frequencyDomainResources.buf)
8111                {
8112                   if(controlRSet->pdcch_DMRS_ScramblingID)
8113                   {
8114                      if(pdcchCfg->searchSpacesToAddModList)
8115                      {
8116                         FreeSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
8117                         DU_FREE(pdcchCfg->searchSpacesToAddModList, \
8118                               sizeof(struct PDCCH_Config__searchSpacesToAddModList));
8119                      }
8120                      DU_FREE(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
8121                   }
8122                   DU_FREE(controlRSet->frequencyDomainResources.buf, \
8123                         controlRSet->frequencyDomainResources.size);
8124                }
8125             }
8126             for(idx1 = 0; idx1 <controlRSetList->list.count; idx1++)
8127             {
8128                DU_FREE(controlRSetList->list.array[idx1], sizeof(struct ControlResourceSet));
8129             }
8130             DU_FREE(controlRSetList->list.array, controlRSetList->list.size);
8131          }
8132          DU_FREE(pdcchCfg->controlResourceSetToAddModList, \
8133                sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
8134       }
8135       DU_FREE(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
8136    }
8137 }       
8138
8139 /*******************************************************************
8140  *
8141  * @brief Free SCS specific carrier list in DL frequency info
8142  *
8143  * @details
8144  *
8145  *    Function : FreeScsSpecificCarrierListDl
8146  *
8147  *    Functionality: Free SCS specific carrier list in DL frequency info
8148  *
8149  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
8150  *
8151  * @return void
8152  *
8153  * ****************************************************************/
8154 void FreeScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
8155 {
8156    uint8_t listIdx = 0;
8157
8158    if(!scsCarrierList->list.array)
8159    {
8160       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
8161       {
8162          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
8163       }
8164       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
8165    }
8166 }
8167
8168 /*******************************************************************
8169  *
8170  * @brief Free DL frequency info in DL config common
8171  *
8172  * @details
8173  *
8174  *    Function : FreeFreqInfoDl
8175  *
8176  *    Functionality: Free DL frequency info in DL config common
8177  *
8178  * @params[in] Pointer to DownlinkConfigCommon_t
8179  *
8180  * @return void
8181  *
8182  * ****************************************************************/
8183 void FreeFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
8184 {
8185    uint8_t freqBandIdx = 0;
8186
8187    /* SSB Absolute Frequency */
8188    DU_FREE(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
8189
8190    /* NR Multi Frequency Band List */
8191    if(frequencyInfoDL->frequencyBandList.list.array)
8192    {
8193       for(freqBandIdx = 0; freqBandIdx < frequencyInfoDL->frequencyBandList.list.count; freqBandIdx++)
8194       {
8195          DU_FREE(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
8196       }
8197       DU_FREE(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
8198    }
8199
8200    /* Subcarrier Spacing specifc carrier List */
8201    FreeScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList);
8202 }
8203
8204 /*******************************************************************
8205  *
8206  * @brief Free DL config common in Serving cell config common
8207  *
8208  * @details
8209  *
8210  *    Function : FreeDlConfigCommon
8211  *
8212  *    Functionality: Free DL config common in Serving cell config common
8213  *
8214  * @params[in] Pointer to DownlinkConfigCommon_t
8215  *
8216  * @return void
8217  *
8218  * ****************************************************************/
8219 void FreeDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
8220 {
8221    /* DL Frequency Info */
8222    if(dlCfgCommon->frequencyInfoDL)
8223    {
8224       FreeFreqInfoDl(dlCfgCommon->frequencyInfoDL);
8225       DU_FREE(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
8226    }
8227
8228    /* DL BWP config common */
8229    if(dlCfgCommon->initialDownlinkBWP)
8230    {
8231       FreeBwpDlCommon(dlCfgCommon->initialDownlinkBWP);
8232       DU_FREE(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
8233    }
8234 }
8235
8236 /*******************************************************************
8237  *
8238  * @brief Free SCS specific carrier list in UL frequency Info
8239  *
8240  * @details
8241  *
8242  *    Function : FreeScsSpecificCarrierListUl
8243  *
8244  *    Functionality: Free SCS specific carrier list in UL frequency Info
8245  *
8246  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
8247  *
8248  * @return void
8249  *
8250  * ****************************************************************/
8251 void FreeScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
8252 {
8253    uint8_t listIdx = 0;
8254
8255    if(scsCarrierList->list.array)
8256    {
8257       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
8258       {
8259          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
8260       }
8261       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
8262    }
8263 }
8264
8265 /*******************************************************************
8266  *
8267  * @brief Free frequency info in UL config common
8268  *
8269  * @details
8270  *
8271  *    Function : FreeFreqInfoUl
8272  *
8273  *    Functionality: Free frequency info in UL config common
8274  *
8275  * @params[in] Pointer to FrequencyInfoUL_t
8276  *
8277  * @return void
8278  *
8279  * ****************************************************************/
8280 void FreeFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
8281 {
8282    uint8_t listIdx= 0;
8283
8284    /* NR Multi Frequency Band List */
8285    if(!frequencyInfoUL->frequencyBandList)
8286    {
8287       if(frequencyInfoUL->frequencyBandList->list.array)
8288       {
8289          for(listIdx = 0; listIdx < frequencyInfoUL->frequencyBandList->list.count; listIdx++)
8290          {
8291             DU_FREE(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
8292          }
8293          DU_FREE(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
8294       }
8295       DU_FREE(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
8296    }
8297
8298    /* Absolute frequency point A */
8299    DU_FREE(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
8300
8301    /* Subcarrier Spacing specifc carrier */
8302    FreeScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList);
8303
8304    /* P-MAX */
8305    DU_FREE(frequencyInfoUL->p_Max, sizeof(P_Max_t));
8306 }
8307
8308 /*******************************************************************
8309  *
8310  * @brief Free UL config common in Serving cell config common
8311  *
8312  * @details
8313  *
8314  *    Function : FreeUlConfigCommon
8315  *
8316  *    Functionality: Free UL config common in Serving cell config common
8317  *
8318  * @params[in] Pointer to UplinkConfigCommon_t
8319  *
8320  * @return void
8321  *
8322  * ****************************************************************/
8323 void FreeUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
8324 {
8325    /* UL Frequency Info */
8326    if(ulCfgCommon->frequencyInfoUL)
8327    {
8328       FreeFreqInfoUl(ulCfgCommon->frequencyInfoUL);
8329       DU_FREE(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
8330    }
8331
8332    /* UL BWP common */
8333    if(ulCfgCommon->initialUplinkBWP)
8334    {
8335       FreeBwpUlCommon(ulCfgCommon->initialUplinkBWP);
8336       DU_FREE(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
8337    }
8338 }
8339
8340 /*******************************************************************
8341  *
8342  * @brief Free SP cell config common in Reconfig with Sync
8343  *
8344  * @details
8345  *
8346  *    Function : FreeSpCellConfigCommon
8347  *
8348  *    Functionality: Free SP cell config common in Reconfig with Sync
8349  *
8350  * @params[in] Pointer to ServingCellConfigCommon_t
8351  *
8352  * @return void
8353  *
8354  * ****************************************************************/
8355 void FreeSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
8356 {
8357    /* Free Physical cell identity */
8358    DU_FREE(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
8359
8360    /* Free Downlink Config common */
8361    if(spCellConfigCommon->downlinkConfigCommon)
8362    {
8363       FreeDlConfigCommon(spCellConfigCommon->downlinkConfigCommon);
8364       DU_FREE(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
8365    }
8366
8367    /* Free Uplink Config common */
8368    if(spCellConfigCommon->uplinkConfigCommon)
8369    {
8370       FreeUlConfigCommon(spCellConfigCommon->uplinkConfigCommon);
8371       DU_FREE(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
8372    }
8373
8374    /* Free Timing Advance offset */
8375    DU_FREE(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
8376
8377    /* Free SSB Position in Burst */
8378    if(spCellConfigCommon->ssb_PositionsInBurst)
8379    {
8380       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.buf, \
8381          spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.size);
8382       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
8383    }
8384
8385    /* Free SSB Periodicity in Serving cell */
8386    DU_FREE(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
8387
8388    /* Free SSB subcarrier spacing */
8389    DU_FREE(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
8390
8391    /* TDD UL-DL configuration common */
8392    DU_FREE(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
8393 }
8394
8395 /*******************************************************************
8396  *
8397  * @brief Free dedicated RACH configuration in Reconfiguration with sync
8398  *
8399  * @details
8400  *
8401  *    Function : FreeRecfgWithSync
8402  *
8403  *    Functionality:
8404  *       Free dedicated RACH configuration in Reconfiguration with sync
8405  *
8406  * @params[in] Pinter to Rach config dedicated struct
8407  *
8408  * @return void
8409  *
8410  * ****************************************************************/
8411 void FreeRachConfigDedicated(struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
8412 {
8413    uint8_t listIdx = 0;
8414    CFRA_t *cfra = NULLP;
8415    struct CFRA__resources__ssb *ssbResource = NULLP;
8416
8417    /* Uplink */
8418    if(rachCfgDed->choice.uplink)
8419    {
8420       /* CFRA : Contention free Random Access */
8421       if(rachCfgDed->choice.uplink->cfra)
8422       {
8423          cfra = rachCfgDed->choice.uplink->cfra;
8424
8425          /* CFRA occassions */
8426          if(cfra->occasions)
8427          {
8428             /* CFRA occassions : SSB per RACH occasion */
8429             DU_FREE(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
8430             DU_FREE(cfra->occasions, sizeof(struct CFRA__occasions));
8431          }
8432
8433          /* CFRA resource */
8434          cfra->resources.present = CFRA__resources_PR_ssb;
8435
8436          /* CFRA resource : SSB */
8437          if(cfra->resources.choice.ssb)
8438          {
8439             ssbResource = cfra->resources.choice.ssb;
8440
8441             /* CFRA SSB resource list */
8442             if(ssbResource->ssb_ResourceList.list.array)
8443             {
8444                for(listIdx = 0; listIdx < ssbResource->ssb_ResourceList.list.count; listIdx++)
8445                {
8446                   DU_FREE(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
8447                }
8448                DU_FREE(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
8449             }
8450             DU_FREE(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
8451          }
8452          DU_FREE(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
8453       }
8454       DU_FREE(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
8455    }
8456 }
8457
8458 /*******************************************************************
8459  *
8460  * @brief Frees reconfiguration with sync in SP cell config
8461  *
8462  * @details
8463  *
8464  *    Function : FreeRecfgWithSync
8465  *
8466  *    Functionality: Fress reconfiguration with sync in SP cell config
8467  *
8468  * @params[in] Pointer to ReconfigurationWithSync_t
8469  *
8470  * @return void
8471  *
8472  * ****************************************************************/
8473 void FreeRecfgWithSync(ReconfigurationWithSync_t *recfgWithSync)
8474 {
8475    /* Free SP Cell config common */
8476    if(recfgWithSync->spCellConfigCommon)
8477    {
8478       FreeSpCellConfigCommon(recfgWithSync->spCellConfigCommon);
8479       DU_FREE(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
8480    }
8481
8482    /* Free Dedicated RACH configuration */
8483    if(recfgWithSync->rach_ConfigDedicated)
8484    {
8485       FreeRachConfigDedicated(recfgWithSync->rach_ConfigDedicated);
8486       DU_FREE(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
8487    }
8488 }
8489
8490 /*******************************************************************
8491  *
8492  * @brief Frees emmory allocated for DUToCURRCContainer 
8493  *
8494  * @details
8495  *
8496  *    Function : FreeMemDuToCuRrcCont
8497  *
8498  *    Functionality: Deallocating memory of DuToCuRrcContainer
8499  *
8500  * @params[in] DuToCuRRCContainer, DuToCuRRCContainer
8501  *
8502  * @return ROK     - success
8503  *         RFAILED - failure
8504  *
8505  * ****************************************************************/
8506 uint8_t FreeMemDuToCuRrcCont(CellGroupConfigRrc_t *cellGrpCfg)
8507 {
8508    uint8_t idx=0;
8509    SpCellConfig_t *spCellCfg=NULLP;
8510    ServingCellConfig_t *srvCellCfg=NULLP;
8511    BWP_DownlinkDedicated_t *dlBwp=NULLP;
8512    MAC_CellGroupConfig_t *macCellGrpCfg=NULLP;
8513    PhysicalCellGroupConfig_t *phyCellGrpCfg=NULLP;
8514    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList=NULLP;
8515    struct RLC_Config *rlcConfig=NULLP;
8516    struct LogicalChannelConfig *macLcConfig=NULLP;
8517    struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg=NULLP;
8518    struct SchedulingRequestConfig *schedulingRequestConfig=NULLP;
8519    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList=NULLP;
8520    struct TAG_Config *tagConfig=NULLP;
8521    struct TAG_Config__tag_ToAddModList *tagList=NULLP;
8522    struct MAC_CellGroupConfig__phr_Config *phrConfig=NULLP;
8523    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg=NULLP;
8524
8525    rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
8526    if(rlcBearerList)
8527    {
8528       if(rlcBearerList->list.array)
8529       {
8530          for(idx=0; idx<rlcBearerList->list.count; idx++)
8531          {
8532             if(rlcBearerList->list.array[idx])
8533             {  
8534                rlcConfig   = rlcBearerList->list.array[idx]->rlc_Config;
8535                macLcConfig = rlcBearerList->list.array[idx]->mac_LogicalChannelConfig;
8536                if(rlcConfig)
8537                {
8538                   switch(rlcConfig->present)
8539                   {
8540                      case RLC_Config_PR_NOTHING:
8541                         break;
8542
8543                      case RLC_Config_PR_am:
8544                         {
8545                            if(rlcConfig->choice.am)
8546                            {
8547                               DU_FREE(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
8548                               DU_FREE(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
8549                               DU_FREE(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
8550                            }
8551                            break;
8552                         }
8553                      case RLC_Config_PR_um_Bi_Directional:
8554                         {
8555                            if(rlcConfig->choice.um_Bi_Directional)
8556                            {
8557                               DU_FREE(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t)); 
8558                               DU_FREE(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8559                               DU_FREE(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
8560                            }
8561                            break;
8562                         }
8563                      case RLC_Config_PR_um_Uni_Directional_UL:
8564                         {
8565                            if(rlcConfig->choice.um_Uni_Directional_UL)
8566                            {
8567                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8568                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
8569                            }
8570                            break;
8571                         }
8572                      case RLC_Config_PR_um_Uni_Directional_DL:
8573                         {
8574                            if(rlcConfig->choice.um_Uni_Directional_DL )
8575                            {
8576                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8577                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
8578                            }
8579                            break;
8580                         }
8581                   }     
8582                   DU_FREE(rlcConfig, sizeof(struct RLC_Config));
8583                }
8584                DU_FREE(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
8585                if(macLcConfig)
8586                {
8587                   if(macLcConfig->ul_SpecificParameters)
8588                   {
8589                      DU_FREE(macLcConfig->ul_SpecificParameters->schedulingRequestID,   sizeof(SchedulingRequestId_t));
8590                      DU_FREE(macLcConfig->ul_SpecificParameters->logicalChannelGroup,   sizeof(long));
8591                      DU_FREE(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
8592                   }
8593                   DU_FREE(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
8594                }
8595                DU_FREE(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
8596             }   
8597          }
8598          DU_FREE(rlcBearerList->list.array, rlcBearerList->list.size);
8599       }
8600       DU_FREE(cellGrpCfg->rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8601    }
8602
8603    macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
8604    if(macCellGrpCfg)
8605    {
8606       drxCfg = macCellGrpCfg->drx_ConfigRrc;
8607
8608       if(drxCfg)
8609       {
8610           switch(drxCfg->present)
8611           {
8612             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
8613                break;
8614             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
8615             {
8616                if(drxCfg->choice.setup)
8617                {
8618                   DU_FREE(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));  
8619                   DU_FREE(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
8620                }
8621             }
8622             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
8623                break;
8624           }
8625           DU_FREE(drxCfg, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
8626       }
8627       schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig; 
8628       if(schedulingRequestConfig)
8629       {
8630          schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
8631          if(schReqList)
8632          {
8633             if(schReqList->list.array)
8634             {
8635                for(idx=0;idx<schReqList->list.count; idx++)
8636                {
8637                   if(schReqList->list.array[idx])
8638                   {
8639                      DU_FREE(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
8640                      DU_FREE(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
8641                   }
8642                }
8643                DU_FREE(schReqList->list.array, schReqList->list.size);
8644             }
8645             DU_FREE(schedulingRequestConfig->schedulingRequestToAddModList,\
8646                   sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));    }
8647             DU_FREE(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
8648       }
8649       if(macCellGrpCfg->bsr_Config)
8650       {
8651          DU_FREE(macCellGrpCfg->bsr_Config->logicalChannelSR_DelayTimer, sizeof(long));
8652          DU_FREE(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
8653       }
8654       tagConfig = macCellGrpCfg->tag_Config;
8655       if(tagConfig)
8656       {
8657          tagList = tagConfig->tag_ToAddModList;
8658          if(tagList)
8659          {
8660             if(tagList->list.array)
8661             {
8662                for(idx=0; idx<tagList->list.count; idx++)
8663                {
8664                   DU_FREE(tagList->list.array[idx], sizeof(struct TAG));
8665                }
8666                DU_FREE(tagList->list.array, tagList->list.size);
8667             }
8668             DU_FREE(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
8669          }
8670          DU_FREE(tagConfig, sizeof(struct TAG_Config));
8671       }
8672
8673       phrConfig = macCellGrpCfg->phr_Config;
8674       if(phrConfig)
8675       {
8676          DU_FREE(phrConfig->choice.setup, sizeof(struct PHR_Config));
8677          DU_FREE(phrConfig, sizeof(struct MAC_CellGroupConfig__phr_Config));
8678       }
8679
8680       DU_FREE(macCellGrpCfg, sizeof(MAC_CellGroupConfig_t));
8681    }
8682
8683    phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
8684    if(phyCellGrpCfg)
8685    {
8686       DU_FREE(phyCellGrpCfg->p_NR_FR1, sizeof(long));
8687       DU_FREE(phyCellGrpCfg, sizeof(PhysicalCellGroupConfig_t));
8688    }
8689
8690    spCellCfg = cellGrpCfg->spCellConfig;
8691    if(spCellCfg)
8692    {
8693       /* Free serving cell index */
8694       DU_FREE(spCellCfg->servCellIndex, sizeof(long));
8695
8696       /* Free Reconfiguration with sync */
8697       if(spCellCfg->reconfigurationWithSync)
8698       {
8699          FreeRecfgWithSync(spCellCfg->reconfigurationWithSync);
8700          DU_FREE(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
8701       }
8702
8703       /* Free rlmInSyncOutOfSyncThreshold */
8704       DU_FREE(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
8705
8706       /* Free SP Cell config dedicated */
8707       if(spCellCfg->spCellConfigDedicated)
8708       {
8709          srvCellCfg = spCellCfg->spCellConfigDedicated;
8710
8711          /* Free TDD UL-DL config dedicated */
8712          DU_FREE(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
8713
8714          /* Free Initial Downlink BWP */
8715          if(srvCellCfg->initialDownlinkBWP)
8716          {
8717             dlBwp = srvCellCfg->initialDownlinkBWP;
8718
8719             /* Free DL BWP PDCCH Config */
8720             if(dlBwp->pdcch_Config)
8721             {
8722                FreeBWPDlDedPdcchCfg(dlBwp);
8723                DU_FREE(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
8724             }
8725
8726             /* Free DL BWP PDSCH config */
8727             if(dlBwp->pdsch_Config)
8728             {
8729                FreeBWPDlDedPdschCfg(dlBwp);
8730                DU_FREE(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
8731             }
8732             DU_FREE(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
8733          }
8734
8735          /* Free First Active Downlink BWP */
8736          DU_FREE(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
8737
8738          /* Free Default downlink BWP */
8739          DU_FREE(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
8740
8741          /* Free Uplink config */
8742          if(srvCellCfg->uplinkConfig)
8743          {
8744             FreeinitialUplinkBWP(srvCellCfg->uplinkConfig);
8745             DU_FREE(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));  
8746          }
8747
8748          /* Free PDSCH serving cell config */
8749          if(srvCellCfg->pdsch_ServingCellConfig)
8750          {
8751             pdschCfg= srvCellCfg->pdsch_ServingCellConfig;
8752             if(pdschCfg->choice.setup)
8753             {
8754                DU_FREE(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH,sizeof(long));
8755                DU_FREE(pdschCfg->choice.setup, sizeof(struct PDSCH_ServingCellConfig));
8756             }
8757             DU_FREE(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct ServingCellConfig__pdsch_ServingCellConfig));
8758          }
8759
8760          DU_FREE(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
8761       }
8762       DU_FREE(spCellCfg,sizeof(SpCellConfig_t));
8763    }
8764    return ROK;
8765 }
8766
8767 /*******************************************************************
8768  *
8769  * @brief Builds CellGroupConfigRrc for DU To CU RRC Container 
8770  *
8771  * @details
8772  *
8773  *    Function : BuildCellGroupConfigRrc
8774  *
8775  *    Functionality: Builds and copied Cell group config buffer into 
8776  *       DuToCuRrcContainer
8777  *
8778  * @params[in] idx, index in F1AP msg
8779  *             DuToCuRRCContainer, DuToCuRRCContainer
8780  *
8781  * @return ROK     - success
8782  *         RFAILED - failure
8783  *
8784  * ****************************************************************/
8785 uint8_t BuildCellGroupConfigRrc(DuUeCb *ueCb, OCTET_STRING_t *duToCuRrcContainer)
8786 {
8787    uint8_t  ret = ROK;
8788    CellGroupConfigRrc_t  cellGrpCfg;
8789    asn_enc_rval_t        encRetVal;
8790    memset(&cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
8791    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8792
8793    while(true)
8794    {
8795       cellGrpCfg.cellGroupId = CELL_GRP_ID;
8796
8797       cellGrpCfg.rlc_BearerToAddModList = NULLP;
8798       DU_ALLOC(cellGrpCfg.rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8799       if(!cellGrpCfg.rlc_BearerToAddModList)
8800       {
8801          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8802          ret = RFAILED;
8803          break;
8804       }
8805       if(BuildRlcBearerToAddModList(ueCb, cellGrpCfg.rlc_BearerToAddModList) != ROK)
8806       {
8807          DU_LOG("\nERROR  -->  F1AP : BuildRlcBearerToAddModList failed");
8808          ret = RFAILED;
8809          break;
8810       }
8811
8812       cellGrpCfg.rlc_BearerToReleaseList = NULLP;
8813       cellGrpCfg.mac_CellGroupConfig = NULLP;
8814       DU_ALLOC(cellGrpCfg.mac_CellGroupConfig, sizeof(MAC_CellGroupConfig_t));
8815       if(!cellGrpCfg.mac_CellGroupConfig)
8816       {
8817          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8818          ret = RFAILED;
8819          break;
8820       }
8821       if(BuildMacCellGrpCfg(ueCb, cellGrpCfg.mac_CellGroupConfig) != ROK)
8822       {
8823          DU_LOG("\nERROR  -->  F1AP : BuildMacCellGrpCfg failed");
8824          ret = RFAILED;
8825          break;
8826       }
8827
8828       cellGrpCfg.physicalCellGroupConfig = NULLP;
8829       DU_ALLOC(cellGrpCfg.physicalCellGroupConfig, sizeof(PhysicalCellGroupConfig_t));
8830       if(!cellGrpCfg.physicalCellGroupConfig)
8831       {
8832          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8833          ret = RFAILED;
8834          break;
8835       }
8836       if(BuildPhyCellGrpCfg(ueCb, cellGrpCfg.physicalCellGroupConfig) != ROK)
8837       {
8838          DU_LOG("\nERROR  -->  F1AP : BuildPhyCellGrpCfg failed");
8839          ret = RFAILED;
8840          break;
8841       }
8842
8843       cellGrpCfg.spCellConfig = NULLP;
8844       DU_ALLOC(cellGrpCfg.spCellConfig, sizeof(SpCellConfig_t));
8845       if(!cellGrpCfg.spCellConfig)
8846       {
8847          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8848          ret = RFAILED;
8849          break;
8850       }
8851       if(BuildSpCellCfg(ueCb, cellGrpCfg.spCellConfig) != ROK)
8852       {
8853          DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfg failed");
8854          ret = RFAILED;
8855          break;
8856       }
8857
8858       cellGrpCfg.sCellToAddModList = NULLP;
8859       cellGrpCfg.sCellToReleaseList = NULLP;
8860       cellGrpCfg.ext1 = NULLP;
8861
8862       /* encode cellGrpCfg into duToCuRrcContainer */
8863       xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, &cellGrpCfg);
8864       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8865       encBufSize = 0;
8866       encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, &cellGrpCfg, PrepFinalEncBuf, encBuf);
8867       /* Encode results */
8868       if(encRetVal.encoded == ENCODE_FAIL)
8869       {
8870          DU_LOG( "\nERROR  --> F1AP : Could not encode DuToCuRrcContainer (at %s)\n",\
8871                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
8872          ret = RFAILED;
8873          break;
8874       }
8875       else
8876       {
8877          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DuToCuRrcContainer\n");
8878 #ifdef DEBUG_ASN_PRINT
8879          for(int i=0; i< encBufSize; i++)
8880          {
8881             printf("%x",encBuf[i]);
8882          }
8883 #endif
8884       }
8885
8886       duToCuRrcContainer->size = encBufSize;
8887       DU_ALLOC(duToCuRrcContainer->buf, duToCuRrcContainer->size);
8888       if(!duToCuRrcContainer->buf)
8889       {
8890          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDuToCuRrcContainer");
8891          ret = RFAILED;
8892          break;
8893       }
8894       if(ret == ROK)
8895       {
8896          memcpy(duToCuRrcContainer->buf, encBuf, duToCuRrcContainer->size);
8897       }
8898       break;
8899    }
8900    FreeMemDuToCuRrcCont(&cellGrpCfg);
8901    return ret;
8902 }
8903
8904 /*******************************************************************
8905  *
8906  * @brief Free memory allocated in InitialULRRCMessage
8907  *
8908  * @details
8909  *
8910  *    Function : freeInitUlRrcMsgTransfer
8911  *
8912  *    Functionality: Free memory allocated in InitialULRRCMessage
8913  *
8914  * @params[in]F1AP_PDU_t  *f1apMsg)
8915  *
8916  * @return ROK     - success
8917  *         RFAILED - failure
8918  *
8919  * ****************************************************************/
8920
8921 uint8_t freeInitUlRrcMsgTransfer(F1AP_PDU_t  *f1apMsg)
8922 {
8923    uint8_t ieIdx, arrIdx;
8924    InitialULRRCMessageTransfer_t *initULRRCMsg=NULLP;
8925
8926    if(f1apMsg)
8927    {
8928       if(f1apMsg->choice.initiatingMessage)
8929       {
8930          initULRRCMsg = &f1apMsg->choice.initiatingMessage->value.\
8931             choice.InitialULRRCMessageTransfer;
8932          if(initULRRCMsg->protocolIEs.list.array)
8933          {
8934             for(ieIdx = 0; ieIdx < initULRRCMsg->protocolIEs.list.count; ieIdx++)
8935             {
8936                switch(initULRRCMsg->protocolIEs.list.array[ieIdx]->id)
8937                {
8938                   case ProtocolIE_ID_id_NRCGI:
8939                   {
8940                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf)
8941                      {
8942                         if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf)
8943                         {
8944                            DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf,\
8945                            initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.size);
8946                         }
8947                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf,\
8948                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.size);
8949                      }
8950                      break;
8951                   }
8952                   case ProtocolIE_ID_id_RRCContainer:
8953                   {
8954                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
8955                      {
8956                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,\
8957                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
8958                      }
8959                      break;
8960                   }
8961                   case ProtocolIE_ID_id_DUtoCURRCContainer:
8962                   {
8963                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf)
8964                      {
8965                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf,
8966                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.size);
8967                      }
8968                      break;
8969                   }
8970                   default:
8971                      break;
8972                }
8973              }
8974              for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
8975              {
8976                 if(initULRRCMsg->protocolIEs.list.array[arrIdx])
8977                 {
8978                    DU_FREE(initULRRCMsg->protocolIEs.list.array[arrIdx],\
8979                       sizeof(InitialULRRCMessageTransferIEs_t));
8980                 }
8981              }
8982              DU_FREE(initULRRCMsg->protocolIEs.list.array, initULRRCMsg->protocolIEs.list.size);
8983           }
8984          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8985       }
8986       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
8987    }
8988    else
8989    {
8990       DU_LOG("\nERROR  -->  DU_APP : Recevied F1ap Pdu is null at freeInitUlRrcMsgTransfer()");
8991       return RFAILED;
8992    }
8993    return ROK;
8994 }
8995
8996 /*******************************************************************
8997  *
8998  * @brief Builds and sends the InitialULRRCMessage 
8999  *
9000  * @details
9001  *
9002  *    Function : BuildAndSendInitialRrcMsgTransfer 
9003  *
9004  *    Functionality: Constructs the Initial UL RRC Message Transfer and sends
9005  *                   it to the CU through SCTP.
9006  *
9007  * @params[in] 
9008  *
9009  * @return ROK     - success
9010  *         RFAILED - failure
9011  *
9012  * ****************************************************************/
9013 uint8_t BuildAndSendInitialRrcMsgTransfer(uint32_t gnbDuUeF1apId, uint16_t crnti,
9014       uint16_t rrcContSize, uint8_t *rrcContainer)
9015 {
9016    uint8_t   ret;
9017    uint8_t   elementCnt;
9018    uint8_t   ieIdx, cellIdx, ueIdx;
9019    DuUeCb    *duUeCb = NULLP;
9020    asn_enc_rval_t  encRetVal;
9021    F1AP_PDU_t  *f1apMsg = NULLP;
9022    InitialULRRCMessageTransfer_t *initULRRCMsg = NULLP;
9023    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
9024
9025    while(true)
9026    {
9027       DU_LOG("\n INFO   -->  F1AP : Building RRC Setup Request\n");
9028       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
9029       if(f1apMsg == NULLP)
9030       {
9031          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
9032          break;
9033       }
9034       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
9035       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
9036       if(f1apMsg->choice.initiatingMessage == NULLP)
9037       {
9038          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU failed");
9039          break;
9040       }
9041       f1apMsg->choice.initiatingMessage->procedureCode =\
9042                                                         ProcedureCode_id_InitialULRRCMessageTransfer;
9043       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
9044       f1apMsg->choice.initiatingMessage->value.present = \
9045                                                          InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
9046       initULRRCMsg =\
9047                     &f1apMsg->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
9048       elementCnt = 5;
9049       initULRRCMsg->protocolIEs.list.count = elementCnt;
9050       initULRRCMsg->protocolIEs.list.size = \
9051                                             elementCnt * sizeof(InitialULRRCMessageTransferIEs_t *);
9052       /* Initialize the F1Setup members */
9053       DU_ALLOC(initULRRCMsg->protocolIEs.list.array,initULRRCMsg->protocolIEs.list.size);
9054       if(initULRRCMsg->protocolIEs.list.array == NULLP)
9055       {
9056          DU_LOG(" ERROR  -->  F1AP : Memory allocation for\
9057                RRCSetupRequestMessageTransferIEs failed");
9058          break;
9059       }
9060       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
9061       {
9062          DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx],\
9063                sizeof(InitialULRRCMessageTransferIEs_t));
9064          if(initULRRCMsg->protocolIEs.list.array[ieIdx] == NULLP)
9065          {
9066             break;
9067          }
9068       }
9069       ieIdx = 0;
9070       /*GNB DU UE F1AP ID*/
9071       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9072                                                         ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
9073       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  = Criticality_reject;
9074       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
9075                                                                   InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
9076       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
9077
9078
9079       /*NRCGI*/
9080       ieIdx++;
9081       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9082                                                         ProtocolIE_ID_id_NRCGI;
9083       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  =Criticality_reject;
9084       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
9085                                                                   InitialULRRCMessageTransferIEs__value_PR_NRCGI;
9086
9087       ret =\
9088            BuildNrcgi(&initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
9089       if(ret!=ROK)
9090       {
9091          break;
9092       }
9093
9094       /*CRNTI*/
9095       ieIdx++;
9096       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9097                                                         ProtocolIE_ID_id_C_RNTI;
9098       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9099       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9100                                                                  InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
9101       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.C_RNTI = crnti;
9102
9103       /*RRCContainer*/
9104       ieIdx++;
9105       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9106                                                         ProtocolIE_ID_id_RRCContainer;
9107       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9108       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9109                                                                  InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
9110
9111       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size = rrcContSize;
9112       DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,
9113             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size)
9114       if(!initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
9115       {
9116          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRCSetupRequestMessageTransferIEs failed");
9117          break;
9118       
9119       }
9120       memcpy(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, rrcContainer,
9121             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
9122
9123
9124       /*DUtoCURRCContainer*/
9125       ieIdx++;
9126       initULRRCMsg->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCContainer;
9127       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9128       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9129                                                                  InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
9130
9131       for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
9132       {
9133          for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
9134          {
9135             if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
9136                   (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti == crnti))
9137             {
9138                duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
9139             }
9140          }
9141       }
9142
9143       ret = BuildCellGroupConfigRrc(duUeCb, &initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer);
9144       if(ret != ROK)
9145       {
9146          break;
9147       }
9148
9149       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
9150
9151       /* Encode the Intial UL RRC Message transfer as APER */
9152       memset(encBuf, 0, ENC_BUF_MAX_LEN);
9153       encBufSize = 0;
9154       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
9155       /* Encode results */
9156       if(encRetVal.encoded == ENCODE_FAIL)
9157       {
9158          DU_LOG( "\nERROR  --> F1AP : Could not encode Initial UL RRC Message Transfer\
9159                structure (at %s)\n",encRetVal.failed_type ? \
9160                encRetVal.failed_type->name : "unknown");
9161          ret = RFAILED;
9162          break;
9163       }
9164       else
9165       {
9166
9167          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Initial UL RRC\
9168                Message transfer\n");
9169 #ifdef DEBUG_ASN_PRINT
9170          for(int i=0; i< encBufSize; i++)
9171          {
9172             printf("%x",encBuf[i]);
9173          }
9174 #endif
9175       }
9176       /* Sending  msg  */
9177       if(sendF1APMsg() != ROK)
9178       {
9179          DU_LOG("\nERROR  -->  F1AP : Sending Initial UL RRC Message Transfer Failed");
9180          ret = RFAILED;
9181          break;
9182       }
9183       break;
9184    }
9185    freeInitUlRrcMsgTransfer(f1apMsg);
9186    return ret;
9187 }/* End of BuildAndSendInitialRrcMsgTransfer*/
9188
9189 /*****  UE SETUP REQUEST *****/
9190
9191 /******************************************************************
9192 *
9193 * @brief Function to delete the RLC Lc cfg from UE APP DB
9194 *
9195 * @details
9196 *
9197 *  Function : freeRlcLcCfg
9198 *
9199 *  Functionality: Function to delete the RLC Lc cfg from UE APP DB
9200 *
9201 *
9202  *****************************************************************/
9203
9204 void freeRlcLcCfg(RlcBearerCfg *lcCfg)
9205 {
9206    switch(lcCfg->rlcMode)
9207    {
9208       case RLC_AM :
9209          {
9210             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
9211             break;
9212          }
9213       case RLC_UM_BI_DIRECTIONAL :
9214          {
9215             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
9216             break;
9217          }
9218       case RLC_UM_UNI_DIRECTIONAL_UL :
9219          {
9220             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
9221             break;
9222          }
9223       case RLC_UM_UNI_DIRECTIONAL_DL :
9224          {
9225             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
9226             break;
9227          }
9228       default:
9229          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at freeRlcLcCfg()", lcCfg->rlcMode);
9230          break;
9231    }
9232    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
9233 }
9234
9235 /*******************************************************************
9236  *
9237  * @brief Function to free MacLcCfg
9238  *
9239  * @details
9240  *
9241  *    Function : freeMacLcCfg
9242  *
9243  *    Functionality: Function to free MacLcCfg
9244  *
9245  * @params[in] LcCfg *lcCfg,
9246  * @return void
9247  *
9248  * ****************************************************************/
9249
9250 void freeMacLcCfg(LcCfg *lcCfg)
9251 {
9252     /* Deleting DRBQOS */
9253    if(lcCfg->drbQos)
9254    {
9255       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
9256    }
9257    /* Deleting SNSSAI */
9258    if(lcCfg->snssai)
9259    {
9260       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
9261    }
9262 }
9263 /*******************************************************************
9264  *
9265  * @brief Free UE NR Capability received in UE Context setup request
9266  *
9267  * @details
9268  *
9269  *    Function : freeAperDecodeUeNrCapability
9270  *
9271  *    Functionality:  
9272  *       Free UE NR Capability received in UE Context setup request
9273  *
9274  * @params[in] 
9275  * @return ROK     - success
9276  *         RFAILED - failure
9277  *
9278  * ****************************************************************/
9279 void freeAperDecodeUeNrCapability(void *ueNrCapability)
9280 {
9281    uint8_t arrIdx =0;
9282    FeatureSets_t *featureSets =NULLP;
9283    UE_NR_Capability_t *ueNrCap = (UE_NR_Capability_t *)ueNrCapability;
9284
9285    if(ueNrCap->rf_Parameters.supportedBandListNR.list.array)
9286    {
9287       for(arrIdx = 0; arrIdx < ueNrCap->rf_Parameters.supportedBandListNR.list.count; arrIdx++)
9288       {
9289          if(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx])
9290             free(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx]);
9291       }
9292       free(ueNrCap->rf_Parameters.supportedBandListNR.list.array);
9293    }
9294
9295    if(ueNrCap->featureSets)
9296    {
9297       featureSets = ueNrCap->featureSets;
9298       if(featureSets->featureSetsDownlinkPerCC)
9299       {
9300          if(featureSets->featureSetsDownlinkPerCC->list.array)
9301          {
9302             for(arrIdx = 0; arrIdx < featureSets->featureSetsDownlinkPerCC->list.count; arrIdx++)
9303             {
9304                if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx])
9305                {
9306                   if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL)
9307                      free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL);
9308                   free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]);
9309                }
9310             }
9311             free(featureSets->featureSetsDownlinkPerCC->list.array);
9312          }
9313          free(featureSets->featureSetsDownlinkPerCC);
9314       }
9315       if(featureSets->featureSetsUplinkPerCC)
9316       {
9317          if(featureSets->featureSetsUplinkPerCC->list.array)
9318          {
9319             for(arrIdx = 0; arrIdx < featureSets->featureSetsUplinkPerCC->list.count; arrIdx++)
9320             {
9321                if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx])
9322                {
9323                   if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL)
9324                      free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL);
9325                   free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]);
9326                }
9327             }
9328             free(featureSets->featureSetsUplinkPerCC->list.array);
9329          }
9330          free(featureSets->featureSetsUplinkPerCC);
9331       }
9332       free(ueNrCap->featureSets);
9333    }   
9334 }
9335
9336 /*******************************************************************
9337 *
9338 * @brief Function to free PdcchSearchSpcToAddModList
9339          where memory allocated by aper_decoder
9340 *
9341 * @details
9342 *
9343 *    Function : freeAperDecodePdcchSearchSpcToAddModList 
9344 *
9345 *    Functionality: Function to free PdcchSearchSpcToAddModList
9346 *
9347 * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
9348 * @return void
9349 *
9350 * ****************************************************************/
9351
9352 void freeAperDecodePdcchSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
9353 {
9354    uint8_t searchSpcArrIdx=0;
9355    uint8_t searchSpcArrIdx1=0;
9356    struct  SearchSpace *searchSpc=NULLP;
9357
9358
9359    if(searchSpcList->list.array)
9360    {
9361       if(searchSpcList->list.array[searchSpcArrIdx1])
9362       {
9363          searchSpc = searchSpcList->list.array[searchSpcArrIdx1];
9364          if(searchSpc->controlResourceSetId)
9365          {
9366             if(searchSpc->monitoringSlotPeriodicityAndOffset)
9367             {
9368                if(searchSpc->monitoringSymbolsWithinSlot)
9369                {
9370                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
9371                   {
9372                      if(searchSpc->nrofCandidates)
9373                      {
9374                         if(searchSpc->searchSpaceType)
9375                         {
9376                            free(searchSpc->searchSpaceType->choice.ue_Specific);
9377                            free(searchSpc->searchSpaceType);
9378                         }
9379                         free(searchSpc->nrofCandidates);
9380                      }
9381                      free(searchSpc->monitoringSymbolsWithinSlot->buf);
9382                   }
9383                   free(searchSpc->monitoringSymbolsWithinSlot);
9384                }
9385                free(searchSpc->monitoringSlotPeriodicityAndOffset);
9386             }
9387             free(searchSpc->controlResourceSetId);
9388          }
9389       }
9390       for(searchSpcArrIdx = 0; searchSpcArrIdx < searchSpcList->list.count; searchSpcArrIdx++)
9391       {
9392          free(searchSpcList->list.array[searchSpcArrIdx]);
9393       }
9394       free(searchSpcList->list.array);
9395    }
9396 }
9397 /*******************************************************************
9398 *
9399 * @brief Function for free part for the memory allocated by aper_decoder
9400
9401 * @details
9402 *
9403 *    Function : freeAperDecodeBWPDlDedPdcchConfig
9404 *
9405 *    Functionality: Function to free BWPDlDedPdcchConfig
9406 *
9407 * @params[in] 
9408 * @return void
9409 *
9410 * ****************************************************************/
9411
9412
9413 void freeAperDecodeBWPDlDedPdcchConfig(BWP_DownlinkDedicated_t *dlBwp)
9414 {
9415    uint8_t arrIdx1=0;
9416    uint8_t arrIdx2=0;
9417    struct PDCCH_Config *pdcchCfg=NULLP;
9418    struct ControlResourceSet *controlRSet=NULLP;
9419    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
9420    
9421    if(dlBwp->pdcch_Config->choice.setup)
9422    {
9423       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
9424       if(pdcchCfg->controlResourceSetToAddModList)
9425       {
9426          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
9427          if(controlRSetList->list.array)
9428          {
9429             controlRSet = controlRSetList->list.array[arrIdx2];
9430             if(controlRSet)
9431             {
9432                if(controlRSet->frequencyDomainResources.buf)
9433                {
9434                   if(controlRSet->pdcch_DMRS_ScramblingID)
9435                   {
9436                      if(pdcchCfg->searchSpacesToAddModList)
9437                      {
9438                         freeAperDecodePdcchSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
9439                         free(pdcchCfg->searchSpacesToAddModList);
9440                      }
9441                      free(controlRSet->pdcch_DMRS_ScramblingID);
9442                   }
9443                   free(controlRSet->frequencyDomainResources.buf);
9444                }
9445             }
9446             for(arrIdx1 = 0; arrIdx1 <controlRSetList->list.count; arrIdx1++)
9447             {
9448                free(controlRSetList->list.array[arrIdx1]);
9449             }
9450             free(controlRSetList->list.array);
9451          }
9452          free(pdcchCfg->controlResourceSetToAddModList);
9453       }
9454       free(dlBwp->pdcch_Config->choice.setup);
9455    }
9456 }
9457 /*******************************************************************
9458 *
9459 * @brief Function to free PdschTimeDomAllocationList 
9460 *     where the memory allocated by aper_decoder
9461
9462 * @details
9463 *
9464 *    Function : freeAperDecodePdschTimeDomAllocationList
9465 *
9466 *    Functionality: Function to free PdschTimeDomAllocationList
9467 *
9468 * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList 
9469 * @return void
9470 *
9471 * ****************************************************************/
9472
9473
9474 void freeAperDecodePdschTimeDomAllocationList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
9475 {
9476    uint8_t arrIdx=0;
9477
9478    if(timeDomAllocList->choice.setup)
9479    {
9480       if(timeDomAllocList->choice.setup->list.array)
9481       {
9482          for(arrIdx = 0; arrIdx <timeDomAllocList->choice.setup->list.count ; arrIdx++)
9483          {
9484             free(timeDomAllocList->choice.setup->list.array[arrIdx]);
9485          }
9486          free(timeDomAllocList->choice.setup->list.array);
9487       }
9488       free(timeDomAllocList->choice.setup);
9489    }
9490 }
9491
9492 /*******************************************************************
9493 *
9494 * @brief Function to free BWPDlDedPdschConfig 
9495 *        where the memory allocated by aper_decoder
9496 *  
9497 * @details
9498 *
9499 *    Function : freeAperDecodeBWPDlDedPdschConfig 
9500 *
9501 *    Functionality: Function to free BWPDlDedPdschConfig 
9502 *
9503 * @params[in] BWP_DownlinkDedicated_t *dlBwp 
9504 * @return void
9505 *
9506 * ****************************************************************/
9507
9508
9509 void freeAperDecodeBWPDlDedPdschConfig(BWP_DownlinkDedicated_t *dlBwp)
9510 {
9511    struct PDSCH_Config *pdschCfg=NULLP;
9512    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
9513    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
9514    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
9515
9516    if(dlBwp->pdsch_Config->choice.setup)
9517    {
9518       pdschCfg=dlBwp->pdsch_Config->choice.setup;
9519       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
9520       {
9521          if(pdschCfg->pdsch_TimeDomainAllocationList)
9522          {
9523             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
9524             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
9525             {
9526                prbBndlType=&pdschCfg->prb_BundlingType;
9527                free(prbBndlType->choice.staticBundling);
9528                free(pdschCfg->maxNrofCodeWordsScheduledByDCI);
9529             }
9530             freeAperDecodePdschTimeDomAllocationList(timeDomAllocList);
9531             free(pdschCfg->pdsch_TimeDomainAllocationList);
9532          }
9533          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
9534          if(dmrsDlCfg->choice.setup)
9535          {
9536             free(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition);
9537             free(dmrsDlCfg->choice.setup);
9538          }
9539          free(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA);
9540       }
9541       free(dlBwp->pdsch_Config->choice.setup);
9542    }
9543 }
9544 /*******************************************************************
9545 *
9546 * @brief Function to free PuschTimeDomAllocListCfg
9547                  where the memory allocated by aper_decoder
9548 *
9549 * @details
9550 *
9551 *    Function : freeAperDecodePuschTimeDomAllocListCfg
9552 *
9553 *    Functionality: Function to free PuschTimeDomAllocListCfg
9554 *
9555 * @params[in] PUSCH_Config_t *puschCfg 
9556 * @return void
9557 *
9558 * ****************************************************************/
9559
9560
9561 void freeAperDecodePuschTimeDomAllocListCfg(PUSCH_Config_t *puschCfg)
9562 {
9563    uint8_t arrIdx=0;
9564    uint8_t arrIdx1=0;
9565    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
9566
9567    if(puschCfg->pusch_TimeDomainAllocationList)
9568    {
9569       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
9570       if(timeDomAllocList_t->choice.setup)
9571       {
9572          if(timeDomAllocList_t->choice.setup->list.array)
9573          {
9574             free(timeDomAllocList_t->choice.setup->list.array[arrIdx1]->k2);
9575             for(arrIdx = 0; arrIdx<timeDomAllocList_t->choice.setup->list.count; arrIdx++)
9576             {
9577                free(timeDomAllocList_t->choice.setup->list.array[arrIdx]);
9578             }
9579             free(timeDomAllocList_t->choice.setup->list.array);
9580          }
9581          free(timeDomAllocList_t->choice.setup);
9582       }
9583       free(puschCfg->transformPrecoder);
9584       free(puschCfg->pusch_TimeDomainAllocationList);
9585    }
9586 }
9587 /*******************************************************************
9588 *
9589 * @brief Function to free InitialUlBWPConfig where memory allocated by aper_decoder
9590 *
9591 * @details
9592 *
9593 *    Function : freeAperDecodeInitialUlBWPConfig 
9594 *
9595 *    Functionality: Function to free InitialUlBWPConfig
9596 *
9597 * @params[in]  BWP_UplinkDedicated_t *ulBwp
9598 * @return void
9599 *
9600 * ****************************************************************/
9601
9602
9603 void freeAperDecodeInitialUlBWPConfig(BWP_UplinkDedicated_t *ulBwp)
9604 {
9605    uint8_t  rSetIdx =0;
9606    uint8_t  rsrcIdx =0;
9607    SRS_Config_t   *srsCfg = NULLP;
9608    PUSCH_Config_t *puschCfg = NULLP;
9609    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
9610    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
9611    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
9612    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
9613
9614    if(ulBwp->pusch_Config)
9615    {
9616       if(ulBwp->pusch_Config->choice.setup)
9617       {
9618          puschCfg=ulBwp->pusch_Config->choice.setup;
9619          if(puschCfg->dataScramblingIdentityPUSCH)
9620          {
9621             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
9622             {
9623                freeAperDecodePuschTimeDomAllocListCfg(puschCfg);
9624                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
9625                if(dmrsUlCfg->choice.setup)
9626                {
9627                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
9628                   {
9629                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
9630                      {
9631                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0);
9632                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled);
9633                      }
9634                      free(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition);
9635                   }
9636                   free(dmrsUlCfg->choice.setup);
9637                }
9638                free(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA);
9639             }
9640             free(puschCfg->dataScramblingIdentityPUSCH);
9641          }
9642          free(ulBwp->pusch_Config->choice.setup);
9643       }
9644       free(ulBwp->pusch_Config);
9645
9646       /* Free SRS-Config */
9647       if(ulBwp->srs_Config)
9648       {
9649          if(ulBwp->srs_Config->choice.setup)
9650          {
9651             srsCfg = ulBwp->srs_Config->choice.setup;
9652
9653             /* Free Resource Set to add/mod list */
9654             if(srsCfg->srs_ResourceSetToAddModList)
9655             {
9656                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
9657                if(rsrcSetList->list.array)
9658                {
9659                   rSetIdx = 0;
9660
9661                   /* Free SRS resource Id list in this SRS resource set */
9662                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
9663                   {
9664                      rsrcIdList =
9665                         rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
9666
9667                      if(rsrcIdList->list.array)
9668                      {
9669                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count;
9670                               rsrcIdx++)
9671                         {
9672                            free(rsrcIdList->list.array[rsrcIdx]);
9673                         }
9674                         free(rsrcIdList->list.array);
9675                      }
9676                      free(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList);
9677                   }
9678
9679                   /* Free resource type info for this SRS resource set */
9680
9681                   free(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic);
9682
9683                   /* Free memory for each resource set */
9684                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
9685                   {
9686                      free(rsrcSetList->list.array[rSetIdx]);
9687                   }
9688                   free(rsrcSetList->list.array);
9689                }
9690                free(srsCfg->srs_ResourceSetToAddModList);
9691             }
9692
9693             /* Free resource to add/modd list */
9694             if(srsCfg->srs_ResourceToAddModList)
9695             {
9696                resourceList = srsCfg->srs_ResourceToAddModList;
9697                if(resourceList->list.array)
9698                {
9699                   rsrcIdx = 0;
9700
9701                   free(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2);
9702                   free(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic);
9703
9704                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
9705                   {
9706                      free(resourceList->list.array[rsrcIdx]);
9707                   }
9708                   free(resourceList->list.array);
9709                }
9710                free(srsCfg->srs_ResourceToAddModList);
9711             }
9712
9713             free(ulBwp->srs_Config->choice.setup);
9714          }
9715          free(ulBwp->srs_Config);
9716       }
9717    }
9718 }
9719 /*******************************************************************
9720 *
9721 * @brief Function to free initialUplinkBWPConfig where memory allocated by aper_decoder
9722 *
9723 * @details
9724 *
9725 *    Function : freeAperDecodeinitialUplinkBWPConfig
9726 *
9727 *    Functionality: Function to free initialUplinkBWPConfig
9728 *
9729 * @params[in] UplinkConfig_t *ulCfg 
9730 * @return void
9731 *
9732 * ****************************************************************/
9733
9734
9735 void freeAperDecodeinitialUplinkBWPConfig(UplinkConfig_t *ulCfg)
9736 {
9737    BWP_UplinkDedicated_t *ulBwp=NULLP;
9738    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
9739    
9740    if(ulCfg->initialUplinkBWP)
9741    {
9742       ulBwp=ulCfg->initialUplinkBWP;
9743       if(ulCfg->firstActiveUplinkBWP_Id)
9744       {
9745          if(ulCfg->pusch_ServingCellConfig)
9746          {
9747             puschCfg=ulCfg->pusch_ServingCellConfig;
9748             if(puschCfg->choice.setup)
9749             {
9750                if(puschCfg->choice.setup->ext1)
9751                {
9752                   free(puschCfg->choice.setup->ext1->processingType2Enabled);
9753                   free(puschCfg->choice.setup->ext1->maxMIMO_Layers);
9754                   free(puschCfg->choice.setup->ext1);
9755                }
9756                free(puschCfg->choice.setup);
9757             }
9758             free(ulCfg->pusch_ServingCellConfig);
9759          }
9760          free(ulCfg->firstActiveUplinkBWP_Id);
9761       }
9762       freeAperDecodeInitialUlBWPConfig(ulBwp);
9763       free(ulCfg->initialUplinkBWP);
9764    }
9765 }
9766
9767 /*******************************************************************
9768  *
9769  * @brief Function to free DuUeCfg
9770  *
9771  * @details
9772  *
9773  *    Function : freeDuUeCfg
9774  *
9775  *    Functionality: Function to free DuUeCfg
9776  *
9777  * @params[in] DuUeCfg *ueCfg
9778  * @return void
9779  *
9780  * ****************************************************************/
9781 void freeDuUeCfg(UeCtxtActionType actionType, DuUeCfg *ueCfg)
9782 {
9783    uint8_t lcIdx = 0;
9784    uint8_t arrIdx = 0;
9785    SpCellConfig_t *spCellCfg = NULLP;
9786    ServingCellConfig_t *srvCellCfg = NULLP;
9787    BWP_DownlinkDedicated_t *dlBwp = NULLP;
9788    MAC_CellGroupConfig_t *macCellGrpCfg = NULLP;
9789    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
9790    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList = NULLP;
9791    struct RLC_Config *rlcConfig = NULLP;
9792    struct LogicalChannelConfig *macLcConfig = NULLP;
9793    struct SchedulingRequestConfig *schedulingRequestConfig = NULLP;
9794    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList = NULLP;
9795    struct TAG_Config *tagConfig = NULLP;
9796    struct TAG_Config__tag_ToAddModList *tagList = NULLP;
9797    struct MAC_CellGroupConfig__phr_Config *phrConfig = NULLP;
9798    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg = NULLP;
9799    CellGroupConfigRrc_t *cellGrpCfg = ueCfg->cellGrpCfg;
9800   
9801    if(ueCfg->ueNrCapability)
9802    {
9803       freeAperDecodeUeNrCapability(ueCfg->ueNrCapability);
9804       DU_FREE(ueCfg->ueNrCapability, sizeof(UE_NR_Capability_t));
9805       ueCfg->ueNrCapability = NULLP;
9806    }
9807
9808    if(ueCfg->cellGrpCfg)
9809    {
9810       rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
9811       if(rlcBearerList)
9812       {
9813          if(rlcBearerList->list.array)
9814          {
9815             for(arrIdx=0; arrIdx<rlcBearerList->list.count; arrIdx++)
9816             {
9817                if(rlcBearerList->list.array[arrIdx])
9818                {
9819                   rlcConfig   = rlcBearerList->list.array[arrIdx]->rlc_Config;
9820                   macLcConfig = rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig;
9821
9822                   if(rlcBearerList->list.array[arrIdx]->servedRadioBearer)
9823                   {
9824                      free(rlcBearerList->list.array[arrIdx]->servedRadioBearer);
9825                   }
9826                   if(rlcConfig)
9827                   {
9828                      if(rlcConfig->choice.am)
9829                      {
9830                         free(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength);
9831                         free(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength);
9832                         free(rlcConfig->choice.am);
9833                      }
9834                      free(rlcBearerList->list.array[arrIdx]->rlc_Config);
9835                   }
9836                   if(macLcConfig)
9837                   {
9838                      if(macLcConfig->ul_SpecificParameters)
9839                      {
9840                         free(macLcConfig->ul_SpecificParameters->schedulingRequestID);
9841                         free(macLcConfig->ul_SpecificParameters->logicalChannelGroup);
9842                         free(macLcConfig->ul_SpecificParameters);
9843                      }
9844                      free(rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig);
9845                   }
9846                   free(rlcBearerList->list.array[arrIdx]); 
9847                }
9848             }
9849             free(rlcBearerList->list.array);
9850          }
9851          free(cellGrpCfg->rlc_BearerToAddModList);
9852       }
9853
9854       macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
9855       if(macCellGrpCfg)
9856       {
9857          schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig;
9858          if(schedulingRequestConfig)
9859          {
9860             schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
9861             if(schReqList)
9862             {
9863                if(schReqList->list.array)
9864                {
9865                   for(arrIdx=0;arrIdx<schReqList->list.count; arrIdx++)
9866                   {
9867                      if(schReqList->list.array[arrIdx])
9868                      {
9869                         free(schReqList->list.array[arrIdx]->sr_ProhibitTimer); 
9870                         free(schReqList->list.array[arrIdx]);
9871                      }
9872                   }
9873                   free(schReqList->list.array);
9874                }
9875                free(schedulingRequestConfig->schedulingRequestToAddModList);
9876             }
9877             free(macCellGrpCfg->schedulingRequestConfig);
9878          }
9879          if(macCellGrpCfg->bsr_Config)
9880          {
9881             free(macCellGrpCfg->bsr_Config);
9882          }
9883          tagConfig = macCellGrpCfg->tag_Config;
9884          if(tagConfig)
9885          {
9886             tagList = tagConfig->tag_ToAddModList;
9887             if(tagList)
9888             {
9889                if(tagList->list.array)
9890                {
9891                   for(arrIdx=0; arrIdx<tagList->list.count; arrIdx++)
9892                   {
9893                      free(tagList->list.array[arrIdx]);
9894                   }
9895                   free(tagList->list.array);
9896                }
9897                free(tagConfig->tag_ToAddModList);
9898             }
9899             free(tagConfig); 
9900          }
9901
9902          phrConfig = macCellGrpCfg->phr_Config;
9903          if(phrConfig)
9904          {
9905             free(phrConfig->choice.setup); 
9906             free(phrConfig); 
9907          }
9908
9909          free(macCellGrpCfg); 
9910       }
9911
9912       phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
9913       if(phyCellGrpCfg)
9914       {
9915          free(phyCellGrpCfg->p_NR_FR1);
9916          free(phyCellGrpCfg); 
9917       }
9918
9919       spCellCfg = cellGrpCfg->spCellConfig;
9920       if(spCellCfg)
9921       {
9922          if(spCellCfg->servCellIndex)
9923          {
9924             if(spCellCfg->rlmInSyncOutOfSyncThreshold)
9925             {
9926                if(spCellCfg->spCellConfigDedicated)
9927                {
9928                   srvCellCfg = spCellCfg->spCellConfigDedicated;
9929                   if(srvCellCfg->initialDownlinkBWP)
9930                   {
9931                      dlBwp = srvCellCfg->initialDownlinkBWP;
9932                      if(srvCellCfg->firstActiveDownlinkBWP_Id)
9933                      {
9934                         if(srvCellCfg->defaultDownlinkBWP_Id)
9935                         {
9936                            if(srvCellCfg->uplinkConfig)
9937                            {
9938
9939                               if(srvCellCfg->pdsch_ServingCellConfig)
9940                               {
9941                                  pdschCfg=
9942                                     srvCellCfg->pdsch_ServingCellConfig;
9943                                  if(pdschCfg->choice.setup)
9944                                  {
9945
9946                                     free(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH);
9947                                     free(pdschCfg->choice.setup);
9948                                  }
9949
9950                                  free(srvCellCfg->pdsch_ServingCellConfig);
9951                               }
9952
9953                               freeAperDecodeinitialUplinkBWPConfig(srvCellCfg->uplinkConfig);
9954                               free(srvCellCfg->uplinkConfig);
9955                            }
9956                            free(srvCellCfg->defaultDownlinkBWP_Id);
9957                         }
9958
9959                         free(srvCellCfg->firstActiveDownlinkBWP_Id);
9960                      }
9961                      if(dlBwp->pdcch_Config)
9962                      {
9963                         if(dlBwp->pdsch_Config)
9964                         {
9965                            freeAperDecodeBWPDlDedPdschConfig(dlBwp);
9966                            free(dlBwp->pdsch_Config);
9967                         }
9968                         freeAperDecodeBWPDlDedPdcchConfig(dlBwp);
9969                         free(dlBwp->pdcch_Config);
9970                      }
9971                      free(srvCellCfg->initialDownlinkBWP);
9972                   }
9973
9974                   free(spCellCfg->spCellConfigDedicated);
9975                }
9976                free(spCellCfg->rlmInSyncOutOfSyncThreshold);
9977             }
9978             free(spCellCfg->servCellIndex); 
9979          }
9980          free(spCellCfg);
9981       }
9982       DU_FREE(ueCfg->cellGrpCfg, sizeof(CellGroupConfigRrc_t));
9983       ueCfg->cellGrpCfg = NULLP;
9984    }
9985
9986    if(ueCfg->ambrCfg)
9987    {
9988       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCfg->ambrCfg, sizeof(AmbrCfg));
9989    }
9990
9991    if(actionType != UE_CTXT_CFG_QUERY)
9992    {
9993       for(lcIdx = 0; lcIdx < ueCfg->numRlcLcs; lcIdx++)
9994       {
9995          freeRlcLcCfg(&ueCfg->rlcLcCfg[lcIdx].rlcBearerCfg);
9996       }
9997    }
9998
9999    for(lcIdx = 0; lcIdx < ueCfg->numMacLcs; lcIdx++)
10000    {
10001       freeMacLcCfg(&ueCfg->macLcCfg[lcIdx].lcConfig);
10002    }
10003
10004    for(lcIdx = 0; lcIdx < ueCfg->numDrb; lcIdx++)
10005    {
10006       DU_FREE(ueCfg->upTnlInfo[lcIdx].tnlCfg1, sizeof(GtpTnlCfg));
10007    }
10008 }
10009
10010 /*******************************************************************
10011  *
10012  * @brief Function to free UecontextSetupDb
10013  *
10014  * @details
10015  *
10016  *    Function : freeF1UeDb
10017  *
10018  *    Functionality: Function to free UecontextSetupDb
10019  *
10020  * @params[in] UecontextSetupDb *
10021  * @return void
10022  *
10023  * ****************************************************************/
10024
10025 void freeF1UeDb(F1UeContextSetupDb *f1UeDb)
10026 {
10027    
10028    if(f1UeDb->dlRrcMsg)
10029    {
10030       if(f1UeDb->dlRrcMsg->rrcMsgPdu)
10031       {
10032         //DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,\
10033                f1UeDb->dlRrcMsg->rrcMsgPdu, f1UeDb->dlRrcMsg->rrcMsgSize);
10034       }
10035       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
10036    }
10037    freeDuUeCfg(f1UeDb->actionType, &f1UeDb->duUeCfg);
10038    memset(f1UeDb, 0, sizeof(F1UeContextSetupDb));
10039    DU_FREE(f1UeDb, sizeof(F1UeContextSetupDb));
10040 }
10041
10042 /*******************************************************************
10043  *
10044  * @brief Function to build Am cfg Info
10045  *
10046  * @details
10047  *
10048  *    Function : extractRlcAmCfg
10049  *
10050  *    Functionality: Function to build Am cfg Info
10051  *
10052  * @params[in] AmBearerCfg *
10053  *             void *
10054  *
10055  * @return ROK/RFAILED
10056  *
10057  * ****************************************************************/
10058
10059 void extractRlcAmCfg(AmBearerCfg *amCfgToSet, struct RLC_Config__am *rlcAmCfg)
10060 {
10061    if(rlcAmCfg)
10062    {
10063       /* UL AM */
10064       if(rlcAmCfg->dl_AM_RLC.sn_FieldLength)
10065       {
10066          amCfgToSet->ulAmCfg.snLenUl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->dl_AM_RLC.sn_FieldLength));
10067          /*TODO: Check the timer value when sent by real CU */
10068          amCfgToSet->ulAmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_Reassembly); 
10069          amCfgToSet->ulAmCfg.statProhTmr = convertProhibitTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_StatusProhibit);
10070       }
10071
10072       /* DL AM */
10073       if(rlcAmCfg->ul_AM_RLC.sn_FieldLength)
10074       {
10075          amCfgToSet->dlAmCfg.snLenDl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->ul_AM_RLC.sn_FieldLength));
10076          amCfgToSet->dlAmCfg.pollRetxTmr = covertPollRetxTmrEnumToValue(rlcAmCfg->ul_AM_RLC.t_PollRetransmit);
10077          amCfgToSet->dlAmCfg.pollPdu   = covertPollPduEnumToValue(rlcAmCfg->ul_AM_RLC.pollPDU);
10078          amCfgToSet->dlAmCfg.pollByte  = covertPollByteEnumToValue(rlcAmCfg->ul_AM_RLC.pollByte);
10079          amCfgToSet->dlAmCfg.maxRetxTh = covertMaxRetxEnumToValue(rlcAmCfg->ul_AM_RLC.maxRetxThreshold);
10080       }
10081    }
10082 }
10083
10084 /*******************************************************************
10085  *
10086  * @brief Function to build Um Bi Info
10087  *
10088  * @details
10089  *
10090  *    Function : extractRlcUmBiCfg
10091  *
10092  *    Functionality: Function to build Um Bi Info
10093  *
10094  * @params[in] UmBiDirBearerCfg *
10095  *             void *
10096  *
10097  * @return ROK/RFAILED
10098  *
10099  * ****************************************************************/
10100
10101 void extractRlcUmBiCfg(UmBiDirBearerCfg *umBiCfgToSet, struct RLC_Config__um_Bi_Directional *rlcBiCfg)
10102 {
10103    if(rlcBiCfg)
10104    {
10105       /* UL UM BI DIR Cfg */
10106       if(rlcBiCfg->dl_UM_RLC.sn_FieldLength)
10107       {
10108          umBiCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->dl_UM_RLC.sn_FieldLength));
10109          umBiCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcBiCfg->dl_UM_RLC.t_Reassembly);
10110       }
10111
10112       /* DL UM BI DIR Cfg */
10113       if(rlcBiCfg->ul_UM_RLC.sn_FieldLength)
10114          umBiCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->ul_UM_RLC.sn_FieldLength));
10115    }
10116 }
10117
10118 /*******************************************************************
10119  *
10120  * @brief Function to build Um Ul Info
10121  *
10122  * @details
10123  *
10124  *    Function : extractRlcUmUlCfg
10125  *
10126  *    Functionality: Function to build Um Ul Info
10127  *
10128  * @params[in] UmUniDirUlBearerCfg *
10129  *             void *
10130  *
10131  * @return ROK/RFAILED
10132  *
10133  * ****************************************************************/
10134
10135 void extractRlcUmUlCfg(UmUniDirUlBearerCfg *umUlCfgToSet, struct RLC_Config__um_Uni_Directional_DL *umUlCfg)
10136 {
10137    if(umUlCfg)
10138    {
10139       if(umUlCfg->dl_UM_RLC.sn_FieldLength)
10140       {
10141          umUlCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umUlCfg->dl_UM_RLC.sn_FieldLength));
10142          umUlCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(umUlCfg->dl_UM_RLC.t_Reassembly);
10143       }
10144    }
10145 }
10146
10147 /*******************************************************************
10148  *
10149  * @brief Function to build Um Uni Dl Info
10150  *
10151  * @details
10152  *
10153  *    Function : extractRlcUmDlCfg
10154  *
10155  *    Functionality: Function to build Um Uni Dl Info
10156  *
10157  * @params[in] UmUniDirDlBearerCfg *
10158  *             void *
10159  *
10160  * @return ROK/RFAILED
10161  *
10162  * ****************************************************************/
10163 void extractRlcUmDlCfg(UmUniDirDlBearerCfg *umDlCfgToSet, struct RLC_Config__um_Uni_Directional_UL *umDlCfg)
10164 {
10165    if(umDlCfg)
10166    {
10167       if(umDlCfg->ul_UM_RLC.sn_FieldLength)
10168          umDlCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umDlCfg->ul_UM_RLC.sn_FieldLength));
10169    }
10170 }
10171
10172 /*******************************************************************
10173  *
10174  * @brief Function to extractRlcModeCfg
10175  *
10176  * @details
10177  *
10178  *    Function : extractRlcModeCfg
10179  *
10180  *    Functionality: Function to extractRlcModeCfg
10181  *
10182  * @params[in] RLC_Config_t *
10183  *             RlcBearerCfg *
10184  *             void  *    
10185  * @return ROK/RFAILED
10186  *
10187  * ****************************************************************/
10188 void extractRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *rlcDbCfg, RLC_Config_t *lcCfg)
10189 {
10190    if(lcCfg)
10191    {
10192       switch(rlcMode)
10193       {
10194          case RLC_AM :
10195             {
10196                if(lcCfg->choice.am)
10197                {
10198                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.amCfg, sizeof(AmBearerCfg));
10199                   if(rlcDbCfg->u.amCfg)
10200                      extractRlcAmCfg(rlcDbCfg->u.amCfg, lcCfg->choice.am);
10201                }
10202                break;
10203             }
10204          case RLC_UM_BI_DIRECTIONAL :
10205             {
10206                if(lcCfg->choice.um_Bi_Directional)
10207                {
10208                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
10209                   if(rlcDbCfg->u.umBiDirCfg)
10210                      extractRlcUmBiCfg(rlcDbCfg->u.umBiDirCfg, lcCfg->choice.um_Bi_Directional);
10211                }
10212                break;
10213             }
10214          case RLC_UM_UNI_DIRECTIONAL_UL :
10215             {
10216                if(lcCfg->choice.um_Uni_Directional_DL)
10217                {
10218                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
10219                   if(rlcDbCfg->u.umUniDirUlCfg)
10220                      extractRlcUmUlCfg(rlcDbCfg->u.umUniDirUlCfg, lcCfg->choice.um_Uni_Directional_DL);
10221                }
10222                break;
10223             }
10224          case RLC_UM_UNI_DIRECTIONAL_DL :
10225             {
10226                if(lcCfg->choice.um_Uni_Directional_UL)
10227                {
10228                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
10229                   if(rlcDbCfg->u.umUniDirDlCfg)
10230                      extractRlcUmDlCfg(rlcDbCfg->u.umUniDirDlCfg, lcCfg->choice.um_Uni_Directional_UL);
10231                }
10232                break;
10233             }
10234          default:
10235             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
10236             break;
10237       }
10238    }
10239 }
10240
10241 /*******************************************************************
10242  *
10243  * @brief Function to extract extractUlLcCfg
10244  *
10245  * @details
10246  *
10247  *    Function : extractUlLcCfg
10248  *
10249  *    Functionality: Function to extract extractUlLcCfg
10250  *
10251  * @params[in] UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg
10252  * @return void
10253  *
10254  * ****************************************************************/
10255
10256 void extractUlLcCfg(UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg)
10257 {
10258    if(ulLcCfg)
10259    {
10260       if(ulLcCfg->ul_SpecificParameters)
10261       {
10262          f1UlLcCfg->priority = \
10263             ulLcCfg->ul_SpecificParameters->priority;
10264       if(ulLcCfg->ul_SpecificParameters->logicalChannelGroup)
10265       {
10266          f1UlLcCfg->lcGroup = \
10267            *(ulLcCfg->ul_SpecificParameters->logicalChannelGroup);
10268       }
10269       if(ulLcCfg->ul_SpecificParameters->schedulingRequestID)
10270       {
10271          f1UlLcCfg->schReqId = \
10272            *(ulLcCfg->ul_SpecificParameters->schedulingRequestID);
10273       }
10274       f1UlLcCfg->pbr = \
10275          ulLcCfg->ul_SpecificParameters->prioritisedBitRate;
10276       f1UlLcCfg->bsd = \
10277          ulLcCfg->ul_SpecificParameters->bucketSizeDuration;
10278       }
10279    }
10280 }
10281
10282 /*******************************************************************
10283 *
10284 * @brief Function to extract Snssai Cfg Info from CU
10285 *
10286 * @details
10287 *
10288 *    Function : extractDrbSnssaiCfg
10289 *
10290 *    Functionality: Function to extract Drb Snssai Cfg Info from CU
10291 *
10292 * @params[in] DRB_Information_t *drbInfo, Snssai  *snssai
10293 * @return ROK/RFAILED
10294 *
10295 * ****************************************************************/
10296
10297 uint8_t extractDrbSnssaiCfg(SNSSAI_t *RecvSnssai, Snssai **snssaiToBeShared)
10298 {
10299    if(!(*snssaiToBeShared))
10300    {
10301       DU_ALLOC_SHRABL_BUF((*snssaiToBeShared), sizeof(Snssai));
10302       if(snssaiToBeShared == NULLP)
10303       {
10304          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Memory failed at allocating for SNSSAI ");
10305          return RFAILED;
10306       }
10307    }
10308    if(RecvSnssai)
10309    {
10310       memcpy(&(*snssaiToBeShared)->sst, RecvSnssai->sST.buf, RecvSnssai->sST.size);
10311       if(RecvSnssai->sD)
10312       {
10313          memcpy((*snssaiToBeShared)->sd, RecvSnssai->sD->buf,  RecvSnssai->sD->size);
10314       }
10315       else
10316       {
10317          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Received Null pointer of Snssai->SD");
10318          return RFAILED;
10319       }
10320    }
10321    return ROK;
10322 }
10323
10324 /*******************************************************************
10325  *
10326  * @brief Function to procRlcLcCfg
10327  *
10328  * @details
10329  *
10330  *    Function : procRlcLcCfg
10331  *
10332  *    Functionality: Function to procRlcLcCfg
10333  *
10334  * @params[in] rbId, lcId, rbType, rlcMod
10335  *             RLC_Config_t *, RlcBearerCfg * , 
10336  * @return void
10337  *
10338  * ****************************************************************/
10339
10340 void procRlcLcCfg(uint8_t rbId, uint8_t lcId, uint8_t rbType, uint8_t rlcMode,\
10341    uint8_t configType, RLC_Config_t *f1RlcCfg, DuRlcBearerCfg *lcCfg, QoSInformation_t *qoSInformation)
10342 {
10343    DRB_Information_t *drbInfo;
10344
10345    lcCfg->rlcBearerCfg.rbId   = rbId;
10346    lcCfg->configType = configType;
10347
10348    if(rbType == RB_TYPE_SRB)
10349    {
10350       lcCfg->rlcBearerCfg.rbType = RB_TYPE_SRB;
10351       lcCfg->rlcBearerCfg.lcId   = rbId;
10352       lcCfg->rlcBearerCfg.lcType = LCH_DCCH;
10353       lcCfg->rlcBearerCfg.rlcMode = RLC_AM;
10354    }
10355    else if(rbType == RB_TYPE_DRB)
10356    {
10357       lcCfg->rlcBearerCfg.rbType = RB_TYPE_DRB;
10358       lcCfg->rlcBearerCfg.lcId   = lcId;
10359       lcCfg->rlcBearerCfg.lcType = LCH_DTCH;
10360       lcCfg->rlcBearerCfg.rlcMode = rlcMode;
10361    }
10362    if(f1RlcCfg) /* rlc mode config recived */
10363    {
10364       extractRlcModeCfg(lcCfg->rlcBearerCfg.rlcMode, &lcCfg->rlcBearerCfg, f1RlcCfg);
10365    }
10366    if(qoSInformation != NULLP)
10367    {
10368       if(qoSInformation->present == QoSInformation_PR_choice_extension)
10369       {
10370          if(qoSInformation->choice.choice_extension->value.present ==\
10371                QoSInformation_ExtIEs__value_PR_DRB_Information)
10372          {
10373             drbInfo = &qoSInformation->choice.choice_extension->value.choice.DRB_Information; 
10374             if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &lcCfg->rlcBearerCfg.snssai) != ROK)
10375             {
10376                DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information at procRlcLcCfg()");
10377                return;
10378             }
10379          }
10380       }
10381    }
10382 }
10383
10384 /*******************************************************************
10385  *
10386  * @brief Fills DrbQos Info received by CU
10387  *
10388  * @details
10389  *
10390  *    Function : extractQosInfo
10391  *
10392  *    Functionality: Fills DrbQos Info received  by CU
10393  *
10394  * @params[in] DrbQosInfo *qosToAdd, 
10395  *             QoSFlowLevelQoSParameters_t *qosFlowCfg
10396  * @return void
10397  *
10398  * ****************************************************************/
10399
10400 void extractQosInfo(DrbQosInfo *qosToAdd, QoSFlowLevelQoSParameters_t *qosFlowCfg)
10401 {
10402    uint8_t qosCntIdx = 0;
10403    ProtocolExtensionContainer_4624P74_t *qosIeExt = NULLP;
10404
10405    qosToAdd->fiveQiType = qosFlowCfg->qoS_Characteristics.present;
10406    qosToAdd->u.nonDyn5Qi.fiveQi     =\
10407                                      qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->fiveQI;
10408    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow)
10409    {
10410       qosToAdd->u.nonDyn5Qi.avgWindow = \
10411                                         *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
10412    }
10413
10414    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume)
10415    {
10416       qosToAdd->u.nonDyn5Qi.maxDataBurstVol = \
10417                                               *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
10418    }
10419
10420    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel)
10421    {
10422       qosToAdd->u.nonDyn5Qi.priorLevel = \
10423                                          *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel);
10424    }
10425    qosToAdd->ngRanRetPri.priorityLevel = \
10426                                          qosFlowCfg->nGRANallocationRetentionPriority.priorityLevel; 
10427    qosToAdd->ngRanRetPri.preEmptionCap = \
10428                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionCapability;
10429    qosToAdd->ngRanRetPri.preEmptionVul = \
10430                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionVulnerability;
10431    if(qosFlowCfg->gBR_QoS_Flow_Information)
10432    {
10433       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateDl, \
10434             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.buf, \
10435             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.size);
10436       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateUl, \
10437             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.buf, \
10438             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.size);
10439       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateDl,\
10440             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.buf, \
10441             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.size);
10442       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateUl,\
10443             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.buf, \
10444             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.size);
10445    }
10446    /*Extracting PDU_SESSION_ID*/
10447    qosIeExt = (ProtocolExtensionContainer_4624P74_t *)qosFlowCfg->iE_Extensions;
10448    if(qosIeExt)
10449    {
10450       for(qosCntIdx = 0; qosCntIdx < qosIeExt->list.count; qosCntIdx++)
10451       {
10452          if(qosIeExt->list.array[qosCntIdx]->extensionValue.present == \
10453                QoSFlowLevelQoSParameters_ExtIEs__extensionValue_PR_PDUSessionID)
10454          {
10455             qosToAdd->pduSessionId = qosIeExt->list.array[qosCntIdx]->extensionValue.choice.PDUSessionID;
10456             DU_LOG("\nDEBUG -->  DU_F1AP : extractQosInfo: PDU SessionID:%d",qosToAdd->pduSessionId);
10457          }
10458       }  
10459    }
10460    qosToAdd->ulPduSessAggMaxBitRate = 0;
10461 }
10462
10463 /*******************************************************************
10464  *
10465  * @brief Function to extract GTP Tunnel Info from CU
10466  *
10467  * @details
10468  *
10469  *    Function : extractUpTnlInfo
10470  *
10471  *    Functionality: Function to extract GTP Tunnel Info from CU
10472  *
10473  * @params[in] F1AP message
10474  * @return ROK/RFAILED
10475  *
10476  * ****************************************************************/
10477
10478 uint8_t extractUpTnlInfo(uint8_t drbId, uint8_t configType,\
10479    ULUPTNLInformation_ToBeSetup_List_t *tnlInfo, UpTnlCfg *upTnlInfo)
10480 {
10481    uint8_t tnlIdx;
10482    uint32_t ipv4_du = 0;
10483    GTPTunnel_t *gtpTunnel = NULLP;
10484
10485    upTnlInfo->drbId = drbId; 
10486    upTnlInfo->configType = configType;
10487 #ifdef O1_ENABLE
10488    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
10489 #else
10490    cmInetAddr((char *)DU_IP_V4_ADDR, &ipv4_du);
10491 #endif
10492
10493    for(tnlIdx=0; tnlIdx < tnlInfo->list.count; tnlIdx++)
10494    {
10495       if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.present == UPTransportLayerInformation_PR_gTPTunnel)
10496       {
10497          if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel)
10498          {
10499             gtpTunnel = tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel;
10500             DU_ALLOC(upTnlInfo->tnlCfg1, sizeof(GtpTnlCfg));
10501             if(upTnlInfo->tnlCfg1 == NULLP)
10502             {
10503                DU_LOG("\nERROR  -->  F1AP : extractUpTnlInfo: Failed to allocate mmeory for tunnel cfg 1");
10504                return RFAILED;
10505             }
10506             bitStringToInt(&gtpTunnel->transportLayerAddress, &upTnlInfo->tnlCfg1->ulTnlAddress);
10507             upTnlInfo->tnlCfg1->dlTnlAddress = ipv4_du;
10508             if(gtpTunnel->gTP_TEID.size > 0)
10509             {
10510                teIdStringToInt(gtpTunnel->gTP_TEID.buf, &upTnlInfo->tnlCfg1->teId);
10511             }
10512          }
10513          break;
10514       }
10515    }
10516    return ROK;
10517 }
10518
10519 /*******************************************************************
10520 *
10521 * @brief Function to extract Drb Qos Cfg Info from CU
10522 *
10523 * @details
10524 *
10525 *    Function : extractDrbQosCfg 
10526 *
10527 *    Functionality: Function to extract Drb Qos Cfg Info from CU
10528 *
10529 * @params[in] DRB_Information_t *drbInfo, LcCfg *macLcToAdd
10530 * @return ROK/RFAILED
10531 *
10532 * ****************************************************************/
10533
10534 uint8_t extractDrbQosCfg(DRB_Information_t *drbInfo, LcCfg *macLcToAdd ) 
10535 {
10536    if(!macLcToAdd->drbQos)
10537    {
10538       DU_ALLOC_SHRABL_BUF(macLcToAdd->drbQos, sizeof(DrbQosInfo));
10539       if(macLcToAdd->drbQos == NULLP)
10540       {
10541          DU_LOG("\nERROR  -->  DUAPP:Memory failed at allocating DrbQos at extractDrbQosCfg()");
10542          return RFAILED;
10543       }
10544
10545    }
10546    if(drbInfo->dRB_QoS.qoS_Characteristics.present == QoS_Characteristics_PR_non_Dynamic_5QI)
10547    {
10548       extractQosInfo(macLcToAdd->drbQos, &drbInfo->dRB_QoS);
10549       macLcToAdd->dlLcCfg.lcp = macLcToAdd->drbQos->ngRanRetPri.priorityLevel;
10550    }
10551    if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &macLcToAdd->snssai) != ROK)
10552    {
10553       DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information  at extractDrbQosCfg()");
10554       return RFAILED;
10555    }
10556    return ROK;
10557 }
10558 /*******************************************************************
10559  *
10560  * @brief Function to extract DRB info received from CU
10561  *
10562  * @details
10563  *
10564  *    Function : extractDrbCfg
10565  *
10566  *    Functionality: Function to extract DRB info received from CU
10567  *
10568  * @params[in] F1AP message
10569  * @return void
10570  *
10571  * ****************************************************************/
10572 uint8_t extractDrbCfg(DRBs_ToBeSetup_Item_t *drbItem, DRBs_ToBeSetupMod_Item_t *drbSetupModItem,\
10573 DRBs_ToBeModified_Item_t *drbModItem,  DuLcCfg *lcCfgToAdd, UpTnlCfg *upTnlInfo)
10574 {
10575    DRB_Information_t *drbInfo = NULLP;
10576
10577    if(drbItem != NULLP)
10578    {
10579       if(extractUpTnlInfo(drbItem->dRBID, CONFIG_ADD, &drbItem->uLUPTNLInformation_ToBeSetup_List, upTnlInfo) != ROK)
10580       {
10581          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10582          return RFAILED;
10583       }
10584       if(drbItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10585       {
10586          if(drbItem->qoSInformation.choice.choice_extension->value.present == QoSInformation_ExtIEs__value_PR_DRB_Information)
10587          {
10588             drbInfo = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10589             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10590             {
10591                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");
10592                return RFAILED;
10593             }
10594          }
10595       }
10596    }
10597    else if(drbSetupModItem != NULLP)
10598    {
10599       if(extractUpTnlInfo(drbSetupModItem->dRBID, CONFIG_ADD, &drbSetupModItem->uLUPTNLInformation_ToBeSetup_List,\
10600       upTnlInfo) != ROK)
10601       {
10602          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10603          return RFAILED;
10604       }
10605       if(drbSetupModItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10606       {
10607          if(drbSetupModItem->qoSInformation.choice.choice_extension->value.present ==\
10608          QoSInformation_ExtIEs__value_PR_DRB_Information)
10609          {
10610             drbInfo = &drbSetupModItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10611             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10612             {
10613                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10614                return RFAILED;
10615             }
10616
10617          }
10618       }
10619    }
10620    else if(drbModItem != NULLP)
10621    {
10622       if(extractUpTnlInfo(drbModItem->dRBID, CONFIG_MOD, &drbModItem->uLUPTNLInformation_ToBeSetup_List,\
10623       upTnlInfo) != ROK)
10624       {
10625          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10626          return RFAILED;
10627       }
10628       if(drbModItem->qoSInformation != NULLP)
10629       {
10630          if(drbModItem->qoSInformation->present == QoSInformation_PR_choice_extension)
10631          {
10632             if(drbModItem->qoSInformation->choice.choice_extension->value.present ==\
10633                   QoSInformation_ExtIEs__value_PR_DRB_Information)
10634             {
10635                drbInfo = &drbModItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information;
10636                if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10637                {
10638                   DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10639                   return RFAILED;
10640                }
10641
10642             }
10643          }
10644       }
10645    }
10646    return ROK;
10647 }
10648
10649 /*******************************************************************
10650  *
10651  * @brief Function to extract RB info received from CU
10652  *
10653  * @details
10654  *
10655  *    Function : extractMacRbCfg
10656  *
10657  *    Functionality: Function to extract RB info received from CU
10658  *
10659  * @params[in] F1AP message
10660  * @return ROK/RFAILED
10661  *
10662  * ****************************************************************/
10663
10664 uint8_t extractMacRbCfg(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbCfg,\
10665 DRBs_ToBeSetupMod_Item_t *drbSetupModCfg,  DRBs_ToBeModified_Item_t *drbModCfg, LogicalChannelConfig_t *ulLcCfg, DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10666 {
10667    if(drbCfg != NULLP)
10668    {
10669       if(extractDrbCfg(drbCfg, NULL, NULL, lcCfg, upTnlInfo) != ROK)
10670       {
10671          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10672          return RFAILED;
10673       }
10674    }
10675    else if(drbSetupModCfg != NULLP)
10676    { 
10677       if(extractDrbCfg(NULL, drbSetupModCfg, NULL, lcCfg, upTnlInfo) != ROK)
10678       {
10679          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10680          return RFAILED;
10681       }
10682    }
10683    else if(drbModCfg != NULLP)
10684    { 
10685       if(extractDrbCfg(NULL, NULL, drbModCfg, lcCfg, upTnlInfo) != ROK)
10686       {
10687          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10688          return RFAILED;
10689       }
10690    }
10691    else
10692    {
10693       lcCfg->lcConfig.drbQos = NULLP;
10694       lcCfg->lcConfig.snssai = NULLP;
10695       if(lcCfg->lcConfig.lcId == SRB2_LCID)
10696          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_3;
10697       else
10698          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_1;
10699
10700    }
10701    if(ulLcCfg)
10702    {
10703       lcCfg->lcConfig.ulLcCfgPres = true;
10704       extractUlLcCfg(&lcCfg->lcConfig.ulLcCfg, ulLcCfg);
10705    }
10706    else
10707       lcCfg->lcConfig.ulLcCfgPres = false;
10708    return ROK;
10709 }
10710
10711 /*******************************************************************
10712  *
10713  * @brief Function processing LC config info received from CU
10714  *
10715  * @details
10716  *
10717  *    Function : procMacLcCfg
10718  *
10719  *    Functionality: Function processing LC config info received from CU
10720  *
10721  * @params[in] F1AP message
10722  * @return ROK/RFAILED
10723  *
10724  * ****************************************************************/
10725
10726 uint8_t procMacLcCfg(uint8_t lcId, uint8_t rbType, uint8_t configType, DRBs_ToBeSetup_Item_t *drbItem,\
10727 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LogicalChannelConfig_t *ulLcCfg,\
10728 DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10729 {
10730    uint8_t ret = ROK;
10731
10732    lcCfg->lcConfig.lcId = lcId;
10733    lcCfg->configType = configType;
10734    if(rbType == RB_TYPE_SRB)
10735    {
10736       ret = extractMacRbCfg(lcId, NULL, NULL, NULL, ulLcCfg, lcCfg, NULL);
10737    }
10738    else if(rbType == RB_TYPE_DRB && upTnlInfo != NULLP)
10739    {
10740       if(drbItem != NULL)
10741         ret = extractMacRbCfg(lcId, drbItem, NULL, NULL, ulLcCfg, lcCfg, upTnlInfo);
10742       else if(drbSetupModItem != NULL)
10743         ret = extractMacRbCfg(lcId, NULL, drbSetupModItem, NULL, ulLcCfg, lcCfg, upTnlInfo);
10744       else if(drbModItem != NULL)
10745         ret = extractMacRbCfg(lcId, NULL, NULL, drbModItem, ulLcCfg, lcCfg, upTnlInfo);
10746    }
10747    return ret;
10748 }
10749
10750 /*******************************************************************
10751  *
10752  * @brief Function to extract Rlc cfg To Add/Mod in CellGrp Info
10753  *
10754  * @details
10755  *
10756  *    Function : extractRlcCfgToAddMod
10757  *
10758  *    Functionality: Function to extract Rlc cfg To Add/Mod in CellGrp Info
10759  *
10760  * @params[in] CellGroupConfigRrc__rlc_BearerTo pointer
10761  *             DuUeCfg Pointer
10762  * @return ROK/RFAILED
10763  *
10764  * ****************************************************************/
10765
10766 uint8_t extractRlcCfgToAddMod(struct CellGroupConfigRrc__rlc_BearerToAddModList *lcCfg, DuUeCfg *ueCfgDb)
10767 {
10768   uint8_t idx, rbId, lcId, rlcMode, rbType;
10769   RLC_Config_t *f1RlcCfg = NULLP;
10770   LogicalChannelConfig_t *macUlLcCfg = NULLP;
10771
10772   for(idx = 0; idx < lcCfg->list.count; idx++)
10773   {
10774      lcId = lcCfg->list.array[idx]->logicalChannelIdentity;
10775      if(lcCfg->list.array[idx]->servedRadioBearer)
10776      {
10777         /* RadioBearer for SRB/DRB */
10778         if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10779         RLC_BearerConfig__servedRadioBearer_PR_srb_Identity)
10780         {
10781            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.srb_Identity;
10782            rbType = RB_TYPE_SRB;
10783         }
10784         else if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10785         RLC_BearerConfig__servedRadioBearer_PR_drb_Identity)
10786         {
10787            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.drb_Identity;
10788            rbType = RB_TYPE_DRB;
10789         }
10790         else
10791         {
10792            DU_LOG("\nERROR  -->  No components present in Bearer config to ADD/MOD");
10793            return RFAILED;
10794         }
10795         /* MAC UL LC Config */
10796         if(lcCfg->list.array[idx]->mac_LogicalChannelConfig)
10797         {
10798            macUlLcCfg = lcCfg->list.array[idx]->mac_LogicalChannelConfig;
10799         }
10800      }
10801      else
10802      {
10803         DU_LOG("\nERROR  -->  DUAPP: Received RadioBearer config is NULL");
10804         return RFAILED;
10805      }
10806      /* RLC Mode Config */
10807      if(lcCfg->list.array[idx]->rlc_Config)
10808      {
10809         rlcMode  = lcCfg->list.array[idx]->rlc_Config->present;
10810         f1RlcCfg = lcCfg->list.array[idx]->rlc_Config;
10811      }
10812      
10813      /* Filling RLC/MAC Config*/
10814      memset(&ueCfgDb->macLcCfg[idx], 0, sizeof(DuLcCfg));
10815      memset(&ueCfgDb->rlcLcCfg[idx], 0, sizeof(DuRlcBearerCfg));
10816      procRlcLcCfg(rbId, lcId, rbType, rlcMode, CONFIG_UNKNOWN, f1RlcCfg, &(ueCfgDb->rlcLcCfg[idx]), NULLP);
10817      if(procMacLcCfg(lcId, rbType, CONFIG_UNKNOWN, NULL, NULL, NULL, macUlLcCfg, &ueCfgDb->macLcCfg[idx], NULL) != ROK)
10818      {
10819         DU_LOG("\nERROR  -->  DU APP : Failed while filling MAC LC config at extractRlcCfgToAddMod()");
10820         return RFAILED;
10821      }
10822      (ueCfgDb->numRlcLcs)++;
10823      (ueCfgDb->numMacLcs)++;
10824      DU_LOG("\nDEBUG  -> DUAPP: extractRlcCfgToAddMod:RBType:%d, DrbID: %d,lcId:%d, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
10825         rbType, rbId, lcId, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
10826   }
10827   //TODO: To send the failure cause in UeContextSetupRsp 
10828   return ROK;
10829 }
10830
10831 /*******************************************************************
10832  *
10833  * @brief DeAlloc pdsch serv cell config info
10834  *
10835  * @details
10836  *
10837  *    Function : freeMacPdschServCellInfo
10838  *
10839  *    Functionality: DeAlloc pdsch serv cell config info
10840  *
10841  * @params[in] PdschServCellCfg pointer
10842  * @return void
10843  *
10844  * ****************************************************************/
10845
10846 void freeMacPdschServCellInfo(PdschServCellCfg *pdsch)
10847 {
10848    if(pdsch->xOverhead)
10849    {
10850       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->xOverhead, sizeof(PdschXOverhead));
10851    }
10852    if(pdsch->codeBlkGrpFlushInd)
10853    {
10854       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->codeBlkGrpFlushInd, sizeof(bool));
10855    }
10856    if(pdsch->maxCodeBlkGrpPerTb)
10857    {
10858       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10859    }
10860    if(pdsch->maxMimoLayers)
10861    {
10862       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxMimoLayers, sizeof(uint8_t));
10863    }
10864 }
10865
10866 /*******************************************************************
10867  *
10868  * @brief Free Serving cell Info
10869  *
10870  * @details
10871  *
10872  *    Function : freeMacServingCellInfo
10873  *
10874  *    Functionality: Free Serving cell Info
10875  *
10876  * @params[in] ServCellCfgInfo *srvCellCfg
10877  * @return void
10878  *
10879  * ****************************************************************/
10880 void freeMacServingCellInfo(ServCellRecfgInfo *srvCellCfg)
10881 {
10882    uint8_t timeDomRsrcIdx;
10883
10884    if(srvCellCfg->initDlBwp.pdschPresent)
10885    {
10886       for(timeDomRsrcIdx = 0; timeDomRsrcIdx < srvCellCfg->initDlBwp.pdschCfg.numTimeDomRsrcAlloc; timeDomRsrcIdx++)
10887       {
10888          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, \
10889             srvCellCfg->initDlBwp.pdschCfg.timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
10890       }
10891    }
10892
10893    freeMacPdschServCellInfo(&srvCellCfg->pdschServCellCfg);
10894    if(srvCellCfg->bwpInactivityTmr)
10895    {
10896       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
10897    }
10898
10899    if(srvCellCfg->initUlBwp.pucchPresent)
10900    {
10901       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->initUlBwp.pucchCfg.dlDataToUlAck, sizeof(PucchDlDataToUlAck));
10902    }
10903 }
10904
10905 /*******************************************************************
10906  *
10907  * @brief Free cell Grp Cfg Info
10908  *
10909  * @details
10910  *
10911  *    Function : freeUeRecfgCellGrpInfo
10912  *
10913  *    Functionality: Free cell Grp Cfg Info
10914  *
10915  * @params[in] DuMacUeCfg*  duUeCfg
10916  * @return void
10917  *
10918  * ****************************************************************/
10919
10920 void freeUeRecfgCellGrpInfo(DuMacUeCfg *macUeCfg)
10921 {
10922    freeMacServingCellInfo(&macUeCfg->spCellCfg.servCellCfg);
10923 }
10924
10925 /*******************************************************************
10926  *
10927  * @brief Fills Reconfig SchReqReConfig
10928  *
10929  * @details
10930  *
10931  *    Function : extractSchReqReConfig
10932  *
10933  *    Functionality: Fills Reconfig SchReqReConfig
10934  *
10935  * @params[in] SchedulingRequestConfig_t *cuSchedReq
10936  *             SchedReqCfg*  macSchedReq
10937  * @return void
10938  *
10939  * ****************************************************************/
10940 void extractSchReqReConfig(SchedulingRequestConfig_t *cuSchedReq, SchedReqCfg *macSchedReq)
10941 {
10942    uint8_t schReqIdx = 0;
10943    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqListToAdd = NULLP;
10944    struct SchedulingRequestConfig__schedulingRequestToReleaseList *schReqListToRel = NULLP;
10945
10946    if(cuSchedReq->schedulingRequestToAddModList)
10947    {
10948       schReqListToAdd = cuSchedReq->schedulingRequestToAddModList;
10949       if(schReqListToAdd->list.count)
10950       {
10951          macSchedReq->addModListCount = schReqListToAdd->list.count;
10952          for(schReqIdx = 0; schReqIdx < schReqListToAdd->list.count; schReqIdx++)
10953          {
10954             macSchedReq->addModList[schReqIdx].schedReqId = \
10955                schReqListToAdd->list.array[schReqIdx]->schedulingRequestId;
10956             macSchedReq->addModList[schReqIdx].srProhibitTmr = \
10957                *(schReqListToAdd->list.array[schReqIdx]->sr_ProhibitTimer);
10958             macSchedReq->addModList[schReqIdx].srTransMax    =\
10959                schReqListToAdd->list.array[schReqIdx]->sr_TransMax;
10960          }
10961       }
10962    }
10963    /* Scheduling Req To release */
10964    if(cuSchedReq->schedulingRequestToReleaseList)
10965    {
10966       schReqListToRel = cuSchedReq->schedulingRequestToReleaseList;
10967       if(schReqListToRel->list.count)
10968       {
10969          macSchedReq->relListCount = schReqListToRel->list.count;
10970          for(schReqIdx = 0; schReqIdx < schReqListToRel->list.count; schReqIdx++)
10971          {
10972             macSchedReq->relList[schReqIdx] = \
10973                *schReqListToRel->list.array[schReqIdx];
10974          }
10975       }
10976    }
10977 }
10978
10979 /*******************************************************************
10980  *
10981  * @brief Fills TagReconfig
10982  *
10983  * @details
10984  *
10985  *    Function : extractTagReconfig
10986  *
10987  *    Functionality: Fills extractTagReconfig
10988  *
10989  * @params[in] TAG_Config_t *cuTagCfg
10990  *             TagCfg *macTagCfg
10991  * @return void
10992  *
10993  * ****************************************************************/
10994
10995 void extractTagReconfig(TAG_Config_t *cuTagCfg, TagCfg *macTagCfg)
10996 {
10997   uint8_t tagIdx = 0;
10998   struct TAG_Config__tag_ToAddModList  *tagListToAddMod = NULLP;
10999   struct TAG_Config__tag_ToReleaseList *tagListToRel = NULLP;
11000
11001   /* Tag config to AddMod */
11002   if(cuTagCfg->tag_ToAddModList)
11003   {
11004      tagListToAddMod = cuTagCfg->tag_ToAddModList; 
11005      if(tagListToAddMod->list.count)
11006      {
11007         macTagCfg->addModListCount = tagListToAddMod->list.count;
11008         for(tagIdx = 0; tagIdx < tagListToAddMod->list.count; tagIdx++)
11009         {
11010            macTagCfg->addModList[tagIdx].tagId =\
11011               tagListToAddMod->list.array[tagIdx]->tag_Id;     
11012            macTagCfg->addModList[tagIdx].timeAlignTimer = \
11013
11014               tagListToAddMod->list.array[tagIdx]->timeAlignmentTimer;
11015         }
11016      }
11017   }
11018   /* Tag config to release */
11019   if(cuTagCfg->tag_ToReleaseList)
11020   {
11021      tagListToRel = cuTagCfg->tag_ToReleaseList;
11022      if(tagListToRel->list.count)
11023      {
11024         macTagCfg->relListCount = tagListToRel->list.count;
11025         for(tagIdx = 0; tagIdx < tagListToRel->list.count; tagIdx++)
11026         {
11027            macTagCfg->relList[tagIdx] = *tagListToRel->list.array[tagIdx];     
11028         }
11029      }
11030   }
11031 }
11032
11033 /*******************************************************************
11034  *
11035  * @brief Fills PdcchCfg received by CU
11036  *
11037  * @details
11038  *
11039  *    Function : extractPdcchCfg
11040  *
11041  *    Functionality: Fills PdcchCfg received  by CU
11042  *
11043  * @params[in] PDCCH_Config_t *cuPdcchCfg,
11044  *             PdcchConfig *duPdcchCfg
11045  * @return void
11046  *
11047  * ****************************************************************/
11048
11049 void extractPdcchCfg(PDCCH_Config_t *cuPdcchCfg, PdcchConfig *macPdcchCfg)
11050 {
11051    uint8_t cRsetIdx = 0;
11052    uint8_t srchSpcIdx = 0;
11053
11054    struct PDCCH_Config__controlResourceSetToAddModList *cRsetToAddModList = NULLP;
11055    struct PDCCH_Config__controlResourceSetToReleaseList *cRsetToRelList = NULLP;
11056    struct PDCCH_Config__searchSpacesToAddModList *srchSpcToAddModList = NULLP;
11057    struct PDCCH_Config__searchSpacesToReleaseList *srchSpcToRelList = NULLP;
11058
11059
11060    /* Control Resource Set To Add/Mod List */
11061    if(cuPdcchCfg->controlResourceSetToAddModList)
11062    {
11063       cRsetToAddModList = cuPdcchCfg->controlResourceSetToAddModList;
11064       if(cRsetToAddModList->list.count)
11065       {
11066          macPdcchCfg->numCRsetToAddMod = cRsetToAddModList->list.count;
11067          for(cRsetIdx = 0; cRsetIdx < cRsetToAddModList->list.count; cRsetIdx++)
11068          {
11069             macPdcchCfg->cRSetToAddModList[cRsetIdx].cRSetId = \
11070                cRsetToAddModList->list.array[cRsetIdx]->controlResourceSetId;
11071             //freqDomRsrcBitStringToInt(&cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources,\
11072                   macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc);
11073             memcpy(macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc, \
11074                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.buf,
11075                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.size);
11076
11077             macPdcchCfg->cRSetToAddModList[cRsetIdx].duration = \
11078                 cRsetToAddModList->list.array[cRsetIdx]->duration;
11079
11080             macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType = \
11081                cRsetToAddModList->list.array[cRsetIdx]->cce_REG_MappingType.present;   
11082             if(macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType == CCE_REG_MAPPINGTYPE_PR_INTERLEAVED)
11083             {
11084                //TODO: handle the case for Interleaved
11085             }
11086             macPdcchCfg->cRSetToAddModList[cRsetIdx].precoderGranularity = \
11087                 cRsetToAddModList->list.array[cRsetIdx]->precoderGranularity;
11088             if(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID)
11089             {
11090                macPdcchCfg->cRSetToAddModList[cRsetIdx].dmrsScramblingId= \
11091                   *(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID);
11092             }
11093          }
11094       }
11095    }
11096    /* Control Resource Set To Release List */
11097    if(cuPdcchCfg->controlResourceSetToReleaseList)
11098    {
11099       cRsetToRelList = cuPdcchCfg->controlResourceSetToReleaseList;
11100       if(cRsetToRelList->list.count)
11101       {
11102          macPdcchCfg->numCRsetToRel = cRsetToRelList->list.count;
11103          for(cRsetIdx = 0; cRsetIdx < cRsetToRelList->list.count; cRsetIdx++)
11104          {
11105             macPdcchCfg->cRSetToRelList[cRsetIdx] = *(cRsetToRelList->list.array[cRsetIdx]);
11106          }
11107       }
11108    }
11109
11110    /* Search space To Add/Mod List */
11111    if(cuPdcchCfg->searchSpacesToAddModList)
11112    {
11113       srchSpcToAddModList = cuPdcchCfg->searchSpacesToAddModList;
11114       if(srchSpcToAddModList->list.count)
11115       {
11116          macPdcchCfg->numSearchSpcToAddMod = srchSpcToAddModList->list.count;
11117          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToAddModList->list.count; srchSpcIdx++)
11118          {
11119             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceId =\
11120                                                                           srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceId;
11121             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].cRSetId =\
11122                                                                     *(srchSpcToAddModList->list.array[srchSpcIdx]->controlResourceSetId);
11123             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset)
11124             {
11125                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSlotPeriodicityAndOffset =\
11126                                                                                          srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset->present;
11127             }
11128             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot)
11129             {
11130                bitStringToInt(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot,\
11131                      macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSymbolsWithinSlot);
11132             }
11133             if(srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates)
11134             {
11135                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel1 = \
11136                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel1;
11137                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel2 = \
11138                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel2;
11139                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel4 = \
11140                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel4;
11141
11142                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel8 = \
11143                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel8;
11144
11145                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel16 = \
11146                                                                                         srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel16;
11147             }
11148             if(srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType)
11149             {
11150                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType =\
11151                                                                                srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->present;
11152                if(macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType == SEARCHSPACETYPE_PR_UE_SPECIFIC)
11153                {
11154                   macPdcchCfg->searchSpcToAddModList[srchSpcIdx].ueSpecificDciFormat =\
11155                                                                                       srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->choice.ue_Specific->dci_Formats;
11156                }
11157
11158             }
11159          }
11160       }
11161    }
11162    /* Search space To Rel List */
11163    if(cuPdcchCfg->searchSpacesToReleaseList)
11164    {
11165       srchSpcToRelList = cuPdcchCfg->searchSpacesToReleaseList;
11166       if(srchSpcToRelList->list.count)
11167       {
11168          macPdcchCfg->numSearchSpcToRel = srchSpcToRelList->list.count;
11169          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToRelList->list.count; srchSpcIdx++)
11170          {
11171             macPdcchCfg->searchSpcToRelList[srchSpcIdx] =\
11172                                                          *(srchSpcToRelList->list.array[srchSpcIdx]);
11173          }
11174       }
11175    }
11176 }
11177
11178 /*******************************************************************
11179  *
11180  * @brief Fills PdschCfg received by CU
11181  *
11182  * @details
11183  *
11184  *    Function : extractPdschCfg
11185  *
11186  *    Functionality: Fills PdschCfg received  by CU
11187  *
11188  * @params[in] PDSCH_Config_t *cuPdschCfg = Information which is send by CU,
11189  *                   which we have stored in F1UeContextSetupDb,
11190  *             PdschConfig *macPdschCfg = Used to Store the information which
11191  *                   needs to send in other layer, as well as this can be the variable
11192  *                   which stores the information in DuCb,
11193  *             PdschConfig *storedPdschCfg =  Null in case of sending the
11194  *                   information to other layer else it will have stored pdsch 
11195  *                   configuration in copyOfmacUeCfg.
11196  * @return void
11197  *
11198  * ****************************************************************/
11199
11200 void extractPdschCfg(PDSCH_Config_t *cuPdschCfg, PdschConfig *macPdschCfg, PdschConfig *storedPdschCfg)
11201 {
11202    uint8_t timeDomIdx;
11203    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAlloc = NULLP;
11204
11205    if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
11206    {
11207       if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->present == \
11208             PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup)
11209       {
11210          if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup)
11211          {
11212             macPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
11213                *(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_AdditionalPosition);
11214          }
11215       }
11216    }
11217    macPdschCfg->resourceAllocType = cuPdschCfg->resourceAllocation;
11218    if(cuPdschCfg->pdsch_TimeDomainAllocationList)
11219    {
11220       timeDomAlloc = cuPdschCfg->pdsch_TimeDomainAllocationList;
11221       if(timeDomAlloc->present ==\
11222             PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup)
11223       {
11224          if(timeDomAlloc->choice.setup)
11225          {
11226             macPdschCfg->numTimeDomRsrcAlloc  = timeDomAlloc->choice.setup->list.count;
11227             for(timeDomIdx = 0; timeDomIdx < timeDomAlloc->choice.setup->list.count; timeDomIdx++)
11228             {
11229                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 = NULLP;
11230                if(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0)
11231                {
11232                   if(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 == NULL)
11233                   {
11234                      if(storedPdschCfg)
11235                      {
11236                         if(storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
11237                         {
11238                            macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 =\
11239                            storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0;
11240                         }
11241                         else
11242                         {
11243                            DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
11244                         }
11245                      }
11246                      else
11247                      {
11248                         DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
11249                      }
11250                      if(!macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
11251                      {
11252                         DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for k0 at extractPdschCfg()");
11253                         return;
11254                      }
11255                   }
11256                   *(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0) = \
11257                   *(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0);
11258                }
11259                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].mappingType = \
11260                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->mappingType;
11261                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].startSymbolAndLength = \
11262                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11263             }
11264          }
11265       }
11266    }
11267    macPdschCfg->rbgSize = cuPdschCfg->rbg_Size;
11268    if(cuPdschCfg->maxNrofCodeWordsScheduledByDCI)
11269       macPdschCfg->numCodeWordsSchByDci = *(cuPdschCfg->maxNrofCodeWordsScheduledByDCI);
11270    if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_staticBundling)
11271    {
11272       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11273       if(cuPdschCfg->prb_BundlingType.choice.staticBundling)
11274       {
11275          if(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize)
11276          {
11277             macPdschCfg->bundlingInfo.StaticBundling.size = \
11278                *(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize);
11279          }
11280       }
11281    }
11282    else if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_dynamicBundling)
11283    {
11284       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11285    }
11286
11287 }
11288
11289 /*******************************************************************
11290  *
11291  * @brief Fills PdschServingCellCfg received by CU
11292  *
11293  * @details
11294  *
11295  *    Function : extractPdschServingCellCfg
11296  *
11297  *    Functionality: Fills PdschCfg received  by CU
11298  *
11299  * @params[in] PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg,
11300  *             PdschServCellCfg *macUePdschSrvCellCfg
11301  * @return ROK/RFAILED
11302  *
11303  * ****************************************************************/
11304
11305 uint8_t extractPdschServingCellCfg(PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg, PdschServCellCfg *macUePdschSrvCellCfg)
11306 {
11307    if(cuPdschSrvCellCfg->codeBlockGroupTransmission)
11308    {
11309       if(cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup)
11310       {
11311          if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11312          {
11313             *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11314                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11315          }
11316          else
11317          {
11318             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
11319             if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11320             {
11321                *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11322                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11323             }
11324             else
11325             {
11326                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxCodeBlkGrpPerTb at extractPdschServingCellCfg()");
11327                return RFAILED;
11328             }
11329          }
11330          if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11331          {
11332             *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11333                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11334          }
11335          else
11336          {
11337             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->codeBlkGrpFlushInd , sizeof(bool));
11338             if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11339             {
11340                *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11341                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11342             }
11343             else
11344             {
11345                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for codeBlkGrpFlushInd at extractPdschServingCellCfg()");
11346                return RFAILED;
11347             }
11348          }
11349       }
11350    }
11351    if(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH)
11352    {
11353       macUePdschSrvCellCfg->numHarqProcForPdsch = *(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH); 
11354    }
11355    if(cuPdschSrvCellCfg->ext1)
11356    {
11357       if(cuPdschSrvCellCfg->ext1->maxMIMO_Layers)
11358       {
11359         if(macUePdschSrvCellCfg->maxMimoLayers)
11360         {
11361            *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11362         }
11363         else
11364         {
11365            DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxMimoLayers, sizeof(uint8_t));
11366            if(macUePdschSrvCellCfg->maxMimoLayers)
11367            {
11368               *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11369            }
11370            else
11371            {
11372               DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxMimoLayers at extractPdschServingCellCfg()");
11373               return RFAILED;
11374            }
11375         }
11376       }
11377    }
11378    if(cuPdschSrvCellCfg->xOverhead)
11379    {
11380       if(macUePdschSrvCellCfg->xOverhead)
11381       {
11382          *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11383       }
11384       else
11385       {
11386          DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->xOverhead, sizeof(PdschXOverhead));
11387          if(macUePdschSrvCellCfg->xOverhead)
11388          {
11389             *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11390          }
11391          else
11392          {
11393             DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for xOverhead at extractPdschServingCellCfg()");
11394             return RFAILED;
11395          }
11396       }
11397    }
11398    return ROK;
11399 }
11400
11401 /*******************************************************************
11402  *
11403  * @brief Fills PuschCfg received by CU
11404  *
11405  * @details
11406  *
11407  *    Function : extractPuschCfg
11408  *
11409  *    Functionality: Fills PuschCfg received  by CU
11410  *
11411  * @params[in] BWP_UplinkDedicated__pusch_Config *cuPuschCfg,
11412  *             PuschCfg *macPuschCfg
11413  * @return void
11414  *
11415  * ****************************************************************/
11416
11417 void extractPuschCfg(struct BWP_UplinkDedicated__pusch_Config *cuPuschCfg, PuschCfg *macPuschCfg)
11418 {
11419    uint8_t timeDomIdx = 0;
11420    DMRS_UplinkConfig_t *dmrsUlCfg = NULLP;
11421    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList = NULLP;
11422
11423    if(cuPuschCfg->present == BWP_UplinkDedicated__pusch_Config_PR_setup)
11424    {
11425       if(cuPuschCfg->choice.setup)
11426       {
11427          if(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH)
11428          {
11429              macPuschCfg->dataScramblingId = \
11430                 *(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH);
11431          }
11432          if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA)
11433          {
11434             if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->present == PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup)
11435             {
11436                if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup)
11437                {
11438                   dmrsUlCfg = (cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup);
11439                   if(dmrsUlCfg->dmrs_AdditionalPosition)
11440                   {
11441                      macPuschCfg->dmrsUlCfgForPuschMapTypeA.addPos =\
11442                         *(dmrsUlCfg->dmrs_AdditionalPosition);
11443                   }
11444                   if(dmrsUlCfg->transformPrecodingDisabled)
11445                   {
11446                      if(dmrsUlCfg->transformPrecodingDisabled->scramblingID0)
11447                      {
11448                         macPuschCfg->dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0 = \
11449                            *(dmrsUlCfg->transformPrecodingDisabled->scramblingID0);
11450                      }
11451                   }
11452                }
11453             }
11454          }
11455          /*Res Alloc Type for UL */
11456          if(cuPuschCfg->choice.setup->resourceAllocation)
11457          {
11458             macPuschCfg->resourceAllocType = \
11459                cuPuschCfg->choice.setup->resourceAllocation;
11460          }
11461          if(cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList)
11462          {
11463             timeDomAllocList = cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList;
11464             if(timeDomAllocList->present == PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup)
11465             {
11466                if(timeDomAllocList->choice.setup)
11467                {
11468                   macPuschCfg->numTimeDomRsrcAlloc = timeDomAllocList->choice.setup->list.count;
11469                   for(timeDomIdx = 0; timeDomIdx <timeDomAllocList->choice.setup->list.count; timeDomIdx++)
11470                   {
11471                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].k2 = \
11472                         *(timeDomAllocList->choice.setup->list.array[timeDomIdx]->k2);
11473                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].mappingType = \
11474                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->mappingType;
11475                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].startSymbolAndLength = \
11476                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11477                   }
11478                }
11479             }
11480          }
11481          if(cuPuschCfg->choice.setup->transformPrecoder)
11482             macPuschCfg->transformPrecoder = *(cuPuschCfg->choice.setup->transformPrecoder);
11483       }
11484    }
11485 }
11486
11487 /*******************************************************************
11488  *
11489  * @brief Function to fill pucch Power Control
11490  *
11491  * @details
11492  *
11493  *    Function : extractPucchPowerControl
11494  *
11495  *    Functionality: Function to fill pucch Power Control
11496  *
11497  * @params[in] PucchPowerControl *pwrCtrl,
11498  *             struct PUCCH_PowerControl *cuPwrCtrlCfg
11499  * @return void
11500  *
11501  * ****************************************************************/
11502
11503 void extractPucchPowerControl(PucchPowerControl *pwrCtrl, struct PUCCH_PowerControl *cuPwrCtrlCfg)
11504 {
11505    uint8_t arrIdx;
11506
11507    if(cuPwrCtrlCfg->deltaF_PUCCH_f0)
11508       pwrCtrl->deltaF_Format0 = *cuPwrCtrlCfg->deltaF_PUCCH_f0;
11509    if(cuPwrCtrlCfg->deltaF_PUCCH_f1)
11510       pwrCtrl->deltaF_Format1 = *cuPwrCtrlCfg->deltaF_PUCCH_f1;
11511    if(cuPwrCtrlCfg->deltaF_PUCCH_f2)
11512       pwrCtrl->deltaF_Format2 = *cuPwrCtrlCfg->deltaF_PUCCH_f2;
11513    if(cuPwrCtrlCfg->deltaF_PUCCH_f3)
11514       pwrCtrl->deltaF_Format3 = *cuPwrCtrlCfg->deltaF_PUCCH_f3;
11515    if(cuPwrCtrlCfg->deltaF_PUCCH_f4)
11516       pwrCtrl->deltaF_Format4 = *cuPwrCtrlCfg->deltaF_PUCCH_f4;
11517    if(cuPwrCtrlCfg->p0_Set)
11518    {
11519       pwrCtrl->p0SetCount = cuPwrCtrlCfg->p0_Set->list.count;
11520       for(arrIdx=0; arrIdx < pwrCtrl->p0SetCount; arrIdx++)
11521       {
11522          pwrCtrl->p0Set[arrIdx].p0PucchId =\
11523             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Id;
11524          pwrCtrl->p0Set[arrIdx].p0PucchVal =\
11525             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Value;
11526       }
11527    }
11528    if(cuPwrCtrlCfg->pathlossReferenceRSs)
11529    {
11530       pwrCtrl->pathLossRefRSListCount = cuPwrCtrlCfg->pathlossReferenceRSs->list.count;
11531       for(arrIdx = 0; arrIdx < pwrCtrl->pathLossRefRSListCount; arrIdx++)
11532       {
11533          pwrCtrl->pathLossRefRSList[arrIdx].pathLossRefRSId =\
11534             cuPwrCtrlCfg->pathlossReferenceRSs->list.array[arrIdx]->pucch_PathlossReferenceRS_Id;
11535       }
11536    }
11537 }
11538  
11539  /*******************************************************************
11540  *
11541  * @brief Function to extractResrcSetToAddModList sent by CU
11542  *
11543  * @details
11544  *
11545  *    Function : extractResrcSetToAddModList
11546  *
11547  *    Functionality: Fucntion to extractResrcSetToAddModList
11548  *
11549  * @params[in] PucchResrcSetCfg pointer,
11550  *             struct PUCCH_Config__resourceSetToAddModList pointer
11551  * @return void
11552  *
11553  * ****************************************************************/
11554
11555 void extractResrcSetToAddModList(PucchResrcSetCfg *macRsrcSetList, struct PUCCH_Config__resourceSetToAddModList *cuRsrcSetList)
11556 {
11557    uint8_t arrIdx, rsrcListIdx;
11558
11559    macRsrcSetList->resrcSetToAddModListCount = cuRsrcSetList->list.count; 
11560    for(arrIdx = 0; arrIdx < macRsrcSetList->resrcSetToAddModListCount; arrIdx++)
11561    {
11562       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcSetId     =\
11563          cuRsrcSetList->list.array[arrIdx]->pucch_ResourceSetId;
11564       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount =\
11565          cuRsrcSetList->list.array[arrIdx]->resourceList.list.count;
11566       for(rsrcListIdx = 0; rsrcListIdx < macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount; rsrcListIdx++)
11567       {
11568          macRsrcSetList->resrcSetToAddModList[arrIdx].resrcList[rsrcListIdx] =\
11569             *cuRsrcSetList->list.array[arrIdx]->resourceList.list.array[rsrcListIdx];
11570       }
11571
11572       if(cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1)
11573       {
11574          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize =\
11575             *cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1;
11576       }
11577       else
11578       {
11579          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize = 0;
11580       }
11581    }
11582 }/* End of extractResrcSetToAddModList */
11583
11584 /*******************************************************************
11585  *
11586  * @brief Fills extractResrcToAddModList sent by CU
11587  *
11588  * @details
11589  *
11590  *    Function : extractResrcToAddModList
11591  *
11592  *    Functionality: Fills extractResrcToAddModList
11593  *
11594  * @params[in] PucchResrcCfg pointer,
11595  *             struct PUCCH_Config__resourceToAddModList pointer
11596  * @return ROk/RFAILED
11597  *
11598  * ****************************************************************/
11599
11600 uint8_t extractResrcToAddModList(PucchResrcCfg *macResrcList, struct PUCCH_Config__resourceToAddModList *cuResrcList)
11601 {
11602    uint8_t arrIdx;
11603    
11604    macResrcList->resrcToAddModListCount = cuResrcList->list.count;
11605    for(arrIdx = 0; arrIdx < macResrcList->resrcToAddModListCount; arrIdx++)
11606    {
11607       macResrcList->resrcToAddModList[arrIdx].resrcId      =\
11608         cuResrcList->list.array[arrIdx]->pucch_ResourceId; 
11609       macResrcList->resrcToAddModList[arrIdx].startPrb     =\
11610         cuResrcList->list.array[arrIdx]->startingPRB;
11611       if(cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping)
11612       {
11613          macResrcList->resrcToAddModList[arrIdx].intraFreqHop =\
11614            *cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping;
11615       }
11616       if(cuResrcList->list.array[arrIdx]->secondHopPRB)
11617       {
11618          macResrcList->resrcToAddModList[arrIdx].secondPrbHop =\
11619            *cuResrcList->list.array[arrIdx]->secondHopPRB;
11620       }
11621       /* PUCCH RSRC FORMAT */
11622       if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format0)
11623       {
11624          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_0;
11625          if(cuResrcList->list.array[arrIdx]->format.choice.format0)
11626          {
11627             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0, sizeof(PucchFormat0));
11628             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0 == NULLP)
11629             {
11630                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format0 in extractResrcToAddModList()");
11631                return RFAILED;
11632             }
11633             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->initialCyclicShift =\
11634                cuResrcList->list.array[arrIdx]->format.choice.format0->initialCyclicShift;
11635             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->numSymbols =\
11636                cuResrcList->list.array[arrIdx]->format.choice.format0->nrofSymbols;
11637             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->startSymbolIdx =\
11638                cuResrcList->list.array[arrIdx]->format.choice.format0->startingSymbolIndex;
11639          }
11640       }
11641       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format1)
11642       {
11643          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_1;
11644          if(cuResrcList->list.array[arrIdx]->format.choice.format1)
11645          {
11646             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1, sizeof(PucchFormat1));
11647             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1 == NULLP)
11648             {
11649                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format1 in extractResrcToAddModList()");
11650                return RFAILED;
11651             }
11652             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->initialCyclicShift =\
11653                 cuResrcList->list.array[arrIdx]->format.choice.format1->initialCyclicShift;
11654             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->numSymbols =\
11655                 cuResrcList->list.array[arrIdx]->format.choice.format1->nrofSymbols;
11656             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->startSymbolIdx =\
11657                 cuResrcList->list.array[arrIdx]->format.choice.format1->startingSymbolIndex;
11658             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->timeDomOCC =\
11659                 cuResrcList->list.array[arrIdx]->format.choice.format1->timeDomainOCC;
11660          }
11661       }
11662       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format2)
11663       {
11664          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_2;
11665          if(cuResrcList->list.array[arrIdx]->format.choice.format2)
11666          {
11667             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
11668             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2 == NULLP)
11669             {
11670                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format2 in extractResrcToAddModList()");
11671                return RFAILED;
11672             }
11673             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numPrbs =\
11674                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofPRBs;
11675             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numSymbols =\
11676                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofSymbols;
11677             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->startSymbolIdx =\
11678                 cuResrcList->list.array[arrIdx]->format.choice.format2->startingSymbolIndex;
11679          }
11680       }
11681       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format3)
11682       {
11683          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_3;
11684          if(cuResrcList->list.array[arrIdx]->format.choice.format3)
11685          {
11686             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
11687             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3 == NULLP)
11688             {
11689                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format3 in extractResrcToAddModList()");
11690                return RFAILED;
11691             }
11692             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numPrbs =\
11693                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofPRBs;
11694             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numSymbols =\
11695                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofSymbols;
11696             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->startSymbolIdx =\
11697                 cuResrcList->list.array[arrIdx]->format.choice.format3->startingSymbolIndex;
11698          }
11699       }
11700       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format4)
11701       {
11702          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_4;
11703          if(cuResrcList->list.array[arrIdx]->format.choice.format4)
11704          {
11705             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4, sizeof(PucchFormat4));
11706             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4 == NULLP)
11707             {
11708                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format4 in extractResrcToAddModList()");
11709                return RFAILED;
11710             }
11711             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->numSymbols =\
11712                 cuResrcList->list.array[arrIdx]->format.choice.format4->nrofSymbols;
11713             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occLen =\
11714                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Length;
11715             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occIdx =\
11716                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Index;
11717             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->startSymbolIdx =\
11718                 cuResrcList->list.array[arrIdx]->format.choice.format4->startingSymbolIndex;
11719          }
11720       }
11721    }
11722    return ROK;
11723
11724 }/* End of extractResrcToAddModList */
11725
11726 /*******************************************************************
11727  *
11728  * @brief Fills fillPucchSchedReqPeriodAndOffset sent by CU
11729  *
11730  * @details
11731  *
11732  *    Function : fillPucchSchedReqPeriodAndOffset
11733  *
11734  *    Functionality: To fillPucchSchedReqPeriodAndOffset
11735  *
11736  * @params[in] macPeriodicty,
11737  *     SchedulingRequestResourceConfig__periodicityAndOffset pointer
11738  * @return void
11739  *
11740  * ****************************************************************/
11741
11742 void fillPucchSchedReqPeriodAndOffset(uint8_t macPeriodicty, uint16_t  macOffset,\
11743    struct SchedulingRequestResourceConfig__periodicityAndOffset *cuPeriodicty)
11744 {
11745    macPeriodicty = cuPeriodicty->present;
11746    switch(macPeriodicty)
11747    {
11748       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
11749          {
11750             macOffset     = cuPeriodicty->choice.sym2;
11751             break;
11752          }
11753       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
11754          {
11755             macOffset     = cuPeriodicty->choice.sym6or7;
11756             break;
11757          }
11758       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
11759          {
11760             macOffset     = cuPeriodicty->choice.sl1;
11761             break;
11762          }
11763       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
11764          {
11765             macOffset = cuPeriodicty->choice.sl2;
11766             break;
11767          }
11768       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
11769          {
11770             macOffset = cuPeriodicty->choice.sl4;
11771             break;
11772          }
11773       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
11774          {
11775             macOffset = cuPeriodicty->choice.sl5;
11776             break;
11777          }
11778       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
11779          {
11780             macOffset = cuPeriodicty->choice.sl8;
11781             break;
11782          }
11783       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
11784          {
11785             macOffset = cuPeriodicty->choice.sl10;
11786             break;
11787          }
11788       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
11789          {
11790             macOffset = cuPeriodicty->choice.sl16;
11791             break;
11792          }
11793       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
11794          {
11795             macOffset = cuPeriodicty->choice.sl20;
11796             break;
11797          }
11798       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
11799          {
11800             macOffset = cuPeriodicty->choice.sl40;
11801             break;
11802          }
11803       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
11804          {
11805             macOffset = cuPeriodicty->choice.sl80;
11806             break;
11807          }
11808       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
11809          {
11810             macOffset = cuPeriodicty->choice.sl160;
11811             break;
11812          }
11813       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
11814          {
11815             macOffset = cuPeriodicty->choice.sl320;
11816             break;
11817          }
11818       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
11819          {
11820             macOffset = cuPeriodicty->choice.sl640;
11821             break;
11822          }
11823       default :
11824          DU_LOG("\nERROR  -->  F1AP : Invalid periodicity %d", macPeriodicty);
11825    }
11826 }
11827
11828 /*******************************************************************
11829  *
11830  * @brief Function to extractPucchFormatCfg sent by CU
11831  *
11832  * @details
11833  *
11834  *    Function : extractPucchFormatCfg
11835  *
11836  *    Functionality: Function to extractPucchFormatCfg
11837  *
11838  * @params[in] PucchFormatCfg pointer,
11839  *             PUCCH_FormatConfig_t pointer
11840  * @return void
11841  *
11842  * ****************************************************************/
11843
11844 void extractPucchFormatCfg(PucchFormatCfg *macFormatCfg, PUCCH_FormatConfig_t *cuFormatCfg)
11845  {
11846     if(cuFormatCfg->interslotFrequencyHopping)
11847        macFormatCfg->interSlotFreqHop = *cuFormatCfg->interslotFrequencyHopping;
11848     if(cuFormatCfg->additionalDMRS)  
11849        macFormatCfg->addDmrs = *cuFormatCfg->additionalDMRS;
11850     if(cuFormatCfg->maxCodeRate)
11851        macFormatCfg->maxCodeRate = *cuFormatCfg->maxCodeRate;
11852     if(cuFormatCfg->nrofSlots)  
11853        macFormatCfg->numSlots = *cuFormatCfg->nrofSlots;
11854     if(cuFormatCfg->pi2BPSK)  
11855        macFormatCfg->pi2BPSK = *cuFormatCfg->pi2BPSK;
11856     if(cuFormatCfg->simultaneousHARQ_ACK_CSI)  
11857        macFormatCfg->harqAckCSI = *cuFormatCfg->simultaneousHARQ_ACK_CSI;
11858  }/* End of extractPucchFormatCfg */
11859
11860 /*******************************************************************
11861  *
11862  * @brief Function to extractSchedReqCfgToAddMod sent by CU
11863  *
11864  * @details
11865  *
11866  *    Function : extractSchedReqCfgToAddMod
11867  *
11868  *    Functionality: Function to extractSchedReqCfgToAddMod
11869  *
11870  * @params[in] PucchSchedReqCfg pointer,
11871  *      PUCCH_Config__schedulingRequestResourceToAddModList pointer
11872  * @return void
11873  *
11874  * ****************************************************************/
11875
11876 void extractSchedReqCfgToAddMod(PucchSchedReqCfg *macSchedReqCfg, struct PUCCH_Config__schedulingRequestResourceToAddModList *cuSchedReqList)
11877 {
11878    uint8_t arrIdx;
11879
11880    macSchedReqCfg->schedAddModListCount = cuSchedReqList->list.count;
11881    for(arrIdx = 0; arrIdx <  macSchedReqCfg->schedAddModListCount; arrIdx++)
11882    {
11883       macSchedReqCfg->schedAddModList[arrIdx].resrcId =\
11884          cuSchedReqList->list.array[arrIdx]->schedulingRequestResourceId;
11885       macSchedReqCfg->schedAddModList[arrIdx].requestId =\
11886          cuSchedReqList->list.array[arrIdx]->schedulingRequestID;
11887       if(cuSchedReqList->list.array[arrIdx]->periodicityAndOffset)
11888       {
11889          fillPucchSchedReqPeriodAndOffset(macSchedReqCfg->schedAddModList[arrIdx].periodicity,\
11890             macSchedReqCfg->schedAddModList[arrIdx].offset, cuSchedReqList->list.array[arrIdx]->periodicityAndOffset);
11891       }
11892       if(cuSchedReqList->list.array[arrIdx]->resource)
11893       {
11894          macSchedReqCfg->schedAddModList[arrIdx].resrc =\
11895             *cuSchedReqList->list.array[arrIdx]->resource;
11896       }
11897    }
11898
11899 }/* End of extractSchedReqCfgToAddMod */
11900
11901  /*******************************************************************
11902  *
11903  * @brief Fills PucchCfg received by CU
11904  *
11905  * @details
11906  *
11907  *    Function : extractPucchCfg
11908  *
11909  *    Functionality: Fills PucchCfg received  by CU
11910  *
11911  * @params[in] BWP_UplinkDedicated__pucch_Config *cuPucchCfg = Information which
11912  *                is send by CU, which we have stored in F1UeContextSetupDb,
11913  *             PucchCfg *macPucchCfg = Used to Store the information which
11914  *                needs to send in other layer, as well as this can be the variable
11915  *                which stores the information in DuCb,
11916  *             PucchCfg *storedPucchCfg = Null in case of sending the
11917  *                information to other layer else it will have Pucch Cfg which
11918  *                we have stored in copyOfmacUeCfg.
11919  * @return ROK/RFAILED
11920  *
11921  * ****************************************************************/
11922
11923 uint8_t extractPucchCfg(struct BWP_UplinkDedicated__pucch_Config *cuPucchCfg, PucchCfg *macPucchCfg,\
11924 PucchCfg *storedPucchCfg)        
11925 {
11926    uint8_t arrIdx;
11927
11928    if(cuPucchCfg->present == BWP_UplinkDedicated__pucch_Config_PR_setup)
11929    {
11930       if(cuPucchCfg->choice.setup)
11931       {
11932          /* Resource Set Cfg */ 
11933          if(cuPucchCfg->choice.setup->resourceSetToAddModList)
11934          {
11935             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrcSet, sizeof(PucchResrcSetCfg));
11936             if(macPucchCfg->resrcSet == NULLP)
11937             {
11938                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc set List in extractPucchCfg()");
11939                return RFAILED;
11940             }
11941             memset(macPucchCfg->resrcSet, 0, sizeof(PucchResrcSetCfg));
11942             extractResrcSetToAddModList(macPucchCfg->resrcSet, cuPucchCfg->choice.setup->resourceSetToAddModList);
11943          }
11944          
11945          /* Resource Cfg */ 
11946          if(cuPucchCfg->choice.setup->resourceToAddModList)
11947          {
11948             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrc, sizeof(PucchResrcCfg));
11949             if(macPucchCfg->resrc == NULLP)
11950             {
11951                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc List in extractPucchCfg()");
11952                return RFAILED;
11953             }
11954             memset(macPucchCfg->resrc, 0, sizeof(PucchResrcCfg));
11955             extractResrcToAddModList(macPucchCfg->resrc, cuPucchCfg->choice.setup->resourceToAddModList);
11956          }
11957          
11958          /* Format 1 Cfg */ 
11959          if(cuPucchCfg->choice.setup->format1)
11960          {
11961             DU_ALLOC_SHRABL_BUF(macPucchCfg->format1, sizeof(PucchFormatCfg));
11962             if(macPucchCfg->format1 == NULLP)
11963             {
11964                DU_LOG("\nERROR --> F1AP : Failed to extract format 1 Cfg in  extractPucchCfg()");
11965                return RFAILED;
11966             }
11967             memset(macPucchCfg->format1, 0, sizeof(PucchFormatCfg));
11968             extractPucchFormatCfg(macPucchCfg->format1,\
11969                cuPucchCfg->choice.setup->format1->choice.setup);
11970          }
11971          
11972          /* Format 2 Cfg */
11973          if(cuPucchCfg->choice.setup->format2)
11974          {
11975             DU_ALLOC_SHRABL_BUF(macPucchCfg->format2, sizeof(PucchFormatCfg));
11976             if(macPucchCfg->format2 == NULLP)
11977             {
11978                DU_LOG("\nERROR --> F1AP : Failed to extract format 2 Cfg in  extractPucchCfg()");
11979                return RFAILED;
11980             }
11981             memset(macPucchCfg->format2, 0, sizeof(PucchFormatCfg));
11982             extractPucchFormatCfg(macPucchCfg->format2,\
11983                cuPucchCfg->choice.setup->format2->choice.setup);
11984          }
11985          
11986          /* Format 3 Cfg */
11987          if(cuPucchCfg->choice.setup->format3)
11988          {
11989             DU_ALLOC_SHRABL_BUF(macPucchCfg->format3, sizeof(PucchFormatCfg));
11990             if(macPucchCfg->format3 == NULLP)
11991             {
11992                DU_LOG("\nERROR --> F1AP : Failed to extract format 3 Cfg in  extractPucchCfg()");
11993                return RFAILED;
11994             }
11995             memset(macPucchCfg->format3, 0, sizeof(PucchFormatCfg));
11996             extractPucchFormatCfg(macPucchCfg->format3,\
11997                cuPucchCfg->choice.setup->format3->choice.setup);
11998          }
11999
12000          /* Format 4 Cfg */
12001          if(cuPucchCfg->choice.setup->format4)
12002          {
12003             DU_ALLOC_SHRABL_BUF(macPucchCfg->format4, sizeof(PucchFormatCfg));
12004             if(macPucchCfg->format4 == NULLP)
12005             {
12006                DU_LOG("\nERROR --> F1AP : Failed to extract format 4 Cfg in  extractPucchCfg()");
12007                return RFAILED;
12008             }
12009             memset(macPucchCfg->format4, 0, sizeof(PucchFormatCfg));
12010             extractPucchFormatCfg(macPucchCfg->format4,\
12011                cuPucchCfg->choice.setup->format4->choice.setup);
12012          }
12013
12014          /* Sched Req List */
12015          if(cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList)
12016          {
12017             DU_ALLOC_SHRABL_BUF(macPucchCfg->schedReq, sizeof(PucchSchedReqCfg));
12018             if(macPucchCfg->schedReq == NULLP)
12019             {
12020                DU_LOG("\nERROR --> F1AP : Failed to extract schedReqCfg in  extractPucchCfg()");
12021                return RFAILED;
12022             }
12023             memset(macPucchCfg->schedReq, 0, sizeof(PucchSchedReqCfg));
12024             extractSchedReqCfgToAddMod(macPucchCfg->schedReq,\
12025             cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList);
12026          }
12027
12028          /*TODO: Add support for  Spatial Info */
12029
12030          /* MultiCsiCfg */
12031          if(cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList)
12032          {
12033             DU_ALLOC_SHRABL_BUF(macPucchCfg->multiCsiCfg, sizeof(PucchMultiCsiCfg));
12034             if(macPucchCfg->multiCsiCfg == NULLP)
12035             {
12036                DU_LOG("\nERROR --> F1AP : Failed to extract multiCsiCfg in  extractPucchCfg()");
12037                return RFAILED;
12038             }
12039             memset(macPucchCfg->multiCsiCfg, 0, sizeof(PucchMultiCsiCfg));
12040             macPucchCfg->multiCsiCfg->multiCsiResrcListCount = cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.count;
12041             for(arrIdx =0; arrIdx < macPucchCfg->multiCsiCfg->multiCsiResrcListCount; arrIdx++)
12042             {
12043                macPucchCfg->multiCsiCfg->multiCsiResrcList[arrIdx] =\
12044                  *cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.array[arrIdx];
12045             }
12046          }
12047
12048          /* Dl_DataToUL_ACK */ 
12049          if(cuPucchCfg->choice.setup->dl_DataToUL_ACK)
12050     {
12051        if(storedPucchCfg)
12052        {
12053           if(storedPucchCfg->dlDataToUlAck)
12054           {
12055              macPucchCfg->dlDataToUlAck = storedPucchCfg->dlDataToUlAck; 
12056           }
12057           else
12058           {
12059             DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
12060           }
12061        }
12062        else
12063        {
12064           DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
12065        }
12066        if(macPucchCfg->dlDataToUlAck == NULLP)
12067        {
12068           DU_LOG("\nERROR --> F1AP : Failed to extract Dl_DataToUL_ACK in extractPucchCfg()");
12069           return RFAILED;
12070        }
12071        memset(macPucchCfg->dlDataToUlAck, 0, sizeof(PucchDlDataToUlAck));
12072        macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount = cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.count;
12073        for(arrIdx = 0; arrIdx < macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; arrIdx++)
12074        {
12075           macPucchCfg->dlDataToUlAck->dlDataToUlAckList[arrIdx] =\
12076           *cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.array[arrIdx];
12077        }
12078          }
12079
12080          /* Power Control */
12081          if(cuPucchCfg->choice.setup->pucch_PowerControl)
12082          {
12083             DU_ALLOC_SHRABL_BUF(macPucchCfg->powerControl, sizeof(PucchPowerControl));
12084             if(macPucchCfg->powerControl == NULLP)
12085             {
12086                DU_LOG("\nERROR --> F1AP : Failed to extract power control in extractPucchCfg()");
12087                return RFAILED;
12088             }
12089             extractPucchPowerControl(macPucchCfg->powerControl,\
12090                cuPucchCfg->choice.setup->pucch_PowerControl);
12091          }
12092       }
12093    }
12094    return ROK;
12095 }
12096
12097 /*******************************************************************
12098  *
12099  * @brief Fills ServingCellReconfig received by CU
12100  *
12101  * @details
12102  *
12103  *    Function : extractSpCellDedicatedCfg
12104  *
12105  *    Functionality: Fills ServingCellReconfig received  by CU
12106  *
12107  * @params[in] ServingCellConfig_t *cuSrvCellCfg = Information which is send by
12108  *                  CU, which we have stored in F1UeContextSetupDb,
12109  *             ServCellCfgInfo *macSrvCellCfg = Used to Store the information
12110  *                  which  needs to send in other layer, as well as this can be the
12111  *                  variable which stores the information in DuCb, 
12112  *             ServCellCfgInfo *storedSrvCellCfg = Null in case of sending the
12113  *                  information to other layer else it will have ServCellCfgInfo which
12114  *                  we have stored in copyOfmacUeCfg.
12115  * @return ROK/RFAILD
12116  *
12117  * ****************************************************************/
12118 uint8_t extractSpCellDedicatedCfg(ServingCellConfig_t *cuSrvCellCfg, ServCellRecfgInfo *macSrvCellCfg,\
12119 ServCellRecfgInfo *storedSrvCellCfg)
12120 {
12121    uint8_t ret = ROK;
12122    BWP_DownlinkDedicated_t *dlBwp = NULLP;
12123    BWP_UplinkDedicated_t   *ulBwp = NULLP;
12124
12125    if(cuSrvCellCfg->initialDownlinkBWP)
12126    {
12127       dlBwp = ((BWP_DownlinkDedicated_t *)(cuSrvCellCfg->initialDownlinkBWP));
12128       if(dlBwp->pdcch_Config)
12129       {
12130          if(dlBwp->pdcch_Config->choice.setup)
12131          {
12132             macSrvCellCfg->initDlBwp.pdcchPresent = true;
12133             if(storedSrvCellCfg)
12134             {
12135                if(!storedSrvCellCfg->initDlBwp.pdcchPresent)
12136                {
12137                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12138                }
12139                else
12140                {
12141                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12142                }
12143             }
12144             else
12145             {
12146                extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12147             }
12148          }
12149       }
12150       if(dlBwp->pdsch_Config)
12151       {
12152          if(dlBwp->pdsch_Config->choice.setup)
12153          {
12154             macSrvCellCfg->initDlBwp.pdschPresent = true;
12155             
12156             if(storedSrvCellCfg)
12157             {
12158                if(!storedSrvCellCfg->initDlBwp.pdschPresent)
12159                {
12160                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
12161                }
12162                else
12163                {
12164                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg,\
12165                         &storedSrvCellCfg->initDlBwp.pdschCfg);
12166                }
12167             }
12168             else
12169             {
12170                extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
12171             }
12172          }
12173       }
12174    }
12175    if(cuSrvCellCfg->firstActiveDownlinkBWP_Id)
12176       macSrvCellCfg->firstActvDlBwpId = *(cuSrvCellCfg->firstActiveDownlinkBWP_Id);
12177    if(cuSrvCellCfg->defaultDownlinkBWP_Id)
12178       macSrvCellCfg->defaultDlBwpId = *(cuSrvCellCfg->defaultDownlinkBWP_Id);
12179    if(cuSrvCellCfg->bwp_InactivityTimer)
12180    {
12181       if(macSrvCellCfg->bwpInactivityTmr)
12182       {
12183          memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
12184       }
12185       else
12186       {
12187          macSrvCellCfg->bwpInactivityTmr = NULLP;
12188          DU_ALLOC_SHRABL_BUF(macSrvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
12189          if(macSrvCellCfg->bwpInactivityTmr)
12190          {
12191             memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
12192          }
12193          else
12194          {
12195             DU_LOG("\nERROR  --> F1AP : Memory Alloc failed for bwpInactivityTmr at extractSpCellDedicatedCfg()");
12196             return RFAILED;
12197          }
12198       }
12199    }
12200    if(cuSrvCellCfg->pdsch_ServingCellConfig)
12201    {
12202       if(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup)
12203       {
12204          ret = extractPdschServingCellCfg(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup, &macSrvCellCfg->pdschServCellCfg);
12205          if(ret == RFAILED)
12206          {
12207             DU_LOG("\nERROR --> F1AP : Failed at extractPdschServingCellCfg()");
12208             return RFAILED;
12209          }
12210       }
12211    }
12212    if(cuSrvCellCfg->uplinkConfig)
12213    {
12214       if(cuSrvCellCfg->uplinkConfig->initialUplinkBWP)
12215       {
12216          ulBwp = ((BWP_UplinkDedicated_t *)(cuSrvCellCfg->uplinkConfig->initialUplinkBWP));
12217          if(ulBwp->pusch_Config)
12218          {
12219             macSrvCellCfg->initUlBwp.puschPresent = true;
12220             extractPuschCfg(ulBwp->pusch_Config, &macSrvCellCfg->initUlBwp.puschCfg);
12221          }
12222          if(ulBwp->pucch_Config)
12223          {
12224             macSrvCellCfg->initUlBwp.pucchPresent = true;
12225             memset(&macSrvCellCfg->initUlBwp.pucchCfg, 0, sizeof(PucchCfg));
12226             if(storedSrvCellCfg)
12227             {
12228                if(!storedSrvCellCfg->initUlBwp.pucchPresent)
12229                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
12230                else
12231                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg,\
12232                   &storedSrvCellCfg->initUlBwp.pucchCfg);
12233             }
12234             else
12235             {
12236                extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
12237             }
12238          }
12239       }
12240       if(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id)
12241          macSrvCellCfg->firstActvUlBwpId = *(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id);
12242    }
12243    return ret;
12244 }
12245
12246 #ifdef NR_DRX
12247
12248 /*******************************************************************
12249  *
12250  * @brief fill long cycle offset value of drx in UE structure
12251  *
12252  * @details
12253  *
12254  *    Function : fillLongCycleOffsetValueInUeDb
12255  *
12256  *    Functionality: fill long cycle offset value of drx in UE structure
12257  *
12258  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
12259  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
12260  *
12261  * @return ROK     - success
12262  *         RFAILED - failure
12263  *
12264  * ****************************************************************/
12265 void fillLongCycleOffsetValueInUeDb(DrxLongCycleStartOffset *drxLongCycleStartOffset, struct DRX_ConfigRrc__drx_LongCycleStartOffset  *drx_LongCycleStartOffset)
12266 {
12267
12268    drxLongCycleStartOffset->drxLongCycleStartOffsetChoice = convertLongDrxCycleLengthEnumToValue(drx_LongCycleStartOffset->present);
12269    switch(drx_LongCycleStartOffset->present)
12270    {
12271       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
12272          {
12273             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10;
12274             break;
12275          }
12276       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
12277          {
12278             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms20;
12279             break;
12280          }
12281       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
12282          {
12283             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms32;
12284             break;
12285          }
12286       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
12287         {
12288             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms40;
12289             break;
12290          }
12291       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
12292          {
12293             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms60;
12294             break;
12295          }
12296       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
12297          {
12298             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms64;
12299             break;
12300          }
12301       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
12302          {
12303             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms70;
12304             break;
12305          }
12306       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
12307          {
12308             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms80;
12309             break;
12310          }
12311       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
12312          {
12313             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms128;
12314             break;
12315          }
12316       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
12317          {
12318             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms160;
12319             break;
12320          }
12321       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
12322          {
12323             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms256;
12324             break;
12325          }
12326       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
12327          {
12328             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms320;
12329             break;
12330          }
12331       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
12332          {
12333             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms512;
12334             break;
12335          }
12336       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
12337          {
12338             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms640;
12339             break;
12340          }
12341       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
12342          {
12343             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1024;
12344             break;
12345          }
12346       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
12347          {
12348             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1280;
12349             break;
12350          }
12351       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
12352          {
12353             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2048;
12354             break;
12355          }
12356       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
12357          {
12358             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2560;
12359             break;
12360          }
12361        case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
12362          {
12363             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms5120;
12364             break;
12365          }
12366       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
12367          {
12368             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10240;
12369             break;
12370          }
12371       default :
12372          break;
12373    }
12374 }
12375
12376 /*******************************************************************
12377  *
12378  * @brief Fills drx configuration structure with the help of drx_ConfigRrc
12379  *which recive from CU or storedDrxCfg which is already stored
12380  *
12381  * @details
12382  *
12383  *    Function : extractDrxConfiguration 
12384  *
12385  *    Functionality: Fills Reconfig Cell group Info received by CU
12386  *   
12387  * @params[in] cuMacCellGrpDrxConfig  = MAC_CellGroupConfig__drx_ConfigRrc information which
12388  *                       is send by CU, which we have stored in F1UeContextSetupDb
12389  *             DrxCfg * drxCfg  = Used to Store the information,
12390  *                      which needs to send in other layer, as well as this can be
12391  *                      the variable which stores the information in DuCb,
12392  *             DrxCfg *storedDrxCfg = Null in case of sending the
12393  *                      information to other layer else it will have the drx information 
12394  *                      stored in the copyOfmacUeCfg which we have stored in F1UeContextSetupDb.
12395  *
12396  * @return void
12397  *
12398  * ****************************************************************/
12399 void extractDrxConfiguration(struct MAC_CellGroupConfig__drx_ConfigRrc *cuMacCellGrpDrxConfig, DrxCfg * drxCfg, DrxCfg *storedDrxCfg)
12400 {
12401    struct DRX_ConfigRrc *cuDrxConfig;
12402
12403    if(storedDrxCfg)
12404    {
12405       memcpy(drxCfg, storedDrxCfg, sizeof(DrxCfg));
12406    }
12407    else
12408    {
12409       if(cuMacCellGrpDrxConfig)
12410       {
12411          switch(cuMacCellGrpDrxConfig->present)
12412          {
12413             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
12414                break;
12415
12416             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
12417                {
12418                   cuDrxConfig = cuMacCellGrpDrxConfig->choice.setup;
12419                   if(cuDrxConfig)
12420                   {
12421                      switch(cuDrxConfig->drx_onDurationTimer.present)
12422                      {
12423                         case DRX_ConfigRrc__drx_onDurationTimer_PR_NOTHING:
12424                            break;
12425                         case DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds:
12426                            {
12427                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = true;
12428                               drxCfg->drxOnDurationTimer.onDurationtimerValue.milliSeconds=convertOnDurationTimerMilliSecondsEnumToValue(cuDrxConfig->\
12429                               drx_onDurationTimer.choice.milliSeconds);
12430                               break;
12431                            }
12432                         case DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds:
12433                            {
12434                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = false;
12435                               drxCfg->drxOnDurationTimer.onDurationtimerValue.subMilliSeconds = cuDrxConfig->drx_onDurationTimer.choice.subMilliSeconds;
12436                               break;
12437                            }
12438                      }
12439                   }
12440                   fillLongCycleOffsetValueInUeDb(&drxCfg->drxLongCycleStartOffset, &cuDrxConfig->drx_LongCycleStartOffset);
12441                   drxCfg->drxInactivityTimer = convertDrxInactivityTimerEnumToValue(cuDrxConfig->drx_InactivityTimer);
12442                   drxCfg->drxHarqRttTimerDl = cuDrxConfig->drx_HARQ_RTT_TimerDL;
12443                   drxCfg->drxHarqRttTimerUl = cuDrxConfig->drx_HARQ_RTT_TimerUL;
12444                   drxCfg->drxRetransmissionTimerDl = convertDrxRetransmissionTimerDlEnumToValue(cuDrxConfig->drx_RetransmissionTimerDL);
12445                   drxCfg->drxRetransmissionTimerUl = convertDrxRetransmissionTimerUlEnumToValue(cuDrxConfig->drx_RetransmissionTimerUL);
12446                   drxCfg->drxSlotOffset = cuDrxConfig->drx_SlotOffset;
12447                   if(cuDrxConfig->shortDRX)
12448                   {
12449                      drxCfg->shortDrxPres=true;
12450                      drxCfg->shortDrx.drxShortCycle = convertShortDrxCycleLengthEnumToValue(cuDrxConfig->shortDRX->drx_ShortCycle);
12451                      drxCfg->shortDrx.drxShortCycleTimer = cuDrxConfig->shortDRX->drx_ShortCycleTimer;
12452                   }
12453                   else
12454                      drxCfg->shortDrxPres=false;
12455
12456                   break;
12457                }
12458
12459             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
12460                break;
12461          }
12462       }
12463    }
12464 }
12465 #endif
12466
12467 /*******************************************************************
12468  *
12469  * @brief Fills Reconfig Cell group Info received by CU
12470  *
12471  * @details
12472  *
12473  *    Function : extractUeRecfgCellInfo
12474  *
12475  *    Functionality: Fills Reconfig Cell group Info received by CU
12476  *   
12477  * @params[in] CellGroupConfigRrc_t *cellGrp = CellGroupConfigRrc_t information which
12478  *                       is send by CU, which we have stored in F1UeContextSetupDb
12479  *             DuMacUeCfg *MacUeCfg = Used to Store the information,
12480  *                      which needs to send in other layer, as well as this can be
12481  *                      the variable which stores the information in DuCb,
12482  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
12483  *                      information to other layer else it will have copyOfmacUeCfg
12484  *                      which we have stored in F1UeContextSetupDb.
12485  *
12486  * @return ROK/RFAILED
12487  *
12488  * ****************************************************************/
12489 uint8_t extractUeRecfgCellInfo(CellGroupConfigRrc_t *cellGrp, DuMacUeCfg *macUeCfg, DuMacUeCfg *storedMacUeCfg)
12490 {
12491    uint8_t ret = ROK;
12492    MAC_CellGroupConfig_t     *macCellGroup = NULLP;
12493    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
12494    SpCellConfig_t            *spcellCfg = NULLP;
12495    ServingCellConfig_t       *servCellCfg = NULLP;
12496
12497    if(cellGrp)
12498    {
12499       /* Fill MacCell Group Reconfig  */
12500       if(cellGrp->mac_CellGroupConfig)
12501       {
12502          macUeCfg->macCellGrpCfgPres = true;
12503          macCellGroup = ((MAC_CellGroupConfig_t *)(cellGrp->mac_CellGroupConfig));
12504
12505 #ifdef NR_DRX         
12506          if(macCellGroup->drx_ConfigRrc)
12507          {
12508             if(storedMacUeCfg)
12509             {
12510                if(!storedMacUeCfg->macCellGrpCfgPres) 
12511                {
12512                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL);    
12513                }
12514                else
12515                {
12516                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg, &storedMacUeCfg->macCellGrpCfg.drxCfg);    
12517                }
12518             }
12519             else
12520             {
12521                extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL); 
12522             }
12523          }
12524 #endif
12525
12526          if(macCellGroup->schedulingRequestConfig)
12527          {
12528             extractSchReqReConfig(macCellGroup->schedulingRequestConfig, &macUeCfg->macCellGrpCfg.schReqCfg);
12529          }
12530          if(macCellGroup->tag_Config)
12531          {
12532             extractTagReconfig(macCellGroup->tag_Config, &macUeCfg->macCellGrpCfg.tagCfg);
12533          }
12534          if(macCellGroup->bsr_Config)
12535          {
12536             macUeCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer = macCellGroup->bsr_Config->periodicBSR_Timer;
12537             macUeCfg->macCellGrpCfg.bsrTmrCfg.retxTimer     = macCellGroup->bsr_Config->retxBSR_Timer;
12538             if(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer)
12539             {
12540                macUeCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer  =\
12541                *(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer);
12542             }
12543          }
12544          if(macCellGroup->phr_Config)
12545          {
12546             if(macCellGroup->phr_Config->present == MAC_CellGroupConfig__phr_Config_PR_setup)
12547             {
12548                macUeCfg->macCellGrpCfg.phrCfgSetupPres = true;
12549                if(macCellGroup->phr_Config->choice.setup)
12550                {
12551                   macUeCfg->macCellGrpCfg.phrCfg.periodicTimer     = \
12552                   macCellGroup->phr_Config->choice.setup->phr_PeriodicTimer;
12553                   macUeCfg->macCellGrpCfg.phrCfg.prohibitTimer     = \
12554                   macCellGroup->phr_Config->choice.setup->phr_ProhibitTimer;
12555                   macUeCfg->macCellGrpCfg.phrCfg.txPowerFactor     = \
12556                   macCellGroup->phr_Config->choice.setup->phr_Tx_PowerFactorChange;
12557                   macUeCfg->macCellGrpCfg.phrCfg.multiplePHR       = \
12558                   macCellGroup->phr_Config->choice.setup->multiplePHR;
12559                   macUeCfg->macCellGrpCfg.phrCfg.dummy             = \
12560                   macCellGroup->phr_Config->choice.setup->dummy;
12561                   macUeCfg->macCellGrpCfg.phrCfg.phrType2OtherCell = \
12562                   macCellGroup->phr_Config->choice.setup->phr_Type2OtherCell;
12563                   macUeCfg->macCellGrpCfg.phrCfg.phrOtherCG        = \
12564                   macCellGroup->phr_Config->choice.setup->phr_ModeOtherCG;
12565                }
12566             }
12567          }
12568       }
12569       /* Fill Physical Cell Group Reconfig */
12570       if(cellGrp->physicalCellGroupConfig)
12571       {
12572          macUeCfg->phyCellGrpCfgPres = true;
12573          phyCellGrpCfg = ((PhysicalCellGroupConfig_t *)(cellGrp->physicalCellGroupConfig));
12574          if(phyCellGrpCfg->p_NR_FR1)
12575          {
12576             if(*(phyCellGrpCfg->p_NR_FR1) != macUeCfg->phyCellGrpCfg.pNrFr1)
12577                macUeCfg->phyCellGrpCfg.pNrFr1 = *(phyCellGrpCfg->p_NR_FR1);
12578          }
12579          macUeCfg->phyCellGrpCfg.pdschHarqAckCodebook = phyCellGrpCfg->pdsch_HARQ_ACK_Codebook;
12580       }
12581       /* Fill SpCell Reconfig */
12582       if(cellGrp->spCellConfig)
12583       {
12584          macUeCfg->spCellCfgPres = true;
12585          spcellCfg = ((SpCellConfig_t *)(cellGrp->spCellConfig));  
12586          if(spcellCfg->servCellIndex)
12587          {
12588             macUeCfg->spCellCfg.servCellIdx = *(spcellCfg->servCellIndex);
12589          }
12590          /* Fill Serving cell Reconfig info */
12591          if(cellGrp->spCellConfig->spCellConfigDedicated)
12592          {
12593             servCellCfg = ((ServingCellConfig_t *)(cellGrp->spCellConfig->spCellConfigDedicated));
12594             if(storedMacUeCfg)
12595             {
12596                if(!storedMacUeCfg->spCellCfgPres)
12597                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12598                else
12599                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg,\
12600                         &storedMacUeCfg->spCellCfg.servCellCfg);
12601             }
12602             else
12603             {
12604                ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12605             }
12606             if(ret == RFAILED)
12607             {
12608                DU_LOG("\nERROR --> F1AP : Failed at extractSpCellDedicatedCfg()");
12609             }
12610          }
12611       }
12612    }
12613    return ret;
12614 }
12615 /*******************************************************************
12616 *
12617 * @brief free the memory allocated by decoder
12618 *
12619 * @details
12620 *
12621 *    Function : freeAperDecodeNrcgi 
12622 *
12623 *    Functionality: Free Nrcgi values
12624 *
12625 * @params[in] NRCGI_t *nrcgi
12626 * @return void
12627 *
12628 * ****************************************************************/
12629
12630
12631 void freeAperDecodeNrcgi(NRCGI_t *nrcgi)
12632 {
12633     if(nrcgi->pLMN_Identity.buf != NULLP)
12634     {
12635        free(nrcgi->pLMN_Identity.buf);
12636     }
12637     if(nrcgi->nRCellIdentity.buf != NULLP)
12638     {
12639        free(nrcgi->nRCellIdentity.buf);
12640     }
12641 }
12642 /*******************************************************************
12643 *
12644 * @brief free the memory allocated by decoder
12645 *
12646 * @details
12647 *
12648 *    Function : freeAperDecodeCuToDuInfo 
12649 *
12650 *    Functionality:  Free Cu To Du Information
12651 *
12652 * @params[in] CUtoDURRCInformation_t *rrcMsg
12653 * @return void
12654 *
12655 * ****************************************************************/
12656
12657
12658 void freeAperDecodeCuToDuInfo(CUtoDURRCInformation_t *rrcMsg)
12659 {
12660    uint8_t ieIdx =0;
12661    uint8_t arrIdx =0;
12662
12663    if(rrcMsg->uE_CapabilityRAT_ContainerList)
12664    {
12665       if(rrcMsg->uE_CapabilityRAT_ContainerList->buf)
12666          free(rrcMsg->uE_CapabilityRAT_ContainerList->buf);
12667       free(rrcMsg->uE_CapabilityRAT_ContainerList);
12668    }
12669
12670    if(rrcMsg->iE_Extensions)
12671    {
12672       if(rrcMsg->iE_Extensions->list.array)
12673       {
12674          for(ieIdx= 0; ieIdx < rrcMsg->iE_Extensions->list.count; ieIdx++)
12675          {
12676             if(rrcMsg->iE_Extensions->list.array[ieIdx])
12677             {
12678                switch(rrcMsg->iE_Extensions->list.array[ieIdx]->id)
12679                {
12680                   case ProtocolIE_ID_id_CellGroupConfig:
12681                      if(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf != NULLP)
12682                      {
12683                         free(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf);
12684                      }
12685                      break;
12686                   default:
12687                      DU_LOG("\nERROR  -->  F1AP : Invalid Event type %ld at FreeCuToDuInfo()", \
12688                            rrcMsg->iE_Extensions->list.array[ieIdx]->id);
12689                      break;
12690                }
12691             }
12692          }
12693          for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
12694          {
12695             free(rrcMsg->iE_Extensions->list.array[arrIdx]);
12696          }
12697          free(rrcMsg->iE_Extensions->list.array);
12698
12699       }
12700
12701       free(rrcMsg->iE_Extensions);
12702    }
12703 }
12704 /*******************************************************************
12705 *
12706 * @brief free the memory allocated by decoder
12707 *
12708 * @details 
12709 *
12710 *    Function : freeAperDecodeSplCellList
12711 *
12712 *    Functionality: Free Spl Cell List 
12713                     where memory allocated by aper_decoder
12714 *
12715 * @params[in]  SCell_ToBeSetup_List_t *spCellLst
12716 * @return void
12717 *
12718 * ****************************************************************/
12719
12720
12721 void freeAperDecodeSplCellList(SCell_ToBeSetup_List_t *spCellLst)
12722 {
12723     uint8_t  cellIdx =0;
12724
12725     if(spCellLst->list.array != NULLP)
12726     {
12727        for(cellIdx=0; cellIdx<spCellLst->list.count; cellIdx++)
12728        {
12729           if(cellIdx==0&&spCellLst->list.array[cellIdx]!=NULLP)
12730           {
12731              freeAperDecodeNrcgi(&spCellLst->list.array[cellIdx]->value.choice.SCell_ToBeSetup_Item.sCell_ID);
12732           }
12733           if(spCellLst->list.array[cellIdx]!=NULLP)
12734           {
12735              free(spCellLst->list.array[cellIdx]);
12736           }
12737        }
12738        free(spCellLst->list.array);
12739     }
12740 }
12741 /*******************************************************************
12742 *
12743 * @brief free the memory allocated by decoder
12744 *
12745 * @details
12746 *
12747 *    Function : freeAperDecodeSRBSetup 
12748 *
12749 *    Functionality: added free part for the memory allocated by aper_decoder
12750 *
12751 * @params[in] SRBs_ToBeSetup_List_t *srbSet
12752 * @return void
12753 *
12754 ****************************************************************/
12755
12756
12757 void freeAperDecodeSRBSetup(SRBs_ToBeSetup_List_t *srbSet)
12758 {
12759     uint8_t srbIdx =0;
12760     if(srbSet->list.array != NULLP)
12761     {
12762        for(srbIdx=0; srbIdx<srbSet->list.count; srbIdx++)
12763        {
12764           if(srbSet->list.array[srbIdx]!=NULLP)
12765           {
12766              free(srbSet->list.array[srbIdx]);
12767           }
12768        }
12769        free(srbSet->list.array);
12770     }
12771 }
12772
12773 /*******************************************************************
12774 *
12775 * @brief free the memory allocated by decoder
12776 *
12777 * @details
12778 *
12779 *    Function : freeAperDecodeULTnlInfo
12780 *
12781 *    Functionality: added free part for the memory allocated by aper_decoder
12782 *
12783 * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
12784 * @return void
12785 *
12786 * ****************************************************************/
12787
12788
12789 void freeAperDecodeULTnlInfo(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
12790 {
12791    uint8_t ulIdx=0;
12792    if(ulInfo->list.array != NULLP)
12793    {
12794       for(ulIdx=0; ulIdx<ulInfo->list.count; ulIdx++)
12795       {
12796          if(ulIdx==0&&ulInfo->list.array[ulIdx]!=NULLP)
12797          {
12798             if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel!=NULLP)
12799             {
12800                if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12801                      transportLayerAddress.buf != NULLP)
12802                {
12803                   if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf\
12804                         !=NULLP)
12805                   {
12806                      free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf);
12807                   }
12808                   free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12809                         transportLayerAddress.buf);
12810                }
12811                free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel);
12812             }
12813          }
12814          if(ulInfo->list.array[ulIdx]!=NULLP)
12815          {
12816             free(ulInfo->list.array[ulIdx]);
12817          }
12818       }
12819       free(ulInfo->list.array);
12820    }
12821 }
12822 /*******************************************************************
12823 *
12824 * @brief free the memory allocated by decoder
12825 *
12826 * @details
12827 *
12828 *    Function : freeAperDecodeDRBSetup  
12829 *
12830 *    Functionality: free DRBSetup which is allocated by decoder
12831 *
12832 * @params[in]  DRBs_ToBeSetup_List_t *drbSet
12833 * @return void
12834 *
12835 * ****************************************************************/
12836
12837 void freeAperDecodeDRBSetup(DRBs_ToBeSetup_List_t *drbSet)
12838 {
12839    DRBs_ToBeSetup_Item_t *drbSetItem = NULLP;
12840    uint8_t  flowIdx =0;
12841    uint8_t  drbIdx =0;
12842
12843    if(drbSet->list.array != NULLP)
12844    {
12845       for(drbIdx=0; drbIdx<drbSet->list.count; drbIdx++)
12846       {
12847          if(drbIdx==0&&drbSet->list.array[drbIdx] != NULLP)
12848          {
12849             drbSetItem =&drbSet->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12850             if(drbSetItem->qoSInformation.choice.choice_extension != NULLP)
12851             {
12852                if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12853                      qoS_Characteristics.choice.non_Dynamic_5QI !=NULLP)
12854                {
12855                   if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12856                         qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12857                   {
12858                      if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12859                            qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12860                      {
12861
12862                         if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf!=NULLP)
12863                         {
12864
12865                            if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD!=NULLP)
12866                            {
12867
12868                               if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD->\
12869                                     buf!=NULLP)
12870                               {
12871
12872                                  if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.\
12873                                        flows_Mapped_To_DRB_List.list.array != NULLP)
12874                                  {
12875
12876                                     for(flowIdx=0;flowIdx<drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12877                                           DRB_Information.flows_Mapped_To_DRB_List.list.count; flowIdx++)
12878                                     {
12879
12880                                        if(flowIdx==0&&drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12881                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12882                                        {
12883                                           if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12884                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12885                                                 qoSFlowLevelQoSParameters.\
12886                                                 qoS_Characteristics.choice.non_Dynamic_5QI!=NULLP)
12887                                           {
12888                                              if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12889                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12890                                                    qoSFlowLevelQoSParameters.\
12891                                                    qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12892                                              {
12893
12894                                                 if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12895                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12896                                                       qoSFlowLevelQoSParameters.\
12897                                                       qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12898                                                 {
12899
12900
12901                                                    free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12902                                                          DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12903                                                          qoSFlowLevelQoSParameters.\
12904                                                          qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12905                                                 }
12906
12907                                                 free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12908                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12909                                                       qoSFlowLevelQoSParameters.\
12910                                                       qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12911                                              }
12912
12913                                              free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12914
12915                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12916                                                    qoSFlowLevelQoSParameters.\
12917                                                    qoS_Characteristics.choice.non_Dynamic_5QI);
12918                                           }
12919                                        }
12920                                        if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12921                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12922                                        {
12923
12924                                           free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12925                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]);
12926                                        }
12927                                     }
12928
12929                                     free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12930                                           DRB_Information.flows_Mapped_To_DRB_List.list.array);
12931                                  }
12932
12933                                  free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12934                                        DRB_Information.sNSSAI.sD->buf);
12935                               }
12936
12937                               free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD);
12938                            }
12939
12940                            free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf);
12941
12942                         }
12943
12944                         free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12945
12946                               qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12947                      }
12948
12949                      free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12950                            qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12951                   }
12952
12953                   free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12954                         qoS_Characteristics.choice.non_Dynamic_5QI);
12955                }
12956                free(drbSetItem->qoSInformation.choice.choice_extension);
12957             }
12958             freeAperDecodeULTnlInfo(&drbSetItem->uLUPTNLInformation_ToBeSetup_List);
12959             if(drbSetItem->uLConfiguration)
12960             {
12961                free(drbSetItem->uLConfiguration);
12962             }
12963          }
12964          if(drbSet->list.array[drbIdx]!=NULLP)
12965          {
12966             free(drbSet->list.array[drbIdx]);
12967          }
12968       }
12969       free(drbSet->list.array);
12970    }
12971 }
12972
12973
12974 /*******************************************************************
12975  *
12976  * @brief builds Mac Cell Cfg
12977  *
12978  * @details
12979  *
12980  *    Function : procUeRecfgCellInfo
12981  *
12982  *    Functionality: builds Mac Cell Cfg
12983  *
12984  * @params[in] DuMacUeCfg *macUeCfgToSend = Used to Store the information which
12985  *                       needs to send in other layer, as well as this can be
12986  *                       the variable which stores the information in DuCb.
12987  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
12988  *                       information to other layer else it will have copyOfmacUeCfg  
12989  *                       which we have stored in F1UeContextSetupDb
12990  *             void *cellInfo = CellGroupConfigRrc_t information which is send
12991  *                        by CU, which we have stored in F1UeContextSetupDb 
12992  *
12993  * @return void 
12994  *
12995  * ****************************************************************/
12996 uint8_t procUeRecfgCellInfo(DuMacUeCfg *macUeCfgToSend, DuMacUeCfg *storedMacUeCfg, void *cellInfo)
12997 {
12998    uint8_t ret = ROK;
12999    CellGroupConfigRrc_t *cellGrp = NULLP;
13000
13001    if(cellInfo)
13002    {
13003       cellGrp = (CellGroupConfigRrc_t *)cellInfo;
13004       ret = extractUeRecfgCellInfo(cellGrp, macUeCfgToSend, storedMacUeCfg);
13005       if(ret == RFAILED)
13006          DU_LOG("\nERROR  -->  F1AP : Failed at procUeRecfgCellInfo()");
13007    }
13008    if(ret == RFAILED)
13009    {
13010       freeUeRecfgCellGrpInfo(macUeCfgToSend);
13011    }
13012    return ret;
13013 }
13014
13015 /*******************************************************************
13016  *
13017  * @brief Filling modulation info in mac ue cfg
13018  *
13019  * @details
13020  *
13021  *    Function : duFillModulationDetails
13022  *
13023  *    Functionality: Filling modulation info in mac ue cfg
13024  *
13025  * @params[in] MAC UE Config to be updated
13026  *             Current UE configuration
13027  *             UE NR capability from CU
13028  * @return ROK     - success
13029  *         RFAILED - failure
13030  *
13031  * ****************************************************************/
13032 void duFillModulationDetails(DuMacUeCfg *ueCfg, DuMacUeCfg *oldUeCfg, void *ueCap)
13033 {
13034    UE_NR_Capability_t *ueNrCap=NULLP;
13035
13036    if(!ueCap && oldUeCfg)
13037    {
13038       memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));     
13039       memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13040    }
13041    else
13042    {
13043       ueNrCap = (UE_NR_Capability_t *)ueCap;
13044
13045       /* Filling DL modulation info */
13046       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsDownlinkPerCC && \
13047          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0] && \
13048          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL)
13049       {
13050          switch(*(ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL))
13051          {
13052             case ModulationOrder_qpsk:
13053                {
13054                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
13055                   break;
13056                }
13057             case ModulationOrder_qam16:
13058                {
13059                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM16;
13060                   break;
13061                }
13062             case ModulationOrder_qam64:
13063                {
13064                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM64;
13065                   ueCfg->dlModInfo.mcsIndex = PDSCH_MCS_INDEX;
13066                   ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64;
13067                   break;
13068                }
13069             case ModulationOrder_qam256:
13070                {
13071                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM256;
13072                   break;
13073                }
13074             default:
13075                {
13076                   DU_LOG("\nERROR  -->  DU APP: Incorrect downlink modulation order received. Reatining old modulation configuration");
13077                   if(oldUeCfg)
13078                      memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
13079                   break;
13080                }
13081          }
13082       }
13083       else
13084       {
13085          if(oldUeCfg)
13086             memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
13087       }
13088
13089       /* Filling UL modulation info */
13090       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsUplinkPerCC && \
13091          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0] && \
13092          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL)
13093       {
13094          switch(*(ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL))
13095          {
13096             case ModulationOrder_qpsk:
13097                {
13098                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
13099                   break;
13100                }
13101             case ModulationOrder_qam16:
13102                {
13103                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM16;
13104                   ueCfg->ulModInfo.mcsIndex = PUSCH_MCS_INDEX;
13105                   ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64;
13106                   break;
13107                }
13108             case ModulationOrder_qam64:
13109                {
13110                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM64;
13111                   break;
13112                }
13113             case ModulationOrder_qam256:
13114                {
13115                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM256;
13116                   break;
13117                }
13118             default:
13119                {
13120                   DU_LOG("\nERROR  -->  DU APP: Incorrect uplink modulation order received. Reatining old modulation configuration");
13121                   if(oldUeCfg)
13122                      memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13123                   break;
13124                }
13125          }
13126       }
13127       else
13128       {
13129          if(oldUeCfg)
13130             memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13131       }
13132    }
13133 }
13134
13135 /*******************************************************************
13136  *
13137  * @brief Function to extract info from CU to DU RRC container extension
13138  *
13139  * @details
13140  *
13141  *    Function : extractCuToDuRrcInfoExt
13142  *
13143  *    Functionality: Function to extract info from CU to DU RRC container
13144  *    extension
13145  *
13146  * @params[in] ProtocolExtensionContainer_4624P16_t pointer
13147  *
13148  * @return ROK
13149  *         RFAILED
13150  *
13151  * ****************************************************************/
13152 uint8_t extractCuToDuRrcInfoExt(ProtocolExtensionContainer_4624P16_t *protocolIeExtn, DuUeCfg *ueCfgDb)
13153 {
13154    uint8_t ieIdx =0;
13155    uint16_t recvBufLen =0;
13156    CellGroupConfigRrc_t *cellGrpCfg = NULLP;
13157    CUtoDURRCInformation_ExtIEs_t *extIeInfo = NULLP;
13158    asn_dec_rval_t rval; /* Decoder return value */
13159    memset(&rval, 0, sizeof(asn_dec_rval_t));
13160
13161    if(protocolIeExtn)
13162    {
13163       for(ieIdx = 0; ieIdx < protocolIeExtn->list.count; ieIdx++)
13164       {
13165          extIeInfo = ((CUtoDURRCInformation_ExtIEs_t *)(protocolIeExtn->list.array[ieIdx]));
13166          switch(extIeInfo->id)
13167          {
13168             case ProtocolIE_ID_id_CellGroupConfig:
13169                {
13170                   /* decoding the CellGroup Buf received */
13171                   recvBufLen = extIeInfo->extensionValue.choice.CellGroupConfig.size;
13172                   DU_ALLOC(cellGrpCfg, sizeof(CellGroupConfigRrc_t));
13173                   if(cellGrpCfg)
13174                   {
13175                      memset(cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
13176                      rval = uper_decode(0, &asn_DEF_CellGroupConfigRrc, (void **)&cellGrpCfg,
13177                            extIeInfo->extensionValue.choice.CellGroupConfig.buf, recvBufLen, 0, 0);
13178                      if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13179                      {
13180                         DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13181                         return RFAILED;
13182                      }
13183                      xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, cellGrpCfg);
13184
13185                      if(extractRlcCfgToAddMod(cellGrpCfg->rlc_BearerToAddModList, ueCfgDb))
13186                         return NULLP;
13187                      ueCfgDb->cellGrpCfg = cellGrpCfg;
13188                   }
13189                   break;
13190                }
13191
13192             case ProtocolIE_ID_id_HandoverPreparationInformation:
13193                {
13194                   DU_LOG("\nINFO -->  F1AP : Received HANDOVER PREPARATION INFO in UE CONTEXT SETUP REQUEST");
13195                   break;
13196                }
13197
13198             default:
13199                DU_LOG("\nERROR  -->  F1AP : Invalid IE received CUtoDURRCInformation: %ld at decodeCellGrpCfg()", extIeInfo->id);
13200                break;
13201          }
13202       }
13203    }
13204    return ROK;
13205 }
13206
13207 /*******************************************************************
13208  *
13209  * @brief Fills Srb List received by CU
13210  *
13211  * @details
13212  *
13213  *    Function : procSrbListToSetup
13214  *
13215  *    Functionality: Fills Srb List received  by CU
13216  *
13217  * @params[in] SRBs_ToBeSetup_Item_t *cuSrbItem
13218  *             DuLcCfg pointer
13219  *             RlcBearerCfg pointer
13220  * @return void
13221  *
13222  * ****************************************************************/
13223 uint8_t procSrbListToSetup(SRBs_ToBeSetup_Item_t * srbItem, DuLcCfg *duMacLcToAdd, DuRlcBearerCfg *rlcLcToAdd)
13224 {
13225
13226    /* Filling RLC INFO */
13227    procRlcLcCfg(srbItem->sRBID, srbItem->sRBID, RB_TYPE_SRB, RLC_AM, CONFIG_ADD, NULL, rlcLcToAdd, NULL);
13228
13229    /* Filling MAC INFO */
13230    if(procMacLcCfg(srbItem->sRBID, RB_TYPE_SRB, CONFIG_ADD, NULL,NULL, NULL, NULL, duMacLcToAdd, NULL)  != ROK)
13231    { 
13232       DU_LOG("\nERROR  -->  F1AP : Failed at MAC LC Cfg in procSrbListToSetup()");
13233       return RFAILED;
13234    }
13235
13236    return ROK;
13237 }
13238
13239
13240
13241 /*******************************************************************
13242  *
13243  * @brief extract Srb List received by CU
13244  *
13245  * @details
13246  *
13247  *    Function : extractSrbListToSetup
13248  *
13249  *    Functionality: extract Srb List received by CU
13250  *                   for both MAC and RLC
13251  *
13252  * @params[in] SRBs_ToBeSetup_Item_t pointer
13253  *             DuUeCfg pointer
13254  * @return ROK/RFAIED
13255  *
13256  * ****************************************************************/
13257
13258 uint8_t extractSrbListToSetup(SRBs_ToBeSetup_List_t *srbCfg, DuUeCfg *ueCfgDb)
13259 {
13260    uint8_t ret = ROK, srbIdx = 0, rlcLcIdx = 0;
13261    SRBs_ToBeSetup_Item_t *srbItem = NULLP;
13262    DuLcCfg *macLcCtxt = NULLP;
13263    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13264
13265    if(srbCfg)
13266    {
13267       for(srbIdx = 0; srbIdx < srbCfg->list.count; srbIdx++)
13268       {
13269          macLcCtxt = NULL;
13270          rlcLcCtxt = NULL;
13271
13272          srbItem = &srbCfg->list.array[srbIdx]->value.choice.SRBs_ToBeSetup_Item;
13273          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13274          { 
13275             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in MAC");
13276             ret = RFAILED;
13277             break;
13278          }
13279          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13280          {
13281             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in RLC");
13282             ret = RFAILED;
13283             break;
13284          }
13285
13286          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numMacLcs; rlcLcIdx++)
13287          {
13288             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == srbItem->sRBID && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
13289             {
13290                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13291                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13292                break;
13293             }
13294          }
13295          if(!macLcCtxt)
13296          {
13297             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13298             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13299             ueCfgDb->numMacLcs++;
13300          }
13301          if(!rlcLcCtxt)
13302          {
13303             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13304             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13305             ueCfgDb->numRlcLcs++;
13306          }
13307
13308          ret = procSrbListToSetup(srbItem, macLcCtxt, rlcLcCtxt);
13309
13310          DU_LOG("\nDEBUG --> DUAPP: extractSrbListToSetup: SRBID: %ld [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13311                srbItem->sRBID, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13312          if(ret == RFAILED)
13313          {
13314             DU_LOG("\nERROR  -->  F1AP:  Failed at extractSrbListToSetup()");
13315             break;
13316          }
13317       }
13318    }
13319    else
13320       ret = RFAILED;
13321
13322    return ret;
13323 }
13324
13325 /*******************************************************************
13326  *
13327  * @brief Fills Drb List received by CU
13328  *
13329  * @details
13330  *
13331  *    Function : procDrbListToSetupMod
13332  *
13333  *    Functionality: Fills Drb List received by CU
13334  *                   for both MAC and RLC
13335  *
13336  * @params[in] DRBs_ToBeSetup_Item_t , DRBs_ToBeSetupMod_Item_t,
13337  *             DRBs_ToBeModified_Item_t , lcId, DuLcCfg pointer,
13338  *             RlcBearerCfg , UpTnlCfg, DuRlcUeCfg
13339  * @return void
13340  *
13341  * ****************************************************************/
13342
13343 uint8_t procDrbListToSetupMod(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbItem,\
13344 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, DuLcCfg *macLcToAdd, DuRlcBearerCfg *rlcLcToAdd, UpTnlCfg *upTnlInfo, DuRlcUeCfg *storedRlcUeCfg)
13345 {
13346    uint8_t cfgIdx = 0;
13347    RlcMode rlcModeInfo;
13348
13349    if(drbItem != NULLP)
13350    {
13351       /* Filling RLC INFO */
13352       procRlcLcCfg(drbItem->dRBID, lcId, RB_TYPE_DRB, drbItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, &drbItem->\
13353       qoSInformation);
13354
13355       /* Filling MAC INFO */
13356       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, drbItem, NULL, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13357       { 
13358          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13359          return RFAILED;
13360       }
13361    }
13362    else if(drbSetupModItem != NULLP)
13363    {
13364       procRlcLcCfg(drbSetupModItem->dRBID, lcId, RB_TYPE_DRB, drbSetupModItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, 
13365       &drbSetupModItem->qoSInformation);
13366
13367       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, NULL, drbSetupModItem, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13368       {
13369          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13370          return RFAILED;
13371       }
13372    }
13373    else if(drbModItem != NULLP)
13374    {
13375       /* Drb to Mod IEs doesnot have rlcMode to be modified
13376        * in ASN. Hence no change in RLC configurations */
13377       if(storedRlcUeCfg != NULLP)
13378       {
13379          for(cfgIdx = 0; cfgIdx < storedRlcUeCfg->numLcs; cfgIdx++)
13380          {
13381             if(storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.lcId == lcId)
13382             {
13383                rlcModeInfo = storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.rlcMode;
13384                break;
13385             }
13386          }
13387       }
13388
13389       procRlcLcCfg(drbModItem->dRBID, lcId, RB_TYPE_DRB, rlcModeInfo, CONFIG_MOD, NULL, rlcLcToAdd, drbModItem->qoSInformation);
13390       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_MOD, NULL, NULL, drbModItem, NULL, macLcToAdd, upTnlInfo) != ROK)
13391       {
13392          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13393          return RFAILED;
13394       }
13395    }
13396    return ROK;
13397 }
13398
13399 /*******************************************************************
13400  *
13401  * @brief extract Drb List received by CU
13402  *
13403  * @details
13404  *
13405  *    Function : extractDrbListToSetupMod
13406  *
13407  *    Functionality: extract Drb List received by CU
13408  *                   for both MAC and RLC
13409  *
13410  * @params[in] DRBs_ToBeSetup_Item_t pointer
13411  *             DuUeCfg pointer
13412  * @return ROK/RFAIED
13413  *
13414  * ****************************************************************/
13415
13416 uint8_t extractDrbListToSetupMod(DRBs_ToBeSetup_List_t *drbCfg, DRBs_ToBeSetupMod_List_t *drbSetupModCfg,\
13417  DRBs_ToBeModified_List_t *drbModCfg, uint8_t drbCount, DuUeCfg *ueCfgDb, uint32_t *drbBitMap, DuRlcUeCfg *rlcUeCfg)
13418 {
13419    uint8_t ret = ROK;
13420    uint8_t drbIdx = 0, rlcLcIdx = 0;
13421    uint8_t drbId = 0, lcId = 0;
13422    DRBs_ToBeSetup_Item_t *drbItem = NULLP;
13423    DRBs_ToBeSetupMod_ItemIEs_t *drbSetupModItem = NULLP;
13424    DRBs_ToBeModified_ItemIEs_t *drbModItem = NULLP;
13425    DuLcCfg *macLcCtxt = NULLP;
13426    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13427
13428    ret = ROK;
13429    if(drbCount > 0)
13430    {
13431       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13432       {
13433          macLcCtxt = NULL;
13434          rlcLcCtxt = NULL;
13435
13436          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13437          { 
13438             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in MAC at extractDrbListToSetupMod()");
13439             ret = RFAILED;
13440             break;
13441          }
13442          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13443          {
13444             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in RLC at extractDrbListToSetupMod()");
13445             ret = RFAILED;
13446             break;
13447          }
13448
13449          if(drbModCfg != NULLP)
13450          {
13451             drbModItem = (DRBs_ToBeModified_ItemIEs_t *) drbModCfg->list.array[drbIdx];
13452             drbId = drbModItem->value.choice.DRBs_ToBeModified_Item.dRBID;
13453          }
13454          else if(drbCfg != NULLP)
13455             drbId = drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item.dRBID;
13456          else if(drbSetupModCfg != NULL)
13457          {
13458             drbSetupModItem = (DRBs_ToBeSetupMod_ItemIEs_t *) drbSetupModCfg->list.array[drbIdx];
13459             drbId = drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item.dRBID;
13460          }
13461
13462          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13463          {
13464             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && \
13465                    ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13466             {
13467                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13468                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13469                break;
13470             }
13471          }
13472          if(!macLcCtxt)
13473          {
13474             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13475             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13476             ueCfgDb->numMacLcs++;
13477          }
13478          if(!rlcLcCtxt)
13479          {
13480             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
13481             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13482             ueCfgDb->numRlcLcs++;
13483          }
13484
13485          if(drbModCfg != NULLP)
13486          {
13487             lcId = fetchLcId(drbId);
13488             if(lcId < MIN_DRB_LCID)
13489             {
13490                DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToSetupMod() for Modified List", lcId);
13491                break;
13492             } 
13493             ret = procDrbListToSetupMod(lcId, NULL, NULL, &(drbModItem->value.choice.DRBs_ToBeModified_Item),\
13494             macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13495             if(ret == RFAILED)
13496             {
13497                DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for Modified List");
13498                break;
13499             }
13500             ueCfgDb->numDrbModified++;
13501          }
13502          else
13503          {
13504             lcId = getDrbLcId(drbBitMap);
13505             if(lcId == RFAILED)
13506             {
13507                DU_LOG("\nERROR  -->  F1AP :  InCorrect LCID extractDrbListToSetupMod()");
13508                ret = RFAILED;
13509                break;
13510             }
13511             if(drbCfg != NULL)
13512             {
13513                drbItem = &drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
13514                ret = procDrbListToSetupMod(lcId, drbItem, NULL, NULL, macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13515                if(ret == RFAILED)
13516                {
13517                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetup List");
13518                   break;
13519                }
13520             }
13521             else if(drbSetupModCfg != NULL)
13522             {
13523                ret = procDrbListToSetupMod(lcId, NULL, &(drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item), NULL,\
13524                      macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13525                if(ret == RFAILED)
13526                {
13527                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetupMod List");
13528                   break;
13529                }
13530                ueCfgDb->numDrbSetupMod++;
13531             }
13532          }
13533          ueCfgDb->numDrb++;
13534  
13535          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToSetupMod:lcId:%x ,BitMap:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13536                             lcId,*drbBitMap, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13537          if(ret == RFAILED)
13538          {
13539             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod()");
13540             break;
13541          }
13542       }
13543    }
13544    else
13545       ret = RFAILED;
13546
13547    return ret;
13548 }
13549
13550 /*******************************************************************
13551  *
13552  * @brief extract Drb List received from CU
13553  *
13554  * @details
13555  *
13556  *    Function : extractDrbListToRelease
13557  *
13558  *    Functionality: extract Drb List received from CU
13559  *                   for both MAC and RLC
13560  *
13561  * @params[in] DRBs_ToBeReleased_Item_t pointer
13562  *             DuUeCfg pointer
13563  * @return ROK/RFAIED
13564  *
13565  * ****************************************************************/
13566
13567 uint8_t extractDrbListToRelease(uint8_t ueId, DRBs_ToBeReleased_List_t *drbToRel, uint8_t drbCount, DuUeCfg *ueCfgDb, DuRlcUeCfg *rlcUeCfg)
13568 {
13569    uint8_t ret = ROK, teIdx = 0;
13570    uint8_t drbIdx = 0, rlcLcIdx = 0;
13571    uint8_t drbId = 0, lcId = 0;
13572    DRBs_ToBeReleased_ItemIEs_t *drbRelItem = NULLP;
13573    DuLcCfg *macLcCtxt = NULLP;
13574    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13575
13576    ret = ROK;
13577    if(drbCount > 0)
13578    {
13579       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13580       {
13581          macLcCtxt = NULL;
13582          rlcLcCtxt = NULL;
13583
13584          if(drbToRel != NULLP)
13585          {
13586             drbRelItem = (DRBs_ToBeReleased_ItemIEs_t *) drbToRel->list.array[drbIdx];
13587             drbId = drbRelItem->value.choice.DRBs_ToBeReleased_Item.dRBID;
13588          }
13589          else
13590          {
13591             DU_LOG("ERROR  --> DU APP : DrbToRelease pointer is NULL in extractDrbListToRelease");
13592             return RFAILED;
13593          }
13594
13595          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13596          {
13597             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13598             {
13599                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13600                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13601                break;
13602             }
13603          }
13604
13605          if(!macLcCtxt)
13606          {
13607             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13608             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13609             ueCfgDb->numMacLcs++;
13610          }
13611          if(!rlcLcCtxt)
13612          {
13613             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13614             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13615             ueCfgDb->numRlcLcs++;
13616          }
13617          lcId = fetchLcId(drbId);
13618          if(lcId < MIN_DRB_LCID)
13619          {
13620             DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToRelease() for Modified List", lcId);
13621             break;
13622          } 
13623
13624          /* Filling RLC INFO */
13625          procRlcLcCfg(drbId, lcId, RB_TYPE_DRB, rlcLcCtxt->rlcBearerCfg.rlcMode, CONFIG_DEL, NULL, rlcLcCtxt, NULLP);
13626          /* Filling MAC INFO */
13627          if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_DEL, NULL, NULL, NULL, NULL, macLcCtxt, NULLP) != ROK)
13628          { 
13629             DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in extractDrbListToRelease()");
13630             return RFAILED;
13631          }
13632          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].configType = CONFIG_DEL;
13633          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId = drbId;
13634          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId = ueId;
13635
13636          for(teIdx = 0; teIdx < duCb.numTeId; teIdx++)
13637          {
13638             if((duCb.upTnlCfg[teIdx]->ueId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId) && \
13639                   (duCb.upTnlCfg[teIdx]->drbId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId))
13640             {
13641                DU_ALLOC(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, sizeof(GtpTnlCfg)); 
13642                memcpy(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, duCb.upTnlCfg[teIdx]->tnlCfg1, sizeof(GtpTnlCfg));
13643                break;
13644             }
13645          }
13646
13647          ueCfgDb->numDrb++;
13648          if(ret == RFAILED)
13649          {
13650             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToRelease() for Modified List");
13651             break;
13652          }
13653
13654          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToRelease():lcId:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13655                lcId,ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13656       }
13657    }
13658    else
13659       ret = RFAILED;
13660
13661    return ret;
13662 }
13663
13664 /*******************************************************************
13665  *
13666  * @brief Function to extract Dl RRC Msg received from CU
13667  *
13668  * @details
13669  *
13670  *    Function : extractDlRrcMsg
13671  *
13672  *    Functionality: Function to extract Dl RRC Msg received from CU
13673  *
13674  * @params[in] F1AP message
13675  * @return ROK     - success
13676  *         RFAILED - failure
13677  *
13678  * ****************************************************************/
13679
13680 uint8_t extractDlRrcMsg(uint32_t gnbDuUeF1apId, uint32_t gnbCuUeF1apId, \
13681    F1DlRrcMsg *dlRrcMsg, RRCContainer_t *rrcContainer)
13682 {
13683    uint8_t ret = ROK;
13684    dlRrcMsg->rrcMsgSize = rrcContainer->size;
13685    if(dlRrcMsg->rrcMsgSize > 0)
13686    {
13687       DU_ALLOC_SHRABL_BUF(dlRrcMsg->rrcMsgPdu, dlRrcMsg->rrcMsgSize);
13688       if(!dlRrcMsg->rrcMsgPdu)
13689       {
13690          DU_LOG("\nERROR  --> DU APP : Memory allocation failed for RRC Msg in extractDlRrcMsg()");
13691          ret = RFAILED;
13692       }
13693       else
13694       {
13695          dlRrcMsg->gnbDuUeF1apId = gnbDuUeF1apId;
13696          dlRrcMsg->gnbCuUeF1apId = gnbCuUeF1apId;
13697          dlRrcMsg->srbId = SRB1_LCID;
13698          memcpy(dlRrcMsg->rrcMsgPdu, rrcContainer->buf, dlRrcMsg->rrcMsgSize);
13699       }
13700    }
13701    return ret;
13702 }
13703
13704 /*******************************************************************
13705  *
13706  * @brief Extract UE capability info 
13707  *
13708  * @details
13709  *
13710  *    Function : extractUeCapability
13711  *
13712  *    Functionality: Extract UE capability info and stores in ue Cb
13713  *
13714  * @params[in] Octet string of UE capability RAT container list
13715  * @return ROK     - success
13716  *         RFAILED - failure
13717  *
13718  * ****************************************************************/
13719 UE_NR_Capability_t *extractUeCapability(UE_CapabilityRAT_ContainerList_t *ueCapablityListBuf, DuUeCb *ueCb)
13720 {
13721    uint8_t  idx;
13722    uint16_t recvBufLen;
13723    asn_dec_rval_t rval;
13724    UE_NR_Capability_t  *ueNrCap = NULLP;
13725    UE_CapabilityRAT_ContainerListRRC_t  *ueCapRatContList = NULLP;
13726
13727    /* Decoding UE Capability RAT Container List */
13728    recvBufLen = ueCapablityListBuf->size;
13729    DU_ALLOC(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13730    if(!ueCapRatContList)
13731    {
13732       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13733       return NULLP;
13734    }
13735    memset(ueCapRatContList, 0, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13736    memset(&rval, 0, sizeof(asn_dec_rval_t));
13737    rval = uper_decode(0, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, (void **)&ueCapRatContList,
13738           ueCapablityListBuf->buf, recvBufLen, 0, 0);
13739    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13740    {
13741       DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13742       return NULLP;
13743    }
13744    xer_fprint(stdout, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, ueCapRatContList);
13745
13746    /* Free encoded buffer after decoding */
13747
13748    for(idx = 0; idx < ueCapRatContList->list.count; idx++)
13749    {
13750       if(ueCapRatContList->list.array[idx]->rat_Type == RAT_Type_nr)
13751       {
13752          /* Decoding UE NR Capability */
13753           recvBufLen = ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.size;
13754           DU_ALLOC(ueNrCap, sizeof(UE_NR_Capability_t));
13755           if(!ueNrCap)
13756           {
13757              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13758              DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13759              return NULLP;
13760           } 
13761           memset(ueNrCap, 0, sizeof(UE_NR_Capability_t));
13762           memset(&rval, 0, sizeof(asn_dec_rval_t));
13763           rval = uper_decode(0, &asn_DEF_UE_NR_Capability, (void **)&ueNrCap,
13764                  ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf, recvBufLen, 0, 0);
13765           if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13766           {
13767              DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13768              return NULLP;
13769           }
13770           xer_fprint(stdout, &asn_DEF_UE_NR_Capability, ueNrCap);
13771           
13772           /* Free encoded buffer after decoding */
13773           free(ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf);
13774       }
13775       free(ueCapRatContList->list.array[idx]);
13776    }
13777
13778    /* Free Memory*/
13779    free(ueCapRatContList->list.array);
13780    DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13781    return ueNrCap;
13782 }
13783  
13784 /*******************************************************************
13785 *
13786 * @brief free UE context setup request from CU
13787 *
13788 * @details
13789 *
13790 *    Function : freeAperDecodeF1UeContextSetupReq
13791 *
13792 *    Functionality: freeing part for the memory allocated by aper_decoder
13793 *
13794 * @params[in] F1AP message
13795 * @return ROK     - success
13796 *         RFAILED - failure
13797 *
13798 * ****************************************************************/
13799 void freeAperDecodeF1UeContextSetupReq(UEContextSetupRequest_t   *ueSetReq)
13800 {
13801    uint8_t ieIdx = 0;
13802
13803    if(ueSetReq->protocolIEs.list.array != NULLP)
13804    {
13805       for(ieIdx = 0; ieIdx < ueSetReq->protocolIEs.list.count; ieIdx++)
13806       {
13807          if(ueSetReq->protocolIEs.list.array[ieIdx])
13808          {
13809             switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13810             {
13811                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13812                   break;
13813                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13814                   break;
13815                case ProtocolIE_ID_id_SpCell_ID:
13816                   freeAperDecodeNrcgi(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
13817                   break;
13818                case ProtocolIE_ID_id_ServCellIndex:
13819                   break;
13820                case ProtocolIE_ID_id_SpCellULConfigured:
13821                   break;
13822                case ProtocolIE_ID_id_CUtoDURRCInformation:
13823
13824                   freeAperDecodeCuToDuInfo(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation);
13825                   break;
13826                case ProtocolIE_ID_id_SCell_ToBeSetup_List:
13827
13828                   freeAperDecodeSplCellList(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SCell_ToBeSetup_List);
13829                   break;
13830                case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
13831
13832                   freeAperDecodeSRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List);
13833                   break;
13834                case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
13835
13836                   freeAperDecodeDRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List);
13837                   break;
13838                case ProtocolIE_ID_id_RRCContainer:
13839                   {
13840
13841                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf != NULLP)
13842                      {
13843
13844                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
13845                      }
13846                      break;
13847                   }
13848                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13849                   break;
13850                case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
13851                   {
13852                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf)
13853                      {
13854                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf);
13855                      }
13856                      break;
13857                   }
13858 #ifdef NR_DRX
13859                case ProtocolIE_ID_id_DRXCycle:
13860                   {
13861                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength)
13862                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength);
13863                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer)
13864                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer);
13865                      break;
13866                   }
13867 #endif             
13868                 default:
13869                   DU_LOG("\nERROR  -->  F1AP: Invalid event type %ld " ,ueSetReq->protocolIEs.list.array[ieIdx]->id);
13870             } 
13871             free(ueSetReq->protocolIEs.list.array[ieIdx]);
13872          }
13873       }
13874       free(ueSetReq->protocolIEs.list.array);
13875    }
13876 }
13877 /*******************************************************************
13878  *
13879  * @brief Process UE context setup request from CU
13880  *
13881  * @details
13882  *
13883  *    Function : procF1UeContextSetupReq
13884  *
13885  *    Functionality: Process UE context setup request from CU
13886  *
13887  * @params[in] F1AP message
13888  * @return ROK     - success
13889  *         RFAILED - failure
13890  *
13891  * ****************************************************************/
13892 uint8_t procF1UeContextSetupReq(F1AP_PDU_t *f1apMsg)
13893 {
13894    int8_t ueIdx = -1;
13895    uint8_t  ret=0, ieIdx=0, ieExtIdx = 0;
13896    //uint8_t servCellIdx = 0;
13897    bool ueCbFound = false, hoInProgress = false;
13898    uint16_t cellIdx=0;
13899    uint64_t nrCellId = 0;
13900    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0, bitRateSize=0;
13901    DuUeCb   *duUeCb = NULL;
13902    UEContextSetupRequest_t   *ueSetReq = NULL;
13903    DRBs_ToBeSetup_List_t *drbCfg = NULL;
13904    CUtoDURRCInformation_t *rrcInfo = NULL;
13905 #ifdef NR_DRX
13906    DRXCycle_t *drxCycle;
13907 #endif
13908    ret = ROK;
13909
13910    ueSetReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextSetupRequest;
13911    for(ieIdx=0; (ieIdx < ueSetReq->protocolIEs.list.count && ret == ROK); ieIdx++)
13912    {
13913       switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13914       {
13915          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13916             {
13917                gnbCuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
13918                break;
13919             }
13920
13921          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13922             {
13923                gnbDuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
13924                break;
13925             }
13926
13927          case ProtocolIE_ID_id_SpCell_ID:
13928             {
13929                bitStringToInt(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity, &nrCellId);
13930
13931                GET_CELL_IDX(nrCellId, cellIdx);
13932                if(!duCb.actvCellLst[cellIdx])
13933                {
13934                   DU_LOG("\nERROR  -->  F1AP : Cell Id [%lu] not found", nrCellId);
13935                   ret = RFAILED;
13936                }
13937                break;
13938             }
13939
13940          case ProtocolIE_ID_id_ServCellIndex:
13941             {
13942                //servCellIdx = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.ServCellIndex;
13943                break;
13944             }
13945
13946          case ProtocolIE_ID_id_SpCellULConfigured:
13947             {
13948                /* Indicates whether the gNB-CU requests the gNB-DU to configure the uplink as no UL, 
13949                   UL, SUL or UL+SUL for the indicated cell for the UE */
13950                break;
13951             }
13952
13953          case ProtocolIE_ID_id_CUtoDURRCInformation:
13954             {
13955                rrcInfo = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation;
13956
13957                /* Search if UE context is present */
13958                for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
13959                {
13960                   if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId)
13961                   {
13962                      ueCbFound = true;
13963                      duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13964                      break;
13965                   }
13966                }
13967
13968                /* Check if UE Handover scenario */
13969                if(rrcInfo->iE_Extensions)
13970                {
13971                   for(ieExtIdx = 0; ieExtIdx < rrcInfo->iE_Extensions->list.count; ieExtIdx++)
13972                   {
13973                      if(rrcInfo->iE_Extensions->list.array[ieExtIdx]->id == ProtocolIE_ID_id_HandoverPreparationInformation)
13974                      {
13975                         hoInProgress = true;
13976                         break;
13977                      }
13978                   }
13979                }
13980                
13981                /* If UE context is not present, but UE is in handover */
13982                if(!ueCbFound && hoInProgress)
13983                {
13984                   ueIdx = getFreeBitFromUeBitMap(nrCellId);
13985                   if(ueIdx != -1)
13986                      gnbDuUeF1apId = ueIdx +1;
13987                   else
13988                   {
13989                      DU_LOG("\nERROR  -->  F1AP : No free UE IDX found in UE bit map of cell Id [%lu]", nrCellId);
13990                      ret = RFAILED;
13991                      break;
13992                   }
13993                   duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13994                   duUeCb->f1UeDb = NULL;
13995                   duUeCb->gnbCuUeF1apId = gnbCuUeF1apId;
13996                   duUeCb->gnbDuUeF1apId = gnbDuUeF1apId;
13997                   GET_CRNTI(duUeCb->crnti, duUeCb->gnbDuUeF1apId);
13998                   duUeCb->ueState = UE_HANDIN_IN_PROGRESS;
13999                }
14000
14001                if(duUeCb)
14002                {
14003                   DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
14004                   if(duUeCb->f1UeDb)
14005                   {
14006                      memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
14007                      duUeCb->f1UeDb->actionType = UE_CTXT_SETUP;
14008                      duUeCb->f1UeDb->cellIdx = cellIdx;
14009                   }
14010                   else
14011                   {
14012                      DU_LOG("\nERROR  -->  F1AP: Memory Alloc Failed at procF1UeContextSetupReq()");
14013                      ret = RFAILED;
14014                      break;
14015                   }
14016                }
14017                else
14018                {
14019                   DU_LOG("\nERROR  -->  F1AP: DuUeCb is not found at procF1UeContextSetupReq()");
14020                   ret = RFAILED;
14021                   break;
14022                }
14023                  
14024                /* Extract UE capability info */
14025                if(rrcInfo->uE_CapabilityRAT_ContainerList)
14026                {
14027                   duUeCb->f1UeDb->duUeCfg.ueNrCapability = extractUeCapability(rrcInfo->uE_CapabilityRAT_ContainerList, duUeCb);
14028                }
14029
14030                /* Extract IE extension */
14031                if(rrcInfo->iE_Extensions)
14032                {
14033                   if(extractCuToDuRrcInfoExt(rrcInfo->iE_Extensions, &duUeCb->f1UeDb->duUeCfg) != ROK)
14034                   {
14035                      DU_LOG("\nERROR  -->  F1AP: Failed to extract CU to DU RRC information extension IE");
14036                      //TODO: Update the failure cause in ue context Setup Response
14037                      ret = RFAILED;
14038                   }
14039                }
14040                break;
14041             } 
14042
14043 #ifdef NR_DRX
14044          case ProtocolIE_ID_id_DRXCycle:
14045             {
14046                duUeCb->f1UeDb->duUeCfg.drxCyclePres = true;
14047                drxCycle = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle;
14048                duUeCb->f1UeDb->duUeCfg.drxCycle.drxLongCycleLength =  convertLongDrxCycleLengthEnumToValue(drxCycle->longDRXCycleLength);
14049                if(drxCycle->shortDRXCycleLength)
14050                {
14051                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCyclePres = true;
14052                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycle = \
14053                   convertShortDrxCycleLengthEnumToValue(*(drxCycle->shortDRXCycleLength));
14054                }
14055                if(drxCycle->shortDRXCycleTimer)
14056                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycleTimer = *(drxCycle->shortDRXCycleTimer);   
14057
14058                break;
14059             }
14060
14061 #endif
14062          case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
14063             {
14064                if(extractSrbListToSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List,\
14065                         &duUeCb->f1UeDb->duUeCfg))
14066                {
14067                   DU_LOG("\nERROR  -->  DU APP : Failed at extractSrbListToSetup()");
14068                   //TODO: Update the failure cause in ue context Setup Response
14069                   ret = RFAILED;
14070                }
14071                break;
14072             }
14073
14074          case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
14075             {
14076                drbCfg = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List;
14077
14078                if(extractDrbListToSetupMod(drbCfg, NULL, NULL, drbCfg->list.count, &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULLP))
14079                {
14080                   DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod()");
14081                   //TODO: Update the failure cause in ue context Setup Response
14082                   ret = RFAILED;
14083                }
14084                break;
14085             }
14086          case ProtocolIE_ID_id_RRCContainer:
14087             {
14088                /* Filling Dl RRC Msg Info */
14089                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
14090                if(!duUeCb->f1UeDb->dlRrcMsg)
14091                {
14092                   DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for DL RRC Msg in procUeCtxtSetupReq()");
14093                   ret = RFAILED;
14094                }
14095                else
14096                {
14097                   duUeCb->f1UeDb->dlRrcMsgPres = true;
14098                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
14099                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
14100                         &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer);
14101                }          
14102                break;
14103             }
14104
14105          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
14106             {
14107                if(duUeCb->f1UeDb->dlRrcMsg)
14108                {
14109                   if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
14110                   {
14111                      duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
14112                   }
14113                   else
14114                   {
14115                      DU_LOG("\nERROR  -->  Ignoring delivery report, since rrcContainer is not present");
14116                   }
14117                }
14118                break;
14119             }
14120
14121          case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
14122             {
14123                /* MaximumBitRate Uplink */
14124                bitRateSize = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.size;
14125                if(bitRateSize > 0)
14126                {
14127                   DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->duUeCfg.ambrCfg, bitRateSize);
14128                   if(!duUeCb->f1UeDb->duUeCfg.ambrCfg)
14129                   {
14130                      DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for bitRate in procUeCtxtSetupReq");
14131                      ret = RFAILED;
14132                   }
14133                   else
14134                   {
14135                      memset(duUeCb->f1UeDb->duUeCfg.ambrCfg, 0, sizeof(AmbrCfg)); 
14136                      memcpy(&duUeCb->f1UeDb->duUeCfg.ambrCfg->ulBr,
14137                            ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf, bitRateSize);
14138                   }
14139                }
14140                else
14141                   ret = RFAILED;
14142                break;
14143             }
14144
14145          default:
14146             {
14147                break;
14148             }
14149       } /* End of switch */
14150
14151       /* In case of any failure in any IE */
14152       if(ret == RFAILED)
14153       {
14154          // BuildAndSendUeContextSetupRsp(cellId,ueId);
14155          DU_LOG("\nERROR  -->  F1AP: Failed to process UE CNTXT SETUP REQ at procF1UeContextSetupReq()"); 
14156          break;
14157       }
14158    } /* End of for loop of IEs */
14159
14160    if(ret == ROK)
14161       ret = duProcUeContextSetupRequest(duUeCb);
14162
14163    freeAperDecodeF1UeContextSetupReq(ueSetReq); 
14164    return ret;
14165
14166 }
14167 /*******************************************************************
14168  * @brief Free the memory allocated for Dl Tunnel Info
14169  *
14170  * @details
14171  *
14172  *    Function : freeDlTnlInfo
14173  *
14174  *    Functionality:
14175  *       Free the memory allocated for Dl Tunnel Info
14176  *
14177  * @params[in] DLUPTNLInformation_ToBeSetup_List_t *
14178  * @return void
14179  *
14180  * ****************************************************************/
14181
14182 void freeDlTnlInfo(DLUPTNLInformation_ToBeSetup_List_t *tnlInfo)
14183 {
14184    uint8_t arrIdx = 0;
14185
14186    if(tnlInfo)
14187    {
14188       for(arrIdx=0; arrIdx < tnlInfo->list.count; arrIdx++)
14189       {
14190          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf,\
14191                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.size);
14192          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf,\
14193                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.size);
14194          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14195          DU_FREE(tnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14196       }
14197       DU_FREE(tnlInfo->list.array, tnlInfo->list.size);
14198    }
14199 }
14200
14201 /*******************************************************************
14202  * @brief Free the memory allocated for DRB setup List
14203  *
14204  * @details
14205  *
14206  *    Function : freeDrbSetupList
14207  *
14208  *    Functionality:
14209  *       Free the memory allocated for DRB setup list
14210  *
14211  * @params[in] DRBs_Setup_List_t *
14212  * @return void
14213  *
14214  * ****************************************************************/
14215 void freeDrbSetupList(DRBs_Setup_List_t *drbSetupList)
14216 {
14217    uint8_t arrIdx = 0;
14218    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14219
14220    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
14221    {
14222       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14223       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List);
14224       DU_FREE(drbSetupList->list.array[arrIdx],  sizeof(DRBs_Setup_Item_t));
14225    }
14226    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
14227 }
14228
14229 /*******************************************************************
14230  * @brief Free the memory allocated for UE Setup response
14231  *
14232  * @details
14233  *
14234  *    Function : FreeUeContextSetupRsp
14235  *
14236  *    Functionality:
14237  *       Free the memory allocated for UE Setup response
14238  *
14239  * @params[in] F1AP PDU for UE setup response
14240  * @return ROK     - success
14241  *         RFAILED - failure
14242  *
14243  * ****************************************************************/
14244 void FreeUeContextSetupRsp(F1AP_PDU_t *f1apMsg)
14245 {
14246    uint8_t idx;
14247    UEContextSetupResponse_t *ueSetRsp = NULLP;
14248
14249    if(f1apMsg)
14250    {
14251       if(f1apMsg->choice.successfulOutcome)
14252       {
14253          ueSetRsp = &f1apMsg->choice.successfulOutcome->value.choice.\
14254                     UEContextSetupResponse;
14255          if(ueSetRsp->protocolIEs.list.array)
14256          {
14257             for(idx = 0; idx < ueSetRsp->protocolIEs.list.count; idx++)
14258             {
14259                if(ueSetRsp->protocolIEs.list.array[idx])
14260                {
14261                   switch(ueSetRsp->protocolIEs.list.array[idx]->id)
14262                   {
14263                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14264                         break;
14265                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14266                         break;
14267                      case ProtocolIE_ID_id_C_RNTI:
14268                         break;
14269                      case ProtocolIE_ID_id_DUtoCURRCInformation:
14270                         {
14271                            CellGroupConfig_t *cellGrpCfg = NULLP;
14272                            cellGrpCfg  = &ueSetRsp->protocolIEs.list.array[idx]->value.choice.\
14273                                          DUtoCURRCInformation.cellGroupConfig;
14274                            if(cellGrpCfg->buf != NULLP)
14275                            {
14276                               DU_FREE(cellGrpCfg->buf, cellGrpCfg->size);
14277                               cellGrpCfg = NULLP;
14278                            }
14279                            break;
14280                         }
14281                      case ProtocolIE_ID_id_DRBs_Setup_List:
14282                         {
14283                            freeDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List); 
14284                            break;
14285                         }
14286                      default:
14287                         DU_LOG("\nERROR  -->  DUAPP: Invalid Id %ld at FreeUeContextSetupRsp()",\
14288                               ueSetRsp->protocolIEs.list.array[idx]->id);
14289                         break;
14290                   }
14291                   DU_FREE(ueSetRsp->protocolIEs.list.array[idx],\
14292                         sizeof(UEContextSetupResponseIEs_t));
14293                }
14294             }
14295             DU_FREE(ueSetRsp->protocolIEs.list.array, \
14296                   ueSetRsp->protocolIEs.list.size);
14297          }
14298          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14299       }
14300       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14301    }
14302 }
14303
14304 /*******************************************************************
14305  *
14306  * @brief Builds Ue context Setup Rsp DU To CU Info
14307  *
14308  * @details
14309  *
14310  *    Function : EncodeUeCntxtDuToCuInfo
14311  *
14312  *    Functionality: Builds Ue context Setup Rsp DU To CU Info
14313  *
14314  * @params[in] CellGroupConfig_t *, CellGroupConfigRrc_t * 
14315  *
14316  * @return ROK     - success
14317  *         RFAILED - failure
14318  *
14319  ******************************************************************/
14320
14321 uint8_t EncodeUeCntxtDuToCuInfo(CellGroupConfig_t *duToCuCellGrp, CellGroupConfigRrc_t *duCellGrpCfg)
14322 {
14323    asn_enc_rval_t        encRetVal;
14324
14325    xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, duCellGrpCfg);
14326    memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14327    encBufSize = 0;
14328    encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, duCellGrpCfg, PrepFinalEncBuf, encBuf);
14329    /* Encode results */
14330    if(encRetVal.encoded == ENCODE_FAIL)
14331    {
14332       DU_LOG( "\nERROR  -->  F1AP : Could not encode UeCntxtDuToCuInfo (at %s)\n",\
14333             encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14334       return RFAILED;
14335    }
14336    else
14337    {
14338       DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UeCntxtDuToCuInfo\n");
14339 #ifdef DEBUG_ASN_PRINT
14340       for(int i=0; i< encBufSize; i++)
14341       {
14342          printf("%x",encBuf[i]);
14343       }
14344 #endif
14345    }
14346    duToCuCellGrp->size = encBufSize;
14347    DU_ALLOC(duToCuCellGrp->buf, duToCuCellGrp->size);
14348    if(!duToCuCellGrp->buf)
14349    {
14350       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in UeCntxtDuToCuInfo");
14351    }
14352    memcpy(duToCuCellGrp->buf, encBuf, duToCuCellGrp->size);
14353    return ROK;
14354 }
14355
14356 /*******************************************************************
14357  *
14358  * @brief Fills Dl Gtp tunnel Info
14359  *
14360  * @details
14361  *
14362  *    Function : fillGtpTunnelforDl
14363  *
14364  *    Functionality: Fills Dl Gtp tunnel Info
14365  *
14366  * @params[in] 
14367  *
14368  * @return ROK     - success
14369  *         RFAILED - failure
14370  *
14371  * ****************************************************************/
14372
14373 uint8_t fillGtpTunnelforDl(GTPTunnel_t *gtpDl, GtpTnlCfg *gtpUeCfg)
14374 {
14375    uint8_t bufSize = 0;
14376
14377    gtpDl->transportLayerAddress.size    = 4*sizeof(uint8_t);
14378    DU_ALLOC(gtpDl->transportLayerAddress.buf, gtpDl->transportLayerAddress.size);
14379    if(gtpDl->transportLayerAddress.buf == NULLP)
14380    {
14381       return RFAILED;
14382    }
14383    memcpy(gtpDl->transportLayerAddress.buf, &gtpUeCfg->dlTnlAddress, gtpDl->transportLayerAddress.size);
14384
14385    /*GTP TEID*/
14386    gtpDl->gTP_TEID.size = 4 * sizeof(uint8_t);
14387    DU_ALLOC(gtpDl->gTP_TEID.buf, gtpDl->gTP_TEID.size);
14388    if(gtpDl->gTP_TEID.buf == NULLP)
14389    {
14390       return RFAILED;
14391    }
14392    bufSize = 3; /*forming an Octect String*/
14393    fillTeIdString(bufSize, gtpUeCfg->teId, gtpDl->gTP_TEID.buf);
14394
14395    return ROK;
14396 }
14397
14398 /*******************************************************************
14399  *
14400  * @brief Fills DL Tunnel Setup List
14401  *
14402  * @details
14403  *
14404  *    Function : fillDlTnlSetupList
14405  *
14406  *    Functionality: Fills the DL Tunnel Setup List
14407  *
14408  * @params[in] 
14409  *
14410  * @return ROK     - success
14411  *         RFAILED - failure
14412  *
14413  * ****************************************************************/
14414
14415 uint8_t fillDlTnlSetupList(DLUPTNLInformation_ToBeSetup_List_t *dlTnlInfo, UpTnlCfg *tnlCfg)
14416 {
14417    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14418
14419    eleCount = 1;
14420    dlTnlInfo->list.count = eleCount; 
14421    dlTnlInfo->list.size = (eleCount * sizeof(DLUPTNLInformation_ToBeSetup_Item_t *));
14422
14423    /* Initialize the DL Tnl Setup List Members */
14424    DU_ALLOC(dlTnlInfo->list.array, dlTnlInfo->list.size);
14425    if(dlTnlInfo->list.array == NULLP)
14426    {
14427       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL Tnl Setup List in fillDlTnlSetupList()");
14428       ret = RFAILED;
14429    }
14430    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14431    {
14432       DU_ALLOC(dlTnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14433       if(dlTnlInfo->list.array[arrIdx] == NULLP)
14434       {
14435          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDlTnlSetupList()", arrIdx);
14436          return RFAILED;
14437       }
14438       dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.present = UPTransportLayerInformation_PR_gTPTunnel;
14439       DU_ALLOC(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14440       if(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel == NULLP)
14441       {
14442          DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL tunnel info in fillDlTnlSetupList()");
14443          return RFAILED;
14444       }
14445       ret = fillGtpTunnelforDl(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel,\
14446                tnlCfg->tnlCfg1);
14447       if(ret != ROK)
14448          break;
14449    }
14450    return ret;
14451 }
14452
14453 /*******************************************************************
14454  *
14455  * @brief Fills the Drb Setup List for Ue Context Setup Response
14456  *
14457  * @details
14458  *
14459  *    Function : fillDrbSetupList
14460  *
14461  *    Functionality: Fills the Drb Setup List for Ue Context Setup Response
14462  *
14463  * @params[in] 
14464  *
14465  * @return ROK     - success
14466  *         RFAILED - failure
14467  *
14468  * ****************************************************************/
14469 uint8_t fillDrbSetupList(DRBs_Setup_List_t *drbSetupList, DuUeCfg *ueCfg)
14470 {
14471    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14472    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14473
14474    eleCount = ueCfg->numDrb;
14475    drbSetupList->list.count = eleCount;
14476    drbSetupList->list.size = \
14477         (eleCount * sizeof(DRBs_Setup_Item_t *));
14478
14479    /* Initialize the Drb Setup List Members */
14480    DU_ALLOC(drbSetupList->list.array, drbSetupList->list.size);
14481    if(drbSetupList->list.array == NULLP)
14482    {
14483       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DRB Setup List in fillDrbSetupList()");
14484       ret = RFAILED;
14485    }
14486
14487    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14488    {
14489       DU_ALLOC(drbSetupList->list.array[arrIdx], sizeof(DRBs_Setup_Item_t));
14490       if(drbSetupList->list.array[arrIdx] == NULLP)
14491       {
14492          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDrbSetupList()", arrIdx);
14493          return RFAILED;
14494       }
14495       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14496       drbItemIe->id = ProtocolIE_ID_id_DRBs_Setup_Item;
14497       drbItemIe->criticality = Criticality_reject;
14498       drbItemIe->value.present = DRBs_Setup_ItemIEs__value_PR_DRBs_Setup_Item;
14499       drbItemIe->value.choice.DRBs_Setup_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
14500       ret = fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List,\
14501           &ueCfg->upTnlInfo[arrIdx]);
14502       if(ret != ROK)
14503          break;
14504    }
14505    return ret;
14506 }
14507
14508 /*******************************************************************
14509  *
14510  * @brief Builds and sends the UE Setup Response
14511  *
14512  * @details
14513  *
14514  *    Function : BuildAndSendUeContextSetupRsp
14515  *
14516  *    Functionality: Constructs the UE Setup Response and sends
14517  *                   it to the DU through SCTP.
14518  *
14519  * @params[in] uint8_t cellId,uint8_t ueId
14520  *
14521  * @return ROK     - success
14522  *         RFAILED - failure
14523  *
14524  * ****************************************************************/
14525 uint8_t BuildAndSendUeContextSetupRsp(uint8_t cellId,uint8_t ueId)
14526 {
14527    uint8_t   idx, ret, cellIdx, elementCnt;
14528    uint32_t  gnbCuUeF1apId;   /* gNB-CU UE F1AP Id */
14529    uint32_t  gnbDuUeF1apId;   /* gNB-DU UE F1AP Id */
14530    asn_enc_rval_t  encRetVal;        /* Encoder return value */
14531    F1AP_PDU_t               *f1apMsg = NULLP;
14532    UEContextSetupResponse_t *ueSetRsp = NULLP;
14533    DuUeCb                   *ueCb = NULLP;
14534
14535    DU_LOG("\n INFO   -->  F1AP : Building UE Context Setup Response for cellId %d, ueId %d\n", cellId, ueId);
14536
14537    while(true)
14538    {
14539       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14540       if(f1apMsg == NULLP)
14541       {
14542          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14543          ret = RFAILED;
14544          break;
14545       }
14546
14547       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
14548       DU_ALLOC(f1apMsg->choice.successfulOutcome,
14549             sizeof(SuccessfulOutcome_t));
14550       if(f1apMsg->choice.successfulOutcome == NULLP)
14551       {
14552          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
14553          ret = RFAILED;
14554          break;
14555       }
14556
14557       f1apMsg->choice.successfulOutcome->procedureCode = \
14558                                                          ProcedureCode_id_UEContextSetup;
14559       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
14560       f1apMsg->choice.successfulOutcome->value.present = \
14561                                                          SuccessfulOutcome__value_PR_UEContextSetupResponse;
14562
14563       ueSetRsp =
14564          &f1apMsg->choice.successfulOutcome->value.choice.UEContextSetupResponse;
14565       elementCnt = 5;
14566       ueSetRsp->protocolIEs.list.count = elementCnt;
14567       ueSetRsp->protocolIEs.list.size = \
14568                                         elementCnt * sizeof(UEContextSetupResponse_t *);
14569
14570       /* Initialize the UESetup members */
14571       DU_ALLOC(ueSetRsp->protocolIEs.list.array, \
14572             ueSetRsp->protocolIEs.list.size);
14573       if(ueSetRsp->protocolIEs.list.array == NULLP)
14574       {
14575          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14576          ret = RFAILED;
14577          break;
14578       }
14579
14580       for(idx=0; idx<elementCnt; idx++)
14581       {
14582          DU_ALLOC(ueSetRsp->protocolIEs.list.array[idx],\
14583                sizeof(UEContextSetupResponseIEs_t));
14584          if(ueSetRsp->protocolIEs.list.array[idx] == NULLP)
14585          {
14586             DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14587             ret = RFAILED;
14588             break;
14589          }
14590       }
14591       /* Fetching Ue Cb Info*/
14592       GET_CELL_IDX(cellId, cellIdx);
14593       gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
14594       gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
14595       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
14596
14597       idx = 0;
14598       /*GNB CU UE F1AP ID*/
14599       ueSetRsp->protocolIEs.list.array[idx]->id = \
14600                                                   ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
14601       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14602       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14603                                                              UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
14604       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
14605
14606       /*GNB DU UE F1AP ID*/
14607       idx++;
14608       ueSetRsp->protocolIEs.list.array[idx]->id = \
14609                                                   ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14610       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14611       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14612                                                              UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
14613       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
14614
14615
14616       /*DUtoCURRC Information */
14617       idx++;
14618       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14619                                                    ProtocolIE_ID_id_DUtoCURRCInformation;
14620       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14621       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14622                                                             UEContextSetupResponseIEs__value_PR_DUtoCURRCInformation;
14623       BuildCellGroupConfigRrc(ueCb, &ueSetRsp->protocolIEs.list.array[idx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
14624
14625       /* CRNTI */
14626       idx++;
14627       ueSetRsp->protocolIEs.list.array[idx]->id  = ProtocolIE_ID_id_C_RNTI;
14628       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14629       ueSetRsp->protocolIEs.list.array[idx]->value.present = UEContextSetupResponseIEs__value_PR_C_RNTI;
14630       ueSetRsp->protocolIEs.list.array[idx]->value.choice.C_RNTI = ueCb->crnti; 
14631
14632
14633       /* Drb Setup List */
14634       idx++;
14635       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14636                                                    ProtocolIE_ID_id_DRBs_Setup_List;
14637       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14638       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14639                                                             UEContextSetupResponseIEs__value_PR_DRBs_Setup_List;
14640       ret = fillDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List,\
14641             &ueCb->f1UeDb->duUeCfg);
14642       if(ret == RFAILED)
14643       {
14644          DU_LOG("\nERROR  -->  F1AP : Failed to fillDrbSetupList in BuildAndSendUeContextSetupRsp()");
14645          freeF1UeDb(ueCb->f1UeDb);
14646          ueCb->f1UeDb = NULLP;
14647          break;
14648       }
14649
14650       /* Free UeContext Db created during Ue context Req */
14651       freeF1UeDb(ueCb->f1UeDb);
14652       ueCb->f1UeDb = NULLP;
14653
14654       /* TODO: To send Drb list */
14655       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14656
14657       /* Encode the UE context setup response type as APER */
14658       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14659       encBufSize = 0;
14660       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14661             encBuf);
14662       /* Encode results */
14663       if(encRetVal.encoded == ENCODE_FAIL)
14664       {
14665          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Response structure (at %s)\n",\
14666                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14667          ret = RFAILED;
14668          break;
14669       }
14670       else
14671       {
14672          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Setup Response\n");
14673 #ifdef DEBUG_ASN_PRINT
14674          for(int i=0; i< encBufSize; i++)
14675          {
14676             printf("%x",encBuf[i]);
14677          }
14678 #endif
14679       }
14680
14681       /* Sending  msg  */
14682       if(sendF1APMsg()  != ROK)
14683       {
14684          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Response failed");
14685          ret = RFAILED;
14686          break;
14687       }
14688       break;
14689    }
14690    FreeUeContextSetupRsp(f1apMsg);
14691    return ret;
14692 }/* End of BuildAndSendUeContextSetupRsp */
14693
14694 /*******************************************************************
14695 *
14696 * @brief  Build And Send Ue Context Rsp 
14697 *
14698 * @details
14699 *
14700 *    Function : BuildAndSendUeCtxtRsp 
14701 *
14702 *    Functionality : Build And Send Ue Context Rsp
14703
14704 * @params[in]
14705 * @return sucess = ROK
14706 *         failure = RFAILED
14707 *
14708 * ****************************************************************/
14709 uint8_t BuildAndSendUeCtxtRsp(uint8_t cellId, uint8_t ueId)
14710 {
14711    uint8_t cellIdx = 0, actionType = 0; 
14712
14713    GET_CELL_IDX(cellId, cellIdx);
14714    actionType = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].f1UeDb->actionType;
14715
14716    switch(actionType)
14717    {
14718       case UE_CTXT_SETUP:
14719          {
14720             if((BuildAndSendUeContextSetupRsp(cellId,ueId)) != ROK)
14721             {
14722                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextSetupRsp()");
14723                return RFAILED;
14724             }
14725             break;
14726          }
14727       case UE_CTXT_MOD:
14728          {
14729             if((BuildAndSendUeContextModRsp(&duCb.actvCellLst[cellIdx]->ueCb[ueId-1])) != ROK)
14730             {
14731                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextModRsp");
14732                return RFAILED;
14733             }
14734             break;
14735          }
14736       default:
14737          DU_LOG("ERROR  -->  F1AP: Invalid Action Type %d at BuildAndSendUeCtxtRsp()", actionType);
14738          break;
14739
14740    }
14741    return ROK;
14742 }
14743
14744 /*******************************************************************
14745  *
14746  * @brief deallocating the memory of  F1reset msg
14747  *
14748  * @details
14749  *
14750  *    Function : FreeF1ResetReq
14751  *
14752  *    Functionality :
14753  *         - freeing memory of F1reset request msg
14754  *
14755  * @params[in]
14756  * @return void
14757  *
14758  *
14759  * ****************************************************************/
14760 void FreeF1ResetReq(F1AP_PDU_t *f1apMsg)
14761 {
14762    uint8_t idx =0 ;
14763    Reset_t *f1ResetMsg;
14764
14765    if(f1apMsg)
14766    {
14767       if(f1apMsg->choice.initiatingMessage)
14768       {
14769          f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14770
14771          if(f1ResetMsg->protocolIEs.list.array)
14772          {
14773             for(idx=0 ;idx < f1ResetMsg->protocolIEs.list.count ; idx++)
14774             {
14775                if(f1ResetMsg->protocolIEs.list.array[idx])
14776                {
14777                   DU_FREE(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14778                }
14779             }
14780             DU_FREE(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14781          }
14782          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14783       }
14784       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14785    }
14786 }
14787 /*******************************************************************
14788  *
14789  * @brief Build and Send F1reset request 
14790  *
14791  * @details
14792  *
14793  *    Function : BuildAndSendF1ResetReq
14794  *
14795  *    Functionality:
14796  *         - Build and Send F1reset request msg
14797  *
14798  * @params[in]
14799  * @return ROK     - success
14800  *         RFAILED - failure
14801  *
14802  * ****************************************************************/
14803 uint8_t BuildAndSendF1ResetReq()
14804 {
14805    uint8_t          elementCnt=0;
14806    uint8_t          idx=0;
14807    uint8_t          ret= RFAILED;
14808    Reset_t          *f1ResetMsg = NULLP;
14809    F1AP_PDU_t       *f1apMsg = NULLP;
14810    asn_enc_rval_t   encRetVal;
14811    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset request \n");
14812    do
14813    {
14814       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14815       if(f1apMsg == NULLP)
14816       {
14817          break;
14818       }
14819       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
14820       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14821       if(f1apMsg->choice.initiatingMessage == NULLP)
14822       {
14823          break;
14824       }
14825       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_Reset;
14826       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
14827       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_Reset;
14828
14829       f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14830
14831       elementCnt = 3;
14832       f1ResetMsg->protocolIEs.list.count = elementCnt;
14833       f1ResetMsg->protocolIEs.list.size = elementCnt * sizeof(ResetIEs_t *);
14834
14835       /* Initialize the F1Setup members */
14836       DU_ALLOC(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14837       if(f1ResetMsg->protocolIEs.list.array == NULLP)
14838       {
14839          break;
14840       }
14841       for(idx=0; idx<elementCnt; idx++)
14842       {
14843          DU_ALLOC(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14844          if(f1ResetMsg->protocolIEs.list.array[idx] == NULLP)
14845          {
14846             break;
14847          }
14848       }
14849
14850       /*TransactionID*/
14851       idx=0;
14852       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
14853       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14854       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_TransactionID;
14855       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.TransactionID = 1;
14856
14857       /*Cause*/
14858       idx++;
14859       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_Cause;
14860       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_ignore;
14861       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_Cause;
14862       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.present = Cause_PR_radioNetwork;
14863       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.choice.radioNetwork = CauseRadioNetwork_action_desirable_for_radio_reasons;
14864
14865       /*Reset Type*/
14866       idx++;
14867       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_ResetType;
14868       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14869       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_ResetType;
14870       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.present = ResetType_PR_f1_Interface;
14871       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.choice.f1_Interface = ResetAll_reset_all;
14872
14873       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14874
14875       /* Encode the F1SetupRequest type as APER */
14876       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14877       encBufSize = 0;
14878       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14879             encBuf);
14880
14881       /* Encode results */
14882       if(encRetVal.encoded == ENCODE_FAIL)
14883       {
14884          DU_LOG("\nERROR  -->  F1AP : Could not encode F1Reset structure (at %s)\n",\
14885                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14886          break;
14887       }
14888       else
14889       {
14890          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1Reset\n");
14891 #ifdef DEBUG_ASN_PRINT
14892          for(idx=0; idx< encBufSize; idx++)
14893          {
14894             printf("%x",encBuf[idx]);
14895          }
14896 #endif
14897       }
14898
14899       if(sendF1APMsg() != ROK)
14900       {
14901          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset request failed");
14902          break;
14903       }
14904
14905       ret = ROK;
14906       break;
14907    }while(true);
14908
14909    FreeF1ResetReq(f1apMsg);
14910    return ret;
14911 }
14912 /*******************************************************************
14913  *
14914  * @brief Build And Send F1ResetAck
14915  *
14916  * @details
14917  *
14918  *    Function : BuildAndSendF1ResetAck
14919  *
14920  *    Functionality:
14921  *         - Build And Send  F1ResetRSP
14922  *
14923  * @return ROK     - success
14924  *         RFAILED - failure
14925  *
14926  * ****************************************************************/
14927 void FreeF1ResetAck(F1AP_PDU_t *f1apMsg)
14928 {
14929    uint8_t idx;
14930    ResetAcknowledge_t *f1ResetAck;
14931
14932    if(f1apMsg)
14933    {
14934       if(f1apMsg->choice.successfulOutcome)
14935       {
14936          f1ResetAck= &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14937
14938          if(f1ResetAck->protocolIEs.list.array)
14939          {
14940             for(idx=0; idx<f1ResetAck->protocolIEs.list.count ; idx++)
14941             {
14942                if(f1ResetAck->protocolIEs.list.array[idx])
14943                {
14944                   DU_FREE(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14945                }
14946             }
14947             DU_FREE(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14948          }
14949          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14950       }
14951       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14952    }
14953 }
14954
14955 /*******************************************************************
14956  *
14957  * @brief Build And Send F1ResetAck
14958  *
14959  * @details
14960  *
14961  *    Function : BuildAndSendF1ResetAck
14962  *
14963  *    Functionality:
14964  *         - Build And Send  F1ResetRSP
14965  *
14966  *  @params[in]
14967  * @return ROK     - success
14968  *         RFAILED - failure
14969  *
14970  * ****************************************************************/
14971 uint8_t BuildAndSendF1ResetAck()
14972 {
14973    uint8_t                idx = 0;
14974    uint8_t                elementCnt = 0;
14975    uint8_t                ret = RFAILED;
14976    F1AP_PDU_t             *f1apMsg = NULL;
14977    ResetAcknowledge_t     *f1ResetAck = NULLP;
14978    asn_enc_rval_t         encRetVal;
14979    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset Acknowledgment \n");
14980
14981    do{
14982       /* Allocate the memory for F1ResetRequest_t */
14983       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14984       if(f1apMsg == NULLP)
14985       {
14986          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14987          break;
14988       }
14989
14990       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
14991
14992       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14993       if(f1apMsg->choice.successfulOutcome == NULLP)
14994       {
14995          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14996          break;
14997       }
14998       f1apMsg->choice.successfulOutcome->criticality   = Criticality_reject;
14999       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetAcknowledge;
15000       f1ResetAck = &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
15001
15002       elementCnt = 1;
15003
15004       f1ResetAck->protocolIEs.list.count = elementCnt;
15005       f1ResetAck->protocolIEs.list.size = elementCnt*sizeof(ResetAcknowledgeIEs_t *);
15006
15007       DU_ALLOC(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
15008       if(f1ResetAck->protocolIEs.list.array == NULLP)
15009       {
15010          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1ResetAckIEs failed");
15011          break;
15012       }
15013
15014       for(idx=0; idx<elementCnt; idx++)
15015       {
15016          DU_ALLOC(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
15017          if(f1ResetAck->protocolIEs.list.array[idx] == NULLP)
15018          {
15019             break;
15020          }
15021       }
15022       /*TransactionID*/
15023       idx = 0;
15024       f1ResetAck->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
15025       f1ResetAck->protocolIEs.list.array[idx]->criticality = Criticality_reject;
15026       f1ResetAck->protocolIEs.list.array[idx]->value.present = ResetAcknowledgeIEs__value_PR_TransactionID;
15027       f1ResetAck->protocolIEs.list.array[idx]->value.choice.TransactionID = TRANS_ID;
15028
15029       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15030
15031       /* Encode the F1SetupRequest type as UPER */
15032       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15033       encBufSize = 0;
15034       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
15035
15036       /* Check encode results */
15037       if(encRetVal.encoded == ENCODE_FAIL)
15038       {
15039          DU_LOG("\nERROR  -->  F1AP : Could not encode F1ResetAck structure (at %s)\n",\
15040                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15041          break;
15042       }
15043       else
15044       {
15045          DU_LOG("\nDUBUG   -->  F1AP : Created APER encoded buffer for F1ResetAck\n");
15046 #ifdef DEBUG_ASN_PRINT
15047          for(int i=0; i< encBufSize; i++)
15048          {
15049             printf("%x",encBuf[i]);
15050          }
15051 #endif
15052       }
15053       /* Sending msg */
15054       if(sendF1APMsg() != ROK)
15055       {
15056          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset Acknowledgement failed");
15057          break;
15058       }
15059
15060       ret = ROK;
15061       break;
15062    }while(true);
15063
15064    FreeF1ResetAck(f1apMsg);
15065    return ret;
15066 }
15067 /******************************************************************
15068 *
15069 * @brief free F1 reset msg allocated by aper_decoder 
15070 *
15071 * @details
15072 *
15073 *    Function : freeAperDecodeF1ResetMsg 
15074 *
15075 *    Functionality: free F1 reset msg allocated by aper_decoder 
15076 *
15077 * @params[in] Reset_t *f1ResetMsg 
15078 * @return void 
15079 *
15080 * ****************************************************************/
15081
15082 void freeAperDecodeF1ResetMsg(Reset_t *f1ResetMsg)
15083 {
15084    uint8_t ieIdx =0;
15085    if(f1ResetMsg->protocolIEs.list.array)
15086    {
15087       for(ieIdx=0 ;ieIdx < f1ResetMsg->protocolIEs.list.count ; ieIdx++)
15088       {
15089          if(f1ResetMsg->protocolIEs.list.array[ieIdx])
15090          {
15091             free(f1ResetMsg->protocolIEs.list.array[ieIdx]);
15092          }
15093       }
15094       free(f1ResetMsg->protocolIEs.list.array);
15095    }
15096 }
15097
15098 /******************************************************************
15099  *
15100  * @brief Processes DL RRC Message Transfer  sent by CU
15101  *
15102  * @details
15103  *
15104  *    Function : procF1ResetReq
15105  *
15106  *    Functionality: Processes DL RRC Message Transfer sent by CU
15107  *
15108  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15109  * @return ROK     - success
15110  *         RFAILED - failure
15111  *
15112  * ****************************************************************/
15113 uint8_t procF1ResetReq(F1AP_PDU_t *f1apMsg)
15114 {
15115    /* we are currently not supporting Ue release. right now we are supporting only init case of fireset */
15116    uint8_t       ieIdx = 0;
15117    uint8_t        ret = ROK;
15118    Reset_t       *f1ResetMsg = NULLP;
15119
15120    DU_LOG("\nINFO   -->  Processing F1 reset request");
15121    f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
15122
15123    for(ieIdx=0; ieIdx<f1ResetMsg->protocolIEs.list.count; ieIdx++)
15124    {
15125       switch(f1ResetMsg->protocolIEs.list.array[ieIdx]->id)
15126       {
15127          case ProtocolIE_ID_id_TransactionID:
15128             break;
15129
15130          case ProtocolIE_ID_id_Cause:
15131             break;
15132
15133          case ProtocolIE_ID_id_ResetType:
15134             {
15135                break;
15136             }
15137
15138          default:
15139             break;
15140       }
15141    }
15142    ret = BuildAndSendF1ResetAck();
15143    DU_LOG("\nINFO   -->  UE release is not supported for now");
15144
15145    freeAperDecodeF1ResetMsg(f1ResetMsg);
15146
15147    return ret;
15148 }
15149
15150 /*******************************************************************
15151  *
15152  * @brief free the RRC delivery report
15153  *
15154  * @details
15155  *
15156  *    Function : freeRrcDeliveryReport
15157  *
15158  *    Functionality: free the RRC delivery report
15159  *
15160  * @params[in]
15161  * @return ROK     - success
15162  *         RFAILED - failure
15163  *
15164  * ****************************************************************/
15165 void freeRrcDeliveryReport(F1AP_PDU_t  *f1apMsg )
15166 {
15167    uint8_t idx=0;
15168    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
15169
15170    if(f1apMsg)
15171    {
15172       if(f1apMsg->choice.initiatingMessage)
15173       {
15174          rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
15175          if(rrcDeliveryReport->protocolIEs.list.array)
15176          {
15177             for(idx =0 ;idx <rrcDeliveryReport->protocolIEs.list.count ;
15178                   idx++)
15179             {
15180                if(rrcDeliveryReport->protocolIEs.list.array[idx])
15181                {
15182                   DU_FREE(rrcDeliveryReport->protocolIEs.list.array[idx],
15183                         sizeof(RRCDeliveryReportIEs_t));
15184                }   
15185             }
15186             DU_FREE(rrcDeliveryReport->protocolIEs.list.array,
15187                   rrcDeliveryReport->protocolIEs.list.size);
15188          }
15189          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
15190       }
15191       DU_FREE(f1apMsg,
15192             sizeof(F1AP_PDU_t));
15193    }
15194 }
15195
15196 /*******************************************************************
15197 *
15198 * @brief Builds and sends the RRC delivery report
15199 *
15200 * @details
15201 *
15202 *    Function : BuildAndSendRrcDeliveryReport
15203 *
15204 *    Functionality: Builds and sends the RRC delivery report
15205 *
15206 * @params[in]
15207 *
15208 * @return ROK     - success
15209 *         RFAILED - failure
15210 *
15211 * ****************************************************************/
15212 uint8_t BuildAndSendRrcDeliveryReport(uint32_t gnbCuUeF1apId, \
15213    uint32_t gnbDuUeF1apId, RrcDeliveryReport *rrcDelivery)
15214 {
15215    uint8_t             ret = RFAILED;
15216    uint8_t             idx    = 0;
15217    uint8_t             idx1   = 0;
15218    uint8_t             elementCnt = 0;
15219    F1AP_PDU_t          *f1apMsg = NULLP;
15220    asn_enc_rval_t      encRetVal;  
15221    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
15222
15223    do{
15224
15225       DU_LOG("\nINFO   -->  F1AP : Building RRC delivery Message Transfer Message\n");
15226       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15227       if(f1apMsg == NULLP)
15228       {
15229          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
15230          break;
15231       }
15232       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
15233       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
15234       if(f1apMsg->choice.initiatingMessage == NULLP)
15235       {
15236          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU  failed");
15237          break;
15238       }
15239       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_RRCDeliveryReport;
15240       f1apMsg->choice.initiatingMessage->criticality   = Criticality_ignore;
15241       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_RRCDeliveryReport;
15242
15243       rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
15244       elementCnt = 4;
15245       rrcDeliveryReport->protocolIEs.list.count = elementCnt;
15246       rrcDeliveryReport->protocolIEs.list.size = elementCnt * sizeof(RRCDeliveryReportIEs_t *);
15247
15248       /* Initialize the F1Setup members */
15249       DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array, rrcDeliveryReport->protocolIEs.list.size);
15250       if(rrcDeliveryReport->protocolIEs.list.array == NULLP)
15251       {
15252          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRC Delivery  failed");
15253          break;
15254       }
15255       for(idx =0 ;idx <elementCnt; idx++)
15256       {
15257          DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array[idx], sizeof(RRCDeliveryReportIEs_t));
15258          if(rrcDeliveryReport->protocolIEs.list.array[idx] == NULLP)
15259          {
15260             break;
15261          }
15262       }
15263
15264       idx1 = 0;
15265
15266       /*GNB CU UE F1AP ID*/
15267       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
15268       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15269       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_CU_UE_F1AP_ID;
15270       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
15271
15272       /*GNB DU UE F1AP ID*/
15273       idx1++;
15274       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
15275       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15276       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_DU_UE_F1AP_ID;
15277       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
15278
15279       /*RRC delivery status*/
15280       idx1++;
15281       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_RRCDeliveryStatus;
15282       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15283       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_RRCDeliveryStatus;
15284       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.delivery_status =\
15285       rrcDelivery->rrcDeliveryStatus.deliveryStatus;
15286       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.triggering_message =\
15287       rrcDelivery->rrcDeliveryStatus.triggeringMessage;
15288
15289       /* SRB ID */ 
15290       idx1++;
15291       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
15292       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15293       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_SRBID;
15294       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.SRBID =  rrcDelivery->srbId;
15295
15296       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15297
15298       /* Encode the RRC DELIVERY REPORT type as APER */
15299       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15300       encBufSize = 0;
15301       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
15302             encBuf);
15303
15304       /* Encode results */
15305       if(encRetVal.encoded == ENCODE_FAIL)
15306       {
15307          DU_LOG("\nERROR  -->  F1AP : Could not encode RRC Delivery Msg structure (at %s)\n",\
15308                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15309          break;
15310       }
15311       else
15312       {
15313          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for RRC Delivery Msg \n");
15314 #ifdef DEBUG_ASN_PRINT
15315          for(idx=0; idx< encBufSize; idx++)
15316          {
15317             printf("%x",encBuf[idx]);
15318          }
15319 #endif
15320       }
15321
15322       /* Sending msg */
15323       if(sendF1APMsg() != ROK)
15324       {
15325          DU_LOG("\nERROR  -->  F1AP : Sending RRC delivery  msg request failed");
15326          break;
15327       }
15328       ret = ROK;
15329       break;
15330
15331    }while(true);
15332
15333    freeRrcDeliveryReport(f1apMsg);
15334    return ret;
15335 }
15336
15337 /*******************************************************************
15338  *
15339  * @brief Processes cells to be activated
15340  *
15341  * @details
15342  *
15343  *    Function : extractCellsToBeActivated
15344  *
15345  *    Functionality:
15346  *      - Processes cells to be activated list received in F1SetupRsp
15347  *
15348  * @params[in] void
15349  * @return ROK     - success
15350  *         RFAILED - failure
15351  *
15352  * ****************************************************************/
15353
15354 uint8_t extractCellsToBeActivated(Cells_to_be_Activated_List_t cellsToActivate)
15355 {
15356    uint8_t  ret = ROK;
15357    uint16_t idx, pci = 0;
15358    uint64_t nci;
15359    Cells_to_be_Activated_List_Item_t cell;
15360
15361    for(idx=0; idx<cellsToActivate.list.count; idx++)
15362    {
15363       nci = 0;
15364       cell = cellsToActivate.list.array[idx]->value.choice.Cells_to_be_Activated_List_Item;
15365       bitStringToInt(&cell.nRCGI.nRCellIdentity, &nci);
15366
15367       if(cell.nRPCI)
15368       {
15369          pci = *cell.nRPCI;
15370       }
15371       ret = duProcCellsToBeActivated(cell.nRCGI.pLMN_Identity.buf, nci, pci);
15372    }
15373    return ret;
15374 }
15375 /******************************************************************
15376 *
15377 * @brief Processes F1 Setup Response allocated by aper_decoder 
15378 *
15379 * @details
15380 *
15381 *    Function : freeF1SetupRsp 
15382 *
15383 *    Functionality: free F1 Setup Response allocated by aper_decoder 
15384 *
15385 * @params[in] F1SetupResponse_t *f1SetRspMsg 
15386 * @return void 
15387 *
15388 * ****************************************************************/
15389
15390 void freeAperDecodeF1SetupRsp(F1SetupResponse_t *f1SetRspMsg)
15391 {
15392    uint8_t ieIdx =0;
15393    uint8_t arrIdx =0;
15394    Cells_to_be_Activated_List_t *cellToActivate =NULLP;
15395    RRC_Version_t      *rrcVer =NULLP;
15396
15397    if(f1SetRspMsg->protocolIEs.list.array)
15398    {
15399       for(ieIdx=0; ieIdx<f1SetRspMsg->protocolIEs.list.count; ieIdx++)
15400       {
15401          if(f1SetRspMsg->protocolIEs.list.array[ieIdx])
15402          {
15403             switch(f1SetRspMsg->protocolIEs.list.array[ieIdx]->id)
15404             {
15405                case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15406                   {
15407                      cellToActivate =
15408                         &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.Cells_to_be_Activated_List;
15409                      if(cellToActivate->list.array)
15410                      {
15411                         for(arrIdx=0; arrIdx<cellToActivate->list.count ; arrIdx++)
15412                         {
15413                            if(cellToActivate->list.array[arrIdx])
15414                            {
15415
15416                               if(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.nRCGI.\
15417                               pLMN_Identity.buf)
15418                               {
15419                                  if(cellToActivate->list.array[0]->value.choice.\
15420                                        Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf)
15421                                  {
15422                                     free(cellToActivate->list.array[0]->value.choice.\
15423                                           Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf);
15424                                  }
15425
15426                                  free(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
15427                                        nRCGI.pLMN_Identity.buf);
15428                               }
15429                               free(cellToActivate->list.array[arrIdx]);
15430                            }
15431                         }
15432                         free(cellToActivate->list.array);
15433                      }
15434                      break;
15435                   }
15436                case ProtocolIE_ID_id_TransactionID:
15437                   {
15438                      break;
15439                   }
15440                case ProtocolIE_ID_id_gNB_CU_Name:
15441                   {
15442                      free(f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_Name.buf);
15443                      break;
15444                   }
15445                case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15446                   {
15447                      rrcVer = &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
15448                      if(rrcVer->latest_RRC_Version.buf)
15449                      {
15450                         if(rrcVer->iE_Extensions)
15451                         {
15452                            if(rrcVer->iE_Extensions->list.array)
15453                            {
15454                               if(rrcVer->iE_Extensions->list.array[0])
15455                               {
15456                                  if(rrcVer->iE_Extensions->list.\
15457                                        array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf)
15458                                  {
15459                                     free(rrcVer->iE_Extensions->list.\
15460                                           array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf);
15461                                  }
15462                                  free(rrcVer->iE_Extensions->list.array[0]);
15463                               }
15464                               free(rrcVer->iE_Extensions->list.array);
15465                            }
15466                            free(rrcVer->iE_Extensions);
15467                         }
15468                         free(rrcVer->latest_RRC_Version.buf);
15469                      }
15470                      break;
15471
15472                   }
15473                default:
15474                   {
15475                      DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15476                            f1SetRspMsg->protocolIEs.list.array[ieIdx]->id);
15477                   }
15478             }
15479             free(f1SetRspMsg->protocolIEs.list.array[ieIdx]);
15480          }
15481       }
15482       free(f1SetRspMsg->protocolIEs.list.array);
15483    }
15484 }
15485 /******************************************************************
15486  *
15487  * @brief Processes F1 Setup Response sent by CU
15488  *
15489  * @details
15490  *
15491  *    Function : procF1SetupRsp
15492  *
15493  *    Functionality: Processes F1 Setup Response sent by CU
15494  *
15495  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15496  * @return ROK     - success
15497  *         RFAILED - failure
15498  *
15499  * ****************************************************************/
15500 uint8_t procF1SetupRsp(F1AP_PDU_t *f1apMsg, MsgLen recvBufLen, char *recvBuf)
15501 {
15502    uint8_t ret = ROK;
15503    uint16_t idx =0;
15504    F1SetupResponse_t *f1SetRspMsg = NULLP;
15505    GNB_CU_Name_t     *cuName = NULLP;
15506    F1SetupRsp  f1SetRspDb;
15507    RRC_Version_t      *rrcVer =NULLP;
15508    
15509    memset(&f1SetRspDb, 0, sizeof(F1SetupRsp));
15510
15511    DU_LOG("\nINFO   -->  F1AP : F1 Setup Response received");
15512    f1SetRspMsg = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
15513
15514    for(idx=0; idx<f1SetRspMsg->protocolIEs.list.count; idx++)
15515    {
15516       switch(f1SetRspMsg->protocolIEs.list.array[idx]->id)
15517       {
15518          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15519             {
15520                extractCellsToBeActivated(f1SetRspMsg->protocolIEs.list.array[idx]->\
15521                      value.choice.Cells_to_be_Activated_List);
15522                break;
15523             }
15524          case ProtocolIE_ID_id_TransactionID:
15525             {
15526                f1SetRspDb.transId = f1SetRspMsg->protocolIEs.list.array[idx]->\
15527                                     value.choice.TransactionID;
15528                break;
15529             }
15530          case ProtocolIE_ID_id_gNB_CU_Name:
15531             {
15532                cuName = &f1SetRspMsg->protocolIEs.list.array[idx]->\
15533                         value.choice.GNB_CU_Name;
15534                strcpy(f1SetRspDb.cuName, (const char*)cuName->buf);
15535                break;
15536             }
15537          case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15538             {
15539                rrcVer = &f1SetRspMsg->protocolIEs.list.array[idx]->value.choice.RRC_Version;
15540                strcpy(f1SetRspDb.rrcVersion.rrcVer,
15541                      (const char*)rrcVer->latest_RRC_Version.buf);
15542                break;
15543             }
15544          default:
15545             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15546                   f1SetRspMsg->protocolIEs.list.array[idx]->id);
15547       }
15548    }
15549    
15550    duProcF1SetupRsp();
15551    freeAperDecodeF1SetupRsp(f1SetRspMsg);
15552
15553    duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize = recvBufLen;
15554    DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize);
15555    if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
15556    {
15557       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the buf of F1setup response");
15558       return RFAILED;
15559    }
15560    memcpy(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, recvBuf, recvBufLen);
15561
15562    if(BuildAndSendE2SetupReq() != ROK)
15563    {
15564       DU_LOG("\nERROR  -->  F1AP : Failed to build and send E2 setup request ");
15565       return RFAILED;
15566    }
15567    return ret;
15568 }
15569 /*******************************************************************
15570 *
15571 * @brief free GNB DU config update ack
15572 *
15573 * @details
15574 *
15575 *    Function : freeAperDecodeGnbDuAck 
15576 *
15577 *    Functionality: Processes GNB DU config update ack And
15578 *                     added free part for the memory allocated by aper_decoder
15579 *
15580 * @params[in] F1AP_PDU_t ASN decoded F1AP message
15581 * @return ROK     - success
15582 *         RFAILED - failure
15583 *
15584 * ****************************************************************/
15585
15586 void freeAperDecodeGnbDuAck(GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck)
15587 {
15588    uint8_t ieIdx = 0;
15589
15590    if(gnbDuAck->protocolIEs.list.array)
15591    {
15592       for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15593       {
15594          if(gnbDuAck->protocolIEs.list.array[ieIdx])
15595          {
15596             free(gnbDuAck->protocolIEs.list.array[ieIdx]);
15597          }
15598       }
15599       free(gnbDuAck->protocolIEs.list.array);
15600    }
15601 }
15602
15603 /*******************************************************************
15604 *
15605 * @brief Building  result of gnb-du config update ack output
15606 *
15607 * @details
15608 *
15609 *    Function : duProcGnbDuCfgUpdAckMsg 
15610 *
15611 *    Functionality: 
15612 *        Building output of gnb-du config update ack 
15613 *
15614 * @params[in] transId
15615 * @return void
15616 *
15617 * ****************************************************************/
15618
15619 uint8_t duProcGnbDuCfgUpdAckMsg(uint8_t transId)
15620 {
15621    uint8_t  ieIdx=0, arrIdx=0,ret=ROK;
15622    uint8_t  ueId =0 , ueIdx =0, totalActiveUe = 0;
15623    uint16_t cellIdx =0, crnti=0;
15624    uint64_t cellId =0;
15625    CmLList *f1apPduNode = NULLP;
15626    ReservedF1apPduInfo *f1apPduInfo =NULLP;
15627    F1AP_PDU_t *f1apMsgPdu = NULLP;
15628    GNBDUConfigurationUpdate_t *gnbDuConfigUpdate = NULLP;
15629    BIT_STRING_t *cellIdentity=NULLP;
15630    struct Served_Cells_To_Delete_ItemIEs *deleteItemIe=NULLP;
15631    Served_Cells_To_Delete_List_t *cellsToDelete=NULLP;
15632    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
15633
15634    DU_LOG("\nINFO   -->  DU APP: GNB-DU config update Ack received ");
15635    f1apPduNode = searchFromReservedF1apPduList(transId);
15636    f1apPduInfo = (ReservedF1apPduInfo *)f1apPduNode->node;
15637    f1apMsgPdu = (F1AP_PDU_t *)f1apPduInfo->f1apMsg;
15638
15639    if(f1apMsgPdu)
15640    {
15641       if(f1apMsgPdu->choice.initiatingMessage)
15642       {
15643          gnbDuConfigUpdate = &f1apMsgPdu->choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
15644          for(ieIdx=0; ieIdx < gnbDuConfigUpdate->protocolIEs.list.count; ieIdx++)
15645          {
15646             switch(gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->id)
15647             {
15648                case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
15649                   {
15650                      cellsToDelete = &gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
15651                                      Served_Cells_To_Delete_List;
15652                      if(cellsToDelete->list.array)
15653                      {
15654                         if(cellsToDelete->list.array[arrIdx])
15655                         {
15656                            deleteItemIe = (Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx];
15657                            deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
15658                            if(deleteItem->oldNRCGI.nRCellIdentity.buf)
15659                            {
15660                               cellIdentity = &deleteItem->oldNRCGI.nRCellIdentity;
15661                               bitStringToInt(cellIdentity, &cellId);
15662
15663                               GET_CELL_IDX(cellId, cellIdx);
15664                               if(duCb.actvCellLst[cellIdx] != NULLP)
15665                               {
15666                                  duCb.actvCellLst[cellId-1]->cellStatus = DELETION_IN_PROGRESS;
15667                               }
15668                            }
15669                         }
15670                      }
15671
15672                      if(duCb.actvCellLst[cellIdx] != NULLP)
15673                      {
15674                         if(duCb.actvCellLst[cellIdx]->numActvUes == 0)
15675                         {
15676                            ret = duSendCellDeletReq(cellId);
15677                            if(ret == RFAILED)
15678                            {
15679                               DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to send cell delete\
15680                               request for cellId[%lu]", cellId);
15681                            }
15682                         }
15683                         else
15684                         {
15685                            totalActiveUe = duCb.actvCellLst[cellIdx]->numActvUes;
15686                            while(totalActiveUe)
15687                            {
15688                               if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState != UE_ACTIVE)
15689                               {
15690                                  ueIdx++;
15691                                  continue;
15692                               }
15693
15694                               crnti = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti;
15695                               GET_UE_ID(crnti,ueId);
15696                               /* Sending Ue Context release request only for maximum supporting UEs */
15697                               ret = BuildAndSendUeContextReleaseReq(cellId, ueId);
15698                               if(ret == RFAILED)
15699                               {
15700                                  DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to build and send UE delete\
15701                                  request for cellId[%lu]", cellId);
15702                               }
15703                               ueIdx++;
15704                               totalActiveUe--;
15705                            }
15706                         }
15707                      }
15708                      else
15709                      {
15710                         DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): CellId [%lu] not found", cellId);
15711                         ret = RFAILED;
15712                      }
15713                      break;
15714                   }
15715
15716                default:
15717                   break;
15718             }
15719          }
15720       }
15721    }
15722    
15723    FreeDUConfigUpdate(f1apMsgPdu);
15724    deleteFromReservedF1apPduList(f1apPduNode);
15725    return ret;
15726 }
15727
15728 /*******************************************************************
15729 *
15730 * @brief Processes GNB DU config update ack
15731 *
15732 * @details
15733 *
15734 *    Function : procF1GNBDUCfgUpdAck
15735 *
15736 *    Functionality: added free part for the memory allocated by aper_decoder
15737 *
15738 * @params[in] F1AP_PDU_t *f1apMsg 
15739 * @return void 
15740 *
15741 * ****************************************************************/
15742 uint8_t procF1GNBDUCfgUpdAck(F1AP_PDU_t *f1apMsg)
15743 {
15744    uint8_t ieIdx=0,transId=0;
15745    GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck = NULLP;
15746
15747    DU_LOG("\nINFO   -->  F1AP : GNB-DU config update acknowledgment");
15748    gnbDuAck = &f1apMsg->choice.successfulOutcome->value.choice.GNBDUConfigurationUpdateAcknowledge;
15749
15750    for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15751    {
15752       switch(gnbDuAck->protocolIEs.list.array[ieIdx]->id)
15753       {
15754          case ProtocolIE_ID_id_TransactionID:
15755             {
15756                transId = gnbDuAck->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
15757                break;
15758             }
15759          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15760             {
15761                break;
15762             }
15763          default :
15764             {
15765                DU_LOG("\nERROR  -->  F1AP: procF1GNBDUCfgUpdAck(): Invalid IE Received: %ld", \
15766                      gnbDuAck->protocolIEs.list.array[ieIdx]->id);
15767                break;
15768             }
15769       }
15770    }
15771    
15772    duProcGnbDuCfgUpdAckMsg(transId);
15773     
15774 #if 0
15775    /* presently we are not supporting F1 Reset from DU to CU , we are only
15776     * supporting F1 Reset from CU to DU */
15777
15778    if(BuildAndSendF1ResetReq() != ROK)
15779    {
15780       return RFAILED;
15781    }
15782 #endif
15783
15784    freeAperDecodeGnbDuAck(gnbDuAck);
15785    return ROK;
15786 }
15787 /******************************************************************
15788 *
15789 * @brief free DL RRC Message Transfer allocated by aper_decoder 
15790 *
15791 * @details
15792 *
15793 *    Function : freeAperDecodef1DlRrcMsg 
15794 *
15795 *    Functionality: free DL RRC Message Transfer allocated by aper_decoder 
15796 *
15797 * @params[in] DLRRCMessageTransfer_t *f1DlRrcMsg 
15798 * @return ROK     - success
15799 *         RFAILED - failure
15800 *
15801 * ****************************************************************/
15802
15803 void freeAperDecodef1DlRrcMsg(DLRRCMessageTransfer_t *f1DlRrcMsg)
15804 {
15805    uint8_t ieIdx =0;
15806    RRCContainer_t *rrcContainer = NULLP;
15807
15808    if(f1DlRrcMsg->protocolIEs.list.array)
15809    {
15810       for(ieIdx=0; ieIdx<f1DlRrcMsg->protocolIEs.list.count; ieIdx++)
15811       {
15812          if(f1DlRrcMsg->protocolIEs.list.array[ieIdx])
15813          {
15814             switch(f1DlRrcMsg->protocolIEs.list.array[ieIdx]->id)
15815             {
15816                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15817                   break;
15818                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15819                   break;
15820                case ProtocolIE_ID_id_SRBID:
15821                   break;
15822                case ProtocolIE_ID_id_RRCContainer:
15823                   {
15824                      rrcContainer =&f1DlRrcMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer;
15825                      free(rrcContainer->buf);
15826                   }
15827                case ProtocolIE_ID_id_ExecuteDuplication:
15828                   break;
15829                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15830                   break;
15831                   break;
15832             }
15833             free(f1DlRrcMsg->protocolIEs.list.array[ieIdx]);
15834          }
15835       }
15836       free(f1DlRrcMsg->protocolIEs.list.array);
15837    }
15838 }
15839 /******************************************************************
15840  *
15841  * @brief Processes DL RRC Message Transfer  sent by CU
15842  *
15843  * @details
15844  *
15845  *    Function : procF1DlRrcMsgTrans
15846  *
15847  *    Functionality: Processes DL RRC Message Transfer sent by CU
15848  *
15849  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15850  * @return ROK     - success
15851  *         RFAILED - failure
15852  *
15853  * ****************************************************************/
15854 uint8_t procF1DlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
15855 {
15856    uint8_t  idx, ret;
15857    DLRRCMessageTransfer_t *f1DlRrcMsg = NULLP;
15858    F1DlRrcMsg dlMsg;
15859    memset(&dlMsg, 0, sizeof(F1DlRrcMsg));
15860
15861    DU_LOG("\nINFO   -->  DU_APP : DL RRC message transfer Recevied");
15862    f1DlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
15863
15864    ret = ROK;
15865
15866    for(idx=0; idx<f1DlRrcMsg->protocolIEs.list.count; idx++)
15867    {
15868       switch(f1DlRrcMsg->protocolIEs.list.array[idx]->id)
15869       {
15870          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15871             {
15872                dlMsg.gnbCuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
15873                break;
15874             }
15875          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15876             {
15877                dlMsg.gnbDuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
15878                break;
15879             }
15880          case ProtocolIE_ID_id_SRBID:
15881             {
15882                dlMsg.srbId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
15883                break;
15884             }
15885          case ProtocolIE_ID_id_ExecuteDuplication:
15886             dlMsg.execDup = true;
15887             break;
15888
15889          case ProtocolIE_ID_id_RRCContainer:
15890             {
15891                if(f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
15892                {
15893              dlMsg.rrcMsgSize = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
15894              DU_ALLOC_SHRABL_BUF(dlMsg.rrcMsgPdu, dlMsg.rrcMsgSize);
15895              if(dlMsg.rrcMsgPdu)
15896              {
15897                 memcpy(dlMsg.rrcMsgPdu, f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf,\
15898                       dlMsg.rrcMsgSize);
15899              }
15900              else
15901              {
15902                 DU_LOG("\nERROR  -->  DU APP : Memory alloc Failed at RRC Container at procF1DlRrcMsgTrans()");
15903                 return RFAILED;
15904              }
15905           }
15906           else
15907           {
15908              DU_LOG("\nERROR  -->  DU_APP : RRC Container Size is invalid:%ld",\
15909                    f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
15910              return RFAILED;
15911           }
15912           break;
15913        }
15914     case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15915        {
15916           dlMsg.deliveryStatRpt = true;
15917           break;
15918        }
15919     default:
15920        DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
15921              f1DlRrcMsg->protocolIEs.list.array[idx]->id);
15922       }
15923    }
15924
15925    ret = duProcDlRrcMsg(&dlMsg);
15926
15927    freeAperDecodef1DlRrcMsg(f1DlRrcMsg);
15928    return ret;
15929 }
15930 /*******************************************************************
15931  *
15932 * @brief Builds the DRB to be Setup Mod list
15933 *
15934 * @details
15935 *
15936 *    Function : 
15937 *
15938 *    Functionality: Constructs the DRB to be Setup Mod list
15939 *
15940 * @params[in] DRBs_SetupMod_List_t *drbSet
15941 *
15942 * @return ROK     - success
15943 *         RFAILED - failure
15944 *
15945 * ****************************************************************/
15946 uint8_t BuildSrbSetupModList(SRBs_SetupMod_List_t *srbList, DuUeCfg *ueCfg)
15947 {
15948    uint8_t srbIdx = 0;
15949    struct SRBs_SetupMod_ItemIEs *srbItemIe;
15950
15951    srbList->list.count = ueCfg->numRlcLcs;
15952    srbList->list.size = srbList->list.count * sizeof(SRBs_SetupMod_ItemIEs_t *);
15953
15954    DU_ALLOC(srbList->list.array, srbList->list.size);
15955    if(srbList->list.array == NULLP)
15956    {
15957       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15958       return RFAILED;
15959    }
15960
15961    for(srbIdx = 0; srbIdx < srbList->list.count; srbIdx++)
15962    {
15963       DU_ALLOC(srbList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15964       if(srbList->list.array[srbIdx] == NULLP)
15965       {
15966          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15967          return RFAILED;
15968       }
15969    } 
15970
15971    for(srbIdx=0; srbIdx < srbList->list.count; srbIdx++)
15972    {
15973       srbItemIe = (struct SRBs_SetupMod_ItemIEs *)srbList->list.array[srbIdx];
15974       srbItemIe->id = ProtocolIE_ID_id_SRBs_SetupMod_Item;
15975       srbItemIe->criticality = Criticality_reject;
15976       srbItemIe->value.present = SRBs_SetupMod_ItemIEs__value_PR_SRBs_SetupMod_Item;
15977       srbItemIe->value.choice.SRBs_SetupMod_Item.sRBID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.rbId;
15978       srbItemIe->value.choice.SRBs_SetupMod_Item.lCID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.lcId;
15979    }
15980    return ROK;
15981 }
15982
15983 /*******************************************************************
15984  *
15985 * @brief Builds the DRB to be Setup Mod list
15986 *
15987 * @details
15988 *
15989 *    Function : 
15990 *
15991 *    Functionality: Constructs the DRB to be Setup Mod list
15992 *
15993 * @params[in] DRBs_SetupMod_List_t *drbSet
15994 *
15995 * @return ROK     - success
15996 *         RFAILED - failure
15997 *
15998 * ****************************************************************/
15999
16000 uint8_t BuildDrbSetupModList(DRBs_SetupMod_List_t *drbSet , DuUeCfg *ueCfg)
16001 {
16002    uint8_t arrIdx =0;
16003    uint8_t drbCnt =0;
16004    struct DRBs_SetupMod_ItemIEs *drbItemIe;
16005
16006    drbCnt = ueCfg->numDrbSetupMod;
16007
16008    drbSet->list.count = drbCnt;
16009    drbSet->list.size = drbCnt * sizeof(DRBs_SetupMod_ItemIEs_t *);
16010    DU_ALLOC(drbSet->list.array, drbSet->list.size);
16011    if(drbSet->list.array == NULLP)
16012    {
16013       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
16014       return  RFAILED;
16015    }
16016    for(arrIdx=0; arrIdx<drbCnt; arrIdx++)
16017    {
16018       DU_ALLOC(drbSet->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
16019       if(drbSet->list.array[arrIdx] == NULLP)
16020       {
16021               DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
16022               return  RFAILED;
16023       }
16024
16025       drbItemIe = (struct DRBs_SetupMod_ItemIEs *)drbSet->list.array[arrIdx];
16026       drbItemIe->id = ProtocolIE_ID_id_DRBs_SetupMod_Item;
16027       drbItemIe->criticality = Criticality_reject;
16028       drbItemIe->value.present = DRBs_SetupMod_ItemIEs__value_PR_DRBs_SetupMod_Item;
16029       drbItemIe->value.choice.DRBs_SetupMod_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
16030       if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List,\
16031       &ueCfg->upTnlInfo[arrIdx])!= ROK)
16032       {
16033          DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbToBeSetupModList");
16034          return RFAILED;
16035       }
16036       
16037    }
16038
16039    return ROK;
16040 }
16041 /*******************************************************************
16042 * @brief Free the memory allocated for DRB setup List
16043 *
16044 * @details
16045 *
16046 *    Function : FreeDrbSetupModList 
16047 *
16048 *    Functionality:
16049 *       Free the memory allocated for DRB setup list
16050 *
16051 * @params[in] DRBs_Setup_List_t *
16052 * @return void
16053 *
16054 * ****************************************************************/
16055 void FreeDrbSetupModList(DRBs_SetupMod_List_t *drbSetupList)
16056 {
16057    uint8_t arrIdx = 0;
16058    DRBs_SetupMod_ItemIEs_t *drbItemIe = NULLP;
16059
16060    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
16061    {
16062       drbItemIe = ((DRBs_SetupMod_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
16063       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List);
16064       DU_FREE(drbSetupList->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
16065    }
16066    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
16067 }
16068
16069 /*******************************************************************
16070 *
16071 * @brief Builds the DRB to be Mod list
16072 *
16073 * @details
16074 *
16075 *    Function : 
16076 *
16077 *    Functionality: Constructs the DRB to be Mod list
16078 *
16079 * @params[in] DRBs_Modified_List_t *drbModList
16080 *
16081 * @return ROK     - success
16082 *         RFAILED - failure
16083 *
16084 * ****************************************************************/
16085
16086 uint8_t BuildDrbModList(DRBs_Modified_List_t *drbModList, DuUeCfg *ueCfg)
16087 {
16088    uint8_t arrIdx =0, drbIdx = 0;
16089    uint8_t drbCnt =0;
16090    struct DRBs_Modified_ItemIEs *drbItemIe;
16091
16092    drbCnt = ueCfg->numDrbModified;
16093
16094    drbModList->list.count = drbCnt;
16095    drbModList->list.size = drbCnt * sizeof(DRBs_Modified_ItemIEs_t *);
16096    DU_ALLOC(drbModList->list.array, drbModList->list.size);
16097    if(drbModList->list.array == NULLP)
16098    {
16099       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList()");
16100       return  RFAILED;
16101    }
16102
16103    drbIdx = 0;
16104    for(arrIdx = 0; arrIdx < ueCfg->numMacLcs; arrIdx++)
16105    {
16106       if(ueCfg->macLcCfg[arrIdx].configType == CONFIG_MOD)
16107       {
16108          DU_ALLOC(drbModList->list.array[drbIdx], sizeof(DRBs_Modified_ItemIEs_t));
16109          if(drbModList->list.array[drbIdx] == NULLP)
16110          {
16111             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList");
16112             return  RFAILED;
16113          }
16114
16115          drbItemIe = (struct DRBs_Modified_ItemIEs *)drbModList->list.array[drbIdx];
16116          drbItemIe->id = ProtocolIE_ID_id_DRBs_Modified_Item;
16117          drbItemIe->criticality = Criticality_reject;
16118          drbItemIe->value.present = DRBs_Modified_ItemIEs__value_PR_DRBs_Modified_Item;
16119          drbItemIe->value.choice.DRBs_Modified_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
16120          if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List,\
16121                   &ueCfg->upTnlInfo[arrIdx])!= ROK)
16122          {
16123             DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbModList");
16124             return RFAILED;
16125          }
16126          drbIdx++;
16127       } 
16128    }
16129
16130    return ROK;
16131 }
16132
16133 /*******************************************************************
16134 * @brief Free the memory allocated for DRB Mod List
16135 *
16136 * @details
16137 *
16138 *    Function : FreeDrbModList 
16139 *
16140 *    Functionality:
16141 *       Free the memory allocated for DRB modified list
16142 *
16143 * @params[in] DRBs_Modified_List_t *
16144 * @return void
16145 *
16146 * ****************************************************************/
16147 void FreeDrbModList(DRBs_Modified_List_t *drbModList)
16148 {
16149    uint8_t arrIdx = 0;
16150    DRBs_Modified_ItemIEs_t *drbItemIe = NULLP;
16151
16152    for(arrIdx = 0; arrIdx < drbModList->list.count; arrIdx++)
16153    {
16154       drbItemIe = ((DRBs_Modified_ItemIEs_t *)drbModList->list.array[arrIdx]);
16155       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List);
16156       DU_FREE(drbModList->list.array[arrIdx], sizeof(DRBs_Modified_ItemIEs_t));
16157    }
16158    DU_FREE(drbModList->list.array, drbModList->list.size);
16159 }
16160
16161 /*******************************************************************
16162 * @brief Free the memory allocated for SRB setup List
16163 *
16164 * @details
16165 *
16166 *    Function : FreeSrbSetupModList 
16167 *
16168 *    Functionality:
16169 *       Free the memory allocated for SRB setup list
16170 *
16171 * @params[in] SRBs_Setup_List_t *
16172 * @return void
16173 *
16174 * ****************************************************************/
16175 void FreeSrbSetupModList(SRBs_SetupMod_List_t *srbSetupList)
16176 {
16177    uint8_t srbIdx = 0;
16178    
16179    for(srbIdx = 0; srbIdx < srbSetupList->list.count; srbIdx++)
16180       DU_FREE(srbSetupList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
16181    DU_FREE(srbSetupList->list.array, srbSetupList->list.size);
16182 }
16183
16184 /*******************************************************************
16185 * @brief Free the memory allocated for UE Context Mod Response
16186 *
16187 * @details
16188 *
16189 *    Function : FreeUeContextModResp 
16190 *
16191 *    Functionality:
16192 *       Free the memory allocated for UE Context Mod Response
16193 *
16194 * @params[in] F1AP_PDU_t *f1apMsg
16195 * @return void
16196 *
16197 * ****************************************************************/
16198
16199 void FreeUeContextModResp(F1AP_PDU_t *f1apMsg)
16200 {
16201    uint8_t ieIdx;
16202    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
16203    if(f1apMsg)
16204    {
16205       if(f1apMsg->choice.successfulOutcome)
16206       {
16207          ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
16208          if(ueContextModifyRes->protocolIEs.list.array)
16209          {
16210             for(ieIdx=0 ; ieIdx<ueContextModifyRes->protocolIEs.list.count; ieIdx++)
16211             {
16212                if(ueContextModifyRes->protocolIEs.list.array[ieIdx])
16213                {
16214                   switch(ueContextModifyRes->protocolIEs.list.array[ieIdx]->id)
16215                   {
16216                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16217                         break;
16218                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16219                         break;
16220                      case ProtocolIE_ID_id_DUtoCURRCInformation:
16221                         {
16222                            DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.\
16223                               cellGroupConfig.buf, ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
16224                               DUtoCURRCInformation.cellGroupConfig.size);
16225                            break;
16226                         }
16227                      case ProtocolIE_ID_id_DRBs_SetupMod_List:
16228                         {
16229                             FreeDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16230                             value.choice.DRBs_SetupMod_List));
16231                             break;
16232                         }
16233                      case ProtocolIE_ID_id_DRBs_Modified_List:
16234                         {
16235                             FreeDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16236                             value.choice.DRBs_Modified_List));
16237                             break;
16238                         }
16239                      case ProtocolIE_ID_id_SRBs_SetupMod_List:
16240                         {
16241                            FreeSrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
16242                               SRBs_SetupMod_List));
16243                            break; 
16244                         }
16245                   }
16246                   DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
16247                }
16248
16249             }
16250             DU_FREE(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
16251          }
16252          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16253       }
16254       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
16255    }
16256 }
16257
16258 /*****************************************************************i
16259 *
16260 * @brief Creating the ue context modifcation response and sending
16261 *
16262 * @details
16263 *
16264 *    Function : BuildAndSendUeContextModRsp 
16265 *
16266 *    Functionality:
16267 *         - Creating the ue context modifcation response 
16268 *
16269 * @params[in] uint8_t cellId,uint8_t ueId
16270 * @return ROK     - success
16271 *         RFAILED - failure
16272 *
16273 * ****************************************************************/
16274 uint8_t BuildAndSendUeContextModRsp(DuUeCb *ueCb)
16275 {
16276    uint8_t   ieIdx = 0, tnlIdx = 0, rbIdx = 0;
16277    uint8_t   elementCnt = 0;
16278    uint8_t   ret = RFAILED;
16279    F1AP_PDU_t *f1apMsg = NULLP;
16280    asn_enc_rval_t  encRetVal;
16281    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
16282
16283    DU_LOG("\nINFO  -->  F1AP : Building UE context modification response\n");
16284
16285    while(true)
16286    {
16287       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
16288       if(f1apMsg == NULLP)
16289       {
16290          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16291          break;
16292       }
16293
16294       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
16295
16296       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16297       if(f1apMsg->choice.successfulOutcome == NULLP)
16298       {
16299          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16300          break;
16301       }
16302       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextModification;
16303       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
16304       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_UEContextModificationResponse;
16305
16306       ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
16307   
16308       if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
16309       {
16310          elementCnt = 2;
16311          if(ueCb->f1UeDb->duUeCfg.numDrbSetupMod)
16312             elementCnt++;
16313          if(ueCb->f1UeDb->duUeCfg.numDrbModified)
16314             elementCnt++; 
16315       }
16316       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16317       {
16318          elementCnt = 5;
16319       }
16320       if(ueCb->f1UeDb->actionType == UE_CTXT_RRC_RECFG_COMPLETE)
16321          elementCnt = 2;
16322       ueContextModifyRes->protocolIEs.list.count = elementCnt;
16323       ueContextModifyRes->protocolIEs.list.size = elementCnt*sizeof(UEContextModificationResponse_t*);
16324
16325       /* Initialize the UE context modification members */
16326       DU_ALLOC(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
16327       if(ueContextModifyRes->protocolIEs.list.array == NULLP)
16328       {
16329          DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16330          break;
16331       }
16332
16333       for(ieIdx=0 ; ieIdx<elementCnt; ieIdx++)
16334       {
16335          DU_ALLOC(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
16336          if(ueContextModifyRes->protocolIEs.list.array[ieIdx] == NULLP)
16337          {
16338             DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16339             break;
16340          }
16341       }
16342
16343       ieIdx=0;
16344       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
16345       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16346       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16347       UEContextModificationResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
16348       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
16349
16350       ieIdx++;
16351       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16352       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16353       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present=\
16354       UEContextModificationResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
16355       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
16356
16357       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16358       {
16359          ieIdx++;
16360          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCInformation;
16361          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16362          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16363          UEContextModificationResponseIEs__value_PR_DUtoCURRCInformation;
16364          BuildCellGroupConfigRrc(ueCb, &ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
16365       }
16366
16367       if((ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY) || \
16368            ((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbSetupMod)))
16369       { 
16370          ieIdx++;
16371          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_SetupMod_List;
16372          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16373          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16374                                                                            UEContextModificationResponseIEs__value_PR_DRBs_SetupMod_List;
16375          if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16376          {
16377             for(tnlIdx = 0; tnlIdx < duCb.numTeId; tnlIdx++)
16378             {
16379                if(duCb.upTnlCfg[tnlIdx]->ueId == ueCb->gnbDuUeF1apId)
16380                {
16381                   memcpy(&ueCb->f1UeDb->duUeCfg.upTnlInfo[ueCb->f1UeDb->duUeCfg.numDrbSetupMod++], duCb.upTnlCfg[tnlIdx], sizeof(UpTnlCfg));
16382                }
16383             }
16384          }
16385          ret = BuildDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16386                   value.choice.DRBs_SetupMod_List) , &ueCb->f1UeDb->duUeCfg);
16387          if(ret != ROK)
16388          {
16389             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB setupmod List ");
16390             break;
16391          }
16392       }
16393
16394       if((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbModified))
16395       { 
16396          ieIdx++;
16397          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_Modified_List;
16398          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16399          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16400                                                                     UEContextModificationResponseIEs__value_PR_DRBs_Modified_List;
16401          ret = BuildDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16402                                  value.choice.DRBs_Modified_List) , &ueCb->f1UeDb->duUeCfg);
16403          if(ret != ROK)
16404          {
16405             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB Modified List ");
16406             break;
16407          }
16408       }
16409
16410       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16411       {
16412          ieIdx++;
16413          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_SRBs_SetupMod_List;
16414          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16415          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16416                                                                             UEContextModificationResponseIEs__value_PR_SRBs_SetupMod_List;
16417          for(rbIdx = 0; rbIdx < ueCb->duRlcUeCfg.numLcs; rbIdx++)
16418          {
16419             if(ueCb->duRlcUeCfg.rlcLcCfg[rbIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
16420             {
16421                memcpy(&ueCb->f1UeDb->duUeCfg.rlcLcCfg[ueCb->f1UeDb->duUeCfg.numRlcLcs++], &ueCb->duRlcUeCfg.rlcLcCfg[rbIdx],\
16422                      sizeof(DuRlcBearerCfg));
16423             }
16424          }
16425          ret = BuildSrbSetupModList(&ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.SRBs_SetupMod_List, \
16426                &ueCb->f1UeDb->duUeCfg);
16427          if(ret != ROK)
16428          {
16429             DU_LOG( "\nERROR  -->  F1AP : Failed to build SRB setupmod List ");
16430             break;
16431          }
16432       }
16433
16434       freeF1UeDb(ueCb->f1UeDb);
16435       ueCb->f1UeDb = NULLP;
16436
16437       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16438
16439       /* Encode the F1SetupRequest type as APER */
16440       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16441       encBufSize = 0;
16442       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,encBuf);
16443
16444       /* Encode results */
16445       if(encRetVal.encoded == ENCODE_FAIL)
16446       {
16447          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Modification Response structure (at %s)\n",\
16448                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16449          ret = RFAILED;
16450          break;
16451       }
16452       else
16453       {
16454          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Modification Response\n");
16455 #ifdef DEBUG_ASN_PRINT
16456          for(int i=0; i< encBufSize; i++)
16457          {
16458             printf("%x",encBuf[i]);
16459          }
16460 #endif
16461       }
16462
16463       /* Sending  msg  */
16464       if(sendF1APMsg() != ROK && (ret == ROK))
16465       {
16466          DU_LOG("\nERROR  -->  F1AP : Sending UE Modification Res Failed");
16467          ret = RFAILED;
16468          break;
16469       }
16470
16471       ret = ROK;
16472       break;
16473    }
16474
16475    FreeUeContextModResp(f1apMsg);
16476    return ret;
16477 }
16478
16479 /*******************************************************************
16480  *
16481  * @brief Deallocating the memory allocated by the aper decoder
16482  *          for QOSInfo
16483  *
16484  * @details
16485  *
16486  *    Function : freeAperDecodeQosInfo
16487  *
16488  *    Functionality:  Deallocating the memory allocated for QOSInfo
16489  *
16490  * @params[in] QoSFlowLevelQoSParameters_t *drbQos
16491  *
16492  * @return void
16493  *
16494  * ****************************************************************/
16495
16496 void freeAperDecodeQosInfo(QoSFlowLevelQoSParameters_t *drbQos)
16497 {
16498    if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI != NULLP)
16499    {
16500       if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
16501       {
16502          if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
16503          {
16504             free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
16505          }
16506          free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
16507       }
16508       free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI);
16509    }
16510 }
16511 /*******************************************************************
16512  *
16513  * @brief Deallocating the memory allocated by the aper decoder
16514  *          for UlTnlInfoforDrb
16515  *
16516  * @details
16517  *
16518  *    Function : freeAperDecodeUlTnlInfoforDrbSetupMod 
16519  *
16520  *    Functionality:  Deallocating memory allocated for UlTnlInfoforDrb
16521  *
16522  * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
16523  *
16524  * @return void
16525  *
16526  * ****************************************************************/
16527 void freeAperDecodeUlTnlInfoforDrbSetupMod(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
16528 {
16529    uint8_t arrIdx =0;
16530
16531    if(ulInfo->list.array)
16532    {
16533       for(arrIdx=0; arrIdx<ulInfo->list.count ; arrIdx++)
16534       {
16535          if(ulInfo->list.array[arrIdx])
16536          {
16537             if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel )
16538             {
16539                if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf)
16540                {
16541                   if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf)
16542                   {
16543                      free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16544                            gTP_TEID.buf);
16545                   }
16546                   free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16547                         transportLayerAddress.buf);
16548                }
16549                free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel);
16550             }
16551             free(ulInfo->list.array[arrIdx]);
16552          }
16553       }
16554       free(ulInfo->list.array);
16555    }
16556 }
16557
16558 /*******************************************************************
16559  *
16560  * @brief Deallocating the memory allocated by the aper decoder
16561  *          for DrbSetupModItem  
16562  *
16563  * @details
16564  *
16565  *    Function : freeAperDecodeDrbSetupModItem 
16566  *
16567  *    Functionality:  Deallocating memory allocated for DrbSetupModItem
16568  *
16569  * @params[in] DRBs_ToBeSetupMod_Item_t *drbItem
16570  *
16571  * @return void
16572  *
16573  * ****************************************************************/
16574
16575 void freeAperDecodeDrbSetupModItem(DRBs_ToBeSetupMod_Item_t *drbItem)
16576 {
16577    uint8_t arrIdx =0;
16578    SNSSAI_t *snssai =NULLP;
16579    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16580
16581    drbItem->qoSInformation.present = QoSInformation_PR_choice_extension;
16582    switch(drbItem->qoSInformation.present)
16583    {
16584       case QoSInformation_PR_NOTHING:
16585          break;
16586       case QoSInformation_PR_eUTRANQoS:
16587          {
16588             if(drbItem->qoSInformation.choice.eUTRANQoS)
16589             {
16590                free(drbItem->qoSInformation.choice.eUTRANQoS);
16591             }
16592             break;
16593          }
16594       case QoSInformation_PR_choice_extension:
16595          {
16596             if(drbItem->qoSInformation.choice.choice_extension)
16597             {
16598                freeAperDecodeQosInfo(&drbItem->qoSInformation.choice.choice_extension->value.choice.\
16599                      DRB_Information.dRB_QoS);
16600                snssai = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16601                if(snssai->sST.buf)
16602                {
16603                   free(snssai->sST.buf);
16604                }
16605                if(snssai->sD)
16606                {
16607                   if(snssai->sD->buf)
16608                   {
16609                      free(snssai->sD->buf);
16610                   }
16611                   free(snssai->sD);
16612                }
16613
16614                flowMap = &drbItem->qoSInformation.choice.choice_extension->value.choice.\
16615                          DRB_Information.flows_Mapped_To_DRB_List;
16616                if(flowMap->list.array)
16617                {
16618                   for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16619                   {
16620                      if(flowMap->list.array[arrIdx] )
16621                      {
16622                         freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16623                         free(flowMap->list.array[arrIdx]);
16624                      }
16625                   }
16626                   free(flowMap->list.array);
16627                }
16628
16629                free(drbItem->qoSInformation.choice.choice_extension);
16630             }
16631             break;
16632          }
16633
16634    }
16635    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16636    if(drbItem->uLConfiguration)
16637    {
16638       free(drbItem->uLConfiguration);
16639    }
16640 }
16641
16642 /*******************************************************************
16643  *
16644  * @brief Deallocating the memory allocated by the aper decoder
16645  *          for DrbToBeSetupModList
16646  *
16647  * @details
16648  *
16649  *    Function : freeAperDecodeDrbToBeSetupModList
16650  *
16651  *    Functionality:  Deallocating memory allocated for DrbToBeSetupModList
16652  *
16653  * @params[in] DRBs_ToBeSetupMod_List_t *drbSet
16654  *
16655  * @return void
16656  *
16657  * ****************************************************************/
16658
16659 void freeAperDecodeDrbToBeSetupModList(DRBs_ToBeSetupMod_List_t *drbSet)
16660 {
16661    uint8_t arrIdx =0;
16662    struct DRBs_ToBeSetupMod_ItemIEs *drbItemIe;
16663
16664    if(drbSet->list.array)
16665    {
16666       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16667       {
16668          if(drbSet->list.array[arrIdx] != NULLP)
16669          {
16670             if(arrIdx == 0)
16671             {
16672                drbItemIe = (DRBs_ToBeSetupMod_ItemIEs_t *)drbSet->list.array[arrIdx];
16673                freeAperDecodeDrbSetupModItem(&(drbItemIe->value.choice.DRBs_ToBeSetupMod_Item));
16674             }
16675             free(drbSet->list.array[arrIdx]);
16676          }
16677       }
16678       free(drbSet->list.array);
16679    }
16680
16681 }
16682
16683 /*******************************************************************
16684  *
16685  * @brief Deallocating the memory allocated by the aper decoder
16686  *          for DrbSetupModItem  
16687  *
16688  * @details
16689  *
16690  *    Function : freeAperDecodeDrbModifiedItem 
16691  *
16692  *    Functionality:  Deallocating memory allocated for DrbModifedItem
16693  *
16694  * @params[in] DRBs_ToBeModified_Item_t *drbItem
16695  *
16696  * @return void
16697  *
16698  * ****************************************************************/
16699
16700 void freeAperDecodeDrbModifiedItem(DRBs_ToBeModified_Item_t *drbItem)
16701 {
16702    uint8_t arrIdx =0;
16703    SNSSAI_t *snssai =NULLP;
16704    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16705
16706    if(drbItem->qoSInformation != NULLP)
16707    {
16708       drbItem->qoSInformation->present = QoSInformation_PR_choice_extension;
16709       switch(drbItem->qoSInformation->present)
16710       {
16711          case QoSInformation_PR_NOTHING:
16712             break;
16713          case QoSInformation_PR_eUTRANQoS:
16714             {
16715                if(drbItem->qoSInformation->choice.eUTRANQoS)
16716                {
16717                   free(drbItem->qoSInformation->choice.eUTRANQoS);
16718                }
16719                break;
16720             }
16721          case QoSInformation_PR_choice_extension:
16722             {
16723                if(drbItem->qoSInformation->choice.choice_extension)
16724                {
16725                   freeAperDecodeQosInfo(&drbItem->qoSInformation->choice.choice_extension->value.choice.\
16726                         DRB_Information.dRB_QoS);
16727                   snssai = &drbItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16728                   if(snssai->sST.buf)
16729                   {
16730                      free(snssai->sST.buf);
16731                   }
16732                   if(snssai->sD)
16733                   {
16734                      if(snssai->sD->buf)
16735                      {
16736                         free(snssai->sD->buf);
16737                      }
16738                      free(snssai->sD);
16739                   }
16740
16741                   flowMap = &drbItem->qoSInformation->choice.choice_extension->value.choice.\
16742                             DRB_Information.flows_Mapped_To_DRB_List;
16743                   if(flowMap->list.array)
16744                   {
16745                      for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16746                      {
16747                         if(flowMap->list.array[arrIdx] )
16748                         {
16749                            freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16750                            free(flowMap->list.array[arrIdx]);
16751                         }
16752                      }
16753                      free(flowMap->list.array);
16754                   }
16755
16756                   free(drbItem->qoSInformation->choice.choice_extension);
16757                }
16758                break;
16759             }
16760       }
16761       free(drbItem->qoSInformation);
16762    }
16763    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16764    if(drbItem->uLConfiguration)
16765    {
16766       free(drbItem->uLConfiguration);
16767    }
16768 }
16769
16770 /*******************************************************************
16771  *
16772  * @brief Deallocating the memory allocated by the aper decoder
16773  *          for DrbToBeSetupModList
16774  *
16775  * @details
16776  *
16777  *    Function : freeAperDecodeDrbToBeModifiedList
16778  *
16779  *    Functionality:  Deallocating memory allocated for DrbToBeModifiedList
16780  *
16781  * @params[in] DRBs_ToBeModified_List_t *drbSet
16782  *
16783  * @return void
16784  *
16785  * ****************************************************************/
16786
16787 void freeAperDecodeDrbToBeModifiedList(DRBs_ToBeModified_List_t *drbSet)
16788 {
16789    uint8_t arrIdx =0;
16790    struct DRBs_ToBeModified_ItemIEs *drbItemIe;
16791
16792    if(drbSet->list.array)
16793    {
16794       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16795       {
16796          if(drbSet->list.array[arrIdx] != NULLP)
16797          {
16798             if(arrIdx == 0)
16799             {
16800                drbItemIe = (DRBs_ToBeModified_ItemIEs_t *)drbSet->list.array[arrIdx];
16801                freeAperDecodeDrbModifiedItem(&(drbItemIe->value.choice.DRBs_ToBeModified_Item));
16802             }
16803             free(drbSet->list.array[arrIdx]);
16804          }
16805       }
16806       free(drbSet->list.array);
16807    }
16808
16809 }
16810
16811 /*******************************************************************
16812  *
16813  * @brief Deallocating the memory allocated by the aper decoder
16814  *          for DrbToBeSetupModList
16815  *
16816  * @details
16817  *
16818  *    Function : freeAperDecodeDrbToBeReleasedList
16819  *
16820  *    Functionality:  Deallocating memory allocated for DrbToBeReleasedList
16821  *
16822  * @params[in] DRBs_ToBeReleased_List_t *drbSet
16823  *
16824  * @return void
16825  *
16826  * ****************************************************************/
16827
16828 void freeAperDecodeDrbToBeReleasedList(DRBs_ToBeReleased_List_t *drbSet)
16829 {
16830    uint8_t arrIdx =0;
16831
16832    if(drbSet->list.array)
16833    {
16834       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16835       {
16836          if(drbSet->list.array[arrIdx] != NULLP)
16837          {
16838             free(drbSet->list.array[arrIdx]);
16839          }
16840       }
16841       free(drbSet->list.array);
16842    }
16843
16844 }
16845 /*******************************************************************
16846  *
16847  * @brief Deallocating the memory allocated by the aper decoder
16848  *          for UeContextModificationReqMsg
16849  *
16850  * @details
16851  *
16852  *    Function : freeAperDecodeUeContextModificationReqMsg
16853  *
16854  *    Functionality:  Deallocating memory allocated for
16855  *                  UeContextModificationReqMsg
16856  *
16857  * @params[in] UEContextModificationRequest_t *UeContextModifyReq
16858  *
16859  * @return void
16860  *
16861  * ****************************************************************/
16862 void freeAperDecodeUeContextModificationReqMsg(UEContextModificationRequest_t *ueContextModifyReq )
16863 {
16864    uint8_t arrIdx, ieId;
16865
16866    if(ueContextModifyReq->protocolIEs.list.array)
16867    {
16868       for( arrIdx = 0 ; arrIdx<ueContextModifyReq->protocolIEs.list.count ; arrIdx++)
16869       {
16870          if(ueContextModifyReq->protocolIEs.list.array[arrIdx])
16871          {
16872             ieId = ueContextModifyReq->protocolIEs.list.array[arrIdx]->id;
16873             switch(ieId)
16874             {
16875                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16876                   break;
16877                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16878                   break;
16879                case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
16880                   {
16881                      freeAperDecodeDrbToBeSetupModList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16882                            value.choice.DRBs_ToBeSetupMod_List);
16883                      break;
16884                   }
16885                case ProtocolIE_ID_id_DRBs_ToBeModified_List:
16886                   {
16887                      freeAperDecodeDrbToBeModifiedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16888                            value.choice.DRBs_ToBeModified_List);
16889                      break;
16890                   }
16891                case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
16892                   {
16893                      freeAperDecodeDrbToBeReleasedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16894                            value.choice.DRBs_ToBeReleased_List);
16895                      break;
16896                   }
16897                case ProtocolIE_ID_id_TransmissionActionIndicator:
16898                   break;
16899                case ProtocolIE_ID_id_RRCContainer:
16900                   {
16901                      free(ueContextModifyReq->protocolIEs.list.array[arrIdx]->value.choice.RRCContainer.buf);
16902                   }
16903             }
16904             free(ueContextModifyReq->protocolIEs.list.array[arrIdx]);
16905          }
16906       }
16907       free(ueContextModifyReq->protocolIEs.list.array);
16908    }
16909 }
16910 /*******************************************************************
16911  *
16912  * @brief processing the F1 UeContextModificationReq
16913  *
16914  * @details
16915  *
16916  *    Function : procF1UeContextModificationReq
16917  *
16918  *    Functionality:  processing the F1 UeContextModificationReq
16919  *
16920  * @params[in] F1AP_PDU_t *f1apMsg
16921  *
16922  * @return
16923  * ****************************************************************/
16924 uint8_t procF1UeContextModificationReq(F1AP_PDU_t *f1apMsg)
16925 {
16926    UEContextModificationRequest_t *ueContextModifyReq = NULLP;
16927    uint8_t  ret = ROK, ieIdx = 0, cellIdx=0;
16928    DuUeCb   *duUeCb = NULLP;
16929    DRBs_ToBeSetupMod_List_t *drbSetupModCfg = NULLP;
16930    DRBs_ToBeModified_List_t *drbModifiedCfg = NULLP;
16931    DRBs_ToBeReleased_List_t *drbToRelease = NULLP;
16932    uint32_t gnbCuUeF1apId, gnbDuUeF1apId;
16933
16934    ueContextModifyReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextModificationRequest;
16935    for(ieIdx=0; (ieIdx < ueContextModifyReq->protocolIEs.list.count && ret == ROK); ieIdx++)
16936    {
16937       switch(ueContextModifyReq->protocolIEs.list.array[ieIdx]->id)
16938       {
16939          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16940             {
16941                gnbCuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
16942                break;
16943             }
16944          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16945             {
16946                gnbDuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
16947                for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
16948                {
16949                   if(duCb.actvCellLst[cellIdx])
16950                   {
16951                      if((duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbDuUeF1apId == gnbDuUeF1apId)&&\
16952                            (duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbCuUeF1apId == gnbCuUeF1apId))
16953                      {
16954                         duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1];
16955                         if(duUeCb->f1UeDb == NULLP)
16956                         {
16957                            DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
16958                            duUeCb->f1UeDb->cellIdx = cellIdx;
16959                            duUeCb->f1UeDb->actionType = UE_CTXT_MOD;
16960                         }
16961                         break;
16962                      }
16963                   }
16964                }
16965                if(duUeCb == NULLP)
16966                {
16967                   DU_LOG("\nERROR  -->  DU APP : wrong values of gnbCuUeF1apId and gnbDuUeF1apId ");
16968                   ret = RFAILED;
16969                }
16970                break;
16971             }
16972
16973          case ProtocolIE_ID_id_RRCContainer:
16974             {
16975                /* Filling Dl RRC Msg Info */
16976                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
16977                if(!duUeCb->f1UeDb->dlRrcMsg)
16978                {
16979                   DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16980                         Memory allocation failed ");
16981                   ret = RFAILED;
16982                }
16983                else
16984                {
16985                   duUeCb->f1UeDb->dlRrcMsgPres = true;
16986                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
16987                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
16988                         &ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
16989                         value.choice.RRCContainer);
16990                }
16991
16992                break;
16993             }
16994
16995          case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
16996          case ProtocolIE_ID_id_DRBs_ToBeModified_List:
16997          case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
16998             {
16999                if(duUeCb->f1UeDb)
17000                {
17001                   /*DRBs to be Added*/
17002                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present ==\
17003                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List)
17004                   {
17005                      drbSetupModCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17006                                       choice.DRBs_ToBeSetupMod_List;
17007
17008                      if(extractDrbListToSetupMod(NULL, drbSetupModCfg, NULL, drbSetupModCfg->list.count,\
17009                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULL))
17010                      {
17011                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbSetupModList");
17012                         ret = RFAILED;
17013                      }
17014                   }
17015
17016                   /*DRBs to be Modified*/
17017                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
17018                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List)
17019
17020                   {
17021                      drbModifiedCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17022                                       choice.DRBs_ToBeModified_List;
17023                      if(extractDrbListToSetupMod(NULL, NULL, drbModifiedCfg, drbModifiedCfg->list.count,\
17024                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, &duUeCb->duRlcUeCfg))
17025                      {
17026                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
17027                         ret = RFAILED;
17028                      }
17029                   }
17030                   /*DRBs to be Released*/
17031                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
17032                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeReleased_List)
17033
17034                   {
17035                      drbToRelease = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17036                                       choice.DRBs_ToBeReleased_List;
17037                      if(extractDrbListToRelease(gnbDuUeF1apId, drbToRelease, drbToRelease->list.count,\
17038                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->duRlcUeCfg))
17039                      {
17040                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
17041                         ret = RFAILED;
17042                      }
17043                   }
17044                }
17045                break;
17046             }
17047
17048          case ProtocolIE_ID_id_GNB_DUConfigurationQuery:
17049             {
17050                DU_LOG("\nINFO  -->  DU APP : Received GNB DU Configuration Query in UE Context Modification Request from CU");
17051                if(duUeCb->f1UeDb)
17052                {
17053                   duUeCb->f1UeDb->actionType = UE_CTXT_CFG_QUERY;
17054                }
17055                break;
17056             }
17057
17058          case ProtocolIE_ID_id_RRCReconfigurationCompleteIndicator:
17059             {
17060                if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.RRCReconfigurationCompleteIndicator == \
17061                   RRCReconfigurationCompleteIndicator_true)
17062                {
17063                   duUeCb->f1UeDb->actionType = UE_CTXT_RRC_RECFG_COMPLETE;
17064                }
17065                break;
17066             }
17067          case ProtocolIE_ID_id_TransmissionActionIndicator:
17068             {
17069                if(duUeCb->f1UeDb)
17070                {
17071                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.TransmissionActionIndicator  == TransmissionActionIndicator_stop)
17072                   {
17073                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = STOP_TRANSMISSION; 
17074                   }
17075                   else 
17076                   {
17077                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = RESTART_TRANSMISSION; 
17078                   }
17079                }
17080                break;
17081             }
17082
17083          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
17084             {
17085                if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
17086                {
17087                   duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
17088                }
17089                break;
17090             }
17091 #ifdef NR_DRX
17092          case ProtocolIE_ID_id_DRXConfigurationIndicator:
17093             {
17094                duUeCb->f1UeDb->duUeCfg.drxConfigIndicatorRelease = true;
17095                break;
17096             }
17097 #endif
17098               
17099       }
17100    }
17101
17102    if(ret != RFAILED) 
17103    {
17104       ret = duProcUeContextModReq(duUeCb);
17105    }
17106    freeAperDecodeUeContextModificationReqMsg(ueContextModifyReq);
17107    return ret; 
17108 }
17109
17110 /*****************************************************************i
17111 *
17112 * @brief Free memory allocated for UE Context Release Request
17113 *
17114 * @details
17115 *
17116 *    Function : FreeUeContextReleaseReq
17117 *
17118 *    Functionality:
17119 *         - Free memory allocated for UE Context Release Request
17120 *
17121 * @params[in] F1AP_PDU_t *f1apMsg
17122 * @return void 
17123 *
17124 * *************************************************************/
17125 void FreeUeContextReleaseReq(F1AP_PDU_t *f1apMsg)
17126 {
17127    uint8_t ieIdx;
17128    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
17129    
17130    if(f1apMsg)
17131    {
17132       if(f1apMsg->choice.initiatingMessage)
17133       {
17134          ueReleaseReq =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
17135          if(ueReleaseReq->protocolIEs.list.array)
17136          {
17137             for(ieIdx=0 ; ieIdx<ueReleaseReq->protocolIEs.list.count; ieIdx++)
17138             {
17139                DU_FREE(ueReleaseReq->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseRequest_t));
17140             }
17141             DU_FREE(ueReleaseReq->protocolIEs.list.array, ueReleaseReq->protocolIEs.list.size);
17142          }
17143          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
17144       }
17145       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
17146    }
17147
17148 }
17149 /*****************************************************************i
17150 *
17151 * @brief Build and Send UE Context Release Request  
17152 *
17153 * @details
17154 *
17155 *    Function : BuildAndSendUeContextReleaseReq
17156 *
17157 *    Functionality:
17158 *         - Build and Send UE Context Release Request 
17159 *
17160 * @params[in]
17161 * @return ROK     - success
17162 *         RFAILED - failure
17163 *
17164 * *************************************************************/
17165 uint8_t BuildAndSendUeContextReleaseReq(uint16_t cellId, uint8_t ueId)
17166 {
17167    bool memAllocFail = false;
17168    uint8_t ieIdx =0;
17169    uint8_t ret = RFAILED;
17170    uint16_t cellIdx =0;
17171    uint16_t crnti = 0;
17172    uint8_t  elementCnt = 0;
17173    uint32_t  gnbCuUeF1apId =0;   /* gNB-CU UE F1AP Id */
17174    uint32_t  gnbDuUeF1apId =0;   /* gNB-DU UE F1AP Id */
17175    asn_enc_rval_t encRetVal; 
17176    F1AP_PDU_t *f1apMsg = NULLP;
17177    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
17178
17179    DU_LOG("\nINFO  --> Building the UE Context Release Request");
17180    do
17181    {
17182       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
17183       if(f1apMsg == NULLP)
17184       {
17185          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for f1apMsg");
17186          break;
17187       }
17188
17189       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
17190       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
17191       if(f1apMsg->choice.initiatingMessage == NULLP)
17192       {
17193          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for\
17194          initiatingMessage");   
17195          break;
17196       }
17197       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_UEContextReleaseRequest;
17198       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
17199       f1apMsg->choice.initiatingMessage->value.present = \
17200       InitiatingMessage__value_PR_UEContextReleaseRequest;
17201
17202       ueReleaseReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
17203
17204       elementCnt = 2;
17205
17206       ueReleaseReq->protocolIEs.list.count = elementCnt;
17207       ueReleaseReq->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseRequest_t *);
17208
17209       /* Initialize the F1Setup members */
17210       DU_ALLOC(ueReleaseReq->protocolIEs.list.array,ueReleaseReq->protocolIEs.list.size);
17211       if(ueReleaseReq->protocolIEs.list.array == NULLP)
17212       {
17213          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE array");
17214          break;
17215       }
17216       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
17217       {
17218          DU_ALLOC(ueReleaseReq->protocolIEs.list.array[ieIdx],\
17219                sizeof(UEContextReleaseRequest_t));
17220          if(ueReleaseReq->protocolIEs.list.array[ieIdx] == NULLP)
17221          {
17222             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE elements");
17223             memAllocFail = true;  
17224             break;
17225          }
17226       }
17227       if(memAllocFail == true)
17228          break;
17229
17230       /* Fetching Ue Cb Info*/
17231       GET_CELL_IDX(cellId, cellIdx);
17232       if(duCb.actvCellLst[cellIdx] == NULLP)
17233       {
17234          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): CellId[%d] does not exist", cellId);
17235          break;
17236       }
17237       else
17238       {
17239          GET_CRNTI(crnti, ueId);
17240          if(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].crnti != crnti)
17241          {
17242             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): crnti[%d] does not exist", crnti);
17243             break;
17244          }
17245          gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
17246          gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
17247       }
17248
17249       ieIdx=0; 
17250       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID; 
17251       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17252       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present = \
17253       UEContextReleaseRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
17254       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
17255       
17256       ieIdx++;
17257       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
17258       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17259       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present =\
17260       UEContextReleaseRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
17261       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17262       
17263       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17264
17265       /* Encode the F1SetupRequest type as APER */
17266       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17267       encBufSize = 0;
17268       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17269       /* Encode results */
17270       if(encRetVal.encoded == ENCODE_FAIL)
17271       {
17272          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseRequest structure (at %s)\n",\
17273                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17274          break;
17275       }
17276       else
17277       {
17278          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseRequest\n");
17279 #ifdef DEBUG_ASN_PRINT
17280          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17281          {
17282             printf("%x",encBuf[ieIdx]);
17283          }
17284 #endif
17285       }
17286
17287       /* Sending msg */
17288       if(sendF1APMsg() != ROK)
17289       {
17290          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Request failed");
17291          break;
17292       }
17293       ret = ROK;
17294       break;
17295    }while(true);
17296
17297    FreeUeContextReleaseReq(f1apMsg);
17298    return ret;
17299 }
17300 /*****************************************************************i
17301  *
17302  * @brief Free memory allocated for UE Context Release Complete
17303  *
17304  * @details
17305  *
17306  *    Function : FreeUeContextReleaseComplete
17307  *
17308  *    Functionality:
17309  *         - Free memory allocated for UE Context Release Complete
17310  *
17311  * @params[in] F1AP_PDU_t *f1apMsg
17312  * @return void
17313  *
17314  * *************************************************************/
17315 void FreeUeContextReleaseComplete(F1AP_PDU_t *f1apMsg)
17316 {
17317    uint8_t ieIdx;
17318    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17319
17320    if(f1apMsg)
17321    {
17322       if(f1apMsg->choice.successfulOutcome)
17323       {
17324          ueReleaseComplete =&f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17325          if(ueReleaseComplete->protocolIEs.list.array)
17326          {
17327             for(ieIdx=0 ; ieIdx<ueReleaseComplete->protocolIEs.list.count; ieIdx++)
17328             {
17329                DU_FREE(ueReleaseComplete->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseComplete_t));
17330             }
17331             DU_FREE(ueReleaseComplete->protocolIEs.list.array, ueReleaseComplete->protocolIEs.list.size);
17332          }
17333          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17334       }
17335       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
17336    }
17337
17338 }
17339 /*****************************************************************i
17340  *
17341  * @brief Build and Send UE Context Release Complete
17342  *
17343  * @details
17344  *
17345  *    Function : BuildAndSendUeContextReleaseComplete
17346  *
17347  *    Functionality:
17348  *         - Build and Send UE Context Release Complete
17349  *
17350  * @params[in]  cellId,  gnbCuUeF1apId, gnbDuUeF1apId
17351  * @return ROK     - success
17352  *         RFAILED - failure
17353  *
17354  * *************************************************************/
17355 uint8_t BuildAndSendUeContextReleaseComplete(uint16_t cellId, uint32_t gnbCuUeF1apId, uint32_t gnbDuUeF1apId)
17356 {
17357    bool memAllocFail = false;
17358    uint8_t ieIdx =0, ret = RFAILED, elementCnt = 0;
17359    asn_enc_rval_t encRetVal;
17360    F1AP_PDU_t *f1apMsg = NULLP;
17361    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17362
17363    DU_LOG("\nINFO  --> Building the UE Context Release Complete");
17364    do
17365    {
17366       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
17367       if(f1apMsg == NULLP)
17368       {
17369          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for f1apMsg");
17370          break;
17371       }
17372
17373       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
17374       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17375       if(f1apMsg->choice.successfulOutcome == NULLP)
17376       {
17377          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for\
17378                successfulOutcome");
17379          break;
17380       }
17381       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextRelease;
17382       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
17383       f1apMsg->choice.successfulOutcome->value.present = \
17384       SuccessfulOutcome__value_PR_UEContextReleaseComplete;
17385
17386       ueReleaseComplete = &f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17387
17388       elementCnt = 2;
17389       ueReleaseComplete->protocolIEs.list.count = elementCnt;
17390       ueReleaseComplete->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseComplete_t *);
17391
17392       /* Initialize the UE Release Complete members */
17393       DU_ALLOC(ueReleaseComplete->protocolIEs.list.array,ueReleaseComplete->protocolIEs.list.size);
17394       if(ueReleaseComplete->protocolIEs.list.array == NULLP)
17395       {
17396          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE array");
17397          break;
17398       }
17399       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
17400       {
17401          DU_ALLOC(ueReleaseComplete->protocolIEs.list.array[ieIdx],\
17402                sizeof(UEContextReleaseComplete_t));
17403          if(ueReleaseComplete->protocolIEs.list.array[ieIdx] == NULLP)
17404          {
17405             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE\
17406             elements");
17407             memAllocFail = true;
17408             break;
17409          }
17410       }
17411       if(memAllocFail == true)
17412          break;
17413
17414
17415       ieIdx=0;
17416       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
17417       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17418       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present = \
17419       UEContextReleaseCompleteIEs__value_PR_GNB_CU_UE_F1AP_ID;
17420       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
17421
17422       ieIdx++;
17423       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
17424       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17425       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present =\
17426       UEContextReleaseCompleteIEs__value_PR_GNB_DU_UE_F1AP_ID;
17427       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17428
17429       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17430
17431       /* Encode the F1SetupComplete type as APER */
17432       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17433       encBufSize = 0;
17434       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17435       /* Encode results */
17436       if(encRetVal.encoded == ENCODE_FAIL)
17437       {
17438          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseComplete structure (at %s)\n",\
17439                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17440          break;
17441       }
17442       else
17443       {
17444          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseComplete\n");
17445 #ifdef DEBUG_ASN_PRINT
17446          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17447          {
17448             printf("%x",encBuf[ieIdx]);
17449          }
17450 #endif
17451       }
17452
17453       /* Sending msg */
17454       if(sendF1APMsg() != ROK)
17455       {
17456          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Complete failed");
17457          break;
17458       }
17459       ret = ROK;
17460       break;
17461    }while(true);
17462    
17463    if((ret == ROK) && (duCb.actvCellLst[cellId-1]) && (duCb.actvCellLst[cellId-1]->cellStatus == DELETION_IN_PROGRESS) 
17464          && (duCb.actvCellLst[cellId-1]->numActvUes == 0))
17465    {
17466       ret = duSendCellDeletReq(cellId);
17467       if(ret != ROK)
17468       {
17469          DU_LOG("\nERROR  -->  F1AP: BuildAndSendUeContextReleaseComplete(): Failed to process cell\
17470                Delete req for CellId");
17471       }
17472    }
17473    FreeUeContextReleaseComplete(f1apMsg);
17474    return ret;
17475
17476 }
17477
17478 /*******************************************************************
17479 *
17480 * @brief added free part for the memory allocated by aper_decoder 
17481 *
17482 * @details
17483 *
17484 *    Function : freeAperDecodeUeContextReleaseCommand 
17485 *
17486 *    Functionality: added free part for the memory allocated by aper_decoder
17487 *
17488 * @params[in] F1AP_PDU_t *f1apMsg
17489 * @return void
17490 *
17491 * ****************************************************************/
17492 void freeAperDecodeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17493 {
17494    uint8_t ieIdx=0;
17495    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17496
17497    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17498    
17499    if(ueContextReleaseCommand->protocolIEs.list.array)
17500    {
17501       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17502       {
17503          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17504          {
17505             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17506             {
17507                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17508                   break;
17509                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17510                   break;
17511                case ProtocolIE_ID_id_Cause:
17512                   break;
17513                case ProtocolIE_ID_id_RRCContainer:
17514                {
17515                   if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
17516                   {
17517                      free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
17518                   }
17519                   break;
17520                }
17521                default :
17522                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17523                        ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17524                   break;
17525             }
17526          }
17527          free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]);
17528       }
17529       free(ueContextReleaseCommand->protocolIEs.list.array);
17530    }
17531 }
17532 /*******************************************************************
17533 *
17534 * @brief processing of UE Context Release Command
17535 *
17536 * @details
17537 *
17538 *    Function : procF1UeContextReleaseCommand 
17539 *
17540 *    Functionality: processing of UE Context Release Command
17541 *
17542 * @params[in] F1AP_PDU_t *f1apMsg
17543 * @return void
17544 *
17545 * ****************************************************************/
17546 uint8_t procF1UeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17547 {
17548    uint8_t  ieIdx=0, ret=ROK, ueIdx=0;
17549    uint16_t cellIdx =0, cellId = 0;
17550    bool ueIdxFound = false;
17551    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0;
17552    DuUeCb   *duUeCb = NULLP;
17553    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17554
17555    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17556
17557    if(ueContextReleaseCommand->protocolIEs.list.array)
17558    {
17559       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17560       {
17561          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17562          {
17563             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17564             {
17565                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17566                   {
17567                      gnbCuUeF1apId= ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17568                                     value.choice.GNB_CU_UE_F1AP_ID;
17569                      break;
17570                   }
17571
17572                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17573                   {
17574                      gnbDuUeF1apId = ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17575                                      value.choice.GNB_DU_UE_F1AP_ID;
17576                      break;
17577                   }
17578
17579                case ProtocolIE_ID_id_Cause:
17580                   {
17581                      for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
17582                      {
17583                         for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
17584                         {
17585                            if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
17586                                  (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId))
17587                            {
17588                               cellId = duCb.actvCellLst[cellIdx]->cellId;
17589                               duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
17590                               ueIdxFound = true;
17591                               break;
17592                            }
17593                         }
17594                         if(ueIdxFound == true)
17595                         {
17596                            break;
17597                         }
17598                      }
17599                      
17600                      if(!ueIdxFound)
17601                      {
17602                         DU_LOG("\nERROR  -->  F1AP: procF1UeContextReleaseCommand(): Ue Information is not available");
17603                         ret = RFAILED;
17604                      }
17605                      break;
17606                   }
17607
17608                case ProtocolIE_ID_id_RRCContainer:
17609                   {
17610                      if(ueIdxFound == true)  
17611                      {
17612                         DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
17613                         if(duUeCb->f1UeDb)
17614                         {
17615                            memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
17616                            duUeCb->f1UeDb->actionType = UE_CTXT_RELEASE;
17617                            duUeCb->f1UeDb->cellIdx = cellIdx;
17618                            /* Filling Dl RRC Msg Info */
17619                            DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
17620                            if(!duUeCb->f1UeDb->dlRrcMsg)
17621                            {
17622                               DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17623                                     Memory allocation failed ");
17624                               ret = RFAILED;
17625                            }
17626                            else
17627                            {
17628                               duUeCb->f1UeDb->dlRrcMsgPres = true;
17629                               memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
17630                               ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
17631                                     &ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17632                                     value.choice.RRCContainer);
17633                            }
17634
17635                         }
17636                         else
17637                         {
17638                            DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17639                                  Memory allocation failed ");
17640                            ret = RFAILED;
17641
17642                         }
17643                      }
17644                      break;
17645                   }
17646                default :
17647                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17648                         ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17649                   break;
17650             }
17651          }
17652       }
17653    }
17654    if(ret != RFAILED)
17655    {
17656       duProcUeContextReleaseCommand(cellId, duUeCb);
17657    }
17658    freeAperDecodeUeContextReleaseCommand(f1apMsg);
17659    return ret;
17660 }
17661
17662 /**************************************************************
17663  *
17664  * @brief free the memory allocated by aper decoder for paging
17665  *
17666  * @details
17667  *
17668  *    Function : freeAperDecodePagingMsg
17669  *
17670  *    Functionality:
17671  *         - free the memory allocated by aper decoder for
17672  *         the paging f1ap msg
17673  *
17674  * @params[in] Paging_t   *paging
17675  * @return ROK     - success
17676  *         RFAILED - failure
17677  *
17678  ****************************************************************/
17679 void freeAperDecodePagingMsg(Paging_t   *paging)
17680 {
17681    uint8_t ieIdx, cellIdx;
17682    PagingCell_ItemIEs_t *pagingCellItemIes;
17683    PagingCell_Item_t *pagingCellItem;
17684    PagingCell_list_t  *pagingCelllist;
17685
17686    if(paging)
17687    {
17688       if(paging->protocolIEs.list.array)
17689       {
17690          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17691          {
17692             if(paging->protocolIEs.list.array[ieIdx])
17693             {
17694                switch(paging->protocolIEs.list.array[ieIdx]->id)
17695                {
17696                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17697                      {
17698                         free(paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10.buf);
17699                         break;
17700                      }
17701                   case ProtocolIE_ID_id_PagingIdentity:
17702                      {
17703                         if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present == PagingIdentity_PR_cNUEPagingIdentity)
17704                         {
17705                            if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)
17706                            {
17707                               if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->present == \
17708                                     CNUEPagingIdentity_PR_fiveG_S_TMSI)
17709                               {
17710                                  free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->choice.fiveG_S_TMSI.buf);
17711                               }
17712                               free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity);
17713                            }
17714                         }
17715                         break;
17716                      }
17717                   case ProtocolIE_ID_id_PagingCell_List:
17718                      {
17719                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list;
17720                         if(pagingCelllist->list.array)
17721                         {
17722                            for(cellIdx = 0; cellIdx < pagingCelllist->list.count; cellIdx++)
17723                            {
17724                               if(pagingCelllist->list.array[cellIdx])
17725                               {
17726                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellIdx];
17727                                  if(pagingCellItemIes->id == ProtocolIE_ID_id_PagingCell_Item)
17728                                  {
17729                                     pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17730                                     free(pagingCellItem->nRCGI.pLMN_Identity.buf);
17731                                     free(pagingCellItem->nRCGI.nRCellIdentity.buf);
17732                                  }
17733                                  free(pagingCelllist->list.array[cellIdx]);
17734                               }
17735                            }
17736                            free(pagingCelllist->list.array);
17737                         }
17738                         break;
17739                      }
17740                }
17741                free(paging->protocolIEs.list.array[ieIdx]);
17742             }
17743          }
17744          free(paging->protocolIEs.list.array);
17745
17746       }
17747    }
17748 }
17749
17750 /**************************************************************
17751  *
17752  * @brief processing the paging f1ap msg received from CU 
17753  *
17754  * @details
17755  *
17756  *    Function : procPagingMsg
17757  *
17758  *    Functionality:
17759  *         - processing the paging f1ap msg received from CU
17760  *
17761  * @params[in] F1AP_PDU_t *f1apMsg
17762  * @return ROK     - success
17763  *         RFAILED - failure
17764  *
17765  *
17766  ****************************************************************/
17767 uint8_t procPagingMsg(F1AP_PDU_t *f1apMsg) 
17768 {
17769    uint8_t ieIdx = 0, cellListIdx = 0;
17770    uint64_t cellId = 0;
17771    Paging_t   *paging = NULLP;
17772    PagingCell_list_t  *pagingCelllist = NULLP;
17773    PagingCell_ItemIEs_t *pagingCellItemIes = NULLP;
17774    PagingCell_Item_t *pagingCellItem = NULLP;
17775    DuPagingMsg *tmpPagingParam = NULLP;
17776
17777    paging = &f1apMsg->choice.initiatingMessage->value.choice.Paging;
17778    if(paging)
17779    {
17780       if(paging->protocolIEs.list.array)
17781       {
17782          DU_ALLOC(tmpPagingParam, sizeof(DuPagingMsg));
17783          if(tmpPagingParam == NULLP)
17784          {
17785             DU_LOG("\nERROR  --> DU APP : Memory Allocation Failure in procPagingMsg");
17786             freeAperDecodePagingMsg(paging);
17787             return RFAILED;
17788          }
17789          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17790          {
17791             if(paging->protocolIEs.list.array[ieIdx])
17792             {
17793                switch(paging->protocolIEs.list.array[ieIdx]->id)
17794                {
17795                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17796                      {
17797                         bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10,\
17798                                          &tmpPagingParam->pagUeId);
17799                         break;
17800                      }
17801
17802                   case ProtocolIE_ID_id_PagingIdentity:
17803                      {
17804                         switch(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present)
17805                         {
17806                            case PagingIdentity_PR_cNUEPagingIdentity: 
17807                               {
17808                                  if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)  
17809                                  {
17810                                     bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.\
17811                                           cNUEPagingIdentity->choice.fiveG_S_TMSI, &tmpPagingParam->sTmsi);
17812
17813                                  }
17814                                  break;
17815                               }
17816                             case PagingIdentity_PR_rANUEPagingIdentity:
17817                                {
17818                                   /*TODO: This Identifier is specific to RAN Initiated Paging â€“ Connected Mode Paging*/
17819                                   break;
17820                                }
17821                             default:
17822                                {
17823                                   DU_LOG("ERROR  -->  DU APP: Invalid UE Paging Identity, Skipping this Paging Message:");
17824                                   continue;
17825                                }
17826                         }
17827                      }
17828
17829                   case ProtocolIE_ID_id_PagingDRX:
17830                      {
17831                         tmpPagingParam->pagingDrxPres = TRUE;
17832                         tmpPagingParam->pagingDrx = convertPagingCycleEnumToValue(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingDRX);
17833                         break;
17834                      }
17835
17836                   case ProtocolIE_ID_id_PagingPriority:
17837                      {
17838                         tmpPagingParam->pagPriority = paging->protocolIEs.list.array[ieIdx]->value.choice.PagingPriority;
17839                         break;
17840                      }
17841
17842                   case ProtocolIE_ID_id_PagingCell_List:
17843                      {
17844                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list; 
17845                         if(pagingCelllist->list.array)
17846                         {
17847                            for(cellListIdx = 0; cellListIdx < pagingCelllist->list.count; cellListIdx++)
17848                            {
17849                               if(pagingCelllist->list.array[cellListIdx])
17850                               {
17851                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellListIdx];
17852                                  pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17853                                  bitStringToInt(&pagingCellItem->nRCGI.nRCellIdentity, &cellId);
17854                                  if(processPagingMsg(cellId, tmpPagingParam) != ROK)
17855                                  {
17856                                     DU_LOG("\nERROR  --> DU APP : Paging Processing Failed at CellId:%lu",cellId);
17857                                     continue;
17858                                  }
17859                               }
17860                            }
17861                         }
17862                         break;
17863                      }
17864                    default:
17865                      {
17866                          DU_LOG("\nERROR  --> F1AP : Incorrect Paging IE option");
17867                          break;
17868                      }
17869                }
17870             }
17871          }
17872       }
17873    }
17874    DU_FREE(tmpPagingParam, sizeof(DuPagingMsg));
17875    freeAperDecodePagingMsg(paging);
17876   
17877    return ROK;
17878 }
17879
17880 /**************************************************************
17881  *
17882  * @brief Handles received F1AP message and sends back response  
17883  *
17884  * @details
17885  *
17886  *    Function : F1APMsgHdlr
17887  *
17888  *    Functionality:
17889  *         - Decodes received F1AP control message
17890  *         - Prepares response message, encodes and sends to SCTP
17891  *
17892  * @params[in] 
17893  * @return ROK     - success
17894  *         RFAILED - failure
17895  *
17896  * ****************************************************************/
17897 void F1APMsgHdlr(Buffer *mBuf)
17898 {
17899    int i =0;
17900    char *recvBuf =NULLP;
17901    MsgLen copyCnt =0;
17902    MsgLen recvBufLen =0;
17903    F1AP_PDU_t *f1apMsg =NULLP;
17904    asn_dec_rval_t rval; /* Decoder return value */
17905    F1AP_PDU_t f1apasnmsg ;
17906    DU_LOG("\nINFO  -->  F1AP : Received F1AP message buffer");
17907    ODU_PRINT_MSG(mBuf, 0,0);
17908
17909    /* Copy mBuf into char array to decode it */
17910    ODU_GET_MSG_LEN(mBuf, &recvBufLen);
17911    DU_ALLOC(recvBuf, (Size)recvBufLen);
17912
17913    if(recvBuf == NULLP)
17914    {
17915       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed");
17916       return;
17917    }
17918    if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
17919    {
17920       DU_LOG("\nERROR   -->  F1AP : Failed while copying %d", copyCnt);
17921       return;
17922    }
17923
17924 #ifdef DEBUG_ASN_PRINT
17925    printf("\nDEBUG   -->  F1AP : Received flat buffer to be decoded : ");
17926    for(i=0; i< recvBufLen; i++)
17927    {
17928       printf("%x",recvBuf[i]);
17929    }
17930 #endif
17931
17932    /* Decoding flat buffer into F1AP messsage */
17933    f1apMsg = &f1apasnmsg;
17934    memset(f1apMsg, 0, sizeof(F1AP_PDU_t));
17935
17936    rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0);
17937
17938    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
17939    {
17940       DU_LOG("\nERROR  -->  F1AP : ASN decode failed");
17941       return;
17942    }
17943    printf("\n");
17944    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17945
17946    switch(f1apMsg->present)
17947    {
17948       case F1AP_PDU_PR_successfulOutcome:
17949          {
17950             switch(f1apMsg->choice.successfulOutcome->value.present)
17951             {
17952                case SuccessfulOutcome__value_PR_ResetAcknowledge:
17953                   {
17954                      DU_LOG("\nINFO   -->  F1AP : F1ResetAcknowledge is received successfully ");
17955                      break;
17956                   }
17957                case SuccessfulOutcome__value_PR_F1SetupResponse:
17958                   {                             
17959 #ifndef ODU_TEST_STUB
17960                      procF1SetupRsp(f1apMsg, recvBufLen, recvBuf);
17961 #endif
17962                      break;
17963                   }
17964
17965                case SuccessfulOutcome__value_PR_GNBDUConfigurationUpdateAcknowledge:
17966                   {
17967                      procF1GNBDUCfgUpdAck(f1apMsg);
17968                      break;
17969                   }
17970
17971                default:
17972                   {
17973                      DU_LOG("\nERROR  -->  F1AP : Invalid type of SuccessfulOutcome__value_PR_ResetAcknowledge [%d]",\
17974                            f1apMsg->choice.successfulOutcome->value.present);
17975                      return;
17976                   }
17977             }/* End of switch(successfulOutcome) */
17978             free(f1apMsg->choice.successfulOutcome);
17979             break;
17980          }
17981       case F1AP_PDU_PR_initiatingMessage:
17982          {
17983             switch(f1apMsg->choice.initiatingMessage->value.present)
17984             {
17985                case InitiatingMessage__value_PR_Reset:
17986                   {
17987                      procF1ResetReq(f1apMsg);
17988                      break;
17989                   }
17990                case InitiatingMessage__value_PR_DLRRCMessageTransfer:
17991                   {
17992                      procF1DlRrcMsgTrans(f1apMsg);
17993                      break;
17994                   }
17995                case InitiatingMessage__value_PR_UEContextSetupRequest:
17996                   {
17997                      procF1UeContextSetupReq(f1apMsg);
17998                      break;
17999                   }
18000                case InitiatingMessage__value_PR_UEContextModificationRequest:
18001                   {
18002                      procF1UeContextModificationReq(f1apMsg);
18003                      break;
18004                   }
18005                case InitiatingMessage__value_PR_UEContextReleaseCommand:
18006                   {
18007                       procF1UeContextReleaseCommand(f1apMsg);
18008                       break;
18009                   }
18010                case InitiatingMessage__value_PR_Paging:
18011                   {
18012                      procPagingMsg(f1apMsg);
18013                      break;
18014                   }
18015                default:
18016                   {
18017                      DU_LOG("\nERROR  -->  F1AP : Invalid type of F1AP_PDU_PR_initiatingMessage [%d]",
18018                            f1apMsg->choice.initiatingMessage->value.present);
18019                      return;
18020                   }
18021             }/* End of switch(initiatingMessage) */
18022             free(f1apMsg->choice.initiatingMessage);
18023             break;
18024          }
18025
18026       default:
18027          {
18028             DU_LOG("\nERROR  -->  F1AP : Invalid type of f1apMsg->present [%d]",f1apMsg->present);
18029             return;
18030          }
18031          free(f1apMsg);
18032
18033    }/* End of switch(f1apMsg->present) */
18034    
18035    DU_FREE(recvBuf, (Size)recvBufLen);
18036 } /* End of F1APMsgHdlr */
18037
18038 /**********************************************************************
18039   End of file
18040  **********************************************************************/