[Epic-ID: ODUHIGH-516][Task-ID: ODUHIGH-521] E2 Database Implementation and configuration
[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 add or modify E2NodeComponent list
1594  *
1595  * @details
1596  *
1597  *    Function : addOrModifyE2NodeComponent 
1598  *
1599  * Functionality: add or modify E2NodeComponent list 
1600  *
1601  * @parameter uint8_t componentactiontype, bool reqPart, uint8_t bufSize, char *bufString
1602  * @return ROK     - success
1603  *         RFAILED - failure
1604  *
1605  ******************************************************************/
1606 uint8_t addOrModifyE2NodeComponent(uint8_t action, bool reqPart, uint8_t bufSize, char *bufString)
1607 {
1608    E2NodeComponent *e2NodeComponentInfo;
1609    CmLList  *node = NULLP;
1610    
1611    if(action == E2_NODE_COMPONENT_ADD)
1612    {
1613       if(reqPart == true)
1614       {
1615          DU_ALLOC(e2NodeComponentInfo, sizeof(E2NodeComponent));
1616          if(!e2NodeComponentInfo)
1617          {
1618             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed for e2NodeComponentInfo in %s",__func__);
1619             return RFAILED;
1620          }
1621          e2NodeComponentInfo->interfaceType =F1;
1622          e2NodeComponentInfo->componentId=duCfgParam.duId;
1623          e2NodeComponentInfo->componentActionType = action;
1624          e2NodeComponentInfo->reqBufSize = bufSize;
1625
1626          DU_ALLOC(e2NodeComponentInfo->componentRequestPart, bufSize);
1627          if(e2NodeComponentInfo->componentRequestPart == NULLP)
1628          {
1629             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed for componentRequestPart");
1630             DU_FREE(e2NodeComponentInfo, sizeof(E2NodeComponent));
1631             return RFAILED;
1632          }
1633          memcpy(e2NodeComponentInfo->componentRequestPart, bufString, e2NodeComponentInfo->reqBufSize);
1634          DU_ALLOC(node, sizeof(CmLList));
1635          if(node)
1636          {
1637             node->node = (PTR) e2NodeComponentInfo;
1638             cmLListAdd2Tail(&duCb.e2apDb.e2NodeComponentList, node);
1639          }
1640          else
1641          {
1642             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed for e2NodeComponentList node");
1643             DU_FREE(e2NodeComponentInfo->componentRequestPart, bufSize);
1644             DU_FREE(e2NodeComponentInfo, sizeof(E2NodeComponent));
1645             return RFAILED;
1646          }
1647       }
1648       else
1649       {
1650          if(duCb.e2apDb.e2NodeComponentList.count)
1651          {
1652             CM_LLIST_FIRST_NODE(&duCb.e2apDb.e2NodeComponentList, node);
1653             while(node)
1654             {
1655                e2NodeComponentInfo = (E2NodeComponent*)node->node;
1656                if((e2NodeComponentInfo->interfaceType == F1) && (e2NodeComponentInfo->componentActionType == action))
1657                {
1658                   e2NodeComponentInfo->rspBufSize = bufSize;
1659
1660                   DU_ALLOC(e2NodeComponentInfo->componentResponsePart, bufSize);
1661                   if(e2NodeComponentInfo->componentResponsePart == NULLP)
1662                   {
1663                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the encoding of f1setup rsp");
1664                      return RFAILED;
1665                   }
1666                   memcpy(e2NodeComponentInfo->componentResponsePart, bufString, e2NodeComponentInfo->rspBufSize);
1667                   break;
1668                }
1669                node = node->next;
1670             }
1671          } 
1672       }
1673    }
1674    return ROK;
1675 }
1676 /*******************************************************************
1677  *
1678  * @brief Builds and Send the F1SetupRequest
1679  *
1680  * @details
1681  *
1682  *    Function : BuildAndSendF1SetupReq
1683  *
1684  * Functionality:Fills the F1SetupRequest
1685  *
1686  * @return ROK     - success
1687  *         RFAILED - failure
1688  *
1689  ******************************************************************/
1690 uint8_t BuildAndSendF1SetupReq()
1691 {
1692    uint8_t   ret, ieIdx, elementCnt;
1693    F1AP_PDU_t                 *f1apMsg = NULLP;
1694    F1SetupRequest_t           *f1SetupReq=NULLP;
1695    GNB_DU_Served_Cells_List_t *duServedCell=NULLP;
1696    RRC_Version_t              *rrcVer=NULLP;
1697    asn_enc_rval_t             encRetVal;        /* Encoder return value */
1698    ret= RFAILED;
1699
1700    DU_LOG("\nINFO   -->  F1AP : Building F1 Setup Request\n");
1701    do
1702    {
1703       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
1704       if(f1apMsg == NULLP)
1705       {
1706          break;
1707       }
1708       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
1709       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1710       if(f1apMsg->choice.initiatingMessage == NULLP)
1711       {
1712          break;
1713       }
1714       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_F1Setup;
1715       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
1716       f1apMsg->choice.initiatingMessage->value.present = \
1717                                                          InitiatingMessage__value_PR_F1SetupRequest;
1718
1719       f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1720
1721       elementCnt = 5;
1722
1723       f1SetupReq->protocolIEs.list.count = elementCnt;
1724       f1SetupReq->protocolIEs.list.size = elementCnt * sizeof(F1SetupRequestIEs_t *);
1725
1726       /* Initialize the F1Setup members */
1727       DU_ALLOC(f1SetupReq->protocolIEs.list.array,f1SetupReq->protocolIEs.list.size);
1728       if(f1SetupReq->protocolIEs.list.array == NULLP)
1729       {
1730          break;
1731       }
1732       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
1733       {
1734          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx],\
1735                sizeof(F1SetupRequestIEs_t));
1736          if(f1SetupReq->protocolIEs.list.array[ieIdx] == NULLP)
1737          {
1738             break;
1739          }
1740       }
1741
1742       ieIdx = 0;
1743       /*TransactionID*/
1744       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_TransactionID;
1745       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1746       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present =\
1747                                                                 F1SetupRequestIEs__value_PR_TransactionID;
1748       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = \
1749                                                                               TRANS_ID;
1750
1751       /*DU ID*/
1752       ieIdx++;
1753       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
1754       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1755       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1756                                                                  F1SetupRequestIEs__value_PR_GNB_DU_ID;
1757       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size =\
1758                                                                               sizeof(uint8_t);
1759
1760       DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1761             f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1762       if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == \
1763             NULLP)
1764       {
1765          break;
1766       }
1767
1768       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] =\
1769                                                                                 duCfgParam.duId;
1770       /* DU name IE is of type printableString_t which wireshark is unable to decode.
1771        * However this string is decoded successfully on online decoders.
1772        * Since this is an optional IE and the value received in it are not
1773        * used as of now, eliminating this IE for now to avoid wireshark error.
1774        */
1775       /*DU Name*/
1776       if(duCfgParam.duName != NULL)
1777       {
1778          ieIdx++;
1779          f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_Name;
1780          f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_ignore;
1781          f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = F1SetupRequestIEs__value_PR_GNB_DU_Name;
1782          f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size = strlen((char *)duCfgParam.duName);
1783          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf, \
1784                f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size);
1785          if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf == NULLP)
1786          {
1787             break;
1788          }
1789          strcpy((char*)f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,
1790                (char*)duCfgParam.duName);
1791       }
1792
1793       /*Served Cell list */
1794       ieIdx++;
1795       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1796                                                       ProtocolIE_ID_id_gNB_DU_Served_Cells_List;
1797       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1798       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1799                                                                  F1SetupRequestIEs__value_PR_GNB_DU_Served_Cells_List;
1800       duServedCell = &f1SetupReq->protocolIEs.list.\
1801                      array[ieIdx]->value.choice.GNB_DU_Served_Cells_List;
1802       if(BuildServedCellList(duServedCell))
1803       {
1804          break;
1805       }
1806
1807       /*RRC Version*/
1808       ieIdx++;
1809       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1810                                                       ProtocolIE_ID_id_GNB_DU_RRC_Version ;
1811       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1812       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1813                                                                  F1SetupRequestIEs__value_PR_RRC_Version;
1814       rrcVer = &f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
1815       if(BuildRrcVer(rrcVer))
1816       {
1817          break;
1818       }
1819
1820       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
1821
1822       /* Encode the F1SetupRequest type as APER */
1823       memset(encBuf, 0, ENC_BUF_MAX_LEN);
1824       encBufSize = 0;
1825       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
1826             encBuf);
1827
1828       /* Encode results */
1829       if(encRetVal.encoded == ENCODE_FAIL)
1830       {
1831          DU_LOG("\nERROR  -->  F1AP : Could not encode F1SetupRequest structure (at %s)\n",\
1832                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1833          break;
1834       }
1835       else
1836       {
1837          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1SetupRequest\n");
1838 #ifdef DEBUG_ASN_PRINT
1839          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
1840          {
1841             printf("%x",encBuf[ieIdx]);
1842          }
1843 #endif
1844          
1845
1846       }
1847       addOrModifyE2NodeComponent(E2_NODE_COMPONENT_ADD, true, encBufSize, encBuf);
1848       /* Sending msg */
1849       if(sendF1APMsg() != ROK)
1850       {
1851          DU_LOG("\nERROR  -->  F1AP : Sending F1 Setup request failed");
1852          break;
1853       }
1854
1855       ret=ROK;
1856       break;
1857    }while(true);
1858
1859    FreeF1SetupReq(f1apMsg);
1860
1861    return ret;
1862 }/* End of BuildAndSendF1SetupReq */
1863
1864 /*******************************************************************
1865  *
1866  * @brief Deallocating memory allocated for Served_Cells_To_Modify_Item_t
1867  *
1868  * @details
1869  *
1870  *    Function : freeCellsToModifyItem 
1871  *
1872  *    Functionality: Deallocating memory of variables allocated in
1873  *                    BuildAndSendDUConfigUpdate function
1874  *
1875  * @params[in]  Served_Cells_To_Modify_Item_t *modifyItem
1876  *
1877  * @return ROK     - void
1878  *
1879  * ****************************************************************/
1880
1881 void freeCellsToModifyItem(Served_Cells_To_Modify_Item_t *modifyItem)
1882 {
1883    uint8_t arrIdx=0, servedPlmnIdx=0, sliceLstIdx=0;
1884    ServedPLMNs_Item_t *servedPlmnItem = NULLP;
1885    SliceSupportItem_t *sliceSupportItem = NULLP;
1886
1887    DU_FREE(modifyItem->oldNRCGI.pLMN_Identity.buf, modifyItem->oldNRCGI.pLMN_Identity.size);
1888    DU_FREE(modifyItem->oldNRCGI.nRCellIdentity.buf, modifyItem->oldNRCGI.nRCellIdentity.size);
1889
1890    DU_FREE(modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1891            modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.size);
1892    DU_FREE(modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1893          modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.size);
1894
1895    if(modifyItem->served_Cell_Information.servedPLMNs.list.array != NULLP)
1896    {
1897       if(modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx] != NULLP)
1898       {
1899          servedPlmnItem = modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx];
1900
1901          DU_FREE(servedPlmnItem->pLMN_Identity.buf,servedPlmnItem->pLMN_Identity.size);
1902
1903          if(servedPlmnItem->iE_Extensions != NULLP)
1904          {
1905             if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1906             {
1907                if(servedPlmnItem->iE_Extensions->list.array[arrIdx] != NULLP)
1908                {
1909                   if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1910                         list.array != NULLP)
1911                   {
1912                      for(sliceLstIdx =0; sliceLstIdx<servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1913                            extensionValue.choice.SliceSupportList.list.count; sliceLstIdx++)
1914                      {
1915                         if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1916                               list.array[sliceLstIdx] != NULLP)
1917                         {
1918
1919                            sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1920                                               SliceSupportList.list.array[sliceLstIdx];
1921
1922                            DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sliceSupportItem->sNSSAI.sST.size);
1923                            if(sliceSupportItem->sNSSAI.sD != NULLP)
1924                            {
1925                               DU_FREE(sliceSupportItem->sNSSAI.sD->buf, sliceSupportItem->sNSSAI.sD->size);
1926                               DU_FREE(sliceSupportItem->sNSSAI.sD,sizeof(OCTET_STRING_t));
1927                            }
1928                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1929                                  SliceSupportList.list.array[sliceLstIdx], sizeof(SliceSupportItem_t));
1930                         }
1931                      }
1932                      DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.\
1933                            choice.SliceSupportList.list.array,\
1934                            servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1935                            extensionValue.choice.SliceSupportList.list.size);
1936                   }
1937                }
1938                for(servedPlmnIdx=0; servedPlmnIdx< servedPlmnItem->iE_Extensions->list.count ; servedPlmnIdx++)
1939                {
1940                   DU_FREE(servedPlmnItem->iE_Extensions->list.array[servedPlmnIdx], sizeof(ServedPLMNs_ItemExtIEs_t ));
1941                }
1942                DU_FREE(servedPlmnItem->iE_Extensions->list.array, servedPlmnItem->iE_Extensions->list.size);
1943             }
1944             DU_FREE(servedPlmnItem->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1945          }
1946       }
1947       for(servedPlmnIdx=0; servedPlmnIdx<modifyItem->served_Cell_Information.servedPLMNs.list.count; servedPlmnIdx++)
1948       {
1949          DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array[servedPlmnIdx], sizeof(ServedPLMNs_Item_t));
1950       }
1951       DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array,\
1952          modifyItem->served_Cell_Information.servedPLMNs.list.size);
1953    }
1954    
1955    if(modifyItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1956    {
1957       freeFddNrFreqInfo(modifyItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1958    }  
1959    else
1960    {
1961       if(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD)
1962       {
1963          freeTddNrFreqInfo(&modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1964          DU_FREE(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1965       }
1966    }
1967    DU_FREE(modifyItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1968          modifyItem->served_Cell_Information.measurementTimingConfiguration.size);
1969 }
1970
1971 /*******************************************************************
1972  *
1973  * @brief Deallocating memory of BuildAndSendDUConfigUpdate
1974  *
1975  * @details
1976  *
1977  *    Function : FreeDUConfigUpdate
1978  *
1979  *    Functionality: Deallocating memory of variables allocated in
1980  *                    BuildAndSendDUConfigUpdate function
1981  *
1982  * @params[in]  F1AP_PDU_t *f1apDuCfg
1983  *
1984  * @return ROK     - void
1985  *
1986  * ****************************************************************/
1987 void FreeDUConfigUpdate(F1AP_PDU_t *f1apDuCfg)
1988 {
1989    uint8_t  idx=0,ieIdx=0, cellModifyIdx=0, cellDeleteIdx=0;
1990    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
1991    Served_Cells_To_Modify_List_t  *cellsToModify=NULLP;
1992    Served_Cells_To_Delete_List_t  *cellsToDelete=NULLP;
1993    Served_Cells_To_Delete_Item_t  *deleteItem = NULLP;
1994    Served_Cells_To_Delete_ItemIEs_t *deleteItemIe = NULLP;
1995    Cells_Status_ItemIEs_t *cellStatusItemIE;
1996
1997    if(f1apDuCfg != NULLP)
1998    {
1999       if(f1apDuCfg->choice.initiatingMessage != NULLP)
2000       {
2001          duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->\
2002                        value.choice.GNBDUConfigurationUpdate;
2003          if(duCfgUpdate->protocolIEs.list.array != NULLP)
2004          {
2005             for(ieIdx=0; ieIdx<duCfgUpdate->protocolIEs.list.count; ieIdx++)
2006             {
2007                if(duCfgUpdate->protocolIEs.list.array[ieIdx] != NULLP)
2008                {
2009                   switch(duCfgUpdate->protocolIEs.list.array[ieIdx]->id)
2010                   {
2011                      case ProtocolIE_ID_id_Served_Cells_To_Modify_List:
2012                         {
2013                            cellsToModify = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
2014                                            value.choice.Served_Cells_To_Modify_List;
2015                            if(cellsToModify->list.array != NULLP)
2016                            {
2017                               for(cellModifyIdx=0; cellModifyIdx<cellsToModify->list.count ;cellModifyIdx++)
2018                               {
2019                                  if(cellsToModify->list.array[cellModifyIdx] != NULLP)
2020                                  {
2021                                     freeCellsToModifyItem(&cellsToModify->list.array[cellModifyIdx]->value.choice.\
2022                                           Served_Cells_To_Modify_Item);
2023                                     DU_FREE(cellsToModify->list.array[cellModifyIdx],\
2024                                           sizeof(Served_Cells_To_Modify_ItemIEs_t));
2025                                  }
2026                               }
2027                               DU_FREE(cellsToModify->list.array,cellsToModify->list.size);
2028                            }
2029                            break;
2030                         }
2031                      case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
2032                         {
2033                            cellsToDelete = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
2034                                            value.choice.Served_Cells_To_Delete_List;
2035                            if(cellsToDelete->list.array != NULLP)
2036                            {
2037                               for(cellDeleteIdx=0; cellDeleteIdx<cellsToDelete->list.count ;cellDeleteIdx++)
2038                               {
2039                                  if(cellsToDelete->list.array[cellDeleteIdx] != NULLP)
2040                                  {
2041                                     deleteItemIe = ((Served_Cells_To_Delete_ItemIEs_t*)\
2042                                           cellsToDelete->list.array[cellDeleteIdx]);
2043                                     deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
2044                                     DU_FREE(deleteItem->oldNRCGI.pLMN_Identity.buf,\
2045                                           deleteItem->oldNRCGI.pLMN_Identity.size); 
2046                                     DU_FREE(deleteItem->oldNRCGI.nRCellIdentity.buf,\
2047                                           deleteItem->oldNRCGI.nRCellIdentity.size);
2048                                     DU_FREE(cellsToDelete->list.array[cellDeleteIdx],\
2049                                           sizeof(Served_Cells_To_Delete_ItemIEs_t));
2050                                  }
2051                               }
2052                               DU_FREE(cellsToDelete->list.array,cellsToDelete->list.size);
2053                            }
2054
2055                            break;
2056                         }
2057                      case ProtocolIE_ID_id_gNB_DU_ID:
2058                         {
2059                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
2060                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
2061                            break;
2062                         }
2063                      case ProtocolIE_ID_id_Cells_Status_List:
2064                         {
2065                            for(idx = 0; idx < duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.count; idx++)
2066                            {
2067                               cellStatusItemIE = (Cells_Status_ItemIEs_t *)duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array[idx];
2068                               DU_FREE(cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.nRCellIdentity.buf, cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.nRCellIdentity.size);
2069                               DU_FREE(cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.pLMN_Identity.buf, cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.pLMN_Identity.size);
2070                               DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array[idx],sizeof(Cells_Status_ItemIEs_t));
2071                            }
2072                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array,\
2073                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.size);
2074                         }
2075                   }
2076                   DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx],\
2077                         sizeof(GNBDUConfigurationUpdateIEs_t));
2078                }
2079             }
2080             DU_FREE(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2081          }
2082          DU_FREE(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2083       }
2084       DU_FREE(f1apDuCfg, (Size)sizeof(F1AP_PDU_t));
2085    }
2086 }
2087
2088 /*******************************************************************
2089  *
2090  * @brief Fills Served Plmns required in ServCellInfo IE
2091  *
2092  * @details
2093  *
2094  *    Function : fillServedPlmns
2095  *
2096  *    Functionality: Fills Served Plmns required in ServCellInfo IE
2097  *
2098  * @params[in] Pointer to ServedPLMNs_List_t *
2099  *
2100  * @return ROK     - success
2101  *         RFAILED - failure
2102  *
2103  *****************************************************************/
2104
2105 uint8_t fillServedPlmns(ServedPLMNs_List_t *servedPlmn)
2106 {
2107    uint8_t ieIdx=0, arrayIdx=0, ieListCnt=0, elementCnt=0, sliceLstIdx=0;
2108
2109    servedPlmn->list.array[arrayIdx]->pLMN_Identity.size = 3*sizeof(uint8_t);
2110    DU_ALLOC(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf, servedPlmn->list.\
2111          array[arrayIdx]->pLMN_Identity.size);
2112    if(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf == NULLP)
2113    {
2114       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2115       return RFAILED;
2116    }
2117    buildPlmnId(duCfgParam.srvdCellLst[arrayIdx].duCellInfo.cellInfo.srvdPlmn[arrayIdx].plmn,\
2118          servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf);
2119    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
2120    if(servedPlmn->list.array[arrayIdx]->iE_Extensions == NULLP)
2121    {
2122       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2123       return RFAILED;
2124    }
2125
2126    ieListCnt=1;
2127    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.count = ieListCnt;
2128    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.size = ieListCnt *sizeof(ServedPLMNs_ItemExtIEs_t *);
2129    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array,servedPlmn->list.array[arrayIdx]->\
2130          iE_Extensions->list.size);
2131    if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array == NULLP)
2132    {
2133       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2134       return RFAILED;
2135    }
2136    for(ieIdx=arrayIdx;ieIdx<ieListCnt;ieIdx++)
2137    {
2138       DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx],\
2139             sizeof(ServedPLMNs_ItemExtIEs_t));
2140       if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx] == NULLP)
2141       {
2142          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2143          return RFAILED;
2144       }
2145    }
2146    
2147    ieIdx = 0;
2148    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices; 
2149    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->id =ProtocolIE_ID_id_TAISliceSupportList;
2150    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->criticality = Criticality_ignore;
2151    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.present = \
2152    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
2153    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2154       list.count = elementCnt;
2155    servedPlmn->list.array[arrayIdx]->\
2156       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2157       list.size = elementCnt * sizeof(SliceSupportItem_t *);
2158    DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2159          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2160          list.array,servedPlmn->list.array[arrayIdx]->\
2161          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.size);
2162    if(servedPlmn->list.array[arrayIdx]->\
2163          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2164          list.array == NULLP)
2165    {
2166       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2167       return RFAILED;
2168    }
2169
2170    for(sliceLstIdx =0; sliceLstIdx< elementCnt; sliceLstIdx++)
2171    {
2172       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2173       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2174       list.array[sliceLstIdx],sizeof( SliceSupportItem_t));
2175       if(servedPlmn->list.array[arrayIdx]->\
2176       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2177       list.array[sliceLstIdx] == NULLP)
2178       {   
2179          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2180          return RFAILED;
2181       }
2182       
2183       servedPlmn->list.array[arrayIdx]->\
2184       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2185       list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
2186       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2187       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2188       list.array[sliceLstIdx]->sNSSAI.sST.buf,servedPlmn->list.array[arrayIdx]->\
2189       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->\
2190       sNSSAI.sST.size);
2191       
2192       if(servedPlmn->list.array[arrayIdx]->\
2193       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2194       list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
2195       {
2196          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2197          return RFAILED;
2198       }
2199       servedPlmn->list.array[arrayIdx]->\
2200       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2201       list.array[sliceLstIdx]->sNSSAI.sST.buf[arrayIdx] =  duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
2202       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
2203
2204       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2205       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2206       list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
2207       if(servedPlmn->list.array[arrayIdx]->\
2208       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2209       list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
2210       {
2211          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2212          return RFAILED;
2213       }
2214       servedPlmn->list.array[arrayIdx]->\
2215       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2216       list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
2217       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2218       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2219       list.array[sliceLstIdx]->sNSSAI.sD->buf,servedPlmn->list.array[arrayIdx]->\
2220       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2221       list.array[sliceLstIdx]->sNSSAI.sD->size);
2222       if(servedPlmn->list.array[arrayIdx]->\
2223       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2224       list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
2225       {
2226          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2227          return RFAILED;
2228       }
2229       memcpy(servedPlmn->list.array[arrayIdx]->\
2230       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2231       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
2232       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sd,\
2233       servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2234       list.array[sliceLstIdx]->sNSSAI.sD->size);
2235    }
2236    return ROK;
2237 }
2238
2239 /*******************************************************************
2240  *
2241  * @brief Fills Nr Fdd Info required in ServCellInfo IE
2242  *
2243  * @details
2244  *
2245  *    Function : fillNrFddInfo
2246  *
2247  *    Functionality: Fills Nr Fdd Info required in ServCellInfo IE
2248  *
2249  * @params[in] FDD_Info_t *fDD
2250  *
2251  * @return ROK     - success
2252  *         RFAILED - failure
2253  *
2254  *****************************************************************/
2255
2256 uint8_t fillNrFddInfo(FDD_Info_t *fDD)
2257 {
2258    fDD->uL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.\
2259       f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn;
2260    fDD->uL_NRFreqInfo.freqBandListNr.list.count = 1;
2261    fDD->uL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t*);
2262    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.\
2263          array, fDD->uL_NRFreqInfo.freqBandListNr.list.size);
2264    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array == NULLP)
2265    {
2266       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2267       return RFAILED;
2268    }
2269
2270    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0], \
2271       sizeof(FreqBandNrItem_t));
2272    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2273    {
2274       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2275       return RFAILED;
2276    }
2277    
2278    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2279       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
2280       freqBand[0].nrFreqBand;
2281    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2282    fDD->dL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.\
2283       dlNrFreqInfo.nrArfcn;
2284    fDD->dL_NRFreqInfo.freqBandListNr.list.count = 1;
2285    fDD->dL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
2286    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array, fDD->dL_NRFreqInfo.freqBandListNr.list.size);
2287    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array == NULLP)
2288    {
2289       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2290       return RFAILED;
2291    }
2292    
2293    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0],  sizeof(FreqBandNrItem_t));
2294    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2295    {
2296       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2297       return RFAILED;
2298    }
2299
2300    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2301       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
2302       freqBand[0].nrFreqBand;
2303    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2304    
2305    /*Transmission Bandwidth*/
2306    fDD->uL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2307       f1Mode.mode.fdd.ulTxBw.nrScs;
2308    fDD->uL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2309       f1Mode.mode.fdd.ulTxBw.nrb;
2310    fDD->dL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2311       f1Mode.mode.fdd.dlTxBw.nrScs;
2312    fDD->dL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2313       f1Mode.mode.fdd.dlTxBw.nrb;
2314
2315    return ROK;
2316 }
2317
2318 /*******************************************************************
2319  *
2320  * @brief Fills ServCellInfo IE
2321  *
2322  * @details
2323  *
2324  *    Function : fillServedCellInfo
2325  *
2326  *    Functionality: Fills ServCellInfo
2327  *
2328  * @params[in] Pointer to Served_Cell_Information_t *
2329  *
2330  * @return ROK     - success
2331  *         RFAILED - failure
2332  *
2333  *****************************************************************/
2334
2335 uint8_t fillServedCellInfo(Served_Cell_Information_t *srvCellInfo)
2336 {
2337    uint8_t ieIdx, ieListCnt;
2338
2339    /*nRCGI*/
2340    srvCellInfo->nRCGI.pLMN_Identity.size =3*sizeof(uint8_t);
2341    DU_ALLOC(srvCellInfo->nRCGI.pLMN_Identity.buf,\
2342          srvCellInfo->nRCGI.pLMN_Identity.size);
2343    if(srvCellInfo->nRCGI.pLMN_Identity.buf == NULLP)
2344    {
2345       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2346       return RFAILED;
2347    }
2348    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2349          srvCellInfo->nRCGI.pLMN_Identity.buf);
2350    srvCellInfo->nRCGI.nRCellIdentity.size =5*sizeof(uint8_t);
2351    DU_ALLOC(srvCellInfo->nRCGI.nRCellIdentity.buf,\
2352          srvCellInfo->nRCGI.nRCellIdentity.size);
2353    if(srvCellInfo->nRCGI.nRCellIdentity.buf == NULLP)
2354    {   
2355       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2356       return RFAILED;
2357    }
2358    
2359    fillBitString(&srvCellInfo->nRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2360    /*nRPCI*/
2361    srvCellInfo->nRPCI = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
2362
2363    /*servedPLMNs*/
2364    ieListCnt = 1;
2365    srvCellInfo->servedPLMNs.list.count = ieListCnt;
2366    srvCellInfo->servedPLMNs.list.size = ieListCnt*sizeof(ServedPLMNs_Item_t *);
2367    DU_ALLOC(srvCellInfo->servedPLMNs.list.array, srvCellInfo->servedPLMNs.list.size);
2368    if(srvCellInfo->servedPLMNs.list.array == NULLP)
2369    {
2370       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2371       return RFAILED;
2372    }
2373    for(ieIdx=0; ieIdx < ieListCnt; ieIdx++)
2374    {
2375       DU_ALLOC(srvCellInfo->servedPLMNs.list.array[ieIdx], sizeof(ServedPLMNs_Item_t));
2376       if(srvCellInfo->servedPLMNs.list.array[ieIdx]== NULLP)
2377       {
2378          DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2379          return RFAILED;
2380       }
2381    }
2382    if(fillServedPlmns(&srvCellInfo->servedPLMNs))
2383    {
2384       DU_LOG("\nERROR  --> Failed to fill Served Plmn info");
2385       return RFAILED;
2386    }
2387
2388 #ifndef NR_TDD
2389    /*nR Mode Info with FDD*/
2390    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_fDD;
2391    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.fDD, sizeof(FDD_Info_t));
2392    if(srvCellInfo->nR_Mode_Info.choice.fDD == NULLP)
2393    {
2394       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2395       return RFAILED;
2396    }
2397    if(fillNrFddInfo(srvCellInfo->nR_Mode_Info.choice.fDD))
2398    {
2399        DU_LOG("\nERROR  --> Failed to fill the Nr FDD information");
2400       return RFAILED;
2401    }
2402 #else
2403    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_tDD;   
2404    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
2405    if(srvCellInfo->nR_Mode_Info.choice.tDD == NULLP)
2406    {
2407       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2408       return RFAILED;
2409    }
2410    if(fillNrTddInfo(srvCellInfo->nR_Mode_Info.choice.tDD) != ROK)
2411    {
2412       DU_LOG("\nERROR  --> Failed to fill the Nr TDD information");
2413       return RFAILED;
2414    }
2415 #endif
2416
2417    /*Measurement timing Config*/
2418    if(BuildMeasTimingConf(&srvCellInfo->measurementTimingConfiguration) != ROK)
2419       return RFAILED;
2420
2421    return ROK;
2422 }
2423
2424 /*******************************************************************
2425  *
2426  * @brief Fills ServCellToModItem IE
2427  *
2428  * @details
2429  *
2430  *    Function : fillServCellToModItem
2431  *
2432  *    Functionality: Fills ServCellToModItem IE
2433  *
2434  * @params[in] Pointer to Served_Cells_To_Modify_Item_t *
2435  *
2436  * @return ROK     - success
2437  *         RFAILED - failure
2438  *
2439  *****************************************************************/
2440
2441 uint8_t fillServCellToModItem(Served_Cells_To_Modify_Item_t *modifyItem)
2442 {
2443    /*pLMN_Identity*/
2444    modifyItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2445    DU_ALLOC(modifyItem->oldNRCGI.pLMN_Identity.buf,modifyItem->oldNRCGI.pLMN_Identity.size);
2446    if(modifyItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2447    {
2448       return RFAILED;
2449    }
2450    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2451          modifyItem->oldNRCGI.pLMN_Identity.buf);
2452
2453    /*nRCellIdentity*/
2454    modifyItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2455    DU_ALLOC(modifyItem->oldNRCGI.nRCellIdentity.buf,\
2456          modifyItem->oldNRCGI.nRCellIdentity.size);
2457    if(modifyItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2458    {
2459       return RFAILED;
2460    }
2461    fillBitString(&modifyItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2462
2463    if(fillServedCellInfo(&modifyItem->served_Cell_Information))
2464       return RFAILED;
2465    else
2466       return ROK;
2467 }
2468
2469 /*******************************************************************
2470  *
2471  * @brief Builds ServCellToModList
2472  *
2473  * @details
2474  *
2475  *    Function : buildServCellToModList
2476  *
2477  *    Functionality: Builds the serv cell to Mod List
2478  *
2479  * @params[in] Pointer to Served_Cells_To_Modify_List_t *
2480  *
2481  * @return ROK     - success
2482  *         RFAILED - failure
2483  *
2484  *****************************************************************/
2485
2486 uint8_t buildServCellToModList(Served_Cells_To_Modify_List_t *cellsToModify)
2487 {
2488    uint8_t ieListCnt, ieIdx;
2489    Served_Cells_To_Modify_Item_t *modifyItem = NULLP;
2490
2491    ieListCnt = 1;
2492    cellsToModify->list.count = ieListCnt;
2493    cellsToModify->list.size = ieListCnt*sizeof(Served_Cells_To_Modify_ItemIEs_t *);
2494    DU_ALLOC(cellsToModify->list.array,cellsToModify->list.size);
2495    if(cellsToModify->list.array == NULLP)
2496    {
2497       return RFAILED;
2498    }
2499    for(ieIdx=0; ieIdx< ieListCnt; ieIdx++)
2500    {
2501       DU_ALLOC(cellsToModify->list.array[ieIdx],sizeof(Served_Cells_To_Modify_ItemIEs_t));
2502       if(cellsToModify->list.array[ieIdx] == NULLP)
2503       {
2504          return RFAILED;
2505       }
2506    }
2507    cellsToModify->list.array[0]->id = ProtocolIE_ID_id_Served_Cells_To_Modify_Item;
2508    cellsToModify->list.array[0]->criticality = Criticality_reject;
2509    cellsToModify->list.array[0]->value.present =\
2510       Served_Cells_To_Modify_ItemIEs__value_PR_Served_Cells_To_Modify_Item;
2511    modifyItem=&cellsToModify->list.array[0]->value.choice.Served_Cells_To_Modify_Item;
2512
2513    if(fillServCellToModItem(modifyItem))
2514       return RFAILED;
2515    else
2516       return ROK;
2517 }
2518 /*******************************************************************
2519  *
2520  * @brief filling the DeleteItemList
2521  *
2522  * @details
2523  *
2524  *    Function : fillCellToDeleteItem 
2525  *
2526  *    Functionality: Filling the DeleteItemIe 
2527  *
2528  * @params[in] Pointer to Served_Cells_To_Delete_ItemIEs_t 
2529  *
2530  * @return ROK     - success
2531  *         RFAILED - failure
2532  *
2533  *****************************************************************/
2534 uint8_t fillCellToDeleteItem(struct Served_Cells_To_Delete_ItemIEs *deleteItemIe)
2535 {
2536    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
2537    
2538    deleteItemIe->id = ProtocolIE_ID_id_Served_Cells_To_Delete_Item;
2539    deleteItemIe->criticality = Criticality_reject;
2540    deleteItemIe->value.present =\
2541    Served_Cells_To_Delete_ItemIEs__value_PR_Served_Cells_To_Delete_Item;
2542    deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
2543
2544    /*pLMN_Identity*/
2545    deleteItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2546    DU_ALLOC(deleteItem->oldNRCGI.pLMN_Identity.buf,deleteItem->oldNRCGI.pLMN_Identity.size);
2547    if(deleteItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2548    {
2549       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2550       return RFAILED;
2551    }
2552    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2553          deleteItem->oldNRCGI.pLMN_Identity.buf);
2554
2555    /*nRCellIdentity*/
2556    deleteItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2557    DU_ALLOC(deleteItem->oldNRCGI.nRCellIdentity.buf,\
2558          deleteItem->oldNRCGI.nRCellIdentity.size);
2559    if(deleteItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2560    {
2561       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2562       return RFAILED;
2563    }
2564    fillBitString(&deleteItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2565    return ROK;
2566
2567
2568 /*******************************************************************
2569  *
2570  * @brief Builds ServCellToDeleteList
2571  *
2572  * @details
2573  *
2574  *    Function : buildServCellToDeleteList
2575  *
2576  *    Functionality: Builds the serv cell to delete List
2577  *
2578  * @params[in] Pointer to Served_Cells_To_Delete_List_t *
2579  *
2580  * @return ROK     - success
2581  *         RFAILED - failure
2582  *
2583  *****************************************************************/
2584  
2585 uint8_t buildServCellToDeleteList(Served_Cells_To_Delete_List_t *cellsToDelete)
2586 {
2587    uint8_t ieListCnt, arrIdx;
2588    
2589    ieListCnt = 1;
2590    cellsToDelete->list.count = ieListCnt;
2591    cellsToDelete->list.size = ieListCnt*sizeof(Served_Cells_To_Delete_ItemIEs_t *);
2592    
2593    DU_ALLOC(cellsToDelete->list.array,cellsToDelete->list.size);
2594    if(cellsToDelete->list.array == NULLP)
2595    {
2596       DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2597       return RFAILED;
2598    }
2599    
2600    for(arrIdx=0; arrIdx< ieListCnt; arrIdx++)
2601    {
2602       DU_ALLOC(cellsToDelete->list.array[arrIdx],sizeof(Served_Cells_To_Delete_ItemIEs_t));
2603       if(cellsToDelete->list.array[arrIdx] == NULLP)
2604       {
2605          DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2606          return RFAILED;
2607       }
2608    }
2609    
2610    arrIdx=0;
2611    if(fillCellToDeleteItem((Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx]) !=ROK)
2612    {
2613       DU_LOG("\nERROR  -->  F1AP: buildServCellToDeleteList(): failed to fill Served_Cells_To_Delete_ItemIEs");
2614       return RFAILED;
2615    }
2616    return ROK;
2617 }
2618
2619 /*******************************************************************
2620  *
2621  * @brief Builds CellsStatusList
2622  *
2623  * @details
2624  *
2625  *    Function : buildCellsStatusList
2626  *
2627  *    Functionality: Builds the Cell Status List
2628  *
2629  * @params[in] Pointer to Cells_Status_List_t *
2630  *
2631  * @return ROK     - success
2632  *         RFAILED - failure
2633  *
2634  *****************************************************************/
2635 uint8_t buildCellsStatusList(Cells_Status_List_t *cellStatusList)
2636 {
2637    uint8_t elementCnt = 0, idx = 0, ret = ROK;
2638    Cells_Status_ItemIEs_t *cellStatusItemIE;
2639
2640    elementCnt = 1;
2641    cellStatusList->list.count = elementCnt;
2642    cellStatusList->list.size = elementCnt * sizeof(Cells_Status_ItemIEs_t *);
2643    DU_ALLOC(cellStatusList->list.array, cellStatusList->list.size);
2644
2645    for(idx = 0; idx < elementCnt; idx++)
2646    {
2647       DU_ALLOC(cellStatusList->list.array[idx], sizeof(Cells_Status_ItemIEs_t));
2648       if(!cellStatusList->list.array[idx])
2649       {
2650          DU_LOG("ERROR  --> F1AP: buildCellsStatusList() memory allocation failure");
2651          return RFAILED;
2652       }
2653    }
2654    idx = 0;
2655    cellStatusItemIE = (Cells_Status_ItemIEs_t *)cellStatusList->list.array[idx];
2656    cellStatusItemIE->id = ProtocolIE_ID_id_Cells_Status_Item;
2657    cellStatusItemIE->criticality = Criticality_reject;
2658    cellStatusItemIE->value.present = Cells_Status_ItemIEs__value_PR_Cells_Status_Item;
2659    ret = BuildNrcgi(&cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI);
2660    if(ret == RFAILED)
2661    {
2662          DU_LOG("ERROR  --> F1AP: buildCellsStatusList() NRCGI failed");
2663          return RFAILED;
2664    }
2665    cellStatusItemIE->value.choice.Cells_Status_Item.service_status.service_state = Service_State_in_service;
2666    return ROK;
2667 }
2668
2669 /*******************************************************************
2670  *
2671  * @brief Builds and sends the DUConfigUpdate
2672  *
2673  * @details
2674  *
2675  *    Function : BuildAndSendDUConfigUpdate
2676  *
2677  *    Functionality: Constructs the DU Update message and sends
2678  *                   it to the CU through SCTP.
2679  *
2680  * @params[in] void **buf,Buffer to which encoded pattern is written into
2681  * @params[in] int *size,size of buffer
2682  *
2683  * @return ROK     - success
2684  *         RFAILED - failure
2685  *
2686  * ****************************************************************/
2687 uint8_t BuildAndSendDUConfigUpdate(ServCellAction servCellAction)
2688 {
2689    uint8_t ret =0, ieIdx=0, elementCnt=0;
2690    bool memAlloctionFailure = false;
2691    F1AP_PDU_t                 *f1apDuCfg = NULLP;
2692    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
2693    asn_enc_rval_t encRetVal;     /* Encoder return value */
2694    
2695    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2696    ret= RFAILED;
2697
2698    while(true)
2699    {
2700       DU_LOG("\nINFO   -->  F1AP : Building DU config update\n");
2701       /* Allocate the memory for F1DuCfg */
2702       DU_ALLOC(f1apDuCfg, sizeof(F1AP_PDU_t));
2703       if(f1apDuCfg == NULLP)
2704       {
2705          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2706          break;
2707       }
2708
2709       f1apDuCfg->present = F1AP_PDU_PR_initiatingMessage;
2710       DU_ALLOC(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2711       if(f1apDuCfg->choice.initiatingMessage == NULLP)
2712       {
2713          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2714          break;
2715       }
2716
2717       f1apDuCfg->choice.initiatingMessage->procedureCode = \
2718                                                            ProcedureCode_id_gNBDUConfigurationUpdate;
2719       f1apDuCfg->choice.initiatingMessage->criticality = Criticality_reject;
2720       f1apDuCfg->choice.initiatingMessage->value.present = \
2721                                                            InitiatingMessage__value_PR_GNBDUConfigurationUpdate;
2722       duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->value.\
2723                     choice.GNBDUConfigurationUpdate;
2724       elementCnt = 4;
2725       duCfgUpdate->protocolIEs.list.count = elementCnt;
2726       duCfgUpdate->protocolIEs.list.size = \
2727                                            elementCnt * sizeof(GNBDUConfigurationUpdateIEs_t*);
2728
2729       /* Initialize the F1Setup members */
2730       DU_ALLOC(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2731       if(duCfgUpdate->protocolIEs.list.array == NULLP)
2732       {
2733          DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2734          break;
2735       }
2736       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
2737       {
2738          DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx],sizeof(GNBDUConfigurationUpdateIEs_t));
2739          if(duCfgUpdate->protocolIEs.list.array[ieIdx] == NULLP)
2740          {
2741             DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2742             memAlloctionFailure = true;
2743             break;
2744          }
2745       }
2746       
2747       if(memAlloctionFailure == true)
2748       {
2749          break;
2750       }
2751       /*TransactionID*/
2752       ieIdx = 0;
2753       duCfgUpdate->protocolIEs.list.array[ieIdx]->id=ProtocolIE_ID_id_TransactionID;
2754       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
2755       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2756       GNBDUConfigurationUpdateIEs__value_PR_TransactionID;
2757       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = TRANS_ID;
2758       
2759       ieIdx++;
2760       if(servCellAction == SERV_CELL_TO_MODIFY)
2761       {
2762          /*Served Cell to Modify */
2763          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2764          ProtocolIE_ID_id_Served_Cells_To_Modify_List;
2765          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2766          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2767          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Modify_List;
2768          if(buildServCellToModList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2769                   Served_Cells_To_Modify_List))
2770          {
2771             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToModList");
2772             break;
2773          }
2774       }
2775       else
2776       {
2777          /*Served Cell to Delete */ 
2778          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2779          ProtocolIE_ID_id_Served_Cells_To_Delete_List;
2780          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2781          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2782          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Delete_List;
2783          if(buildServCellToDeleteList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2784          Served_Cells_To_Delete_List)!=ROK)
2785          {
2786             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToDeleteList");
2787             break;
2788          }
2789          
2790       }
2791       // TODO :GNB DU SYS INFO:MIB AND SIB1 INFORMATION TO BE BUILT AND FILLED HERE
2792       
2793       /*Cell Status List*/
2794       ieIdx++;
2795       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_Cells_Status_List;
2796       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2797       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2798            GNBDUConfigurationUpdateIEs__value_PR_Cells_Status_List;
2799       ret = buildCellsStatusList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List);
2800       if(ret == RFAILED)
2801       {
2802          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Cell Status List building failed");
2803          break;
2804       }
2805
2806       /*GNB DU ID */
2807       ieIdx++;
2808       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
2809       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2810       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2811       GNBDUConfigurationUpdateIEs__value_PR_GNB_DU_ID;
2812       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size = sizeof(uint8_t);
2813       DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
2814             duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
2815       if(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == NULLP)
2816       {
2817          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Memory allocation failed for GNB_DU_ID");
2818          break;
2819       }
2820       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] = duCfgParam.duId;
2821
2822       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apDuCfg);
2823
2824       /* Encode the DU Config Update type as APER */
2825       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
2826       encBufSize = 0;
2827       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apDuCfg, PrepFinalEncBuf, encBuf);
2828
2829       /* Checking encode results */
2830       if(encRetVal.encoded == ENCODE_FAIL)
2831       {
2832          DU_LOG("ERROR  -->  F1AP : Could not encode DUConfigUpdate structure (at %s)\n",\
2833                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2834          break;
2835       }
2836       else
2837       {
2838          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DUConfigUpdate\n");
2839 #ifdef DEBUG_ASN_PRINT
2840          for(ieIdx =0; ieIdx < encBufSize; ieIdx++)
2841          {
2842             printf("%x",encBuf[ieIdx]);
2843          }
2844 #endif
2845       }
2846       /* Sending msg */
2847       if(sendF1APMsg() != ROK)
2848       {
2849          DU_LOG("\nERROR  -->  F1AP : Sending GNB-DU Config Update failed");
2850          break;
2851       }
2852
2853       ret = ROK;
2854       break;
2855    }
2856   
2857    addToReservedF1apPduList(TRANS_ID,f1apDuCfg);
2858    return ret;
2859 }
2860
2861
2862 /*******************************************************************
2863  *
2864  * @brief free the ULRRCMessageTransfer
2865  *
2866  * @details
2867  *
2868  *    Function : FreeULRRCMessageTransfer
2869  *
2870  *    Functionality: Deallocating the memory of variable allocated in
2871  *                      FreeULRRCMessageTransfer
2872  *
2873  * @params[in]
2874  *
2875  * @return ROK     - void
2876  *
2877  ******************************************************************/
2878 void FreeULRRCMessageTransfer( F1AP_PDU_t *f1apMsg)
2879 {
2880    uint8_t idx1;
2881    ULRRCMessageTransfer_t  *ulRRCMsg;
2882
2883    if(f1apMsg != NULLP)
2884    { 
2885       if(f1apMsg->choice.initiatingMessage != NULLP)
2886       {
2887          ulRRCMsg = &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2888          if(ulRRCMsg->protocolIEs.list.array != NULLP)
2889          {
2890             for(idx1=0;idx1<ulRRCMsg->protocolIEs.list.count;idx1++)
2891             {
2892                if(ulRRCMsg->protocolIEs.list.array[idx1] != NULLP)
2893                {
2894                   if(ulRRCMsg->protocolIEs.list.array[idx1]->value.present ==
2895                         ULRRCMessageTransferIEs__value_PR_RRCContainer)
2896                   {
2897                      DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2898                            ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2899                   }
2900                   DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1],sizeof(ULRRCMessageTransferIEs_t));
2901                }
2902             }
2903             DU_FREE(ulRRCMsg->protocolIEs.list.array,ulRRCMsg->protocolIEs.list.size );
2904          }
2905          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2906       }
2907       DU_FREE(f1apMsg,sizeof(F1AP_PDU_t));
2908    }
2909 }
2910 /*******************************************************************
2911  *
2912  * @brief Builds and sends the ULRRCMessageTransfer 
2913  *
2914  * @details
2915  *
2916  *    Function : BuildAndSendULRRCMessageTransfer
2917  *
2918  *    Functionality: Constructs the UL RRC Message Transfer and sends
2919  *                   it to the CU through SCTP.
2920  *
2921  * @params[in] 
2922  *
2923  * @return ROK     - success
2924  *         RFAILED - failure
2925  *
2926  * ****************************************************************/
2927 uint8_t BuildAndSendULRRCMessageTransfer(DuUeCb  *ueCb, uint8_t lcId, \
2928       uint16_t msgLen, uint8_t *rrcMsg)
2929 {
2930    uint8_t                 elementCnt=0, idx1=0, idx=0;
2931    uint8_t                 ret = RFAILED;
2932    F1AP_PDU_t              *f1apMsg = NULLP;
2933    ULRRCMessageTransfer_t  *ulRRCMsg = NULLP;
2934    asn_enc_rval_t          encRetVal;        /* Encoder return value */
2935    
2936    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2937
2938    while(true)
2939    {
2940       DU_LOG("\nINFO   -->  F1AP : Building UL RRC Message Transfer Message\n");
2941
2942       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
2943       if(f1apMsg == NULLP)
2944       {
2945          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
2946          break;
2947       }
2948       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
2949       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2950       if(f1apMsg->choice.initiatingMessage == NULLP)
2951       {
2952          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
2953          break;
2954       }
2955       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_ULRRCMessageTransfer;
2956       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
2957       f1apMsg->choice.initiatingMessage->value.present = \
2958                                                          InitiatingMessage__value_PR_ULRRCMessageTransfer;
2959       ulRRCMsg =
2960          &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2961       elementCnt = 4;
2962       ulRRCMsg->protocolIEs.list.count = elementCnt;
2963       ulRRCMsg->protocolIEs.list.size = \
2964                                         elementCnt * sizeof(ULRRCMessageTransferIEs_t *);
2965
2966       /* Initialize the F1Setup members */
2967       DU_ALLOC(ulRRCMsg->protocolIEs.list.array, ulRRCMsg->protocolIEs.list.size);
2968       if(ulRRCMsg->protocolIEs.list.array == NULLP)
2969       {
2970          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UL RRC MessageTransferIEs failed");
2971          break;
2972       }
2973       for(idx=0; idx<elementCnt; idx++)
2974       {
2975          DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx],sizeof(ULRRCMessageTransferIEs_t));
2976          if(ulRRCMsg->protocolIEs.list.array[idx] == NULLP)
2977          {
2978             break;
2979          }
2980       }
2981
2982       idx1 = 0;
2983
2984       /*GNB CU UE F1AP ID*/
2985       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
2986       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2987       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2988                                                               ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
2989       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
2990
2991       /*GNB DU UE F1AP ID*/
2992       idx1++;
2993       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
2994       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2995       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2996                                                               ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
2997       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
2998
2999       /*SRBID*/
3000       idx1++;
3001       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
3002       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
3003       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
3004                                                               ULRRCMessageTransferIEs__value_PR_SRBID;
3005       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.SRBID = lcId;
3006
3007       /*RRCContainer*/
3008       idx1++;
3009       ulRRCMsg->protocolIEs.list.array[idx1]->id  = ProtocolIE_ID_id_RRCContainer;
3010       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
3011       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
3012                                                               ULRRCMessageTransferIEs__value_PR_RRCContainer;
3013       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size = msgLen;
3014       DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
3015             ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size)
3016       if(!ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf)
3017       {
3018          DU_LOG(" ERROR  -->  F1AP : Memory allocation for BuildAndSendULRRCMessageTransfer failed");
3019          break;
3020       }
3021       memset(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, 0, msgLen);
3022       memcpy(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, \
3023             rrcMsg, ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
3024
3025       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
3026
3027       /* Encode the F1SetupRequest type as APER */
3028       memset(encBuf, 0, ENC_BUF_MAX_LEN);
3029       encBufSize = 0;
3030       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
3031             encBuf);
3032       /* Encode results */
3033       if(encRetVal.encoded == ENCODE_FAIL)
3034       {
3035          DU_LOG( "\nERROR  -->  F1AP : Could not encode ULRRCMessageTransfer structure (at %s)\n",\
3036                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
3037          break;
3038       }
3039       else
3040       {
3041          DU_LOG("\nDEBUG  -->  F1AP : Created APER encoded buffer for ULRRCMessageTransfer\n");
3042 #ifdef DEBUG_ASN_PRINT
3043          for(int i=0; i< encBufSize; i++)
3044          {
3045             printf("%x",encBuf[i]);
3046          }
3047 #endif
3048       }
3049
3050       /* Sending  msg  */
3051       if(sendF1APMsg()  !=      ROK)
3052       {
3053          DU_LOG("\nERROR  -->   F1AP : Sending  UL RRC Message Transfer Failed");
3054          break;
3055       }
3056       ret = ROK;
3057       break;
3058    }
3059    FreeULRRCMessageTransfer(f1apMsg);
3060
3061    return ret;
3062 }/* End of BuildAndSendULRRCMessageTransfer*/
3063
3064 /*******************************************************************
3065  *
3066  * @brief Builds tag config 
3067  *
3068  * @details
3069  *
3070  *    Function : BuildTagConfig 
3071  *
3072  *    Functionality: Builds tag config in MacCellGroupConfig
3073  *
3074  * @params[in] TAG_Config *tag_Config
3075  *
3076  * @return ROK     - success
3077  *         RFAILED - failure
3078  *
3079  * ****************************************************************/
3080 uint8_t BuildTagConfig(DuUeCb *ueCb, struct TAG_Config *tagConfig)
3081 {
3082    struct TAG_Config__tag_ToAddModList *tagList;
3083    uint8_t                     idx, elementCnt;
3084
3085    tagConfig->tag_ToReleaseList = NULLP;
3086    tagConfig->tag_ToAddModList = NULLP;
3087    DU_ALLOC(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
3088    if(!tagConfig->tag_ToAddModList)
3089    {
3090       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3091       return RFAILED;
3092    }
3093
3094    if(ueCb == NULLP)
3095       elementCnt = ODU_VALUE_ONE;
3096    else
3097       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModListCount;
3098
3099    tagList = tagConfig->tag_ToAddModList;
3100    tagList->list.count = elementCnt;
3101    tagList->list.size  =  elementCnt * sizeof(struct TAG *);
3102
3103    tagList->list.array = NULLP;
3104    DU_ALLOC(tagList->list.array, tagList->list.size);
3105    if(!tagList->list.array)
3106    {
3107       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3108       return RFAILED;
3109    }
3110
3111    for(idx=0; idx<tagList->list.count; idx++)
3112    {
3113       tagList->list.array[idx] = NULLP;
3114       DU_ALLOC(tagList->list.array[idx], sizeof(struct TAG));
3115       if(!tagList->list.array[idx])
3116       {
3117          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3118          return RFAILED;
3119       }
3120    }
3121
3122    if(ueCb == NULLP)
3123    {
3124       idx = 0;
3125       tagList->list.array[idx]->tag_Id = TAG_ID;
3126       tagList->list.array[idx]->timeAlignmentTimer = TIME_ALIGNMENT_TMR;
3127    }
3128    else
3129    {
3130       for(idx=0; idx<tagList->list.count; idx++)
3131       {
3132          tagList->list.array[idx]->tag_Id = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].tagId;
3133          tagList->list.array[idx]->timeAlignmentTimer = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].timeAlignTimer;
3134       }
3135    }
3136
3137    return ROK;
3138 }
3139
3140 /*******************************************************************
3141  *
3142  * @brief Builds PHR Config 
3143  *
3144  * @details
3145  *
3146  *    Function : BuildPhrConfig
3147  *
3148  *    Functionality: Builds phrConfig in MacCellGroupConfig
3149  *
3150  * @params[in] PHR Config *
3151  *
3152  * @return ROK     - success
3153  *         RFAILED - failure
3154  *
3155  * ****************************************************************/
3156 uint8_t BuildPhrConfig(DuUeCb *ueCb, struct MAC_CellGroupConfig__phr_Config *phrConfig)
3157 {
3158
3159    phrConfig->present = MAC_CellGroupConfig__phr_Config_PR_setup;
3160    phrConfig->choice.setup = NULLP;
3161    DU_ALLOC(phrConfig->choice.setup, sizeof(struct PHR_Config));
3162    if(!phrConfig->choice.setup)
3163    {
3164       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhrConfig");
3165       return RFAILED;
3166    }
3167
3168    if(ueCb == NULLP)
3169    {
3170       phrConfig->choice.setup->phr_PeriodicTimer        = PHR_PERIODIC_TMR;
3171       phrConfig->choice.setup->phr_ProhibitTimer        = PHR_PROHIBHIT_TMR;
3172       phrConfig->choice.setup->phr_Tx_PowerFactorChange = PHR_PWR_FACTOR_CHANGE;
3173       phrConfig->choice.setup->multiplePHR              = false;
3174       phrConfig->choice.setup->dummy                    = false;
3175       phrConfig->choice.setup->phr_Type2OtherCell       = false;
3176       phrConfig->choice.setup->phr_ModeOtherCG          = PHR_MODE_OTHER_CG;
3177    }
3178    else
3179    {
3180       phrConfig->choice.setup->phr_PeriodicTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.periodicTimer;
3181       phrConfig->choice.setup->phr_ProhibitTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.prohibitTimer;
3182       phrConfig->choice.setup->phr_Tx_PowerFactorChange = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.txPowerFactor;
3183       phrConfig->choice.setup->multiplePHR              = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.multiplePHR;
3184       phrConfig->choice.setup->dummy                    = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.dummy;
3185       phrConfig->choice.setup->phr_Type2OtherCell       = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrType2OtherCell;
3186       phrConfig->choice.setup->phr_ModeOtherCG          = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrOtherCG;
3187    }
3188
3189    return ROK;
3190 }
3191
3192 /*******************************************************************
3193  *
3194  * @brief Builds BSR Config 
3195  *
3196  * @details
3197  *
3198  *    Function : BuildBsrConfig
3199  *
3200  *    Functionality: Builds BuildBsrConfig in MacCellGroupConfig
3201  *
3202  * @params[in] BSR_Config *bsrConfig
3203  *
3204  * @return ROK     - success
3205  *         RFAILED - failure
3206  *
3207  * ****************************************************************/
3208 uint8_t BuildBsrConfig(DuUeCb *ueCb, struct BSR_Config *bsrConfig)
3209 {
3210    if(ueCb == NULLP)
3211    {
3212       bsrConfig->periodicBSR_Timer = PERIODIC_BSR_TMR;
3213       bsrConfig->retxBSR_Timer     = RETX_BSR_TMR;
3214       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
3215    }
3216    else
3217    {
3218       bsrConfig->periodicBSR_Timer = convertBsrPeriodicTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.periodicTimer);
3219       bsrConfig->retxBSR_Timer     = convertBsrRetxTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.retxTimer);
3220
3221       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
3222       DU_ALLOC(bsrConfig->logicalChannelSR_DelayTimer, sizeof(long));
3223       if(bsrConfig->logicalChannelSR_DelayTimer == NULLP)
3224       {
3225          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildBsrConfig");
3226          return RFAILED;
3227       }
3228       *(bsrConfig->logicalChannelSR_DelayTimer) = convertLcSrDelayTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.srDelayTimer);
3229    }
3230
3231    return ROK;
3232 }
3233
3234 /*******************************************************************
3235  *
3236  * @brief Builds scheduling request config 
3237  *
3238  * @details
3239  *
3240  *    Function : BuildSchedulingReqConfig 
3241  *
3242  *    Functionality: Builds BuildSchedulingReqConfig in MacCellGroupConfig
3243  *
3244  * @params[in] SchedulingRequestConfig *schedulingRequestConfig
3245  *
3246  * @return ROK     - success
3247  *         RFAILED - failure
3248  *
3249  * ****************************************************************/
3250 uint8_t BuildSchedulingReqConfig(DuUeCb *ueCb, struct SchedulingRequestConfig *schedulingRequestConfig)
3251 {
3252    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList;
3253    uint8_t                     idx, elementCnt;
3254
3255    schedulingRequestConfig->schedulingRequestToAddModList = NULLP;
3256    DU_ALLOC(schedulingRequestConfig->schedulingRequestToAddModList,
3257          sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));
3258    if(!schedulingRequestConfig->schedulingRequestToAddModList)
3259    {
3260       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3261       return RFAILED;
3262    }
3263
3264    if(ueCb == NULLP)
3265       elementCnt = ODU_VALUE_ONE;
3266    else
3267       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModListCount;
3268
3269    schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
3270    schReqList->list.count = elementCnt;
3271    schReqList->list.size  = elementCnt * sizeof(struct SchedulingRequestToAddMod *);
3272
3273    schReqList->list.array = NULLP;
3274    DU_ALLOC(schReqList->list.array, schReqList->list.size);
3275    if(!schReqList->list.array)
3276    {
3277       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3278       return RFAILED;
3279    }
3280
3281    for(idx=0; idx<schReqList->list.count; idx++)
3282    {
3283       schReqList->list.array[idx] = NULLP;
3284       DU_ALLOC(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
3285       if(!schReqList->list.array[idx])
3286       {
3287          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3288          return RFAILED;
3289       }
3290    }
3291
3292    if(ueCb == NULLP)
3293    {
3294       idx = 0;
3295       schReqList->list.array[idx]->schedulingRequestId = SCH_REQ_ID;
3296
3297       schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
3298       DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
3299       if(!schReqList->list.array[idx]->sr_ProhibitTimer)
3300       {
3301          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3302          return RFAILED;
3303       }
3304       *(schReqList->list.array[idx]->sr_ProhibitTimer) = SR_PROHIBIT_TMR;
3305       schReqList->list.array[idx]->sr_TransMax = SR_TRANS_MAX;
3306    }
3307    else
3308    {
3309       for(idx=0; idx<schReqList->list.count; idx++)
3310       {
3311          schReqList->list.array[idx]->schedulingRequestId = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].schedReqId;
3312
3313          schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
3314          DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
3315          if(!schReqList->list.array[idx]->sr_ProhibitTimer)
3316          {
3317             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3318             return RFAILED;
3319          }
3320          *(schReqList->list.array[idx]->sr_ProhibitTimer) = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srProhibitTmr;
3321          schReqList->list.array[idx]->sr_TransMax = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srTransMax;
3322       }
3323    }
3324
3325    schedulingRequestConfig->schedulingRequestToReleaseList = NULLP;
3326
3327    return ROK;
3328 }
3329
3330 /*******************************************************************
3331  *
3332  * @brief Builds RLC Configuration for AM mode
3333  *
3334  * @details
3335  *
3336  *    Function : BuildRlcConfigAm
3337  *
3338  *    Functionality: 
3339  *       Builds AM mode RLC Config in BuildRlcBearerToAddModList
3340  *
3341  * @params[in] AmBearerCfg *amCfg
3342  *             RLC_Config_t  *rlcConfig
3343  *
3344  * @return ROK     - success
3345  *         RFAILED - failure
3346  *
3347  * ****************************************************************/
3348 uint8_t BuildRlcConfigAm(AmBearerCfg *amCfg, struct RLC_Config *rlcConfig)
3349 {
3350    rlcConfig->choice.am = NULLP;
3351    DU_ALLOC(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
3352    if(!rlcConfig->choice.am)
3353    {
3354       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3355       return RFAILED;
3356    }
3357
3358    /* Fill AM UL configuration */
3359    rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength = NULLP;
3360    DU_ALLOC(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
3361    if(!rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength)
3362    {
3363       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3364       return RFAILED;
3365    }
3366
3367    /* Fill default AM UL configuration if input pointer to DU database is NULL */
3368    if(amCfg == NULLP)
3369    {
3370       
3371       *(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"*/
3372       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = T_POLL_RETRANSMIT;
3373       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = POLL_PDU;
3374       rlcConfig->choice.am->ul_AM_RLC.pollByte          = POLL_BYTE;
3375       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = MAX_RETX_THRESHOLD;
3376    }
3377    else
3378    {
3379       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->dlAmCfg.snLenDl);
3380       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = covertPollRetxTmrValueToEnum(amCfg->dlAmCfg.pollRetxTmr);
3381       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = covertPollPduValueToEnum(amCfg->dlAmCfg.pollPdu);
3382       rlcConfig->choice.am->ul_AM_RLC.pollByte          = covertPollByteValueToEnum(amCfg->dlAmCfg.pollByte);
3383       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = covertMaxRetxValueToEnum(amCfg->dlAmCfg.maxRetxTh);
3384    }
3385
3386    /* Fill AM DL configuraion */
3387    rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength = NULLP;
3388    DU_ALLOC(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
3389    if(!rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength)
3390    {
3391       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3392       return RFAILED;
3393    }
3394
3395    /* Fill default AM DL configuration if input pointer to DU database is NULL */
3396    if(amCfg == NULLP)
3397    {
3398       *(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"*/
3399       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = T_REASSEMBLY;
3400       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = T_STATUS_PROHIBHIT;
3401    }
3402    else /* Fill AM configuration from DU database */
3403    {
3404       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->ulAmCfg.snLenUl);
3405       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = convertReasmblTmrValueToEnum(amCfg->ulAmCfg.reAssemTmr);
3406       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = convertProhibitTmrValueToEnum(amCfg->ulAmCfg.statProhTmr);
3407    }
3408    return ROK;
3409 }
3410
3411 /*******************************************************************
3412  *
3413  * @brief Builds RLC Config for UM Bidirection
3414  *
3415  * @details
3416  *
3417  *    Function : BuildRlcConfig UmBiDir
3418  *
3419  *    Functionality: 
3420  *       Builds RLC Config for UM Bidirection in BuildRlcBearerToAddModList 
3421  *
3422  * @params[in] UmBiDirBearerCfg *umBiDirCfg
3423  *             RLC_Config_t *rlcConfig
3424  *
3425  * @return ROK     - success
3426  *         RFAILED - failure
3427  *
3428  * ****************************************************************/
3429 uint8_t BuildRlcConfigUmBiDir(UmBiDirBearerCfg *umBiDirCfg, struct RLC_Config *rlcConfig)
3430 {
3431    rlcConfig->choice.um_Bi_Directional = NULLP;
3432    DU_ALLOC(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
3433    if(rlcConfig->choice.um_Bi_Directional == NULLP)
3434    {
3435       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3436       return RFAILED;
3437    }
3438
3439    /* Fill UM Bidirectional UL configuration */
3440    rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength = NULLP;
3441    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3442    if(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength == NULLP)
3443    {
3444       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3445       return RFAILED;
3446    }
3447
3448    if(umBiDirCfg != NULLP)
3449    {
3450       *(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->dlUmCfg.snLenDlUm);     
3451    }
3452
3453    /* Fill UM Bidirectional DL configuration */
3454    rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength = NULLP;
3455    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3456    if(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength == NULLP)
3457    {
3458       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3459       return RFAILED;
3460    }
3461
3462    if(umBiDirCfg != NULLP)
3463    {
3464       *(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->ulUmCfg.snLenUlUm);     
3465       rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umBiDirCfg->ulUmCfg.reAssemTmr);
3466    }
3467
3468    return ROK;
3469 }
3470
3471 /*******************************************************************
3472  *
3473  * @brief Builds RLC Config for UM Uni directional UL
3474  *
3475  * @details
3476  *
3477  *    Function : BuildRlcConfigUmUniDirUl
3478  *
3479  *    Functionality: 
3480  *       Builds RLC Config for UM Unidirection UL in BuildRlcBearerToAddModList 
3481  *
3482  * @params[in] UmUniDirDlBearerCfg *umUniDirDlCfg
3483  *             RLC_Config_t *rlcConfig
3484  *
3485  * @return ROK     - success
3486  *         RFAILED - failure
3487  *
3488  * ****************************************************************/
3489 uint8_t BuildRlcConfigUmUniDirUl(UmUniDirDlBearerCfg *umUniDirDlCfg, RLC_Config_t *rlcConfig)
3490 {
3491    rlcConfig->choice.um_Uni_Directional_UL = NULLP;
3492    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
3493    if(rlcConfig->choice.um_Uni_Directional_UL == NULLP)
3494    {
3495       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3496       return RFAILED;
3497    }
3498
3499    rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength = NULLP;
3500    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3501    if(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength == NULLP)
3502    {
3503       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3504       return RFAILED;
3505    }
3506
3507    if(umUniDirDlCfg != NULLP)
3508    {
3509       *(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirDlCfg->dlUmCfg.snLenDlUm);
3510    }
3511
3512    return ROK;
3513 }
3514
3515 /*******************************************************************
3516  *
3517  * @brief Builds RLC Config for UM Uni directional DL
3518  *
3519  * @details
3520  *
3521  *    Function : BuildRlcConfigUmUniDirDl
3522  *
3523  *    Functionality: 
3524  *       Builds RLC Config for UM Unidirection DL in BuildRlcBearerToAddModList 
3525  *
3526  * @params[in] UmUniDirUlBearerCfg *umUniDirUlCfg
3527  *             RLC_Config_t *rlcConfig
3528  *
3529  * @return ROK     - success
3530  *         RFAILED - failure
3531  *
3532  * ****************************************************************/
3533 uint8_t BuildRlcConfigUmUniDirDl(UmUniDirUlBearerCfg *umUniDirUlCfg, RLC_Config_t *rlcConfig)
3534 {
3535    rlcConfig->choice.um_Uni_Directional_DL = NULLP;
3536    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
3537    if(rlcConfig->choice.um_Uni_Directional_DL == NULLP)
3538    {
3539       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3540       return RFAILED;
3541    }
3542
3543    rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength = NULLP;
3544    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3545    if(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength == NULLP)
3546    {
3547       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3548       return RFAILED;
3549    }
3550
3551    if(umUniDirUlCfg != NULLP)
3552    {
3553       *(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirUlCfg->ulUmCfg.snLenUlUm);
3554       rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umUniDirUlCfg->ulUmCfg.reAssemTmr);
3555    }
3556
3557    return ROK;
3558 }
3559
3560 /*******************************************************************
3561  *
3562  * @brief Builds RLC Config
3563  *
3564  * @details
3565  *
3566  *    Function : BuildRlcConfig
3567  *
3568  *    Functionality: Builds RLC Config in BuildRlcBearerToAddModList 
3569  *
3570  * @params[in] RLC_Config_t *rlcConfig
3571  *
3572  * @return ROK     - success
3573  *         RFAILED - failure
3574  *
3575  * ****************************************************************/
3576 uint8_t BuildRlcConfig(RlcBearerCfg *rbCfg, struct RLC_Config *rlcConfig)
3577 {
3578    
3579    /* Fill default values if rbCfg is NULL */
3580    if(rbCfg == NULLP)
3581    {
3582       rlcConfig->present = RLC_Config_PR_am;
3583       BuildRlcConfigAm(NULLP, rlcConfig);
3584    }
3585    /* If RbCfg is present, fill RLC configurations from DU Database */
3586    else
3587    {
3588       rlcConfig->present = covertRlcModeFromIntEnumToRrcEnum(rbCfg->rlcMode);
3589       switch(rlcConfig->present)
3590       {
3591          case RLC_Config_PR_am:
3592             BuildRlcConfigAm(rbCfg->u.amCfg, rlcConfig);
3593             break;
3594          case RLC_Config_PR_um_Bi_Directional:
3595             BuildRlcConfigUmBiDir(rbCfg->u.umBiDirCfg, rlcConfig);
3596             break;
3597          case RLC_Config_PR_um_Uni_Directional_UL:
3598             BuildRlcConfigUmUniDirUl(rbCfg->u.umUniDirDlCfg, rlcConfig);
3599             break;
3600          case RLC_Config_PR_um_Uni_Directional_DL:
3601             BuildRlcConfigUmUniDirDl(rbCfg->u.umUniDirUlCfg, rlcConfig);
3602             break;
3603          case RLC_Config_PR_NOTHING:
3604          default:
3605             break;
3606       }
3607    }
3608
3609    return ROK;
3610 }
3611
3612 /*******************************************************************
3613  *
3614  * @brief Builds MAC LC Config
3615  *
3616  * @details
3617  *
3618  *    Function : BuildMacLCConfig 
3619  *
3620  *    Functionality: Builds MAC LC Config in BuildRlcBearerToAddModList 
3621  *
3622  * @params[in] struct LogicalChannelConfig macLcConfig
3623  *
3624  * @return ROK     - success
3625  *         RFAILED - failure
3626  *
3627  * ****************************************************************/
3628 uint8_t BuildMacLCConfig(LcCfg *lcCfgDb, struct LogicalChannelConfig *macLcConfig)
3629 {
3630    macLcConfig->ul_SpecificParameters = NULLP;
3631    DU_ALLOC(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
3632    if(!macLcConfig->ul_SpecificParameters)
3633    {
3634       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3635       return RFAILED;
3636    }
3637
3638    if(lcCfgDb == NULLP)
3639    {
3640       macLcConfig->ul_SpecificParameters->priority = MAC_LC_PRIORITY;
3641       macLcConfig->ul_SpecificParameters->prioritisedBitRate =  PRIORTISIED_BIT_RATE;
3642       macLcConfig->ul_SpecificParameters->bucketSizeDuration =  BUCKET_SIZE_DURATION;
3643    }
3644    else
3645    {
3646       macLcConfig->ul_SpecificParameters->priority = lcCfgDb->ulLcCfg.priority;
3647       macLcConfig->ul_SpecificParameters->prioritisedBitRate = lcCfgDb->ulLcCfg.pbr;
3648       macLcConfig->ul_SpecificParameters->bucketSizeDuration = lcCfgDb->ulLcCfg.bsd;
3649    }
3650
3651    macLcConfig->ul_SpecificParameters->allowedServingCells = NULLP;
3652    macLcConfig->ul_SpecificParameters->allowedSCS_List = NULLP;
3653    macLcConfig->ul_SpecificParameters->maxPUSCH_Duration = NULLP;
3654    macLcConfig->ul_SpecificParameters->configuredGrantType1Allowed = NULLP;
3655
3656    macLcConfig->ul_SpecificParameters->logicalChannelGroup = NULLP;
3657    DU_ALLOC(macLcConfig->ul_SpecificParameters->logicalChannelGroup,    sizeof(long));
3658    if(!macLcConfig->ul_SpecificParameters->logicalChannelGroup)
3659    {
3660       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3661       return RFAILED;
3662    }
3663
3664    if(lcCfgDb == NULLP)
3665       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = LC_GRP;
3666    else
3667       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = lcCfgDb->ulLcCfg.lcGroup;
3668
3669    macLcConfig->ul_SpecificParameters->schedulingRequestID = NULLP;
3670    DU_ALLOC(macLcConfig->ul_SpecificParameters->schedulingRequestID,    sizeof(SchedulingRequestId_t));
3671    if(!macLcConfig->ul_SpecificParameters->schedulingRequestID)
3672    {
3673       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3674       return RFAILED;
3675    }
3676
3677    if(lcCfgDb == NULLP)
3678       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = SCH_REQ_ID;
3679    else
3680       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = lcCfgDb->ulLcCfg.schReqId;
3681
3682    macLcConfig->ul_SpecificParameters->logicalChannelSR_Mask = false;
3683    macLcConfig->ul_SpecificParameters->logicalChannelSR_DelayTimerApplied = false;
3684    macLcConfig->ul_SpecificParameters->bitRateQueryProhibitTimer = NULLP;
3685
3686    return ROK;
3687 }
3688
3689 /*******************************************************************
3690  *
3691  * @brief Builds RLC Bearer to Add/Mod list
3692  *
3693  * @details
3694  *
3695  *    Function :BuildRlcBearerToAddModList 
3696  *
3697  *    Functionality: Builds RLC Bearer to Add/Mod list in DuToCuRrcContainer
3698  *
3699  * @params[in] rlc_BearerToAddModList
3700  *
3701  * @return ROK     - success
3702  *         RFAILED - failure
3703  *
3704  * ****************************************************************/
3705 uint8_t BuildRlcBearerToAddModList(DuUeCb *ueCb, struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList)
3706 {
3707    uint8_t  idx = 0, lcIdx=0, macLcIdx = 0, elementCnt = 0;
3708
3709    if(ueCb == NULLP)
3710       elementCnt = 1;
3711    else if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
3712       elementCnt = ueCb->duRlcUeCfg.numLcs;
3713    else
3714    {
3715       for(lcIdx = 0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3716       {
3717          if(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == false)
3718             elementCnt++;
3719       }
3720    }
3721    rlcBearerList->list.count = elementCnt;
3722    rlcBearerList->list.size  = elementCnt * sizeof(struct RLC_BearerConfig *);
3723
3724    rlcBearerList->list.array = NULLP;
3725    DU_ALLOC(rlcBearerList->list.array, rlcBearerList->list.size);
3726    if(!rlcBearerList->list.array)
3727    {
3728       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3729       return RFAILED;
3730    }
3731
3732    for(idx=0; idx<rlcBearerList->list.count; idx++)
3733    {
3734       rlcBearerList->list.array[idx] = NULLP;
3735       DU_ALLOC(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
3736       if(!rlcBearerList->list.array[idx])
3737       {
3738          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3739          return RFAILED;
3740       }
3741    }
3742
3743    if(ueCb == NULLP)
3744    {
3745       idx=0;
3746       rlcBearerList->list.array[idx]->logicalChannelIdentity = SRB1_LCID;
3747       DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3748       if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3749       {     
3750          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3751          return RFAILED;
3752       }     
3753       rlcBearerList->list.array[idx]->servedRadioBearer->present = RLC_BearerConfig__servedRadioBearer_PR_srb_Identity;
3754       rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = SRB1_LCID;
3755       rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3756
3757       /* Fill RLC related Configurations for this Radio Bearer */
3758       rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3759       DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3760       if(!rlcBearerList->list.array[idx]->rlc_Config)
3761       {
3762          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3763          return RFAILED;
3764       }
3765       if(BuildRlcConfig(NULLP, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3766       {
3767          DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3768          return RFAILED;
3769       }
3770
3771       /* Fill MAC related configurations for this Radio Bearer */
3772       rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3773       DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3774       if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3775       {
3776          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3777          return RFAILED;
3778       }
3779       if(BuildMacLCConfig(NULLP, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3780       {
3781          DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3782          return RFAILED;
3783       }
3784    }
3785    else
3786    {
3787       idx=0;
3788       for(lcIdx=0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3789       {
3790          if((ueCb->f1UeDb->actionType != UE_CTXT_CFG_QUERY) && (ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == true))
3791             continue;
3792
3793          /* Fill Logical channel identity */
3794          rlcBearerList->list.array[idx]->logicalChannelIdentity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId;
3795
3796          /* Fill Radio Bearer Id and type (DRB/SRB) for this logical channel */
3797          DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3798          if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3799          {
3800             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3801             return RFAILED;
3802          }
3803          rlcBearerList->list.array[idx]->servedRadioBearer->present = \
3804                                                                       covertRbTypeFromIntEnumToRrcEnum(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbType);
3805          switch(rlcBearerList->list.array[idx]->servedRadioBearer->present)
3806          {
3807             case RLC_BearerConfig__servedRadioBearer_PR_srb_Identity: 
3808                rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3809                break;
3810             case RLC_BearerConfig__servedRadioBearer_PR_drb_Identity:
3811                rlcBearerList->list.array[idx]->servedRadioBearer->choice.drb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3812                break;
3813             case RLC_BearerConfig__servedRadioBearer_PR_NOTHING:
3814             default:
3815                break;
3816          }
3817          ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent = true;
3818
3819          rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3820
3821          /* Fill RLC related Configurations for this Radio Bearer */
3822          rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3823          DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3824          if(!rlcBearerList->list.array[idx]->rlc_Config)
3825          {
3826             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3827             return RFAILED;
3828          }
3829          if(BuildRlcConfig(&ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3830          {
3831             DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3832             return RFAILED;
3833          }
3834
3835          /* Fill MAC related configurations for this Radio Bearer */
3836          rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3837          DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3838          if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3839          {
3840             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3841             return RFAILED;
3842          }
3843          for(macLcIdx = 0; macLcIdx < ueCb->duMacUeCfg.numLcs; macLcIdx++)
3844          {
3845             if(ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig.lcId == ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId)
3846             {
3847                if(BuildMacLCConfig(&ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3848                {
3849                   DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3850                   return RFAILED;
3851                }
3852                break;
3853             }
3854          }
3855
3856          idx++;
3857       }
3858    }
3859    return ROK;
3860 }
3861
3862 /*******************************************************************
3863  *
3864  * @brief Build Control resource set to add/modify list 
3865  *
3866  * @details
3867  *
3868  *    Function : BuildControlRSetToAddModList
3869  *
3870  *    Functionality: Build Control resource set to add/modify list
3871  *
3872  * @params[in] 
3873  * struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList
3874  *
3875  * @return ROK     - success
3876  *         RFAILED - failure
3877  *
3878  * ****************************************************************/
3879 uint8_t BuildControlRSetToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList)
3880 {
3881    uint8_t idx;
3882    uint8_t elementCnt;
3883    uint8_t numBytes, bitsUnused;
3884    struct ControlResourceSet *controlRSet;
3885    uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
3886    uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
3887
3888    if(pdcchCfg == NULLP)
3889       elementCnt = 1;
3890    else
3891       elementCnt = pdcchCfg->numCRsetToAddMod;
3892
3893    controlRSetList->list.count = elementCnt;
3894    controlRSetList->list.size = elementCnt * sizeof(struct ControlResourceSet *);
3895
3896    controlRSetList->list.array = NULLP;
3897    DU_ALLOC(controlRSetList->list.array, controlRSetList->list.size);
3898    if(!controlRSetList->list.array)
3899    {
3900       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3901       return RFAILED;
3902    }
3903
3904    for(idx = 0; idx < elementCnt; idx++)
3905    {
3906       controlRSetList->list.array[idx] = NULLP;
3907       DU_ALLOC(controlRSetList->list.array[idx], sizeof(struct ControlResourceSet));
3908       if(!controlRSetList->list.array[idx])
3909       {
3910          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3911          return RFAILED;
3912       }
3913    }
3914
3915    for(idx = 0; idx < elementCnt; idx++)
3916    {
3917       controlRSet = controlRSetList->list.array[idx];
3918
3919       if(pdcchCfg == NULLP)
3920          controlRSet->controlResourceSetId = PDCCH_CTRL_RSRC_SET_ONE_ID;
3921       else
3922          controlRSet->controlResourceSetId = pdcchCfg->cRSetToAddModList[idx].cRSetId;
3923
3924       /* size 6 bytes
3925        * 3 LSBs unsued
3926        * Bit string stored ff0000000000
3927        */
3928       numBytes = 6;
3929       bitsUnused = 3;
3930       controlRSet->frequencyDomainResources.size = numBytes * sizeof(uint8_t);
3931
3932       controlRSet->frequencyDomainResources.buf = NULLP;
3933       DU_ALLOC(controlRSet->frequencyDomainResources.buf, controlRSet->frequencyDomainResources.size);
3934       if(!controlRSet->frequencyDomainResources.buf)
3935       {
3936          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3937          return RFAILED;
3938       }
3939
3940       memset(controlRSet->frequencyDomainResources.buf, 0, FREQ_DOM_RSRC_SIZE);
3941
3942       if(pdcchCfg == NULLP)
3943       {
3944          coreset0EndPrb = CORESET0_END_PRB;
3945          coreset1StartPrb = coreset0EndPrb + 6;
3946          coreset1NumPrb = CORESET1_NUM_PRB;
3947          /* calculate the PRBs */
3948          fillCoresetFeqDomAllocMap(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
3949          memcpy(controlRSet->frequencyDomainResources.buf, freqDomainResource, FREQ_DOM_RSRC_SIZE);
3950          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3951
3952          controlRSet->duration = PDCCH_CTRL_RSRC_SET_ONE_DURATION;
3953          controlRSet->cce_REG_MappingType.present = ControlResourceSet__cce_REG_MappingType_PR_nonInterleaved;
3954          controlRSet->precoderGranularity = PDCCH_CTRL_RSRC_SET_ONE_PRECOD_GRANULARITY;
3955       }
3956       else
3957       {
3958          memcpy(controlRSet->frequencyDomainResources.buf, pdcchCfg->cRSetToAddModList[idx].freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
3959          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3960          controlRSet->duration = pdcchCfg->cRSetToAddModList[idx].duration;
3961          controlRSet->cce_REG_MappingType.present = pdcchCfg->cRSetToAddModList[idx].cceRegMappingType;
3962          controlRSet->precoderGranularity = pdcchCfg->cRSetToAddModList[idx].precoderGranularity;
3963       }
3964       controlRSet->tci_StatesPDCCH_ToAddList = NULLP;
3965       controlRSet->tci_StatesPDCCH_ToReleaseList = NULLP;
3966       controlRSet->tci_PresentInDCI = NULLP;
3967
3968 #if 0
3969       uint8_t tciStateIdx;
3970
3971       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList, \
3972             sizeof(struct ControlResourceSet__tci_StatesPDCCH_ToAddList));
3973       if(!controlRset->tci_StatesPDCCH_ToAddList)
3974       {
3975          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3976          return RFAILED;
3977       }
3978
3979       elementCnt = 1;
3980       controlRset->tci_StatesPDCCH_ToAddList->list.count = elementCnt;
3981       controlRset->tci_StatesPDCCH_ToAddList->list.size = elementCnt * sizeof(TCI_StateId_t *);
3982       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array, \
3983             controlRset->tci_StatesPDCCH_ToAddList->list.size)
3984          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array)
3985          {
3986             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3987             return RFAILED;
3988          }
3989
3990       for(tciStateIdx = 0; tciStateIdx <elementCntl; tciStateIdx++)
3991       {
3992          DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx], sizeof(TCI_StateId_t));
3993          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx])
3994          {
3995             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3996             return RFAILED;
3997          }
3998       }
3999
4000       tciStateIdx = 0;
4001       /* TODO */
4002       *(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx]);
4003
4004       DU_ALLOC(controlRset->tci_PresentInDCI, sizeof(long));
4005       if(!controlRset->tci_PresentInDCI)
4006       {
4007          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
4008          return RFAILED;
4009       }
4010       /* TODO */
4011       *(controlRset->tci_PresentInDCI);
4012 #endif
4013
4014       controlRSet->pdcch_DMRS_ScramblingID = NULLP;
4015       DU_ALLOC(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
4016       if(!controlRSet->pdcch_DMRS_ScramblingID)
4017       {
4018          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
4019          return RFAILED;
4020       }
4021       if(pdcchCfg == NULLP)
4022          *(controlRSet->pdcch_DMRS_ScramblingID) = SCRAMBLING_ID;
4023       else
4024          *(controlRSet->pdcch_DMRS_ScramblingID) = pdcchCfg->cRSetToAddModList[idx].dmrsScramblingId;
4025    }
4026    return ROK;
4027 } /* End BuildControlRSetToAddModList */
4028
4029 /*******************************************************************
4030  *
4031  * @brief Build search space to add/modify list
4032  *
4033  * @details
4034  *
4035  *    Function : BuildSearchSpcToAddModList
4036  *
4037  *    Functionality: Build search space to add/modify list
4038  *
4039  * @params[in] 
4040  * @return ROK     - success
4041  *         RFAILED - failure
4042  *
4043  * ****************************************************************/
4044 uint8_t BuildSearchSpcToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
4045 {
4046    uint8_t idx;
4047    uint8_t numBytes;
4048    uint8_t byteIdx;
4049    uint8_t bitsUnused;
4050    uint8_t elementCnt;
4051    struct SearchSpace *searchSpc;
4052
4053    if(pdcchCfg == NULLP)
4054       elementCnt = 1;
4055    else
4056       elementCnt = pdcchCfg->numSearchSpcToAddMod;
4057
4058    searchSpcList->list.count = elementCnt;
4059    searchSpcList->list.size = elementCnt * sizeof(struct SearchSpace *);
4060
4061    searchSpcList->list.array = NULLP;
4062    DU_ALLOC(searchSpcList->list.array, searchSpcList->list.size);
4063    if(!searchSpcList->list.array)
4064    {
4065       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4066       return RFAILED;
4067    }
4068
4069    for(idx = 0; idx < elementCnt; idx++)
4070    {
4071       searchSpcList->list.array[idx] = NULLP;
4072       DU_ALLOC(searchSpcList->list.array[idx], sizeof(struct SearchSpace));
4073       if(!searchSpcList->list.array[idx])
4074       {
4075          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4076          return RFAILED;
4077       }
4078    }
4079
4080    for(idx = 0; idx < elementCnt; idx++)
4081    {
4082       searchSpc = searchSpcList->list.array[idx];
4083
4084       if(pdcchCfg == NULLP)
4085          searchSpc->searchSpaceId = PDCCH_SRCH_SPC_TWO_ID;
4086       else
4087          searchSpc->searchSpaceId = pdcchCfg->searchSpcToAddModList[idx].searchSpaceId;
4088
4089       searchSpc->controlResourceSetId = NULLP;
4090       DU_ALLOC(searchSpc->controlResourceSetId, sizeof(ControlResourceSetId_t));
4091       if(!searchSpc->controlResourceSetId)
4092       {
4093          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4094          return RFAILED;
4095       }
4096       if(pdcchCfg == NULLP)
4097          *(searchSpc->controlResourceSetId) = PDCCH_CTRL_RSRC_SET_ONE_ID;
4098       else
4099          *(searchSpc->controlResourceSetId) = pdcchCfg->searchSpcToAddModList[idx].cRSetId;
4100
4101       searchSpc->monitoringSlotPeriodicityAndOffset = NULLP;
4102       DU_ALLOC(searchSpc->monitoringSlotPeriodicityAndOffset, sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
4103       if(!searchSpc->monitoringSlotPeriodicityAndOffset)
4104       {
4105          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4106          return RFAILED;
4107       }
4108       if(pdcchCfg == NULLP)
4109          searchSpc->monitoringSlotPeriodicityAndOffset->present = SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
4110       else
4111          searchSpc->monitoringSlotPeriodicityAndOffset->present = pdcchCfg->searchSpcToAddModList[idx].mSlotPeriodicityAndOffset;
4112
4113       searchSpc->duration = NULLP;
4114       searchSpc->monitoringSymbolsWithinSlot = NULLP;
4115       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot, sizeof(BIT_STRING_t));
4116       if(!searchSpc->monitoringSymbolsWithinSlot)
4117       {
4118          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4119          return RFAILED;
4120       }
4121
4122       /* Values taken from reference logs :
4123        * size 2 bytes
4124        * 2 LSBs unsued
4125        * Bit string stores 8000
4126        */
4127       numBytes = 2;
4128       bitsUnused = 2;
4129       searchSpc->monitoringSymbolsWithinSlot->size = numBytes * sizeof(uint8_t);
4130       searchSpc->monitoringSymbolsWithinSlot->buf = NULLP;
4131       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot->buf, searchSpc->monitoringSymbolsWithinSlot->size);
4132       if(!searchSpc->monitoringSymbolsWithinSlot->buf)
4133       {
4134          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4135          return RFAILED;
4136       }
4137       if(pdcchCfg == NULLP)
4138       {
4139          byteIdx = 0;
4140          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = PDCCH_SYMBOL_WITHIN_SLOT /* setting MSB to 128 i.e. 0x80 */;
4141          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = 0;
4142       }
4143       else
4144          memcpy(searchSpc->monitoringSymbolsWithinSlot->buf, pdcchCfg->searchSpcToAddModList[idx].mSymbolsWithinSlot, numBytes);
4145       searchSpc->monitoringSymbolsWithinSlot->bits_unused = bitsUnused;
4146
4147       searchSpc->nrofCandidates = NULLP;
4148       DU_ALLOC(searchSpc->nrofCandidates, sizeof(struct SearchSpace__nrofCandidates));
4149       if(!searchSpc->nrofCandidates)
4150       {
4151          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4152          return RFAILED;
4153       }
4154
4155       if(pdcchCfg == NULLP)
4156       {
4157          searchSpc->nrofCandidates->aggregationLevel1 = PDCCH_SRCH_SPC_TWO_AGG_LVL1_CANDIDATE;
4158          searchSpc->nrofCandidates->aggregationLevel2 = PDCCH_SRCH_SPC_TWO_AGG_LVL2_CANDIDATE;
4159          searchSpc->nrofCandidates->aggregationLevel4 = PDCCH_SRCH_SPC_TWO_AGG_LVL4_CANDIDATE;
4160          searchSpc->nrofCandidates->aggregationLevel8 = PDCCH_SRCH_SPC_TWO_AGG_LVL8_CANDIDATE;
4161          searchSpc->nrofCandidates->aggregationLevel16 = PDCCH_SRCH_SPC_TWO_AGG_LVL16_CANDIDATE;
4162       }
4163       else
4164       {
4165          searchSpc->nrofCandidates->aggregationLevel1 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel1;
4166          searchSpc->nrofCandidates->aggregationLevel2 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel2;
4167          searchSpc->nrofCandidates->aggregationLevel4 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel4;
4168          searchSpc->nrofCandidates->aggregationLevel8 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel8;
4169          searchSpc->nrofCandidates->aggregationLevel16 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel16;
4170       }
4171
4172       searchSpc->searchSpaceType = NULLP;
4173       DU_ALLOC(searchSpc->searchSpaceType, sizeof(struct SearchSpace__searchSpaceType));
4174       if(!searchSpc->searchSpaceType)
4175       {
4176          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4177          return RFAILED;
4178       }
4179       if(pdcchCfg == NULLP)
4180          searchSpc->searchSpaceType->present = SearchSpace__searchSpaceType_PR_ue_Specific;
4181       else
4182          searchSpc->searchSpaceType->present = pdcchCfg->searchSpcToAddModList[idx].searchSpaceType;
4183
4184       searchSpc->searchSpaceType->choice.ue_Specific = NULLP;
4185       DU_ALLOC(searchSpc->searchSpaceType->choice.ue_Specific, sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
4186       if(!searchSpc->searchSpaceType->choice.ue_Specific)
4187       {
4188          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4189          return RFAILED;
4190       }  
4191       if(pdcchCfg == NULLP)
4192          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
4193       else
4194          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = pdcchCfg->searchSpcToAddModList[idx].ueSpecificDciFormat;
4195    }
4196    return ROK;
4197 }/* End BuildSearchSpcToAddModList */
4198
4199 /*******************************************************************
4200  *
4201  * @brief Builds BWP DL dedicated PDCCH config
4202  *
4203  * @details
4204  *
4205  *    Function : BuildBWPDlDedPdcchCfg
4206  *
4207  *    Functionality: Builds BWP DL dedicated PDCCH config
4208  *
4209  * @params[in] struct PDCCH_Config *pdcchCfg
4210  *
4211  * @return ROK     - success
4212  *         RFAILED - failure
4213  *
4214  * ****************************************************************/
4215 uint8_t BuildBWPDlDedPdcchCfg(PdcchConfig *pdcchCfgDb, struct PDCCH_Config *pdcchCfg)
4216 {
4217    pdcchCfg->controlResourceSetToAddModList = NULLP;
4218    DU_ALLOC(pdcchCfg->controlResourceSetToAddModList, sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
4219    if(!pdcchCfg->controlResourceSetToAddModList)
4220    {
4221       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
4222       return RFAILED;
4223    }
4224
4225    if(BuildControlRSetToAddModList(pdcchCfgDb, pdcchCfg->controlResourceSetToAddModList) != ROK)
4226    {
4227       DU_LOG("\nERROR  --> F1AP : Failed in BuildControlRSetToAddModList()");
4228       return RFAILED;
4229    }
4230
4231    pdcchCfg->controlResourceSetToReleaseList = NULLP;
4232
4233    pdcchCfg->searchSpacesToAddModList = NULLP;
4234    DU_ALLOC(pdcchCfg->searchSpacesToAddModList, sizeof(struct PDCCH_Config__searchSpacesToAddModList));
4235    if(!pdcchCfg->searchSpacesToAddModList)
4236    {
4237       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
4238       return RFAILED;
4239    }
4240
4241    if(BuildSearchSpcToAddModList(pdcchCfgDb, pdcchCfg->searchSpacesToAddModList) != ROK)
4242    {
4243       DU_LOG("\nERROR  --> F1AP : Failed in BuildSearchSpcToAddModList()");
4244       return RFAILED;
4245    }
4246
4247    pdcchCfg->searchSpacesToReleaseList = NULLP;
4248    pdcchCfg->downlinkPreemption = NULLP;
4249    pdcchCfg->tpc_PUSCH = NULLP;
4250    pdcchCfg->tpc_PUCCH = NULLP;
4251    pdcchCfg->tpc_SRS = NULLP;
4252
4253    return ROK;
4254 }
4255
4256 /*******************************************************************
4257  *
4258  * @brief Builds DMRS DL PDSCH Mapping type A
4259  *
4260  * @details
4261  *
4262  *    Function : BuildDMRSDLPdschMapTypeA
4263  *
4264  *    Functionality: Builds DMRS DL PDSCH Mapping type A
4265  *
4266  * @params[in]
4267  * struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg
4268  * @return ROK     - success
4269  *         RFAILED - failure
4270  *
4271  * ****************************************************************/
4272 uint8_t BuildDMRSDLPdschMapTypeA(PdschConfig *pdschCfg, struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg)
4273 {
4274    dmrsDlCfg->present = PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup;
4275    dmrsDlCfg->choice.setup = NULLP;
4276    DU_ALLOC(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
4277    if(!dmrsDlCfg->choice.setup)
4278    {
4279       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
4280       return RFAILED;
4281    }
4282
4283    dmrsDlCfg->choice.setup->dmrs_Type = NULLP;
4284    dmrsDlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4285    DU_ALLOC(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4286    if(!dmrsDlCfg->choice.setup->dmrs_AdditionalPosition)
4287    {
4288       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
4289       return RFAILED;
4290    }
4291    if(pdschCfg == NULLP)
4292       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS;
4293    else
4294       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = pdschCfg->dmrsDlCfgForPdschMapTypeA.addPos;
4295
4296    dmrsDlCfg->choice.setup->maxLength = NULLP;
4297    dmrsDlCfg->choice.setup->scramblingID0 = NULLP;
4298    dmrsDlCfg->choice.setup->scramblingID1 = NULLP;
4299    dmrsDlCfg->choice.setup->phaseTrackingRS = NULLP;
4300
4301    return ROK;
4302 }
4303
4304 /*******************************************************************
4305  *
4306  * @brief Builds TCI states to add/modify list
4307  *
4308  * @details
4309  *
4310  *    Function : BuildTCIStatesToAddModList
4311  *
4312  *    Functionality:Builds TCI states to add/modify list
4313  *
4314  * @params[in] 
4315  * struct PDSCH_Config__tci_StatesToAddModList *tciStatesList
4316  *
4317  * @return ROK     - success
4318  *         RFAILED - failure
4319  *
4320  * ****************************************************************/
4321 uint8_t BuildTCIStatesToAddModList(struct PDSCH_Config__tci_StatesToAddModList *tciStatesList)
4322 {
4323    return ROK;
4324 }
4325
4326 /*******************************************************************
4327  *
4328  * @brief Builds PDSCH time domain allocation list
4329  *
4330  * @details
4331  *
4332  *    Function : BuildPdschTimeDomAllocList
4333  *
4334  *    Functionality: Builds PDSCH time domain allocation list
4335  *
4336  * @params[in] 
4337  * struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
4338  *
4339  * @return ROK     - success
4340  *         RFAILED - failure
4341  *
4342  * ****************************************************************/
4343 uint8_t BuildPdschTimeDomAllocList(PdschConfig *pdschCfg, struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
4344 {
4345    uint8_t idx;
4346    uint8_t elementCnt;
4347    struct PDSCH_TimeDomainResourceAllocation *timeDomAlloc;
4348
4349    timeDomAllocList->present = PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup;
4350
4351    timeDomAllocList->choice.setup = NULLP;
4352    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PDSCH_TimeDomainResourceAllocationList));
4353    if(!timeDomAllocList->choice.setup)
4354    {
4355       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4356       return RFAILED;
4357    }
4358
4359 if(pdschCfg == NULLP)
4360    elementCnt = 2;
4361 else
4362 elementCnt = pdschCfg->numTimeDomRsrcAlloc;
4363    timeDomAllocList->choice.setup->list.count = elementCnt;
4364    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(struct PDSCH_TimeDomainResourceAllocation *);
4365
4366    timeDomAllocList->choice.setup->list.array = NULLP;
4367    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4368    if(!timeDomAllocList->choice.setup->list.array)
4369    {
4370       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4371       return RFAILED;
4372    }
4373
4374    for(idx = 0; idx < elementCnt; idx++)
4375    {
4376       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4377       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], \
4378             sizeof(struct PDSCH_TimeDomainResourceAllocation));
4379       if(!timeDomAllocList->choice.setup->list.array[idx])
4380       {
4381          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4382          return RFAILED;
4383       }
4384    }
4385
4386    if(pdschCfg == NULLP)
4387    {
4388       idx = 0;
4389       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4390       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4391       if(!timeDomAlloc->k0)
4392       {
4393          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4394          return RFAILED;
4395       }
4396       *(timeDomAlloc->k0) = 0;
4397       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4398       timeDomAlloc->startSymbolAndLength = \
4399                                            calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4400
4401       idx++;
4402       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4403       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4404       if(!timeDomAlloc->k0)
4405       {
4406          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4407          return RFAILED;
4408       }
4409       *(timeDomAlloc->k0) = 1;
4410       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4411       timeDomAlloc->startSymbolAndLength = calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4412    }
4413    else
4414    {
4415       for(idx = 0; idx < elementCnt; idx++)
4416       {
4417          timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4418          if(pdschCfg->timeDomRsrcAllociList[idx].k0)
4419          {
4420             DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4421             if(!timeDomAlloc->k0)
4422             {
4423                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4424                return RFAILED;
4425             }
4426             *(timeDomAlloc->k0) = *(pdschCfg->timeDomRsrcAllociList[idx].k0);
4427          }
4428          timeDomAlloc->mappingType = pdschCfg->timeDomRsrcAllociList[idx].mappingType;
4429          timeDomAlloc->startSymbolAndLength = pdschCfg->timeDomRsrcAllociList[idx].startSymbolAndLength;
4430       }
4431    }
4432
4433    return ROK;
4434 }
4435
4436 /*******************************************************************
4437  *
4438  * @brief Builds PDSCH PRB Bundling type
4439  *
4440  * @details
4441  *
4442  *    Function : BuildPdschPrbBundlingType
4443  *
4444  *    Functionality: Builds PDSCH PRB Bundling type
4445  *
4446  * @params[in] 
4447  * struct PDSCH_Config__prb_BundlingType *prbBndlType
4448  *
4449  * @return ROK     - success
4450  *         RFAILED - failure
4451  *
4452  * ****************************************************************/
4453 uint8_t BuildPdschPrbBundlingType(PdschConfig *pdschCfg, struct PDSCH_Config__prb_BundlingType *prbBndlType)
4454 {
4455    if(pdschCfg == NULLP)
4456       prbBndlType->present = PDSCH_Config__prb_BundlingType_PR_staticBundling;
4457    else
4458       prbBndlType->present = pdschCfg->bundlingType;
4459
4460    prbBndlType->choice.staticBundling = NULLP;
4461    DU_ALLOC(prbBndlType->choice.staticBundling, \
4462          sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
4463    if(!prbBndlType->choice.staticBundling)
4464    {
4465       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschPrbBundlingType");
4466       return RFAILED;
4467    }
4468    prbBndlType->choice.staticBundling->bundleSize = NULLP;
4469
4470    return ROK;
4471 }
4472
4473 /*******************************************************************
4474  *
4475  * @brief Builds BWP DL dedicated PDSCH config 
4476  *
4477  * @details
4478  *
4479  *    Function : BuildBWPDlDedPdschCfg
4480  *
4481  *    Functionality: Builds BWP DL dedicated PDSCH config
4482  *
4483  * @params[in] struct PDSCH_Config *pdschCfg
4484  *
4485  * @return ROK     - success
4486  *         RFAILED - failure
4487  *
4488  * ****************************************************************/
4489 uint8_t BuildBWPDlDedPdschCfg(PdschConfig *pdschCfgDb, struct PDSCH_Config *pdschCfg)
4490 {
4491    pdschCfg->dataScramblingIdentityPDSCH = NULLP;
4492
4493    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA = NULLP;
4494    DU_ALLOC(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
4495    if(!pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
4496    {
4497       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4498       return RFAILED;
4499    }
4500
4501    if(BuildDMRSDLPdschMapTypeA(pdschCfgDb, pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA) != ROK)
4502    {
4503       return RFAILED;
4504    }
4505
4506    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeB = NULLP;
4507    pdschCfg->tci_StatesToAddModList = NULLP;
4508    pdschCfg->tci_StatesToReleaseList = NULLP;
4509    pdschCfg->vrb_ToPRB_Interleaver = NULLP;
4510 #if 0
4511    DU_ALLOC(pdschCfg->tci_StatesToAddModList, sizeof(struct PDSCH_Config__tci_StatesToAddModList));
4512    if(!pdschCfg->tci_StatesToAddModList)
4513    {
4514       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4515       return RFAILED;
4516    }
4517    if(BuildTCIStatesToAddModList(pdschCfg->tci_StatesToAddModList) != ROK)
4518    {
4519       return RFAILED;
4520    }
4521 #endif
4522
4523 if(pdschCfgDb == NULLP)
4524    pdschCfg->resourceAllocation = RES_ALLOC_TYPE;
4525 else
4526 pdschCfg->resourceAllocation = pdschCfgDb->resourceAllocType;
4527
4528    pdschCfg->pdsch_TimeDomainAllocationList = NULLP;
4529    DU_ALLOC(pdschCfg->pdsch_TimeDomainAllocationList, sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
4530    if(!pdschCfg->pdsch_TimeDomainAllocationList)
4531    {
4532       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4533       return RFAILED;
4534    }
4535    if(BuildPdschTimeDomAllocList(pdschCfgDb, pdschCfg->pdsch_TimeDomainAllocationList) != ROK)
4536    {
4537       return RFAILED;
4538    }
4539
4540    pdschCfg->pdsch_AggregationFactor = NULLP;
4541    pdschCfg->rateMatchPatternToAddModList = NULLP;
4542    pdschCfg->rateMatchPatternToReleaseList = NULLP;
4543    pdschCfg->rateMatchPatternGroup1 = NULLP;
4544    pdschCfg->rateMatchPatternGroup2 = NULLP;
4545    if(pdschCfgDb == NULLP)
4546       pdschCfg->rbg_Size = PDSCH_RBG_SIZE;
4547    else
4548       pdschCfg->rbg_Size = pdschCfgDb->rbgSize;
4549    pdschCfg->mcs_Table = NULLP;
4550
4551    pdschCfg->maxNrofCodeWordsScheduledByDCI = NULLP;
4552    DU_ALLOC(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
4553    if(!pdschCfg->maxNrofCodeWordsScheduledByDCI)
4554    {
4555       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4556       return RFAILED;
4557    }
4558    if(pdschCfgDb == NULLP)
4559       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = PDSCH_MAX_CODEWORD_SCH_BY_DCI;
4560    else
4561       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = pdschCfgDb->numCodeWordsSchByDci;
4562
4563    if(BuildPdschPrbBundlingType(pdschCfgDb, &pdschCfg->prb_BundlingType) != ROK)
4564    {
4565       return RFAILED;
4566    }
4567
4568    pdschCfg->zp_CSI_RS_ResourceToAddModList = NULLP;
4569    pdschCfg->zp_CSI_RS_ResourceToReleaseList = NULLP;
4570    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4571    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4572    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4573    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4574    pdschCfg->p_ZP_CSI_RS_ResourceSet = NULLP;
4575
4576    return ROK;
4577 }
4578
4579 /*******************************************************************
4580  *
4581  * @brief Builds intitial DL BWP
4582  * @details
4583  *
4584  *    Function : BuildInitialDlBWP 
4585  *
4586  *    Functionality: Builds intitial DL BWP in spCellCfgDed
4587  *
4588  * @params[in] BWP_DownlinkDedicated_t *dlBwp
4589  *
4590  * @return ROK     - success
4591  *         RFAILED - failure
4592  *
4593  * ****************************************************************/
4594 uint8_t BuildInitialDlBWP(InitialDlBwp *initiDlBwp, BWP_DownlinkDedicated_t *dlBwp)
4595 {
4596    PdcchConfig *pdcchCfg = NULLP;
4597    PdschConfig *pdschCfg = NULLP;
4598
4599    if(initiDlBwp)
4600    {
4601       if(initiDlBwp->pdcchPresent)
4602          pdcchCfg = &initiDlBwp->pdcchCfg;
4603       if(initiDlBwp->pdschPresent)
4604          pdschCfg = &initiDlBwp->pdschCfg;
4605    }
4606
4607    dlBwp->pdcch_Config = NULLP;
4608    DU_ALLOC(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
4609    if(!dlBwp->pdcch_Config)
4610    {
4611       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4612       return RFAILED;
4613    }
4614    dlBwp->pdcch_Config->present = BWP_DownlinkDedicated__pdcch_Config_PR_setup; 
4615
4616    dlBwp->pdcch_Config->choice.setup = NULLP;
4617    DU_ALLOC(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
4618    if(!dlBwp->pdcch_Config->choice.setup)
4619    {
4620       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4621       return RFAILED;
4622    }
4623    if(BuildBWPDlDedPdcchCfg(pdcchCfg, dlBwp->pdcch_Config->choice.setup) != ROK)
4624    {
4625       return RFAILED;
4626    }
4627
4628    dlBwp->pdsch_Config = NULLP;
4629    DU_ALLOC(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
4630    if(!dlBwp->pdsch_Config)
4631    {
4632       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4633       return RFAILED;
4634    }
4635    dlBwp->pdsch_Config->present = BWP_DownlinkDedicated__pdsch_Config_PR_setup;
4636
4637    dlBwp->pdsch_Config->choice.setup = NULLP;
4638    DU_ALLOC(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
4639    if(!dlBwp->pdsch_Config->choice.setup)
4640    {
4641       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4642       return RFAILED;
4643    }
4644
4645    if(BuildBWPDlDedPdschCfg(pdschCfg, dlBwp->pdsch_Config->choice.setup) != ROK)
4646    {
4647       return RFAILED;
4648    }
4649
4650    dlBwp->sps_Config = NULLP;
4651    dlBwp->radioLinkMonitoringConfig = NULLP; 
4652    return ROK;
4653 }
4654
4655 /*******************************************************************
4656  *
4657  * @brief Builds DMRS UL Pusch Mapping type A
4658  *
4659  * @details
4660  *
4661  *    Function : BuildDMRSULPuschMapTypeA
4662  *
4663  *    Functionality: Builds DMRS UL Pusch Mapping type A
4664  *
4665  * @params[in] 
4666  *    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg
4667  * @return ROK     - success
4668  *         RFAILED - failure
4669  *
4670  * ****************************************************************/
4671 uint8_t BuildDMRSULPuschMapTypeA(DmrsUlCfg *ulDmrsCfgDb, struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg)
4672 {
4673    dmrsUlCfg->present = PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup;
4674    dmrsUlCfg->choice.setup= NULLP;
4675    DU_ALLOC(dmrsUlCfg->choice.setup, sizeof(DMRS_UplinkConfig_t));
4676    if(!dmrsUlCfg->choice.setup)
4677    {
4678       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4679       return RFAILED;
4680    }
4681
4682    dmrsUlCfg->choice.setup->dmrs_Type = NULLP;
4683    dmrsUlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4684    DU_ALLOC(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4685    if(!dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
4686    {
4687       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4688       return RFAILED;
4689    }
4690    if(ulDmrsCfgDb == NULLP)
4691       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS; 
4692    else
4693       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = ulDmrsCfgDb->addPos;
4694
4695    dmrsUlCfg->choice.setup->phaseTrackingRS = NULLP;
4696    dmrsUlCfg->choice.setup->maxLength = NULLP;
4697    dmrsUlCfg->choice.setup->transformPrecodingDisabled = NULLP;
4698    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled, sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
4699    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled)
4700    {
4701       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4702       return RFAILED;
4703    }
4704
4705    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0 = NULLP;
4706    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
4707          sizeof(long));
4708    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0)
4709    {
4710       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4711       return RFAILED;
4712    }
4713    if(ulDmrsCfgDb == NULLP)
4714       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = SCRAMBLING_ID;
4715    else
4716       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = ulDmrsCfgDb->transPrecodDisabled.scramblingId0;
4717
4718    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID1 = NULLP;
4719    dmrsUlCfg->choice.setup->transformPrecodingEnabled = NULLP;
4720    return ROK;
4721 }
4722
4723 /*******************************************************************
4724  *
4725  * @brief Build PUSCH time domain allocation list
4726  *
4727  * @details
4728  *
4729  *    Function : BuildPuschTimeDomAllocList
4730  *
4731  *    Functionality: Build PUSCH time domain allocation list
4732  *
4733  * @params[in] 
4734  * struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList
4735  *
4736  * @return ROK     - success
4737  *         RFAILED - failure
4738  *
4739  * ****************************************************************/
4740 uint8_t BuildPuschTimeDomAllocList(PuschCfg *puschCfgDb, struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList)
4741 {
4742    uint8_t idx;
4743    uint8_t elementCnt;
4744    PUSCH_TimeDomainResourceAllocation_t  *timeDomAlloc;
4745
4746    timeDomAllocList->present = PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup;
4747    timeDomAllocList->choice.setup = NULLP;
4748    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PUSCH_TimeDomainResourceAllocationList));
4749    if(!timeDomAllocList->choice.setup)
4750    {
4751       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4752       return RFAILED;
4753    }
4754
4755    if(puschCfgDb == NULLP)
4756       elementCnt = 2;
4757    else
4758       elementCnt = puschCfgDb->numTimeDomRsrcAlloc;
4759
4760    timeDomAllocList->choice.setup->list.count = elementCnt;
4761    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(PUSCH_TimeDomainResourceAllocation_t *);
4762    timeDomAllocList->choice.setup->list.array = NULLP;
4763    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4764    if(!timeDomAllocList->choice.setup->list.array)
4765    {
4766       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4767       return RFAILED;
4768    }
4769
4770    for(idx = 0; idx < elementCnt; idx++)
4771    {
4772       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4773       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], sizeof(PUSCH_TimeDomainResourceAllocation_t));
4774       if(!timeDomAllocList->choice.setup->list.array[idx])
4775       {
4776          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4777          return RFAILED;
4778       }
4779    }
4780
4781    for(idx = 0; idx < elementCnt; idx++)
4782    {
4783       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4784       DU_ALLOC(timeDomAlloc->k2, sizeof(long));
4785       if(!timeDomAlloc->k2)
4786       {
4787          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4788          return RFAILED;
4789       }
4790       if(puschCfgDb == NULLP)
4791       {
4792          if(idx == 0)
4793             *(timeDomAlloc->k2) = PUSCH_K2_CFG1;
4794          else if(idx == 1)
4795             *(timeDomAlloc->k2) = PUSCH_K2_CFG2;
4796
4797          timeDomAlloc->mappingType = PUSCH_MAPPING_TYPE_A;
4798          timeDomAlloc->startSymbolAndLength = calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
4799       }
4800       else
4801       {
4802          *(timeDomAlloc->k2) = puschCfgDb->timeDomRsrcAllocList[idx].k2;
4803          timeDomAlloc->mappingType = puschCfgDb->timeDomRsrcAllocList[idx].mappingType;
4804          timeDomAlloc->startSymbolAndLength = puschCfgDb->timeDomRsrcAllocList[idx].startSymbolAndLength;
4805       }
4806    }
4807
4808    return ROK;
4809 }
4810
4811 /*******************************************************************
4812  *
4813  * @brief Builds BWP UL dedicated PUSCH Config
4814  *
4815  * @details
4816  *
4817  *    Function : BuildBWPUlDedPuschCfg
4818  *
4819  *    Functionality:
4820  *      Builds BWP UL dedicated PUSCH Config
4821  *
4822  * @params[in] : PUSCH_Config_t *puschCfg
4823  *    
4824  * @return ROK     - success
4825  *         RFAILED - failure
4826  *
4827  * ****************************************************************/
4828 uint8_t BuildBWPUlDedPuschCfg(PuschCfg *puschCfgDb, PUSCH_Config_t *puschCfg)
4829 {
4830    DmrsUlCfg *ulDmrsCfg = NULLP;
4831    
4832    if(puschCfgDb)
4833       ulDmrsCfg = &puschCfgDb->dmrsUlCfgForPuschMapTypeA;
4834
4835    puschCfg->dataScramblingIdentityPUSCH = NULLP;
4836    DU_ALLOC(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
4837    if(!puschCfg->dataScramblingIdentityPUSCH)
4838    {
4839       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4840       return RFAILED;
4841    }
4842    if(puschCfgDb == NULLP)
4843       *(puschCfg->dataScramblingIdentityPUSCH) = SCRAMBLING_ID;
4844    else
4845       *(puschCfg->dataScramblingIdentityPUSCH) = puschCfgDb->dataScramblingId;
4846
4847    puschCfg->txConfig = NULLP;
4848    puschCfg->dmrs_UplinkForPUSCH_MappingTypeA = NULLP;
4849    DU_ALLOC(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
4850    if(!puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
4851    {
4852       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4853       return RFAILED;
4854    }
4855
4856    if(BuildDMRSULPuschMapTypeA(ulDmrsCfg, puschCfg->dmrs_UplinkForPUSCH_MappingTypeA) != ROK)
4857    {
4858       return RFAILED;
4859    }
4860
4861    puschCfg->dmrs_UplinkForPUSCH_MappingTypeB = NULLP;
4862    puschCfg->pusch_PowerControl = NULLP;
4863    puschCfg->frequencyHopping = NULLP;
4864    puschCfg->frequencyHoppingOffsetLists = NULLP;
4865
4866    if(puschCfgDb == NULLP)
4867       puschCfg->resourceAllocation = RES_ALLOC_TYPE;
4868    else
4869       puschCfg->resourceAllocation = puschCfgDb->resourceAllocType;
4870
4871    puschCfg->pusch_TimeDomainAllocationList = NULLP;
4872    DU_ALLOC(puschCfg->pusch_TimeDomainAllocationList, sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
4873    if(!puschCfg->pusch_TimeDomainAllocationList)
4874    {
4875       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4876       return RFAILED;
4877    }
4878
4879    if(BuildPuschTimeDomAllocList(puschCfgDb, puschCfg->pusch_TimeDomainAllocationList) != ROK)
4880    {
4881       return RFAILED;
4882    }
4883
4884    puschCfg->pusch_AggregationFactor = NULLP;
4885    puschCfg->mcs_Table = NULLP;
4886    puschCfg->mcs_TableTransformPrecoder = NULLP;
4887    puschCfg->transformPrecoder = NULLP;
4888    DU_ALLOC(puschCfg->transformPrecoder, sizeof(long));
4889    if(!puschCfg->transformPrecoder)
4890    {
4891       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4892       return RFAILED;
4893    }
4894    if(puschCfgDb == NULLP)
4895       *(puschCfg->transformPrecoder) = PUSCH_TRANSFORM_PRECODER;
4896    else
4897       *(puschCfg->transformPrecoder) = puschCfgDb->transformPrecoder;
4898
4899    puschCfg->codebookSubset = NULLP;
4900    puschCfg->maxRank = NULLP;
4901    puschCfg->rbg_Size = NULLP;
4902    puschCfg->uci_OnPUSCH = NULLP;
4903    puschCfg->tp_pi2BPSK = NULLP;
4904
4905    return ROK;
4906 }
4907
4908 /*******************************************************************
4909  *
4910  * @brief Builds PUCCH resource set add/modify list
4911  *
4912  * @details
4913  *
4914  *    Function : BuildPucchRsrcSetAddModList
4915  *
4916  *    Functionality:
4917  *      Builds PUCCH resource set add/modify list
4918  *
4919  * @params[in] : PucchResrcSetCfg *rsrcSetCfgDb
4920  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4921  *
4922  * @return ROK     - success
4923  *         RFAILED - failure
4924  *
4925  * ****************************************************************/
4926 uint8_t BuildPucchRsrcSetAddModList(PucchResrcSetCfg *rsrcSetCfgDb, \
4927    struct PUCCH_Config__resourceSetToAddModList *resourceSetToAddModList)
4928 {
4929    uint8_t elementCnt = 0, rsrcSetIdx = 0, rsrcIdx = 0;
4930    PUCCH_ResourceSet_t *rsrcSet = NULLP;
4931
4932    if(rsrcSetCfgDb == NULLP)
4933       elementCnt = 1;
4934    else
4935       elementCnt = rsrcSetCfgDb->resrcSetToAddModListCount;
4936
4937    resourceSetToAddModList->list.count = elementCnt;
4938    resourceSetToAddModList->list.size = elementCnt * sizeof(PUCCH_ResourceSet_t *);
4939    DU_ALLOC(resourceSetToAddModList->list.array, resourceSetToAddModList->list.size);
4940    if(resourceSetToAddModList->list.array == NULLP)
4941    {
4942       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4943       return RFAILED;
4944    }
4945    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4946    {
4947       DU_ALLOC(resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
4948       if(resourceSetToAddModList->list.array[rsrcSetIdx] == NULLP)
4949       {
4950          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4951          return RFAILED;
4952       }
4953    }
4954
4955    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4956    {
4957       rsrcSet = resourceSetToAddModList->list.array[rsrcSetIdx];
4958
4959       /* Resource set Id */
4960       if(rsrcSetCfgDb == NULLP)
4961          rsrcSet->pucch_ResourceSetId = 1;
4962       else
4963          rsrcSet->pucch_ResourceSetId = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcSetId;
4964  
4965       /* Resource list of a resource set */
4966       if(rsrcSetCfgDb == NULLP)
4967          elementCnt = 1;
4968       else
4969          elementCnt = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcListCount;
4970       rsrcSet->resourceList.list.count = elementCnt;
4971       rsrcSet->resourceList.list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
4972       DU_ALLOC(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
4973       if(rsrcSet->resourceList.list.array == NULLP)
4974       {
4975          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4976          return RFAILED;
4977       }
4978
4979       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4980       {
4981          DU_ALLOC(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
4982          if(rsrcSet->resourceList.list.array[rsrcIdx] == NULLP)
4983          {
4984             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4985             return RFAILED;
4986          }
4987       }
4988       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4989       {
4990          if(rsrcSetCfgDb == NULLP)
4991             *(rsrcSet->resourceList.list.array[rsrcIdx]) = 1;
4992          else
4993             *(rsrcSet->resourceList.list.array[rsrcIdx]) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcList[rsrcIdx];
4994       }
4995
4996       /* Max payload size (minus 1) in a Resource set */
4997       rsrcSet->maxPayloadMinus1 = NULLP;
4998       if(rsrcSetCfgDb && rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize)
4999       {
5000          DU_ALLOC(rsrcSet->maxPayloadMinus1, sizeof(long));
5001          if(rsrcSet->maxPayloadMinus1 == NULLP)
5002          {
5003             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
5004             return RFAILED;
5005          }
5006          *(rsrcSet->maxPayloadMinus1) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize;
5007       }
5008    }
5009    return ROK;
5010 }
5011
5012 /*******************************************************************
5013  *
5014  * @brief Builds PUCCH resource add/modify list
5015  *
5016  * @details
5017  *
5018  *    Function : BuildPucchRsrcAdddModList
5019  *
5020  *    Functionality:
5021  *      Builds PUCCH resource add/modify list
5022  *
5023  * @params[in] : PucchResrcCfg *rsrcSetCfgDb
5024  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
5025  *
5026  * @return ROK     - success
5027  *         RFAILED - failure
5028  *
5029  * ****************************************************************/
5030 uint8_t BuildPucchRsrcAddModList(PucchResrcCfg *rsrcCfgDb, struct PUCCH_Config__resourceToAddModList  *resourceToAddModList)
5031 {
5032    uint8_t elementCnt = 0, rsrcIdx = 0;
5033    PUCCH_Resource_t *rsrc = NULLP;
5034
5035    if(rsrcCfgDb == NULLP)
5036       elementCnt = 1;
5037    else
5038       elementCnt = rsrcCfgDb->resrcToAddModListCount;
5039    resourceToAddModList->list.count = elementCnt;
5040    resourceToAddModList->list.size = elementCnt * sizeof(PUCCH_Resource_t *);
5041    DU_ALLOC(resourceToAddModList->list.array, resourceToAddModList->list.size);
5042    if(resourceToAddModList->list.array == NULLP)
5043    {
5044       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5045       return RFAILED;
5046    }
5047    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
5048    {
5049       DU_ALLOC(resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
5050       if(resourceToAddModList->list.array[rsrcIdx] == NULLP)
5051       {
5052          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5053          return RFAILED;
5054       }
5055    }
5056
5057    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
5058    {
5059       rsrc = resourceToAddModList->list.array[rsrcIdx];
5060
5061       if(rsrcCfgDb == NULLP)
5062       {
5063          rsrc->pucch_ResourceId = 1;
5064          rsrc->startingPRB = 0;
5065          rsrc->format.present = PUCCH_Resource__format_PR_format1; 
5066          DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
5067          if(rsrc->format.choice.format1 == NULLP)
5068          {
5069             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5070             return RFAILED;
5071          }  
5072          rsrc->format.choice.format1->initialCyclicShift = 0;
5073          rsrc->format.choice.format1->nrofSymbols = 4;
5074          rsrc->format.choice.format1->startingSymbolIndex = 0;
5075          rsrc->format.choice.format1->timeDomainOCC = 0;
5076       }
5077       else
5078       {
5079          rsrc->pucch_ResourceId = rsrcCfgDb->resrcToAddModList[rsrcIdx].resrcId;
5080          rsrc->startingPRB = rsrcCfgDb->resrcToAddModList[rsrcIdx].startPrb;
5081          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop)
5082          {
5083             DU_ALLOC(rsrc->intraSlotFrequencyHopping, sizeof(long));
5084             if(rsrc->intraSlotFrequencyHopping == NULLP)
5085             {
5086                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5087                return RFAILED;
5088             }
5089             *(rsrc->intraSlotFrequencyHopping) = rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop;
5090          }
5091          else
5092             rsrc->intraSlotFrequencyHopping = NULLP;
5093
5094          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop)
5095          {
5096             DU_ALLOC(rsrc->secondHopPRB, sizeof(PRB_Id_t));
5097             if(rsrc->secondHopPRB == NULLP)
5098             {
5099                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5100                return RFAILED;
5101             }
5102             *(rsrc->secondHopPRB) = rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop;
5103          }
5104          else
5105             rsrc->secondHopPRB = NULLP;
5106          rsrc->format.present = covertPucchFormatIntEnumToRrcEnum(rsrcCfgDb->resrcToAddModList[rsrcIdx].pucchFormat); 
5107
5108          switch(rsrc->format.present)
5109          {
5110             case PUCCH_Resource__format_PR_NOTHING:
5111                break;
5112             case PUCCH_Resource__format_PR_format0:
5113                {
5114                   DU_ALLOC(rsrc->format.choice.format0, sizeof(PUCCH_format0_t));
5115                   if(rsrc->format.choice.format0 == NULLP)
5116                   {
5117                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5118                      return RFAILED;
5119                   }
5120                   rsrc->format.choice.format0->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->initialCyclicShift;
5121                   rsrc->format.choice.format0->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->numSymbols;
5122                   rsrc->format.choice.format0->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->startSymbolIdx;
5123                   break;
5124                }
5125
5126             case PUCCH_Resource__format_PR_format1:
5127                {
5128                   DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
5129                   if(rsrc->format.choice.format1 == NULLP)
5130                   {
5131                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5132                      return RFAILED;
5133                   }  
5134                   rsrc->format.choice.format1->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->initialCyclicShift;
5135                   rsrc->format.choice.format1->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->numSymbols;
5136                   rsrc->format.choice.format1->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->startSymbolIdx;
5137                   rsrc->format.choice.format1->timeDomainOCC = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->timeDomOCC;
5138                   break;
5139                }
5140
5141             case PUCCH_Resource__format_PR_format2:
5142                {
5143                   DU_ALLOC(rsrc->format.choice.format2, sizeof(PUCCH_format2_t));
5144                   if(rsrc->format.choice.format2 == NULLP)
5145                   {
5146                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5147                      return RFAILED;
5148                   } 
5149                   rsrc->format.choice.format2->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numPrbs;
5150                   rsrc->format.choice.format2->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numSymbols;
5151                   rsrc->format.choice.format2->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->startSymbolIdx;
5152                   break;
5153                }
5154
5155             case PUCCH_Resource__format_PR_format3:
5156                {
5157                   DU_ALLOC(rsrc->format.choice.format3, sizeof(PUCCH_format3_t));
5158                   if(rsrc->format.choice.format3 == NULLP)
5159                   {
5160                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5161                      return RFAILED;
5162                   }
5163                   rsrc->format.choice.format3->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numPrbs;
5164                   rsrc->format.choice.format3->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numSymbols;
5165                   rsrc->format.choice.format3->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->startSymbolIdx;
5166                   break;
5167                }
5168
5169             case PUCCH_Resource__format_PR_format4:
5170                {
5171                   DU_ALLOC(rsrc->format.choice.format4, sizeof(PUCCH_format4_t));
5172                   if(rsrc->format.choice.format4 == NULLP)
5173                   {
5174                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5175                      return RFAILED;
5176                   }
5177                   rsrc->format.choice.format4->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->numSymbols;
5178                   rsrc->format.choice.format4->occ_Length = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occLen;
5179                   rsrc->format.choice.format4->occ_Index = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occIdx;
5180                   rsrc->format.choice.format4->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->startSymbolIdx;
5181                   break;
5182                }
5183          }
5184       }
5185    }
5186    return ROK;
5187 }
5188
5189 /*******************************************************************
5190  *
5191  * @brief Builds PUCCH format  config
5192  *
5193  * @details
5194  *
5195  *    Function : BuildPucchFormat
5196  *
5197  *    Functionality: Builds PUCCH format  config
5198  *
5199  * @params[in] : PucchFormatCfg *formatDb
5200  *               PUCCH_FormatConfig_t *format
5201  *
5202  * @return ROK     - success
5203  *         RFAILED - failure
5204  *
5205  * ****************************************************************/
5206 uint8_t BuildPucchFormat(PucchFormatCfg *formatDb, PUCCH_FormatConfig_t *format)
5207 {
5208    /* Inter Slot Fequency hopping */
5209    format->interslotFrequencyHopping = NULLP;
5210    if((formatDb != NULLP) && (formatDb->interSlotFreqHop == true))
5211    {
5212       DU_ALLOC(format->interslotFrequencyHopping, sizeof(long));
5213       if(format->interslotFrequencyHopping)
5214       {
5215          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5216          return RFAILED;
5217       }
5218       *(format->interslotFrequencyHopping) = PUCCH_FormatConfig__interslotFrequencyHopping_enabled;
5219    }
5220
5221    /* Additional DMRS */
5222    format->additionalDMRS = NULLP;
5223    if((formatDb != NULLP) && (formatDb->addDmrs == true))
5224    {
5225       DU_ALLOC(format->additionalDMRS, sizeof(long));
5226       if(format->additionalDMRS)
5227       {
5228          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5229          return RFAILED;
5230       }
5231       *(format->additionalDMRS) = PUCCH_FormatConfig__additionalDMRS_true;
5232    }
5233
5234     /* Maximum code rate */
5235    format->maxCodeRate = NULLP;
5236    if((formatDb != NULLP) && (formatDb->maxCodeRate != 0))
5237    {
5238       DU_ALLOC(format->maxCodeRate, sizeof(long));
5239       if(format->maxCodeRate)
5240       {
5241          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5242          return RFAILED;
5243       }  
5244       *(format->maxCodeRate) = formatDb->maxCodeRate;
5245    }
5246  
5247    /* Number of slots */
5248    format->nrofSlots = NULLP;
5249    if((formatDb == NULLP) || ((formatDb != NULLP) && (formatDb->numSlots != 0)))
5250    {
5251       DU_ALLOC(format->nrofSlots, sizeof(long));
5252       if(format->nrofSlots == NULLP)
5253       {
5254          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5255          return RFAILED;
5256       }
5257       if(formatDb == NULLP)
5258          *(format->nrofSlots) = PUCCH_FormatConfig__nrofSlots_n4;
5259       else
5260          *(format->nrofSlots) = formatDb->numSlots;
5261    }
5262
5263    /* Pi2BPSK*/
5264    format->pi2BPSK = NULLP;
5265    if((formatDb != NULLP) && (formatDb->pi2BPSK == true))
5266    {
5267       DU_ALLOC(format->pi2BPSK, sizeof(long));
5268       if(format->pi2BPSK)
5269       {     
5270          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5271          return RFAILED;
5272       }     
5273       *(format->pi2BPSK) = PUCCH_FormatConfig__pi2BPSK_enabled;
5274    }
5275
5276    /* Simultaneous HARQ ACK and CSI */
5277    format->simultaneousHARQ_ACK_CSI = NULLP;
5278    if((formatDb != NULLP) && (formatDb->harqAckCSI == true))
5279    {
5280       DU_ALLOC(format->simultaneousHARQ_ACK_CSI, sizeof(long));
5281       if(format->simultaneousHARQ_ACK_CSI)
5282       {     
5283          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5284          return RFAILED;
5285       }     
5286       *(format->simultaneousHARQ_ACK_CSI) = PUCCH_FormatConfig__simultaneousHARQ_ACK_CSI_true;
5287    }
5288
5289    return ROK;
5290 }
5291
5292
5293 /*******************************************************************
5294  *
5295  * @brief Builds PUCCH scheduling request list
5296  *
5297  * @details
5298  *
5299  *    Function : BuildPucchSchReqAddModList
5300  *
5301  *    Functionality:
5302  *      Builds PUCCH scheduling request list
5303  *
5304  * @params[in] : PucchSchedReqCfg *schReqDb
5305  *               struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList
5306  *
5307  * @return ROK     - success
5308  *         RFAILED - failure
5309  *
5310  * ****************************************************************/
5311 uint8_t BuildPucchSchReqAddModList(PucchSchedReqCfg *schReqDb, \
5312    struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList)
5313 {
5314    uint8_t elementCnt = 0, schReqIdx = 0;
5315    SchedulingRequestResourceConfig_t *schReqRsrc;
5316
5317    elementCnt = schReqDb->schedAddModListCount;
5318    schReqRsrcToAddModList->list.count = elementCnt;
5319    schReqRsrcToAddModList->list.size = elementCnt *sizeof(struct SchedulingRequestResourceConfig *);
5320
5321    schReqRsrcToAddModList->list.array = NULLP;
5322    DU_ALLOC(schReqRsrcToAddModList->list.array, schReqRsrcToAddModList->list.size);
5323    if(schReqRsrcToAddModList->list.array == NULLP)
5324    {
5325       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5326       return RFAILED;
5327    }
5328
5329    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
5330    {
5331       DU_ALLOC(schReqRsrcToAddModList->list.array[schReqIdx], schReqRsrcToAddModList->list.size);
5332       if(schReqRsrcToAddModList->list.array[schReqIdx] == NULLP)
5333       {
5334          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5335          return RFAILED;
5336       }
5337    }
5338
5339    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
5340    {
5341       schReqRsrc = schReqRsrcToAddModList->list.array[schReqIdx];
5342       schReqRsrc->schedulingRequestResourceId = schReqDb->schedAddModList[schReqIdx].resrcId;
5343       schReqRsrc->schedulingRequestID = schReqDb->schedAddModList[schReqIdx].requestId;
5344
5345       if(schReqDb->schedAddModList[schReqIdx].periodicity)
5346       {
5347          schReqRsrc->periodicityAndOffset = NULLP;
5348          DU_ALLOC(schReqRsrc->periodicityAndOffset, sizeof(struct SchedulingRequestResourceConfig__periodicityAndOffset));
5349          if(schReqRsrc->periodicityAndOffset == NULLP)
5350          {
5351             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5352             return RFAILED;
5353          }
5354
5355          schReqRsrc->periodicityAndOffset->present = schReqDb->schedAddModList[schReqIdx].periodicity;
5356          switch(schReqRsrc->periodicityAndOffset->present)
5357          {
5358             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_NOTHING:
5359                break;
5360             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
5361                schReqRsrc->periodicityAndOffset->choice.sym2 = schReqDb->schedAddModList[schReqIdx].offset;
5362                break;
5363             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
5364                schReqRsrc->periodicityAndOffset->choice.sym6or7 = schReqDb->schedAddModList[schReqIdx].offset;
5365                break;
5366             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
5367                schReqRsrc->periodicityAndOffset->choice.sl1 = schReqDb->schedAddModList[schReqIdx].offset;
5368                break;
5369             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
5370                schReqRsrc->periodicityAndOffset->choice.sl2 = schReqDb->schedAddModList[schReqIdx].offset;
5371                break;
5372             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
5373                schReqRsrc->periodicityAndOffset->choice.sl4 = schReqDb->schedAddModList[schReqIdx].offset;
5374                break;
5375             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
5376                schReqRsrc->periodicityAndOffset->choice.sl5 = schReqDb->schedAddModList[schReqIdx].offset;
5377                break;
5378             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
5379                schReqRsrc->periodicityAndOffset->choice.sl8 = schReqDb->schedAddModList[schReqIdx].offset;
5380                break;
5381             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
5382                schReqRsrc->periodicityAndOffset->choice.sl10 = schReqDb->schedAddModList[schReqIdx].offset;
5383                break;
5384             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
5385                schReqRsrc->periodicityAndOffset->choice.sl16 = schReqDb->schedAddModList[schReqIdx].offset;
5386                break;
5387             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
5388                schReqRsrc->periodicityAndOffset->choice.sl20 = schReqDb->schedAddModList[schReqIdx].offset;
5389                break;
5390             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
5391                schReqRsrc->periodicityAndOffset->choice.sl40 = schReqDb->schedAddModList[schReqIdx].offset;
5392                break;
5393             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
5394                schReqRsrc->periodicityAndOffset->choice.sl80 = schReqDb->schedAddModList[schReqIdx].offset;
5395                break;
5396             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
5397                schReqRsrc->periodicityAndOffset->choice.sl160 = schReqDb->schedAddModList[schReqIdx].offset;
5398                break;
5399             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
5400                schReqRsrc->periodicityAndOffset->choice.sl320 = schReqDb->schedAddModList[schReqIdx].offset;
5401                break;
5402             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
5403                schReqRsrc->periodicityAndOffset->choice.sl640 = schReqDb->schedAddModList[schReqIdx].offset;
5404                break;
5405          }
5406       }
5407
5408       if(schReqDb->schedAddModList[schReqIdx].resrc)
5409       {
5410          schReqRsrc->resource = NULLP;
5411          DU_ALLOC(schReqRsrc->resource, sizeof(PUCCH_ResourceId_t));
5412          if(schReqRsrc->resource == NULLP)
5413          {
5414             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5415             return RFAILED;
5416          }
5417          *(schReqRsrc->resource) = schReqDb->schedAddModList[schReqIdx].resrc;
5418
5419       }
5420    }
5421    return ROK;
5422 }
5423
5424 /*******************************************************************
5425  *
5426  * @brief Builds PUCCH multi csi resource list
5427  *
5428  * @details
5429  *
5430  *    Function : BuildPucchMultiCsiRsrcList
5431  *
5432  *    Functionality:
5433  *      Builds PUCCH multi csi resource list
5434  *
5435  * @params[in] : PucchMultiCsiCfg *multiCsiDb
5436  *               struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList
5437  *
5438  * @return ROK     - success
5439  *         RFAILED - failure
5440  *
5441  * ****************************************************************/
5442 uint8_t BuildPucchMultiCsiRsrcList(PucchMultiCsiCfg *multiCsiDb, struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList)
5443 {
5444    uint8_t elementCnt = 0, rsrcIdx = 0;
5445
5446    elementCnt = multiCsiDb->multiCsiResrcListCount;
5447    multiCsiRsrcList->list.count = elementCnt;
5448    multiCsiRsrcList->list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
5449    multiCsiRsrcList->list.array = NULLP;
5450    DU_ALLOC(multiCsiRsrcList->list.array, multiCsiRsrcList->list.size);
5451    if(multiCsiRsrcList->list.array == NULLP)
5452    {
5453       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5454       return RFAILED;
5455    }
5456
5457    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5458    {
5459       DU_ALLOC(multiCsiRsrcList->list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
5460       if(multiCsiRsrcList->list.array[rsrcIdx] == NULLP)
5461       {
5462          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5463          return RFAILED;
5464       }
5465    }
5466
5467    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5468    {
5469       *(multiCsiRsrcList->list.array[rsrcIdx]) = multiCsiDb->multiCsiResrcList[rsrcIdx];
5470    }
5471    return ROK;
5472 }
5473
5474 /*******************************************************************
5475  *
5476  * @brief Builds DL data -to- Ul Ack list
5477  *
5478  * @details
5479  *
5480  *    Function : BuildDlDataToUlAckList
5481  *
5482  *    Functionality: Builds DL data -to- Ul Ack list
5483  *
5484  * @params[in] : PucchDlDataToUlAck *dlDataToUlAckDb
5485  *               struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList
5486  *
5487  * @return ROK     - success
5488  *         RFAILED - failure
5489  *
5490  * ****************************************************************/
5491 uint8_t BuildDlDataToUlAckList(PucchDlDataToUlAck *dlDataToUlAckDb, struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList)
5492 {
5493    uint8_t elementCnt = 0, arrIdx = 0;
5494
5495    if(dlDataToUlAckDb == NULLP)
5496       elementCnt = 2;
5497    else
5498       elementCnt = dlDataToUlAckDb->dlDataToUlAckListCount;
5499
5500    dlDataToUlACKList->list.count = elementCnt;
5501    dlDataToUlACKList->list.size = elementCnt * sizeof(long *);
5502    DU_ALLOC(dlDataToUlACKList->list.array, dlDataToUlACKList->list.size);
5503    if(dlDataToUlACKList->list.array == NULLP)
5504    {
5505       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5506       return RFAILED;
5507    }   
5508
5509    for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5510    {
5511       DU_ALLOC(dlDataToUlACKList->list.array[arrIdx], sizeof(long));
5512       if(dlDataToUlACKList->list.array[arrIdx] == NULLP)
5513       {
5514          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5515          return RFAILED;
5516       }   
5517    }
5518
5519    if(dlDataToUlAckDb == NULLP)
5520    {
5521       arrIdx = 0;
5522       *(dlDataToUlACKList->list.array[arrIdx++]) = 1;
5523       *(dlDataToUlACKList->list.array[arrIdx]) = 2;
5524    }
5525    else
5526    {
5527       for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5528       {
5529          *(dlDataToUlACKList->list.array[arrIdx]) = dlDataToUlAckDb->dlDataToUlAckList[arrIdx];
5530       }
5531    }
5532    return ROK;
5533 }
5534
5535 /*******************************************************************
5536  *
5537  * @brief Builds BWP UL dedicated PUCCH Config
5538  *
5539  * @details
5540  *
5541  *    Function : BuildBWPUlDedPucchCfg
5542  *
5543  *    Functionality:
5544  *      Builds BWP UL dedicated PUCCH Config
5545  *
5546  * @params[in] : PUCCH_Config_t *pucchCfg
5547  *
5548  * @return ROK     - success
5549  *         RFAILED - failure
5550  *
5551  * ****************************************************************/
5552 uint8_t BuildBWPUlDedPucchCfg(PucchCfg *pucchCfgDb, PUCCH_Config_t *pucchCfg)
5553 {
5554    PucchResrcSetCfg *rsrcSetCfgDb = NULLP;
5555    PucchResrcCfg *rsrcCfgDb = NULLP;
5556    PucchFormatCfg *format1Db = NULLP;
5557    PucchFormatCfg *format2Db = NULLP;
5558    PucchFormatCfg *format3Db = NULLP;
5559    PucchFormatCfg *format4Db = NULLP;
5560    PucchSchedReqCfg *schReqDb = NULLP;   
5561    PucchMultiCsiCfg  *multiCsiDb = NULLP;
5562    PucchDlDataToUlAck *dlDataToUlAckDb = NULLP;
5563
5564    if(pucchCfgDb)
5565    {
5566       rsrcSetCfgDb = pucchCfgDb->resrcSet;
5567       rsrcCfgDb = pucchCfgDb->resrc;
5568       format1Db = pucchCfgDb->format1;
5569       format2Db = pucchCfgDb->format2;
5570       format3Db = pucchCfgDb->format3;
5571       format4Db = pucchCfgDb->format4;
5572       schReqDb = pucchCfgDb->schedReq;
5573       multiCsiDb = pucchCfgDb->multiCsiCfg;
5574       dlDataToUlAckDb = pucchCfgDb->dlDataToUlAck;
5575    }
5576
5577    /* RESOURCE SET */
5578    DU_ALLOC(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
5579    if(pucchCfg->resourceSetToAddModList == NULL)
5580    {
5581       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5582       return RFAILED;
5583    }
5584
5585    if(BuildPucchRsrcSetAddModList(rsrcSetCfgDb, pucchCfg->resourceSetToAddModList) != ROK)
5586    {
5587       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5588       return RFAILED;
5589    }
5590
5591    /* PUCCH RESOURCE */
5592    DU_ALLOC(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
5593    if(pucchCfg->resourceToAddModList == NULLP)
5594    {
5595       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5596       return RFAILED;
5597    }
5598
5599    if(BuildPucchRsrcAddModList(rsrcCfgDb, pucchCfg->resourceToAddModList) != ROK)
5600    {
5601       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5602       return RFAILED;
5603    }
5604
5605    /* PUCCH Format 1 */
5606    DU_ALLOC(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
5607    if(pucchCfg->format1 == NULLP)
5608    {
5609       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5610       return RFAILED;
5611    }
5612    
5613    pucchCfg->format1->present = PUCCH_Config__format1_PR_setup;
5614    DU_ALLOC(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
5615    if(pucchCfg->format1->choice.setup == NULLP)
5616    {
5617       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5618       return RFAILED;
5619    }
5620
5621    if(BuildPucchFormat(format1Db, pucchCfg->format1->choice.setup) != ROK)
5622    {
5623       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5624       return RFAILED;
5625    }
5626
5627    /* PUCCH Format 2 */
5628    if(format2Db)
5629    {
5630       DU_ALLOC(pucchCfg->format2, sizeof(struct PUCCH_Config__format2));
5631       if(pucchCfg->format2 == NULLP)
5632       {
5633          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5634          return RFAILED;
5635       }
5636
5637       pucchCfg->format2->present = PUCCH_Config__format2_PR_setup;
5638       DU_ALLOC(pucchCfg->format2->choice.setup, sizeof(PUCCH_FormatConfig_t));
5639       if(pucchCfg->format2->choice.setup == NULLP)
5640       {
5641          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5642          return RFAILED;
5643       }
5644
5645       if(BuildPucchFormat(format2Db, pucchCfg->format2->choice.setup) != ROK)
5646       {
5647          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5648          return RFAILED;
5649       }
5650    }
5651
5652    /* PUCCH Format 3 */
5653    if(format3Db)
5654    {
5655       DU_ALLOC(pucchCfg->format3, sizeof(struct PUCCH_Config__format3));
5656       if(pucchCfg->format3 == NULLP)
5657       {
5658          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5659          return RFAILED;
5660       }
5661
5662       pucchCfg->format3->present = PUCCH_Config__format3_PR_setup;
5663       DU_ALLOC(pucchCfg->format3->choice.setup, sizeof(PUCCH_FormatConfig_t));
5664       if(pucchCfg->format3->choice.setup == NULLP)
5665       {
5666          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5667          return RFAILED;
5668       }
5669
5670       if(BuildPucchFormat(format3Db, pucchCfg->format3->choice.setup) != ROK)
5671       {
5672          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5673          return RFAILED;
5674       }
5675    }
5676
5677    /* PUCCH Format 4 */
5678    if(format4Db)
5679    {
5680       DU_ALLOC(pucchCfg->format4, sizeof(struct PUCCH_Config__format4));
5681       if(pucchCfg->format4 == NULLP)
5682       {
5683          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5684          return RFAILED;
5685       }
5686
5687       pucchCfg->format4->present = PUCCH_Config__format4_PR_setup;
5688       DU_ALLOC(pucchCfg->format4->choice.setup, sizeof(PUCCH_FormatConfig_t));
5689       if(pucchCfg->format4->choice.setup == NULLP)
5690       {
5691          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5692          return RFAILED;
5693       }
5694
5695       if(BuildPucchFormat(format4Db, pucchCfg->format4->choice.setup) != ROK)
5696       {
5697          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5698          return RFAILED;
5699       }
5700    }
5701
5702    /* Scheduling Request */
5703    if(schReqDb && (schReqDb->schedAddModListCount != 0))
5704    {
5705       pucchCfg->schedulingRequestResourceToAddModList = NULLP;
5706       DU_ALLOC(pucchCfg->schedulingRequestResourceToAddModList, sizeof(struct PUCCH_Config__schedulingRequestResourceToAddModList));
5707       if(pucchCfg->schedulingRequestResourceToAddModList == NULLP)
5708       {
5709          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5710          return RFAILED;
5711       }
5712
5713       if(BuildPucchSchReqAddModList(schReqDb, pucchCfg->schedulingRequestResourceToAddModList) != ROK)
5714       {
5715          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5716          return RFAILED;
5717       }
5718    }
5719
5720    /* Multi CSI */
5721    if(multiCsiDb && (multiCsiDb->multiCsiResrcListCount != 0))
5722    {
5723       pucchCfg->multi_CSI_PUCCH_ResourceList = NULLP;
5724       DU_ALLOC(pucchCfg->multi_CSI_PUCCH_ResourceList, sizeof(struct PUCCH_Config__multi_CSI_PUCCH_ResourceList));
5725       if(pucchCfg->multi_CSI_PUCCH_ResourceList == NULLP)
5726       {
5727          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5728          return RFAILED;
5729       }
5730
5731       if(BuildPucchMultiCsiRsrcList(multiCsiDb, pucchCfg->multi_CSI_PUCCH_ResourceList) != ROK)
5732       {
5733          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5734          return RFAILED;
5735       }
5736    }
5737
5738    /* DL DATA TO UL ACK */
5739    DU_ALLOC(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
5740    if(pucchCfg->dl_DataToUL_ACK == NULLP)
5741    {
5742       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5743       return RFAILED;
5744    }
5745
5746    if(BuildDlDataToUlAckList(dlDataToUlAckDb, pucchCfg->dl_DataToUL_ACK) != ROK)
5747    {
5748       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5749       return RFAILED;
5750    }
5751    
5752    /* TODO : spatial relation info add/mod list and power control*/
5753
5754    return ROK;
5755 }
5756
5757 /*******************************************************************
5758  *
5759  * @brief Fills SRS resource to add/modify list 
5760  *
5761  * @details
5762  *
5763  *    Function : BuildSrsRsrcAddModList
5764  *
5765  *    Functionality: Fills SRS resource to add/modify list
5766  *
5767  * @params[in] 
5768  * @return ROK     - success
5769  *         RFAILED - failure
5770  *
5771  * ****************************************************************/
5772 uint8_t BuildSrsRsrcAddModList(struct SRS_Config__srs_ResourceToAddModList *resourceList)
5773 {
5774    uint8_t   elementCnt;
5775    uint8_t   rsrcIdx;
5776
5777    elementCnt = 1;
5778    resourceList->list.count = elementCnt;
5779    resourceList->list.size = elementCnt * sizeof(SRS_Resource_t *);
5780    resourceList->list.array = NULLP;
5781    DU_ALLOC(resourceList->list.array, resourceList->list.size);
5782    if(!resourceList->list.array)
5783    {
5784       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5785       return RFAILED;
5786    }
5787
5788    for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
5789    {
5790       DU_ALLOC(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
5791       if(!resourceList->list.array[rsrcIdx])
5792       {
5793          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5794          return RFAILED;
5795       }
5796    }
5797
5798    rsrcIdx = 0;
5799    resourceList->list.array[rsrcIdx]->srs_ResourceId = SRS_RSRC_ID;
5800    resourceList->list.array[rsrcIdx]->nrofSRS_Ports = SRS_Resource__nrofSRS_Ports_port1;
5801    resourceList->list.array[rsrcIdx]->transmissionComb.present = SRS_Resource__transmissionComb_PR_n2;
5802
5803    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2 = NULLP;
5804    DU_ALLOC(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2, \
5805          sizeof(struct SRS_Resource__transmissionComb__n2));
5806    if(!resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2)
5807    {
5808       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5809       return RFAILED;
5810    }
5811    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->combOffset_n2\
5812       = SRS_COMB_OFFSET_N2;
5813    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->cyclicShift_n2\
5814       = SRS_CYCLIC_SHIFT_N2;
5815
5816    resourceList->list.array[rsrcIdx]->resourceMapping.startPosition = \
5817                                                                       PUSCH_START_SYMBOL;
5818    resourceList->list.array[rsrcIdx]->resourceMapping.nrofSymbols =  \
5819                                                                      SRS_Resource__resourceMapping__nrofSymbols_n1;
5820    resourceList->list.array[rsrcIdx]->resourceMapping.repetitionFactor = \
5821                                                                          SRS_Resource__resourceMapping__repetitionFactor_n1;
5822
5823    resourceList->list.array[rsrcIdx]->freqDomainPosition = SRS_FREQ_DOM_POS;
5824    resourceList->list.array[rsrcIdx]->freqDomainShift = SRS_FREQ_DOM_SHIFT;
5825    resourceList->list.array[rsrcIdx]->freqHopping.c_SRS = C_SRS;
5826    resourceList->list.array[rsrcIdx]->freqHopping.b_SRS = B_SRS;
5827    resourceList->list.array[rsrcIdx]->freqHopping.b_hop = B_HOP;
5828    resourceList->list.array[rsrcIdx]->groupOrSequenceHopping = \
5829                                                                SRS_Resource__groupOrSequenceHopping_neither;
5830
5831    /* Setting resource type to aperiodic for intergration purposes */
5832    resourceList->list.array[rsrcIdx]->resourceType.present = \
5833                                                              SRS_Resource__resourceType_PR_aperiodic;
5834    resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic = NULLP;
5835    DU_ALLOC(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,
5836          sizeof(struct SRS_Resource__resourceType__aperiodic));
5837    if(!resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic)
5838    {
5839       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5840       return RFAILED;
5841    }
5842
5843    resourceList->list.array[rsrcIdx]->sequenceId = SRS_SEQ_ID;
5844
5845    return ROK;
5846 }
5847
5848 /*******************************************************************
5849  *
5850  * @brief Build SRS resource set Add/mod list
5851  *
5852  * @details
5853  *
5854  *    Function : BuildSrsRsrcSetAddModList
5855  *
5856  *    Functionality: Build SRS resource set Add/mod list
5857  *
5858  * @params[in] 
5859  * @return ROK     - success
5860  *         RFAILED - failure
5861  *
5862  * ****************************************************************/
5863    uint8_t BuildSrsRsrcSetAddModList
5864 (
5865  struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList
5866  )
5867 {
5868    uint8_t  elementCnt;
5869    uint8_t  rSetIdx;
5870    uint8_t  rsrcIdx;
5871    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList;
5872
5873    elementCnt = 1;
5874    rsrcSetList->list.count = elementCnt;
5875    rsrcSetList->list.size = elementCnt * sizeof(SRS_ResourceSet_t *);
5876    rsrcSetList->list.array = NULLP;
5877    DU_ALLOC(rsrcSetList->list.array, rsrcSetList->list.size);
5878    if(!rsrcSetList->list.array)
5879    {
5880       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5881       return RFAILED;
5882    }
5883
5884    for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
5885    {
5886       DU_ALLOC(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
5887       if(!rsrcSetList->list.array[rSetIdx])
5888       {
5889          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5890          return RFAILED;
5891       }
5892    }
5893
5894    rSetIdx = 0;
5895    rsrcSetList->list.array[rSetIdx]->srs_ResourceSetId = SRS_RSET_ID;
5896
5897    /* Fill Resource Id list in resource set */
5898    rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList = NULLP;
5899    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
5900          sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
5901    if(!rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
5902    {
5903       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5904       return RFAILED;
5905    }
5906
5907    elementCnt = 1;
5908    rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
5909    rsrcIdList->list.count = elementCnt;
5910    rsrcIdList->list.size = elementCnt * sizeof(SRS_ResourceId_t *);
5911    rsrcIdList->list.array = NULLP;
5912    DU_ALLOC(rsrcIdList->list.array, rsrcIdList->list.size);
5913    if(!rsrcIdList->list.array)
5914    {
5915       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5916       return RFAILED;
5917    }
5918
5919    for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
5920    {
5921       DU_ALLOC(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
5922       if(!rsrcIdList->list.array[rsrcIdx])
5923       {
5924          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5925          return RFAILED;
5926       }
5927    }
5928
5929    rsrcIdx = 0;
5930    *rsrcIdList->list.array[rsrcIdx] = SRS_RSRC_ID;
5931
5932    /* Fill resource type */
5933    rsrcSetList->list.array[rSetIdx]->resourceType.present = \
5934                                                             SRS_ResourceSet__resourceType_PR_aperiodic;
5935
5936    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic = NULLP;
5937    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
5938          sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
5939    if(!rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic)
5940    {
5941       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5942       return RFAILED;
5943    }
5944    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->aperiodicSRS_ResourceTrigger \
5945       = APERIODIC_SRS_RESRC_TRIGGER;
5946
5947    /* TODO : Fill values for below IEs as expected by Viavi */
5948    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->csi_RS = NULLP;
5949    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->slotOffset = NULLP;
5950
5951
5952    rsrcSetList->list.array[rSetIdx]->usage = SRS_ResourceSet__usage_codebook;
5953    rsrcSetList->list.array[rSetIdx]->alpha = NULLP;
5954    rsrcSetList->list.array[rSetIdx]->p0 = NULLP;
5955    rsrcSetList->list.array[rSetIdx]->pathlossReferenceRS = NULLP;
5956    rsrcSetList->list.array[rSetIdx]->srs_PowerControlAdjustmentStates = NULLP;
5957
5958    return ROK;
5959 }
5960
5961 /*******************************************************************
5962  *
5963  * @brief Builds BWP UL dedicated SRS Config
5964  *
5965  * @details
5966  *
5967  *    Function : BuildBWPUlDedSrsCfg
5968  *
5969  *    Functionality: Builds BWP UL dedicated SRS Config
5970  *
5971  * @params[in] SRS Config 
5972  * @return ROK     - success
5973  *         RFAILED - failure
5974  *
5975  * ****************************************************************/
5976 uint8_t BuildBWPUlDedSrsCfg(SRS_Config_t *srsCfg)
5977 {
5978    srsCfg->srs_ResourceSetToReleaseList = NULLP;
5979    srsCfg->srs_ResourceSetToAddModList = NULLP;
5980    DU_ALLOC(srsCfg->srs_ResourceSetToAddModList, \
5981          sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
5982    if(!srsCfg->srs_ResourceSetToAddModList)
5983    {
5984       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5985       return RFAILED;
5986    }
5987    if(BuildSrsRsrcSetAddModList(srsCfg->srs_ResourceSetToAddModList) != ROK)
5988    {
5989       return RFAILED;
5990    }
5991
5992    srsCfg->srs_ResourceToReleaseList = NULLP;
5993
5994    /* Resource to Add/Modify list */
5995    srsCfg->srs_ResourceToAddModList = NULLP;
5996    DU_ALLOC(srsCfg->srs_ResourceToAddModList, \
5997          sizeof(struct SRS_Config__srs_ResourceToAddModList));
5998    if(!srsCfg->srs_ResourceToAddModList)
5999    {
6000       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
6001       return RFAILED;
6002    }
6003
6004    if(BuildSrsRsrcAddModList(srsCfg->srs_ResourceToAddModList) != ROK)
6005    {
6006       return RFAILED;
6007    }
6008    srsCfg->tpc_Accumulation = NULLP;
6009
6010    return ROK;
6011 }
6012
6013
6014
6015 /*******************************************************************
6016  *
6017  * @brief Builds Pusch Serving cell Config
6018  *
6019  * @details
6020  *
6021  *    Function : BuildPuschSrvCellCfg
6022  *
6023  *    Functionality: Builds Pusch Serving cell Config
6024  *
6025  * @params[in] struct UplinkConfig__pusch_ServingCellConfig *puschCfg
6026  *
6027  * @return ROK     - success
6028  *         RFAILED - failure
6029  *
6030  * ****************************************************************/
6031 uint8_t BuildPuschSrvCellCfg(struct UplinkConfig__pusch_ServingCellConfig *puschCfg)
6032 {
6033    puschCfg->present = UplinkConfig__pusch_ServingCellConfig_PR_setup;
6034    puschCfg->choice.setup = NULLP;
6035    DU_ALLOC(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
6036    if(!puschCfg->choice.setup)
6037    {
6038       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
6039       return RFAILED;
6040    }
6041
6042    puschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
6043    puschCfg->choice.setup->rateMatching = NULLP;
6044    puschCfg->choice.setup->xOverhead = NULLP;
6045    puschCfg->choice.setup->ext1 = NULLP;
6046
6047    DU_ALLOC(puschCfg->choice.setup->ext1, sizeof(struct PUSCH_ServingCellConfig__ext1));
6048    if(!puschCfg->choice.setup->ext1)
6049    {
6050       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
6051       return RFAILED;
6052    }
6053
6054    puschCfg->choice.setup->ext1->maxMIMO_Layers = NULLP;
6055    DU_ALLOC(puschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
6056    if(!puschCfg->choice.setup->ext1->maxMIMO_Layers)
6057    {
6058       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
6059       return RFAILED;
6060    }
6061    *(puschCfg->choice.setup->ext1->maxMIMO_Layers) = PUSCH_MAX_MIMO_LAYERS;
6062
6063    puschCfg->choice.setup->ext1->processingType2Enabled= NULLP;
6064    DU_ALLOC(puschCfg->choice.setup->ext1->processingType2Enabled,sizeof(BOOLEAN_t));
6065    if(!puschCfg->choice.setup->ext1->processingType2Enabled)
6066    {
6067       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
6068       return RFAILED;
6069    }
6070    *(puschCfg->choice.setup->ext1->processingType2Enabled) = PUSCH_PROCESS_TYPE2_ENABLED;
6071
6072    return ROK;
6073 }
6074
6075 /*******************************************************************
6076  *
6077  * @brief Builds inital UL BWP
6078  *
6079  * @details
6080  *
6081  *    Function : BuildInitialUlBWP
6082  *
6083  *    Functionality: Builds initial UL BWP
6084  *
6085  * @params[in] BWP_UplinkDedicated_t *ulBwp
6086  * @return ROK     - success
6087  *         RFAILED - failure
6088  *
6089  * ****************************************************************/
6090 uint8_t BuildInitialUlBWP(InitialUlBwp *initUlBwp, BWP_UplinkDedicated_t *ulBwp)
6091 {
6092    PucchCfg *pucchCfg = NULLP;
6093    PuschCfg *puschCfg = NULLP;
6094
6095    if(initUlBwp)
6096    {
6097       if(initUlBwp->pucchPresent)
6098          pucchCfg = &initUlBwp->pucchCfg;
6099       if(initUlBwp->puschPresent)
6100          puschCfg = &initUlBwp->puschCfg;
6101    }
6102
6103    ulBwp->pucch_Config = NULLP;
6104    DU_ALLOC(ulBwp->pucch_Config, sizeof(struct BWP_UplinkDedicated__pucch_Config));
6105    if(!ulBwp->pucch_Config)
6106    {
6107       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6108       return RFAILED;
6109    }
6110
6111    ulBwp->pucch_Config->present = BWP_UplinkDedicated__pucch_Config_PR_setup;
6112    ulBwp->pucch_Config->choice.setup = NULLP;
6113    DU_ALLOC(ulBwp->pucch_Config->choice.setup, sizeof(PUCCH_Config_t));
6114    if(!ulBwp->pucch_Config->choice.setup)
6115    {
6116       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6117       return RFAILED;
6118    }
6119
6120    if(BuildBWPUlDedPucchCfg(pucchCfg, ulBwp->pucch_Config->choice.setup) != ROK)
6121    {
6122       return RFAILED;
6123    }
6124
6125    /* Fill BWP UL dedicated PUSCH config */
6126    ulBwp->pusch_Config = NULLP;
6127    DU_ALLOC(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
6128    if(!ulBwp->pusch_Config)
6129    {
6130       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6131       return RFAILED;
6132    }
6133
6134    ulBwp->pusch_Config->present = BWP_UplinkDedicated__pusch_Config_PR_setup;
6135    ulBwp->pusch_Config->choice.setup = NULLP;
6136    DU_ALLOC(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
6137    if(!ulBwp->pusch_Config->choice.setup)
6138    {
6139       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6140       return RFAILED;
6141    }
6142
6143    if(BuildBWPUlDedPuschCfg(puschCfg, ulBwp->pusch_Config->choice.setup) != ROK)
6144    {
6145       return RFAILED;
6146    }
6147
6148    ulBwp->configuredGrantConfig = NULLP;
6149
6150    /* Fill BPW UL dedicated SRS config */
6151    ulBwp->srs_Config = NULLP;
6152    DU_ALLOC(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
6153    if(!ulBwp->srs_Config)
6154    {
6155       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6156       return RFAILED;
6157    }
6158
6159    ulBwp->srs_Config->present = BWP_UplinkDedicated__srs_Config_PR_setup;
6160    ulBwp->srs_Config->choice.setup = NULLP;
6161    DU_ALLOC(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
6162    if(!ulBwp->srs_Config->choice.setup)
6163    {
6164       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6165       return RFAILED;
6166    }
6167
6168    if(BuildBWPUlDedSrsCfg(ulBwp->srs_Config->choice.setup) != ROK)
6169    {
6170       return RFAILED;   
6171    }
6172
6173    ulBwp->beamFailureRecoveryConfig = NULLP;
6174
6175    return ROK;
6176 }
6177
6178 /*******************************************************************
6179  *
6180  * @brief Builds UL config
6181  * @details
6182  *
6183  *    Function : BuildUlCfg 
6184  *
6185  *    Functionality: Builds UL config in spCellCfgDed
6186  *
6187  * @params[in] UplinkConfig_t *ulCfg
6188  *
6189  * @return ROK     - success
6190  *         RFAILED - failure
6191  *
6192  * ****************************************************************/
6193 uint8_t BuildUlCfg(ServCellRecfgInfo *servCellRecfg, UplinkConfig_t *ulCfg)
6194 {
6195    InitialUlBwp *initUlBwp = NULLP;
6196
6197    if(servCellRecfg)
6198    {
6199       initUlBwp = &servCellRecfg->initUlBwp;
6200    }
6201
6202    ulCfg->initialUplinkBWP = NULLP;
6203    DU_ALLOC(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
6204    if(!ulCfg->initialUplinkBWP)
6205    {
6206       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6207       return RFAILED;
6208    }
6209
6210    if(BuildInitialUlBWP(initUlBwp, ulCfg->initialUplinkBWP) != ROK)
6211    {
6212       return RFAILED;
6213    }
6214
6215    ulCfg->uplinkBWP_ToReleaseList = NULLP;
6216    ulCfg->uplinkBWP_ToAddModList = NULLP;
6217    ulCfg->firstActiveUplinkBWP_Id = NULLP;
6218    DU_ALLOC(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
6219    if(!ulCfg->firstActiveUplinkBWP_Id)
6220    {
6221       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6222       return RFAILED;
6223    }
6224    if(servCellRecfg == NULLP)
6225       *(ulCfg->firstActiveUplinkBWP_Id) = ACTIVE_UL_BWP_ID;
6226    else
6227       *(ulCfg->firstActiveUplinkBWP_Id) = servCellRecfg->firstActvUlBwpId;
6228
6229    ulCfg->pusch_ServingCellConfig = NULLP;
6230    DU_ALLOC(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
6231    if(!ulCfg->pusch_ServingCellConfig)
6232    {
6233       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6234       return RFAILED;
6235    }
6236
6237    if(BuildPuschSrvCellCfg(ulCfg->pusch_ServingCellConfig) != ROK)
6238    {
6239       return RFAILED;
6240    }
6241
6242    ulCfg->carrierSwitching = NULLP;
6243    ulCfg->ext1 = NULLP;
6244    return ROK;
6245 }
6246
6247 /*******************************************************************
6248  *
6249  * @brief Builds PDSCH serving cell config
6250  * @details
6251  *
6252  *    Function : BuildPdschSrvCellCfg
6253  *
6254  *    Functionality: Builds PDSCH serving cell config in spCellCfgDed
6255  *
6256  * @params[in] struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg 
6257  *
6258  * @return ROK     - success
6259  *         RFAILED - failure
6260  *
6261  * ****************************************************************/
6262 uint8_t BuildPdschSrvCellCfg(PdschServCellCfg *pdschServCellDb, struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg)
6263 {
6264    pdschCfg->present =  ServingCellConfig__pdsch_ServingCellConfig_PR_setup;
6265    pdschCfg->choice.setup = NULLP;
6266    DU_ALLOC(pdschCfg->choice.setup, sizeof( struct PDSCH_ServingCellConfig));
6267    if(!pdschCfg->choice.setup)
6268    {
6269       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6270       return RFAILED;
6271    }
6272
6273    /* Code Block Group Transmission */
6274    pdschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
6275    if(pdschServCellDb && (pdschServCellDb->maxCodeBlkGrpPerTb || pdschServCellDb->codeBlkGrpFlushInd))
6276    {
6277       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission, sizeof(struct PDSCH_ServingCellConfig__codeBlockGroupTransmission));
6278       if(pdschCfg->choice.setup->codeBlockGroupTransmission == NULLP)
6279       {
6280          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6281          return RFAILED;
6282       }
6283
6284       pdschCfg->choice.setup->codeBlockGroupTransmission->present = PDSCH_ServingCellConfig__codeBlockGroupTransmission_PR_setup;
6285       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup = NULLP;
6286       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup, sizeof(struct PDSCH_CodeBlockGroupTransmission ));
6287       if(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup == NULLP)
6288       {
6289          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6290          return RFAILED;
6291       }
6292
6293       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock = \
6294          *(pdschServCellDb->maxCodeBlkGrpPerTb);
6295       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator = \
6296          *(pdschServCellDb->codeBlkGrpFlushInd);
6297    }
6298
6299    /* xOverhead */
6300    pdschCfg->choice.setup->xOverhead = NULLP;
6301    if(pdschServCellDb && pdschServCellDb->xOverhead)
6302    {
6303       DU_ALLOC(pdschCfg->choice.setup->xOverhead, sizeof(long));
6304       if(pdschCfg->choice.setup->xOverhead == NULLP)
6305       {
6306          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6307          return RFAILED;
6308       }
6309       *(pdschCfg->choice.setup->xOverhead) = *(pdschServCellDb->xOverhead);
6310    }
6311
6312    /* Number of HARQ processes */
6313    pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH = NULLP;
6314    DU_ALLOC(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH, sizeof(long));
6315    if(!pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH)
6316    {
6317       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6318       return RFAILED;
6319    }
6320
6321    if(pdschServCellDb == NULLP)
6322    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = PDSCH_NUM_HARQ_PROC;
6323    else
6324    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = pdschServCellDb->numHarqProcForPdsch;
6325
6326    pdschCfg->choice.setup->pucch_Cell = NULLP;
6327
6328    /* Extension */
6329    pdschCfg->choice.setup->ext1 = NULLP;
6330    if(pdschServCellDb && pdschServCellDb->maxMimoLayers)
6331    {
6332       DU_ALLOC(pdschCfg->choice.setup->ext1, sizeof(struct PDSCH_ServingCellConfig__ext1));
6333       if(pdschCfg->choice.setup->ext1 == NULLP)
6334       {
6335          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6336          return RFAILED;
6337       }
6338
6339       DU_ALLOC(pdschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
6340       if(pdschCfg->choice.setup->ext1->maxMIMO_Layers == NULLP)
6341       {
6342          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6343          return RFAILED;
6344       }
6345       *(pdschCfg->choice.setup->ext1->maxMIMO_Layers) = *(pdschServCellDb->maxMimoLayers);
6346    }
6347
6348    return ROK;
6349 }
6350
6351 /*******************************************************************
6352  *
6353  * @brief Builds CSI Meas config
6354  * @details
6355  *
6356  *    Function : BuildCsiMeasCfg 
6357  *
6358  *    Functionality: Builds CSI Meas config in spCellCfgDed
6359  *
6360  * @params[in] struct ServingCellConfig__csi_MeasConfig *csiMeasCfg
6361  *
6362  * @return ROK     - success
6363  *         RFAILED - failure
6364  *
6365  * ****************************************************************/
6366 uint8_t BuildCsiMeasCfg(struct ServingCellConfig__csi_MeasConfig *csiMeasCfg)
6367 {
6368
6369    return ROK;
6370 }
6371
6372 /*******************************************************************
6373  *
6374  * @brief Builds DL BWP to add/modify list
6375  * @details
6376  *
6377  *    Function : BuildDlBwpToAddModList
6378  *
6379  *    Functionality: Builds DL BWP to add/modify list
6380  *
6381  * @params[in] ServCellRecfgInfo *servCellRecfg, 
6382  *             struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList
6383  *
6384  * @return ROK     - success
6385  *         RFAILED - failure
6386  *
6387  * ****************************************************************/ 
6388 uint8_t BuildDlBwpToAddModList(ServCellRecfgInfo *servCellRecfg, struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList)
6389 {
6390    uint8_t elementCnt, idx;
6391
6392    elementCnt = servCellRecfg->numDlBwpToAddOrMod;
6393    dlBwpAddModList->list.count = elementCnt;
6394    dlBwpAddModList->list.size = elementCnt * sizeof(struct BWP_Downlink *);
6395    dlBwpAddModList->list.array = NULLP;
6396    DU_ALLOC(dlBwpAddModList->list.array, dlBwpAddModList->list.size);
6397    if(dlBwpAddModList->list.array == NULLP)
6398    {
6399       DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6400       return RFAILED;
6401    }
6402
6403    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6404    {
6405       DU_ALLOC(dlBwpAddModList->list.array[idx], sizeof(BWP_Downlink_t));
6406       if(dlBwpAddModList->list.array[idx] == NULLP)
6407       {
6408          DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6409          return RFAILED;
6410       }
6411    }
6412
6413    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6414    {
6415       dlBwpAddModList->list.array[idx]->bwp_Id = servCellRecfg->dlBwpToAddOrModList[idx].bwpId;
6416       dlBwpAddModList->list.array[idx]->bwp_Common = NULLP;
6417       dlBwpAddModList->list.array[idx]->bwp_Dedicated = NULLP;
6418    }
6419    return ROK;
6420 }
6421
6422 /*******************************************************************
6423  *
6424  * @brief Builds Spcell config dedicated
6425  * @details
6426  *
6427  *    Function : BuildSpCellCfgDed
6428  *
6429  *    Functionality: Builds sp cell config dedicated in spCellCfg
6430  *
6431  * @params[in] ServingCellConfig_t srvCellCfg
6432  *
6433  * @return ROK     - success
6434  *         RFAILED - failure
6435  *
6436  * ****************************************************************/
6437 uint8_t BuildSpCellCfgDed(DuUeCb *ueCb, ServingCellConfig_t *srvCellCfg)
6438 {
6439    ServCellRecfgInfo *servCellRecfg = NULLP;
6440    InitialDlBwp *initDlBwp = NULLP;
6441    PdschServCellCfg *pdschServCellDb = NULLP;
6442
6443    if(ueCb)
6444    {
6445       servCellRecfg = &ueCb->duMacUeCfg.spCellCfg.servCellCfg;
6446       initDlBwp = &servCellRecfg->initDlBwp;
6447       pdschServCellDb = &servCellRecfg->pdschServCellCfg;
6448    }
6449
6450    srvCellCfg->tdd_UL_DL_ConfigurationDedicated = NULLP;
6451
6452    srvCellCfg->initialDownlinkBWP = NULLP;
6453    DU_ALLOC(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
6454    if(!srvCellCfg->initialDownlinkBWP)
6455    {
6456       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6457       return RFAILED;
6458    }
6459
6460    if(BuildInitialDlBWP(initDlBwp, srvCellCfg->initialDownlinkBWP) != ROK)
6461    {
6462       DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6463       return RFAILED;
6464    }
6465
6466    srvCellCfg->downlinkBWP_ToReleaseList = NULLP;
6467
6468    srvCellCfg->downlinkBWP_ToAddModList = NULLP;
6469    if(ueCb && ueCb->duMacUeCfg.spCellCfg.servCellCfg.numDlBwpToAddOrMod)
6470    {
6471       DU_ALLOC(srvCellCfg->downlinkBWP_ToAddModList, sizeof(struct ServingCellConfig__downlinkBWP_ToAddModList));
6472       if(srvCellCfg->downlinkBWP_ToAddModList == NULLP)
6473       {
6474          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6475          return RFAILED;
6476       }
6477
6478       if(BuildDlBwpToAddModList(&ueCb->duMacUeCfg.spCellCfg.servCellCfg, srvCellCfg->downlinkBWP_ToAddModList) != ROK)
6479       {
6480          DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6481          return RFAILED;
6482       }
6483    }
6484
6485    srvCellCfg->firstActiveDownlinkBWP_Id = NULLP;
6486    DU_ALLOC(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
6487    if(!srvCellCfg->firstActiveDownlinkBWP_Id)
6488    {
6489       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6490       return RFAILED;
6491    }
6492    if(ueCb == NULLP)
6493       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6494    else
6495       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.firstActvDlBwpId;
6496
6497    srvCellCfg->bwp_InactivityTimer = NULLP;
6498
6499    srvCellCfg->defaultDownlinkBWP_Id = NULLP;
6500    DU_ALLOC(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
6501    if(!srvCellCfg->defaultDownlinkBWP_Id)
6502    {
6503       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6504       return RFAILED;
6505    }
6506    if(ueCb == NULLP)
6507       *(srvCellCfg->defaultDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6508    else
6509       *(srvCellCfg->defaultDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.defaultDlBwpId;
6510
6511    srvCellCfg->uplinkConfig = NULLP;
6512    DU_ALLOC(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));
6513    if(!srvCellCfg->uplinkConfig)
6514    {
6515       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6516       return RFAILED;
6517    }
6518
6519    if(BuildUlCfg(servCellRecfg, srvCellCfg->uplinkConfig) != ROK)
6520    {
6521       DU_LOG("\nERROR  -->  F1AP : BuildUlCfg failed");
6522       return RFAILED;
6523    }
6524    srvCellCfg->supplementaryUplink = NULLP;
6525    srvCellCfg->pdcch_ServingCellConfig = NULLP;
6526
6527    srvCellCfg->pdsch_ServingCellConfig = NULLP;
6528    DU_ALLOC(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct  ServingCellConfig__pdsch_ServingCellConfig));
6529    if(!srvCellCfg->pdsch_ServingCellConfig)
6530    {
6531       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6532       return RFAILED;
6533    }
6534
6535    if(BuildPdschSrvCellCfg(pdschServCellDb, srvCellCfg->pdsch_ServingCellConfig) != ROK)
6536    {
6537       DU_LOG("\nERROR  -->  F1AP : BuildPdschSrvCellCfg failed");
6538       return RFAILED;
6539    }
6540
6541    srvCellCfg->csi_MeasConfig = NULLP;
6542 #if 0
6543    DU_ALLOC(srvCellCfg->csi_MeasConfig, sizeof(struct   ServingCellConfig__csi_MeasConfig))
6544       if(!srvCellCfg->csi_MeasConfig)
6545       {
6546          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6547          return RFAILED;
6548       }
6549
6550    if(BuildCsiMeasCfg(srvCellCfg->csi_MeasConfig) != ROK)
6551    {
6552       DU_LOG("\nF1AP : BuildCsiMeasCfg failed");
6553       return RFAILED;
6554    }
6555 #endif
6556    srvCellCfg->sCellDeactivationTimer = NULLP;
6557    srvCellCfg->crossCarrierSchedulingConfig = NULLP;
6558    srvCellCfg->tag_Id = TAG_ID;
6559    srvCellCfg->dummy = NULLP;
6560    srvCellCfg->pathlossReferenceLinking = NULLP;
6561    srvCellCfg->servingCellMO = NULLP;
6562    srvCellCfg->ext1 = NULLP;
6563
6564    return ROK;
6565 }
6566
6567 /*******************************************************************
6568  *
6569  * @brief Fills SCS specific carrier list in DL frequency info
6570  *
6571  * @details
6572  *
6573  *    Function : BuildScsSpecificCarrierListDl
6574  *
6575  *    Functionality: Fills SCS specific carrier list in DL frequency info
6576  *
6577  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
6578  *
6579  * @return ROK     - success
6580  *         RFAILED - failure
6581  *
6582  * ****************************************************************/
6583 uint8_t BuildScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
6584 {
6585    uint8_t elementCnt = 0, listIdx = 0;
6586    ScsSpecCarrier duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.dlScsCarrier;
6587
6588    elementCnt = ODU_VALUE_ONE;
6589    scsCarrierList->list.count = elementCnt;
6590    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6591
6592    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6593    if(!scsCarrierList->list.array)
6594    {
6595       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for scs carrier list array \
6596          in BuildScsSpecificCarrierListDl()");
6597       return RFAILED;
6598    }
6599
6600    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6601    {
6602       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6603       if(!scsCarrierList->list.array[listIdx])
6604       {    
6605          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SCS Specific Carrier list array \
6606             element in BuildScsSpecificCarrierListDl()");
6607          return RFAILED;
6608       }    
6609    }
6610
6611    listIdx = 0;
6612    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6613    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6614    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6615
6616    return ROK;
6617 }
6618
6619 /*******************************************************************
6620  *
6621  * @brief Fills DL frequency info in DL config common
6622  *
6623  * @details
6624  *
6625  *    Function : BuildFreqInfoDl
6626  *
6627  *    Functionality: Fills DL frequency info in DL config common
6628  *
6629  * @params[in] Pointer to DownlinkConfigCommon_t
6630  *
6631  * @return ROK     - success
6632  *         RFAILED - failure
6633  *
6634  * ****************************************************************/
6635 uint8_t BuildFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
6636 {
6637    uint8_t freqBandIdx = 0, elementCnt = 0;
6638    DlCfgCommon  dlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg;
6639
6640    /* TODO : Fill SSB Absolute Frequency */
6641    /*
6642       DU_ALLOC(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
6643       if(!frequencyInfoDL->absoluteFrequencySSB)
6644       {
6645       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB Absolute Frequency in BuildFreqInfoDl()");
6646       return RFAILED;
6647       }
6648       frequencyInfoDL->absoluteFrequencySSB = ?;
6649       */
6650
6651    /* NR Multi Frequency Band List */
6652    elementCnt = ODU_VALUE_ONE;
6653    frequencyInfoDL->frequencyBandList.list.count = elementCnt;
6654    frequencyInfoDL->frequencyBandList.list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6655
6656    DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
6657    if(!frequencyInfoDL->frequencyBandList.list.array)
6658    {
6659       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for Frequency Band List array in BuildFreqInfoDl()");
6660       return RFAILED;
6661    }
6662
6663    for(freqBandIdx = 0; freqBandIdx < elementCnt; freqBandIdx++)
6664    {
6665       DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
6666       if(!frequencyInfoDL->frequencyBandList.list.array[freqBandIdx])
6667       {
6668          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoDl()");
6669          return RFAILED;
6670       }
6671    }
6672
6673    freqBandIdx = 0;
6674    *(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx]) = dlCfg.freqBandInd;
6675
6676    /* TODO : Absolute Frequency to Point A */
6677    //frequencyInfoDL->absoluteFrequencyPointA
6678
6679    /* Subcarrier Spacing specifc carrier List */
6680    if((BuildScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList)) != ROK)
6681    {
6682       DU_LOG("\nERROR  -->  DU APP : Failed to fill SCS specific carrier list DL in BuildFreqInfoDl()");
6683       return RFAILED;
6684    }
6685
6686    return ROK;
6687
6688 }
6689
6690 /*******************************************************************
6691  *
6692  * @brief Fills DL config common in Serving cell config common
6693  *
6694  * @details
6695  *
6696  *    Function : BuildDlConfigCommon
6697  *
6698  *    Functionality: Fills DL config common in Serving cell config common
6699  *
6700  * @params[in] Pointer to DownlinkConfigCommon_t
6701  *
6702  * @return ROK     - success
6703  *         RFAILED - failure
6704  *
6705  * ****************************************************************/
6706 uint8_t BuildDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
6707 {
6708    /* DL Frequency Info */
6709    DU_ALLOC(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
6710    if(!dlCfgCommon->frequencyInfoDL)
6711    {
6712       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL frequency info in BuildDlConfigCommon()");
6713       return RFAILED;
6714    }
6715    if((BuildFreqInfoDl(dlCfgCommon->frequencyInfoDL))!= ROK)
6716    {
6717       DU_LOG("\nERROR  --> DU APP : Failed to fill DL frequency info in BuildDlConfigCommon()");
6718       return RFAILED;
6719    }
6720
6721    /* DL BWP config common */
6722    DU_ALLOC(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
6723    if(!dlCfgCommon->initialDownlinkBWP)
6724    {
6725       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL BWP config common in BuildDlConfigCommon()");
6726       return RFAILED;
6727    }
6728    if((BuildBwpDlCommon(dlCfgCommon->initialDownlinkBWP)) != ROK)
6729    {
6730       DU_LOG("\nERROR  --> DU APP : Failed to fill DL DWP config common in BuildDlConfigCommon()");
6731       return RFAILED;
6732    }
6733
6734    return ROK;
6735 }
6736
6737 /*******************************************************************
6738  *
6739  * @brief Fills SCS specific carrier list in UL frequency Info
6740  *
6741  * @details
6742  *
6743  *    Function : BuildScsSpecificCarrierListUl
6744  *
6745  *    Functionality: Fills SCS specific carrier list in UL frequency Info
6746  *
6747  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
6748  *
6749  * @return ROK     - success
6750  *         RFAILED - failure
6751  *
6752  * ****************************************************************/
6753 uint8_t BuildScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
6754 {
6755    uint8_t elementCnt = 0, listIdx = 0; 
6756    ScsSpecCarrier   duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.ulScsCarrier;
6757
6758    elementCnt = ODU_VALUE_ONE;
6759    scsCarrierList->list.count = elementCnt;
6760    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6761
6762    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6763    if(!scsCarrierList->list.array)
6764    {
6765       DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6766       return RFAILED;
6767    }
6768
6769    for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
6770    {
6771       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6772       if(!scsCarrierList->list.array[listIdx])
6773       {    
6774          DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6775          return RFAILED;
6776       }    
6777    }
6778    listIdx = 0; 
6779    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6780    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6781    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6782
6783    return ROK;
6784 }
6785
6786 /*******************************************************************
6787  *
6788  * @brief Fills frequency info in UL config common
6789  *
6790  * @details
6791  *
6792  *    Function : BuildFreqInfoUl
6793  *
6794  *    Functionality: Fills frequency info in UL config common
6795  *
6796  * @params[in] Pointer to FrequencyInfoUL_t
6797  *
6798  * @return ROK     - success
6799  *         RFAILED - failure
6800  *
6801  * ****************************************************************/
6802 uint8_t BuildFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
6803 {
6804    uint8_t elementCnt = 0, listIdx= 0;
6805    UlCfgCommon  ulCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg;
6806
6807    /* NR Multi Frequency Band List */
6808    DU_ALLOC(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
6809    if(!frequencyInfoUL->frequencyBandList)
6810    {
6811       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band list in BuildFreqInfoUl()");
6812       return RFAILED;
6813    }
6814
6815    elementCnt = ODU_VALUE_ONE;
6816    frequencyInfoUL->frequencyBandList->list.count = elementCnt;
6817    frequencyInfoUL->frequencyBandList->list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6818
6819    DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
6820    if(!frequencyInfoUL->frequencyBandList->list.array)
6821    {
6822       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array in BuildFreqInfoUl()");
6823       return RFAILED;
6824    }
6825
6826    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6827    {
6828       DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
6829       if(!frequencyInfoUL->frequencyBandList->list.array[listIdx])
6830       {
6831          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoUl()");
6832          return RFAILED;
6833       }
6834    }
6835
6836    listIdx = 0;
6837    *(frequencyInfoUL->frequencyBandList->list.array[listIdx]) = ulCfg.freqBandInd;
6838
6839    /* TODO : Fill Absolute frequency point A */
6840    /*
6841       DU_ALLOC(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
6842       if(!frequencyInfoUL->absoluteFrequencyPointA)
6843       {
6844       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for absolute frequency point A in BuildFreqInfoUl()");
6845       return RFAILED;
6846       }
6847     *(frequencyInfoUL->absoluteFrequencyPointA) = ?;
6848     */
6849
6850    /* Subcarrier Spacing specifc carrier */
6851    if((BuildScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList)) != ROK) 
6852    {
6853       DU_LOG("\nERROR  --> DU APP : Failed to fill SCS Specific Carrier list UL in BuildFreqInfoUl()");
6854       return RFAILED;
6855    }
6856
6857    /* P-MAX */
6858    DU_ALLOC(frequencyInfoUL->p_Max, sizeof(P_Max_t));
6859    if(!frequencyInfoUL->p_Max)
6860    {
6861       DU_LOG("\nERROR  -->  DU APP : UL Frequency Infoo  memory allocation failure");
6862       return RFAILED;
6863    }
6864    *frequencyInfoUL->p_Max = ulCfg.pMax;
6865
6866    return ROK;
6867 }
6868
6869 /*******************************************************************
6870  *
6871  * @brief Fills UL config common in Serving cell config common
6872  *
6873  * @details
6874  *
6875  *    Function : BuildUlConfigCommon
6876  *
6877  *    Functionality: Fills UL config common in Serving cell config common
6878  *
6879  * @params[in] Pointer to UplinkConfigCommon_t
6880  *
6881  * @return ROK     - success
6882  *         RFAILED - failure
6883  *
6884  * ****************************************************************/
6885 uint8_t BuildUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
6886 {
6887    /* UL Frequency Info */
6888    DU_ALLOC(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
6889    if(!ulCfgCommon->frequencyInfoUL)
6890    {
6891       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for UL frequency info in BuildUlConfigCommon()");
6892       return RFAILED;
6893    }
6894
6895    if((BuildFreqInfoUl(ulCfgCommon->frequencyInfoUL)) != ROK)
6896    {
6897       DU_LOG("\nERROR  -->  DU APP : Failed to fill frequency info UL in BuildUlConfigCommon()");
6898       return RFAILED;
6899    }
6900
6901    /* UL BWP common */
6902    DU_ALLOC(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
6903    if(!ulCfgCommon->initialUplinkBWP)
6904    {
6905       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for initial UL BWP in BuildUlConfigCommon()");
6906       return RFAILED;
6907    }
6908
6909    if((BuildBwpUlCommon(ulCfgCommon->initialUplinkBWP)) != ROK)
6910    {
6911       DU_LOG("\nERROR  -->  DU APP : Failed to fill BWP UL common in BuildUlConfigCommon()");
6912       return RFAILED;
6913    }
6914
6915    /* Time Alignment timer */
6916    ulCfgCommon->dummy = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.timeAlignTimerComm;
6917
6918    return ROK;
6919 }
6920
6921 /*******************************************************************
6922  *
6923  * @brief Fills SSB position in burst in SP cell config common
6924  *
6925  * @details
6926  *
6927  *    Function : BuildSsbPosInBurst
6928  *
6929  *    Functionality: 
6930  *       Fills SSB position in burst in SP cell config common
6931  *
6932  * @params[in] Pointer to struct ServingCellConfigCommon__ssb_PositionsInBurst
6933  *
6934  * @return ROK     - success
6935  *         RFAILED - failure
6936  *
6937  * ****************************************************************/
6938 uint8_t BuildSsbPosInBurst(struct ServingCellConfigCommon__ssb_PositionsInBurst *ssbPosInBurst)
6939 {
6940    uint8_t bitStringSizeInBytes = 0;
6941
6942    ssbPosInBurst->present = ServingCellConfigCommon__ssb_PositionsInBurst_PR_mediumBitmap;
6943
6944    /* As per spec 38.331,in the definition of ServingCellConfigCommon */
6945    bitStringSizeInBytes = 1;
6946    ssbPosInBurst->choice.mediumBitmap.size = bitStringSizeInBytes * sizeof(uint8_t);
6947
6948    DU_ALLOC(ssbPosInBurst->choice.mediumBitmap.buf, ssbPosInBurst->choice.mediumBitmap.size);
6949    if(!ssbPosInBurst->choice.mediumBitmap.buf)
6950    {
6951       DU_LOG("\nERROR  -->  DU APP : Memory Allocation failed for medium bit map buffer in BuildSsbPosInBurst()");
6952       return RFAILED;
6953    }
6954
6955    if((fillBitString(&ssbPosInBurst->choice.mediumBitmap, 0, bitStringSizeInBytes, \
6956                duCfgParam.sib1Params.srvCellCfgCommSib.ssbPosInBurst)) != ROK)
6957    {
6958       DU_LOG("\nERROR  -->  DU APP : Failed to fill medium bit map in BuildSsbPosInBurst()");
6959       return RFAILED;
6960    }
6961
6962    return ROK;
6963 }
6964
6965 /*******************************************************************
6966  *
6967  * @brief Fills SP cell config common in Reconfig with Sync
6968  *
6969  * @details
6970  *
6971  *    Function : BuildSpCellConfigCommon
6972  *
6973  *    Functionality: Fills SP cell config common in Reconfig with Sync
6974  *
6975  * @params[in] Pointer to ServingCellConfigCommon_t
6976  *
6977  * @return ROK     - success
6978  *         RFAILED - failure
6979  *
6980  * ****************************************************************/
6981 uint8_t BuildSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
6982 {
6983    /* Physical Cell Identity */
6984    DU_ALLOC(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
6985    if(!spCellConfigCommon->physCellId)
6986    {
6987       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for physical cell id in BuildSpCellConfigCommon()");
6988       return RFAILED;
6989    } 
6990    *(spCellConfigCommon->physCellId) = NR_PCI;
6991
6992    /* Downlink Config Common */
6993    DU_ALLOC(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
6994    if(!spCellConfigCommon->downlinkConfigCommon)
6995    {
6996       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for DL Config Common in BuildSpCellConfigCommon()");
6997       return RFAILED;
6998    }
6999    if((BuildDlConfigCommon(spCellConfigCommon->downlinkConfigCommon)) != ROK)
7000    {
7001       DU_LOG("\nERROR  -->  DU APP : Failed to fill DL config commin in BuildSpCellConfigCommon()");
7002       return RFAILED;
7003    }
7004
7005    /* Uplinlink Config Common */
7006    DU_ALLOC(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
7007    if(!spCellConfigCommon->uplinkConfigCommon)
7008    {
7009       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for UL Config Common in BuildSpCellConfigCommon()");
7010       return RFAILED;
7011    }
7012    if((BuildUlConfigCommon(spCellConfigCommon->uplinkConfigCommon)) != ROK)
7013    {
7014       DU_LOG("\nERROR  -->  DU APP : Failed to fill UL config commin in BuildSpCellConfigCommon()");
7015       return RFAILED;
7016    }
7017
7018    /* Timing Advance offset */
7019    DU_ALLOC(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
7020    if(!spCellConfigCommon->n_TimingAdvanceOffset)
7021    {
7022       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for Timing Advance Offset in BuildSpCellConfigCommon()");
7023       return RFAILED;
7024    }
7025    *(spCellConfigCommon->n_TimingAdvanceOffset) = ServingCellConfigCommon__n_TimingAdvanceOffset_n0;
7026
7027    /* SSB Position In Burst */
7028    DU_ALLOC(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
7029    if(!spCellConfigCommon->ssb_PositionsInBurst)
7030    {
7031       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Position In Burst in BuildSpCellConfigCommon()");
7032       return RFAILED;
7033    }
7034    if((BuildSsbPosInBurst(spCellConfigCommon->ssb_PositionsInBurst)) != ROK)
7035    {
7036       DU_LOG("\nERROR  -->  DU APP : Failed to fill SSB Position In Burst in BuildSpCellConfigCommon()");
7037       return RFAILED;
7038    }
7039
7040    /* SSB Periodicity in Serving cell */
7041    DU_ALLOC(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
7042    if(!spCellConfigCommon->ssb_periodicityServingCell)
7043    {
7044       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Periodicity serving cell in \
7045          BuildSpCellConfigCommon()");
7046       return RFAILED;
7047    }
7048    *(spCellConfigCommon->ssb_periodicityServingCell) = \
7049       convertSsbPeriodicityValueToEnum(duCfgParam.sib1Params.srvCellCfgCommSib.ssbPrdServingCell);
7050
7051    /* DMRS Type A position */
7052    spCellConfigCommon->dmrs_TypeA_Position = convertDmrsTypeAPosValueToEnum(duCfgParam.macCellCfg.ssbCfg.dmrsTypeAPos);
7053
7054    /* SSB subcarrier spacing */
7055    DU_ALLOC(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
7056    if(!spCellConfigCommon->ssbSubcarrierSpacing)
7057    {
7058       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for sub-carrier spacing in BuildSpCellConfigCommon()");
7059       return RFAILED;
7060    }
7061    *(spCellConfigCommon->ssbSubcarrierSpacing) = duCfgParam.sib1Params.srvCellCfgCommSib.scs;
7062
7063    /* TDD UL-DL configuration common */
7064    DU_ALLOC(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
7065    if(!spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)
7066    {
7067       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for TDD UL-DL config common in BuildSpCellConfigCommon()");
7068       return RFAILED;
7069    }
7070    if((BuildTddUlDlCfgComm(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)) != ROK)
7071    {
7072       DU_LOG("\nERROR  -->  DU APP : Failed to fill TDD UL-DL config common in BuildSpCellConfigCommon()");
7073       return RFAILED;
7074    }
7075
7076    /* SS PBCH Block Power */
7077    spCellConfigCommon->ss_PBCH_BlockPower = duCfgParam.sib1Params.srvCellCfgCommSib.ssPbchBlockPwr;
7078
7079    return ROK;
7080 }
7081
7082 /*******************************************************************
7083  *
7084  * @brief Fills dedicated RACH configuration in Reconfiguration with sync
7085  *
7086  * @details
7087  *
7088  *    Function : BuildRecfgWithSync
7089  *
7090  *    Functionality: 
7091  *       Fills dedicated RACH configuration in Reconfiguration with sync
7092  *
7093  * @params[in] DU UE CB
7094  *             Pointer to Rach config dedicated struct
7095  *
7096  * @return ROK     - success
7097  *         RFAILED - failure
7098  *
7099  * ****************************************************************/
7100 uint8_t BuildRachConfigDedicated(DuUeCb *ueCb, struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
7101 {
7102    uint8_t elementCnt = 0, listIdx = 0;
7103    CFRA_t *cfra = NULLP;
7104    struct CFRA__resources__ssb *ssbResource = NULLP;
7105    RachCfgCommon duRachCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.rachCfg;
7106
7107    rachCfgDed->present = ReconfigurationWithSync__rach_ConfigDedicated_PR_uplink;
7108
7109    /* Uplink */
7110    DU_ALLOC(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
7111    if(!rachCfgDed->choice.uplink)
7112    {
7113       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for RACH uplink configuration in BuildRachConfigDedicated()");
7114       return RFAILED;
7115    }
7116
7117    /* CFRA : Contention free Random Access */
7118    DU_ALLOC(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
7119    if(!rachCfgDed->choice.uplink->cfra)
7120    {
7121       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA in BuildRachConfigDedicated()");
7122       return RFAILED;
7123    }
7124    cfra = rachCfgDed->choice.uplink->cfra;
7125
7126    /* CFRA occassions */
7127    DU_ALLOC(cfra->occasions, sizeof(struct CFRA__occasions));
7128    if(!cfra->occasions)
7129    {
7130       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA occassion in BuildRachConfigDedicated()");
7131       return RFAILED;
7132    }
7133
7134    /* CFRA occassions : RACH generic configuration */
7135    cfra->occasions->rach_ConfigGeneric.prach_ConfigurationIndex = duRachCfg.prachCfgIdx;
7136    cfra->occasions->rach_ConfigGeneric.msg1_FDM = duRachCfg.msg1Fdm;
7137    cfra->occasions->rach_ConfigGeneric.msg1_FrequencyStart = duRachCfg.msg1FreqStart;
7138    cfra->occasions->rach_ConfigGeneric.zeroCorrelationZoneConfig = duRachCfg.zeroCorrZoneCfg;
7139    cfra->occasions->rach_ConfigGeneric.preambleReceivedTargetPower = duRachCfg.preambleRcvdTgtPwr;
7140    cfra->occasions->rach_ConfigGeneric.preambleTransMax = duRachCfg.preambleTransMax;
7141    cfra->occasions->rach_ConfigGeneric.powerRampingStep = duRachCfg.pwrRampingStep;
7142    cfra->occasions->rach_ConfigGeneric.ra_ResponseWindow = duRachCfg.raRspWindow;
7143
7144    /* CFRA occassions : SSB per RACH occasion */
7145    DU_ALLOC(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
7146    if(!cfra->occasions->ssb_perRACH_Occasion)
7147    {
7148       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB per RACH occassion in BuildRachConfigDedicated()");
7149       return RFAILED;
7150    }
7151    *(cfra->occasions->ssb_perRACH_Occasion) = convertCFRASsbPerRachOccasionValueToEnum(duCfgParam.macCellCfg.prachCfg.ssbPerRach);
7152
7153    /* CFRA resource */
7154    cfra->resources.present = CFRA__resources_PR_ssb;
7155
7156    /* CFRA resource : SSB */
7157    DU_ALLOC(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
7158    if(!cfra->resources.choice.ssb)
7159    {
7160       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA resource - SSB in BuildRachConfigDedicated()");
7161       return RFAILED;
7162    }
7163    ssbResource = cfra->resources.choice.ssb;
7164
7165    /* CFRA SSB resource list */
7166    elementCnt = ueCb->cfraResource.numSsb;
7167    ssbResource->ssb_ResourceList.list.count = elementCnt;
7168    ssbResource->ssb_ResourceList.list.size = elementCnt * sizeof(CFRA_SSB_Resource_t *);
7169
7170    DU_ALLOC(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
7171    if(!ssbResource->ssb_ResourceList.list.array)
7172    {
7173       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list in BuildRachConfigDedicated()");
7174       return RFAILED;
7175    }
7176
7177    for(listIdx = 0; listIdx < elementCnt; listIdx++)
7178    {
7179       DU_ALLOC(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
7180       if(!ssbResource->ssb_ResourceList.list.array[listIdx])
7181       {
7182          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list element in BuildRachConfigDedicated()");  
7183          return RFAILED;
7184       }
7185       ssbResource->ssb_ResourceList.list.array[listIdx]->ssb = ueCb->cfraResource.ssbResource[listIdx].ssbIdx;
7186       ssbResource->ssb_ResourceList.list.array[listIdx]->ra_PreambleIndex = ueCb->cfraResource.ssbResource[listIdx].raPreambleIdx;
7187    }
7188
7189    return ROK;
7190 }
7191
7192 /*******************************************************************
7193  *
7194  * @brief Fills reconfiguration with sync in SP cell config
7195  *
7196  * @details
7197  *
7198  *    Function : BuildRecfgWithSync
7199  *
7200  *    Functionality: Fills reconfiguration with sync in SP cell config
7201  *
7202  * @params[in] DU UE CB
7203  *             Pointer to ReconfigurationWithSync_t
7204  *
7205  * @return ROK     - success
7206  *         RFAILED - failure
7207  *
7208  * ****************************************************************/
7209 uint8_t BuildRecfgWithSync(DuUeCb *ueCb, ReconfigurationWithSync_t *recfgWithSync)
7210 {
7211    /* SP Cell Config Common */  
7212    DU_ALLOC(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
7213    if(!recfgWithSync->spCellConfigCommon)
7214    {
7215       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for spCellConfigCommon in BuildRecfgWithSync()");
7216       return RFAILED;
7217    }
7218
7219    if((BuildSpCellConfigCommon(recfgWithSync->spCellConfigCommon)) != ROK)
7220    {
7221       DU_LOG("\nERROR  -->  DU APP : Failed to build SpCellConfigCommon in BuildRecfgWithSync()");
7222       return RFAILED;
7223    }
7224
7225    /* New UE Identity */
7226    recfgWithSync->newUE_Identity = ueCb->crnti;
7227
7228    /* T304 timer */
7229    recfgWithSync->t304 = ReconfigurationWithSync__t304_ms1000;
7230
7231    /* RACH configuration dedicated */
7232    DU_ALLOC(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
7233    if(!recfgWithSync->rach_ConfigDedicated)
7234    {
7235       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for RACH config dedicated in BuildRecfgWithSync()");
7236       return RFAILED;
7237    }
7238
7239    if((BuildRachConfigDedicated(ueCb, recfgWithSync->rach_ConfigDedicated)) != ROK)
7240    {
7241       DU_LOG("\nERROR  -->  DU APP : Failed to build RACH config dedicated in BuildRecfgWithSync()");
7242       return RFAILED;
7243    }
7244
7245    return ROK;
7246 }
7247
7248 /*******************************************************************
7249  *
7250  * @brief Builds Spcell config 
7251  *
7252  * @details
7253  *
7254  *    Function : BuildSpCellCfg 
7255  *
7256  *    Functionality: Builds sp cell config in DuToCuRrcContainer
7257  *
7258  * @params[in] SpCellConfig_t spCellCfg
7259  *
7260  * @return ROK     - success
7261  *         RFAILED - failure
7262  *
7263  * ****************************************************************/
7264 uint8_t BuildSpCellCfg(DuUeCb *ueCb, SpCellConfig_t *spCellCfg)
7265 {
7266    spCellCfg->servCellIndex = NULLP;
7267    DU_ALLOC(spCellCfg->servCellIndex, sizeof(long));
7268    if(!spCellCfg->servCellIndex)
7269    {
7270       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7271       return RFAILED;
7272    }
7273
7274    if(ueCb == NULLP)
7275       *(spCellCfg->servCellIndex) = SERV_CELL_IDX;
7276    else
7277       *(spCellCfg->servCellIndex) = ueCb->duMacUeCfg.spCellCfg.servCellIdx;
7278
7279    spCellCfg->reconfigurationWithSync = NULLP;
7280    if(ueCb && (ueCb->ueState == UE_HANDIN_IN_PROGRESS))
7281    {
7282       DU_ALLOC(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
7283       if(!spCellCfg->reconfigurationWithSync)
7284       {
7285          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7286          return RFAILED;
7287       }
7288
7289       if((BuildRecfgWithSync(ueCb, spCellCfg->reconfigurationWithSync)) != ROK)
7290       {
7291          DU_LOG("\nERROR  -->  F1AP : Building of reconfiguration with sync failed at BuildSpCellCfg");
7292          return RFAILED;
7293       }
7294    }
7295
7296    spCellCfg->rlf_TimersAndConstants = NULLP;
7297    spCellCfg->rlmInSyncOutOfSyncThreshold = NULLP;
7298
7299    DU_ALLOC(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
7300    if(!spCellCfg->rlmInSyncOutOfSyncThreshold)
7301    {
7302       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7303       return RFAILED;
7304    }
7305    *(spCellCfg->rlmInSyncOutOfSyncThreshold) = RLM_SYNC_OUT_SYNC_THRESHOLD;
7306
7307    spCellCfg->spCellConfigDedicated = NULLP;
7308    DU_ALLOC(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
7309    if(!spCellCfg->spCellConfigDedicated)
7310    {
7311       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7312       return RFAILED;
7313    }
7314    if(BuildSpCellCfgDed(ueCb, spCellCfg->spCellConfigDedicated) != ROK)
7315    {
7316       DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfgDed failed");
7317       return RFAILED;
7318    }
7319
7320    return ROK;
7321 }
7322
7323 /*******************************************************************
7324  *
7325  * @brief Builds Phy cell group config 
7326  *
7327  * @details
7328  *
7329  *    Function : BuildPhyCellGrpCfg 
7330  *
7331  *    Functionality: Builds Phy cell group config in DuToCuRrcContainer
7332  *
7333  * @params[in] PhysicalCellGroupConfig_t *phyCellGrpCfg 
7334  *
7335  * @return ROK     - success
7336  *         RFAILED - failure
7337  *
7338  * ****************************************************************/
7339 uint8_t BuildPhyCellGrpCfg(DuUeCb *ueCb, PhysicalCellGroupConfig_t *phyCellGrpCfg)
7340 {
7341    phyCellGrpCfg->harq_ACK_SpatialBundlingPUCCH = NULLP;
7342    phyCellGrpCfg->harq_ACK_SpatialBundlingPUSCH = NULLP;
7343
7344    phyCellGrpCfg->p_NR_FR1 = NULLP;
7345    DU_ALLOC(phyCellGrpCfg->p_NR_FR1, sizeof(long));
7346    if(!phyCellGrpCfg->p_NR_FR1)
7347    {
7348       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhyCellGrpCfg");
7349       return RFAILED;
7350    }
7351
7352    if(ueCb == NULLP)
7353    {
7354       *(phyCellGrpCfg->p_NR_FR1)             = P_NR_FR1;
7355       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = PDSCH_HARQ_ACK_CODEBOOK;
7356    }
7357    else
7358    {
7359       *(phyCellGrpCfg->p_NR_FR1) = ueCb->duMacUeCfg.phyCellGrpCfg.pNrFr1;
7360       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = ueCb->duMacUeCfg.phyCellGrpCfg.pdschHarqAckCodebook;
7361    }
7362
7363    phyCellGrpCfg->tpc_SRS_RNTI = NULLP;
7364    phyCellGrpCfg->tpc_PUCCH_RNTI = NULLP;
7365    phyCellGrpCfg->tpc_PUSCH_RNTI = NULLP;
7366    phyCellGrpCfg->sp_CSI_RNTI = NULLP;
7367    phyCellGrpCfg->cs_RNTI = NULLP;
7368    phyCellGrpCfg->ext1 = NULLP;
7369    phyCellGrpCfg->ext2 = NULLP;
7370
7371    return ROK;
7372 }
7373 #ifdef NR_DRX
7374 /*******************************************************************
7375  *
7376  * @brief fill long cycle offset value of drx
7377  *
7378  * @details
7379  *
7380  *    Function : fillLongCycleOffsetValFromDuCb 
7381  *
7382  *    Functionality: fill long cycle offset value of drx
7383  *
7384  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
7385  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
7386  *
7387  * @return ROK     - success
7388  *         RFAILED - failure
7389  *
7390  * ****************************************************************/
7391 void fillLongCycleOffsetValFromDuCb(DrxLongCycleStartOffset  drxLongCycleStartOffset,\
7392 struct DRX_ConfigRrc__drx_LongCycleStartOffset *drx_LongCycleStartOffset)
7393 {
7394    
7395    drx_LongCycleStartOffset->present = convertLongDrxCycleLengthValueToEnum(drxLongCycleStartOffset.drxLongCycleStartOffsetChoice); 
7396    switch(drx_LongCycleStartOffset->present)
7397    {
7398       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
7399          {
7400             drx_LongCycleStartOffset->choice.ms10 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7401             break;
7402          }
7403       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
7404          {
7405             drx_LongCycleStartOffset->choice.ms20 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7406             break;
7407          }
7408       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
7409          {
7410             drx_LongCycleStartOffset->choice.ms32 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7411             break;
7412          }
7413       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
7414          {
7415             drx_LongCycleStartOffset->choice.ms40 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7416             break;
7417          }
7418       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
7419          {
7420             drx_LongCycleStartOffset->choice.ms60 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7421             break;
7422          }
7423       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
7424          {
7425             drx_LongCycleStartOffset->choice.ms64 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7426             break;
7427          }
7428       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
7429          {
7430             drx_LongCycleStartOffset->choice.ms70 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7431             break;
7432          }
7433       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
7434          {
7435             drx_LongCycleStartOffset->choice.ms80 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7436             break;
7437          }
7438       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
7439          {
7440             drx_LongCycleStartOffset->choice.ms128 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7441             break;
7442          }
7443       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
7444          {
7445             drx_LongCycleStartOffset->choice.ms160 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7446             break;
7447          }
7448       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
7449          {
7450             drx_LongCycleStartOffset->choice.ms256 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7451             break;
7452          }
7453       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
7454          {
7455             drx_LongCycleStartOffset->choice.ms320 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7456             break;
7457          }
7458       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
7459          {
7460             drx_LongCycleStartOffset->choice.ms512 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7461             break;
7462          }
7463       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
7464          {
7465             drx_LongCycleStartOffset->choice.ms640 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7466             break;
7467          }
7468       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
7469          {
7470             drx_LongCycleStartOffset->choice.ms1024 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7471             break;
7472          }
7473       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
7474          {
7475             drx_LongCycleStartOffset->choice.ms1280 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7476             break;
7477          }
7478       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
7479          {
7480             drx_LongCycleStartOffset->choice.ms2048 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7481             break;
7482          }
7483       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
7484          {
7485             drx_LongCycleStartOffset->choice.ms2560 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7486             break;
7487          }
7488       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
7489          {
7490             drx_LongCycleStartOffset->choice.ms5120 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7491             break;
7492          }
7493       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
7494          {
7495             drx_LongCycleStartOffset->choice.ms10240 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7496             break;
7497          }
7498       default :
7499          break;
7500    }
7501 }
7502 /*******************************************************************
7503  *
7504  * @brief Builds drx config IE 
7505  *
7506  * @details
7507  *
7508  *    Function : BuildDrxConfigRrc 
7509  *
7510  *    Functionality: Build drx config in MacCellGrpCfg 
7511  *
7512  * @params[in] struct MAC_CellGroupConfig__drx_ConfigRrc 
7513  *
7514  * @return ROK     - success
7515  *         RFAILED - failure
7516  *
7517  * ****************************************************************/
7518 uint8_t BuildDrxConfigRrc(DuUeCb *ueCb, struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg)
7519 {
7520    drxCfg->present = MAC_CellGroupConfig__drx_ConfigRrc_PR_setup;
7521    DU_ALLOC(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
7522    if(!drxCfg->choice.setup)
7523    {
7524       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7525       return RFAILED;
7526    }
7527    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationTimerValInMs)
7528    {
7529       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds;
7530       drxCfg->choice.setup->drx_onDurationTimer.choice.milliSeconds = convertOnDurationTimerMilliSecondsValueToEnum(ueCb->duMacUeCfg.\
7531       macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationtimerValue.milliSeconds);
7532    }
7533    else
7534    {
7535       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds;
7536       drxCfg->choice.setup->drx_onDurationTimer.choice.subMilliSeconds = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7537       drxOnDurationTimer.onDurationtimerValue.subMilliSeconds;
7538    }
7539    drxCfg->choice.setup->drx_InactivityTimer = convertDrxInactivityTimerValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxInactivityTimer);
7540    drxCfg->choice.setup->drx_HARQ_RTT_TimerDL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerDl;
7541    drxCfg->choice.setup->drx_HARQ_RTT_TimerUL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerUl;
7542    drxCfg->choice.setup->drx_RetransmissionTimerDL = convertDrxRetransmissionTimerDlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7543    drxRetransmissionTimerDl);
7544    drxCfg->choice.setup->drx_RetransmissionTimerUL = convertDrxRetransmissionTimerUlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7545    drxRetransmissionTimerUl);
7546    drxCfg->choice.setup->drx_SlotOffset = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxSlotOffset;
7547    fillLongCycleOffsetValFromDuCb(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxLongCycleStartOffset, &drxCfg->choice.setup->drx_LongCycleStartOffset);
7548    
7549    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrxPres)
7550    {
7551       DU_ALLOC(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));
7552       if(drxCfg->choice.setup->shortDRX)
7553       {
7554          drxCfg->choice.setup->shortDRX->drx_ShortCycle = convertShortDrxCycleLengthValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7555          shortDrx.drxShortCycle);
7556          drxCfg->choice.setup->shortDRX->drx_ShortCycleTimer = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrx.drxShortCycleTimer;
7557       }
7558       else
7559       {
7560          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7561          return RFAILED;
7562       }
7563    }
7564    return ROK;
7565 }
7566 #endif
7567 /*******************************************************************
7568  *
7569  * @brief Builds Mac cell group config 
7570  *
7571  * @details
7572  *
7573  *    Function : BuildMacCellGrpCfg 
7574  *
7575  *    Functionality: Builds Mac cell group config in DuToCuRrcContainer
7576  *
7577  * @params[in] MAC_CellGroupConfig_t *macCellGrpCfg
7578  *
7579  * @return ROK     - success
7580  *         RFAILED - failure
7581  *
7582  * ****************************************************************/
7583 uint8_t BuildMacCellGrpCfg(DuUeCb *ueCb, MAC_CellGroupConfig_t *macCellGrpCfg)
7584 {
7585    macCellGrpCfg->drx_ConfigRrc = NULLP;
7586 #ifdef NR_DRX   
7587    if(ueCb)
7588    {
7589       DU_ALLOC(macCellGrpCfg->drx_ConfigRrc, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
7590       if(!macCellGrpCfg->drx_ConfigRrc)
7591       {
7592          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7593          return RFAILED;
7594       }
7595       if(BuildDrxConfigRrc(ueCb, macCellGrpCfg->drx_ConfigRrc) != ROK)
7596       {
7597          DU_LOG("\nERROR  -->  F1AP : failed to build drx config");
7598          return RFAILED;
7599       }
7600    }
7601 #endif
7602    macCellGrpCfg->schedulingRequestConfig = NULLP;
7603    DU_ALLOC(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
7604    if(!macCellGrpCfg->schedulingRequestConfig)
7605    {
7606       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7607       return RFAILED;
7608    }
7609
7610    if(BuildSchedulingReqConfig(ueCb, macCellGrpCfg->schedulingRequestConfig) != ROK)
7611    {
7612       DU_LOG("\nERROR  -->  F1AP : BuildSchedulingReqConfig failed");
7613       return RFAILED;
7614    }
7615
7616    macCellGrpCfg->bsr_Config = NULLP;
7617    DU_ALLOC(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
7618    if(!macCellGrpCfg->bsr_Config)
7619    {
7620       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7621       return RFAILED;
7622    }
7623
7624    if(BuildBsrConfig(ueCb, macCellGrpCfg->bsr_Config) != ROK)
7625    {
7626       DU_LOG("\nERROR  -->  F1AP : BuildBsrConfig failed");
7627       return RFAILED;
7628    }
7629
7630    macCellGrpCfg->tag_Config = NULLP;
7631    DU_ALLOC(macCellGrpCfg->tag_Config, sizeof(struct TAG_Config));
7632    if(!macCellGrpCfg->tag_Config)
7633    {
7634       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7635       return RFAILED;
7636    }
7637
7638    if(BuildTagConfig(ueCb, macCellGrpCfg->tag_Config) != ROK)
7639    {
7640       DU_LOG("\nERROR  -->  F1AP : BuildTagConfig failed");
7641       return RFAILED;
7642    }
7643
7644    macCellGrpCfg->phr_Config = NULLP;
7645    DU_ALLOC(macCellGrpCfg->phr_Config, sizeof(struct MAC_CellGroupConfig__phr_Config));
7646    if(!macCellGrpCfg->phr_Config)
7647    {
7648       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7649       return RFAILED;
7650    }
7651
7652    if(BuildPhrConfig(ueCb, macCellGrpCfg->phr_Config) != ROK)
7653    {
7654       DU_LOG("\nERROR  -->  F1AP : BuildPhrConfig failed");
7655       return RFAILED;
7656    }
7657
7658    macCellGrpCfg->skipUplinkTxDynamic = false;
7659    macCellGrpCfg->ext1 = NULLP;
7660
7661    return ROK;
7662 }
7663 /*******************************************************************
7664  *
7665  * @brief Frees memeory allocated for SearchSpcToAddModList
7666  *
7667  * @details
7668  *
7669  *    Function : FreeSearchSpcToAddModList
7670  *
7671  *    Functionality: Deallocating memory of SearchSpcToAddModList
7672  *
7673  * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
7674  *
7675  * @return void
7676  *
7677  4221 * ****************************************************************/
7678 void FreeSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
7679 {
7680    uint8_t idx1=0;
7681    uint8_t idx2=0;
7682    struct  SearchSpace *searchSpc=NULLP;
7683
7684    if(searchSpcList->list.array)
7685    {
7686       if(searchSpcList->list.array[idx2])
7687       {
7688          searchSpc = searchSpcList->list.array[idx2];
7689          if(searchSpc->controlResourceSetId)
7690          {
7691             if(searchSpc->monitoringSlotPeriodicityAndOffset)
7692             {
7693                if(searchSpc->monitoringSymbolsWithinSlot)
7694                {
7695                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
7696                   {
7697                      if(searchSpc->nrofCandidates)
7698                      {
7699                         if(searchSpc->searchSpaceType)
7700                         {
7701                            DU_FREE(searchSpc->searchSpaceType->choice.ue_Specific,\
7702                                  sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
7703                            DU_FREE(searchSpc->searchSpaceType, sizeof(struct
7704                                     SearchSpace__searchSpaceType));
7705                         }
7706                         DU_FREE(searchSpc->nrofCandidates,
7707                               sizeof(struct SearchSpace__nrofCandidates));
7708                      }
7709                      DU_FREE(searchSpc->monitoringSymbolsWithinSlot->buf, \
7710                            searchSpc->monitoringSymbolsWithinSlot->size);
7711                   }
7712                   DU_FREE(searchSpc->monitoringSymbolsWithinSlot,
7713                         sizeof(BIT_STRING_t));
7714                }
7715                DU_FREE(searchSpc->monitoringSlotPeriodicityAndOffset, \
7716                      sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
7717             }
7718             DU_FREE(searchSpc->controlResourceSetId,
7719                   sizeof(ControlResourceSetId_t));
7720          }
7721       }
7722       for(idx1 = 0; idx1 < searchSpcList->list.count; idx1++)
7723       {
7724          DU_FREE(searchSpcList->list.array[idx1],
7725                sizeof(struct SearchSpace));
7726       }
7727       DU_FREE(searchSpcList->list.array,searchSpcList->list.size);
7728    }
7729 }
7730 /*******************************************************************
7731  *
7732  * @brief Frees memory allocated for PdschTimeDomAllocList
7733  *
7734  * @details
7735  *
7736  *    Function : FreePdschTimeDomAllocList
7737  *
7738  *    Functionality: Deallocating memory of PdschTimeDomAllocList
7739  *
7740  * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
7741  *
7742  * @return void
7743  *
7744  * ****************************************************************/
7745 void FreePdschTimeDomAllocList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
7746 {
7747    uint8_t idx1=0;
7748
7749    if(timeDomAllocList->choice.setup)
7750    {
7751       if(timeDomAllocList->choice.setup->list.array)
7752       {
7753          for(idx1 = 0; idx1 <timeDomAllocList->choice.setup->list.count ; idx1++)
7754          {
7755             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1]->k0, sizeof(long));
7756             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1],
7757                   sizeof(struct PDSCH_TimeDomainResourceAllocation));
7758          }
7759          DU_FREE(timeDomAllocList->choice.setup->list.array, \
7760                timeDomAllocList->choice.setup->list.size);
7761       }
7762       DU_FREE(timeDomAllocList->choice.setup,\
7763             sizeof(struct PDSCH_TimeDomainResourceAllocationList));
7764    }
7765 }
7766 /*******************************************************************
7767  *
7768  * @brief Frees memory allocated for PuschTimeDomAllocList
7769  *
7770  *@details
7771  *
7772  *    Function : FreePuschTimeDomAllocList
7773  *
7774  *    Functionality: Deallocating memory of PuschTimeDomAllocList
7775  *
7776  * @params[in] PUSCH_Config_t *puschCfg
7777  *
7778  * @return void
7779  *
7780  * ****************************************************************/
7781 void FreePuschTimeDomAllocList(PUSCH_Config_t *puschCfg)
7782 {
7783    uint8_t rsrcListIdx=0;
7784    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
7785
7786    if(puschCfg->pusch_TimeDomainAllocationList)
7787    {
7788       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
7789       if(timeDomAllocList_t->choice.setup)
7790       {
7791          if(timeDomAllocList_t->choice.setup->list.array)
7792          {
7793             for(rsrcListIdx = 0; rsrcListIdx<timeDomAllocList_t->choice.setup->list.count; rsrcListIdx++)
7794             {
7795                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx]->k2, sizeof(long));
7796                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx],\
7797                      sizeof(PUSCH_TimeDomainResourceAllocation_t));
7798             }
7799             DU_FREE(timeDomAllocList_t->choice.setup->list.array, \
7800                   timeDomAllocList_t->choice.setup->list.size);
7801          }
7802          DU_FREE(timeDomAllocList_t->choice.setup, \
7803                sizeof(struct PUSCH_TimeDomainResourceAllocationList));
7804       }
7805       DU_FREE(puschCfg->transformPrecoder, sizeof(long));
7806       DU_FREE(puschCfg->pusch_TimeDomainAllocationList, \
7807             sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
7808    }
7809
7810 }
7811
7812 /*******************************************************************
7813  *
7814  * @brief Frees memory allocated for Dedicated PUCCH config
7815  *
7816  * @details
7817  *
7818  *    Function : FreeBWPUlDedPucchCfg
7819  *
7820  *    Functionality: Deallocating memory of Dedicated PUCCH cfg
7821  *
7822  * @params[in] BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg
7823  *
7824  * @return void
7825  *
7826  * ****************************************************************/
7827 void FreeBWPUlDedPucchCfg(struct BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg)
7828 {
7829    uint8_t k1Idx, rsrcIdx, rsrcSetIdx;
7830    PUCCH_Config_t *pucchCfg = NULLP;
7831    PUCCH_ResourceSet_t *rsrcSet = NULLP;
7832    PUCCH_Resource_t *rsrc = NULLP;
7833
7834    if(ulBwpPucchCfg)
7835    {
7836       if(ulBwpPucchCfg->choice.setup)
7837       {
7838          pucchCfg = ulBwpPucchCfg->choice.setup;
7839
7840          //Free resource set list
7841          if(pucchCfg->resourceSetToAddModList)
7842          {
7843             if(pucchCfg->resourceSetToAddModList->list.array)
7844             {
7845                for(rsrcSetIdx=0; rsrcSetIdx < pucchCfg->resourceSetToAddModList->list.count; rsrcSetIdx++)
7846                {
7847                   rsrcSet = pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx];
7848                   if(rsrcSet->resourceList.list.array)
7849                   {
7850                      for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
7851                      {
7852                         DU_FREE(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
7853                      }
7854                      DU_FREE(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
7855                   }
7856                   DU_FREE(pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
7857                }
7858                DU_FREE(pucchCfg->resourceSetToAddModList->list.array, pucchCfg->resourceSetToAddModList->list.size);
7859             }
7860             DU_FREE(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
7861          }
7862
7863          //Free resource list
7864          if(pucchCfg->resourceToAddModList)
7865          {
7866             if(pucchCfg->resourceToAddModList->list.array)
7867             {
7868                for(rsrcIdx=0; rsrcIdx < pucchCfg->resourceToAddModList->list.count; rsrcIdx++)
7869                {
7870                   rsrc = pucchCfg->resourceToAddModList->list.array[rsrcIdx];
7871                   DU_FREE(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
7872                   DU_FREE(pucchCfg->resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
7873                }
7874                DU_FREE(pucchCfg->resourceToAddModList->list.array, pucchCfg->resourceToAddModList->list.size);
7875             }
7876             DU_FREE(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
7877          }
7878
7879          //PUCCH Format 1
7880          if(pucchCfg->format1)
7881          {
7882             if(pucchCfg->format1->choice.setup)
7883             {
7884                DU_FREE(pucchCfg->format1->choice.setup->nrofSlots, sizeof(long));
7885                DU_FREE(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
7886             }
7887             DU_FREE(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
7888          }
7889          
7890          //DL DATA TO UL ACK
7891          if(pucchCfg->dl_DataToUL_ACK)
7892          {
7893             if(pucchCfg->dl_DataToUL_ACK->list.array)
7894             {
7895                for(k1Idx = 0; k1Idx <  pucchCfg->dl_DataToUL_ACK->list.count; k1Idx++)
7896                {
7897                   DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array[k1Idx], sizeof(long));
7898                }
7899                DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array, pucchCfg->dl_DataToUL_ACK->list.size);
7900             }
7901             DU_FREE(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
7902          }
7903
7904          DU_FREE(ulBwpPucchCfg->choice.setup, sizeof(PUCCH_Config_t));
7905       }
7906       DU_FREE(ulBwpPucchCfg, sizeof(struct BWP_UplinkDedicated__pucch_Config));
7907    }
7908 }
7909
7910 /*******************************************************************
7911  *
7912  * @brief Frees memory allocated for InitialUlBWP
7913  *
7914  * @details
7915  *
7916  *    Function : FreeInitialUlBWP
7917  *
7918  *    Functionality: Deallocating memory of InitialUlBWP
7919  *
7920  * @params[in] BWP_UplinkDedicated_t *ulBwp
7921  *
7922  * @return void
7923  *
7924  * ****************************************************************/
7925 void FreeInitialUlBWP(BWP_UplinkDedicated_t *ulBwp)
7926 {
7927    uint8_t  rSetIdx, rsrcIdx;
7928    SRS_Config_t   *srsCfg = NULLP;
7929    PUSCH_Config_t *puschCfg = NULLP;
7930    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
7931    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
7932    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
7933    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
7934
7935    FreeBWPUlDedPucchCfg(ulBwp->pucch_Config);
7936
7937    if(ulBwp->pusch_Config)
7938    {
7939       if(ulBwp->pusch_Config->choice.setup)
7940       {
7941          puschCfg=ulBwp->pusch_Config->choice.setup;
7942          if(puschCfg->dataScramblingIdentityPUSCH)
7943          {
7944             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
7945             {
7946                FreePuschTimeDomAllocList(puschCfg);
7947                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
7948                if(dmrsUlCfg->choice.setup)
7949                {
7950                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
7951                   {
7952                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
7953                      {
7954                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
7955                               sizeof(long));
7956                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled,
7957                               sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
7958                      }
7959                      DU_FREE(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition,
7960                            sizeof(long));
7961                   }
7962                   DU_FREE(dmrsUlCfg->choice.setup,sizeof(DMRS_UplinkConfig_t));
7963                }
7964                DU_FREE(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, \
7965                      sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
7966             }
7967             DU_FREE(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
7968          }
7969          DU_FREE(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
7970       }
7971       DU_FREE(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
7972
7973       /* Free SRS-Config */
7974       if(ulBwp->srs_Config)
7975       {
7976          if(ulBwp->srs_Config->choice.setup)
7977          {
7978             srsCfg = ulBwp->srs_Config->choice.setup;
7979
7980             /* Free Resource Set to add/mod list */
7981             if(srsCfg->srs_ResourceSetToAddModList)
7982             {
7983                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
7984                if(rsrcSetList->list.array)
7985                {
7986                   rSetIdx = 0;
7987
7988                   /* Free SRS resource Id list in this SRS resource set */
7989                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
7990                   {
7991                      rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
7992
7993                      if(rsrcIdList->list.array)
7994                      {
7995                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
7996                         {
7997                            DU_FREE(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
7998                         }
7999                         DU_FREE(rsrcIdList->list.array, rsrcIdList->list.size);
8000                      }
8001                      DU_FREE(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
8002                            sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
8003                   }
8004
8005                   /* Free resource type info for this SRS resource set */
8006                   DU_FREE(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
8007                         sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
8008
8009                   /* Free memory for each resource set */
8010                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
8011                   {
8012                      DU_FREE(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
8013                   }
8014                   DU_FREE(rsrcSetList->list.array, rsrcSetList->list.size); 
8015                }
8016                DU_FREE(srsCfg->srs_ResourceSetToAddModList, \
8017                      sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
8018             }
8019
8020             /* Free resource to add/modd list */
8021             if(srsCfg->srs_ResourceToAddModList)
8022             {
8023                resourceList = srsCfg->srs_ResourceToAddModList;
8024                if(resourceList->list.array)
8025                {
8026                   rsrcIdx = 0;
8027                   DU_FREE(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2,\
8028                         sizeof(struct SRS_Resource__transmissionComb__n2));
8029                   DU_FREE(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,\
8030                         sizeof(struct SRS_Resource__resourceType__aperiodic));
8031
8032                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
8033                   {
8034                      DU_FREE(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
8035                   }
8036                   DU_FREE(resourceList->list.array, resourceList->list.size);
8037                }
8038                DU_FREE(srsCfg->srs_ResourceToAddModList, \
8039                      sizeof(struct SRS_Config__srs_ResourceToAddModList));
8040             }
8041
8042             DU_FREE(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
8043          }
8044          DU_FREE(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
8045       }
8046    }
8047 }       
8048 /*******************************************************************
8049  *
8050  * @brief Frees memory allocated for initialUplinkBWP
8051  *
8052  * @details
8053  *
8054  *    Function : FreeinitialUplinkBWP
8055  *
8056  *    Functionality: Deallocating memory of initialUplinkBWP
8057  *
8058  * @params[in] UplinkConfig_t *ulCfg
8059  *
8060  * @return void
8061  *         
8062  *
8063  * ****************************************************************/
8064 void FreeinitialUplinkBWP(UplinkConfig_t *ulCfg)
8065 {
8066    BWP_UplinkDedicated_t *ulBwp=NULLP; 
8067    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
8068
8069    if(ulCfg->initialUplinkBWP)
8070    {
8071       ulBwp=ulCfg->initialUplinkBWP;
8072       if(ulCfg->firstActiveUplinkBWP_Id)
8073       {
8074          if(ulCfg->pusch_ServingCellConfig)
8075          {
8076             puschCfg=ulCfg->pusch_ServingCellConfig;
8077             if(puschCfg->choice.setup)
8078             {
8079                if(puschCfg->choice.setup->ext1)
8080                {
8081                   DU_FREE(puschCfg->choice.setup->ext1->\
8082                         processingType2Enabled,sizeof(BOOLEAN_t));
8083                   DU_FREE(puschCfg->choice.setup->ext1->\
8084                         maxMIMO_Layers,sizeof(long));
8085                   DU_FREE(puschCfg->choice.setup->ext1, \
8086                         sizeof(struct PUSCH_ServingCellConfig__ext1));
8087                }
8088                DU_FREE(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
8089             }
8090             DU_FREE(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
8091          }
8092          DU_FREE(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
8093       }
8094       FreeInitialUlBWP(ulBwp);
8095       DU_FREE(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
8096    }
8097 }
8098 /*******************************************************************
8099  *
8100  * @brief Frees emmory allocated for BWPDlDedPdschCfg
8101  *
8102  * @details
8103  *
8104  *    Function : FreeBWPDlDedPdschCfg
8105  *
8106  *    Functionality: Deallocating memory of BWPDlDedPdschCfg
8107  *
8108  * @params[in] BWP_DownlinkDedicated_t *dlBwp
8109  *
8110  * @return void
8111  *
8112  *
8113  * ****************************************************************/
8114 void FreeBWPDlDedPdschCfg(BWP_DownlinkDedicated_t *dlBwp)
8115 {
8116    struct PDSCH_Config *pdschCfg=NULLP;
8117    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
8118    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
8119    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
8120
8121    if(dlBwp->pdsch_Config->choice.setup)
8122    {
8123       pdschCfg=dlBwp->pdsch_Config->choice.setup;
8124       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
8125       {
8126          if(pdschCfg->pdsch_TimeDomainAllocationList)
8127          {
8128             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
8129             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
8130             {
8131                prbBndlType=&pdschCfg->prb_BundlingType;
8132                DU_FREE(prbBndlType->choice.staticBundling,\
8133                      sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
8134                DU_FREE(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
8135             }
8136             FreePdschTimeDomAllocList(timeDomAllocList);
8137             DU_FREE(pdschCfg->pdsch_TimeDomainAllocationList, \
8138                   sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
8139          }
8140          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
8141          if(dmrsDlCfg->choice.setup)
8142          {
8143             DU_FREE(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition,
8144                   sizeof(long));
8145             DU_FREE(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
8146          }
8147          DU_FREE(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, \
8148                sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
8149       }
8150       DU_FREE(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
8151    }
8152 }
8153 /*******************************************************************
8154  *
8155  * @brief Frees emmory allocated for BWPDlDedPdcchCfg
8156  *
8157  * @details
8158  *
8159  *    Function : FreeBWPDlDedPdcchCfg
8160  *
8161  *    Functionality: Deallocating memory of BWPDlDedPdcchCfg
8162  *
8163  * @params[in] BWP_DownlinkDedicated_t *dlBwp
8164  *
8165  * @return void
8166  *         
8167  *
8168  * ****************************************************************/
8169 void FreeBWPDlDedPdcchCfg(BWP_DownlinkDedicated_t *dlBwp)
8170 {
8171    uint8_t idx1=0;
8172    uint8_t idx2=0;
8173    struct PDCCH_Config *pdcchCfg=NULLP;
8174    struct ControlResourceSet *controlRSet=NULLP;
8175    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
8176
8177    if(dlBwp->pdcch_Config->choice.setup)
8178    {
8179       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
8180       if(pdcchCfg->controlResourceSetToAddModList)
8181       {
8182          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
8183          if(controlRSetList->list.array)
8184          {
8185             controlRSet = controlRSetList->list.array[idx2];
8186             if(controlRSet)
8187             {
8188                if(controlRSet->frequencyDomainResources.buf)
8189                {
8190                   if(controlRSet->pdcch_DMRS_ScramblingID)
8191                   {
8192                      if(pdcchCfg->searchSpacesToAddModList)
8193                      {
8194                         FreeSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
8195                         DU_FREE(pdcchCfg->searchSpacesToAddModList, \
8196                               sizeof(struct PDCCH_Config__searchSpacesToAddModList));
8197                      }
8198                      DU_FREE(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
8199                   }
8200                   DU_FREE(controlRSet->frequencyDomainResources.buf, \
8201                         controlRSet->frequencyDomainResources.size);
8202                }
8203             }
8204             for(idx1 = 0; idx1 <controlRSetList->list.count; idx1++)
8205             {
8206                DU_FREE(controlRSetList->list.array[idx1], sizeof(struct ControlResourceSet));
8207             }
8208             DU_FREE(controlRSetList->list.array, controlRSetList->list.size);
8209          }
8210          DU_FREE(pdcchCfg->controlResourceSetToAddModList, \
8211                sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
8212       }
8213       DU_FREE(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
8214    }
8215 }       
8216
8217 /*******************************************************************
8218  *
8219  * @brief Free SCS specific carrier list in DL frequency info
8220  *
8221  * @details
8222  *
8223  *    Function : FreeScsSpecificCarrierListDl
8224  *
8225  *    Functionality: Free SCS specific carrier list in DL frequency info
8226  *
8227  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
8228  *
8229  * @return void
8230  *
8231  * ****************************************************************/
8232 void FreeScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
8233 {
8234    uint8_t listIdx = 0;
8235
8236    if(!scsCarrierList->list.array)
8237    {
8238       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
8239       {
8240          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
8241       }
8242       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
8243    }
8244 }
8245
8246 /*******************************************************************
8247  *
8248  * @brief Free DL frequency info in DL config common
8249  *
8250  * @details
8251  *
8252  *    Function : FreeFreqInfoDl
8253  *
8254  *    Functionality: Free DL frequency info in DL config common
8255  *
8256  * @params[in] Pointer to DownlinkConfigCommon_t
8257  *
8258  * @return void
8259  *
8260  * ****************************************************************/
8261 void FreeFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
8262 {
8263    uint8_t freqBandIdx = 0;
8264
8265    /* SSB Absolute Frequency */
8266    DU_FREE(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
8267
8268    /* NR Multi Frequency Band List */
8269    if(frequencyInfoDL->frequencyBandList.list.array)
8270    {
8271       for(freqBandIdx = 0; freqBandIdx < frequencyInfoDL->frequencyBandList.list.count; freqBandIdx++)
8272       {
8273          DU_FREE(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
8274       }
8275       DU_FREE(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
8276    }
8277
8278    /* Subcarrier Spacing specifc carrier List */
8279    FreeScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList);
8280 }
8281
8282 /*******************************************************************
8283  *
8284  * @brief Free DL config common in Serving cell config common
8285  *
8286  * @details
8287  *
8288  *    Function : FreeDlConfigCommon
8289  *
8290  *    Functionality: Free DL config common in Serving cell config common
8291  *
8292  * @params[in] Pointer to DownlinkConfigCommon_t
8293  *
8294  * @return void
8295  *
8296  * ****************************************************************/
8297 void FreeDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
8298 {
8299    /* DL Frequency Info */
8300    if(dlCfgCommon->frequencyInfoDL)
8301    {
8302       FreeFreqInfoDl(dlCfgCommon->frequencyInfoDL);
8303       DU_FREE(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
8304    }
8305
8306    /* DL BWP config common */
8307    if(dlCfgCommon->initialDownlinkBWP)
8308    {
8309       FreeBwpDlCommon(dlCfgCommon->initialDownlinkBWP);
8310       DU_FREE(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
8311    }
8312 }
8313
8314 /*******************************************************************
8315  *
8316  * @brief Free SCS specific carrier list in UL frequency Info
8317  *
8318  * @details
8319  *
8320  *    Function : FreeScsSpecificCarrierListUl
8321  *
8322  *    Functionality: Free SCS specific carrier list in UL frequency Info
8323  *
8324  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
8325  *
8326  * @return void
8327  *
8328  * ****************************************************************/
8329 void FreeScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
8330 {
8331    uint8_t listIdx = 0;
8332
8333    if(scsCarrierList->list.array)
8334    {
8335       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
8336       {
8337          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
8338       }
8339       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
8340    }
8341 }
8342
8343 /*******************************************************************
8344  *
8345  * @brief Free frequency info in UL config common
8346  *
8347  * @details
8348  *
8349  *    Function : FreeFreqInfoUl
8350  *
8351  *    Functionality: Free frequency info in UL config common
8352  *
8353  * @params[in] Pointer to FrequencyInfoUL_t
8354  *
8355  * @return void
8356  *
8357  * ****************************************************************/
8358 void FreeFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
8359 {
8360    uint8_t listIdx= 0;
8361
8362    /* NR Multi Frequency Band List */
8363    if(!frequencyInfoUL->frequencyBandList)
8364    {
8365       if(frequencyInfoUL->frequencyBandList->list.array)
8366       {
8367          for(listIdx = 0; listIdx < frequencyInfoUL->frequencyBandList->list.count; listIdx++)
8368          {
8369             DU_FREE(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
8370          }
8371          DU_FREE(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
8372       }
8373       DU_FREE(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
8374    }
8375
8376    /* Absolute frequency point A */
8377    DU_FREE(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
8378
8379    /* Subcarrier Spacing specifc carrier */
8380    FreeScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList);
8381
8382    /* P-MAX */
8383    DU_FREE(frequencyInfoUL->p_Max, sizeof(P_Max_t));
8384 }
8385
8386 /*******************************************************************
8387  *
8388  * @brief Free UL config common in Serving cell config common
8389  *
8390  * @details
8391  *
8392  *    Function : FreeUlConfigCommon
8393  *
8394  *    Functionality: Free UL config common in Serving cell config common
8395  *
8396  * @params[in] Pointer to UplinkConfigCommon_t
8397  *
8398  * @return void
8399  *
8400  * ****************************************************************/
8401 void FreeUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
8402 {
8403    /* UL Frequency Info */
8404    if(ulCfgCommon->frequencyInfoUL)
8405    {
8406       FreeFreqInfoUl(ulCfgCommon->frequencyInfoUL);
8407       DU_FREE(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
8408    }
8409
8410    /* UL BWP common */
8411    if(ulCfgCommon->initialUplinkBWP)
8412    {
8413       FreeBwpUlCommon(ulCfgCommon->initialUplinkBWP);
8414       DU_FREE(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
8415    }
8416 }
8417
8418 /*******************************************************************
8419  *
8420  * @brief Free SP cell config common in Reconfig with Sync
8421  *
8422  * @details
8423  *
8424  *    Function : FreeSpCellConfigCommon
8425  *
8426  *    Functionality: Free SP cell config common in Reconfig with Sync
8427  *
8428  * @params[in] Pointer to ServingCellConfigCommon_t
8429  *
8430  * @return void
8431  *
8432  * ****************************************************************/
8433 void FreeSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
8434 {
8435    /* Free Physical cell identity */
8436    DU_FREE(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
8437
8438    /* Free Downlink Config common */
8439    if(spCellConfigCommon->downlinkConfigCommon)
8440    {
8441       FreeDlConfigCommon(spCellConfigCommon->downlinkConfigCommon);
8442       DU_FREE(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
8443    }
8444
8445    /* Free Uplink Config common */
8446    if(spCellConfigCommon->uplinkConfigCommon)
8447    {
8448       FreeUlConfigCommon(spCellConfigCommon->uplinkConfigCommon);
8449       DU_FREE(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
8450    }
8451
8452    /* Free Timing Advance offset */
8453    DU_FREE(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
8454
8455    /* Free SSB Position in Burst */
8456    if(spCellConfigCommon->ssb_PositionsInBurst)
8457    {
8458       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.buf, \
8459          spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.size);
8460       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
8461    }
8462
8463    /* Free SSB Periodicity in Serving cell */
8464    DU_FREE(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
8465
8466    /* Free SSB subcarrier spacing */
8467    DU_FREE(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
8468
8469    /* TDD UL-DL configuration common */
8470    DU_FREE(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
8471 }
8472
8473 /*******************************************************************
8474  *
8475  * @brief Free dedicated RACH configuration in Reconfiguration with sync
8476  *
8477  * @details
8478  *
8479  *    Function : FreeRecfgWithSync
8480  *
8481  *    Functionality:
8482  *       Free dedicated RACH configuration in Reconfiguration with sync
8483  *
8484  * @params[in] Pinter to Rach config dedicated struct
8485  *
8486  * @return void
8487  *
8488  * ****************************************************************/
8489 void FreeRachConfigDedicated(struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
8490 {
8491    uint8_t listIdx = 0;
8492    CFRA_t *cfra = NULLP;
8493    struct CFRA__resources__ssb *ssbResource = NULLP;
8494
8495    /* Uplink */
8496    if(rachCfgDed->choice.uplink)
8497    {
8498       /* CFRA : Contention free Random Access */
8499       if(rachCfgDed->choice.uplink->cfra)
8500       {
8501          cfra = rachCfgDed->choice.uplink->cfra;
8502
8503          /* CFRA occassions */
8504          if(cfra->occasions)
8505          {
8506             /* CFRA occassions : SSB per RACH occasion */
8507             DU_FREE(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
8508             DU_FREE(cfra->occasions, sizeof(struct CFRA__occasions));
8509          }
8510
8511          /* CFRA resource */
8512          cfra->resources.present = CFRA__resources_PR_ssb;
8513
8514          /* CFRA resource : SSB */
8515          if(cfra->resources.choice.ssb)
8516          {
8517             ssbResource = cfra->resources.choice.ssb;
8518
8519             /* CFRA SSB resource list */
8520             if(ssbResource->ssb_ResourceList.list.array)
8521             {
8522                for(listIdx = 0; listIdx < ssbResource->ssb_ResourceList.list.count; listIdx++)
8523                {
8524                   DU_FREE(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
8525                }
8526                DU_FREE(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
8527             }
8528             DU_FREE(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
8529          }
8530          DU_FREE(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
8531       }
8532       DU_FREE(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
8533    }
8534 }
8535
8536 /*******************************************************************
8537  *
8538  * @brief Frees reconfiguration with sync in SP cell config
8539  *
8540  * @details
8541  *
8542  *    Function : FreeRecfgWithSync
8543  *
8544  *    Functionality: Fress reconfiguration with sync in SP cell config
8545  *
8546  * @params[in] Pointer to ReconfigurationWithSync_t
8547  *
8548  * @return void
8549  *
8550  * ****************************************************************/
8551 void FreeRecfgWithSync(ReconfigurationWithSync_t *recfgWithSync)
8552 {
8553    /* Free SP Cell config common */
8554    if(recfgWithSync->spCellConfigCommon)
8555    {
8556       FreeSpCellConfigCommon(recfgWithSync->spCellConfigCommon);
8557       DU_FREE(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
8558    }
8559
8560    /* Free Dedicated RACH configuration */
8561    if(recfgWithSync->rach_ConfigDedicated)
8562    {
8563       FreeRachConfigDedicated(recfgWithSync->rach_ConfigDedicated);
8564       DU_FREE(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
8565    }
8566 }
8567
8568 /*******************************************************************
8569  *
8570  * @brief Frees emmory allocated for DUToCURRCContainer 
8571  *
8572  * @details
8573  *
8574  *    Function : FreeMemDuToCuRrcCont
8575  *
8576  *    Functionality: Deallocating memory of DuToCuRrcContainer
8577  *
8578  * @params[in] DuToCuRRCContainer, DuToCuRRCContainer
8579  *
8580  * @return ROK     - success
8581  *         RFAILED - failure
8582  *
8583  * ****************************************************************/
8584 uint8_t FreeMemDuToCuRrcCont(CellGroupConfigRrc_t *cellGrpCfg)
8585 {
8586    uint8_t idx=0;
8587    SpCellConfig_t *spCellCfg=NULLP;
8588    ServingCellConfig_t *srvCellCfg=NULLP;
8589    BWP_DownlinkDedicated_t *dlBwp=NULLP;
8590    MAC_CellGroupConfig_t *macCellGrpCfg=NULLP;
8591    PhysicalCellGroupConfig_t *phyCellGrpCfg=NULLP;
8592    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList=NULLP;
8593    struct RLC_Config *rlcConfig=NULLP;
8594    struct LogicalChannelConfig *macLcConfig=NULLP;
8595    struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg=NULLP;
8596    struct SchedulingRequestConfig *schedulingRequestConfig=NULLP;
8597    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList=NULLP;
8598    struct TAG_Config *tagConfig=NULLP;
8599    struct TAG_Config__tag_ToAddModList *tagList=NULLP;
8600    struct MAC_CellGroupConfig__phr_Config *phrConfig=NULLP;
8601    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg=NULLP;
8602
8603    rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
8604    if(rlcBearerList)
8605    {
8606       if(rlcBearerList->list.array)
8607       {
8608          for(idx=0; idx<rlcBearerList->list.count; idx++)
8609          {
8610             if(rlcBearerList->list.array[idx])
8611             {  
8612                rlcConfig   = rlcBearerList->list.array[idx]->rlc_Config;
8613                macLcConfig = rlcBearerList->list.array[idx]->mac_LogicalChannelConfig;
8614                if(rlcConfig)
8615                {
8616                   switch(rlcConfig->present)
8617                   {
8618                      case RLC_Config_PR_NOTHING:
8619                         break;
8620
8621                      case RLC_Config_PR_am:
8622                         {
8623                            if(rlcConfig->choice.am)
8624                            {
8625                               DU_FREE(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
8626                               DU_FREE(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
8627                               DU_FREE(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
8628                            }
8629                            break;
8630                         }
8631                      case RLC_Config_PR_um_Bi_Directional:
8632                         {
8633                            if(rlcConfig->choice.um_Bi_Directional)
8634                            {
8635                               DU_FREE(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t)); 
8636                               DU_FREE(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8637                               DU_FREE(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
8638                            }
8639                            break;
8640                         }
8641                      case RLC_Config_PR_um_Uni_Directional_UL:
8642                         {
8643                            if(rlcConfig->choice.um_Uni_Directional_UL)
8644                            {
8645                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8646                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
8647                            }
8648                            break;
8649                         }
8650                      case RLC_Config_PR_um_Uni_Directional_DL:
8651                         {
8652                            if(rlcConfig->choice.um_Uni_Directional_DL )
8653                            {
8654                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8655                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
8656                            }
8657                            break;
8658                         }
8659                   }     
8660                   DU_FREE(rlcConfig, sizeof(struct RLC_Config));
8661                }
8662                DU_FREE(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
8663                if(macLcConfig)
8664                {
8665                   if(macLcConfig->ul_SpecificParameters)
8666                   {
8667                      DU_FREE(macLcConfig->ul_SpecificParameters->schedulingRequestID,   sizeof(SchedulingRequestId_t));
8668                      DU_FREE(macLcConfig->ul_SpecificParameters->logicalChannelGroup,   sizeof(long));
8669                      DU_FREE(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
8670                   }
8671                   DU_FREE(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
8672                }
8673                DU_FREE(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
8674             }   
8675          }
8676          DU_FREE(rlcBearerList->list.array, rlcBearerList->list.size);
8677       }
8678       DU_FREE(cellGrpCfg->rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8679    }
8680
8681    macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
8682    if(macCellGrpCfg)
8683    {
8684       drxCfg = macCellGrpCfg->drx_ConfigRrc;
8685
8686       if(drxCfg)
8687       {
8688           switch(drxCfg->present)
8689           {
8690             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
8691                break;
8692             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
8693             {
8694                if(drxCfg->choice.setup)
8695                {
8696                   DU_FREE(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));  
8697                   DU_FREE(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
8698                }
8699             }
8700             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
8701                break;
8702           }
8703           DU_FREE(drxCfg, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
8704       }
8705       schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig; 
8706       if(schedulingRequestConfig)
8707       {
8708          schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
8709          if(schReqList)
8710          {
8711             if(schReqList->list.array)
8712             {
8713                for(idx=0;idx<schReqList->list.count; idx++)
8714                {
8715                   if(schReqList->list.array[idx])
8716                   {
8717                      DU_FREE(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
8718                      DU_FREE(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
8719                   }
8720                }
8721                DU_FREE(schReqList->list.array, schReqList->list.size);
8722             }
8723             DU_FREE(schedulingRequestConfig->schedulingRequestToAddModList,\
8724                   sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));    }
8725             DU_FREE(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
8726       }
8727       if(macCellGrpCfg->bsr_Config)
8728       {
8729          DU_FREE(macCellGrpCfg->bsr_Config->logicalChannelSR_DelayTimer, sizeof(long));
8730          DU_FREE(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
8731       }
8732       tagConfig = macCellGrpCfg->tag_Config;
8733       if(tagConfig)
8734       {
8735          tagList = tagConfig->tag_ToAddModList;
8736          if(tagList)
8737          {
8738             if(tagList->list.array)
8739             {
8740                for(idx=0; idx<tagList->list.count; idx++)
8741                {
8742                   DU_FREE(tagList->list.array[idx], sizeof(struct TAG));
8743                }
8744                DU_FREE(tagList->list.array, tagList->list.size);
8745             }
8746             DU_FREE(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
8747          }
8748          DU_FREE(tagConfig, sizeof(struct TAG_Config));
8749       }
8750
8751       phrConfig = macCellGrpCfg->phr_Config;
8752       if(phrConfig)
8753       {
8754          DU_FREE(phrConfig->choice.setup, sizeof(struct PHR_Config));
8755          DU_FREE(phrConfig, sizeof(struct MAC_CellGroupConfig__phr_Config));
8756       }
8757
8758       DU_FREE(macCellGrpCfg, sizeof(MAC_CellGroupConfig_t));
8759    }
8760
8761    phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
8762    if(phyCellGrpCfg)
8763    {
8764       DU_FREE(phyCellGrpCfg->p_NR_FR1, sizeof(long));
8765       DU_FREE(phyCellGrpCfg, sizeof(PhysicalCellGroupConfig_t));
8766    }
8767
8768    spCellCfg = cellGrpCfg->spCellConfig;
8769    if(spCellCfg)
8770    {
8771       /* Free serving cell index */
8772       DU_FREE(spCellCfg->servCellIndex, sizeof(long));
8773
8774       /* Free Reconfiguration with sync */
8775       if(spCellCfg->reconfigurationWithSync)
8776       {
8777          FreeRecfgWithSync(spCellCfg->reconfigurationWithSync);
8778          DU_FREE(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
8779       }
8780
8781       /* Free rlmInSyncOutOfSyncThreshold */
8782       DU_FREE(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
8783
8784       /* Free SP Cell config dedicated */
8785       if(spCellCfg->spCellConfigDedicated)
8786       {
8787          srvCellCfg = spCellCfg->spCellConfigDedicated;
8788
8789          /* Free TDD UL-DL config dedicated */
8790          DU_FREE(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
8791
8792          /* Free Initial Downlink BWP */
8793          if(srvCellCfg->initialDownlinkBWP)
8794          {
8795             dlBwp = srvCellCfg->initialDownlinkBWP;
8796
8797             /* Free DL BWP PDCCH Config */
8798             if(dlBwp->pdcch_Config)
8799             {
8800                FreeBWPDlDedPdcchCfg(dlBwp);
8801                DU_FREE(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
8802             }
8803
8804             /* Free DL BWP PDSCH config */
8805             if(dlBwp->pdsch_Config)
8806             {
8807                FreeBWPDlDedPdschCfg(dlBwp);
8808                DU_FREE(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
8809             }
8810             DU_FREE(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
8811          }
8812
8813          /* Free First Active Downlink BWP */
8814          DU_FREE(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
8815
8816          /* Free Default downlink BWP */
8817          DU_FREE(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
8818
8819          /* Free Uplink config */
8820          if(srvCellCfg->uplinkConfig)
8821          {
8822             FreeinitialUplinkBWP(srvCellCfg->uplinkConfig);
8823             DU_FREE(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));  
8824          }
8825
8826          /* Free PDSCH serving cell config */
8827          if(srvCellCfg->pdsch_ServingCellConfig)
8828          {
8829             pdschCfg= srvCellCfg->pdsch_ServingCellConfig;
8830             if(pdschCfg->choice.setup)
8831             {
8832                DU_FREE(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH,sizeof(long));
8833                DU_FREE(pdschCfg->choice.setup, sizeof(struct PDSCH_ServingCellConfig));
8834             }
8835             DU_FREE(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct ServingCellConfig__pdsch_ServingCellConfig));
8836          }
8837
8838          DU_FREE(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
8839       }
8840       DU_FREE(spCellCfg,sizeof(SpCellConfig_t));
8841    }
8842    return ROK;
8843 }
8844
8845 /*******************************************************************
8846  *
8847  * @brief Builds CellGroupConfigRrc for DU To CU RRC Container 
8848  *
8849  * @details
8850  *
8851  *    Function : BuildCellGroupConfigRrc
8852  *
8853  *    Functionality: Builds and copied Cell group config buffer into 
8854  *       DuToCuRrcContainer
8855  *
8856  * @params[in] idx, index in F1AP msg
8857  *             DuToCuRRCContainer, DuToCuRRCContainer
8858  *
8859  * @return ROK     - success
8860  *         RFAILED - failure
8861  *
8862  * ****************************************************************/
8863 uint8_t BuildCellGroupConfigRrc(DuUeCb *ueCb, OCTET_STRING_t *duToCuRrcContainer)
8864 {
8865    uint8_t  ret = ROK;
8866    CellGroupConfigRrc_t  cellGrpCfg;
8867    asn_enc_rval_t        encRetVal;
8868    memset(&cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
8869    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8870
8871    while(true)
8872    {
8873       cellGrpCfg.cellGroupId = CELL_GRP_ID;
8874
8875       cellGrpCfg.rlc_BearerToAddModList = NULLP;
8876       DU_ALLOC(cellGrpCfg.rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8877       if(!cellGrpCfg.rlc_BearerToAddModList)
8878       {
8879          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8880          ret = RFAILED;
8881          break;
8882       }
8883       if(BuildRlcBearerToAddModList(ueCb, cellGrpCfg.rlc_BearerToAddModList) != ROK)
8884       {
8885          DU_LOG("\nERROR  -->  F1AP : BuildRlcBearerToAddModList failed");
8886          ret = RFAILED;
8887          break;
8888       }
8889
8890       cellGrpCfg.rlc_BearerToReleaseList = NULLP;
8891       cellGrpCfg.mac_CellGroupConfig = NULLP;
8892       DU_ALLOC(cellGrpCfg.mac_CellGroupConfig, sizeof(MAC_CellGroupConfig_t));
8893       if(!cellGrpCfg.mac_CellGroupConfig)
8894       {
8895          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8896          ret = RFAILED;
8897          break;
8898       }
8899       if(BuildMacCellGrpCfg(ueCb, cellGrpCfg.mac_CellGroupConfig) != ROK)
8900       {
8901          DU_LOG("\nERROR  -->  F1AP : BuildMacCellGrpCfg failed");
8902          ret = RFAILED;
8903          break;
8904       }
8905
8906       cellGrpCfg.physicalCellGroupConfig = NULLP;
8907       DU_ALLOC(cellGrpCfg.physicalCellGroupConfig, sizeof(PhysicalCellGroupConfig_t));
8908       if(!cellGrpCfg.physicalCellGroupConfig)
8909       {
8910          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8911          ret = RFAILED;
8912          break;
8913       }
8914       if(BuildPhyCellGrpCfg(ueCb, cellGrpCfg.physicalCellGroupConfig) != ROK)
8915       {
8916          DU_LOG("\nERROR  -->  F1AP : BuildPhyCellGrpCfg failed");
8917          ret = RFAILED;
8918          break;
8919       }
8920
8921       cellGrpCfg.spCellConfig = NULLP;
8922       DU_ALLOC(cellGrpCfg.spCellConfig, sizeof(SpCellConfig_t));
8923       if(!cellGrpCfg.spCellConfig)
8924       {
8925          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8926          ret = RFAILED;
8927          break;
8928       }
8929       if(BuildSpCellCfg(ueCb, cellGrpCfg.spCellConfig) != ROK)
8930       {
8931          DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfg failed");
8932          ret = RFAILED;
8933          break;
8934       }
8935
8936       cellGrpCfg.sCellToAddModList = NULLP;
8937       cellGrpCfg.sCellToReleaseList = NULLP;
8938       cellGrpCfg.ext1 = NULLP;
8939
8940       /* encode cellGrpCfg into duToCuRrcContainer */
8941       xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, &cellGrpCfg);
8942       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8943       encBufSize = 0;
8944       encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, &cellGrpCfg, PrepFinalEncBuf, encBuf);
8945       /* Encode results */
8946       if(encRetVal.encoded == ENCODE_FAIL)
8947       {
8948          DU_LOG( "\nERROR  --> F1AP : Could not encode DuToCuRrcContainer (at %s)\n",\
8949                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
8950          ret = RFAILED;
8951          break;
8952       }
8953       else
8954       {
8955          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DuToCuRrcContainer\n");
8956 #ifdef DEBUG_ASN_PRINT
8957          for(int i=0; i< encBufSize; i++)
8958          {
8959             printf("%x",encBuf[i]);
8960          }
8961 #endif
8962       }
8963
8964       duToCuRrcContainer->size = encBufSize;
8965       DU_ALLOC(duToCuRrcContainer->buf, duToCuRrcContainer->size);
8966       if(!duToCuRrcContainer->buf)
8967       {
8968          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDuToCuRrcContainer");
8969          ret = RFAILED;
8970          break;
8971       }
8972       if(ret == ROK)
8973       {
8974          memcpy(duToCuRrcContainer->buf, encBuf, duToCuRrcContainer->size);
8975       }
8976       break;
8977    }
8978    FreeMemDuToCuRrcCont(&cellGrpCfg);
8979    return ret;
8980 }
8981
8982 /*******************************************************************
8983  *
8984  * @brief Free memory allocated in InitialULRRCMessage
8985  *
8986  * @details
8987  *
8988  *    Function : freeInitUlRrcMsgTransfer
8989  *
8990  *    Functionality: Free memory allocated in InitialULRRCMessage
8991  *
8992  * @params[in]F1AP_PDU_t  *f1apMsg)
8993  *
8994  * @return ROK     - success
8995  *         RFAILED - failure
8996  *
8997  * ****************************************************************/
8998
8999 uint8_t freeInitUlRrcMsgTransfer(F1AP_PDU_t  *f1apMsg)
9000 {
9001    uint8_t ieIdx, arrIdx;
9002    InitialULRRCMessageTransfer_t *initULRRCMsg=NULLP;
9003
9004    if(f1apMsg)
9005    {
9006       if(f1apMsg->choice.initiatingMessage)
9007       {
9008          initULRRCMsg = &f1apMsg->choice.initiatingMessage->value.\
9009             choice.InitialULRRCMessageTransfer;
9010          if(initULRRCMsg->protocolIEs.list.array)
9011          {
9012             for(ieIdx = 0; ieIdx < initULRRCMsg->protocolIEs.list.count; ieIdx++)
9013             {
9014                switch(initULRRCMsg->protocolIEs.list.array[ieIdx]->id)
9015                {
9016                   case ProtocolIE_ID_id_NRCGI:
9017                   {
9018                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf)
9019                      {
9020                         if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf)
9021                         {
9022                            DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf,\
9023                            initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.size);
9024                         }
9025                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf,\
9026                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.size);
9027                      }
9028                      break;
9029                   }
9030                   case ProtocolIE_ID_id_RRCContainer:
9031                   {
9032                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
9033                      {
9034                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,\
9035                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
9036                      }
9037                      break;
9038                   }
9039                   case ProtocolIE_ID_id_DUtoCURRCContainer:
9040                   {
9041                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf)
9042                      {
9043                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf,
9044                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.size);
9045                      }
9046                      break;
9047                   }
9048                   default:
9049                      break;
9050                }
9051              }
9052              for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
9053              {
9054                 if(initULRRCMsg->protocolIEs.list.array[arrIdx])
9055                 {
9056                    DU_FREE(initULRRCMsg->protocolIEs.list.array[arrIdx],\
9057                       sizeof(InitialULRRCMessageTransferIEs_t));
9058                 }
9059              }
9060              DU_FREE(initULRRCMsg->protocolIEs.list.array, initULRRCMsg->protocolIEs.list.size);
9061           }
9062          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
9063       }
9064       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
9065    }
9066    else
9067    {
9068       DU_LOG("\nERROR  -->  DU_APP : Recevied F1ap Pdu is null at freeInitUlRrcMsgTransfer()");
9069       return RFAILED;
9070    }
9071    return ROK;
9072 }
9073
9074 /*******************************************************************
9075  *
9076  * @brief Builds and sends the InitialULRRCMessage 
9077  *
9078  * @details
9079  *
9080  *    Function : BuildAndSendInitialRrcMsgTransfer 
9081  *
9082  *    Functionality: Constructs the Initial UL RRC Message Transfer and sends
9083  *                   it to the CU through SCTP.
9084  *
9085  * @params[in] 
9086  *
9087  * @return ROK     - success
9088  *         RFAILED - failure
9089  *
9090  * ****************************************************************/
9091 uint8_t BuildAndSendInitialRrcMsgTransfer(uint32_t gnbDuUeF1apId, uint16_t crnti,
9092       uint16_t rrcContSize, uint8_t *rrcContainer)
9093 {
9094    uint8_t   ret;
9095    uint8_t   elementCnt;
9096    uint8_t   ieIdx, cellIdx, ueIdx;
9097    DuUeCb    *duUeCb = NULLP;
9098    asn_enc_rval_t  encRetVal;
9099    F1AP_PDU_t  *f1apMsg = NULLP;
9100    InitialULRRCMessageTransfer_t *initULRRCMsg = NULLP;
9101    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
9102
9103    while(true)
9104    {
9105       DU_LOG("\n INFO   -->  F1AP : Building RRC Setup Request\n");
9106       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
9107       if(f1apMsg == NULLP)
9108       {
9109          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
9110          break;
9111       }
9112       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
9113       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
9114       if(f1apMsg->choice.initiatingMessage == NULLP)
9115       {
9116          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU failed");
9117          break;
9118       }
9119       f1apMsg->choice.initiatingMessage->procedureCode =\
9120                                                         ProcedureCode_id_InitialULRRCMessageTransfer;
9121       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
9122       f1apMsg->choice.initiatingMessage->value.present = \
9123                                                          InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
9124       initULRRCMsg =\
9125                     &f1apMsg->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
9126       elementCnt = 5;
9127       initULRRCMsg->protocolIEs.list.count = elementCnt;
9128       initULRRCMsg->protocolIEs.list.size = \
9129                                             elementCnt * sizeof(InitialULRRCMessageTransferIEs_t *);
9130       /* Initialize the F1Setup members */
9131       DU_ALLOC(initULRRCMsg->protocolIEs.list.array,initULRRCMsg->protocolIEs.list.size);
9132       if(initULRRCMsg->protocolIEs.list.array == NULLP)
9133       {
9134          DU_LOG(" ERROR  -->  F1AP : Memory allocation for\
9135                RRCSetupRequestMessageTransferIEs failed");
9136          break;
9137       }
9138       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
9139       {
9140          DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx],\
9141                sizeof(InitialULRRCMessageTransferIEs_t));
9142          if(initULRRCMsg->protocolIEs.list.array[ieIdx] == NULLP)
9143          {
9144             break;
9145          }
9146       }
9147       ieIdx = 0;
9148       /*GNB DU UE F1AP ID*/
9149       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9150                                                         ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
9151       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  = Criticality_reject;
9152       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
9153                                                                   InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
9154       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
9155
9156
9157       /*NRCGI*/
9158       ieIdx++;
9159       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9160                                                         ProtocolIE_ID_id_NRCGI;
9161       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  =Criticality_reject;
9162       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
9163                                                                   InitialULRRCMessageTransferIEs__value_PR_NRCGI;
9164
9165       ret =\
9166            BuildNrcgi(&initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
9167       if(ret!=ROK)
9168       {
9169          break;
9170       }
9171
9172       /*CRNTI*/
9173       ieIdx++;
9174       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9175                                                         ProtocolIE_ID_id_C_RNTI;
9176       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9177       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9178                                                                  InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
9179       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.C_RNTI = crnti;
9180
9181       /*RRCContainer*/
9182       ieIdx++;
9183       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9184                                                         ProtocolIE_ID_id_RRCContainer;
9185       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9186       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9187                                                                  InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
9188
9189       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size = rrcContSize;
9190       DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,
9191             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size)
9192       if(!initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
9193       {
9194          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRCSetupRequestMessageTransferIEs failed");
9195          break;
9196       
9197       }
9198       memcpy(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, rrcContainer,
9199             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
9200
9201
9202       /*DUtoCURRCContainer*/
9203       ieIdx++;
9204       initULRRCMsg->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCContainer;
9205       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9206       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9207                                                                  InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
9208
9209       for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
9210       {
9211          for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
9212          {
9213             if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
9214                   (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti == crnti))
9215             {
9216                duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
9217             }
9218          }
9219       }
9220
9221       ret = BuildCellGroupConfigRrc(duUeCb, &initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer);
9222       if(ret != ROK)
9223       {
9224          break;
9225       }
9226
9227       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
9228
9229       /* Encode the Intial UL RRC Message transfer as APER */
9230       memset(encBuf, 0, ENC_BUF_MAX_LEN);
9231       encBufSize = 0;
9232       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
9233       /* Encode results */
9234       if(encRetVal.encoded == ENCODE_FAIL)
9235       {
9236          DU_LOG( "\nERROR  --> F1AP : Could not encode Initial UL RRC Message Transfer\
9237                structure (at %s)\n",encRetVal.failed_type ? \
9238                encRetVal.failed_type->name : "unknown");
9239          ret = RFAILED;
9240          break;
9241       }
9242       else
9243       {
9244
9245          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Initial UL RRC\
9246                Message transfer\n");
9247 #ifdef DEBUG_ASN_PRINT
9248          for(int i=0; i< encBufSize; i++)
9249          {
9250             printf("%x",encBuf[i]);
9251          }
9252 #endif
9253       }
9254       /* Sending  msg  */
9255       if(sendF1APMsg() != ROK)
9256       {
9257          DU_LOG("\nERROR  -->  F1AP : Sending Initial UL RRC Message Transfer Failed");
9258          ret = RFAILED;
9259          break;
9260       }
9261       break;
9262    }
9263    freeInitUlRrcMsgTransfer(f1apMsg);
9264    return ret;
9265 }/* End of BuildAndSendInitialRrcMsgTransfer*/
9266
9267 /*****  UE SETUP REQUEST *****/
9268
9269 /******************************************************************
9270 *
9271 * @brief Function to delete the RLC Lc cfg from UE APP DB
9272 *
9273 * @details
9274 *
9275 *  Function : freeRlcLcCfg
9276 *
9277 *  Functionality: Function to delete the RLC Lc cfg from UE APP DB
9278 *
9279 *
9280  *****************************************************************/
9281
9282 void freeRlcLcCfg(RlcBearerCfg *lcCfg)
9283 {
9284    switch(lcCfg->rlcMode)
9285    {
9286       case RLC_AM :
9287          {
9288             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
9289             break;
9290          }
9291       case RLC_UM_BI_DIRECTIONAL :
9292          {
9293             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
9294             break;
9295          }
9296       case RLC_UM_UNI_DIRECTIONAL_UL :
9297          {
9298             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
9299             break;
9300          }
9301       case RLC_UM_UNI_DIRECTIONAL_DL :
9302          {
9303             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
9304             break;
9305          }
9306       default:
9307          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at freeRlcLcCfg()", lcCfg->rlcMode);
9308          break;
9309    }
9310    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
9311 }
9312
9313 /*******************************************************************
9314  *
9315  * @brief Function to free MacLcCfg
9316  *
9317  * @details
9318  *
9319  *    Function : freeMacLcCfg
9320  *
9321  *    Functionality: Function to free MacLcCfg
9322  *
9323  * @params[in] LcCfg *lcCfg,
9324  * @return void
9325  *
9326  * ****************************************************************/
9327
9328 void freeMacLcCfg(LcCfg *lcCfg)
9329 {
9330     /* Deleting DRBQOS */
9331    if(lcCfg->drbQos)
9332    {
9333       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
9334    }
9335    /* Deleting SNSSAI */
9336    if(lcCfg->snssai)
9337    {
9338       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
9339    }
9340 }
9341 /*******************************************************************
9342  *
9343  * @brief Free UE NR Capability received in UE Context setup request
9344  *
9345  * @details
9346  *
9347  *    Function : freeAperDecodeUeNrCapability
9348  *
9349  *    Functionality:  
9350  *       Free UE NR Capability received in UE Context setup request
9351  *
9352  * @params[in] 
9353  * @return ROK     - success
9354  *         RFAILED - failure
9355  *
9356  * ****************************************************************/
9357 void freeAperDecodeUeNrCapability(void *ueNrCapability)
9358 {
9359    uint8_t arrIdx =0;
9360    FeatureSets_t *featureSets =NULLP;
9361    UE_NR_Capability_t *ueNrCap = (UE_NR_Capability_t *)ueNrCapability;
9362
9363    if(ueNrCap->rf_Parameters.supportedBandListNR.list.array)
9364    {
9365       for(arrIdx = 0; arrIdx < ueNrCap->rf_Parameters.supportedBandListNR.list.count; arrIdx++)
9366       {
9367          if(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx])
9368             free(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx]);
9369       }
9370       free(ueNrCap->rf_Parameters.supportedBandListNR.list.array);
9371    }
9372
9373    if(ueNrCap->featureSets)
9374    {
9375       featureSets = ueNrCap->featureSets;
9376       if(featureSets->featureSetsDownlinkPerCC)
9377       {
9378          if(featureSets->featureSetsDownlinkPerCC->list.array)
9379          {
9380             for(arrIdx = 0; arrIdx < featureSets->featureSetsDownlinkPerCC->list.count; arrIdx++)
9381             {
9382                if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx])
9383                {
9384                   if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL)
9385                      free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL);
9386                   free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]);
9387                }
9388             }
9389             free(featureSets->featureSetsDownlinkPerCC->list.array);
9390          }
9391          free(featureSets->featureSetsDownlinkPerCC);
9392       }
9393       if(featureSets->featureSetsUplinkPerCC)
9394       {
9395          if(featureSets->featureSetsUplinkPerCC->list.array)
9396          {
9397             for(arrIdx = 0; arrIdx < featureSets->featureSetsUplinkPerCC->list.count; arrIdx++)
9398             {
9399                if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx])
9400                {
9401                   if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL)
9402                      free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL);
9403                   free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]);
9404                }
9405             }
9406             free(featureSets->featureSetsUplinkPerCC->list.array);
9407          }
9408          free(featureSets->featureSetsUplinkPerCC);
9409       }
9410       free(ueNrCap->featureSets);
9411    }   
9412 }
9413
9414 /*******************************************************************
9415 *
9416 * @brief Function to free PdcchSearchSpcToAddModList
9417          where memory allocated by aper_decoder
9418 *
9419 * @details
9420 *
9421 *    Function : freeAperDecodePdcchSearchSpcToAddModList 
9422 *
9423 *    Functionality: Function to free PdcchSearchSpcToAddModList
9424 *
9425 * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
9426 * @return void
9427 *
9428 * ****************************************************************/
9429
9430 void freeAperDecodePdcchSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
9431 {
9432    uint8_t searchSpcArrIdx=0;
9433    uint8_t searchSpcArrIdx1=0;
9434    struct  SearchSpace *searchSpc=NULLP;
9435
9436
9437    if(searchSpcList->list.array)
9438    {
9439       if(searchSpcList->list.array[searchSpcArrIdx1])
9440       {
9441          searchSpc = searchSpcList->list.array[searchSpcArrIdx1];
9442          if(searchSpc->controlResourceSetId)
9443          {
9444             if(searchSpc->monitoringSlotPeriodicityAndOffset)
9445             {
9446                if(searchSpc->monitoringSymbolsWithinSlot)
9447                {
9448                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
9449                   {
9450                      if(searchSpc->nrofCandidates)
9451                      {
9452                         if(searchSpc->searchSpaceType)
9453                         {
9454                            free(searchSpc->searchSpaceType->choice.ue_Specific);
9455                            free(searchSpc->searchSpaceType);
9456                         }
9457                         free(searchSpc->nrofCandidates);
9458                      }
9459                      free(searchSpc->monitoringSymbolsWithinSlot->buf);
9460                   }
9461                   free(searchSpc->monitoringSymbolsWithinSlot);
9462                }
9463                free(searchSpc->monitoringSlotPeriodicityAndOffset);
9464             }
9465             free(searchSpc->controlResourceSetId);
9466          }
9467       }
9468       for(searchSpcArrIdx = 0; searchSpcArrIdx < searchSpcList->list.count; searchSpcArrIdx++)
9469       {
9470          free(searchSpcList->list.array[searchSpcArrIdx]);
9471       }
9472       free(searchSpcList->list.array);
9473    }
9474 }
9475 /*******************************************************************
9476 *
9477 * @brief Function for free part for the memory allocated by aper_decoder
9478
9479 * @details
9480 *
9481 *    Function : freeAperDecodeBWPDlDedPdcchConfig
9482 *
9483 *    Functionality: Function to free BWPDlDedPdcchConfig
9484 *
9485 * @params[in] 
9486 * @return void
9487 *
9488 * ****************************************************************/
9489
9490
9491 void freeAperDecodeBWPDlDedPdcchConfig(BWP_DownlinkDedicated_t *dlBwp)
9492 {
9493    uint8_t arrIdx1=0;
9494    uint8_t arrIdx2=0;
9495    struct PDCCH_Config *pdcchCfg=NULLP;
9496    struct ControlResourceSet *controlRSet=NULLP;
9497    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
9498    
9499    if(dlBwp->pdcch_Config->choice.setup)
9500    {
9501       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
9502       if(pdcchCfg->controlResourceSetToAddModList)
9503       {
9504          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
9505          if(controlRSetList->list.array)
9506          {
9507             controlRSet = controlRSetList->list.array[arrIdx2];
9508             if(controlRSet)
9509             {
9510                if(controlRSet->frequencyDomainResources.buf)
9511                {
9512                   if(controlRSet->pdcch_DMRS_ScramblingID)
9513                   {
9514                      if(pdcchCfg->searchSpacesToAddModList)
9515                      {
9516                         freeAperDecodePdcchSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
9517                         free(pdcchCfg->searchSpacesToAddModList);
9518                      }
9519                      free(controlRSet->pdcch_DMRS_ScramblingID);
9520                   }
9521                   free(controlRSet->frequencyDomainResources.buf);
9522                }
9523             }
9524             for(arrIdx1 = 0; arrIdx1 <controlRSetList->list.count; arrIdx1++)
9525             {
9526                free(controlRSetList->list.array[arrIdx1]);
9527             }
9528             free(controlRSetList->list.array);
9529          }
9530          free(pdcchCfg->controlResourceSetToAddModList);
9531       }
9532       free(dlBwp->pdcch_Config->choice.setup);
9533    }
9534 }
9535 /*******************************************************************
9536 *
9537 * @brief Function to free PdschTimeDomAllocationList 
9538 *     where the memory allocated by aper_decoder
9539
9540 * @details
9541 *
9542 *    Function : freeAperDecodePdschTimeDomAllocationList
9543 *
9544 *    Functionality: Function to free PdschTimeDomAllocationList
9545 *
9546 * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList 
9547 * @return void
9548 *
9549 * ****************************************************************/
9550
9551
9552 void freeAperDecodePdschTimeDomAllocationList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
9553 {
9554    uint8_t arrIdx=0;
9555
9556    if(timeDomAllocList->choice.setup)
9557    {
9558       if(timeDomAllocList->choice.setup->list.array)
9559       {
9560          for(arrIdx = 0; arrIdx <timeDomAllocList->choice.setup->list.count ; arrIdx++)
9561          {
9562             free(timeDomAllocList->choice.setup->list.array[arrIdx]);
9563          }
9564          free(timeDomAllocList->choice.setup->list.array);
9565       }
9566       free(timeDomAllocList->choice.setup);
9567    }
9568 }
9569
9570 /*******************************************************************
9571 *
9572 * @brief Function to free BWPDlDedPdschConfig 
9573 *        where the memory allocated by aper_decoder
9574 *  
9575 * @details
9576 *
9577 *    Function : freeAperDecodeBWPDlDedPdschConfig 
9578 *
9579 *    Functionality: Function to free BWPDlDedPdschConfig 
9580 *
9581 * @params[in] BWP_DownlinkDedicated_t *dlBwp 
9582 * @return void
9583 *
9584 * ****************************************************************/
9585
9586
9587 void freeAperDecodeBWPDlDedPdschConfig(BWP_DownlinkDedicated_t *dlBwp)
9588 {
9589    struct PDSCH_Config *pdschCfg=NULLP;
9590    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
9591    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
9592    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
9593
9594    if(dlBwp->pdsch_Config->choice.setup)
9595    {
9596       pdschCfg=dlBwp->pdsch_Config->choice.setup;
9597       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
9598       {
9599          if(pdschCfg->pdsch_TimeDomainAllocationList)
9600          {
9601             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
9602             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
9603             {
9604                prbBndlType=&pdschCfg->prb_BundlingType;
9605                free(prbBndlType->choice.staticBundling);
9606                free(pdschCfg->maxNrofCodeWordsScheduledByDCI);
9607             }
9608             freeAperDecodePdschTimeDomAllocationList(timeDomAllocList);
9609             free(pdschCfg->pdsch_TimeDomainAllocationList);
9610          }
9611          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
9612          if(dmrsDlCfg->choice.setup)
9613          {
9614             free(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition);
9615             free(dmrsDlCfg->choice.setup);
9616          }
9617          free(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA);
9618       }
9619       free(dlBwp->pdsch_Config->choice.setup);
9620    }
9621 }
9622 /*******************************************************************
9623 *
9624 * @brief Function to free PuschTimeDomAllocListCfg
9625                  where the memory allocated by aper_decoder
9626 *
9627 * @details
9628 *
9629 *    Function : freeAperDecodePuschTimeDomAllocListCfg
9630 *
9631 *    Functionality: Function to free PuschTimeDomAllocListCfg
9632 *
9633 * @params[in] PUSCH_Config_t *puschCfg 
9634 * @return void
9635 *
9636 * ****************************************************************/
9637
9638
9639 void freeAperDecodePuschTimeDomAllocListCfg(PUSCH_Config_t *puschCfg)
9640 {
9641    uint8_t arrIdx=0;
9642    uint8_t arrIdx1=0;
9643    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
9644
9645    if(puschCfg->pusch_TimeDomainAllocationList)
9646    {
9647       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
9648       if(timeDomAllocList_t->choice.setup)
9649       {
9650          if(timeDomAllocList_t->choice.setup->list.array)
9651          {
9652             free(timeDomAllocList_t->choice.setup->list.array[arrIdx1]->k2);
9653             for(arrIdx = 0; arrIdx<timeDomAllocList_t->choice.setup->list.count; arrIdx++)
9654             {
9655                free(timeDomAllocList_t->choice.setup->list.array[arrIdx]);
9656             }
9657             free(timeDomAllocList_t->choice.setup->list.array);
9658          }
9659          free(timeDomAllocList_t->choice.setup);
9660       }
9661       free(puschCfg->transformPrecoder);
9662       free(puschCfg->pusch_TimeDomainAllocationList);
9663    }
9664 }
9665 /*******************************************************************
9666 *
9667 * @brief Function to free InitialUlBWPConfig where memory allocated by aper_decoder
9668 *
9669 * @details
9670 *
9671 *    Function : freeAperDecodeInitialUlBWPConfig 
9672 *
9673 *    Functionality: Function to free InitialUlBWPConfig
9674 *
9675 * @params[in]  BWP_UplinkDedicated_t *ulBwp
9676 * @return void
9677 *
9678 * ****************************************************************/
9679
9680
9681 void freeAperDecodeInitialUlBWPConfig(BWP_UplinkDedicated_t *ulBwp)
9682 {
9683    uint8_t  rSetIdx =0;
9684    uint8_t  rsrcIdx =0;
9685    SRS_Config_t   *srsCfg = NULLP;
9686    PUSCH_Config_t *puschCfg = NULLP;
9687    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
9688    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
9689    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
9690    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
9691
9692    if(ulBwp->pusch_Config)
9693    {
9694       if(ulBwp->pusch_Config->choice.setup)
9695       {
9696          puschCfg=ulBwp->pusch_Config->choice.setup;
9697          if(puschCfg->dataScramblingIdentityPUSCH)
9698          {
9699             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
9700             {
9701                freeAperDecodePuschTimeDomAllocListCfg(puschCfg);
9702                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
9703                if(dmrsUlCfg->choice.setup)
9704                {
9705                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
9706                   {
9707                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
9708                      {
9709                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0);
9710                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled);
9711                      }
9712                      free(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition);
9713                   }
9714                   free(dmrsUlCfg->choice.setup);
9715                }
9716                free(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA);
9717             }
9718             free(puschCfg->dataScramblingIdentityPUSCH);
9719          }
9720          free(ulBwp->pusch_Config->choice.setup);
9721       }
9722       free(ulBwp->pusch_Config);
9723
9724       /* Free SRS-Config */
9725       if(ulBwp->srs_Config)
9726       {
9727          if(ulBwp->srs_Config->choice.setup)
9728          {
9729             srsCfg = ulBwp->srs_Config->choice.setup;
9730
9731             /* Free Resource Set to add/mod list */
9732             if(srsCfg->srs_ResourceSetToAddModList)
9733             {
9734                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
9735                if(rsrcSetList->list.array)
9736                {
9737                   rSetIdx = 0;
9738
9739                   /* Free SRS resource Id list in this SRS resource set */
9740                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
9741                   {
9742                      rsrcIdList =
9743                         rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
9744
9745                      if(rsrcIdList->list.array)
9746                      {
9747                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count;
9748                               rsrcIdx++)
9749                         {
9750                            free(rsrcIdList->list.array[rsrcIdx]);
9751                         }
9752                         free(rsrcIdList->list.array);
9753                      }
9754                      free(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList);
9755                   }
9756
9757                   /* Free resource type info for this SRS resource set */
9758
9759                   free(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic);
9760
9761                   /* Free memory for each resource set */
9762                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
9763                   {
9764                      free(rsrcSetList->list.array[rSetIdx]);
9765                   }
9766                   free(rsrcSetList->list.array);
9767                }
9768                free(srsCfg->srs_ResourceSetToAddModList);
9769             }
9770
9771             /* Free resource to add/modd list */
9772             if(srsCfg->srs_ResourceToAddModList)
9773             {
9774                resourceList = srsCfg->srs_ResourceToAddModList;
9775                if(resourceList->list.array)
9776                {
9777                   rsrcIdx = 0;
9778
9779                   free(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2);
9780                   free(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic);
9781
9782                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
9783                   {
9784                      free(resourceList->list.array[rsrcIdx]);
9785                   }
9786                   free(resourceList->list.array);
9787                }
9788                free(srsCfg->srs_ResourceToAddModList);
9789             }
9790
9791             free(ulBwp->srs_Config->choice.setup);
9792          }
9793          free(ulBwp->srs_Config);
9794       }
9795    }
9796 }
9797 /*******************************************************************
9798 *
9799 * @brief Function to free initialUplinkBWPConfig where memory allocated by aper_decoder
9800 *
9801 * @details
9802 *
9803 *    Function : freeAperDecodeinitialUplinkBWPConfig
9804 *
9805 *    Functionality: Function to free initialUplinkBWPConfig
9806 *
9807 * @params[in] UplinkConfig_t *ulCfg 
9808 * @return void
9809 *
9810 * ****************************************************************/
9811
9812
9813 void freeAperDecodeinitialUplinkBWPConfig(UplinkConfig_t *ulCfg)
9814 {
9815    BWP_UplinkDedicated_t *ulBwp=NULLP;
9816    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
9817    
9818    if(ulCfg->initialUplinkBWP)
9819    {
9820       ulBwp=ulCfg->initialUplinkBWP;
9821       if(ulCfg->firstActiveUplinkBWP_Id)
9822       {
9823          if(ulCfg->pusch_ServingCellConfig)
9824          {
9825             puschCfg=ulCfg->pusch_ServingCellConfig;
9826             if(puschCfg->choice.setup)
9827             {
9828                if(puschCfg->choice.setup->ext1)
9829                {
9830                   free(puschCfg->choice.setup->ext1->processingType2Enabled);
9831                   free(puschCfg->choice.setup->ext1->maxMIMO_Layers);
9832                   free(puschCfg->choice.setup->ext1);
9833                }
9834                free(puschCfg->choice.setup);
9835             }
9836             free(ulCfg->pusch_ServingCellConfig);
9837          }
9838          free(ulCfg->firstActiveUplinkBWP_Id);
9839       }
9840       freeAperDecodeInitialUlBWPConfig(ulBwp);
9841       free(ulCfg->initialUplinkBWP);
9842    }
9843 }
9844
9845 /*******************************************************************
9846  *
9847  * @brief Function to free DuUeCfg
9848  *
9849  * @details
9850  *
9851  *    Function : freeDuUeCfg
9852  *
9853  *    Functionality: Function to free DuUeCfg
9854  *
9855  * @params[in] DuUeCfg *ueCfg
9856  * @return void
9857  *
9858  * ****************************************************************/
9859 void freeDuUeCfg(UeCtxtActionType actionType, DuUeCfg *ueCfg)
9860 {
9861    uint8_t lcIdx = 0;
9862    uint8_t arrIdx = 0;
9863    SpCellConfig_t *spCellCfg = NULLP;
9864    ServingCellConfig_t *srvCellCfg = NULLP;
9865    BWP_DownlinkDedicated_t *dlBwp = NULLP;
9866    MAC_CellGroupConfig_t *macCellGrpCfg = NULLP;
9867    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
9868    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList = NULLP;
9869    struct RLC_Config *rlcConfig = NULLP;
9870    struct LogicalChannelConfig *macLcConfig = NULLP;
9871    struct SchedulingRequestConfig *schedulingRequestConfig = NULLP;
9872    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList = NULLP;
9873    struct TAG_Config *tagConfig = NULLP;
9874    struct TAG_Config__tag_ToAddModList *tagList = NULLP;
9875    struct MAC_CellGroupConfig__phr_Config *phrConfig = NULLP;
9876    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg = NULLP;
9877    CellGroupConfigRrc_t *cellGrpCfg = ueCfg->cellGrpCfg;
9878   
9879    if(ueCfg->ueNrCapability)
9880    {
9881       freeAperDecodeUeNrCapability(ueCfg->ueNrCapability);
9882       DU_FREE(ueCfg->ueNrCapability, sizeof(UE_NR_Capability_t));
9883       ueCfg->ueNrCapability = NULLP;
9884    }
9885
9886    if(ueCfg->cellGrpCfg)
9887    {
9888       rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
9889       if(rlcBearerList)
9890       {
9891          if(rlcBearerList->list.array)
9892          {
9893             for(arrIdx=0; arrIdx<rlcBearerList->list.count; arrIdx++)
9894             {
9895                if(rlcBearerList->list.array[arrIdx])
9896                {
9897                   rlcConfig   = rlcBearerList->list.array[arrIdx]->rlc_Config;
9898                   macLcConfig = rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig;
9899
9900                   if(rlcBearerList->list.array[arrIdx]->servedRadioBearer)
9901                   {
9902                      free(rlcBearerList->list.array[arrIdx]->servedRadioBearer);
9903                   }
9904                   if(rlcConfig)
9905                   {
9906                      if(rlcConfig->choice.am)
9907                      {
9908                         free(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength);
9909                         free(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength);
9910                         free(rlcConfig->choice.am);
9911                      }
9912                      free(rlcBearerList->list.array[arrIdx]->rlc_Config);
9913                   }
9914                   if(macLcConfig)
9915                   {
9916                      if(macLcConfig->ul_SpecificParameters)
9917                      {
9918                         free(macLcConfig->ul_SpecificParameters->schedulingRequestID);
9919                         free(macLcConfig->ul_SpecificParameters->logicalChannelGroup);
9920                         free(macLcConfig->ul_SpecificParameters);
9921                      }
9922                      free(rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig);
9923                   }
9924                   free(rlcBearerList->list.array[arrIdx]); 
9925                }
9926             }
9927             free(rlcBearerList->list.array);
9928          }
9929          free(cellGrpCfg->rlc_BearerToAddModList);
9930       }
9931
9932       macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
9933       if(macCellGrpCfg)
9934       {
9935          schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig;
9936          if(schedulingRequestConfig)
9937          {
9938             schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
9939             if(schReqList)
9940             {
9941                if(schReqList->list.array)
9942                {
9943                   for(arrIdx=0;arrIdx<schReqList->list.count; arrIdx++)
9944                   {
9945                      if(schReqList->list.array[arrIdx])
9946                      {
9947                         free(schReqList->list.array[arrIdx]->sr_ProhibitTimer); 
9948                         free(schReqList->list.array[arrIdx]);
9949                      }
9950                   }
9951                   free(schReqList->list.array);
9952                }
9953                free(schedulingRequestConfig->schedulingRequestToAddModList);
9954             }
9955             free(macCellGrpCfg->schedulingRequestConfig);
9956          }
9957          if(macCellGrpCfg->bsr_Config)
9958          {
9959             free(macCellGrpCfg->bsr_Config);
9960          }
9961          tagConfig = macCellGrpCfg->tag_Config;
9962          if(tagConfig)
9963          {
9964             tagList = tagConfig->tag_ToAddModList;
9965             if(tagList)
9966             {
9967                if(tagList->list.array)
9968                {
9969                   for(arrIdx=0; arrIdx<tagList->list.count; arrIdx++)
9970                   {
9971                      free(tagList->list.array[arrIdx]);
9972                   }
9973                   free(tagList->list.array);
9974                }
9975                free(tagConfig->tag_ToAddModList);
9976             }
9977             free(tagConfig); 
9978          }
9979
9980          phrConfig = macCellGrpCfg->phr_Config;
9981          if(phrConfig)
9982          {
9983             free(phrConfig->choice.setup); 
9984             free(phrConfig); 
9985          }
9986
9987          free(macCellGrpCfg); 
9988       }
9989
9990       phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
9991       if(phyCellGrpCfg)
9992       {
9993          free(phyCellGrpCfg->p_NR_FR1);
9994          free(phyCellGrpCfg); 
9995       }
9996
9997       spCellCfg = cellGrpCfg->spCellConfig;
9998       if(spCellCfg)
9999       {
10000          if(spCellCfg->servCellIndex)
10001          {
10002             if(spCellCfg->rlmInSyncOutOfSyncThreshold)
10003             {
10004                if(spCellCfg->spCellConfigDedicated)
10005                {
10006                   srvCellCfg = spCellCfg->spCellConfigDedicated;
10007                   if(srvCellCfg->initialDownlinkBWP)
10008                   {
10009                      dlBwp = srvCellCfg->initialDownlinkBWP;
10010                      if(srvCellCfg->firstActiveDownlinkBWP_Id)
10011                      {
10012                         if(srvCellCfg->defaultDownlinkBWP_Id)
10013                         {
10014                            if(srvCellCfg->uplinkConfig)
10015                            {
10016
10017                               if(srvCellCfg->pdsch_ServingCellConfig)
10018                               {
10019                                  pdschCfg=
10020                                     srvCellCfg->pdsch_ServingCellConfig;
10021                                  if(pdschCfg->choice.setup)
10022                                  {
10023
10024                                     free(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH);
10025                                     free(pdschCfg->choice.setup);
10026                                  }
10027
10028                                  free(srvCellCfg->pdsch_ServingCellConfig);
10029                               }
10030
10031                               freeAperDecodeinitialUplinkBWPConfig(srvCellCfg->uplinkConfig);
10032                               free(srvCellCfg->uplinkConfig);
10033                            }
10034                            free(srvCellCfg->defaultDownlinkBWP_Id);
10035                         }
10036
10037                         free(srvCellCfg->firstActiveDownlinkBWP_Id);
10038                      }
10039                      if(dlBwp->pdcch_Config)
10040                      {
10041                         if(dlBwp->pdsch_Config)
10042                         {
10043                            freeAperDecodeBWPDlDedPdschConfig(dlBwp);
10044                            free(dlBwp->pdsch_Config);
10045                         }
10046                         freeAperDecodeBWPDlDedPdcchConfig(dlBwp);
10047                         free(dlBwp->pdcch_Config);
10048                      }
10049                      free(srvCellCfg->initialDownlinkBWP);
10050                   }
10051
10052                   free(spCellCfg->spCellConfigDedicated);
10053                }
10054                free(spCellCfg->rlmInSyncOutOfSyncThreshold);
10055             }
10056             free(spCellCfg->servCellIndex); 
10057          }
10058          free(spCellCfg);
10059       }
10060       DU_FREE(ueCfg->cellGrpCfg, sizeof(CellGroupConfigRrc_t));
10061       ueCfg->cellGrpCfg = NULLP;
10062    }
10063
10064    if(ueCfg->ambrCfg)
10065    {
10066       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCfg->ambrCfg, sizeof(AmbrCfg));
10067    }
10068
10069    if(actionType != UE_CTXT_CFG_QUERY)
10070    {
10071       for(lcIdx = 0; lcIdx < ueCfg->numRlcLcs; lcIdx++)
10072       {
10073          freeRlcLcCfg(&ueCfg->rlcLcCfg[lcIdx].rlcBearerCfg);
10074       }
10075    }
10076
10077    for(lcIdx = 0; lcIdx < ueCfg->numMacLcs; lcIdx++)
10078    {
10079       freeMacLcCfg(&ueCfg->macLcCfg[lcIdx].lcConfig);
10080    }
10081
10082    for(lcIdx = 0; lcIdx < ueCfg->numDrb; lcIdx++)
10083    {
10084       DU_FREE(ueCfg->upTnlInfo[lcIdx].tnlCfg1, sizeof(GtpTnlCfg));
10085    }
10086 }
10087
10088 /*******************************************************************
10089  *
10090  * @brief Function to free UecontextSetupDb
10091  *
10092  * @details
10093  *
10094  *    Function : freeF1UeDb
10095  *
10096  *    Functionality: Function to free UecontextSetupDb
10097  *
10098  * @params[in] UecontextSetupDb *
10099  * @return void
10100  *
10101  * ****************************************************************/
10102
10103 void freeF1UeDb(F1UeContextSetupDb *f1UeDb)
10104 {
10105    
10106    if(f1UeDb->dlRrcMsg)
10107    {
10108       if(f1UeDb->dlRrcMsg->rrcMsgPdu)
10109       {
10110         //DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,\
10111                f1UeDb->dlRrcMsg->rrcMsgPdu, f1UeDb->dlRrcMsg->rrcMsgSize);
10112       }
10113       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
10114    }
10115    freeDuUeCfg(f1UeDb->actionType, &f1UeDb->duUeCfg);
10116    memset(f1UeDb, 0, sizeof(F1UeContextSetupDb));
10117    DU_FREE(f1UeDb, sizeof(F1UeContextSetupDb));
10118 }
10119
10120 /*******************************************************************
10121  *
10122  * @brief Function to build Am cfg Info
10123  *
10124  * @details
10125  *
10126  *    Function : extractRlcAmCfg
10127  *
10128  *    Functionality: Function to build Am cfg Info
10129  *
10130  * @params[in] AmBearerCfg *
10131  *             void *
10132  *
10133  * @return ROK/RFAILED
10134  *
10135  * ****************************************************************/
10136
10137 void extractRlcAmCfg(AmBearerCfg *amCfgToSet, struct RLC_Config__am *rlcAmCfg)
10138 {
10139    if(rlcAmCfg)
10140    {
10141       /* UL AM */
10142       if(rlcAmCfg->dl_AM_RLC.sn_FieldLength)
10143       {
10144          amCfgToSet->ulAmCfg.snLenUl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->dl_AM_RLC.sn_FieldLength));
10145          /*TODO: Check the timer value when sent by real CU */
10146          amCfgToSet->ulAmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_Reassembly); 
10147          amCfgToSet->ulAmCfg.statProhTmr = convertProhibitTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_StatusProhibit);
10148       }
10149
10150       /* DL AM */
10151       if(rlcAmCfg->ul_AM_RLC.sn_FieldLength)
10152       {
10153          amCfgToSet->dlAmCfg.snLenDl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->ul_AM_RLC.sn_FieldLength));
10154          amCfgToSet->dlAmCfg.pollRetxTmr = covertPollRetxTmrEnumToValue(rlcAmCfg->ul_AM_RLC.t_PollRetransmit);
10155          amCfgToSet->dlAmCfg.pollPdu   = covertPollPduEnumToValue(rlcAmCfg->ul_AM_RLC.pollPDU);
10156          amCfgToSet->dlAmCfg.pollByte  = covertPollByteEnumToValue(rlcAmCfg->ul_AM_RLC.pollByte);
10157          amCfgToSet->dlAmCfg.maxRetxTh = covertMaxRetxEnumToValue(rlcAmCfg->ul_AM_RLC.maxRetxThreshold);
10158       }
10159    }
10160 }
10161
10162 /*******************************************************************
10163  *
10164  * @brief Function to build Um Bi Info
10165  *
10166  * @details
10167  *
10168  *    Function : extractRlcUmBiCfg
10169  *
10170  *    Functionality: Function to build Um Bi Info
10171  *
10172  * @params[in] UmBiDirBearerCfg *
10173  *             void *
10174  *
10175  * @return ROK/RFAILED
10176  *
10177  * ****************************************************************/
10178
10179 void extractRlcUmBiCfg(UmBiDirBearerCfg *umBiCfgToSet, struct RLC_Config__um_Bi_Directional *rlcBiCfg)
10180 {
10181    if(rlcBiCfg)
10182    {
10183       /* UL UM BI DIR Cfg */
10184       if(rlcBiCfg->dl_UM_RLC.sn_FieldLength)
10185       {
10186          umBiCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->dl_UM_RLC.sn_FieldLength));
10187          umBiCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcBiCfg->dl_UM_RLC.t_Reassembly);
10188       }
10189
10190       /* DL UM BI DIR Cfg */
10191       if(rlcBiCfg->ul_UM_RLC.sn_FieldLength)
10192          umBiCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->ul_UM_RLC.sn_FieldLength));
10193    }
10194 }
10195
10196 /*******************************************************************
10197  *
10198  * @brief Function to build Um Ul Info
10199  *
10200  * @details
10201  *
10202  *    Function : extractRlcUmUlCfg
10203  *
10204  *    Functionality: Function to build Um Ul Info
10205  *
10206  * @params[in] UmUniDirUlBearerCfg *
10207  *             void *
10208  *
10209  * @return ROK/RFAILED
10210  *
10211  * ****************************************************************/
10212
10213 void extractRlcUmUlCfg(UmUniDirUlBearerCfg *umUlCfgToSet, struct RLC_Config__um_Uni_Directional_DL *umUlCfg)
10214 {
10215    if(umUlCfg)
10216    {
10217       if(umUlCfg->dl_UM_RLC.sn_FieldLength)
10218       {
10219          umUlCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umUlCfg->dl_UM_RLC.sn_FieldLength));
10220          umUlCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(umUlCfg->dl_UM_RLC.t_Reassembly);
10221       }
10222    }
10223 }
10224
10225 /*******************************************************************
10226  *
10227  * @brief Function to build Um Uni Dl Info
10228  *
10229  * @details
10230  *
10231  *    Function : extractRlcUmDlCfg
10232  *
10233  *    Functionality: Function to build Um Uni Dl Info
10234  *
10235  * @params[in] UmUniDirDlBearerCfg *
10236  *             void *
10237  *
10238  * @return ROK/RFAILED
10239  *
10240  * ****************************************************************/
10241 void extractRlcUmDlCfg(UmUniDirDlBearerCfg *umDlCfgToSet, struct RLC_Config__um_Uni_Directional_UL *umDlCfg)
10242 {
10243    if(umDlCfg)
10244    {
10245       if(umDlCfg->ul_UM_RLC.sn_FieldLength)
10246          umDlCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umDlCfg->ul_UM_RLC.sn_FieldLength));
10247    }
10248 }
10249
10250 /*******************************************************************
10251  *
10252  * @brief Function to extractRlcModeCfg
10253  *
10254  * @details
10255  *
10256  *    Function : extractRlcModeCfg
10257  *
10258  *    Functionality: Function to extractRlcModeCfg
10259  *
10260  * @params[in] RLC_Config_t *
10261  *             RlcBearerCfg *
10262  *             void  *    
10263  * @return ROK/RFAILED
10264  *
10265  * ****************************************************************/
10266 void extractRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *rlcDbCfg, RLC_Config_t *lcCfg)
10267 {
10268    if(lcCfg)
10269    {
10270       switch(rlcMode)
10271       {
10272          case RLC_AM :
10273             {
10274                if(lcCfg->choice.am)
10275                {
10276                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.amCfg, sizeof(AmBearerCfg));
10277                   if(rlcDbCfg->u.amCfg)
10278                      extractRlcAmCfg(rlcDbCfg->u.amCfg, lcCfg->choice.am);
10279                }
10280                break;
10281             }
10282          case RLC_UM_BI_DIRECTIONAL :
10283             {
10284                if(lcCfg->choice.um_Bi_Directional)
10285                {
10286                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
10287                   if(rlcDbCfg->u.umBiDirCfg)
10288                      extractRlcUmBiCfg(rlcDbCfg->u.umBiDirCfg, lcCfg->choice.um_Bi_Directional);
10289                }
10290                break;
10291             }
10292          case RLC_UM_UNI_DIRECTIONAL_UL :
10293             {
10294                if(lcCfg->choice.um_Uni_Directional_DL)
10295                {
10296                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
10297                   if(rlcDbCfg->u.umUniDirUlCfg)
10298                      extractRlcUmUlCfg(rlcDbCfg->u.umUniDirUlCfg, lcCfg->choice.um_Uni_Directional_DL);
10299                }
10300                break;
10301             }
10302          case RLC_UM_UNI_DIRECTIONAL_DL :
10303             {
10304                if(lcCfg->choice.um_Uni_Directional_UL)
10305                {
10306                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
10307                   if(rlcDbCfg->u.umUniDirDlCfg)
10308                      extractRlcUmDlCfg(rlcDbCfg->u.umUniDirDlCfg, lcCfg->choice.um_Uni_Directional_UL);
10309                }
10310                break;
10311             }
10312          default:
10313             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
10314             break;
10315       }
10316    }
10317 }
10318
10319 /*******************************************************************
10320  *
10321  * @brief Function to extract extractUlLcCfg
10322  *
10323  * @details
10324  *
10325  *    Function : extractUlLcCfg
10326  *
10327  *    Functionality: Function to extract extractUlLcCfg
10328  *
10329  * @params[in] UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg
10330  * @return void
10331  *
10332  * ****************************************************************/
10333
10334 void extractUlLcCfg(UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg)
10335 {
10336    if(ulLcCfg)
10337    {
10338       if(ulLcCfg->ul_SpecificParameters)
10339       {
10340          f1UlLcCfg->priority = \
10341             ulLcCfg->ul_SpecificParameters->priority;
10342       if(ulLcCfg->ul_SpecificParameters->logicalChannelGroup)
10343       {
10344          f1UlLcCfg->lcGroup = \
10345            *(ulLcCfg->ul_SpecificParameters->logicalChannelGroup);
10346       }
10347       if(ulLcCfg->ul_SpecificParameters->schedulingRequestID)
10348       {
10349          f1UlLcCfg->schReqId = \
10350            *(ulLcCfg->ul_SpecificParameters->schedulingRequestID);
10351       }
10352       f1UlLcCfg->pbr = \
10353          ulLcCfg->ul_SpecificParameters->prioritisedBitRate;
10354       f1UlLcCfg->bsd = \
10355          ulLcCfg->ul_SpecificParameters->bucketSizeDuration;
10356       }
10357    }
10358 }
10359
10360 /*******************************************************************
10361 *
10362 * @brief Function to extract Snssai Cfg Info from CU
10363 *
10364 * @details
10365 *
10366 *    Function : extractDrbSnssaiCfg
10367 *
10368 *    Functionality: Function to extract Drb Snssai Cfg Info from CU
10369 *
10370 * @params[in] DRB_Information_t *drbInfo, Snssai  *snssai
10371 * @return ROK/RFAILED
10372 *
10373 * ****************************************************************/
10374
10375 uint8_t extractDrbSnssaiCfg(SNSSAI_t *RecvSnssai, Snssai **snssaiToBeShared)
10376 {
10377    if(!(*snssaiToBeShared))
10378    {
10379       DU_ALLOC_SHRABL_BUF((*snssaiToBeShared), sizeof(Snssai));
10380       if(snssaiToBeShared == NULLP)
10381       {
10382          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Memory failed at allocating for SNSSAI ");
10383          return RFAILED;
10384       }
10385    }
10386    if(RecvSnssai)
10387    {
10388       memcpy(&(*snssaiToBeShared)->sst, RecvSnssai->sST.buf, RecvSnssai->sST.size);
10389       if(RecvSnssai->sD)
10390       {
10391          memcpy((*snssaiToBeShared)->sd, RecvSnssai->sD->buf,  RecvSnssai->sD->size);
10392       }
10393       else
10394       {
10395          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Received Null pointer of Snssai->SD");
10396          return RFAILED;
10397       }
10398    }
10399    return ROK;
10400 }
10401
10402 /*******************************************************************
10403  *
10404  * @brief Function to procRlcLcCfg
10405  *
10406  * @details
10407  *
10408  *    Function : procRlcLcCfg
10409  *
10410  *    Functionality: Function to procRlcLcCfg
10411  *
10412  * @params[in] rbId, lcId, rbType, rlcMod
10413  *             RLC_Config_t *, RlcBearerCfg * , 
10414  * @return void
10415  *
10416  * ****************************************************************/
10417
10418 void procRlcLcCfg(uint8_t rbId, uint8_t lcId, uint8_t rbType, uint8_t rlcMode,\
10419    uint8_t configType, RLC_Config_t *f1RlcCfg, DuRlcBearerCfg *lcCfg, QoSInformation_t *qoSInformation)
10420 {
10421    DRB_Information_t *drbInfo;
10422
10423    lcCfg->rlcBearerCfg.rbId   = rbId;
10424    lcCfg->configType = configType;
10425
10426    if(rbType == RB_TYPE_SRB)
10427    {
10428       lcCfg->rlcBearerCfg.rbType = RB_TYPE_SRB;
10429       lcCfg->rlcBearerCfg.lcId   = rbId;
10430       lcCfg->rlcBearerCfg.lcType = LCH_DCCH;
10431       lcCfg->rlcBearerCfg.rlcMode = RLC_AM;
10432    }
10433    else if(rbType == RB_TYPE_DRB)
10434    {
10435       lcCfg->rlcBearerCfg.rbType = RB_TYPE_DRB;
10436       lcCfg->rlcBearerCfg.lcId   = lcId;
10437       lcCfg->rlcBearerCfg.lcType = LCH_DTCH;
10438       lcCfg->rlcBearerCfg.rlcMode = rlcMode;
10439    }
10440    if(f1RlcCfg) /* rlc mode config recived */
10441    {
10442       extractRlcModeCfg(lcCfg->rlcBearerCfg.rlcMode, &lcCfg->rlcBearerCfg, f1RlcCfg);
10443    }
10444    if(qoSInformation != NULLP)
10445    {
10446       if(qoSInformation->present == QoSInformation_PR_choice_extension)
10447       {
10448          if(qoSInformation->choice.choice_extension->value.present ==\
10449                QoSInformation_ExtIEs__value_PR_DRB_Information)
10450          {
10451             drbInfo = &qoSInformation->choice.choice_extension->value.choice.DRB_Information; 
10452             if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &lcCfg->rlcBearerCfg.snssai) != ROK)
10453             {
10454                DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information at procRlcLcCfg()");
10455                return;
10456             }
10457          }
10458       }
10459    }
10460 }
10461
10462 /*******************************************************************
10463  *
10464  * @brief Fills DrbQos Info received by CU
10465  *
10466  * @details
10467  *
10468  *    Function : extractQosInfo
10469  *
10470  *    Functionality: Fills DrbQos Info received  by CU
10471  *
10472  * @params[in] DrbQosInfo *qosToAdd, 
10473  *             QoSFlowLevelQoSParameters_t *qosFlowCfg
10474  * @return void
10475  *
10476  * ****************************************************************/
10477
10478 void extractQosInfo(DrbQosInfo *qosToAdd, QoSFlowLevelQoSParameters_t *qosFlowCfg)
10479 {
10480    uint8_t qosCntIdx = 0;
10481    ProtocolExtensionContainer_4624P74_t *qosIeExt = NULLP;
10482
10483    qosToAdd->fiveQiType = qosFlowCfg->qoS_Characteristics.present;
10484    qosToAdd->u.nonDyn5Qi.fiveQi     =\
10485                                      qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->fiveQI;
10486    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow)
10487    {
10488       qosToAdd->u.nonDyn5Qi.avgWindow = \
10489                                         *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
10490    }
10491
10492    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume)
10493    {
10494       qosToAdd->u.nonDyn5Qi.maxDataBurstVol = \
10495                                               *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
10496    }
10497
10498    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel)
10499    {
10500       qosToAdd->u.nonDyn5Qi.priorLevel = \
10501                                          *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel);
10502    }
10503    qosToAdd->ngRanRetPri.priorityLevel = \
10504                                          qosFlowCfg->nGRANallocationRetentionPriority.priorityLevel; 
10505    qosToAdd->ngRanRetPri.preEmptionCap = \
10506                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionCapability;
10507    qosToAdd->ngRanRetPri.preEmptionVul = \
10508                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionVulnerability;
10509    if(qosFlowCfg->gBR_QoS_Flow_Information)
10510    {
10511       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateDl, \
10512             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.buf, \
10513             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.size);
10514       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateUl, \
10515             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.buf, \
10516             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.size);
10517       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateDl,\
10518             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.buf, \
10519             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.size);
10520       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateUl,\
10521             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.buf, \
10522             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.size);
10523    }
10524    /*Extracting PDU_SESSION_ID*/
10525    qosIeExt = (ProtocolExtensionContainer_4624P74_t *)qosFlowCfg->iE_Extensions;
10526    if(qosIeExt)
10527    {
10528       for(qosCntIdx = 0; qosCntIdx < qosIeExt->list.count; qosCntIdx++)
10529       {
10530          if(qosIeExt->list.array[qosCntIdx]->extensionValue.present == \
10531                QoSFlowLevelQoSParameters_ExtIEs__extensionValue_PR_PDUSessionID)
10532          {
10533             qosToAdd->pduSessionId = qosIeExt->list.array[qosCntIdx]->extensionValue.choice.PDUSessionID;
10534             DU_LOG("\nDEBUG -->  DU_F1AP : extractQosInfo: PDU SessionID:%d",qosToAdd->pduSessionId);
10535          }
10536       }  
10537    }
10538    qosToAdd->ulPduSessAggMaxBitRate = 0;
10539 }
10540
10541 /*******************************************************************
10542  *
10543  * @brief Function to extract GTP Tunnel Info from CU
10544  *
10545  * @details
10546  *
10547  *    Function : extractUpTnlInfo
10548  *
10549  *    Functionality: Function to extract GTP Tunnel Info from CU
10550  *
10551  * @params[in] F1AP message
10552  * @return ROK/RFAILED
10553  *
10554  * ****************************************************************/
10555
10556 uint8_t extractUpTnlInfo(uint8_t drbId, uint8_t configType,\
10557    ULUPTNLInformation_ToBeSetup_List_t *tnlInfo, UpTnlCfg *upTnlInfo)
10558 {
10559    uint8_t tnlIdx;
10560    uint32_t ipv4_du = 0;
10561    GTPTunnel_t *gtpTunnel = NULLP;
10562
10563    upTnlInfo->drbId = drbId; 
10564    upTnlInfo->configType = configType;
10565 #ifdef O1_ENABLE
10566    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
10567 #else
10568    cmInetAddr((char *)DU_IP_V4_ADDR, &ipv4_du);
10569 #endif
10570
10571    for(tnlIdx=0; tnlIdx < tnlInfo->list.count; tnlIdx++)
10572    {
10573       if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.present == UPTransportLayerInformation_PR_gTPTunnel)
10574       {
10575          if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel)
10576          {
10577             gtpTunnel = tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel;
10578             DU_ALLOC(upTnlInfo->tnlCfg1, sizeof(GtpTnlCfg));
10579             if(upTnlInfo->tnlCfg1 == NULLP)
10580             {
10581                DU_LOG("\nERROR  -->  F1AP : extractUpTnlInfo: Failed to allocate mmeory for tunnel cfg 1");
10582                return RFAILED;
10583             }
10584             bitStringToInt(&gtpTunnel->transportLayerAddress, &upTnlInfo->tnlCfg1->ulTnlAddress);
10585             upTnlInfo->tnlCfg1->dlTnlAddress = ipv4_du;
10586             if(gtpTunnel->gTP_TEID.size > 0)
10587             {
10588                teIdStringToInt(gtpTunnel->gTP_TEID.buf, &upTnlInfo->tnlCfg1->teId);
10589             }
10590          }
10591          break;
10592       }
10593    }
10594    return ROK;
10595 }
10596
10597 /*******************************************************************
10598 *
10599 * @brief Function to extract Drb Qos Cfg Info from CU
10600 *
10601 * @details
10602 *
10603 *    Function : extractDrbQosCfg 
10604 *
10605 *    Functionality: Function to extract Drb Qos Cfg Info from CU
10606 *
10607 * @params[in] DRB_Information_t *drbInfo, LcCfg *macLcToAdd
10608 * @return ROK/RFAILED
10609 *
10610 * ****************************************************************/
10611
10612 uint8_t extractDrbQosCfg(DRB_Information_t *drbInfo, LcCfg *macLcToAdd ) 
10613 {
10614    if(!macLcToAdd->drbQos)
10615    {
10616       DU_ALLOC_SHRABL_BUF(macLcToAdd->drbQos, sizeof(DrbQosInfo));
10617       if(macLcToAdd->drbQos == NULLP)
10618       {
10619          DU_LOG("\nERROR  -->  DUAPP:Memory failed at allocating DrbQos at extractDrbQosCfg()");
10620          return RFAILED;
10621       }
10622
10623    }
10624    if(drbInfo->dRB_QoS.qoS_Characteristics.present == QoS_Characteristics_PR_non_Dynamic_5QI)
10625    {
10626       extractQosInfo(macLcToAdd->drbQos, &drbInfo->dRB_QoS);
10627       macLcToAdd->dlLcCfg.lcp = macLcToAdd->drbQos->ngRanRetPri.priorityLevel;
10628    }
10629    if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &macLcToAdd->snssai) != ROK)
10630    {
10631       DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information  at extractDrbQosCfg()");
10632       return RFAILED;
10633    }
10634    return ROK;
10635 }
10636 /*******************************************************************
10637  *
10638  * @brief Function to extract DRB info received from CU
10639  *
10640  * @details
10641  *
10642  *    Function : extractDrbCfg
10643  *
10644  *    Functionality: Function to extract DRB info received from CU
10645  *
10646  * @params[in] F1AP message
10647  * @return void
10648  *
10649  * ****************************************************************/
10650 uint8_t extractDrbCfg(DRBs_ToBeSetup_Item_t *drbItem, DRBs_ToBeSetupMod_Item_t *drbSetupModItem,\
10651 DRBs_ToBeModified_Item_t *drbModItem,  DuLcCfg *lcCfgToAdd, UpTnlCfg *upTnlInfo)
10652 {
10653    DRB_Information_t *drbInfo = NULLP;
10654
10655    if(drbItem != NULLP)
10656    {
10657       if(extractUpTnlInfo(drbItem->dRBID, CONFIG_ADD, &drbItem->uLUPTNLInformation_ToBeSetup_List, upTnlInfo) != ROK)
10658       {
10659          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10660          return RFAILED;
10661       }
10662       if(drbItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10663       {
10664          if(drbItem->qoSInformation.choice.choice_extension->value.present == QoSInformation_ExtIEs__value_PR_DRB_Information)
10665          {
10666             drbInfo = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10667             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10668             {
10669                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");
10670                return RFAILED;
10671             }
10672          }
10673       }
10674    }
10675    else if(drbSetupModItem != NULLP)
10676    {
10677       if(extractUpTnlInfo(drbSetupModItem->dRBID, CONFIG_ADD, &drbSetupModItem->uLUPTNLInformation_ToBeSetup_List,\
10678       upTnlInfo) != ROK)
10679       {
10680          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10681          return RFAILED;
10682       }
10683       if(drbSetupModItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10684       {
10685          if(drbSetupModItem->qoSInformation.choice.choice_extension->value.present ==\
10686          QoSInformation_ExtIEs__value_PR_DRB_Information)
10687          {
10688             drbInfo = &drbSetupModItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10689             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10690             {
10691                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10692                return RFAILED;
10693             }
10694
10695          }
10696       }
10697    }
10698    else if(drbModItem != NULLP)
10699    {
10700       if(extractUpTnlInfo(drbModItem->dRBID, CONFIG_MOD, &drbModItem->uLUPTNLInformation_ToBeSetup_List,\
10701       upTnlInfo) != ROK)
10702       {
10703          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10704          return RFAILED;
10705       }
10706       if(drbModItem->qoSInformation != NULLP)
10707       {
10708          if(drbModItem->qoSInformation->present == QoSInformation_PR_choice_extension)
10709          {
10710             if(drbModItem->qoSInformation->choice.choice_extension->value.present ==\
10711                   QoSInformation_ExtIEs__value_PR_DRB_Information)
10712             {
10713                drbInfo = &drbModItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information;
10714                if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10715                {
10716                   DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10717                   return RFAILED;
10718                }
10719
10720             }
10721          }
10722       }
10723    }
10724    return ROK;
10725 }
10726
10727 /*******************************************************************
10728  *
10729  * @brief Function to extract RB info received from CU
10730  *
10731  * @details
10732  *
10733  *    Function : extractMacRbCfg
10734  *
10735  *    Functionality: Function to extract RB info received from CU
10736  *
10737  * @params[in] F1AP message
10738  * @return ROK/RFAILED
10739  *
10740  * ****************************************************************/
10741
10742 uint8_t extractMacRbCfg(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbCfg,\
10743 DRBs_ToBeSetupMod_Item_t *drbSetupModCfg,  DRBs_ToBeModified_Item_t *drbModCfg, LogicalChannelConfig_t *ulLcCfg, DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10744 {
10745    if(drbCfg != NULLP)
10746    {
10747       if(extractDrbCfg(drbCfg, NULL, NULL, lcCfg, upTnlInfo) != ROK)
10748       {
10749          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10750          return RFAILED;
10751       }
10752    }
10753    else if(drbSetupModCfg != NULLP)
10754    { 
10755       if(extractDrbCfg(NULL, drbSetupModCfg, NULL, lcCfg, upTnlInfo) != ROK)
10756       {
10757          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10758          return RFAILED;
10759       }
10760    }
10761    else if(drbModCfg != NULLP)
10762    { 
10763       if(extractDrbCfg(NULL, NULL, drbModCfg, lcCfg, upTnlInfo) != ROK)
10764       {
10765          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10766          return RFAILED;
10767       }
10768    }
10769    else
10770    {
10771       lcCfg->lcConfig.drbQos = NULLP;
10772       lcCfg->lcConfig.snssai = NULLP;
10773       if(lcCfg->lcConfig.lcId == SRB2_LCID)
10774          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_3;
10775       else
10776          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_1;
10777
10778    }
10779    if(ulLcCfg)
10780    {
10781       lcCfg->lcConfig.ulLcCfgPres = true;
10782       extractUlLcCfg(&lcCfg->lcConfig.ulLcCfg, ulLcCfg);
10783    }
10784    else
10785       lcCfg->lcConfig.ulLcCfgPres = false;
10786    return ROK;
10787 }
10788
10789 /*******************************************************************
10790  *
10791  * @brief Function processing LC config info received from CU
10792  *
10793  * @details
10794  *
10795  *    Function : procMacLcCfg
10796  *
10797  *    Functionality: Function processing LC config info received from CU
10798  *
10799  * @params[in] F1AP message
10800  * @return ROK/RFAILED
10801  *
10802  * ****************************************************************/
10803
10804 uint8_t procMacLcCfg(uint8_t lcId, uint8_t rbType, uint8_t configType, DRBs_ToBeSetup_Item_t *drbItem,\
10805 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LogicalChannelConfig_t *ulLcCfg,\
10806 DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10807 {
10808    uint8_t ret = ROK;
10809
10810    lcCfg->lcConfig.lcId = lcId;
10811    lcCfg->configType = configType;
10812    if(rbType == RB_TYPE_SRB)
10813    {
10814       ret = extractMacRbCfg(lcId, NULL, NULL, NULL, ulLcCfg, lcCfg, NULL);
10815    }
10816    else if(rbType == RB_TYPE_DRB && upTnlInfo != NULLP)
10817    {
10818       if(drbItem != NULL)
10819         ret = extractMacRbCfg(lcId, drbItem, NULL, NULL, ulLcCfg, lcCfg, upTnlInfo);
10820       else if(drbSetupModItem != NULL)
10821         ret = extractMacRbCfg(lcId, NULL, drbSetupModItem, NULL, ulLcCfg, lcCfg, upTnlInfo);
10822       else if(drbModItem != NULL)
10823         ret = extractMacRbCfg(lcId, NULL, NULL, drbModItem, ulLcCfg, lcCfg, upTnlInfo);
10824    }
10825    return ret;
10826 }
10827
10828 /*******************************************************************
10829  *
10830  * @brief Function to extract Rlc cfg To Add/Mod in CellGrp Info
10831  *
10832  * @details
10833  *
10834  *    Function : extractRlcCfgToAddMod
10835  *
10836  *    Functionality: Function to extract Rlc cfg To Add/Mod in CellGrp Info
10837  *
10838  * @params[in] CellGroupConfigRrc__rlc_BearerTo pointer
10839  *             DuUeCfg Pointer
10840  * @return ROK/RFAILED
10841  *
10842  * ****************************************************************/
10843
10844 uint8_t extractRlcCfgToAddMod(struct CellGroupConfigRrc__rlc_BearerToAddModList *lcCfg, DuUeCfg *ueCfgDb)
10845 {
10846   uint8_t idx, rbId, lcId, rlcMode, rbType;
10847   RLC_Config_t *f1RlcCfg = NULLP;
10848   LogicalChannelConfig_t *macUlLcCfg = NULLP;
10849
10850   for(idx = 0; idx < lcCfg->list.count; idx++)
10851   {
10852      lcId = lcCfg->list.array[idx]->logicalChannelIdentity;
10853      if(lcCfg->list.array[idx]->servedRadioBearer)
10854      {
10855         /* RadioBearer for SRB/DRB */
10856         if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10857         RLC_BearerConfig__servedRadioBearer_PR_srb_Identity)
10858         {
10859            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.srb_Identity;
10860            rbType = RB_TYPE_SRB;
10861         }
10862         else if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10863         RLC_BearerConfig__servedRadioBearer_PR_drb_Identity)
10864         {
10865            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.drb_Identity;
10866            rbType = RB_TYPE_DRB;
10867         }
10868         else
10869         {
10870            DU_LOG("\nERROR  -->  No components present in Bearer config to ADD/MOD");
10871            return RFAILED;
10872         }
10873         /* MAC UL LC Config */
10874         if(lcCfg->list.array[idx]->mac_LogicalChannelConfig)
10875         {
10876            macUlLcCfg = lcCfg->list.array[idx]->mac_LogicalChannelConfig;
10877         }
10878      }
10879      else
10880      {
10881         DU_LOG("\nERROR  -->  DUAPP: Received RadioBearer config is NULL");
10882         return RFAILED;
10883      }
10884      /* RLC Mode Config */
10885      if(lcCfg->list.array[idx]->rlc_Config)
10886      {
10887         rlcMode  = lcCfg->list.array[idx]->rlc_Config->present;
10888         f1RlcCfg = lcCfg->list.array[idx]->rlc_Config;
10889      }
10890      
10891      /* Filling RLC/MAC Config*/
10892      memset(&ueCfgDb->macLcCfg[idx], 0, sizeof(DuLcCfg));
10893      memset(&ueCfgDb->rlcLcCfg[idx], 0, sizeof(DuRlcBearerCfg));
10894      procRlcLcCfg(rbId, lcId, rbType, rlcMode, CONFIG_UNKNOWN, f1RlcCfg, &(ueCfgDb->rlcLcCfg[idx]), NULLP);
10895      if(procMacLcCfg(lcId, rbType, CONFIG_UNKNOWN, NULL, NULL, NULL, macUlLcCfg, &ueCfgDb->macLcCfg[idx], NULL) != ROK)
10896      {
10897         DU_LOG("\nERROR  -->  DU APP : Failed while filling MAC LC config at extractRlcCfgToAddMod()");
10898         return RFAILED;
10899      }
10900      (ueCfgDb->numRlcLcs)++;
10901      (ueCfgDb->numMacLcs)++;
10902      DU_LOG("\nDEBUG  -> DUAPP: extractRlcCfgToAddMod:RBType:%d, DrbID: %d,lcId:%d, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
10903         rbType, rbId, lcId, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
10904   }
10905   //TODO: To send the failure cause in UeContextSetupRsp 
10906   return ROK;
10907 }
10908
10909 /*******************************************************************
10910  *
10911  * @brief DeAlloc pdsch serv cell config info
10912  *
10913  * @details
10914  *
10915  *    Function : freeMacPdschServCellInfo
10916  *
10917  *    Functionality: DeAlloc pdsch serv cell config info
10918  *
10919  * @params[in] PdschServCellCfg pointer
10920  * @return void
10921  *
10922  * ****************************************************************/
10923
10924 void freeMacPdschServCellInfo(PdschServCellCfg *pdsch)
10925 {
10926    if(pdsch->xOverhead)
10927    {
10928       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->xOverhead, sizeof(PdschXOverhead));
10929    }
10930    if(pdsch->codeBlkGrpFlushInd)
10931    {
10932       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->codeBlkGrpFlushInd, sizeof(bool));
10933    }
10934    if(pdsch->maxCodeBlkGrpPerTb)
10935    {
10936       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10937    }
10938    if(pdsch->maxMimoLayers)
10939    {
10940       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxMimoLayers, sizeof(uint8_t));
10941    }
10942 }
10943
10944 /*******************************************************************
10945  *
10946  * @brief Free Serving cell Info
10947  *
10948  * @details
10949  *
10950  *    Function : freeMacServingCellInfo
10951  *
10952  *    Functionality: Free Serving cell Info
10953  *
10954  * @params[in] ServCellCfgInfo *srvCellCfg
10955  * @return void
10956  *
10957  * ****************************************************************/
10958 void freeMacServingCellInfo(ServCellRecfgInfo *srvCellCfg)
10959 {
10960    uint8_t timeDomRsrcIdx;
10961
10962    if(srvCellCfg->initDlBwp.pdschPresent)
10963    {
10964       for(timeDomRsrcIdx = 0; timeDomRsrcIdx < srvCellCfg->initDlBwp.pdschCfg.numTimeDomRsrcAlloc; timeDomRsrcIdx++)
10965       {
10966          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, \
10967             srvCellCfg->initDlBwp.pdschCfg.timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
10968       }
10969    }
10970
10971    freeMacPdschServCellInfo(&srvCellCfg->pdschServCellCfg);
10972    if(srvCellCfg->bwpInactivityTmr)
10973    {
10974       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
10975    }
10976
10977    if(srvCellCfg->initUlBwp.pucchPresent)
10978    {
10979       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->initUlBwp.pucchCfg.dlDataToUlAck, sizeof(PucchDlDataToUlAck));
10980    }
10981 }
10982
10983 /*******************************************************************
10984  *
10985  * @brief Free cell Grp Cfg Info
10986  *
10987  * @details
10988  *
10989  *    Function : freeUeRecfgCellGrpInfo
10990  *
10991  *    Functionality: Free cell Grp Cfg Info
10992  *
10993  * @params[in] DuMacUeCfg*  duUeCfg
10994  * @return void
10995  *
10996  * ****************************************************************/
10997
10998 void freeUeRecfgCellGrpInfo(DuMacUeCfg *macUeCfg)
10999 {
11000    freeMacServingCellInfo(&macUeCfg->spCellCfg.servCellCfg);
11001 }
11002
11003 /*******************************************************************
11004  *
11005  * @brief Fills Reconfig SchReqReConfig
11006  *
11007  * @details
11008  *
11009  *    Function : extractSchReqReConfig
11010  *
11011  *    Functionality: Fills Reconfig SchReqReConfig
11012  *
11013  * @params[in] SchedulingRequestConfig_t *cuSchedReq
11014  *             SchedReqCfg*  macSchedReq
11015  * @return void
11016  *
11017  * ****************************************************************/
11018 void extractSchReqReConfig(SchedulingRequestConfig_t *cuSchedReq, SchedReqCfg *macSchedReq)
11019 {
11020    uint8_t schReqIdx = 0;
11021    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqListToAdd = NULLP;
11022    struct SchedulingRequestConfig__schedulingRequestToReleaseList *schReqListToRel = NULLP;
11023
11024    if(cuSchedReq->schedulingRequestToAddModList)
11025    {
11026       schReqListToAdd = cuSchedReq->schedulingRequestToAddModList;
11027       if(schReqListToAdd->list.count)
11028       {
11029          macSchedReq->addModListCount = schReqListToAdd->list.count;
11030          for(schReqIdx = 0; schReqIdx < schReqListToAdd->list.count; schReqIdx++)
11031          {
11032             macSchedReq->addModList[schReqIdx].schedReqId = \
11033                schReqListToAdd->list.array[schReqIdx]->schedulingRequestId;
11034             macSchedReq->addModList[schReqIdx].srProhibitTmr = \
11035                *(schReqListToAdd->list.array[schReqIdx]->sr_ProhibitTimer);
11036             macSchedReq->addModList[schReqIdx].srTransMax    =\
11037                schReqListToAdd->list.array[schReqIdx]->sr_TransMax;
11038          }
11039       }
11040    }
11041    /* Scheduling Req To release */
11042    if(cuSchedReq->schedulingRequestToReleaseList)
11043    {
11044       schReqListToRel = cuSchedReq->schedulingRequestToReleaseList;
11045       if(schReqListToRel->list.count)
11046       {
11047          macSchedReq->relListCount = schReqListToRel->list.count;
11048          for(schReqIdx = 0; schReqIdx < schReqListToRel->list.count; schReqIdx++)
11049          {
11050             macSchedReq->relList[schReqIdx] = \
11051                *schReqListToRel->list.array[schReqIdx];
11052          }
11053       }
11054    }
11055 }
11056
11057 /*******************************************************************
11058  *
11059  * @brief Fills TagReconfig
11060  *
11061  * @details
11062  *
11063  *    Function : extractTagReconfig
11064  *
11065  *    Functionality: Fills extractTagReconfig
11066  *
11067  * @params[in] TAG_Config_t *cuTagCfg
11068  *             TagCfg *macTagCfg
11069  * @return void
11070  *
11071  * ****************************************************************/
11072
11073 void extractTagReconfig(TAG_Config_t *cuTagCfg, TagCfg *macTagCfg)
11074 {
11075   uint8_t tagIdx = 0;
11076   struct TAG_Config__tag_ToAddModList  *tagListToAddMod = NULLP;
11077   struct TAG_Config__tag_ToReleaseList *tagListToRel = NULLP;
11078
11079   /* Tag config to AddMod */
11080   if(cuTagCfg->tag_ToAddModList)
11081   {
11082      tagListToAddMod = cuTagCfg->tag_ToAddModList; 
11083      if(tagListToAddMod->list.count)
11084      {
11085         macTagCfg->addModListCount = tagListToAddMod->list.count;
11086         for(tagIdx = 0; tagIdx < tagListToAddMod->list.count; tagIdx++)
11087         {
11088            macTagCfg->addModList[tagIdx].tagId =\
11089               tagListToAddMod->list.array[tagIdx]->tag_Id;     
11090            macTagCfg->addModList[tagIdx].timeAlignTimer = \
11091
11092               tagListToAddMod->list.array[tagIdx]->timeAlignmentTimer;
11093         }
11094      }
11095   }
11096   /* Tag config to release */
11097   if(cuTagCfg->tag_ToReleaseList)
11098   {
11099      tagListToRel = cuTagCfg->tag_ToReleaseList;
11100      if(tagListToRel->list.count)
11101      {
11102         macTagCfg->relListCount = tagListToRel->list.count;
11103         for(tagIdx = 0; tagIdx < tagListToRel->list.count; tagIdx++)
11104         {
11105            macTagCfg->relList[tagIdx] = *tagListToRel->list.array[tagIdx];     
11106         }
11107      }
11108   }
11109 }
11110
11111 /*******************************************************************
11112  *
11113  * @brief Fills PdcchCfg received by CU
11114  *
11115  * @details
11116  *
11117  *    Function : extractPdcchCfg
11118  *
11119  *    Functionality: Fills PdcchCfg received  by CU
11120  *
11121  * @params[in] PDCCH_Config_t *cuPdcchCfg,
11122  *             PdcchConfig *duPdcchCfg
11123  * @return void
11124  *
11125  * ****************************************************************/
11126
11127 void extractPdcchCfg(PDCCH_Config_t *cuPdcchCfg, PdcchConfig *macPdcchCfg)
11128 {
11129    uint8_t cRsetIdx = 0;
11130    uint8_t srchSpcIdx = 0;
11131
11132    struct PDCCH_Config__controlResourceSetToAddModList *cRsetToAddModList = NULLP;
11133    struct PDCCH_Config__controlResourceSetToReleaseList *cRsetToRelList = NULLP;
11134    struct PDCCH_Config__searchSpacesToAddModList *srchSpcToAddModList = NULLP;
11135    struct PDCCH_Config__searchSpacesToReleaseList *srchSpcToRelList = NULLP;
11136
11137
11138    /* Control Resource Set To Add/Mod List */
11139    if(cuPdcchCfg->controlResourceSetToAddModList)
11140    {
11141       cRsetToAddModList = cuPdcchCfg->controlResourceSetToAddModList;
11142       if(cRsetToAddModList->list.count)
11143       {
11144          macPdcchCfg->numCRsetToAddMod = cRsetToAddModList->list.count;
11145          for(cRsetIdx = 0; cRsetIdx < cRsetToAddModList->list.count; cRsetIdx++)
11146          {
11147             macPdcchCfg->cRSetToAddModList[cRsetIdx].cRSetId = \
11148                cRsetToAddModList->list.array[cRsetIdx]->controlResourceSetId;
11149             //freqDomRsrcBitStringToInt(&cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources,\
11150                   macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc);
11151             memcpy(macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc, \
11152                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.buf,
11153                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.size);
11154
11155             macPdcchCfg->cRSetToAddModList[cRsetIdx].duration = \
11156                 cRsetToAddModList->list.array[cRsetIdx]->duration;
11157
11158             macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType = \
11159                cRsetToAddModList->list.array[cRsetIdx]->cce_REG_MappingType.present;   
11160             if(macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType == CCE_REG_MAPPINGTYPE_PR_INTERLEAVED)
11161             {
11162                //TODO: handle the case for Interleaved
11163             }
11164             macPdcchCfg->cRSetToAddModList[cRsetIdx].precoderGranularity = \
11165                 cRsetToAddModList->list.array[cRsetIdx]->precoderGranularity;
11166             if(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID)
11167             {
11168                macPdcchCfg->cRSetToAddModList[cRsetIdx].dmrsScramblingId= \
11169                   *(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID);
11170             }
11171          }
11172       }
11173    }
11174    /* Control Resource Set To Release List */
11175    if(cuPdcchCfg->controlResourceSetToReleaseList)
11176    {
11177       cRsetToRelList = cuPdcchCfg->controlResourceSetToReleaseList;
11178       if(cRsetToRelList->list.count)
11179       {
11180          macPdcchCfg->numCRsetToRel = cRsetToRelList->list.count;
11181          for(cRsetIdx = 0; cRsetIdx < cRsetToRelList->list.count; cRsetIdx++)
11182          {
11183             macPdcchCfg->cRSetToRelList[cRsetIdx] = *(cRsetToRelList->list.array[cRsetIdx]);
11184          }
11185       }
11186    }
11187
11188    /* Search space To Add/Mod List */
11189    if(cuPdcchCfg->searchSpacesToAddModList)
11190    {
11191       srchSpcToAddModList = cuPdcchCfg->searchSpacesToAddModList;
11192       if(srchSpcToAddModList->list.count)
11193       {
11194          macPdcchCfg->numSearchSpcToAddMod = srchSpcToAddModList->list.count;
11195          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToAddModList->list.count; srchSpcIdx++)
11196          {
11197             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceId =\
11198                                                                           srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceId;
11199             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].cRSetId =\
11200                                                                     *(srchSpcToAddModList->list.array[srchSpcIdx]->controlResourceSetId);
11201             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset)
11202             {
11203                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSlotPeriodicityAndOffset =\
11204                                                                                          srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset->present;
11205             }
11206             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot)
11207             {
11208                bitStringToInt(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot,\
11209                      macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSymbolsWithinSlot);
11210             }
11211             if(srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates)
11212             {
11213                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel1 = \
11214                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel1;
11215                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel2 = \
11216                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel2;
11217                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel4 = \
11218                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel4;
11219
11220                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel8 = \
11221                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel8;
11222
11223                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel16 = \
11224                                                                                         srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel16;
11225             }
11226             if(srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType)
11227             {
11228                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType =\
11229                                                                                srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->present;
11230                if(macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType == SEARCHSPACETYPE_PR_UE_SPECIFIC)
11231                {
11232                   macPdcchCfg->searchSpcToAddModList[srchSpcIdx].ueSpecificDciFormat =\
11233                                                                                       srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->choice.ue_Specific->dci_Formats;
11234                }
11235
11236             }
11237          }
11238       }
11239    }
11240    /* Search space To Rel List */
11241    if(cuPdcchCfg->searchSpacesToReleaseList)
11242    {
11243       srchSpcToRelList = cuPdcchCfg->searchSpacesToReleaseList;
11244       if(srchSpcToRelList->list.count)
11245       {
11246          macPdcchCfg->numSearchSpcToRel = srchSpcToRelList->list.count;
11247          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToRelList->list.count; srchSpcIdx++)
11248          {
11249             macPdcchCfg->searchSpcToRelList[srchSpcIdx] =\
11250                                                          *(srchSpcToRelList->list.array[srchSpcIdx]);
11251          }
11252       }
11253    }
11254 }
11255
11256 /*******************************************************************
11257  *
11258  * @brief Fills PdschCfg received by CU
11259  *
11260  * @details
11261  *
11262  *    Function : extractPdschCfg
11263  *
11264  *    Functionality: Fills PdschCfg received  by CU
11265  *
11266  * @params[in] PDSCH_Config_t *cuPdschCfg = Information which is send by CU,
11267  *                   which we have stored in F1UeContextSetupDb,
11268  *             PdschConfig *macPdschCfg = Used to Store the information which
11269  *                   needs to send in other layer, as well as this can be the variable
11270  *                   which stores the information in DuCb,
11271  *             PdschConfig *storedPdschCfg =  Null in case of sending the
11272  *                   information to other layer else it will have stored pdsch 
11273  *                   configuration in copyOfmacUeCfg.
11274  * @return void
11275  *
11276  * ****************************************************************/
11277
11278 void extractPdschCfg(PDSCH_Config_t *cuPdschCfg, PdschConfig *macPdschCfg, PdschConfig *storedPdschCfg)
11279 {
11280    uint8_t timeDomIdx;
11281    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAlloc = NULLP;
11282
11283    if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
11284    {
11285       if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->present == \
11286             PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup)
11287       {
11288          if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup)
11289          {
11290             macPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
11291                *(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_AdditionalPosition);
11292          }
11293       }
11294    }
11295    macPdschCfg->resourceAllocType = cuPdschCfg->resourceAllocation;
11296    if(cuPdschCfg->pdsch_TimeDomainAllocationList)
11297    {
11298       timeDomAlloc = cuPdschCfg->pdsch_TimeDomainAllocationList;
11299       if(timeDomAlloc->present ==\
11300             PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup)
11301       {
11302          if(timeDomAlloc->choice.setup)
11303          {
11304             macPdschCfg->numTimeDomRsrcAlloc  = timeDomAlloc->choice.setup->list.count;
11305             for(timeDomIdx = 0; timeDomIdx < timeDomAlloc->choice.setup->list.count; timeDomIdx++)
11306             {
11307                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 = NULLP;
11308                if(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0)
11309                {
11310                   if(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 == NULL)
11311                   {
11312                      if(storedPdschCfg)
11313                      {
11314                         if(storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
11315                         {
11316                            macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 =\
11317                            storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0;
11318                         }
11319                         else
11320                         {
11321                            DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
11322                         }
11323                      }
11324                      else
11325                      {
11326                         DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
11327                      }
11328                      if(!macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
11329                      {
11330                         DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for k0 at extractPdschCfg()");
11331                         return;
11332                      }
11333                   }
11334                   *(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0) = \
11335                   *(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0);
11336                }
11337                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].mappingType = \
11338                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->mappingType;
11339                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].startSymbolAndLength = \
11340                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11341             }
11342          }
11343       }
11344    }
11345    macPdschCfg->rbgSize = cuPdschCfg->rbg_Size;
11346    if(cuPdschCfg->maxNrofCodeWordsScheduledByDCI)
11347       macPdschCfg->numCodeWordsSchByDci = *(cuPdschCfg->maxNrofCodeWordsScheduledByDCI);
11348    if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_staticBundling)
11349    {
11350       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11351       if(cuPdschCfg->prb_BundlingType.choice.staticBundling)
11352       {
11353          if(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize)
11354          {
11355             macPdschCfg->bundlingInfo.StaticBundling.size = \
11356                *(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize);
11357          }
11358       }
11359    }
11360    else if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_dynamicBundling)
11361    {
11362       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11363    }
11364
11365 }
11366
11367 /*******************************************************************
11368  *
11369  * @brief Fills PdschServingCellCfg received by CU
11370  *
11371  * @details
11372  *
11373  *    Function : extractPdschServingCellCfg
11374  *
11375  *    Functionality: Fills PdschCfg received  by CU
11376  *
11377  * @params[in] PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg,
11378  *             PdschServCellCfg *macUePdschSrvCellCfg
11379  * @return ROK/RFAILED
11380  *
11381  * ****************************************************************/
11382
11383 uint8_t extractPdschServingCellCfg(PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg, PdschServCellCfg *macUePdschSrvCellCfg)
11384 {
11385    if(cuPdschSrvCellCfg->codeBlockGroupTransmission)
11386    {
11387       if(cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup)
11388       {
11389          if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11390          {
11391             *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11392                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11393          }
11394          else
11395          {
11396             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
11397             if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11398             {
11399                *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11400                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11401             }
11402             else
11403             {
11404                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxCodeBlkGrpPerTb at extractPdschServingCellCfg()");
11405                return RFAILED;
11406             }
11407          }
11408          if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11409          {
11410             *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11411                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11412          }
11413          else
11414          {
11415             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->codeBlkGrpFlushInd , sizeof(bool));
11416             if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11417             {
11418                *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11419                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11420             }
11421             else
11422             {
11423                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for codeBlkGrpFlushInd at extractPdschServingCellCfg()");
11424                return RFAILED;
11425             }
11426          }
11427       }
11428    }
11429    if(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH)
11430    {
11431       macUePdschSrvCellCfg->numHarqProcForPdsch = *(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH); 
11432    }
11433    if(cuPdschSrvCellCfg->ext1)
11434    {
11435       if(cuPdschSrvCellCfg->ext1->maxMIMO_Layers)
11436       {
11437         if(macUePdschSrvCellCfg->maxMimoLayers)
11438         {
11439            *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11440         }
11441         else
11442         {
11443            DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxMimoLayers, sizeof(uint8_t));
11444            if(macUePdschSrvCellCfg->maxMimoLayers)
11445            {
11446               *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11447            }
11448            else
11449            {
11450               DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxMimoLayers at extractPdschServingCellCfg()");
11451               return RFAILED;
11452            }
11453         }
11454       }
11455    }
11456    if(cuPdschSrvCellCfg->xOverhead)
11457    {
11458       if(macUePdschSrvCellCfg->xOverhead)
11459       {
11460          *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11461       }
11462       else
11463       {
11464          DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->xOverhead, sizeof(PdschXOverhead));
11465          if(macUePdschSrvCellCfg->xOverhead)
11466          {
11467             *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11468          }
11469          else
11470          {
11471             DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for xOverhead at extractPdschServingCellCfg()");
11472             return RFAILED;
11473          }
11474       }
11475    }
11476    return ROK;
11477 }
11478
11479 /*******************************************************************
11480  *
11481  * @brief Fills PuschCfg received by CU
11482  *
11483  * @details
11484  *
11485  *    Function : extractPuschCfg
11486  *
11487  *    Functionality: Fills PuschCfg received  by CU
11488  *
11489  * @params[in] BWP_UplinkDedicated__pusch_Config *cuPuschCfg,
11490  *             PuschCfg *macPuschCfg
11491  * @return void
11492  *
11493  * ****************************************************************/
11494
11495 void extractPuschCfg(struct BWP_UplinkDedicated__pusch_Config *cuPuschCfg, PuschCfg *macPuschCfg)
11496 {
11497    uint8_t timeDomIdx = 0;
11498    DMRS_UplinkConfig_t *dmrsUlCfg = NULLP;
11499    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList = NULLP;
11500
11501    if(cuPuschCfg->present == BWP_UplinkDedicated__pusch_Config_PR_setup)
11502    {
11503       if(cuPuschCfg->choice.setup)
11504       {
11505          if(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH)
11506          {
11507              macPuschCfg->dataScramblingId = \
11508                 *(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH);
11509          }
11510          if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA)
11511          {
11512             if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->present == PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup)
11513             {
11514                if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup)
11515                {
11516                   dmrsUlCfg = (cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup);
11517                   if(dmrsUlCfg->dmrs_AdditionalPosition)
11518                   {
11519                      macPuschCfg->dmrsUlCfgForPuschMapTypeA.addPos =\
11520                         *(dmrsUlCfg->dmrs_AdditionalPosition);
11521                   }
11522                   if(dmrsUlCfg->transformPrecodingDisabled)
11523                   {
11524                      if(dmrsUlCfg->transformPrecodingDisabled->scramblingID0)
11525                      {
11526                         macPuschCfg->dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0 = \
11527                            *(dmrsUlCfg->transformPrecodingDisabled->scramblingID0);
11528                      }
11529                   }
11530                }
11531             }
11532          }
11533          /*Res Alloc Type for UL */
11534          if(cuPuschCfg->choice.setup->resourceAllocation)
11535          {
11536             macPuschCfg->resourceAllocType = \
11537                cuPuschCfg->choice.setup->resourceAllocation;
11538          }
11539          if(cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList)
11540          {
11541             timeDomAllocList = cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList;
11542             if(timeDomAllocList->present == PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup)
11543             {
11544                if(timeDomAllocList->choice.setup)
11545                {
11546                   macPuschCfg->numTimeDomRsrcAlloc = timeDomAllocList->choice.setup->list.count;
11547                   for(timeDomIdx = 0; timeDomIdx <timeDomAllocList->choice.setup->list.count; timeDomIdx++)
11548                   {
11549                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].k2 = \
11550                         *(timeDomAllocList->choice.setup->list.array[timeDomIdx]->k2);
11551                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].mappingType = \
11552                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->mappingType;
11553                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].startSymbolAndLength = \
11554                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11555                   }
11556                }
11557             }
11558          }
11559          if(cuPuschCfg->choice.setup->transformPrecoder)
11560             macPuschCfg->transformPrecoder = *(cuPuschCfg->choice.setup->transformPrecoder);
11561       }
11562    }
11563 }
11564
11565 /*******************************************************************
11566  *
11567  * @brief Function to fill pucch Power Control
11568  *
11569  * @details
11570  *
11571  *    Function : extractPucchPowerControl
11572  *
11573  *    Functionality: Function to fill pucch Power Control
11574  *
11575  * @params[in] PucchPowerControl *pwrCtrl,
11576  *             struct PUCCH_PowerControl *cuPwrCtrlCfg
11577  * @return void
11578  *
11579  * ****************************************************************/
11580
11581 void extractPucchPowerControl(PucchPowerControl *pwrCtrl, struct PUCCH_PowerControl *cuPwrCtrlCfg)
11582 {
11583    uint8_t arrIdx;
11584
11585    if(cuPwrCtrlCfg->deltaF_PUCCH_f0)
11586       pwrCtrl->deltaF_Format0 = *cuPwrCtrlCfg->deltaF_PUCCH_f0;
11587    if(cuPwrCtrlCfg->deltaF_PUCCH_f1)
11588       pwrCtrl->deltaF_Format1 = *cuPwrCtrlCfg->deltaF_PUCCH_f1;
11589    if(cuPwrCtrlCfg->deltaF_PUCCH_f2)
11590       pwrCtrl->deltaF_Format2 = *cuPwrCtrlCfg->deltaF_PUCCH_f2;
11591    if(cuPwrCtrlCfg->deltaF_PUCCH_f3)
11592       pwrCtrl->deltaF_Format3 = *cuPwrCtrlCfg->deltaF_PUCCH_f3;
11593    if(cuPwrCtrlCfg->deltaF_PUCCH_f4)
11594       pwrCtrl->deltaF_Format4 = *cuPwrCtrlCfg->deltaF_PUCCH_f4;
11595    if(cuPwrCtrlCfg->p0_Set)
11596    {
11597       pwrCtrl->p0SetCount = cuPwrCtrlCfg->p0_Set->list.count;
11598       for(arrIdx=0; arrIdx < pwrCtrl->p0SetCount; arrIdx++)
11599       {
11600          pwrCtrl->p0Set[arrIdx].p0PucchId =\
11601             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Id;
11602          pwrCtrl->p0Set[arrIdx].p0PucchVal =\
11603             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Value;
11604       }
11605    }
11606    if(cuPwrCtrlCfg->pathlossReferenceRSs)
11607    {
11608       pwrCtrl->pathLossRefRSListCount = cuPwrCtrlCfg->pathlossReferenceRSs->list.count;
11609       for(arrIdx = 0; arrIdx < pwrCtrl->pathLossRefRSListCount; arrIdx++)
11610       {
11611          pwrCtrl->pathLossRefRSList[arrIdx].pathLossRefRSId =\
11612             cuPwrCtrlCfg->pathlossReferenceRSs->list.array[arrIdx]->pucch_PathlossReferenceRS_Id;
11613       }
11614    }
11615 }
11616  
11617  /*******************************************************************
11618  *
11619  * @brief Function to extractResrcSetToAddModList sent by CU
11620  *
11621  * @details
11622  *
11623  *    Function : extractResrcSetToAddModList
11624  *
11625  *    Functionality: Fucntion to extractResrcSetToAddModList
11626  *
11627  * @params[in] PucchResrcSetCfg pointer,
11628  *             struct PUCCH_Config__resourceSetToAddModList pointer
11629  * @return void
11630  *
11631  * ****************************************************************/
11632
11633 void extractResrcSetToAddModList(PucchResrcSetCfg *macRsrcSetList, struct PUCCH_Config__resourceSetToAddModList *cuRsrcSetList)
11634 {
11635    uint8_t arrIdx, rsrcListIdx;
11636
11637    macRsrcSetList->resrcSetToAddModListCount = cuRsrcSetList->list.count; 
11638    for(arrIdx = 0; arrIdx < macRsrcSetList->resrcSetToAddModListCount; arrIdx++)
11639    {
11640       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcSetId     =\
11641          cuRsrcSetList->list.array[arrIdx]->pucch_ResourceSetId;
11642       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount =\
11643          cuRsrcSetList->list.array[arrIdx]->resourceList.list.count;
11644       for(rsrcListIdx = 0; rsrcListIdx < macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount; rsrcListIdx++)
11645       {
11646          macRsrcSetList->resrcSetToAddModList[arrIdx].resrcList[rsrcListIdx] =\
11647             *cuRsrcSetList->list.array[arrIdx]->resourceList.list.array[rsrcListIdx];
11648       }
11649
11650       if(cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1)
11651       {
11652          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize =\
11653             *cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1;
11654       }
11655       else
11656       {
11657          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize = 0;
11658       }
11659    }
11660 }/* End of extractResrcSetToAddModList */
11661
11662 /*******************************************************************
11663  *
11664  * @brief Fills extractResrcToAddModList sent by CU
11665  *
11666  * @details
11667  *
11668  *    Function : extractResrcToAddModList
11669  *
11670  *    Functionality: Fills extractResrcToAddModList
11671  *
11672  * @params[in] PucchResrcCfg pointer,
11673  *             struct PUCCH_Config__resourceToAddModList pointer
11674  * @return ROk/RFAILED
11675  *
11676  * ****************************************************************/
11677
11678 uint8_t extractResrcToAddModList(PucchResrcCfg *macResrcList, struct PUCCH_Config__resourceToAddModList *cuResrcList)
11679 {
11680    uint8_t arrIdx;
11681    
11682    macResrcList->resrcToAddModListCount = cuResrcList->list.count;
11683    for(arrIdx = 0; arrIdx < macResrcList->resrcToAddModListCount; arrIdx++)
11684    {
11685       macResrcList->resrcToAddModList[arrIdx].resrcId      =\
11686         cuResrcList->list.array[arrIdx]->pucch_ResourceId; 
11687       macResrcList->resrcToAddModList[arrIdx].startPrb     =\
11688         cuResrcList->list.array[arrIdx]->startingPRB;
11689       if(cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping)
11690       {
11691          macResrcList->resrcToAddModList[arrIdx].intraFreqHop =\
11692            *cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping;
11693       }
11694       if(cuResrcList->list.array[arrIdx]->secondHopPRB)
11695       {
11696          macResrcList->resrcToAddModList[arrIdx].secondPrbHop =\
11697            *cuResrcList->list.array[arrIdx]->secondHopPRB;
11698       }
11699       /* PUCCH RSRC FORMAT */
11700       if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format0)
11701       {
11702          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_0;
11703          if(cuResrcList->list.array[arrIdx]->format.choice.format0)
11704          {
11705             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0, sizeof(PucchFormat0));
11706             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0 == NULLP)
11707             {
11708                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format0 in extractResrcToAddModList()");
11709                return RFAILED;
11710             }
11711             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->initialCyclicShift =\
11712                cuResrcList->list.array[arrIdx]->format.choice.format0->initialCyclicShift;
11713             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->numSymbols =\
11714                cuResrcList->list.array[arrIdx]->format.choice.format0->nrofSymbols;
11715             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->startSymbolIdx =\
11716                cuResrcList->list.array[arrIdx]->format.choice.format0->startingSymbolIndex;
11717          }
11718       }
11719       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format1)
11720       {
11721          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_1;
11722          if(cuResrcList->list.array[arrIdx]->format.choice.format1)
11723          {
11724             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1, sizeof(PucchFormat1));
11725             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1 == NULLP)
11726             {
11727                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format1 in extractResrcToAddModList()");
11728                return RFAILED;
11729             }
11730             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->initialCyclicShift =\
11731                 cuResrcList->list.array[arrIdx]->format.choice.format1->initialCyclicShift;
11732             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->numSymbols =\
11733                 cuResrcList->list.array[arrIdx]->format.choice.format1->nrofSymbols;
11734             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->startSymbolIdx =\
11735                 cuResrcList->list.array[arrIdx]->format.choice.format1->startingSymbolIndex;
11736             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->timeDomOCC =\
11737                 cuResrcList->list.array[arrIdx]->format.choice.format1->timeDomainOCC;
11738          }
11739       }
11740       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format2)
11741       {
11742          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_2;
11743          if(cuResrcList->list.array[arrIdx]->format.choice.format2)
11744          {
11745             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
11746             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2 == NULLP)
11747             {
11748                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format2 in extractResrcToAddModList()");
11749                return RFAILED;
11750             }
11751             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numPrbs =\
11752                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofPRBs;
11753             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numSymbols =\
11754                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofSymbols;
11755             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->startSymbolIdx =\
11756                 cuResrcList->list.array[arrIdx]->format.choice.format2->startingSymbolIndex;
11757          }
11758       }
11759       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format3)
11760       {
11761          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_3;
11762          if(cuResrcList->list.array[arrIdx]->format.choice.format3)
11763          {
11764             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
11765             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3 == NULLP)
11766             {
11767                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format3 in extractResrcToAddModList()");
11768                return RFAILED;
11769             }
11770             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numPrbs =\
11771                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofPRBs;
11772             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numSymbols =\
11773                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofSymbols;
11774             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->startSymbolIdx =\
11775                 cuResrcList->list.array[arrIdx]->format.choice.format3->startingSymbolIndex;
11776          }
11777       }
11778       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format4)
11779       {
11780          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_4;
11781          if(cuResrcList->list.array[arrIdx]->format.choice.format4)
11782          {
11783             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4, sizeof(PucchFormat4));
11784             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4 == NULLP)
11785             {
11786                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format4 in extractResrcToAddModList()");
11787                return RFAILED;
11788             }
11789             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->numSymbols =\
11790                 cuResrcList->list.array[arrIdx]->format.choice.format4->nrofSymbols;
11791             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occLen =\
11792                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Length;
11793             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occIdx =\
11794                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Index;
11795             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->startSymbolIdx =\
11796                 cuResrcList->list.array[arrIdx]->format.choice.format4->startingSymbolIndex;
11797          }
11798       }
11799    }
11800    return ROK;
11801
11802 }/* End of extractResrcToAddModList */
11803
11804 /*******************************************************************
11805  *
11806  * @brief Fills fillPucchSchedReqPeriodAndOffset sent by CU
11807  *
11808  * @details
11809  *
11810  *    Function : fillPucchSchedReqPeriodAndOffset
11811  *
11812  *    Functionality: To fillPucchSchedReqPeriodAndOffset
11813  *
11814  * @params[in] macPeriodicty,
11815  *     SchedulingRequestResourceConfig__periodicityAndOffset pointer
11816  * @return void
11817  *
11818  * ****************************************************************/
11819
11820 void fillPucchSchedReqPeriodAndOffset(uint8_t macPeriodicty, uint16_t  macOffset,\
11821    struct SchedulingRequestResourceConfig__periodicityAndOffset *cuPeriodicty)
11822 {
11823    macPeriodicty = cuPeriodicty->present;
11824    switch(macPeriodicty)
11825    {
11826       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
11827          {
11828             macOffset     = cuPeriodicty->choice.sym2;
11829             break;
11830          }
11831       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
11832          {
11833             macOffset     = cuPeriodicty->choice.sym6or7;
11834             break;
11835          }
11836       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
11837          {
11838             macOffset     = cuPeriodicty->choice.sl1;
11839             break;
11840          }
11841       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
11842          {
11843             macOffset = cuPeriodicty->choice.sl2;
11844             break;
11845          }
11846       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
11847          {
11848             macOffset = cuPeriodicty->choice.sl4;
11849             break;
11850          }
11851       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
11852          {
11853             macOffset = cuPeriodicty->choice.sl5;
11854             break;
11855          }
11856       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
11857          {
11858             macOffset = cuPeriodicty->choice.sl8;
11859             break;
11860          }
11861       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
11862          {
11863             macOffset = cuPeriodicty->choice.sl10;
11864             break;
11865          }
11866       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
11867          {
11868             macOffset = cuPeriodicty->choice.sl16;
11869             break;
11870          }
11871       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
11872          {
11873             macOffset = cuPeriodicty->choice.sl20;
11874             break;
11875          }
11876       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
11877          {
11878             macOffset = cuPeriodicty->choice.sl40;
11879             break;
11880          }
11881       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
11882          {
11883             macOffset = cuPeriodicty->choice.sl80;
11884             break;
11885          }
11886       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
11887          {
11888             macOffset = cuPeriodicty->choice.sl160;
11889             break;
11890          }
11891       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
11892          {
11893             macOffset = cuPeriodicty->choice.sl320;
11894             break;
11895          }
11896       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
11897          {
11898             macOffset = cuPeriodicty->choice.sl640;
11899             break;
11900          }
11901       default :
11902          DU_LOG("\nERROR  -->  F1AP : Invalid periodicity %d", macPeriodicty);
11903    }
11904 }
11905
11906 /*******************************************************************
11907  *
11908  * @brief Function to extractPucchFormatCfg sent by CU
11909  *
11910  * @details
11911  *
11912  *    Function : extractPucchFormatCfg
11913  *
11914  *    Functionality: Function to extractPucchFormatCfg
11915  *
11916  * @params[in] PucchFormatCfg pointer,
11917  *             PUCCH_FormatConfig_t pointer
11918  * @return void
11919  *
11920  * ****************************************************************/
11921
11922 void extractPucchFormatCfg(PucchFormatCfg *macFormatCfg, PUCCH_FormatConfig_t *cuFormatCfg)
11923  {
11924     if(cuFormatCfg->interslotFrequencyHopping)
11925        macFormatCfg->interSlotFreqHop = *cuFormatCfg->interslotFrequencyHopping;
11926     if(cuFormatCfg->additionalDMRS)  
11927        macFormatCfg->addDmrs = *cuFormatCfg->additionalDMRS;
11928     if(cuFormatCfg->maxCodeRate)
11929        macFormatCfg->maxCodeRate = *cuFormatCfg->maxCodeRate;
11930     if(cuFormatCfg->nrofSlots)  
11931        macFormatCfg->numSlots = *cuFormatCfg->nrofSlots;
11932     if(cuFormatCfg->pi2BPSK)  
11933        macFormatCfg->pi2BPSK = *cuFormatCfg->pi2BPSK;
11934     if(cuFormatCfg->simultaneousHARQ_ACK_CSI)  
11935        macFormatCfg->harqAckCSI = *cuFormatCfg->simultaneousHARQ_ACK_CSI;
11936  }/* End of extractPucchFormatCfg */
11937
11938 /*******************************************************************
11939  *
11940  * @brief Function to extractSchedReqCfgToAddMod sent by CU
11941  *
11942  * @details
11943  *
11944  *    Function : extractSchedReqCfgToAddMod
11945  *
11946  *    Functionality: Function to extractSchedReqCfgToAddMod
11947  *
11948  * @params[in] PucchSchedReqCfg pointer,
11949  *      PUCCH_Config__schedulingRequestResourceToAddModList pointer
11950  * @return void
11951  *
11952  * ****************************************************************/
11953
11954 void extractSchedReqCfgToAddMod(PucchSchedReqCfg *macSchedReqCfg, struct PUCCH_Config__schedulingRequestResourceToAddModList *cuSchedReqList)
11955 {
11956    uint8_t arrIdx;
11957
11958    macSchedReqCfg->schedAddModListCount = cuSchedReqList->list.count;
11959    for(arrIdx = 0; arrIdx <  macSchedReqCfg->schedAddModListCount; arrIdx++)
11960    {
11961       macSchedReqCfg->schedAddModList[arrIdx].resrcId =\
11962          cuSchedReqList->list.array[arrIdx]->schedulingRequestResourceId;
11963       macSchedReqCfg->schedAddModList[arrIdx].requestId =\
11964          cuSchedReqList->list.array[arrIdx]->schedulingRequestID;
11965       if(cuSchedReqList->list.array[arrIdx]->periodicityAndOffset)
11966       {
11967          fillPucchSchedReqPeriodAndOffset(macSchedReqCfg->schedAddModList[arrIdx].periodicity,\
11968             macSchedReqCfg->schedAddModList[arrIdx].offset, cuSchedReqList->list.array[arrIdx]->periodicityAndOffset);
11969       }
11970       if(cuSchedReqList->list.array[arrIdx]->resource)
11971       {
11972          macSchedReqCfg->schedAddModList[arrIdx].resrc =\
11973             *cuSchedReqList->list.array[arrIdx]->resource;
11974       }
11975    }
11976
11977 }/* End of extractSchedReqCfgToAddMod */
11978
11979  /*******************************************************************
11980  *
11981  * @brief Fills PucchCfg received by CU
11982  *
11983  * @details
11984  *
11985  *    Function : extractPucchCfg
11986  *
11987  *    Functionality: Fills PucchCfg received  by CU
11988  *
11989  * @params[in] BWP_UplinkDedicated__pucch_Config *cuPucchCfg = Information which
11990  *                is send by CU, which we have stored in F1UeContextSetupDb,
11991  *             PucchCfg *macPucchCfg = Used to Store the information which
11992  *                needs to send in other layer, as well as this can be the variable
11993  *                which stores the information in DuCb,
11994  *             PucchCfg *storedPucchCfg = Null in case of sending the
11995  *                information to other layer else it will have Pucch Cfg which
11996  *                we have stored in copyOfmacUeCfg.
11997  * @return ROK/RFAILED
11998  *
11999  * ****************************************************************/
12000
12001 uint8_t extractPucchCfg(struct BWP_UplinkDedicated__pucch_Config *cuPucchCfg, PucchCfg *macPucchCfg,\
12002 PucchCfg *storedPucchCfg)        
12003 {
12004    uint8_t arrIdx;
12005
12006    if(cuPucchCfg->present == BWP_UplinkDedicated__pucch_Config_PR_setup)
12007    {
12008       if(cuPucchCfg->choice.setup)
12009       {
12010          /* Resource Set Cfg */ 
12011          if(cuPucchCfg->choice.setup->resourceSetToAddModList)
12012          {
12013             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrcSet, sizeof(PucchResrcSetCfg));
12014             if(macPucchCfg->resrcSet == NULLP)
12015             {
12016                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc set List in extractPucchCfg()");
12017                return RFAILED;
12018             }
12019             memset(macPucchCfg->resrcSet, 0, sizeof(PucchResrcSetCfg));
12020             extractResrcSetToAddModList(macPucchCfg->resrcSet, cuPucchCfg->choice.setup->resourceSetToAddModList);
12021          }
12022          
12023          /* Resource Cfg */ 
12024          if(cuPucchCfg->choice.setup->resourceToAddModList)
12025          {
12026             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrc, sizeof(PucchResrcCfg));
12027             if(macPucchCfg->resrc == NULLP)
12028             {
12029                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc List in extractPucchCfg()");
12030                return RFAILED;
12031             }
12032             memset(macPucchCfg->resrc, 0, sizeof(PucchResrcCfg));
12033             extractResrcToAddModList(macPucchCfg->resrc, cuPucchCfg->choice.setup->resourceToAddModList);
12034          }
12035          
12036          /* Format 1 Cfg */ 
12037          if(cuPucchCfg->choice.setup->format1)
12038          {
12039             DU_ALLOC_SHRABL_BUF(macPucchCfg->format1, sizeof(PucchFormatCfg));
12040             if(macPucchCfg->format1 == NULLP)
12041             {
12042                DU_LOG("\nERROR --> F1AP : Failed to extract format 1 Cfg in  extractPucchCfg()");
12043                return RFAILED;
12044             }
12045             memset(macPucchCfg->format1, 0, sizeof(PucchFormatCfg));
12046             extractPucchFormatCfg(macPucchCfg->format1,\
12047                cuPucchCfg->choice.setup->format1->choice.setup);
12048          }
12049          
12050          /* Format 2 Cfg */
12051          if(cuPucchCfg->choice.setup->format2)
12052          {
12053             DU_ALLOC_SHRABL_BUF(macPucchCfg->format2, sizeof(PucchFormatCfg));
12054             if(macPucchCfg->format2 == NULLP)
12055             {
12056                DU_LOG("\nERROR --> F1AP : Failed to extract format 2 Cfg in  extractPucchCfg()");
12057                return RFAILED;
12058             }
12059             memset(macPucchCfg->format2, 0, sizeof(PucchFormatCfg));
12060             extractPucchFormatCfg(macPucchCfg->format2,\
12061                cuPucchCfg->choice.setup->format2->choice.setup);
12062          }
12063          
12064          /* Format 3 Cfg */
12065          if(cuPucchCfg->choice.setup->format3)
12066          {
12067             DU_ALLOC_SHRABL_BUF(macPucchCfg->format3, sizeof(PucchFormatCfg));
12068             if(macPucchCfg->format3 == NULLP)
12069             {
12070                DU_LOG("\nERROR --> F1AP : Failed to extract format 3 Cfg in  extractPucchCfg()");
12071                return RFAILED;
12072             }
12073             memset(macPucchCfg->format3, 0, sizeof(PucchFormatCfg));
12074             extractPucchFormatCfg(macPucchCfg->format3,\
12075                cuPucchCfg->choice.setup->format3->choice.setup);
12076          }
12077
12078          /* Format 4 Cfg */
12079          if(cuPucchCfg->choice.setup->format4)
12080          {
12081             DU_ALLOC_SHRABL_BUF(macPucchCfg->format4, sizeof(PucchFormatCfg));
12082             if(macPucchCfg->format4 == NULLP)
12083             {
12084                DU_LOG("\nERROR --> F1AP : Failed to extract format 4 Cfg in  extractPucchCfg()");
12085                return RFAILED;
12086             }
12087             memset(macPucchCfg->format4, 0, sizeof(PucchFormatCfg));
12088             extractPucchFormatCfg(macPucchCfg->format4,\
12089                cuPucchCfg->choice.setup->format4->choice.setup);
12090          }
12091
12092          /* Sched Req List */
12093          if(cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList)
12094          {
12095             DU_ALLOC_SHRABL_BUF(macPucchCfg->schedReq, sizeof(PucchSchedReqCfg));
12096             if(macPucchCfg->schedReq == NULLP)
12097             {
12098                DU_LOG("\nERROR --> F1AP : Failed to extract schedReqCfg in  extractPucchCfg()");
12099                return RFAILED;
12100             }
12101             memset(macPucchCfg->schedReq, 0, sizeof(PucchSchedReqCfg));
12102             extractSchedReqCfgToAddMod(macPucchCfg->schedReq,\
12103             cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList);
12104          }
12105
12106          /*TODO: Add support for  Spatial Info */
12107
12108          /* MultiCsiCfg */
12109          if(cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList)
12110          {
12111             DU_ALLOC_SHRABL_BUF(macPucchCfg->multiCsiCfg, sizeof(PucchMultiCsiCfg));
12112             if(macPucchCfg->multiCsiCfg == NULLP)
12113             {
12114                DU_LOG("\nERROR --> F1AP : Failed to extract multiCsiCfg in  extractPucchCfg()");
12115                return RFAILED;
12116             }
12117             memset(macPucchCfg->multiCsiCfg, 0, sizeof(PucchMultiCsiCfg));
12118             macPucchCfg->multiCsiCfg->multiCsiResrcListCount = cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.count;
12119             for(arrIdx =0; arrIdx < macPucchCfg->multiCsiCfg->multiCsiResrcListCount; arrIdx++)
12120             {
12121                macPucchCfg->multiCsiCfg->multiCsiResrcList[arrIdx] =\
12122                  *cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.array[arrIdx];
12123             }
12124          }
12125
12126          /* Dl_DataToUL_ACK */ 
12127          if(cuPucchCfg->choice.setup->dl_DataToUL_ACK)
12128     {
12129        if(storedPucchCfg)
12130        {
12131           if(storedPucchCfg->dlDataToUlAck)
12132           {
12133              macPucchCfg->dlDataToUlAck = storedPucchCfg->dlDataToUlAck; 
12134           }
12135           else
12136           {
12137             DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
12138           }
12139        }
12140        else
12141        {
12142           DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
12143        }
12144        if(macPucchCfg->dlDataToUlAck == NULLP)
12145        {
12146           DU_LOG("\nERROR --> F1AP : Failed to extract Dl_DataToUL_ACK in extractPucchCfg()");
12147           return RFAILED;
12148        }
12149        memset(macPucchCfg->dlDataToUlAck, 0, sizeof(PucchDlDataToUlAck));
12150        macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount = cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.count;
12151        for(arrIdx = 0; arrIdx < macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; arrIdx++)
12152        {
12153           macPucchCfg->dlDataToUlAck->dlDataToUlAckList[arrIdx] =\
12154           *cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.array[arrIdx];
12155        }
12156          }
12157
12158          /* Power Control */
12159          if(cuPucchCfg->choice.setup->pucch_PowerControl)
12160          {
12161             DU_ALLOC_SHRABL_BUF(macPucchCfg->powerControl, sizeof(PucchPowerControl));
12162             if(macPucchCfg->powerControl == NULLP)
12163             {
12164                DU_LOG("\nERROR --> F1AP : Failed to extract power control in extractPucchCfg()");
12165                return RFAILED;
12166             }
12167             extractPucchPowerControl(macPucchCfg->powerControl,\
12168                cuPucchCfg->choice.setup->pucch_PowerControl);
12169          }
12170       }
12171    }
12172    return ROK;
12173 }
12174
12175 /*******************************************************************
12176  *
12177  * @brief Fills ServingCellReconfig received by CU
12178  *
12179  * @details
12180  *
12181  *    Function : extractSpCellDedicatedCfg
12182  *
12183  *    Functionality: Fills ServingCellReconfig received  by CU
12184  *
12185  * @params[in] ServingCellConfig_t *cuSrvCellCfg = Information which is send by
12186  *                  CU, which we have stored in F1UeContextSetupDb,
12187  *             ServCellCfgInfo *macSrvCellCfg = Used to Store the information
12188  *                  which  needs to send in other layer, as well as this can be the
12189  *                  variable which stores the information in DuCb, 
12190  *             ServCellCfgInfo *storedSrvCellCfg = Null in case of sending the
12191  *                  information to other layer else it will have ServCellCfgInfo which
12192  *                  we have stored in copyOfmacUeCfg.
12193  * @return ROK/RFAILD
12194  *
12195  * ****************************************************************/
12196 uint8_t extractSpCellDedicatedCfg(ServingCellConfig_t *cuSrvCellCfg, ServCellRecfgInfo *macSrvCellCfg,\
12197 ServCellRecfgInfo *storedSrvCellCfg)
12198 {
12199    uint8_t ret = ROK;
12200    BWP_DownlinkDedicated_t *dlBwp = NULLP;
12201    BWP_UplinkDedicated_t   *ulBwp = NULLP;
12202
12203    if(cuSrvCellCfg->initialDownlinkBWP)
12204    {
12205       dlBwp = ((BWP_DownlinkDedicated_t *)(cuSrvCellCfg->initialDownlinkBWP));
12206       if(dlBwp->pdcch_Config)
12207       {
12208          if(dlBwp->pdcch_Config->choice.setup)
12209          {
12210             macSrvCellCfg->initDlBwp.pdcchPresent = true;
12211             if(storedSrvCellCfg)
12212             {
12213                if(!storedSrvCellCfg->initDlBwp.pdcchPresent)
12214                {
12215                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12216                }
12217                else
12218                {
12219                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12220                }
12221             }
12222             else
12223             {
12224                extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12225             }
12226          }
12227       }
12228       if(dlBwp->pdsch_Config)
12229       {
12230          if(dlBwp->pdsch_Config->choice.setup)
12231          {
12232             macSrvCellCfg->initDlBwp.pdschPresent = true;
12233             
12234             if(storedSrvCellCfg)
12235             {
12236                if(!storedSrvCellCfg->initDlBwp.pdschPresent)
12237                {
12238                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
12239                }
12240                else
12241                {
12242                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg,\
12243                         &storedSrvCellCfg->initDlBwp.pdschCfg);
12244                }
12245             }
12246             else
12247             {
12248                extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
12249             }
12250          }
12251       }
12252    }
12253    if(cuSrvCellCfg->firstActiveDownlinkBWP_Id)
12254       macSrvCellCfg->firstActvDlBwpId = *(cuSrvCellCfg->firstActiveDownlinkBWP_Id);
12255    if(cuSrvCellCfg->defaultDownlinkBWP_Id)
12256       macSrvCellCfg->defaultDlBwpId = *(cuSrvCellCfg->defaultDownlinkBWP_Id);
12257    if(cuSrvCellCfg->bwp_InactivityTimer)
12258    {
12259       if(macSrvCellCfg->bwpInactivityTmr)
12260       {
12261          memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
12262       }
12263       else
12264       {
12265          macSrvCellCfg->bwpInactivityTmr = NULLP;
12266          DU_ALLOC_SHRABL_BUF(macSrvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
12267          if(macSrvCellCfg->bwpInactivityTmr)
12268          {
12269             memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
12270          }
12271          else
12272          {
12273             DU_LOG("\nERROR  --> F1AP : Memory Alloc failed for bwpInactivityTmr at extractSpCellDedicatedCfg()");
12274             return RFAILED;
12275          }
12276       }
12277    }
12278    if(cuSrvCellCfg->pdsch_ServingCellConfig)
12279    {
12280       if(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup)
12281       {
12282          ret = extractPdschServingCellCfg(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup, &macSrvCellCfg->pdschServCellCfg);
12283          if(ret == RFAILED)
12284          {
12285             DU_LOG("\nERROR --> F1AP : Failed at extractPdschServingCellCfg()");
12286             return RFAILED;
12287          }
12288       }
12289    }
12290    if(cuSrvCellCfg->uplinkConfig)
12291    {
12292       if(cuSrvCellCfg->uplinkConfig->initialUplinkBWP)
12293       {
12294          ulBwp = ((BWP_UplinkDedicated_t *)(cuSrvCellCfg->uplinkConfig->initialUplinkBWP));
12295          if(ulBwp->pusch_Config)
12296          {
12297             macSrvCellCfg->initUlBwp.puschPresent = true;
12298             extractPuschCfg(ulBwp->pusch_Config, &macSrvCellCfg->initUlBwp.puschCfg);
12299          }
12300          if(ulBwp->pucch_Config)
12301          {
12302             macSrvCellCfg->initUlBwp.pucchPresent = true;
12303             memset(&macSrvCellCfg->initUlBwp.pucchCfg, 0, sizeof(PucchCfg));
12304             if(storedSrvCellCfg)
12305             {
12306                if(!storedSrvCellCfg->initUlBwp.pucchPresent)
12307                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
12308                else
12309                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg,\
12310                   &storedSrvCellCfg->initUlBwp.pucchCfg);
12311             }
12312             else
12313             {
12314                extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
12315             }
12316          }
12317       }
12318       if(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id)
12319          macSrvCellCfg->firstActvUlBwpId = *(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id);
12320    }
12321    return ret;
12322 }
12323
12324 #ifdef NR_DRX
12325
12326 /*******************************************************************
12327  *
12328  * @brief fill long cycle offset value of drx in UE structure
12329  *
12330  * @details
12331  *
12332  *    Function : fillLongCycleOffsetValueInUeDb
12333  *
12334  *    Functionality: fill long cycle offset value of drx in UE structure
12335  *
12336  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
12337  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
12338  *
12339  * @return ROK     - success
12340  *         RFAILED - failure
12341  *
12342  * ****************************************************************/
12343 void fillLongCycleOffsetValueInUeDb(DrxLongCycleStartOffset *drxLongCycleStartOffset, struct DRX_ConfigRrc__drx_LongCycleStartOffset  *drx_LongCycleStartOffset)
12344 {
12345
12346    drxLongCycleStartOffset->drxLongCycleStartOffsetChoice = convertLongDrxCycleLengthEnumToValue(drx_LongCycleStartOffset->present);
12347    switch(drx_LongCycleStartOffset->present)
12348    {
12349       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
12350          {
12351             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10;
12352             break;
12353          }
12354       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
12355          {
12356             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms20;
12357             break;
12358          }
12359       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
12360          {
12361             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms32;
12362             break;
12363          }
12364       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
12365         {
12366             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms40;
12367             break;
12368          }
12369       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
12370          {
12371             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms60;
12372             break;
12373          }
12374       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
12375          {
12376             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms64;
12377             break;
12378          }
12379       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
12380          {
12381             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms70;
12382             break;
12383          }
12384       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
12385          {
12386             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms80;
12387             break;
12388          }
12389       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
12390          {
12391             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms128;
12392             break;
12393          }
12394       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
12395          {
12396             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms160;
12397             break;
12398          }
12399       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
12400          {
12401             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms256;
12402             break;
12403          }
12404       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
12405          {
12406             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms320;
12407             break;
12408          }
12409       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
12410          {
12411             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms512;
12412             break;
12413          }
12414       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
12415          {
12416             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms640;
12417             break;
12418          }
12419       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
12420          {
12421             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1024;
12422             break;
12423          }
12424       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
12425          {
12426             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1280;
12427             break;
12428          }
12429       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
12430          {
12431             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2048;
12432             break;
12433          }
12434       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
12435          {
12436             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2560;
12437             break;
12438          }
12439        case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
12440          {
12441             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms5120;
12442             break;
12443          }
12444       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
12445          {
12446             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10240;
12447             break;
12448          }
12449       default :
12450          break;
12451    }
12452 }
12453
12454 /*******************************************************************
12455  *
12456  * @brief Fills drx configuration structure with the help of drx_ConfigRrc
12457  *which recive from CU or storedDrxCfg which is already stored
12458  *
12459  * @details
12460  *
12461  *    Function : extractDrxConfiguration 
12462  *
12463  *    Functionality: Fills Reconfig Cell group Info received by CU
12464  *   
12465  * @params[in] cuMacCellGrpDrxConfig  = MAC_CellGroupConfig__drx_ConfigRrc information which
12466  *                       is send by CU, which we have stored in F1UeContextSetupDb
12467  *             DrxCfg * drxCfg  = Used to Store the information,
12468  *                      which needs to send in other layer, as well as this can be
12469  *                      the variable which stores the information in DuCb,
12470  *             DrxCfg *storedDrxCfg = Null in case of sending the
12471  *                      information to other layer else it will have the drx information 
12472  *                      stored in the copyOfmacUeCfg which we have stored in F1UeContextSetupDb.
12473  *
12474  * @return void
12475  *
12476  * ****************************************************************/
12477 void extractDrxConfiguration(struct MAC_CellGroupConfig__drx_ConfigRrc *cuMacCellGrpDrxConfig, DrxCfg * drxCfg, DrxCfg *storedDrxCfg)
12478 {
12479    struct DRX_ConfigRrc *cuDrxConfig;
12480
12481    if(storedDrxCfg)
12482    {
12483       memcpy(drxCfg, storedDrxCfg, sizeof(DrxCfg));
12484    }
12485    else
12486    {
12487       if(cuMacCellGrpDrxConfig)
12488       {
12489          switch(cuMacCellGrpDrxConfig->present)
12490          {
12491             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
12492                break;
12493
12494             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
12495                {
12496                   cuDrxConfig = cuMacCellGrpDrxConfig->choice.setup;
12497                   if(cuDrxConfig)
12498                   {
12499                      switch(cuDrxConfig->drx_onDurationTimer.present)
12500                      {
12501                         case DRX_ConfigRrc__drx_onDurationTimer_PR_NOTHING:
12502                            break;
12503                         case DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds:
12504                            {
12505                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = true;
12506                               drxCfg->drxOnDurationTimer.onDurationtimerValue.milliSeconds=convertOnDurationTimerMilliSecondsEnumToValue(cuDrxConfig->\
12507                               drx_onDurationTimer.choice.milliSeconds);
12508                               break;
12509                            }
12510                         case DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds:
12511                            {
12512                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = false;
12513                               drxCfg->drxOnDurationTimer.onDurationtimerValue.subMilliSeconds = cuDrxConfig->drx_onDurationTimer.choice.subMilliSeconds;
12514                               break;
12515                            }
12516                      }
12517                   }
12518                   fillLongCycleOffsetValueInUeDb(&drxCfg->drxLongCycleStartOffset, &cuDrxConfig->drx_LongCycleStartOffset);
12519                   drxCfg->drxInactivityTimer = convertDrxInactivityTimerEnumToValue(cuDrxConfig->drx_InactivityTimer);
12520                   drxCfg->drxHarqRttTimerDl = cuDrxConfig->drx_HARQ_RTT_TimerDL;
12521                   drxCfg->drxHarqRttTimerUl = cuDrxConfig->drx_HARQ_RTT_TimerUL;
12522                   drxCfg->drxRetransmissionTimerDl = convertDrxRetransmissionTimerDlEnumToValue(cuDrxConfig->drx_RetransmissionTimerDL);
12523                   drxCfg->drxRetransmissionTimerUl = convertDrxRetransmissionTimerUlEnumToValue(cuDrxConfig->drx_RetransmissionTimerUL);
12524                   drxCfg->drxSlotOffset = cuDrxConfig->drx_SlotOffset;
12525                   if(cuDrxConfig->shortDRX)
12526                   {
12527                      drxCfg->shortDrxPres=true;
12528                      drxCfg->shortDrx.drxShortCycle = convertShortDrxCycleLengthEnumToValue(cuDrxConfig->shortDRX->drx_ShortCycle);
12529                      drxCfg->shortDrx.drxShortCycleTimer = cuDrxConfig->shortDRX->drx_ShortCycleTimer;
12530                   }
12531                   else
12532                      drxCfg->shortDrxPres=false;
12533
12534                   break;
12535                }
12536
12537             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
12538                break;
12539          }
12540       }
12541    }
12542 }
12543 #endif
12544
12545 /*******************************************************************
12546  *
12547  * @brief Fills Reconfig Cell group Info received by CU
12548  *
12549  * @details
12550  *
12551  *    Function : extractUeRecfgCellInfo
12552  *
12553  *    Functionality: Fills Reconfig Cell group Info received by CU
12554  *   
12555  * @params[in] CellGroupConfigRrc_t *cellGrp = CellGroupConfigRrc_t information which
12556  *                       is send by CU, which we have stored in F1UeContextSetupDb
12557  *             DuMacUeCfg *MacUeCfg = Used to Store the information,
12558  *                      which needs to send in other layer, as well as this can be
12559  *                      the variable which stores the information in DuCb,
12560  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
12561  *                      information to other layer else it will have copyOfmacUeCfg
12562  *                      which we have stored in F1UeContextSetupDb.
12563  *
12564  * @return ROK/RFAILED
12565  *
12566  * ****************************************************************/
12567 uint8_t extractUeRecfgCellInfo(CellGroupConfigRrc_t *cellGrp, DuMacUeCfg *macUeCfg, DuMacUeCfg *storedMacUeCfg)
12568 {
12569    uint8_t ret = ROK;
12570    MAC_CellGroupConfig_t     *macCellGroup = NULLP;
12571    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
12572    SpCellConfig_t            *spcellCfg = NULLP;
12573    ServingCellConfig_t       *servCellCfg = NULLP;
12574
12575    if(cellGrp)
12576    {
12577       /* Fill MacCell Group Reconfig  */
12578       if(cellGrp->mac_CellGroupConfig)
12579       {
12580          macUeCfg->macCellGrpCfgPres = true;
12581          macCellGroup = ((MAC_CellGroupConfig_t *)(cellGrp->mac_CellGroupConfig));
12582
12583 #ifdef NR_DRX         
12584          if(macCellGroup->drx_ConfigRrc)
12585          {
12586             if(storedMacUeCfg)
12587             {
12588                if(!storedMacUeCfg->macCellGrpCfgPres) 
12589                {
12590                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL);    
12591                }
12592                else
12593                {
12594                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg, &storedMacUeCfg->macCellGrpCfg.drxCfg);    
12595                }
12596             }
12597             else
12598             {
12599                extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL); 
12600             }
12601          }
12602 #endif
12603
12604          if(macCellGroup->schedulingRequestConfig)
12605          {
12606             extractSchReqReConfig(macCellGroup->schedulingRequestConfig, &macUeCfg->macCellGrpCfg.schReqCfg);
12607          }
12608          if(macCellGroup->tag_Config)
12609          {
12610             extractTagReconfig(macCellGroup->tag_Config, &macUeCfg->macCellGrpCfg.tagCfg);
12611          }
12612          if(macCellGroup->bsr_Config)
12613          {
12614             macUeCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer = macCellGroup->bsr_Config->periodicBSR_Timer;
12615             macUeCfg->macCellGrpCfg.bsrTmrCfg.retxTimer     = macCellGroup->bsr_Config->retxBSR_Timer;
12616             if(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer)
12617             {
12618                macUeCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer  =\
12619                *(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer);
12620             }
12621          }
12622          if(macCellGroup->phr_Config)
12623          {
12624             if(macCellGroup->phr_Config->present == MAC_CellGroupConfig__phr_Config_PR_setup)
12625             {
12626                macUeCfg->macCellGrpCfg.phrCfgSetupPres = true;
12627                if(macCellGroup->phr_Config->choice.setup)
12628                {
12629                   macUeCfg->macCellGrpCfg.phrCfg.periodicTimer     = \
12630                   macCellGroup->phr_Config->choice.setup->phr_PeriodicTimer;
12631                   macUeCfg->macCellGrpCfg.phrCfg.prohibitTimer     = \
12632                   macCellGroup->phr_Config->choice.setup->phr_ProhibitTimer;
12633                   macUeCfg->macCellGrpCfg.phrCfg.txPowerFactor     = \
12634                   macCellGroup->phr_Config->choice.setup->phr_Tx_PowerFactorChange;
12635                   macUeCfg->macCellGrpCfg.phrCfg.multiplePHR       = \
12636                   macCellGroup->phr_Config->choice.setup->multiplePHR;
12637                   macUeCfg->macCellGrpCfg.phrCfg.dummy             = \
12638                   macCellGroup->phr_Config->choice.setup->dummy;
12639                   macUeCfg->macCellGrpCfg.phrCfg.phrType2OtherCell = \
12640                   macCellGroup->phr_Config->choice.setup->phr_Type2OtherCell;
12641                   macUeCfg->macCellGrpCfg.phrCfg.phrOtherCG        = \
12642                   macCellGroup->phr_Config->choice.setup->phr_ModeOtherCG;
12643                }
12644             }
12645          }
12646       }
12647       /* Fill Physical Cell Group Reconfig */
12648       if(cellGrp->physicalCellGroupConfig)
12649       {
12650          macUeCfg->phyCellGrpCfgPres = true;
12651          phyCellGrpCfg = ((PhysicalCellGroupConfig_t *)(cellGrp->physicalCellGroupConfig));
12652          if(phyCellGrpCfg->p_NR_FR1)
12653          {
12654             if(*(phyCellGrpCfg->p_NR_FR1) != macUeCfg->phyCellGrpCfg.pNrFr1)
12655                macUeCfg->phyCellGrpCfg.pNrFr1 = *(phyCellGrpCfg->p_NR_FR1);
12656          }
12657          macUeCfg->phyCellGrpCfg.pdschHarqAckCodebook = phyCellGrpCfg->pdsch_HARQ_ACK_Codebook;
12658       }
12659       /* Fill SpCell Reconfig */
12660       if(cellGrp->spCellConfig)
12661       {
12662          macUeCfg->spCellCfgPres = true;
12663          spcellCfg = ((SpCellConfig_t *)(cellGrp->spCellConfig));  
12664          if(spcellCfg->servCellIndex)
12665          {
12666             macUeCfg->spCellCfg.servCellIdx = *(spcellCfg->servCellIndex);
12667          }
12668          /* Fill Serving cell Reconfig info */
12669          if(cellGrp->spCellConfig->spCellConfigDedicated)
12670          {
12671             servCellCfg = ((ServingCellConfig_t *)(cellGrp->spCellConfig->spCellConfigDedicated));
12672             if(storedMacUeCfg)
12673             {
12674                if(!storedMacUeCfg->spCellCfgPres)
12675                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12676                else
12677                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg,\
12678                         &storedMacUeCfg->spCellCfg.servCellCfg);
12679             }
12680             else
12681             {
12682                ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12683             }
12684             if(ret == RFAILED)
12685             {
12686                DU_LOG("\nERROR --> F1AP : Failed at extractSpCellDedicatedCfg()");
12687             }
12688          }
12689       }
12690    }
12691    return ret;
12692 }
12693 /*******************************************************************
12694 *
12695 * @brief free the memory allocated by decoder
12696 *
12697 * @details
12698 *
12699 *    Function : freeAperDecodeNrcgi 
12700 *
12701 *    Functionality: Free Nrcgi values
12702 *
12703 * @params[in] NRCGI_t *nrcgi
12704 * @return void
12705 *
12706 * ****************************************************************/
12707
12708
12709 void freeAperDecodeNrcgi(NRCGI_t *nrcgi)
12710 {
12711     if(nrcgi->pLMN_Identity.buf != NULLP)
12712     {
12713        free(nrcgi->pLMN_Identity.buf);
12714     }
12715     if(nrcgi->nRCellIdentity.buf != NULLP)
12716     {
12717        free(nrcgi->nRCellIdentity.buf);
12718     }
12719 }
12720 /*******************************************************************
12721 *
12722 * @brief free the memory allocated by decoder
12723 *
12724 * @details
12725 *
12726 *    Function : freeAperDecodeCuToDuInfo 
12727 *
12728 *    Functionality:  Free Cu To Du Information
12729 *
12730 * @params[in] CUtoDURRCInformation_t *rrcMsg
12731 * @return void
12732 *
12733 * ****************************************************************/
12734
12735
12736 void freeAperDecodeCuToDuInfo(CUtoDURRCInformation_t *rrcMsg)
12737 {
12738    uint8_t ieIdx =0;
12739    uint8_t arrIdx =0;
12740
12741    if(rrcMsg->uE_CapabilityRAT_ContainerList)
12742    {
12743       if(rrcMsg->uE_CapabilityRAT_ContainerList->buf)
12744          free(rrcMsg->uE_CapabilityRAT_ContainerList->buf);
12745       free(rrcMsg->uE_CapabilityRAT_ContainerList);
12746    }
12747
12748    if(rrcMsg->iE_Extensions)
12749    {
12750       if(rrcMsg->iE_Extensions->list.array)
12751       {
12752          for(ieIdx= 0; ieIdx < rrcMsg->iE_Extensions->list.count; ieIdx++)
12753          {
12754             if(rrcMsg->iE_Extensions->list.array[ieIdx])
12755             {
12756                switch(rrcMsg->iE_Extensions->list.array[ieIdx]->id)
12757                {
12758                   case ProtocolIE_ID_id_CellGroupConfig:
12759                      if(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf != NULLP)
12760                      {
12761                         free(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf);
12762                      }
12763                      break;
12764                   default:
12765                      DU_LOG("\nERROR  -->  F1AP : Invalid Event type %ld at FreeCuToDuInfo()", \
12766                            rrcMsg->iE_Extensions->list.array[ieIdx]->id);
12767                      break;
12768                }
12769             }
12770          }
12771          for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
12772          {
12773             free(rrcMsg->iE_Extensions->list.array[arrIdx]);
12774          }
12775          free(rrcMsg->iE_Extensions->list.array);
12776
12777       }
12778
12779       free(rrcMsg->iE_Extensions);
12780    }
12781 }
12782 /*******************************************************************
12783 *
12784 * @brief free the memory allocated by decoder
12785 *
12786 * @details 
12787 *
12788 *    Function : freeAperDecodeSplCellList
12789 *
12790 *    Functionality: Free Spl Cell List 
12791                     where memory allocated by aper_decoder
12792 *
12793 * @params[in]  SCell_ToBeSetup_List_t *spCellLst
12794 * @return void
12795 *
12796 * ****************************************************************/
12797
12798
12799 void freeAperDecodeSplCellList(SCell_ToBeSetup_List_t *spCellLst)
12800 {
12801     uint8_t  cellIdx =0;
12802
12803     if(spCellLst->list.array != NULLP)
12804     {
12805        for(cellIdx=0; cellIdx<spCellLst->list.count; cellIdx++)
12806        {
12807           if(cellIdx==0&&spCellLst->list.array[cellIdx]!=NULLP)
12808           {
12809              freeAperDecodeNrcgi(&spCellLst->list.array[cellIdx]->value.choice.SCell_ToBeSetup_Item.sCell_ID);
12810           }
12811           if(spCellLst->list.array[cellIdx]!=NULLP)
12812           {
12813              free(spCellLst->list.array[cellIdx]);
12814           }
12815        }
12816        free(spCellLst->list.array);
12817     }
12818 }
12819 /*******************************************************************
12820 *
12821 * @brief free the memory allocated by decoder
12822 *
12823 * @details
12824 *
12825 *    Function : freeAperDecodeSRBSetup 
12826 *
12827 *    Functionality: added free part for the memory allocated by aper_decoder
12828 *
12829 * @params[in] SRBs_ToBeSetup_List_t *srbSet
12830 * @return void
12831 *
12832 ****************************************************************/
12833
12834
12835 void freeAperDecodeSRBSetup(SRBs_ToBeSetup_List_t *srbSet)
12836 {
12837     uint8_t srbIdx =0;
12838     if(srbSet->list.array != NULLP)
12839     {
12840        for(srbIdx=0; srbIdx<srbSet->list.count; srbIdx++)
12841        {
12842           if(srbSet->list.array[srbIdx]!=NULLP)
12843           {
12844              free(srbSet->list.array[srbIdx]);
12845           }
12846        }
12847        free(srbSet->list.array);
12848     }
12849 }
12850
12851 /*******************************************************************
12852 *
12853 * @brief free the memory allocated by decoder
12854 *
12855 * @details
12856 *
12857 *    Function : freeAperDecodeULTnlInfo
12858 *
12859 *    Functionality: added free part for the memory allocated by aper_decoder
12860 *
12861 * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
12862 * @return void
12863 *
12864 * ****************************************************************/
12865
12866
12867 void freeAperDecodeULTnlInfo(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
12868 {
12869    uint8_t ulIdx=0;
12870    if(ulInfo->list.array != NULLP)
12871    {
12872       for(ulIdx=0; ulIdx<ulInfo->list.count; ulIdx++)
12873       {
12874          if(ulIdx==0&&ulInfo->list.array[ulIdx]!=NULLP)
12875          {
12876             if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel!=NULLP)
12877             {
12878                if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12879                      transportLayerAddress.buf != NULLP)
12880                {
12881                   if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf\
12882                         !=NULLP)
12883                   {
12884                      free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf);
12885                   }
12886                   free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12887                         transportLayerAddress.buf);
12888                }
12889                free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel);
12890             }
12891          }
12892          if(ulInfo->list.array[ulIdx]!=NULLP)
12893          {
12894             free(ulInfo->list.array[ulIdx]);
12895          }
12896       }
12897       free(ulInfo->list.array);
12898    }
12899 }
12900 /*******************************************************************
12901 *
12902 * @brief free the memory allocated by decoder
12903 *
12904 * @details
12905 *
12906 *    Function : freeAperDecodeDRBSetup  
12907 *
12908 *    Functionality: free DRBSetup which is allocated by decoder
12909 *
12910 * @params[in]  DRBs_ToBeSetup_List_t *drbSet
12911 * @return void
12912 *
12913 * ****************************************************************/
12914
12915 void freeAperDecodeDRBSetup(DRBs_ToBeSetup_List_t *drbSet)
12916 {
12917    DRBs_ToBeSetup_Item_t *drbSetItem = NULLP;
12918    uint8_t  flowIdx =0;
12919    uint8_t  drbIdx =0;
12920
12921    if(drbSet->list.array != NULLP)
12922    {
12923       for(drbIdx=0; drbIdx<drbSet->list.count; drbIdx++)
12924       {
12925          if(drbIdx==0&&drbSet->list.array[drbIdx] != NULLP)
12926          {
12927             drbSetItem =&drbSet->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12928             if(drbSetItem->qoSInformation.choice.choice_extension != NULLP)
12929             {
12930                if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12931                      qoS_Characteristics.choice.non_Dynamic_5QI !=NULLP)
12932                {
12933                   if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12934                         qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12935                   {
12936                      if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12937                            qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12938                      {
12939
12940                         if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf!=NULLP)
12941                         {
12942
12943                            if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD!=NULLP)
12944                            {
12945
12946                               if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD->\
12947                                     buf!=NULLP)
12948                               {
12949
12950                                  if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.\
12951                                        flows_Mapped_To_DRB_List.list.array != NULLP)
12952                                  {
12953
12954                                     for(flowIdx=0;flowIdx<drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12955                                           DRB_Information.flows_Mapped_To_DRB_List.list.count; flowIdx++)
12956                                     {
12957
12958                                        if(flowIdx==0&&drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12959                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12960                                        {
12961                                           if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12962                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12963                                                 qoSFlowLevelQoSParameters.\
12964                                                 qoS_Characteristics.choice.non_Dynamic_5QI!=NULLP)
12965                                           {
12966                                              if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12967                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12968                                                    qoSFlowLevelQoSParameters.\
12969                                                    qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12970                                              {
12971
12972                                                 if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12973                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12974                                                       qoSFlowLevelQoSParameters.\
12975                                                       qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12976                                                 {
12977
12978
12979                                                    free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12980                                                          DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12981                                                          qoSFlowLevelQoSParameters.\
12982                                                          qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12983                                                 }
12984
12985                                                 free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12986                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12987                                                       qoSFlowLevelQoSParameters.\
12988                                                       qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12989                                              }
12990
12991                                              free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12992
12993                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12994                                                    qoSFlowLevelQoSParameters.\
12995                                                    qoS_Characteristics.choice.non_Dynamic_5QI);
12996                                           }
12997                                        }
12998                                        if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12999                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
13000                                        {
13001
13002                                           free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
13003                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]);
13004                                        }
13005                                     }
13006
13007                                     free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
13008                                           DRB_Information.flows_Mapped_To_DRB_List.list.array);
13009                                  }
13010
13011                                  free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
13012                                        DRB_Information.sNSSAI.sD->buf);
13013                               }
13014
13015                               free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD);
13016                            }
13017
13018                            free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf);
13019
13020                         }
13021
13022                         free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
13023
13024                               qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
13025                      }
13026
13027                      free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
13028                            qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
13029                   }
13030
13031                   free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
13032                         qoS_Characteristics.choice.non_Dynamic_5QI);
13033                }
13034                free(drbSetItem->qoSInformation.choice.choice_extension);
13035             }
13036             freeAperDecodeULTnlInfo(&drbSetItem->uLUPTNLInformation_ToBeSetup_List);
13037             if(drbSetItem->uLConfiguration)
13038             {
13039                free(drbSetItem->uLConfiguration);
13040             }
13041          }
13042          if(drbSet->list.array[drbIdx]!=NULLP)
13043          {
13044             free(drbSet->list.array[drbIdx]);
13045          }
13046       }
13047       free(drbSet->list.array);
13048    }
13049 }
13050
13051
13052 /*******************************************************************
13053  *
13054  * @brief builds Mac Cell Cfg
13055  *
13056  * @details
13057  *
13058  *    Function : procUeRecfgCellInfo
13059  *
13060  *    Functionality: builds Mac Cell Cfg
13061  *
13062  * @params[in] DuMacUeCfg *macUeCfgToSend = Used to Store the information which
13063  *                       needs to send in other layer, as well as this can be
13064  *                       the variable which stores the information in DuCb.
13065  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
13066  *                       information to other layer else it will have copyOfmacUeCfg  
13067  *                       which we have stored in F1UeContextSetupDb
13068  *             void *cellInfo = CellGroupConfigRrc_t information which is send
13069  *                        by CU, which we have stored in F1UeContextSetupDb 
13070  *
13071  * @return void 
13072  *
13073  * ****************************************************************/
13074 uint8_t procUeRecfgCellInfo(DuMacUeCfg *macUeCfgToSend, DuMacUeCfg *storedMacUeCfg, void *cellInfo)
13075 {
13076    uint8_t ret = ROK;
13077    CellGroupConfigRrc_t *cellGrp = NULLP;
13078
13079    if(cellInfo)
13080    {
13081       cellGrp = (CellGroupConfigRrc_t *)cellInfo;
13082       ret = extractUeRecfgCellInfo(cellGrp, macUeCfgToSend, storedMacUeCfg);
13083       if(ret == RFAILED)
13084          DU_LOG("\nERROR  -->  F1AP : Failed at procUeRecfgCellInfo()");
13085    }
13086    if(ret == RFAILED)
13087    {
13088       freeUeRecfgCellGrpInfo(macUeCfgToSend);
13089    }
13090    return ret;
13091 }
13092
13093 /*******************************************************************
13094  *
13095  * @brief Filling modulation info in mac ue cfg
13096  *
13097  * @details
13098  *
13099  *    Function : duFillModulationDetails
13100  *
13101  *    Functionality: Filling modulation info in mac ue cfg
13102  *
13103  * @params[in] MAC UE Config to be updated
13104  *             Current UE configuration
13105  *             UE NR capability from CU
13106  * @return ROK     - success
13107  *         RFAILED - failure
13108  *
13109  * ****************************************************************/
13110 void duFillModulationDetails(DuMacUeCfg *ueCfg, DuMacUeCfg *oldUeCfg, void *ueCap)
13111 {
13112    UE_NR_Capability_t *ueNrCap=NULLP;
13113
13114    if(!ueCap && oldUeCfg)
13115    {
13116       memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));     
13117       memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13118    }
13119    else
13120    {
13121       ueNrCap = (UE_NR_Capability_t *)ueCap;
13122
13123       /* Filling DL modulation info */
13124       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsDownlinkPerCC && \
13125          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0] && \
13126          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL)
13127       {
13128          switch(*(ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL))
13129          {
13130             case ModulationOrder_qpsk:
13131                {
13132                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
13133                   break;
13134                }
13135             case ModulationOrder_qam16:
13136                {
13137                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM16;
13138                   break;
13139                }
13140             case ModulationOrder_qam64:
13141                {
13142                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM64;
13143                   ueCfg->dlModInfo.mcsIndex = PDSCH_MCS_INDEX;
13144                   ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64;
13145                   break;
13146                }
13147             case ModulationOrder_qam256:
13148                {
13149                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM256;
13150                   break;
13151                }
13152             default:
13153                {
13154                   DU_LOG("\nERROR  -->  DU APP: Incorrect downlink modulation order received. Reatining old modulation configuration");
13155                   if(oldUeCfg)
13156                      memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
13157                   break;
13158                }
13159          }
13160       }
13161       else
13162       {
13163          if(oldUeCfg)
13164             memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
13165       }
13166
13167       /* Filling UL modulation info */
13168       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsUplinkPerCC && \
13169          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0] && \
13170          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL)
13171       {
13172          switch(*(ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL))
13173          {
13174             case ModulationOrder_qpsk:
13175                {
13176                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
13177                   break;
13178                }
13179             case ModulationOrder_qam16:
13180                {
13181                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM16;
13182                   ueCfg->ulModInfo.mcsIndex = PUSCH_MCS_INDEX;
13183                   ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64;
13184                   break;
13185                }
13186             case ModulationOrder_qam64:
13187                {
13188                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM64;
13189                   break;
13190                }
13191             case ModulationOrder_qam256:
13192                {
13193                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM256;
13194                   break;
13195                }
13196             default:
13197                {
13198                   DU_LOG("\nERROR  -->  DU APP: Incorrect uplink modulation order received. Reatining old modulation configuration");
13199                   if(oldUeCfg)
13200                      memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13201                   break;
13202                }
13203          }
13204       }
13205       else
13206       {
13207          if(oldUeCfg)
13208             memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13209       }
13210    }
13211 }
13212
13213 /*******************************************************************
13214  *
13215  * @brief Function to extract info from CU to DU RRC container extension
13216  *
13217  * @details
13218  *
13219  *    Function : extractCuToDuRrcInfoExt
13220  *
13221  *    Functionality: Function to extract info from CU to DU RRC container
13222  *    extension
13223  *
13224  * @params[in] ProtocolExtensionContainer_4624P16_t pointer
13225  *
13226  * @return ROK
13227  *         RFAILED
13228  *
13229  * ****************************************************************/
13230 uint8_t extractCuToDuRrcInfoExt(ProtocolExtensionContainer_4624P16_t *protocolIeExtn, DuUeCfg *ueCfgDb)
13231 {
13232    uint8_t ieIdx =0;
13233    uint16_t recvBufLen =0;
13234    CellGroupConfigRrc_t *cellGrpCfg = NULLP;
13235    CUtoDURRCInformation_ExtIEs_t *extIeInfo = NULLP;
13236    asn_dec_rval_t rval; /* Decoder return value */
13237    memset(&rval, 0, sizeof(asn_dec_rval_t));
13238
13239    if(protocolIeExtn)
13240    {
13241       for(ieIdx = 0; ieIdx < protocolIeExtn->list.count; ieIdx++)
13242       {
13243          extIeInfo = ((CUtoDURRCInformation_ExtIEs_t *)(protocolIeExtn->list.array[ieIdx]));
13244          switch(extIeInfo->id)
13245          {
13246             case ProtocolIE_ID_id_CellGroupConfig:
13247                {
13248                   /* decoding the CellGroup Buf received */
13249                   recvBufLen = extIeInfo->extensionValue.choice.CellGroupConfig.size;
13250                   DU_ALLOC(cellGrpCfg, sizeof(CellGroupConfigRrc_t));
13251                   if(cellGrpCfg)
13252                   {
13253                      memset(cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
13254                      rval = uper_decode(0, &asn_DEF_CellGroupConfigRrc, (void **)&cellGrpCfg,
13255                            extIeInfo->extensionValue.choice.CellGroupConfig.buf, recvBufLen, 0, 0);
13256                      if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13257                      {
13258                         DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13259                         return RFAILED;
13260                      }
13261                      xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, cellGrpCfg);
13262
13263                      if(extractRlcCfgToAddMod(cellGrpCfg->rlc_BearerToAddModList, ueCfgDb))
13264                         return NULLP;
13265                      ueCfgDb->cellGrpCfg = cellGrpCfg;
13266                   }
13267                   break;
13268                }
13269
13270             case ProtocolIE_ID_id_HandoverPreparationInformation:
13271                {
13272                   DU_LOG("\nINFO -->  F1AP : Received HANDOVER PREPARATION INFO in UE CONTEXT SETUP REQUEST");
13273                   break;
13274                }
13275
13276             default:
13277                DU_LOG("\nERROR  -->  F1AP : Invalid IE received CUtoDURRCInformation: %ld at decodeCellGrpCfg()", extIeInfo->id);
13278                break;
13279          }
13280       }
13281    }
13282    return ROK;
13283 }
13284
13285 /*******************************************************************
13286  *
13287  * @brief Fills Srb List received by CU
13288  *
13289  * @details
13290  *
13291  *    Function : procSrbListToSetup
13292  *
13293  *    Functionality: Fills Srb List received  by CU
13294  *
13295  * @params[in] SRBs_ToBeSetup_Item_t *cuSrbItem
13296  *             DuLcCfg pointer
13297  *             RlcBearerCfg pointer
13298  * @return void
13299  *
13300  * ****************************************************************/
13301 uint8_t procSrbListToSetup(SRBs_ToBeSetup_Item_t * srbItem, DuLcCfg *duMacLcToAdd, DuRlcBearerCfg *rlcLcToAdd)
13302 {
13303
13304    /* Filling RLC INFO */
13305    procRlcLcCfg(srbItem->sRBID, srbItem->sRBID, RB_TYPE_SRB, RLC_AM, CONFIG_ADD, NULL, rlcLcToAdd, NULL);
13306
13307    /* Filling MAC INFO */
13308    if(procMacLcCfg(srbItem->sRBID, RB_TYPE_SRB, CONFIG_ADD, NULL,NULL, NULL, NULL, duMacLcToAdd, NULL)  != ROK)
13309    { 
13310       DU_LOG("\nERROR  -->  F1AP : Failed at MAC LC Cfg in procSrbListToSetup()");
13311       return RFAILED;
13312    }
13313
13314    return ROK;
13315 }
13316
13317
13318
13319 /*******************************************************************
13320  *
13321  * @brief extract Srb List received by CU
13322  *
13323  * @details
13324  *
13325  *    Function : extractSrbListToSetup
13326  *
13327  *    Functionality: extract Srb List received by CU
13328  *                   for both MAC and RLC
13329  *
13330  * @params[in] SRBs_ToBeSetup_Item_t pointer
13331  *             DuUeCfg pointer
13332  * @return ROK/RFAIED
13333  *
13334  * ****************************************************************/
13335
13336 uint8_t extractSrbListToSetup(SRBs_ToBeSetup_List_t *srbCfg, DuUeCfg *ueCfgDb)
13337 {
13338    uint8_t ret = ROK, srbIdx = 0, rlcLcIdx = 0;
13339    SRBs_ToBeSetup_Item_t *srbItem = NULLP;
13340    DuLcCfg *macLcCtxt = NULLP;
13341    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13342
13343    if(srbCfg)
13344    {
13345       for(srbIdx = 0; srbIdx < srbCfg->list.count; srbIdx++)
13346       {
13347          macLcCtxt = NULL;
13348          rlcLcCtxt = NULL;
13349
13350          srbItem = &srbCfg->list.array[srbIdx]->value.choice.SRBs_ToBeSetup_Item;
13351          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13352          { 
13353             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in MAC");
13354             ret = RFAILED;
13355             break;
13356          }
13357          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13358          {
13359             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in RLC");
13360             ret = RFAILED;
13361             break;
13362          }
13363
13364          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numMacLcs; rlcLcIdx++)
13365          {
13366             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == srbItem->sRBID && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
13367             {
13368                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13369                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13370                break;
13371             }
13372          }
13373          if(!macLcCtxt)
13374          {
13375             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13376             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13377             ueCfgDb->numMacLcs++;
13378          }
13379          if(!rlcLcCtxt)
13380          {
13381             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13382             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13383             ueCfgDb->numRlcLcs++;
13384          }
13385
13386          ret = procSrbListToSetup(srbItem, macLcCtxt, rlcLcCtxt);
13387
13388          DU_LOG("\nDEBUG --> DUAPP: extractSrbListToSetup: SRBID: %ld [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13389                srbItem->sRBID, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13390          if(ret == RFAILED)
13391          {
13392             DU_LOG("\nERROR  -->  F1AP:  Failed at extractSrbListToSetup()");
13393             break;
13394          }
13395       }
13396    }
13397    else
13398       ret = RFAILED;
13399
13400    return ret;
13401 }
13402
13403 /*******************************************************************
13404  *
13405  * @brief Fills Drb List received by CU
13406  *
13407  * @details
13408  *
13409  *    Function : procDrbListToSetupMod
13410  *
13411  *    Functionality: Fills Drb List received by CU
13412  *                   for both MAC and RLC
13413  *
13414  * @params[in] DRBs_ToBeSetup_Item_t , DRBs_ToBeSetupMod_Item_t,
13415  *             DRBs_ToBeModified_Item_t , lcId, DuLcCfg pointer,
13416  *             RlcBearerCfg , UpTnlCfg, DuRlcUeCfg
13417  * @return void
13418  *
13419  * ****************************************************************/
13420
13421 uint8_t procDrbListToSetupMod(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbItem,\
13422 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, DuLcCfg *macLcToAdd, DuRlcBearerCfg *rlcLcToAdd, UpTnlCfg *upTnlInfo, DuRlcUeCfg *storedRlcUeCfg)
13423 {
13424    uint8_t cfgIdx = 0;
13425    RlcMode rlcModeInfo;
13426
13427    if(drbItem != NULLP)
13428    {
13429       /* Filling RLC INFO */
13430       procRlcLcCfg(drbItem->dRBID, lcId, RB_TYPE_DRB, drbItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, &drbItem->\
13431       qoSInformation);
13432
13433       /* Filling MAC INFO */
13434       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, drbItem, NULL, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13435       { 
13436          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13437          return RFAILED;
13438       }
13439    }
13440    else if(drbSetupModItem != NULLP)
13441    {
13442       procRlcLcCfg(drbSetupModItem->dRBID, lcId, RB_TYPE_DRB, drbSetupModItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, 
13443       &drbSetupModItem->qoSInformation);
13444
13445       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, NULL, drbSetupModItem, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13446       {
13447          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13448          return RFAILED;
13449       }
13450    }
13451    else if(drbModItem != NULLP)
13452    {
13453       /* Drb to Mod IEs doesnot have rlcMode to be modified
13454        * in ASN. Hence no change in RLC configurations */
13455       if(storedRlcUeCfg != NULLP)
13456       {
13457          for(cfgIdx = 0; cfgIdx < storedRlcUeCfg->numLcs; cfgIdx++)
13458          {
13459             if(storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.lcId == lcId)
13460             {
13461                rlcModeInfo = storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.rlcMode;
13462                break;
13463             }
13464          }
13465       }
13466
13467       procRlcLcCfg(drbModItem->dRBID, lcId, RB_TYPE_DRB, rlcModeInfo, CONFIG_MOD, NULL, rlcLcToAdd, drbModItem->qoSInformation);
13468       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_MOD, NULL, NULL, drbModItem, NULL, macLcToAdd, upTnlInfo) != ROK)
13469       {
13470          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13471          return RFAILED;
13472       }
13473    }
13474    return ROK;
13475 }
13476
13477 /*******************************************************************
13478  *
13479  * @brief extract Drb List received by CU
13480  *
13481  * @details
13482  *
13483  *    Function : extractDrbListToSetupMod
13484  *
13485  *    Functionality: extract Drb List received by CU
13486  *                   for both MAC and RLC
13487  *
13488  * @params[in] DRBs_ToBeSetup_Item_t pointer
13489  *             DuUeCfg pointer
13490  * @return ROK/RFAIED
13491  *
13492  * ****************************************************************/
13493
13494 uint8_t extractDrbListToSetupMod(DRBs_ToBeSetup_List_t *drbCfg, DRBs_ToBeSetupMod_List_t *drbSetupModCfg,\
13495  DRBs_ToBeModified_List_t *drbModCfg, uint8_t drbCount, DuUeCfg *ueCfgDb, uint32_t *drbBitMap, DuRlcUeCfg *rlcUeCfg)
13496 {
13497    uint8_t ret = ROK;
13498    uint8_t drbIdx = 0, rlcLcIdx = 0;
13499    uint8_t drbId = 0, lcId = 0;
13500    DRBs_ToBeSetup_Item_t *drbItem = NULLP;
13501    DRBs_ToBeSetupMod_ItemIEs_t *drbSetupModItem = NULLP;
13502    DRBs_ToBeModified_ItemIEs_t *drbModItem = NULLP;
13503    DuLcCfg *macLcCtxt = NULLP;
13504    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13505
13506    ret = ROK;
13507    if(drbCount > 0)
13508    {
13509       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13510       {
13511          macLcCtxt = NULL;
13512          rlcLcCtxt = NULL;
13513
13514          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13515          { 
13516             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in MAC at extractDrbListToSetupMod()");
13517             ret = RFAILED;
13518             break;
13519          }
13520          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13521          {
13522             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in RLC at extractDrbListToSetupMod()");
13523             ret = RFAILED;
13524             break;
13525          }
13526
13527          if(drbModCfg != NULLP)
13528          {
13529             drbModItem = (DRBs_ToBeModified_ItemIEs_t *) drbModCfg->list.array[drbIdx];
13530             drbId = drbModItem->value.choice.DRBs_ToBeModified_Item.dRBID;
13531          }
13532          else if(drbCfg != NULLP)
13533             drbId = drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item.dRBID;
13534          else if(drbSetupModCfg != NULL)
13535          {
13536             drbSetupModItem = (DRBs_ToBeSetupMod_ItemIEs_t *) drbSetupModCfg->list.array[drbIdx];
13537             drbId = drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item.dRBID;
13538          }
13539
13540          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13541          {
13542             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && \
13543                    ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13544             {
13545                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13546                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13547                break;
13548             }
13549          }
13550          if(!macLcCtxt)
13551          {
13552             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13553             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13554             ueCfgDb->numMacLcs++;
13555          }
13556          if(!rlcLcCtxt)
13557          {
13558             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
13559             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13560             ueCfgDb->numRlcLcs++;
13561          }
13562
13563          if(drbModCfg != NULLP)
13564          {
13565             lcId = fetchLcId(drbId);
13566             if(lcId < MIN_DRB_LCID)
13567             {
13568                DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToSetupMod() for Modified List", lcId);
13569                break;
13570             } 
13571             ret = procDrbListToSetupMod(lcId, NULL, NULL, &(drbModItem->value.choice.DRBs_ToBeModified_Item),\
13572             macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13573             if(ret == RFAILED)
13574             {
13575                DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for Modified List");
13576                break;
13577             }
13578             ueCfgDb->numDrbModified++;
13579          }
13580          else
13581          {
13582             lcId = getDrbLcId(drbBitMap);
13583             if(lcId == RFAILED)
13584             {
13585                DU_LOG("\nERROR  -->  F1AP :  InCorrect LCID extractDrbListToSetupMod()");
13586                ret = RFAILED;
13587                break;
13588             }
13589             if(drbCfg != NULL)
13590             {
13591                drbItem = &drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
13592                ret = procDrbListToSetupMod(lcId, drbItem, NULL, NULL, macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13593                if(ret == RFAILED)
13594                {
13595                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetup List");
13596                   break;
13597                }
13598             }
13599             else if(drbSetupModCfg != NULL)
13600             {
13601                ret = procDrbListToSetupMod(lcId, NULL, &(drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item), NULL,\
13602                      macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13603                if(ret == RFAILED)
13604                {
13605                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetupMod List");
13606                   break;
13607                }
13608                ueCfgDb->numDrbSetupMod++;
13609             }
13610          }
13611          ueCfgDb->numDrb++;
13612  
13613          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToSetupMod:lcId:%x ,BitMap:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13614                             lcId,*drbBitMap, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13615          if(ret == RFAILED)
13616          {
13617             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod()");
13618             break;
13619          }
13620       }
13621    }
13622    else
13623       ret = RFAILED;
13624
13625    return ret;
13626 }
13627
13628 /*******************************************************************
13629  *
13630  * @brief extract Drb List received from CU
13631  *
13632  * @details
13633  *
13634  *    Function : extractDrbListToRelease
13635  *
13636  *    Functionality: extract Drb List received from CU
13637  *                   for both MAC and RLC
13638  *
13639  * @params[in] DRBs_ToBeReleased_Item_t pointer
13640  *             DuUeCfg pointer
13641  * @return ROK/RFAIED
13642  *
13643  * ****************************************************************/
13644
13645 uint8_t extractDrbListToRelease(uint8_t ueId, DRBs_ToBeReleased_List_t *drbToRel, uint8_t drbCount, DuUeCfg *ueCfgDb, DuRlcUeCfg *rlcUeCfg)
13646 {
13647    uint8_t ret = ROK, teIdx = 0;
13648    uint8_t drbIdx = 0, rlcLcIdx = 0;
13649    uint8_t drbId = 0, lcId = 0;
13650    DRBs_ToBeReleased_ItemIEs_t *drbRelItem = NULLP;
13651    DuLcCfg *macLcCtxt = NULLP;
13652    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13653
13654    ret = ROK;
13655    if(drbCount > 0)
13656    {
13657       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13658       {
13659          macLcCtxt = NULL;
13660          rlcLcCtxt = NULL;
13661
13662          if(drbToRel != NULLP)
13663          {
13664             drbRelItem = (DRBs_ToBeReleased_ItemIEs_t *) drbToRel->list.array[drbIdx];
13665             drbId = drbRelItem->value.choice.DRBs_ToBeReleased_Item.dRBID;
13666          }
13667          else
13668          {
13669             DU_LOG("ERROR  --> DU APP : DrbToRelease pointer is NULL in extractDrbListToRelease");
13670             return RFAILED;
13671          }
13672
13673          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13674          {
13675             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13676             {
13677                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13678                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13679                break;
13680             }
13681          }
13682
13683          if(!macLcCtxt)
13684          {
13685             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13686             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13687             ueCfgDb->numMacLcs++;
13688          }
13689          if(!rlcLcCtxt)
13690          {
13691             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13692             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13693             ueCfgDb->numRlcLcs++;
13694          }
13695          lcId = fetchLcId(drbId);
13696          if(lcId < MIN_DRB_LCID)
13697          {
13698             DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToRelease() for Modified List", lcId);
13699             break;
13700          } 
13701
13702          /* Filling RLC INFO */
13703          procRlcLcCfg(drbId, lcId, RB_TYPE_DRB, rlcLcCtxt->rlcBearerCfg.rlcMode, CONFIG_DEL, NULL, rlcLcCtxt, NULLP);
13704          /* Filling MAC INFO */
13705          if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_DEL, NULL, NULL, NULL, NULL, macLcCtxt, NULLP) != ROK)
13706          { 
13707             DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in extractDrbListToRelease()");
13708             return RFAILED;
13709          }
13710          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].configType = CONFIG_DEL;
13711          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId = drbId;
13712          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId = ueId;
13713
13714          for(teIdx = 0; teIdx < duCb.numTeId; teIdx++)
13715          {
13716             if((duCb.upTnlCfg[teIdx]->ueId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId) && \
13717                   (duCb.upTnlCfg[teIdx]->drbId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId))
13718             {
13719                DU_ALLOC(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, sizeof(GtpTnlCfg)); 
13720                memcpy(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, duCb.upTnlCfg[teIdx]->tnlCfg1, sizeof(GtpTnlCfg));
13721                break;
13722             }
13723          }
13724
13725          ueCfgDb->numDrb++;
13726          if(ret == RFAILED)
13727          {
13728             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToRelease() for Modified List");
13729             break;
13730          }
13731
13732          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToRelease():lcId:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13733                lcId,ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13734       }
13735    }
13736    else
13737       ret = RFAILED;
13738
13739    return ret;
13740 }
13741
13742 /*******************************************************************
13743  *
13744  * @brief Function to extract Dl RRC Msg received from CU
13745  *
13746  * @details
13747  *
13748  *    Function : extractDlRrcMsg
13749  *
13750  *    Functionality: Function to extract Dl RRC Msg received from CU
13751  *
13752  * @params[in] F1AP message
13753  * @return ROK     - success
13754  *         RFAILED - failure
13755  *
13756  * ****************************************************************/
13757
13758 uint8_t extractDlRrcMsg(uint32_t gnbDuUeF1apId, uint32_t gnbCuUeF1apId, \
13759    F1DlRrcMsg *dlRrcMsg, RRCContainer_t *rrcContainer)
13760 {
13761    uint8_t ret = ROK;
13762    dlRrcMsg->rrcMsgSize = rrcContainer->size;
13763    if(dlRrcMsg->rrcMsgSize > 0)
13764    {
13765       DU_ALLOC_SHRABL_BUF(dlRrcMsg->rrcMsgPdu, dlRrcMsg->rrcMsgSize);
13766       if(!dlRrcMsg->rrcMsgPdu)
13767       {
13768          DU_LOG("\nERROR  --> DU APP : Memory allocation failed for RRC Msg in extractDlRrcMsg()");
13769          ret = RFAILED;
13770       }
13771       else
13772       {
13773          dlRrcMsg->gnbDuUeF1apId = gnbDuUeF1apId;
13774          dlRrcMsg->gnbCuUeF1apId = gnbCuUeF1apId;
13775          dlRrcMsg->srbId = SRB1_LCID;
13776          memcpy(dlRrcMsg->rrcMsgPdu, rrcContainer->buf, dlRrcMsg->rrcMsgSize);
13777       }
13778    }
13779    return ret;
13780 }
13781
13782 /*******************************************************************
13783  *
13784  * @brief Extract UE capability info 
13785  *
13786  * @details
13787  *
13788  *    Function : extractUeCapability
13789  *
13790  *    Functionality: Extract UE capability info and stores in ue Cb
13791  *
13792  * @params[in] Octet string of UE capability RAT container list
13793  * @return ROK     - success
13794  *         RFAILED - failure
13795  *
13796  * ****************************************************************/
13797 UE_NR_Capability_t *extractUeCapability(UE_CapabilityRAT_ContainerList_t *ueCapablityListBuf, DuUeCb *ueCb)
13798 {
13799    uint8_t  idx;
13800    uint16_t recvBufLen;
13801    asn_dec_rval_t rval;
13802    UE_NR_Capability_t  *ueNrCap = NULLP;
13803    UE_CapabilityRAT_ContainerListRRC_t  *ueCapRatContList = NULLP;
13804
13805    /* Decoding UE Capability RAT Container List */
13806    recvBufLen = ueCapablityListBuf->size;
13807    DU_ALLOC(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13808    if(!ueCapRatContList)
13809    {
13810       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13811       return NULLP;
13812    }
13813    memset(ueCapRatContList, 0, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13814    memset(&rval, 0, sizeof(asn_dec_rval_t));
13815    rval = uper_decode(0, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, (void **)&ueCapRatContList,
13816           ueCapablityListBuf->buf, recvBufLen, 0, 0);
13817    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13818    {
13819       DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13820       return NULLP;
13821    }
13822    xer_fprint(stdout, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, ueCapRatContList);
13823
13824    /* Free encoded buffer after decoding */
13825
13826    for(idx = 0; idx < ueCapRatContList->list.count; idx++)
13827    {
13828       if(ueCapRatContList->list.array[idx]->rat_Type == RAT_Type_nr)
13829       {
13830          /* Decoding UE NR Capability */
13831           recvBufLen = ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.size;
13832           DU_ALLOC(ueNrCap, sizeof(UE_NR_Capability_t));
13833           if(!ueNrCap)
13834           {
13835              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13836              DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13837              return NULLP;
13838           } 
13839           memset(ueNrCap, 0, sizeof(UE_NR_Capability_t));
13840           memset(&rval, 0, sizeof(asn_dec_rval_t));
13841           rval = uper_decode(0, &asn_DEF_UE_NR_Capability, (void **)&ueNrCap,
13842                  ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf, recvBufLen, 0, 0);
13843           if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13844           {
13845              DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13846              return NULLP;
13847           }
13848           xer_fprint(stdout, &asn_DEF_UE_NR_Capability, ueNrCap);
13849           
13850           /* Free encoded buffer after decoding */
13851           free(ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf);
13852       }
13853       free(ueCapRatContList->list.array[idx]);
13854    }
13855
13856    /* Free Memory*/
13857    free(ueCapRatContList->list.array);
13858    DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13859    return ueNrCap;
13860 }
13861  
13862 /*******************************************************************
13863 *
13864 * @brief free UE context setup request from CU
13865 *
13866 * @details
13867 *
13868 *    Function : freeAperDecodeF1UeContextSetupReq
13869 *
13870 *    Functionality: freeing part for the memory allocated by aper_decoder
13871 *
13872 * @params[in] F1AP message
13873 * @return ROK     - success
13874 *         RFAILED - failure
13875 *
13876 * ****************************************************************/
13877 void freeAperDecodeF1UeContextSetupReq(UEContextSetupRequest_t   *ueSetReq)
13878 {
13879    uint8_t ieIdx = 0;
13880
13881    if(ueSetReq->protocolIEs.list.array != NULLP)
13882    {
13883       for(ieIdx = 0; ieIdx < ueSetReq->protocolIEs.list.count; ieIdx++)
13884       {
13885          if(ueSetReq->protocolIEs.list.array[ieIdx])
13886          {
13887             switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13888             {
13889                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13890                   break;
13891                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13892                   break;
13893                case ProtocolIE_ID_id_SpCell_ID:
13894                   freeAperDecodeNrcgi(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
13895                   break;
13896                case ProtocolIE_ID_id_ServCellIndex:
13897                   break;
13898                case ProtocolIE_ID_id_SpCellULConfigured:
13899                   break;
13900                case ProtocolIE_ID_id_CUtoDURRCInformation:
13901
13902                   freeAperDecodeCuToDuInfo(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation);
13903                   break;
13904                case ProtocolIE_ID_id_SCell_ToBeSetup_List:
13905
13906                   freeAperDecodeSplCellList(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SCell_ToBeSetup_List);
13907                   break;
13908                case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
13909
13910                   freeAperDecodeSRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List);
13911                   break;
13912                case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
13913
13914                   freeAperDecodeDRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List);
13915                   break;
13916                case ProtocolIE_ID_id_RRCContainer:
13917                   {
13918
13919                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf != NULLP)
13920                      {
13921
13922                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
13923                      }
13924                      break;
13925                   }
13926                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13927                   break;
13928                case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
13929                   {
13930                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf)
13931                      {
13932                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf);
13933                      }
13934                      break;
13935                   }
13936 #ifdef NR_DRX
13937                case ProtocolIE_ID_id_DRXCycle:
13938                   {
13939                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength)
13940                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength);
13941                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer)
13942                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer);
13943                      break;
13944                   }
13945 #endif             
13946                 default:
13947                   DU_LOG("\nERROR  -->  F1AP: Invalid event type %ld " ,ueSetReq->protocolIEs.list.array[ieIdx]->id);
13948             } 
13949             free(ueSetReq->protocolIEs.list.array[ieIdx]);
13950          }
13951       }
13952       free(ueSetReq->protocolIEs.list.array);
13953    }
13954 }
13955 /*******************************************************************
13956  *
13957  * @brief Process UE context setup request from CU
13958  *
13959  * @details
13960  *
13961  *    Function : procF1UeContextSetupReq
13962  *
13963  *    Functionality: Process UE context setup request from CU
13964  *
13965  * @params[in] F1AP message
13966  * @return ROK     - success
13967  *         RFAILED - failure
13968  *
13969  * ****************************************************************/
13970 uint8_t procF1UeContextSetupReq(F1AP_PDU_t *f1apMsg)
13971 {
13972    int8_t ueIdx = -1;
13973    uint8_t  ret=0, ieIdx=0, ieExtIdx = 0;
13974    //uint8_t servCellIdx = 0;
13975    bool ueCbFound = false, hoInProgress = false;
13976    uint16_t cellIdx=0;
13977    uint64_t nrCellId = 0;
13978    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0, bitRateSize=0;
13979    DuUeCb   *duUeCb = NULL;
13980    UEContextSetupRequest_t   *ueSetReq = NULL;
13981    DRBs_ToBeSetup_List_t *drbCfg = NULL;
13982    CUtoDURRCInformation_t *rrcInfo = NULL;
13983 #ifdef NR_DRX
13984    DRXCycle_t *drxCycle;
13985 #endif
13986    ret = ROK;
13987
13988    ueSetReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextSetupRequest;
13989    for(ieIdx=0; (ieIdx < ueSetReq->protocolIEs.list.count && ret == ROK); ieIdx++)
13990    {
13991       switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13992       {
13993          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13994             {
13995                gnbCuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
13996                break;
13997             }
13998
13999          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14000             {
14001                gnbDuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
14002                break;
14003             }
14004
14005          case ProtocolIE_ID_id_SpCell_ID:
14006             {
14007                bitStringToInt(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity, &nrCellId);
14008
14009                GET_CELL_IDX(nrCellId, cellIdx);
14010                if(!duCb.actvCellLst[cellIdx])
14011                {
14012                   DU_LOG("\nERROR  -->  F1AP : Cell Id [%lu] not found", nrCellId);
14013                   ret = RFAILED;
14014                }
14015                break;
14016             }
14017
14018          case ProtocolIE_ID_id_ServCellIndex:
14019             {
14020                //servCellIdx = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.ServCellIndex;
14021                break;
14022             }
14023
14024          case ProtocolIE_ID_id_SpCellULConfigured:
14025             {
14026                /* Indicates whether the gNB-CU requests the gNB-DU to configure the uplink as no UL, 
14027                   UL, SUL or UL+SUL for the indicated cell for the UE */
14028                break;
14029             }
14030
14031          case ProtocolIE_ID_id_CUtoDURRCInformation:
14032             {
14033                rrcInfo = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation;
14034
14035                /* Search if UE context is present */
14036                for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
14037                {
14038                   if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId)
14039                   {
14040                      ueCbFound = true;
14041                      duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
14042                      break;
14043                   }
14044                }
14045
14046                /* Check if UE Handover scenario */
14047                if(rrcInfo->iE_Extensions)
14048                {
14049                   for(ieExtIdx = 0; ieExtIdx < rrcInfo->iE_Extensions->list.count; ieExtIdx++)
14050                   {
14051                      if(rrcInfo->iE_Extensions->list.array[ieExtIdx]->id == ProtocolIE_ID_id_HandoverPreparationInformation)
14052                      {
14053                         hoInProgress = true;
14054                         break;
14055                      }
14056                   }
14057                }
14058                
14059                /* If UE context is not present, but UE is in handover */
14060                if(!ueCbFound && hoInProgress)
14061                {
14062                   ueIdx = getFreeBitFromUeBitMap(nrCellId);
14063                   if(ueIdx != -1)
14064                      gnbDuUeF1apId = ueIdx +1;
14065                   else
14066                   {
14067                      DU_LOG("\nERROR  -->  F1AP : No free UE IDX found in UE bit map of cell Id [%lu]", nrCellId);
14068                      ret = RFAILED;
14069                      break;
14070                   }
14071                   duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
14072                   duUeCb->f1UeDb = NULL;
14073                   duUeCb->gnbCuUeF1apId = gnbCuUeF1apId;
14074                   duUeCb->gnbDuUeF1apId = gnbDuUeF1apId;
14075                   GET_CRNTI(duUeCb->crnti, duUeCb->gnbDuUeF1apId);
14076                   duUeCb->ueState = UE_HANDIN_IN_PROGRESS;
14077                }
14078
14079                if(duUeCb)
14080                {
14081                   DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
14082                   if(duUeCb->f1UeDb)
14083                   {
14084                      memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
14085                      duUeCb->f1UeDb->actionType = UE_CTXT_SETUP;
14086                      duUeCb->f1UeDb->cellIdx = cellIdx;
14087                   }
14088                   else
14089                   {
14090                      DU_LOG("\nERROR  -->  F1AP: Memory Alloc Failed at procF1UeContextSetupReq()");
14091                      ret = RFAILED;
14092                      break;
14093                   }
14094                }
14095                else
14096                {
14097                   DU_LOG("\nERROR  -->  F1AP: DuUeCb is not found at procF1UeContextSetupReq()");
14098                   ret = RFAILED;
14099                   break;
14100                }
14101                  
14102                /* Extract UE capability info */
14103                if(rrcInfo->uE_CapabilityRAT_ContainerList)
14104                {
14105                   duUeCb->f1UeDb->duUeCfg.ueNrCapability = extractUeCapability(rrcInfo->uE_CapabilityRAT_ContainerList, duUeCb);
14106                }
14107
14108                /* Extract IE extension */
14109                if(rrcInfo->iE_Extensions)
14110                {
14111                   if(extractCuToDuRrcInfoExt(rrcInfo->iE_Extensions, &duUeCb->f1UeDb->duUeCfg) != ROK)
14112                   {
14113                      DU_LOG("\nERROR  -->  F1AP: Failed to extract CU to DU RRC information extension IE");
14114                      //TODO: Update the failure cause in ue context Setup Response
14115                      ret = RFAILED;
14116                   }
14117                }
14118                break;
14119             } 
14120
14121 #ifdef NR_DRX
14122          case ProtocolIE_ID_id_DRXCycle:
14123             {
14124                duUeCb->f1UeDb->duUeCfg.drxCyclePres = true;
14125                drxCycle = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle;
14126                duUeCb->f1UeDb->duUeCfg.drxCycle.drxLongCycleLength =  convertLongDrxCycleLengthEnumToValue(drxCycle->longDRXCycleLength);
14127                if(drxCycle->shortDRXCycleLength)
14128                {
14129                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCyclePres = true;
14130                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycle = \
14131                   convertShortDrxCycleLengthEnumToValue(*(drxCycle->shortDRXCycleLength));
14132                }
14133                if(drxCycle->shortDRXCycleTimer)
14134                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycleTimer = *(drxCycle->shortDRXCycleTimer);   
14135
14136                break;
14137             }
14138
14139 #endif
14140          case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
14141             {
14142                if(extractSrbListToSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List,\
14143                         &duUeCb->f1UeDb->duUeCfg))
14144                {
14145                   DU_LOG("\nERROR  -->  DU APP : Failed at extractSrbListToSetup()");
14146                   //TODO: Update the failure cause in ue context Setup Response
14147                   ret = RFAILED;
14148                }
14149                break;
14150             }
14151
14152          case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
14153             {
14154                drbCfg = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List;
14155
14156                if(extractDrbListToSetupMod(drbCfg, NULL, NULL, drbCfg->list.count, &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULLP))
14157                {
14158                   DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod()");
14159                   //TODO: Update the failure cause in ue context Setup Response
14160                   ret = RFAILED;
14161                }
14162                break;
14163             }
14164          case ProtocolIE_ID_id_RRCContainer:
14165             {
14166                /* Filling Dl RRC Msg Info */
14167                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
14168                if(!duUeCb->f1UeDb->dlRrcMsg)
14169                {
14170                   DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for DL RRC Msg in procUeCtxtSetupReq()");
14171                   ret = RFAILED;
14172                }
14173                else
14174                {
14175                   duUeCb->f1UeDb->dlRrcMsgPres = true;
14176                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
14177                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
14178                         &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer);
14179                }          
14180                break;
14181             }
14182
14183          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
14184             {
14185                if(duUeCb->f1UeDb->dlRrcMsg)
14186                {
14187                   if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
14188                   {
14189                      duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
14190                   }
14191                   else
14192                   {
14193                      DU_LOG("\nERROR  -->  Ignoring delivery report, since rrcContainer is not present");
14194                   }
14195                }
14196                break;
14197             }
14198
14199          case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
14200             {
14201                /* MaximumBitRate Uplink */
14202                bitRateSize = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.size;
14203                if(bitRateSize > 0)
14204                {
14205                   DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->duUeCfg.ambrCfg, bitRateSize);
14206                   if(!duUeCb->f1UeDb->duUeCfg.ambrCfg)
14207                   {
14208                      DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for bitRate in procUeCtxtSetupReq");
14209                      ret = RFAILED;
14210                   }
14211                   else
14212                   {
14213                      memset(duUeCb->f1UeDb->duUeCfg.ambrCfg, 0, sizeof(AmbrCfg)); 
14214                      memcpy(&duUeCb->f1UeDb->duUeCfg.ambrCfg->ulBr,
14215                            ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf, bitRateSize);
14216                   }
14217                }
14218                else
14219                   ret = RFAILED;
14220                break;
14221             }
14222
14223          default:
14224             {
14225                break;
14226             }
14227       } /* End of switch */
14228
14229       /* In case of any failure in any IE */
14230       if(ret == RFAILED)
14231       {
14232          // BuildAndSendUeContextSetupRsp(cellId,ueId);
14233          DU_LOG("\nERROR  -->  F1AP: Failed to process UE CNTXT SETUP REQ at procF1UeContextSetupReq()"); 
14234          break;
14235       }
14236    } /* End of for loop of IEs */
14237
14238    if(ret == ROK)
14239       ret = duProcUeContextSetupRequest(duUeCb);
14240
14241    freeAperDecodeF1UeContextSetupReq(ueSetReq); 
14242    return ret;
14243
14244 }
14245 /*******************************************************************
14246  * @brief Free the memory allocated for Dl Tunnel Info
14247  *
14248  * @details
14249  *
14250  *    Function : freeDlTnlInfo
14251  *
14252  *    Functionality:
14253  *       Free the memory allocated for Dl Tunnel Info
14254  *
14255  * @params[in] DLUPTNLInformation_ToBeSetup_List_t *
14256  * @return void
14257  *
14258  * ****************************************************************/
14259
14260 void freeDlTnlInfo(DLUPTNLInformation_ToBeSetup_List_t *tnlInfo)
14261 {
14262    uint8_t arrIdx = 0;
14263
14264    if(tnlInfo)
14265    {
14266       for(arrIdx=0; arrIdx < tnlInfo->list.count; arrIdx++)
14267       {
14268          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf,\
14269                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.size);
14270          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf,\
14271                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.size);
14272          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14273          DU_FREE(tnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14274       }
14275       DU_FREE(tnlInfo->list.array, tnlInfo->list.size);
14276    }
14277 }
14278
14279 /*******************************************************************
14280  * @brief Free the memory allocated for DRB setup List
14281  *
14282  * @details
14283  *
14284  *    Function : freeDrbSetupList
14285  *
14286  *    Functionality:
14287  *       Free the memory allocated for DRB setup list
14288  *
14289  * @params[in] DRBs_Setup_List_t *
14290  * @return void
14291  *
14292  * ****************************************************************/
14293 void freeDrbSetupList(DRBs_Setup_List_t *drbSetupList)
14294 {
14295    uint8_t arrIdx = 0;
14296    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14297
14298    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
14299    {
14300       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14301       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List);
14302       DU_FREE(drbSetupList->list.array[arrIdx],  sizeof(DRBs_Setup_Item_t));
14303    }
14304    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
14305 }
14306
14307 /*******************************************************************
14308  * @brief Free the memory allocated for UE Setup response
14309  *
14310  * @details
14311  *
14312  *    Function : FreeUeContextSetupRsp
14313  *
14314  *    Functionality:
14315  *       Free the memory allocated for UE Setup response
14316  *
14317  * @params[in] F1AP PDU for UE setup response
14318  * @return ROK     - success
14319  *         RFAILED - failure
14320  *
14321  * ****************************************************************/
14322 void FreeUeContextSetupRsp(F1AP_PDU_t *f1apMsg)
14323 {
14324    uint8_t idx;
14325    UEContextSetupResponse_t *ueSetRsp = NULLP;
14326
14327    if(f1apMsg)
14328    {
14329       if(f1apMsg->choice.successfulOutcome)
14330       {
14331          ueSetRsp = &f1apMsg->choice.successfulOutcome->value.choice.\
14332                     UEContextSetupResponse;
14333          if(ueSetRsp->protocolIEs.list.array)
14334          {
14335             for(idx = 0; idx < ueSetRsp->protocolIEs.list.count; idx++)
14336             {
14337                if(ueSetRsp->protocolIEs.list.array[idx])
14338                {
14339                   switch(ueSetRsp->protocolIEs.list.array[idx]->id)
14340                   {
14341                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14342                         break;
14343                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14344                         break;
14345                      case ProtocolIE_ID_id_C_RNTI:
14346                         break;
14347                      case ProtocolIE_ID_id_DUtoCURRCInformation:
14348                         {
14349                            CellGroupConfig_t *cellGrpCfg = NULLP;
14350                            cellGrpCfg  = &ueSetRsp->protocolIEs.list.array[idx]->value.choice.\
14351                                          DUtoCURRCInformation.cellGroupConfig;
14352                            if(cellGrpCfg->buf != NULLP)
14353                            {
14354                               DU_FREE(cellGrpCfg->buf, cellGrpCfg->size);
14355                               cellGrpCfg = NULLP;
14356                            }
14357                            break;
14358                         }
14359                      case ProtocolIE_ID_id_DRBs_Setup_List:
14360                         {
14361                            freeDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List); 
14362                            break;
14363                         }
14364                      default:
14365                         DU_LOG("\nERROR  -->  DUAPP: Invalid Id %ld at FreeUeContextSetupRsp()",\
14366                               ueSetRsp->protocolIEs.list.array[idx]->id);
14367                         break;
14368                   }
14369                   DU_FREE(ueSetRsp->protocolIEs.list.array[idx],\
14370                         sizeof(UEContextSetupResponseIEs_t));
14371                }
14372             }
14373             DU_FREE(ueSetRsp->protocolIEs.list.array, \
14374                   ueSetRsp->protocolIEs.list.size);
14375          }
14376          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14377       }
14378       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14379    }
14380 }
14381
14382 /*******************************************************************
14383  *
14384  * @brief Builds Ue context Setup Rsp DU To CU Info
14385  *
14386  * @details
14387  *
14388  *    Function : EncodeUeCntxtDuToCuInfo
14389  *
14390  *    Functionality: Builds Ue context Setup Rsp DU To CU Info
14391  *
14392  * @params[in] CellGroupConfig_t *, CellGroupConfigRrc_t * 
14393  *
14394  * @return ROK     - success
14395  *         RFAILED - failure
14396  *
14397  ******************************************************************/
14398
14399 uint8_t EncodeUeCntxtDuToCuInfo(CellGroupConfig_t *duToCuCellGrp, CellGroupConfigRrc_t *duCellGrpCfg)
14400 {
14401    asn_enc_rval_t        encRetVal;
14402
14403    xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, duCellGrpCfg);
14404    memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14405    encBufSize = 0;
14406    encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, duCellGrpCfg, PrepFinalEncBuf, encBuf);
14407    /* Encode results */
14408    if(encRetVal.encoded == ENCODE_FAIL)
14409    {
14410       DU_LOG( "\nERROR  -->  F1AP : Could not encode UeCntxtDuToCuInfo (at %s)\n",\
14411             encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14412       return RFAILED;
14413    }
14414    else
14415    {
14416       DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UeCntxtDuToCuInfo\n");
14417 #ifdef DEBUG_ASN_PRINT
14418       for(int i=0; i< encBufSize; i++)
14419       {
14420          printf("%x",encBuf[i]);
14421       }
14422 #endif
14423    }
14424    duToCuCellGrp->size = encBufSize;
14425    DU_ALLOC(duToCuCellGrp->buf, duToCuCellGrp->size);
14426    if(!duToCuCellGrp->buf)
14427    {
14428       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in UeCntxtDuToCuInfo");
14429    }
14430    memcpy(duToCuCellGrp->buf, encBuf, duToCuCellGrp->size);
14431    return ROK;
14432 }
14433
14434 /*******************************************************************
14435  *
14436  * @brief Fills Dl Gtp tunnel Info
14437  *
14438  * @details
14439  *
14440  *    Function : fillGtpTunnelforDl
14441  *
14442  *    Functionality: Fills Dl Gtp tunnel Info
14443  *
14444  * @params[in] 
14445  *
14446  * @return ROK     - success
14447  *         RFAILED - failure
14448  *
14449  * ****************************************************************/
14450
14451 uint8_t fillGtpTunnelforDl(GTPTunnel_t *gtpDl, GtpTnlCfg *gtpUeCfg)
14452 {
14453    uint8_t bufSize = 0;
14454
14455    gtpDl->transportLayerAddress.size    = 4*sizeof(uint8_t);
14456    DU_ALLOC(gtpDl->transportLayerAddress.buf, gtpDl->transportLayerAddress.size);
14457    if(gtpDl->transportLayerAddress.buf == NULLP)
14458    {
14459       return RFAILED;
14460    }
14461    memcpy(gtpDl->transportLayerAddress.buf, &gtpUeCfg->dlTnlAddress, gtpDl->transportLayerAddress.size);
14462
14463    /*GTP TEID*/
14464    gtpDl->gTP_TEID.size = 4 * sizeof(uint8_t);
14465    DU_ALLOC(gtpDl->gTP_TEID.buf, gtpDl->gTP_TEID.size);
14466    if(gtpDl->gTP_TEID.buf == NULLP)
14467    {
14468       return RFAILED;
14469    }
14470    bufSize = 3; /*forming an Octect String*/
14471    fillTeIdString(bufSize, gtpUeCfg->teId, gtpDl->gTP_TEID.buf);
14472
14473    return ROK;
14474 }
14475
14476 /*******************************************************************
14477  *
14478  * @brief Fills DL Tunnel Setup List
14479  *
14480  * @details
14481  *
14482  *    Function : fillDlTnlSetupList
14483  *
14484  *    Functionality: Fills the DL Tunnel Setup List
14485  *
14486  * @params[in] 
14487  *
14488  * @return ROK     - success
14489  *         RFAILED - failure
14490  *
14491  * ****************************************************************/
14492
14493 uint8_t fillDlTnlSetupList(DLUPTNLInformation_ToBeSetup_List_t *dlTnlInfo, UpTnlCfg *tnlCfg)
14494 {
14495    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14496
14497    eleCount = 1;
14498    dlTnlInfo->list.count = eleCount; 
14499    dlTnlInfo->list.size = (eleCount * sizeof(DLUPTNLInformation_ToBeSetup_Item_t *));
14500
14501    /* Initialize the DL Tnl Setup List Members */
14502    DU_ALLOC(dlTnlInfo->list.array, dlTnlInfo->list.size);
14503    if(dlTnlInfo->list.array == NULLP)
14504    {
14505       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL Tnl Setup List in fillDlTnlSetupList()");
14506       ret = RFAILED;
14507    }
14508    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14509    {
14510       DU_ALLOC(dlTnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14511       if(dlTnlInfo->list.array[arrIdx] == NULLP)
14512       {
14513          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDlTnlSetupList()", arrIdx);
14514          return RFAILED;
14515       }
14516       dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.present = UPTransportLayerInformation_PR_gTPTunnel;
14517       DU_ALLOC(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14518       if(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel == NULLP)
14519       {
14520          DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL tunnel info in fillDlTnlSetupList()");
14521          return RFAILED;
14522       }
14523       ret = fillGtpTunnelforDl(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel,\
14524                tnlCfg->tnlCfg1);
14525       if(ret != ROK)
14526          break;
14527    }
14528    return ret;
14529 }
14530
14531 /*******************************************************************
14532  *
14533  * @brief Fills the Drb Setup List for Ue Context Setup Response
14534  *
14535  * @details
14536  *
14537  *    Function : fillDrbSetupList
14538  *
14539  *    Functionality: Fills the Drb Setup List for Ue Context Setup Response
14540  *
14541  * @params[in] 
14542  *
14543  * @return ROK     - success
14544  *         RFAILED - failure
14545  *
14546  * ****************************************************************/
14547 uint8_t fillDrbSetupList(DRBs_Setup_List_t *drbSetupList, DuUeCfg *ueCfg)
14548 {
14549    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14550    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14551
14552    eleCount = ueCfg->numDrb;
14553    drbSetupList->list.count = eleCount;
14554    drbSetupList->list.size = \
14555         (eleCount * sizeof(DRBs_Setup_Item_t *));
14556
14557    /* Initialize the Drb Setup List Members */
14558    DU_ALLOC(drbSetupList->list.array, drbSetupList->list.size);
14559    if(drbSetupList->list.array == NULLP)
14560    {
14561       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DRB Setup List in fillDrbSetupList()");
14562       ret = RFAILED;
14563    }
14564
14565    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14566    {
14567       DU_ALLOC(drbSetupList->list.array[arrIdx], sizeof(DRBs_Setup_Item_t));
14568       if(drbSetupList->list.array[arrIdx] == NULLP)
14569       {
14570          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDrbSetupList()", arrIdx);
14571          return RFAILED;
14572       }
14573       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14574       drbItemIe->id = ProtocolIE_ID_id_DRBs_Setup_Item;
14575       drbItemIe->criticality = Criticality_reject;
14576       drbItemIe->value.present = DRBs_Setup_ItemIEs__value_PR_DRBs_Setup_Item;
14577       drbItemIe->value.choice.DRBs_Setup_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
14578       ret = fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List,\
14579           &ueCfg->upTnlInfo[arrIdx]);
14580       if(ret != ROK)
14581          break;
14582    }
14583    return ret;
14584 }
14585
14586 /*******************************************************************
14587  *
14588  * @brief Builds and sends the UE Setup Response
14589  *
14590  * @details
14591  *
14592  *    Function : BuildAndSendUeContextSetupRsp
14593  *
14594  *    Functionality: Constructs the UE Setup Response and sends
14595  *                   it to the DU through SCTP.
14596  *
14597  * @params[in] uint8_t cellId,uint8_t ueId
14598  *
14599  * @return ROK     - success
14600  *         RFAILED - failure
14601  *
14602  * ****************************************************************/
14603 uint8_t BuildAndSendUeContextSetupRsp(uint8_t cellId,uint8_t ueId)
14604 {
14605    uint8_t   idx, ret, cellIdx, elementCnt;
14606    uint32_t  gnbCuUeF1apId;   /* gNB-CU UE F1AP Id */
14607    uint32_t  gnbDuUeF1apId;   /* gNB-DU UE F1AP Id */
14608    asn_enc_rval_t  encRetVal;        /* Encoder return value */
14609    F1AP_PDU_t               *f1apMsg = NULLP;
14610    UEContextSetupResponse_t *ueSetRsp = NULLP;
14611    DuUeCb                   *ueCb = NULLP;
14612
14613    DU_LOG("\n INFO   -->  F1AP : Building UE Context Setup Response for cellId %d, ueId %d\n", cellId, ueId);
14614
14615    while(true)
14616    {
14617       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14618       if(f1apMsg == NULLP)
14619       {
14620          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14621          ret = RFAILED;
14622          break;
14623       }
14624
14625       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
14626       DU_ALLOC(f1apMsg->choice.successfulOutcome,
14627             sizeof(SuccessfulOutcome_t));
14628       if(f1apMsg->choice.successfulOutcome == NULLP)
14629       {
14630          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
14631          ret = RFAILED;
14632          break;
14633       }
14634
14635       f1apMsg->choice.successfulOutcome->procedureCode = \
14636                                                          ProcedureCode_id_UEContextSetup;
14637       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
14638       f1apMsg->choice.successfulOutcome->value.present = \
14639                                                          SuccessfulOutcome__value_PR_UEContextSetupResponse;
14640
14641       ueSetRsp =
14642          &f1apMsg->choice.successfulOutcome->value.choice.UEContextSetupResponse;
14643       elementCnt = 5;
14644       ueSetRsp->protocolIEs.list.count = elementCnt;
14645       ueSetRsp->protocolIEs.list.size = \
14646                                         elementCnt * sizeof(UEContextSetupResponse_t *);
14647
14648       /* Initialize the UESetup members */
14649       DU_ALLOC(ueSetRsp->protocolIEs.list.array, \
14650             ueSetRsp->protocolIEs.list.size);
14651       if(ueSetRsp->protocolIEs.list.array == NULLP)
14652       {
14653          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14654          ret = RFAILED;
14655          break;
14656       }
14657
14658       for(idx=0; idx<elementCnt; idx++)
14659       {
14660          DU_ALLOC(ueSetRsp->protocolIEs.list.array[idx],\
14661                sizeof(UEContextSetupResponseIEs_t));
14662          if(ueSetRsp->protocolIEs.list.array[idx] == NULLP)
14663          {
14664             DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14665             ret = RFAILED;
14666             break;
14667          }
14668       }
14669       /* Fetching Ue Cb Info*/
14670       GET_CELL_IDX(cellId, cellIdx);
14671       gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
14672       gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
14673       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
14674
14675       idx = 0;
14676       /*GNB CU UE F1AP ID*/
14677       ueSetRsp->protocolIEs.list.array[idx]->id = \
14678                                                   ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
14679       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14680       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14681                                                              UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
14682       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
14683
14684       /*GNB DU UE F1AP ID*/
14685       idx++;
14686       ueSetRsp->protocolIEs.list.array[idx]->id = \
14687                                                   ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14688       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14689       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14690                                                              UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
14691       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
14692
14693
14694       /*DUtoCURRC Information */
14695       idx++;
14696       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14697                                                    ProtocolIE_ID_id_DUtoCURRCInformation;
14698       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14699       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14700                                                             UEContextSetupResponseIEs__value_PR_DUtoCURRCInformation;
14701       BuildCellGroupConfigRrc(ueCb, &ueSetRsp->protocolIEs.list.array[idx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
14702
14703       /* CRNTI */
14704       idx++;
14705       ueSetRsp->protocolIEs.list.array[idx]->id  = ProtocolIE_ID_id_C_RNTI;
14706       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14707       ueSetRsp->protocolIEs.list.array[idx]->value.present = UEContextSetupResponseIEs__value_PR_C_RNTI;
14708       ueSetRsp->protocolIEs.list.array[idx]->value.choice.C_RNTI = ueCb->crnti; 
14709
14710
14711       /* Drb Setup List */
14712       idx++;
14713       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14714                                                    ProtocolIE_ID_id_DRBs_Setup_List;
14715       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14716       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14717                                                             UEContextSetupResponseIEs__value_PR_DRBs_Setup_List;
14718       ret = fillDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List,\
14719             &ueCb->f1UeDb->duUeCfg);
14720       if(ret == RFAILED)
14721       {
14722          DU_LOG("\nERROR  -->  F1AP : Failed to fillDrbSetupList in BuildAndSendUeContextSetupRsp()");
14723          freeF1UeDb(ueCb->f1UeDb);
14724          ueCb->f1UeDb = NULLP;
14725          break;
14726       }
14727
14728       /* Free UeContext Db created during Ue context Req */
14729       freeF1UeDb(ueCb->f1UeDb);
14730       ueCb->f1UeDb = NULLP;
14731
14732       /* TODO: To send Drb list */
14733       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14734
14735       /* Encode the UE context setup response type as APER */
14736       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14737       encBufSize = 0;
14738       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14739             encBuf);
14740       /* Encode results */
14741       if(encRetVal.encoded == ENCODE_FAIL)
14742       {
14743          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Response structure (at %s)\n",\
14744                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14745          ret = RFAILED;
14746          break;
14747       }
14748       else
14749       {
14750          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Setup Response\n");
14751 #ifdef DEBUG_ASN_PRINT
14752          for(int i=0; i< encBufSize; i++)
14753          {
14754             printf("%x",encBuf[i]);
14755          }
14756 #endif
14757       }
14758
14759       /* Sending  msg  */
14760       if(sendF1APMsg()  != ROK)
14761       {
14762          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Response failed");
14763          ret = RFAILED;
14764          break;
14765       }
14766       break;
14767    }
14768    FreeUeContextSetupRsp(f1apMsg);
14769    return ret;
14770 }/* End of BuildAndSendUeContextSetupRsp */
14771
14772 /*******************************************************************
14773 *
14774 * @brief  Build And Send Ue Context Rsp 
14775 *
14776 * @details
14777 *
14778 *    Function : BuildAndSendUeCtxtRsp 
14779 *
14780 *    Functionality : Build And Send Ue Context Rsp
14781
14782 * @params[in]
14783 * @return sucess = ROK
14784 *         failure = RFAILED
14785 *
14786 * ****************************************************************/
14787 uint8_t BuildAndSendUeCtxtRsp(uint8_t cellId, uint8_t ueId)
14788 {
14789    uint8_t cellIdx = 0, actionType = 0; 
14790
14791    GET_CELL_IDX(cellId, cellIdx);
14792    actionType = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].f1UeDb->actionType;
14793
14794    switch(actionType)
14795    {
14796       case UE_CTXT_SETUP:
14797          {
14798             if((BuildAndSendUeContextSetupRsp(cellId,ueId)) != ROK)
14799             {
14800                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextSetupRsp()");
14801                return RFAILED;
14802             }
14803             break;
14804          }
14805       case UE_CTXT_MOD:
14806          {
14807             if((BuildAndSendUeContextModRsp(&duCb.actvCellLst[cellIdx]->ueCb[ueId-1])) != ROK)
14808             {
14809                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextModRsp");
14810                return RFAILED;
14811             }
14812             break;
14813          }
14814       default:
14815          DU_LOG("ERROR  -->  F1AP: Invalid Action Type %d at BuildAndSendUeCtxtRsp()", actionType);
14816          break;
14817
14818    }
14819    return ROK;
14820 }
14821
14822 /*******************************************************************
14823  *
14824  * @brief deallocating the memory of  F1reset msg
14825  *
14826  * @details
14827  *
14828  *    Function : FreeF1ResetReq
14829  *
14830  *    Functionality :
14831  *         - freeing memory of F1reset request msg
14832  *
14833  * @params[in]
14834  * @return void
14835  *
14836  *
14837  * ****************************************************************/
14838 void FreeF1ResetReq(F1AP_PDU_t *f1apMsg)
14839 {
14840    uint8_t idx =0 ;
14841    Reset_t *f1ResetMsg;
14842
14843    if(f1apMsg)
14844    {
14845       if(f1apMsg->choice.initiatingMessage)
14846       {
14847          f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14848
14849          if(f1ResetMsg->protocolIEs.list.array)
14850          {
14851             for(idx=0 ;idx < f1ResetMsg->protocolIEs.list.count ; idx++)
14852             {
14853                if(f1ResetMsg->protocolIEs.list.array[idx])
14854                {
14855                   DU_FREE(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14856                }
14857             }
14858             DU_FREE(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14859          }
14860          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14861       }
14862       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14863    }
14864 }
14865 /*******************************************************************
14866  *
14867  * @brief Build and Send F1reset request 
14868  *
14869  * @details
14870  *
14871  *    Function : BuildAndSendF1ResetReq
14872  *
14873  *    Functionality:
14874  *         - Build and Send F1reset request msg
14875  *
14876  * @params[in]
14877  * @return ROK     - success
14878  *         RFAILED - failure
14879  *
14880  * ****************************************************************/
14881 uint8_t BuildAndSendF1ResetReq()
14882 {
14883    uint8_t          elementCnt=0;
14884    uint8_t          idx=0;
14885    uint8_t          ret= RFAILED;
14886    Reset_t          *f1ResetMsg = NULLP;
14887    F1AP_PDU_t       *f1apMsg = NULLP;
14888    asn_enc_rval_t   encRetVal;
14889    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset request \n");
14890    do
14891    {
14892       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14893       if(f1apMsg == NULLP)
14894       {
14895          break;
14896       }
14897       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
14898       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14899       if(f1apMsg->choice.initiatingMessage == NULLP)
14900       {
14901          break;
14902       }
14903       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_Reset;
14904       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
14905       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_Reset;
14906
14907       f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14908
14909       elementCnt = 3;
14910       f1ResetMsg->protocolIEs.list.count = elementCnt;
14911       f1ResetMsg->protocolIEs.list.size = elementCnt * sizeof(ResetIEs_t *);
14912
14913       /* Initialize the F1Setup members */
14914       DU_ALLOC(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14915       if(f1ResetMsg->protocolIEs.list.array == NULLP)
14916       {
14917          break;
14918       }
14919       for(idx=0; idx<elementCnt; idx++)
14920       {
14921          DU_ALLOC(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14922          if(f1ResetMsg->protocolIEs.list.array[idx] == NULLP)
14923          {
14924             break;
14925          }
14926       }
14927
14928       /*TransactionID*/
14929       idx=0;
14930       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
14931       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14932       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_TransactionID;
14933       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.TransactionID = 1;
14934
14935       /*Cause*/
14936       idx++;
14937       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_Cause;
14938       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_ignore;
14939       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_Cause;
14940       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.present = Cause_PR_radioNetwork;
14941       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.choice.radioNetwork = CauseRadioNetwork_action_desirable_for_radio_reasons;
14942
14943       /*Reset Type*/
14944       idx++;
14945       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_ResetType;
14946       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14947       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_ResetType;
14948       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.present = ResetType_PR_f1_Interface;
14949       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.choice.f1_Interface = ResetAll_reset_all;
14950
14951       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14952
14953       /* Encode the F1SetupRequest type as APER */
14954       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14955       encBufSize = 0;
14956       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14957             encBuf);
14958
14959       /* Encode results */
14960       if(encRetVal.encoded == ENCODE_FAIL)
14961       {
14962          DU_LOG("\nERROR  -->  F1AP : Could not encode F1Reset structure (at %s)\n",\
14963                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14964          break;
14965       }
14966       else
14967       {
14968          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1Reset\n");
14969 #ifdef DEBUG_ASN_PRINT
14970          for(idx=0; idx< encBufSize; idx++)
14971          {
14972             printf("%x",encBuf[idx]);
14973          }
14974 #endif
14975       }
14976
14977       if(sendF1APMsg() != ROK)
14978       {
14979          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset request failed");
14980          break;
14981       }
14982
14983       ret = ROK;
14984       break;
14985    }while(true);
14986
14987    FreeF1ResetReq(f1apMsg);
14988    return ret;
14989 }
14990 /*******************************************************************
14991  *
14992  * @brief Build And Send F1ResetAck
14993  *
14994  * @details
14995  *
14996  *    Function : BuildAndSendF1ResetAck
14997  *
14998  *    Functionality:
14999  *         - Build And Send  F1ResetRSP
15000  *
15001  * @return ROK     - success
15002  *         RFAILED - failure
15003  *
15004  * ****************************************************************/
15005 void FreeF1ResetAck(F1AP_PDU_t *f1apMsg)
15006 {
15007    uint8_t idx;
15008    ResetAcknowledge_t *f1ResetAck;
15009
15010    if(f1apMsg)
15011    {
15012       if(f1apMsg->choice.successfulOutcome)
15013       {
15014          f1ResetAck= &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
15015
15016          if(f1ResetAck->protocolIEs.list.array)
15017          {
15018             for(idx=0; idx<f1ResetAck->protocolIEs.list.count ; idx++)
15019             {
15020                if(f1ResetAck->protocolIEs.list.array[idx])
15021                {
15022                   DU_FREE(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
15023                }
15024             }
15025             DU_FREE(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
15026          }
15027          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
15028       }
15029       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
15030    }
15031 }
15032
15033 /*******************************************************************
15034  *
15035  * @brief Build And Send F1ResetAck
15036  *
15037  * @details
15038  *
15039  *    Function : BuildAndSendF1ResetAck
15040  *
15041  *    Functionality:
15042  *         - Build And Send  F1ResetRSP
15043  *
15044  *  @params[in]
15045  * @return ROK     - success
15046  *         RFAILED - failure
15047  *
15048  * ****************************************************************/
15049 uint8_t BuildAndSendF1ResetAck()
15050 {
15051    uint8_t                idx = 0;
15052    uint8_t                elementCnt = 0;
15053    uint8_t                ret = RFAILED;
15054    F1AP_PDU_t             *f1apMsg = NULL;
15055    ResetAcknowledge_t     *f1ResetAck = NULLP;
15056    asn_enc_rval_t         encRetVal;
15057    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset Acknowledgment \n");
15058
15059    do{
15060       /* Allocate the memory for F1ResetRequest_t */
15061       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15062       if(f1apMsg == NULLP)
15063       {
15064          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
15065          break;
15066       }
15067
15068       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
15069
15070       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
15071       if(f1apMsg->choice.successfulOutcome == NULLP)
15072       {
15073          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
15074          break;
15075       }
15076       f1apMsg->choice.successfulOutcome->criticality   = Criticality_reject;
15077       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetAcknowledge;
15078       f1ResetAck = &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
15079
15080       elementCnt = 1;
15081
15082       f1ResetAck->protocolIEs.list.count = elementCnt;
15083       f1ResetAck->protocolIEs.list.size = elementCnt*sizeof(ResetAcknowledgeIEs_t *);
15084
15085       DU_ALLOC(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
15086       if(f1ResetAck->protocolIEs.list.array == NULLP)
15087       {
15088          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1ResetAckIEs failed");
15089          break;
15090       }
15091
15092       for(idx=0; idx<elementCnt; idx++)
15093       {
15094          DU_ALLOC(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
15095          if(f1ResetAck->protocolIEs.list.array[idx] == NULLP)
15096          {
15097             break;
15098          }
15099       }
15100       /*TransactionID*/
15101       idx = 0;
15102       f1ResetAck->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
15103       f1ResetAck->protocolIEs.list.array[idx]->criticality = Criticality_reject;
15104       f1ResetAck->protocolIEs.list.array[idx]->value.present = ResetAcknowledgeIEs__value_PR_TransactionID;
15105       f1ResetAck->protocolIEs.list.array[idx]->value.choice.TransactionID = TRANS_ID;
15106
15107       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15108
15109       /* Encode the F1SetupRequest type as UPER */
15110       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15111       encBufSize = 0;
15112       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
15113
15114       /* Check encode results */
15115       if(encRetVal.encoded == ENCODE_FAIL)
15116       {
15117          DU_LOG("\nERROR  -->  F1AP : Could not encode F1ResetAck structure (at %s)\n",\
15118                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15119          break;
15120       }
15121       else
15122       {
15123          DU_LOG("\nDUBUG   -->  F1AP : Created APER encoded buffer for F1ResetAck\n");
15124 #ifdef DEBUG_ASN_PRINT
15125          for(int i=0; i< encBufSize; i++)
15126          {
15127             printf("%x",encBuf[i]);
15128          }
15129 #endif
15130       }
15131       /* Sending msg */
15132       if(sendF1APMsg() != ROK)
15133       {
15134          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset Acknowledgement failed");
15135          break;
15136       }
15137
15138       ret = ROK;
15139       break;
15140    }while(true);
15141
15142    FreeF1ResetAck(f1apMsg);
15143    return ret;
15144 }
15145 /******************************************************************
15146 *
15147 * @brief free F1 reset msg allocated by aper_decoder 
15148 *
15149 * @details
15150 *
15151 *    Function : freeAperDecodeF1ResetMsg 
15152 *
15153 *    Functionality: free F1 reset msg allocated by aper_decoder 
15154 *
15155 * @params[in] Reset_t *f1ResetMsg 
15156 * @return void 
15157 *
15158 * ****************************************************************/
15159
15160 void freeAperDecodeF1ResetMsg(Reset_t *f1ResetMsg)
15161 {
15162    uint8_t ieIdx =0;
15163    if(f1ResetMsg->protocolIEs.list.array)
15164    {
15165       for(ieIdx=0 ;ieIdx < f1ResetMsg->protocolIEs.list.count ; ieIdx++)
15166       {
15167          if(f1ResetMsg->protocolIEs.list.array[ieIdx])
15168          {
15169             free(f1ResetMsg->protocolIEs.list.array[ieIdx]);
15170          }
15171       }
15172       free(f1ResetMsg->protocolIEs.list.array);
15173    }
15174 }
15175
15176 /******************************************************************
15177  *
15178  * @brief Processes DL RRC Message Transfer  sent by CU
15179  *
15180  * @details
15181  *
15182  *    Function : procF1ResetReq
15183  *
15184  *    Functionality: Processes DL RRC Message Transfer sent by CU
15185  *
15186  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15187  * @return ROK     - success
15188  *         RFAILED - failure
15189  *
15190  * ****************************************************************/
15191 uint8_t procF1ResetReq(F1AP_PDU_t *f1apMsg)
15192 {
15193    /* we are currently not supporting Ue release. right now we are supporting only init case of fireset */
15194    uint8_t       ieIdx = 0;
15195    uint8_t        ret = ROK;
15196    Reset_t       *f1ResetMsg = NULLP;
15197
15198    DU_LOG("\nINFO   -->  Processing F1 reset request");
15199    f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
15200
15201    for(ieIdx=0; ieIdx<f1ResetMsg->protocolIEs.list.count; ieIdx++)
15202    {
15203       switch(f1ResetMsg->protocolIEs.list.array[ieIdx]->id)
15204       {
15205          case ProtocolIE_ID_id_TransactionID:
15206             break;
15207
15208          case ProtocolIE_ID_id_Cause:
15209             break;
15210
15211          case ProtocolIE_ID_id_ResetType:
15212             {
15213                break;
15214             }
15215
15216          default:
15217             break;
15218       }
15219    }
15220    ret = BuildAndSendF1ResetAck();
15221    DU_LOG("\nINFO   -->  UE release is not supported for now");
15222
15223    freeAperDecodeF1ResetMsg(f1ResetMsg);
15224
15225    return ret;
15226 }
15227
15228 /*******************************************************************
15229  *
15230  * @brief free the RRC delivery report
15231  *
15232  * @details
15233  *
15234  *    Function : freeRrcDeliveryReport
15235  *
15236  *    Functionality: free the RRC delivery report
15237  *
15238  * @params[in]
15239  * @return ROK     - success
15240  *         RFAILED - failure
15241  *
15242  * ****************************************************************/
15243 void freeRrcDeliveryReport(F1AP_PDU_t  *f1apMsg )
15244 {
15245    uint8_t idx=0;
15246    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
15247
15248    if(f1apMsg)
15249    {
15250       if(f1apMsg->choice.initiatingMessage)
15251       {
15252          rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
15253          if(rrcDeliveryReport->protocolIEs.list.array)
15254          {
15255             for(idx =0 ;idx <rrcDeliveryReport->protocolIEs.list.count ;
15256                   idx++)
15257             {
15258                if(rrcDeliveryReport->protocolIEs.list.array[idx])
15259                {
15260                   DU_FREE(rrcDeliveryReport->protocolIEs.list.array[idx],
15261                         sizeof(RRCDeliveryReportIEs_t));
15262                }   
15263             }
15264             DU_FREE(rrcDeliveryReport->protocolIEs.list.array,
15265                   rrcDeliveryReport->protocolIEs.list.size);
15266          }
15267          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
15268       }
15269       DU_FREE(f1apMsg,
15270             sizeof(F1AP_PDU_t));
15271    }
15272 }
15273
15274 /*******************************************************************
15275 *
15276 * @brief Builds and sends the RRC delivery report
15277 *
15278 * @details
15279 *
15280 *    Function : BuildAndSendRrcDeliveryReport
15281 *
15282 *    Functionality: Builds and sends the RRC delivery report
15283 *
15284 * @params[in]
15285 *
15286 * @return ROK     - success
15287 *         RFAILED - failure
15288 *
15289 * ****************************************************************/
15290 uint8_t BuildAndSendRrcDeliveryReport(uint32_t gnbCuUeF1apId, \
15291    uint32_t gnbDuUeF1apId, RrcDeliveryReport *rrcDelivery)
15292 {
15293    uint8_t             ret = RFAILED;
15294    uint8_t             idx    = 0;
15295    uint8_t             idx1   = 0;
15296    uint8_t             elementCnt = 0;
15297    F1AP_PDU_t          *f1apMsg = NULLP;
15298    asn_enc_rval_t      encRetVal;  
15299    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
15300
15301    do{
15302
15303       DU_LOG("\nINFO   -->  F1AP : Building RRC delivery Message Transfer Message\n");
15304       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15305       if(f1apMsg == NULLP)
15306       {
15307          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
15308          break;
15309       }
15310       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
15311       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
15312       if(f1apMsg->choice.initiatingMessage == NULLP)
15313       {
15314          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU  failed");
15315          break;
15316       }
15317       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_RRCDeliveryReport;
15318       f1apMsg->choice.initiatingMessage->criticality   = Criticality_ignore;
15319       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_RRCDeliveryReport;
15320
15321       rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
15322       elementCnt = 4;
15323       rrcDeliveryReport->protocolIEs.list.count = elementCnt;
15324       rrcDeliveryReport->protocolIEs.list.size = elementCnt * sizeof(RRCDeliveryReportIEs_t *);
15325
15326       /* Initialize the F1Setup members */
15327       DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array, rrcDeliveryReport->protocolIEs.list.size);
15328       if(rrcDeliveryReport->protocolIEs.list.array == NULLP)
15329       {
15330          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRC Delivery  failed");
15331          break;
15332       }
15333       for(idx =0 ;idx <elementCnt; idx++)
15334       {
15335          DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array[idx], sizeof(RRCDeliveryReportIEs_t));
15336          if(rrcDeliveryReport->protocolIEs.list.array[idx] == NULLP)
15337          {
15338             break;
15339          }
15340       }
15341
15342       idx1 = 0;
15343
15344       /*GNB CU UE F1AP ID*/
15345       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
15346       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15347       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_CU_UE_F1AP_ID;
15348       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
15349
15350       /*GNB DU UE F1AP ID*/
15351       idx1++;
15352       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
15353       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15354       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_DU_UE_F1AP_ID;
15355       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
15356
15357       /*RRC delivery status*/
15358       idx1++;
15359       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_RRCDeliveryStatus;
15360       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15361       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_RRCDeliveryStatus;
15362       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.delivery_status =\
15363       rrcDelivery->rrcDeliveryStatus.deliveryStatus;
15364       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.triggering_message =\
15365       rrcDelivery->rrcDeliveryStatus.triggeringMessage;
15366
15367       /* SRB ID */ 
15368       idx1++;
15369       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
15370       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15371       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_SRBID;
15372       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.SRBID =  rrcDelivery->srbId;
15373
15374       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15375
15376       /* Encode the RRC DELIVERY REPORT type as APER */
15377       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15378       encBufSize = 0;
15379       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
15380             encBuf);
15381
15382       /* Encode results */
15383       if(encRetVal.encoded == ENCODE_FAIL)
15384       {
15385          DU_LOG("\nERROR  -->  F1AP : Could not encode RRC Delivery Msg structure (at %s)\n",\
15386                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15387          break;
15388       }
15389       else
15390       {
15391          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for RRC Delivery Msg \n");
15392 #ifdef DEBUG_ASN_PRINT
15393          for(idx=0; idx< encBufSize; idx++)
15394          {
15395             printf("%x",encBuf[idx]);
15396          }
15397 #endif
15398       }
15399
15400       /* Sending msg */
15401       if(sendF1APMsg() != ROK)
15402       {
15403          DU_LOG("\nERROR  -->  F1AP : Sending RRC delivery  msg request failed");
15404          break;
15405       }
15406       ret = ROK;
15407       break;
15408
15409    }while(true);
15410
15411    freeRrcDeliveryReport(f1apMsg);
15412    return ret;
15413 }
15414
15415 /*******************************************************************
15416  *
15417  * @brief Processes cells to be activated
15418  *
15419  * @details
15420  *
15421  *    Function : extractCellsToBeActivated
15422  *
15423  *    Functionality:
15424  *      - Processes cells to be activated list received in F1SetupRsp
15425  *
15426  * @params[in] void
15427  * @return ROK     - success
15428  *         RFAILED - failure
15429  *
15430  * ****************************************************************/
15431
15432 uint8_t extractCellsToBeActivated(Cells_to_be_Activated_List_t cellsToActivate)
15433 {
15434    uint8_t  ret = ROK;
15435    uint16_t idx, pci = 0;
15436    uint64_t nci;
15437    Cells_to_be_Activated_List_Item_t cell;
15438
15439    for(idx=0; idx<cellsToActivate.list.count; idx++)
15440    {
15441       nci = 0;
15442       cell = cellsToActivate.list.array[idx]->value.choice.Cells_to_be_Activated_List_Item;
15443       bitStringToInt(&cell.nRCGI.nRCellIdentity, &nci);
15444
15445       if(cell.nRPCI)
15446       {
15447          pci = *cell.nRPCI;
15448       }
15449       ret = duProcCellsToBeActivated(cell.nRCGI.pLMN_Identity.buf, nci, pci);
15450    }
15451    return ret;
15452 }
15453 /******************************************************************
15454 *
15455 * @brief Processes F1 Setup Response allocated by aper_decoder 
15456 *
15457 * @details
15458 *
15459 *    Function : freeF1SetupRsp 
15460 *
15461 *    Functionality: free F1 Setup Response allocated by aper_decoder 
15462 *
15463 * @params[in] F1SetupResponse_t *f1SetRspMsg 
15464 * @return void 
15465 *
15466 * ****************************************************************/
15467
15468 void freeAperDecodeF1SetupRsp(F1SetupResponse_t *f1SetRspMsg)
15469 {
15470    uint8_t ieIdx =0;
15471    uint8_t arrIdx =0;
15472    Cells_to_be_Activated_List_t *cellToActivate =NULLP;
15473    RRC_Version_t      *rrcVer =NULLP;
15474
15475    if(f1SetRspMsg->protocolIEs.list.array)
15476    {
15477       for(ieIdx=0; ieIdx<f1SetRspMsg->protocolIEs.list.count; ieIdx++)
15478       {
15479          if(f1SetRspMsg->protocolIEs.list.array[ieIdx])
15480          {
15481             switch(f1SetRspMsg->protocolIEs.list.array[ieIdx]->id)
15482             {
15483                case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15484                   {
15485                      cellToActivate =
15486                         &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.Cells_to_be_Activated_List;
15487                      if(cellToActivate->list.array)
15488                      {
15489                         for(arrIdx=0; arrIdx<cellToActivate->list.count ; arrIdx++)
15490                         {
15491                            if(cellToActivate->list.array[arrIdx])
15492                            {
15493
15494                               if(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.nRCGI.\
15495                               pLMN_Identity.buf)
15496                               {
15497                                  if(cellToActivate->list.array[0]->value.choice.\
15498                                        Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf)
15499                                  {
15500                                     free(cellToActivate->list.array[0]->value.choice.\
15501                                           Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf);
15502                                  }
15503
15504                                  free(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
15505                                        nRCGI.pLMN_Identity.buf);
15506                               }
15507                               free(cellToActivate->list.array[arrIdx]);
15508                            }
15509                         }
15510                         free(cellToActivate->list.array);
15511                      }
15512                      break;
15513                   }
15514                case ProtocolIE_ID_id_TransactionID:
15515                   {
15516                      break;
15517                   }
15518                case ProtocolIE_ID_id_gNB_CU_Name:
15519                   {
15520                      free(f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_Name.buf);
15521                      break;
15522                   }
15523                case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15524                   {
15525                      rrcVer = &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
15526                      if(rrcVer->latest_RRC_Version.buf)
15527                      {
15528                         if(rrcVer->iE_Extensions)
15529                         {
15530                            if(rrcVer->iE_Extensions->list.array)
15531                            {
15532                               if(rrcVer->iE_Extensions->list.array[0])
15533                               {
15534                                  if(rrcVer->iE_Extensions->list.\
15535                                        array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf)
15536                                  {
15537                                     free(rrcVer->iE_Extensions->list.\
15538                                           array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf);
15539                                  }
15540                                  free(rrcVer->iE_Extensions->list.array[0]);
15541                               }
15542                               free(rrcVer->iE_Extensions->list.array);
15543                            }
15544                            free(rrcVer->iE_Extensions);
15545                         }
15546                         free(rrcVer->latest_RRC_Version.buf);
15547                      }
15548                      break;
15549
15550                   }
15551                default:
15552                   {
15553                      DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15554                            f1SetRspMsg->protocolIEs.list.array[ieIdx]->id);
15555                   }
15556             }
15557             free(f1SetRspMsg->protocolIEs.list.array[ieIdx]);
15558          }
15559       }
15560       free(f1SetRspMsg->protocolIEs.list.array);
15561    }
15562 }
15563 /******************************************************************
15564  *
15565  * @brief Processes F1 Setup Response sent by CU
15566  *
15567  * @details
15568  *
15569  *    Function : procF1SetupRsp
15570  *
15571  *    Functionality: Processes F1 Setup Response sent by CU
15572  *
15573  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15574  * @return ROK     - success
15575  *         RFAILED - failure
15576  *
15577  * ****************************************************************/
15578 uint8_t procF1SetupRsp(F1AP_PDU_t *f1apMsg, MsgLen recvBufLen, char *recvBuf)
15579 {
15580    uint8_t ret = ROK;
15581    uint16_t idx =0;
15582    F1SetupResponse_t *f1SetRspMsg = NULLP;
15583    GNB_CU_Name_t     *cuName = NULLP;
15584    F1SetupRsp  f1SetRspDb;
15585    RRC_Version_t      *rrcVer =NULLP;
15586    
15587    memset(&f1SetRspDb, 0, sizeof(F1SetupRsp));
15588
15589    DU_LOG("\nINFO   -->  F1AP : F1 Setup Response received");
15590    f1SetRspMsg = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
15591
15592    for(idx=0; idx<f1SetRspMsg->protocolIEs.list.count; idx++)
15593    {
15594       switch(f1SetRspMsg->protocolIEs.list.array[idx]->id)
15595       {
15596          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15597             {
15598                extractCellsToBeActivated(f1SetRspMsg->protocolIEs.list.array[idx]->\
15599                      value.choice.Cells_to_be_Activated_List);
15600                break;
15601             }
15602          case ProtocolIE_ID_id_TransactionID:
15603             {
15604                f1SetRspDb.transId = f1SetRspMsg->protocolIEs.list.array[idx]->\
15605                                     value.choice.TransactionID;
15606                break;
15607             }
15608          case ProtocolIE_ID_id_gNB_CU_Name:
15609             {
15610                cuName = &f1SetRspMsg->protocolIEs.list.array[idx]->\
15611                         value.choice.GNB_CU_Name;
15612                strcpy(f1SetRspDb.cuName, (const char*)cuName->buf);
15613                break;
15614             }
15615          case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15616             {
15617                rrcVer = &f1SetRspMsg->protocolIEs.list.array[idx]->value.choice.RRC_Version;
15618                strcpy(f1SetRspDb.rrcVersion.rrcVer,
15619                      (const char*)rrcVer->latest_RRC_Version.buf);
15620                break;
15621             }
15622          default:
15623             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15624                   f1SetRspMsg->protocolIEs.list.array[idx]->id);
15625       }
15626    }
15627    
15628    duProcF1SetupRsp();
15629    freeAperDecodeF1SetupRsp(f1SetRspMsg);
15630    
15631    addOrModifyE2NodeComponent(E2_NODE_COMPONENT_ADD, false, recvBufLen, recvBuf);
15632
15633    if(BuildAndSendE2SetupReq() != ROK)
15634    {
15635       DU_LOG("\nERROR  -->  F1AP : Failed to build and send E2 setup request ");
15636       return RFAILED;
15637    }
15638    return ret;
15639 }
15640 /*******************************************************************
15641 *
15642 * @brief free GNB DU config update ack
15643 *
15644 * @details
15645 *
15646 *    Function : freeAperDecodeGnbDuAck 
15647 *
15648 *    Functionality: Processes GNB DU config update ack And
15649 *                     added free part for the memory allocated by aper_decoder
15650 *
15651 * @params[in] F1AP_PDU_t ASN decoded F1AP message
15652 * @return ROK     - success
15653 *         RFAILED - failure
15654 *
15655 * ****************************************************************/
15656
15657 void freeAperDecodeGnbDuAck(GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck)
15658 {
15659    uint8_t ieIdx = 0;
15660
15661    if(gnbDuAck->protocolIEs.list.array)
15662    {
15663       for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15664       {
15665          if(gnbDuAck->protocolIEs.list.array[ieIdx])
15666          {
15667             free(gnbDuAck->protocolIEs.list.array[ieIdx]);
15668          }
15669       }
15670       free(gnbDuAck->protocolIEs.list.array);
15671    }
15672 }
15673
15674 /*******************************************************************
15675 *
15676 * @brief Building  result of gnb-du config update ack output
15677 *
15678 * @details
15679 *
15680 *    Function : duProcGnbDuCfgUpdAckMsg 
15681 *
15682 *    Functionality: 
15683 *        Building output of gnb-du config update ack 
15684 *
15685 * @params[in] transId
15686 * @return void
15687 *
15688 * ****************************************************************/
15689
15690 uint8_t duProcGnbDuCfgUpdAckMsg(uint8_t transId)
15691 {
15692    uint8_t  ieIdx=0, arrIdx=0,ret=ROK;
15693    uint8_t  ueId =0 , ueIdx =0, totalActiveUe = 0;
15694    uint16_t cellIdx =0, crnti=0;
15695    uint64_t cellId =0;
15696    CmLList *f1apPduNode = NULLP;
15697    ReservedF1apPduInfo *f1apPduInfo =NULLP;
15698    F1AP_PDU_t *f1apMsgPdu = NULLP;
15699    GNBDUConfigurationUpdate_t *gnbDuConfigUpdate = NULLP;
15700    BIT_STRING_t *cellIdentity=NULLP;
15701    struct Served_Cells_To_Delete_ItemIEs *deleteItemIe=NULLP;
15702    Served_Cells_To_Delete_List_t *cellsToDelete=NULLP;
15703    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
15704
15705    DU_LOG("\nINFO   -->  DU APP: GNB-DU config update Ack received ");
15706    f1apPduNode = searchFromReservedF1apPduList(transId);
15707    f1apPduInfo = (ReservedF1apPduInfo *)f1apPduNode->node;
15708    f1apMsgPdu = (F1AP_PDU_t *)f1apPduInfo->f1apMsg;
15709
15710    if(f1apMsgPdu)
15711    {
15712       if(f1apMsgPdu->choice.initiatingMessage)
15713       {
15714          gnbDuConfigUpdate = &f1apMsgPdu->choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
15715          for(ieIdx=0; ieIdx < gnbDuConfigUpdate->protocolIEs.list.count; ieIdx++)
15716          {
15717             switch(gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->id)
15718             {
15719                case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
15720                   {
15721                      cellsToDelete = &gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
15722                                      Served_Cells_To_Delete_List;
15723                      if(cellsToDelete->list.array)
15724                      {
15725                         if(cellsToDelete->list.array[arrIdx])
15726                         {
15727                            deleteItemIe = (Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx];
15728                            deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
15729                            if(deleteItem->oldNRCGI.nRCellIdentity.buf)
15730                            {
15731                               cellIdentity = &deleteItem->oldNRCGI.nRCellIdentity;
15732                               bitStringToInt(cellIdentity, &cellId);
15733
15734                               GET_CELL_IDX(cellId, cellIdx);
15735                               if(duCb.actvCellLst[cellIdx] != NULLP)
15736                               {
15737                                  duCb.actvCellLst[cellId-1]->cellStatus = DELETION_IN_PROGRESS;
15738                               }
15739                            }
15740                         }
15741                      }
15742
15743                      if(duCb.actvCellLst[cellIdx] != NULLP)
15744                      {
15745                         if(duCb.actvCellLst[cellIdx]->numActvUes == 0)
15746                         {
15747                            ret = duSendCellDeletReq(cellId);
15748                            if(ret == RFAILED)
15749                            {
15750                               DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to send cell delete\
15751                               request for cellId[%lu]", cellId);
15752                            }
15753                         }
15754                         else
15755                         {
15756                            totalActiveUe = duCb.actvCellLst[cellIdx]->numActvUes;
15757                            while(totalActiveUe)
15758                            {
15759                               if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState != UE_ACTIVE)
15760                               {
15761                                  ueIdx++;
15762                                  continue;
15763                               }
15764
15765                               crnti = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti;
15766                               GET_UE_ID(crnti,ueId);
15767                               /* Sending Ue Context release request only for maximum supporting UEs */
15768                               ret = BuildAndSendUeContextReleaseReq(cellId, ueId);
15769                               if(ret == RFAILED)
15770                               {
15771                                  DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to build and send UE delete\
15772                                  request for cellId[%lu]", cellId);
15773                               }
15774                               ueIdx++;
15775                               totalActiveUe--;
15776                            }
15777                         }
15778                      }
15779                      else
15780                      {
15781                         DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): CellId [%lu] not found", cellId);
15782                         ret = RFAILED;
15783                      }
15784                      break;
15785                   }
15786
15787                default:
15788                   break;
15789             }
15790          }
15791       }
15792    }
15793    
15794    FreeDUConfigUpdate(f1apMsgPdu);
15795    deleteFromReservedF1apPduList(f1apPduNode);
15796    return ret;
15797 }
15798
15799 /*******************************************************************
15800 *
15801 * @brief Processes GNB DU config update ack
15802 *
15803 * @details
15804 *
15805 *    Function : procF1GNBDUCfgUpdAck
15806 *
15807 *    Functionality: added free part for the memory allocated by aper_decoder
15808 *
15809 * @params[in] F1AP_PDU_t *f1apMsg 
15810 * @return void 
15811 *
15812 * ****************************************************************/
15813 uint8_t procF1GNBDUCfgUpdAck(F1AP_PDU_t *f1apMsg)
15814 {
15815    uint8_t ieIdx=0,transId=0;
15816    GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck = NULLP;
15817
15818    DU_LOG("\nINFO   -->  F1AP : GNB-DU config update acknowledgment");
15819    gnbDuAck = &f1apMsg->choice.successfulOutcome->value.choice.GNBDUConfigurationUpdateAcknowledge;
15820
15821    for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15822    {
15823       switch(gnbDuAck->protocolIEs.list.array[ieIdx]->id)
15824       {
15825          case ProtocolIE_ID_id_TransactionID:
15826             {
15827                transId = gnbDuAck->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
15828                break;
15829             }
15830          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15831             {
15832                break;
15833             }
15834          default :
15835             {
15836                DU_LOG("\nERROR  -->  F1AP: procF1GNBDUCfgUpdAck(): Invalid IE Received: %ld", \
15837                      gnbDuAck->protocolIEs.list.array[ieIdx]->id);
15838                break;
15839             }
15840       }
15841    }
15842    
15843    duProcGnbDuCfgUpdAckMsg(transId);
15844     
15845 #if 0
15846    /* presently we are not supporting F1 Reset from DU to CU , we are only
15847     * supporting F1 Reset from CU to DU */
15848
15849    if(BuildAndSendF1ResetReq() != ROK)
15850    {
15851       return RFAILED;
15852    }
15853 #endif
15854
15855    freeAperDecodeGnbDuAck(gnbDuAck);
15856    return ROK;
15857 }
15858 /******************************************************************
15859 *
15860 * @brief free DL RRC Message Transfer allocated by aper_decoder 
15861 *
15862 * @details
15863 *
15864 *    Function : freeAperDecodef1DlRrcMsg 
15865 *
15866 *    Functionality: free DL RRC Message Transfer allocated by aper_decoder 
15867 *
15868 * @params[in] DLRRCMessageTransfer_t *f1DlRrcMsg 
15869 * @return ROK     - success
15870 *         RFAILED - failure
15871 *
15872 * ****************************************************************/
15873
15874 void freeAperDecodef1DlRrcMsg(DLRRCMessageTransfer_t *f1DlRrcMsg)
15875 {
15876    uint8_t ieIdx =0;
15877    RRCContainer_t *rrcContainer = NULLP;
15878
15879    if(f1DlRrcMsg->protocolIEs.list.array)
15880    {
15881       for(ieIdx=0; ieIdx<f1DlRrcMsg->protocolIEs.list.count; ieIdx++)
15882       {
15883          if(f1DlRrcMsg->protocolIEs.list.array[ieIdx])
15884          {
15885             switch(f1DlRrcMsg->protocolIEs.list.array[ieIdx]->id)
15886             {
15887                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15888                   break;
15889                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15890                   break;
15891                case ProtocolIE_ID_id_SRBID:
15892                   break;
15893                case ProtocolIE_ID_id_RRCContainer:
15894                   {
15895                      rrcContainer =&f1DlRrcMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer;
15896                      free(rrcContainer->buf);
15897                   }
15898                case ProtocolIE_ID_id_ExecuteDuplication:
15899                   break;
15900                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15901                   break;
15902                   break;
15903             }
15904             free(f1DlRrcMsg->protocolIEs.list.array[ieIdx]);
15905          }
15906       }
15907       free(f1DlRrcMsg->protocolIEs.list.array);
15908    }
15909 }
15910 /******************************************************************
15911  *
15912  * @brief Processes DL RRC Message Transfer  sent by CU
15913  *
15914  * @details
15915  *
15916  *    Function : procF1DlRrcMsgTrans
15917  *
15918  *    Functionality: Processes DL RRC Message Transfer sent by CU
15919  *
15920  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15921  * @return ROK     - success
15922  *         RFAILED - failure
15923  *
15924  * ****************************************************************/
15925 uint8_t procF1DlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
15926 {
15927    uint8_t  idx, ret;
15928    DLRRCMessageTransfer_t *f1DlRrcMsg = NULLP;
15929    F1DlRrcMsg dlMsg;
15930    memset(&dlMsg, 0, sizeof(F1DlRrcMsg));
15931
15932    DU_LOG("\nINFO   -->  DU_APP : DL RRC message transfer Recevied");
15933    f1DlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
15934
15935    ret = ROK;
15936
15937    for(idx=0; idx<f1DlRrcMsg->protocolIEs.list.count; idx++)
15938    {
15939       switch(f1DlRrcMsg->protocolIEs.list.array[idx]->id)
15940       {
15941          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15942             {
15943                dlMsg.gnbCuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
15944                break;
15945             }
15946          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15947             {
15948                dlMsg.gnbDuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
15949                break;
15950             }
15951          case ProtocolIE_ID_id_SRBID:
15952             {
15953                dlMsg.srbId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
15954                break;
15955             }
15956          case ProtocolIE_ID_id_ExecuteDuplication:
15957             dlMsg.execDup = true;
15958             break;
15959
15960          case ProtocolIE_ID_id_RRCContainer:
15961             {
15962                if(f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
15963                {
15964              dlMsg.rrcMsgSize = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
15965              DU_ALLOC_SHRABL_BUF(dlMsg.rrcMsgPdu, dlMsg.rrcMsgSize);
15966              if(dlMsg.rrcMsgPdu)
15967              {
15968                 memcpy(dlMsg.rrcMsgPdu, f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf,\
15969                       dlMsg.rrcMsgSize);
15970              }
15971              else
15972              {
15973                 DU_LOG("\nERROR  -->  DU APP : Memory alloc Failed at RRC Container at procF1DlRrcMsgTrans()");
15974                 return RFAILED;
15975              }
15976           }
15977           else
15978           {
15979              DU_LOG("\nERROR  -->  DU_APP : RRC Container Size is invalid:%ld",\
15980                    f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
15981              return RFAILED;
15982           }
15983           break;
15984        }
15985     case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15986        {
15987           dlMsg.deliveryStatRpt = true;
15988           break;
15989        }
15990     default:
15991        DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
15992              f1DlRrcMsg->protocolIEs.list.array[idx]->id);
15993       }
15994    }
15995
15996    ret = duProcDlRrcMsg(&dlMsg);
15997
15998    freeAperDecodef1DlRrcMsg(f1DlRrcMsg);
15999    return ret;
16000 }
16001 /*******************************************************************
16002  *
16003 * @brief Builds the DRB to be Setup Mod list
16004 *
16005 * @details
16006 *
16007 *    Function : 
16008 *
16009 *    Functionality: Constructs the DRB to be Setup Mod list
16010 *
16011 * @params[in] DRBs_SetupMod_List_t *drbSet
16012 *
16013 * @return ROK     - success
16014 *         RFAILED - failure
16015 *
16016 * ****************************************************************/
16017 uint8_t BuildSrbSetupModList(SRBs_SetupMod_List_t *srbList, DuUeCfg *ueCfg)
16018 {
16019    uint8_t srbIdx = 0;
16020    struct SRBs_SetupMod_ItemIEs *srbItemIe;
16021
16022    srbList->list.count = ueCfg->numRlcLcs;
16023    srbList->list.size = srbList->list.count * sizeof(SRBs_SetupMod_ItemIEs_t *);
16024
16025    DU_ALLOC(srbList->list.array, srbList->list.size);
16026    if(srbList->list.array == NULLP)
16027    {
16028       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
16029       return RFAILED;
16030    }
16031
16032    for(srbIdx = 0; srbIdx < srbList->list.count; srbIdx++)
16033    {
16034       DU_ALLOC(srbList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
16035       if(srbList->list.array[srbIdx] == NULLP)
16036       {
16037          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
16038          return RFAILED;
16039       }
16040    } 
16041
16042    for(srbIdx=0; srbIdx < srbList->list.count; srbIdx++)
16043    {
16044       srbItemIe = (struct SRBs_SetupMod_ItemIEs *)srbList->list.array[srbIdx];
16045       srbItemIe->id = ProtocolIE_ID_id_SRBs_SetupMod_Item;
16046       srbItemIe->criticality = Criticality_reject;
16047       srbItemIe->value.present = SRBs_SetupMod_ItemIEs__value_PR_SRBs_SetupMod_Item;
16048       srbItemIe->value.choice.SRBs_SetupMod_Item.sRBID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.rbId;
16049       srbItemIe->value.choice.SRBs_SetupMod_Item.lCID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.lcId;
16050    }
16051    return ROK;
16052 }
16053
16054 /*******************************************************************
16055  *
16056 * @brief Builds the DRB to be Setup Mod list
16057 *
16058 * @details
16059 *
16060 *    Function : 
16061 *
16062 *    Functionality: Constructs the DRB to be Setup Mod list
16063 *
16064 * @params[in] DRBs_SetupMod_List_t *drbSet
16065 *
16066 * @return ROK     - success
16067 *         RFAILED - failure
16068 *
16069 * ****************************************************************/
16070
16071 uint8_t BuildDrbSetupModList(DRBs_SetupMod_List_t *drbSet , DuUeCfg *ueCfg)
16072 {
16073    uint8_t arrIdx =0;
16074    uint8_t drbCnt =0;
16075    struct DRBs_SetupMod_ItemIEs *drbItemIe;
16076
16077    drbCnt = ueCfg->numDrbSetupMod;
16078
16079    drbSet->list.count = drbCnt;
16080    drbSet->list.size = drbCnt * sizeof(DRBs_SetupMod_ItemIEs_t *);
16081    DU_ALLOC(drbSet->list.array, drbSet->list.size);
16082    if(drbSet->list.array == NULLP)
16083    {
16084       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
16085       return  RFAILED;
16086    }
16087    for(arrIdx=0; arrIdx<drbCnt; arrIdx++)
16088    {
16089       DU_ALLOC(drbSet->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
16090       if(drbSet->list.array[arrIdx] == NULLP)
16091       {
16092               DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
16093               return  RFAILED;
16094       }
16095
16096       drbItemIe = (struct DRBs_SetupMod_ItemIEs *)drbSet->list.array[arrIdx];
16097       drbItemIe->id = ProtocolIE_ID_id_DRBs_SetupMod_Item;
16098       drbItemIe->criticality = Criticality_reject;
16099       drbItemIe->value.present = DRBs_SetupMod_ItemIEs__value_PR_DRBs_SetupMod_Item;
16100       drbItemIe->value.choice.DRBs_SetupMod_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
16101       if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List,\
16102       &ueCfg->upTnlInfo[arrIdx])!= ROK)
16103       {
16104          DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbToBeSetupModList");
16105          return RFAILED;
16106       }
16107       
16108    }
16109
16110    return ROK;
16111 }
16112 /*******************************************************************
16113 * @brief Free the memory allocated for DRB setup List
16114 *
16115 * @details
16116 *
16117 *    Function : FreeDrbSetupModList 
16118 *
16119 *    Functionality:
16120 *       Free the memory allocated for DRB setup list
16121 *
16122 * @params[in] DRBs_Setup_List_t *
16123 * @return void
16124 *
16125 * ****************************************************************/
16126 void FreeDrbSetupModList(DRBs_SetupMod_List_t *drbSetupList)
16127 {
16128    uint8_t arrIdx = 0;
16129    DRBs_SetupMod_ItemIEs_t *drbItemIe = NULLP;
16130
16131    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
16132    {
16133       drbItemIe = ((DRBs_SetupMod_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
16134       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List);
16135       DU_FREE(drbSetupList->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
16136    }
16137    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
16138 }
16139
16140 /*******************************************************************
16141 *
16142 * @brief Builds the DRB to be Mod list
16143 *
16144 * @details
16145 *
16146 *    Function : 
16147 *
16148 *    Functionality: Constructs the DRB to be Mod list
16149 *
16150 * @params[in] DRBs_Modified_List_t *drbModList
16151 *
16152 * @return ROK     - success
16153 *         RFAILED - failure
16154 *
16155 * ****************************************************************/
16156
16157 uint8_t BuildDrbModList(DRBs_Modified_List_t *drbModList, DuUeCfg *ueCfg)
16158 {
16159    uint8_t arrIdx =0, drbIdx = 0;
16160    uint8_t drbCnt =0;
16161    struct DRBs_Modified_ItemIEs *drbItemIe;
16162
16163    drbCnt = ueCfg->numDrbModified;
16164
16165    drbModList->list.count = drbCnt;
16166    drbModList->list.size = drbCnt * sizeof(DRBs_Modified_ItemIEs_t *);
16167    DU_ALLOC(drbModList->list.array, drbModList->list.size);
16168    if(drbModList->list.array == NULLP)
16169    {
16170       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList()");
16171       return  RFAILED;
16172    }
16173
16174    drbIdx = 0;
16175    for(arrIdx = 0; arrIdx < ueCfg->numMacLcs; arrIdx++)
16176    {
16177       if(ueCfg->macLcCfg[arrIdx].configType == CONFIG_MOD)
16178       {
16179          DU_ALLOC(drbModList->list.array[drbIdx], sizeof(DRBs_Modified_ItemIEs_t));
16180          if(drbModList->list.array[drbIdx] == NULLP)
16181          {
16182             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList");
16183             return  RFAILED;
16184          }
16185
16186          drbItemIe = (struct DRBs_Modified_ItemIEs *)drbModList->list.array[drbIdx];
16187          drbItemIe->id = ProtocolIE_ID_id_DRBs_Modified_Item;
16188          drbItemIe->criticality = Criticality_reject;
16189          drbItemIe->value.present = DRBs_Modified_ItemIEs__value_PR_DRBs_Modified_Item;
16190          drbItemIe->value.choice.DRBs_Modified_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
16191          if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List,\
16192                   &ueCfg->upTnlInfo[arrIdx])!= ROK)
16193          {
16194             DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbModList");
16195             return RFAILED;
16196          }
16197          drbIdx++;
16198       } 
16199    }
16200
16201    return ROK;
16202 }
16203
16204 /*******************************************************************
16205 * @brief Free the memory allocated for DRB Mod List
16206 *
16207 * @details
16208 *
16209 *    Function : FreeDrbModList 
16210 *
16211 *    Functionality:
16212 *       Free the memory allocated for DRB modified list
16213 *
16214 * @params[in] DRBs_Modified_List_t *
16215 * @return void
16216 *
16217 * ****************************************************************/
16218 void FreeDrbModList(DRBs_Modified_List_t *drbModList)
16219 {
16220    uint8_t arrIdx = 0;
16221    DRBs_Modified_ItemIEs_t *drbItemIe = NULLP;
16222
16223    for(arrIdx = 0; arrIdx < drbModList->list.count; arrIdx++)
16224    {
16225       drbItemIe = ((DRBs_Modified_ItemIEs_t *)drbModList->list.array[arrIdx]);
16226       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List);
16227       DU_FREE(drbModList->list.array[arrIdx], sizeof(DRBs_Modified_ItemIEs_t));
16228    }
16229    DU_FREE(drbModList->list.array, drbModList->list.size);
16230 }
16231
16232 /*******************************************************************
16233 * @brief Free the memory allocated for SRB setup List
16234 *
16235 * @details
16236 *
16237 *    Function : FreeSrbSetupModList 
16238 *
16239 *    Functionality:
16240 *       Free the memory allocated for SRB setup list
16241 *
16242 * @params[in] SRBs_Setup_List_t *
16243 * @return void
16244 *
16245 * ****************************************************************/
16246 void FreeSrbSetupModList(SRBs_SetupMod_List_t *srbSetupList)
16247 {
16248    uint8_t srbIdx = 0;
16249    
16250    for(srbIdx = 0; srbIdx < srbSetupList->list.count; srbIdx++)
16251       DU_FREE(srbSetupList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
16252    DU_FREE(srbSetupList->list.array, srbSetupList->list.size);
16253 }
16254
16255 /*******************************************************************
16256 * @brief Free the memory allocated for UE Context Mod Response
16257 *
16258 * @details
16259 *
16260 *    Function : FreeUeContextModResp 
16261 *
16262 *    Functionality:
16263 *       Free the memory allocated for UE Context Mod Response
16264 *
16265 * @params[in] F1AP_PDU_t *f1apMsg
16266 * @return void
16267 *
16268 * ****************************************************************/
16269
16270 void FreeUeContextModResp(F1AP_PDU_t *f1apMsg)
16271 {
16272    uint8_t ieIdx;
16273    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
16274    if(f1apMsg)
16275    {
16276       if(f1apMsg->choice.successfulOutcome)
16277       {
16278          ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
16279          if(ueContextModifyRes->protocolIEs.list.array)
16280          {
16281             for(ieIdx=0 ; ieIdx<ueContextModifyRes->protocolIEs.list.count; ieIdx++)
16282             {
16283                if(ueContextModifyRes->protocolIEs.list.array[ieIdx])
16284                {
16285                   switch(ueContextModifyRes->protocolIEs.list.array[ieIdx]->id)
16286                   {
16287                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16288                         break;
16289                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16290                         break;
16291                      case ProtocolIE_ID_id_DUtoCURRCInformation:
16292                         {
16293                            DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.\
16294                               cellGroupConfig.buf, ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
16295                               DUtoCURRCInformation.cellGroupConfig.size);
16296                            break;
16297                         }
16298                      case ProtocolIE_ID_id_DRBs_SetupMod_List:
16299                         {
16300                             FreeDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16301                             value.choice.DRBs_SetupMod_List));
16302                             break;
16303                         }
16304                      case ProtocolIE_ID_id_DRBs_Modified_List:
16305                         {
16306                             FreeDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16307                             value.choice.DRBs_Modified_List));
16308                             break;
16309                         }
16310                      case ProtocolIE_ID_id_SRBs_SetupMod_List:
16311                         {
16312                            FreeSrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
16313                               SRBs_SetupMod_List));
16314                            break; 
16315                         }
16316                   }
16317                   DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
16318                }
16319
16320             }
16321             DU_FREE(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
16322          }
16323          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16324       }
16325       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
16326    }
16327 }
16328
16329 /*****************************************************************i
16330 *
16331 * @brief Creating the ue context modifcation response and sending
16332 *
16333 * @details
16334 *
16335 *    Function : BuildAndSendUeContextModRsp 
16336 *
16337 *    Functionality:
16338 *         - Creating the ue context modifcation response 
16339 *
16340 * @params[in] uint8_t cellId,uint8_t ueId
16341 * @return ROK     - success
16342 *         RFAILED - failure
16343 *
16344 * ****************************************************************/
16345 uint8_t BuildAndSendUeContextModRsp(DuUeCb *ueCb)
16346 {
16347    uint8_t   ieIdx = 0, tnlIdx = 0, rbIdx = 0;
16348    uint8_t   elementCnt = 0;
16349    uint8_t   ret = RFAILED;
16350    F1AP_PDU_t *f1apMsg = NULLP;
16351    asn_enc_rval_t  encRetVal;
16352    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
16353
16354    DU_LOG("\nINFO  -->  F1AP : Building UE context modification response\n");
16355
16356    while(true)
16357    {
16358       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
16359       if(f1apMsg == NULLP)
16360       {
16361          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16362          break;
16363       }
16364
16365       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
16366
16367       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16368       if(f1apMsg->choice.successfulOutcome == NULLP)
16369       {
16370          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16371          break;
16372       }
16373       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextModification;
16374       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
16375       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_UEContextModificationResponse;
16376
16377       ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
16378   
16379       if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
16380       {
16381          elementCnt = 2;
16382          if(ueCb->f1UeDb->duUeCfg.numDrbSetupMod)
16383             elementCnt++;
16384          if(ueCb->f1UeDb->duUeCfg.numDrbModified)
16385             elementCnt++; 
16386       }
16387       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16388       {
16389          elementCnt = 5;
16390       }
16391       if(ueCb->f1UeDb->actionType == UE_CTXT_RRC_RECFG_COMPLETE)
16392          elementCnt = 2;
16393       ueContextModifyRes->protocolIEs.list.count = elementCnt;
16394       ueContextModifyRes->protocolIEs.list.size = elementCnt*sizeof(UEContextModificationResponse_t*);
16395
16396       /* Initialize the UE context modification members */
16397       DU_ALLOC(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
16398       if(ueContextModifyRes->protocolIEs.list.array == NULLP)
16399       {
16400          DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16401          break;
16402       }
16403
16404       for(ieIdx=0 ; ieIdx<elementCnt; ieIdx++)
16405       {
16406          DU_ALLOC(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
16407          if(ueContextModifyRes->protocolIEs.list.array[ieIdx] == NULLP)
16408          {
16409             DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16410             break;
16411          }
16412       }
16413
16414       ieIdx=0;
16415       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
16416       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16417       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16418       UEContextModificationResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
16419       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
16420
16421       ieIdx++;
16422       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16423       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16424       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present=\
16425       UEContextModificationResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
16426       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
16427
16428       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16429       {
16430          ieIdx++;
16431          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCInformation;
16432          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16433          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16434          UEContextModificationResponseIEs__value_PR_DUtoCURRCInformation;
16435          BuildCellGroupConfigRrc(ueCb, &ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
16436       }
16437
16438       if((ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY) || \
16439            ((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbSetupMod)))
16440       { 
16441          ieIdx++;
16442          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_SetupMod_List;
16443          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16444          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16445                                                                            UEContextModificationResponseIEs__value_PR_DRBs_SetupMod_List;
16446          if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16447          {
16448             for(tnlIdx = 0; tnlIdx < duCb.numTeId; tnlIdx++)
16449             {
16450                if(duCb.upTnlCfg[tnlIdx]->ueId == ueCb->gnbDuUeF1apId)
16451                {
16452                   memcpy(&ueCb->f1UeDb->duUeCfg.upTnlInfo[ueCb->f1UeDb->duUeCfg.numDrbSetupMod++], duCb.upTnlCfg[tnlIdx], sizeof(UpTnlCfg));
16453                }
16454             }
16455          }
16456          ret = BuildDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16457                   value.choice.DRBs_SetupMod_List) , &ueCb->f1UeDb->duUeCfg);
16458          if(ret != ROK)
16459          {
16460             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB setupmod List ");
16461             break;
16462          }
16463       }
16464
16465       if((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbModified))
16466       { 
16467          ieIdx++;
16468          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_Modified_List;
16469          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16470          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16471                                                                     UEContextModificationResponseIEs__value_PR_DRBs_Modified_List;
16472          ret = BuildDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16473                                  value.choice.DRBs_Modified_List) , &ueCb->f1UeDb->duUeCfg);
16474          if(ret != ROK)
16475          {
16476             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB Modified List ");
16477             break;
16478          }
16479       }
16480
16481       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16482       {
16483          ieIdx++;
16484          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_SRBs_SetupMod_List;
16485          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16486          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16487                                                                             UEContextModificationResponseIEs__value_PR_SRBs_SetupMod_List;
16488          for(rbIdx = 0; rbIdx < ueCb->duRlcUeCfg.numLcs; rbIdx++)
16489          {
16490             if(ueCb->duRlcUeCfg.rlcLcCfg[rbIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
16491             {
16492                memcpy(&ueCb->f1UeDb->duUeCfg.rlcLcCfg[ueCb->f1UeDb->duUeCfg.numRlcLcs++], &ueCb->duRlcUeCfg.rlcLcCfg[rbIdx],\
16493                      sizeof(DuRlcBearerCfg));
16494             }
16495          }
16496          ret = BuildSrbSetupModList(&ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.SRBs_SetupMod_List, \
16497                &ueCb->f1UeDb->duUeCfg);
16498          if(ret != ROK)
16499          {
16500             DU_LOG( "\nERROR  -->  F1AP : Failed to build SRB setupmod List ");
16501             break;
16502          }
16503       }
16504
16505       freeF1UeDb(ueCb->f1UeDb);
16506       ueCb->f1UeDb = NULLP;
16507
16508       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16509
16510       /* Encode the F1SetupRequest type as APER */
16511       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16512       encBufSize = 0;
16513       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,encBuf);
16514
16515       /* Encode results */
16516       if(encRetVal.encoded == ENCODE_FAIL)
16517       {
16518          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Modification Response structure (at %s)\n",\
16519                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16520          ret = RFAILED;
16521          break;
16522       }
16523       else
16524       {
16525          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Modification Response\n");
16526 #ifdef DEBUG_ASN_PRINT
16527          for(int i=0; i< encBufSize; i++)
16528          {
16529             printf("%x",encBuf[i]);
16530          }
16531 #endif
16532       }
16533
16534       /* Sending  msg  */
16535       if(sendF1APMsg() != ROK && (ret == ROK))
16536       {
16537          DU_LOG("\nERROR  -->  F1AP : Sending UE Modification Res Failed");
16538          ret = RFAILED;
16539          break;
16540       }
16541
16542       ret = ROK;
16543       break;
16544    }
16545
16546    FreeUeContextModResp(f1apMsg);
16547    return ret;
16548 }
16549
16550 /*******************************************************************
16551  *
16552  * @brief Deallocating the memory allocated by the aper decoder
16553  *          for QOSInfo
16554  *
16555  * @details
16556  *
16557  *    Function : freeAperDecodeQosInfo
16558  *
16559  *    Functionality:  Deallocating the memory allocated for QOSInfo
16560  *
16561  * @params[in] QoSFlowLevelQoSParameters_t *drbQos
16562  *
16563  * @return void
16564  *
16565  * ****************************************************************/
16566
16567 void freeAperDecodeQosInfo(QoSFlowLevelQoSParameters_t *drbQos)
16568 {
16569    if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI != NULLP)
16570    {
16571       if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
16572       {
16573          if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
16574          {
16575             free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
16576          }
16577          free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
16578       }
16579       free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI);
16580    }
16581 }
16582 /*******************************************************************
16583  *
16584  * @brief Deallocating the memory allocated by the aper decoder
16585  *          for UlTnlInfoforDrb
16586  *
16587  * @details
16588  *
16589  *    Function : freeAperDecodeUlTnlInfoforDrbSetupMod 
16590  *
16591  *    Functionality:  Deallocating memory allocated for UlTnlInfoforDrb
16592  *
16593  * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
16594  *
16595  * @return void
16596  *
16597  * ****************************************************************/
16598 void freeAperDecodeUlTnlInfoforDrbSetupMod(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
16599 {
16600    uint8_t arrIdx =0;
16601
16602    if(ulInfo->list.array)
16603    {
16604       for(arrIdx=0; arrIdx<ulInfo->list.count ; arrIdx++)
16605       {
16606          if(ulInfo->list.array[arrIdx])
16607          {
16608             if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel )
16609             {
16610                if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf)
16611                {
16612                   if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf)
16613                   {
16614                      free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16615                            gTP_TEID.buf);
16616                   }
16617                   free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16618                         transportLayerAddress.buf);
16619                }
16620                free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel);
16621             }
16622             free(ulInfo->list.array[arrIdx]);
16623          }
16624       }
16625       free(ulInfo->list.array);
16626    }
16627 }
16628
16629 /*******************************************************************
16630  *
16631  * @brief Deallocating the memory allocated by the aper decoder
16632  *          for DrbSetupModItem  
16633  *
16634  * @details
16635  *
16636  *    Function : freeAperDecodeDrbSetupModItem 
16637  *
16638  *    Functionality:  Deallocating memory allocated for DrbSetupModItem
16639  *
16640  * @params[in] DRBs_ToBeSetupMod_Item_t *drbItem
16641  *
16642  * @return void
16643  *
16644  * ****************************************************************/
16645
16646 void freeAperDecodeDrbSetupModItem(DRBs_ToBeSetupMod_Item_t *drbItem)
16647 {
16648    uint8_t arrIdx =0;
16649    SNSSAI_t *snssai =NULLP;
16650    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16651
16652    drbItem->qoSInformation.present = QoSInformation_PR_choice_extension;
16653    switch(drbItem->qoSInformation.present)
16654    {
16655       case QoSInformation_PR_NOTHING:
16656          break;
16657       case QoSInformation_PR_eUTRANQoS:
16658          {
16659             if(drbItem->qoSInformation.choice.eUTRANQoS)
16660             {
16661                free(drbItem->qoSInformation.choice.eUTRANQoS);
16662             }
16663             break;
16664          }
16665       case QoSInformation_PR_choice_extension:
16666          {
16667             if(drbItem->qoSInformation.choice.choice_extension)
16668             {
16669                freeAperDecodeQosInfo(&drbItem->qoSInformation.choice.choice_extension->value.choice.\
16670                      DRB_Information.dRB_QoS);
16671                snssai = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16672                if(snssai->sST.buf)
16673                {
16674                   free(snssai->sST.buf);
16675                }
16676                if(snssai->sD)
16677                {
16678                   if(snssai->sD->buf)
16679                   {
16680                      free(snssai->sD->buf);
16681                   }
16682                   free(snssai->sD);
16683                }
16684
16685                flowMap = &drbItem->qoSInformation.choice.choice_extension->value.choice.\
16686                          DRB_Information.flows_Mapped_To_DRB_List;
16687                if(flowMap->list.array)
16688                {
16689                   for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16690                   {
16691                      if(flowMap->list.array[arrIdx] )
16692                      {
16693                         freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16694                         free(flowMap->list.array[arrIdx]);
16695                      }
16696                   }
16697                   free(flowMap->list.array);
16698                }
16699
16700                free(drbItem->qoSInformation.choice.choice_extension);
16701             }
16702             break;
16703          }
16704
16705    }
16706    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16707    if(drbItem->uLConfiguration)
16708    {
16709       free(drbItem->uLConfiguration);
16710    }
16711 }
16712
16713 /*******************************************************************
16714  *
16715  * @brief Deallocating the memory allocated by the aper decoder
16716  *          for DrbToBeSetupModList
16717  *
16718  * @details
16719  *
16720  *    Function : freeAperDecodeDrbToBeSetupModList
16721  *
16722  *    Functionality:  Deallocating memory allocated for DrbToBeSetupModList
16723  *
16724  * @params[in] DRBs_ToBeSetupMod_List_t *drbSet
16725  *
16726  * @return void
16727  *
16728  * ****************************************************************/
16729
16730 void freeAperDecodeDrbToBeSetupModList(DRBs_ToBeSetupMod_List_t *drbSet)
16731 {
16732    uint8_t arrIdx =0;
16733    struct DRBs_ToBeSetupMod_ItemIEs *drbItemIe;
16734
16735    if(drbSet->list.array)
16736    {
16737       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16738       {
16739          if(drbSet->list.array[arrIdx] != NULLP)
16740          {
16741             if(arrIdx == 0)
16742             {
16743                drbItemIe = (DRBs_ToBeSetupMod_ItemIEs_t *)drbSet->list.array[arrIdx];
16744                freeAperDecodeDrbSetupModItem(&(drbItemIe->value.choice.DRBs_ToBeSetupMod_Item));
16745             }
16746             free(drbSet->list.array[arrIdx]);
16747          }
16748       }
16749       free(drbSet->list.array);
16750    }
16751
16752 }
16753
16754 /*******************************************************************
16755  *
16756  * @brief Deallocating the memory allocated by the aper decoder
16757  *          for DrbSetupModItem  
16758  *
16759  * @details
16760  *
16761  *    Function : freeAperDecodeDrbModifiedItem 
16762  *
16763  *    Functionality:  Deallocating memory allocated for DrbModifedItem
16764  *
16765  * @params[in] DRBs_ToBeModified_Item_t *drbItem
16766  *
16767  * @return void
16768  *
16769  * ****************************************************************/
16770
16771 void freeAperDecodeDrbModifiedItem(DRBs_ToBeModified_Item_t *drbItem)
16772 {
16773    uint8_t arrIdx =0;
16774    SNSSAI_t *snssai =NULLP;
16775    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16776
16777    if(drbItem->qoSInformation != NULLP)
16778    {
16779       drbItem->qoSInformation->present = QoSInformation_PR_choice_extension;
16780       switch(drbItem->qoSInformation->present)
16781       {
16782          case QoSInformation_PR_NOTHING:
16783             break;
16784          case QoSInformation_PR_eUTRANQoS:
16785             {
16786                if(drbItem->qoSInformation->choice.eUTRANQoS)
16787                {
16788                   free(drbItem->qoSInformation->choice.eUTRANQoS);
16789                }
16790                break;
16791             }
16792          case QoSInformation_PR_choice_extension:
16793             {
16794                if(drbItem->qoSInformation->choice.choice_extension)
16795                {
16796                   freeAperDecodeQosInfo(&drbItem->qoSInformation->choice.choice_extension->value.choice.\
16797                         DRB_Information.dRB_QoS);
16798                   snssai = &drbItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16799                   if(snssai->sST.buf)
16800                   {
16801                      free(snssai->sST.buf);
16802                   }
16803                   if(snssai->sD)
16804                   {
16805                      if(snssai->sD->buf)
16806                      {
16807                         free(snssai->sD->buf);
16808                      }
16809                      free(snssai->sD);
16810                   }
16811
16812                   flowMap = &drbItem->qoSInformation->choice.choice_extension->value.choice.\
16813                             DRB_Information.flows_Mapped_To_DRB_List;
16814                   if(flowMap->list.array)
16815                   {
16816                      for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16817                      {
16818                         if(flowMap->list.array[arrIdx] )
16819                         {
16820                            freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16821                            free(flowMap->list.array[arrIdx]);
16822                         }
16823                      }
16824                      free(flowMap->list.array);
16825                   }
16826
16827                   free(drbItem->qoSInformation->choice.choice_extension);
16828                }
16829                break;
16830             }
16831       }
16832       free(drbItem->qoSInformation);
16833    }
16834    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16835    if(drbItem->uLConfiguration)
16836    {
16837       free(drbItem->uLConfiguration);
16838    }
16839 }
16840
16841 /*******************************************************************
16842  *
16843  * @brief Deallocating the memory allocated by the aper decoder
16844  *          for DrbToBeSetupModList
16845  *
16846  * @details
16847  *
16848  *    Function : freeAperDecodeDrbToBeModifiedList
16849  *
16850  *    Functionality:  Deallocating memory allocated for DrbToBeModifiedList
16851  *
16852  * @params[in] DRBs_ToBeModified_List_t *drbSet
16853  *
16854  * @return void
16855  *
16856  * ****************************************************************/
16857
16858 void freeAperDecodeDrbToBeModifiedList(DRBs_ToBeModified_List_t *drbSet)
16859 {
16860    uint8_t arrIdx =0;
16861    struct DRBs_ToBeModified_ItemIEs *drbItemIe;
16862
16863    if(drbSet->list.array)
16864    {
16865       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16866       {
16867          if(drbSet->list.array[arrIdx] != NULLP)
16868          {
16869             if(arrIdx == 0)
16870             {
16871                drbItemIe = (DRBs_ToBeModified_ItemIEs_t *)drbSet->list.array[arrIdx];
16872                freeAperDecodeDrbModifiedItem(&(drbItemIe->value.choice.DRBs_ToBeModified_Item));
16873             }
16874             free(drbSet->list.array[arrIdx]);
16875          }
16876       }
16877       free(drbSet->list.array);
16878    }
16879
16880 }
16881
16882 /*******************************************************************
16883  *
16884  * @brief Deallocating the memory allocated by the aper decoder
16885  *          for DrbToBeSetupModList
16886  *
16887  * @details
16888  *
16889  *    Function : freeAperDecodeDrbToBeReleasedList
16890  *
16891  *    Functionality:  Deallocating memory allocated for DrbToBeReleasedList
16892  *
16893  * @params[in] DRBs_ToBeReleased_List_t *drbSet
16894  *
16895  * @return void
16896  *
16897  * ****************************************************************/
16898
16899 void freeAperDecodeDrbToBeReleasedList(DRBs_ToBeReleased_List_t *drbSet)
16900 {
16901    uint8_t arrIdx =0;
16902
16903    if(drbSet->list.array)
16904    {
16905       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16906       {
16907          if(drbSet->list.array[arrIdx] != NULLP)
16908          {
16909             free(drbSet->list.array[arrIdx]);
16910          }
16911       }
16912       free(drbSet->list.array);
16913    }
16914
16915 }
16916 /*******************************************************************
16917  *
16918  * @brief Deallocating the memory allocated by the aper decoder
16919  *          for UeContextModificationReqMsg
16920  *
16921  * @details
16922  *
16923  *    Function : freeAperDecodeUeContextModificationReqMsg
16924  *
16925  *    Functionality:  Deallocating memory allocated for
16926  *                  UeContextModificationReqMsg
16927  *
16928  * @params[in] UEContextModificationRequest_t *UeContextModifyReq
16929  *
16930  * @return void
16931  *
16932  * ****************************************************************/
16933 void freeAperDecodeUeContextModificationReqMsg(UEContextModificationRequest_t *ueContextModifyReq )
16934 {
16935    uint8_t arrIdx, ieId;
16936
16937    if(ueContextModifyReq->protocolIEs.list.array)
16938    {
16939       for( arrIdx = 0 ; arrIdx<ueContextModifyReq->protocolIEs.list.count ; arrIdx++)
16940       {
16941          if(ueContextModifyReq->protocolIEs.list.array[arrIdx])
16942          {
16943             ieId = ueContextModifyReq->protocolIEs.list.array[arrIdx]->id;
16944             switch(ieId)
16945             {
16946                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16947                   break;
16948                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16949                   break;
16950                case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
16951                   {
16952                      freeAperDecodeDrbToBeSetupModList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16953                            value.choice.DRBs_ToBeSetupMod_List);
16954                      break;
16955                   }
16956                case ProtocolIE_ID_id_DRBs_ToBeModified_List:
16957                   {
16958                      freeAperDecodeDrbToBeModifiedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16959                            value.choice.DRBs_ToBeModified_List);
16960                      break;
16961                   }
16962                case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
16963                   {
16964                      freeAperDecodeDrbToBeReleasedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16965                            value.choice.DRBs_ToBeReleased_List);
16966                      break;
16967                   }
16968                case ProtocolIE_ID_id_TransmissionActionIndicator:
16969                   break;
16970                case ProtocolIE_ID_id_RRCContainer:
16971                   {
16972                      free(ueContextModifyReq->protocolIEs.list.array[arrIdx]->value.choice.RRCContainer.buf);
16973                   }
16974             }
16975             free(ueContextModifyReq->protocolIEs.list.array[arrIdx]);
16976          }
16977       }
16978       free(ueContextModifyReq->protocolIEs.list.array);
16979    }
16980 }
16981 /*******************************************************************
16982  *
16983  * @brief processing the F1 UeContextModificationReq
16984  *
16985  * @details
16986  *
16987  *    Function : procF1UeContextModificationReq
16988  *
16989  *    Functionality:  processing the F1 UeContextModificationReq
16990  *
16991  * @params[in] F1AP_PDU_t *f1apMsg
16992  *
16993  * @return
16994  * ****************************************************************/
16995 uint8_t procF1UeContextModificationReq(F1AP_PDU_t *f1apMsg)
16996 {
16997    UEContextModificationRequest_t *ueContextModifyReq = NULLP;
16998    uint8_t  ret = ROK, ieIdx = 0, cellIdx=0;
16999    DuUeCb   *duUeCb = NULLP;
17000    DRBs_ToBeSetupMod_List_t *drbSetupModCfg = NULLP;
17001    DRBs_ToBeModified_List_t *drbModifiedCfg = NULLP;
17002    DRBs_ToBeReleased_List_t *drbToRelease = NULLP;
17003    uint32_t gnbCuUeF1apId, gnbDuUeF1apId;
17004
17005    ueContextModifyReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextModificationRequest;
17006    for(ieIdx=0; (ieIdx < ueContextModifyReq->protocolIEs.list.count && ret == ROK); ieIdx++)
17007    {
17008       switch(ueContextModifyReq->protocolIEs.list.array[ieIdx]->id)
17009       {
17010          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17011             {
17012                gnbCuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
17013                break;
17014             }
17015          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17016             {
17017                gnbDuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
17018                for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
17019                {
17020                   if(duCb.actvCellLst[cellIdx])
17021                   {
17022                      if((duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbDuUeF1apId == gnbDuUeF1apId)&&\
17023                            (duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbCuUeF1apId == gnbCuUeF1apId))
17024                      {
17025                         duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1];
17026                         if(duUeCb->f1UeDb == NULLP)
17027                         {
17028                            DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
17029                            duUeCb->f1UeDb->cellIdx = cellIdx;
17030                            duUeCb->f1UeDb->actionType = UE_CTXT_MOD;
17031                         }
17032                         break;
17033                      }
17034                   }
17035                }
17036                if(duUeCb == NULLP)
17037                {
17038                   DU_LOG("\nERROR  -->  DU APP : wrong values of gnbCuUeF1apId and gnbDuUeF1apId ");
17039                   ret = RFAILED;
17040                }
17041                break;
17042             }
17043
17044          case ProtocolIE_ID_id_RRCContainer:
17045             {
17046                /* Filling Dl RRC Msg Info */
17047                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
17048                if(!duUeCb->f1UeDb->dlRrcMsg)
17049                {
17050                   DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17051                         Memory allocation failed ");
17052                   ret = RFAILED;
17053                }
17054                else
17055                {
17056                   duUeCb->f1UeDb->dlRrcMsgPres = true;
17057                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
17058                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
17059                         &ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
17060                         value.choice.RRCContainer);
17061                }
17062
17063                break;
17064             }
17065
17066          case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
17067          case ProtocolIE_ID_id_DRBs_ToBeModified_List:
17068          case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
17069             {
17070                if(duUeCb->f1UeDb)
17071                {
17072                   /*DRBs to be Added*/
17073                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present ==\
17074                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List)
17075                   {
17076                      drbSetupModCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17077                                       choice.DRBs_ToBeSetupMod_List;
17078
17079                      if(extractDrbListToSetupMod(NULL, drbSetupModCfg, NULL, drbSetupModCfg->list.count,\
17080                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULL))
17081                      {
17082                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbSetupModList");
17083                         ret = RFAILED;
17084                      }
17085                   }
17086
17087                   /*DRBs to be Modified*/
17088                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
17089                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List)
17090
17091                   {
17092                      drbModifiedCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17093                                       choice.DRBs_ToBeModified_List;
17094                      if(extractDrbListToSetupMod(NULL, NULL, drbModifiedCfg, drbModifiedCfg->list.count,\
17095                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, &duUeCb->duRlcUeCfg))
17096                      {
17097                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
17098                         ret = RFAILED;
17099                      }
17100                   }
17101                   /*DRBs to be Released*/
17102                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
17103                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeReleased_List)
17104
17105                   {
17106                      drbToRelease = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17107                                       choice.DRBs_ToBeReleased_List;
17108                      if(extractDrbListToRelease(gnbDuUeF1apId, drbToRelease, drbToRelease->list.count,\
17109                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->duRlcUeCfg))
17110                      {
17111                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
17112                         ret = RFAILED;
17113                      }
17114                   }
17115                }
17116                break;
17117             }
17118
17119          case ProtocolIE_ID_id_GNB_DUConfigurationQuery:
17120             {
17121                DU_LOG("\nINFO  -->  DU APP : Received GNB DU Configuration Query in UE Context Modification Request from CU");
17122                if(duUeCb->f1UeDb)
17123                {
17124                   duUeCb->f1UeDb->actionType = UE_CTXT_CFG_QUERY;
17125                }
17126                break;
17127             }
17128
17129          case ProtocolIE_ID_id_RRCReconfigurationCompleteIndicator:
17130             {
17131                if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.RRCReconfigurationCompleteIndicator == \
17132                   RRCReconfigurationCompleteIndicator_true)
17133                {
17134                   duUeCb->f1UeDb->actionType = UE_CTXT_RRC_RECFG_COMPLETE;
17135                }
17136                break;
17137             }
17138          case ProtocolIE_ID_id_TransmissionActionIndicator:
17139             {
17140                if(duUeCb->f1UeDb)
17141                {
17142                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.TransmissionActionIndicator  == TransmissionActionIndicator_stop)
17143                   {
17144                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = STOP_TRANSMISSION; 
17145                   }
17146                   else 
17147                   {
17148                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = RESTART_TRANSMISSION; 
17149                   }
17150                }
17151                break;
17152             }
17153
17154          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
17155             {
17156                if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
17157                {
17158                   duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
17159                }
17160                break;
17161             }
17162 #ifdef NR_DRX
17163          case ProtocolIE_ID_id_DRXConfigurationIndicator:
17164             {
17165                duUeCb->f1UeDb->duUeCfg.drxConfigIndicatorRelease = true;
17166                break;
17167             }
17168 #endif
17169               
17170       }
17171    }
17172
17173    if(ret != RFAILED) 
17174    {
17175       ret = duProcUeContextModReq(duUeCb);
17176    }
17177    freeAperDecodeUeContextModificationReqMsg(ueContextModifyReq);
17178    return ret; 
17179 }
17180
17181 /*****************************************************************i
17182 *
17183 * @brief Free memory allocated for UE Context Release Request
17184 *
17185 * @details
17186 *
17187 *    Function : FreeUeContextReleaseReq
17188 *
17189 *    Functionality:
17190 *         - Free memory allocated for UE Context Release Request
17191 *
17192 * @params[in] F1AP_PDU_t *f1apMsg
17193 * @return void 
17194 *
17195 * *************************************************************/
17196 void FreeUeContextReleaseReq(F1AP_PDU_t *f1apMsg)
17197 {
17198    uint8_t ieIdx;
17199    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
17200    
17201    if(f1apMsg)
17202    {
17203       if(f1apMsg->choice.initiatingMessage)
17204       {
17205          ueReleaseReq =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
17206          if(ueReleaseReq->protocolIEs.list.array)
17207          {
17208             for(ieIdx=0 ; ieIdx<ueReleaseReq->protocolIEs.list.count; ieIdx++)
17209             {
17210                DU_FREE(ueReleaseReq->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseRequest_t));
17211             }
17212             DU_FREE(ueReleaseReq->protocolIEs.list.array, ueReleaseReq->protocolIEs.list.size);
17213          }
17214          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
17215       }
17216       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
17217    }
17218
17219 }
17220 /*****************************************************************i
17221 *
17222 * @brief Build and Send UE Context Release Request  
17223 *
17224 * @details
17225 *
17226 *    Function : BuildAndSendUeContextReleaseReq
17227 *
17228 *    Functionality:
17229 *         - Build and Send UE Context Release Request 
17230 *
17231 * @params[in]
17232 * @return ROK     - success
17233 *         RFAILED - failure
17234 *
17235 * *************************************************************/
17236 uint8_t BuildAndSendUeContextReleaseReq(uint16_t cellId, uint8_t ueId)
17237 {
17238    bool memAllocFail = false;
17239    uint8_t ieIdx =0;
17240    uint8_t ret = RFAILED;
17241    uint16_t cellIdx =0;
17242    uint16_t crnti = 0;
17243    uint8_t  elementCnt = 0;
17244    uint32_t  gnbCuUeF1apId =0;   /* gNB-CU UE F1AP Id */
17245    uint32_t  gnbDuUeF1apId =0;   /* gNB-DU UE F1AP Id */
17246    asn_enc_rval_t encRetVal; 
17247    F1AP_PDU_t *f1apMsg = NULLP;
17248    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
17249
17250    DU_LOG("\nINFO  --> Building the UE Context Release Request");
17251    do
17252    {
17253       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
17254       if(f1apMsg == NULLP)
17255       {
17256          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for f1apMsg");
17257          break;
17258       }
17259
17260       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
17261       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
17262       if(f1apMsg->choice.initiatingMessage == NULLP)
17263       {
17264          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for\
17265          initiatingMessage");   
17266          break;
17267       }
17268       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_UEContextReleaseRequest;
17269       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
17270       f1apMsg->choice.initiatingMessage->value.present = \
17271       InitiatingMessage__value_PR_UEContextReleaseRequest;
17272
17273       ueReleaseReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
17274
17275       elementCnt = 2;
17276
17277       ueReleaseReq->protocolIEs.list.count = elementCnt;
17278       ueReleaseReq->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseRequest_t *);
17279
17280       /* Initialize the F1Setup members */
17281       DU_ALLOC(ueReleaseReq->protocolIEs.list.array,ueReleaseReq->protocolIEs.list.size);
17282       if(ueReleaseReq->protocolIEs.list.array == NULLP)
17283       {
17284          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE array");
17285          break;
17286       }
17287       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
17288       {
17289          DU_ALLOC(ueReleaseReq->protocolIEs.list.array[ieIdx],\
17290                sizeof(UEContextReleaseRequest_t));
17291          if(ueReleaseReq->protocolIEs.list.array[ieIdx] == NULLP)
17292          {
17293             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE elements");
17294             memAllocFail = true;  
17295             break;
17296          }
17297       }
17298       if(memAllocFail == true)
17299          break;
17300
17301       /* Fetching Ue Cb Info*/
17302       GET_CELL_IDX(cellId, cellIdx);
17303       if(duCb.actvCellLst[cellIdx] == NULLP)
17304       {
17305          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): CellId[%d] does not exist", cellId);
17306          break;
17307       }
17308       else
17309       {
17310          GET_CRNTI(crnti, ueId);
17311          if(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].crnti != crnti)
17312          {
17313             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): crnti[%d] does not exist", crnti);
17314             break;
17315          }
17316          gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
17317          gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
17318       }
17319
17320       ieIdx=0; 
17321       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID; 
17322       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17323       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present = \
17324       UEContextReleaseRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
17325       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
17326       
17327       ieIdx++;
17328       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
17329       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17330       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present =\
17331       UEContextReleaseRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
17332       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17333       
17334       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17335
17336       /* Encode the F1SetupRequest type as APER */
17337       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17338       encBufSize = 0;
17339       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17340       /* Encode results */
17341       if(encRetVal.encoded == ENCODE_FAIL)
17342       {
17343          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseRequest structure (at %s)\n",\
17344                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17345          break;
17346       }
17347       else
17348       {
17349          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseRequest\n");
17350 #ifdef DEBUG_ASN_PRINT
17351          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17352          {
17353             printf("%x",encBuf[ieIdx]);
17354          }
17355 #endif
17356       }
17357
17358       /* Sending msg */
17359       if(sendF1APMsg() != ROK)
17360       {
17361          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Request failed");
17362          break;
17363       }
17364       ret = ROK;
17365       break;
17366    }while(true);
17367
17368    FreeUeContextReleaseReq(f1apMsg);
17369    return ret;
17370 }
17371 /*****************************************************************i
17372  *
17373  * @brief Free memory allocated for UE Context Release Complete
17374  *
17375  * @details
17376  *
17377  *    Function : FreeUeContextReleaseComplete
17378  *
17379  *    Functionality:
17380  *         - Free memory allocated for UE Context Release Complete
17381  *
17382  * @params[in] F1AP_PDU_t *f1apMsg
17383  * @return void
17384  *
17385  * *************************************************************/
17386 void FreeUeContextReleaseComplete(F1AP_PDU_t *f1apMsg)
17387 {
17388    uint8_t ieIdx;
17389    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17390
17391    if(f1apMsg)
17392    {
17393       if(f1apMsg->choice.successfulOutcome)
17394       {
17395          ueReleaseComplete =&f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17396          if(ueReleaseComplete->protocolIEs.list.array)
17397          {
17398             for(ieIdx=0 ; ieIdx<ueReleaseComplete->protocolIEs.list.count; ieIdx++)
17399             {
17400                DU_FREE(ueReleaseComplete->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseComplete_t));
17401             }
17402             DU_FREE(ueReleaseComplete->protocolIEs.list.array, ueReleaseComplete->protocolIEs.list.size);
17403          }
17404          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17405       }
17406       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
17407    }
17408
17409 }
17410 /*****************************************************************i
17411  *
17412  * @brief Build and Send UE Context Release Complete
17413  *
17414  * @details
17415  *
17416  *    Function : BuildAndSendUeContextReleaseComplete
17417  *
17418  *    Functionality:
17419  *         - Build and Send UE Context Release Complete
17420  *
17421  * @params[in]  cellId,  gnbCuUeF1apId, gnbDuUeF1apId
17422  * @return ROK     - success
17423  *         RFAILED - failure
17424  *
17425  * *************************************************************/
17426 uint8_t BuildAndSendUeContextReleaseComplete(uint16_t cellId, uint32_t gnbCuUeF1apId, uint32_t gnbDuUeF1apId)
17427 {
17428    bool memAllocFail = false;
17429    uint8_t ieIdx =0, ret = RFAILED, elementCnt = 0;
17430    asn_enc_rval_t encRetVal;
17431    F1AP_PDU_t *f1apMsg = NULLP;
17432    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17433
17434    DU_LOG("\nINFO  --> Building the UE Context Release Complete");
17435    do
17436    {
17437       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
17438       if(f1apMsg == NULLP)
17439       {
17440          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for f1apMsg");
17441          break;
17442       }
17443
17444       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
17445       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17446       if(f1apMsg->choice.successfulOutcome == NULLP)
17447       {
17448          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for\
17449                successfulOutcome");
17450          break;
17451       }
17452       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextRelease;
17453       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
17454       f1apMsg->choice.successfulOutcome->value.present = \
17455       SuccessfulOutcome__value_PR_UEContextReleaseComplete;
17456
17457       ueReleaseComplete = &f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17458
17459       elementCnt = 2;
17460       ueReleaseComplete->protocolIEs.list.count = elementCnt;
17461       ueReleaseComplete->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseComplete_t *);
17462
17463       /* Initialize the UE Release Complete members */
17464       DU_ALLOC(ueReleaseComplete->protocolIEs.list.array,ueReleaseComplete->protocolIEs.list.size);
17465       if(ueReleaseComplete->protocolIEs.list.array == NULLP)
17466       {
17467          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE array");
17468          break;
17469       }
17470       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
17471       {
17472          DU_ALLOC(ueReleaseComplete->protocolIEs.list.array[ieIdx],\
17473                sizeof(UEContextReleaseComplete_t));
17474          if(ueReleaseComplete->protocolIEs.list.array[ieIdx] == NULLP)
17475          {
17476             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE\
17477             elements");
17478             memAllocFail = true;
17479             break;
17480          }
17481       }
17482       if(memAllocFail == true)
17483          break;
17484
17485
17486       ieIdx=0;
17487       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
17488       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17489       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present = \
17490       UEContextReleaseCompleteIEs__value_PR_GNB_CU_UE_F1AP_ID;
17491       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
17492
17493       ieIdx++;
17494       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
17495       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17496       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present =\
17497       UEContextReleaseCompleteIEs__value_PR_GNB_DU_UE_F1AP_ID;
17498       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17499
17500       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17501
17502       /* Encode the F1SetupComplete type as APER */
17503       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17504       encBufSize = 0;
17505       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17506       /* Encode results */
17507       if(encRetVal.encoded == ENCODE_FAIL)
17508       {
17509          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseComplete structure (at %s)\n",\
17510                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17511          break;
17512       }
17513       else
17514       {
17515          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseComplete\n");
17516 #ifdef DEBUG_ASN_PRINT
17517          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17518          {
17519             printf("%x",encBuf[ieIdx]);
17520          }
17521 #endif
17522       }
17523
17524       /* Sending msg */
17525       if(sendF1APMsg() != ROK)
17526       {
17527          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Complete failed");
17528          break;
17529       }
17530       ret = ROK;
17531       break;
17532    }while(true);
17533    
17534    if((ret == ROK) && (duCb.actvCellLst[cellId-1]) && (duCb.actvCellLst[cellId-1]->cellStatus == DELETION_IN_PROGRESS) 
17535          && (duCb.actvCellLst[cellId-1]->numActvUes == 0))
17536    {
17537       ret = duSendCellDeletReq(cellId);
17538       if(ret != ROK)
17539       {
17540          DU_LOG("\nERROR  -->  F1AP: BuildAndSendUeContextReleaseComplete(): Failed to process cell\
17541                Delete req for CellId");
17542       }
17543    }
17544    FreeUeContextReleaseComplete(f1apMsg);
17545    return ret;
17546
17547 }
17548
17549 /*******************************************************************
17550 *
17551 * @brief added free part for the memory allocated by aper_decoder 
17552 *
17553 * @details
17554 *
17555 *    Function : freeAperDecodeUeContextReleaseCommand 
17556 *
17557 *    Functionality: added free part for the memory allocated by aper_decoder
17558 *
17559 * @params[in] F1AP_PDU_t *f1apMsg
17560 * @return void
17561 *
17562 * ****************************************************************/
17563 void freeAperDecodeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17564 {
17565    uint8_t ieIdx=0;
17566    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17567
17568    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17569    
17570    if(ueContextReleaseCommand->protocolIEs.list.array)
17571    {
17572       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17573       {
17574          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17575          {
17576             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17577             {
17578                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17579                   break;
17580                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17581                   break;
17582                case ProtocolIE_ID_id_Cause:
17583                   break;
17584                case ProtocolIE_ID_id_RRCContainer:
17585                {
17586                   if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
17587                   {
17588                      free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
17589                   }
17590                   break;
17591                }
17592                default :
17593                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17594                        ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17595                   break;
17596             }
17597          }
17598          free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]);
17599       }
17600       free(ueContextReleaseCommand->protocolIEs.list.array);
17601    }
17602 }
17603 /*******************************************************************
17604 *
17605 * @brief processing of UE Context Release Command
17606 *
17607 * @details
17608 *
17609 *    Function : procF1UeContextReleaseCommand 
17610 *
17611 *    Functionality: processing of UE Context Release Command
17612 *
17613 * @params[in] F1AP_PDU_t *f1apMsg
17614 * @return void
17615 *
17616 * ****************************************************************/
17617 uint8_t procF1UeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17618 {
17619    uint8_t  ieIdx=0, ret=ROK, ueIdx=0;
17620    uint16_t cellIdx =0, cellId = 0;
17621    bool ueIdxFound = false;
17622    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0;
17623    DuUeCb   *duUeCb = NULLP;
17624    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17625
17626    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17627
17628    if(ueContextReleaseCommand->protocolIEs.list.array)
17629    {
17630       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17631       {
17632          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17633          {
17634             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17635             {
17636                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17637                   {
17638                      gnbCuUeF1apId= ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17639                                     value.choice.GNB_CU_UE_F1AP_ID;
17640                      break;
17641                   }
17642
17643                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17644                   {
17645                      gnbDuUeF1apId = ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17646                                      value.choice.GNB_DU_UE_F1AP_ID;
17647                      break;
17648                   }
17649
17650                case ProtocolIE_ID_id_Cause:
17651                   {
17652                      for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
17653                      {
17654                         for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
17655                         {
17656                            if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
17657                                  (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId))
17658                            {
17659                               cellId = duCb.actvCellLst[cellIdx]->cellId;
17660                               duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
17661                               ueIdxFound = true;
17662                               break;
17663                            }
17664                         }
17665                         if(ueIdxFound == true)
17666                         {
17667                            break;
17668                         }
17669                      }
17670                      
17671                      if(!ueIdxFound)
17672                      {
17673                         DU_LOG("\nERROR  -->  F1AP: procF1UeContextReleaseCommand(): Ue Information is not available");
17674                         ret = RFAILED;
17675                      }
17676                      break;
17677                   }
17678
17679                case ProtocolIE_ID_id_RRCContainer:
17680                   {
17681                      if(ueIdxFound == true)  
17682                      {
17683                         DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
17684                         if(duUeCb->f1UeDb)
17685                         {
17686                            memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
17687                            duUeCb->f1UeDb->actionType = UE_CTXT_RELEASE;
17688                            duUeCb->f1UeDb->cellIdx = cellIdx;
17689                            /* Filling Dl RRC Msg Info */
17690                            DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
17691                            if(!duUeCb->f1UeDb->dlRrcMsg)
17692                            {
17693                               DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17694                                     Memory allocation failed ");
17695                               ret = RFAILED;
17696                            }
17697                            else
17698                            {
17699                               duUeCb->f1UeDb->dlRrcMsgPres = true;
17700                               memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
17701                               ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
17702                                     &ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17703                                     value.choice.RRCContainer);
17704                            }
17705
17706                         }
17707                         else
17708                         {
17709                            DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17710                                  Memory allocation failed ");
17711                            ret = RFAILED;
17712
17713                         }
17714                      }
17715                      break;
17716                   }
17717                default :
17718                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17719                         ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17720                   break;
17721             }
17722          }
17723       }
17724    }
17725    if(ret != RFAILED)
17726    {
17727       duProcUeContextReleaseCommand(cellId, duUeCb);
17728    }
17729    freeAperDecodeUeContextReleaseCommand(f1apMsg);
17730    return ret;
17731 }
17732
17733 /**************************************************************
17734  *
17735  * @brief free the memory allocated by aper decoder for paging
17736  *
17737  * @details
17738  *
17739  *    Function : freeAperDecodePagingMsg
17740  *
17741  *    Functionality:
17742  *         - free the memory allocated by aper decoder for
17743  *         the paging f1ap msg
17744  *
17745  * @params[in] Paging_t   *paging
17746  * @return ROK     - success
17747  *         RFAILED - failure
17748  *
17749  ****************************************************************/
17750 void freeAperDecodePagingMsg(Paging_t   *paging)
17751 {
17752    uint8_t ieIdx, cellIdx;
17753    PagingCell_ItemIEs_t *pagingCellItemIes;
17754    PagingCell_Item_t *pagingCellItem;
17755    PagingCell_list_t  *pagingCelllist;
17756
17757    if(paging)
17758    {
17759       if(paging->protocolIEs.list.array)
17760       {
17761          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17762          {
17763             if(paging->protocolIEs.list.array[ieIdx])
17764             {
17765                switch(paging->protocolIEs.list.array[ieIdx]->id)
17766                {
17767                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17768                      {
17769                         free(paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10.buf);
17770                         break;
17771                      }
17772                   case ProtocolIE_ID_id_PagingIdentity:
17773                      {
17774                         if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present == PagingIdentity_PR_cNUEPagingIdentity)
17775                         {
17776                            if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)
17777                            {
17778                               if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->present == \
17779                                     CNUEPagingIdentity_PR_fiveG_S_TMSI)
17780                               {
17781                                  free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->choice.fiveG_S_TMSI.buf);
17782                               }
17783                               free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity);
17784                            }
17785                         }
17786                         break;
17787                      }
17788                   case ProtocolIE_ID_id_PagingCell_List:
17789                      {
17790                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list;
17791                         if(pagingCelllist->list.array)
17792                         {
17793                            for(cellIdx = 0; cellIdx < pagingCelllist->list.count; cellIdx++)
17794                            {
17795                               if(pagingCelllist->list.array[cellIdx])
17796                               {
17797                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellIdx];
17798                                  if(pagingCellItemIes->id == ProtocolIE_ID_id_PagingCell_Item)
17799                                  {
17800                                     pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17801                                     free(pagingCellItem->nRCGI.pLMN_Identity.buf);
17802                                     free(pagingCellItem->nRCGI.nRCellIdentity.buf);
17803                                  }
17804                                  free(pagingCelllist->list.array[cellIdx]);
17805                               }
17806                            }
17807                            free(pagingCelllist->list.array);
17808                         }
17809                         break;
17810                      }
17811                }
17812                free(paging->protocolIEs.list.array[ieIdx]);
17813             }
17814          }
17815          free(paging->protocolIEs.list.array);
17816
17817       }
17818    }
17819 }
17820
17821 /**************************************************************
17822  *
17823  * @brief processing the paging f1ap msg received from CU 
17824  *
17825  * @details
17826  *
17827  *    Function : procPagingMsg
17828  *
17829  *    Functionality:
17830  *         - processing the paging f1ap msg received from CU
17831  *
17832  * @params[in] F1AP_PDU_t *f1apMsg
17833  * @return ROK     - success
17834  *         RFAILED - failure
17835  *
17836  *
17837  ****************************************************************/
17838 uint8_t procPagingMsg(F1AP_PDU_t *f1apMsg) 
17839 {
17840    uint8_t ieIdx = 0, cellListIdx = 0;
17841    uint64_t cellId = 0;
17842    Paging_t   *paging = NULLP;
17843    PagingCell_list_t  *pagingCelllist = NULLP;
17844    PagingCell_ItemIEs_t *pagingCellItemIes = NULLP;
17845    PagingCell_Item_t *pagingCellItem = NULLP;
17846    DuPagingMsg *tmpPagingParam = NULLP;
17847
17848    paging = &f1apMsg->choice.initiatingMessage->value.choice.Paging;
17849    if(paging)
17850    {
17851       if(paging->protocolIEs.list.array)
17852       {
17853          DU_ALLOC(tmpPagingParam, sizeof(DuPagingMsg));
17854          if(tmpPagingParam == NULLP)
17855          {
17856             DU_LOG("\nERROR  --> DU APP : Memory Allocation Failure in procPagingMsg");
17857             freeAperDecodePagingMsg(paging);
17858             return RFAILED;
17859          }
17860          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17861          {
17862             if(paging->protocolIEs.list.array[ieIdx])
17863             {
17864                switch(paging->protocolIEs.list.array[ieIdx]->id)
17865                {
17866                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17867                      {
17868                         bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10,\
17869                                          &tmpPagingParam->pagUeId);
17870                         break;
17871                      }
17872
17873                   case ProtocolIE_ID_id_PagingIdentity:
17874                      {
17875                         switch(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present)
17876                         {
17877                            case PagingIdentity_PR_cNUEPagingIdentity: 
17878                               {
17879                                  if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)  
17880                                  {
17881                                     bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.\
17882                                           cNUEPagingIdentity->choice.fiveG_S_TMSI, &tmpPagingParam->sTmsi);
17883
17884                                  }
17885                                  break;
17886                               }
17887                             case PagingIdentity_PR_rANUEPagingIdentity:
17888                                {
17889                                   /*TODO: This Identifier is specific to RAN Initiated Paging â€“ Connected Mode Paging*/
17890                                   break;
17891                                }
17892                             default:
17893                                {
17894                                   DU_LOG("ERROR  -->  DU APP: Invalid UE Paging Identity, Skipping this Paging Message:");
17895                                   continue;
17896                                }
17897                         }
17898                      }
17899
17900                   case ProtocolIE_ID_id_PagingDRX:
17901                      {
17902                         tmpPagingParam->pagingDrxPres = TRUE;
17903                         tmpPagingParam->pagingDrx = convertPagingCycleEnumToValue(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingDRX);
17904                         break;
17905                      }
17906
17907                   case ProtocolIE_ID_id_PagingPriority:
17908                      {
17909                         tmpPagingParam->pagPriority = paging->protocolIEs.list.array[ieIdx]->value.choice.PagingPriority;
17910                         break;
17911                      }
17912
17913                   case ProtocolIE_ID_id_PagingCell_List:
17914                      {
17915                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list; 
17916                         if(pagingCelllist->list.array)
17917                         {
17918                            for(cellListIdx = 0; cellListIdx < pagingCelllist->list.count; cellListIdx++)
17919                            {
17920                               if(pagingCelllist->list.array[cellListIdx])
17921                               {
17922                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellListIdx];
17923                                  pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17924                                  bitStringToInt(&pagingCellItem->nRCGI.nRCellIdentity, &cellId);
17925                                  if(processPagingMsg(cellId, tmpPagingParam) != ROK)
17926                                  {
17927                                     DU_LOG("\nERROR  --> DU APP : Paging Processing Failed at CellId:%lu",cellId);
17928                                     continue;
17929                                  }
17930                               }
17931                            }
17932                         }
17933                         break;
17934                      }
17935                    default:
17936                      {
17937                          DU_LOG("\nERROR  --> F1AP : Incorrect Paging IE option");
17938                          break;
17939                      }
17940                }
17941             }
17942          }
17943       }
17944    }
17945    DU_FREE(tmpPagingParam, sizeof(DuPagingMsg));
17946    freeAperDecodePagingMsg(paging);
17947   
17948    return ROK;
17949 }
17950
17951 /**************************************************************
17952  *
17953  * @brief Handles received F1AP message and sends back response  
17954  *
17955  * @details
17956  *
17957  *    Function : F1APMsgHdlr
17958  *
17959  *    Functionality:
17960  *         - Decodes received F1AP control message
17961  *         - Prepares response message, encodes and sends to SCTP
17962  *
17963  * @params[in] 
17964  * @return ROK     - success
17965  *         RFAILED - failure
17966  *
17967  * ****************************************************************/
17968 void F1APMsgHdlr(Buffer *mBuf)
17969 {
17970    int i =0;
17971    char *recvBuf =NULLP;
17972    MsgLen copyCnt =0;
17973    MsgLen recvBufLen =0;
17974    F1AP_PDU_t *f1apMsg =NULLP;
17975    asn_dec_rval_t rval; /* Decoder return value */
17976    F1AP_PDU_t f1apasnmsg ;
17977    DU_LOG("\nINFO  -->  F1AP : Received F1AP message buffer");
17978    ODU_PRINT_MSG(mBuf, 0,0);
17979
17980    /* Copy mBuf into char array to decode it */
17981    ODU_GET_MSG_LEN(mBuf, &recvBufLen);
17982    DU_ALLOC(recvBuf, (Size)recvBufLen);
17983
17984    if(recvBuf == NULLP)
17985    {
17986       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed");
17987       return;
17988    }
17989    if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
17990    {
17991       DU_LOG("\nERROR   -->  F1AP : Failed while copying %d", copyCnt);
17992       return;
17993    }
17994
17995 #ifdef DEBUG_ASN_PRINT
17996    printf("\nDEBUG   -->  F1AP : Received flat buffer to be decoded : ");
17997    for(i=0; i< recvBufLen; i++)
17998    {
17999       printf("%x",recvBuf[i]);
18000    }
18001 #endif
18002
18003    /* Decoding flat buffer into F1AP messsage */
18004    f1apMsg = &f1apasnmsg;
18005    memset(f1apMsg, 0, sizeof(F1AP_PDU_t));
18006
18007    rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0);
18008
18009    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
18010    {
18011       DU_LOG("\nERROR  -->  F1AP : ASN decode failed");
18012       return;
18013    }
18014    printf("\n");
18015    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
18016
18017    switch(f1apMsg->present)
18018    {
18019       case F1AP_PDU_PR_successfulOutcome:
18020          {
18021             switch(f1apMsg->choice.successfulOutcome->value.present)
18022             {
18023                case SuccessfulOutcome__value_PR_ResetAcknowledge:
18024                   {
18025                      DU_LOG("\nINFO   -->  F1AP : F1ResetAcknowledge is received successfully ");
18026                      break;
18027                   }
18028                case SuccessfulOutcome__value_PR_F1SetupResponse:
18029                   {                             
18030 #ifndef ODU_TEST_STUB
18031                      procF1SetupRsp(f1apMsg, recvBufLen, recvBuf);
18032 #endif
18033                      break;
18034                   }
18035
18036                case SuccessfulOutcome__value_PR_GNBDUConfigurationUpdateAcknowledge:
18037                   {
18038                      procF1GNBDUCfgUpdAck(f1apMsg);
18039                      break;
18040                   }
18041
18042                default:
18043                   {
18044                      DU_LOG("\nERROR  -->  F1AP : Invalid type of SuccessfulOutcome__value_PR_ResetAcknowledge [%d]",\
18045                            f1apMsg->choice.successfulOutcome->value.present);
18046                      return;
18047                   }
18048             }/* End of switch(successfulOutcome) */
18049             free(f1apMsg->choice.successfulOutcome);
18050             break;
18051          }
18052       case F1AP_PDU_PR_initiatingMessage:
18053          {
18054             switch(f1apMsg->choice.initiatingMessage->value.present)
18055             {
18056                case InitiatingMessage__value_PR_Reset:
18057                   {
18058                      procF1ResetReq(f1apMsg);
18059                      break;
18060                   }
18061                case InitiatingMessage__value_PR_DLRRCMessageTransfer:
18062                   {
18063                      procF1DlRrcMsgTrans(f1apMsg);
18064                      break;
18065                   }
18066                case InitiatingMessage__value_PR_UEContextSetupRequest:
18067                   {
18068                      procF1UeContextSetupReq(f1apMsg);
18069                      break;
18070                   }
18071                case InitiatingMessage__value_PR_UEContextModificationRequest:
18072                   {
18073                      procF1UeContextModificationReq(f1apMsg);
18074                      break;
18075                   }
18076                case InitiatingMessage__value_PR_UEContextReleaseCommand:
18077                   {
18078                       procF1UeContextReleaseCommand(f1apMsg);
18079                       break;
18080                   }
18081                case InitiatingMessage__value_PR_Paging:
18082                   {
18083                      procPagingMsg(f1apMsg);
18084                      break;
18085                   }
18086                default:
18087                   {
18088                      DU_LOG("\nERROR  -->  F1AP : Invalid type of F1AP_PDU_PR_initiatingMessage [%d]",
18089                            f1apMsg->choice.initiatingMessage->value.present);
18090                      return;
18091                   }
18092             }/* End of switch(initiatingMessage) */
18093             free(f1apMsg->choice.initiatingMessage);
18094             break;
18095          }
18096
18097       default:
18098          {
18099             DU_LOG("\nERROR  -->  F1AP : Invalid type of f1apMsg->present [%d]",f1apMsg->present);
18100             return;
18101          }
18102          free(f1apMsg);
18103
18104    }/* End of switch(f1apMsg->present) */
18105    
18106    DU_FREE(recvBuf, (Size)recvBufLen);
18107 } /* End of F1APMsgHdlr */
18108
18109 /**********************************************************************
18110   End of file
18111  **********************************************************************/