[Epic-ID: ODUHIGH-516][Task-ID: ODUHIGH-527] Modifying DU's E2 node configurations
[o-du/l2.git] / src / du_app / du_f1ap_msg_hdl.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /* This file contains F1AP message handler functions */
20 #include "common_def.h"
21 #include "du_tmr.h"
22 #include "ckw.h"
23 #include "ckw.x"
24 #include "kwu.h"
25 #include "kwu.x"
26 #include "lkw.h"
27 #include "lrg.h"
28 #include "legtp.h"
29 #include "lkw.x"
30 #include "lrg.x"
31 #include "F1AP-PDU.h"
32 #include "InitiatingMessage.h"
33 #include "SuccessfulOutcome.h"
34 #include "du_app_mac_inf.h"
35 #include "du_cfg.h"
36 #include "du_app_rlc_inf.h"
37 #include "du_e2ap_mgr.h"
38 #include "du_e2ap_msg_hdl.h"
39 #include "du_mgr_main.h"
40 #include "du_mgr.h"
41 #include "du_utils.h"
42 #include "du_ue_mgr.h"
43 #include "RAT-Type.h"
44 #include "NRFreqInfo.h"
45 #include "NRCGI.h"
46 #include "TDD-Info.h"
47 #include "NR-Mode-Info.h"
48 #include "ServedPLMNs-List.h"
49 #include "GNB-DU-Served-Cells-List.h"
50 #include "Served-Cell-Information.h"
51 #include "ProtocolExtensionContainer.h"
52 #include "RRC-Version.h"
53 #include "FDD-Info.h"
54 #include "FreqBandNrItem.h"
55 #include "ServedPLMNs-Item.h"
56 #include "GNB-DU-Served-Cells-Item.h"
57 #include "SliceSupportItem.h"
58 #include "FeatureSetUplinkPerCC.h"
59 #include "SliceSupportItem.h"
60 #include "Served-Cells-To-Modify-Item.h"
61 #include "Served-Cells-To-Delete-List.h"
62 #include "Served-Cells-To-Delete-Item.h"
63 #include "QoSInformation.h"
64 #include "ULUPTNLInformation-ToBeSetup-List.h"
65 #include "DRB-Information.h"
66 #include "DRBs-ToBeSetup-Item.h"
67 #include "DRBs-ToBeSetupMod-Item.h"
68 #include "DRBs-ToBeModified-Item.h"
69 #include "CUtoDURRCInformation.h"
70 #include "SCell-ToBeSetup-List.h"
71 #include "SRBs-ToBeSetup-List.h"
72 #include "DRBs-ToBeSetup-List.h"
73 #include "SRBs-ToBeSetup-Item.h"
74 #include "DRBs-ToBeModified-List.h"
75 #include "RRCContainer.h"
76 #include "UE-CapabilityRAT-ContainerList.h"
77 #include "DRBs-Setup-List.h"
78 #include "CellGroupConfig.h"
79 #include "ResetAll.h"
80 #include "ResetType.h"
81 #include "Cells-to-be-Activated-List.h"
82 #include "GNB-CU-Name.h"
83 #include "SRBs-SetupMod-List.h"
84 #include "DRBs-SetupMod-List.h"
85 #include "DRBs-ToBeSetupMod-List.h"
86 #include "PagingCell-Item.h"
87 #include "PagingCell-list.h"
88 #include "QoS-Characteristics.h"
89 #include "ULUPTNLInformation-ToBeSetup-Item.h"
90 #include "Flows-Mapped-To-DRB-Item.h"
91 #include "NonDynamic5QIDescriptor.h"
92 #include "Dynamic5QIDescriptor.h"
93 #include "FeatureSetDownlinkPerCC.h"
94 #include "FeatureSets.h"
95 #include "UE-NR-Capability.h"
96 #include "UE-CapabilityRAT-Container.h"
97 #include "UE-CapabilityRAT-ContainerListRRC.h"
98 #include "GNB-DU-System-Information.h"
99 #include "CellGroupConfigRrc.h"
100 #include "MAC-CellGroupConfig.h"
101 #include "SchedulingRequestConfig.h"
102 #include "SchedulingRequestToAddMod.h"
103 #include "BSR-Config.h"
104 #include "TAG-Config.h"
105 #include "TAG.h"
106 #include "PHR-Config.h"
107 #include "RLC-Config.h"
108 #include "UL-AM-RLC.h"
109 #include "DL-AM-RLC.h"
110 #include "LogicalChannelConfig.h"
111 #include "RLC-BearerConfig.h"
112 #include "PhysicalCellGroupConfig.h"
113 #include "SpCellConfig.h"
114 #include "TDD-UL-DL-ConfigDedicated.h"
115 #include "ServingCellConfig.h"
116 #include "ControlResourceSet.h"
117 #include "SearchSpace.h"
118 #include "PDCCH-Config.h"
119 #include "PDSCH-TimeDomainResourceAllocation.h"
120 #include "PDSCH-TimeDomainResourceAllocationList.h"
121 #include "PDSCH-CodeBlockGroupTransmission.h"
122 #include "PDSCH-ServingCellConfig.h"
123 #include "DMRS-DownlinkConfig.h"
124 #include "PDSCH-Config.h"
125 #include "BWP-DownlinkDedicated.h"
126 #include "BWP-Downlink.h"
127 #include "PUSCH-TimeDomainResourceAllocation.h"
128 #include "PUSCH-TimeDomainResourceAllocationList.h"
129 #include "DMRS-UplinkConfig.h"
130 #include "PUSCH-Config.h"
131 #include "SRS-ResourceId.h"
132 #include "SRS-Resource.h"
133 #include "SRS-ResourceSet.h"
134 #include "SRS-Config.h"
135 #include "BWP-UplinkDedicated.h"
136 #include "PUSCH-ServingCellConfig.h"
137 #include "UplinkConfig.h"
138 #include "DUtoCURRCContainer.h"
139 #include "GBR-QoSFlowInformation.h"
140 #include "QoSFlowLevelQoSParameters.h"
141 #include "PUCCH-Config.h"
142 #include "PUCCH-ResourceSet.h"
143 #include "PUCCH-Resource.h"
144 #include "PUCCH-PowerControl.h"
145 #include "P0-PUCCH.h"
146 #include "PUCCH-PathlossReferenceRS.h"
147 #include "PUCCH-format0.h"
148 #include "PUCCH-format1.h"
149 #include "PUCCH-format2.h"
150 #include "PUCCH-format3.h"
151 #include "PUCCH-format4.h"
152 #include "PUCCH-FormatConfig.h"
153 #include "SchedulingRequestResourceConfig.h"
154 #include<ProtocolIE-Field.h>
155 #include "ProtocolExtensionField.h"
156 #include "odu_common_codec.h"
157 #include "du_mgr.h"
158 #include "du_cell_mgr.h"
159 #include "du_f1ap_msg_hdl.h"
160 #include "DRBs-Setup-Item.h"
161 #include "DLUPTNLInformation-ToBeSetup-List.h"
162 #include "DLUPTNLInformation-ToBeSetup-Item.h"
163 #include "UPTransportLayerInformation.h"
164 #include "GTPTunnel.h"
165 #include "SupportedSULFreqBandItem.h"
166 #include "du_f1ap_conversions.h"
167 #include "CNUEPagingIdentity.h"
168 #include "PCCH-Config.h"
169 #include "SCS-SpecificCarrier.h"
170 #include "FrequencyInfoDL.h"
171 #include "DownlinkConfigCommon.h"
172 #include "FrequencyInfoUL.h"
173 #include "UplinkConfigCommon.h"
174 #include "TDD-UL-DL-ConfigCommon.h"
175 #include "RACH-ConfigDedicated.h"
176 #include "CFRA-SSB-Resource.h"
177 #include "BWP-UplinkCommon.h"
178 #include "ReconfigurationWithSync.h"
179 #include "BCCH-DL-SCH-Message.h"
180 #include "du_sys_info_hdl.h"
181 #include "DRX-ConfigRrc.h"
182 #include "MeasurementTimingConfigurationRrc.h"
183 #include "MeasurementTimingConfigurationRrc-IEs.h"
184 #include "MeasTimingList.h"
185 #include "MeasTiming.h"
186 #include "Cells-Status-List.h"
187 #include "Cells-Status-Item.h"
188
189 #ifdef O1_ENABLE
190 #include "CmInterface.h"
191 extern StartupConfig g_cfg;
192 #endif
193
194 DuCfgParams duCfgParam;
195
196 /******************************************************************
197  *
198  * @brief Function to fetch lcId based on DRB Id
199  *
200  * @details
201  *
202  *    Function : fetchLcId
203  *
204  *    @params[in] drbId
205  *
206  *    Functionality: Function to fetch lcId based on DRB Id
207  *
208  * Returns: lcId - SUCCESS
209  *          RFAILED - FAILURE
210  *****************************************************************/
211
212 uint8_t fetchLcId(uint8_t drbId)
213 {
214    uint8_t cellIdx = 0, ueIdx = 0, lcIdx = 0, numLcs = 0, lcId = 0;
215
216    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
217    {
218       for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
219       {
220          if(duCb.actvCellLst[cellIdx] != NULLP)
221          {
222             numLcs = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.numLcs;
223             for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
224             {
225                if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId == drbId && \
226                   duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
227                {
228                   lcId = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId;
229                   return lcId;
230                }
231             }
232          }
233       }
234    }
235    DU_LOG("\nERROR   -->  DU_APP: fetchLcId() failed for drbId %d", drbId);
236    return RFAILED;
237 }
238
239 /*******************************************************************
240 *
241 * @brief Adding F1AP pdu to reserved pdu list
242 *
243 * @details
244 *
245 *    Function : addToReservedF1apPduList 
246 *
247 *    Functionality: Adding F1AP pdu to reserved pdu list.
248 *     These pdu are awaiting aknowledgment from CU
249 *
250 * @params[in] uint8_t transId, F1AP_PDU_t *f1apMsg
251 *
252 * @return ROK - success
253 *         RFAILED - failure
254 *
255 * ****************************************************************/
256 void addToReservedF1apPduList(uint8_t transId, F1AP_PDU_t *f1apPdu)
257 {
258    CmLList         *node = NULLP;
259    ReservedF1apPduInfo *pduInfo = NULLP;
260    DU_ALLOC(pduInfo, sizeof(ReservedF1apPduInfo));
261    if(pduInfo)
262    {
263       DU_ALLOC(node, sizeof(CmLList));
264       if(node)
265       {
266          pduInfo->transId = transId;
267          pduInfo->f1apMsg = (void*) f1apPdu;
268
269          node->node = (PTR)pduInfo;
270          cmLListAdd2Tail(&duCb.reservedF1apPduList, node);
271       }
272    }
273 }
274
275 /*******************************************************************
276 *
277 * @brief searching for F1AP pdu from ReservedF1apPduList 
278 *
279 * @details
280 *
281 *    Function : searchFromReservedF1apPduList 
282 *
283 *    Functionality: searching for F1AP pdu information
284 *
285 * @params[in] uint8_t transId
286 *
287 * @return pointer to F1AP_PDU_t
288 *
289 * ****************************************************************/
290
291 CmLList *searchFromReservedF1apPduList(uint8_t transId)
292 {
293    CmLList         *node;
294    ReservedF1apPduInfo *f1apPdu;
295    if(duCb.reservedF1apPduList.count)
296    {
297       CM_LLIST_FIRST_NODE(&duCb.reservedF1apPduList, node);
298       while(node)
299       {
300          f1apPdu = (ReservedF1apPduInfo*)node->node;
301          if(f1apPdu->transId == transId)
302          {
303             return node;
304          }
305          node = node->next;
306       }
307    }
308    return NULL;
309 }
310
311 /*******************************************************************
312 *
313 * @brief deleting F1AP pdu information from ReservedF1apPduList
314 *
315 * @details
316 *
317 *    Function : deleteFromReservedF1apPduList 
318 *
319 *    Functionality: deleting pdu information from ReservedF1apPduList
320 *
321 * @params[in] CmLList *node 
322 *
323 * @return void 
324 *
325 * ****************************************************************/
326
327 void deleteFromReservedF1apPduList(CmLList *node)
328 {
329    ReservedF1apPduInfo *f1apPdu;
330
331    if(node != NULL)
332    {
333       f1apPdu = (ReservedF1apPduInfo *)node->node;
334       cmLListDelFrm(&duCb.reservedF1apPduList, node);
335       DU_FREE(f1apPdu, sizeof(ReservedF1apPduInfo));
336       DU_FREE(node, sizeof(CmLList));
337       node = NULL;
338    }
339 }
340
341 /*******************************************************************
342  *
343  * @brief Builds Uplink Info for NR 
344  *
345  * @details
346  *
347  *    Function : BuildULNRInfo
348  *
349  *    Functionality: Building NR Uplink Info
350  *
351  * @params[in] NRFreqInfo_t *ulnrfreq
352  * @return ROK     - success
353  *         RFAILED - failure
354  *
355  * ****************************************************************/
356 uint8_t BuildULNRInfo(NRFreqInfo_t *ulnrfreq)
357 {
358    uint8_t idx=0;
359    ulnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
360                        fdd.ulNrFreqInfo.nrArfcn;
361    ulnrfreq->freqBandListNr.list.count = 1;
362    ulnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
363    DU_ALLOC(ulnrfreq->freqBandListNr.list.array,ulnrfreq->freqBandListNr.list.size);
364    if(ulnrfreq->freqBandListNr.list.array == NULLP)
365    {
366       return RFAILED;
367    }
368    for(idx=0;idx<ulnrfreq->freqBandListNr.list.count;idx++)
369    {
370       DU_ALLOC(ulnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
371       if(ulnrfreq->freqBandListNr.list.array[idx] == NULLP)
372       {
373          return RFAILED;
374       }
375    }
376    ulnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
377                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
378                                                                  freqBand[0].nrFreqBand;
379    ulnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
380    return ROK;
381 }
382 /*******************************************************************
383  *
384  * @brief Builds Downlink NR Info 
385  *
386  * @details
387  *
388  *    Function : BuildDLNRInfo
389  *
390  *    Functionality: Building Downlink NR Info
391  *    
392  * @params[in] NRFreqInfo_t *dlnrfreq
393  * @return ROK     - success
394  *         RFAILED - failure
395  *
396  * ****************************************************************/
397 uint8_t BuildDLNRInfo(NRFreqInfo_t *dlnrfreq)
398 {
399    uint8_t idx=0;
400    dlnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
401                        fdd.dlNrFreqInfo.nrArfcn;
402    dlnrfreq->freqBandListNr.list.count = 1;
403    dlnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
404    DU_ALLOC(dlnrfreq->freqBandListNr.list.array,dlnrfreq->freqBandListNr.list.size);
405    if(dlnrfreq->freqBandListNr.list.array == NULLP)
406    {
407       return RFAILED;   
408    }
409    for(idx=0;idx< dlnrfreq->freqBandListNr.list.count;idx++)
410    {
411       DU_ALLOC(dlnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
412       if(dlnrfreq->freqBandListNr.list.array[idx] == NULLP)
413       {
414          return RFAILED;
415       }
416    }   
417    dlnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
418                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
419                                                                  freqBand[0].nrFreqBand;
420    dlnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
421
422    return ROK;
423 }
424
425 /*******************************************************************
426  *
427  * @brief Builds Nrcgi 
428  *
429  * @details
430  *
431  *    Function : BuildNrcgi
432  *
433  *    Functionality: Building the PLMN ID and NR Cell id
434  *
435  * @params[in] NRCGI_t *nrcgi
436  * @return ROK     - success
437  *         RFAILED - failure
438  *
439  * ****************************************************************/
440 uint8_t BuildNrcgi(NRCGI_t *nrcgi)
441 {
442    uint8_t ret;
443    uint8_t byteSize = 5;
444    /* Allocate Buffer Memory */
445    nrcgi->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
446    DU_ALLOC(nrcgi->pLMN_Identity.buf, nrcgi->pLMN_Identity.size);
447    if(nrcgi->pLMN_Identity.buf == NULLP)
448    {
449       return RFAILED;
450    }
451    ret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
452          nrcgi->pLMN_Identity.buf); // Building PLMN function
453    if(ret != ROK)
454    {
455       return RFAILED;
456    }
457    /*nrCellIdentity*/
458    nrcgi->nRCellIdentity.size = byteSize * sizeof(uint8_t);
459    DU_ALLOC(nrcgi->nRCellIdentity.buf, nrcgi->nRCellIdentity.size); 
460    if(nrcgi->nRCellIdentity.buf == NULLP)
461    {
462       return RFAILED;
463    }
464    fillBitString(&nrcgi->nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
465
466    return ROK;
467 }
468 /*******************************************************************
469  *
470  * @brief Builds FiveGStac 
471  *
472  * @details
473  *
474  *    Function : BuildFiveGSTac
475  *
476  *    Functionality: Building the FiveGSTac
477  *
478  * @params[in] OCTET_STRING_t *fivegsTac
479  * @return ROK     - success
480  *         RFAILED - failure
481  *
482  * ****************************************************************/
483 uint8_t BuildFiveGSTac(Served_Cell_Information_t *servcell)
484 {
485    DU_ALLOC(servcell->fiveGS_TAC,sizeof(FiveGS_TAC_t));
486    if(servcell->fiveGS_TAC == NULLP)
487    {
488       return RFAILED;
489    }
490    servcell->fiveGS_TAC->size = 3 * sizeof(uint8_t);
491    DU_ALLOC(servcell->fiveGS_TAC->buf,\
492          sizeof(servcell->fiveGS_TAC->size));
493    if(servcell->fiveGS_TAC->buf == NULLP)
494    {
495       return RFAILED;
496    }
497    servcell->fiveGS_TAC->buf[0] = 0;
498    servcell->fiveGS_TAC->buf[1] = 0;
499    servcell->fiveGS_TAC->buf[2] = duCfgParam.srvdCellLst[0].duCellInfo.tac;
500    return ROK;  
501 }
502
503 /*******************************************************************
504  *
505  * @brief fill nr frequency information
506  *
507  * @details
508  *
509  *    Function : fillNrTddInfo 
510  *
511  *    Functionality: fill nr frequency information
512  *
513  * @params[in] NRFreqInfo_t freqInfo
514  * @return ROK     - success
515  *         RFAILED - failure
516  *
517  * ****************************************************************/
518 uint8_t fillNrTddInfo(TDD_Info_t *tddInfo)
519 {
520    uint8_t elementCnt = 1, freqBandListIdx = 0, supportedBandIdx = 0;
521    NRFreqInfo_t *freqInfo = NULLP;
522
523    if(tddInfo == NULLP)
524    {
525       DU_LOG("\nERROR  --> DU APP : Null pointer received at fillNrTddInfo");
526       return RFAILED;
527    }
528    
529    freqInfo = &tddInfo->nRFreqInfo;
530    freqInfo->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.nrArfcn; 
531
532    freqInfo->freqBandListNr.list.count = elementCnt; 
533    freqInfo->freqBandListNr.list.size = freqInfo->freqBandListNr.list.count  * sizeof(FreqBandNrItem_t *);
534    DU_ALLOC(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
535    if(!freqInfo->freqBandListNr.list.array)
536    {
537       DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
538       return RFAILED;
539    }
540
541    for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
542    {
543       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
544       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx])
545       {
546          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
547          return RFAILED;
548       }
549
550       freqInfo->freqBandListNr.list.array[freqBandListIdx]->freqBandIndicatorNr = duCfgParam.srvdCellLst[0].duCellInfo.\
551       f1Mode.mode.tdd.nrFreqInfo.freqBand[0].nrFreqBand;
552
553       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count = elementCnt;
554       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size = freqInfo->freqBandListNr.list.array[freqBandListIdx]->\
555       supportedSULBandList.list.count * sizeof(SupportedSULFreqBandItem_t*);
556
557       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
558             freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
559       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
560       {
561          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
562          return RFAILED;
563       }
564
565       for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
566       {
567          DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
568                sizeof(SupportedSULFreqBandItem_t));
569          if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx])
570          {
571             DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
572             return RFAILED;
573          }
574
575          freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx]->freqBandIndicatorNr =\
576          duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[0].sulBand[0];
577       }
578    }
579
580    tddInfo->transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrScs;
581    tddInfo->transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrb;
582
583    return ROK;
584 }
585
586 /*******************************************************************
587  *
588  * @brief Builds NR Mode 
589  *
590  * @details
591  *
592  *    Function : BuildNrMode
593  *
594  *    Functionality: Building the NR Mode
595  *
596  * @params[in] NR_Mode_Info_t *fdd
597  * @return ROK     - success
598  *         RFAILED - failure
599  *
600  * ****************************************************************/
601 uint8_t BuildNrMode(NR_Mode_Info_t *mode)
602 {
603    uint8_t BuildDLNRInforet=0;
604    uint8_t BuildULNRInforet=0; 
605    
606 #ifdef NR_TDD
607    mode->present = NR_Mode_Info_PR_tDD;
608 #else
609    mode->present = NR_Mode_Info_PR_fDD;
610 #endif   
611    
612    if(mode->present == NR_Mode_Info_PR_fDD)
613    {
614       DU_ALLOC(mode->choice.fDD,sizeof(FDD_Info_t));
615       if(mode->choice.fDD == NULLP)
616       {
617          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
618          return RFAILED;
619       }
620       BuildULNRInforet = BuildULNRInfo(&mode->choice.fDD->uL_NRFreqInfo);
621       if(BuildULNRInforet != ROK)
622       {
623          DU_LOG("\nERROR  --> Failed to build UlNrFreqInfo");
624          return RFAILED;    
625       }
626       BuildDLNRInforet = BuildDLNRInfo(&mode->choice.fDD->dL_NRFreqInfo);
627       if(BuildDLNRInforet != ROK)
628       {
629          DU_LOG("\nERROR  --> Failed to build DlNrFreqInfo");
630          return RFAILED;
631       }
632       mode->choice.fDD->uL_Transmission_Bandwidth.nRSCS = \
633                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
634                                                           f1Mode.mode.fdd.ulTxBw.nrScs;
635       mode->choice.fDD->uL_Transmission_Bandwidth.nRNRB = \
636                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
637                                                           f1Mode.mode.fdd.ulTxBw.nrb;
638       mode->choice.fDD->dL_Transmission_Bandwidth.nRSCS = \
639                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
640                                                           f1Mode.mode.fdd.dlTxBw.nrScs;
641       mode->choice.fDD->dL_Transmission_Bandwidth.nRNRB = \
642                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
643                                                           f1Mode.mode.fdd.dlTxBw.nrb;
644    }
645    else if(mode->present == NR_Mode_Info_PR_tDD) 
646    {
647       DU_ALLOC(mode->choice.tDD,sizeof(TDD_Info_t));
648       if(mode->choice.tDD == NULLP)
649       {
650          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
651          return RFAILED;
652       }
653
654       if(fillNrTddInfo(mode->choice.tDD) != ROK)
655       {
656          DU_LOG("\nERROR  --> Failed to fill Nr TDD information");
657          return RFAILED;
658       }
659
660    }
661
662    return ROK;
663 }
664 /*******************************************************************
665  *
666  * @brief Builds IE Extensions for Served PLMNs 
667  *
668  * @details
669  *
670  *    Function : BuildExtensions
671  *
672  *    Functionality: Building the IE Extensions
673  *
674  * @params[in] struct ProtocolExtensionContainer_4624P3 *buildextend
675  * @return ROK     - success
676  *         RFAILED - failure
677  *
678  * ****************************************************************/
679 uint8_t BuildExtensions(ProtocolExtensionContainer_4624P3_t **ieExtend)
680 {
681    uint8_t idx=0, plmnidx=0, sliceLstIdx=0;
682    uint8_t elementCnt=0, extensionCnt=0;
683
684    extensionCnt=IE_EXTENSION_LIST_COUNT;
685    DU_ALLOC(*ieExtend,sizeof(ProtocolExtensionContainer_4624P3_t));
686    if((*ieExtend) == NULLP)
687    {
688       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
689       return RFAILED;
690    }
691    (*ieExtend)->list.count = extensionCnt;
692    (*ieExtend)->list.size = \
693                             extensionCnt * sizeof(ServedPLMNs_ItemExtIEs_t *);
694    DU_ALLOC((*ieExtend)->list.array,(*ieExtend)->list.size);
695    if((*ieExtend)->list.array == NULLP)
696    {
697       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
698       return RFAILED;
699    }
700    for(plmnidx=0;plmnidx<extensionCnt;plmnidx++)
701    {
702       DU_ALLOC((*ieExtend)->list.array[plmnidx],\
703             sizeof(ServedPLMNs_ItemExtIEs_t));
704       if((*ieExtend)->list.array[plmnidx] == NULLP)
705       {
706          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
707          return RFAILED;
708       }
709    }
710    
711    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices;
712    idx = 0;
713    (*ieExtend)->list.array[idx]->id = ProtocolIE_ID_id_TAISliceSupportList;
714    (*ieExtend)->list.array[idx]->criticality = Criticality_ignore;
715    (*ieExtend)->list.array[idx]->extensionValue.present = \
716    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
717    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
718       list.count = elementCnt;
719    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
720       list.size = (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
721       list.count * sizeof(SliceSupportItem_t *);
722
723    DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
724          list.array, elementCnt * sizeof(SliceSupportItem_t *));
725    if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
726          list.array == NULLP)
727    {
728       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
729       return RFAILED;
730    }
731
732    for(sliceLstIdx =0; sliceLstIdx<elementCnt; sliceLstIdx++)
733    {
734       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
735             list.array[sliceLstIdx],sizeof(SliceSupportItem_t));
736       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
737             list.array[sliceLstIdx] == NULLP) 
738       {
739          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
740          return RFAILED;
741       }
742       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
743          list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
744       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
745             .list.array[sliceLstIdx]->sNSSAI.sST.buf,(*ieExtend)->list.array[idx]->\
746             extensionValue.choice.SliceSupportList.\
747             list.array[sliceLstIdx]->sNSSAI.sST.size);
748       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
749             .list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
750       {
751          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
752          return RFAILED;
753       }
754       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
755          list.array[sliceLstIdx]->sNSSAI.sST.buf[0] = duCfgParam.srvdCellLst[0].duCellInfo.\
756          cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
757       
758       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
759             list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
760       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
761             list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
762       {
763          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
764          return RFAILED;
765       }
766       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
767          list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
768       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
769             list.array[sliceLstIdx]->sNSSAI.sD->buf, (*ieExtend)->list.array[idx]->extensionValue.choice.\
770             SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
771       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
772             list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
773       {
774          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
775          return RFAILED;
776       }
777       memcpy((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
778       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[0].duCellInfo.\
779       cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sd, (*ieExtend)->list.array[idx]->\
780       extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
781    }
782    return ROK;
783 }
784 /*******************************************************************
785  *
786  * @brief Builds Served PLMN 
787  *
788  * @details
789  *
790  *    Function : BuildServedPlmn
791  *
792  *    Functionality: Building the Served PLMN
793  *
794  * @params[in] GNB_DU_Served_Cells_Item_t *srvCellItem
795  * @return ROK     - success
796  *         RFAILED - failure
797  *
798  * ****************************************************************/
799 uint8_t  BuildServedPlmn(ServedPLMNs_List_t *srvplmn)
800 {  
801    uint8_t  plmnidx;
802    uint8_t  servPlmnCnt=1;
803    uint8_t buildPlmnIdret=0;
804    uint8_t BuildExtensionsret=0;
805    srvplmn->list.count = servPlmnCnt;
806    srvplmn->list.size = \
807                         servPlmnCnt*sizeof(ServedPLMNs_Item_t *);
808    DU_ALLOC(srvplmn->list.array,srvplmn->list.size);
809    if(srvplmn->list.array == NULLP)
810    {
811       return RFAILED;
812    }
813    for(plmnidx=0; plmnidx<servPlmnCnt; plmnidx++)
814    {   
815       DU_ALLOC(srvplmn->list.array[plmnidx],\
816             sizeof(ServedPLMNs_Item_t));
817       if(srvplmn->list.array[plmnidx] == NULLP)
818       {
819          return RFAILED;
820       }  
821    }
822    srvplmn->list.array[0]->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
823    DU_ALLOC(srvplmn->list.array[0]->pLMN_Identity.buf, srvplmn->list.array[0]->pLMN_Identity.size);
824    buildPlmnIdret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
825          srvplmn->list.array[0]->pLMN_Identity.buf);
826    if(buildPlmnIdret!= ROK)
827    {
828       return RFAILED;
829    }
830    BuildExtensionsret = BuildExtensions(&srvplmn->list.array[0]->iE_Extensions);
831    if(BuildExtensionsret!= ROK)
832    {
833       return RFAILED;
834    }
835    return ROK;
836 }
837
838 /*******************************************************************
839  *
840  * @brief Frees Measurement Timing configuration 
841  *
842  * @details
843  *
844  *    Function : FreeMeasTimingConf
845  *
846  *    Functionality: Frees Timing Configuration
847  *
848  * @params[in] MeasurementTimingConfigurationRrc_t measTimingConfRrc
849  * @return ROK     - success
850  *         RFAILED - failure
851  *
852  * ****************************************************************/
853 void FreeMeasTimingConf(MeasurementTimingConfigurationRrc_t   measTimingConfRrc)
854 {
855    uint8_t measIeIdx = 0;
856    MeasurementTimingConfigurationRrc_IEs_t  *measTimingConfIEs = NULLP;
857
858    if(measTimingConfRrc.criticalExtensions.choice.c1)
859    {
860       if(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf)
861       {
862          measTimingConfIEs = measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf;
863          if(measTimingConfIEs->measTiming)
864          {
865             if(measTimingConfIEs->measTiming->list.array)
866             {
867                for(measIeIdx = 0; measIeIdx < measTimingConfIEs->measTiming->list.count; measIeIdx++)
868                {
869                   if(measTimingConfIEs->measTiming->list.array[measIeIdx])
870                   {
871                      DU_FREE(measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming, sizeof(struct MeasTiming__frequencyAndTiming));
872                      DU_FREE(measTimingConfIEs->measTiming->list.array[measIeIdx], sizeof(MeasTiming_t));
873                   }
874                }
875                DU_FREE(measTimingConfIEs->measTiming->list.array, measTimingConfIEs->measTiming->list.size);
876             }
877             DU_FREE(measTimingConfIEs->measTiming, sizeof(MeasTimingList_t));
878          }
879          DU_FREE(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf, sizeof(MeasurementTimingConfigurationRrc_IEs_t));
880       }
881       DU_FREE(measTimingConfRrc.criticalExtensions.choice.c1, sizeof(struct MeasurementTimingConfigurationRrc__criticalExtensions__c1));
882    }
883 }
884
885 /*******************************************************************
886  *
887  * @brief Builds MEasuerment Timing Configuration
888  *
889  * @details
890  *
891  *    Function : BuildMeasTimingConf
892  *
893  *    Functionality: Building Measurement Timing Configuration
894  *
895  * @params[in] Pointer to octet string to store Measurement timing
896  *             Configuration
897  * @return ROK     - success
898  *         RFAILED - failure
899  *
900  * ****************************************************************/
901 uint8_t BuildMeasTimingConf(OCTET_STRING_t *measTimingConf)
902 {
903    uint8_t ret = RFAILED;
904    uint8_t elementCnt = 0;
905    uint8_t measIeIdx = 0;
906    asn_enc_rval_t encRetVal;
907    MeasurementTimingConfigurationRrc_t   measTimingConfRrc;
908    MeasurementTimingConfigurationRrc_IEs_t  *measTimingConfIEs = NULLP;
909    struct MeasTiming__frequencyAndTiming  *freqAndTiming = NULLP;
910
911    while(true)
912    {
913       measTimingConfRrc.criticalExtensions.present = MeasurementTimingConfigurationRrc__criticalExtensions_PR_c1;
914       DU_ALLOC(measTimingConfRrc.criticalExtensions.choice.c1, sizeof(struct MeasurementTimingConfigurationRrc__criticalExtensions__c1));
915       if(!measTimingConfRrc.criticalExtensions.choice.c1)
916       {
917          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for critical extension choice C1");
918          break;
919       }
920       measTimingConfRrc.criticalExtensions.choice.c1->present = MeasurementTimingConfigurationRrc__criticalExtensions__c1_PR_measTimingConf;
921
922       DU_ALLOC(measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf, sizeof(MeasurementTimingConfigurationRrc_IEs_t));
923       if(!measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf)
924       {
925          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for measTimingConf");
926          break;
927       }
928       measTimingConfIEs = measTimingConfRrc.criticalExtensions.choice.c1->choice.measTimingConf;
929
930       DU_ALLOC(measTimingConfIEs->measTiming, sizeof(MeasTimingList_t));
931       if(!measTimingConfIEs->measTiming)
932       {
933          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList");
934          break;
935       }
936
937       elementCnt = 1;  
938       measTimingConfIEs->measTiming->list.count = elementCnt;
939       measTimingConfIEs->measTiming->list.size = elementCnt * sizeof(MeasTiming_t *);
940       DU_ALLOC(measTimingConfIEs->measTiming->list.array, measTimingConfIEs->measTiming->list.size);
941       if(!measTimingConfIEs->measTiming->list.array)
942       {
943          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList array");
944          break;
945       }
946
947       for(measIeIdx = 0; measIeIdx < elementCnt; measIeIdx++)
948       {
949          DU_ALLOC(measTimingConfIEs->measTiming->list.array[measIeIdx], sizeof(MeasTiming_t));
950          if(!measTimingConfIEs->measTiming->list.array[measIeIdx])
951          {
952             DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for MeasTimingList array index %d", measIeIdx);
953             break;
954          }
955       }
956       if(measIeIdx < elementCnt)
957       {
958          break;
959       }
960
961       measIeIdx = 0;
962       DU_ALLOC(measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming, sizeof(struct MeasTiming__frequencyAndTiming));
963       if(!measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming)
964       {
965          DU_LOG("ERROR  --> DU_APP : BuildMeasTimingConf(): Memory allocation failure for frequencyAndTiming");
966          break;
967       }
968       freqAndTiming = measTimingConfIEs->measTiming->list.array[measIeIdx]->frequencyAndTiming;
969       freqAndTiming->carrierFreq = MEAS_TIMING_ARFCN;
970       freqAndTiming->ssbSubcarrierSpacing = duCfgParam.macCellCfg.ssbCfg.scsCmn;
971       freqAndTiming->ssb_MeasurementTimingConfiguration.periodicityAndOffset.present = duCfgParam.macCellCfg.ssbCfg.ssbPeriod + 1;
972       freqAndTiming->ssb_MeasurementTimingConfiguration.periodicityAndOffset.choice.sf20 = duCfgParam.macCellCfg.ssbCfg.ssbScOffset;
973       freqAndTiming->ssb_MeasurementTimingConfiguration.duration = duCfgParam.srvdCellLst[0].duCellInfo.measTimeCfgDuration;
974
975       /* Encode the F1SetupRequest type as APER */
976       xer_fprint(stdout, &asn_DEF_MeasurementTimingConfigurationRrc, &measTimingConfRrc);
977
978       memset(encBuf, 0, ENC_BUF_MAX_LEN);
979       encBufSize = 0;
980       encRetVal = uper_encode(&asn_DEF_MeasurementTimingConfigurationRrc, 0, &measTimingConfRrc, PrepFinalEncBuf, encBuf);
981
982       /* Encode results */
983       if(encRetVal.encoded == ENCODE_FAIL)
984       {     
985          DU_LOG("\nERROR  -->  F1AP : Could not encode Measurement Timing Configuration structure (at %s)\n",\
986                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
987          break;
988       }     
989       else  
990       {     
991          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Measurement Timing Configuration \n");
992 #ifdef DEBUG_ASN_PRINT
993          for(measIeIdx=0; measIeIdx< encBufSize; measIeIdx++)
994          {
995             printf("%x",encBuf[measIeIdx]);
996          }
997 #endif
998
999          measTimingConf->size = encBufSize;
1000          DU_ALLOC(measTimingConf->buf, encBufSize);
1001          if(measTimingConf->buf == NULLP)
1002          {
1003             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed for MeasurementTimingConfiguration buffer");
1004             return RFAILED;
1005          }
1006          memcpy(measTimingConf->buf, &encBuf, encBufSize);
1007
1008          FreeMeasTimingConf(measTimingConfRrc);
1009
1010          ret = ROK;
1011          break;
1012       }
1013    }
1014    return ret;
1015 }
1016
1017 /*******************************************************************
1018  *
1019  * @brief Builds Served Cell List
1020  *
1021  * @details
1022  *
1023  *    Function : BuildServedCellList
1024  *
1025  *    Functionality: Building Served Cell List
1026  *
1027  * @params[in] PLMNID plmn
1028  * @return ROK     - success
1029  *         RFAILED - failure
1030  *
1031  * ****************************************************************/
1032
1033 uint8_t BuildServedCellList(GNB_DU_Served_Cells_List_t *duServedCell)
1034 {
1035    uint8_t  BuildNrcgiret=0;
1036    uint8_t  BuildFiveGSTacret=0;
1037    uint8_t  BuildServedPlmnret=0;
1038    uint8_t  BuildNrModeret=0;
1039    uint8_t  idx;
1040    uint8_t  plmnidx;
1041    uint8_t  plmnCnt=1;
1042    GNB_DU_Served_Cells_Item_t *srvCellItem;
1043    duServedCell->list.size = plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t *);
1044    duServedCell->list.count = plmnCnt;
1045
1046    DU_ALLOC(duServedCell->list.array, duServedCell->list.size);
1047    if(duServedCell->list.array == NULLP)
1048    {
1049       return RFAILED;
1050    }
1051    for(plmnidx=0; plmnidx<plmnCnt; plmnidx++)
1052    {
1053       DU_ALLOC(duServedCell->list.array[plmnidx],\
1054             sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1055       if(duServedCell->list.array[plmnidx] == NULLP)
1056       {
1057          return RFAILED;
1058       }
1059    }
1060    idx = 0;
1061    duServedCell->list.array[idx]->id = ProtocolIE_ID_id_GNB_DU_Served_Cells_Item;
1062    duServedCell->list.array[idx]->criticality = Criticality_reject;
1063    duServedCell->list.array[idx]->value.present = \
1064                                                   GNB_DU_Served_Cells_ItemIEs__value_PR_GNB_DU_Served_Cells_Item;
1065    srvCellItem = \
1066                  &duServedCell->list.array[idx]->value.choice.GNB_DU_Served_Cells_Item;
1067    /*nRCGI*/
1068    BuildNrcgiret = BuildNrcgi(&srvCellItem->served_Cell_Information.nRCGI);
1069    if(BuildNrcgiret != ROK)
1070    {
1071       return RFAILED;
1072    }
1073    /*nRPCI*/
1074    srvCellItem->served_Cell_Information.nRPCI = \
1075                                                 duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
1076
1077    /* fiveGS_TAC */
1078    BuildFiveGSTacret = BuildFiveGSTac(&srvCellItem->served_Cell_Information);
1079    if(BuildFiveGSTacret != ROK)
1080    {
1081       return RFAILED;
1082    }
1083
1084    /* Served PLMNs */
1085    BuildServedPlmnret = BuildServedPlmn(&srvCellItem->served_Cell_Information.servedPLMNs);
1086    if(BuildServedPlmnret !=ROK)
1087    {
1088       return RFAILED;
1089    }
1090
1091    /* nR Mode Info with FDD/TDD */
1092    BuildNrModeret = BuildNrMode(&srvCellItem->served_Cell_Information.nR_Mode_Info);
1093    if(BuildNrModeret != ROK)
1094    {
1095       return RFAILED;
1096    }
1097
1098    /*Measurement timing Config*/
1099    if(BuildMeasTimingConf(&srvCellItem->served_Cell_Information.measurementTimingConfiguration) != ROK)
1100       return RFAILED;
1101
1102    /* GNB DU System Information */
1103    DU_ALLOC(srvCellItem->gNB_DU_System_Information,
1104          sizeof(GNB_DU_System_Information_t));
1105    if(!srvCellItem->gNB_DU_System_Information)
1106    {
1107       return RFAILED;
1108    }
1109    /* MIB */
1110    srvCellItem->gNB_DU_System_Information->mIB_message.size = duCfgParam.srvdCellLst[0].duSysInfo.mibLen;
1111    DU_ALLOC(srvCellItem->gNB_DU_System_Information->mIB_message.buf,
1112          srvCellItem->gNB_DU_System_Information->mIB_message.size);
1113    if(!srvCellItem->gNB_DU_System_Information->mIB_message.buf)
1114    {
1115       return RFAILED;
1116    }
1117    memcpy(srvCellItem->gNB_DU_System_Information->mIB_message.buf, duCfgParam.srvdCellLst[0].duSysInfo.mibMsg, \
1118          srvCellItem->gNB_DU_System_Information->mIB_message.size);
1119
1120    /* SIB1 */
1121    srvCellItem->gNB_DU_System_Information->sIB1_message.size =\
1122                                                               duCfgParam.srvdCellLst[0].duSysInfo.sib1Len;
1123
1124    DU_ALLOC(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,
1125          srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1126    if(!srvCellItem->gNB_DU_System_Information->sIB1_message.buf)
1127    {
1128       return RFAILED;
1129    }
1130    for(int x=0; x<srvCellItem->gNB_DU_System_Information->sIB1_message.size; x++)
1131    {
1132       srvCellItem->gNB_DU_System_Information->sIB1_message.buf[x]=\
1133                                                                   duCfgParam.srvdCellLst[0].duSysInfo.sib1Msg[x];
1134    }
1135    return ROK; 
1136 }                                                                                                                  
1137 /*******************************************************************
1138  *
1139  * @brief Builds RRC Version 
1140  *
1141  * @details
1142  *
1143  *    Function : BuildRrcVer
1144  *
1145  *    Functionality: Building RRC Version
1146  *
1147  * @params[in] int idx,int elementCnt,RRC_Version_t *rrcver
1148  * @return ROK     - success
1149  *         RFAILED - failure
1150  *
1151  * ****************************************************************/
1152 uint8_t BuildRrcVer(RRC_Version_t *rrcVer)
1153 {
1154    uint8_t rrcExt;
1155    uint8_t rrcLatest;
1156    rrcVer->latest_RRC_Version.size = sizeof(uint8_t);
1157    DU_ALLOC(rrcVer->latest_RRC_Version.buf,sizeof(uint8_t));
1158    if(rrcVer->latest_RRC_Version.buf == NULLP)
1159    {
1160       return RFAILED;
1161    }
1162    rrcVer->latest_RRC_Version.buf[0] = 0;
1163    rrcVer->latest_RRC_Version.bits_unused = 5;
1164    DU_ALLOC(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1165    if(rrcVer->iE_Extensions == NULLP)
1166    {  
1167       return RFAILED;
1168    }
1169    rrcVer->iE_Extensions->list.count = 1;
1170    rrcVer->iE_Extensions->list.size = sizeof(RRC_Version_ExtIEs_t *);
1171    DU_ALLOC(rrcVer->iE_Extensions->list.array,rrcVer->iE_Extensions->list.size);
1172    if(rrcVer->iE_Extensions->list.array == NULLP)
1173    {
1174       return RFAILED;
1175    }
1176    rrcExt = 0;
1177    DU_ALLOC(rrcVer->iE_Extensions->list.array[0],\
1178          sizeof(RRC_Version_ExtIEs_t));
1179    if(rrcVer->iE_Extensions->list.array[0] == NULLP)
1180    {
1181       return RFAILED;
1182    }
1183    rrcVer->iE_Extensions->list.array[rrcExt]->id = \
1184                                                    ProtocolIE_ID_id_latest_RRC_Version_Enhanced;
1185    rrcVer->iE_Extensions->list.array[rrcExt]->criticality = Criticality_reject;
1186    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.present =\
1187                                                                       RRC_Version_ExtIEs__extensionValue_PR_Latest_RRC_Version_Enhanced;
1188    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1189       .Latest_RRC_Version_Enhanced.size = 3*sizeof(uint8_t);
1190    DU_ALLOC(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1191          .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1192          array[rrcExt]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1193    if(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
1194          .Latest_RRC_Version_Enhanced.buf == NULLP)
1195    {
1196       return RFAILED;
1197    }
1198    rrcLatest = 0;
1199    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1200       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 15;
1201    rrcLatest++;
1202    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1203       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 5;
1204    rrcLatest++;
1205    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
1206       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 0;
1207    return ROK;
1208 }
1209 /*******************************************************************
1210  *
1211  * @brief Sends F1 msg over SCTP
1212  *
1213  * @details
1214  *
1215  *    Function : sendF1APMsg
1216  *
1217  *    Functionality: Sends F1 msg over SCTP
1218  *
1219  * @params[in] Region region
1220  *             Pool pool
1221  * @return ROK     - success
1222  *         RFAILED - failure
1223  *
1224  * ****************************************************************/
1225 uint8_t sendF1APMsg()
1226 {
1227    Buffer *mBuf = NULLP;
1228   
1229    if(ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) == ROK)
1230    {
1231       if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
1232       {
1233             ODU_PRINT_MSG(mBuf, 0,0);
1234
1235             if(sctpSend(mBuf, F1_INTERFACE) != ROK)
1236             {
1237                DU_LOG("\nERROR  -->  F1AP : SCTP Send failed");
1238                ODU_PUT_MSG_BUF(mBuf);
1239                return RFAILED;
1240             }
1241       }
1242       else
1243       {
1244          DU_LOG("\nERROR  -->  F1AP : ODU_ADD_POST_MSG_MULT failed");
1245          ODU_PUT_MSG_BUF(mBuf);
1246          return RFAILED;
1247       }
1248       ODU_PUT_MSG_BUF(mBuf);
1249    }
1250    else
1251    {
1252       DU_LOG("\nERROR  -->  F1AP : Failed to allocate memory");
1253       return RFAILED;
1254    }
1255    return ROK; 
1256 } /* sendF1APMsg */
1257
1258 /*******************************************************************
1259  *
1260  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1261  *
1262  * @details
1263  *
1264  *    Function :  FreeRrcVer
1265  *
1266  *    Functionality: deallocating the memory of function BuildRrcVer
1267  *
1268  * @params[in] RRC_Version_t *rrcVer
1269  * 
1270  * @return void
1271  *
1272  *****************************************************************/
1273 void FreeRrcVer(RRC_Version_t *rrcVer)
1274 {
1275    if(rrcVer->latest_RRC_Version.buf != NULLP)
1276    {
1277       if(rrcVer->iE_Extensions != NULLP)
1278       {
1279          if(rrcVer->iE_Extensions->list.array != NULLP)
1280          {
1281             if(rrcVer->iE_Extensions->list.array[0] != NULLP)
1282             {
1283                if(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf
1284                      != NULLP)
1285                {
1286                   DU_FREE(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice\
1287                         .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1288                         array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1289                }
1290                DU_FREE(rrcVer->iE_Extensions->list.array[0],sizeof(RRC_Version_ExtIEs_t));
1291             }
1292             DU_FREE(rrcVer->iE_Extensions->list.array,sizeof(RRC_Version_ExtIEs_t*));
1293          }
1294          DU_FREE(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1295       }
1296       DU_FREE(rrcVer->latest_RRC_Version.buf,rrcVer->latest_RRC_Version.size);
1297    }
1298 }
1299
1300 /*******************************************************************
1301  *
1302  * @brief Deallocating memory of TDD NrFreqInfo 
1303  *
1304  * @details
1305  *
1306  *    Function : freeTddNrFreqInfo 
1307  *
1308  *    Functionality: freeTddNrFreqInfo 
1309  *
1310  * @params[in]  F1AP_PDU_t *f1apDuCfg
1311  *
1312  * @return ROK     - void
1313  *
1314  * ****************************************************************/
1315 void freeTddNrFreqInfo(NRFreqInfo_t *freqInfo)
1316 {
1317    uint8_t freqBandListIdx = 0, supportedBandIdx = 0;
1318
1319    if(freqInfo->freqBandListNr.list.array)
1320    {
1321       for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
1322       {
1323          if(freqInfo->freqBandListNr.list.array[freqBandListIdx])
1324          {
1325             if(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
1326             {
1327                for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
1328                {
1329                   DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
1330                         sizeof(SupportedSULFreqBandItem_t));
1331                }
1332                DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
1333                      freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
1334
1335             }
1336             DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
1337          }
1338       }
1339       DU_FREE(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
1340    }
1341 }
1342
1343 /*******************************************************************
1344  *
1345  * @brief Deallocating memory allocated for Nr fdd frequencey mode 
1346  *
1347  * @details
1348  *
1349  *    Function : freeFddNrFreqInfo 
1350  *
1351  *    Functionality:Free memory allocated for Nr fdd frequencey mode 
1352  *
1353  * @params[in]  
1354  *
1355  * @return ROK     - void
1356  *
1357  * ****************************************************************/
1358 void freeFddNrFreqInfo(FDD_Info_t *fDD)
1359 {
1360    uint8_t arrIdx =0;
1361
1362    if(fDD != NULLP)
1363    {
1364       if(fDD->uL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1365       {
1366          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.\
1367                array[arrIdx], sizeof(FreqBandNrItem_t));
1368          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.array, \
1369                fDD->uL_NRFreqInfo.freqBandListNr.list.size);
1370       }
1371
1372       if(fDD->dL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1373       {
1374          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.\
1375                array[arrIdx], sizeof(FreqBandNrItem_t));
1376          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.array,\
1377                fDD->dL_NRFreqInfo.freqBandListNr.list.size);
1378       }
1379       DU_FREE(fDD,sizeof(FDD_Info_t));
1380    }
1381 }
1382
1383 /*******************************************************************
1384  *
1385  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1386  *
1387  * @details
1388  *
1389  *    Function :  FreeServedCellList
1390  *
1391  *    Functionality:  deallocating the memory of function BuildServedCellList
1392
1393  *
1394  * @params[in] GNB_DU_Served_Cells_List_t *duServedCell
1395  *
1396  * @return void
1397  *
1398  * ****************************************************************/
1399 void FreeServedCellList( GNB_DU_Served_Cells_List_t *duServedCell)
1400 {
1401    uint8_t   plmnCnt= 1;
1402    uint8_t  extensionCnt=IE_EXTENSION_LIST_COUNT;
1403    uint8_t  plmnIdx=0, sliceIdx=0;
1404    GNB_DU_Served_Cells_Item_t *srvCellItem;
1405    ServedPLMNs_Item_t  *servedPlmnItem;
1406    SliceSupportItem_t  *sliceSupportItem;
1407
1408    if(duServedCell->list.array!=NULLP)
1409    {
1410       if(duServedCell->list.array[0]!=NULLP)
1411       {
1412          srvCellItem= &duServedCell->list.array[0]->value.choice.GNB_DU_Served_Cells_Item;
1413
1414          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1415                srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.size * sizeof(uint8_t));
1416          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1417                srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.size * sizeof(uint8_t));
1418
1419          if(srvCellItem->served_Cell_Information.fiveGS_TAC!=NULLP)
1420          {
1421             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC->buf,\
1422                   sizeof(srvCellItem->served_Cell_Information.fiveGS_TAC->size));
1423             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC,sizeof(FiveGS_TAC_t));
1424          }
1425
1426          if(srvCellItem->served_Cell_Information.servedPLMNs.list.array!=NULLP)
1427          {
1428             if(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx] != NULLP)
1429             {
1430                servedPlmnItem = srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx];
1431                DU_FREE(servedPlmnItem->pLMN_Identity.buf, servedPlmnItem->pLMN_Identity.size);
1432
1433                if(servedPlmnItem->iE_Extensions != NULLP)
1434                {
1435                   if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1436                   {
1437                      if(servedPlmnItem->iE_Extensions->list.array[0] != NULLP)
1438                      {
1439                         if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1440                               SliceSupportList.list.array != NULLP)
1441                         {
1442                            for(sliceIdx =0; sliceIdx<servedPlmnItem->iE_Extensions->list.array[0]->\
1443                                  extensionValue.choice.SliceSupportList.list.count; sliceIdx++)
1444                            {
1445                               if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1446                                     SliceSupportList.list.array[sliceIdx] != NULLP)
1447                               {
1448                                  sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[0]->\
1449                                                     extensionValue.choice.SliceSupportList.list.array[sliceIdx];
1450
1451                                  DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sizeof(uint8_t));
1452
1453                                  if(sliceSupportItem->sNSSAI.sD != NULLP)
1454                                  {
1455                                     DU_FREE(sliceSupportItem->sNSSAI.sD->buf,\
1456                                           sliceSupportItem->sNSSAI.sD->size);
1457                                     DU_FREE(sliceSupportItem->sNSSAI.sD, sizeof(OCTET_STRING_t));
1458                                  }
1459
1460                                  DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.\
1461                                        choice.SliceSupportList.list.array[sliceIdx], sizeof(SliceSupportItem_t));
1462                               }
1463                            }
1464                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1465                                  SliceSupportList.list.array, servedPlmnItem->iE_Extensions->list.array[0]->\
1466                                  extensionValue.choice.SliceSupportList.list.size);
1467                         }
1468                         DU_FREE(servedPlmnItem->iE_Extensions->list.array[0],\
1469                               sizeof(ServedPLMNs_ItemExtIEs_t));
1470                      }
1471                      DU_FREE(servedPlmnItem->iE_Extensions->list.array,\
1472                            extensionCnt*sizeof(ServedPLMNs_ItemExtIEs_t*));
1473                   }
1474                   DU_FREE(servedPlmnItem->iE_Extensions, sizeof(ProtocolExtensionContainer_4624P3_t));
1475                }
1476                DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx],\
1477                      sizeof(ServedPLMNs_Item_t));
1478             }
1479             DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array,\
1480                   sizeof(ServedPLMNs_Item_t *));
1481          }
1482
1483          if(srvCellItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1484          {
1485             freeFddNrFreqInfo(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1486          }
1487          else   
1488          {
1489             if(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD != NULLP)
1490             {
1491                freeTddNrFreqInfo(&srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1492                DU_FREE(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1493             }
1494          }
1495          
1496          DU_FREE(srvCellItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1497                srvCellItem->served_Cell_Information.measurementTimingConfiguration.size);
1498
1499          if(srvCellItem->gNB_DU_System_Information != NULLP)
1500          {
1501             if(srvCellItem->gNB_DU_System_Information->mIB_message.buf != NULLP)
1502             {
1503                DU_FREE(srvCellItem->gNB_DU_System_Information->mIB_message.buf,\
1504                      srvCellItem->gNB_DU_System_Information->mIB_message.size);
1505             }
1506
1507             if(srvCellItem->gNB_DU_System_Information->sIB1_message.buf != NULLP)
1508             { 
1509                DU_FREE(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,\
1510                      srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1511             }
1512
1513             DU_FREE(srvCellItem->gNB_DU_System_Information, sizeof(GNB_DU_System_Information_t));
1514          }
1515
1516          DU_FREE(duServedCell->list.array[0], sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1517       }
1518       DU_FREE(duServedCell->list.array, plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t*));
1519    }
1520 }
1521
1522 /*******************************************************************
1523  *
1524  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1525  *
1526  * @details
1527  *
1528  *    Function :  FreeF1SetupReq
1529  *
1530  *    Functionality:  deallocating the memory of function BuildAndSendF1SetupReq
1531  *
1532  * @params[in] F1AP_PDU_t *f1apMsg
1533  *
1534  * @return void
1535  *
1536  * ****************************************************************/
1537 void FreeF1SetupReq(F1AP_PDU_t *f1apMsg)
1538 {
1539    uint8_t ieIdx, ieIdx2;
1540    F1SetupRequest_t *f1SetupReq=NULLP;
1541
1542    if(f1apMsg != NULLP)
1543    {
1544       if(f1apMsg->choice.initiatingMessage != NULLP)
1545       {
1546          f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1547          if(f1SetupReq->protocolIEs.list.array != NULLP)
1548          {
1549             for(ieIdx = 0; ieIdx < f1SetupReq->protocolIEs.list.count; ieIdx++)
1550             {
1551                if(f1SetupReq->protocolIEs.list.array[ieIdx] != NULLP)
1552                {
1553                   switch(f1SetupReq->protocolIEs.list.array[ieIdx]->id)
1554                   {
1555                      case ProtocolIE_ID_id_TransactionID:
1556                         break;
1557                      case ProtocolIE_ID_id_gNB_DU_ID:
1558                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1559                               f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1560                         break;
1561                      case ProtocolIE_ID_id_gNB_DU_Name:
1562                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,\
1563                               strlen((char *)duCfgParam.duName));
1564                         break;
1565                      case ProtocolIE_ID_id_gNB_DU_Served_Cells_List:
1566                         FreeServedCellList(&f1SetupReq->protocolIEs.list.\
1567                               array[ieIdx]->value.choice.GNB_DU_Served_Cells_List);
1568                         break;
1569                      case ProtocolIE_ID_id_GNB_DU_RRC_Version:
1570                         FreeRrcVer(&f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version);
1571                         break;
1572                      default:
1573                         DU_LOG("\nERROR  -->  Invalid Event Type %ld", f1SetupReq->protocolIEs.list.array[ieIdx]->id);
1574                         break;
1575                   }
1576                }
1577             }
1578             for(ieIdx2=0; ieIdx2< ieIdx; ieIdx2++)
1579             {
1580                DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx2],sizeof(F1SetupRequestIEs_t));
1581             }
1582             DU_FREE(f1SetupReq->protocolIEs.list.array,\
1583                   f1SetupReq->protocolIEs.list.size);
1584          }
1585          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1586       }
1587       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
1588    }
1589 }
1590
1591 /*******************************************************************
1592  *
1593  * @brief Builds and Send the F1SetupRequest
1594  *
1595  * @details
1596  *
1597  *    Function : BuildAndSendF1SetupReq
1598  *
1599  * Functionality:Fills the F1SetupRequest
1600  *
1601  * @return ROK     - success
1602  *         RFAILED - failure
1603  *
1604  ******************************************************************/
1605 uint8_t BuildAndSendF1SetupReq()
1606 {
1607    uint8_t   ret, ieIdx, elementCnt;
1608    F1AP_PDU_t                 *f1apMsg = NULLP;
1609    F1SetupRequest_t           *f1SetupReq=NULLP;
1610    GNB_DU_Served_Cells_List_t *duServedCell=NULLP;
1611    RRC_Version_t              *rrcVer=NULLP;
1612    asn_enc_rval_t             encRetVal;        /* Encoder return value */
1613    ret= RFAILED;
1614
1615    DU_LOG("\nINFO   -->  F1AP : Building F1 Setup Request\n");
1616    do
1617    {
1618       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
1619       if(f1apMsg == NULLP)
1620       {
1621          break;
1622       }
1623       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
1624       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1625       if(f1apMsg->choice.initiatingMessage == NULLP)
1626       {
1627          break;
1628       }
1629       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_F1Setup;
1630       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
1631       f1apMsg->choice.initiatingMessage->value.present = \
1632                                                          InitiatingMessage__value_PR_F1SetupRequest;
1633
1634       f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1635
1636       elementCnt = 5;
1637
1638       f1SetupReq->protocolIEs.list.count = elementCnt;
1639       f1SetupReq->protocolIEs.list.size = elementCnt * sizeof(F1SetupRequestIEs_t *);
1640
1641       /* Initialize the F1Setup members */
1642       DU_ALLOC(f1SetupReq->protocolIEs.list.array,f1SetupReq->protocolIEs.list.size);
1643       if(f1SetupReq->protocolIEs.list.array == NULLP)
1644       {
1645          break;
1646       }
1647       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
1648       {
1649          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx],\
1650                sizeof(F1SetupRequestIEs_t));
1651          if(f1SetupReq->protocolIEs.list.array[ieIdx] == NULLP)
1652          {
1653             break;
1654          }
1655       }
1656
1657       ieIdx = 0;
1658       /*TransactionID*/
1659       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_TransactionID;
1660       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1661       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present =\
1662                                                                 F1SetupRequestIEs__value_PR_TransactionID;
1663       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = \
1664                                                                               TRANS_ID;
1665
1666       /*DU ID*/
1667       ieIdx++;
1668       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
1669       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1670       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1671                                                                  F1SetupRequestIEs__value_PR_GNB_DU_ID;
1672       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size =\
1673                                                                               sizeof(uint8_t);
1674
1675       DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1676             f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1677       if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == \
1678             NULLP)
1679       {
1680          break;
1681       }
1682
1683       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] =\
1684                                                                                 duCfgParam.duId;
1685       /* DU name IE is of type printableString_t which wireshark is unable to decode.
1686        * However this string is decoded successfully on online decoders.
1687        * Since this is an optional IE and the value received in it are not
1688        * used as of now, eliminating this IE for now to avoid wireshark error.
1689        */
1690       /*DU Name*/
1691       if(duCfgParam.duName != NULL)
1692       {
1693          ieIdx++;
1694          f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_Name;
1695          f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_ignore;
1696          f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = F1SetupRequestIEs__value_PR_GNB_DU_Name;
1697          f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size = strlen((char *)duCfgParam.duName);
1698          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf, \
1699                f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size);
1700          if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf == NULLP)
1701          {
1702             break;
1703          }
1704          strcpy((char*)f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,
1705                (char*)duCfgParam.duName);
1706       }
1707
1708       /*Served Cell list */
1709       ieIdx++;
1710       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1711                                                       ProtocolIE_ID_id_gNB_DU_Served_Cells_List;
1712       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1713       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1714                                                                  F1SetupRequestIEs__value_PR_GNB_DU_Served_Cells_List;
1715       duServedCell = &f1SetupReq->protocolIEs.list.\
1716                      array[ieIdx]->value.choice.GNB_DU_Served_Cells_List;
1717       if(BuildServedCellList(duServedCell))
1718       {
1719          break;
1720       }
1721
1722       /*RRC Version*/
1723       ieIdx++;
1724       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1725                                                       ProtocolIE_ID_id_GNB_DU_RRC_Version ;
1726       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1727       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1728                                                                  F1SetupRequestIEs__value_PR_RRC_Version;
1729       rrcVer = &f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
1730       if(BuildRrcVer(rrcVer))
1731       {
1732          break;
1733       }
1734
1735       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
1736
1737       /* Encode the F1SetupRequest type as APER */
1738       memset(encBuf, 0, ENC_BUF_MAX_LEN);
1739       encBufSize = 0;
1740       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
1741             encBuf);
1742
1743       /* Encode results */
1744       if(encRetVal.encoded == ENCODE_FAIL)
1745       {
1746          DU_LOG("\nERROR  -->  F1AP : Could not encode F1SetupRequest structure (at %s)\n",\
1747                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1748          break;
1749       }
1750       else
1751       {
1752          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1SetupRequest\n");
1753 #ifdef DEBUG_ASN_PRINT
1754          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
1755          {
1756             printf("%x",encBuf[ieIdx]);
1757          }
1758 #endif
1759          
1760
1761       }
1762       
1763       /* Sending msg */
1764       if(sendF1APMsg() != ROK)
1765       {
1766          DU_LOG("\nERROR  -->  F1AP : Sending F1 Setup request failed");
1767          break;
1768       }
1769       
1770       if(fillE2NodeComponentReqInfo(F1, duCfgParam.duId,  E2_NODE_COMPONENT_ADD, encBufSize, encBuf) !=ROK)
1771       {
1772          DU_LOG("\nERROR  -->  F1AP : Failed to add the e2 node in the list");
1773          break;
1774       }
1775
1776       ret=ROK;
1777       break;
1778    }while(true);
1779
1780    FreeF1SetupReq(f1apMsg);
1781
1782    return ret;
1783 }/* End of BuildAndSendF1SetupReq */
1784
1785 /*******************************************************************
1786  *
1787  * @brief Deallocating memory allocated for Served_Cells_To_Modify_Item_t
1788  *
1789  * @details
1790  *
1791  *    Function : freeCellsToModifyItem 
1792  *
1793  *    Functionality: Deallocating memory of variables allocated in
1794  *                    BuildAndSendDUConfigUpdate function
1795  *
1796  * @params[in]  Served_Cells_To_Modify_Item_t *modifyItem
1797  *
1798  * @return ROK     - void
1799  *
1800  * ****************************************************************/
1801
1802 void freeCellsToModifyItem(Served_Cells_To_Modify_Item_t *modifyItem)
1803 {
1804    uint8_t arrIdx=0, servedPlmnIdx=0, sliceLstIdx=0;
1805    ServedPLMNs_Item_t *servedPlmnItem = NULLP;
1806    SliceSupportItem_t *sliceSupportItem = NULLP;
1807
1808    DU_FREE(modifyItem->oldNRCGI.pLMN_Identity.buf, modifyItem->oldNRCGI.pLMN_Identity.size);
1809    DU_FREE(modifyItem->oldNRCGI.nRCellIdentity.buf, modifyItem->oldNRCGI.nRCellIdentity.size);
1810
1811    DU_FREE(modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1812            modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.size);
1813    DU_FREE(modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1814          modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.size);
1815
1816    if(modifyItem->served_Cell_Information.servedPLMNs.list.array != NULLP)
1817    {
1818       if(modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx] != NULLP)
1819       {
1820          servedPlmnItem = modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx];
1821
1822          DU_FREE(servedPlmnItem->pLMN_Identity.buf,servedPlmnItem->pLMN_Identity.size);
1823
1824          if(servedPlmnItem->iE_Extensions != NULLP)
1825          {
1826             if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1827             {
1828                if(servedPlmnItem->iE_Extensions->list.array[arrIdx] != NULLP)
1829                {
1830                   if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1831                         list.array != NULLP)
1832                   {
1833                      for(sliceLstIdx =0; sliceLstIdx<servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1834                            extensionValue.choice.SliceSupportList.list.count; sliceLstIdx++)
1835                      {
1836                         if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1837                               list.array[sliceLstIdx] != NULLP)
1838                         {
1839
1840                            sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1841                                               SliceSupportList.list.array[sliceLstIdx];
1842
1843                            DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sliceSupportItem->sNSSAI.sST.size);
1844                            if(sliceSupportItem->sNSSAI.sD != NULLP)
1845                            {
1846                               DU_FREE(sliceSupportItem->sNSSAI.sD->buf, sliceSupportItem->sNSSAI.sD->size);
1847                               DU_FREE(sliceSupportItem->sNSSAI.sD,sizeof(OCTET_STRING_t));
1848                            }
1849                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1850                                  SliceSupportList.list.array[sliceLstIdx], sizeof(SliceSupportItem_t));
1851                         }
1852                      }
1853                      DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.\
1854                            choice.SliceSupportList.list.array,\
1855                            servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1856                            extensionValue.choice.SliceSupportList.list.size);
1857                   }
1858                }
1859                for(servedPlmnIdx=0; servedPlmnIdx< servedPlmnItem->iE_Extensions->list.count ; servedPlmnIdx++)
1860                {
1861                   DU_FREE(servedPlmnItem->iE_Extensions->list.array[servedPlmnIdx], sizeof(ServedPLMNs_ItemExtIEs_t ));
1862                }
1863                DU_FREE(servedPlmnItem->iE_Extensions->list.array, servedPlmnItem->iE_Extensions->list.size);
1864             }
1865             DU_FREE(servedPlmnItem->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1866          }
1867       }
1868       for(servedPlmnIdx=0; servedPlmnIdx<modifyItem->served_Cell_Information.servedPLMNs.list.count; servedPlmnIdx++)
1869       {
1870          DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array[servedPlmnIdx], sizeof(ServedPLMNs_Item_t));
1871       }
1872       DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array,\
1873          modifyItem->served_Cell_Information.servedPLMNs.list.size);
1874    }
1875    
1876    if(modifyItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1877    {
1878       freeFddNrFreqInfo(modifyItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1879    }  
1880    else
1881    {
1882       if(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD)
1883       {
1884          freeTddNrFreqInfo(&modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1885          DU_FREE(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1886       }
1887    }
1888    DU_FREE(modifyItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1889          modifyItem->served_Cell_Information.measurementTimingConfiguration.size);
1890 }
1891
1892 /*******************************************************************
1893  *
1894  * @brief Deallocating memory of BuildAndSendDUConfigUpdate
1895  *
1896  * @details
1897  *
1898  *    Function : FreeDUConfigUpdate
1899  *
1900  *    Functionality: Deallocating memory of variables allocated in
1901  *                    BuildAndSendDUConfigUpdate function
1902  *
1903  * @params[in]  F1AP_PDU_t *f1apDuCfg
1904  *
1905  * @return ROK     - void
1906  *
1907  * ****************************************************************/
1908 void FreeDUConfigUpdate(F1AP_PDU_t *f1apDuCfg)
1909 {
1910    uint8_t  idx=0,ieIdx=0, cellModifyIdx=0, cellDeleteIdx=0;
1911    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
1912    Served_Cells_To_Modify_List_t  *cellsToModify=NULLP;
1913    Served_Cells_To_Delete_List_t  *cellsToDelete=NULLP;
1914    Served_Cells_To_Delete_Item_t  *deleteItem = NULLP;
1915    Served_Cells_To_Delete_ItemIEs_t *deleteItemIe = NULLP;
1916    Cells_Status_ItemIEs_t *cellStatusItemIE;
1917
1918    if(f1apDuCfg != NULLP)
1919    {
1920       if(f1apDuCfg->choice.initiatingMessage != NULLP)
1921       {
1922          duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->\
1923                        value.choice.GNBDUConfigurationUpdate;
1924          if(duCfgUpdate->protocolIEs.list.array != NULLP)
1925          {
1926             for(ieIdx=0; ieIdx<duCfgUpdate->protocolIEs.list.count; ieIdx++)
1927             {
1928                if(duCfgUpdate->protocolIEs.list.array[ieIdx] != NULLP)
1929                {
1930                   switch(duCfgUpdate->protocolIEs.list.array[ieIdx]->id)
1931                   {
1932                      case ProtocolIE_ID_id_Served_Cells_To_Modify_List:
1933                         {
1934                            cellsToModify = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1935                                            value.choice.Served_Cells_To_Modify_List;
1936                            if(cellsToModify->list.array != NULLP)
1937                            {
1938                               for(cellModifyIdx=0; cellModifyIdx<cellsToModify->list.count ;cellModifyIdx++)
1939                               {
1940                                  if(cellsToModify->list.array[cellModifyIdx] != NULLP)
1941                                  {
1942                                     freeCellsToModifyItem(&cellsToModify->list.array[cellModifyIdx]->value.choice.\
1943                                           Served_Cells_To_Modify_Item);
1944                                     DU_FREE(cellsToModify->list.array[cellModifyIdx],\
1945                                           sizeof(Served_Cells_To_Modify_ItemIEs_t));
1946                                  }
1947                               }
1948                               DU_FREE(cellsToModify->list.array,cellsToModify->list.size);
1949                            }
1950                            break;
1951                         }
1952                      case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
1953                         {
1954                            cellsToDelete = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1955                                            value.choice.Served_Cells_To_Delete_List;
1956                            if(cellsToDelete->list.array != NULLP)
1957                            {
1958                               for(cellDeleteIdx=0; cellDeleteIdx<cellsToDelete->list.count ;cellDeleteIdx++)
1959                               {
1960                                  if(cellsToDelete->list.array[cellDeleteIdx] != NULLP)
1961                                  {
1962                                     deleteItemIe = ((Served_Cells_To_Delete_ItemIEs_t*)\
1963                                           cellsToDelete->list.array[cellDeleteIdx]);
1964                                     deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
1965                                     DU_FREE(deleteItem->oldNRCGI.pLMN_Identity.buf,\
1966                                           deleteItem->oldNRCGI.pLMN_Identity.size); 
1967                                     DU_FREE(deleteItem->oldNRCGI.nRCellIdentity.buf,\
1968                                           deleteItem->oldNRCGI.nRCellIdentity.size);
1969                                     DU_FREE(cellsToDelete->list.array[cellDeleteIdx],\
1970                                           sizeof(Served_Cells_To_Delete_ItemIEs_t));
1971                                  }
1972                               }
1973                               DU_FREE(cellsToDelete->list.array,cellsToDelete->list.size);
1974                            }
1975
1976                            break;
1977                         }
1978                      case ProtocolIE_ID_id_gNB_DU_ID:
1979                         {
1980                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1981                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1982                            break;
1983                         }
1984                      case ProtocolIE_ID_id_Cells_Status_List:
1985                         {
1986                            for(idx = 0; idx < duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.count; idx++)
1987                            {
1988                               cellStatusItemIE = (Cells_Status_ItemIEs_t *)duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array[idx];
1989                               DU_FREE(cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.nRCellIdentity.buf, cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.nRCellIdentity.size);
1990                               DU_FREE(cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.pLMN_Identity.buf, cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI.pLMN_Identity.size);
1991                               DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array[idx],sizeof(Cells_Status_ItemIEs_t));
1992                            }
1993                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.array,\
1994                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List.list.size);
1995                         }
1996                   }
1997                   DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx],\
1998                         sizeof(GNBDUConfigurationUpdateIEs_t));
1999                }
2000             }
2001             DU_FREE(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2002          }
2003          DU_FREE(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2004       }
2005       DU_FREE(f1apDuCfg, (Size)sizeof(F1AP_PDU_t));
2006    }
2007 }
2008
2009 /*******************************************************************
2010  *
2011  * @brief Fills Served Plmns required in ServCellInfo IE
2012  *
2013  * @details
2014  *
2015  *    Function : fillServedPlmns
2016  *
2017  *    Functionality: Fills Served Plmns required in ServCellInfo IE
2018  *
2019  * @params[in] Pointer to ServedPLMNs_List_t *
2020  *
2021  * @return ROK     - success
2022  *         RFAILED - failure
2023  *
2024  *****************************************************************/
2025
2026 uint8_t fillServedPlmns(ServedPLMNs_List_t *servedPlmn)
2027 {
2028    uint8_t ieIdx=0, arrayIdx=0, ieListCnt=0, elementCnt=0, sliceLstIdx=0;
2029
2030    servedPlmn->list.array[arrayIdx]->pLMN_Identity.size = 3*sizeof(uint8_t);
2031    DU_ALLOC(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf, servedPlmn->list.\
2032          array[arrayIdx]->pLMN_Identity.size);
2033    if(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf == NULLP)
2034    {
2035       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2036       return RFAILED;
2037    }
2038    buildPlmnId(duCfgParam.srvdCellLst[arrayIdx].duCellInfo.cellInfo.srvdPlmn[arrayIdx].plmn,\
2039          servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf);
2040    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
2041    if(servedPlmn->list.array[arrayIdx]->iE_Extensions == NULLP)
2042    {
2043       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2044       return RFAILED;
2045    }
2046
2047    ieListCnt=1;
2048    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.count = ieListCnt;
2049    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.size = ieListCnt *sizeof(ServedPLMNs_ItemExtIEs_t *);
2050    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array,servedPlmn->list.array[arrayIdx]->\
2051          iE_Extensions->list.size);
2052    if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array == NULLP)
2053    {
2054       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2055       return RFAILED;
2056    }
2057    for(ieIdx=arrayIdx;ieIdx<ieListCnt;ieIdx++)
2058    {
2059       DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx],\
2060             sizeof(ServedPLMNs_ItemExtIEs_t));
2061       if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx] == NULLP)
2062       {
2063          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2064          return RFAILED;
2065       }
2066    }
2067    
2068    ieIdx = 0;
2069    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices; 
2070    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->id =ProtocolIE_ID_id_TAISliceSupportList;
2071    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->criticality = Criticality_ignore;
2072    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.present = \
2073    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
2074    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2075       list.count = elementCnt;
2076    servedPlmn->list.array[arrayIdx]->\
2077       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2078       list.size = elementCnt * sizeof(SliceSupportItem_t *);
2079    DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2080          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2081          list.array,servedPlmn->list.array[arrayIdx]->\
2082          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.size);
2083    if(servedPlmn->list.array[arrayIdx]->\
2084          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2085          list.array == NULLP)
2086    {
2087       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2088       return RFAILED;
2089    }
2090
2091    for(sliceLstIdx =0; sliceLstIdx< elementCnt; sliceLstIdx++)
2092    {
2093       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2094       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2095       list.array[sliceLstIdx],sizeof( SliceSupportItem_t));
2096       if(servedPlmn->list.array[arrayIdx]->\
2097       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2098       list.array[sliceLstIdx] == NULLP)
2099       {   
2100          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2101          return RFAILED;
2102       }
2103       
2104       servedPlmn->list.array[arrayIdx]->\
2105       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2106       list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
2107       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2108       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2109       list.array[sliceLstIdx]->sNSSAI.sST.buf,servedPlmn->list.array[arrayIdx]->\
2110       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->\
2111       sNSSAI.sST.size);
2112       
2113       if(servedPlmn->list.array[arrayIdx]->\
2114       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2115       list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
2116       {
2117          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2118          return RFAILED;
2119       }
2120       servedPlmn->list.array[arrayIdx]->\
2121       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2122       list.array[sliceLstIdx]->sNSSAI.sST.buf[arrayIdx] =  duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
2123       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
2124
2125       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2126       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2127       list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
2128       if(servedPlmn->list.array[arrayIdx]->\
2129       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2130       list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
2131       {
2132          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2133          return RFAILED;
2134       }
2135       servedPlmn->list.array[arrayIdx]->\
2136       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2137       list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
2138       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
2139       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2140       list.array[sliceLstIdx]->sNSSAI.sD->buf,servedPlmn->list.array[arrayIdx]->\
2141       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2142       list.array[sliceLstIdx]->sNSSAI.sD->size);
2143       if(servedPlmn->list.array[arrayIdx]->\
2144       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2145       list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
2146       {
2147          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
2148          return RFAILED;
2149       }
2150       memcpy(servedPlmn->list.array[arrayIdx]->\
2151       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2152       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
2153       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sd,\
2154       servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
2155       list.array[sliceLstIdx]->sNSSAI.sD->size);
2156    }
2157    return ROK;
2158 }
2159
2160 /*******************************************************************
2161  *
2162  * @brief Fills Nr Fdd Info required in ServCellInfo IE
2163  *
2164  * @details
2165  *
2166  *    Function : fillNrFddInfo
2167  *
2168  *    Functionality: Fills Nr Fdd Info required in ServCellInfo IE
2169  *
2170  * @params[in] FDD_Info_t *fDD
2171  *
2172  * @return ROK     - success
2173  *         RFAILED - failure
2174  *
2175  *****************************************************************/
2176
2177 uint8_t fillNrFddInfo(FDD_Info_t *fDD)
2178 {
2179    fDD->uL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.\
2180       f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn;
2181    fDD->uL_NRFreqInfo.freqBandListNr.list.count = 1;
2182    fDD->uL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t*);
2183    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.\
2184          array, fDD->uL_NRFreqInfo.freqBandListNr.list.size);
2185    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array == NULLP)
2186    {
2187       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2188       return RFAILED;
2189    }
2190
2191    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0], \
2192       sizeof(FreqBandNrItem_t));
2193    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2194    {
2195       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2196       return RFAILED;
2197    }
2198    
2199    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2200       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
2201       freqBand[0].nrFreqBand;
2202    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2203    fDD->dL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.\
2204       dlNrFreqInfo.nrArfcn;
2205    fDD->dL_NRFreqInfo.freqBandListNr.list.count = 1;
2206    fDD->dL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
2207    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array, fDD->dL_NRFreqInfo.freqBandListNr.list.size);
2208    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array == NULLP)
2209    {
2210       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2211       return RFAILED;
2212    }
2213    
2214    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0],  sizeof(FreqBandNrItem_t));
2215    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
2216    {
2217       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
2218       return RFAILED;
2219    }
2220
2221    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
2222       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
2223       freqBand[0].nrFreqBand;
2224    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
2225    
2226    /*Transmission Bandwidth*/
2227    fDD->uL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2228       f1Mode.mode.fdd.ulTxBw.nrScs;
2229    fDD->uL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2230       f1Mode.mode.fdd.ulTxBw.nrb;
2231    fDD->dL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2232       f1Mode.mode.fdd.dlTxBw.nrScs;
2233    fDD->dL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2234       f1Mode.mode.fdd.dlTxBw.nrb;
2235
2236    return ROK;
2237 }
2238
2239 /*******************************************************************
2240  *
2241  * @brief Fills ServCellInfo IE
2242  *
2243  * @details
2244  *
2245  *    Function : fillServedCellInfo
2246  *
2247  *    Functionality: Fills ServCellInfo
2248  *
2249  * @params[in] Pointer to Served_Cell_Information_t *
2250  *
2251  * @return ROK     - success
2252  *         RFAILED - failure
2253  *
2254  *****************************************************************/
2255
2256 uint8_t fillServedCellInfo(Served_Cell_Information_t *srvCellInfo)
2257 {
2258    uint8_t ieIdx, ieListCnt;
2259
2260    /*nRCGI*/
2261    srvCellInfo->nRCGI.pLMN_Identity.size =3*sizeof(uint8_t);
2262    DU_ALLOC(srvCellInfo->nRCGI.pLMN_Identity.buf,\
2263          srvCellInfo->nRCGI.pLMN_Identity.size);
2264    if(srvCellInfo->nRCGI.pLMN_Identity.buf == NULLP)
2265    {
2266       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2267       return RFAILED;
2268    }
2269    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2270          srvCellInfo->nRCGI.pLMN_Identity.buf);
2271    srvCellInfo->nRCGI.nRCellIdentity.size =5*sizeof(uint8_t);
2272    DU_ALLOC(srvCellInfo->nRCGI.nRCellIdentity.buf,\
2273          srvCellInfo->nRCGI.nRCellIdentity.size);
2274    if(srvCellInfo->nRCGI.nRCellIdentity.buf == NULLP)
2275    {   
2276       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2277       return RFAILED;
2278    }
2279    
2280    fillBitString(&srvCellInfo->nRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2281    /*nRPCI*/
2282    srvCellInfo->nRPCI = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
2283
2284    /*servedPLMNs*/
2285    ieListCnt = 1;
2286    srvCellInfo->servedPLMNs.list.count = ieListCnt;
2287    srvCellInfo->servedPLMNs.list.size = ieListCnt*sizeof(ServedPLMNs_Item_t *);
2288    DU_ALLOC(srvCellInfo->servedPLMNs.list.array, srvCellInfo->servedPLMNs.list.size);
2289    if(srvCellInfo->servedPLMNs.list.array == NULLP)
2290    {
2291       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2292       return RFAILED;
2293    }
2294    for(ieIdx=0; ieIdx < ieListCnt; ieIdx++)
2295    {
2296       DU_ALLOC(srvCellInfo->servedPLMNs.list.array[ieIdx], sizeof(ServedPLMNs_Item_t));
2297       if(srvCellInfo->servedPLMNs.list.array[ieIdx]== NULLP)
2298       {
2299          DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2300          return RFAILED;
2301       }
2302    }
2303    if(fillServedPlmns(&srvCellInfo->servedPLMNs))
2304    {
2305       DU_LOG("\nERROR  --> Failed to fill Served Plmn info");
2306       return RFAILED;
2307    }
2308
2309 #ifndef NR_TDD
2310    /*nR Mode Info with FDD*/
2311    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_fDD;
2312    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.fDD, sizeof(FDD_Info_t));
2313    if(srvCellInfo->nR_Mode_Info.choice.fDD == NULLP)
2314    {
2315       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2316       return RFAILED;
2317    }
2318    if(fillNrFddInfo(srvCellInfo->nR_Mode_Info.choice.fDD))
2319    {
2320        DU_LOG("\nERROR  --> Failed to fill the Nr FDD information");
2321       return RFAILED;
2322    }
2323 #else
2324    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_tDD;   
2325    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
2326    if(srvCellInfo->nR_Mode_Info.choice.tDD == NULLP)
2327    {
2328       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2329       return RFAILED;
2330    }
2331    if(fillNrTddInfo(srvCellInfo->nR_Mode_Info.choice.tDD) != ROK)
2332    {
2333       DU_LOG("\nERROR  --> Failed to fill the Nr TDD information");
2334       return RFAILED;
2335    }
2336 #endif
2337
2338    /*Measurement timing Config*/
2339    if(BuildMeasTimingConf(&srvCellInfo->measurementTimingConfiguration) != ROK)
2340       return RFAILED;
2341
2342    return ROK;
2343 }
2344
2345 /*******************************************************************
2346  *
2347  * @brief Fills ServCellToModItem IE
2348  *
2349  * @details
2350  *
2351  *    Function : fillServCellToModItem
2352  *
2353  *    Functionality: Fills ServCellToModItem IE
2354  *
2355  * @params[in] Pointer to Served_Cells_To_Modify_Item_t *
2356  *
2357  * @return ROK     - success
2358  *         RFAILED - failure
2359  *
2360  *****************************************************************/
2361
2362 uint8_t fillServCellToModItem(Served_Cells_To_Modify_Item_t *modifyItem)
2363 {
2364    /*pLMN_Identity*/
2365    modifyItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2366    DU_ALLOC(modifyItem->oldNRCGI.pLMN_Identity.buf,modifyItem->oldNRCGI.pLMN_Identity.size);
2367    if(modifyItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2368    {
2369       return RFAILED;
2370    }
2371    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2372          modifyItem->oldNRCGI.pLMN_Identity.buf);
2373
2374    /*nRCellIdentity*/
2375    modifyItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2376    DU_ALLOC(modifyItem->oldNRCGI.nRCellIdentity.buf,\
2377          modifyItem->oldNRCGI.nRCellIdentity.size);
2378    if(modifyItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2379    {
2380       return RFAILED;
2381    }
2382    fillBitString(&modifyItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2383
2384    if(fillServedCellInfo(&modifyItem->served_Cell_Information))
2385       return RFAILED;
2386    else
2387       return ROK;
2388 }
2389
2390 /*******************************************************************
2391  *
2392  * @brief Builds ServCellToModList
2393  *
2394  * @details
2395  *
2396  *    Function : buildServCellToModList
2397  *
2398  *    Functionality: Builds the serv cell to Mod List
2399  *
2400  * @params[in] Pointer to Served_Cells_To_Modify_List_t *
2401  *
2402  * @return ROK     - success
2403  *         RFAILED - failure
2404  *
2405  *****************************************************************/
2406
2407 uint8_t buildServCellToModList(Served_Cells_To_Modify_List_t *cellsToModify)
2408 {
2409    uint8_t ieListCnt, ieIdx;
2410    Served_Cells_To_Modify_Item_t *modifyItem = NULLP;
2411
2412    ieListCnt = 1;
2413    cellsToModify->list.count = ieListCnt;
2414    cellsToModify->list.size = ieListCnt*sizeof(Served_Cells_To_Modify_ItemIEs_t *);
2415    DU_ALLOC(cellsToModify->list.array,cellsToModify->list.size);
2416    if(cellsToModify->list.array == NULLP)
2417    {
2418       return RFAILED;
2419    }
2420    for(ieIdx=0; ieIdx< ieListCnt; ieIdx++)
2421    {
2422       DU_ALLOC(cellsToModify->list.array[ieIdx],sizeof(Served_Cells_To_Modify_ItemIEs_t));
2423       if(cellsToModify->list.array[ieIdx] == NULLP)
2424       {
2425          return RFAILED;
2426       }
2427    }
2428    cellsToModify->list.array[0]->id = ProtocolIE_ID_id_Served_Cells_To_Modify_Item;
2429    cellsToModify->list.array[0]->criticality = Criticality_reject;
2430    cellsToModify->list.array[0]->value.present =\
2431       Served_Cells_To_Modify_ItemIEs__value_PR_Served_Cells_To_Modify_Item;
2432    modifyItem=&cellsToModify->list.array[0]->value.choice.Served_Cells_To_Modify_Item;
2433
2434    if(fillServCellToModItem(modifyItem))
2435       return RFAILED;
2436    else
2437       return ROK;
2438 }
2439 /*******************************************************************
2440  *
2441  * @brief filling the DeleteItemList
2442  *
2443  * @details
2444  *
2445  *    Function : fillCellToDeleteItem 
2446  *
2447  *    Functionality: Filling the DeleteItemIe 
2448  *
2449  * @params[in] Pointer to Served_Cells_To_Delete_ItemIEs_t 
2450  *
2451  * @return ROK     - success
2452  *         RFAILED - failure
2453  *
2454  *****************************************************************/
2455 uint8_t fillCellToDeleteItem(struct Served_Cells_To_Delete_ItemIEs *deleteItemIe)
2456 {
2457    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
2458    
2459    deleteItemIe->id = ProtocolIE_ID_id_Served_Cells_To_Delete_Item;
2460    deleteItemIe->criticality = Criticality_reject;
2461    deleteItemIe->value.present =\
2462    Served_Cells_To_Delete_ItemIEs__value_PR_Served_Cells_To_Delete_Item;
2463    deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
2464
2465    /*pLMN_Identity*/
2466    deleteItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2467    DU_ALLOC(deleteItem->oldNRCGI.pLMN_Identity.buf,deleteItem->oldNRCGI.pLMN_Identity.size);
2468    if(deleteItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2469    {
2470       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2471       return RFAILED;
2472    }
2473    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2474          deleteItem->oldNRCGI.pLMN_Identity.buf);
2475
2476    /*nRCellIdentity*/
2477    deleteItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2478    DU_ALLOC(deleteItem->oldNRCGI.nRCellIdentity.buf,\
2479          deleteItem->oldNRCGI.nRCellIdentity.size);
2480    if(deleteItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2481    {
2482       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2483       return RFAILED;
2484    }
2485    fillBitString(&deleteItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2486    return ROK;
2487
2488
2489 /*******************************************************************
2490  *
2491  * @brief Builds ServCellToDeleteList
2492  *
2493  * @details
2494  *
2495  *    Function : buildServCellToDeleteList
2496  *
2497  *    Functionality: Builds the serv cell to delete List
2498  *
2499  * @params[in] Pointer to Served_Cells_To_Delete_List_t *
2500  *
2501  * @return ROK     - success
2502  *         RFAILED - failure
2503  *
2504  *****************************************************************/
2505  
2506 uint8_t buildServCellToDeleteList(Served_Cells_To_Delete_List_t *cellsToDelete)
2507 {
2508    uint8_t ieListCnt, arrIdx;
2509    
2510    ieListCnt = 1;
2511    cellsToDelete->list.count = ieListCnt;
2512    cellsToDelete->list.size = ieListCnt*sizeof(Served_Cells_To_Delete_ItemIEs_t *);
2513    
2514    DU_ALLOC(cellsToDelete->list.array,cellsToDelete->list.size);
2515    if(cellsToDelete->list.array == NULLP)
2516    {
2517       DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2518       return RFAILED;
2519    }
2520    
2521    for(arrIdx=0; arrIdx< ieListCnt; arrIdx++)
2522    {
2523       DU_ALLOC(cellsToDelete->list.array[arrIdx],sizeof(Served_Cells_To_Delete_ItemIEs_t));
2524       if(cellsToDelete->list.array[arrIdx] == NULLP)
2525       {
2526          DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2527          return RFAILED;
2528       }
2529    }
2530    
2531    arrIdx=0;
2532    if(fillCellToDeleteItem((Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx]) !=ROK)
2533    {
2534       DU_LOG("\nERROR  -->  F1AP: buildServCellToDeleteList(): failed to fill Served_Cells_To_Delete_ItemIEs");
2535       return RFAILED;
2536    }
2537    return ROK;
2538 }
2539
2540 /*******************************************************************
2541  *
2542  * @brief Builds CellsStatusList
2543  *
2544  * @details
2545  *
2546  *    Function : buildCellsStatusList
2547  *
2548  *    Functionality: Builds the Cell Status List
2549  *
2550  * @params[in] Pointer to Cells_Status_List_t *
2551  *
2552  * @return ROK     - success
2553  *         RFAILED - failure
2554  *
2555  *****************************************************************/
2556 uint8_t buildCellsStatusList(Cells_Status_List_t *cellStatusList)
2557 {
2558    uint8_t elementCnt = 0, idx = 0, ret = ROK;
2559    Cells_Status_ItemIEs_t *cellStatusItemIE;
2560
2561    elementCnt = 1;
2562    cellStatusList->list.count = elementCnt;
2563    cellStatusList->list.size = elementCnt * sizeof(Cells_Status_ItemIEs_t *);
2564    DU_ALLOC(cellStatusList->list.array, cellStatusList->list.size);
2565
2566    for(idx = 0; idx < elementCnt; idx++)
2567    {
2568       DU_ALLOC(cellStatusList->list.array[idx], sizeof(Cells_Status_ItemIEs_t));
2569       if(!cellStatusList->list.array[idx])
2570       {
2571          DU_LOG("ERROR  --> F1AP: buildCellsStatusList() memory allocation failure");
2572          return RFAILED;
2573       }
2574    }
2575    idx = 0;
2576    cellStatusItemIE = (Cells_Status_ItemIEs_t *)cellStatusList->list.array[idx];
2577    cellStatusItemIE->id = ProtocolIE_ID_id_Cells_Status_Item;
2578    cellStatusItemIE->criticality = Criticality_reject;
2579    cellStatusItemIE->value.present = Cells_Status_ItemIEs__value_PR_Cells_Status_Item;
2580    ret = BuildNrcgi(&cellStatusItemIE->value.choice.Cells_Status_Item.nRCGI);
2581    if(ret == RFAILED)
2582    {
2583          DU_LOG("ERROR  --> F1AP: buildCellsStatusList() NRCGI failed");
2584          return RFAILED;
2585    }
2586    cellStatusItemIE->value.choice.Cells_Status_Item.service_status.service_state = Service_State_in_service;
2587    return ROK;
2588 }
2589
2590 /*******************************************************************
2591  *
2592  * @brief Builds and sends the DUConfigUpdate
2593  *
2594  * @details
2595  *
2596  *    Function : BuildAndSendDUConfigUpdate
2597  *
2598  *    Functionality: Constructs the DU Update message and sends
2599  *                   it to the CU through SCTP.
2600  *
2601  * @params[in] void **buf,Buffer to which encoded pattern is written into
2602  * @params[in] int *size,size of buffer
2603  *
2604  * @return ROK     - success
2605  *         RFAILED - failure
2606  *
2607  * ****************************************************************/
2608 uint8_t BuildAndSendDUConfigUpdate(ServCellAction servCellAction)
2609 {
2610    uint8_t ret =0, ieIdx=0, elementCnt=0;
2611    bool memAlloctionFailure = false;
2612    F1AP_PDU_t                 *f1apDuCfg = NULLP;
2613    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
2614    asn_enc_rval_t encRetVal;     /* Encoder return value */
2615    
2616    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2617    ret= RFAILED;
2618
2619    while(true)
2620    {
2621       DU_LOG("\nINFO   -->  F1AP : Building DU config update\n");
2622       /* Allocate the memory for F1DuCfg */
2623       DU_ALLOC(f1apDuCfg, sizeof(F1AP_PDU_t));
2624       if(f1apDuCfg == NULLP)
2625       {
2626          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2627          break;
2628       }
2629
2630       f1apDuCfg->present = F1AP_PDU_PR_initiatingMessage;
2631       DU_ALLOC(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2632       if(f1apDuCfg->choice.initiatingMessage == NULLP)
2633       {
2634          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2635          break;
2636       }
2637
2638       f1apDuCfg->choice.initiatingMessage->procedureCode = \
2639                                                            ProcedureCode_id_gNBDUConfigurationUpdate;
2640       f1apDuCfg->choice.initiatingMessage->criticality = Criticality_reject;
2641       f1apDuCfg->choice.initiatingMessage->value.present = \
2642                                                            InitiatingMessage__value_PR_GNBDUConfigurationUpdate;
2643       duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->value.\
2644                     choice.GNBDUConfigurationUpdate;
2645       elementCnt = 4;
2646       duCfgUpdate->protocolIEs.list.count = elementCnt;
2647       duCfgUpdate->protocolIEs.list.size = \
2648                                            elementCnt * sizeof(GNBDUConfigurationUpdateIEs_t*);
2649
2650       /* Initialize the F1Setup members */
2651       DU_ALLOC(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2652       if(duCfgUpdate->protocolIEs.list.array == NULLP)
2653       {
2654          DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2655          break;
2656       }
2657       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
2658       {
2659          DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx],sizeof(GNBDUConfigurationUpdateIEs_t));
2660          if(duCfgUpdate->protocolIEs.list.array[ieIdx] == NULLP)
2661          {
2662             DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2663             memAlloctionFailure = true;
2664             break;
2665          }
2666       }
2667       
2668       if(memAlloctionFailure == true)
2669       {
2670          break;
2671       }
2672       /*TransactionID*/
2673       ieIdx = 0;
2674       duCfgUpdate->protocolIEs.list.array[ieIdx]->id=ProtocolIE_ID_id_TransactionID;
2675       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
2676       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2677       GNBDUConfigurationUpdateIEs__value_PR_TransactionID;
2678       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = TRANS_ID;
2679       
2680       ieIdx++;
2681       if(servCellAction == SERV_CELL_TO_MODIFY)
2682       {
2683          /*Served Cell to Modify */
2684          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2685          ProtocolIE_ID_id_Served_Cells_To_Modify_List;
2686          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2687          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2688          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Modify_List;
2689          if(buildServCellToModList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2690                   Served_Cells_To_Modify_List))
2691          {
2692             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToModList");
2693             break;
2694          }
2695       }
2696       else
2697       {
2698          /*Served Cell to Delete */ 
2699          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2700          ProtocolIE_ID_id_Served_Cells_To_Delete_List;
2701          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2702          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2703          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Delete_List;
2704          if(buildServCellToDeleteList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2705          Served_Cells_To_Delete_List)!=ROK)
2706          {
2707             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToDeleteList");
2708             break;
2709          }
2710          
2711       }
2712       // TODO :GNB DU SYS INFO:MIB AND SIB1 INFORMATION TO BE BUILT AND FILLED HERE
2713       
2714       /*Cell Status List*/
2715       ieIdx++;
2716       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_Cells_Status_List;
2717       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2718       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2719            GNBDUConfigurationUpdateIEs__value_PR_Cells_Status_List;
2720       ret = buildCellsStatusList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.Cells_Status_List);
2721       if(ret == RFAILED)
2722       {
2723          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Cell Status List building failed");
2724          break;
2725       }
2726
2727       /*GNB DU ID */
2728       ieIdx++;
2729       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
2730       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2731       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2732       GNBDUConfigurationUpdateIEs__value_PR_GNB_DU_ID;
2733       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size = sizeof(uint8_t);
2734       DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
2735             duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
2736       if(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == NULLP)
2737       {
2738          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Memory allocation failed for GNB_DU_ID");
2739          break;
2740       }
2741       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] = duCfgParam.duId;
2742
2743       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apDuCfg);
2744
2745       /* Encode the DU Config Update type as APER */
2746       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
2747       encBufSize = 0;
2748       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apDuCfg, PrepFinalEncBuf, encBuf);
2749
2750       /* Checking encode results */
2751       if(encRetVal.encoded == ENCODE_FAIL)
2752       {
2753          DU_LOG("ERROR  -->  F1AP : Could not encode DUConfigUpdate structure (at %s)\n",\
2754                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2755          break;
2756       }
2757       else
2758       {
2759          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DUConfigUpdate\n");
2760 #ifdef DEBUG_ASN_PRINT
2761          for(ieIdx =0; ieIdx < encBufSize; ieIdx++)
2762          {
2763             printf("%x",encBuf[ieIdx]);
2764          }
2765 #endif
2766       }
2767       
2768       /* Sending msg */
2769       if(sendF1APMsg() != ROK)
2770       {
2771          DU_LOG("\nERROR  -->  F1AP : Sending GNB-DU Config Update failed");
2772          break;
2773       }
2774       
2775       if(fillE2NodeComponentReqInfo(F1, duCfgParam.duId, E2_NODE_COMPONENT_UPDATE, encBufSize, encBuf)!=ROK)
2776       {
2777          DU_LOG("\nERROR  -->  F1AP : Failed to update the e2 node in the list");
2778          break;
2779       }
2780
2781       ret = ROK;
2782       break;
2783    }
2784   
2785    addToReservedF1apPduList(TRANS_ID,f1apDuCfg);
2786    return ret;
2787 }
2788
2789
2790 /*******************************************************************
2791  *
2792  * @brief free the ULRRCMessageTransfer
2793  *
2794  * @details
2795  *
2796  *    Function : FreeULRRCMessageTransfer
2797  *
2798  *    Functionality: Deallocating the memory of variable allocated in
2799  *                      FreeULRRCMessageTransfer
2800  *
2801  * @params[in]
2802  *
2803  * @return ROK     - void
2804  *
2805  ******************************************************************/
2806 void FreeULRRCMessageTransfer( F1AP_PDU_t *f1apMsg)
2807 {
2808    uint8_t idx1;
2809    ULRRCMessageTransfer_t  *ulRRCMsg;
2810
2811    if(f1apMsg != NULLP)
2812    { 
2813       if(f1apMsg->choice.initiatingMessage != NULLP)
2814       {
2815          ulRRCMsg = &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2816          if(ulRRCMsg->protocolIEs.list.array != NULLP)
2817          {
2818             for(idx1=0;idx1<ulRRCMsg->protocolIEs.list.count;idx1++)
2819             {
2820                if(ulRRCMsg->protocolIEs.list.array[idx1] != NULLP)
2821                {
2822                   if(ulRRCMsg->protocolIEs.list.array[idx1]->value.present ==
2823                         ULRRCMessageTransferIEs__value_PR_RRCContainer)
2824                   {
2825                      DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2826                            ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2827                   }
2828                   DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1],sizeof(ULRRCMessageTransferIEs_t));
2829                }
2830             }
2831             DU_FREE(ulRRCMsg->protocolIEs.list.array,ulRRCMsg->protocolIEs.list.size );
2832          }
2833          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2834       }
2835       DU_FREE(f1apMsg,sizeof(F1AP_PDU_t));
2836    }
2837 }
2838 /*******************************************************************
2839  *
2840  * @brief Builds and sends the ULRRCMessageTransfer 
2841  *
2842  * @details
2843  *
2844  *    Function : BuildAndSendULRRCMessageTransfer
2845  *
2846  *    Functionality: Constructs the UL RRC Message Transfer and sends
2847  *                   it to the CU through SCTP.
2848  *
2849  * @params[in] 
2850  *
2851  * @return ROK     - success
2852  *         RFAILED - failure
2853  *
2854  * ****************************************************************/
2855 uint8_t BuildAndSendULRRCMessageTransfer(DuUeCb  *ueCb, uint8_t lcId, \
2856       uint16_t msgLen, uint8_t *rrcMsg)
2857 {
2858    uint8_t                 elementCnt=0, idx1=0, idx=0;
2859    uint8_t                 ret = RFAILED;
2860    F1AP_PDU_t              *f1apMsg = NULLP;
2861    ULRRCMessageTransfer_t  *ulRRCMsg = NULLP;
2862    asn_enc_rval_t          encRetVal;        /* Encoder return value */
2863    
2864    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2865
2866    while(true)
2867    {
2868       DU_LOG("\nINFO   -->  F1AP : Building UL RRC Message Transfer Message\n");
2869
2870       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
2871       if(f1apMsg == NULLP)
2872       {
2873          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
2874          break;
2875       }
2876       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
2877       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2878       if(f1apMsg->choice.initiatingMessage == NULLP)
2879       {
2880          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
2881          break;
2882       }
2883       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_ULRRCMessageTransfer;
2884       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
2885       f1apMsg->choice.initiatingMessage->value.present = \
2886                                                          InitiatingMessage__value_PR_ULRRCMessageTransfer;
2887       ulRRCMsg =
2888          &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2889       elementCnt = 4;
2890       ulRRCMsg->protocolIEs.list.count = elementCnt;
2891       ulRRCMsg->protocolIEs.list.size = \
2892                                         elementCnt * sizeof(ULRRCMessageTransferIEs_t *);
2893
2894       /* Initialize the F1Setup members */
2895       DU_ALLOC(ulRRCMsg->protocolIEs.list.array, ulRRCMsg->protocolIEs.list.size);
2896       if(ulRRCMsg->protocolIEs.list.array == NULLP)
2897       {
2898          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UL RRC MessageTransferIEs failed");
2899          break;
2900       }
2901       for(idx=0; idx<elementCnt; idx++)
2902       {
2903          DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx],sizeof(ULRRCMessageTransferIEs_t));
2904          if(ulRRCMsg->protocolIEs.list.array[idx] == NULLP)
2905          {
2906             break;
2907          }
2908       }
2909
2910       idx1 = 0;
2911
2912       /*GNB CU UE F1AP ID*/
2913       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
2914       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2915       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2916                                                               ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
2917       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
2918
2919       /*GNB DU UE F1AP ID*/
2920       idx1++;
2921       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
2922       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2923       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2924                                                               ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
2925       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
2926
2927       /*SRBID*/
2928       idx1++;
2929       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
2930       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2931       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2932                                                               ULRRCMessageTransferIEs__value_PR_SRBID;
2933       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.SRBID = lcId;
2934
2935       /*RRCContainer*/
2936       idx1++;
2937       ulRRCMsg->protocolIEs.list.array[idx1]->id  = ProtocolIE_ID_id_RRCContainer;
2938       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2939       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2940                                                               ULRRCMessageTransferIEs__value_PR_RRCContainer;
2941       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size = msgLen;
2942       DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2943             ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size)
2944       if(!ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf)
2945       {
2946          DU_LOG(" ERROR  -->  F1AP : Memory allocation for BuildAndSendULRRCMessageTransfer failed");
2947          break;
2948       }
2949       memset(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, 0, msgLen);
2950       memcpy(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, \
2951             rrcMsg, ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2952
2953       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
2954
2955       /* Encode the F1SetupRequest type as APER */
2956       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2957       encBufSize = 0;
2958       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
2959             encBuf);
2960       /* Encode results */
2961       if(encRetVal.encoded == ENCODE_FAIL)
2962       {
2963          DU_LOG( "\nERROR  -->  F1AP : Could not encode ULRRCMessageTransfer structure (at %s)\n",\
2964                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2965          break;
2966       }
2967       else
2968       {
2969          DU_LOG("\nDEBUG  -->  F1AP : Created APER encoded buffer for ULRRCMessageTransfer\n");
2970 #ifdef DEBUG_ASN_PRINT
2971          for(int i=0; i< encBufSize; i++)
2972          {
2973             printf("%x",encBuf[i]);
2974          }
2975 #endif
2976       }
2977
2978       /* Sending  msg  */
2979       if(sendF1APMsg()  !=      ROK)
2980       {
2981          DU_LOG("\nERROR  -->   F1AP : Sending  UL RRC Message Transfer Failed");
2982          break;
2983       }
2984       ret = ROK;
2985       break;
2986    }
2987    FreeULRRCMessageTransfer(f1apMsg);
2988
2989    return ret;
2990 }/* End of BuildAndSendULRRCMessageTransfer*/
2991
2992 /*******************************************************************
2993  *
2994  * @brief Builds tag config 
2995  *
2996  * @details
2997  *
2998  *    Function : BuildTagConfig 
2999  *
3000  *    Functionality: Builds tag config in MacCellGroupConfig
3001  *
3002  * @params[in] TAG_Config *tag_Config
3003  *
3004  * @return ROK     - success
3005  *         RFAILED - failure
3006  *
3007  * ****************************************************************/
3008 uint8_t BuildTagConfig(DuUeCb *ueCb, struct TAG_Config *tagConfig)
3009 {
3010    struct TAG_Config__tag_ToAddModList *tagList;
3011    uint8_t                     idx, elementCnt;
3012
3013    tagConfig->tag_ToReleaseList = NULLP;
3014    tagConfig->tag_ToAddModList = NULLP;
3015    DU_ALLOC(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
3016    if(!tagConfig->tag_ToAddModList)
3017    {
3018       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3019       return RFAILED;
3020    }
3021
3022    if(ueCb == NULLP)
3023       elementCnt = ODU_VALUE_ONE;
3024    else
3025       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModListCount;
3026
3027    tagList = tagConfig->tag_ToAddModList;
3028    tagList->list.count = elementCnt;
3029    tagList->list.size  =  elementCnt * sizeof(struct TAG *);
3030
3031    tagList->list.array = NULLP;
3032    DU_ALLOC(tagList->list.array, tagList->list.size);
3033    if(!tagList->list.array)
3034    {
3035       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3036       return RFAILED;
3037    }
3038
3039    for(idx=0; idx<tagList->list.count; idx++)
3040    {
3041       tagList->list.array[idx] = NULLP;
3042       DU_ALLOC(tagList->list.array[idx], sizeof(struct TAG));
3043       if(!tagList->list.array[idx])
3044       {
3045          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
3046          return RFAILED;
3047       }
3048    }
3049
3050    if(ueCb == NULLP)
3051    {
3052       idx = 0;
3053       tagList->list.array[idx]->tag_Id = TAG_ID;
3054       tagList->list.array[idx]->timeAlignmentTimer = TIME_ALIGNMENT_TMR;
3055    }
3056    else
3057    {
3058       for(idx=0; idx<tagList->list.count; idx++)
3059       {
3060          tagList->list.array[idx]->tag_Id = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].tagId;
3061          tagList->list.array[idx]->timeAlignmentTimer = ueCb->duMacUeCfg.macCellGrpCfg.tagCfg.addModList[idx].timeAlignTimer;
3062       }
3063    }
3064
3065    return ROK;
3066 }
3067
3068 /*******************************************************************
3069  *
3070  * @brief Builds PHR Config 
3071  *
3072  * @details
3073  *
3074  *    Function : BuildPhrConfig
3075  *
3076  *    Functionality: Builds phrConfig in MacCellGroupConfig
3077  *
3078  * @params[in] PHR Config *
3079  *
3080  * @return ROK     - success
3081  *         RFAILED - failure
3082  *
3083  * ****************************************************************/
3084 uint8_t BuildPhrConfig(DuUeCb *ueCb, struct MAC_CellGroupConfig__phr_Config *phrConfig)
3085 {
3086
3087    phrConfig->present = MAC_CellGroupConfig__phr_Config_PR_setup;
3088    phrConfig->choice.setup = NULLP;
3089    DU_ALLOC(phrConfig->choice.setup, sizeof(struct PHR_Config));
3090    if(!phrConfig->choice.setup)
3091    {
3092       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhrConfig");
3093       return RFAILED;
3094    }
3095
3096    if(ueCb == NULLP)
3097    {
3098       phrConfig->choice.setup->phr_PeriodicTimer        = PHR_PERIODIC_TMR;
3099       phrConfig->choice.setup->phr_ProhibitTimer        = PHR_PROHIBHIT_TMR;
3100       phrConfig->choice.setup->phr_Tx_PowerFactorChange = PHR_PWR_FACTOR_CHANGE;
3101       phrConfig->choice.setup->multiplePHR              = false;
3102       phrConfig->choice.setup->dummy                    = false;
3103       phrConfig->choice.setup->phr_Type2OtherCell       = false;
3104       phrConfig->choice.setup->phr_ModeOtherCG          = PHR_MODE_OTHER_CG;
3105    }
3106    else
3107    {
3108       phrConfig->choice.setup->phr_PeriodicTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.periodicTimer;
3109       phrConfig->choice.setup->phr_ProhibitTimer        = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.prohibitTimer;
3110       phrConfig->choice.setup->phr_Tx_PowerFactorChange = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.txPowerFactor;
3111       phrConfig->choice.setup->multiplePHR              = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.multiplePHR;
3112       phrConfig->choice.setup->dummy                    = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.dummy;
3113       phrConfig->choice.setup->phr_Type2OtherCell       = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrType2OtherCell;
3114       phrConfig->choice.setup->phr_ModeOtherCG          = ueCb->duMacUeCfg.macCellGrpCfg.phrCfg.phrOtherCG;
3115    }
3116
3117    return ROK;
3118 }
3119
3120 /*******************************************************************
3121  *
3122  * @brief Builds BSR Config 
3123  *
3124  * @details
3125  *
3126  *    Function : BuildBsrConfig
3127  *
3128  *    Functionality: Builds BuildBsrConfig in MacCellGroupConfig
3129  *
3130  * @params[in] BSR_Config *bsrConfig
3131  *
3132  * @return ROK     - success
3133  *         RFAILED - failure
3134  *
3135  * ****************************************************************/
3136 uint8_t BuildBsrConfig(DuUeCb *ueCb, struct BSR_Config *bsrConfig)
3137 {
3138    if(ueCb == NULLP)
3139    {
3140       bsrConfig->periodicBSR_Timer = PERIODIC_BSR_TMR;
3141       bsrConfig->retxBSR_Timer     = RETX_BSR_TMR;
3142       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
3143    }
3144    else
3145    {
3146       bsrConfig->periodicBSR_Timer = convertBsrPeriodicTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.periodicTimer);
3147       bsrConfig->retxBSR_Timer     = convertBsrRetxTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.retxTimer);
3148
3149       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
3150       DU_ALLOC(bsrConfig->logicalChannelSR_DelayTimer, sizeof(long));
3151       if(bsrConfig->logicalChannelSR_DelayTimer == NULLP)
3152       {
3153          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildBsrConfig");
3154          return RFAILED;
3155       }
3156       *(bsrConfig->logicalChannelSR_DelayTimer) = convertLcSrDelayTmrValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.bsrTmrCfg.srDelayTimer);
3157    }
3158
3159    return ROK;
3160 }
3161
3162 /*******************************************************************
3163  *
3164  * @brief Builds scheduling request config 
3165  *
3166  * @details
3167  *
3168  *    Function : BuildSchedulingReqConfig 
3169  *
3170  *    Functionality: Builds BuildSchedulingReqConfig in MacCellGroupConfig
3171  *
3172  * @params[in] SchedulingRequestConfig *schedulingRequestConfig
3173  *
3174  * @return ROK     - success
3175  *         RFAILED - failure
3176  *
3177  * ****************************************************************/
3178 uint8_t BuildSchedulingReqConfig(DuUeCb *ueCb, struct SchedulingRequestConfig *schedulingRequestConfig)
3179 {
3180    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList;
3181    uint8_t                     idx, elementCnt;
3182
3183    schedulingRequestConfig->schedulingRequestToAddModList = NULLP;
3184    DU_ALLOC(schedulingRequestConfig->schedulingRequestToAddModList,
3185          sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));
3186    if(!schedulingRequestConfig->schedulingRequestToAddModList)
3187    {
3188       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3189       return RFAILED;
3190    }
3191
3192    if(ueCb == NULLP)
3193       elementCnt = ODU_VALUE_ONE;
3194    else
3195       elementCnt = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModListCount;
3196
3197    schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
3198    schReqList->list.count = elementCnt;
3199    schReqList->list.size  = elementCnt * sizeof(struct SchedulingRequestToAddMod *);
3200
3201    schReqList->list.array = NULLP;
3202    DU_ALLOC(schReqList->list.array, schReqList->list.size);
3203    if(!schReqList->list.array)
3204    {
3205       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3206       return RFAILED;
3207    }
3208
3209    for(idx=0; idx<schReqList->list.count; idx++)
3210    {
3211       schReqList->list.array[idx] = NULLP;
3212       DU_ALLOC(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
3213       if(!schReqList->list.array[idx])
3214       {
3215          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3216          return RFAILED;
3217       }
3218    }
3219
3220    if(ueCb == NULLP)
3221    {
3222       idx = 0;
3223       schReqList->list.array[idx]->schedulingRequestId = SCH_REQ_ID;
3224
3225       schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
3226       DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
3227       if(!schReqList->list.array[idx]->sr_ProhibitTimer)
3228       {
3229          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3230          return RFAILED;
3231       }
3232       *(schReqList->list.array[idx]->sr_ProhibitTimer) = SR_PROHIBIT_TMR;
3233       schReqList->list.array[idx]->sr_TransMax = SR_TRANS_MAX;
3234    }
3235    else
3236    {
3237       for(idx=0; idx<schReqList->list.count; idx++)
3238       {
3239          schReqList->list.array[idx]->schedulingRequestId = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].schedReqId;
3240
3241          schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
3242          DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
3243          if(!schReqList->list.array[idx]->sr_ProhibitTimer)
3244          {
3245             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
3246             return RFAILED;
3247          }
3248          *(schReqList->list.array[idx]->sr_ProhibitTimer) = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srProhibitTmr;
3249          schReqList->list.array[idx]->sr_TransMax = ueCb->duMacUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srTransMax;
3250       }
3251    }
3252
3253    schedulingRequestConfig->schedulingRequestToReleaseList = NULLP;
3254
3255    return ROK;
3256 }
3257
3258 /*******************************************************************
3259  *
3260  * @brief Builds RLC Configuration for AM mode
3261  *
3262  * @details
3263  *
3264  *    Function : BuildRlcConfigAm
3265  *
3266  *    Functionality: 
3267  *       Builds AM mode RLC Config in BuildRlcBearerToAddModList
3268  *
3269  * @params[in] AmBearerCfg *amCfg
3270  *             RLC_Config_t  *rlcConfig
3271  *
3272  * @return ROK     - success
3273  *         RFAILED - failure
3274  *
3275  * ****************************************************************/
3276 uint8_t BuildRlcConfigAm(AmBearerCfg *amCfg, struct RLC_Config *rlcConfig)
3277 {
3278    rlcConfig->choice.am = NULLP;
3279    DU_ALLOC(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
3280    if(!rlcConfig->choice.am)
3281    {
3282       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3283       return RFAILED;
3284    }
3285
3286    /* Fill AM UL configuration */
3287    rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength = NULLP;
3288    DU_ALLOC(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
3289    if(!rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength)
3290    {
3291       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3292       return RFAILED;
3293    }
3294
3295    /* Fill default AM UL configuration if input pointer to DU database is NULL */
3296    if(amCfg == NULLP)
3297    {
3298       
3299       *(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"*/
3300       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = T_POLL_RETRANSMIT;
3301       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = POLL_PDU;
3302       rlcConfig->choice.am->ul_AM_RLC.pollByte          = POLL_BYTE;
3303       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = MAX_RETX_THRESHOLD;
3304    }
3305    else
3306    {
3307       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->dlAmCfg.snLenDl);
3308       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = covertPollRetxTmrValueToEnum(amCfg->dlAmCfg.pollRetxTmr);
3309       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = covertPollPduValueToEnum(amCfg->dlAmCfg.pollPdu);
3310       rlcConfig->choice.am->ul_AM_RLC.pollByte          = covertPollByteValueToEnum(amCfg->dlAmCfg.pollByte);
3311       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = covertMaxRetxValueToEnum(amCfg->dlAmCfg.maxRetxTh);
3312    }
3313
3314    /* Fill AM DL configuraion */
3315    rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength = NULLP;
3316    DU_ALLOC(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
3317    if(!rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength)
3318    {
3319       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3320       return RFAILED;
3321    }
3322
3323    /* Fill default AM DL configuration if input pointer to DU database is NULL */
3324    if(amCfg == NULLP)
3325    {
3326       *(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"*/
3327       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = T_REASSEMBLY;
3328       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = T_STATUS_PROHIBHIT;
3329    }
3330    else /* Fill AM configuration from DU database */
3331    {
3332       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->ulAmCfg.snLenUl);
3333       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = convertReasmblTmrValueToEnum(amCfg->ulAmCfg.reAssemTmr);
3334       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = convertProhibitTmrValueToEnum(amCfg->ulAmCfg.statProhTmr);
3335    }
3336    return ROK;
3337 }
3338
3339 /*******************************************************************
3340  *
3341  * @brief Builds RLC Config for UM Bidirection
3342  *
3343  * @details
3344  *
3345  *    Function : BuildRlcConfig UmBiDir
3346  *
3347  *    Functionality: 
3348  *       Builds RLC Config for UM Bidirection in BuildRlcBearerToAddModList 
3349  *
3350  * @params[in] UmBiDirBearerCfg *umBiDirCfg
3351  *             RLC_Config_t *rlcConfig
3352  *
3353  * @return ROK     - success
3354  *         RFAILED - failure
3355  *
3356  * ****************************************************************/
3357 uint8_t BuildRlcConfigUmBiDir(UmBiDirBearerCfg *umBiDirCfg, struct RLC_Config *rlcConfig)
3358 {
3359    rlcConfig->choice.um_Bi_Directional = NULLP;
3360    DU_ALLOC(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
3361    if(rlcConfig->choice.um_Bi_Directional == NULLP)
3362    {
3363       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3364       return RFAILED;
3365    }
3366
3367    /* Fill UM Bidirectional UL configuration */
3368    rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength = NULLP;
3369    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3370    if(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength == NULLP)
3371    {
3372       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3373       return RFAILED;
3374    }
3375
3376    if(umBiDirCfg != NULLP)
3377    {
3378       *(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->dlUmCfg.snLenDlUm);     
3379    }
3380
3381    /* Fill UM Bidirectional DL configuration */
3382    rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength = NULLP;
3383    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3384    if(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength == NULLP)
3385    {
3386       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3387       return RFAILED;
3388    }
3389
3390    if(umBiDirCfg != NULLP)
3391    {
3392       *(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->ulUmCfg.snLenUlUm);     
3393       rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umBiDirCfg->ulUmCfg.reAssemTmr);
3394    }
3395
3396    return ROK;
3397 }
3398
3399 /*******************************************************************
3400  *
3401  * @brief Builds RLC Config for UM Uni directional UL
3402  *
3403  * @details
3404  *
3405  *    Function : BuildRlcConfigUmUniDirUl
3406  *
3407  *    Functionality: 
3408  *       Builds RLC Config for UM Unidirection UL in BuildRlcBearerToAddModList 
3409  *
3410  * @params[in] UmUniDirDlBearerCfg *umUniDirDlCfg
3411  *             RLC_Config_t *rlcConfig
3412  *
3413  * @return ROK     - success
3414  *         RFAILED - failure
3415  *
3416  * ****************************************************************/
3417 uint8_t BuildRlcConfigUmUniDirUl(UmUniDirDlBearerCfg *umUniDirDlCfg, RLC_Config_t *rlcConfig)
3418 {
3419    rlcConfig->choice.um_Uni_Directional_UL = NULLP;
3420    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
3421    if(rlcConfig->choice.um_Uni_Directional_UL == NULLP)
3422    {
3423       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3424       return RFAILED;
3425    }
3426
3427    rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength = NULLP;
3428    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3429    if(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength == NULLP)
3430    {
3431       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3432       return RFAILED;
3433    }
3434
3435    if(umUniDirDlCfg != NULLP)
3436    {
3437       *(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirDlCfg->dlUmCfg.snLenDlUm);
3438    }
3439
3440    return ROK;
3441 }
3442
3443 /*******************************************************************
3444  *
3445  * @brief Builds RLC Config for UM Uni directional DL
3446  *
3447  * @details
3448  *
3449  *    Function : BuildRlcConfigUmUniDirDl
3450  *
3451  *    Functionality: 
3452  *       Builds RLC Config for UM Unidirection DL in BuildRlcBearerToAddModList 
3453  *
3454  * @params[in] UmUniDirUlBearerCfg *umUniDirUlCfg
3455  *             RLC_Config_t *rlcConfig
3456  *
3457  * @return ROK     - success
3458  *         RFAILED - failure
3459  *
3460  * ****************************************************************/
3461 uint8_t BuildRlcConfigUmUniDirDl(UmUniDirUlBearerCfg *umUniDirUlCfg, RLC_Config_t *rlcConfig)
3462 {
3463    rlcConfig->choice.um_Uni_Directional_DL = NULLP;
3464    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
3465    if(rlcConfig->choice.um_Uni_Directional_DL == NULLP)
3466    {
3467       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3468       return RFAILED;
3469    }
3470
3471    rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength = NULLP;
3472    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3473    if(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength == NULLP)
3474    {
3475       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3476       return RFAILED;
3477    }
3478
3479    if(umUniDirUlCfg != NULLP)
3480    {
3481       *(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirUlCfg->ulUmCfg.snLenUlUm);
3482       rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umUniDirUlCfg->ulUmCfg.reAssemTmr);
3483    }
3484
3485    return ROK;
3486 }
3487
3488 /*******************************************************************
3489  *
3490  * @brief Builds RLC Config
3491  *
3492  * @details
3493  *
3494  *    Function : BuildRlcConfig
3495  *
3496  *    Functionality: Builds RLC Config in BuildRlcBearerToAddModList 
3497  *
3498  * @params[in] RLC_Config_t *rlcConfig
3499  *
3500  * @return ROK     - success
3501  *         RFAILED - failure
3502  *
3503  * ****************************************************************/
3504 uint8_t BuildRlcConfig(RlcBearerCfg *rbCfg, struct RLC_Config *rlcConfig)
3505 {
3506    
3507    /* Fill default values if rbCfg is NULL */
3508    if(rbCfg == NULLP)
3509    {
3510       rlcConfig->present = RLC_Config_PR_am;
3511       BuildRlcConfigAm(NULLP, rlcConfig);
3512    }
3513    /* If RbCfg is present, fill RLC configurations from DU Database */
3514    else
3515    {
3516       rlcConfig->present = covertRlcModeFromIntEnumToRrcEnum(rbCfg->rlcMode);
3517       switch(rlcConfig->present)
3518       {
3519          case RLC_Config_PR_am:
3520             BuildRlcConfigAm(rbCfg->u.amCfg, rlcConfig);
3521             break;
3522          case RLC_Config_PR_um_Bi_Directional:
3523             BuildRlcConfigUmBiDir(rbCfg->u.umBiDirCfg, rlcConfig);
3524             break;
3525          case RLC_Config_PR_um_Uni_Directional_UL:
3526             BuildRlcConfigUmUniDirUl(rbCfg->u.umUniDirDlCfg, rlcConfig);
3527             break;
3528          case RLC_Config_PR_um_Uni_Directional_DL:
3529             BuildRlcConfigUmUniDirDl(rbCfg->u.umUniDirUlCfg, rlcConfig);
3530             break;
3531          case RLC_Config_PR_NOTHING:
3532          default:
3533             break;
3534       }
3535    }
3536
3537    return ROK;
3538 }
3539
3540 /*******************************************************************
3541  *
3542  * @brief Builds MAC LC Config
3543  *
3544  * @details
3545  *
3546  *    Function : BuildMacLCConfig 
3547  *
3548  *    Functionality: Builds MAC LC Config in BuildRlcBearerToAddModList 
3549  *
3550  * @params[in] struct LogicalChannelConfig macLcConfig
3551  *
3552  * @return ROK     - success
3553  *         RFAILED - failure
3554  *
3555  * ****************************************************************/
3556 uint8_t BuildMacLCConfig(LcCfg *lcCfgDb, struct LogicalChannelConfig *macLcConfig)
3557 {
3558    macLcConfig->ul_SpecificParameters = NULLP;
3559    DU_ALLOC(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
3560    if(!macLcConfig->ul_SpecificParameters)
3561    {
3562       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3563       return RFAILED;
3564    }
3565
3566    if(lcCfgDb == NULLP)
3567    {
3568       macLcConfig->ul_SpecificParameters->priority = MAC_LC_PRIORITY;
3569       macLcConfig->ul_SpecificParameters->prioritisedBitRate =  PRIORTISIED_BIT_RATE;
3570       macLcConfig->ul_SpecificParameters->bucketSizeDuration =  BUCKET_SIZE_DURATION;
3571    }
3572    else
3573    {
3574       macLcConfig->ul_SpecificParameters->priority = lcCfgDb->ulLcCfg.priority;
3575       macLcConfig->ul_SpecificParameters->prioritisedBitRate = lcCfgDb->ulLcCfg.pbr;
3576       macLcConfig->ul_SpecificParameters->bucketSizeDuration = lcCfgDb->ulLcCfg.bsd;
3577    }
3578
3579    macLcConfig->ul_SpecificParameters->allowedServingCells = NULLP;
3580    macLcConfig->ul_SpecificParameters->allowedSCS_List = NULLP;
3581    macLcConfig->ul_SpecificParameters->maxPUSCH_Duration = NULLP;
3582    macLcConfig->ul_SpecificParameters->configuredGrantType1Allowed = NULLP;
3583
3584    macLcConfig->ul_SpecificParameters->logicalChannelGroup = NULLP;
3585    DU_ALLOC(macLcConfig->ul_SpecificParameters->logicalChannelGroup,    sizeof(long));
3586    if(!macLcConfig->ul_SpecificParameters->logicalChannelGroup)
3587    {
3588       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3589       return RFAILED;
3590    }
3591
3592    if(lcCfgDb == NULLP)
3593       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = LC_GRP;
3594    else
3595       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = lcCfgDb->ulLcCfg.lcGroup;
3596
3597    macLcConfig->ul_SpecificParameters->schedulingRequestID = NULLP;
3598    DU_ALLOC(macLcConfig->ul_SpecificParameters->schedulingRequestID,    sizeof(SchedulingRequestId_t));
3599    if(!macLcConfig->ul_SpecificParameters->schedulingRequestID)
3600    {
3601       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3602       return RFAILED;
3603    }
3604
3605    if(lcCfgDb == NULLP)
3606       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = SCH_REQ_ID;
3607    else
3608       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = lcCfgDb->ulLcCfg.schReqId;
3609
3610    macLcConfig->ul_SpecificParameters->logicalChannelSR_Mask = false;
3611    macLcConfig->ul_SpecificParameters->logicalChannelSR_DelayTimerApplied = false;
3612    macLcConfig->ul_SpecificParameters->bitRateQueryProhibitTimer = NULLP;
3613
3614    return ROK;
3615 }
3616
3617 /*******************************************************************
3618  *
3619  * @brief Builds RLC Bearer to Add/Mod list
3620  *
3621  * @details
3622  *
3623  *    Function :BuildRlcBearerToAddModList 
3624  *
3625  *    Functionality: Builds RLC Bearer to Add/Mod list in DuToCuRrcContainer
3626  *
3627  * @params[in] rlc_BearerToAddModList
3628  *
3629  * @return ROK     - success
3630  *         RFAILED - failure
3631  *
3632  * ****************************************************************/
3633 uint8_t BuildRlcBearerToAddModList(DuUeCb *ueCb, struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList)
3634 {
3635    uint8_t  idx = 0, lcIdx=0, macLcIdx = 0, elementCnt = 0;
3636
3637    if(ueCb == NULLP)
3638       elementCnt = 1;
3639    else if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
3640       elementCnt = ueCb->duRlcUeCfg.numLcs;
3641    else
3642    {
3643       for(lcIdx = 0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3644       {
3645          if(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == false)
3646             elementCnt++;
3647       }
3648    }
3649    rlcBearerList->list.count = elementCnt;
3650    rlcBearerList->list.size  = elementCnt * sizeof(struct RLC_BearerConfig *);
3651
3652    rlcBearerList->list.array = NULLP;
3653    DU_ALLOC(rlcBearerList->list.array, rlcBearerList->list.size);
3654    if(!rlcBearerList->list.array)
3655    {
3656       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3657       return RFAILED;
3658    }
3659
3660    for(idx=0; idx<rlcBearerList->list.count; idx++)
3661    {
3662       rlcBearerList->list.array[idx] = NULLP;
3663       DU_ALLOC(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
3664       if(!rlcBearerList->list.array[idx])
3665       {
3666          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3667          return RFAILED;
3668       }
3669    }
3670
3671    if(ueCb == NULLP)
3672    {
3673       idx=0;
3674       rlcBearerList->list.array[idx]->logicalChannelIdentity = SRB1_LCID;
3675       DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3676       if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3677       {     
3678          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3679          return RFAILED;
3680       }     
3681       rlcBearerList->list.array[idx]->servedRadioBearer->present = RLC_BearerConfig__servedRadioBearer_PR_srb_Identity;
3682       rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = SRB1_LCID;
3683       rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3684
3685       /* Fill RLC related Configurations for this Radio Bearer */
3686       rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3687       DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3688       if(!rlcBearerList->list.array[idx]->rlc_Config)
3689       {
3690          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3691          return RFAILED;
3692       }
3693       if(BuildRlcConfig(NULLP, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3694       {
3695          DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3696          return RFAILED;
3697       }
3698
3699       /* Fill MAC related configurations for this Radio Bearer */
3700       rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3701       DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3702       if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3703       {
3704          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3705          return RFAILED;
3706       }
3707       if(BuildMacLCConfig(NULLP, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3708       {
3709          DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3710          return RFAILED;
3711       }
3712    }
3713    else
3714    {
3715       idx=0;
3716       for(lcIdx=0; lcIdx<ueCb->duRlcUeCfg.numLcs; lcIdx++)
3717       {
3718          if((ueCb->f1UeDb->actionType != UE_CTXT_CFG_QUERY) && (ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent == true))
3719             continue;
3720
3721          /* Fill Logical channel identity */
3722          rlcBearerList->list.array[idx]->logicalChannelIdentity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId;
3723
3724          /* Fill Radio Bearer Id and type (DRB/SRB) for this logical channel */
3725          DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3726          if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3727          {
3728             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3729             return RFAILED;
3730          }
3731          rlcBearerList->list.array[idx]->servedRadioBearer->present = \
3732                                                                       covertRbTypeFromIntEnumToRrcEnum(ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbType);
3733          switch(rlcBearerList->list.array[idx]->servedRadioBearer->present)
3734          {
3735             case RLC_BearerConfig__servedRadioBearer_PR_srb_Identity: 
3736                rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3737                break;
3738             case RLC_BearerConfig__servedRadioBearer_PR_drb_Identity:
3739                rlcBearerList->list.array[idx]->servedRadioBearer->choice.drb_Identity = ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.rbId;
3740                break;
3741             case RLC_BearerConfig__servedRadioBearer_PR_NOTHING:
3742             default:
3743                break;
3744          }
3745          ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.isLcAddModRspSent = true;
3746
3747          rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3748
3749          /* Fill RLC related Configurations for this Radio Bearer */
3750          rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3751          DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3752          if(!rlcBearerList->list.array[idx]->rlc_Config)
3753          {
3754             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3755             return RFAILED;
3756          }
3757          if(BuildRlcConfig(&ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3758          {
3759             DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3760             return RFAILED;
3761          }
3762
3763          /* Fill MAC related configurations for this Radio Bearer */
3764          rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3765          DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3766          if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3767          {
3768             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3769             return RFAILED;
3770          }
3771          for(macLcIdx = 0; macLcIdx < ueCb->duMacUeCfg.numLcs; macLcIdx++)
3772          {
3773             if(ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig.lcId == ueCb->duRlcUeCfg.rlcLcCfg[lcIdx].rlcBearerCfg.lcId)
3774             {
3775                if(BuildMacLCConfig(&ueCb->duMacUeCfg.lcCfgList[macLcIdx].lcConfig, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3776                {
3777                   DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3778                   return RFAILED;
3779                }
3780                break;
3781             }
3782          }
3783
3784          idx++;
3785       }
3786    }
3787    return ROK;
3788 }
3789
3790 /*******************************************************************
3791  *
3792  * @brief Build Control resource set to add/modify list 
3793  *
3794  * @details
3795  *
3796  *    Function : BuildControlRSetToAddModList
3797  *
3798  *    Functionality: Build Control resource set to add/modify list
3799  *
3800  * @params[in] 
3801  * struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList
3802  *
3803  * @return ROK     - success
3804  *         RFAILED - failure
3805  *
3806  * ****************************************************************/
3807 uint8_t BuildControlRSetToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList)
3808 {
3809    uint8_t idx;
3810    uint8_t elementCnt;
3811    uint8_t numBytes, bitsUnused;
3812    struct ControlResourceSet *controlRSet;
3813    uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
3814    uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
3815
3816    if(pdcchCfg == NULLP)
3817       elementCnt = 1;
3818    else
3819       elementCnt = pdcchCfg->numCRsetToAddMod;
3820
3821    controlRSetList->list.count = elementCnt;
3822    controlRSetList->list.size = elementCnt * sizeof(struct ControlResourceSet *);
3823
3824    controlRSetList->list.array = NULLP;
3825    DU_ALLOC(controlRSetList->list.array, controlRSetList->list.size);
3826    if(!controlRSetList->list.array)
3827    {
3828       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3829       return RFAILED;
3830    }
3831
3832    for(idx = 0; idx < elementCnt; idx++)
3833    {
3834       controlRSetList->list.array[idx] = NULLP;
3835       DU_ALLOC(controlRSetList->list.array[idx], sizeof(struct ControlResourceSet));
3836       if(!controlRSetList->list.array[idx])
3837       {
3838          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3839          return RFAILED;
3840       }
3841    }
3842
3843    for(idx = 0; idx < elementCnt; idx++)
3844    {
3845       controlRSet = controlRSetList->list.array[idx];
3846
3847       if(pdcchCfg == NULLP)
3848          controlRSet->controlResourceSetId = PDCCH_CTRL_RSRC_SET_ONE_ID;
3849       else
3850          controlRSet->controlResourceSetId = pdcchCfg->cRSetToAddModList[idx].cRSetId;
3851
3852       /* size 6 bytes
3853        * 3 LSBs unsued
3854        * Bit string stored ff0000000000
3855        */
3856       numBytes = 6;
3857       bitsUnused = 3;
3858       controlRSet->frequencyDomainResources.size = numBytes * sizeof(uint8_t);
3859
3860       controlRSet->frequencyDomainResources.buf = NULLP;
3861       DU_ALLOC(controlRSet->frequencyDomainResources.buf, controlRSet->frequencyDomainResources.size);
3862       if(!controlRSet->frequencyDomainResources.buf)
3863       {
3864          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3865          return RFAILED;
3866       }
3867
3868       memset(controlRSet->frequencyDomainResources.buf, 0, FREQ_DOM_RSRC_SIZE);
3869
3870       if(pdcchCfg == NULLP)
3871       {
3872          coreset0EndPrb = CORESET0_END_PRB;
3873          coreset1StartPrb = coreset0EndPrb + 6;
3874          coreset1NumPrb = CORESET1_NUM_PRB;
3875          /* calculate the PRBs */
3876          fillCoresetFeqDomAllocMap(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
3877          memcpy(controlRSet->frequencyDomainResources.buf, freqDomainResource, FREQ_DOM_RSRC_SIZE);
3878          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3879
3880          controlRSet->duration = PDCCH_CTRL_RSRC_SET_ONE_DURATION;
3881          controlRSet->cce_REG_MappingType.present = ControlResourceSet__cce_REG_MappingType_PR_nonInterleaved;
3882          controlRSet->precoderGranularity = PDCCH_CTRL_RSRC_SET_ONE_PRECOD_GRANULARITY;
3883       }
3884       else
3885       {
3886          memcpy(controlRSet->frequencyDomainResources.buf, pdcchCfg->cRSetToAddModList[idx].freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
3887          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3888          controlRSet->duration = pdcchCfg->cRSetToAddModList[idx].duration;
3889          controlRSet->cce_REG_MappingType.present = pdcchCfg->cRSetToAddModList[idx].cceRegMappingType;
3890          controlRSet->precoderGranularity = pdcchCfg->cRSetToAddModList[idx].precoderGranularity;
3891       }
3892       controlRSet->tci_StatesPDCCH_ToAddList = NULLP;
3893       controlRSet->tci_StatesPDCCH_ToReleaseList = NULLP;
3894       controlRSet->tci_PresentInDCI = NULLP;
3895
3896 #if 0
3897       uint8_t tciStateIdx;
3898
3899       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList, \
3900             sizeof(struct ControlResourceSet__tci_StatesPDCCH_ToAddList));
3901       if(!controlRset->tci_StatesPDCCH_ToAddList)
3902       {
3903          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3904          return RFAILED;
3905       }
3906
3907       elementCnt = 1;
3908       controlRset->tci_StatesPDCCH_ToAddList->list.count = elementCnt;
3909       controlRset->tci_StatesPDCCH_ToAddList->list.size = elementCnt * sizeof(TCI_StateId_t *);
3910       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array, \
3911             controlRset->tci_StatesPDCCH_ToAddList->list.size)
3912          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array)
3913          {
3914             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3915             return RFAILED;
3916          }
3917
3918       for(tciStateIdx = 0; tciStateIdx <elementCntl; tciStateIdx++)
3919       {
3920          DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx], sizeof(TCI_StateId_t));
3921          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx])
3922          {
3923             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3924             return RFAILED;
3925          }
3926       }
3927
3928       tciStateIdx = 0;
3929       /* TODO */
3930       *(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx]);
3931
3932       DU_ALLOC(controlRset->tci_PresentInDCI, sizeof(long));
3933       if(!controlRset->tci_PresentInDCI)
3934       {
3935          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3936          return RFAILED;
3937       }
3938       /* TODO */
3939       *(controlRset->tci_PresentInDCI);
3940 #endif
3941
3942       controlRSet->pdcch_DMRS_ScramblingID = NULLP;
3943       DU_ALLOC(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
3944       if(!controlRSet->pdcch_DMRS_ScramblingID)
3945       {
3946          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3947          return RFAILED;
3948       }
3949       if(pdcchCfg == NULLP)
3950          *(controlRSet->pdcch_DMRS_ScramblingID) = SCRAMBLING_ID;
3951       else
3952          *(controlRSet->pdcch_DMRS_ScramblingID) = pdcchCfg->cRSetToAddModList[idx].dmrsScramblingId;
3953    }
3954    return ROK;
3955 } /* End BuildControlRSetToAddModList */
3956
3957 /*******************************************************************
3958  *
3959  * @brief Build search space to add/modify list
3960  *
3961  * @details
3962  *
3963  *    Function : BuildSearchSpcToAddModList
3964  *
3965  *    Functionality: Build search space to add/modify list
3966  *
3967  * @params[in] 
3968  * @return ROK     - success
3969  *         RFAILED - failure
3970  *
3971  * ****************************************************************/
3972 uint8_t BuildSearchSpcToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
3973 {
3974    uint8_t idx;
3975    uint8_t numBytes;
3976    uint8_t byteIdx;
3977    uint8_t bitsUnused;
3978    uint8_t elementCnt;
3979    struct SearchSpace *searchSpc;
3980
3981    if(pdcchCfg == NULLP)
3982       elementCnt = 1;
3983    else
3984       elementCnt = pdcchCfg->numSearchSpcToAddMod;
3985
3986    searchSpcList->list.count = elementCnt;
3987    searchSpcList->list.size = elementCnt * sizeof(struct SearchSpace *);
3988
3989    searchSpcList->list.array = NULLP;
3990    DU_ALLOC(searchSpcList->list.array, searchSpcList->list.size);
3991    if(!searchSpcList->list.array)
3992    {
3993       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3994       return RFAILED;
3995    }
3996
3997    for(idx = 0; idx < elementCnt; idx++)
3998    {
3999       searchSpcList->list.array[idx] = NULLP;
4000       DU_ALLOC(searchSpcList->list.array[idx], sizeof(struct SearchSpace));
4001       if(!searchSpcList->list.array[idx])
4002       {
4003          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4004          return RFAILED;
4005       }
4006    }
4007
4008    for(idx = 0; idx < elementCnt; idx++)
4009    {
4010       searchSpc = searchSpcList->list.array[idx];
4011
4012       if(pdcchCfg == NULLP)
4013          searchSpc->searchSpaceId = PDCCH_SRCH_SPC_TWO_ID;
4014       else
4015          searchSpc->searchSpaceId = pdcchCfg->searchSpcToAddModList[idx].searchSpaceId;
4016
4017       searchSpc->controlResourceSetId = NULLP;
4018       DU_ALLOC(searchSpc->controlResourceSetId, sizeof(ControlResourceSetId_t));
4019       if(!searchSpc->controlResourceSetId)
4020       {
4021          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4022          return RFAILED;
4023       }
4024       if(pdcchCfg == NULLP)
4025          *(searchSpc->controlResourceSetId) = PDCCH_CTRL_RSRC_SET_ONE_ID;
4026       else
4027          *(searchSpc->controlResourceSetId) = pdcchCfg->searchSpcToAddModList[idx].cRSetId;
4028
4029       searchSpc->monitoringSlotPeriodicityAndOffset = NULLP;
4030       DU_ALLOC(searchSpc->monitoringSlotPeriodicityAndOffset, sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
4031       if(!searchSpc->monitoringSlotPeriodicityAndOffset)
4032       {
4033          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4034          return RFAILED;
4035       }
4036       if(pdcchCfg == NULLP)
4037          searchSpc->monitoringSlotPeriodicityAndOffset->present = SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
4038       else
4039          searchSpc->monitoringSlotPeriodicityAndOffset->present = pdcchCfg->searchSpcToAddModList[idx].mSlotPeriodicityAndOffset;
4040
4041       searchSpc->duration = NULLP;
4042       searchSpc->monitoringSymbolsWithinSlot = NULLP;
4043       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot, sizeof(BIT_STRING_t));
4044       if(!searchSpc->monitoringSymbolsWithinSlot)
4045       {
4046          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4047          return RFAILED;
4048       }
4049
4050       /* Values taken from reference logs :
4051        * size 2 bytes
4052        * 2 LSBs unsued
4053        * Bit string stores 8000
4054        */
4055       numBytes = 2;
4056       bitsUnused = 2;
4057       searchSpc->monitoringSymbolsWithinSlot->size = numBytes * sizeof(uint8_t);
4058       searchSpc->monitoringSymbolsWithinSlot->buf = NULLP;
4059       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot->buf, searchSpc->monitoringSymbolsWithinSlot->size);
4060       if(!searchSpc->monitoringSymbolsWithinSlot->buf)
4061       {
4062          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4063          return RFAILED;
4064       }
4065       if(pdcchCfg == NULLP)
4066       {
4067          byteIdx = 0;
4068          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = PDCCH_SYMBOL_WITHIN_SLOT /* setting MSB to 128 i.e. 0x80 */;
4069          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = 0;
4070       }
4071       else
4072          memcpy(searchSpc->monitoringSymbolsWithinSlot->buf, pdcchCfg->searchSpcToAddModList[idx].mSymbolsWithinSlot, numBytes);
4073       searchSpc->monitoringSymbolsWithinSlot->bits_unused = bitsUnused;
4074
4075       searchSpc->nrofCandidates = NULLP;
4076       DU_ALLOC(searchSpc->nrofCandidates, sizeof(struct SearchSpace__nrofCandidates));
4077       if(!searchSpc->nrofCandidates)
4078       {
4079          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4080          return RFAILED;
4081       }
4082
4083       if(pdcchCfg == NULLP)
4084       {
4085          searchSpc->nrofCandidates->aggregationLevel1 = PDCCH_SRCH_SPC_TWO_AGG_LVL1_CANDIDATE;
4086          searchSpc->nrofCandidates->aggregationLevel2 = PDCCH_SRCH_SPC_TWO_AGG_LVL2_CANDIDATE;
4087          searchSpc->nrofCandidates->aggregationLevel4 = PDCCH_SRCH_SPC_TWO_AGG_LVL4_CANDIDATE;
4088          searchSpc->nrofCandidates->aggregationLevel8 = PDCCH_SRCH_SPC_TWO_AGG_LVL8_CANDIDATE;
4089          searchSpc->nrofCandidates->aggregationLevel16 = PDCCH_SRCH_SPC_TWO_AGG_LVL16_CANDIDATE;
4090       }
4091       else
4092       {
4093          searchSpc->nrofCandidates->aggregationLevel1 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel1;
4094          searchSpc->nrofCandidates->aggregationLevel2 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel2;
4095          searchSpc->nrofCandidates->aggregationLevel4 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel4;
4096          searchSpc->nrofCandidates->aggregationLevel8 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel8;
4097          searchSpc->nrofCandidates->aggregationLevel16 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel16;
4098       }
4099
4100       searchSpc->searchSpaceType = NULLP;
4101       DU_ALLOC(searchSpc->searchSpaceType, sizeof(struct SearchSpace__searchSpaceType));
4102       if(!searchSpc->searchSpaceType)
4103       {
4104          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4105          return RFAILED;
4106       }
4107       if(pdcchCfg == NULLP)
4108          searchSpc->searchSpaceType->present = SearchSpace__searchSpaceType_PR_ue_Specific;
4109       else
4110          searchSpc->searchSpaceType->present = pdcchCfg->searchSpcToAddModList[idx].searchSpaceType;
4111
4112       searchSpc->searchSpaceType->choice.ue_Specific = NULLP;
4113       DU_ALLOC(searchSpc->searchSpaceType->choice.ue_Specific, sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
4114       if(!searchSpc->searchSpaceType->choice.ue_Specific)
4115       {
4116          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
4117          return RFAILED;
4118       }  
4119       if(pdcchCfg == NULLP)
4120          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
4121       else
4122          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = pdcchCfg->searchSpcToAddModList[idx].ueSpecificDciFormat;
4123    }
4124    return ROK;
4125 }/* End BuildSearchSpcToAddModList */
4126
4127 /*******************************************************************
4128  *
4129  * @brief Builds BWP DL dedicated PDCCH config
4130  *
4131  * @details
4132  *
4133  *    Function : BuildBWPDlDedPdcchCfg
4134  *
4135  *    Functionality: Builds BWP DL dedicated PDCCH config
4136  *
4137  * @params[in] struct PDCCH_Config *pdcchCfg
4138  *
4139  * @return ROK     - success
4140  *         RFAILED - failure
4141  *
4142  * ****************************************************************/
4143 uint8_t BuildBWPDlDedPdcchCfg(PdcchConfig *pdcchCfgDb, struct PDCCH_Config *pdcchCfg)
4144 {
4145    pdcchCfg->controlResourceSetToAddModList = NULLP;
4146    DU_ALLOC(pdcchCfg->controlResourceSetToAddModList, sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
4147    if(!pdcchCfg->controlResourceSetToAddModList)
4148    {
4149       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
4150       return RFAILED;
4151    }
4152
4153    if(BuildControlRSetToAddModList(pdcchCfgDb, pdcchCfg->controlResourceSetToAddModList) != ROK)
4154    {
4155       DU_LOG("\nERROR  --> F1AP : Failed in BuildControlRSetToAddModList()");
4156       return RFAILED;
4157    }
4158
4159    pdcchCfg->controlResourceSetToReleaseList = NULLP;
4160
4161    pdcchCfg->searchSpacesToAddModList = NULLP;
4162    DU_ALLOC(pdcchCfg->searchSpacesToAddModList, sizeof(struct PDCCH_Config__searchSpacesToAddModList));
4163    if(!pdcchCfg->searchSpacesToAddModList)
4164    {
4165       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
4166       return RFAILED;
4167    }
4168
4169    if(BuildSearchSpcToAddModList(pdcchCfgDb, pdcchCfg->searchSpacesToAddModList) != ROK)
4170    {
4171       DU_LOG("\nERROR  --> F1AP : Failed in BuildSearchSpcToAddModList()");
4172       return RFAILED;
4173    }
4174
4175    pdcchCfg->searchSpacesToReleaseList = NULLP;
4176    pdcchCfg->downlinkPreemption = NULLP;
4177    pdcchCfg->tpc_PUSCH = NULLP;
4178    pdcchCfg->tpc_PUCCH = NULLP;
4179    pdcchCfg->tpc_SRS = NULLP;
4180
4181    return ROK;
4182 }
4183
4184 /*******************************************************************
4185  *
4186  * @brief Builds DMRS DL PDSCH Mapping type A
4187  *
4188  * @details
4189  *
4190  *    Function : BuildDMRSDLPdschMapTypeA
4191  *
4192  *    Functionality: Builds DMRS DL PDSCH Mapping type A
4193  *
4194  * @params[in]
4195  * struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg
4196  * @return ROK     - success
4197  *         RFAILED - failure
4198  *
4199  * ****************************************************************/
4200 uint8_t BuildDMRSDLPdschMapTypeA(PdschConfig *pdschCfg, struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg)
4201 {
4202    dmrsDlCfg->present = PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup;
4203    dmrsDlCfg->choice.setup = NULLP;
4204    DU_ALLOC(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
4205    if(!dmrsDlCfg->choice.setup)
4206    {
4207       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
4208       return RFAILED;
4209    }
4210
4211    dmrsDlCfg->choice.setup->dmrs_Type = NULLP;
4212    dmrsDlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4213    DU_ALLOC(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4214    if(!dmrsDlCfg->choice.setup->dmrs_AdditionalPosition)
4215    {
4216       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
4217       return RFAILED;
4218    }
4219    if(pdschCfg == NULLP)
4220       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS;
4221    else
4222       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = pdschCfg->dmrsDlCfgForPdschMapTypeA.addPos;
4223
4224    dmrsDlCfg->choice.setup->maxLength = NULLP;
4225    dmrsDlCfg->choice.setup->scramblingID0 = NULLP;
4226    dmrsDlCfg->choice.setup->scramblingID1 = NULLP;
4227    dmrsDlCfg->choice.setup->phaseTrackingRS = NULLP;
4228
4229    return ROK;
4230 }
4231
4232 /*******************************************************************
4233  *
4234  * @brief Builds TCI states to add/modify list
4235  *
4236  * @details
4237  *
4238  *    Function : BuildTCIStatesToAddModList
4239  *
4240  *    Functionality:Builds TCI states to add/modify list
4241  *
4242  * @params[in] 
4243  * struct PDSCH_Config__tci_StatesToAddModList *tciStatesList
4244  *
4245  * @return ROK     - success
4246  *         RFAILED - failure
4247  *
4248  * ****************************************************************/
4249 uint8_t BuildTCIStatesToAddModList(struct PDSCH_Config__tci_StatesToAddModList *tciStatesList)
4250 {
4251    return ROK;
4252 }
4253
4254 /*******************************************************************
4255  *
4256  * @brief Builds PDSCH time domain allocation list
4257  *
4258  * @details
4259  *
4260  *    Function : BuildPdschTimeDomAllocList
4261  *
4262  *    Functionality: Builds PDSCH time domain allocation list
4263  *
4264  * @params[in] 
4265  * struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
4266  *
4267  * @return ROK     - success
4268  *         RFAILED - failure
4269  *
4270  * ****************************************************************/
4271 uint8_t BuildPdschTimeDomAllocList(PdschConfig *pdschCfg, struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
4272 {
4273    uint8_t idx;
4274    uint8_t elementCnt;
4275    struct PDSCH_TimeDomainResourceAllocation *timeDomAlloc;
4276
4277    timeDomAllocList->present = PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup;
4278
4279    timeDomAllocList->choice.setup = NULLP;
4280    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PDSCH_TimeDomainResourceAllocationList));
4281    if(!timeDomAllocList->choice.setup)
4282    {
4283       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4284       return RFAILED;
4285    }
4286
4287 if(pdschCfg == NULLP)
4288    elementCnt = 2;
4289 else
4290 elementCnt = pdschCfg->numTimeDomRsrcAlloc;
4291    timeDomAllocList->choice.setup->list.count = elementCnt;
4292    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(struct PDSCH_TimeDomainResourceAllocation *);
4293
4294    timeDomAllocList->choice.setup->list.array = NULLP;
4295    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4296    if(!timeDomAllocList->choice.setup->list.array)
4297    {
4298       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4299       return RFAILED;
4300    }
4301
4302    for(idx = 0; idx < elementCnt; idx++)
4303    {
4304       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4305       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], \
4306             sizeof(struct PDSCH_TimeDomainResourceAllocation));
4307       if(!timeDomAllocList->choice.setup->list.array[idx])
4308       {
4309          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4310          return RFAILED;
4311       }
4312    }
4313
4314    if(pdschCfg == NULLP)
4315    {
4316       idx = 0;
4317       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4318       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4319       if(!timeDomAlloc->k0)
4320       {
4321          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4322          return RFAILED;
4323       }
4324       *(timeDomAlloc->k0) = 0;
4325       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4326       timeDomAlloc->startSymbolAndLength = \
4327                                            calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4328
4329       idx++;
4330       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4331       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4332       if(!timeDomAlloc->k0)
4333       {
4334          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4335          return RFAILED;
4336       }
4337       *(timeDomAlloc->k0) = 1;
4338       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4339       timeDomAlloc->startSymbolAndLength = calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4340    }
4341    else
4342    {
4343       for(idx = 0; idx < elementCnt; idx++)
4344       {
4345          timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4346          if(pdschCfg->timeDomRsrcAllociList[idx].k0)
4347          {
4348             DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4349             if(!timeDomAlloc->k0)
4350             {
4351                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4352                return RFAILED;
4353             }
4354             *(timeDomAlloc->k0) = *(pdschCfg->timeDomRsrcAllociList[idx].k0);
4355          }
4356          timeDomAlloc->mappingType = pdschCfg->timeDomRsrcAllociList[idx].mappingType;
4357          timeDomAlloc->startSymbolAndLength = pdschCfg->timeDomRsrcAllociList[idx].startSymbolAndLength;
4358       }
4359    }
4360
4361    return ROK;
4362 }
4363
4364 /*******************************************************************
4365  *
4366  * @brief Builds PDSCH PRB Bundling type
4367  *
4368  * @details
4369  *
4370  *    Function : BuildPdschPrbBundlingType
4371  *
4372  *    Functionality: Builds PDSCH PRB Bundling type
4373  *
4374  * @params[in] 
4375  * struct PDSCH_Config__prb_BundlingType *prbBndlType
4376  *
4377  * @return ROK     - success
4378  *         RFAILED - failure
4379  *
4380  * ****************************************************************/
4381 uint8_t BuildPdschPrbBundlingType(PdschConfig *pdschCfg, struct PDSCH_Config__prb_BundlingType *prbBndlType)
4382 {
4383    if(pdschCfg == NULLP)
4384       prbBndlType->present = PDSCH_Config__prb_BundlingType_PR_staticBundling;
4385    else
4386       prbBndlType->present = pdschCfg->bundlingType;
4387
4388    prbBndlType->choice.staticBundling = NULLP;
4389    DU_ALLOC(prbBndlType->choice.staticBundling, \
4390          sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
4391    if(!prbBndlType->choice.staticBundling)
4392    {
4393       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschPrbBundlingType");
4394       return RFAILED;
4395    }
4396    prbBndlType->choice.staticBundling->bundleSize = NULLP;
4397
4398    return ROK;
4399 }
4400
4401 /*******************************************************************
4402  *
4403  * @brief Builds BWP DL dedicated PDSCH config 
4404  *
4405  * @details
4406  *
4407  *    Function : BuildBWPDlDedPdschCfg
4408  *
4409  *    Functionality: Builds BWP DL dedicated PDSCH config
4410  *
4411  * @params[in] struct PDSCH_Config *pdschCfg
4412  *
4413  * @return ROK     - success
4414  *         RFAILED - failure
4415  *
4416  * ****************************************************************/
4417 uint8_t BuildBWPDlDedPdschCfg(PdschConfig *pdschCfgDb, struct PDSCH_Config *pdschCfg)
4418 {
4419    pdschCfg->dataScramblingIdentityPDSCH = NULLP;
4420
4421    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA = NULLP;
4422    DU_ALLOC(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
4423    if(!pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
4424    {
4425       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4426       return RFAILED;
4427    }
4428
4429    if(BuildDMRSDLPdschMapTypeA(pdschCfgDb, pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA) != ROK)
4430    {
4431       return RFAILED;
4432    }
4433
4434    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeB = NULLP;
4435    pdschCfg->tci_StatesToAddModList = NULLP;
4436    pdschCfg->tci_StatesToReleaseList = NULLP;
4437    pdschCfg->vrb_ToPRB_Interleaver = NULLP;
4438 #if 0
4439    DU_ALLOC(pdschCfg->tci_StatesToAddModList, sizeof(struct PDSCH_Config__tci_StatesToAddModList));
4440    if(!pdschCfg->tci_StatesToAddModList)
4441    {
4442       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4443       return RFAILED;
4444    }
4445    if(BuildTCIStatesToAddModList(pdschCfg->tci_StatesToAddModList) != ROK)
4446    {
4447       return RFAILED;
4448    }
4449 #endif
4450
4451 if(pdschCfgDb == NULLP)
4452    pdschCfg->resourceAllocation = RES_ALLOC_TYPE;
4453 else
4454 pdschCfg->resourceAllocation = pdschCfgDb->resourceAllocType;
4455
4456    pdschCfg->pdsch_TimeDomainAllocationList = NULLP;
4457    DU_ALLOC(pdschCfg->pdsch_TimeDomainAllocationList, sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
4458    if(!pdschCfg->pdsch_TimeDomainAllocationList)
4459    {
4460       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4461       return RFAILED;
4462    }
4463    if(BuildPdschTimeDomAllocList(pdschCfgDb, pdschCfg->pdsch_TimeDomainAllocationList) != ROK)
4464    {
4465       return RFAILED;
4466    }
4467
4468    pdschCfg->pdsch_AggregationFactor = NULLP;
4469    pdschCfg->rateMatchPatternToAddModList = NULLP;
4470    pdschCfg->rateMatchPatternToReleaseList = NULLP;
4471    pdschCfg->rateMatchPatternGroup1 = NULLP;
4472    pdschCfg->rateMatchPatternGroup2 = NULLP;
4473    if(pdschCfgDb == NULLP)
4474       pdschCfg->rbg_Size = PDSCH_RBG_SIZE;
4475    else
4476       pdschCfg->rbg_Size = pdschCfgDb->rbgSize;
4477    pdschCfg->mcs_Table = NULLP;
4478
4479    pdschCfg->maxNrofCodeWordsScheduledByDCI = NULLP;
4480    DU_ALLOC(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
4481    if(!pdschCfg->maxNrofCodeWordsScheduledByDCI)
4482    {
4483       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4484       return RFAILED;
4485    }
4486    if(pdschCfgDb == NULLP)
4487       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = PDSCH_MAX_CODEWORD_SCH_BY_DCI;
4488    else
4489       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = pdschCfgDb->numCodeWordsSchByDci;
4490
4491    if(BuildPdschPrbBundlingType(pdschCfgDb, &pdschCfg->prb_BundlingType) != ROK)
4492    {
4493       return RFAILED;
4494    }
4495
4496    pdschCfg->zp_CSI_RS_ResourceToAddModList = NULLP;
4497    pdschCfg->zp_CSI_RS_ResourceToReleaseList = NULLP;
4498    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4499    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4500    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4501    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4502    pdschCfg->p_ZP_CSI_RS_ResourceSet = NULLP;
4503
4504    return ROK;
4505 }
4506
4507 /*******************************************************************
4508  *
4509  * @brief Builds intitial DL BWP
4510  * @details
4511  *
4512  *    Function : BuildInitialDlBWP 
4513  *
4514  *    Functionality: Builds intitial DL BWP in spCellCfgDed
4515  *
4516  * @params[in] BWP_DownlinkDedicated_t *dlBwp
4517  *
4518  * @return ROK     - success
4519  *         RFAILED - failure
4520  *
4521  * ****************************************************************/
4522 uint8_t BuildInitialDlBWP(InitialDlBwp *initiDlBwp, BWP_DownlinkDedicated_t *dlBwp)
4523 {
4524    PdcchConfig *pdcchCfg = NULLP;
4525    PdschConfig *pdschCfg = NULLP;
4526
4527    if(initiDlBwp)
4528    {
4529       if(initiDlBwp->pdcchPresent)
4530          pdcchCfg = &initiDlBwp->pdcchCfg;
4531       if(initiDlBwp->pdschPresent)
4532          pdschCfg = &initiDlBwp->pdschCfg;
4533    }
4534
4535    dlBwp->pdcch_Config = NULLP;
4536    DU_ALLOC(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
4537    if(!dlBwp->pdcch_Config)
4538    {
4539       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4540       return RFAILED;
4541    }
4542    dlBwp->pdcch_Config->present = BWP_DownlinkDedicated__pdcch_Config_PR_setup; 
4543
4544    dlBwp->pdcch_Config->choice.setup = NULLP;
4545    DU_ALLOC(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
4546    if(!dlBwp->pdcch_Config->choice.setup)
4547    {
4548       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4549       return RFAILED;
4550    }
4551    if(BuildBWPDlDedPdcchCfg(pdcchCfg, dlBwp->pdcch_Config->choice.setup) != ROK)
4552    {
4553       return RFAILED;
4554    }
4555
4556    dlBwp->pdsch_Config = NULLP;
4557    DU_ALLOC(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
4558    if(!dlBwp->pdsch_Config)
4559    {
4560       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4561       return RFAILED;
4562    }
4563    dlBwp->pdsch_Config->present = BWP_DownlinkDedicated__pdsch_Config_PR_setup;
4564
4565    dlBwp->pdsch_Config->choice.setup = NULLP;
4566    DU_ALLOC(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
4567    if(!dlBwp->pdsch_Config->choice.setup)
4568    {
4569       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4570       return RFAILED;
4571    }
4572
4573    if(BuildBWPDlDedPdschCfg(pdschCfg, dlBwp->pdsch_Config->choice.setup) != ROK)
4574    {
4575       return RFAILED;
4576    }
4577
4578    dlBwp->sps_Config = NULLP;
4579    dlBwp->radioLinkMonitoringConfig = NULLP; 
4580    return ROK;
4581 }
4582
4583 /*******************************************************************
4584  *
4585  * @brief Builds DMRS UL Pusch Mapping type A
4586  *
4587  * @details
4588  *
4589  *    Function : BuildDMRSULPuschMapTypeA
4590  *
4591  *    Functionality: Builds DMRS UL Pusch Mapping type A
4592  *
4593  * @params[in] 
4594  *    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg
4595  * @return ROK     - success
4596  *         RFAILED - failure
4597  *
4598  * ****************************************************************/
4599 uint8_t BuildDMRSULPuschMapTypeA(DmrsUlCfg *ulDmrsCfgDb, struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg)
4600 {
4601    dmrsUlCfg->present = PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup;
4602    dmrsUlCfg->choice.setup= NULLP;
4603    DU_ALLOC(dmrsUlCfg->choice.setup, sizeof(DMRS_UplinkConfig_t));
4604    if(!dmrsUlCfg->choice.setup)
4605    {
4606       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4607       return RFAILED;
4608    }
4609
4610    dmrsUlCfg->choice.setup->dmrs_Type = NULLP;
4611    dmrsUlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4612    DU_ALLOC(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4613    if(!dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
4614    {
4615       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4616       return RFAILED;
4617    }
4618    if(ulDmrsCfgDb == NULLP)
4619       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS; 
4620    else
4621       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = ulDmrsCfgDb->addPos;
4622
4623    dmrsUlCfg->choice.setup->phaseTrackingRS = NULLP;
4624    dmrsUlCfg->choice.setup->maxLength = NULLP;
4625    dmrsUlCfg->choice.setup->transformPrecodingDisabled = NULLP;
4626    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled, sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
4627    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled)
4628    {
4629       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4630       return RFAILED;
4631    }
4632
4633    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0 = NULLP;
4634    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
4635          sizeof(long));
4636    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0)
4637    {
4638       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4639       return RFAILED;
4640    }
4641    if(ulDmrsCfgDb == NULLP)
4642       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = SCRAMBLING_ID;
4643    else
4644       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = ulDmrsCfgDb->transPrecodDisabled.scramblingId0;
4645
4646    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID1 = NULLP;
4647    dmrsUlCfg->choice.setup->transformPrecodingEnabled = NULLP;
4648    return ROK;
4649 }
4650
4651 /*******************************************************************
4652  *
4653  * @brief Build PUSCH time domain allocation list
4654  *
4655  * @details
4656  *
4657  *    Function : BuildPuschTimeDomAllocList
4658  *
4659  *    Functionality: Build PUSCH time domain allocation list
4660  *
4661  * @params[in] 
4662  * struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList
4663  *
4664  * @return ROK     - success
4665  *         RFAILED - failure
4666  *
4667  * ****************************************************************/
4668 uint8_t BuildPuschTimeDomAllocList(PuschCfg *puschCfgDb, struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList)
4669 {
4670    uint8_t idx;
4671    uint8_t elementCnt;
4672    PUSCH_TimeDomainResourceAllocation_t  *timeDomAlloc;
4673
4674    timeDomAllocList->present = PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup;
4675    timeDomAllocList->choice.setup = NULLP;
4676    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PUSCH_TimeDomainResourceAllocationList));
4677    if(!timeDomAllocList->choice.setup)
4678    {
4679       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4680       return RFAILED;
4681    }
4682
4683    if(puschCfgDb == NULLP)
4684       elementCnt = 2;
4685    else
4686       elementCnt = puschCfgDb->numTimeDomRsrcAlloc;
4687
4688    timeDomAllocList->choice.setup->list.count = elementCnt;
4689    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(PUSCH_TimeDomainResourceAllocation_t *);
4690    timeDomAllocList->choice.setup->list.array = NULLP;
4691    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4692    if(!timeDomAllocList->choice.setup->list.array)
4693    {
4694       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4695       return RFAILED;
4696    }
4697
4698    for(idx = 0; idx < elementCnt; idx++)
4699    {
4700       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4701       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], sizeof(PUSCH_TimeDomainResourceAllocation_t));
4702       if(!timeDomAllocList->choice.setup->list.array[idx])
4703       {
4704          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4705          return RFAILED;
4706       }
4707    }
4708
4709    for(idx = 0; idx < elementCnt; idx++)
4710    {
4711       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4712       DU_ALLOC(timeDomAlloc->k2, sizeof(long));
4713       if(!timeDomAlloc->k2)
4714       {
4715          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4716          return RFAILED;
4717       }
4718       if(puschCfgDb == NULLP)
4719       {
4720          if(idx == 0)
4721             *(timeDomAlloc->k2) = PUSCH_K2_CFG1;
4722          else if(idx == 1)
4723             *(timeDomAlloc->k2) = PUSCH_K2_CFG2;
4724
4725          timeDomAlloc->mappingType = PUSCH_MAPPING_TYPE_A;
4726          timeDomAlloc->startSymbolAndLength = calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
4727       }
4728       else
4729       {
4730          *(timeDomAlloc->k2) = puschCfgDb->timeDomRsrcAllocList[idx].k2;
4731          timeDomAlloc->mappingType = puschCfgDb->timeDomRsrcAllocList[idx].mappingType;
4732          timeDomAlloc->startSymbolAndLength = puschCfgDb->timeDomRsrcAllocList[idx].startSymbolAndLength;
4733       }
4734    }
4735
4736    return ROK;
4737 }
4738
4739 /*******************************************************************
4740  *
4741  * @brief Builds BWP UL dedicated PUSCH Config
4742  *
4743  * @details
4744  *
4745  *    Function : BuildBWPUlDedPuschCfg
4746  *
4747  *    Functionality:
4748  *      Builds BWP UL dedicated PUSCH Config
4749  *
4750  * @params[in] : PUSCH_Config_t *puschCfg
4751  *    
4752  * @return ROK     - success
4753  *         RFAILED - failure
4754  *
4755  * ****************************************************************/
4756 uint8_t BuildBWPUlDedPuschCfg(PuschCfg *puschCfgDb, PUSCH_Config_t *puschCfg)
4757 {
4758    DmrsUlCfg *ulDmrsCfg = NULLP;
4759    
4760    if(puschCfgDb)
4761       ulDmrsCfg = &puschCfgDb->dmrsUlCfgForPuschMapTypeA;
4762
4763    puschCfg->dataScramblingIdentityPUSCH = NULLP;
4764    DU_ALLOC(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
4765    if(!puschCfg->dataScramblingIdentityPUSCH)
4766    {
4767       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4768       return RFAILED;
4769    }
4770    if(puschCfgDb == NULLP)
4771       *(puschCfg->dataScramblingIdentityPUSCH) = SCRAMBLING_ID;
4772    else
4773       *(puschCfg->dataScramblingIdentityPUSCH) = puschCfgDb->dataScramblingId;
4774
4775    puschCfg->txConfig = NULLP;
4776    puschCfg->dmrs_UplinkForPUSCH_MappingTypeA = NULLP;
4777    DU_ALLOC(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
4778    if(!puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
4779    {
4780       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4781       return RFAILED;
4782    }
4783
4784    if(BuildDMRSULPuschMapTypeA(ulDmrsCfg, puschCfg->dmrs_UplinkForPUSCH_MappingTypeA) != ROK)
4785    {
4786       return RFAILED;
4787    }
4788
4789    puschCfg->dmrs_UplinkForPUSCH_MappingTypeB = NULLP;
4790    puschCfg->pusch_PowerControl = NULLP;
4791    puschCfg->frequencyHopping = NULLP;
4792    puschCfg->frequencyHoppingOffsetLists = NULLP;
4793
4794    if(puschCfgDb == NULLP)
4795       puschCfg->resourceAllocation = RES_ALLOC_TYPE;
4796    else
4797       puschCfg->resourceAllocation = puschCfgDb->resourceAllocType;
4798
4799    puschCfg->pusch_TimeDomainAllocationList = NULLP;
4800    DU_ALLOC(puschCfg->pusch_TimeDomainAllocationList, sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
4801    if(!puschCfg->pusch_TimeDomainAllocationList)
4802    {
4803       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4804       return RFAILED;
4805    }
4806
4807    if(BuildPuschTimeDomAllocList(puschCfgDb, puschCfg->pusch_TimeDomainAllocationList) != ROK)
4808    {
4809       return RFAILED;
4810    }
4811
4812    puschCfg->pusch_AggregationFactor = NULLP;
4813    puschCfg->mcs_Table = NULLP;
4814    puschCfg->mcs_TableTransformPrecoder = NULLP;
4815    puschCfg->transformPrecoder = NULLP;
4816    DU_ALLOC(puschCfg->transformPrecoder, sizeof(long));
4817    if(!puschCfg->transformPrecoder)
4818    {
4819       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4820       return RFAILED;
4821    }
4822    if(puschCfgDb == NULLP)
4823       *(puschCfg->transformPrecoder) = PUSCH_TRANSFORM_PRECODER;
4824    else
4825       *(puschCfg->transformPrecoder) = puschCfgDb->transformPrecoder;
4826
4827    puschCfg->codebookSubset = NULLP;
4828    puschCfg->maxRank = NULLP;
4829    puschCfg->rbg_Size = NULLP;
4830    puschCfg->uci_OnPUSCH = NULLP;
4831    puschCfg->tp_pi2BPSK = NULLP;
4832
4833    return ROK;
4834 }
4835
4836 /*******************************************************************
4837  *
4838  * @brief Builds PUCCH resource set add/modify list
4839  *
4840  * @details
4841  *
4842  *    Function : BuildPucchRsrcSetAddModList
4843  *
4844  *    Functionality:
4845  *      Builds PUCCH resource set add/modify list
4846  *
4847  * @params[in] : PucchResrcSetCfg *rsrcSetCfgDb
4848  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4849  *
4850  * @return ROK     - success
4851  *         RFAILED - failure
4852  *
4853  * ****************************************************************/
4854 uint8_t BuildPucchRsrcSetAddModList(PucchResrcSetCfg *rsrcSetCfgDb, \
4855    struct PUCCH_Config__resourceSetToAddModList *resourceSetToAddModList)
4856 {
4857    uint8_t elementCnt = 0, rsrcSetIdx = 0, rsrcIdx = 0;
4858    PUCCH_ResourceSet_t *rsrcSet = NULLP;
4859
4860    if(rsrcSetCfgDb == NULLP)
4861       elementCnt = 1;
4862    else
4863       elementCnt = rsrcSetCfgDb->resrcSetToAddModListCount;
4864
4865    resourceSetToAddModList->list.count = elementCnt;
4866    resourceSetToAddModList->list.size = elementCnt * sizeof(PUCCH_ResourceSet_t *);
4867    DU_ALLOC(resourceSetToAddModList->list.array, resourceSetToAddModList->list.size);
4868    if(resourceSetToAddModList->list.array == NULLP)
4869    {
4870       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4871       return RFAILED;
4872    }
4873    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4874    {
4875       DU_ALLOC(resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
4876       if(resourceSetToAddModList->list.array[rsrcSetIdx] == NULLP)
4877       {
4878          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4879          return RFAILED;
4880       }
4881    }
4882
4883    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4884    {
4885       rsrcSet = resourceSetToAddModList->list.array[rsrcSetIdx];
4886
4887       /* Resource set Id */
4888       if(rsrcSetCfgDb == NULLP)
4889          rsrcSet->pucch_ResourceSetId = 1;
4890       else
4891          rsrcSet->pucch_ResourceSetId = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcSetId;
4892  
4893       /* Resource list of a resource set */
4894       if(rsrcSetCfgDb == NULLP)
4895          elementCnt = 1;
4896       else
4897          elementCnt = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcListCount;
4898       rsrcSet->resourceList.list.count = elementCnt;
4899       rsrcSet->resourceList.list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
4900       DU_ALLOC(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
4901       if(rsrcSet->resourceList.list.array == NULLP)
4902       {
4903          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4904          return RFAILED;
4905       }
4906
4907       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4908       {
4909          DU_ALLOC(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
4910          if(rsrcSet->resourceList.list.array[rsrcIdx] == NULLP)
4911          {
4912             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4913             return RFAILED;
4914          }
4915       }
4916       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4917       {
4918          if(rsrcSetCfgDb == NULLP)
4919             *(rsrcSet->resourceList.list.array[rsrcIdx]) = 1;
4920          else
4921             *(rsrcSet->resourceList.list.array[rsrcIdx]) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcList[rsrcIdx];
4922       }
4923
4924       /* Max payload size (minus 1) in a Resource set */
4925       rsrcSet->maxPayloadMinus1 = NULLP;
4926       if(rsrcSetCfgDb && rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize)
4927       {
4928          DU_ALLOC(rsrcSet->maxPayloadMinus1, sizeof(long));
4929          if(rsrcSet->maxPayloadMinus1 == NULLP)
4930          {
4931             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4932             return RFAILED;
4933          }
4934          *(rsrcSet->maxPayloadMinus1) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize;
4935       }
4936    }
4937    return ROK;
4938 }
4939
4940 /*******************************************************************
4941  *
4942  * @brief Builds PUCCH resource add/modify list
4943  *
4944  * @details
4945  *
4946  *    Function : BuildPucchRsrcAdddModList
4947  *
4948  *    Functionality:
4949  *      Builds PUCCH resource add/modify list
4950  *
4951  * @params[in] : PucchResrcCfg *rsrcSetCfgDb
4952  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4953  *
4954  * @return ROK     - success
4955  *         RFAILED - failure
4956  *
4957  * ****************************************************************/
4958 uint8_t BuildPucchRsrcAddModList(PucchResrcCfg *rsrcCfgDb, struct PUCCH_Config__resourceToAddModList  *resourceToAddModList)
4959 {
4960    uint8_t elementCnt = 0, rsrcIdx = 0;
4961    PUCCH_Resource_t *rsrc = NULLP;
4962
4963    if(rsrcCfgDb == NULLP)
4964       elementCnt = 1;
4965    else
4966       elementCnt = rsrcCfgDb->resrcToAddModListCount;
4967    resourceToAddModList->list.count = elementCnt;
4968    resourceToAddModList->list.size = elementCnt * sizeof(PUCCH_Resource_t *);
4969    DU_ALLOC(resourceToAddModList->list.array, resourceToAddModList->list.size);
4970    if(resourceToAddModList->list.array == NULLP)
4971    {
4972       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4973       return RFAILED;
4974    }
4975    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4976    {
4977       DU_ALLOC(resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
4978       if(resourceToAddModList->list.array[rsrcIdx] == NULLP)
4979       {
4980          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4981          return RFAILED;
4982       }
4983    }
4984
4985    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4986    {
4987       rsrc = resourceToAddModList->list.array[rsrcIdx];
4988
4989       if(rsrcCfgDb == NULLP)
4990       {
4991          rsrc->pucch_ResourceId = 1;
4992          rsrc->startingPRB = 0;
4993          rsrc->format.present = PUCCH_Resource__format_PR_format1; 
4994          DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4995          if(rsrc->format.choice.format1 == NULLP)
4996          {
4997             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4998             return RFAILED;
4999          }  
5000          rsrc->format.choice.format1->initialCyclicShift = 0;
5001          rsrc->format.choice.format1->nrofSymbols = 4;
5002          rsrc->format.choice.format1->startingSymbolIndex = 0;
5003          rsrc->format.choice.format1->timeDomainOCC = 0;
5004       }
5005       else
5006       {
5007          rsrc->pucch_ResourceId = rsrcCfgDb->resrcToAddModList[rsrcIdx].resrcId;
5008          rsrc->startingPRB = rsrcCfgDb->resrcToAddModList[rsrcIdx].startPrb;
5009          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop)
5010          {
5011             DU_ALLOC(rsrc->intraSlotFrequencyHopping, sizeof(long));
5012             if(rsrc->intraSlotFrequencyHopping == NULLP)
5013             {
5014                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5015                return RFAILED;
5016             }
5017             *(rsrc->intraSlotFrequencyHopping) = rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop;
5018          }
5019          else
5020             rsrc->intraSlotFrequencyHopping = NULLP;
5021
5022          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop)
5023          {
5024             DU_ALLOC(rsrc->secondHopPRB, sizeof(PRB_Id_t));
5025             if(rsrc->secondHopPRB == NULLP)
5026             {
5027                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5028                return RFAILED;
5029             }
5030             *(rsrc->secondHopPRB) = rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop;
5031          }
5032          else
5033             rsrc->secondHopPRB = NULLP;
5034          rsrc->format.present = covertPucchFormatIntEnumToRrcEnum(rsrcCfgDb->resrcToAddModList[rsrcIdx].pucchFormat); 
5035
5036          switch(rsrc->format.present)
5037          {
5038             case PUCCH_Resource__format_PR_NOTHING:
5039                break;
5040             case PUCCH_Resource__format_PR_format0:
5041                {
5042                   DU_ALLOC(rsrc->format.choice.format0, sizeof(PUCCH_format0_t));
5043                   if(rsrc->format.choice.format0 == NULLP)
5044                   {
5045                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5046                      return RFAILED;
5047                   }
5048                   rsrc->format.choice.format0->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->initialCyclicShift;
5049                   rsrc->format.choice.format0->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->numSymbols;
5050                   rsrc->format.choice.format0->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->startSymbolIdx;
5051                   break;
5052                }
5053
5054             case PUCCH_Resource__format_PR_format1:
5055                {
5056                   DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
5057                   if(rsrc->format.choice.format1 == NULLP)
5058                   {
5059                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5060                      return RFAILED;
5061                   }  
5062                   rsrc->format.choice.format1->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->initialCyclicShift;
5063                   rsrc->format.choice.format1->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->numSymbols;
5064                   rsrc->format.choice.format1->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->startSymbolIdx;
5065                   rsrc->format.choice.format1->timeDomainOCC = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->timeDomOCC;
5066                   break;
5067                }
5068
5069             case PUCCH_Resource__format_PR_format2:
5070                {
5071                   DU_ALLOC(rsrc->format.choice.format2, sizeof(PUCCH_format2_t));
5072                   if(rsrc->format.choice.format2 == NULLP)
5073                   {
5074                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5075                      return RFAILED;
5076                   } 
5077                   rsrc->format.choice.format2->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numPrbs;
5078                   rsrc->format.choice.format2->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numSymbols;
5079                   rsrc->format.choice.format2->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->startSymbolIdx;
5080                   break;
5081                }
5082
5083             case PUCCH_Resource__format_PR_format3:
5084                {
5085                   DU_ALLOC(rsrc->format.choice.format3, sizeof(PUCCH_format3_t));
5086                   if(rsrc->format.choice.format3 == NULLP)
5087                   {
5088                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5089                      return RFAILED;
5090                   }
5091                   rsrc->format.choice.format3->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numPrbs;
5092                   rsrc->format.choice.format3->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numSymbols;
5093                   rsrc->format.choice.format3->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->startSymbolIdx;
5094                   break;
5095                }
5096
5097             case PUCCH_Resource__format_PR_format4:
5098                {
5099                   DU_ALLOC(rsrc->format.choice.format4, sizeof(PUCCH_format4_t));
5100                   if(rsrc->format.choice.format4 == NULLP)
5101                   {
5102                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
5103                      return RFAILED;
5104                   }
5105                   rsrc->format.choice.format4->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->numSymbols;
5106                   rsrc->format.choice.format4->occ_Length = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occLen;
5107                   rsrc->format.choice.format4->occ_Index = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occIdx;
5108                   rsrc->format.choice.format4->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->startSymbolIdx;
5109                   break;
5110                }
5111          }
5112       }
5113    }
5114    return ROK;
5115 }
5116
5117 /*******************************************************************
5118  *
5119  * @brief Builds PUCCH format  config
5120  *
5121  * @details
5122  *
5123  *    Function : BuildPucchFormat
5124  *
5125  *    Functionality: Builds PUCCH format  config
5126  *
5127  * @params[in] : PucchFormatCfg *formatDb
5128  *               PUCCH_FormatConfig_t *format
5129  *
5130  * @return ROK     - success
5131  *         RFAILED - failure
5132  *
5133  * ****************************************************************/
5134 uint8_t BuildPucchFormat(PucchFormatCfg *formatDb, PUCCH_FormatConfig_t *format)
5135 {
5136    /* Inter Slot Fequency hopping */
5137    format->interslotFrequencyHopping = NULLP;
5138    if((formatDb != NULLP) && (formatDb->interSlotFreqHop == true))
5139    {
5140       DU_ALLOC(format->interslotFrequencyHopping, sizeof(long));
5141       if(format->interslotFrequencyHopping)
5142       {
5143          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5144          return RFAILED;
5145       }
5146       *(format->interslotFrequencyHopping) = PUCCH_FormatConfig__interslotFrequencyHopping_enabled;
5147    }
5148
5149    /* Additional DMRS */
5150    format->additionalDMRS = NULLP;
5151    if((formatDb != NULLP) && (formatDb->addDmrs == true))
5152    {
5153       DU_ALLOC(format->additionalDMRS, sizeof(long));
5154       if(format->additionalDMRS)
5155       {
5156          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5157          return RFAILED;
5158       }
5159       *(format->additionalDMRS) = PUCCH_FormatConfig__additionalDMRS_true;
5160    }
5161
5162     /* Maximum code rate */
5163    format->maxCodeRate = NULLP;
5164    if((formatDb != NULLP) && (formatDb->maxCodeRate != 0))
5165    {
5166       DU_ALLOC(format->maxCodeRate, sizeof(long));
5167       if(format->maxCodeRate)
5168       {
5169          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5170          return RFAILED;
5171       }  
5172       *(format->maxCodeRate) = formatDb->maxCodeRate;
5173    }
5174  
5175    /* Number of slots */
5176    format->nrofSlots = NULLP;
5177    if((formatDb == NULLP) || ((formatDb != NULLP) && (formatDb->numSlots != 0)))
5178    {
5179       DU_ALLOC(format->nrofSlots, sizeof(long));
5180       if(format->nrofSlots == NULLP)
5181       {
5182          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5183          return RFAILED;
5184       }
5185       if(formatDb == NULLP)
5186          *(format->nrofSlots) = PUCCH_FormatConfig__nrofSlots_n4;
5187       else
5188          *(format->nrofSlots) = formatDb->numSlots;
5189    }
5190
5191    /* Pi2BPSK*/
5192    format->pi2BPSK = NULLP;
5193    if((formatDb != NULLP) && (formatDb->pi2BPSK == true))
5194    {
5195       DU_ALLOC(format->pi2BPSK, sizeof(long));
5196       if(format->pi2BPSK)
5197       {     
5198          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5199          return RFAILED;
5200       }     
5201       *(format->pi2BPSK) = PUCCH_FormatConfig__pi2BPSK_enabled;
5202    }
5203
5204    /* Simultaneous HARQ ACK and CSI */
5205    format->simultaneousHARQ_ACK_CSI = NULLP;
5206    if((formatDb != NULLP) && (formatDb->harqAckCSI == true))
5207    {
5208       DU_ALLOC(format->simultaneousHARQ_ACK_CSI, sizeof(long));
5209       if(format->simultaneousHARQ_ACK_CSI)
5210       {     
5211          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
5212          return RFAILED;
5213       }     
5214       *(format->simultaneousHARQ_ACK_CSI) = PUCCH_FormatConfig__simultaneousHARQ_ACK_CSI_true;
5215    }
5216
5217    return ROK;
5218 }
5219
5220
5221 /*******************************************************************
5222  *
5223  * @brief Builds PUCCH scheduling request list
5224  *
5225  * @details
5226  *
5227  *    Function : BuildPucchSchReqAddModList
5228  *
5229  *    Functionality:
5230  *      Builds PUCCH scheduling request list
5231  *
5232  * @params[in] : PucchSchedReqCfg *schReqDb
5233  *               struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList
5234  *
5235  * @return ROK     - success
5236  *         RFAILED - failure
5237  *
5238  * ****************************************************************/
5239 uint8_t BuildPucchSchReqAddModList(PucchSchedReqCfg *schReqDb, \
5240    struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList)
5241 {
5242    uint8_t elementCnt = 0, schReqIdx = 0;
5243    SchedulingRequestResourceConfig_t *schReqRsrc;
5244
5245    elementCnt = schReqDb->schedAddModListCount;
5246    schReqRsrcToAddModList->list.count = elementCnt;
5247    schReqRsrcToAddModList->list.size = elementCnt *sizeof(struct SchedulingRequestResourceConfig *);
5248
5249    schReqRsrcToAddModList->list.array = NULLP;
5250    DU_ALLOC(schReqRsrcToAddModList->list.array, schReqRsrcToAddModList->list.size);
5251    if(schReqRsrcToAddModList->list.array == NULLP)
5252    {
5253       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5254       return RFAILED;
5255    }
5256
5257    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
5258    {
5259       DU_ALLOC(schReqRsrcToAddModList->list.array[schReqIdx], schReqRsrcToAddModList->list.size);
5260       if(schReqRsrcToAddModList->list.array[schReqIdx] == NULLP)
5261       {
5262          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5263          return RFAILED;
5264       }
5265    }
5266
5267    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
5268    {
5269       schReqRsrc = schReqRsrcToAddModList->list.array[schReqIdx];
5270       schReqRsrc->schedulingRequestResourceId = schReqDb->schedAddModList[schReqIdx].resrcId;
5271       schReqRsrc->schedulingRequestID = schReqDb->schedAddModList[schReqIdx].requestId;
5272
5273       if(schReqDb->schedAddModList[schReqIdx].periodicity)
5274       {
5275          schReqRsrc->periodicityAndOffset = NULLP;
5276          DU_ALLOC(schReqRsrc->periodicityAndOffset, sizeof(struct SchedulingRequestResourceConfig__periodicityAndOffset));
5277          if(schReqRsrc->periodicityAndOffset == NULLP)
5278          {
5279             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5280             return RFAILED;
5281          }
5282
5283          schReqRsrc->periodicityAndOffset->present = schReqDb->schedAddModList[schReqIdx].periodicity;
5284          switch(schReqRsrc->periodicityAndOffset->present)
5285          {
5286             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_NOTHING:
5287                break;
5288             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
5289                schReqRsrc->periodicityAndOffset->choice.sym2 = schReqDb->schedAddModList[schReqIdx].offset;
5290                break;
5291             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
5292                schReqRsrc->periodicityAndOffset->choice.sym6or7 = schReqDb->schedAddModList[schReqIdx].offset;
5293                break;
5294             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
5295                schReqRsrc->periodicityAndOffset->choice.sl1 = schReqDb->schedAddModList[schReqIdx].offset;
5296                break;
5297             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
5298                schReqRsrc->periodicityAndOffset->choice.sl2 = schReqDb->schedAddModList[schReqIdx].offset;
5299                break;
5300             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
5301                schReqRsrc->periodicityAndOffset->choice.sl4 = schReqDb->schedAddModList[schReqIdx].offset;
5302                break;
5303             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
5304                schReqRsrc->periodicityAndOffset->choice.sl5 = schReqDb->schedAddModList[schReqIdx].offset;
5305                break;
5306             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
5307                schReqRsrc->periodicityAndOffset->choice.sl8 = schReqDb->schedAddModList[schReqIdx].offset;
5308                break;
5309             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
5310                schReqRsrc->periodicityAndOffset->choice.sl10 = schReqDb->schedAddModList[schReqIdx].offset;
5311                break;
5312             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
5313                schReqRsrc->periodicityAndOffset->choice.sl16 = schReqDb->schedAddModList[schReqIdx].offset;
5314                break;
5315             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
5316                schReqRsrc->periodicityAndOffset->choice.sl20 = schReqDb->schedAddModList[schReqIdx].offset;
5317                break;
5318             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
5319                schReqRsrc->periodicityAndOffset->choice.sl40 = schReqDb->schedAddModList[schReqIdx].offset;
5320                break;
5321             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
5322                schReqRsrc->periodicityAndOffset->choice.sl80 = schReqDb->schedAddModList[schReqIdx].offset;
5323                break;
5324             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
5325                schReqRsrc->periodicityAndOffset->choice.sl160 = schReqDb->schedAddModList[schReqIdx].offset;
5326                break;
5327             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
5328                schReqRsrc->periodicityAndOffset->choice.sl320 = schReqDb->schedAddModList[schReqIdx].offset;
5329                break;
5330             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
5331                schReqRsrc->periodicityAndOffset->choice.sl640 = schReqDb->schedAddModList[schReqIdx].offset;
5332                break;
5333          }
5334       }
5335
5336       if(schReqDb->schedAddModList[schReqIdx].resrc)
5337       {
5338          schReqRsrc->resource = NULLP;
5339          DU_ALLOC(schReqRsrc->resource, sizeof(PUCCH_ResourceId_t));
5340          if(schReqRsrc->resource == NULLP)
5341          {
5342             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5343             return RFAILED;
5344          }
5345          *(schReqRsrc->resource) = schReqDb->schedAddModList[schReqIdx].resrc;
5346
5347       }
5348    }
5349    return ROK;
5350 }
5351
5352 /*******************************************************************
5353  *
5354  * @brief Builds PUCCH multi csi resource list
5355  *
5356  * @details
5357  *
5358  *    Function : BuildPucchMultiCsiRsrcList
5359  *
5360  *    Functionality:
5361  *      Builds PUCCH multi csi resource list
5362  *
5363  * @params[in] : PucchMultiCsiCfg *multiCsiDb
5364  *               struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList
5365  *
5366  * @return ROK     - success
5367  *         RFAILED - failure
5368  *
5369  * ****************************************************************/
5370 uint8_t BuildPucchMultiCsiRsrcList(PucchMultiCsiCfg *multiCsiDb, struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList)
5371 {
5372    uint8_t elementCnt = 0, rsrcIdx = 0;
5373
5374    elementCnt = multiCsiDb->multiCsiResrcListCount;
5375    multiCsiRsrcList->list.count = elementCnt;
5376    multiCsiRsrcList->list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
5377    multiCsiRsrcList->list.array = NULLP;
5378    DU_ALLOC(multiCsiRsrcList->list.array, multiCsiRsrcList->list.size);
5379    if(multiCsiRsrcList->list.array == NULLP)
5380    {
5381       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5382       return RFAILED;
5383    }
5384
5385    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5386    {
5387       DU_ALLOC(multiCsiRsrcList->list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
5388       if(multiCsiRsrcList->list.array[rsrcIdx] == NULLP)
5389       {
5390          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5391          return RFAILED;
5392       }
5393    }
5394
5395    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5396    {
5397       *(multiCsiRsrcList->list.array[rsrcIdx]) = multiCsiDb->multiCsiResrcList[rsrcIdx];
5398    }
5399    return ROK;
5400 }
5401
5402 /*******************************************************************
5403  *
5404  * @brief Builds DL data -to- Ul Ack list
5405  *
5406  * @details
5407  *
5408  *    Function : BuildDlDataToUlAckList
5409  *
5410  *    Functionality: Builds DL data -to- Ul Ack list
5411  *
5412  * @params[in] : PucchDlDataToUlAck *dlDataToUlAckDb
5413  *               struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList
5414  *
5415  * @return ROK     - success
5416  *         RFAILED - failure
5417  *
5418  * ****************************************************************/
5419 uint8_t BuildDlDataToUlAckList(PucchDlDataToUlAck *dlDataToUlAckDb, struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList)
5420 {
5421    uint8_t elementCnt = 0, arrIdx = 0;
5422
5423    if(dlDataToUlAckDb == NULLP)
5424       elementCnt = 2;
5425    else
5426       elementCnt = dlDataToUlAckDb->dlDataToUlAckListCount;
5427
5428    dlDataToUlACKList->list.count = elementCnt;
5429    dlDataToUlACKList->list.size = elementCnt * sizeof(long *);
5430    DU_ALLOC(dlDataToUlACKList->list.array, dlDataToUlACKList->list.size);
5431    if(dlDataToUlACKList->list.array == NULLP)
5432    {
5433       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5434       return RFAILED;
5435    }   
5436
5437    for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5438    {
5439       DU_ALLOC(dlDataToUlACKList->list.array[arrIdx], sizeof(long));
5440       if(dlDataToUlACKList->list.array[arrIdx] == NULLP)
5441       {
5442          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5443          return RFAILED;
5444       }   
5445    }
5446
5447    if(dlDataToUlAckDb == NULLP)
5448    {
5449       arrIdx = 0;
5450       *(dlDataToUlACKList->list.array[arrIdx++]) = 1;
5451       *(dlDataToUlACKList->list.array[arrIdx]) = 2;
5452    }
5453    else
5454    {
5455       for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5456       {
5457          *(dlDataToUlACKList->list.array[arrIdx]) = dlDataToUlAckDb->dlDataToUlAckList[arrIdx];
5458       }
5459    }
5460    return ROK;
5461 }
5462
5463 /*******************************************************************
5464  *
5465  * @brief Builds BWP UL dedicated PUCCH Config
5466  *
5467  * @details
5468  *
5469  *    Function : BuildBWPUlDedPucchCfg
5470  *
5471  *    Functionality:
5472  *      Builds BWP UL dedicated PUCCH Config
5473  *
5474  * @params[in] : PUCCH_Config_t *pucchCfg
5475  *
5476  * @return ROK     - success
5477  *         RFAILED - failure
5478  *
5479  * ****************************************************************/
5480 uint8_t BuildBWPUlDedPucchCfg(PucchCfg *pucchCfgDb, PUCCH_Config_t *pucchCfg)
5481 {
5482    PucchResrcSetCfg *rsrcSetCfgDb = NULLP;
5483    PucchResrcCfg *rsrcCfgDb = NULLP;
5484    PucchFormatCfg *format1Db = NULLP;
5485    PucchFormatCfg *format2Db = NULLP;
5486    PucchFormatCfg *format3Db = NULLP;
5487    PucchFormatCfg *format4Db = NULLP;
5488    PucchSchedReqCfg *schReqDb = NULLP;   
5489    PucchMultiCsiCfg  *multiCsiDb = NULLP;
5490    PucchDlDataToUlAck *dlDataToUlAckDb = NULLP;
5491
5492    if(pucchCfgDb)
5493    {
5494       rsrcSetCfgDb = pucchCfgDb->resrcSet;
5495       rsrcCfgDb = pucchCfgDb->resrc;
5496       format1Db = pucchCfgDb->format1;
5497       format2Db = pucchCfgDb->format2;
5498       format3Db = pucchCfgDb->format3;
5499       format4Db = pucchCfgDb->format4;
5500       schReqDb = pucchCfgDb->schedReq;
5501       multiCsiDb = pucchCfgDb->multiCsiCfg;
5502       dlDataToUlAckDb = pucchCfgDb->dlDataToUlAck;
5503    }
5504
5505    /* RESOURCE SET */
5506    DU_ALLOC(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
5507    if(pucchCfg->resourceSetToAddModList == NULL)
5508    {
5509       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5510       return RFAILED;
5511    }
5512
5513    if(BuildPucchRsrcSetAddModList(rsrcSetCfgDb, pucchCfg->resourceSetToAddModList) != ROK)
5514    {
5515       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5516       return RFAILED;
5517    }
5518
5519    /* PUCCH RESOURCE */
5520    DU_ALLOC(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
5521    if(pucchCfg->resourceToAddModList == NULLP)
5522    {
5523       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5524       return RFAILED;
5525    }
5526
5527    if(BuildPucchRsrcAddModList(rsrcCfgDb, pucchCfg->resourceToAddModList) != ROK)
5528    {
5529       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5530       return RFAILED;
5531    }
5532
5533    /* PUCCH Format 1 */
5534    DU_ALLOC(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
5535    if(pucchCfg->format1 == NULLP)
5536    {
5537       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5538       return RFAILED;
5539    }
5540    
5541    pucchCfg->format1->present = PUCCH_Config__format1_PR_setup;
5542    DU_ALLOC(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
5543    if(pucchCfg->format1->choice.setup == NULLP)
5544    {
5545       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5546       return RFAILED;
5547    }
5548
5549    if(BuildPucchFormat(format1Db, pucchCfg->format1->choice.setup) != ROK)
5550    {
5551       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5552       return RFAILED;
5553    }
5554
5555    /* PUCCH Format 2 */
5556    if(format2Db)
5557    {
5558       DU_ALLOC(pucchCfg->format2, sizeof(struct PUCCH_Config__format2));
5559       if(pucchCfg->format2 == NULLP)
5560       {
5561          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5562          return RFAILED;
5563       }
5564
5565       pucchCfg->format2->present = PUCCH_Config__format2_PR_setup;
5566       DU_ALLOC(pucchCfg->format2->choice.setup, sizeof(PUCCH_FormatConfig_t));
5567       if(pucchCfg->format2->choice.setup == NULLP)
5568       {
5569          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5570          return RFAILED;
5571       }
5572
5573       if(BuildPucchFormat(format2Db, pucchCfg->format2->choice.setup) != ROK)
5574       {
5575          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5576          return RFAILED;
5577       }
5578    }
5579
5580    /* PUCCH Format 3 */
5581    if(format3Db)
5582    {
5583       DU_ALLOC(pucchCfg->format3, sizeof(struct PUCCH_Config__format3));
5584       if(pucchCfg->format3 == NULLP)
5585       {
5586          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5587          return RFAILED;
5588       }
5589
5590       pucchCfg->format3->present = PUCCH_Config__format3_PR_setup;
5591       DU_ALLOC(pucchCfg->format3->choice.setup, sizeof(PUCCH_FormatConfig_t));
5592       if(pucchCfg->format3->choice.setup == NULLP)
5593       {
5594          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5595          return RFAILED;
5596       }
5597
5598       if(BuildPucchFormat(format3Db, pucchCfg->format3->choice.setup) != ROK)
5599       {
5600          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5601          return RFAILED;
5602       }
5603    }
5604
5605    /* PUCCH Format 4 */
5606    if(format4Db)
5607    {
5608       DU_ALLOC(pucchCfg->format4, sizeof(struct PUCCH_Config__format4));
5609       if(pucchCfg->format4 == NULLP)
5610       {
5611          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5612          return RFAILED;
5613       }
5614
5615       pucchCfg->format4->present = PUCCH_Config__format4_PR_setup;
5616       DU_ALLOC(pucchCfg->format4->choice.setup, sizeof(PUCCH_FormatConfig_t));
5617       if(pucchCfg->format4->choice.setup == NULLP)
5618       {
5619          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5620          return RFAILED;
5621       }
5622
5623       if(BuildPucchFormat(format4Db, pucchCfg->format4->choice.setup) != ROK)
5624       {
5625          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5626          return RFAILED;
5627       }
5628    }
5629
5630    /* Scheduling Request */
5631    if(schReqDb && (schReqDb->schedAddModListCount != 0))
5632    {
5633       pucchCfg->schedulingRequestResourceToAddModList = NULLP;
5634       DU_ALLOC(pucchCfg->schedulingRequestResourceToAddModList, sizeof(struct PUCCH_Config__schedulingRequestResourceToAddModList));
5635       if(pucchCfg->schedulingRequestResourceToAddModList == NULLP)
5636       {
5637          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5638          return RFAILED;
5639       }
5640
5641       if(BuildPucchSchReqAddModList(schReqDb, pucchCfg->schedulingRequestResourceToAddModList) != ROK)
5642       {
5643          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5644          return RFAILED;
5645       }
5646    }
5647
5648    /* Multi CSI */
5649    if(multiCsiDb && (multiCsiDb->multiCsiResrcListCount != 0))
5650    {
5651       pucchCfg->multi_CSI_PUCCH_ResourceList = NULLP;
5652       DU_ALLOC(pucchCfg->multi_CSI_PUCCH_ResourceList, sizeof(struct PUCCH_Config__multi_CSI_PUCCH_ResourceList));
5653       if(pucchCfg->multi_CSI_PUCCH_ResourceList == NULLP)
5654       {
5655          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5656          return RFAILED;
5657       }
5658
5659       if(BuildPucchMultiCsiRsrcList(multiCsiDb, pucchCfg->multi_CSI_PUCCH_ResourceList) != ROK)
5660       {
5661          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5662          return RFAILED;
5663       }
5664    }
5665
5666    /* DL DATA TO UL ACK */
5667    DU_ALLOC(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
5668    if(pucchCfg->dl_DataToUL_ACK == NULLP)
5669    {
5670       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5671       return RFAILED;
5672    }
5673
5674    if(BuildDlDataToUlAckList(dlDataToUlAckDb, pucchCfg->dl_DataToUL_ACK) != ROK)
5675    {
5676       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5677       return RFAILED;
5678    }
5679    
5680    /* TODO : spatial relation info add/mod list and power control*/
5681
5682    return ROK;
5683 }
5684
5685 /*******************************************************************
5686  *
5687  * @brief Fills SRS resource to add/modify list 
5688  *
5689  * @details
5690  *
5691  *    Function : BuildSrsRsrcAddModList
5692  *
5693  *    Functionality: Fills SRS resource to add/modify list
5694  *
5695  * @params[in] 
5696  * @return ROK     - success
5697  *         RFAILED - failure
5698  *
5699  * ****************************************************************/
5700 uint8_t BuildSrsRsrcAddModList(struct SRS_Config__srs_ResourceToAddModList *resourceList)
5701 {
5702    uint8_t   elementCnt;
5703    uint8_t   rsrcIdx;
5704
5705    elementCnt = 1;
5706    resourceList->list.count = elementCnt;
5707    resourceList->list.size = elementCnt * sizeof(SRS_Resource_t *);
5708    resourceList->list.array = NULLP;
5709    DU_ALLOC(resourceList->list.array, resourceList->list.size);
5710    if(!resourceList->list.array)
5711    {
5712       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5713       return RFAILED;
5714    }
5715
5716    for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
5717    {
5718       DU_ALLOC(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
5719       if(!resourceList->list.array[rsrcIdx])
5720       {
5721          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5722          return RFAILED;
5723       }
5724    }
5725
5726    rsrcIdx = 0;
5727    resourceList->list.array[rsrcIdx]->srs_ResourceId = SRS_RSRC_ID;
5728    resourceList->list.array[rsrcIdx]->nrofSRS_Ports = SRS_Resource__nrofSRS_Ports_port1;
5729    resourceList->list.array[rsrcIdx]->transmissionComb.present = SRS_Resource__transmissionComb_PR_n2;
5730
5731    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2 = NULLP;
5732    DU_ALLOC(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2, \
5733          sizeof(struct SRS_Resource__transmissionComb__n2));
5734    if(!resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2)
5735    {
5736       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5737       return RFAILED;
5738    }
5739    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->combOffset_n2\
5740       = SRS_COMB_OFFSET_N2;
5741    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->cyclicShift_n2\
5742       = SRS_CYCLIC_SHIFT_N2;
5743
5744    resourceList->list.array[rsrcIdx]->resourceMapping.startPosition = \
5745                                                                       PUSCH_START_SYMBOL;
5746    resourceList->list.array[rsrcIdx]->resourceMapping.nrofSymbols =  \
5747                                                                      SRS_Resource__resourceMapping__nrofSymbols_n1;
5748    resourceList->list.array[rsrcIdx]->resourceMapping.repetitionFactor = \
5749                                                                          SRS_Resource__resourceMapping__repetitionFactor_n1;
5750
5751    resourceList->list.array[rsrcIdx]->freqDomainPosition = SRS_FREQ_DOM_POS;
5752    resourceList->list.array[rsrcIdx]->freqDomainShift = SRS_FREQ_DOM_SHIFT;
5753    resourceList->list.array[rsrcIdx]->freqHopping.c_SRS = C_SRS;
5754    resourceList->list.array[rsrcIdx]->freqHopping.b_SRS = B_SRS;
5755    resourceList->list.array[rsrcIdx]->freqHopping.b_hop = B_HOP;
5756    resourceList->list.array[rsrcIdx]->groupOrSequenceHopping = \
5757                                                                SRS_Resource__groupOrSequenceHopping_neither;
5758
5759    /* Setting resource type to aperiodic for intergration purposes */
5760    resourceList->list.array[rsrcIdx]->resourceType.present = \
5761                                                              SRS_Resource__resourceType_PR_aperiodic;
5762    resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic = NULLP;
5763    DU_ALLOC(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,
5764          sizeof(struct SRS_Resource__resourceType__aperiodic));
5765    if(!resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic)
5766    {
5767       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5768       return RFAILED;
5769    }
5770
5771    resourceList->list.array[rsrcIdx]->sequenceId = SRS_SEQ_ID;
5772
5773    return ROK;
5774 }
5775
5776 /*******************************************************************
5777  *
5778  * @brief Build SRS resource set Add/mod list
5779  *
5780  * @details
5781  *
5782  *    Function : BuildSrsRsrcSetAddModList
5783  *
5784  *    Functionality: Build SRS resource set Add/mod list
5785  *
5786  * @params[in] 
5787  * @return ROK     - success
5788  *         RFAILED - failure
5789  *
5790  * ****************************************************************/
5791    uint8_t BuildSrsRsrcSetAddModList
5792 (
5793  struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList
5794  )
5795 {
5796    uint8_t  elementCnt;
5797    uint8_t  rSetIdx;
5798    uint8_t  rsrcIdx;
5799    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList;
5800
5801    elementCnt = 1;
5802    rsrcSetList->list.count = elementCnt;
5803    rsrcSetList->list.size = elementCnt * sizeof(SRS_ResourceSet_t *);
5804    rsrcSetList->list.array = NULLP;
5805    DU_ALLOC(rsrcSetList->list.array, rsrcSetList->list.size);
5806    if(!rsrcSetList->list.array)
5807    {
5808       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5809       return RFAILED;
5810    }
5811
5812    for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
5813    {
5814       DU_ALLOC(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
5815       if(!rsrcSetList->list.array[rSetIdx])
5816       {
5817          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5818          return RFAILED;
5819       }
5820    }
5821
5822    rSetIdx = 0;
5823    rsrcSetList->list.array[rSetIdx]->srs_ResourceSetId = SRS_RSET_ID;
5824
5825    /* Fill Resource Id list in resource set */
5826    rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList = NULLP;
5827    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
5828          sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
5829    if(!rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
5830    {
5831       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5832       return RFAILED;
5833    }
5834
5835    elementCnt = 1;
5836    rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
5837    rsrcIdList->list.count = elementCnt;
5838    rsrcIdList->list.size = elementCnt * sizeof(SRS_ResourceId_t *);
5839    rsrcIdList->list.array = NULLP;
5840    DU_ALLOC(rsrcIdList->list.array, rsrcIdList->list.size);
5841    if(!rsrcIdList->list.array)
5842    {
5843       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5844       return RFAILED;
5845    }
5846
5847    for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
5848    {
5849       DU_ALLOC(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
5850       if(!rsrcIdList->list.array[rsrcIdx])
5851       {
5852          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5853          return RFAILED;
5854       }
5855    }
5856
5857    rsrcIdx = 0;
5858    *rsrcIdList->list.array[rsrcIdx] = SRS_RSRC_ID;
5859
5860    /* Fill resource type */
5861    rsrcSetList->list.array[rSetIdx]->resourceType.present = \
5862                                                             SRS_ResourceSet__resourceType_PR_aperiodic;
5863
5864    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic = NULLP;
5865    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
5866          sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
5867    if(!rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic)
5868    {
5869       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5870       return RFAILED;
5871    }
5872    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->aperiodicSRS_ResourceTrigger \
5873       = APERIODIC_SRS_RESRC_TRIGGER;
5874
5875    /* TODO : Fill values for below IEs as expected by Viavi */
5876    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->csi_RS = NULLP;
5877    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->slotOffset = NULLP;
5878
5879
5880    rsrcSetList->list.array[rSetIdx]->usage = SRS_ResourceSet__usage_codebook;
5881    rsrcSetList->list.array[rSetIdx]->alpha = NULLP;
5882    rsrcSetList->list.array[rSetIdx]->p0 = NULLP;
5883    rsrcSetList->list.array[rSetIdx]->pathlossReferenceRS = NULLP;
5884    rsrcSetList->list.array[rSetIdx]->srs_PowerControlAdjustmentStates = NULLP;
5885
5886    return ROK;
5887 }
5888
5889 /*******************************************************************
5890  *
5891  * @brief Builds BWP UL dedicated SRS Config
5892  *
5893  * @details
5894  *
5895  *    Function : BuildBWPUlDedSrsCfg
5896  *
5897  *    Functionality: Builds BWP UL dedicated SRS Config
5898  *
5899  * @params[in] SRS Config 
5900  * @return ROK     - success
5901  *         RFAILED - failure
5902  *
5903  * ****************************************************************/
5904 uint8_t BuildBWPUlDedSrsCfg(SRS_Config_t *srsCfg)
5905 {
5906    srsCfg->srs_ResourceSetToReleaseList = NULLP;
5907    srsCfg->srs_ResourceSetToAddModList = NULLP;
5908    DU_ALLOC(srsCfg->srs_ResourceSetToAddModList, \
5909          sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
5910    if(!srsCfg->srs_ResourceSetToAddModList)
5911    {
5912       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5913       return RFAILED;
5914    }
5915    if(BuildSrsRsrcSetAddModList(srsCfg->srs_ResourceSetToAddModList) != ROK)
5916    {
5917       return RFAILED;
5918    }
5919
5920    srsCfg->srs_ResourceToReleaseList = NULLP;
5921
5922    /* Resource to Add/Modify list */
5923    srsCfg->srs_ResourceToAddModList = NULLP;
5924    DU_ALLOC(srsCfg->srs_ResourceToAddModList, \
5925          sizeof(struct SRS_Config__srs_ResourceToAddModList));
5926    if(!srsCfg->srs_ResourceToAddModList)
5927    {
5928       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5929       return RFAILED;
5930    }
5931
5932    if(BuildSrsRsrcAddModList(srsCfg->srs_ResourceToAddModList) != ROK)
5933    {
5934       return RFAILED;
5935    }
5936    srsCfg->tpc_Accumulation = NULLP;
5937
5938    return ROK;
5939 }
5940
5941
5942
5943 /*******************************************************************
5944  *
5945  * @brief Builds Pusch Serving cell Config
5946  *
5947  * @details
5948  *
5949  *    Function : BuildPuschSrvCellCfg
5950  *
5951  *    Functionality: Builds Pusch Serving cell Config
5952  *
5953  * @params[in] struct UplinkConfig__pusch_ServingCellConfig *puschCfg
5954  *
5955  * @return ROK     - success
5956  *         RFAILED - failure
5957  *
5958  * ****************************************************************/
5959 uint8_t BuildPuschSrvCellCfg(struct UplinkConfig__pusch_ServingCellConfig *puschCfg)
5960 {
5961    puschCfg->present = UplinkConfig__pusch_ServingCellConfig_PR_setup;
5962    puschCfg->choice.setup = NULLP;
5963    DU_ALLOC(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
5964    if(!puschCfg->choice.setup)
5965    {
5966       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5967       return RFAILED;
5968    }
5969
5970    puschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5971    puschCfg->choice.setup->rateMatching = NULLP;
5972    puschCfg->choice.setup->xOverhead = NULLP;
5973    puschCfg->choice.setup->ext1 = NULLP;
5974
5975    DU_ALLOC(puschCfg->choice.setup->ext1, sizeof(struct PUSCH_ServingCellConfig__ext1));
5976    if(!puschCfg->choice.setup->ext1)
5977    {
5978       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5979       return RFAILED;
5980    }
5981
5982    puschCfg->choice.setup->ext1->maxMIMO_Layers = NULLP;
5983    DU_ALLOC(puschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5984    if(!puschCfg->choice.setup->ext1->maxMIMO_Layers)
5985    {
5986       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5987       return RFAILED;
5988    }
5989    *(puschCfg->choice.setup->ext1->maxMIMO_Layers) = PUSCH_MAX_MIMO_LAYERS;
5990
5991    puschCfg->choice.setup->ext1->processingType2Enabled= NULLP;
5992    DU_ALLOC(puschCfg->choice.setup->ext1->processingType2Enabled,sizeof(BOOLEAN_t));
5993    if(!puschCfg->choice.setup->ext1->processingType2Enabled)
5994    {
5995       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5996       return RFAILED;
5997    }
5998    *(puschCfg->choice.setup->ext1->processingType2Enabled) = PUSCH_PROCESS_TYPE2_ENABLED;
5999
6000    return ROK;
6001 }
6002
6003 /*******************************************************************
6004  *
6005  * @brief Builds inital UL BWP
6006  *
6007  * @details
6008  *
6009  *    Function : BuildInitialUlBWP
6010  *
6011  *    Functionality: Builds initial UL BWP
6012  *
6013  * @params[in] BWP_UplinkDedicated_t *ulBwp
6014  * @return ROK     - success
6015  *         RFAILED - failure
6016  *
6017  * ****************************************************************/
6018 uint8_t BuildInitialUlBWP(InitialUlBwp *initUlBwp, BWP_UplinkDedicated_t *ulBwp)
6019 {
6020    PucchCfg *pucchCfg = NULLP;
6021    PuschCfg *puschCfg = NULLP;
6022
6023    if(initUlBwp)
6024    {
6025       if(initUlBwp->pucchPresent)
6026          pucchCfg = &initUlBwp->pucchCfg;
6027       if(initUlBwp->puschPresent)
6028          puschCfg = &initUlBwp->puschCfg;
6029    }
6030
6031    ulBwp->pucch_Config = NULLP;
6032    DU_ALLOC(ulBwp->pucch_Config, sizeof(struct BWP_UplinkDedicated__pucch_Config));
6033    if(!ulBwp->pucch_Config)
6034    {
6035       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6036       return RFAILED;
6037    }
6038
6039    ulBwp->pucch_Config->present = BWP_UplinkDedicated__pucch_Config_PR_setup;
6040    ulBwp->pucch_Config->choice.setup = NULLP;
6041    DU_ALLOC(ulBwp->pucch_Config->choice.setup, sizeof(PUCCH_Config_t));
6042    if(!ulBwp->pucch_Config->choice.setup)
6043    {
6044       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6045       return RFAILED;
6046    }
6047
6048    if(BuildBWPUlDedPucchCfg(pucchCfg, ulBwp->pucch_Config->choice.setup) != ROK)
6049    {
6050       return RFAILED;
6051    }
6052
6053    /* Fill BWP UL dedicated PUSCH config */
6054    ulBwp->pusch_Config = NULLP;
6055    DU_ALLOC(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
6056    if(!ulBwp->pusch_Config)
6057    {
6058       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6059       return RFAILED;
6060    }
6061
6062    ulBwp->pusch_Config->present = BWP_UplinkDedicated__pusch_Config_PR_setup;
6063    ulBwp->pusch_Config->choice.setup = NULLP;
6064    DU_ALLOC(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
6065    if(!ulBwp->pusch_Config->choice.setup)
6066    {
6067       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6068       return RFAILED;
6069    }
6070
6071    if(BuildBWPUlDedPuschCfg(puschCfg, ulBwp->pusch_Config->choice.setup) != ROK)
6072    {
6073       return RFAILED;
6074    }
6075
6076    ulBwp->configuredGrantConfig = NULLP;
6077
6078    /* Fill BPW UL dedicated SRS config */
6079    ulBwp->srs_Config = NULLP;
6080    DU_ALLOC(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
6081    if(!ulBwp->srs_Config)
6082    {
6083       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6084       return RFAILED;
6085    }
6086
6087    ulBwp->srs_Config->present = BWP_UplinkDedicated__srs_Config_PR_setup;
6088    ulBwp->srs_Config->choice.setup = NULLP;
6089    DU_ALLOC(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
6090    if(!ulBwp->srs_Config->choice.setup)
6091    {
6092       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
6093       return RFAILED;
6094    }
6095
6096    if(BuildBWPUlDedSrsCfg(ulBwp->srs_Config->choice.setup) != ROK)
6097    {
6098       return RFAILED;   
6099    }
6100
6101    ulBwp->beamFailureRecoveryConfig = NULLP;
6102
6103    return ROK;
6104 }
6105
6106 /*******************************************************************
6107  *
6108  * @brief Builds UL config
6109  * @details
6110  *
6111  *    Function : BuildUlCfg 
6112  *
6113  *    Functionality: Builds UL config in spCellCfgDed
6114  *
6115  * @params[in] UplinkConfig_t *ulCfg
6116  *
6117  * @return ROK     - success
6118  *         RFAILED - failure
6119  *
6120  * ****************************************************************/
6121 uint8_t BuildUlCfg(ServCellRecfgInfo *servCellRecfg, UplinkConfig_t *ulCfg)
6122 {
6123    InitialUlBwp *initUlBwp = NULLP;
6124
6125    if(servCellRecfg)
6126    {
6127       initUlBwp = &servCellRecfg->initUlBwp;
6128    }
6129
6130    ulCfg->initialUplinkBWP = NULLP;
6131    DU_ALLOC(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
6132    if(!ulCfg->initialUplinkBWP)
6133    {
6134       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6135       return RFAILED;
6136    }
6137
6138    if(BuildInitialUlBWP(initUlBwp, ulCfg->initialUplinkBWP) != ROK)
6139    {
6140       return RFAILED;
6141    }
6142
6143    ulCfg->uplinkBWP_ToReleaseList = NULLP;
6144    ulCfg->uplinkBWP_ToAddModList = NULLP;
6145    ulCfg->firstActiveUplinkBWP_Id = NULLP;
6146    DU_ALLOC(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
6147    if(!ulCfg->firstActiveUplinkBWP_Id)
6148    {
6149       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6150       return RFAILED;
6151    }
6152    if(servCellRecfg == NULLP)
6153       *(ulCfg->firstActiveUplinkBWP_Id) = ACTIVE_UL_BWP_ID;
6154    else
6155       *(ulCfg->firstActiveUplinkBWP_Id) = servCellRecfg->firstActvUlBwpId;
6156
6157    ulCfg->pusch_ServingCellConfig = NULLP;
6158    DU_ALLOC(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
6159    if(!ulCfg->pusch_ServingCellConfig)
6160    {
6161       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
6162       return RFAILED;
6163    }
6164
6165    if(BuildPuschSrvCellCfg(ulCfg->pusch_ServingCellConfig) != ROK)
6166    {
6167       return RFAILED;
6168    }
6169
6170    ulCfg->carrierSwitching = NULLP;
6171    ulCfg->ext1 = NULLP;
6172    return ROK;
6173 }
6174
6175 /*******************************************************************
6176  *
6177  * @brief Builds PDSCH serving cell config
6178  * @details
6179  *
6180  *    Function : BuildPdschSrvCellCfg
6181  *
6182  *    Functionality: Builds PDSCH serving cell config in spCellCfgDed
6183  *
6184  * @params[in] struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg 
6185  *
6186  * @return ROK     - success
6187  *         RFAILED - failure
6188  *
6189  * ****************************************************************/
6190 uint8_t BuildPdschSrvCellCfg(PdschServCellCfg *pdschServCellDb, struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg)
6191 {
6192    pdschCfg->present =  ServingCellConfig__pdsch_ServingCellConfig_PR_setup;
6193    pdschCfg->choice.setup = NULLP;
6194    DU_ALLOC(pdschCfg->choice.setup, sizeof( struct PDSCH_ServingCellConfig));
6195    if(!pdschCfg->choice.setup)
6196    {
6197       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6198       return RFAILED;
6199    }
6200
6201    /* Code Block Group Transmission */
6202    pdschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
6203    if(pdschServCellDb && (pdschServCellDb->maxCodeBlkGrpPerTb || pdschServCellDb->codeBlkGrpFlushInd))
6204    {
6205       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission, sizeof(struct PDSCH_ServingCellConfig__codeBlockGroupTransmission));
6206       if(pdschCfg->choice.setup->codeBlockGroupTransmission == NULLP)
6207       {
6208          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6209          return RFAILED;
6210       }
6211
6212       pdschCfg->choice.setup->codeBlockGroupTransmission->present = PDSCH_ServingCellConfig__codeBlockGroupTransmission_PR_setup;
6213       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup = NULLP;
6214       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup, sizeof(struct PDSCH_CodeBlockGroupTransmission ));
6215       if(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup == NULLP)
6216       {
6217          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6218          return RFAILED;
6219       }
6220
6221       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock = \
6222          *(pdschServCellDb->maxCodeBlkGrpPerTb);
6223       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator = \
6224          *(pdschServCellDb->codeBlkGrpFlushInd);
6225    }
6226
6227    /* xOverhead */
6228    pdschCfg->choice.setup->xOverhead = NULLP;
6229    if(pdschServCellDb && pdschServCellDb->xOverhead)
6230    {
6231       DU_ALLOC(pdschCfg->choice.setup->xOverhead, sizeof(long));
6232       if(pdschCfg->choice.setup->xOverhead == NULLP)
6233       {
6234          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6235          return RFAILED;
6236       }
6237       *(pdschCfg->choice.setup->xOverhead) = *(pdschServCellDb->xOverhead);
6238    }
6239
6240    /* Number of HARQ processes */
6241    pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH = NULLP;
6242    DU_ALLOC(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH, sizeof(long));
6243    if(!pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH)
6244    {
6245       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6246       return RFAILED;
6247    }
6248
6249    if(pdschServCellDb == NULLP)
6250    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = PDSCH_NUM_HARQ_PROC;
6251    else
6252    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = pdschServCellDb->numHarqProcForPdsch;
6253
6254    pdschCfg->choice.setup->pucch_Cell = NULLP;
6255
6256    /* Extension */
6257    pdschCfg->choice.setup->ext1 = NULLP;
6258    if(pdschServCellDb && pdschServCellDb->maxMimoLayers)
6259    {
6260       DU_ALLOC(pdschCfg->choice.setup->ext1, sizeof(struct PDSCH_ServingCellConfig__ext1));
6261       if(pdschCfg->choice.setup->ext1 == NULLP)
6262       {
6263          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6264          return RFAILED;
6265       }
6266
6267       DU_ALLOC(pdschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
6268       if(pdschCfg->choice.setup->ext1->maxMIMO_Layers == NULLP)
6269       {
6270          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
6271          return RFAILED;
6272       }
6273       *(pdschCfg->choice.setup->ext1->maxMIMO_Layers) = *(pdschServCellDb->maxMimoLayers);
6274    }
6275
6276    return ROK;
6277 }
6278
6279 /*******************************************************************
6280  *
6281  * @brief Builds CSI Meas config
6282  * @details
6283  *
6284  *    Function : BuildCsiMeasCfg 
6285  *
6286  *    Functionality: Builds CSI Meas config in spCellCfgDed
6287  *
6288  * @params[in] struct ServingCellConfig__csi_MeasConfig *csiMeasCfg
6289  *
6290  * @return ROK     - success
6291  *         RFAILED - failure
6292  *
6293  * ****************************************************************/
6294 uint8_t BuildCsiMeasCfg(struct ServingCellConfig__csi_MeasConfig *csiMeasCfg)
6295 {
6296
6297    return ROK;
6298 }
6299
6300 /*******************************************************************
6301  *
6302  * @brief Builds DL BWP to add/modify list
6303  * @details
6304  *
6305  *    Function : BuildDlBwpToAddModList
6306  *
6307  *    Functionality: Builds DL BWP to add/modify list
6308  *
6309  * @params[in] ServCellRecfgInfo *servCellRecfg, 
6310  *             struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList
6311  *
6312  * @return ROK     - success
6313  *         RFAILED - failure
6314  *
6315  * ****************************************************************/ 
6316 uint8_t BuildDlBwpToAddModList(ServCellRecfgInfo *servCellRecfg, struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList)
6317 {
6318    uint8_t elementCnt, idx;
6319
6320    elementCnt = servCellRecfg->numDlBwpToAddOrMod;
6321    dlBwpAddModList->list.count = elementCnt;
6322    dlBwpAddModList->list.size = elementCnt * sizeof(struct BWP_Downlink *);
6323    dlBwpAddModList->list.array = NULLP;
6324    DU_ALLOC(dlBwpAddModList->list.array, dlBwpAddModList->list.size);
6325    if(dlBwpAddModList->list.array == NULLP)
6326    {
6327       DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6328       return RFAILED;
6329    }
6330
6331    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6332    {
6333       DU_ALLOC(dlBwpAddModList->list.array[idx], sizeof(BWP_Downlink_t));
6334       if(dlBwpAddModList->list.array[idx] == NULLP)
6335       {
6336          DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6337          return RFAILED;
6338       }
6339    }
6340
6341    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6342    {
6343       dlBwpAddModList->list.array[idx]->bwp_Id = servCellRecfg->dlBwpToAddOrModList[idx].bwpId;
6344       dlBwpAddModList->list.array[idx]->bwp_Common = NULLP;
6345       dlBwpAddModList->list.array[idx]->bwp_Dedicated = NULLP;
6346    }
6347    return ROK;
6348 }
6349
6350 /*******************************************************************
6351  *
6352  * @brief Builds Spcell config dedicated
6353  * @details
6354  *
6355  *    Function : BuildSpCellCfgDed
6356  *
6357  *    Functionality: Builds sp cell config dedicated in spCellCfg
6358  *
6359  * @params[in] ServingCellConfig_t srvCellCfg
6360  *
6361  * @return ROK     - success
6362  *         RFAILED - failure
6363  *
6364  * ****************************************************************/
6365 uint8_t BuildSpCellCfgDed(DuUeCb *ueCb, ServingCellConfig_t *srvCellCfg)
6366 {
6367    ServCellRecfgInfo *servCellRecfg = NULLP;
6368    InitialDlBwp *initDlBwp = NULLP;
6369    PdschServCellCfg *pdschServCellDb = NULLP;
6370
6371    if(ueCb)
6372    {
6373       servCellRecfg = &ueCb->duMacUeCfg.spCellCfg.servCellCfg;
6374       initDlBwp = &servCellRecfg->initDlBwp;
6375       pdschServCellDb = &servCellRecfg->pdschServCellCfg;
6376    }
6377
6378    srvCellCfg->tdd_UL_DL_ConfigurationDedicated = NULLP;
6379
6380    srvCellCfg->initialDownlinkBWP = NULLP;
6381    DU_ALLOC(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
6382    if(!srvCellCfg->initialDownlinkBWP)
6383    {
6384       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6385       return RFAILED;
6386    }
6387
6388    if(BuildInitialDlBWP(initDlBwp, srvCellCfg->initialDownlinkBWP) != ROK)
6389    {
6390       DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6391       return RFAILED;
6392    }
6393
6394    srvCellCfg->downlinkBWP_ToReleaseList = NULLP;
6395
6396    srvCellCfg->downlinkBWP_ToAddModList = NULLP;
6397    if(ueCb && ueCb->duMacUeCfg.spCellCfg.servCellCfg.numDlBwpToAddOrMod)
6398    {
6399       DU_ALLOC(srvCellCfg->downlinkBWP_ToAddModList, sizeof(struct ServingCellConfig__downlinkBWP_ToAddModList));
6400       if(srvCellCfg->downlinkBWP_ToAddModList == NULLP)
6401       {
6402          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6403          return RFAILED;
6404       }
6405
6406       if(BuildDlBwpToAddModList(&ueCb->duMacUeCfg.spCellCfg.servCellCfg, srvCellCfg->downlinkBWP_ToAddModList) != ROK)
6407       {
6408          DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6409          return RFAILED;
6410       }
6411    }
6412
6413    srvCellCfg->firstActiveDownlinkBWP_Id = NULLP;
6414    DU_ALLOC(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
6415    if(!srvCellCfg->firstActiveDownlinkBWP_Id)
6416    {
6417       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6418       return RFAILED;
6419    }
6420    if(ueCb == NULLP)
6421       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6422    else
6423       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.firstActvDlBwpId;
6424
6425    srvCellCfg->bwp_InactivityTimer = NULLP;
6426
6427    srvCellCfg->defaultDownlinkBWP_Id = NULLP;
6428    DU_ALLOC(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
6429    if(!srvCellCfg->defaultDownlinkBWP_Id)
6430    {
6431       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6432       return RFAILED;
6433    }
6434    if(ueCb == NULLP)
6435       *(srvCellCfg->defaultDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6436    else
6437       *(srvCellCfg->defaultDownlinkBWP_Id) = ueCb->duMacUeCfg.spCellCfg.servCellCfg.defaultDlBwpId;
6438
6439    srvCellCfg->uplinkConfig = NULLP;
6440    DU_ALLOC(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));
6441    if(!srvCellCfg->uplinkConfig)
6442    {
6443       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6444       return RFAILED;
6445    }
6446
6447    if(BuildUlCfg(servCellRecfg, srvCellCfg->uplinkConfig) != ROK)
6448    {
6449       DU_LOG("\nERROR  -->  F1AP : BuildUlCfg failed");
6450       return RFAILED;
6451    }
6452    srvCellCfg->supplementaryUplink = NULLP;
6453    srvCellCfg->pdcch_ServingCellConfig = NULLP;
6454
6455    srvCellCfg->pdsch_ServingCellConfig = NULLP;
6456    DU_ALLOC(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct  ServingCellConfig__pdsch_ServingCellConfig));
6457    if(!srvCellCfg->pdsch_ServingCellConfig)
6458    {
6459       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6460       return RFAILED;
6461    }
6462
6463    if(BuildPdschSrvCellCfg(pdschServCellDb, srvCellCfg->pdsch_ServingCellConfig) != ROK)
6464    {
6465       DU_LOG("\nERROR  -->  F1AP : BuildPdschSrvCellCfg failed");
6466       return RFAILED;
6467    }
6468
6469    srvCellCfg->csi_MeasConfig = NULLP;
6470 #if 0
6471    DU_ALLOC(srvCellCfg->csi_MeasConfig, sizeof(struct   ServingCellConfig__csi_MeasConfig))
6472       if(!srvCellCfg->csi_MeasConfig)
6473       {
6474          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6475          return RFAILED;
6476       }
6477
6478    if(BuildCsiMeasCfg(srvCellCfg->csi_MeasConfig) != ROK)
6479    {
6480       DU_LOG("\nF1AP : BuildCsiMeasCfg failed");
6481       return RFAILED;
6482    }
6483 #endif
6484    srvCellCfg->sCellDeactivationTimer = NULLP;
6485    srvCellCfg->crossCarrierSchedulingConfig = NULLP;
6486    srvCellCfg->tag_Id = TAG_ID;
6487    srvCellCfg->dummy = NULLP;
6488    srvCellCfg->pathlossReferenceLinking = NULLP;
6489    srvCellCfg->servingCellMO = NULLP;
6490    srvCellCfg->ext1 = NULLP;
6491
6492    return ROK;
6493 }
6494
6495 /*******************************************************************
6496  *
6497  * @brief Fills SCS specific carrier list in DL frequency info
6498  *
6499  * @details
6500  *
6501  *    Function : BuildScsSpecificCarrierListDl
6502  *
6503  *    Functionality: Fills SCS specific carrier list in DL frequency info
6504  *
6505  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
6506  *
6507  * @return ROK     - success
6508  *         RFAILED - failure
6509  *
6510  * ****************************************************************/
6511 uint8_t BuildScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
6512 {
6513    uint8_t elementCnt = 0, listIdx = 0;
6514    ScsSpecCarrier duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.dlScsCarrier;
6515
6516    elementCnt = ODU_VALUE_ONE;
6517    scsCarrierList->list.count = elementCnt;
6518    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6519
6520    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6521    if(!scsCarrierList->list.array)
6522    {
6523       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for scs carrier list array \
6524          in BuildScsSpecificCarrierListDl()");
6525       return RFAILED;
6526    }
6527
6528    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6529    {
6530       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6531       if(!scsCarrierList->list.array[listIdx])
6532       {    
6533          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SCS Specific Carrier list array \
6534             element in BuildScsSpecificCarrierListDl()");
6535          return RFAILED;
6536       }    
6537    }
6538
6539    listIdx = 0;
6540    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6541    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6542    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6543
6544    return ROK;
6545 }
6546
6547 /*******************************************************************
6548  *
6549  * @brief Fills DL frequency info in DL config common
6550  *
6551  * @details
6552  *
6553  *    Function : BuildFreqInfoDl
6554  *
6555  *    Functionality: Fills DL frequency info in DL config common
6556  *
6557  * @params[in] Pointer to DownlinkConfigCommon_t
6558  *
6559  * @return ROK     - success
6560  *         RFAILED - failure
6561  *
6562  * ****************************************************************/
6563 uint8_t BuildFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
6564 {
6565    uint8_t freqBandIdx = 0, elementCnt = 0;
6566    DlCfgCommon  dlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg;
6567
6568    /* TODO : Fill SSB Absolute Frequency */
6569    /*
6570       DU_ALLOC(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
6571       if(!frequencyInfoDL->absoluteFrequencySSB)
6572       {
6573       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB Absolute Frequency in BuildFreqInfoDl()");
6574       return RFAILED;
6575       }
6576       frequencyInfoDL->absoluteFrequencySSB = ?;
6577       */
6578
6579    /* NR Multi Frequency Band List */
6580    elementCnt = ODU_VALUE_ONE;
6581    frequencyInfoDL->frequencyBandList.list.count = elementCnt;
6582    frequencyInfoDL->frequencyBandList.list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6583
6584    DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
6585    if(!frequencyInfoDL->frequencyBandList.list.array)
6586    {
6587       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for Frequency Band List array in BuildFreqInfoDl()");
6588       return RFAILED;
6589    }
6590
6591    for(freqBandIdx = 0; freqBandIdx < elementCnt; freqBandIdx++)
6592    {
6593       DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
6594       if(!frequencyInfoDL->frequencyBandList.list.array[freqBandIdx])
6595       {
6596          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoDl()");
6597          return RFAILED;
6598       }
6599    }
6600
6601    freqBandIdx = 0;
6602    *(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx]) = dlCfg.freqBandInd;
6603
6604    /* TODO : Absolute Frequency to Point A */
6605    //frequencyInfoDL->absoluteFrequencyPointA
6606
6607    /* Subcarrier Spacing specifc carrier List */
6608    if((BuildScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList)) != ROK)
6609    {
6610       DU_LOG("\nERROR  -->  DU APP : Failed to fill SCS specific carrier list DL in BuildFreqInfoDl()");
6611       return RFAILED;
6612    }
6613
6614    return ROK;
6615
6616 }
6617
6618 /*******************************************************************
6619  *
6620  * @brief Fills DL config common in Serving cell config common
6621  *
6622  * @details
6623  *
6624  *    Function : BuildDlConfigCommon
6625  *
6626  *    Functionality: Fills DL config common in Serving cell config common
6627  *
6628  * @params[in] Pointer to DownlinkConfigCommon_t
6629  *
6630  * @return ROK     - success
6631  *         RFAILED - failure
6632  *
6633  * ****************************************************************/
6634 uint8_t BuildDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
6635 {
6636    /* DL Frequency Info */
6637    DU_ALLOC(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
6638    if(!dlCfgCommon->frequencyInfoDL)
6639    {
6640       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL frequency info in BuildDlConfigCommon()");
6641       return RFAILED;
6642    }
6643    if((BuildFreqInfoDl(dlCfgCommon->frequencyInfoDL))!= ROK)
6644    {
6645       DU_LOG("\nERROR  --> DU APP : Failed to fill DL frequency info in BuildDlConfigCommon()");
6646       return RFAILED;
6647    }
6648
6649    /* DL BWP config common */
6650    DU_ALLOC(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
6651    if(!dlCfgCommon->initialDownlinkBWP)
6652    {
6653       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL BWP config common in BuildDlConfigCommon()");
6654       return RFAILED;
6655    }
6656    if((BuildBwpDlCommon(dlCfgCommon->initialDownlinkBWP)) != ROK)
6657    {
6658       DU_LOG("\nERROR  --> DU APP : Failed to fill DL DWP config common in BuildDlConfigCommon()");
6659       return RFAILED;
6660    }
6661
6662    return ROK;
6663 }
6664
6665 /*******************************************************************
6666  *
6667  * @brief Fills SCS specific carrier list in UL frequency Info
6668  *
6669  * @details
6670  *
6671  *    Function : BuildScsSpecificCarrierListUl
6672  *
6673  *    Functionality: Fills SCS specific carrier list in UL frequency Info
6674  *
6675  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
6676  *
6677  * @return ROK     - success
6678  *         RFAILED - failure
6679  *
6680  * ****************************************************************/
6681 uint8_t BuildScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
6682 {
6683    uint8_t elementCnt = 0, listIdx = 0; 
6684    ScsSpecCarrier   duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.ulScsCarrier;
6685
6686    elementCnt = ODU_VALUE_ONE;
6687    scsCarrierList->list.count = elementCnt;
6688    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6689
6690    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6691    if(!scsCarrierList->list.array)
6692    {
6693       DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6694       return RFAILED;
6695    }
6696
6697    for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
6698    {
6699       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6700       if(!scsCarrierList->list.array[listIdx])
6701       {    
6702          DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6703          return RFAILED;
6704       }    
6705    }
6706    listIdx = 0; 
6707    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6708    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6709    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6710
6711    return ROK;
6712 }
6713
6714 /*******************************************************************
6715  *
6716  * @brief Fills frequency info in UL config common
6717  *
6718  * @details
6719  *
6720  *    Function : BuildFreqInfoUl
6721  *
6722  *    Functionality: Fills frequency info in UL config common
6723  *
6724  * @params[in] Pointer to FrequencyInfoUL_t
6725  *
6726  * @return ROK     - success
6727  *         RFAILED - failure
6728  *
6729  * ****************************************************************/
6730 uint8_t BuildFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
6731 {
6732    uint8_t elementCnt = 0, listIdx= 0;
6733    UlCfgCommon  ulCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg;
6734
6735    /* NR Multi Frequency Band List */
6736    DU_ALLOC(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
6737    if(!frequencyInfoUL->frequencyBandList)
6738    {
6739       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band list in BuildFreqInfoUl()");
6740       return RFAILED;
6741    }
6742
6743    elementCnt = ODU_VALUE_ONE;
6744    frequencyInfoUL->frequencyBandList->list.count = elementCnt;
6745    frequencyInfoUL->frequencyBandList->list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6746
6747    DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
6748    if(!frequencyInfoUL->frequencyBandList->list.array)
6749    {
6750       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array in BuildFreqInfoUl()");
6751       return RFAILED;
6752    }
6753
6754    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6755    {
6756       DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
6757       if(!frequencyInfoUL->frequencyBandList->list.array[listIdx])
6758       {
6759          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoUl()");
6760          return RFAILED;
6761       }
6762    }
6763
6764    listIdx = 0;
6765    *(frequencyInfoUL->frequencyBandList->list.array[listIdx]) = ulCfg.freqBandInd;
6766
6767    /* TODO : Fill Absolute frequency point A */
6768    /*
6769       DU_ALLOC(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
6770       if(!frequencyInfoUL->absoluteFrequencyPointA)
6771       {
6772       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for absolute frequency point A in BuildFreqInfoUl()");
6773       return RFAILED;
6774       }
6775     *(frequencyInfoUL->absoluteFrequencyPointA) = ?;
6776     */
6777
6778    /* Subcarrier Spacing specifc carrier */
6779    if((BuildScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList)) != ROK) 
6780    {
6781       DU_LOG("\nERROR  --> DU APP : Failed to fill SCS Specific Carrier list UL in BuildFreqInfoUl()");
6782       return RFAILED;
6783    }
6784
6785    /* P-MAX */
6786    DU_ALLOC(frequencyInfoUL->p_Max, sizeof(P_Max_t));
6787    if(!frequencyInfoUL->p_Max)
6788    {
6789       DU_LOG("\nERROR  -->  DU APP : UL Frequency Infoo  memory allocation failure");
6790       return RFAILED;
6791    }
6792    *frequencyInfoUL->p_Max = ulCfg.pMax;
6793
6794    return ROK;
6795 }
6796
6797 /*******************************************************************
6798  *
6799  * @brief Fills UL config common in Serving cell config common
6800  *
6801  * @details
6802  *
6803  *    Function : BuildUlConfigCommon
6804  *
6805  *    Functionality: Fills UL config common in Serving cell config common
6806  *
6807  * @params[in] Pointer to UplinkConfigCommon_t
6808  *
6809  * @return ROK     - success
6810  *         RFAILED - failure
6811  *
6812  * ****************************************************************/
6813 uint8_t BuildUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
6814 {
6815    /* UL Frequency Info */
6816    DU_ALLOC(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
6817    if(!ulCfgCommon->frequencyInfoUL)
6818    {
6819       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for UL frequency info in BuildUlConfigCommon()");
6820       return RFAILED;
6821    }
6822
6823    if((BuildFreqInfoUl(ulCfgCommon->frequencyInfoUL)) != ROK)
6824    {
6825       DU_LOG("\nERROR  -->  DU APP : Failed to fill frequency info UL in BuildUlConfigCommon()");
6826       return RFAILED;
6827    }
6828
6829    /* UL BWP common */
6830    DU_ALLOC(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
6831    if(!ulCfgCommon->initialUplinkBWP)
6832    {
6833       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for initial UL BWP in BuildUlConfigCommon()");
6834       return RFAILED;
6835    }
6836
6837    if((BuildBwpUlCommon(ulCfgCommon->initialUplinkBWP)) != ROK)
6838    {
6839       DU_LOG("\nERROR  -->  DU APP : Failed to fill BWP UL common in BuildUlConfigCommon()");
6840       return RFAILED;
6841    }
6842
6843    /* Time Alignment timer */
6844    ulCfgCommon->dummy = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.timeAlignTimerComm;
6845
6846    return ROK;
6847 }
6848
6849 /*******************************************************************
6850  *
6851  * @brief Fills SSB position in burst in SP cell config common
6852  *
6853  * @details
6854  *
6855  *    Function : BuildSsbPosInBurst
6856  *
6857  *    Functionality: 
6858  *       Fills SSB position in burst in SP cell config common
6859  *
6860  * @params[in] Pointer to struct ServingCellConfigCommon__ssb_PositionsInBurst
6861  *
6862  * @return ROK     - success
6863  *         RFAILED - failure
6864  *
6865  * ****************************************************************/
6866 uint8_t BuildSsbPosInBurst(struct ServingCellConfigCommon__ssb_PositionsInBurst *ssbPosInBurst)
6867 {
6868    uint8_t bitStringSizeInBytes = 0;
6869
6870    ssbPosInBurst->present = ServingCellConfigCommon__ssb_PositionsInBurst_PR_mediumBitmap;
6871
6872    /* As per spec 38.331,in the definition of ServingCellConfigCommon */
6873    bitStringSizeInBytes = 1;
6874    ssbPosInBurst->choice.mediumBitmap.size = bitStringSizeInBytes * sizeof(uint8_t);
6875
6876    DU_ALLOC(ssbPosInBurst->choice.mediumBitmap.buf, ssbPosInBurst->choice.mediumBitmap.size);
6877    if(!ssbPosInBurst->choice.mediumBitmap.buf)
6878    {
6879       DU_LOG("\nERROR  -->  DU APP : Memory Allocation failed for medium bit map buffer in BuildSsbPosInBurst()");
6880       return RFAILED;
6881    }
6882
6883    if((fillBitString(&ssbPosInBurst->choice.mediumBitmap, 0, bitStringSizeInBytes, \
6884                duCfgParam.sib1Params.srvCellCfgCommSib.ssbPosInBurst)) != ROK)
6885    {
6886       DU_LOG("\nERROR  -->  DU APP : Failed to fill medium bit map in BuildSsbPosInBurst()");
6887       return RFAILED;
6888    }
6889
6890    return ROK;
6891 }
6892
6893 /*******************************************************************
6894  *
6895  * @brief Fills SP cell config common in Reconfig with Sync
6896  *
6897  * @details
6898  *
6899  *    Function : BuildSpCellConfigCommon
6900  *
6901  *    Functionality: Fills SP cell config common in Reconfig with Sync
6902  *
6903  * @params[in] Pointer to ServingCellConfigCommon_t
6904  *
6905  * @return ROK     - success
6906  *         RFAILED - failure
6907  *
6908  * ****************************************************************/
6909 uint8_t BuildSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
6910 {
6911    /* Physical Cell Identity */
6912    DU_ALLOC(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
6913    if(!spCellConfigCommon->physCellId)
6914    {
6915       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for physical cell id in BuildSpCellConfigCommon()");
6916       return RFAILED;
6917    } 
6918    *(spCellConfigCommon->physCellId) = NR_PCI;
6919
6920    /* Downlink Config Common */
6921    DU_ALLOC(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
6922    if(!spCellConfigCommon->downlinkConfigCommon)
6923    {
6924       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for DL Config Common in BuildSpCellConfigCommon()");
6925       return RFAILED;
6926    }
6927    if((BuildDlConfigCommon(spCellConfigCommon->downlinkConfigCommon)) != ROK)
6928    {
6929       DU_LOG("\nERROR  -->  DU APP : Failed to fill DL config commin in BuildSpCellConfigCommon()");
6930       return RFAILED;
6931    }
6932
6933    /* Uplinlink Config Common */
6934    DU_ALLOC(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
6935    if(!spCellConfigCommon->uplinkConfigCommon)
6936    {
6937       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for UL Config Common in BuildSpCellConfigCommon()");
6938       return RFAILED;
6939    }
6940    if((BuildUlConfigCommon(spCellConfigCommon->uplinkConfigCommon)) != ROK)
6941    {
6942       DU_LOG("\nERROR  -->  DU APP : Failed to fill UL config commin in BuildSpCellConfigCommon()");
6943       return RFAILED;
6944    }
6945
6946    /* Timing Advance offset */
6947    DU_ALLOC(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
6948    if(!spCellConfigCommon->n_TimingAdvanceOffset)
6949    {
6950       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for Timing Advance Offset in BuildSpCellConfigCommon()");
6951       return RFAILED;
6952    }
6953    *(spCellConfigCommon->n_TimingAdvanceOffset) = ServingCellConfigCommon__n_TimingAdvanceOffset_n0;
6954
6955    /* SSB Position In Burst */
6956    DU_ALLOC(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
6957    if(!spCellConfigCommon->ssb_PositionsInBurst)
6958    {
6959       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Position In Burst in BuildSpCellConfigCommon()");
6960       return RFAILED;
6961    }
6962    if((BuildSsbPosInBurst(spCellConfigCommon->ssb_PositionsInBurst)) != ROK)
6963    {
6964       DU_LOG("\nERROR  -->  DU APP : Failed to fill SSB Position In Burst in BuildSpCellConfigCommon()");
6965       return RFAILED;
6966    }
6967
6968    /* SSB Periodicity in Serving cell */
6969    DU_ALLOC(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
6970    if(!spCellConfigCommon->ssb_periodicityServingCell)
6971    {
6972       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Periodicity serving cell in \
6973          BuildSpCellConfigCommon()");
6974       return RFAILED;
6975    }
6976    *(spCellConfigCommon->ssb_periodicityServingCell) = \
6977       convertSsbPeriodicityValueToEnum(duCfgParam.sib1Params.srvCellCfgCommSib.ssbPrdServingCell);
6978
6979    /* DMRS Type A position */
6980    spCellConfigCommon->dmrs_TypeA_Position = convertDmrsTypeAPosValueToEnum(duCfgParam.macCellCfg.ssbCfg.dmrsTypeAPos);
6981
6982    /* SSB subcarrier spacing */
6983    DU_ALLOC(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
6984    if(!spCellConfigCommon->ssbSubcarrierSpacing)
6985    {
6986       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for sub-carrier spacing in BuildSpCellConfigCommon()");
6987       return RFAILED;
6988    }
6989    *(spCellConfigCommon->ssbSubcarrierSpacing) = duCfgParam.sib1Params.srvCellCfgCommSib.scs;
6990
6991    /* TDD UL-DL configuration common */
6992    DU_ALLOC(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
6993    if(!spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)
6994    {
6995       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for TDD UL-DL config common in BuildSpCellConfigCommon()");
6996       return RFAILED;
6997    }
6998    if((BuildTddUlDlCfgComm(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)) != ROK)
6999    {
7000       DU_LOG("\nERROR  -->  DU APP : Failed to fill TDD UL-DL config common in BuildSpCellConfigCommon()");
7001       return RFAILED;
7002    }
7003
7004    /* SS PBCH Block Power */
7005    spCellConfigCommon->ss_PBCH_BlockPower = duCfgParam.sib1Params.srvCellCfgCommSib.ssPbchBlockPwr;
7006
7007    return ROK;
7008 }
7009
7010 /*******************************************************************
7011  *
7012  * @brief Fills dedicated RACH configuration in Reconfiguration with sync
7013  *
7014  * @details
7015  *
7016  *    Function : BuildRecfgWithSync
7017  *
7018  *    Functionality: 
7019  *       Fills dedicated RACH configuration in Reconfiguration with sync
7020  *
7021  * @params[in] DU UE CB
7022  *             Pointer to Rach config dedicated struct
7023  *
7024  * @return ROK     - success
7025  *         RFAILED - failure
7026  *
7027  * ****************************************************************/
7028 uint8_t BuildRachConfigDedicated(DuUeCb *ueCb, struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
7029 {
7030    uint8_t elementCnt = 0, listIdx = 0;
7031    CFRA_t *cfra = NULLP;
7032    struct CFRA__resources__ssb *ssbResource = NULLP;
7033    RachCfgCommon duRachCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.rachCfg;
7034
7035    rachCfgDed->present = ReconfigurationWithSync__rach_ConfigDedicated_PR_uplink;
7036
7037    /* Uplink */
7038    DU_ALLOC(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
7039    if(!rachCfgDed->choice.uplink)
7040    {
7041       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for RACH uplink configuration in BuildRachConfigDedicated()");
7042       return RFAILED;
7043    }
7044
7045    /* CFRA : Contention free Random Access */
7046    DU_ALLOC(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
7047    if(!rachCfgDed->choice.uplink->cfra)
7048    {
7049       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA in BuildRachConfigDedicated()");
7050       return RFAILED;
7051    }
7052    cfra = rachCfgDed->choice.uplink->cfra;
7053
7054    /* CFRA occassions */
7055    DU_ALLOC(cfra->occasions, sizeof(struct CFRA__occasions));
7056    if(!cfra->occasions)
7057    {
7058       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA occassion in BuildRachConfigDedicated()");
7059       return RFAILED;
7060    }
7061
7062    /* CFRA occassions : RACH generic configuration */
7063    cfra->occasions->rach_ConfigGeneric.prach_ConfigurationIndex = duRachCfg.prachCfgIdx;
7064    cfra->occasions->rach_ConfigGeneric.msg1_FDM = duRachCfg.msg1Fdm;
7065    cfra->occasions->rach_ConfigGeneric.msg1_FrequencyStart = duRachCfg.msg1FreqStart;
7066    cfra->occasions->rach_ConfigGeneric.zeroCorrelationZoneConfig = duRachCfg.zeroCorrZoneCfg;
7067    cfra->occasions->rach_ConfigGeneric.preambleReceivedTargetPower = duRachCfg.preambleRcvdTgtPwr;
7068    cfra->occasions->rach_ConfigGeneric.preambleTransMax = duRachCfg.preambleTransMax;
7069    cfra->occasions->rach_ConfigGeneric.powerRampingStep = duRachCfg.pwrRampingStep;
7070    cfra->occasions->rach_ConfigGeneric.ra_ResponseWindow = duRachCfg.raRspWindow;
7071
7072    /* CFRA occassions : SSB per RACH occasion */
7073    DU_ALLOC(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
7074    if(!cfra->occasions->ssb_perRACH_Occasion)
7075    {
7076       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB per RACH occassion in BuildRachConfigDedicated()");
7077       return RFAILED;
7078    }
7079    *(cfra->occasions->ssb_perRACH_Occasion) = convertCFRASsbPerRachOccasionValueToEnum(duCfgParam.macCellCfg.prachCfg.ssbPerRach);
7080
7081    /* CFRA resource */
7082    cfra->resources.present = CFRA__resources_PR_ssb;
7083
7084    /* CFRA resource : SSB */
7085    DU_ALLOC(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
7086    if(!cfra->resources.choice.ssb)
7087    {
7088       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA resource - SSB in BuildRachConfigDedicated()");
7089       return RFAILED;
7090    }
7091    ssbResource = cfra->resources.choice.ssb;
7092
7093    /* CFRA SSB resource list */
7094    elementCnt = ueCb->cfraResource.numSsb;
7095    ssbResource->ssb_ResourceList.list.count = elementCnt;
7096    ssbResource->ssb_ResourceList.list.size = elementCnt * sizeof(CFRA_SSB_Resource_t *);
7097
7098    DU_ALLOC(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
7099    if(!ssbResource->ssb_ResourceList.list.array)
7100    {
7101       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list in BuildRachConfigDedicated()");
7102       return RFAILED;
7103    }
7104
7105    for(listIdx = 0; listIdx < elementCnt; listIdx++)
7106    {
7107       DU_ALLOC(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
7108       if(!ssbResource->ssb_ResourceList.list.array[listIdx])
7109       {
7110          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list element in BuildRachConfigDedicated()");  
7111          return RFAILED;
7112       }
7113       ssbResource->ssb_ResourceList.list.array[listIdx]->ssb = ueCb->cfraResource.ssbResource[listIdx].ssbIdx;
7114       ssbResource->ssb_ResourceList.list.array[listIdx]->ra_PreambleIndex = ueCb->cfraResource.ssbResource[listIdx].raPreambleIdx;
7115    }
7116
7117    return ROK;
7118 }
7119
7120 /*******************************************************************
7121  *
7122  * @brief Fills reconfiguration with sync in SP cell config
7123  *
7124  * @details
7125  *
7126  *    Function : BuildRecfgWithSync
7127  *
7128  *    Functionality: Fills reconfiguration with sync in SP cell config
7129  *
7130  * @params[in] DU UE CB
7131  *             Pointer to ReconfigurationWithSync_t
7132  *
7133  * @return ROK     - success
7134  *         RFAILED - failure
7135  *
7136  * ****************************************************************/
7137 uint8_t BuildRecfgWithSync(DuUeCb *ueCb, ReconfigurationWithSync_t *recfgWithSync)
7138 {
7139    /* SP Cell Config Common */  
7140    DU_ALLOC(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
7141    if(!recfgWithSync->spCellConfigCommon)
7142    {
7143       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for spCellConfigCommon in BuildRecfgWithSync()");
7144       return RFAILED;
7145    }
7146
7147    if((BuildSpCellConfigCommon(recfgWithSync->spCellConfigCommon)) != ROK)
7148    {
7149       DU_LOG("\nERROR  -->  DU APP : Failed to build SpCellConfigCommon in BuildRecfgWithSync()");
7150       return RFAILED;
7151    }
7152
7153    /* New UE Identity */
7154    recfgWithSync->newUE_Identity = ueCb->crnti;
7155
7156    /* T304 timer */
7157    recfgWithSync->t304 = ReconfigurationWithSync__t304_ms1000;
7158
7159    /* RACH configuration dedicated */
7160    DU_ALLOC(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
7161    if(!recfgWithSync->rach_ConfigDedicated)
7162    {
7163       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for RACH config dedicated in BuildRecfgWithSync()");
7164       return RFAILED;
7165    }
7166
7167    if((BuildRachConfigDedicated(ueCb, recfgWithSync->rach_ConfigDedicated)) != ROK)
7168    {
7169       DU_LOG("\nERROR  -->  DU APP : Failed to build RACH config dedicated in BuildRecfgWithSync()");
7170       return RFAILED;
7171    }
7172
7173    return ROK;
7174 }
7175
7176 /*******************************************************************
7177  *
7178  * @brief Builds Spcell config 
7179  *
7180  * @details
7181  *
7182  *    Function : BuildSpCellCfg 
7183  *
7184  *    Functionality: Builds sp cell config in DuToCuRrcContainer
7185  *
7186  * @params[in] SpCellConfig_t spCellCfg
7187  *
7188  * @return ROK     - success
7189  *         RFAILED - failure
7190  *
7191  * ****************************************************************/
7192 uint8_t BuildSpCellCfg(DuUeCb *ueCb, SpCellConfig_t *spCellCfg)
7193 {
7194    spCellCfg->servCellIndex = NULLP;
7195    DU_ALLOC(spCellCfg->servCellIndex, sizeof(long));
7196    if(!spCellCfg->servCellIndex)
7197    {
7198       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7199       return RFAILED;
7200    }
7201
7202    if(ueCb == NULLP)
7203       *(spCellCfg->servCellIndex) = SERV_CELL_IDX;
7204    else
7205       *(spCellCfg->servCellIndex) = ueCb->duMacUeCfg.spCellCfg.servCellIdx;
7206
7207    spCellCfg->reconfigurationWithSync = NULLP;
7208    if(ueCb && (ueCb->ueState == UE_HANDIN_IN_PROGRESS))
7209    {
7210       DU_ALLOC(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
7211       if(!spCellCfg->reconfigurationWithSync)
7212       {
7213          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7214          return RFAILED;
7215       }
7216
7217       if((BuildRecfgWithSync(ueCb, spCellCfg->reconfigurationWithSync)) != ROK)
7218       {
7219          DU_LOG("\nERROR  -->  F1AP : Building of reconfiguration with sync failed at BuildSpCellCfg");
7220          return RFAILED;
7221       }
7222    }
7223
7224    spCellCfg->rlf_TimersAndConstants = NULLP;
7225    spCellCfg->rlmInSyncOutOfSyncThreshold = NULLP;
7226
7227    DU_ALLOC(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
7228    if(!spCellCfg->rlmInSyncOutOfSyncThreshold)
7229    {
7230       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7231       return RFAILED;
7232    }
7233    *(spCellCfg->rlmInSyncOutOfSyncThreshold) = RLM_SYNC_OUT_SYNC_THRESHOLD;
7234
7235    spCellCfg->spCellConfigDedicated = NULLP;
7236    DU_ALLOC(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
7237    if(!spCellCfg->spCellConfigDedicated)
7238    {
7239       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
7240       return RFAILED;
7241    }
7242    if(BuildSpCellCfgDed(ueCb, spCellCfg->spCellConfigDedicated) != ROK)
7243    {
7244       DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfgDed failed");
7245       return RFAILED;
7246    }
7247
7248    return ROK;
7249 }
7250
7251 /*******************************************************************
7252  *
7253  * @brief Builds Phy cell group config 
7254  *
7255  * @details
7256  *
7257  *    Function : BuildPhyCellGrpCfg 
7258  *
7259  *    Functionality: Builds Phy cell group config in DuToCuRrcContainer
7260  *
7261  * @params[in] PhysicalCellGroupConfig_t *phyCellGrpCfg 
7262  *
7263  * @return ROK     - success
7264  *         RFAILED - failure
7265  *
7266  * ****************************************************************/
7267 uint8_t BuildPhyCellGrpCfg(DuUeCb *ueCb, PhysicalCellGroupConfig_t *phyCellGrpCfg)
7268 {
7269    phyCellGrpCfg->harq_ACK_SpatialBundlingPUCCH = NULLP;
7270    phyCellGrpCfg->harq_ACK_SpatialBundlingPUSCH = NULLP;
7271
7272    phyCellGrpCfg->p_NR_FR1 = NULLP;
7273    DU_ALLOC(phyCellGrpCfg->p_NR_FR1, sizeof(long));
7274    if(!phyCellGrpCfg->p_NR_FR1)
7275    {
7276       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhyCellGrpCfg");
7277       return RFAILED;
7278    }
7279
7280    if(ueCb == NULLP)
7281    {
7282       *(phyCellGrpCfg->p_NR_FR1)             = P_NR_FR1;
7283       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = PDSCH_HARQ_ACK_CODEBOOK;
7284    }
7285    else
7286    {
7287       *(phyCellGrpCfg->p_NR_FR1) = ueCb->duMacUeCfg.phyCellGrpCfg.pNrFr1;
7288       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = ueCb->duMacUeCfg.phyCellGrpCfg.pdschHarqAckCodebook;
7289    }
7290
7291    phyCellGrpCfg->tpc_SRS_RNTI = NULLP;
7292    phyCellGrpCfg->tpc_PUCCH_RNTI = NULLP;
7293    phyCellGrpCfg->tpc_PUSCH_RNTI = NULLP;
7294    phyCellGrpCfg->sp_CSI_RNTI = NULLP;
7295    phyCellGrpCfg->cs_RNTI = NULLP;
7296    phyCellGrpCfg->ext1 = NULLP;
7297    phyCellGrpCfg->ext2 = NULLP;
7298
7299    return ROK;
7300 }
7301 #ifdef NR_DRX
7302 /*******************************************************************
7303  *
7304  * @brief fill long cycle offset value of drx
7305  *
7306  * @details
7307  *
7308  *    Function : fillLongCycleOffsetValFromDuCb 
7309  *
7310  *    Functionality: fill long cycle offset value of drx
7311  *
7312  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
7313  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
7314  *
7315  * @return ROK     - success
7316  *         RFAILED - failure
7317  *
7318  * ****************************************************************/
7319 void fillLongCycleOffsetValFromDuCb(DrxLongCycleStartOffset  drxLongCycleStartOffset,\
7320 struct DRX_ConfigRrc__drx_LongCycleStartOffset *drx_LongCycleStartOffset)
7321 {
7322    
7323    drx_LongCycleStartOffset->present = convertLongDrxCycleLengthValueToEnum(drxLongCycleStartOffset.drxLongCycleStartOffsetChoice); 
7324    switch(drx_LongCycleStartOffset->present)
7325    {
7326       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
7327          {
7328             drx_LongCycleStartOffset->choice.ms10 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7329             break;
7330          }
7331       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
7332          {
7333             drx_LongCycleStartOffset->choice.ms20 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7334             break;
7335          }
7336       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
7337          {
7338             drx_LongCycleStartOffset->choice.ms32 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7339             break;
7340          }
7341       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
7342          {
7343             drx_LongCycleStartOffset->choice.ms40 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7344             break;
7345          }
7346       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
7347          {
7348             drx_LongCycleStartOffset->choice.ms60 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7349             break;
7350          }
7351       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
7352          {
7353             drx_LongCycleStartOffset->choice.ms64 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7354             break;
7355          }
7356       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
7357          {
7358             drx_LongCycleStartOffset->choice.ms70 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7359             break;
7360          }
7361       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
7362          {
7363             drx_LongCycleStartOffset->choice.ms80 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7364             break;
7365          }
7366       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
7367          {
7368             drx_LongCycleStartOffset->choice.ms128 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7369             break;
7370          }
7371       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
7372          {
7373             drx_LongCycleStartOffset->choice.ms160 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7374             break;
7375          }
7376       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
7377          {
7378             drx_LongCycleStartOffset->choice.ms256 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7379             break;
7380          }
7381       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
7382          {
7383             drx_LongCycleStartOffset->choice.ms320 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7384             break;
7385          }
7386       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
7387          {
7388             drx_LongCycleStartOffset->choice.ms512 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7389             break;
7390          }
7391       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
7392          {
7393             drx_LongCycleStartOffset->choice.ms640 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7394             break;
7395          }
7396       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
7397          {
7398             drx_LongCycleStartOffset->choice.ms1024 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7399             break;
7400          }
7401       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
7402          {
7403             drx_LongCycleStartOffset->choice.ms1280 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7404             break;
7405          }
7406       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
7407          {
7408             drx_LongCycleStartOffset->choice.ms2048 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7409             break;
7410          }
7411       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
7412          {
7413             drx_LongCycleStartOffset->choice.ms2560 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7414             break;
7415          }
7416       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
7417          {
7418             drx_LongCycleStartOffset->choice.ms5120 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7419             break;
7420          }
7421       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
7422          {
7423             drx_LongCycleStartOffset->choice.ms10240 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7424             break;
7425          }
7426       default :
7427          break;
7428    }
7429 }
7430 /*******************************************************************
7431  *
7432  * @brief Builds drx config IE 
7433  *
7434  * @details
7435  *
7436  *    Function : BuildDrxConfigRrc 
7437  *
7438  *    Functionality: Build drx config in MacCellGrpCfg 
7439  *
7440  * @params[in] struct MAC_CellGroupConfig__drx_ConfigRrc 
7441  *
7442  * @return ROK     - success
7443  *         RFAILED - failure
7444  *
7445  * ****************************************************************/
7446 uint8_t BuildDrxConfigRrc(DuUeCb *ueCb, struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg)
7447 {
7448    drxCfg->present = MAC_CellGroupConfig__drx_ConfigRrc_PR_setup;
7449    DU_ALLOC(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
7450    if(!drxCfg->choice.setup)
7451    {
7452       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7453       return RFAILED;
7454    }
7455    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationTimerValInMs)
7456    {
7457       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds;
7458       drxCfg->choice.setup->drx_onDurationTimer.choice.milliSeconds = convertOnDurationTimerMilliSecondsValueToEnum(ueCb->duMacUeCfg.\
7459       macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationtimerValue.milliSeconds);
7460    }
7461    else
7462    {
7463       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds;
7464       drxCfg->choice.setup->drx_onDurationTimer.choice.subMilliSeconds = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7465       drxOnDurationTimer.onDurationtimerValue.subMilliSeconds;
7466    }
7467    drxCfg->choice.setup->drx_InactivityTimer = convertDrxInactivityTimerValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxInactivityTimer);
7468    drxCfg->choice.setup->drx_HARQ_RTT_TimerDL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerDl;
7469    drxCfg->choice.setup->drx_HARQ_RTT_TimerUL = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerUl;
7470    drxCfg->choice.setup->drx_RetransmissionTimerDL = convertDrxRetransmissionTimerDlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7471    drxRetransmissionTimerDl);
7472    drxCfg->choice.setup->drx_RetransmissionTimerUL = convertDrxRetransmissionTimerUlValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7473    drxRetransmissionTimerUl);
7474    drxCfg->choice.setup->drx_SlotOffset = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxSlotOffset;
7475    fillLongCycleOffsetValFromDuCb(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.drxLongCycleStartOffset, &drxCfg->choice.setup->drx_LongCycleStartOffset);
7476    
7477    if(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrxPres)
7478    {
7479       DU_ALLOC(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));
7480       if(drxCfg->choice.setup->shortDRX)
7481       {
7482          drxCfg->choice.setup->shortDRX->drx_ShortCycle = convertShortDrxCycleLengthValueToEnum(ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.\
7483          shortDrx.drxShortCycle);
7484          drxCfg->choice.setup->shortDRX->drx_ShortCycleTimer = ueCb->duMacUeCfg.macCellGrpCfg.drxCfg.shortDrx.drxShortCycleTimer;
7485       }
7486       else
7487       {
7488          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7489          return RFAILED;
7490       }
7491    }
7492    return ROK;
7493 }
7494 #endif
7495 /*******************************************************************
7496  *
7497  * @brief Builds Mac cell group config 
7498  *
7499  * @details
7500  *
7501  *    Function : BuildMacCellGrpCfg 
7502  *
7503  *    Functionality: Builds Mac cell group config in DuToCuRrcContainer
7504  *
7505  * @params[in] MAC_CellGroupConfig_t *macCellGrpCfg
7506  *
7507  * @return ROK     - success
7508  *         RFAILED - failure
7509  *
7510  * ****************************************************************/
7511 uint8_t BuildMacCellGrpCfg(DuUeCb *ueCb, MAC_CellGroupConfig_t *macCellGrpCfg)
7512 {
7513    macCellGrpCfg->drx_ConfigRrc = NULLP;
7514 #ifdef NR_DRX   
7515    if(ueCb)
7516    {
7517       DU_ALLOC(macCellGrpCfg->drx_ConfigRrc, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
7518       if(!macCellGrpCfg->drx_ConfigRrc)
7519       {
7520          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7521          return RFAILED;
7522       }
7523       if(BuildDrxConfigRrc(ueCb, macCellGrpCfg->drx_ConfigRrc) != ROK)
7524       {
7525          DU_LOG("\nERROR  -->  F1AP : failed to build drx config");
7526          return RFAILED;
7527       }
7528    }
7529 #endif
7530    macCellGrpCfg->schedulingRequestConfig = NULLP;
7531    DU_ALLOC(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
7532    if(!macCellGrpCfg->schedulingRequestConfig)
7533    {
7534       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7535       return RFAILED;
7536    }
7537
7538    if(BuildSchedulingReqConfig(ueCb, macCellGrpCfg->schedulingRequestConfig) != ROK)
7539    {
7540       DU_LOG("\nERROR  -->  F1AP : BuildSchedulingReqConfig failed");
7541       return RFAILED;
7542    }
7543
7544    macCellGrpCfg->bsr_Config = NULLP;
7545    DU_ALLOC(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
7546    if(!macCellGrpCfg->bsr_Config)
7547    {
7548       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7549       return RFAILED;
7550    }
7551
7552    if(BuildBsrConfig(ueCb, macCellGrpCfg->bsr_Config) != ROK)
7553    {
7554       DU_LOG("\nERROR  -->  F1AP : BuildBsrConfig failed");
7555       return RFAILED;
7556    }
7557
7558    macCellGrpCfg->tag_Config = NULLP;
7559    DU_ALLOC(macCellGrpCfg->tag_Config, sizeof(struct TAG_Config));
7560    if(!macCellGrpCfg->tag_Config)
7561    {
7562       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7563       return RFAILED;
7564    }
7565
7566    if(BuildTagConfig(ueCb, macCellGrpCfg->tag_Config) != ROK)
7567    {
7568       DU_LOG("\nERROR  -->  F1AP : BuildTagConfig failed");
7569       return RFAILED;
7570    }
7571
7572    macCellGrpCfg->phr_Config = NULLP;
7573    DU_ALLOC(macCellGrpCfg->phr_Config, sizeof(struct MAC_CellGroupConfig__phr_Config));
7574    if(!macCellGrpCfg->phr_Config)
7575    {
7576       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7577       return RFAILED;
7578    }
7579
7580    if(BuildPhrConfig(ueCb, macCellGrpCfg->phr_Config) != ROK)
7581    {
7582       DU_LOG("\nERROR  -->  F1AP : BuildPhrConfig failed");
7583       return RFAILED;
7584    }
7585
7586    macCellGrpCfg->skipUplinkTxDynamic = false;
7587    macCellGrpCfg->ext1 = NULLP;
7588
7589    return ROK;
7590 }
7591 /*******************************************************************
7592  *
7593  * @brief Frees memeory allocated for SearchSpcToAddModList
7594  *
7595  * @details
7596  *
7597  *    Function : FreeSearchSpcToAddModList
7598  *
7599  *    Functionality: Deallocating memory of SearchSpcToAddModList
7600  *
7601  * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
7602  *
7603  * @return void
7604  *
7605  4221 * ****************************************************************/
7606 void FreeSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
7607 {
7608    uint8_t idx1=0;
7609    uint8_t idx2=0;
7610    struct  SearchSpace *searchSpc=NULLP;
7611
7612    if(searchSpcList->list.array)
7613    {
7614       if(searchSpcList->list.array[idx2])
7615       {
7616          searchSpc = searchSpcList->list.array[idx2];
7617          if(searchSpc->controlResourceSetId)
7618          {
7619             if(searchSpc->monitoringSlotPeriodicityAndOffset)
7620             {
7621                if(searchSpc->monitoringSymbolsWithinSlot)
7622                {
7623                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
7624                   {
7625                      if(searchSpc->nrofCandidates)
7626                      {
7627                         if(searchSpc->searchSpaceType)
7628                         {
7629                            DU_FREE(searchSpc->searchSpaceType->choice.ue_Specific,\
7630                                  sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
7631                            DU_FREE(searchSpc->searchSpaceType, sizeof(struct
7632                                     SearchSpace__searchSpaceType));
7633                         }
7634                         DU_FREE(searchSpc->nrofCandidates,
7635                               sizeof(struct SearchSpace__nrofCandidates));
7636                      }
7637                      DU_FREE(searchSpc->monitoringSymbolsWithinSlot->buf, \
7638                            searchSpc->monitoringSymbolsWithinSlot->size);
7639                   }
7640                   DU_FREE(searchSpc->monitoringSymbolsWithinSlot,
7641                         sizeof(BIT_STRING_t));
7642                }
7643                DU_FREE(searchSpc->monitoringSlotPeriodicityAndOffset, \
7644                      sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
7645             }
7646             DU_FREE(searchSpc->controlResourceSetId,
7647                   sizeof(ControlResourceSetId_t));
7648          }
7649       }
7650       for(idx1 = 0; idx1 < searchSpcList->list.count; idx1++)
7651       {
7652          DU_FREE(searchSpcList->list.array[idx1],
7653                sizeof(struct SearchSpace));
7654       }
7655       DU_FREE(searchSpcList->list.array,searchSpcList->list.size);
7656    }
7657 }
7658 /*******************************************************************
7659  *
7660  * @brief Frees memory allocated for PdschTimeDomAllocList
7661  *
7662  * @details
7663  *
7664  *    Function : FreePdschTimeDomAllocList
7665  *
7666  *    Functionality: Deallocating memory of PdschTimeDomAllocList
7667  *
7668  * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
7669  *
7670  * @return void
7671  *
7672  * ****************************************************************/
7673 void FreePdschTimeDomAllocList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
7674 {
7675    uint8_t idx1=0;
7676
7677    if(timeDomAllocList->choice.setup)
7678    {
7679       if(timeDomAllocList->choice.setup->list.array)
7680       {
7681          for(idx1 = 0; idx1 <timeDomAllocList->choice.setup->list.count ; idx1++)
7682          {
7683             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1]->k0, sizeof(long));
7684             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1],
7685                   sizeof(struct PDSCH_TimeDomainResourceAllocation));
7686          }
7687          DU_FREE(timeDomAllocList->choice.setup->list.array, \
7688                timeDomAllocList->choice.setup->list.size);
7689       }
7690       DU_FREE(timeDomAllocList->choice.setup,\
7691             sizeof(struct PDSCH_TimeDomainResourceAllocationList));
7692    }
7693 }
7694 /*******************************************************************
7695  *
7696  * @brief Frees memory allocated for PuschTimeDomAllocList
7697  *
7698  *@details
7699  *
7700  *    Function : FreePuschTimeDomAllocList
7701  *
7702  *    Functionality: Deallocating memory of PuschTimeDomAllocList
7703  *
7704  * @params[in] PUSCH_Config_t *puschCfg
7705  *
7706  * @return void
7707  *
7708  * ****************************************************************/
7709 void FreePuschTimeDomAllocList(PUSCH_Config_t *puschCfg)
7710 {
7711    uint8_t rsrcListIdx=0;
7712    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
7713
7714    if(puschCfg->pusch_TimeDomainAllocationList)
7715    {
7716       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
7717       if(timeDomAllocList_t->choice.setup)
7718       {
7719          if(timeDomAllocList_t->choice.setup->list.array)
7720          {
7721             for(rsrcListIdx = 0; rsrcListIdx<timeDomAllocList_t->choice.setup->list.count; rsrcListIdx++)
7722             {
7723                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx]->k2, sizeof(long));
7724                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx],\
7725                      sizeof(PUSCH_TimeDomainResourceAllocation_t));
7726             }
7727             DU_FREE(timeDomAllocList_t->choice.setup->list.array, \
7728                   timeDomAllocList_t->choice.setup->list.size);
7729          }
7730          DU_FREE(timeDomAllocList_t->choice.setup, \
7731                sizeof(struct PUSCH_TimeDomainResourceAllocationList));
7732       }
7733       DU_FREE(puschCfg->transformPrecoder, sizeof(long));
7734       DU_FREE(puschCfg->pusch_TimeDomainAllocationList, \
7735             sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
7736    }
7737
7738 }
7739
7740 /*******************************************************************
7741  *
7742  * @brief Frees memory allocated for Dedicated PUCCH config
7743  *
7744  * @details
7745  *
7746  *    Function : FreeBWPUlDedPucchCfg
7747  *
7748  *    Functionality: Deallocating memory of Dedicated PUCCH cfg
7749  *
7750  * @params[in] BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg
7751  *
7752  * @return void
7753  *
7754  * ****************************************************************/
7755 void FreeBWPUlDedPucchCfg(struct BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg)
7756 {
7757    uint8_t k1Idx, rsrcIdx, rsrcSetIdx;
7758    PUCCH_Config_t *pucchCfg = NULLP;
7759    PUCCH_ResourceSet_t *rsrcSet = NULLP;
7760    PUCCH_Resource_t *rsrc = NULLP;
7761
7762    if(ulBwpPucchCfg)
7763    {
7764       if(ulBwpPucchCfg->choice.setup)
7765       {
7766          pucchCfg = ulBwpPucchCfg->choice.setup;
7767
7768          //Free resource set list
7769          if(pucchCfg->resourceSetToAddModList)
7770          {
7771             if(pucchCfg->resourceSetToAddModList->list.array)
7772             {
7773                for(rsrcSetIdx=0; rsrcSetIdx < pucchCfg->resourceSetToAddModList->list.count; rsrcSetIdx++)
7774                {
7775                   rsrcSet = pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx];
7776                   if(rsrcSet->resourceList.list.array)
7777                   {
7778                      for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
7779                      {
7780                         DU_FREE(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
7781                      }
7782                      DU_FREE(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
7783                   }
7784                   DU_FREE(pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
7785                }
7786                DU_FREE(pucchCfg->resourceSetToAddModList->list.array, pucchCfg->resourceSetToAddModList->list.size);
7787             }
7788             DU_FREE(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
7789          }
7790
7791          //Free resource list
7792          if(pucchCfg->resourceToAddModList)
7793          {
7794             if(pucchCfg->resourceToAddModList->list.array)
7795             {
7796                for(rsrcIdx=0; rsrcIdx < pucchCfg->resourceToAddModList->list.count; rsrcIdx++)
7797                {
7798                   rsrc = pucchCfg->resourceToAddModList->list.array[rsrcIdx];
7799                   DU_FREE(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
7800                   DU_FREE(pucchCfg->resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
7801                }
7802                DU_FREE(pucchCfg->resourceToAddModList->list.array, pucchCfg->resourceToAddModList->list.size);
7803             }
7804             DU_FREE(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
7805          }
7806
7807          //PUCCH Format 1
7808          if(pucchCfg->format1)
7809          {
7810             if(pucchCfg->format1->choice.setup)
7811             {
7812                DU_FREE(pucchCfg->format1->choice.setup->nrofSlots, sizeof(long));
7813                DU_FREE(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
7814             }
7815             DU_FREE(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
7816          }
7817          
7818          //DL DATA TO UL ACK
7819          if(pucchCfg->dl_DataToUL_ACK)
7820          {
7821             if(pucchCfg->dl_DataToUL_ACK->list.array)
7822             {
7823                for(k1Idx = 0; k1Idx <  pucchCfg->dl_DataToUL_ACK->list.count; k1Idx++)
7824                {
7825                   DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array[k1Idx], sizeof(long));
7826                }
7827                DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array, pucchCfg->dl_DataToUL_ACK->list.size);
7828             }
7829             DU_FREE(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
7830          }
7831
7832          DU_FREE(ulBwpPucchCfg->choice.setup, sizeof(PUCCH_Config_t));
7833       }
7834       DU_FREE(ulBwpPucchCfg, sizeof(struct BWP_UplinkDedicated__pucch_Config));
7835    }
7836 }
7837
7838 /*******************************************************************
7839  *
7840  * @brief Frees memory allocated for InitialUlBWP
7841  *
7842  * @details
7843  *
7844  *    Function : FreeInitialUlBWP
7845  *
7846  *    Functionality: Deallocating memory of InitialUlBWP
7847  *
7848  * @params[in] BWP_UplinkDedicated_t *ulBwp
7849  *
7850  * @return void
7851  *
7852  * ****************************************************************/
7853 void FreeInitialUlBWP(BWP_UplinkDedicated_t *ulBwp)
7854 {
7855    uint8_t  rSetIdx, rsrcIdx;
7856    SRS_Config_t   *srsCfg = NULLP;
7857    PUSCH_Config_t *puschCfg = NULLP;
7858    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
7859    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
7860    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
7861    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
7862
7863    FreeBWPUlDedPucchCfg(ulBwp->pucch_Config);
7864
7865    if(ulBwp->pusch_Config)
7866    {
7867       if(ulBwp->pusch_Config->choice.setup)
7868       {
7869          puschCfg=ulBwp->pusch_Config->choice.setup;
7870          if(puschCfg->dataScramblingIdentityPUSCH)
7871          {
7872             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
7873             {
7874                FreePuschTimeDomAllocList(puschCfg);
7875                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
7876                if(dmrsUlCfg->choice.setup)
7877                {
7878                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
7879                   {
7880                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
7881                      {
7882                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
7883                               sizeof(long));
7884                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled,
7885                               sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
7886                      }
7887                      DU_FREE(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition,
7888                            sizeof(long));
7889                   }
7890                   DU_FREE(dmrsUlCfg->choice.setup,sizeof(DMRS_UplinkConfig_t));
7891                }
7892                DU_FREE(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, \
7893                      sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
7894             }
7895             DU_FREE(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
7896          }
7897          DU_FREE(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
7898       }
7899       DU_FREE(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
7900
7901       /* Free SRS-Config */
7902       if(ulBwp->srs_Config)
7903       {
7904          if(ulBwp->srs_Config->choice.setup)
7905          {
7906             srsCfg = ulBwp->srs_Config->choice.setup;
7907
7908             /* Free Resource Set to add/mod list */
7909             if(srsCfg->srs_ResourceSetToAddModList)
7910             {
7911                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
7912                if(rsrcSetList->list.array)
7913                {
7914                   rSetIdx = 0;
7915
7916                   /* Free SRS resource Id list in this SRS resource set */
7917                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
7918                   {
7919                      rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
7920
7921                      if(rsrcIdList->list.array)
7922                      {
7923                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
7924                         {
7925                            DU_FREE(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
7926                         }
7927                         DU_FREE(rsrcIdList->list.array, rsrcIdList->list.size);
7928                      }
7929                      DU_FREE(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
7930                            sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
7931                   }
7932
7933                   /* Free resource type info for this SRS resource set */
7934                   DU_FREE(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
7935                         sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
7936
7937                   /* Free memory for each resource set */
7938                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
7939                   {
7940                      DU_FREE(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
7941                   }
7942                   DU_FREE(rsrcSetList->list.array, rsrcSetList->list.size); 
7943                }
7944                DU_FREE(srsCfg->srs_ResourceSetToAddModList, \
7945                      sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
7946             }
7947
7948             /* Free resource to add/modd list */
7949             if(srsCfg->srs_ResourceToAddModList)
7950             {
7951                resourceList = srsCfg->srs_ResourceToAddModList;
7952                if(resourceList->list.array)
7953                {
7954                   rsrcIdx = 0;
7955                   DU_FREE(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2,\
7956                         sizeof(struct SRS_Resource__transmissionComb__n2));
7957                   DU_FREE(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,\
7958                         sizeof(struct SRS_Resource__resourceType__aperiodic));
7959
7960                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
7961                   {
7962                      DU_FREE(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
7963                   }
7964                   DU_FREE(resourceList->list.array, resourceList->list.size);
7965                }
7966                DU_FREE(srsCfg->srs_ResourceToAddModList, \
7967                      sizeof(struct SRS_Config__srs_ResourceToAddModList));
7968             }
7969
7970             DU_FREE(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
7971          }
7972          DU_FREE(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
7973       }
7974    }
7975 }       
7976 /*******************************************************************
7977  *
7978  * @brief Frees memory allocated for initialUplinkBWP
7979  *
7980  * @details
7981  *
7982  *    Function : FreeinitialUplinkBWP
7983  *
7984  *    Functionality: Deallocating memory of initialUplinkBWP
7985  *
7986  * @params[in] UplinkConfig_t *ulCfg
7987  *
7988  * @return void
7989  *         
7990  *
7991  * ****************************************************************/
7992 void FreeinitialUplinkBWP(UplinkConfig_t *ulCfg)
7993 {
7994    BWP_UplinkDedicated_t *ulBwp=NULLP; 
7995    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
7996
7997    if(ulCfg->initialUplinkBWP)
7998    {
7999       ulBwp=ulCfg->initialUplinkBWP;
8000       if(ulCfg->firstActiveUplinkBWP_Id)
8001       {
8002          if(ulCfg->pusch_ServingCellConfig)
8003          {
8004             puschCfg=ulCfg->pusch_ServingCellConfig;
8005             if(puschCfg->choice.setup)
8006             {
8007                if(puschCfg->choice.setup->ext1)
8008                {
8009                   DU_FREE(puschCfg->choice.setup->ext1->\
8010                         processingType2Enabled,sizeof(BOOLEAN_t));
8011                   DU_FREE(puschCfg->choice.setup->ext1->\
8012                         maxMIMO_Layers,sizeof(long));
8013                   DU_FREE(puschCfg->choice.setup->ext1, \
8014                         sizeof(struct PUSCH_ServingCellConfig__ext1));
8015                }
8016                DU_FREE(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
8017             }
8018             DU_FREE(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
8019          }
8020          DU_FREE(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
8021       }
8022       FreeInitialUlBWP(ulBwp);
8023       DU_FREE(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
8024    }
8025 }
8026 /*******************************************************************
8027  *
8028  * @brief Frees emmory allocated for BWPDlDedPdschCfg
8029  *
8030  * @details
8031  *
8032  *    Function : FreeBWPDlDedPdschCfg
8033  *
8034  *    Functionality: Deallocating memory of BWPDlDedPdschCfg
8035  *
8036  * @params[in] BWP_DownlinkDedicated_t *dlBwp
8037  *
8038  * @return void
8039  *
8040  *
8041  * ****************************************************************/
8042 void FreeBWPDlDedPdschCfg(BWP_DownlinkDedicated_t *dlBwp)
8043 {
8044    struct PDSCH_Config *pdschCfg=NULLP;
8045    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
8046    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
8047    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
8048
8049    if(dlBwp->pdsch_Config->choice.setup)
8050    {
8051       pdschCfg=dlBwp->pdsch_Config->choice.setup;
8052       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
8053       {
8054          if(pdschCfg->pdsch_TimeDomainAllocationList)
8055          {
8056             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
8057             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
8058             {
8059                prbBndlType=&pdschCfg->prb_BundlingType;
8060                DU_FREE(prbBndlType->choice.staticBundling,\
8061                      sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
8062                DU_FREE(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
8063             }
8064             FreePdschTimeDomAllocList(timeDomAllocList);
8065             DU_FREE(pdschCfg->pdsch_TimeDomainAllocationList, \
8066                   sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
8067          }
8068          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
8069          if(dmrsDlCfg->choice.setup)
8070          {
8071             DU_FREE(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition,
8072                   sizeof(long));
8073             DU_FREE(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
8074          }
8075          DU_FREE(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, \
8076                sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
8077       }
8078       DU_FREE(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
8079    }
8080 }
8081 /*******************************************************************
8082  *
8083  * @brief Frees emmory allocated for BWPDlDedPdcchCfg
8084  *
8085  * @details
8086  *
8087  *    Function : FreeBWPDlDedPdcchCfg
8088  *
8089  *    Functionality: Deallocating memory of BWPDlDedPdcchCfg
8090  *
8091  * @params[in] BWP_DownlinkDedicated_t *dlBwp
8092  *
8093  * @return void
8094  *         
8095  *
8096  * ****************************************************************/
8097 void FreeBWPDlDedPdcchCfg(BWP_DownlinkDedicated_t *dlBwp)
8098 {
8099    uint8_t idx1=0;
8100    uint8_t idx2=0;
8101    struct PDCCH_Config *pdcchCfg=NULLP;
8102    struct ControlResourceSet *controlRSet=NULLP;
8103    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
8104
8105    if(dlBwp->pdcch_Config->choice.setup)
8106    {
8107       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
8108       if(pdcchCfg->controlResourceSetToAddModList)
8109       {
8110          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
8111          if(controlRSetList->list.array)
8112          {
8113             controlRSet = controlRSetList->list.array[idx2];
8114             if(controlRSet)
8115             {
8116                if(controlRSet->frequencyDomainResources.buf)
8117                {
8118                   if(controlRSet->pdcch_DMRS_ScramblingID)
8119                   {
8120                      if(pdcchCfg->searchSpacesToAddModList)
8121                      {
8122                         FreeSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
8123                         DU_FREE(pdcchCfg->searchSpacesToAddModList, \
8124                               sizeof(struct PDCCH_Config__searchSpacesToAddModList));
8125                      }
8126                      DU_FREE(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
8127                   }
8128                   DU_FREE(controlRSet->frequencyDomainResources.buf, \
8129                         controlRSet->frequencyDomainResources.size);
8130                }
8131             }
8132             for(idx1 = 0; idx1 <controlRSetList->list.count; idx1++)
8133             {
8134                DU_FREE(controlRSetList->list.array[idx1], sizeof(struct ControlResourceSet));
8135             }
8136             DU_FREE(controlRSetList->list.array, controlRSetList->list.size);
8137          }
8138          DU_FREE(pdcchCfg->controlResourceSetToAddModList, \
8139                sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
8140       }
8141       DU_FREE(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
8142    }
8143 }       
8144
8145 /*******************************************************************
8146  *
8147  * @brief Free SCS specific carrier list in DL frequency info
8148  *
8149  * @details
8150  *
8151  *    Function : FreeScsSpecificCarrierListDl
8152  *
8153  *    Functionality: Free SCS specific carrier list in DL frequency info
8154  *
8155  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
8156  *
8157  * @return void
8158  *
8159  * ****************************************************************/
8160 void FreeScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
8161 {
8162    uint8_t listIdx = 0;
8163
8164    if(!scsCarrierList->list.array)
8165    {
8166       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
8167       {
8168          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
8169       }
8170       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
8171    }
8172 }
8173
8174 /*******************************************************************
8175  *
8176  * @brief Free DL frequency info in DL config common
8177  *
8178  * @details
8179  *
8180  *    Function : FreeFreqInfoDl
8181  *
8182  *    Functionality: Free DL frequency info in DL config common
8183  *
8184  * @params[in] Pointer to DownlinkConfigCommon_t
8185  *
8186  * @return void
8187  *
8188  * ****************************************************************/
8189 void FreeFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
8190 {
8191    uint8_t freqBandIdx = 0;
8192
8193    /* SSB Absolute Frequency */
8194    DU_FREE(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
8195
8196    /* NR Multi Frequency Band List */
8197    if(frequencyInfoDL->frequencyBandList.list.array)
8198    {
8199       for(freqBandIdx = 0; freqBandIdx < frequencyInfoDL->frequencyBandList.list.count; freqBandIdx++)
8200       {
8201          DU_FREE(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
8202       }
8203       DU_FREE(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
8204    }
8205
8206    /* Subcarrier Spacing specifc carrier List */
8207    FreeScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList);
8208 }
8209
8210 /*******************************************************************
8211  *
8212  * @brief Free DL config common in Serving cell config common
8213  *
8214  * @details
8215  *
8216  *    Function : FreeDlConfigCommon
8217  *
8218  *    Functionality: Free DL config common in Serving cell config common
8219  *
8220  * @params[in] Pointer to DownlinkConfigCommon_t
8221  *
8222  * @return void
8223  *
8224  * ****************************************************************/
8225 void FreeDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
8226 {
8227    /* DL Frequency Info */
8228    if(dlCfgCommon->frequencyInfoDL)
8229    {
8230       FreeFreqInfoDl(dlCfgCommon->frequencyInfoDL);
8231       DU_FREE(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
8232    }
8233
8234    /* DL BWP config common */
8235    if(dlCfgCommon->initialDownlinkBWP)
8236    {
8237       FreeBwpDlCommon(dlCfgCommon->initialDownlinkBWP);
8238       DU_FREE(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
8239    }
8240 }
8241
8242 /*******************************************************************
8243  *
8244  * @brief Free SCS specific carrier list in UL frequency Info
8245  *
8246  * @details
8247  *
8248  *    Function : FreeScsSpecificCarrierListUl
8249  *
8250  *    Functionality: Free SCS specific carrier list in UL frequency Info
8251  *
8252  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
8253  *
8254  * @return void
8255  *
8256  * ****************************************************************/
8257 void FreeScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
8258 {
8259    uint8_t listIdx = 0;
8260
8261    if(scsCarrierList->list.array)
8262    {
8263       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
8264       {
8265          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
8266       }
8267       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
8268    }
8269 }
8270
8271 /*******************************************************************
8272  *
8273  * @brief Free frequency info in UL config common
8274  *
8275  * @details
8276  *
8277  *    Function : FreeFreqInfoUl
8278  *
8279  *    Functionality: Free frequency info in UL config common
8280  *
8281  * @params[in] Pointer to FrequencyInfoUL_t
8282  *
8283  * @return void
8284  *
8285  * ****************************************************************/
8286 void FreeFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
8287 {
8288    uint8_t listIdx= 0;
8289
8290    /* NR Multi Frequency Band List */
8291    if(!frequencyInfoUL->frequencyBandList)
8292    {
8293       if(frequencyInfoUL->frequencyBandList->list.array)
8294       {
8295          for(listIdx = 0; listIdx < frequencyInfoUL->frequencyBandList->list.count; listIdx++)
8296          {
8297             DU_FREE(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
8298          }
8299          DU_FREE(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
8300       }
8301       DU_FREE(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
8302    }
8303
8304    /* Absolute frequency point A */
8305    DU_FREE(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
8306
8307    /* Subcarrier Spacing specifc carrier */
8308    FreeScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList);
8309
8310    /* P-MAX */
8311    DU_FREE(frequencyInfoUL->p_Max, sizeof(P_Max_t));
8312 }
8313
8314 /*******************************************************************
8315  *
8316  * @brief Free UL config common in Serving cell config common
8317  *
8318  * @details
8319  *
8320  *    Function : FreeUlConfigCommon
8321  *
8322  *    Functionality: Free UL config common in Serving cell config common
8323  *
8324  * @params[in] Pointer to UplinkConfigCommon_t
8325  *
8326  * @return void
8327  *
8328  * ****************************************************************/
8329 void FreeUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
8330 {
8331    /* UL Frequency Info */
8332    if(ulCfgCommon->frequencyInfoUL)
8333    {
8334       FreeFreqInfoUl(ulCfgCommon->frequencyInfoUL);
8335       DU_FREE(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
8336    }
8337
8338    /* UL BWP common */
8339    if(ulCfgCommon->initialUplinkBWP)
8340    {
8341       FreeBwpUlCommon(ulCfgCommon->initialUplinkBWP);
8342       DU_FREE(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
8343    }
8344 }
8345
8346 /*******************************************************************
8347  *
8348  * @brief Free SP cell config common in Reconfig with Sync
8349  *
8350  * @details
8351  *
8352  *    Function : FreeSpCellConfigCommon
8353  *
8354  *    Functionality: Free SP cell config common in Reconfig with Sync
8355  *
8356  * @params[in] Pointer to ServingCellConfigCommon_t
8357  *
8358  * @return void
8359  *
8360  * ****************************************************************/
8361 void FreeSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
8362 {
8363    /* Free Physical cell identity */
8364    DU_FREE(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
8365
8366    /* Free Downlink Config common */
8367    if(spCellConfigCommon->downlinkConfigCommon)
8368    {
8369       FreeDlConfigCommon(spCellConfigCommon->downlinkConfigCommon);
8370       DU_FREE(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
8371    }
8372
8373    /* Free Uplink Config common */
8374    if(spCellConfigCommon->uplinkConfigCommon)
8375    {
8376       FreeUlConfigCommon(spCellConfigCommon->uplinkConfigCommon);
8377       DU_FREE(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
8378    }
8379
8380    /* Free Timing Advance offset */
8381    DU_FREE(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
8382
8383    /* Free SSB Position in Burst */
8384    if(spCellConfigCommon->ssb_PositionsInBurst)
8385    {
8386       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.buf, \
8387          spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.size);
8388       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
8389    }
8390
8391    /* Free SSB Periodicity in Serving cell */
8392    DU_FREE(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
8393
8394    /* Free SSB subcarrier spacing */
8395    DU_FREE(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
8396
8397    /* TDD UL-DL configuration common */
8398    DU_FREE(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
8399 }
8400
8401 /*******************************************************************
8402  *
8403  * @brief Free dedicated RACH configuration in Reconfiguration with sync
8404  *
8405  * @details
8406  *
8407  *    Function : FreeRecfgWithSync
8408  *
8409  *    Functionality:
8410  *       Free dedicated RACH configuration in Reconfiguration with sync
8411  *
8412  * @params[in] Pinter to Rach config dedicated struct
8413  *
8414  * @return void
8415  *
8416  * ****************************************************************/
8417 void FreeRachConfigDedicated(struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
8418 {
8419    uint8_t listIdx = 0;
8420    CFRA_t *cfra = NULLP;
8421    struct CFRA__resources__ssb *ssbResource = NULLP;
8422
8423    /* Uplink */
8424    if(rachCfgDed->choice.uplink)
8425    {
8426       /* CFRA : Contention free Random Access */
8427       if(rachCfgDed->choice.uplink->cfra)
8428       {
8429          cfra = rachCfgDed->choice.uplink->cfra;
8430
8431          /* CFRA occassions */
8432          if(cfra->occasions)
8433          {
8434             /* CFRA occassions : SSB per RACH occasion */
8435             DU_FREE(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
8436             DU_FREE(cfra->occasions, sizeof(struct CFRA__occasions));
8437          }
8438
8439          /* CFRA resource */
8440          cfra->resources.present = CFRA__resources_PR_ssb;
8441
8442          /* CFRA resource : SSB */
8443          if(cfra->resources.choice.ssb)
8444          {
8445             ssbResource = cfra->resources.choice.ssb;
8446
8447             /* CFRA SSB resource list */
8448             if(ssbResource->ssb_ResourceList.list.array)
8449             {
8450                for(listIdx = 0; listIdx < ssbResource->ssb_ResourceList.list.count; listIdx++)
8451                {
8452                   DU_FREE(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
8453                }
8454                DU_FREE(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
8455             }
8456             DU_FREE(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
8457          }
8458          DU_FREE(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
8459       }
8460       DU_FREE(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
8461    }
8462 }
8463
8464 /*******************************************************************
8465  *
8466  * @brief Frees reconfiguration with sync in SP cell config
8467  *
8468  * @details
8469  *
8470  *    Function : FreeRecfgWithSync
8471  *
8472  *    Functionality: Fress reconfiguration with sync in SP cell config
8473  *
8474  * @params[in] Pointer to ReconfigurationWithSync_t
8475  *
8476  * @return void
8477  *
8478  * ****************************************************************/
8479 void FreeRecfgWithSync(ReconfigurationWithSync_t *recfgWithSync)
8480 {
8481    /* Free SP Cell config common */
8482    if(recfgWithSync->spCellConfigCommon)
8483    {
8484       FreeSpCellConfigCommon(recfgWithSync->spCellConfigCommon);
8485       DU_FREE(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
8486    }
8487
8488    /* Free Dedicated RACH configuration */
8489    if(recfgWithSync->rach_ConfigDedicated)
8490    {
8491       FreeRachConfigDedicated(recfgWithSync->rach_ConfigDedicated);
8492       DU_FREE(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
8493    }
8494 }
8495
8496 /*******************************************************************
8497  *
8498  * @brief Frees emmory allocated for DUToCURRCContainer 
8499  *
8500  * @details
8501  *
8502  *    Function : FreeMemDuToCuRrcCont
8503  *
8504  *    Functionality: Deallocating memory of DuToCuRrcContainer
8505  *
8506  * @params[in] DuToCuRRCContainer, DuToCuRRCContainer
8507  *
8508  * @return ROK     - success
8509  *         RFAILED - failure
8510  *
8511  * ****************************************************************/
8512 uint8_t FreeMemDuToCuRrcCont(CellGroupConfigRrc_t *cellGrpCfg)
8513 {
8514    uint8_t idx=0;
8515    SpCellConfig_t *spCellCfg=NULLP;
8516    ServingCellConfig_t *srvCellCfg=NULLP;
8517    BWP_DownlinkDedicated_t *dlBwp=NULLP;
8518    MAC_CellGroupConfig_t *macCellGrpCfg=NULLP;
8519    PhysicalCellGroupConfig_t *phyCellGrpCfg=NULLP;
8520    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList=NULLP;
8521    struct RLC_Config *rlcConfig=NULLP;
8522    struct LogicalChannelConfig *macLcConfig=NULLP;
8523    struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg=NULLP;
8524    struct SchedulingRequestConfig *schedulingRequestConfig=NULLP;
8525    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList=NULLP;
8526    struct TAG_Config *tagConfig=NULLP;
8527    struct TAG_Config__tag_ToAddModList *tagList=NULLP;
8528    struct MAC_CellGroupConfig__phr_Config *phrConfig=NULLP;
8529    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg=NULLP;
8530
8531    rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
8532    if(rlcBearerList)
8533    {
8534       if(rlcBearerList->list.array)
8535       {
8536          for(idx=0; idx<rlcBearerList->list.count; idx++)
8537          {
8538             if(rlcBearerList->list.array[idx])
8539             {  
8540                rlcConfig   = rlcBearerList->list.array[idx]->rlc_Config;
8541                macLcConfig = rlcBearerList->list.array[idx]->mac_LogicalChannelConfig;
8542                if(rlcConfig)
8543                {
8544                   switch(rlcConfig->present)
8545                   {
8546                      case RLC_Config_PR_NOTHING:
8547                         break;
8548
8549                      case RLC_Config_PR_am:
8550                         {
8551                            if(rlcConfig->choice.am)
8552                            {
8553                               DU_FREE(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
8554                               DU_FREE(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
8555                               DU_FREE(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
8556                            }
8557                            break;
8558                         }
8559                      case RLC_Config_PR_um_Bi_Directional:
8560                         {
8561                            if(rlcConfig->choice.um_Bi_Directional)
8562                            {
8563                               DU_FREE(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t)); 
8564                               DU_FREE(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8565                               DU_FREE(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
8566                            }
8567                            break;
8568                         }
8569                      case RLC_Config_PR_um_Uni_Directional_UL:
8570                         {
8571                            if(rlcConfig->choice.um_Uni_Directional_UL)
8572                            {
8573                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8574                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
8575                            }
8576                            break;
8577                         }
8578                      case RLC_Config_PR_um_Uni_Directional_DL:
8579                         {
8580                            if(rlcConfig->choice.um_Uni_Directional_DL )
8581                            {
8582                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8583                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
8584                            }
8585                            break;
8586                         }
8587                   }     
8588                   DU_FREE(rlcConfig, sizeof(struct RLC_Config));
8589                }
8590                DU_FREE(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
8591                if(macLcConfig)
8592                {
8593                   if(macLcConfig->ul_SpecificParameters)
8594                   {
8595                      DU_FREE(macLcConfig->ul_SpecificParameters->schedulingRequestID,   sizeof(SchedulingRequestId_t));
8596                      DU_FREE(macLcConfig->ul_SpecificParameters->logicalChannelGroup,   sizeof(long));
8597                      DU_FREE(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
8598                   }
8599                   DU_FREE(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
8600                }
8601                DU_FREE(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
8602             }   
8603          }
8604          DU_FREE(rlcBearerList->list.array, rlcBearerList->list.size);
8605       }
8606       DU_FREE(cellGrpCfg->rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8607    }
8608
8609    macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
8610    if(macCellGrpCfg)
8611    {
8612       drxCfg = macCellGrpCfg->drx_ConfigRrc;
8613
8614       if(drxCfg)
8615       {
8616           switch(drxCfg->present)
8617           {
8618             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
8619                break;
8620             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
8621             {
8622                if(drxCfg->choice.setup)
8623                {
8624                   DU_FREE(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));  
8625                   DU_FREE(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
8626                }
8627             }
8628             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
8629                break;
8630           }
8631           DU_FREE(drxCfg, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
8632       }
8633       schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig; 
8634       if(schedulingRequestConfig)
8635       {
8636          schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
8637          if(schReqList)
8638          {
8639             if(schReqList->list.array)
8640             {
8641                for(idx=0;idx<schReqList->list.count; idx++)
8642                {
8643                   if(schReqList->list.array[idx])
8644                   {
8645                      DU_FREE(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
8646                      DU_FREE(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
8647                   }
8648                }
8649                DU_FREE(schReqList->list.array, schReqList->list.size);
8650             }
8651             DU_FREE(schedulingRequestConfig->schedulingRequestToAddModList,\
8652                   sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));    }
8653             DU_FREE(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
8654       }
8655       if(macCellGrpCfg->bsr_Config)
8656       {
8657          DU_FREE(macCellGrpCfg->bsr_Config->logicalChannelSR_DelayTimer, sizeof(long));
8658          DU_FREE(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
8659       }
8660       tagConfig = macCellGrpCfg->tag_Config;
8661       if(tagConfig)
8662       {
8663          tagList = tagConfig->tag_ToAddModList;
8664          if(tagList)
8665          {
8666             if(tagList->list.array)
8667             {
8668                for(idx=0; idx<tagList->list.count; idx++)
8669                {
8670                   DU_FREE(tagList->list.array[idx], sizeof(struct TAG));
8671                }
8672                DU_FREE(tagList->list.array, tagList->list.size);
8673             }
8674             DU_FREE(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
8675          }
8676          DU_FREE(tagConfig, sizeof(struct TAG_Config));
8677       }
8678
8679       phrConfig = macCellGrpCfg->phr_Config;
8680       if(phrConfig)
8681       {
8682          DU_FREE(phrConfig->choice.setup, sizeof(struct PHR_Config));
8683          DU_FREE(phrConfig, sizeof(struct MAC_CellGroupConfig__phr_Config));
8684       }
8685
8686       DU_FREE(macCellGrpCfg, sizeof(MAC_CellGroupConfig_t));
8687    }
8688
8689    phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
8690    if(phyCellGrpCfg)
8691    {
8692       DU_FREE(phyCellGrpCfg->p_NR_FR1, sizeof(long));
8693       DU_FREE(phyCellGrpCfg, sizeof(PhysicalCellGroupConfig_t));
8694    }
8695
8696    spCellCfg = cellGrpCfg->spCellConfig;
8697    if(spCellCfg)
8698    {
8699       /* Free serving cell index */
8700       DU_FREE(spCellCfg->servCellIndex, sizeof(long));
8701
8702       /* Free Reconfiguration with sync */
8703       if(spCellCfg->reconfigurationWithSync)
8704       {
8705          FreeRecfgWithSync(spCellCfg->reconfigurationWithSync);
8706          DU_FREE(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
8707       }
8708
8709       /* Free rlmInSyncOutOfSyncThreshold */
8710       DU_FREE(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
8711
8712       /* Free SP Cell config dedicated */
8713       if(spCellCfg->spCellConfigDedicated)
8714       {
8715          srvCellCfg = spCellCfg->spCellConfigDedicated;
8716
8717          /* Free TDD UL-DL config dedicated */
8718          DU_FREE(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
8719
8720          /* Free Initial Downlink BWP */
8721          if(srvCellCfg->initialDownlinkBWP)
8722          {
8723             dlBwp = srvCellCfg->initialDownlinkBWP;
8724
8725             /* Free DL BWP PDCCH Config */
8726             if(dlBwp->pdcch_Config)
8727             {
8728                FreeBWPDlDedPdcchCfg(dlBwp);
8729                DU_FREE(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
8730             }
8731
8732             /* Free DL BWP PDSCH config */
8733             if(dlBwp->pdsch_Config)
8734             {
8735                FreeBWPDlDedPdschCfg(dlBwp);
8736                DU_FREE(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
8737             }
8738             DU_FREE(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
8739          }
8740
8741          /* Free First Active Downlink BWP */
8742          DU_FREE(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
8743
8744          /* Free Default downlink BWP */
8745          DU_FREE(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
8746
8747          /* Free Uplink config */
8748          if(srvCellCfg->uplinkConfig)
8749          {
8750             FreeinitialUplinkBWP(srvCellCfg->uplinkConfig);
8751             DU_FREE(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));  
8752          }
8753
8754          /* Free PDSCH serving cell config */
8755          if(srvCellCfg->pdsch_ServingCellConfig)
8756          {
8757             pdschCfg= srvCellCfg->pdsch_ServingCellConfig;
8758             if(pdschCfg->choice.setup)
8759             {
8760                DU_FREE(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH,sizeof(long));
8761                DU_FREE(pdschCfg->choice.setup, sizeof(struct PDSCH_ServingCellConfig));
8762             }
8763             DU_FREE(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct ServingCellConfig__pdsch_ServingCellConfig));
8764          }
8765
8766          DU_FREE(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
8767       }
8768       DU_FREE(spCellCfg,sizeof(SpCellConfig_t));
8769    }
8770    return ROK;
8771 }
8772
8773 /*******************************************************************
8774  *
8775  * @brief Builds CellGroupConfigRrc for DU To CU RRC Container 
8776  *
8777  * @details
8778  *
8779  *    Function : BuildCellGroupConfigRrc
8780  *
8781  *    Functionality: Builds and copied Cell group config buffer into 
8782  *       DuToCuRrcContainer
8783  *
8784  * @params[in] idx, index in F1AP msg
8785  *             DuToCuRRCContainer, DuToCuRRCContainer
8786  *
8787  * @return ROK     - success
8788  *         RFAILED - failure
8789  *
8790  * ****************************************************************/
8791 uint8_t BuildCellGroupConfigRrc(DuUeCb *ueCb, OCTET_STRING_t *duToCuRrcContainer)
8792 {
8793    uint8_t  ret = ROK;
8794    CellGroupConfigRrc_t  cellGrpCfg;
8795    asn_enc_rval_t        encRetVal;
8796    memset(&cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
8797    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8798
8799    while(true)
8800    {
8801       cellGrpCfg.cellGroupId = CELL_GRP_ID;
8802
8803       cellGrpCfg.rlc_BearerToAddModList = NULLP;
8804       DU_ALLOC(cellGrpCfg.rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8805       if(!cellGrpCfg.rlc_BearerToAddModList)
8806       {
8807          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8808          ret = RFAILED;
8809          break;
8810       }
8811       if(BuildRlcBearerToAddModList(ueCb, cellGrpCfg.rlc_BearerToAddModList) != ROK)
8812       {
8813          DU_LOG("\nERROR  -->  F1AP : BuildRlcBearerToAddModList failed");
8814          ret = RFAILED;
8815          break;
8816       }
8817
8818       cellGrpCfg.rlc_BearerToReleaseList = NULLP;
8819       cellGrpCfg.mac_CellGroupConfig = NULLP;
8820       DU_ALLOC(cellGrpCfg.mac_CellGroupConfig, sizeof(MAC_CellGroupConfig_t));
8821       if(!cellGrpCfg.mac_CellGroupConfig)
8822       {
8823          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8824          ret = RFAILED;
8825          break;
8826       }
8827       if(BuildMacCellGrpCfg(ueCb, cellGrpCfg.mac_CellGroupConfig) != ROK)
8828       {
8829          DU_LOG("\nERROR  -->  F1AP : BuildMacCellGrpCfg failed");
8830          ret = RFAILED;
8831          break;
8832       }
8833
8834       cellGrpCfg.physicalCellGroupConfig = NULLP;
8835       DU_ALLOC(cellGrpCfg.physicalCellGroupConfig, sizeof(PhysicalCellGroupConfig_t));
8836       if(!cellGrpCfg.physicalCellGroupConfig)
8837       {
8838          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8839          ret = RFAILED;
8840          break;
8841       }
8842       if(BuildPhyCellGrpCfg(ueCb, cellGrpCfg.physicalCellGroupConfig) != ROK)
8843       {
8844          DU_LOG("\nERROR  -->  F1AP : BuildPhyCellGrpCfg failed");
8845          ret = RFAILED;
8846          break;
8847       }
8848
8849       cellGrpCfg.spCellConfig = NULLP;
8850       DU_ALLOC(cellGrpCfg.spCellConfig, sizeof(SpCellConfig_t));
8851       if(!cellGrpCfg.spCellConfig)
8852       {
8853          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8854          ret = RFAILED;
8855          break;
8856       }
8857       if(BuildSpCellCfg(ueCb, cellGrpCfg.spCellConfig) != ROK)
8858       {
8859          DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfg failed");
8860          ret = RFAILED;
8861          break;
8862       }
8863
8864       cellGrpCfg.sCellToAddModList = NULLP;
8865       cellGrpCfg.sCellToReleaseList = NULLP;
8866       cellGrpCfg.ext1 = NULLP;
8867
8868       /* encode cellGrpCfg into duToCuRrcContainer */
8869       xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, &cellGrpCfg);
8870       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8871       encBufSize = 0;
8872       encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, &cellGrpCfg, PrepFinalEncBuf, encBuf);
8873       /* Encode results */
8874       if(encRetVal.encoded == ENCODE_FAIL)
8875       {
8876          DU_LOG( "\nERROR  --> F1AP : Could not encode DuToCuRrcContainer (at %s)\n",\
8877                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
8878          ret = RFAILED;
8879          break;
8880       }
8881       else
8882       {
8883          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DuToCuRrcContainer\n");
8884 #ifdef DEBUG_ASN_PRINT
8885          for(int i=0; i< encBufSize; i++)
8886          {
8887             printf("%x",encBuf[i]);
8888          }
8889 #endif
8890       }
8891
8892       duToCuRrcContainer->size = encBufSize;
8893       DU_ALLOC(duToCuRrcContainer->buf, duToCuRrcContainer->size);
8894       if(!duToCuRrcContainer->buf)
8895       {
8896          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDuToCuRrcContainer");
8897          ret = RFAILED;
8898          break;
8899       }
8900       if(ret == ROK)
8901       {
8902          memcpy(duToCuRrcContainer->buf, encBuf, duToCuRrcContainer->size);
8903       }
8904       break;
8905    }
8906    FreeMemDuToCuRrcCont(&cellGrpCfg);
8907    return ret;
8908 }
8909
8910 /*******************************************************************
8911  *
8912  * @brief Free memory allocated in InitialULRRCMessage
8913  *
8914  * @details
8915  *
8916  *    Function : freeInitUlRrcMsgTransfer
8917  *
8918  *    Functionality: Free memory allocated in InitialULRRCMessage
8919  *
8920  * @params[in]F1AP_PDU_t  *f1apMsg)
8921  *
8922  * @return ROK     - success
8923  *         RFAILED - failure
8924  *
8925  * ****************************************************************/
8926
8927 uint8_t freeInitUlRrcMsgTransfer(F1AP_PDU_t  *f1apMsg)
8928 {
8929    uint8_t ieIdx, arrIdx;
8930    InitialULRRCMessageTransfer_t *initULRRCMsg=NULLP;
8931
8932    if(f1apMsg)
8933    {
8934       if(f1apMsg->choice.initiatingMessage)
8935       {
8936          initULRRCMsg = &f1apMsg->choice.initiatingMessage->value.\
8937             choice.InitialULRRCMessageTransfer;
8938          if(initULRRCMsg->protocolIEs.list.array)
8939          {
8940             for(ieIdx = 0; ieIdx < initULRRCMsg->protocolIEs.list.count; ieIdx++)
8941             {
8942                switch(initULRRCMsg->protocolIEs.list.array[ieIdx]->id)
8943                {
8944                   case ProtocolIE_ID_id_NRCGI:
8945                   {
8946                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf)
8947                      {
8948                         if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf)
8949                         {
8950                            DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf,\
8951                            initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.size);
8952                         }
8953                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf,\
8954                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.size);
8955                      }
8956                      break;
8957                   }
8958                   case ProtocolIE_ID_id_RRCContainer:
8959                   {
8960                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
8961                      {
8962                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,\
8963                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
8964                      }
8965                      break;
8966                   }
8967                   case ProtocolIE_ID_id_DUtoCURRCContainer:
8968                   {
8969                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf)
8970                      {
8971                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf,
8972                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.size);
8973                      }
8974                      break;
8975                   }
8976                   default:
8977                      break;
8978                }
8979              }
8980              for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
8981              {
8982                 if(initULRRCMsg->protocolIEs.list.array[arrIdx])
8983                 {
8984                    DU_FREE(initULRRCMsg->protocolIEs.list.array[arrIdx],\
8985                       sizeof(InitialULRRCMessageTransferIEs_t));
8986                 }
8987              }
8988              DU_FREE(initULRRCMsg->protocolIEs.list.array, initULRRCMsg->protocolIEs.list.size);
8989           }
8990          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8991       }
8992       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
8993    }
8994    else
8995    {
8996       DU_LOG("\nERROR  -->  DU_APP : Recevied F1ap Pdu is null at freeInitUlRrcMsgTransfer()");
8997       return RFAILED;
8998    }
8999    return ROK;
9000 }
9001
9002 /*******************************************************************
9003  *
9004  * @brief Builds and sends the InitialULRRCMessage 
9005  *
9006  * @details
9007  *
9008  *    Function : BuildAndSendInitialRrcMsgTransfer 
9009  *
9010  *    Functionality: Constructs the Initial UL RRC Message Transfer and sends
9011  *                   it to the CU through SCTP.
9012  *
9013  * @params[in] 
9014  *
9015  * @return ROK     - success
9016  *         RFAILED - failure
9017  *
9018  * ****************************************************************/
9019 uint8_t BuildAndSendInitialRrcMsgTransfer(uint32_t gnbDuUeF1apId, uint16_t crnti,
9020       uint16_t rrcContSize, uint8_t *rrcContainer)
9021 {
9022    uint8_t   ret;
9023    uint8_t   elementCnt;
9024    uint8_t   ieIdx, cellIdx, ueIdx;
9025    DuUeCb    *duUeCb = NULLP;
9026    asn_enc_rval_t  encRetVal;
9027    F1AP_PDU_t  *f1apMsg = NULLP;
9028    InitialULRRCMessageTransfer_t *initULRRCMsg = NULLP;
9029    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
9030
9031    while(true)
9032    {
9033       DU_LOG("\n INFO   -->  F1AP : Building RRC Setup Request\n");
9034       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
9035       if(f1apMsg == NULLP)
9036       {
9037          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
9038          break;
9039       }
9040       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
9041       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
9042       if(f1apMsg->choice.initiatingMessage == NULLP)
9043       {
9044          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU failed");
9045          break;
9046       }
9047       f1apMsg->choice.initiatingMessage->procedureCode =\
9048                                                         ProcedureCode_id_InitialULRRCMessageTransfer;
9049       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
9050       f1apMsg->choice.initiatingMessage->value.present = \
9051                                                          InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
9052       initULRRCMsg =\
9053                     &f1apMsg->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
9054       elementCnt = 5;
9055       initULRRCMsg->protocolIEs.list.count = elementCnt;
9056       initULRRCMsg->protocolIEs.list.size = \
9057                                             elementCnt * sizeof(InitialULRRCMessageTransferIEs_t *);
9058       /* Initialize the F1Setup members */
9059       DU_ALLOC(initULRRCMsg->protocolIEs.list.array,initULRRCMsg->protocolIEs.list.size);
9060       if(initULRRCMsg->protocolIEs.list.array == NULLP)
9061       {
9062          DU_LOG(" ERROR  -->  F1AP : Memory allocation for\
9063                RRCSetupRequestMessageTransferIEs failed");
9064          break;
9065       }
9066       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
9067       {
9068          DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx],\
9069                sizeof(InitialULRRCMessageTransferIEs_t));
9070          if(initULRRCMsg->protocolIEs.list.array[ieIdx] == NULLP)
9071          {
9072             break;
9073          }
9074       }
9075       ieIdx = 0;
9076       /*GNB DU UE F1AP ID*/
9077       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9078                                                         ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
9079       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  = Criticality_reject;
9080       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
9081                                                                   InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
9082       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
9083
9084
9085       /*NRCGI*/
9086       ieIdx++;
9087       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9088                                                         ProtocolIE_ID_id_NRCGI;
9089       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  =Criticality_reject;
9090       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
9091                                                                   InitialULRRCMessageTransferIEs__value_PR_NRCGI;
9092
9093       ret =\
9094            BuildNrcgi(&initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
9095       if(ret!=ROK)
9096       {
9097          break;
9098       }
9099
9100       /*CRNTI*/
9101       ieIdx++;
9102       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9103                                                         ProtocolIE_ID_id_C_RNTI;
9104       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9105       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9106                                                                  InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
9107       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.C_RNTI = crnti;
9108
9109       /*RRCContainer*/
9110       ieIdx++;
9111       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
9112                                                         ProtocolIE_ID_id_RRCContainer;
9113       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9114       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9115                                                                  InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
9116
9117       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size = rrcContSize;
9118       DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,
9119             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size)
9120       if(!initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
9121       {
9122          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRCSetupRequestMessageTransferIEs failed");
9123          break;
9124       
9125       }
9126       memcpy(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, rrcContainer,
9127             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
9128
9129
9130       /*DUtoCURRCContainer*/
9131       ieIdx++;
9132       initULRRCMsg->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCContainer;
9133       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
9134       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
9135                                                                  InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
9136
9137       for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
9138       {
9139          for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
9140          {
9141             if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
9142                   (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti == crnti))
9143             {
9144                duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
9145             }
9146          }
9147       }
9148
9149       ret = BuildCellGroupConfigRrc(duUeCb, &initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer);
9150       if(ret != ROK)
9151       {
9152          break;
9153       }
9154
9155       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
9156
9157       /* Encode the Intial UL RRC Message transfer as APER */
9158       memset(encBuf, 0, ENC_BUF_MAX_LEN);
9159       encBufSize = 0;
9160       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
9161       /* Encode results */
9162       if(encRetVal.encoded == ENCODE_FAIL)
9163       {
9164          DU_LOG( "\nERROR  --> F1AP : Could not encode Initial UL RRC Message Transfer\
9165                structure (at %s)\n",encRetVal.failed_type ? \
9166                encRetVal.failed_type->name : "unknown");
9167          ret = RFAILED;
9168          break;
9169       }
9170       else
9171       {
9172
9173          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Initial UL RRC\
9174                Message transfer\n");
9175 #ifdef DEBUG_ASN_PRINT
9176          for(int i=0; i< encBufSize; i++)
9177          {
9178             printf("%x",encBuf[i]);
9179          }
9180 #endif
9181       }
9182       /* Sending  msg  */
9183       if(sendF1APMsg() != ROK)
9184       {
9185          DU_LOG("\nERROR  -->  F1AP : Sending Initial UL RRC Message Transfer Failed");
9186          ret = RFAILED;
9187          break;
9188       }
9189       break;
9190    }
9191    freeInitUlRrcMsgTransfer(f1apMsg);
9192    return ret;
9193 }/* End of BuildAndSendInitialRrcMsgTransfer*/
9194
9195 /*****  UE SETUP REQUEST *****/
9196
9197 /******************************************************************
9198 *
9199 * @brief Function to delete the RLC Lc cfg from UE APP DB
9200 *
9201 * @details
9202 *
9203 *  Function : freeRlcLcCfg
9204 *
9205 *  Functionality: Function to delete the RLC Lc cfg from UE APP DB
9206 *
9207 *
9208  *****************************************************************/
9209
9210 void freeRlcLcCfg(RlcBearerCfg *lcCfg)
9211 {
9212    switch(lcCfg->rlcMode)
9213    {
9214       case RLC_AM :
9215          {
9216             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
9217             break;
9218          }
9219       case RLC_UM_BI_DIRECTIONAL :
9220          {
9221             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
9222             break;
9223          }
9224       case RLC_UM_UNI_DIRECTIONAL_UL :
9225          {
9226             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
9227             break;
9228          }
9229       case RLC_UM_UNI_DIRECTIONAL_DL :
9230          {
9231             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
9232             break;
9233          }
9234       default:
9235          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at freeRlcLcCfg()", lcCfg->rlcMode);
9236          break;
9237    }
9238    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
9239 }
9240
9241 /*******************************************************************
9242  *
9243  * @brief Function to free MacLcCfg
9244  *
9245  * @details
9246  *
9247  *    Function : freeMacLcCfg
9248  *
9249  *    Functionality: Function to free MacLcCfg
9250  *
9251  * @params[in] LcCfg *lcCfg,
9252  * @return void
9253  *
9254  * ****************************************************************/
9255
9256 void freeMacLcCfg(LcCfg *lcCfg)
9257 {
9258     /* Deleting DRBQOS */
9259    if(lcCfg->drbQos)
9260    {
9261       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
9262    }
9263    /* Deleting SNSSAI */
9264    if(lcCfg->snssai)
9265    {
9266       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
9267    }
9268 }
9269 /*******************************************************************
9270  *
9271  * @brief Free UE NR Capability received in UE Context setup request
9272  *
9273  * @details
9274  *
9275  *    Function : freeAperDecodeUeNrCapability
9276  *
9277  *    Functionality:  
9278  *       Free UE NR Capability received in UE Context setup request
9279  *
9280  * @params[in] 
9281  * @return ROK     - success
9282  *         RFAILED - failure
9283  *
9284  * ****************************************************************/
9285 void freeAperDecodeUeNrCapability(void *ueNrCapability)
9286 {
9287    uint8_t arrIdx =0;
9288    FeatureSets_t *featureSets =NULLP;
9289    UE_NR_Capability_t *ueNrCap = (UE_NR_Capability_t *)ueNrCapability;
9290
9291    if(ueNrCap->rf_Parameters.supportedBandListNR.list.array)
9292    {
9293       for(arrIdx = 0; arrIdx < ueNrCap->rf_Parameters.supportedBandListNR.list.count; arrIdx++)
9294       {
9295          if(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx])
9296             free(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx]);
9297       }
9298       free(ueNrCap->rf_Parameters.supportedBandListNR.list.array);
9299    }
9300
9301    if(ueNrCap->featureSets)
9302    {
9303       featureSets = ueNrCap->featureSets;
9304       if(featureSets->featureSetsDownlinkPerCC)
9305       {
9306          if(featureSets->featureSetsDownlinkPerCC->list.array)
9307          {
9308             for(arrIdx = 0; arrIdx < featureSets->featureSetsDownlinkPerCC->list.count; arrIdx++)
9309             {
9310                if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx])
9311                {
9312                   if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL)
9313                      free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL);
9314                   free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]);
9315                }
9316             }
9317             free(featureSets->featureSetsDownlinkPerCC->list.array);
9318          }
9319          free(featureSets->featureSetsDownlinkPerCC);
9320       }
9321       if(featureSets->featureSetsUplinkPerCC)
9322       {
9323          if(featureSets->featureSetsUplinkPerCC->list.array)
9324          {
9325             for(arrIdx = 0; arrIdx < featureSets->featureSetsUplinkPerCC->list.count; arrIdx++)
9326             {
9327                if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx])
9328                {
9329                   if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL)
9330                      free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL);
9331                   free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]);
9332                }
9333             }
9334             free(featureSets->featureSetsUplinkPerCC->list.array);
9335          }
9336          free(featureSets->featureSetsUplinkPerCC);
9337       }
9338       free(ueNrCap->featureSets);
9339    }   
9340 }
9341
9342 /*******************************************************************
9343 *
9344 * @brief Function to free PdcchSearchSpcToAddModList
9345          where memory allocated by aper_decoder
9346 *
9347 * @details
9348 *
9349 *    Function : freeAperDecodePdcchSearchSpcToAddModList 
9350 *
9351 *    Functionality: Function to free PdcchSearchSpcToAddModList
9352 *
9353 * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
9354 * @return void
9355 *
9356 * ****************************************************************/
9357
9358 void freeAperDecodePdcchSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
9359 {
9360    uint8_t searchSpcArrIdx=0;
9361    uint8_t searchSpcArrIdx1=0;
9362    struct  SearchSpace *searchSpc=NULLP;
9363
9364
9365    if(searchSpcList->list.array)
9366    {
9367       if(searchSpcList->list.array[searchSpcArrIdx1])
9368       {
9369          searchSpc = searchSpcList->list.array[searchSpcArrIdx1];
9370          if(searchSpc->controlResourceSetId)
9371          {
9372             if(searchSpc->monitoringSlotPeriodicityAndOffset)
9373             {
9374                if(searchSpc->monitoringSymbolsWithinSlot)
9375                {
9376                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
9377                   {
9378                      if(searchSpc->nrofCandidates)
9379                      {
9380                         if(searchSpc->searchSpaceType)
9381                         {
9382                            free(searchSpc->searchSpaceType->choice.ue_Specific);
9383                            free(searchSpc->searchSpaceType);
9384                         }
9385                         free(searchSpc->nrofCandidates);
9386                      }
9387                      free(searchSpc->monitoringSymbolsWithinSlot->buf);
9388                   }
9389                   free(searchSpc->monitoringSymbolsWithinSlot);
9390                }
9391                free(searchSpc->monitoringSlotPeriodicityAndOffset);
9392             }
9393             free(searchSpc->controlResourceSetId);
9394          }
9395       }
9396       for(searchSpcArrIdx = 0; searchSpcArrIdx < searchSpcList->list.count; searchSpcArrIdx++)
9397       {
9398          free(searchSpcList->list.array[searchSpcArrIdx]);
9399       }
9400       free(searchSpcList->list.array);
9401    }
9402 }
9403 /*******************************************************************
9404 *
9405 * @brief Function for free part for the memory allocated by aper_decoder
9406
9407 * @details
9408 *
9409 *    Function : freeAperDecodeBWPDlDedPdcchConfig
9410 *
9411 *    Functionality: Function to free BWPDlDedPdcchConfig
9412 *
9413 * @params[in] 
9414 * @return void
9415 *
9416 * ****************************************************************/
9417
9418
9419 void freeAperDecodeBWPDlDedPdcchConfig(BWP_DownlinkDedicated_t *dlBwp)
9420 {
9421    uint8_t arrIdx1=0;
9422    uint8_t arrIdx2=0;
9423    struct PDCCH_Config *pdcchCfg=NULLP;
9424    struct ControlResourceSet *controlRSet=NULLP;
9425    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
9426    
9427    if(dlBwp->pdcch_Config->choice.setup)
9428    {
9429       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
9430       if(pdcchCfg->controlResourceSetToAddModList)
9431       {
9432          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
9433          if(controlRSetList->list.array)
9434          {
9435             controlRSet = controlRSetList->list.array[arrIdx2];
9436             if(controlRSet)
9437             {
9438                if(controlRSet->frequencyDomainResources.buf)
9439                {
9440                   if(controlRSet->pdcch_DMRS_ScramblingID)
9441                   {
9442                      if(pdcchCfg->searchSpacesToAddModList)
9443                      {
9444                         freeAperDecodePdcchSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
9445                         free(pdcchCfg->searchSpacesToAddModList);
9446                      }
9447                      free(controlRSet->pdcch_DMRS_ScramblingID);
9448                   }
9449                   free(controlRSet->frequencyDomainResources.buf);
9450                }
9451             }
9452             for(arrIdx1 = 0; arrIdx1 <controlRSetList->list.count; arrIdx1++)
9453             {
9454                free(controlRSetList->list.array[arrIdx1]);
9455             }
9456             free(controlRSetList->list.array);
9457          }
9458          free(pdcchCfg->controlResourceSetToAddModList);
9459       }
9460       free(dlBwp->pdcch_Config->choice.setup);
9461    }
9462 }
9463 /*******************************************************************
9464 *
9465 * @brief Function to free PdschTimeDomAllocationList 
9466 *     where the memory allocated by aper_decoder
9467
9468 * @details
9469 *
9470 *    Function : freeAperDecodePdschTimeDomAllocationList
9471 *
9472 *    Functionality: Function to free PdschTimeDomAllocationList
9473 *
9474 * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList 
9475 * @return void
9476 *
9477 * ****************************************************************/
9478
9479
9480 void freeAperDecodePdschTimeDomAllocationList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
9481 {
9482    uint8_t arrIdx=0;
9483
9484    if(timeDomAllocList->choice.setup)
9485    {
9486       if(timeDomAllocList->choice.setup->list.array)
9487       {
9488          for(arrIdx = 0; arrIdx <timeDomAllocList->choice.setup->list.count ; arrIdx++)
9489          {
9490             free(timeDomAllocList->choice.setup->list.array[arrIdx]);
9491          }
9492          free(timeDomAllocList->choice.setup->list.array);
9493       }
9494       free(timeDomAllocList->choice.setup);
9495    }
9496 }
9497
9498 /*******************************************************************
9499 *
9500 * @brief Function to free BWPDlDedPdschConfig 
9501 *        where the memory allocated by aper_decoder
9502 *  
9503 * @details
9504 *
9505 *    Function : freeAperDecodeBWPDlDedPdschConfig 
9506 *
9507 *    Functionality: Function to free BWPDlDedPdschConfig 
9508 *
9509 * @params[in] BWP_DownlinkDedicated_t *dlBwp 
9510 * @return void
9511 *
9512 * ****************************************************************/
9513
9514
9515 void freeAperDecodeBWPDlDedPdschConfig(BWP_DownlinkDedicated_t *dlBwp)
9516 {
9517    struct PDSCH_Config *pdschCfg=NULLP;
9518    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
9519    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
9520    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
9521
9522    if(dlBwp->pdsch_Config->choice.setup)
9523    {
9524       pdschCfg=dlBwp->pdsch_Config->choice.setup;
9525       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
9526       {
9527          if(pdschCfg->pdsch_TimeDomainAllocationList)
9528          {
9529             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
9530             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
9531             {
9532                prbBndlType=&pdschCfg->prb_BundlingType;
9533                free(prbBndlType->choice.staticBundling);
9534                free(pdschCfg->maxNrofCodeWordsScheduledByDCI);
9535             }
9536             freeAperDecodePdschTimeDomAllocationList(timeDomAllocList);
9537             free(pdschCfg->pdsch_TimeDomainAllocationList);
9538          }
9539          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
9540          if(dmrsDlCfg->choice.setup)
9541          {
9542             free(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition);
9543             free(dmrsDlCfg->choice.setup);
9544          }
9545          free(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA);
9546       }
9547       free(dlBwp->pdsch_Config->choice.setup);
9548    }
9549 }
9550 /*******************************************************************
9551 *
9552 * @brief Function to free PuschTimeDomAllocListCfg
9553                  where the memory allocated by aper_decoder
9554 *
9555 * @details
9556 *
9557 *    Function : freeAperDecodePuschTimeDomAllocListCfg
9558 *
9559 *    Functionality: Function to free PuschTimeDomAllocListCfg
9560 *
9561 * @params[in] PUSCH_Config_t *puschCfg 
9562 * @return void
9563 *
9564 * ****************************************************************/
9565
9566
9567 void freeAperDecodePuschTimeDomAllocListCfg(PUSCH_Config_t *puschCfg)
9568 {
9569    uint8_t arrIdx=0;
9570    uint8_t arrIdx1=0;
9571    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
9572
9573    if(puschCfg->pusch_TimeDomainAllocationList)
9574    {
9575       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
9576       if(timeDomAllocList_t->choice.setup)
9577       {
9578          if(timeDomAllocList_t->choice.setup->list.array)
9579          {
9580             free(timeDomAllocList_t->choice.setup->list.array[arrIdx1]->k2);
9581             for(arrIdx = 0; arrIdx<timeDomAllocList_t->choice.setup->list.count; arrIdx++)
9582             {
9583                free(timeDomAllocList_t->choice.setup->list.array[arrIdx]);
9584             }
9585             free(timeDomAllocList_t->choice.setup->list.array);
9586          }
9587          free(timeDomAllocList_t->choice.setup);
9588       }
9589       free(puschCfg->transformPrecoder);
9590       free(puschCfg->pusch_TimeDomainAllocationList);
9591    }
9592 }
9593 /*******************************************************************
9594 *
9595 * @brief Function to free InitialUlBWPConfig where memory allocated by aper_decoder
9596 *
9597 * @details
9598 *
9599 *    Function : freeAperDecodeInitialUlBWPConfig 
9600 *
9601 *    Functionality: Function to free InitialUlBWPConfig
9602 *
9603 * @params[in]  BWP_UplinkDedicated_t *ulBwp
9604 * @return void
9605 *
9606 * ****************************************************************/
9607
9608
9609 void freeAperDecodeInitialUlBWPConfig(BWP_UplinkDedicated_t *ulBwp)
9610 {
9611    uint8_t  rSetIdx =0;
9612    uint8_t  rsrcIdx =0;
9613    SRS_Config_t   *srsCfg = NULLP;
9614    PUSCH_Config_t *puschCfg = NULLP;
9615    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
9616    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
9617    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
9618    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
9619
9620    if(ulBwp->pusch_Config)
9621    {
9622       if(ulBwp->pusch_Config->choice.setup)
9623       {
9624          puschCfg=ulBwp->pusch_Config->choice.setup;
9625          if(puschCfg->dataScramblingIdentityPUSCH)
9626          {
9627             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
9628             {
9629                freeAperDecodePuschTimeDomAllocListCfg(puschCfg);
9630                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
9631                if(dmrsUlCfg->choice.setup)
9632                {
9633                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
9634                   {
9635                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
9636                      {
9637                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0);
9638                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled);
9639                      }
9640                      free(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition);
9641                   }
9642                   free(dmrsUlCfg->choice.setup);
9643                }
9644                free(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA);
9645             }
9646             free(puschCfg->dataScramblingIdentityPUSCH);
9647          }
9648          free(ulBwp->pusch_Config->choice.setup);
9649       }
9650       free(ulBwp->pusch_Config);
9651
9652       /* Free SRS-Config */
9653       if(ulBwp->srs_Config)
9654       {
9655          if(ulBwp->srs_Config->choice.setup)
9656          {
9657             srsCfg = ulBwp->srs_Config->choice.setup;
9658
9659             /* Free Resource Set to add/mod list */
9660             if(srsCfg->srs_ResourceSetToAddModList)
9661             {
9662                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
9663                if(rsrcSetList->list.array)
9664                {
9665                   rSetIdx = 0;
9666
9667                   /* Free SRS resource Id list in this SRS resource set */
9668                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
9669                   {
9670                      rsrcIdList =
9671                         rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
9672
9673                      if(rsrcIdList->list.array)
9674                      {
9675                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count;
9676                               rsrcIdx++)
9677                         {
9678                            free(rsrcIdList->list.array[rsrcIdx]);
9679                         }
9680                         free(rsrcIdList->list.array);
9681                      }
9682                      free(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList);
9683                   }
9684
9685                   /* Free resource type info for this SRS resource set */
9686
9687                   free(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic);
9688
9689                   /* Free memory for each resource set */
9690                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
9691                   {
9692                      free(rsrcSetList->list.array[rSetIdx]);
9693                   }
9694                   free(rsrcSetList->list.array);
9695                }
9696                free(srsCfg->srs_ResourceSetToAddModList);
9697             }
9698
9699             /* Free resource to add/modd list */
9700             if(srsCfg->srs_ResourceToAddModList)
9701             {
9702                resourceList = srsCfg->srs_ResourceToAddModList;
9703                if(resourceList->list.array)
9704                {
9705                   rsrcIdx = 0;
9706
9707                   free(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2);
9708                   free(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic);
9709
9710                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
9711                   {
9712                      free(resourceList->list.array[rsrcIdx]);
9713                   }
9714                   free(resourceList->list.array);
9715                }
9716                free(srsCfg->srs_ResourceToAddModList);
9717             }
9718
9719             free(ulBwp->srs_Config->choice.setup);
9720          }
9721          free(ulBwp->srs_Config);
9722       }
9723    }
9724 }
9725 /*******************************************************************
9726 *
9727 * @brief Function to free initialUplinkBWPConfig where memory allocated by aper_decoder
9728 *
9729 * @details
9730 *
9731 *    Function : freeAperDecodeinitialUplinkBWPConfig
9732 *
9733 *    Functionality: Function to free initialUplinkBWPConfig
9734 *
9735 * @params[in] UplinkConfig_t *ulCfg 
9736 * @return void
9737 *
9738 * ****************************************************************/
9739
9740
9741 void freeAperDecodeinitialUplinkBWPConfig(UplinkConfig_t *ulCfg)
9742 {
9743    BWP_UplinkDedicated_t *ulBwp=NULLP;
9744    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
9745    
9746    if(ulCfg->initialUplinkBWP)
9747    {
9748       ulBwp=ulCfg->initialUplinkBWP;
9749       if(ulCfg->firstActiveUplinkBWP_Id)
9750       {
9751          if(ulCfg->pusch_ServingCellConfig)
9752          {
9753             puschCfg=ulCfg->pusch_ServingCellConfig;
9754             if(puschCfg->choice.setup)
9755             {
9756                if(puschCfg->choice.setup->ext1)
9757                {
9758                   free(puschCfg->choice.setup->ext1->processingType2Enabled);
9759                   free(puschCfg->choice.setup->ext1->maxMIMO_Layers);
9760                   free(puschCfg->choice.setup->ext1);
9761                }
9762                free(puschCfg->choice.setup);
9763             }
9764             free(ulCfg->pusch_ServingCellConfig);
9765          }
9766          free(ulCfg->firstActiveUplinkBWP_Id);
9767       }
9768       freeAperDecodeInitialUlBWPConfig(ulBwp);
9769       free(ulCfg->initialUplinkBWP);
9770    }
9771 }
9772
9773 /*******************************************************************
9774  *
9775  * @brief Function to free DuUeCfg
9776  *
9777  * @details
9778  *
9779  *    Function : freeDuUeCfg
9780  *
9781  *    Functionality: Function to free DuUeCfg
9782  *
9783  * @params[in] DuUeCfg *ueCfg
9784  * @return void
9785  *
9786  * ****************************************************************/
9787 void freeDuUeCfg(UeCtxtActionType actionType, DuUeCfg *ueCfg)
9788 {
9789    uint8_t lcIdx = 0;
9790    uint8_t arrIdx = 0;
9791    SpCellConfig_t *spCellCfg = NULLP;
9792    ServingCellConfig_t *srvCellCfg = NULLP;
9793    BWP_DownlinkDedicated_t *dlBwp = NULLP;
9794    MAC_CellGroupConfig_t *macCellGrpCfg = NULLP;
9795    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
9796    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList = NULLP;
9797    struct RLC_Config *rlcConfig = NULLP;
9798    struct LogicalChannelConfig *macLcConfig = NULLP;
9799    struct SchedulingRequestConfig *schedulingRequestConfig = NULLP;
9800    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList = NULLP;
9801    struct TAG_Config *tagConfig = NULLP;
9802    struct TAG_Config__tag_ToAddModList *tagList = NULLP;
9803    struct MAC_CellGroupConfig__phr_Config *phrConfig = NULLP;
9804    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg = NULLP;
9805    CellGroupConfigRrc_t *cellGrpCfg = ueCfg->cellGrpCfg;
9806   
9807    if(ueCfg->ueNrCapability)
9808    {
9809       freeAperDecodeUeNrCapability(ueCfg->ueNrCapability);
9810       DU_FREE(ueCfg->ueNrCapability, sizeof(UE_NR_Capability_t));
9811       ueCfg->ueNrCapability = NULLP;
9812    }
9813
9814    if(ueCfg->cellGrpCfg)
9815    {
9816       rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
9817       if(rlcBearerList)
9818       {
9819          if(rlcBearerList->list.array)
9820          {
9821             for(arrIdx=0; arrIdx<rlcBearerList->list.count; arrIdx++)
9822             {
9823                if(rlcBearerList->list.array[arrIdx])
9824                {
9825                   rlcConfig   = rlcBearerList->list.array[arrIdx]->rlc_Config;
9826                   macLcConfig = rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig;
9827
9828                   if(rlcBearerList->list.array[arrIdx]->servedRadioBearer)
9829                   {
9830                      free(rlcBearerList->list.array[arrIdx]->servedRadioBearer);
9831                   }
9832                   if(rlcConfig)
9833                   {
9834                      if(rlcConfig->choice.am)
9835                      {
9836                         free(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength);
9837                         free(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength);
9838                         free(rlcConfig->choice.am);
9839                      }
9840                      free(rlcBearerList->list.array[arrIdx]->rlc_Config);
9841                   }
9842                   if(macLcConfig)
9843                   {
9844                      if(macLcConfig->ul_SpecificParameters)
9845                      {
9846                         free(macLcConfig->ul_SpecificParameters->schedulingRequestID);
9847                         free(macLcConfig->ul_SpecificParameters->logicalChannelGroup);
9848                         free(macLcConfig->ul_SpecificParameters);
9849                      }
9850                      free(rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig);
9851                   }
9852                   free(rlcBearerList->list.array[arrIdx]); 
9853                }
9854             }
9855             free(rlcBearerList->list.array);
9856          }
9857          free(cellGrpCfg->rlc_BearerToAddModList);
9858       }
9859
9860       macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
9861       if(macCellGrpCfg)
9862       {
9863          schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig;
9864          if(schedulingRequestConfig)
9865          {
9866             schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
9867             if(schReqList)
9868             {
9869                if(schReqList->list.array)
9870                {
9871                   for(arrIdx=0;arrIdx<schReqList->list.count; arrIdx++)
9872                   {
9873                      if(schReqList->list.array[arrIdx])
9874                      {
9875                         free(schReqList->list.array[arrIdx]->sr_ProhibitTimer); 
9876                         free(schReqList->list.array[arrIdx]);
9877                      }
9878                   }
9879                   free(schReqList->list.array);
9880                }
9881                free(schedulingRequestConfig->schedulingRequestToAddModList);
9882             }
9883             free(macCellGrpCfg->schedulingRequestConfig);
9884          }
9885          if(macCellGrpCfg->bsr_Config)
9886          {
9887             free(macCellGrpCfg->bsr_Config);
9888          }
9889          tagConfig = macCellGrpCfg->tag_Config;
9890          if(tagConfig)
9891          {
9892             tagList = tagConfig->tag_ToAddModList;
9893             if(tagList)
9894             {
9895                if(tagList->list.array)
9896                {
9897                   for(arrIdx=0; arrIdx<tagList->list.count; arrIdx++)
9898                   {
9899                      free(tagList->list.array[arrIdx]);
9900                   }
9901                   free(tagList->list.array);
9902                }
9903                free(tagConfig->tag_ToAddModList);
9904             }
9905             free(tagConfig); 
9906          }
9907
9908          phrConfig = macCellGrpCfg->phr_Config;
9909          if(phrConfig)
9910          {
9911             free(phrConfig->choice.setup); 
9912             free(phrConfig); 
9913          }
9914
9915          free(macCellGrpCfg); 
9916       }
9917
9918       phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
9919       if(phyCellGrpCfg)
9920       {
9921          free(phyCellGrpCfg->p_NR_FR1);
9922          free(phyCellGrpCfg); 
9923       }
9924
9925       spCellCfg = cellGrpCfg->spCellConfig;
9926       if(spCellCfg)
9927       {
9928          if(spCellCfg->servCellIndex)
9929          {
9930             if(spCellCfg->rlmInSyncOutOfSyncThreshold)
9931             {
9932                if(spCellCfg->spCellConfigDedicated)
9933                {
9934                   srvCellCfg = spCellCfg->spCellConfigDedicated;
9935                   if(srvCellCfg->initialDownlinkBWP)
9936                   {
9937                      dlBwp = srvCellCfg->initialDownlinkBWP;
9938                      if(srvCellCfg->firstActiveDownlinkBWP_Id)
9939                      {
9940                         if(srvCellCfg->defaultDownlinkBWP_Id)
9941                         {
9942                            if(srvCellCfg->uplinkConfig)
9943                            {
9944
9945                               if(srvCellCfg->pdsch_ServingCellConfig)
9946                               {
9947                                  pdschCfg=
9948                                     srvCellCfg->pdsch_ServingCellConfig;
9949                                  if(pdschCfg->choice.setup)
9950                                  {
9951
9952                                     free(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH);
9953                                     free(pdschCfg->choice.setup);
9954                                  }
9955
9956                                  free(srvCellCfg->pdsch_ServingCellConfig);
9957                               }
9958
9959                               freeAperDecodeinitialUplinkBWPConfig(srvCellCfg->uplinkConfig);
9960                               free(srvCellCfg->uplinkConfig);
9961                            }
9962                            free(srvCellCfg->defaultDownlinkBWP_Id);
9963                         }
9964
9965                         free(srvCellCfg->firstActiveDownlinkBWP_Id);
9966                      }
9967                      if(dlBwp->pdcch_Config)
9968                      {
9969                         if(dlBwp->pdsch_Config)
9970                         {
9971                            freeAperDecodeBWPDlDedPdschConfig(dlBwp);
9972                            free(dlBwp->pdsch_Config);
9973                         }
9974                         freeAperDecodeBWPDlDedPdcchConfig(dlBwp);
9975                         free(dlBwp->pdcch_Config);
9976                      }
9977                      free(srvCellCfg->initialDownlinkBWP);
9978                   }
9979
9980                   free(spCellCfg->spCellConfigDedicated);
9981                }
9982                free(spCellCfg->rlmInSyncOutOfSyncThreshold);
9983             }
9984             free(spCellCfg->servCellIndex); 
9985          }
9986          free(spCellCfg);
9987       }
9988       DU_FREE(ueCfg->cellGrpCfg, sizeof(CellGroupConfigRrc_t));
9989       ueCfg->cellGrpCfg = NULLP;
9990    }
9991
9992    if(ueCfg->ambrCfg)
9993    {
9994       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCfg->ambrCfg, sizeof(AmbrCfg));
9995    }
9996
9997    if(actionType != UE_CTXT_CFG_QUERY)
9998    {
9999       for(lcIdx = 0; lcIdx < ueCfg->numRlcLcs; lcIdx++)
10000       {
10001          freeRlcLcCfg(&ueCfg->rlcLcCfg[lcIdx].rlcBearerCfg);
10002       }
10003    }
10004
10005    for(lcIdx = 0; lcIdx < ueCfg->numMacLcs; lcIdx++)
10006    {
10007       freeMacLcCfg(&ueCfg->macLcCfg[lcIdx].lcConfig);
10008    }
10009
10010    for(lcIdx = 0; lcIdx < ueCfg->numDrb; lcIdx++)
10011    {
10012       DU_FREE(ueCfg->upTnlInfo[lcIdx].tnlCfg1, sizeof(GtpTnlCfg));
10013    }
10014 }
10015
10016 /*******************************************************************
10017  *
10018  * @brief Function to free UecontextSetupDb
10019  *
10020  * @details
10021  *
10022  *    Function : freeF1UeDb
10023  *
10024  *    Functionality: Function to free UecontextSetupDb
10025  *
10026  * @params[in] UecontextSetupDb *
10027  * @return void
10028  *
10029  * ****************************************************************/
10030
10031 void freeF1UeDb(F1UeContextSetupDb *f1UeDb)
10032 {
10033    
10034    if(f1UeDb->dlRrcMsg)
10035    {
10036       if(f1UeDb->dlRrcMsg->rrcMsgPdu)
10037       {
10038         //DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,\
10039                f1UeDb->dlRrcMsg->rrcMsgPdu, f1UeDb->dlRrcMsg->rrcMsgSize);
10040       }
10041       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
10042    }
10043    freeDuUeCfg(f1UeDb->actionType, &f1UeDb->duUeCfg);
10044    memset(f1UeDb, 0, sizeof(F1UeContextSetupDb));
10045    DU_FREE(f1UeDb, sizeof(F1UeContextSetupDb));
10046 }
10047
10048 /*******************************************************************
10049  *
10050  * @brief Function to build Am cfg Info
10051  *
10052  * @details
10053  *
10054  *    Function : extractRlcAmCfg
10055  *
10056  *    Functionality: Function to build Am cfg Info
10057  *
10058  * @params[in] AmBearerCfg *
10059  *             void *
10060  *
10061  * @return ROK/RFAILED
10062  *
10063  * ****************************************************************/
10064
10065 void extractRlcAmCfg(AmBearerCfg *amCfgToSet, struct RLC_Config__am *rlcAmCfg)
10066 {
10067    if(rlcAmCfg)
10068    {
10069       /* UL AM */
10070       if(rlcAmCfg->dl_AM_RLC.sn_FieldLength)
10071       {
10072          amCfgToSet->ulAmCfg.snLenUl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->dl_AM_RLC.sn_FieldLength));
10073          /*TODO: Check the timer value when sent by real CU */
10074          amCfgToSet->ulAmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_Reassembly); 
10075          amCfgToSet->ulAmCfg.statProhTmr = convertProhibitTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_StatusProhibit);
10076       }
10077
10078       /* DL AM */
10079       if(rlcAmCfg->ul_AM_RLC.sn_FieldLength)
10080       {
10081          amCfgToSet->dlAmCfg.snLenDl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->ul_AM_RLC.sn_FieldLength));
10082          amCfgToSet->dlAmCfg.pollRetxTmr = covertPollRetxTmrEnumToValue(rlcAmCfg->ul_AM_RLC.t_PollRetransmit);
10083          amCfgToSet->dlAmCfg.pollPdu   = covertPollPduEnumToValue(rlcAmCfg->ul_AM_RLC.pollPDU);
10084          amCfgToSet->dlAmCfg.pollByte  = covertPollByteEnumToValue(rlcAmCfg->ul_AM_RLC.pollByte);
10085          amCfgToSet->dlAmCfg.maxRetxTh = covertMaxRetxEnumToValue(rlcAmCfg->ul_AM_RLC.maxRetxThreshold);
10086       }
10087    }
10088 }
10089
10090 /*******************************************************************
10091  *
10092  * @brief Function to build Um Bi Info
10093  *
10094  * @details
10095  *
10096  *    Function : extractRlcUmBiCfg
10097  *
10098  *    Functionality: Function to build Um Bi Info
10099  *
10100  * @params[in] UmBiDirBearerCfg *
10101  *             void *
10102  *
10103  * @return ROK/RFAILED
10104  *
10105  * ****************************************************************/
10106
10107 void extractRlcUmBiCfg(UmBiDirBearerCfg *umBiCfgToSet, struct RLC_Config__um_Bi_Directional *rlcBiCfg)
10108 {
10109    if(rlcBiCfg)
10110    {
10111       /* UL UM BI DIR Cfg */
10112       if(rlcBiCfg->dl_UM_RLC.sn_FieldLength)
10113       {
10114          umBiCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->dl_UM_RLC.sn_FieldLength));
10115          umBiCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcBiCfg->dl_UM_RLC.t_Reassembly);
10116       }
10117
10118       /* DL UM BI DIR Cfg */
10119       if(rlcBiCfg->ul_UM_RLC.sn_FieldLength)
10120          umBiCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->ul_UM_RLC.sn_FieldLength));
10121    }
10122 }
10123
10124 /*******************************************************************
10125  *
10126  * @brief Function to build Um Ul Info
10127  *
10128  * @details
10129  *
10130  *    Function : extractRlcUmUlCfg
10131  *
10132  *    Functionality: Function to build Um Ul Info
10133  *
10134  * @params[in] UmUniDirUlBearerCfg *
10135  *             void *
10136  *
10137  * @return ROK/RFAILED
10138  *
10139  * ****************************************************************/
10140
10141 void extractRlcUmUlCfg(UmUniDirUlBearerCfg *umUlCfgToSet, struct RLC_Config__um_Uni_Directional_DL *umUlCfg)
10142 {
10143    if(umUlCfg)
10144    {
10145       if(umUlCfg->dl_UM_RLC.sn_FieldLength)
10146       {
10147          umUlCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umUlCfg->dl_UM_RLC.sn_FieldLength));
10148          umUlCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(umUlCfg->dl_UM_RLC.t_Reassembly);
10149       }
10150    }
10151 }
10152
10153 /*******************************************************************
10154  *
10155  * @brief Function to build Um Uni Dl Info
10156  *
10157  * @details
10158  *
10159  *    Function : extractRlcUmDlCfg
10160  *
10161  *    Functionality: Function to build Um Uni Dl Info
10162  *
10163  * @params[in] UmUniDirDlBearerCfg *
10164  *             void *
10165  *
10166  * @return ROK/RFAILED
10167  *
10168  * ****************************************************************/
10169 void extractRlcUmDlCfg(UmUniDirDlBearerCfg *umDlCfgToSet, struct RLC_Config__um_Uni_Directional_UL *umDlCfg)
10170 {
10171    if(umDlCfg)
10172    {
10173       if(umDlCfg->ul_UM_RLC.sn_FieldLength)
10174          umDlCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umDlCfg->ul_UM_RLC.sn_FieldLength));
10175    }
10176 }
10177
10178 /*******************************************************************
10179  *
10180  * @brief Function to extractRlcModeCfg
10181  *
10182  * @details
10183  *
10184  *    Function : extractRlcModeCfg
10185  *
10186  *    Functionality: Function to extractRlcModeCfg
10187  *
10188  * @params[in] RLC_Config_t *
10189  *             RlcBearerCfg *
10190  *             void  *    
10191  * @return ROK/RFAILED
10192  *
10193  * ****************************************************************/
10194 void extractRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *rlcDbCfg, RLC_Config_t *lcCfg)
10195 {
10196    if(lcCfg)
10197    {
10198       switch(rlcMode)
10199       {
10200          case RLC_AM :
10201             {
10202                if(lcCfg->choice.am)
10203                {
10204                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.amCfg, sizeof(AmBearerCfg));
10205                   if(rlcDbCfg->u.amCfg)
10206                      extractRlcAmCfg(rlcDbCfg->u.amCfg, lcCfg->choice.am);
10207                }
10208                break;
10209             }
10210          case RLC_UM_BI_DIRECTIONAL :
10211             {
10212                if(lcCfg->choice.um_Bi_Directional)
10213                {
10214                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
10215                   if(rlcDbCfg->u.umBiDirCfg)
10216                      extractRlcUmBiCfg(rlcDbCfg->u.umBiDirCfg, lcCfg->choice.um_Bi_Directional);
10217                }
10218                break;
10219             }
10220          case RLC_UM_UNI_DIRECTIONAL_UL :
10221             {
10222                if(lcCfg->choice.um_Uni_Directional_DL)
10223                {
10224                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
10225                   if(rlcDbCfg->u.umUniDirUlCfg)
10226                      extractRlcUmUlCfg(rlcDbCfg->u.umUniDirUlCfg, lcCfg->choice.um_Uni_Directional_DL);
10227                }
10228                break;
10229             }
10230          case RLC_UM_UNI_DIRECTIONAL_DL :
10231             {
10232                if(lcCfg->choice.um_Uni_Directional_UL)
10233                {
10234                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
10235                   if(rlcDbCfg->u.umUniDirDlCfg)
10236                      extractRlcUmDlCfg(rlcDbCfg->u.umUniDirDlCfg, lcCfg->choice.um_Uni_Directional_UL);
10237                }
10238                break;
10239             }
10240          default:
10241             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
10242             break;
10243       }
10244    }
10245 }
10246
10247 /*******************************************************************
10248  *
10249  * @brief Function to extract extractUlLcCfg
10250  *
10251  * @details
10252  *
10253  *    Function : extractUlLcCfg
10254  *
10255  *    Functionality: Function to extract extractUlLcCfg
10256  *
10257  * @params[in] UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg
10258  * @return void
10259  *
10260  * ****************************************************************/
10261
10262 void extractUlLcCfg(UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg)
10263 {
10264    if(ulLcCfg)
10265    {
10266       if(ulLcCfg->ul_SpecificParameters)
10267       {
10268          f1UlLcCfg->priority = \
10269             ulLcCfg->ul_SpecificParameters->priority;
10270       if(ulLcCfg->ul_SpecificParameters->logicalChannelGroup)
10271       {
10272          f1UlLcCfg->lcGroup = \
10273            *(ulLcCfg->ul_SpecificParameters->logicalChannelGroup);
10274       }
10275       if(ulLcCfg->ul_SpecificParameters->schedulingRequestID)
10276       {
10277          f1UlLcCfg->schReqId = \
10278            *(ulLcCfg->ul_SpecificParameters->schedulingRequestID);
10279       }
10280       f1UlLcCfg->pbr = \
10281          ulLcCfg->ul_SpecificParameters->prioritisedBitRate;
10282       f1UlLcCfg->bsd = \
10283          ulLcCfg->ul_SpecificParameters->bucketSizeDuration;
10284       }
10285    }
10286 }
10287
10288 /*******************************************************************
10289 *
10290 * @brief Function to extract Snssai Cfg Info from CU
10291 *
10292 * @details
10293 *
10294 *    Function : extractDrbSnssaiCfg
10295 *
10296 *    Functionality: Function to extract Drb Snssai Cfg Info from CU
10297 *
10298 * @params[in] DRB_Information_t *drbInfo, Snssai  *snssai
10299 * @return ROK/RFAILED
10300 *
10301 * ****************************************************************/
10302
10303 uint8_t extractDrbSnssaiCfg(SNSSAI_t *RecvSnssai, Snssai **snssaiToBeShared)
10304 {
10305    if(!(*snssaiToBeShared))
10306    {
10307       DU_ALLOC_SHRABL_BUF((*snssaiToBeShared), sizeof(Snssai));
10308       if(snssaiToBeShared == NULLP)
10309       {
10310          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Memory failed at allocating for SNSSAI ");
10311          return RFAILED;
10312       }
10313    }
10314    if(RecvSnssai)
10315    {
10316       memcpy(&(*snssaiToBeShared)->sst, RecvSnssai->sST.buf, RecvSnssai->sST.size);
10317       if(RecvSnssai->sD)
10318       {
10319          memcpy((*snssaiToBeShared)->sd, RecvSnssai->sD->buf,  RecvSnssai->sD->size);
10320       }
10321       else
10322       {
10323          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Received Null pointer of Snssai->SD");
10324          return RFAILED;
10325       }
10326    }
10327    return ROK;
10328 }
10329
10330 /*******************************************************************
10331  *
10332  * @brief Function to procRlcLcCfg
10333  *
10334  * @details
10335  *
10336  *    Function : procRlcLcCfg
10337  *
10338  *    Functionality: Function to procRlcLcCfg
10339  *
10340  * @params[in] rbId, lcId, rbType, rlcMod
10341  *             RLC_Config_t *, RlcBearerCfg * , 
10342  * @return void
10343  *
10344  * ****************************************************************/
10345
10346 void procRlcLcCfg(uint8_t rbId, uint8_t lcId, uint8_t rbType, uint8_t rlcMode,\
10347    uint8_t configType, RLC_Config_t *f1RlcCfg, DuRlcBearerCfg *lcCfg, QoSInformation_t *qoSInformation)
10348 {
10349    DRB_Information_t *drbInfo;
10350
10351    lcCfg->rlcBearerCfg.rbId   = rbId;
10352    lcCfg->configType = configType;
10353
10354    if(rbType == RB_TYPE_SRB)
10355    {
10356       lcCfg->rlcBearerCfg.rbType = RB_TYPE_SRB;
10357       lcCfg->rlcBearerCfg.lcId   = rbId;
10358       lcCfg->rlcBearerCfg.lcType = LCH_DCCH;
10359       lcCfg->rlcBearerCfg.rlcMode = RLC_AM;
10360    }
10361    else if(rbType == RB_TYPE_DRB)
10362    {
10363       lcCfg->rlcBearerCfg.rbType = RB_TYPE_DRB;
10364       lcCfg->rlcBearerCfg.lcId   = lcId;
10365       lcCfg->rlcBearerCfg.lcType = LCH_DTCH;
10366       lcCfg->rlcBearerCfg.rlcMode = rlcMode;
10367    }
10368    if(f1RlcCfg) /* rlc mode config recived */
10369    {
10370       extractRlcModeCfg(lcCfg->rlcBearerCfg.rlcMode, &lcCfg->rlcBearerCfg, f1RlcCfg);
10371    }
10372    if(qoSInformation != NULLP)
10373    {
10374       if(qoSInformation->present == QoSInformation_PR_choice_extension)
10375       {
10376          if(qoSInformation->choice.choice_extension->value.present ==\
10377                QoSInformation_ExtIEs__value_PR_DRB_Information)
10378          {
10379             drbInfo = &qoSInformation->choice.choice_extension->value.choice.DRB_Information; 
10380             if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &lcCfg->rlcBearerCfg.snssai) != ROK)
10381             {
10382                DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information at procRlcLcCfg()");
10383                return;
10384             }
10385          }
10386       }
10387    }
10388 }
10389
10390 /*******************************************************************
10391  *
10392  * @brief Fills DrbQos Info received by CU
10393  *
10394  * @details
10395  *
10396  *    Function : extractQosInfo
10397  *
10398  *    Functionality: Fills DrbQos Info received  by CU
10399  *
10400  * @params[in] DrbQosInfo *qosToAdd, 
10401  *             QoSFlowLevelQoSParameters_t *qosFlowCfg
10402  * @return void
10403  *
10404  * ****************************************************************/
10405
10406 void extractQosInfo(DrbQosInfo *qosToAdd, QoSFlowLevelQoSParameters_t *qosFlowCfg)
10407 {
10408    uint8_t qosCntIdx = 0;
10409    ProtocolExtensionContainer_4624P74_t *qosIeExt = NULLP;
10410
10411    qosToAdd->fiveQiType = qosFlowCfg->qoS_Characteristics.present;
10412    qosToAdd->u.nonDyn5Qi.fiveQi     =\
10413                                      qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->fiveQI;
10414    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow)
10415    {
10416       qosToAdd->u.nonDyn5Qi.avgWindow = \
10417                                         *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
10418    }
10419
10420    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume)
10421    {
10422       qosToAdd->u.nonDyn5Qi.maxDataBurstVol = \
10423                                               *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
10424    }
10425
10426    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel)
10427    {
10428       qosToAdd->u.nonDyn5Qi.priorLevel = \
10429                                          *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel);
10430    }
10431    qosToAdd->ngRanRetPri.priorityLevel = \
10432                                          qosFlowCfg->nGRANallocationRetentionPriority.priorityLevel; 
10433    qosToAdd->ngRanRetPri.preEmptionCap = \
10434                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionCapability;
10435    qosToAdd->ngRanRetPri.preEmptionVul = \
10436                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionVulnerability;
10437    if(qosFlowCfg->gBR_QoS_Flow_Information)
10438    {
10439       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateDl, \
10440             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.buf, \
10441             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.size);
10442       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateUl, \
10443             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.buf, \
10444             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.size);
10445       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateDl,\
10446             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.buf, \
10447             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.size);
10448       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateUl,\
10449             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.buf, \
10450             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.size);
10451    }
10452    /*Extracting PDU_SESSION_ID*/
10453    qosIeExt = (ProtocolExtensionContainer_4624P74_t *)qosFlowCfg->iE_Extensions;
10454    if(qosIeExt)
10455    {
10456       for(qosCntIdx = 0; qosCntIdx < qosIeExt->list.count; qosCntIdx++)
10457       {
10458          if(qosIeExt->list.array[qosCntIdx]->extensionValue.present == \
10459                QoSFlowLevelQoSParameters_ExtIEs__extensionValue_PR_PDUSessionID)
10460          {
10461             qosToAdd->pduSessionId = qosIeExt->list.array[qosCntIdx]->extensionValue.choice.PDUSessionID;
10462             DU_LOG("\nDEBUG -->  DU_F1AP : extractQosInfo: PDU SessionID:%d",qosToAdd->pduSessionId);
10463          }
10464       }  
10465    }
10466    qosToAdd->ulPduSessAggMaxBitRate = 0;
10467 }
10468
10469 /*******************************************************************
10470  *
10471  * @brief Function to extract GTP Tunnel Info from CU
10472  *
10473  * @details
10474  *
10475  *    Function : extractUpTnlInfo
10476  *
10477  *    Functionality: Function to extract GTP Tunnel Info from CU
10478  *
10479  * @params[in] F1AP message
10480  * @return ROK/RFAILED
10481  *
10482  * ****************************************************************/
10483
10484 uint8_t extractUpTnlInfo(uint8_t drbId, uint8_t configType,\
10485    ULUPTNLInformation_ToBeSetup_List_t *tnlInfo, UpTnlCfg *upTnlInfo)
10486 {
10487    uint8_t tnlIdx;
10488    uint32_t ipv4_du = 0;
10489    GTPTunnel_t *gtpTunnel = NULLP;
10490
10491    upTnlInfo->drbId = drbId; 
10492    upTnlInfo->configType = configType;
10493 #ifdef O1_ENABLE
10494    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
10495 #else
10496    cmInetAddr((char *)DU_IP_V4_ADDR, &ipv4_du);
10497 #endif
10498
10499    for(tnlIdx=0; tnlIdx < tnlInfo->list.count; tnlIdx++)
10500    {
10501       if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.present == UPTransportLayerInformation_PR_gTPTunnel)
10502       {
10503          if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel)
10504          {
10505             gtpTunnel = tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel;
10506             DU_ALLOC(upTnlInfo->tnlCfg1, sizeof(GtpTnlCfg));
10507             if(upTnlInfo->tnlCfg1 == NULLP)
10508             {
10509                DU_LOG("\nERROR  -->  F1AP : extractUpTnlInfo: Failed to allocate mmeory for tunnel cfg 1");
10510                return RFAILED;
10511             }
10512             bitStringToInt(&gtpTunnel->transportLayerAddress, &upTnlInfo->tnlCfg1->ulTnlAddress);
10513             upTnlInfo->tnlCfg1->dlTnlAddress = ipv4_du;
10514             if(gtpTunnel->gTP_TEID.size > 0)
10515             {
10516                teIdStringToInt(gtpTunnel->gTP_TEID.buf, &upTnlInfo->tnlCfg1->teId);
10517             }
10518          }
10519          break;
10520       }
10521    }
10522    return ROK;
10523 }
10524
10525 /*******************************************************************
10526 *
10527 * @brief Function to extract Drb Qos Cfg Info from CU
10528 *
10529 * @details
10530 *
10531 *    Function : extractDrbQosCfg 
10532 *
10533 *    Functionality: Function to extract Drb Qos Cfg Info from CU
10534 *
10535 * @params[in] DRB_Information_t *drbInfo, LcCfg *macLcToAdd
10536 * @return ROK/RFAILED
10537 *
10538 * ****************************************************************/
10539
10540 uint8_t extractDrbQosCfg(DRB_Information_t *drbInfo, LcCfg *macLcToAdd ) 
10541 {
10542    if(!macLcToAdd->drbQos)
10543    {
10544       DU_ALLOC_SHRABL_BUF(macLcToAdd->drbQos, sizeof(DrbQosInfo));
10545       if(macLcToAdd->drbQos == NULLP)
10546       {
10547          DU_LOG("\nERROR  -->  DUAPP:Memory failed at allocating DrbQos at extractDrbQosCfg()");
10548          return RFAILED;
10549       }
10550
10551    }
10552    if(drbInfo->dRB_QoS.qoS_Characteristics.present == QoS_Characteristics_PR_non_Dynamic_5QI)
10553    {
10554       extractQosInfo(macLcToAdd->drbQos, &drbInfo->dRB_QoS);
10555       macLcToAdd->dlLcCfg.lcp = macLcToAdd->drbQos->ngRanRetPri.priorityLevel;
10556    }
10557    if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &macLcToAdd->snssai) != ROK)
10558    {
10559       DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information  at extractDrbQosCfg()");
10560       return RFAILED;
10561    }
10562    return ROK;
10563 }
10564 /*******************************************************************
10565  *
10566  * @brief Function to extract DRB info received from CU
10567  *
10568  * @details
10569  *
10570  *    Function : extractDrbCfg
10571  *
10572  *    Functionality: Function to extract DRB info received from CU
10573  *
10574  * @params[in] F1AP message
10575  * @return void
10576  *
10577  * ****************************************************************/
10578 uint8_t extractDrbCfg(DRBs_ToBeSetup_Item_t *drbItem, DRBs_ToBeSetupMod_Item_t *drbSetupModItem,\
10579 DRBs_ToBeModified_Item_t *drbModItem,  DuLcCfg *lcCfgToAdd, UpTnlCfg *upTnlInfo)
10580 {
10581    DRB_Information_t *drbInfo = NULLP;
10582
10583    if(drbItem != NULLP)
10584    {
10585       if(extractUpTnlInfo(drbItem->dRBID, CONFIG_ADD, &drbItem->uLUPTNLInformation_ToBeSetup_List, upTnlInfo) != ROK)
10586       {
10587          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10588          return RFAILED;
10589       }
10590       if(drbItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10591       {
10592          if(drbItem->qoSInformation.choice.choice_extension->value.present == QoSInformation_ExtIEs__value_PR_DRB_Information)
10593          {
10594             drbInfo = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10595             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10596             {
10597                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");
10598                return RFAILED;
10599             }
10600          }
10601       }
10602    }
10603    else if(drbSetupModItem != NULLP)
10604    {
10605       if(extractUpTnlInfo(drbSetupModItem->dRBID, CONFIG_ADD, &drbSetupModItem->uLUPTNLInformation_ToBeSetup_List,\
10606       upTnlInfo) != ROK)
10607       {
10608          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10609          return RFAILED;
10610       }
10611       if(drbSetupModItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10612       {
10613          if(drbSetupModItem->qoSInformation.choice.choice_extension->value.present ==\
10614          QoSInformation_ExtIEs__value_PR_DRB_Information)
10615          {
10616             drbInfo = &drbSetupModItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10617             if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10618             {
10619                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10620                return RFAILED;
10621             }
10622
10623          }
10624       }
10625    }
10626    else if(drbModItem != NULLP)
10627    {
10628       if(extractUpTnlInfo(drbModItem->dRBID, CONFIG_MOD, &drbModItem->uLUPTNLInformation_ToBeSetup_List,\
10629       upTnlInfo) != ROK)
10630       {
10631          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10632          return RFAILED;
10633       }
10634       if(drbModItem->qoSInformation != NULLP)
10635       {
10636          if(drbModItem->qoSInformation->present == QoSInformation_PR_choice_extension)
10637          {
10638             if(drbModItem->qoSInformation->choice.choice_extension->value.present ==\
10639                   QoSInformation_ExtIEs__value_PR_DRB_Information)
10640             {
10641                drbInfo = &drbModItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information;
10642                if(extractDrbQosCfg(drbInfo , &lcCfgToAdd->lcConfig) != ROK)
10643                {
10644                   DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10645                   return RFAILED;
10646                }
10647
10648             }
10649          }
10650       }
10651    }
10652    return ROK;
10653 }
10654
10655 /*******************************************************************
10656  *
10657  * @brief Function to extract RB info received from CU
10658  *
10659  * @details
10660  *
10661  *    Function : extractMacRbCfg
10662  *
10663  *    Functionality: Function to extract RB info received from CU
10664  *
10665  * @params[in] F1AP message
10666  * @return ROK/RFAILED
10667  *
10668  * ****************************************************************/
10669
10670 uint8_t extractMacRbCfg(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbCfg,\
10671 DRBs_ToBeSetupMod_Item_t *drbSetupModCfg,  DRBs_ToBeModified_Item_t *drbModCfg, LogicalChannelConfig_t *ulLcCfg, DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10672 {
10673    if(drbCfg != NULLP)
10674    {
10675       if(extractDrbCfg(drbCfg, NULL, NULL, lcCfg, upTnlInfo) != ROK)
10676       {
10677          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10678          return RFAILED;
10679       }
10680    }
10681    else if(drbSetupModCfg != NULLP)
10682    { 
10683       if(extractDrbCfg(NULL, drbSetupModCfg, NULL, lcCfg, upTnlInfo) != ROK)
10684       {
10685          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10686          return RFAILED;
10687       }
10688    }
10689    else if(drbModCfg != NULLP)
10690    { 
10691       if(extractDrbCfg(NULL, NULL, drbModCfg, lcCfg, upTnlInfo) != ROK)
10692       {
10693          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10694          return RFAILED;
10695       }
10696    }
10697    else
10698    {
10699       lcCfg->lcConfig.drbQos = NULLP;
10700       lcCfg->lcConfig.snssai = NULLP;
10701       if(lcCfg->lcConfig.lcId == SRB2_LCID)
10702          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_3;
10703       else
10704          lcCfg->lcConfig.dlLcCfg.lcp = LC_PRIORITY_1;
10705
10706    }
10707    if(ulLcCfg)
10708    {
10709       lcCfg->lcConfig.ulLcCfgPres = true;
10710       extractUlLcCfg(&lcCfg->lcConfig.ulLcCfg, ulLcCfg);
10711    }
10712    else
10713       lcCfg->lcConfig.ulLcCfgPres = false;
10714    return ROK;
10715 }
10716
10717 /*******************************************************************
10718  *
10719  * @brief Function processing LC config info received from CU
10720  *
10721  * @details
10722  *
10723  *    Function : procMacLcCfg
10724  *
10725  *    Functionality: Function processing LC config info received from CU
10726  *
10727  * @params[in] F1AP message
10728  * @return ROK/RFAILED
10729  *
10730  * ****************************************************************/
10731
10732 uint8_t procMacLcCfg(uint8_t lcId, uint8_t rbType, uint8_t configType, DRBs_ToBeSetup_Item_t *drbItem,\
10733 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LogicalChannelConfig_t *ulLcCfg,\
10734 DuLcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10735 {
10736    uint8_t ret = ROK;
10737
10738    lcCfg->lcConfig.lcId = lcId;
10739    lcCfg->configType = configType;
10740    if(rbType == RB_TYPE_SRB)
10741    {
10742       ret = extractMacRbCfg(lcId, NULL, NULL, NULL, ulLcCfg, lcCfg, NULL);
10743    }
10744    else if(rbType == RB_TYPE_DRB && upTnlInfo != NULLP)
10745    {
10746       if(drbItem != NULL)
10747         ret = extractMacRbCfg(lcId, drbItem, NULL, NULL, ulLcCfg, lcCfg, upTnlInfo);
10748       else if(drbSetupModItem != NULL)
10749         ret = extractMacRbCfg(lcId, NULL, drbSetupModItem, NULL, ulLcCfg, lcCfg, upTnlInfo);
10750       else if(drbModItem != NULL)
10751         ret = extractMacRbCfg(lcId, NULL, NULL, drbModItem, ulLcCfg, lcCfg, upTnlInfo);
10752    }
10753    return ret;
10754 }
10755
10756 /*******************************************************************
10757  *
10758  * @brief Function to extract Rlc cfg To Add/Mod in CellGrp Info
10759  *
10760  * @details
10761  *
10762  *    Function : extractRlcCfgToAddMod
10763  *
10764  *    Functionality: Function to extract Rlc cfg To Add/Mod in CellGrp Info
10765  *
10766  * @params[in] CellGroupConfigRrc__rlc_BearerTo pointer
10767  *             DuUeCfg Pointer
10768  * @return ROK/RFAILED
10769  *
10770  * ****************************************************************/
10771
10772 uint8_t extractRlcCfgToAddMod(struct CellGroupConfigRrc__rlc_BearerToAddModList *lcCfg, DuUeCfg *ueCfgDb)
10773 {
10774   uint8_t idx, rbId, lcId, rlcMode, rbType;
10775   RLC_Config_t *f1RlcCfg = NULLP;
10776   LogicalChannelConfig_t *macUlLcCfg = NULLP;
10777
10778   for(idx = 0; idx < lcCfg->list.count; idx++)
10779   {
10780      lcId = lcCfg->list.array[idx]->logicalChannelIdentity;
10781      if(lcCfg->list.array[idx]->servedRadioBearer)
10782      {
10783         /* RadioBearer for SRB/DRB */
10784         if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10785         RLC_BearerConfig__servedRadioBearer_PR_srb_Identity)
10786         {
10787            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.srb_Identity;
10788            rbType = RB_TYPE_SRB;
10789         }
10790         else if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10791         RLC_BearerConfig__servedRadioBearer_PR_drb_Identity)
10792         {
10793            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.drb_Identity;
10794            rbType = RB_TYPE_DRB;
10795         }
10796         else
10797         {
10798            DU_LOG("\nERROR  -->  No components present in Bearer config to ADD/MOD");
10799            return RFAILED;
10800         }
10801         /* MAC UL LC Config */
10802         if(lcCfg->list.array[idx]->mac_LogicalChannelConfig)
10803         {
10804            macUlLcCfg = lcCfg->list.array[idx]->mac_LogicalChannelConfig;
10805         }
10806      }
10807      else
10808      {
10809         DU_LOG("\nERROR  -->  DUAPP: Received RadioBearer config is NULL");
10810         return RFAILED;
10811      }
10812      /* RLC Mode Config */
10813      if(lcCfg->list.array[idx]->rlc_Config)
10814      {
10815         rlcMode  = lcCfg->list.array[idx]->rlc_Config->present;
10816         f1RlcCfg = lcCfg->list.array[idx]->rlc_Config;
10817      }
10818      
10819      /* Filling RLC/MAC Config*/
10820      memset(&ueCfgDb->macLcCfg[idx], 0, sizeof(DuLcCfg));
10821      memset(&ueCfgDb->rlcLcCfg[idx], 0, sizeof(DuRlcBearerCfg));
10822      procRlcLcCfg(rbId, lcId, rbType, rlcMode, CONFIG_UNKNOWN, f1RlcCfg, &(ueCfgDb->rlcLcCfg[idx]), NULLP);
10823      if(procMacLcCfg(lcId, rbType, CONFIG_UNKNOWN, NULL, NULL, NULL, macUlLcCfg, &ueCfgDb->macLcCfg[idx], NULL) != ROK)
10824      {
10825         DU_LOG("\nERROR  -->  DU APP : Failed while filling MAC LC config at extractRlcCfgToAddMod()");
10826         return RFAILED;
10827      }
10828      (ueCfgDb->numRlcLcs)++;
10829      (ueCfgDb->numMacLcs)++;
10830      DU_LOG("\nDEBUG  -> DUAPP: extractRlcCfgToAddMod:RBType:%d, DrbID: %d,lcId:%d, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
10831         rbType, rbId, lcId, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
10832   }
10833   //TODO: To send the failure cause in UeContextSetupRsp 
10834   return ROK;
10835 }
10836
10837 /*******************************************************************
10838  *
10839  * @brief DeAlloc pdsch serv cell config info
10840  *
10841  * @details
10842  *
10843  *    Function : freeMacPdschServCellInfo
10844  *
10845  *    Functionality: DeAlloc pdsch serv cell config info
10846  *
10847  * @params[in] PdschServCellCfg pointer
10848  * @return void
10849  *
10850  * ****************************************************************/
10851
10852 void freeMacPdschServCellInfo(PdschServCellCfg *pdsch)
10853 {
10854    if(pdsch->xOverhead)
10855    {
10856       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->xOverhead, sizeof(PdschXOverhead));
10857    }
10858    if(pdsch->codeBlkGrpFlushInd)
10859    {
10860       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->codeBlkGrpFlushInd, sizeof(bool));
10861    }
10862    if(pdsch->maxCodeBlkGrpPerTb)
10863    {
10864       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10865    }
10866    if(pdsch->maxMimoLayers)
10867    {
10868       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxMimoLayers, sizeof(uint8_t));
10869    }
10870 }
10871
10872 /*******************************************************************
10873  *
10874  * @brief Free Serving cell Info
10875  *
10876  * @details
10877  *
10878  *    Function : freeMacServingCellInfo
10879  *
10880  *    Functionality: Free Serving cell Info
10881  *
10882  * @params[in] ServCellCfgInfo *srvCellCfg
10883  * @return void
10884  *
10885  * ****************************************************************/
10886 void freeMacServingCellInfo(ServCellRecfgInfo *srvCellCfg)
10887 {
10888    uint8_t timeDomRsrcIdx;
10889
10890    if(srvCellCfg->initDlBwp.pdschPresent)
10891    {
10892       for(timeDomRsrcIdx = 0; timeDomRsrcIdx < srvCellCfg->initDlBwp.pdschCfg.numTimeDomRsrcAlloc; timeDomRsrcIdx++)
10893       {
10894          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, \
10895             srvCellCfg->initDlBwp.pdschCfg.timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
10896       }
10897    }
10898
10899    freeMacPdschServCellInfo(&srvCellCfg->pdschServCellCfg);
10900    if(srvCellCfg->bwpInactivityTmr)
10901    {
10902       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
10903    }
10904
10905    if(srvCellCfg->initUlBwp.pucchPresent)
10906    {
10907       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->initUlBwp.pucchCfg.dlDataToUlAck, sizeof(PucchDlDataToUlAck));
10908    }
10909 }
10910
10911 /*******************************************************************
10912  *
10913  * @brief Free cell Grp Cfg Info
10914  *
10915  * @details
10916  *
10917  *    Function : freeUeRecfgCellGrpInfo
10918  *
10919  *    Functionality: Free cell Grp Cfg Info
10920  *
10921  * @params[in] DuMacUeCfg*  duUeCfg
10922  * @return void
10923  *
10924  * ****************************************************************/
10925
10926 void freeUeRecfgCellGrpInfo(DuMacUeCfg *macUeCfg)
10927 {
10928    freeMacServingCellInfo(&macUeCfg->spCellCfg.servCellCfg);
10929 }
10930
10931 /*******************************************************************
10932  *
10933  * @brief Fills Reconfig SchReqReConfig
10934  *
10935  * @details
10936  *
10937  *    Function : extractSchReqReConfig
10938  *
10939  *    Functionality: Fills Reconfig SchReqReConfig
10940  *
10941  * @params[in] SchedulingRequestConfig_t *cuSchedReq
10942  *             SchedReqCfg*  macSchedReq
10943  * @return void
10944  *
10945  * ****************************************************************/
10946 void extractSchReqReConfig(SchedulingRequestConfig_t *cuSchedReq, SchedReqCfg *macSchedReq)
10947 {
10948    uint8_t schReqIdx = 0;
10949    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqListToAdd = NULLP;
10950    struct SchedulingRequestConfig__schedulingRequestToReleaseList *schReqListToRel = NULLP;
10951
10952    if(cuSchedReq->schedulingRequestToAddModList)
10953    {
10954       schReqListToAdd = cuSchedReq->schedulingRequestToAddModList;
10955       if(schReqListToAdd->list.count)
10956       {
10957          macSchedReq->addModListCount = schReqListToAdd->list.count;
10958          for(schReqIdx = 0; schReqIdx < schReqListToAdd->list.count; schReqIdx++)
10959          {
10960             macSchedReq->addModList[schReqIdx].schedReqId = \
10961                schReqListToAdd->list.array[schReqIdx]->schedulingRequestId;
10962             macSchedReq->addModList[schReqIdx].srProhibitTmr = \
10963                *(schReqListToAdd->list.array[schReqIdx]->sr_ProhibitTimer);
10964             macSchedReq->addModList[schReqIdx].srTransMax    =\
10965                schReqListToAdd->list.array[schReqIdx]->sr_TransMax;
10966          }
10967       }
10968    }
10969    /* Scheduling Req To release */
10970    if(cuSchedReq->schedulingRequestToReleaseList)
10971    {
10972       schReqListToRel = cuSchedReq->schedulingRequestToReleaseList;
10973       if(schReqListToRel->list.count)
10974       {
10975          macSchedReq->relListCount = schReqListToRel->list.count;
10976          for(schReqIdx = 0; schReqIdx < schReqListToRel->list.count; schReqIdx++)
10977          {
10978             macSchedReq->relList[schReqIdx] = \
10979                *schReqListToRel->list.array[schReqIdx];
10980          }
10981       }
10982    }
10983 }
10984
10985 /*******************************************************************
10986  *
10987  * @brief Fills TagReconfig
10988  *
10989  * @details
10990  *
10991  *    Function : extractTagReconfig
10992  *
10993  *    Functionality: Fills extractTagReconfig
10994  *
10995  * @params[in] TAG_Config_t *cuTagCfg
10996  *             TagCfg *macTagCfg
10997  * @return void
10998  *
10999  * ****************************************************************/
11000
11001 void extractTagReconfig(TAG_Config_t *cuTagCfg, TagCfg *macTagCfg)
11002 {
11003   uint8_t tagIdx = 0;
11004   struct TAG_Config__tag_ToAddModList  *tagListToAddMod = NULLP;
11005   struct TAG_Config__tag_ToReleaseList *tagListToRel = NULLP;
11006
11007   /* Tag config to AddMod */
11008   if(cuTagCfg->tag_ToAddModList)
11009   {
11010      tagListToAddMod = cuTagCfg->tag_ToAddModList; 
11011      if(tagListToAddMod->list.count)
11012      {
11013         macTagCfg->addModListCount = tagListToAddMod->list.count;
11014         for(tagIdx = 0; tagIdx < tagListToAddMod->list.count; tagIdx++)
11015         {
11016            macTagCfg->addModList[tagIdx].tagId =\
11017               tagListToAddMod->list.array[tagIdx]->tag_Id;     
11018            macTagCfg->addModList[tagIdx].timeAlignTimer = \
11019
11020               tagListToAddMod->list.array[tagIdx]->timeAlignmentTimer;
11021         }
11022      }
11023   }
11024   /* Tag config to release */
11025   if(cuTagCfg->tag_ToReleaseList)
11026   {
11027      tagListToRel = cuTagCfg->tag_ToReleaseList;
11028      if(tagListToRel->list.count)
11029      {
11030         macTagCfg->relListCount = tagListToRel->list.count;
11031         for(tagIdx = 0; tagIdx < tagListToRel->list.count; tagIdx++)
11032         {
11033            macTagCfg->relList[tagIdx] = *tagListToRel->list.array[tagIdx];     
11034         }
11035      }
11036   }
11037 }
11038
11039 /*******************************************************************
11040  *
11041  * @brief Fills PdcchCfg received by CU
11042  *
11043  * @details
11044  *
11045  *    Function : extractPdcchCfg
11046  *
11047  *    Functionality: Fills PdcchCfg received  by CU
11048  *
11049  * @params[in] PDCCH_Config_t *cuPdcchCfg,
11050  *             PdcchConfig *duPdcchCfg
11051  * @return void
11052  *
11053  * ****************************************************************/
11054
11055 void extractPdcchCfg(PDCCH_Config_t *cuPdcchCfg, PdcchConfig *macPdcchCfg)
11056 {
11057    uint8_t cRsetIdx = 0;
11058    uint8_t srchSpcIdx = 0;
11059
11060    struct PDCCH_Config__controlResourceSetToAddModList *cRsetToAddModList = NULLP;
11061    struct PDCCH_Config__controlResourceSetToReleaseList *cRsetToRelList = NULLP;
11062    struct PDCCH_Config__searchSpacesToAddModList *srchSpcToAddModList = NULLP;
11063    struct PDCCH_Config__searchSpacesToReleaseList *srchSpcToRelList = NULLP;
11064
11065
11066    /* Control Resource Set To Add/Mod List */
11067    if(cuPdcchCfg->controlResourceSetToAddModList)
11068    {
11069       cRsetToAddModList = cuPdcchCfg->controlResourceSetToAddModList;
11070       if(cRsetToAddModList->list.count)
11071       {
11072          macPdcchCfg->numCRsetToAddMod = cRsetToAddModList->list.count;
11073          for(cRsetIdx = 0; cRsetIdx < cRsetToAddModList->list.count; cRsetIdx++)
11074          {
11075             macPdcchCfg->cRSetToAddModList[cRsetIdx].cRSetId = \
11076                cRsetToAddModList->list.array[cRsetIdx]->controlResourceSetId;
11077             //freqDomRsrcBitStringToInt(&cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources,\
11078                   macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc);
11079             memcpy(macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc, \
11080                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.buf,
11081                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.size);
11082
11083             macPdcchCfg->cRSetToAddModList[cRsetIdx].duration = \
11084                 cRsetToAddModList->list.array[cRsetIdx]->duration;
11085
11086             macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType = \
11087                cRsetToAddModList->list.array[cRsetIdx]->cce_REG_MappingType.present;   
11088             if(macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType == CCE_REG_MAPPINGTYPE_PR_INTERLEAVED)
11089             {
11090                //TODO: handle the case for Interleaved
11091             }
11092             macPdcchCfg->cRSetToAddModList[cRsetIdx].precoderGranularity = \
11093                 cRsetToAddModList->list.array[cRsetIdx]->precoderGranularity;
11094             if(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID)
11095             {
11096                macPdcchCfg->cRSetToAddModList[cRsetIdx].dmrsScramblingId= \
11097                   *(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID);
11098             }
11099          }
11100       }
11101    }
11102    /* Control Resource Set To Release List */
11103    if(cuPdcchCfg->controlResourceSetToReleaseList)
11104    {
11105       cRsetToRelList = cuPdcchCfg->controlResourceSetToReleaseList;
11106       if(cRsetToRelList->list.count)
11107       {
11108          macPdcchCfg->numCRsetToRel = cRsetToRelList->list.count;
11109          for(cRsetIdx = 0; cRsetIdx < cRsetToRelList->list.count; cRsetIdx++)
11110          {
11111             macPdcchCfg->cRSetToRelList[cRsetIdx] = *(cRsetToRelList->list.array[cRsetIdx]);
11112          }
11113       }
11114    }
11115
11116    /* Search space To Add/Mod List */
11117    if(cuPdcchCfg->searchSpacesToAddModList)
11118    {
11119       srchSpcToAddModList = cuPdcchCfg->searchSpacesToAddModList;
11120       if(srchSpcToAddModList->list.count)
11121       {
11122          macPdcchCfg->numSearchSpcToAddMod = srchSpcToAddModList->list.count;
11123          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToAddModList->list.count; srchSpcIdx++)
11124          {
11125             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceId =\
11126                                                                           srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceId;
11127             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].cRSetId =\
11128                                                                     *(srchSpcToAddModList->list.array[srchSpcIdx]->controlResourceSetId);
11129             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset)
11130             {
11131                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSlotPeriodicityAndOffset =\
11132                                                                                          srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset->present;
11133             }
11134             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot)
11135             {
11136                bitStringToInt(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot,\
11137                      macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSymbolsWithinSlot);
11138             }
11139             if(srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates)
11140             {
11141                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel1 = \
11142                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel1;
11143                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel2 = \
11144                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel2;
11145                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel4 = \
11146                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel4;
11147
11148                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel8 = \
11149                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel8;
11150
11151                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel16 = \
11152                                                                                         srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel16;
11153             }
11154             if(srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType)
11155             {
11156                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType =\
11157                                                                                srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->present;
11158                if(macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType == SEARCHSPACETYPE_PR_UE_SPECIFIC)
11159                {
11160                   macPdcchCfg->searchSpcToAddModList[srchSpcIdx].ueSpecificDciFormat =\
11161                                                                                       srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->choice.ue_Specific->dci_Formats;
11162                }
11163
11164             }
11165          }
11166       }
11167    }
11168    /* Search space To Rel List */
11169    if(cuPdcchCfg->searchSpacesToReleaseList)
11170    {
11171       srchSpcToRelList = cuPdcchCfg->searchSpacesToReleaseList;
11172       if(srchSpcToRelList->list.count)
11173       {
11174          macPdcchCfg->numSearchSpcToRel = srchSpcToRelList->list.count;
11175          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToRelList->list.count; srchSpcIdx++)
11176          {
11177             macPdcchCfg->searchSpcToRelList[srchSpcIdx] =\
11178                                                          *(srchSpcToRelList->list.array[srchSpcIdx]);
11179          }
11180       }
11181    }
11182 }
11183
11184 /*******************************************************************
11185  *
11186  * @brief Fills PdschCfg received by CU
11187  *
11188  * @details
11189  *
11190  *    Function : extractPdschCfg
11191  *
11192  *    Functionality: Fills PdschCfg received  by CU
11193  *
11194  * @params[in] PDSCH_Config_t *cuPdschCfg = Information which is send by CU,
11195  *                   which we have stored in F1UeContextSetupDb,
11196  *             PdschConfig *macPdschCfg = Used to Store the information which
11197  *                   needs to send in other layer, as well as this can be the variable
11198  *                   which stores the information in DuCb,
11199  *             PdschConfig *storedPdschCfg =  Null in case of sending the
11200  *                   information to other layer else it will have stored pdsch 
11201  *                   configuration in copyOfmacUeCfg.
11202  * @return void
11203  *
11204  * ****************************************************************/
11205
11206 void extractPdschCfg(PDSCH_Config_t *cuPdschCfg, PdschConfig *macPdschCfg, PdschConfig *storedPdschCfg)
11207 {
11208    uint8_t timeDomIdx;
11209    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAlloc = NULLP;
11210
11211    if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
11212    {
11213       if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->present == \
11214             PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup)
11215       {
11216          if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup)
11217          {
11218             macPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
11219                *(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_AdditionalPosition);
11220          }
11221       }
11222    }
11223    macPdschCfg->resourceAllocType = cuPdschCfg->resourceAllocation;
11224    if(cuPdschCfg->pdsch_TimeDomainAllocationList)
11225    {
11226       timeDomAlloc = cuPdschCfg->pdsch_TimeDomainAllocationList;
11227       if(timeDomAlloc->present ==\
11228             PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup)
11229       {
11230          if(timeDomAlloc->choice.setup)
11231          {
11232             macPdschCfg->numTimeDomRsrcAlloc  = timeDomAlloc->choice.setup->list.count;
11233             for(timeDomIdx = 0; timeDomIdx < timeDomAlloc->choice.setup->list.count; timeDomIdx++)
11234             {
11235                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 = NULLP;
11236                if(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0)
11237                {
11238                   if(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 == NULL)
11239                   {
11240                      if(storedPdschCfg)
11241                      {
11242                         if(storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
11243                         {
11244                            macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 =\
11245                            storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0;
11246                         }
11247                         else
11248                         {
11249                            DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
11250                         }
11251                      }
11252                      else
11253                      {
11254                         DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
11255                      }
11256                      if(!macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
11257                      {
11258                         DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for k0 at extractPdschCfg()");
11259                         return;
11260                      }
11261                   }
11262                   *(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0) = \
11263                   *(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0);
11264                }
11265                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].mappingType = \
11266                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->mappingType;
11267                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].startSymbolAndLength = \
11268                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11269             }
11270          }
11271       }
11272    }
11273    macPdschCfg->rbgSize = cuPdschCfg->rbg_Size;
11274    if(cuPdschCfg->maxNrofCodeWordsScheduledByDCI)
11275       macPdschCfg->numCodeWordsSchByDci = *(cuPdschCfg->maxNrofCodeWordsScheduledByDCI);
11276    if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_staticBundling)
11277    {
11278       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11279       if(cuPdschCfg->prb_BundlingType.choice.staticBundling)
11280       {
11281          if(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize)
11282          {
11283             macPdschCfg->bundlingInfo.StaticBundling.size = \
11284                *(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize);
11285          }
11286       }
11287    }
11288    else if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_dynamicBundling)
11289    {
11290       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
11291    }
11292
11293 }
11294
11295 /*******************************************************************
11296  *
11297  * @brief Fills PdschServingCellCfg received by CU
11298  *
11299  * @details
11300  *
11301  *    Function : extractPdschServingCellCfg
11302  *
11303  *    Functionality: Fills PdschCfg received  by CU
11304  *
11305  * @params[in] PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg,
11306  *             PdschServCellCfg *macUePdschSrvCellCfg
11307  * @return ROK/RFAILED
11308  *
11309  * ****************************************************************/
11310
11311 uint8_t extractPdschServingCellCfg(PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg, PdschServCellCfg *macUePdschSrvCellCfg)
11312 {
11313    if(cuPdschSrvCellCfg->codeBlockGroupTransmission)
11314    {
11315       if(cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup)
11316       {
11317          if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11318          {
11319             *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11320                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11321          }
11322          else
11323          {
11324             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
11325             if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11326             {
11327                *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11328                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11329             }
11330             else
11331             {
11332                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxCodeBlkGrpPerTb at extractPdschServingCellCfg()");
11333                return RFAILED;
11334             }
11335          }
11336          if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11337          {
11338             *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11339                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11340          }
11341          else
11342          {
11343             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->codeBlkGrpFlushInd , sizeof(bool));
11344             if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11345             {
11346                *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11347                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11348             }
11349             else
11350             {
11351                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for codeBlkGrpFlushInd at extractPdschServingCellCfg()");
11352                return RFAILED;
11353             }
11354          }
11355       }
11356    }
11357    if(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH)
11358    {
11359       macUePdschSrvCellCfg->numHarqProcForPdsch = *(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH); 
11360    }
11361    if(cuPdschSrvCellCfg->ext1)
11362    {
11363       if(cuPdschSrvCellCfg->ext1->maxMIMO_Layers)
11364       {
11365         if(macUePdschSrvCellCfg->maxMimoLayers)
11366         {
11367            *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11368         }
11369         else
11370         {
11371            DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxMimoLayers, sizeof(uint8_t));
11372            if(macUePdschSrvCellCfg->maxMimoLayers)
11373            {
11374               *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11375            }
11376            else
11377            {
11378               DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxMimoLayers at extractPdschServingCellCfg()");
11379               return RFAILED;
11380            }
11381         }
11382       }
11383    }
11384    if(cuPdschSrvCellCfg->xOverhead)
11385    {
11386       if(macUePdschSrvCellCfg->xOverhead)
11387       {
11388          *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11389       }
11390       else
11391       {
11392          DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->xOverhead, sizeof(PdschXOverhead));
11393          if(macUePdschSrvCellCfg->xOverhead)
11394          {
11395             *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11396          }
11397          else
11398          {
11399             DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for xOverhead at extractPdschServingCellCfg()");
11400             return RFAILED;
11401          }
11402       }
11403    }
11404    return ROK;
11405 }
11406
11407 /*******************************************************************
11408  *
11409  * @brief Fills PuschCfg received by CU
11410  *
11411  * @details
11412  *
11413  *    Function : extractPuschCfg
11414  *
11415  *    Functionality: Fills PuschCfg received  by CU
11416  *
11417  * @params[in] BWP_UplinkDedicated__pusch_Config *cuPuschCfg,
11418  *             PuschCfg *macPuschCfg
11419  * @return void
11420  *
11421  * ****************************************************************/
11422
11423 void extractPuschCfg(struct BWP_UplinkDedicated__pusch_Config *cuPuschCfg, PuschCfg *macPuschCfg)
11424 {
11425    uint8_t timeDomIdx = 0;
11426    DMRS_UplinkConfig_t *dmrsUlCfg = NULLP;
11427    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList = NULLP;
11428
11429    if(cuPuschCfg->present == BWP_UplinkDedicated__pusch_Config_PR_setup)
11430    {
11431       if(cuPuschCfg->choice.setup)
11432       {
11433          if(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH)
11434          {
11435              macPuschCfg->dataScramblingId = \
11436                 *(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH);
11437          }
11438          if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA)
11439          {
11440             if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->present == PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup)
11441             {
11442                if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup)
11443                {
11444                   dmrsUlCfg = (cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup);
11445                   if(dmrsUlCfg->dmrs_AdditionalPosition)
11446                   {
11447                      macPuschCfg->dmrsUlCfgForPuschMapTypeA.addPos =\
11448                         *(dmrsUlCfg->dmrs_AdditionalPosition);
11449                   }
11450                   if(dmrsUlCfg->transformPrecodingDisabled)
11451                   {
11452                      if(dmrsUlCfg->transformPrecodingDisabled->scramblingID0)
11453                      {
11454                         macPuschCfg->dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0 = \
11455                            *(dmrsUlCfg->transformPrecodingDisabled->scramblingID0);
11456                      }
11457                   }
11458                }
11459             }
11460          }
11461          /*Res Alloc Type for UL */
11462          if(cuPuschCfg->choice.setup->resourceAllocation)
11463          {
11464             macPuschCfg->resourceAllocType = \
11465                cuPuschCfg->choice.setup->resourceAllocation;
11466          }
11467          if(cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList)
11468          {
11469             timeDomAllocList = cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList;
11470             if(timeDomAllocList->present == PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup)
11471             {
11472                if(timeDomAllocList->choice.setup)
11473                {
11474                   macPuschCfg->numTimeDomRsrcAlloc = timeDomAllocList->choice.setup->list.count;
11475                   for(timeDomIdx = 0; timeDomIdx <timeDomAllocList->choice.setup->list.count; timeDomIdx++)
11476                   {
11477                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].k2 = \
11478                         *(timeDomAllocList->choice.setup->list.array[timeDomIdx]->k2);
11479                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].mappingType = \
11480                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->mappingType;
11481                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].startSymbolAndLength = \
11482                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11483                   }
11484                }
11485             }
11486          }
11487          if(cuPuschCfg->choice.setup->transformPrecoder)
11488             macPuschCfg->transformPrecoder = *(cuPuschCfg->choice.setup->transformPrecoder);
11489       }
11490    }
11491 }
11492
11493 /*******************************************************************
11494  *
11495  * @brief Function to fill pucch Power Control
11496  *
11497  * @details
11498  *
11499  *    Function : extractPucchPowerControl
11500  *
11501  *    Functionality: Function to fill pucch Power Control
11502  *
11503  * @params[in] PucchPowerControl *pwrCtrl,
11504  *             struct PUCCH_PowerControl *cuPwrCtrlCfg
11505  * @return void
11506  *
11507  * ****************************************************************/
11508
11509 void extractPucchPowerControl(PucchPowerControl *pwrCtrl, struct PUCCH_PowerControl *cuPwrCtrlCfg)
11510 {
11511    uint8_t arrIdx;
11512
11513    if(cuPwrCtrlCfg->deltaF_PUCCH_f0)
11514       pwrCtrl->deltaF_Format0 = *cuPwrCtrlCfg->deltaF_PUCCH_f0;
11515    if(cuPwrCtrlCfg->deltaF_PUCCH_f1)
11516       pwrCtrl->deltaF_Format1 = *cuPwrCtrlCfg->deltaF_PUCCH_f1;
11517    if(cuPwrCtrlCfg->deltaF_PUCCH_f2)
11518       pwrCtrl->deltaF_Format2 = *cuPwrCtrlCfg->deltaF_PUCCH_f2;
11519    if(cuPwrCtrlCfg->deltaF_PUCCH_f3)
11520       pwrCtrl->deltaF_Format3 = *cuPwrCtrlCfg->deltaF_PUCCH_f3;
11521    if(cuPwrCtrlCfg->deltaF_PUCCH_f4)
11522       pwrCtrl->deltaF_Format4 = *cuPwrCtrlCfg->deltaF_PUCCH_f4;
11523    if(cuPwrCtrlCfg->p0_Set)
11524    {
11525       pwrCtrl->p0SetCount = cuPwrCtrlCfg->p0_Set->list.count;
11526       for(arrIdx=0; arrIdx < pwrCtrl->p0SetCount; arrIdx++)
11527       {
11528          pwrCtrl->p0Set[arrIdx].p0PucchId =\
11529             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Id;
11530          pwrCtrl->p0Set[arrIdx].p0PucchVal =\
11531             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Value;
11532       }
11533    }
11534    if(cuPwrCtrlCfg->pathlossReferenceRSs)
11535    {
11536       pwrCtrl->pathLossRefRSListCount = cuPwrCtrlCfg->pathlossReferenceRSs->list.count;
11537       for(arrIdx = 0; arrIdx < pwrCtrl->pathLossRefRSListCount; arrIdx++)
11538       {
11539          pwrCtrl->pathLossRefRSList[arrIdx].pathLossRefRSId =\
11540             cuPwrCtrlCfg->pathlossReferenceRSs->list.array[arrIdx]->pucch_PathlossReferenceRS_Id;
11541       }
11542    }
11543 }
11544  
11545  /*******************************************************************
11546  *
11547  * @brief Function to extractResrcSetToAddModList sent by CU
11548  *
11549  * @details
11550  *
11551  *    Function : extractResrcSetToAddModList
11552  *
11553  *    Functionality: Fucntion to extractResrcSetToAddModList
11554  *
11555  * @params[in] PucchResrcSetCfg pointer,
11556  *             struct PUCCH_Config__resourceSetToAddModList pointer
11557  * @return void
11558  *
11559  * ****************************************************************/
11560
11561 void extractResrcSetToAddModList(PucchResrcSetCfg *macRsrcSetList, struct PUCCH_Config__resourceSetToAddModList *cuRsrcSetList)
11562 {
11563    uint8_t arrIdx, rsrcListIdx;
11564
11565    macRsrcSetList->resrcSetToAddModListCount = cuRsrcSetList->list.count; 
11566    for(arrIdx = 0; arrIdx < macRsrcSetList->resrcSetToAddModListCount; arrIdx++)
11567    {
11568       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcSetId     =\
11569          cuRsrcSetList->list.array[arrIdx]->pucch_ResourceSetId;
11570       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount =\
11571          cuRsrcSetList->list.array[arrIdx]->resourceList.list.count;
11572       for(rsrcListIdx = 0; rsrcListIdx < macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount; rsrcListIdx++)
11573       {
11574          macRsrcSetList->resrcSetToAddModList[arrIdx].resrcList[rsrcListIdx] =\
11575             *cuRsrcSetList->list.array[arrIdx]->resourceList.list.array[rsrcListIdx];
11576       }
11577
11578       if(cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1)
11579       {
11580          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize =\
11581             *cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1;
11582       }
11583       else
11584       {
11585          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize = 0;
11586       }
11587    }
11588 }/* End of extractResrcSetToAddModList */
11589
11590 /*******************************************************************
11591  *
11592  * @brief Fills extractResrcToAddModList sent by CU
11593  *
11594  * @details
11595  *
11596  *    Function : extractResrcToAddModList
11597  *
11598  *    Functionality: Fills extractResrcToAddModList
11599  *
11600  * @params[in] PucchResrcCfg pointer,
11601  *             struct PUCCH_Config__resourceToAddModList pointer
11602  * @return ROk/RFAILED
11603  *
11604  * ****************************************************************/
11605
11606 uint8_t extractResrcToAddModList(PucchResrcCfg *macResrcList, struct PUCCH_Config__resourceToAddModList *cuResrcList)
11607 {
11608    uint8_t arrIdx;
11609    
11610    macResrcList->resrcToAddModListCount = cuResrcList->list.count;
11611    for(arrIdx = 0; arrIdx < macResrcList->resrcToAddModListCount; arrIdx++)
11612    {
11613       macResrcList->resrcToAddModList[arrIdx].resrcId      =\
11614         cuResrcList->list.array[arrIdx]->pucch_ResourceId; 
11615       macResrcList->resrcToAddModList[arrIdx].startPrb     =\
11616         cuResrcList->list.array[arrIdx]->startingPRB;
11617       if(cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping)
11618       {
11619          macResrcList->resrcToAddModList[arrIdx].intraFreqHop =\
11620            *cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping;
11621       }
11622       if(cuResrcList->list.array[arrIdx]->secondHopPRB)
11623       {
11624          macResrcList->resrcToAddModList[arrIdx].secondPrbHop =\
11625            *cuResrcList->list.array[arrIdx]->secondHopPRB;
11626       }
11627       /* PUCCH RSRC FORMAT */
11628       if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format0)
11629       {
11630          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_0;
11631          if(cuResrcList->list.array[arrIdx]->format.choice.format0)
11632          {
11633             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0, sizeof(PucchFormat0));
11634             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0 == NULLP)
11635             {
11636                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format0 in extractResrcToAddModList()");
11637                return RFAILED;
11638             }
11639             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->initialCyclicShift =\
11640                cuResrcList->list.array[arrIdx]->format.choice.format0->initialCyclicShift;
11641             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->numSymbols =\
11642                cuResrcList->list.array[arrIdx]->format.choice.format0->nrofSymbols;
11643             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->startSymbolIdx =\
11644                cuResrcList->list.array[arrIdx]->format.choice.format0->startingSymbolIndex;
11645          }
11646       }
11647       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format1)
11648       {
11649          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_1;
11650          if(cuResrcList->list.array[arrIdx]->format.choice.format1)
11651          {
11652             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1, sizeof(PucchFormat1));
11653             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1 == NULLP)
11654             {
11655                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format1 in extractResrcToAddModList()");
11656                return RFAILED;
11657             }
11658             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->initialCyclicShift =\
11659                 cuResrcList->list.array[arrIdx]->format.choice.format1->initialCyclicShift;
11660             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->numSymbols =\
11661                 cuResrcList->list.array[arrIdx]->format.choice.format1->nrofSymbols;
11662             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->startSymbolIdx =\
11663                 cuResrcList->list.array[arrIdx]->format.choice.format1->startingSymbolIndex;
11664             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->timeDomOCC =\
11665                 cuResrcList->list.array[arrIdx]->format.choice.format1->timeDomainOCC;
11666          }
11667       }
11668       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format2)
11669       {
11670          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_2;
11671          if(cuResrcList->list.array[arrIdx]->format.choice.format2)
11672          {
11673             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
11674             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2 == NULLP)
11675             {
11676                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format2 in extractResrcToAddModList()");
11677                return RFAILED;
11678             }
11679             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numPrbs =\
11680                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofPRBs;
11681             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numSymbols =\
11682                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofSymbols;
11683             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->startSymbolIdx =\
11684                 cuResrcList->list.array[arrIdx]->format.choice.format2->startingSymbolIndex;
11685          }
11686       }
11687       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format3)
11688       {
11689          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_3;
11690          if(cuResrcList->list.array[arrIdx]->format.choice.format3)
11691          {
11692             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
11693             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3 == NULLP)
11694             {
11695                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format3 in extractResrcToAddModList()");
11696                return RFAILED;
11697             }
11698             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numPrbs =\
11699                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofPRBs;
11700             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numSymbols =\
11701                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofSymbols;
11702             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->startSymbolIdx =\
11703                 cuResrcList->list.array[arrIdx]->format.choice.format3->startingSymbolIndex;
11704          }
11705       }
11706       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format4)
11707       {
11708          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_4;
11709          if(cuResrcList->list.array[arrIdx]->format.choice.format4)
11710          {
11711             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4, sizeof(PucchFormat4));
11712             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4 == NULLP)
11713             {
11714                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format4 in extractResrcToAddModList()");
11715                return RFAILED;
11716             }
11717             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->numSymbols =\
11718                 cuResrcList->list.array[arrIdx]->format.choice.format4->nrofSymbols;
11719             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occLen =\
11720                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Length;
11721             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occIdx =\
11722                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Index;
11723             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->startSymbolIdx =\
11724                 cuResrcList->list.array[arrIdx]->format.choice.format4->startingSymbolIndex;
11725          }
11726       }
11727    }
11728    return ROK;
11729
11730 }/* End of extractResrcToAddModList */
11731
11732 /*******************************************************************
11733  *
11734  * @brief Fills fillPucchSchedReqPeriodAndOffset sent by CU
11735  *
11736  * @details
11737  *
11738  *    Function : fillPucchSchedReqPeriodAndOffset
11739  *
11740  *    Functionality: To fillPucchSchedReqPeriodAndOffset
11741  *
11742  * @params[in] macPeriodicty,
11743  *     SchedulingRequestResourceConfig__periodicityAndOffset pointer
11744  * @return void
11745  *
11746  * ****************************************************************/
11747
11748 void fillPucchSchedReqPeriodAndOffset(uint8_t macPeriodicty, uint16_t  macOffset,\
11749    struct SchedulingRequestResourceConfig__periodicityAndOffset *cuPeriodicty)
11750 {
11751    macPeriodicty = cuPeriodicty->present;
11752    switch(macPeriodicty)
11753    {
11754       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
11755          {
11756             macOffset     = cuPeriodicty->choice.sym2;
11757             break;
11758          }
11759       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
11760          {
11761             macOffset     = cuPeriodicty->choice.sym6or7;
11762             break;
11763          }
11764       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
11765          {
11766             macOffset     = cuPeriodicty->choice.sl1;
11767             break;
11768          }
11769       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
11770          {
11771             macOffset = cuPeriodicty->choice.sl2;
11772             break;
11773          }
11774       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
11775          {
11776             macOffset = cuPeriodicty->choice.sl4;
11777             break;
11778          }
11779       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
11780          {
11781             macOffset = cuPeriodicty->choice.sl5;
11782             break;
11783          }
11784       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
11785          {
11786             macOffset = cuPeriodicty->choice.sl8;
11787             break;
11788          }
11789       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
11790          {
11791             macOffset = cuPeriodicty->choice.sl10;
11792             break;
11793          }
11794       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
11795          {
11796             macOffset = cuPeriodicty->choice.sl16;
11797             break;
11798          }
11799       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
11800          {
11801             macOffset = cuPeriodicty->choice.sl20;
11802             break;
11803          }
11804       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
11805          {
11806             macOffset = cuPeriodicty->choice.sl40;
11807             break;
11808          }
11809       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
11810          {
11811             macOffset = cuPeriodicty->choice.sl80;
11812             break;
11813          }
11814       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
11815          {
11816             macOffset = cuPeriodicty->choice.sl160;
11817             break;
11818          }
11819       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
11820          {
11821             macOffset = cuPeriodicty->choice.sl320;
11822             break;
11823          }
11824       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
11825          {
11826             macOffset = cuPeriodicty->choice.sl640;
11827             break;
11828          }
11829       default :
11830          DU_LOG("\nERROR  -->  F1AP : Invalid periodicity %d", macPeriodicty);
11831    }
11832 }
11833
11834 /*******************************************************************
11835  *
11836  * @brief Function to extractPucchFormatCfg sent by CU
11837  *
11838  * @details
11839  *
11840  *    Function : extractPucchFormatCfg
11841  *
11842  *    Functionality: Function to extractPucchFormatCfg
11843  *
11844  * @params[in] PucchFormatCfg pointer,
11845  *             PUCCH_FormatConfig_t pointer
11846  * @return void
11847  *
11848  * ****************************************************************/
11849
11850 void extractPucchFormatCfg(PucchFormatCfg *macFormatCfg, PUCCH_FormatConfig_t *cuFormatCfg)
11851  {
11852     if(cuFormatCfg->interslotFrequencyHopping)
11853        macFormatCfg->interSlotFreqHop = *cuFormatCfg->interslotFrequencyHopping;
11854     if(cuFormatCfg->additionalDMRS)  
11855        macFormatCfg->addDmrs = *cuFormatCfg->additionalDMRS;
11856     if(cuFormatCfg->maxCodeRate)
11857        macFormatCfg->maxCodeRate = *cuFormatCfg->maxCodeRate;
11858     if(cuFormatCfg->nrofSlots)  
11859        macFormatCfg->numSlots = *cuFormatCfg->nrofSlots;
11860     if(cuFormatCfg->pi2BPSK)  
11861        macFormatCfg->pi2BPSK = *cuFormatCfg->pi2BPSK;
11862     if(cuFormatCfg->simultaneousHARQ_ACK_CSI)  
11863        macFormatCfg->harqAckCSI = *cuFormatCfg->simultaneousHARQ_ACK_CSI;
11864  }/* End of extractPucchFormatCfg */
11865
11866 /*******************************************************************
11867  *
11868  * @brief Function to extractSchedReqCfgToAddMod sent by CU
11869  *
11870  * @details
11871  *
11872  *    Function : extractSchedReqCfgToAddMod
11873  *
11874  *    Functionality: Function to extractSchedReqCfgToAddMod
11875  *
11876  * @params[in] PucchSchedReqCfg pointer,
11877  *      PUCCH_Config__schedulingRequestResourceToAddModList pointer
11878  * @return void
11879  *
11880  * ****************************************************************/
11881
11882 void extractSchedReqCfgToAddMod(PucchSchedReqCfg *macSchedReqCfg, struct PUCCH_Config__schedulingRequestResourceToAddModList *cuSchedReqList)
11883 {
11884    uint8_t arrIdx;
11885
11886    macSchedReqCfg->schedAddModListCount = cuSchedReqList->list.count;
11887    for(arrIdx = 0; arrIdx <  macSchedReqCfg->schedAddModListCount; arrIdx++)
11888    {
11889       macSchedReqCfg->schedAddModList[arrIdx].resrcId =\
11890          cuSchedReqList->list.array[arrIdx]->schedulingRequestResourceId;
11891       macSchedReqCfg->schedAddModList[arrIdx].requestId =\
11892          cuSchedReqList->list.array[arrIdx]->schedulingRequestID;
11893       if(cuSchedReqList->list.array[arrIdx]->periodicityAndOffset)
11894       {
11895          fillPucchSchedReqPeriodAndOffset(macSchedReqCfg->schedAddModList[arrIdx].periodicity,\
11896             macSchedReqCfg->schedAddModList[arrIdx].offset, cuSchedReqList->list.array[arrIdx]->periodicityAndOffset);
11897       }
11898       if(cuSchedReqList->list.array[arrIdx]->resource)
11899       {
11900          macSchedReqCfg->schedAddModList[arrIdx].resrc =\
11901             *cuSchedReqList->list.array[arrIdx]->resource;
11902       }
11903    }
11904
11905 }/* End of extractSchedReqCfgToAddMod */
11906
11907  /*******************************************************************
11908  *
11909  * @brief Fills PucchCfg received by CU
11910  *
11911  * @details
11912  *
11913  *    Function : extractPucchCfg
11914  *
11915  *    Functionality: Fills PucchCfg received  by CU
11916  *
11917  * @params[in] BWP_UplinkDedicated__pucch_Config *cuPucchCfg = Information which
11918  *                is send by CU, which we have stored in F1UeContextSetupDb,
11919  *             PucchCfg *macPucchCfg = Used to Store the information which
11920  *                needs to send in other layer, as well as this can be the variable
11921  *                which stores the information in DuCb,
11922  *             PucchCfg *storedPucchCfg = Null in case of sending the
11923  *                information to other layer else it will have Pucch Cfg which
11924  *                we have stored in copyOfmacUeCfg.
11925  * @return ROK/RFAILED
11926  *
11927  * ****************************************************************/
11928
11929 uint8_t extractPucchCfg(struct BWP_UplinkDedicated__pucch_Config *cuPucchCfg, PucchCfg *macPucchCfg,\
11930 PucchCfg *storedPucchCfg)        
11931 {
11932    uint8_t arrIdx;
11933
11934    if(cuPucchCfg->present == BWP_UplinkDedicated__pucch_Config_PR_setup)
11935    {
11936       if(cuPucchCfg->choice.setup)
11937       {
11938          /* Resource Set Cfg */ 
11939          if(cuPucchCfg->choice.setup->resourceSetToAddModList)
11940          {
11941             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrcSet, sizeof(PucchResrcSetCfg));
11942             if(macPucchCfg->resrcSet == NULLP)
11943             {
11944                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc set List in extractPucchCfg()");
11945                return RFAILED;
11946             }
11947             memset(macPucchCfg->resrcSet, 0, sizeof(PucchResrcSetCfg));
11948             extractResrcSetToAddModList(macPucchCfg->resrcSet, cuPucchCfg->choice.setup->resourceSetToAddModList);
11949          }
11950          
11951          /* Resource Cfg */ 
11952          if(cuPucchCfg->choice.setup->resourceToAddModList)
11953          {
11954             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrc, sizeof(PucchResrcCfg));
11955             if(macPucchCfg->resrc == NULLP)
11956             {
11957                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc List in extractPucchCfg()");
11958                return RFAILED;
11959             }
11960             memset(macPucchCfg->resrc, 0, sizeof(PucchResrcCfg));
11961             extractResrcToAddModList(macPucchCfg->resrc, cuPucchCfg->choice.setup->resourceToAddModList);
11962          }
11963          
11964          /* Format 1 Cfg */ 
11965          if(cuPucchCfg->choice.setup->format1)
11966          {
11967             DU_ALLOC_SHRABL_BUF(macPucchCfg->format1, sizeof(PucchFormatCfg));
11968             if(macPucchCfg->format1 == NULLP)
11969             {
11970                DU_LOG("\nERROR --> F1AP : Failed to extract format 1 Cfg in  extractPucchCfg()");
11971                return RFAILED;
11972             }
11973             memset(macPucchCfg->format1, 0, sizeof(PucchFormatCfg));
11974             extractPucchFormatCfg(macPucchCfg->format1,\
11975                cuPucchCfg->choice.setup->format1->choice.setup);
11976          }
11977          
11978          /* Format 2 Cfg */
11979          if(cuPucchCfg->choice.setup->format2)
11980          {
11981             DU_ALLOC_SHRABL_BUF(macPucchCfg->format2, sizeof(PucchFormatCfg));
11982             if(macPucchCfg->format2 == NULLP)
11983             {
11984                DU_LOG("\nERROR --> F1AP : Failed to extract format 2 Cfg in  extractPucchCfg()");
11985                return RFAILED;
11986             }
11987             memset(macPucchCfg->format2, 0, sizeof(PucchFormatCfg));
11988             extractPucchFormatCfg(macPucchCfg->format2,\
11989                cuPucchCfg->choice.setup->format2->choice.setup);
11990          }
11991          
11992          /* Format 3 Cfg */
11993          if(cuPucchCfg->choice.setup->format3)
11994          {
11995             DU_ALLOC_SHRABL_BUF(macPucchCfg->format3, sizeof(PucchFormatCfg));
11996             if(macPucchCfg->format3 == NULLP)
11997             {
11998                DU_LOG("\nERROR --> F1AP : Failed to extract format 3 Cfg in  extractPucchCfg()");
11999                return RFAILED;
12000             }
12001             memset(macPucchCfg->format3, 0, sizeof(PucchFormatCfg));
12002             extractPucchFormatCfg(macPucchCfg->format3,\
12003                cuPucchCfg->choice.setup->format3->choice.setup);
12004          }
12005
12006          /* Format 4 Cfg */
12007          if(cuPucchCfg->choice.setup->format4)
12008          {
12009             DU_ALLOC_SHRABL_BUF(macPucchCfg->format4, sizeof(PucchFormatCfg));
12010             if(macPucchCfg->format4 == NULLP)
12011             {
12012                DU_LOG("\nERROR --> F1AP : Failed to extract format 4 Cfg in  extractPucchCfg()");
12013                return RFAILED;
12014             }
12015             memset(macPucchCfg->format4, 0, sizeof(PucchFormatCfg));
12016             extractPucchFormatCfg(macPucchCfg->format4,\
12017                cuPucchCfg->choice.setup->format4->choice.setup);
12018          }
12019
12020          /* Sched Req List */
12021          if(cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList)
12022          {
12023             DU_ALLOC_SHRABL_BUF(macPucchCfg->schedReq, sizeof(PucchSchedReqCfg));
12024             if(macPucchCfg->schedReq == NULLP)
12025             {
12026                DU_LOG("\nERROR --> F1AP : Failed to extract schedReqCfg in  extractPucchCfg()");
12027                return RFAILED;
12028             }
12029             memset(macPucchCfg->schedReq, 0, sizeof(PucchSchedReqCfg));
12030             extractSchedReqCfgToAddMod(macPucchCfg->schedReq,\
12031             cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList);
12032          }
12033
12034          /*TODO: Add support for  Spatial Info */
12035
12036          /* MultiCsiCfg */
12037          if(cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList)
12038          {
12039             DU_ALLOC_SHRABL_BUF(macPucchCfg->multiCsiCfg, sizeof(PucchMultiCsiCfg));
12040             if(macPucchCfg->multiCsiCfg == NULLP)
12041             {
12042                DU_LOG("\nERROR --> F1AP : Failed to extract multiCsiCfg in  extractPucchCfg()");
12043                return RFAILED;
12044             }
12045             memset(macPucchCfg->multiCsiCfg, 0, sizeof(PucchMultiCsiCfg));
12046             macPucchCfg->multiCsiCfg->multiCsiResrcListCount = cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.count;
12047             for(arrIdx =0; arrIdx < macPucchCfg->multiCsiCfg->multiCsiResrcListCount; arrIdx++)
12048             {
12049                macPucchCfg->multiCsiCfg->multiCsiResrcList[arrIdx] =\
12050                  *cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.array[arrIdx];
12051             }
12052          }
12053
12054          /* Dl_DataToUL_ACK */ 
12055          if(cuPucchCfg->choice.setup->dl_DataToUL_ACK)
12056     {
12057        if(storedPucchCfg)
12058        {
12059           if(storedPucchCfg->dlDataToUlAck)
12060           {
12061              macPucchCfg->dlDataToUlAck = storedPucchCfg->dlDataToUlAck; 
12062           }
12063           else
12064           {
12065             DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
12066           }
12067        }
12068        else
12069        {
12070           DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
12071        }
12072        if(macPucchCfg->dlDataToUlAck == NULLP)
12073        {
12074           DU_LOG("\nERROR --> F1AP : Failed to extract Dl_DataToUL_ACK in extractPucchCfg()");
12075           return RFAILED;
12076        }
12077        memset(macPucchCfg->dlDataToUlAck, 0, sizeof(PucchDlDataToUlAck));
12078        macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount = cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.count;
12079        for(arrIdx = 0; arrIdx < macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; arrIdx++)
12080        {
12081           macPucchCfg->dlDataToUlAck->dlDataToUlAckList[arrIdx] =\
12082           *cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.array[arrIdx];
12083        }
12084          }
12085
12086          /* Power Control */
12087          if(cuPucchCfg->choice.setup->pucch_PowerControl)
12088          {
12089             DU_ALLOC_SHRABL_BUF(macPucchCfg->powerControl, sizeof(PucchPowerControl));
12090             if(macPucchCfg->powerControl == NULLP)
12091             {
12092                DU_LOG("\nERROR --> F1AP : Failed to extract power control in extractPucchCfg()");
12093                return RFAILED;
12094             }
12095             extractPucchPowerControl(macPucchCfg->powerControl,\
12096                cuPucchCfg->choice.setup->pucch_PowerControl);
12097          }
12098       }
12099    }
12100    return ROK;
12101 }
12102
12103 /*******************************************************************
12104  *
12105  * @brief Fills ServingCellReconfig received by CU
12106  *
12107  * @details
12108  *
12109  *    Function : extractSpCellDedicatedCfg
12110  *
12111  *    Functionality: Fills ServingCellReconfig received  by CU
12112  *
12113  * @params[in] ServingCellConfig_t *cuSrvCellCfg = Information which is send by
12114  *                  CU, which we have stored in F1UeContextSetupDb,
12115  *             ServCellCfgInfo *macSrvCellCfg = Used to Store the information
12116  *                  which  needs to send in other layer, as well as this can be the
12117  *                  variable which stores the information in DuCb, 
12118  *             ServCellCfgInfo *storedSrvCellCfg = Null in case of sending the
12119  *                  information to other layer else it will have ServCellCfgInfo which
12120  *                  we have stored in copyOfmacUeCfg.
12121  * @return ROK/RFAILD
12122  *
12123  * ****************************************************************/
12124 uint8_t extractSpCellDedicatedCfg(ServingCellConfig_t *cuSrvCellCfg, ServCellRecfgInfo *macSrvCellCfg,\
12125 ServCellRecfgInfo *storedSrvCellCfg)
12126 {
12127    uint8_t ret = ROK;
12128    BWP_DownlinkDedicated_t *dlBwp = NULLP;
12129    BWP_UplinkDedicated_t   *ulBwp = NULLP;
12130
12131    if(cuSrvCellCfg->initialDownlinkBWP)
12132    {
12133       dlBwp = ((BWP_DownlinkDedicated_t *)(cuSrvCellCfg->initialDownlinkBWP));
12134       if(dlBwp->pdcch_Config)
12135       {
12136          if(dlBwp->pdcch_Config->choice.setup)
12137          {
12138             macSrvCellCfg->initDlBwp.pdcchPresent = true;
12139             if(storedSrvCellCfg)
12140             {
12141                if(!storedSrvCellCfg->initDlBwp.pdcchPresent)
12142                {
12143                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12144                }
12145                else
12146                {
12147                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12148                }
12149             }
12150             else
12151             {
12152                extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
12153             }
12154          }
12155       }
12156       if(dlBwp->pdsch_Config)
12157       {
12158          if(dlBwp->pdsch_Config->choice.setup)
12159          {
12160             macSrvCellCfg->initDlBwp.pdschPresent = true;
12161             
12162             if(storedSrvCellCfg)
12163             {
12164                if(!storedSrvCellCfg->initDlBwp.pdschPresent)
12165                {
12166                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
12167                }
12168                else
12169                {
12170                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg,\
12171                         &storedSrvCellCfg->initDlBwp.pdschCfg);
12172                }
12173             }
12174             else
12175             {
12176                extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
12177             }
12178          }
12179       }
12180    }
12181    if(cuSrvCellCfg->firstActiveDownlinkBWP_Id)
12182       macSrvCellCfg->firstActvDlBwpId = *(cuSrvCellCfg->firstActiveDownlinkBWP_Id);
12183    if(cuSrvCellCfg->defaultDownlinkBWP_Id)
12184       macSrvCellCfg->defaultDlBwpId = *(cuSrvCellCfg->defaultDownlinkBWP_Id);
12185    if(cuSrvCellCfg->bwp_InactivityTimer)
12186    {
12187       if(macSrvCellCfg->bwpInactivityTmr)
12188       {
12189          memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
12190       }
12191       else
12192       {
12193          macSrvCellCfg->bwpInactivityTmr = NULLP;
12194          DU_ALLOC_SHRABL_BUF(macSrvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
12195          if(macSrvCellCfg->bwpInactivityTmr)
12196          {
12197             memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
12198          }
12199          else
12200          {
12201             DU_LOG("\nERROR  --> F1AP : Memory Alloc failed for bwpInactivityTmr at extractSpCellDedicatedCfg()");
12202             return RFAILED;
12203          }
12204       }
12205    }
12206    if(cuSrvCellCfg->pdsch_ServingCellConfig)
12207    {
12208       if(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup)
12209       {
12210          ret = extractPdschServingCellCfg(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup, &macSrvCellCfg->pdschServCellCfg);
12211          if(ret == RFAILED)
12212          {
12213             DU_LOG("\nERROR --> F1AP : Failed at extractPdschServingCellCfg()");
12214             return RFAILED;
12215          }
12216       }
12217    }
12218    if(cuSrvCellCfg->uplinkConfig)
12219    {
12220       if(cuSrvCellCfg->uplinkConfig->initialUplinkBWP)
12221       {
12222          ulBwp = ((BWP_UplinkDedicated_t *)(cuSrvCellCfg->uplinkConfig->initialUplinkBWP));
12223          if(ulBwp->pusch_Config)
12224          {
12225             macSrvCellCfg->initUlBwp.puschPresent = true;
12226             extractPuschCfg(ulBwp->pusch_Config, &macSrvCellCfg->initUlBwp.puschCfg);
12227          }
12228          if(ulBwp->pucch_Config)
12229          {
12230             macSrvCellCfg->initUlBwp.pucchPresent = true;
12231             memset(&macSrvCellCfg->initUlBwp.pucchCfg, 0, sizeof(PucchCfg));
12232             if(storedSrvCellCfg)
12233             {
12234                if(!storedSrvCellCfg->initUlBwp.pucchPresent)
12235                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
12236                else
12237                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg,\
12238                   &storedSrvCellCfg->initUlBwp.pucchCfg);
12239             }
12240             else
12241             {
12242                extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
12243             }
12244          }
12245       }
12246       if(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id)
12247          macSrvCellCfg->firstActvUlBwpId = *(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id);
12248    }
12249    return ret;
12250 }
12251
12252 #ifdef NR_DRX
12253
12254 /*******************************************************************
12255  *
12256  * @brief fill long cycle offset value of drx in UE structure
12257  *
12258  * @details
12259  *
12260  *    Function : fillLongCycleOffsetValueInUeDb
12261  *
12262  *    Functionality: fill long cycle offset value of drx in UE structure
12263  *
12264  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
12265  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
12266  *
12267  * @return ROK     - success
12268  *         RFAILED - failure
12269  *
12270  * ****************************************************************/
12271 void fillLongCycleOffsetValueInUeDb(DrxLongCycleStartOffset *drxLongCycleStartOffset, struct DRX_ConfigRrc__drx_LongCycleStartOffset  *drx_LongCycleStartOffset)
12272 {
12273
12274    drxLongCycleStartOffset->drxLongCycleStartOffsetChoice = convertLongDrxCycleLengthEnumToValue(drx_LongCycleStartOffset->present);
12275    switch(drx_LongCycleStartOffset->present)
12276    {
12277       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
12278          {
12279             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10;
12280             break;
12281          }
12282       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
12283          {
12284             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms20;
12285             break;
12286          }
12287       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
12288          {
12289             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms32;
12290             break;
12291          }
12292       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
12293         {
12294             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms40;
12295             break;
12296          }
12297       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
12298          {
12299             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms60;
12300             break;
12301          }
12302       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
12303          {
12304             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms64;
12305             break;
12306          }
12307       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
12308          {
12309             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms70;
12310             break;
12311          }
12312       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
12313          {
12314             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms80;
12315             break;
12316          }
12317       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
12318          {
12319             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms128;
12320             break;
12321          }
12322       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
12323          {
12324             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms160;
12325             break;
12326          }
12327       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
12328          {
12329             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms256;
12330             break;
12331          }
12332       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
12333          {
12334             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms320;
12335             break;
12336          }
12337       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
12338          {
12339             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms512;
12340             break;
12341          }
12342       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
12343          {
12344             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms640;
12345             break;
12346          }
12347       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
12348          {
12349             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1024;
12350             break;
12351          }
12352       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
12353          {
12354             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1280;
12355             break;
12356          }
12357       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
12358          {
12359             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2048;
12360             break;
12361          }
12362       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
12363          {
12364             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2560;
12365             break;
12366          }
12367        case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
12368          {
12369             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms5120;
12370             break;
12371          }
12372       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
12373          {
12374             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10240;
12375             break;
12376          }
12377       default :
12378          break;
12379    }
12380 }
12381
12382 /*******************************************************************
12383  *
12384  * @brief Fills drx configuration structure with the help of drx_ConfigRrc
12385  *which recive from CU or storedDrxCfg which is already stored
12386  *
12387  * @details
12388  *
12389  *    Function : extractDrxConfiguration 
12390  *
12391  *    Functionality: Fills Reconfig Cell group Info received by CU
12392  *   
12393  * @params[in] cuMacCellGrpDrxConfig  = MAC_CellGroupConfig__drx_ConfigRrc information which
12394  *                       is send by CU, which we have stored in F1UeContextSetupDb
12395  *             DrxCfg * drxCfg  = Used to Store the information,
12396  *                      which needs to send in other layer, as well as this can be
12397  *                      the variable which stores the information in DuCb,
12398  *             DrxCfg *storedDrxCfg = Null in case of sending the
12399  *                      information to other layer else it will have the drx information 
12400  *                      stored in the copyOfmacUeCfg which we have stored in F1UeContextSetupDb.
12401  *
12402  * @return void
12403  *
12404  * ****************************************************************/
12405 void extractDrxConfiguration(struct MAC_CellGroupConfig__drx_ConfigRrc *cuMacCellGrpDrxConfig, DrxCfg * drxCfg, DrxCfg *storedDrxCfg)
12406 {
12407    struct DRX_ConfigRrc *cuDrxConfig;
12408
12409    if(storedDrxCfg)
12410    {
12411       memcpy(drxCfg, storedDrxCfg, sizeof(DrxCfg));
12412    }
12413    else
12414    {
12415       if(cuMacCellGrpDrxConfig)
12416       {
12417          switch(cuMacCellGrpDrxConfig->present)
12418          {
12419             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
12420                break;
12421
12422             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
12423                {
12424                   cuDrxConfig = cuMacCellGrpDrxConfig->choice.setup;
12425                   if(cuDrxConfig)
12426                   {
12427                      switch(cuDrxConfig->drx_onDurationTimer.present)
12428                      {
12429                         case DRX_ConfigRrc__drx_onDurationTimer_PR_NOTHING:
12430                            break;
12431                         case DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds:
12432                            {
12433                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = true;
12434                               drxCfg->drxOnDurationTimer.onDurationtimerValue.milliSeconds=convertOnDurationTimerMilliSecondsEnumToValue(cuDrxConfig->\
12435                               drx_onDurationTimer.choice.milliSeconds);
12436                               break;
12437                            }
12438                         case DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds:
12439                            {
12440                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = false;
12441                               drxCfg->drxOnDurationTimer.onDurationtimerValue.subMilliSeconds = cuDrxConfig->drx_onDurationTimer.choice.subMilliSeconds;
12442                               break;
12443                            }
12444                      }
12445                   }
12446                   fillLongCycleOffsetValueInUeDb(&drxCfg->drxLongCycleStartOffset, &cuDrxConfig->drx_LongCycleStartOffset);
12447                   drxCfg->drxInactivityTimer = convertDrxInactivityTimerEnumToValue(cuDrxConfig->drx_InactivityTimer);
12448                   drxCfg->drxHarqRttTimerDl = cuDrxConfig->drx_HARQ_RTT_TimerDL;
12449                   drxCfg->drxHarqRttTimerUl = cuDrxConfig->drx_HARQ_RTT_TimerUL;
12450                   drxCfg->drxRetransmissionTimerDl = convertDrxRetransmissionTimerDlEnumToValue(cuDrxConfig->drx_RetransmissionTimerDL);
12451                   drxCfg->drxRetransmissionTimerUl = convertDrxRetransmissionTimerUlEnumToValue(cuDrxConfig->drx_RetransmissionTimerUL);
12452                   drxCfg->drxSlotOffset = cuDrxConfig->drx_SlotOffset;
12453                   if(cuDrxConfig->shortDRX)
12454                   {
12455                      drxCfg->shortDrxPres=true;
12456                      drxCfg->shortDrx.drxShortCycle = convertShortDrxCycleLengthEnumToValue(cuDrxConfig->shortDRX->drx_ShortCycle);
12457                      drxCfg->shortDrx.drxShortCycleTimer = cuDrxConfig->shortDRX->drx_ShortCycleTimer;
12458                   }
12459                   else
12460                      drxCfg->shortDrxPres=false;
12461
12462                   break;
12463                }
12464
12465             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
12466                break;
12467          }
12468       }
12469    }
12470 }
12471 #endif
12472
12473 /*******************************************************************
12474  *
12475  * @brief Fills Reconfig Cell group Info received by CU
12476  *
12477  * @details
12478  *
12479  *    Function : extractUeRecfgCellInfo
12480  *
12481  *    Functionality: Fills Reconfig Cell group Info received by CU
12482  *   
12483  * @params[in] CellGroupConfigRrc_t *cellGrp = CellGroupConfigRrc_t information which
12484  *                       is send by CU, which we have stored in F1UeContextSetupDb
12485  *             DuMacUeCfg *MacUeCfg = Used to Store the information,
12486  *                      which needs to send in other layer, as well as this can be
12487  *                      the variable which stores the information in DuCb,
12488  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
12489  *                      information to other layer else it will have copyOfmacUeCfg
12490  *                      which we have stored in F1UeContextSetupDb.
12491  *
12492  * @return ROK/RFAILED
12493  *
12494  * ****************************************************************/
12495 uint8_t extractUeRecfgCellInfo(CellGroupConfigRrc_t *cellGrp, DuMacUeCfg *macUeCfg, DuMacUeCfg *storedMacUeCfg)
12496 {
12497    uint8_t ret = ROK;
12498    MAC_CellGroupConfig_t     *macCellGroup = NULLP;
12499    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
12500    SpCellConfig_t            *spcellCfg = NULLP;
12501    ServingCellConfig_t       *servCellCfg = NULLP;
12502
12503    if(cellGrp)
12504    {
12505       /* Fill MacCell Group Reconfig  */
12506       if(cellGrp->mac_CellGroupConfig)
12507       {
12508          macUeCfg->macCellGrpCfgPres = true;
12509          macCellGroup = ((MAC_CellGroupConfig_t *)(cellGrp->mac_CellGroupConfig));
12510
12511 #ifdef NR_DRX         
12512          if(macCellGroup->drx_ConfigRrc)
12513          {
12514             if(storedMacUeCfg)
12515             {
12516                if(!storedMacUeCfg->macCellGrpCfgPres) 
12517                {
12518                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL);    
12519                }
12520                else
12521                {
12522                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg, &storedMacUeCfg->macCellGrpCfg.drxCfg);    
12523                }
12524             }
12525             else
12526             {
12527                extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL); 
12528             }
12529          }
12530 #endif
12531
12532          if(macCellGroup->schedulingRequestConfig)
12533          {
12534             extractSchReqReConfig(macCellGroup->schedulingRequestConfig, &macUeCfg->macCellGrpCfg.schReqCfg);
12535          }
12536          if(macCellGroup->tag_Config)
12537          {
12538             extractTagReconfig(macCellGroup->tag_Config, &macUeCfg->macCellGrpCfg.tagCfg);
12539          }
12540          if(macCellGroup->bsr_Config)
12541          {
12542             macUeCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer = macCellGroup->bsr_Config->periodicBSR_Timer;
12543             macUeCfg->macCellGrpCfg.bsrTmrCfg.retxTimer     = macCellGroup->bsr_Config->retxBSR_Timer;
12544             if(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer)
12545             {
12546                macUeCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer  =\
12547                *(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer);
12548             }
12549          }
12550          if(macCellGroup->phr_Config)
12551          {
12552             if(macCellGroup->phr_Config->present == MAC_CellGroupConfig__phr_Config_PR_setup)
12553             {
12554                macUeCfg->macCellGrpCfg.phrCfgSetupPres = true;
12555                if(macCellGroup->phr_Config->choice.setup)
12556                {
12557                   macUeCfg->macCellGrpCfg.phrCfg.periodicTimer     = \
12558                   macCellGroup->phr_Config->choice.setup->phr_PeriodicTimer;
12559                   macUeCfg->macCellGrpCfg.phrCfg.prohibitTimer     = \
12560                   macCellGroup->phr_Config->choice.setup->phr_ProhibitTimer;
12561                   macUeCfg->macCellGrpCfg.phrCfg.txPowerFactor     = \
12562                   macCellGroup->phr_Config->choice.setup->phr_Tx_PowerFactorChange;
12563                   macUeCfg->macCellGrpCfg.phrCfg.multiplePHR       = \
12564                   macCellGroup->phr_Config->choice.setup->multiplePHR;
12565                   macUeCfg->macCellGrpCfg.phrCfg.dummy             = \
12566                   macCellGroup->phr_Config->choice.setup->dummy;
12567                   macUeCfg->macCellGrpCfg.phrCfg.phrType2OtherCell = \
12568                   macCellGroup->phr_Config->choice.setup->phr_Type2OtherCell;
12569                   macUeCfg->macCellGrpCfg.phrCfg.phrOtherCG        = \
12570                   macCellGroup->phr_Config->choice.setup->phr_ModeOtherCG;
12571                }
12572             }
12573          }
12574       }
12575       /* Fill Physical Cell Group Reconfig */
12576       if(cellGrp->physicalCellGroupConfig)
12577       {
12578          macUeCfg->phyCellGrpCfgPres = true;
12579          phyCellGrpCfg = ((PhysicalCellGroupConfig_t *)(cellGrp->physicalCellGroupConfig));
12580          if(phyCellGrpCfg->p_NR_FR1)
12581          {
12582             if(*(phyCellGrpCfg->p_NR_FR1) != macUeCfg->phyCellGrpCfg.pNrFr1)
12583                macUeCfg->phyCellGrpCfg.pNrFr1 = *(phyCellGrpCfg->p_NR_FR1);
12584          }
12585          macUeCfg->phyCellGrpCfg.pdschHarqAckCodebook = phyCellGrpCfg->pdsch_HARQ_ACK_Codebook;
12586       }
12587       /* Fill SpCell Reconfig */
12588       if(cellGrp->spCellConfig)
12589       {
12590          macUeCfg->spCellCfgPres = true;
12591          spcellCfg = ((SpCellConfig_t *)(cellGrp->spCellConfig));  
12592          if(spcellCfg->servCellIndex)
12593          {
12594             macUeCfg->spCellCfg.servCellIdx = *(spcellCfg->servCellIndex);
12595          }
12596          /* Fill Serving cell Reconfig info */
12597          if(cellGrp->spCellConfig->spCellConfigDedicated)
12598          {
12599             servCellCfg = ((ServingCellConfig_t *)(cellGrp->spCellConfig->spCellConfigDedicated));
12600             if(storedMacUeCfg)
12601             {
12602                if(!storedMacUeCfg->spCellCfgPres)
12603                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12604                else
12605                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg,\
12606                         &storedMacUeCfg->spCellCfg.servCellCfg);
12607             }
12608             else
12609             {
12610                ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12611             }
12612             if(ret == RFAILED)
12613             {
12614                DU_LOG("\nERROR --> F1AP : Failed at extractSpCellDedicatedCfg()");
12615             }
12616          }
12617       }
12618    }
12619    return ret;
12620 }
12621 /*******************************************************************
12622 *
12623 * @brief free the memory allocated by decoder
12624 *
12625 * @details
12626 *
12627 *    Function : freeAperDecodeNrcgi 
12628 *
12629 *    Functionality: Free Nrcgi values
12630 *
12631 * @params[in] NRCGI_t *nrcgi
12632 * @return void
12633 *
12634 * ****************************************************************/
12635
12636
12637 void freeAperDecodeNrcgi(NRCGI_t *nrcgi)
12638 {
12639     if(nrcgi->pLMN_Identity.buf != NULLP)
12640     {
12641        free(nrcgi->pLMN_Identity.buf);
12642     }
12643     if(nrcgi->nRCellIdentity.buf != NULLP)
12644     {
12645        free(nrcgi->nRCellIdentity.buf);
12646     }
12647 }
12648 /*******************************************************************
12649 *
12650 * @brief free the memory allocated by decoder
12651 *
12652 * @details
12653 *
12654 *    Function : freeAperDecodeCuToDuInfo 
12655 *
12656 *    Functionality:  Free Cu To Du Information
12657 *
12658 * @params[in] CUtoDURRCInformation_t *rrcMsg
12659 * @return void
12660 *
12661 * ****************************************************************/
12662
12663
12664 void freeAperDecodeCuToDuInfo(CUtoDURRCInformation_t *rrcMsg)
12665 {
12666    uint8_t ieIdx =0;
12667    uint8_t arrIdx =0;
12668
12669    if(rrcMsg->uE_CapabilityRAT_ContainerList)
12670    {
12671       if(rrcMsg->uE_CapabilityRAT_ContainerList->buf)
12672          free(rrcMsg->uE_CapabilityRAT_ContainerList->buf);
12673       free(rrcMsg->uE_CapabilityRAT_ContainerList);
12674    }
12675
12676    if(rrcMsg->iE_Extensions)
12677    {
12678       if(rrcMsg->iE_Extensions->list.array)
12679       {
12680          for(ieIdx= 0; ieIdx < rrcMsg->iE_Extensions->list.count; ieIdx++)
12681          {
12682             if(rrcMsg->iE_Extensions->list.array[ieIdx])
12683             {
12684                switch(rrcMsg->iE_Extensions->list.array[ieIdx]->id)
12685                {
12686                   case ProtocolIE_ID_id_CellGroupConfig:
12687                      if(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf != NULLP)
12688                      {
12689                         free(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf);
12690                      }
12691                      break;
12692                   default:
12693                      DU_LOG("\nERROR  -->  F1AP : Invalid Event type %ld at FreeCuToDuInfo()", \
12694                            rrcMsg->iE_Extensions->list.array[ieIdx]->id);
12695                      break;
12696                }
12697             }
12698          }
12699          for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
12700          {
12701             free(rrcMsg->iE_Extensions->list.array[arrIdx]);
12702          }
12703          free(rrcMsg->iE_Extensions->list.array);
12704
12705       }
12706
12707       free(rrcMsg->iE_Extensions);
12708    }
12709 }
12710 /*******************************************************************
12711 *
12712 * @brief free the memory allocated by decoder
12713 *
12714 * @details 
12715 *
12716 *    Function : freeAperDecodeSplCellList
12717 *
12718 *    Functionality: Free Spl Cell List 
12719                     where memory allocated by aper_decoder
12720 *
12721 * @params[in]  SCell_ToBeSetup_List_t *spCellLst
12722 * @return void
12723 *
12724 * ****************************************************************/
12725
12726
12727 void freeAperDecodeSplCellList(SCell_ToBeSetup_List_t *spCellLst)
12728 {
12729     uint8_t  cellIdx =0;
12730
12731     if(spCellLst->list.array != NULLP)
12732     {
12733        for(cellIdx=0; cellIdx<spCellLst->list.count; cellIdx++)
12734        {
12735           if(cellIdx==0&&spCellLst->list.array[cellIdx]!=NULLP)
12736           {
12737              freeAperDecodeNrcgi(&spCellLst->list.array[cellIdx]->value.choice.SCell_ToBeSetup_Item.sCell_ID);
12738           }
12739           if(spCellLst->list.array[cellIdx]!=NULLP)
12740           {
12741              free(spCellLst->list.array[cellIdx]);
12742           }
12743        }
12744        free(spCellLst->list.array);
12745     }
12746 }
12747 /*******************************************************************
12748 *
12749 * @brief free the memory allocated by decoder
12750 *
12751 * @details
12752 *
12753 *    Function : freeAperDecodeSRBSetup 
12754 *
12755 *    Functionality: added free part for the memory allocated by aper_decoder
12756 *
12757 * @params[in] SRBs_ToBeSetup_List_t *srbSet
12758 * @return void
12759 *
12760 ****************************************************************/
12761
12762
12763 void freeAperDecodeSRBSetup(SRBs_ToBeSetup_List_t *srbSet)
12764 {
12765     uint8_t srbIdx =0;
12766     if(srbSet->list.array != NULLP)
12767     {
12768        for(srbIdx=0; srbIdx<srbSet->list.count; srbIdx++)
12769        {
12770           if(srbSet->list.array[srbIdx]!=NULLP)
12771           {
12772              free(srbSet->list.array[srbIdx]);
12773           }
12774        }
12775        free(srbSet->list.array);
12776     }
12777 }
12778
12779 /*******************************************************************
12780 *
12781 * @brief free the memory allocated by decoder
12782 *
12783 * @details
12784 *
12785 *    Function : freeAperDecodeULTnlInfo
12786 *
12787 *    Functionality: added free part for the memory allocated by aper_decoder
12788 *
12789 * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
12790 * @return void
12791 *
12792 * ****************************************************************/
12793
12794
12795 void freeAperDecodeULTnlInfo(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
12796 {
12797    uint8_t ulIdx=0;
12798    if(ulInfo->list.array != NULLP)
12799    {
12800       for(ulIdx=0; ulIdx<ulInfo->list.count; ulIdx++)
12801       {
12802          if(ulIdx==0&&ulInfo->list.array[ulIdx]!=NULLP)
12803          {
12804             if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel!=NULLP)
12805             {
12806                if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12807                      transportLayerAddress.buf != NULLP)
12808                {
12809                   if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf\
12810                         !=NULLP)
12811                   {
12812                      free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf);
12813                   }
12814                   free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12815                         transportLayerAddress.buf);
12816                }
12817                free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel);
12818             }
12819          }
12820          if(ulInfo->list.array[ulIdx]!=NULLP)
12821          {
12822             free(ulInfo->list.array[ulIdx]);
12823          }
12824       }
12825       free(ulInfo->list.array);
12826    }
12827 }
12828 /*******************************************************************
12829 *
12830 * @brief free the memory allocated by decoder
12831 *
12832 * @details
12833 *
12834 *    Function : freeAperDecodeDRBSetup  
12835 *
12836 *    Functionality: free DRBSetup which is allocated by decoder
12837 *
12838 * @params[in]  DRBs_ToBeSetup_List_t *drbSet
12839 * @return void
12840 *
12841 * ****************************************************************/
12842
12843 void freeAperDecodeDRBSetup(DRBs_ToBeSetup_List_t *drbSet)
12844 {
12845    DRBs_ToBeSetup_Item_t *drbSetItem = NULLP;
12846    uint8_t  flowIdx =0;
12847    uint8_t  drbIdx =0;
12848
12849    if(drbSet->list.array != NULLP)
12850    {
12851       for(drbIdx=0; drbIdx<drbSet->list.count; drbIdx++)
12852       {
12853          if(drbIdx==0&&drbSet->list.array[drbIdx] != NULLP)
12854          {
12855             drbSetItem =&drbSet->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12856             if(drbSetItem->qoSInformation.choice.choice_extension != NULLP)
12857             {
12858                if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12859                      qoS_Characteristics.choice.non_Dynamic_5QI !=NULLP)
12860                {
12861                   if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12862                         qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12863                   {
12864                      if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12865                            qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12866                      {
12867
12868                         if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf!=NULLP)
12869                         {
12870
12871                            if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD!=NULLP)
12872                            {
12873
12874                               if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD->\
12875                                     buf!=NULLP)
12876                               {
12877
12878                                  if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.\
12879                                        flows_Mapped_To_DRB_List.list.array != NULLP)
12880                                  {
12881
12882                                     for(flowIdx=0;flowIdx<drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12883                                           DRB_Information.flows_Mapped_To_DRB_List.list.count; flowIdx++)
12884                                     {
12885
12886                                        if(flowIdx==0&&drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12887                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12888                                        {
12889                                           if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12890                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12891                                                 qoSFlowLevelQoSParameters.\
12892                                                 qoS_Characteristics.choice.non_Dynamic_5QI!=NULLP)
12893                                           {
12894                                              if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12895                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12896                                                    qoSFlowLevelQoSParameters.\
12897                                                    qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12898                                              {
12899
12900                                                 if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12901                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12902                                                       qoSFlowLevelQoSParameters.\
12903                                                       qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12904                                                 {
12905
12906
12907                                                    free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12908                                                          DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12909                                                          qoSFlowLevelQoSParameters.\
12910                                                          qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12911                                                 }
12912
12913                                                 free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12914                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12915                                                       qoSFlowLevelQoSParameters.\
12916                                                       qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12917                                              }
12918
12919                                              free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12920
12921                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12922                                                    qoSFlowLevelQoSParameters.\
12923                                                    qoS_Characteristics.choice.non_Dynamic_5QI);
12924                                           }
12925                                        }
12926                                        if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12927                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12928                                        {
12929
12930                                           free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12931                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]);
12932                                        }
12933                                     }
12934
12935                                     free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12936                                           DRB_Information.flows_Mapped_To_DRB_List.list.array);
12937                                  }
12938
12939                                  free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12940                                        DRB_Information.sNSSAI.sD->buf);
12941                               }
12942
12943                               free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD);
12944                            }
12945
12946                            free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf);
12947
12948                         }
12949
12950                         free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12951
12952                               qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12953                      }
12954
12955                      free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12956                            qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12957                   }
12958
12959                   free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12960                         qoS_Characteristics.choice.non_Dynamic_5QI);
12961                }
12962                free(drbSetItem->qoSInformation.choice.choice_extension);
12963             }
12964             freeAperDecodeULTnlInfo(&drbSetItem->uLUPTNLInformation_ToBeSetup_List);
12965             if(drbSetItem->uLConfiguration)
12966             {
12967                free(drbSetItem->uLConfiguration);
12968             }
12969          }
12970          if(drbSet->list.array[drbIdx]!=NULLP)
12971          {
12972             free(drbSet->list.array[drbIdx]);
12973          }
12974       }
12975       free(drbSet->list.array);
12976    }
12977 }
12978
12979
12980 /*******************************************************************
12981  *
12982  * @brief builds Mac Cell Cfg
12983  *
12984  * @details
12985  *
12986  *    Function : procUeRecfgCellInfo
12987  *
12988  *    Functionality: builds Mac Cell Cfg
12989  *
12990  * @params[in] DuMacUeCfg *macUeCfgToSend = Used to Store the information which
12991  *                       needs to send in other layer, as well as this can be
12992  *                       the variable which stores the information in DuCb.
12993  *             DuMacUeCfg *storedMacUeCfg = Null in case of sending the
12994  *                       information to other layer else it will have copyOfmacUeCfg  
12995  *                       which we have stored in F1UeContextSetupDb
12996  *             void *cellInfo = CellGroupConfigRrc_t information which is send
12997  *                        by CU, which we have stored in F1UeContextSetupDb 
12998  *
12999  * @return void 
13000  *
13001  * ****************************************************************/
13002 uint8_t procUeRecfgCellInfo(DuMacUeCfg *macUeCfgToSend, DuMacUeCfg *storedMacUeCfg, void *cellInfo)
13003 {
13004    uint8_t ret = ROK;
13005    CellGroupConfigRrc_t *cellGrp = NULLP;
13006
13007    if(cellInfo)
13008    {
13009       cellGrp = (CellGroupConfigRrc_t *)cellInfo;
13010       ret = extractUeRecfgCellInfo(cellGrp, macUeCfgToSend, storedMacUeCfg);
13011       if(ret == RFAILED)
13012          DU_LOG("\nERROR  -->  F1AP : Failed at procUeRecfgCellInfo()");
13013    }
13014    if(ret == RFAILED)
13015    {
13016       freeUeRecfgCellGrpInfo(macUeCfgToSend);
13017    }
13018    return ret;
13019 }
13020
13021 /*******************************************************************
13022  *
13023  * @brief Filling modulation info in mac ue cfg
13024  *
13025  * @details
13026  *
13027  *    Function : duFillModulationDetails
13028  *
13029  *    Functionality: Filling modulation info in mac ue cfg
13030  *
13031  * @params[in] MAC UE Config to be updated
13032  *             Current UE configuration
13033  *             UE NR capability from CU
13034  * @return ROK     - success
13035  *         RFAILED - failure
13036  *
13037  * ****************************************************************/
13038 void duFillModulationDetails(DuMacUeCfg *ueCfg, DuMacUeCfg *oldUeCfg, void *ueCap)
13039 {
13040    UE_NR_Capability_t *ueNrCap=NULLP;
13041
13042    if(!ueCap && oldUeCfg)
13043    {
13044       memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));     
13045       memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13046    }
13047    else
13048    {
13049       ueNrCap = (UE_NR_Capability_t *)ueCap;
13050
13051       /* Filling DL modulation info */
13052       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsDownlinkPerCC && \
13053          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0] && \
13054          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL)
13055       {
13056          switch(*(ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL))
13057          {
13058             case ModulationOrder_qpsk:
13059                {
13060                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
13061                   break;
13062                }
13063             case ModulationOrder_qam16:
13064                {
13065                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM16;
13066                   break;
13067                }
13068             case ModulationOrder_qam64:
13069                {
13070                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM64;
13071                   ueCfg->dlModInfo.mcsIndex = PDSCH_MCS_INDEX;
13072                   ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64;
13073                   break;
13074                }
13075             case ModulationOrder_qam256:
13076                {
13077                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM256;
13078                   break;
13079                }
13080             default:
13081                {
13082                   DU_LOG("\nERROR  -->  DU APP: Incorrect downlink modulation order received. Reatining old modulation configuration");
13083                   if(oldUeCfg)
13084                      memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
13085                   break;
13086                }
13087          }
13088       }
13089       else
13090       {
13091          if(oldUeCfg)
13092             memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
13093       }
13094
13095       /* Filling UL modulation info */
13096       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsUplinkPerCC && \
13097          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0] && \
13098          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL)
13099       {
13100          switch(*(ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL))
13101          {
13102             case ModulationOrder_qpsk:
13103                {
13104                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
13105                   break;
13106                }
13107             case ModulationOrder_qam16:
13108                {
13109                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM16;
13110                   ueCfg->ulModInfo.mcsIndex = PUSCH_MCS_INDEX;
13111                   ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64;
13112                   break;
13113                }
13114             case ModulationOrder_qam64:
13115                {
13116                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM64;
13117                   break;
13118                }
13119             case ModulationOrder_qam256:
13120                {
13121                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM256;
13122                   break;
13123                }
13124             default:
13125                {
13126                   DU_LOG("\nERROR  -->  DU APP: Incorrect uplink modulation order received. Reatining old modulation configuration");
13127                   if(oldUeCfg)
13128                      memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13129                   break;
13130                }
13131          }
13132       }
13133       else
13134       {
13135          if(oldUeCfg)
13136             memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
13137       }
13138    }
13139 }
13140
13141 /*******************************************************************
13142  *
13143  * @brief Function to extract info from CU to DU RRC container extension
13144  *
13145  * @details
13146  *
13147  *    Function : extractCuToDuRrcInfoExt
13148  *
13149  *    Functionality: Function to extract info from CU to DU RRC container
13150  *    extension
13151  *
13152  * @params[in] ProtocolExtensionContainer_4624P16_t pointer
13153  *
13154  * @return ROK
13155  *         RFAILED
13156  *
13157  * ****************************************************************/
13158 uint8_t extractCuToDuRrcInfoExt(ProtocolExtensionContainer_4624P16_t *protocolIeExtn, DuUeCfg *ueCfgDb)
13159 {
13160    uint8_t ieIdx =0;
13161    uint16_t recvBufLen =0;
13162    CellGroupConfigRrc_t *cellGrpCfg = NULLP;
13163    CUtoDURRCInformation_ExtIEs_t *extIeInfo = NULLP;
13164    asn_dec_rval_t rval; /* Decoder return value */
13165    memset(&rval, 0, sizeof(asn_dec_rval_t));
13166
13167    if(protocolIeExtn)
13168    {
13169       for(ieIdx = 0; ieIdx < protocolIeExtn->list.count; ieIdx++)
13170       {
13171          extIeInfo = ((CUtoDURRCInformation_ExtIEs_t *)(protocolIeExtn->list.array[ieIdx]));
13172          switch(extIeInfo->id)
13173          {
13174             case ProtocolIE_ID_id_CellGroupConfig:
13175                {
13176                   /* decoding the CellGroup Buf received */
13177                   recvBufLen = extIeInfo->extensionValue.choice.CellGroupConfig.size;
13178                   DU_ALLOC(cellGrpCfg, sizeof(CellGroupConfigRrc_t));
13179                   if(cellGrpCfg)
13180                   {
13181                      memset(cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
13182                      rval = uper_decode(0, &asn_DEF_CellGroupConfigRrc, (void **)&cellGrpCfg,
13183                            extIeInfo->extensionValue.choice.CellGroupConfig.buf, recvBufLen, 0, 0);
13184                      if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13185                      {
13186                         DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13187                         return RFAILED;
13188                      }
13189                      xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, cellGrpCfg);
13190
13191                      if(extractRlcCfgToAddMod(cellGrpCfg->rlc_BearerToAddModList, ueCfgDb))
13192                         return NULLP;
13193                      ueCfgDb->cellGrpCfg = cellGrpCfg;
13194                   }
13195                   break;
13196                }
13197
13198             case ProtocolIE_ID_id_HandoverPreparationInformation:
13199                {
13200                   DU_LOG("\nINFO -->  F1AP : Received HANDOVER PREPARATION INFO in UE CONTEXT SETUP REQUEST");
13201                   break;
13202                }
13203
13204             default:
13205                DU_LOG("\nERROR  -->  F1AP : Invalid IE received CUtoDURRCInformation: %ld at decodeCellGrpCfg()", extIeInfo->id);
13206                break;
13207          }
13208       }
13209    }
13210    return ROK;
13211 }
13212
13213 /*******************************************************************
13214  *
13215  * @brief Fills Srb List received by CU
13216  *
13217  * @details
13218  *
13219  *    Function : procSrbListToSetup
13220  *
13221  *    Functionality: Fills Srb List received  by CU
13222  *
13223  * @params[in] SRBs_ToBeSetup_Item_t *cuSrbItem
13224  *             DuLcCfg pointer
13225  *             RlcBearerCfg pointer
13226  * @return void
13227  *
13228  * ****************************************************************/
13229 uint8_t procSrbListToSetup(SRBs_ToBeSetup_Item_t * srbItem, DuLcCfg *duMacLcToAdd, DuRlcBearerCfg *rlcLcToAdd)
13230 {
13231
13232    /* Filling RLC INFO */
13233    procRlcLcCfg(srbItem->sRBID, srbItem->sRBID, RB_TYPE_SRB, RLC_AM, CONFIG_ADD, NULL, rlcLcToAdd, NULL);
13234
13235    /* Filling MAC INFO */
13236    if(procMacLcCfg(srbItem->sRBID, RB_TYPE_SRB, CONFIG_ADD, NULL,NULL, NULL, NULL, duMacLcToAdd, NULL)  != ROK)
13237    { 
13238       DU_LOG("\nERROR  -->  F1AP : Failed at MAC LC Cfg in procSrbListToSetup()");
13239       return RFAILED;
13240    }
13241
13242    return ROK;
13243 }
13244
13245
13246
13247 /*******************************************************************
13248  *
13249  * @brief extract Srb List received by CU
13250  *
13251  * @details
13252  *
13253  *    Function : extractSrbListToSetup
13254  *
13255  *    Functionality: extract Srb List received by CU
13256  *                   for both MAC and RLC
13257  *
13258  * @params[in] SRBs_ToBeSetup_Item_t pointer
13259  *             DuUeCfg pointer
13260  * @return ROK/RFAIED
13261  *
13262  * ****************************************************************/
13263
13264 uint8_t extractSrbListToSetup(SRBs_ToBeSetup_List_t *srbCfg, DuUeCfg *ueCfgDb)
13265 {
13266    uint8_t ret = ROK, srbIdx = 0, rlcLcIdx = 0;
13267    SRBs_ToBeSetup_Item_t *srbItem = NULLP;
13268    DuLcCfg *macLcCtxt = NULLP;
13269    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13270
13271    if(srbCfg)
13272    {
13273       for(srbIdx = 0; srbIdx < srbCfg->list.count; srbIdx++)
13274       {
13275          macLcCtxt = NULL;
13276          rlcLcCtxt = NULL;
13277
13278          srbItem = &srbCfg->list.array[srbIdx]->value.choice.SRBs_ToBeSetup_Item;
13279          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13280          { 
13281             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in MAC");
13282             ret = RFAILED;
13283             break;
13284          }
13285          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13286          {
13287             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in RLC");
13288             ret = RFAILED;
13289             break;
13290          }
13291
13292          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numMacLcs; rlcLcIdx++)
13293          {
13294             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == srbItem->sRBID && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
13295             {
13296                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13297                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13298                break;
13299             }
13300          }
13301          if(!macLcCtxt)
13302          {
13303             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13304             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13305             ueCfgDb->numMacLcs++;
13306          }
13307          if(!rlcLcCtxt)
13308          {
13309             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13310             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13311             ueCfgDb->numRlcLcs++;
13312          }
13313
13314          ret = procSrbListToSetup(srbItem, macLcCtxt, rlcLcCtxt);
13315
13316          DU_LOG("\nDEBUG --> DUAPP: extractSrbListToSetup: SRBID: %ld [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13317                srbItem->sRBID, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13318          if(ret == RFAILED)
13319          {
13320             DU_LOG("\nERROR  -->  F1AP:  Failed at extractSrbListToSetup()");
13321             break;
13322          }
13323       }
13324    }
13325    else
13326       ret = RFAILED;
13327
13328    return ret;
13329 }
13330
13331 /*******************************************************************
13332  *
13333  * @brief Fills Drb List received by CU
13334  *
13335  * @details
13336  *
13337  *    Function : procDrbListToSetupMod
13338  *
13339  *    Functionality: Fills Drb List received by CU
13340  *                   for both MAC and RLC
13341  *
13342  * @params[in] DRBs_ToBeSetup_Item_t , DRBs_ToBeSetupMod_Item_t,
13343  *             DRBs_ToBeModified_Item_t , lcId, DuLcCfg pointer,
13344  *             RlcBearerCfg , UpTnlCfg, DuRlcUeCfg
13345  * @return void
13346  *
13347  * ****************************************************************/
13348
13349 uint8_t procDrbListToSetupMod(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbItem,\
13350 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, DuLcCfg *macLcToAdd, DuRlcBearerCfg *rlcLcToAdd, UpTnlCfg *upTnlInfo, DuRlcUeCfg *storedRlcUeCfg)
13351 {
13352    uint8_t cfgIdx = 0;
13353    RlcMode rlcModeInfo;
13354
13355    if(drbItem != NULLP)
13356    {
13357       /* Filling RLC INFO */
13358       procRlcLcCfg(drbItem->dRBID, lcId, RB_TYPE_DRB, drbItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, &drbItem->\
13359       qoSInformation);
13360
13361       /* Filling MAC INFO */
13362       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, drbItem, NULL, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13363       { 
13364          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13365          return RFAILED;
13366       }
13367    }
13368    else if(drbSetupModItem != NULLP)
13369    {
13370       procRlcLcCfg(drbSetupModItem->dRBID, lcId, RB_TYPE_DRB, drbSetupModItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, 
13371       &drbSetupModItem->qoSInformation);
13372
13373       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, NULL, drbSetupModItem, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13374       {
13375          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13376          return RFAILED;
13377       }
13378    }
13379    else if(drbModItem != NULLP)
13380    {
13381       /* Drb to Mod IEs doesnot have rlcMode to be modified
13382        * in ASN. Hence no change in RLC configurations */
13383       if(storedRlcUeCfg != NULLP)
13384       {
13385          for(cfgIdx = 0; cfgIdx < storedRlcUeCfg->numLcs; cfgIdx++)
13386          {
13387             if(storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.lcId == lcId)
13388             {
13389                rlcModeInfo = storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcBearerCfg.rlcMode;
13390                break;
13391             }
13392          }
13393       }
13394
13395       procRlcLcCfg(drbModItem->dRBID, lcId, RB_TYPE_DRB, rlcModeInfo, CONFIG_MOD, NULL, rlcLcToAdd, drbModItem->qoSInformation);
13396       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_MOD, NULL, NULL, drbModItem, NULL, macLcToAdd, upTnlInfo) != ROK)
13397       {
13398          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13399          return RFAILED;
13400       }
13401    }
13402    return ROK;
13403 }
13404
13405 /*******************************************************************
13406  *
13407  * @brief extract Drb List received by CU
13408  *
13409  * @details
13410  *
13411  *    Function : extractDrbListToSetupMod
13412  *
13413  *    Functionality: extract Drb List received by CU
13414  *                   for both MAC and RLC
13415  *
13416  * @params[in] DRBs_ToBeSetup_Item_t pointer
13417  *             DuUeCfg pointer
13418  * @return ROK/RFAIED
13419  *
13420  * ****************************************************************/
13421
13422 uint8_t extractDrbListToSetupMod(DRBs_ToBeSetup_List_t *drbCfg, DRBs_ToBeSetupMod_List_t *drbSetupModCfg,\
13423  DRBs_ToBeModified_List_t *drbModCfg, uint8_t drbCount, DuUeCfg *ueCfgDb, uint32_t *drbBitMap, DuRlcUeCfg *rlcUeCfg)
13424 {
13425    uint8_t ret = ROK;
13426    uint8_t drbIdx = 0, rlcLcIdx = 0;
13427    uint8_t drbId = 0, lcId = 0;
13428    DRBs_ToBeSetup_Item_t *drbItem = NULLP;
13429    DRBs_ToBeSetupMod_ItemIEs_t *drbSetupModItem = NULLP;
13430    DRBs_ToBeModified_ItemIEs_t *drbModItem = NULLP;
13431    DuLcCfg *macLcCtxt = NULLP;
13432    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13433
13434    ret = ROK;
13435    if(drbCount > 0)
13436    {
13437       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13438       {
13439          macLcCtxt = NULL;
13440          rlcLcCtxt = NULL;
13441
13442          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13443          { 
13444             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in MAC at extractDrbListToSetupMod()");
13445             ret = RFAILED;
13446             break;
13447          }
13448          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13449          {
13450             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in RLC at extractDrbListToSetupMod()");
13451             ret = RFAILED;
13452             break;
13453          }
13454
13455          if(drbModCfg != NULLP)
13456          {
13457             drbModItem = (DRBs_ToBeModified_ItemIEs_t *) drbModCfg->list.array[drbIdx];
13458             drbId = drbModItem->value.choice.DRBs_ToBeModified_Item.dRBID;
13459          }
13460          else if(drbCfg != NULLP)
13461             drbId = drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item.dRBID;
13462          else if(drbSetupModCfg != NULL)
13463          {
13464             drbSetupModItem = (DRBs_ToBeSetupMod_ItemIEs_t *) drbSetupModCfg->list.array[drbIdx];
13465             drbId = drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item.dRBID;
13466          }
13467
13468          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13469          {
13470             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && \
13471                    ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13472             {
13473                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13474                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13475                break;
13476             }
13477          }
13478          if(!macLcCtxt)
13479          {
13480             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13481             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13482             ueCfgDb->numMacLcs++;
13483          }
13484          if(!rlcLcCtxt)
13485          {
13486             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
13487             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13488             ueCfgDb->numRlcLcs++;
13489          }
13490
13491          if(drbModCfg != NULLP)
13492          {
13493             lcId = fetchLcId(drbId);
13494             if(lcId < MIN_DRB_LCID)
13495             {
13496                DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToSetupMod() for Modified List", lcId);
13497                break;
13498             } 
13499             ret = procDrbListToSetupMod(lcId, NULL, NULL, &(drbModItem->value.choice.DRBs_ToBeModified_Item),\
13500             macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13501             if(ret == RFAILED)
13502             {
13503                DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for Modified List");
13504                break;
13505             }
13506             ueCfgDb->numDrbModified++;
13507          }
13508          else
13509          {
13510             lcId = getDrbLcId(drbBitMap);
13511             if(lcId == RFAILED)
13512             {
13513                DU_LOG("\nERROR  -->  F1AP :  InCorrect LCID extractDrbListToSetupMod()");
13514                ret = RFAILED;
13515                break;
13516             }
13517             if(drbCfg != NULL)
13518             {
13519                drbItem = &drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
13520                ret = procDrbListToSetupMod(lcId, drbItem, NULL, NULL, macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13521                if(ret == RFAILED)
13522                {
13523                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetup List");
13524                   break;
13525                }
13526             }
13527             else if(drbSetupModCfg != NULL)
13528             {
13529                ret = procDrbListToSetupMod(lcId, NULL, &(drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item), NULL,\
13530                      macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13531                if(ret == RFAILED)
13532                {
13533                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetupMod List");
13534                   break;
13535                }
13536                ueCfgDb->numDrbSetupMod++;
13537             }
13538          }
13539          ueCfgDb->numDrb++;
13540  
13541          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToSetupMod:lcId:%x ,BitMap:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13542                             lcId,*drbBitMap, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13543          if(ret == RFAILED)
13544          {
13545             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod()");
13546             break;
13547          }
13548       }
13549    }
13550    else
13551       ret = RFAILED;
13552
13553    return ret;
13554 }
13555
13556 /*******************************************************************
13557  *
13558  * @brief extract Drb List received from CU
13559  *
13560  * @details
13561  *
13562  *    Function : extractDrbListToRelease
13563  *
13564  *    Functionality: extract Drb List received from CU
13565  *                   for both MAC and RLC
13566  *
13567  * @params[in] DRBs_ToBeReleased_Item_t pointer
13568  *             DuUeCfg pointer
13569  * @return ROK/RFAIED
13570  *
13571  * ****************************************************************/
13572
13573 uint8_t extractDrbListToRelease(uint8_t ueId, DRBs_ToBeReleased_List_t *drbToRel, uint8_t drbCount, DuUeCfg *ueCfgDb, DuRlcUeCfg *rlcUeCfg)
13574 {
13575    uint8_t ret = ROK, teIdx = 0;
13576    uint8_t drbIdx = 0, rlcLcIdx = 0;
13577    uint8_t drbId = 0, lcId = 0;
13578    DRBs_ToBeReleased_ItemIEs_t *drbRelItem = NULLP;
13579    DuLcCfg *macLcCtxt = NULLP;
13580    DuRlcBearerCfg *rlcLcCtxt = NULLP;
13581
13582    ret = ROK;
13583    if(drbCount > 0)
13584    {
13585       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13586       {
13587          macLcCtxt = NULL;
13588          rlcLcCtxt = NULL;
13589
13590          if(drbToRel != NULLP)
13591          {
13592             drbRelItem = (DRBs_ToBeReleased_ItemIEs_t *) drbToRel->list.array[drbIdx];
13593             drbId = drbRelItem->value.choice.DRBs_ToBeReleased_Item.dRBID;
13594          }
13595          else
13596          {
13597             DU_LOG("ERROR  --> DU APP : DrbToRelease pointer is NULL in extractDrbListToRelease");
13598             return RFAILED;
13599          }
13600
13601          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13602          {
13603             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbId == drbId && ueCfgDb->rlcLcCfg[rlcLcIdx].rlcBearerCfg.rbType == RB_TYPE_DRB)
13604             {
13605                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13606                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13607                break;
13608             }
13609          }
13610
13611          if(!macLcCtxt)
13612          {
13613             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(DuLcCfg));
13614             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13615             ueCfgDb->numMacLcs++;
13616          }
13617          if(!rlcLcCtxt)
13618          {
13619             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(DuRlcBearerCfg));
13620             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13621             ueCfgDb->numRlcLcs++;
13622          }
13623          lcId = fetchLcId(drbId);
13624          if(lcId < MIN_DRB_LCID)
13625          {
13626             DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToRelease() for Modified List", lcId);
13627             break;
13628          } 
13629
13630          /* Filling RLC INFO */
13631          procRlcLcCfg(drbId, lcId, RB_TYPE_DRB, rlcLcCtxt->rlcBearerCfg.rlcMode, CONFIG_DEL, NULL, rlcLcCtxt, NULLP);
13632          /* Filling MAC INFO */
13633          if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_DEL, NULL, NULL, NULL, NULL, macLcCtxt, NULLP) != ROK)
13634          { 
13635             DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in extractDrbListToRelease()");
13636             return RFAILED;
13637          }
13638          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].configType = CONFIG_DEL;
13639          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId = drbId;
13640          ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId = ueId;
13641
13642          for(teIdx = 0; teIdx < duCb.numTeId; teIdx++)
13643          {
13644             if((duCb.upTnlCfg[teIdx]->ueId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].ueId) && \
13645                   (duCb.upTnlCfg[teIdx]->drbId == ueCfgDb->upTnlInfo[ueCfgDb->numDrb].drbId))
13646             {
13647                DU_ALLOC(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, sizeof(GtpTnlCfg)); 
13648                memcpy(ueCfgDb->upTnlInfo[ueCfgDb->numDrb].tnlCfg1, duCb.upTnlCfg[teIdx]->tnlCfg1, sizeof(GtpTnlCfg));
13649                break;
13650             }
13651          }
13652
13653          ueCfgDb->numDrb++;
13654          if(ret == RFAILED)
13655          {
13656             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToRelease() for Modified List");
13657             break;
13658          }
13659
13660          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToRelease():lcId:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13661                lcId,ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13662       }
13663    }
13664    else
13665       ret = RFAILED;
13666
13667    return ret;
13668 }
13669
13670 /*******************************************************************
13671  *
13672  * @brief Function to extract Dl RRC Msg received from CU
13673  *
13674  * @details
13675  *
13676  *    Function : extractDlRrcMsg
13677  *
13678  *    Functionality: Function to extract Dl RRC Msg received from CU
13679  *
13680  * @params[in] F1AP message
13681  * @return ROK     - success
13682  *         RFAILED - failure
13683  *
13684  * ****************************************************************/
13685
13686 uint8_t extractDlRrcMsg(uint32_t gnbDuUeF1apId, uint32_t gnbCuUeF1apId, \
13687    F1DlRrcMsg *dlRrcMsg, RRCContainer_t *rrcContainer)
13688 {
13689    uint8_t ret = ROK;
13690    dlRrcMsg->rrcMsgSize = rrcContainer->size;
13691    if(dlRrcMsg->rrcMsgSize > 0)
13692    {
13693       DU_ALLOC_SHRABL_BUF(dlRrcMsg->rrcMsgPdu, dlRrcMsg->rrcMsgSize);
13694       if(!dlRrcMsg->rrcMsgPdu)
13695       {
13696          DU_LOG("\nERROR  --> DU APP : Memory allocation failed for RRC Msg in extractDlRrcMsg()");
13697          ret = RFAILED;
13698       }
13699       else
13700       {
13701          dlRrcMsg->gnbDuUeF1apId = gnbDuUeF1apId;
13702          dlRrcMsg->gnbCuUeF1apId = gnbCuUeF1apId;
13703          dlRrcMsg->srbId = SRB1_LCID;
13704          memcpy(dlRrcMsg->rrcMsgPdu, rrcContainer->buf, dlRrcMsg->rrcMsgSize);
13705       }
13706    }
13707    return ret;
13708 }
13709
13710 /*******************************************************************
13711  *
13712  * @brief Extract UE capability info 
13713  *
13714  * @details
13715  *
13716  *    Function : extractUeCapability
13717  *
13718  *    Functionality: Extract UE capability info and stores in ue Cb
13719  *
13720  * @params[in] Octet string of UE capability RAT container list
13721  * @return ROK     - success
13722  *         RFAILED - failure
13723  *
13724  * ****************************************************************/
13725 UE_NR_Capability_t *extractUeCapability(UE_CapabilityRAT_ContainerList_t *ueCapablityListBuf, DuUeCb *ueCb)
13726 {
13727    uint8_t  idx;
13728    uint16_t recvBufLen;
13729    asn_dec_rval_t rval;
13730    UE_NR_Capability_t  *ueNrCap = NULLP;
13731    UE_CapabilityRAT_ContainerListRRC_t  *ueCapRatContList = NULLP;
13732
13733    /* Decoding UE Capability RAT Container List */
13734    recvBufLen = ueCapablityListBuf->size;
13735    DU_ALLOC(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13736    if(!ueCapRatContList)
13737    {
13738       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13739       return NULLP;
13740    }
13741    memset(ueCapRatContList, 0, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13742    memset(&rval, 0, sizeof(asn_dec_rval_t));
13743    rval = uper_decode(0, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, (void **)&ueCapRatContList,
13744           ueCapablityListBuf->buf, recvBufLen, 0, 0);
13745    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13746    {
13747       DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13748       return NULLP;
13749    }
13750    xer_fprint(stdout, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, ueCapRatContList);
13751
13752    /* Free encoded buffer after decoding */
13753
13754    for(idx = 0; idx < ueCapRatContList->list.count; idx++)
13755    {
13756       if(ueCapRatContList->list.array[idx]->rat_Type == RAT_Type_nr)
13757       {
13758          /* Decoding UE NR Capability */
13759           recvBufLen = ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.size;
13760           DU_ALLOC(ueNrCap, sizeof(UE_NR_Capability_t));
13761           if(!ueNrCap)
13762           {
13763              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13764              DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13765              return NULLP;
13766           } 
13767           memset(ueNrCap, 0, sizeof(UE_NR_Capability_t));
13768           memset(&rval, 0, sizeof(asn_dec_rval_t));
13769           rval = uper_decode(0, &asn_DEF_UE_NR_Capability, (void **)&ueNrCap,
13770                  ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf, recvBufLen, 0, 0);
13771           if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13772           {
13773              DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13774              return NULLP;
13775           }
13776           xer_fprint(stdout, &asn_DEF_UE_NR_Capability, ueNrCap);
13777           
13778           /* Free encoded buffer after decoding */
13779           free(ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf);
13780       }
13781       free(ueCapRatContList->list.array[idx]);
13782    }
13783
13784    /* Free Memory*/
13785    free(ueCapRatContList->list.array);
13786    DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13787    return ueNrCap;
13788 }
13789  
13790 /*******************************************************************
13791 *
13792 * @brief free UE context setup request from CU
13793 *
13794 * @details
13795 *
13796 *    Function : freeAperDecodeF1UeContextSetupReq
13797 *
13798 *    Functionality: freeing part for the memory allocated by aper_decoder
13799 *
13800 * @params[in] F1AP message
13801 * @return ROK     - success
13802 *         RFAILED - failure
13803 *
13804 * ****************************************************************/
13805 void freeAperDecodeF1UeContextSetupReq(UEContextSetupRequest_t   *ueSetReq)
13806 {
13807    uint8_t ieIdx = 0;
13808
13809    if(ueSetReq->protocolIEs.list.array != NULLP)
13810    {
13811       for(ieIdx = 0; ieIdx < ueSetReq->protocolIEs.list.count; ieIdx++)
13812       {
13813          if(ueSetReq->protocolIEs.list.array[ieIdx])
13814          {
13815             switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13816             {
13817                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13818                   break;
13819                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13820                   break;
13821                case ProtocolIE_ID_id_SpCell_ID:
13822                   freeAperDecodeNrcgi(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
13823                   break;
13824                case ProtocolIE_ID_id_ServCellIndex:
13825                   break;
13826                case ProtocolIE_ID_id_SpCellULConfigured:
13827                   break;
13828                case ProtocolIE_ID_id_CUtoDURRCInformation:
13829
13830                   freeAperDecodeCuToDuInfo(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation);
13831                   break;
13832                case ProtocolIE_ID_id_SCell_ToBeSetup_List:
13833
13834                   freeAperDecodeSplCellList(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SCell_ToBeSetup_List);
13835                   break;
13836                case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
13837
13838                   freeAperDecodeSRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List);
13839                   break;
13840                case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
13841
13842                   freeAperDecodeDRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List);
13843                   break;
13844                case ProtocolIE_ID_id_RRCContainer:
13845                   {
13846
13847                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf != NULLP)
13848                      {
13849
13850                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
13851                      }
13852                      break;
13853                   }
13854                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13855                   break;
13856                case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
13857                   {
13858                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf)
13859                      {
13860                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf);
13861                      }
13862                      break;
13863                   }
13864 #ifdef NR_DRX
13865                case ProtocolIE_ID_id_DRXCycle:
13866                   {
13867                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength)
13868                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleLength);
13869                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer)
13870                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle.shortDRXCycleTimer);
13871                      break;
13872                   }
13873 #endif             
13874                 default:
13875                   DU_LOG("\nERROR  -->  F1AP: Invalid event type %ld " ,ueSetReq->protocolIEs.list.array[ieIdx]->id);
13876             } 
13877             free(ueSetReq->protocolIEs.list.array[ieIdx]);
13878          }
13879       }
13880       free(ueSetReq->protocolIEs.list.array);
13881    }
13882 }
13883 /*******************************************************************
13884  *
13885  * @brief Process UE context setup request from CU
13886  *
13887  * @details
13888  *
13889  *    Function : procF1UeContextSetupReq
13890  *
13891  *    Functionality: Process UE context setup request from CU
13892  *
13893  * @params[in] F1AP message
13894  * @return ROK     - success
13895  *         RFAILED - failure
13896  *
13897  * ****************************************************************/
13898 uint8_t procF1UeContextSetupReq(F1AP_PDU_t *f1apMsg)
13899 {
13900    int8_t ueIdx = -1;
13901    uint8_t  ret=0, ieIdx=0, ieExtIdx = 0;
13902    //uint8_t servCellIdx = 0;
13903    bool ueCbFound = false, hoInProgress = false;
13904    uint16_t cellIdx=0;
13905    uint64_t nrCellId = 0;
13906    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0, bitRateSize=0;
13907    DuUeCb   *duUeCb = NULL;
13908    UEContextSetupRequest_t   *ueSetReq = NULL;
13909    DRBs_ToBeSetup_List_t *drbCfg = NULL;
13910    CUtoDURRCInformation_t *rrcInfo = NULL;
13911 #ifdef NR_DRX
13912    DRXCycle_t *drxCycle;
13913 #endif
13914    ret = ROK;
13915
13916    ueSetReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextSetupRequest;
13917    for(ieIdx=0; (ieIdx < ueSetReq->protocolIEs.list.count && ret == ROK); ieIdx++)
13918    {
13919       switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13920       {
13921          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13922             {
13923                gnbCuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
13924                break;
13925             }
13926
13927          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13928             {
13929                gnbDuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
13930                break;
13931             }
13932
13933          case ProtocolIE_ID_id_SpCell_ID:
13934             {
13935                bitStringToInt(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity, &nrCellId);
13936
13937                GET_CELL_IDX(nrCellId, cellIdx);
13938                if(!duCb.actvCellLst[cellIdx])
13939                {
13940                   DU_LOG("\nERROR  -->  F1AP : Cell Id [%lu] not found", nrCellId);
13941                   ret = RFAILED;
13942                }
13943                break;
13944             }
13945
13946          case ProtocolIE_ID_id_ServCellIndex:
13947             {
13948                //servCellIdx = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.ServCellIndex;
13949                break;
13950             }
13951
13952          case ProtocolIE_ID_id_SpCellULConfigured:
13953             {
13954                /* Indicates whether the gNB-CU requests the gNB-DU to configure the uplink as no UL, 
13955                   UL, SUL or UL+SUL for the indicated cell for the UE */
13956                break;
13957             }
13958
13959          case ProtocolIE_ID_id_CUtoDURRCInformation:
13960             {
13961                rrcInfo = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation;
13962
13963                /* Search if UE context is present */
13964                for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
13965                {
13966                   if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId)
13967                   {
13968                      ueCbFound = true;
13969                      duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13970                      break;
13971                   }
13972                }
13973
13974                /* Check if UE Handover scenario */
13975                if(rrcInfo->iE_Extensions)
13976                {
13977                   for(ieExtIdx = 0; ieExtIdx < rrcInfo->iE_Extensions->list.count; ieExtIdx++)
13978                   {
13979                      if(rrcInfo->iE_Extensions->list.array[ieExtIdx]->id == ProtocolIE_ID_id_HandoverPreparationInformation)
13980                      {
13981                         hoInProgress = true;
13982                         break;
13983                      }
13984                   }
13985                }
13986                
13987                /* If UE context is not present, but UE is in handover */
13988                if(!ueCbFound && hoInProgress)
13989                {
13990                   ueIdx = getFreeBitFromUeBitMap(nrCellId);
13991                   if(ueIdx != -1)
13992                      gnbDuUeF1apId = ueIdx +1;
13993                   else
13994                   {
13995                      DU_LOG("\nERROR  -->  F1AP : No free UE IDX found in UE bit map of cell Id [%lu]", nrCellId);
13996                      ret = RFAILED;
13997                      break;
13998                   }
13999                   duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
14000                   duUeCb->f1UeDb = NULL;
14001                   duUeCb->gnbCuUeF1apId = gnbCuUeF1apId;
14002                   duUeCb->gnbDuUeF1apId = gnbDuUeF1apId;
14003                   GET_CRNTI(duUeCb->crnti, duUeCb->gnbDuUeF1apId);
14004                   duUeCb->ueState = UE_HANDIN_IN_PROGRESS;
14005                }
14006
14007                if(duUeCb)
14008                {
14009                   DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
14010                   if(duUeCb->f1UeDb)
14011                   {
14012                      memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
14013                      duUeCb->f1UeDb->actionType = UE_CTXT_SETUP;
14014                      duUeCb->f1UeDb->cellIdx = cellIdx;
14015                   }
14016                   else
14017                   {
14018                      DU_LOG("\nERROR  -->  F1AP: Memory Alloc Failed at procF1UeContextSetupReq()");
14019                      ret = RFAILED;
14020                      break;
14021                   }
14022                }
14023                else
14024                {
14025                   DU_LOG("\nERROR  -->  F1AP: DuUeCb is not found at procF1UeContextSetupReq()");
14026                   ret = RFAILED;
14027                   break;
14028                }
14029                  
14030                /* Extract UE capability info */
14031                if(rrcInfo->uE_CapabilityRAT_ContainerList)
14032                {
14033                   duUeCb->f1UeDb->duUeCfg.ueNrCapability = extractUeCapability(rrcInfo->uE_CapabilityRAT_ContainerList, duUeCb);
14034                }
14035
14036                /* Extract IE extension */
14037                if(rrcInfo->iE_Extensions)
14038                {
14039                   if(extractCuToDuRrcInfoExt(rrcInfo->iE_Extensions, &duUeCb->f1UeDb->duUeCfg) != ROK)
14040                   {
14041                      DU_LOG("\nERROR  -->  F1AP: Failed to extract CU to DU RRC information extension IE");
14042                      //TODO: Update the failure cause in ue context Setup Response
14043                      ret = RFAILED;
14044                   }
14045                }
14046                break;
14047             } 
14048
14049 #ifdef NR_DRX
14050          case ProtocolIE_ID_id_DRXCycle:
14051             {
14052                duUeCb->f1UeDb->duUeCfg.drxCyclePres = true;
14053                drxCycle = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle;
14054                duUeCb->f1UeDb->duUeCfg.drxCycle.drxLongCycleLength =  convertLongDrxCycleLengthEnumToValue(drxCycle->longDRXCycleLength);
14055                if(drxCycle->shortDRXCycleLength)
14056                {
14057                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCyclePres = true;
14058                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycle = \
14059                   convertShortDrxCycleLengthEnumToValue(*(drxCycle->shortDRXCycleLength));
14060                }
14061                if(drxCycle->shortDRXCycleTimer)
14062                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycleTimer = *(drxCycle->shortDRXCycleTimer);   
14063
14064                break;
14065             }
14066
14067 #endif
14068          case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
14069             {
14070                if(extractSrbListToSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List,\
14071                         &duUeCb->f1UeDb->duUeCfg))
14072                {
14073                   DU_LOG("\nERROR  -->  DU APP : Failed at extractSrbListToSetup()");
14074                   //TODO: Update the failure cause in ue context Setup Response
14075                   ret = RFAILED;
14076                }
14077                break;
14078             }
14079
14080          case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
14081             {
14082                drbCfg = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List;
14083
14084                if(extractDrbListToSetupMod(drbCfg, NULL, NULL, drbCfg->list.count, &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULLP))
14085                {
14086                   DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod()");
14087                   //TODO: Update the failure cause in ue context Setup Response
14088                   ret = RFAILED;
14089                }
14090                break;
14091             }
14092          case ProtocolIE_ID_id_RRCContainer:
14093             {
14094                /* Filling Dl RRC Msg Info */
14095                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
14096                if(!duUeCb->f1UeDb->dlRrcMsg)
14097                {
14098                   DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for DL RRC Msg in procUeCtxtSetupReq()");
14099                   ret = RFAILED;
14100                }
14101                else
14102                {
14103                   duUeCb->f1UeDb->dlRrcMsgPres = true;
14104                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
14105                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
14106                         &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer);
14107                }          
14108                break;
14109             }
14110
14111          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
14112             {
14113                if(duUeCb->f1UeDb->dlRrcMsg)
14114                {
14115                   if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
14116                   {
14117                      duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
14118                   }
14119                   else
14120                   {
14121                      DU_LOG("\nERROR  -->  Ignoring delivery report, since rrcContainer is not present");
14122                   }
14123                }
14124                break;
14125             }
14126
14127          case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
14128             {
14129                /* MaximumBitRate Uplink */
14130                bitRateSize = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.size;
14131                if(bitRateSize > 0)
14132                {
14133                   DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->duUeCfg.ambrCfg, bitRateSize);
14134                   if(!duUeCb->f1UeDb->duUeCfg.ambrCfg)
14135                   {
14136                      DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for bitRate in procUeCtxtSetupReq");
14137                      ret = RFAILED;
14138                   }
14139                   else
14140                   {
14141                      memset(duUeCb->f1UeDb->duUeCfg.ambrCfg, 0, sizeof(AmbrCfg)); 
14142                      memcpy(&duUeCb->f1UeDb->duUeCfg.ambrCfg->ulBr,
14143                            ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf, bitRateSize);
14144                   }
14145                }
14146                else
14147                   ret = RFAILED;
14148                break;
14149             }
14150
14151          default:
14152             {
14153                break;
14154             }
14155       } /* End of switch */
14156
14157       /* In case of any failure in any IE */
14158       if(ret == RFAILED)
14159       {
14160          // BuildAndSendUeContextSetupRsp(cellId,ueId);
14161          DU_LOG("\nERROR  -->  F1AP: Failed to process UE CNTXT SETUP REQ at procF1UeContextSetupReq()"); 
14162          break;
14163       }
14164    } /* End of for loop of IEs */
14165
14166    if(ret == ROK)
14167       ret = duProcUeContextSetupRequest(duUeCb);
14168
14169    freeAperDecodeF1UeContextSetupReq(ueSetReq); 
14170    return ret;
14171
14172 }
14173 /*******************************************************************
14174  * @brief Free the memory allocated for Dl Tunnel Info
14175  *
14176  * @details
14177  *
14178  *    Function : freeDlTnlInfo
14179  *
14180  *    Functionality:
14181  *       Free the memory allocated for Dl Tunnel Info
14182  *
14183  * @params[in] DLUPTNLInformation_ToBeSetup_List_t *
14184  * @return void
14185  *
14186  * ****************************************************************/
14187
14188 void freeDlTnlInfo(DLUPTNLInformation_ToBeSetup_List_t *tnlInfo)
14189 {
14190    uint8_t arrIdx = 0;
14191
14192    if(tnlInfo)
14193    {
14194       for(arrIdx=0; arrIdx < tnlInfo->list.count; arrIdx++)
14195       {
14196          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf,\
14197                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.size);
14198          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf,\
14199                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.size);
14200          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14201          DU_FREE(tnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14202       }
14203       DU_FREE(tnlInfo->list.array, tnlInfo->list.size);
14204    }
14205 }
14206
14207 /*******************************************************************
14208  * @brief Free the memory allocated for DRB setup List
14209  *
14210  * @details
14211  *
14212  *    Function : freeDrbSetupList
14213  *
14214  *    Functionality:
14215  *       Free the memory allocated for DRB setup list
14216  *
14217  * @params[in] DRBs_Setup_List_t *
14218  * @return void
14219  *
14220  * ****************************************************************/
14221 void freeDrbSetupList(DRBs_Setup_List_t *drbSetupList)
14222 {
14223    uint8_t arrIdx = 0;
14224    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14225
14226    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
14227    {
14228       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14229       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List);
14230       DU_FREE(drbSetupList->list.array[arrIdx],  sizeof(DRBs_Setup_Item_t));
14231    }
14232    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
14233 }
14234
14235 /*******************************************************************
14236  * @brief Free the memory allocated for UE Setup response
14237  *
14238  * @details
14239  *
14240  *    Function : FreeUeContextSetupRsp
14241  *
14242  *    Functionality:
14243  *       Free the memory allocated for UE Setup response
14244  *
14245  * @params[in] F1AP PDU for UE setup response
14246  * @return ROK     - success
14247  *         RFAILED - failure
14248  *
14249  * ****************************************************************/
14250 void FreeUeContextSetupRsp(F1AP_PDU_t *f1apMsg)
14251 {
14252    uint8_t idx;
14253    UEContextSetupResponse_t *ueSetRsp = NULLP;
14254
14255    if(f1apMsg)
14256    {
14257       if(f1apMsg->choice.successfulOutcome)
14258       {
14259          ueSetRsp = &f1apMsg->choice.successfulOutcome->value.choice.\
14260                     UEContextSetupResponse;
14261          if(ueSetRsp->protocolIEs.list.array)
14262          {
14263             for(idx = 0; idx < ueSetRsp->protocolIEs.list.count; idx++)
14264             {
14265                if(ueSetRsp->protocolIEs.list.array[idx])
14266                {
14267                   switch(ueSetRsp->protocolIEs.list.array[idx]->id)
14268                   {
14269                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14270                         break;
14271                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14272                         break;
14273                      case ProtocolIE_ID_id_C_RNTI:
14274                         break;
14275                      case ProtocolIE_ID_id_DUtoCURRCInformation:
14276                         {
14277                            CellGroupConfig_t *cellGrpCfg = NULLP;
14278                            cellGrpCfg  = &ueSetRsp->protocolIEs.list.array[idx]->value.choice.\
14279                                          DUtoCURRCInformation.cellGroupConfig;
14280                            if(cellGrpCfg->buf != NULLP)
14281                            {
14282                               DU_FREE(cellGrpCfg->buf, cellGrpCfg->size);
14283                               cellGrpCfg = NULLP;
14284                            }
14285                            break;
14286                         }
14287                      case ProtocolIE_ID_id_DRBs_Setup_List:
14288                         {
14289                            freeDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List); 
14290                            break;
14291                         }
14292                      default:
14293                         DU_LOG("\nERROR  -->  DUAPP: Invalid Id %ld at FreeUeContextSetupRsp()",\
14294                               ueSetRsp->protocolIEs.list.array[idx]->id);
14295                         break;
14296                   }
14297                   DU_FREE(ueSetRsp->protocolIEs.list.array[idx],\
14298                         sizeof(UEContextSetupResponseIEs_t));
14299                }
14300             }
14301             DU_FREE(ueSetRsp->protocolIEs.list.array, \
14302                   ueSetRsp->protocolIEs.list.size);
14303          }
14304          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14305       }
14306       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14307    }
14308 }
14309
14310 /*******************************************************************
14311  *
14312  * @brief Builds Ue context Setup Rsp DU To CU Info
14313  *
14314  * @details
14315  *
14316  *    Function : EncodeUeCntxtDuToCuInfo
14317  *
14318  *    Functionality: Builds Ue context Setup Rsp DU To CU Info
14319  *
14320  * @params[in] CellGroupConfig_t *, CellGroupConfigRrc_t * 
14321  *
14322  * @return ROK     - success
14323  *         RFAILED - failure
14324  *
14325  ******************************************************************/
14326
14327 uint8_t EncodeUeCntxtDuToCuInfo(CellGroupConfig_t *duToCuCellGrp, CellGroupConfigRrc_t *duCellGrpCfg)
14328 {
14329    asn_enc_rval_t        encRetVal;
14330
14331    xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, duCellGrpCfg);
14332    memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14333    encBufSize = 0;
14334    encRetVal = uper_encode(&asn_DEF_CellGroupConfigRrc, 0, duCellGrpCfg, PrepFinalEncBuf, encBuf);
14335    /* Encode results */
14336    if(encRetVal.encoded == ENCODE_FAIL)
14337    {
14338       DU_LOG( "\nERROR  -->  F1AP : Could not encode UeCntxtDuToCuInfo (at %s)\n",\
14339             encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14340       return RFAILED;
14341    }
14342    else
14343    {
14344       DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UeCntxtDuToCuInfo\n");
14345 #ifdef DEBUG_ASN_PRINT
14346       for(int i=0; i< encBufSize; i++)
14347       {
14348          printf("%x",encBuf[i]);
14349       }
14350 #endif
14351    }
14352    duToCuCellGrp->size = encBufSize;
14353    DU_ALLOC(duToCuCellGrp->buf, duToCuCellGrp->size);
14354    if(!duToCuCellGrp->buf)
14355    {
14356       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in UeCntxtDuToCuInfo");
14357    }
14358    memcpy(duToCuCellGrp->buf, encBuf, duToCuCellGrp->size);
14359    return ROK;
14360 }
14361
14362 /*******************************************************************
14363  *
14364  * @brief Fills Dl Gtp tunnel Info
14365  *
14366  * @details
14367  *
14368  *    Function : fillGtpTunnelforDl
14369  *
14370  *    Functionality: Fills Dl Gtp tunnel Info
14371  *
14372  * @params[in] 
14373  *
14374  * @return ROK     - success
14375  *         RFAILED - failure
14376  *
14377  * ****************************************************************/
14378
14379 uint8_t fillGtpTunnelforDl(GTPTunnel_t *gtpDl, GtpTnlCfg *gtpUeCfg)
14380 {
14381    uint8_t bufSize = 0;
14382
14383    gtpDl->transportLayerAddress.size    = 4*sizeof(uint8_t);
14384    DU_ALLOC(gtpDl->transportLayerAddress.buf, gtpDl->transportLayerAddress.size);
14385    if(gtpDl->transportLayerAddress.buf == NULLP)
14386    {
14387       return RFAILED;
14388    }
14389    memcpy(gtpDl->transportLayerAddress.buf, &gtpUeCfg->dlTnlAddress, gtpDl->transportLayerAddress.size);
14390
14391    /*GTP TEID*/
14392    gtpDl->gTP_TEID.size = 4 * sizeof(uint8_t);
14393    DU_ALLOC(gtpDl->gTP_TEID.buf, gtpDl->gTP_TEID.size);
14394    if(gtpDl->gTP_TEID.buf == NULLP)
14395    {
14396       return RFAILED;
14397    }
14398    bufSize = 3; /*forming an Octect String*/
14399    fillTeIdString(bufSize, gtpUeCfg->teId, gtpDl->gTP_TEID.buf);
14400
14401    return ROK;
14402 }
14403
14404 /*******************************************************************
14405  *
14406  * @brief Fills DL Tunnel Setup List
14407  *
14408  * @details
14409  *
14410  *    Function : fillDlTnlSetupList
14411  *
14412  *    Functionality: Fills the DL Tunnel Setup List
14413  *
14414  * @params[in] 
14415  *
14416  * @return ROK     - success
14417  *         RFAILED - failure
14418  *
14419  * ****************************************************************/
14420
14421 uint8_t fillDlTnlSetupList(DLUPTNLInformation_ToBeSetup_List_t *dlTnlInfo, UpTnlCfg *tnlCfg)
14422 {
14423    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14424
14425    eleCount = 1;
14426    dlTnlInfo->list.count = eleCount; 
14427    dlTnlInfo->list.size = (eleCount * sizeof(DLUPTNLInformation_ToBeSetup_Item_t *));
14428
14429    /* Initialize the DL Tnl Setup List Members */
14430    DU_ALLOC(dlTnlInfo->list.array, dlTnlInfo->list.size);
14431    if(dlTnlInfo->list.array == NULLP)
14432    {
14433       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL Tnl Setup List in fillDlTnlSetupList()");
14434       ret = RFAILED;
14435    }
14436    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14437    {
14438       DU_ALLOC(dlTnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14439       if(dlTnlInfo->list.array[arrIdx] == NULLP)
14440       {
14441          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDlTnlSetupList()", arrIdx);
14442          return RFAILED;
14443       }
14444       dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.present = UPTransportLayerInformation_PR_gTPTunnel;
14445       DU_ALLOC(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14446       if(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel == NULLP)
14447       {
14448          DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL tunnel info in fillDlTnlSetupList()");
14449          return RFAILED;
14450       }
14451       ret = fillGtpTunnelforDl(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel,\
14452                tnlCfg->tnlCfg1);
14453       if(ret != ROK)
14454          break;
14455    }
14456    return ret;
14457 }
14458
14459 /*******************************************************************
14460  *
14461  * @brief Fills the Drb Setup List for Ue Context Setup Response
14462  *
14463  * @details
14464  *
14465  *    Function : fillDrbSetupList
14466  *
14467  *    Functionality: Fills the Drb Setup List for Ue Context Setup Response
14468  *
14469  * @params[in] 
14470  *
14471  * @return ROK     - success
14472  *         RFAILED - failure
14473  *
14474  * ****************************************************************/
14475 uint8_t fillDrbSetupList(DRBs_Setup_List_t *drbSetupList, DuUeCfg *ueCfg)
14476 {
14477    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14478    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14479
14480    eleCount = ueCfg->numDrb;
14481    drbSetupList->list.count = eleCount;
14482    drbSetupList->list.size = \
14483         (eleCount * sizeof(DRBs_Setup_Item_t *));
14484
14485    /* Initialize the Drb Setup List Members */
14486    DU_ALLOC(drbSetupList->list.array, drbSetupList->list.size);
14487    if(drbSetupList->list.array == NULLP)
14488    {
14489       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DRB Setup List in fillDrbSetupList()");
14490       ret = RFAILED;
14491    }
14492
14493    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14494    {
14495       DU_ALLOC(drbSetupList->list.array[arrIdx], sizeof(DRBs_Setup_Item_t));
14496       if(drbSetupList->list.array[arrIdx] == NULLP)
14497       {
14498          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDrbSetupList()", arrIdx);
14499          return RFAILED;
14500       }
14501       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14502       drbItemIe->id = ProtocolIE_ID_id_DRBs_Setup_Item;
14503       drbItemIe->criticality = Criticality_reject;
14504       drbItemIe->value.present = DRBs_Setup_ItemIEs__value_PR_DRBs_Setup_Item;
14505       drbItemIe->value.choice.DRBs_Setup_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
14506       ret = fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List,\
14507           &ueCfg->upTnlInfo[arrIdx]);
14508       if(ret != ROK)
14509          break;
14510    }
14511    return ret;
14512 }
14513
14514 /*******************************************************************
14515  *
14516  * @brief Builds and sends the UE Setup Response
14517  *
14518  * @details
14519  *
14520  *    Function : BuildAndSendUeContextSetupRsp
14521  *
14522  *    Functionality: Constructs the UE Setup Response and sends
14523  *                   it to the DU through SCTP.
14524  *
14525  * @params[in] uint8_t cellId,uint8_t ueId
14526  *
14527  * @return ROK     - success
14528  *         RFAILED - failure
14529  *
14530  * ****************************************************************/
14531 uint8_t BuildAndSendUeContextSetupRsp(uint8_t cellId,uint8_t ueId)
14532 {
14533    uint8_t   idx, ret, cellIdx, elementCnt;
14534    uint32_t  gnbCuUeF1apId;   /* gNB-CU UE F1AP Id */
14535    uint32_t  gnbDuUeF1apId;   /* gNB-DU UE F1AP Id */
14536    asn_enc_rval_t  encRetVal;        /* Encoder return value */
14537    F1AP_PDU_t               *f1apMsg = NULLP;
14538    UEContextSetupResponse_t *ueSetRsp = NULLP;
14539    DuUeCb                   *ueCb = NULLP;
14540
14541    DU_LOG("\n INFO   -->  F1AP : Building UE Context Setup Response for cellId %d, ueId %d\n", cellId, ueId);
14542
14543    while(true)
14544    {
14545       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14546       if(f1apMsg == NULLP)
14547       {
14548          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14549          ret = RFAILED;
14550          break;
14551       }
14552
14553       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
14554       DU_ALLOC(f1apMsg->choice.successfulOutcome,
14555             sizeof(SuccessfulOutcome_t));
14556       if(f1apMsg->choice.successfulOutcome == NULLP)
14557       {
14558          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
14559          ret = RFAILED;
14560          break;
14561       }
14562
14563       f1apMsg->choice.successfulOutcome->procedureCode = \
14564                                                          ProcedureCode_id_UEContextSetup;
14565       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
14566       f1apMsg->choice.successfulOutcome->value.present = \
14567                                                          SuccessfulOutcome__value_PR_UEContextSetupResponse;
14568
14569       ueSetRsp =
14570          &f1apMsg->choice.successfulOutcome->value.choice.UEContextSetupResponse;
14571       elementCnt = 5;
14572       ueSetRsp->protocolIEs.list.count = elementCnt;
14573       ueSetRsp->protocolIEs.list.size = \
14574                                         elementCnt * sizeof(UEContextSetupResponse_t *);
14575
14576       /* Initialize the UESetup members */
14577       DU_ALLOC(ueSetRsp->protocolIEs.list.array, \
14578             ueSetRsp->protocolIEs.list.size);
14579       if(ueSetRsp->protocolIEs.list.array == NULLP)
14580       {
14581          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14582          ret = RFAILED;
14583          break;
14584       }
14585
14586       for(idx=0; idx<elementCnt; idx++)
14587       {
14588          DU_ALLOC(ueSetRsp->protocolIEs.list.array[idx],\
14589                sizeof(UEContextSetupResponseIEs_t));
14590          if(ueSetRsp->protocolIEs.list.array[idx] == NULLP)
14591          {
14592             DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14593             ret = RFAILED;
14594             break;
14595          }
14596       }
14597       /* Fetching Ue Cb Info*/
14598       GET_CELL_IDX(cellId, cellIdx);
14599       gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
14600       gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
14601       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
14602
14603       idx = 0;
14604       /*GNB CU UE F1AP ID*/
14605       ueSetRsp->protocolIEs.list.array[idx]->id = \
14606                                                   ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
14607       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14608       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14609                                                              UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
14610       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
14611
14612       /*GNB DU UE F1AP ID*/
14613       idx++;
14614       ueSetRsp->protocolIEs.list.array[idx]->id = \
14615                                                   ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14616       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14617       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14618                                                              UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
14619       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
14620
14621
14622       /*DUtoCURRC Information */
14623       idx++;
14624       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14625                                                    ProtocolIE_ID_id_DUtoCURRCInformation;
14626       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14627       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14628                                                             UEContextSetupResponseIEs__value_PR_DUtoCURRCInformation;
14629       BuildCellGroupConfigRrc(ueCb, &ueSetRsp->protocolIEs.list.array[idx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
14630
14631       /* CRNTI */
14632       idx++;
14633       ueSetRsp->protocolIEs.list.array[idx]->id  = ProtocolIE_ID_id_C_RNTI;
14634       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14635       ueSetRsp->protocolIEs.list.array[idx]->value.present = UEContextSetupResponseIEs__value_PR_C_RNTI;
14636       ueSetRsp->protocolIEs.list.array[idx]->value.choice.C_RNTI = ueCb->crnti; 
14637
14638
14639       /* Drb Setup List */
14640       idx++;
14641       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14642                                                    ProtocolIE_ID_id_DRBs_Setup_List;
14643       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14644       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14645                                                             UEContextSetupResponseIEs__value_PR_DRBs_Setup_List;
14646       ret = fillDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List,\
14647             &ueCb->f1UeDb->duUeCfg);
14648       if(ret == RFAILED)
14649       {
14650          DU_LOG("\nERROR  -->  F1AP : Failed to fillDrbSetupList in BuildAndSendUeContextSetupRsp()");
14651          freeF1UeDb(ueCb->f1UeDb);
14652          ueCb->f1UeDb = NULLP;
14653          break;
14654       }
14655
14656       /* Free UeContext Db created during Ue context Req */
14657       freeF1UeDb(ueCb->f1UeDb);
14658       ueCb->f1UeDb = NULLP;
14659
14660       /* TODO: To send Drb list */
14661       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14662
14663       /* Encode the UE context setup response type as APER */
14664       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14665       encBufSize = 0;
14666       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14667             encBuf);
14668       /* Encode results */
14669       if(encRetVal.encoded == ENCODE_FAIL)
14670       {
14671          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Response structure (at %s)\n",\
14672                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14673          ret = RFAILED;
14674          break;
14675       }
14676       else
14677       {
14678          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Setup Response\n");
14679 #ifdef DEBUG_ASN_PRINT
14680          for(int i=0; i< encBufSize; i++)
14681          {
14682             printf("%x",encBuf[i]);
14683          }
14684 #endif
14685       }
14686
14687       /* Sending  msg  */
14688       if(sendF1APMsg()  != ROK)
14689       {
14690          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Response failed");
14691          ret = RFAILED;
14692          break;
14693       }
14694       break;
14695    }
14696    FreeUeContextSetupRsp(f1apMsg);
14697    return ret;
14698 }/* End of BuildAndSendUeContextSetupRsp */
14699
14700 /*******************************************************************
14701 *
14702 * @brief  Build And Send Ue Context Rsp 
14703 *
14704 * @details
14705 *
14706 *    Function : BuildAndSendUeCtxtRsp 
14707 *
14708 *    Functionality : Build And Send Ue Context Rsp
14709
14710 * @params[in]
14711 * @return sucess = ROK
14712 *         failure = RFAILED
14713 *
14714 * ****************************************************************/
14715 uint8_t BuildAndSendUeCtxtRsp(uint8_t cellId, uint8_t ueId)
14716 {
14717    uint8_t cellIdx = 0, actionType = 0; 
14718
14719    GET_CELL_IDX(cellId, cellIdx);
14720    actionType = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].f1UeDb->actionType;
14721
14722    switch(actionType)
14723    {
14724       case UE_CTXT_SETUP:
14725          {
14726             if((BuildAndSendUeContextSetupRsp(cellId,ueId)) != ROK)
14727             {
14728                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextSetupRsp()");
14729                return RFAILED;
14730             }
14731             break;
14732          }
14733       case UE_CTXT_MOD:
14734          {
14735             if((BuildAndSendUeContextModRsp(&duCb.actvCellLst[cellIdx]->ueCb[ueId-1])) != ROK)
14736             {
14737                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextModRsp");
14738                return RFAILED;
14739             }
14740             break;
14741          }
14742       default:
14743          DU_LOG("ERROR  -->  F1AP: Invalid Action Type %d at BuildAndSendUeCtxtRsp()", actionType);
14744          break;
14745
14746    }
14747    return ROK;
14748 }
14749
14750 /*******************************************************************
14751  *
14752  * @brief deallocating the memory of  F1reset msg
14753  *
14754  * @details
14755  *
14756  *    Function : FreeF1ResetReq
14757  *
14758  *    Functionality :
14759  *         - freeing memory of F1reset request msg
14760  *
14761  * @params[in]
14762  * @return void
14763  *
14764  *
14765  * ****************************************************************/
14766 void FreeF1ResetReq(F1AP_PDU_t *f1apMsg)
14767 {
14768    uint8_t idx =0 ;
14769    Reset_t *f1ResetMsg;
14770
14771    if(f1apMsg)
14772    {
14773       if(f1apMsg->choice.initiatingMessage)
14774       {
14775          f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14776
14777          if(f1ResetMsg->protocolIEs.list.array)
14778          {
14779             for(idx=0 ;idx < f1ResetMsg->protocolIEs.list.count ; idx++)
14780             {
14781                if(f1ResetMsg->protocolIEs.list.array[idx])
14782                {
14783                   DU_FREE(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14784                }
14785             }
14786             DU_FREE(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14787          }
14788          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14789       }
14790       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14791    }
14792 }
14793 /*******************************************************************
14794  *
14795  * @brief Build and Send F1reset request 
14796  *
14797  * @details
14798  *
14799  *    Function : BuildAndSendF1ResetReq
14800  *
14801  *    Functionality:
14802  *         - Build and Send F1reset request msg
14803  *
14804  * @params[in]
14805  * @return ROK     - success
14806  *         RFAILED - failure
14807  *
14808  * ****************************************************************/
14809 uint8_t BuildAndSendF1ResetReq()
14810 {
14811    uint8_t          elementCnt=0;
14812    uint8_t          idx=0;
14813    uint8_t          ret= RFAILED;
14814    Reset_t          *f1ResetMsg = NULLP;
14815    F1AP_PDU_t       *f1apMsg = NULLP;
14816    asn_enc_rval_t   encRetVal;
14817    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset request \n");
14818    do
14819    {
14820       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14821       if(f1apMsg == NULLP)
14822       {
14823          break;
14824       }
14825       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
14826       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14827       if(f1apMsg->choice.initiatingMessage == NULLP)
14828       {
14829          break;
14830       }
14831       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_Reset;
14832       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
14833       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_Reset;
14834
14835       f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14836
14837       elementCnt = 3;
14838       f1ResetMsg->protocolIEs.list.count = elementCnt;
14839       f1ResetMsg->protocolIEs.list.size = elementCnt * sizeof(ResetIEs_t *);
14840
14841       /* Initialize the F1Setup members */
14842       DU_ALLOC(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14843       if(f1ResetMsg->protocolIEs.list.array == NULLP)
14844       {
14845          break;
14846       }
14847       for(idx=0; idx<elementCnt; idx++)
14848       {
14849          DU_ALLOC(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14850          if(f1ResetMsg->protocolIEs.list.array[idx] == NULLP)
14851          {
14852             break;
14853          }
14854       }
14855
14856       /*TransactionID*/
14857       idx=0;
14858       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
14859       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14860       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_TransactionID;
14861       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.TransactionID = 1;
14862
14863       /*Cause*/
14864       idx++;
14865       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_Cause;
14866       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_ignore;
14867       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_Cause;
14868       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.present = Cause_PR_radioNetwork;
14869       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.choice.radioNetwork = CauseRadioNetwork_action_desirable_for_radio_reasons;
14870
14871       /*Reset Type*/
14872       idx++;
14873       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_ResetType;
14874       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14875       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_ResetType;
14876       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.present = ResetType_PR_f1_Interface;
14877       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.choice.f1_Interface = ResetAll_reset_all;
14878
14879       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14880
14881       /* Encode the F1SetupRequest type as APER */
14882       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14883       encBufSize = 0;
14884       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14885             encBuf);
14886
14887       /* Encode results */
14888       if(encRetVal.encoded == ENCODE_FAIL)
14889       {
14890          DU_LOG("\nERROR  -->  F1AP : Could not encode F1Reset structure (at %s)\n",\
14891                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14892          break;
14893       }
14894       else
14895       {
14896          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1Reset\n");
14897 #ifdef DEBUG_ASN_PRINT
14898          for(idx=0; idx< encBufSize; idx++)
14899          {
14900             printf("%x",encBuf[idx]);
14901          }
14902 #endif
14903       }
14904
14905       if(sendF1APMsg() != ROK)
14906       {
14907          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset request failed");
14908          break;
14909       }
14910
14911       ret = ROK;
14912       break;
14913    }while(true);
14914
14915    FreeF1ResetReq(f1apMsg);
14916    return ret;
14917 }
14918 /*******************************************************************
14919  *
14920  * @brief Build And Send F1ResetAck
14921  *
14922  * @details
14923  *
14924  *    Function : BuildAndSendF1ResetAck
14925  *
14926  *    Functionality:
14927  *         - Build And Send  F1ResetRSP
14928  *
14929  * @return ROK     - success
14930  *         RFAILED - failure
14931  *
14932  * ****************************************************************/
14933 void FreeF1ResetAck(F1AP_PDU_t *f1apMsg)
14934 {
14935    uint8_t idx;
14936    ResetAcknowledge_t *f1ResetAck;
14937
14938    if(f1apMsg)
14939    {
14940       if(f1apMsg->choice.successfulOutcome)
14941       {
14942          f1ResetAck= &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14943
14944          if(f1ResetAck->protocolIEs.list.array)
14945          {
14946             for(idx=0; idx<f1ResetAck->protocolIEs.list.count ; idx++)
14947             {
14948                if(f1ResetAck->protocolIEs.list.array[idx])
14949                {
14950                   DU_FREE(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14951                }
14952             }
14953             DU_FREE(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14954          }
14955          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14956       }
14957       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14958    }
14959 }
14960
14961 /*******************************************************************
14962  *
14963  * @brief Build And Send F1ResetAck
14964  *
14965  * @details
14966  *
14967  *    Function : BuildAndSendF1ResetAck
14968  *
14969  *    Functionality:
14970  *         - Build And Send  F1ResetRSP
14971  *
14972  *  @params[in]
14973  * @return ROK     - success
14974  *         RFAILED - failure
14975  *
14976  * ****************************************************************/
14977 uint8_t BuildAndSendF1ResetAck()
14978 {
14979    uint8_t                idx = 0;
14980    uint8_t                elementCnt = 0;
14981    uint8_t                ret = RFAILED;
14982    F1AP_PDU_t             *f1apMsg = NULL;
14983    ResetAcknowledge_t     *f1ResetAck = NULLP;
14984    asn_enc_rval_t         encRetVal;
14985    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset Acknowledgment \n");
14986
14987    do{
14988       /* Allocate the memory for F1ResetRequest_t */
14989       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14990       if(f1apMsg == NULLP)
14991       {
14992          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14993          break;
14994       }
14995
14996       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
14997
14998       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14999       if(f1apMsg->choice.successfulOutcome == NULLP)
15000       {
15001          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
15002          break;
15003       }
15004       f1apMsg->choice.successfulOutcome->criticality   = Criticality_reject;
15005       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetAcknowledge;
15006       f1ResetAck = &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
15007
15008       elementCnt = 1;
15009
15010       f1ResetAck->protocolIEs.list.count = elementCnt;
15011       f1ResetAck->protocolIEs.list.size = elementCnt*sizeof(ResetAcknowledgeIEs_t *);
15012
15013       DU_ALLOC(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
15014       if(f1ResetAck->protocolIEs.list.array == NULLP)
15015       {
15016          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1ResetAckIEs failed");
15017          break;
15018       }
15019
15020       for(idx=0; idx<elementCnt; idx++)
15021       {
15022          DU_ALLOC(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
15023          if(f1ResetAck->protocolIEs.list.array[idx] == NULLP)
15024          {
15025             break;
15026          }
15027       }
15028       /*TransactionID*/
15029       idx = 0;
15030       f1ResetAck->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
15031       f1ResetAck->protocolIEs.list.array[idx]->criticality = Criticality_reject;
15032       f1ResetAck->protocolIEs.list.array[idx]->value.present = ResetAcknowledgeIEs__value_PR_TransactionID;
15033       f1ResetAck->protocolIEs.list.array[idx]->value.choice.TransactionID = TRANS_ID;
15034
15035       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15036
15037       /* Encode the F1SetupRequest type as UPER */
15038       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15039       encBufSize = 0;
15040       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
15041
15042       /* Check encode results */
15043       if(encRetVal.encoded == ENCODE_FAIL)
15044       {
15045          DU_LOG("\nERROR  -->  F1AP : Could not encode F1ResetAck structure (at %s)\n",\
15046                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15047          break;
15048       }
15049       else
15050       {
15051          DU_LOG("\nDUBUG   -->  F1AP : Created APER encoded buffer for F1ResetAck\n");
15052 #ifdef DEBUG_ASN_PRINT
15053          for(int i=0; i< encBufSize; i++)
15054          {
15055             printf("%x",encBuf[i]);
15056          }
15057 #endif
15058       }
15059       /* Sending msg */
15060       if(sendF1APMsg() != ROK)
15061       {
15062          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset Acknowledgement failed");
15063          break;
15064       }
15065
15066       ret = ROK;
15067       break;
15068    }while(true);
15069
15070    FreeF1ResetAck(f1apMsg);
15071    return ret;
15072 }
15073 /******************************************************************
15074 *
15075 * @brief free F1 reset msg allocated by aper_decoder 
15076 *
15077 * @details
15078 *
15079 *    Function : freeAperDecodeF1ResetMsg 
15080 *
15081 *    Functionality: free F1 reset msg allocated by aper_decoder 
15082 *
15083 * @params[in] Reset_t *f1ResetMsg 
15084 * @return void 
15085 *
15086 * ****************************************************************/
15087
15088 void freeAperDecodeF1ResetMsg(Reset_t *f1ResetMsg)
15089 {
15090    uint8_t ieIdx =0;
15091    if(f1ResetMsg->protocolIEs.list.array)
15092    {
15093       for(ieIdx=0 ;ieIdx < f1ResetMsg->protocolIEs.list.count ; ieIdx++)
15094       {
15095          if(f1ResetMsg->protocolIEs.list.array[ieIdx])
15096          {
15097             free(f1ResetMsg->protocolIEs.list.array[ieIdx]);
15098          }
15099       }
15100       free(f1ResetMsg->protocolIEs.list.array);
15101    }
15102 }
15103
15104 /******************************************************************
15105  *
15106  * @brief Processes DL RRC Message Transfer  sent by CU
15107  *
15108  * @details
15109  *
15110  *    Function : procF1ResetReq
15111  *
15112  *    Functionality: Processes DL RRC Message Transfer sent by CU
15113  *
15114  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15115  * @return ROK     - success
15116  *         RFAILED - failure
15117  *
15118  * ****************************************************************/
15119 uint8_t procF1ResetReq(F1AP_PDU_t *f1apMsg)
15120 {
15121    /* we are currently not supporting Ue release. right now we are supporting only init case of fireset */
15122    uint8_t       ieIdx = 0;
15123    uint8_t        ret = ROK;
15124    Reset_t       *f1ResetMsg = NULLP;
15125
15126    DU_LOG("\nINFO   -->  Processing F1 reset request");
15127    f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
15128
15129    for(ieIdx=0; ieIdx<f1ResetMsg->protocolIEs.list.count; ieIdx++)
15130    {
15131       switch(f1ResetMsg->protocolIEs.list.array[ieIdx]->id)
15132       {
15133          case ProtocolIE_ID_id_TransactionID:
15134             break;
15135
15136          case ProtocolIE_ID_id_Cause:
15137             break;
15138
15139          case ProtocolIE_ID_id_ResetType:
15140             {
15141                break;
15142             }
15143
15144          default:
15145             break;
15146       }
15147    }
15148    ret = BuildAndSendF1ResetAck();
15149    DU_LOG("\nINFO   -->  UE release is not supported for now");
15150
15151    freeAperDecodeF1ResetMsg(f1ResetMsg);
15152
15153    return ret;
15154 }
15155
15156 /*******************************************************************
15157  *
15158  * @brief free the RRC delivery report
15159  *
15160  * @details
15161  *
15162  *    Function : freeRrcDeliveryReport
15163  *
15164  *    Functionality: free the RRC delivery report
15165  *
15166  * @params[in]
15167  * @return ROK     - success
15168  *         RFAILED - failure
15169  *
15170  * ****************************************************************/
15171 void freeRrcDeliveryReport(F1AP_PDU_t  *f1apMsg )
15172 {
15173    uint8_t idx=0;
15174    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
15175
15176    if(f1apMsg)
15177    {
15178       if(f1apMsg->choice.initiatingMessage)
15179       {
15180          rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
15181          if(rrcDeliveryReport->protocolIEs.list.array)
15182          {
15183             for(idx =0 ;idx <rrcDeliveryReport->protocolIEs.list.count ;
15184                   idx++)
15185             {
15186                if(rrcDeliveryReport->protocolIEs.list.array[idx])
15187                {
15188                   DU_FREE(rrcDeliveryReport->protocolIEs.list.array[idx],
15189                         sizeof(RRCDeliveryReportIEs_t));
15190                }   
15191             }
15192             DU_FREE(rrcDeliveryReport->protocolIEs.list.array,
15193                   rrcDeliveryReport->protocolIEs.list.size);
15194          }
15195          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
15196       }
15197       DU_FREE(f1apMsg,
15198             sizeof(F1AP_PDU_t));
15199    }
15200 }
15201
15202 /*******************************************************************
15203 *
15204 * @brief Builds and sends the RRC delivery report
15205 *
15206 * @details
15207 *
15208 *    Function : BuildAndSendRrcDeliveryReport
15209 *
15210 *    Functionality: Builds and sends the RRC delivery report
15211 *
15212 * @params[in]
15213 *
15214 * @return ROK     - success
15215 *         RFAILED - failure
15216 *
15217 * ****************************************************************/
15218 uint8_t BuildAndSendRrcDeliveryReport(uint32_t gnbCuUeF1apId, \
15219    uint32_t gnbDuUeF1apId, RrcDeliveryReport *rrcDelivery)
15220 {
15221    uint8_t             ret = RFAILED;
15222    uint8_t             idx    = 0;
15223    uint8_t             idx1   = 0;
15224    uint8_t             elementCnt = 0;
15225    F1AP_PDU_t          *f1apMsg = NULLP;
15226    asn_enc_rval_t      encRetVal;  
15227    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
15228
15229    do{
15230
15231       DU_LOG("\nINFO   -->  F1AP : Building RRC delivery Message Transfer Message\n");
15232       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15233       if(f1apMsg == NULLP)
15234       {
15235          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
15236          break;
15237       }
15238       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
15239       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
15240       if(f1apMsg->choice.initiatingMessage == NULLP)
15241       {
15242          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU  failed");
15243          break;
15244       }
15245       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_RRCDeliveryReport;
15246       f1apMsg->choice.initiatingMessage->criticality   = Criticality_ignore;
15247       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_RRCDeliveryReport;
15248
15249       rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
15250       elementCnt = 4;
15251       rrcDeliveryReport->protocolIEs.list.count = elementCnt;
15252       rrcDeliveryReport->protocolIEs.list.size = elementCnt * sizeof(RRCDeliveryReportIEs_t *);
15253
15254       /* Initialize the F1Setup members */
15255       DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array, rrcDeliveryReport->protocolIEs.list.size);
15256       if(rrcDeliveryReport->protocolIEs.list.array == NULLP)
15257       {
15258          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRC Delivery  failed");
15259          break;
15260       }
15261       for(idx =0 ;idx <elementCnt; idx++)
15262       {
15263          DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array[idx], sizeof(RRCDeliveryReportIEs_t));
15264          if(rrcDeliveryReport->protocolIEs.list.array[idx] == NULLP)
15265          {
15266             break;
15267          }
15268       }
15269
15270       idx1 = 0;
15271
15272       /*GNB CU UE F1AP ID*/
15273       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
15274       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15275       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_CU_UE_F1AP_ID;
15276       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
15277
15278       /*GNB DU UE F1AP ID*/
15279       idx1++;
15280       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
15281       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
15282       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_DU_UE_F1AP_ID;
15283       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
15284
15285       /*RRC delivery status*/
15286       idx1++;
15287       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_RRCDeliveryStatus;
15288       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15289       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_RRCDeliveryStatus;
15290       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.delivery_status =\
15291       rrcDelivery->rrcDeliveryStatus.deliveryStatus;
15292       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.triggering_message =\
15293       rrcDelivery->rrcDeliveryStatus.triggeringMessage;
15294
15295       /* SRB ID */ 
15296       idx1++;
15297       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
15298       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
15299       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_SRBID;
15300       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.SRBID =  rrcDelivery->srbId;
15301
15302       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15303
15304       /* Encode the RRC DELIVERY REPORT type as APER */
15305       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15306       encBufSize = 0;
15307       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
15308             encBuf);
15309
15310       /* Encode results */
15311       if(encRetVal.encoded == ENCODE_FAIL)
15312       {
15313          DU_LOG("\nERROR  -->  F1AP : Could not encode RRC Delivery Msg structure (at %s)\n",\
15314                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15315          break;
15316       }
15317       else
15318       {
15319          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for RRC Delivery Msg \n");
15320 #ifdef DEBUG_ASN_PRINT
15321          for(idx=0; idx< encBufSize; idx++)
15322          {
15323             printf("%x",encBuf[idx]);
15324          }
15325 #endif
15326       }
15327
15328       /* Sending msg */
15329       if(sendF1APMsg() != ROK)
15330       {
15331          DU_LOG("\nERROR  -->  F1AP : Sending RRC delivery  msg request failed");
15332          break;
15333       }
15334       ret = ROK;
15335       break;
15336
15337    }while(true);
15338
15339    freeRrcDeliveryReport(f1apMsg);
15340    return ret;
15341 }
15342
15343 /*******************************************************************
15344  *
15345  * @brief Processes cells to be activated
15346  *
15347  * @details
15348  *
15349  *    Function : extractCellsToBeActivated
15350  *
15351  *    Functionality:
15352  *      - Processes cells to be activated list received in F1SetupRsp
15353  *
15354  * @params[in] void
15355  * @return ROK     - success
15356  *         RFAILED - failure
15357  *
15358  * ****************************************************************/
15359
15360 uint8_t extractCellsToBeActivated(Cells_to_be_Activated_List_t cellsToActivate)
15361 {
15362    uint8_t  ret = ROK;
15363    uint16_t idx, pci = 0;
15364    uint64_t nci;
15365    Cells_to_be_Activated_List_Item_t cell;
15366
15367    for(idx=0; idx<cellsToActivate.list.count; idx++)
15368    {
15369       nci = 0;
15370       cell = cellsToActivate.list.array[idx]->value.choice.Cells_to_be_Activated_List_Item;
15371       bitStringToInt(&cell.nRCGI.nRCellIdentity, &nci);
15372
15373       if(cell.nRPCI)
15374       {
15375          pci = *cell.nRPCI;
15376       }
15377       ret = duProcCellsToBeActivated(cell.nRCGI.pLMN_Identity.buf, nci, pci);
15378    }
15379    return ret;
15380 }
15381 /******************************************************************
15382 *
15383 * @brief Processes F1 Setup Response allocated by aper_decoder 
15384 *
15385 * @details
15386 *
15387 *    Function : freeF1SetupRsp 
15388 *
15389 *    Functionality: free F1 Setup Response allocated by aper_decoder 
15390 *
15391 * @params[in] F1SetupResponse_t *f1SetRspMsg 
15392 * @return void 
15393 *
15394 * ****************************************************************/
15395
15396 void freeAperDecodeF1SetupRsp(F1SetupResponse_t *f1SetRspMsg)
15397 {
15398    uint8_t ieIdx =0;
15399    uint8_t arrIdx =0;
15400    Cells_to_be_Activated_List_t *cellToActivate =NULLP;
15401    RRC_Version_t      *rrcVer =NULLP;
15402
15403    if(f1SetRspMsg->protocolIEs.list.array)
15404    {
15405       for(ieIdx=0; ieIdx<f1SetRspMsg->protocolIEs.list.count; ieIdx++)
15406       {
15407          if(f1SetRspMsg->protocolIEs.list.array[ieIdx])
15408          {
15409             switch(f1SetRspMsg->protocolIEs.list.array[ieIdx]->id)
15410             {
15411                case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15412                   {
15413                      cellToActivate =
15414                         &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.Cells_to_be_Activated_List;
15415                      if(cellToActivate->list.array)
15416                      {
15417                         for(arrIdx=0; arrIdx<cellToActivate->list.count ; arrIdx++)
15418                         {
15419                            if(cellToActivate->list.array[arrIdx])
15420                            {
15421
15422                               if(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.nRCGI.\
15423                               pLMN_Identity.buf)
15424                               {
15425                                  if(cellToActivate->list.array[0]->value.choice.\
15426                                        Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf)
15427                                  {
15428                                     free(cellToActivate->list.array[0]->value.choice.\
15429                                           Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf);
15430                                  }
15431
15432                                  free(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
15433                                        nRCGI.pLMN_Identity.buf);
15434                               }
15435                               free(cellToActivate->list.array[arrIdx]);
15436                            }
15437                         }
15438                         free(cellToActivate->list.array);
15439                      }
15440                      break;
15441                   }
15442                case ProtocolIE_ID_id_TransactionID:
15443                   {
15444                      break;
15445                   }
15446                case ProtocolIE_ID_id_gNB_CU_Name:
15447                   {
15448                      free(f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_Name.buf);
15449                      break;
15450                   }
15451                case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15452                   {
15453                      rrcVer = &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
15454                      if(rrcVer->latest_RRC_Version.buf)
15455                      {
15456                         if(rrcVer->iE_Extensions)
15457                         {
15458                            if(rrcVer->iE_Extensions->list.array)
15459                            {
15460                               if(rrcVer->iE_Extensions->list.array[0])
15461                               {
15462                                  if(rrcVer->iE_Extensions->list.\
15463                                        array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf)
15464                                  {
15465                                     free(rrcVer->iE_Extensions->list.\
15466                                           array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf);
15467                                  }
15468                                  free(rrcVer->iE_Extensions->list.array[0]);
15469                               }
15470                               free(rrcVer->iE_Extensions->list.array);
15471                            }
15472                            free(rrcVer->iE_Extensions);
15473                         }
15474                         free(rrcVer->latest_RRC_Version.buf);
15475                      }
15476                      break;
15477
15478                   }
15479                default:
15480                   {
15481                      DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15482                            f1SetRspMsg->protocolIEs.list.array[ieIdx]->id);
15483                   }
15484             }
15485             free(f1SetRspMsg->protocolIEs.list.array[ieIdx]);
15486          }
15487       }
15488       free(f1SetRspMsg->protocolIEs.list.array);
15489    }
15490 }
15491 /******************************************************************
15492  *
15493  * @brief Processes F1 Setup Response sent by CU
15494  *
15495  * @details
15496  *
15497  *    Function : procF1SetupRsp
15498  *
15499  *    Functionality: Processes F1 Setup Response sent by CU
15500  *
15501  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15502  * @return ROK     - success
15503  *         RFAILED - failure
15504  *
15505  * ****************************************************************/
15506 uint8_t procF1SetupRsp(F1AP_PDU_t *f1apMsg, MsgLen recvBufLen, char *recvBuf)
15507 {
15508    uint8_t ret = ROK;
15509    uint16_t idx =0;
15510    F1SetupResponse_t *f1SetRspMsg = NULLP;
15511    GNB_CU_Name_t     *cuName = NULLP;
15512    F1SetupRsp  f1SetRspDb;
15513    RRC_Version_t      *rrcVer =NULLP;
15514    
15515    memset(&f1SetRspDb, 0, sizeof(F1SetupRsp));
15516
15517    DU_LOG("\nINFO   -->  F1AP : F1 Setup Response received");
15518    f1SetRspMsg = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
15519
15520    for(idx=0; idx<f1SetRspMsg->protocolIEs.list.count; idx++)
15521    {
15522       switch(f1SetRspMsg->protocolIEs.list.array[idx]->id)
15523       {
15524          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15525             {
15526                extractCellsToBeActivated(f1SetRspMsg->protocolIEs.list.array[idx]->\
15527                      value.choice.Cells_to_be_Activated_List);
15528                break;
15529             }
15530          case ProtocolIE_ID_id_TransactionID:
15531             {
15532                f1SetRspDb.transId = f1SetRspMsg->protocolIEs.list.array[idx]->\
15533                                     value.choice.TransactionID;
15534                break;
15535             }
15536          case ProtocolIE_ID_id_gNB_CU_Name:
15537             {
15538                cuName = &f1SetRspMsg->protocolIEs.list.array[idx]->\
15539                         value.choice.GNB_CU_Name;
15540                strcpy(f1SetRspDb.cuName, (const char*)cuName->buf);
15541                break;
15542             }
15543          case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15544             {
15545                rrcVer = &f1SetRspMsg->protocolIEs.list.array[idx]->value.choice.RRC_Version;
15546                strcpy(f1SetRspDb.rrcVersion.rrcVer,
15547                      (const char*)rrcVer->latest_RRC_Version.buf);
15548                break;
15549             }
15550          default:
15551             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15552                   f1SetRspMsg->protocolIEs.list.array[idx]->id);
15553       }
15554    }
15555    
15556    duProcF1SetupRsp();
15557    freeAperDecodeF1SetupRsp(f1SetRspMsg);
15558    
15559    if(fillE2NodeComponentRspInfo(F1, duCfgParam.duId, E2_NODE_COMPONENT_ADD, recvBufLen, recvBuf) !=ROK)
15560    {
15561       DU_LOG("\nERROR  -->  F1AP : Failed to add the e2 node in the list");
15562       return RFAILED;
15563    }
15564
15565    if(BuildAndSendE2SetupReq() != ROK)
15566    {
15567       DU_LOG("\nERROR  -->  F1AP : Failed to build and send E2 setup request ");
15568       return RFAILED;
15569    }
15570    return ret;
15571 }
15572 /*******************************************************************
15573 *
15574 * @brief free GNB DU config update ack
15575 *
15576 * @details
15577 *
15578 *    Function : freeAperDecodeGnbDuAck 
15579 *
15580 *    Functionality: Processes GNB DU config update ack And
15581 *                     added free part for the memory allocated by aper_decoder
15582 *
15583 * @params[in] F1AP_PDU_t ASN decoded F1AP message
15584 * @return ROK     - success
15585 *         RFAILED - failure
15586 *
15587 * ****************************************************************/
15588
15589 void freeAperDecodeGnbDuAck(GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck)
15590 {
15591    uint8_t ieIdx = 0;
15592
15593    if(gnbDuAck->protocolIEs.list.array)
15594    {
15595       for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15596       {
15597          if(gnbDuAck->protocolIEs.list.array[ieIdx])
15598          {
15599             free(gnbDuAck->protocolIEs.list.array[ieIdx]);
15600          }
15601       }
15602       free(gnbDuAck->protocolIEs.list.array);
15603    }
15604 }
15605
15606 /*******************************************************************
15607 *
15608 * @brief Building  result of gnb-du config update ack output
15609 *
15610 * @details
15611 *
15612 *    Function : duProcGnbDuCfgUpdAckMsg 
15613 *
15614 *    Functionality: 
15615 *        Building output of gnb-du config update ack 
15616 *
15617 * @params[in] transId
15618 * @return void
15619 *
15620 * ****************************************************************/
15621
15622 uint8_t duProcGnbDuCfgUpdAckMsg(uint8_t transId)
15623 {
15624    uint8_t  ieIdx=0, arrIdx=0,ret=ROK;
15625    uint8_t  ueId =0 , ueIdx =0, totalActiveUe = 0;
15626    uint16_t cellIdx =0, crnti=0;
15627    uint64_t cellId =0;
15628    CmLList *f1apPduNode = NULLP;
15629    ReservedF1apPduInfo *f1apPduInfo =NULLP;
15630    F1AP_PDU_t *f1apMsgPdu = NULLP;
15631    GNBDUConfigurationUpdate_t *gnbDuConfigUpdate = NULLP;
15632    BIT_STRING_t *cellIdentity=NULLP;
15633    struct Served_Cells_To_Delete_ItemIEs *deleteItemIe=NULLP;
15634    Served_Cells_To_Delete_List_t *cellsToDelete=NULLP;
15635    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
15636
15637    DU_LOG("\nINFO   -->  DU APP: GNB-DU config update Ack received ");
15638    f1apPduNode = searchFromReservedF1apPduList(transId);
15639    f1apPduInfo = (ReservedF1apPduInfo *)f1apPduNode->node;
15640    f1apMsgPdu = (F1AP_PDU_t *)f1apPduInfo->f1apMsg;
15641
15642    if(f1apMsgPdu)
15643    {
15644       if(f1apMsgPdu->choice.initiatingMessage)
15645       {
15646          gnbDuConfigUpdate = &f1apMsgPdu->choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
15647          for(ieIdx=0; ieIdx < gnbDuConfigUpdate->protocolIEs.list.count; ieIdx++)
15648          {
15649             switch(gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->id)
15650             {
15651                case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
15652                   {
15653                      cellsToDelete = &gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
15654                                      Served_Cells_To_Delete_List;
15655                      if(cellsToDelete->list.array)
15656                      {
15657                         if(cellsToDelete->list.array[arrIdx])
15658                         {
15659                            deleteItemIe = (Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx];
15660                            deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
15661                            if(deleteItem->oldNRCGI.nRCellIdentity.buf)
15662                            {
15663                               cellIdentity = &deleteItem->oldNRCGI.nRCellIdentity;
15664                               bitStringToInt(cellIdentity, &cellId);
15665
15666                               GET_CELL_IDX(cellId, cellIdx);
15667                               if(duCb.actvCellLst[cellIdx] != NULLP)
15668                               {
15669                                  duCb.actvCellLst[cellId-1]->cellStatus = DELETION_IN_PROGRESS;
15670                               }
15671                            }
15672                         }
15673                      }
15674
15675                      if(duCb.actvCellLst[cellIdx] != NULLP)
15676                      {
15677                         if(duCb.actvCellLst[cellIdx]->numActvUes == 0)
15678                         {
15679                            ret = duSendCellDeletReq(cellId);
15680                            if(ret == RFAILED)
15681                            {
15682                               DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to send cell delete\
15683                               request for cellId[%lu]", cellId);
15684                            }
15685                         }
15686                         else
15687                         {
15688                            totalActiveUe = duCb.actvCellLst[cellIdx]->numActvUes;
15689                            while(totalActiveUe)
15690                            {
15691                               if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState != UE_ACTIVE)
15692                               {
15693                                  ueIdx++;
15694                                  continue;
15695                               }
15696
15697                               crnti = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti;
15698                               GET_UE_ID(crnti,ueId);
15699                               /* Sending Ue Context release request only for maximum supporting UEs */
15700                               ret = BuildAndSendUeContextReleaseReq(cellId, ueId);
15701                               if(ret == RFAILED)
15702                               {
15703                                  DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to build and send UE delete\
15704                                  request for cellId[%lu]", cellId);
15705                               }
15706                               ueIdx++;
15707                               totalActiveUe--;
15708                            }
15709                         }
15710                      }
15711                      else
15712                      {
15713                         DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): CellId [%lu] not found", cellId);
15714                         ret = RFAILED;
15715                      }
15716                      break;
15717                   }
15718
15719                default:
15720                   break;
15721             }
15722          }
15723       }
15724    }
15725    
15726    FreeDUConfigUpdate(f1apMsgPdu);
15727    deleteFromReservedF1apPduList(f1apPduNode);
15728    return ret;
15729 }
15730
15731 /*******************************************************************
15732 *
15733 * @brief Processes GNB DU config update ack
15734 *
15735 * @details
15736 *
15737 *    Function : procF1GNBDUCfgUpdAck
15738 *
15739 *    Functionality: added free part for the memory allocated by aper_decoder
15740 *
15741 * @params[in] F1AP_PDU_t *f1apMsg,  MsgLen recvBufLen, char *recvBuf 
15742 * @return void 
15743 *
15744 * ****************************************************************/
15745
15746 uint8_t procF1GNBDUCfgUpdAck(F1AP_PDU_t *f1apMsg, MsgLen recvBufLen, char *recvBuf)
15747 {
15748    uint8_t ieIdx=0,transId=0;
15749    GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck = NULLP;
15750
15751    DU_LOG("\nINFO   -->  F1AP : GNB-DU config update acknowledgment");
15752    gnbDuAck = &f1apMsg->choice.successfulOutcome->value.choice.GNBDUConfigurationUpdateAcknowledge;
15753
15754    for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15755    {
15756       switch(gnbDuAck->protocolIEs.list.array[ieIdx]->id)
15757       {
15758          case ProtocolIE_ID_id_TransactionID:
15759             {
15760                transId = gnbDuAck->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
15761                break;
15762             }
15763          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15764             {
15765                break;
15766             }
15767          default :
15768             {
15769                DU_LOG("\nERROR  -->  F1AP: procF1GNBDUCfgUpdAck(): Invalid IE Received: %ld", \
15770                      gnbDuAck->protocolIEs.list.array[ieIdx]->id);
15771                break;
15772             }
15773       }
15774    }
15775    
15776    duProcGnbDuCfgUpdAckMsg(transId);
15777     
15778 #if 0
15779    /* presently we are not supporting F1 Reset from DU to CU , we are only
15780     * supporting F1 Reset from CU to DU */
15781
15782    if(BuildAndSendF1ResetReq() != ROK)
15783    {
15784       return RFAILED;
15785    }
15786 #endif
15787
15788    freeAperDecodeGnbDuAck(gnbDuAck);
15789    
15790    if(fillE2NodeComponentRspInfo(F1,duCfgParam.duId, E2_NODE_COMPONENT_UPDATE, recvBufLen, recvBuf) !=ROK)
15791    {
15792       DU_LOG("\nERROR  -->  F1AP : Failed to update the e2 node in the list");
15793       return RFAILED;
15794    }
15795
15796    return ROK;
15797 }
15798 /******************************************************************
15799 *
15800 * @brief free DL RRC Message Transfer allocated by aper_decoder 
15801 *
15802 * @details
15803 *
15804 *    Function : freeAperDecodef1DlRrcMsg 
15805 *
15806 *    Functionality: free DL RRC Message Transfer allocated by aper_decoder 
15807 *
15808 * @params[in] DLRRCMessageTransfer_t *f1DlRrcMsg 
15809 * @return ROK     - success
15810 *         RFAILED - failure
15811 *
15812 * ****************************************************************/
15813
15814 void freeAperDecodef1DlRrcMsg(DLRRCMessageTransfer_t *f1DlRrcMsg)
15815 {
15816    uint8_t ieIdx =0;
15817    RRCContainer_t *rrcContainer = NULLP;
15818
15819    if(f1DlRrcMsg->protocolIEs.list.array)
15820    {
15821       for(ieIdx=0; ieIdx<f1DlRrcMsg->protocolIEs.list.count; ieIdx++)
15822       {
15823          if(f1DlRrcMsg->protocolIEs.list.array[ieIdx])
15824          {
15825             switch(f1DlRrcMsg->protocolIEs.list.array[ieIdx]->id)
15826             {
15827                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15828                   break;
15829                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15830                   break;
15831                case ProtocolIE_ID_id_SRBID:
15832                   break;
15833                case ProtocolIE_ID_id_RRCContainer:
15834                   {
15835                      rrcContainer =&f1DlRrcMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer;
15836                      free(rrcContainer->buf);
15837                   }
15838                case ProtocolIE_ID_id_ExecuteDuplication:
15839                   break;
15840                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15841                   break;
15842                   break;
15843             }
15844             free(f1DlRrcMsg->protocolIEs.list.array[ieIdx]);
15845          }
15846       }
15847       free(f1DlRrcMsg->protocolIEs.list.array);
15848    }
15849 }
15850 /******************************************************************
15851  *
15852  * @brief Processes DL RRC Message Transfer  sent by CU
15853  *
15854  * @details
15855  *
15856  *    Function : procF1DlRrcMsgTrans
15857  *
15858  *    Functionality: Processes DL RRC Message Transfer sent by CU
15859  *
15860  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15861  * @return ROK     - success
15862  *         RFAILED - failure
15863  *
15864  * ****************************************************************/
15865 uint8_t procF1DlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
15866 {
15867    uint8_t  idx, ret;
15868    DLRRCMessageTransfer_t *f1DlRrcMsg = NULLP;
15869    F1DlRrcMsg dlMsg;
15870    memset(&dlMsg, 0, sizeof(F1DlRrcMsg));
15871
15872    DU_LOG("\nINFO   -->  DU_APP : DL RRC message transfer Recevied");
15873    f1DlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
15874
15875    ret = ROK;
15876
15877    for(idx=0; idx<f1DlRrcMsg->protocolIEs.list.count; idx++)
15878    {
15879       switch(f1DlRrcMsg->protocolIEs.list.array[idx]->id)
15880       {
15881          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15882             {
15883                dlMsg.gnbCuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
15884                break;
15885             }
15886          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15887             {
15888                dlMsg.gnbDuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
15889                break;
15890             }
15891          case ProtocolIE_ID_id_SRBID:
15892             {
15893                dlMsg.srbId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
15894                break;
15895             }
15896          case ProtocolIE_ID_id_ExecuteDuplication:
15897             dlMsg.execDup = true;
15898             break;
15899
15900          case ProtocolIE_ID_id_RRCContainer:
15901             {
15902                if(f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
15903                {
15904              dlMsg.rrcMsgSize = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
15905              DU_ALLOC_SHRABL_BUF(dlMsg.rrcMsgPdu, dlMsg.rrcMsgSize);
15906              if(dlMsg.rrcMsgPdu)
15907              {
15908                 memcpy(dlMsg.rrcMsgPdu, f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf,\
15909                       dlMsg.rrcMsgSize);
15910              }
15911              else
15912              {
15913                 DU_LOG("\nERROR  -->  DU APP : Memory alloc Failed at RRC Container at procF1DlRrcMsgTrans()");
15914                 return RFAILED;
15915              }
15916           }
15917           else
15918           {
15919              DU_LOG("\nERROR  -->  DU_APP : RRC Container Size is invalid:%ld",\
15920                    f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
15921              return RFAILED;
15922           }
15923           break;
15924        }
15925     case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15926        {
15927           dlMsg.deliveryStatRpt = true;
15928           break;
15929        }
15930     default:
15931        DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
15932              f1DlRrcMsg->protocolIEs.list.array[idx]->id);
15933       }
15934    }
15935
15936    ret = duProcDlRrcMsg(&dlMsg);
15937
15938    freeAperDecodef1DlRrcMsg(f1DlRrcMsg);
15939    return ret;
15940 }
15941 /*******************************************************************
15942  *
15943 * @brief Builds the DRB to be Setup Mod list
15944 *
15945 * @details
15946 *
15947 *    Function : 
15948 *
15949 *    Functionality: Constructs the DRB to be Setup Mod list
15950 *
15951 * @params[in] DRBs_SetupMod_List_t *drbSet
15952 *
15953 * @return ROK     - success
15954 *         RFAILED - failure
15955 *
15956 * ****************************************************************/
15957 uint8_t BuildSrbSetupModList(SRBs_SetupMod_List_t *srbList, DuUeCfg *ueCfg)
15958 {
15959    uint8_t srbIdx = 0;
15960    struct SRBs_SetupMod_ItemIEs *srbItemIe;
15961
15962    srbList->list.count = ueCfg->numRlcLcs;
15963    srbList->list.size = srbList->list.count * sizeof(SRBs_SetupMod_ItemIEs_t *);
15964
15965    DU_ALLOC(srbList->list.array, srbList->list.size);
15966    if(srbList->list.array == NULLP)
15967    {
15968       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15969       return RFAILED;
15970    }
15971
15972    for(srbIdx = 0; srbIdx < srbList->list.count; srbIdx++)
15973    {
15974       DU_ALLOC(srbList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15975       if(srbList->list.array[srbIdx] == NULLP)
15976       {
15977          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15978          return RFAILED;
15979       }
15980    } 
15981
15982    for(srbIdx=0; srbIdx < srbList->list.count; srbIdx++)
15983    {
15984       srbItemIe = (struct SRBs_SetupMod_ItemIEs *)srbList->list.array[srbIdx];
15985       srbItemIe->id = ProtocolIE_ID_id_SRBs_SetupMod_Item;
15986       srbItemIe->criticality = Criticality_reject;
15987       srbItemIe->value.present = SRBs_SetupMod_ItemIEs__value_PR_SRBs_SetupMod_Item;
15988       srbItemIe->value.choice.SRBs_SetupMod_Item.sRBID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.rbId;
15989       srbItemIe->value.choice.SRBs_SetupMod_Item.lCID = ueCfg->rlcLcCfg[srbIdx].rlcBearerCfg.lcId;
15990    }
15991    return ROK;
15992 }
15993
15994 /*******************************************************************
15995  *
15996 * @brief Builds the DRB to be Setup Mod list
15997 *
15998 * @details
15999 *
16000 *    Function : 
16001 *
16002 *    Functionality: Constructs the DRB to be Setup Mod list
16003 *
16004 * @params[in] DRBs_SetupMod_List_t *drbSet
16005 *
16006 * @return ROK     - success
16007 *         RFAILED - failure
16008 *
16009 * ****************************************************************/
16010
16011 uint8_t BuildDrbSetupModList(DRBs_SetupMod_List_t *drbSet , DuUeCfg *ueCfg)
16012 {
16013    uint8_t arrIdx =0;
16014    uint8_t drbCnt =0;
16015    struct DRBs_SetupMod_ItemIEs *drbItemIe;
16016
16017    drbCnt = ueCfg->numDrbSetupMod;
16018
16019    drbSet->list.count = drbCnt;
16020    drbSet->list.size = drbCnt * sizeof(DRBs_SetupMod_ItemIEs_t *);
16021    DU_ALLOC(drbSet->list.array, drbSet->list.size);
16022    if(drbSet->list.array == NULLP)
16023    {
16024       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
16025       return  RFAILED;
16026    }
16027    for(arrIdx=0; arrIdx<drbCnt; arrIdx++)
16028    {
16029       DU_ALLOC(drbSet->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
16030       if(drbSet->list.array[arrIdx] == NULLP)
16031       {
16032               DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
16033               return  RFAILED;
16034       }
16035
16036       drbItemIe = (struct DRBs_SetupMod_ItemIEs *)drbSet->list.array[arrIdx];
16037       drbItemIe->id = ProtocolIE_ID_id_DRBs_SetupMod_Item;
16038       drbItemIe->criticality = Criticality_reject;
16039       drbItemIe->value.present = DRBs_SetupMod_ItemIEs__value_PR_DRBs_SetupMod_Item;
16040       drbItemIe->value.choice.DRBs_SetupMod_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
16041       if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List,\
16042       &ueCfg->upTnlInfo[arrIdx])!= ROK)
16043       {
16044          DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbToBeSetupModList");
16045          return RFAILED;
16046       }
16047       
16048    }
16049
16050    return ROK;
16051 }
16052 /*******************************************************************
16053 * @brief Free the memory allocated for DRB setup List
16054 *
16055 * @details
16056 *
16057 *    Function : FreeDrbSetupModList 
16058 *
16059 *    Functionality:
16060 *       Free the memory allocated for DRB setup list
16061 *
16062 * @params[in] DRBs_Setup_List_t *
16063 * @return void
16064 *
16065 * ****************************************************************/
16066 void FreeDrbSetupModList(DRBs_SetupMod_List_t *drbSetupList)
16067 {
16068    uint8_t arrIdx = 0;
16069    DRBs_SetupMod_ItemIEs_t *drbItemIe = NULLP;
16070
16071    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
16072    {
16073       drbItemIe = ((DRBs_SetupMod_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
16074       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List);
16075       DU_FREE(drbSetupList->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
16076    }
16077    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
16078 }
16079
16080 /*******************************************************************
16081 *
16082 * @brief Builds the DRB to be Mod list
16083 *
16084 * @details
16085 *
16086 *    Function : 
16087 *
16088 *    Functionality: Constructs the DRB to be Mod list
16089 *
16090 * @params[in] DRBs_Modified_List_t *drbModList
16091 *
16092 * @return ROK     - success
16093 *         RFAILED - failure
16094 *
16095 * ****************************************************************/
16096
16097 uint8_t BuildDrbModList(DRBs_Modified_List_t *drbModList, DuUeCfg *ueCfg)
16098 {
16099    uint8_t arrIdx =0, drbIdx = 0;
16100    uint8_t drbCnt =0;
16101    struct DRBs_Modified_ItemIEs *drbItemIe;
16102
16103    drbCnt = ueCfg->numDrbModified;
16104
16105    drbModList->list.count = drbCnt;
16106    drbModList->list.size = drbCnt * sizeof(DRBs_Modified_ItemIEs_t *);
16107    DU_ALLOC(drbModList->list.array, drbModList->list.size);
16108    if(drbModList->list.array == NULLP)
16109    {
16110       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList()");
16111       return  RFAILED;
16112    }
16113
16114    drbIdx = 0;
16115    for(arrIdx = 0; arrIdx < ueCfg->numMacLcs; arrIdx++)
16116    {
16117       if(ueCfg->macLcCfg[arrIdx].configType == CONFIG_MOD)
16118       {
16119          DU_ALLOC(drbModList->list.array[drbIdx], sizeof(DRBs_Modified_ItemIEs_t));
16120          if(drbModList->list.array[drbIdx] == NULLP)
16121          {
16122             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbModList");
16123             return  RFAILED;
16124          }
16125
16126          drbItemIe = (struct DRBs_Modified_ItemIEs *)drbModList->list.array[drbIdx];
16127          drbItemIe->id = ProtocolIE_ID_id_DRBs_Modified_Item;
16128          drbItemIe->criticality = Criticality_reject;
16129          drbItemIe->value.present = DRBs_Modified_ItemIEs__value_PR_DRBs_Modified_Item;
16130          drbItemIe->value.choice.DRBs_Modified_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
16131          if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List,\
16132                   &ueCfg->upTnlInfo[arrIdx])!= ROK)
16133          {
16134             DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbModList");
16135             return RFAILED;
16136          }
16137          drbIdx++;
16138       } 
16139    }
16140
16141    return ROK;
16142 }
16143
16144 /*******************************************************************
16145 * @brief Free the memory allocated for DRB Mod List
16146 *
16147 * @details
16148 *
16149 *    Function : FreeDrbModList 
16150 *
16151 *    Functionality:
16152 *       Free the memory allocated for DRB modified list
16153 *
16154 * @params[in] DRBs_Modified_List_t *
16155 * @return void
16156 *
16157 * ****************************************************************/
16158 void FreeDrbModList(DRBs_Modified_List_t *drbModList)
16159 {
16160    uint8_t arrIdx = 0;
16161    DRBs_Modified_ItemIEs_t *drbItemIe = NULLP;
16162
16163    for(arrIdx = 0; arrIdx < drbModList->list.count; arrIdx++)
16164    {
16165       drbItemIe = ((DRBs_Modified_ItemIEs_t *)drbModList->list.array[arrIdx]);
16166       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Modified_Item.dLUPTNLInformation_ToBeSetup_List);
16167       DU_FREE(drbModList->list.array[arrIdx], sizeof(DRBs_Modified_ItemIEs_t));
16168    }
16169    DU_FREE(drbModList->list.array, drbModList->list.size);
16170 }
16171
16172 /*******************************************************************
16173 * @brief Free the memory allocated for SRB setup List
16174 *
16175 * @details
16176 *
16177 *    Function : FreeSrbSetupModList 
16178 *
16179 *    Functionality:
16180 *       Free the memory allocated for SRB setup list
16181 *
16182 * @params[in] SRBs_Setup_List_t *
16183 * @return void
16184 *
16185 * ****************************************************************/
16186 void FreeSrbSetupModList(SRBs_SetupMod_List_t *srbSetupList)
16187 {
16188    uint8_t srbIdx = 0;
16189    
16190    for(srbIdx = 0; srbIdx < srbSetupList->list.count; srbIdx++)
16191       DU_FREE(srbSetupList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
16192    DU_FREE(srbSetupList->list.array, srbSetupList->list.size);
16193 }
16194
16195 /*******************************************************************
16196 * @brief Free the memory allocated for UE Context Mod Response
16197 *
16198 * @details
16199 *
16200 *    Function : FreeUeContextModResp 
16201 *
16202 *    Functionality:
16203 *       Free the memory allocated for UE Context Mod Response
16204 *
16205 * @params[in] F1AP_PDU_t *f1apMsg
16206 * @return void
16207 *
16208 * ****************************************************************/
16209
16210 void FreeUeContextModResp(F1AP_PDU_t *f1apMsg)
16211 {
16212    uint8_t ieIdx;
16213    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
16214    if(f1apMsg)
16215    {
16216       if(f1apMsg->choice.successfulOutcome)
16217       {
16218          ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
16219          if(ueContextModifyRes->protocolIEs.list.array)
16220          {
16221             for(ieIdx=0 ; ieIdx<ueContextModifyRes->protocolIEs.list.count; ieIdx++)
16222             {
16223                if(ueContextModifyRes->protocolIEs.list.array[ieIdx])
16224                {
16225                   switch(ueContextModifyRes->protocolIEs.list.array[ieIdx]->id)
16226                   {
16227                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16228                         break;
16229                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16230                         break;
16231                      case ProtocolIE_ID_id_DUtoCURRCInformation:
16232                         {
16233                            DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.\
16234                               cellGroupConfig.buf, ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
16235                               DUtoCURRCInformation.cellGroupConfig.size);
16236                            break;
16237                         }
16238                      case ProtocolIE_ID_id_DRBs_SetupMod_List:
16239                         {
16240                             FreeDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16241                             value.choice.DRBs_SetupMod_List));
16242                             break;
16243                         }
16244                      case ProtocolIE_ID_id_DRBs_Modified_List:
16245                         {
16246                             FreeDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16247                             value.choice.DRBs_Modified_List));
16248                             break;
16249                         }
16250                      case ProtocolIE_ID_id_SRBs_SetupMod_List:
16251                         {
16252                            FreeSrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
16253                               SRBs_SetupMod_List));
16254                            break; 
16255                         }
16256                   }
16257                   DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
16258                }
16259
16260             }
16261             DU_FREE(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
16262          }
16263          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16264       }
16265       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
16266    }
16267 }
16268
16269 /*****************************************************************i
16270 *
16271 * @brief Creating the ue context modifcation response and sending
16272 *
16273 * @details
16274 *
16275 *    Function : BuildAndSendUeContextModRsp 
16276 *
16277 *    Functionality:
16278 *         - Creating the ue context modifcation response 
16279 *
16280 * @params[in] uint8_t cellId,uint8_t ueId
16281 * @return ROK     - success
16282 *         RFAILED - failure
16283 *
16284 * ****************************************************************/
16285 uint8_t BuildAndSendUeContextModRsp(DuUeCb *ueCb)
16286 {
16287    uint8_t   ieIdx = 0, tnlIdx = 0, rbIdx = 0;
16288    uint8_t   elementCnt = 0;
16289    uint8_t   ret = RFAILED;
16290    F1AP_PDU_t *f1apMsg = NULLP;
16291    asn_enc_rval_t  encRetVal;
16292    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
16293
16294    DU_LOG("\nINFO  -->  F1AP : Building UE context modification response\n");
16295
16296    while(true)
16297    {
16298       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
16299       if(f1apMsg == NULLP)
16300       {
16301          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16302          break;
16303       }
16304
16305       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
16306
16307       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16308       if(f1apMsg->choice.successfulOutcome == NULLP)
16309       {
16310          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
16311          break;
16312       }
16313       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextModification;
16314       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
16315       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_UEContextModificationResponse;
16316
16317       ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
16318   
16319       if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
16320       {
16321          elementCnt = 2;
16322          if(ueCb->f1UeDb->duUeCfg.numDrbSetupMod)
16323             elementCnt++;
16324          if(ueCb->f1UeDb->duUeCfg.numDrbModified)
16325             elementCnt++; 
16326       }
16327       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16328       {
16329          elementCnt = 5;
16330       }
16331       if(ueCb->f1UeDb->actionType == UE_CTXT_RRC_RECFG_COMPLETE)
16332          elementCnt = 2;
16333       ueContextModifyRes->protocolIEs.list.count = elementCnt;
16334       ueContextModifyRes->protocolIEs.list.size = elementCnt*sizeof(UEContextModificationResponse_t*);
16335
16336       /* Initialize the UE context modification members */
16337       DU_ALLOC(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
16338       if(ueContextModifyRes->protocolIEs.list.array == NULLP)
16339       {
16340          DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16341          break;
16342       }
16343
16344       for(ieIdx=0 ; ieIdx<elementCnt; ieIdx++)
16345       {
16346          DU_ALLOC(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
16347          if(ueContextModifyRes->protocolIEs.list.array[ieIdx] == NULLP)
16348          {
16349             DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
16350             break;
16351          }
16352       }
16353
16354       ieIdx=0;
16355       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
16356       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16357       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16358       UEContextModificationResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
16359       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
16360
16361       ieIdx++;
16362       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16363       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16364       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present=\
16365       UEContextModificationResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
16366       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
16367
16368       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16369       {
16370          ieIdx++;
16371          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCInformation;
16372          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16373          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16374          UEContextModificationResponseIEs__value_PR_DUtoCURRCInformation;
16375          BuildCellGroupConfigRrc(ueCb, &ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
16376       }
16377
16378       if((ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY) || \
16379            ((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbSetupMod)))
16380       { 
16381          ieIdx++;
16382          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_SetupMod_List;
16383          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16384          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16385                                                                            UEContextModificationResponseIEs__value_PR_DRBs_SetupMod_List;
16386          if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16387          {
16388             for(tnlIdx = 0; tnlIdx < duCb.numTeId; tnlIdx++)
16389             {
16390                if(duCb.upTnlCfg[tnlIdx]->ueId == ueCb->gnbDuUeF1apId)
16391                {
16392                   memcpy(&ueCb->f1UeDb->duUeCfg.upTnlInfo[ueCb->f1UeDb->duUeCfg.numDrbSetupMod++], duCb.upTnlCfg[tnlIdx], sizeof(UpTnlCfg));
16393                }
16394             }
16395          }
16396          ret = BuildDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16397                   value.choice.DRBs_SetupMod_List) , &ueCb->f1UeDb->duUeCfg);
16398          if(ret != ROK)
16399          {
16400             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB setupmod List ");
16401             break;
16402          }
16403       }
16404
16405       if((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbModified))
16406       { 
16407          ieIdx++;
16408          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_Modified_List;
16409          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16410          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
16411                                                                     UEContextModificationResponseIEs__value_PR_DRBs_Modified_List;
16412          ret = BuildDrbModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
16413                                  value.choice.DRBs_Modified_List) , &ueCb->f1UeDb->duUeCfg);
16414          if(ret != ROK)
16415          {
16416             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB Modified List ");
16417             break;
16418          }
16419       }
16420
16421       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
16422       {
16423          ieIdx++;
16424          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_SRBs_SetupMod_List;
16425          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
16426          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
16427                                                                             UEContextModificationResponseIEs__value_PR_SRBs_SetupMod_List;
16428          for(rbIdx = 0; rbIdx < ueCb->duRlcUeCfg.numLcs; rbIdx++)
16429          {
16430             if(ueCb->duRlcUeCfg.rlcLcCfg[rbIdx].rlcBearerCfg.rbType == RB_TYPE_SRB)
16431             {
16432                memcpy(&ueCb->f1UeDb->duUeCfg.rlcLcCfg[ueCb->f1UeDb->duUeCfg.numRlcLcs++], &ueCb->duRlcUeCfg.rlcLcCfg[rbIdx],\
16433                      sizeof(DuRlcBearerCfg));
16434             }
16435          }
16436          ret = BuildSrbSetupModList(&ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.SRBs_SetupMod_List, \
16437                &ueCb->f1UeDb->duUeCfg);
16438          if(ret != ROK)
16439          {
16440             DU_LOG( "\nERROR  -->  F1AP : Failed to build SRB setupmod List ");
16441             break;
16442          }
16443       }
16444
16445       freeF1UeDb(ueCb->f1UeDb);
16446       ueCb->f1UeDb = NULLP;
16447
16448       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16449
16450       /* Encode the F1SetupRequest type as APER */
16451       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16452       encBufSize = 0;
16453       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,encBuf);
16454
16455       /* Encode results */
16456       if(encRetVal.encoded == ENCODE_FAIL)
16457       {
16458          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Modification Response structure (at %s)\n",\
16459                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16460          ret = RFAILED;
16461          break;
16462       }
16463       else
16464       {
16465          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Modification Response\n");
16466 #ifdef DEBUG_ASN_PRINT
16467          for(int i=0; i< encBufSize; i++)
16468          {
16469             printf("%x",encBuf[i]);
16470          }
16471 #endif
16472       }
16473
16474       /* Sending  msg  */
16475       if(sendF1APMsg() != ROK && (ret == ROK))
16476       {
16477          DU_LOG("\nERROR  -->  F1AP : Sending UE Modification Res Failed");
16478          ret = RFAILED;
16479          break;
16480       }
16481
16482       ret = ROK;
16483       break;
16484    }
16485
16486    FreeUeContextModResp(f1apMsg);
16487    return ret;
16488 }
16489
16490 /*******************************************************************
16491  *
16492  * @brief Deallocating the memory allocated by the aper decoder
16493  *          for QOSInfo
16494  *
16495  * @details
16496  *
16497  *    Function : freeAperDecodeQosInfo
16498  *
16499  *    Functionality:  Deallocating the memory allocated for QOSInfo
16500  *
16501  * @params[in] QoSFlowLevelQoSParameters_t *drbQos
16502  *
16503  * @return void
16504  *
16505  * ****************************************************************/
16506
16507 void freeAperDecodeQosInfo(QoSFlowLevelQoSParameters_t *drbQos)
16508 {
16509    if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI != NULLP)
16510    {
16511       if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
16512       {
16513          if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
16514          {
16515             free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
16516          }
16517          free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
16518       }
16519       free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI);
16520    }
16521 }
16522 /*******************************************************************
16523  *
16524  * @brief Deallocating the memory allocated by the aper decoder
16525  *          for UlTnlInfoforDrb
16526  *
16527  * @details
16528  *
16529  *    Function : freeAperDecodeUlTnlInfoforDrbSetupMod 
16530  *
16531  *    Functionality:  Deallocating memory allocated for UlTnlInfoforDrb
16532  *
16533  * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
16534  *
16535  * @return void
16536  *
16537  * ****************************************************************/
16538 void freeAperDecodeUlTnlInfoforDrbSetupMod(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
16539 {
16540    uint8_t arrIdx =0;
16541
16542    if(ulInfo->list.array)
16543    {
16544       for(arrIdx=0; arrIdx<ulInfo->list.count ; arrIdx++)
16545       {
16546          if(ulInfo->list.array[arrIdx])
16547          {
16548             if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel )
16549             {
16550                if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf)
16551                {
16552                   if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf)
16553                   {
16554                      free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16555                            gTP_TEID.buf);
16556                   }
16557                   free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
16558                         transportLayerAddress.buf);
16559                }
16560                free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel);
16561             }
16562             free(ulInfo->list.array[arrIdx]);
16563          }
16564       }
16565       free(ulInfo->list.array);
16566    }
16567 }
16568
16569 /*******************************************************************
16570  *
16571  * @brief Deallocating the memory allocated by the aper decoder
16572  *          for DrbSetupModItem  
16573  *
16574  * @details
16575  *
16576  *    Function : freeAperDecodeDrbSetupModItem 
16577  *
16578  *    Functionality:  Deallocating memory allocated for DrbSetupModItem
16579  *
16580  * @params[in] DRBs_ToBeSetupMod_Item_t *drbItem
16581  *
16582  * @return void
16583  *
16584  * ****************************************************************/
16585
16586 void freeAperDecodeDrbSetupModItem(DRBs_ToBeSetupMod_Item_t *drbItem)
16587 {
16588    uint8_t arrIdx =0;
16589    SNSSAI_t *snssai =NULLP;
16590    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16591
16592    drbItem->qoSInformation.present = QoSInformation_PR_choice_extension;
16593    switch(drbItem->qoSInformation.present)
16594    {
16595       case QoSInformation_PR_NOTHING:
16596          break;
16597       case QoSInformation_PR_eUTRANQoS:
16598          {
16599             if(drbItem->qoSInformation.choice.eUTRANQoS)
16600             {
16601                free(drbItem->qoSInformation.choice.eUTRANQoS);
16602             }
16603             break;
16604          }
16605       case QoSInformation_PR_choice_extension:
16606          {
16607             if(drbItem->qoSInformation.choice.choice_extension)
16608             {
16609                freeAperDecodeQosInfo(&drbItem->qoSInformation.choice.choice_extension->value.choice.\
16610                      DRB_Information.dRB_QoS);
16611                snssai = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16612                if(snssai->sST.buf)
16613                {
16614                   free(snssai->sST.buf);
16615                }
16616                if(snssai->sD)
16617                {
16618                   if(snssai->sD->buf)
16619                   {
16620                      free(snssai->sD->buf);
16621                   }
16622                   free(snssai->sD);
16623                }
16624
16625                flowMap = &drbItem->qoSInformation.choice.choice_extension->value.choice.\
16626                          DRB_Information.flows_Mapped_To_DRB_List;
16627                if(flowMap->list.array)
16628                {
16629                   for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16630                   {
16631                      if(flowMap->list.array[arrIdx] )
16632                      {
16633                         freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16634                         free(flowMap->list.array[arrIdx]);
16635                      }
16636                   }
16637                   free(flowMap->list.array);
16638                }
16639
16640                free(drbItem->qoSInformation.choice.choice_extension);
16641             }
16642             break;
16643          }
16644
16645    }
16646    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16647    if(drbItem->uLConfiguration)
16648    {
16649       free(drbItem->uLConfiguration);
16650    }
16651 }
16652
16653 /*******************************************************************
16654  *
16655  * @brief Deallocating the memory allocated by the aper decoder
16656  *          for DrbToBeSetupModList
16657  *
16658  * @details
16659  *
16660  *    Function : freeAperDecodeDrbToBeSetupModList
16661  *
16662  *    Functionality:  Deallocating memory allocated for DrbToBeSetupModList
16663  *
16664  * @params[in] DRBs_ToBeSetupMod_List_t *drbSet
16665  *
16666  * @return void
16667  *
16668  * ****************************************************************/
16669
16670 void freeAperDecodeDrbToBeSetupModList(DRBs_ToBeSetupMod_List_t *drbSet)
16671 {
16672    uint8_t arrIdx =0;
16673    struct DRBs_ToBeSetupMod_ItemIEs *drbItemIe;
16674
16675    if(drbSet->list.array)
16676    {
16677       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16678       {
16679          if(drbSet->list.array[arrIdx] != NULLP)
16680          {
16681             if(arrIdx == 0)
16682             {
16683                drbItemIe = (DRBs_ToBeSetupMod_ItemIEs_t *)drbSet->list.array[arrIdx];
16684                freeAperDecodeDrbSetupModItem(&(drbItemIe->value.choice.DRBs_ToBeSetupMod_Item));
16685             }
16686             free(drbSet->list.array[arrIdx]);
16687          }
16688       }
16689       free(drbSet->list.array);
16690    }
16691
16692 }
16693
16694 /*******************************************************************
16695  *
16696  * @brief Deallocating the memory allocated by the aper decoder
16697  *          for DrbSetupModItem  
16698  *
16699  * @details
16700  *
16701  *    Function : freeAperDecodeDrbModifiedItem 
16702  *
16703  *    Functionality:  Deallocating memory allocated for DrbModifedItem
16704  *
16705  * @params[in] DRBs_ToBeModified_Item_t *drbItem
16706  *
16707  * @return void
16708  *
16709  * ****************************************************************/
16710
16711 void freeAperDecodeDrbModifiedItem(DRBs_ToBeModified_Item_t *drbItem)
16712 {
16713    uint8_t arrIdx =0;
16714    SNSSAI_t *snssai =NULLP;
16715    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16716
16717    if(drbItem->qoSInformation != NULLP)
16718    {
16719       drbItem->qoSInformation->present = QoSInformation_PR_choice_extension;
16720       switch(drbItem->qoSInformation->present)
16721       {
16722          case QoSInformation_PR_NOTHING:
16723             break;
16724          case QoSInformation_PR_eUTRANQoS:
16725             {
16726                if(drbItem->qoSInformation->choice.eUTRANQoS)
16727                {
16728                   free(drbItem->qoSInformation->choice.eUTRANQoS);
16729                }
16730                break;
16731             }
16732          case QoSInformation_PR_choice_extension:
16733             {
16734                if(drbItem->qoSInformation->choice.choice_extension)
16735                {
16736                   freeAperDecodeQosInfo(&drbItem->qoSInformation->choice.choice_extension->value.choice.\
16737                         DRB_Information.dRB_QoS);
16738                   snssai = &drbItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16739                   if(snssai->sST.buf)
16740                   {
16741                      free(snssai->sST.buf);
16742                   }
16743                   if(snssai->sD)
16744                   {
16745                      if(snssai->sD->buf)
16746                      {
16747                         free(snssai->sD->buf);
16748                      }
16749                      free(snssai->sD);
16750                   }
16751
16752                   flowMap = &drbItem->qoSInformation->choice.choice_extension->value.choice.\
16753                             DRB_Information.flows_Mapped_To_DRB_List;
16754                   if(flowMap->list.array)
16755                   {
16756                      for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16757                      {
16758                         if(flowMap->list.array[arrIdx] )
16759                         {
16760                            freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16761                            free(flowMap->list.array[arrIdx]);
16762                         }
16763                      }
16764                      free(flowMap->list.array);
16765                   }
16766
16767                   free(drbItem->qoSInformation->choice.choice_extension);
16768                }
16769                break;
16770             }
16771       }
16772       free(drbItem->qoSInformation);
16773    }
16774    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16775    if(drbItem->uLConfiguration)
16776    {
16777       free(drbItem->uLConfiguration);
16778    }
16779 }
16780
16781 /*******************************************************************
16782  *
16783  * @brief Deallocating the memory allocated by the aper decoder
16784  *          for DrbToBeSetupModList
16785  *
16786  * @details
16787  *
16788  *    Function : freeAperDecodeDrbToBeModifiedList
16789  *
16790  *    Functionality:  Deallocating memory allocated for DrbToBeModifiedList
16791  *
16792  * @params[in] DRBs_ToBeModified_List_t *drbSet
16793  *
16794  * @return void
16795  *
16796  * ****************************************************************/
16797
16798 void freeAperDecodeDrbToBeModifiedList(DRBs_ToBeModified_List_t *drbSet)
16799 {
16800    uint8_t arrIdx =0;
16801    struct DRBs_ToBeModified_ItemIEs *drbItemIe;
16802
16803    if(drbSet->list.array)
16804    {
16805       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16806       {
16807          if(drbSet->list.array[arrIdx] != NULLP)
16808          {
16809             if(arrIdx == 0)
16810             {
16811                drbItemIe = (DRBs_ToBeModified_ItemIEs_t *)drbSet->list.array[arrIdx];
16812                freeAperDecodeDrbModifiedItem(&(drbItemIe->value.choice.DRBs_ToBeModified_Item));
16813             }
16814             free(drbSet->list.array[arrIdx]);
16815          }
16816       }
16817       free(drbSet->list.array);
16818    }
16819
16820 }
16821
16822 /*******************************************************************
16823  *
16824  * @brief Deallocating the memory allocated by the aper decoder
16825  *          for DrbToBeSetupModList
16826  *
16827  * @details
16828  *
16829  *    Function : freeAperDecodeDrbToBeReleasedList
16830  *
16831  *    Functionality:  Deallocating memory allocated for DrbToBeReleasedList
16832  *
16833  * @params[in] DRBs_ToBeReleased_List_t *drbSet
16834  *
16835  * @return void
16836  *
16837  * ****************************************************************/
16838
16839 void freeAperDecodeDrbToBeReleasedList(DRBs_ToBeReleased_List_t *drbSet)
16840 {
16841    uint8_t arrIdx =0;
16842
16843    if(drbSet->list.array)
16844    {
16845       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16846       {
16847          if(drbSet->list.array[arrIdx] != NULLP)
16848          {
16849             free(drbSet->list.array[arrIdx]);
16850          }
16851       }
16852       free(drbSet->list.array);
16853    }
16854
16855 }
16856 /*******************************************************************
16857  *
16858  * @brief Deallocating the memory allocated by the aper decoder
16859  *          for UeContextModificationReqMsg
16860  *
16861  * @details
16862  *
16863  *    Function : freeAperDecodeUeContextModificationReqMsg
16864  *
16865  *    Functionality:  Deallocating memory allocated for
16866  *                  UeContextModificationReqMsg
16867  *
16868  * @params[in] UEContextModificationRequest_t *UeContextModifyReq
16869  *
16870  * @return void
16871  *
16872  * ****************************************************************/
16873 void freeAperDecodeUeContextModificationReqMsg(UEContextModificationRequest_t *ueContextModifyReq )
16874 {
16875    uint8_t arrIdx, ieId;
16876
16877    if(ueContextModifyReq->protocolIEs.list.array)
16878    {
16879       for( arrIdx = 0 ; arrIdx<ueContextModifyReq->protocolIEs.list.count ; arrIdx++)
16880       {
16881          if(ueContextModifyReq->protocolIEs.list.array[arrIdx])
16882          {
16883             ieId = ueContextModifyReq->protocolIEs.list.array[arrIdx]->id;
16884             switch(ieId)
16885             {
16886                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16887                   break;
16888                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16889                   break;
16890                case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
16891                   {
16892                      freeAperDecodeDrbToBeSetupModList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16893                            value.choice.DRBs_ToBeSetupMod_List);
16894                      break;
16895                   }
16896                case ProtocolIE_ID_id_DRBs_ToBeModified_List:
16897                   {
16898                      freeAperDecodeDrbToBeModifiedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16899                            value.choice.DRBs_ToBeModified_List);
16900                      break;
16901                   }
16902                case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
16903                   {
16904                      freeAperDecodeDrbToBeReleasedList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16905                            value.choice.DRBs_ToBeReleased_List);
16906                      break;
16907                   }
16908                case ProtocolIE_ID_id_TransmissionActionIndicator:
16909                   break;
16910                case ProtocolIE_ID_id_RRCContainer:
16911                   {
16912                      free(ueContextModifyReq->protocolIEs.list.array[arrIdx]->value.choice.RRCContainer.buf);
16913                   }
16914             }
16915             free(ueContextModifyReq->protocolIEs.list.array[arrIdx]);
16916          }
16917       }
16918       free(ueContextModifyReq->protocolIEs.list.array);
16919    }
16920 }
16921 /*******************************************************************
16922  *
16923  * @brief processing the F1 UeContextModificationReq
16924  *
16925  * @details
16926  *
16927  *    Function : procF1UeContextModificationReq
16928  *
16929  *    Functionality:  processing the F1 UeContextModificationReq
16930  *
16931  * @params[in] F1AP_PDU_t *f1apMsg
16932  *
16933  * @return
16934  * ****************************************************************/
16935 uint8_t procF1UeContextModificationReq(F1AP_PDU_t *f1apMsg)
16936 {
16937    UEContextModificationRequest_t *ueContextModifyReq = NULLP;
16938    uint8_t  ret = ROK, ieIdx = 0, cellIdx=0;
16939    DuUeCb   *duUeCb = NULLP;
16940    DRBs_ToBeSetupMod_List_t *drbSetupModCfg = NULLP;
16941    DRBs_ToBeModified_List_t *drbModifiedCfg = NULLP;
16942    DRBs_ToBeReleased_List_t *drbToRelease = NULLP;
16943    uint32_t gnbCuUeF1apId, gnbDuUeF1apId;
16944
16945    ueContextModifyReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextModificationRequest;
16946    for(ieIdx=0; (ieIdx < ueContextModifyReq->protocolIEs.list.count && ret == ROK); ieIdx++)
16947    {
16948       switch(ueContextModifyReq->protocolIEs.list.array[ieIdx]->id)
16949       {
16950          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16951             {
16952                gnbCuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
16953                break;
16954             }
16955          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16956             {
16957                gnbDuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
16958                for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
16959                {
16960                   if(duCb.actvCellLst[cellIdx])
16961                   {
16962                      if((duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbDuUeF1apId == gnbDuUeF1apId)&&\
16963                            (duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbCuUeF1apId == gnbCuUeF1apId))
16964                      {
16965                         duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1];
16966                         if(duUeCb->f1UeDb == NULLP)
16967                         {
16968                            DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
16969                            duUeCb->f1UeDb->cellIdx = cellIdx;
16970                            duUeCb->f1UeDb->actionType = UE_CTXT_MOD;
16971                         }
16972                         break;
16973                      }
16974                   }
16975                }
16976                if(duUeCb == NULLP)
16977                {
16978                   DU_LOG("\nERROR  -->  DU APP : wrong values of gnbCuUeF1apId and gnbDuUeF1apId ");
16979                   ret = RFAILED;
16980                }
16981                break;
16982             }
16983
16984          case ProtocolIE_ID_id_RRCContainer:
16985             {
16986                /* Filling Dl RRC Msg Info */
16987                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
16988                if(!duUeCb->f1UeDb->dlRrcMsg)
16989                {
16990                   DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16991                         Memory allocation failed ");
16992                   ret = RFAILED;
16993                }
16994                else
16995                {
16996                   duUeCb->f1UeDb->dlRrcMsgPres = true;
16997                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
16998                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
16999                         &ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
17000                         value.choice.RRCContainer);
17001                }
17002
17003                break;
17004             }
17005
17006          case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
17007          case ProtocolIE_ID_id_DRBs_ToBeModified_List:
17008          case ProtocolIE_ID_id_DRBs_ToBeReleased_List:
17009             {
17010                if(duUeCb->f1UeDb)
17011                {
17012                   /*DRBs to be Added*/
17013                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present ==\
17014                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List)
17015                   {
17016                      drbSetupModCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17017                                       choice.DRBs_ToBeSetupMod_List;
17018
17019                      if(extractDrbListToSetupMod(NULL, drbSetupModCfg, NULL, drbSetupModCfg->list.count,\
17020                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULL))
17021                      {
17022                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbSetupModList");
17023                         ret = RFAILED;
17024                      }
17025                   }
17026
17027                   /*DRBs to be Modified*/
17028                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
17029                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List)
17030
17031                   {
17032                      drbModifiedCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17033                                       choice.DRBs_ToBeModified_List;
17034                      if(extractDrbListToSetupMod(NULL, NULL, drbModifiedCfg, drbModifiedCfg->list.count,\
17035                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, &duUeCb->duRlcUeCfg))
17036                      {
17037                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
17038                         ret = RFAILED;
17039                      }
17040                   }
17041                   /*DRBs to be Released*/
17042                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
17043                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeReleased_List)
17044
17045                   {
17046                      drbToRelease = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
17047                                       choice.DRBs_ToBeReleased_List;
17048                      if(extractDrbListToRelease(gnbDuUeF1apId, drbToRelease, drbToRelease->list.count,\
17049                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->duRlcUeCfg))
17050                      {
17051                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
17052                         ret = RFAILED;
17053                      }
17054                   }
17055                }
17056                break;
17057             }
17058
17059          case ProtocolIE_ID_id_GNB_DUConfigurationQuery:
17060             {
17061                DU_LOG("\nINFO  -->  DU APP : Received GNB DU Configuration Query in UE Context Modification Request from CU");
17062                if(duUeCb->f1UeDb)
17063                {
17064                   duUeCb->f1UeDb->actionType = UE_CTXT_CFG_QUERY;
17065                }
17066                break;
17067             }
17068
17069          case ProtocolIE_ID_id_RRCReconfigurationCompleteIndicator:
17070             {
17071                if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.RRCReconfigurationCompleteIndicator == \
17072                   RRCReconfigurationCompleteIndicator_true)
17073                {
17074                   duUeCb->f1UeDb->actionType = UE_CTXT_RRC_RECFG_COMPLETE;
17075                }
17076                break;
17077             }
17078          case ProtocolIE_ID_id_TransmissionActionIndicator:
17079             {
17080                if(duUeCb->f1UeDb)
17081                {
17082                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.TransmissionActionIndicator  == TransmissionActionIndicator_stop)
17083                   {
17084                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = STOP_TRANSMISSION; 
17085                   }
17086                   else 
17087                   {
17088                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = RESTART_TRANSMISSION; 
17089                   }
17090                }
17091                break;
17092             }
17093
17094          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
17095             {
17096                if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
17097                {
17098                   duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
17099                }
17100                break;
17101             }
17102 #ifdef NR_DRX
17103          case ProtocolIE_ID_id_DRXConfigurationIndicator:
17104             {
17105                duUeCb->f1UeDb->duUeCfg.drxConfigIndicatorRelease = true;
17106                break;
17107             }
17108 #endif
17109               
17110       }
17111    }
17112
17113    if(ret != RFAILED) 
17114    {
17115       ret = duProcUeContextModReq(duUeCb);
17116    }
17117    freeAperDecodeUeContextModificationReqMsg(ueContextModifyReq);
17118    return ret; 
17119 }
17120
17121 /*****************************************************************i
17122 *
17123 * @brief Free memory allocated for UE Context Release Request
17124 *
17125 * @details
17126 *
17127 *    Function : FreeUeContextReleaseReq
17128 *
17129 *    Functionality:
17130 *         - Free memory allocated for UE Context Release Request
17131 *
17132 * @params[in] F1AP_PDU_t *f1apMsg
17133 * @return void 
17134 *
17135 * *************************************************************/
17136 void FreeUeContextReleaseReq(F1AP_PDU_t *f1apMsg)
17137 {
17138    uint8_t ieIdx;
17139    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
17140    
17141    if(f1apMsg)
17142    {
17143       if(f1apMsg->choice.initiatingMessage)
17144       {
17145          ueReleaseReq =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
17146          if(ueReleaseReq->protocolIEs.list.array)
17147          {
17148             for(ieIdx=0 ; ieIdx<ueReleaseReq->protocolIEs.list.count; ieIdx++)
17149             {
17150                DU_FREE(ueReleaseReq->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseRequest_t));
17151             }
17152             DU_FREE(ueReleaseReq->protocolIEs.list.array, ueReleaseReq->protocolIEs.list.size);
17153          }
17154          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
17155       }
17156       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
17157    }
17158
17159 }
17160 /*****************************************************************i
17161 *
17162 * @brief Build and Send UE Context Release Request  
17163 *
17164 * @details
17165 *
17166 *    Function : BuildAndSendUeContextReleaseReq
17167 *
17168 *    Functionality:
17169 *         - Build and Send UE Context Release Request 
17170 *
17171 * @params[in]
17172 * @return ROK     - success
17173 *         RFAILED - failure
17174 *
17175 * *************************************************************/
17176 uint8_t BuildAndSendUeContextReleaseReq(uint16_t cellId, uint8_t ueId)
17177 {
17178    bool memAllocFail = false;
17179    uint8_t ieIdx =0;
17180    uint8_t ret = RFAILED;
17181    uint16_t cellIdx =0;
17182    uint16_t crnti = 0;
17183    uint8_t  elementCnt = 0;
17184    uint32_t  gnbCuUeF1apId =0;   /* gNB-CU UE F1AP Id */
17185    uint32_t  gnbDuUeF1apId =0;   /* gNB-DU UE F1AP Id */
17186    asn_enc_rval_t encRetVal; 
17187    F1AP_PDU_t *f1apMsg = NULLP;
17188    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
17189
17190    DU_LOG("\nINFO  --> Building the UE Context Release Request");
17191    do
17192    {
17193       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
17194       if(f1apMsg == NULLP)
17195       {
17196          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for f1apMsg");
17197          break;
17198       }
17199
17200       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
17201       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
17202       if(f1apMsg->choice.initiatingMessage == NULLP)
17203       {
17204          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for\
17205          initiatingMessage");   
17206          break;
17207       }
17208       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_UEContextReleaseRequest;
17209       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
17210       f1apMsg->choice.initiatingMessage->value.present = \
17211       InitiatingMessage__value_PR_UEContextReleaseRequest;
17212
17213       ueReleaseReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
17214
17215       elementCnt = 2;
17216
17217       ueReleaseReq->protocolIEs.list.count = elementCnt;
17218       ueReleaseReq->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseRequest_t *);
17219
17220       /* Initialize the F1Setup members */
17221       DU_ALLOC(ueReleaseReq->protocolIEs.list.array,ueReleaseReq->protocolIEs.list.size);
17222       if(ueReleaseReq->protocolIEs.list.array == NULLP)
17223       {
17224          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE array");
17225          break;
17226       }
17227       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
17228       {
17229          DU_ALLOC(ueReleaseReq->protocolIEs.list.array[ieIdx],\
17230                sizeof(UEContextReleaseRequest_t));
17231          if(ueReleaseReq->protocolIEs.list.array[ieIdx] == NULLP)
17232          {
17233             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE elements");
17234             memAllocFail = true;  
17235             break;
17236          }
17237       }
17238       if(memAllocFail == true)
17239          break;
17240
17241       /* Fetching Ue Cb Info*/
17242       GET_CELL_IDX(cellId, cellIdx);
17243       if(duCb.actvCellLst[cellIdx] == NULLP)
17244       {
17245          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): CellId[%d] does not exist", cellId);
17246          break;
17247       }
17248       else
17249       {
17250          GET_CRNTI(crnti, ueId);
17251          if(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].crnti != crnti)
17252          {
17253             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): crnti[%d] does not exist", crnti);
17254             break;
17255          }
17256          gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
17257          gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
17258       }
17259
17260       ieIdx=0; 
17261       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID; 
17262       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17263       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present = \
17264       UEContextReleaseRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
17265       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
17266       
17267       ieIdx++;
17268       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
17269       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17270       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present =\
17271       UEContextReleaseRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
17272       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17273       
17274       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17275
17276       /* Encode the F1SetupRequest type as APER */
17277       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17278       encBufSize = 0;
17279       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17280       /* Encode results */
17281       if(encRetVal.encoded == ENCODE_FAIL)
17282       {
17283          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseRequest structure (at %s)\n",\
17284                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17285          break;
17286       }
17287       else
17288       {
17289          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseRequest\n");
17290 #ifdef DEBUG_ASN_PRINT
17291          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17292          {
17293             printf("%x",encBuf[ieIdx]);
17294          }
17295 #endif
17296       }
17297
17298       /* Sending msg */
17299       if(sendF1APMsg() != ROK)
17300       {
17301          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Request failed");
17302          break;
17303       }
17304       ret = ROK;
17305       break;
17306    }while(true);
17307
17308    FreeUeContextReleaseReq(f1apMsg);
17309    return ret;
17310 }
17311 /*****************************************************************i
17312  *
17313  * @brief Free memory allocated for UE Context Release Complete
17314  *
17315  * @details
17316  *
17317  *    Function : FreeUeContextReleaseComplete
17318  *
17319  *    Functionality:
17320  *         - Free memory allocated for UE Context Release Complete
17321  *
17322  * @params[in] F1AP_PDU_t *f1apMsg
17323  * @return void
17324  *
17325  * *************************************************************/
17326 void FreeUeContextReleaseComplete(F1AP_PDU_t *f1apMsg)
17327 {
17328    uint8_t ieIdx;
17329    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17330
17331    if(f1apMsg)
17332    {
17333       if(f1apMsg->choice.successfulOutcome)
17334       {
17335          ueReleaseComplete =&f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17336          if(ueReleaseComplete->protocolIEs.list.array)
17337          {
17338             for(ieIdx=0 ; ieIdx<ueReleaseComplete->protocolIEs.list.count; ieIdx++)
17339             {
17340                DU_FREE(ueReleaseComplete->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseComplete_t));
17341             }
17342             DU_FREE(ueReleaseComplete->protocolIEs.list.array, ueReleaseComplete->protocolIEs.list.size);
17343          }
17344          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17345       }
17346       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
17347    }
17348
17349 }
17350 /*****************************************************************i
17351  *
17352  * @brief Build and Send UE Context Release Complete
17353  *
17354  * @details
17355  *
17356  *    Function : BuildAndSendUeContextReleaseComplete
17357  *
17358  *    Functionality:
17359  *         - Build and Send UE Context Release Complete
17360  *
17361  * @params[in]  cellId,  gnbCuUeF1apId, gnbDuUeF1apId
17362  * @return ROK     - success
17363  *         RFAILED - failure
17364  *
17365  * *************************************************************/
17366 uint8_t BuildAndSendUeContextReleaseComplete(uint16_t cellId, uint32_t gnbCuUeF1apId, uint32_t gnbDuUeF1apId)
17367 {
17368    bool memAllocFail = false;
17369    uint8_t ieIdx =0, ret = RFAILED, elementCnt = 0;
17370    asn_enc_rval_t encRetVal;
17371    F1AP_PDU_t *f1apMsg = NULLP;
17372    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
17373
17374    DU_LOG("\nINFO  --> Building the UE Context Release Complete");
17375    do
17376    {
17377       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
17378       if(f1apMsg == NULLP)
17379       {
17380          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for f1apMsg");
17381          break;
17382       }
17383
17384       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
17385       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
17386       if(f1apMsg->choice.successfulOutcome == NULLP)
17387       {
17388          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for\
17389                successfulOutcome");
17390          break;
17391       }
17392       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextRelease;
17393       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
17394       f1apMsg->choice.successfulOutcome->value.present = \
17395       SuccessfulOutcome__value_PR_UEContextReleaseComplete;
17396
17397       ueReleaseComplete = &f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
17398
17399       elementCnt = 2;
17400       ueReleaseComplete->protocolIEs.list.count = elementCnt;
17401       ueReleaseComplete->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseComplete_t *);
17402
17403       /* Initialize the UE Release Complete members */
17404       DU_ALLOC(ueReleaseComplete->protocolIEs.list.array,ueReleaseComplete->protocolIEs.list.size);
17405       if(ueReleaseComplete->protocolIEs.list.array == NULLP)
17406       {
17407          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE array");
17408          break;
17409       }
17410       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
17411       {
17412          DU_ALLOC(ueReleaseComplete->protocolIEs.list.array[ieIdx],\
17413                sizeof(UEContextReleaseComplete_t));
17414          if(ueReleaseComplete->protocolIEs.list.array[ieIdx] == NULLP)
17415          {
17416             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE\
17417             elements");
17418             memAllocFail = true;
17419             break;
17420          }
17421       }
17422       if(memAllocFail == true)
17423          break;
17424
17425
17426       ieIdx=0;
17427       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
17428       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17429       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present = \
17430       UEContextReleaseCompleteIEs__value_PR_GNB_CU_UE_F1AP_ID;
17431       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
17432
17433       ieIdx++;
17434       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
17435       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
17436       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present =\
17437       UEContextReleaseCompleteIEs__value_PR_GNB_DU_UE_F1AP_ID;
17438       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
17439
17440       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17441
17442       /* Encode the F1SetupComplete type as APER */
17443       memset(encBuf, 0, ENC_BUF_MAX_LEN);
17444       encBufSize = 0;
17445       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
17446       /* Encode results */
17447       if(encRetVal.encoded == ENCODE_FAIL)
17448       {
17449          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseComplete structure (at %s)\n",\
17450                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
17451          break;
17452       }
17453       else
17454       {
17455          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseComplete\n");
17456 #ifdef DEBUG_ASN_PRINT
17457          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
17458          {
17459             printf("%x",encBuf[ieIdx]);
17460          }
17461 #endif
17462       }
17463
17464       /* Sending msg */
17465       if(sendF1APMsg() != ROK)
17466       {
17467          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Complete failed");
17468          break;
17469       }
17470       ret = ROK;
17471       break;
17472    }while(true);
17473    
17474    if((ret == ROK) && (duCb.actvCellLst[cellId-1]) && (duCb.actvCellLst[cellId-1]->cellStatus == DELETION_IN_PROGRESS) 
17475          && (duCb.actvCellLst[cellId-1]->numActvUes == 0))
17476    {
17477       ret = duSendCellDeletReq(cellId);
17478       if(ret != ROK)
17479       {
17480          DU_LOG("\nERROR  -->  F1AP: BuildAndSendUeContextReleaseComplete(): Failed to process cell\
17481                Delete req for CellId");
17482       }
17483    }
17484    FreeUeContextReleaseComplete(f1apMsg);
17485    return ret;
17486
17487 }
17488
17489 /*******************************************************************
17490 *
17491 * @brief added free part for the memory allocated by aper_decoder 
17492 *
17493 * @details
17494 *
17495 *    Function : freeAperDecodeUeContextReleaseCommand 
17496 *
17497 *    Functionality: added free part for the memory allocated by aper_decoder
17498 *
17499 * @params[in] F1AP_PDU_t *f1apMsg
17500 * @return void
17501 *
17502 * ****************************************************************/
17503 void freeAperDecodeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17504 {
17505    uint8_t ieIdx=0;
17506    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17507
17508    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17509    
17510    if(ueContextReleaseCommand->protocolIEs.list.array)
17511    {
17512       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17513       {
17514          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17515          {
17516             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17517             {
17518                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17519                   break;
17520                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17521                   break;
17522                case ProtocolIE_ID_id_Cause:
17523                   break;
17524                case ProtocolIE_ID_id_RRCContainer:
17525                {
17526                   if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
17527                   {
17528                      free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
17529                   }
17530                   break;
17531                }
17532                default :
17533                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17534                        ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17535                   break;
17536             }
17537          }
17538          free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]);
17539       }
17540       free(ueContextReleaseCommand->protocolIEs.list.array);
17541    }
17542 }
17543 /*******************************************************************
17544 *
17545 * @brief processing of UE Context Release Command
17546 *
17547 * @details
17548 *
17549 *    Function : procF1UeContextReleaseCommand 
17550 *
17551 *    Functionality: processing of UE Context Release Command
17552 *
17553 * @params[in] F1AP_PDU_t *f1apMsg
17554 * @return void
17555 *
17556 * ****************************************************************/
17557 uint8_t procF1UeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
17558 {
17559    uint8_t  ieIdx=0, ret=ROK, ueIdx=0;
17560    uint16_t cellIdx =0, cellId = 0;
17561    bool ueIdxFound = false;
17562    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0;
17563    DuUeCb   *duUeCb = NULLP;
17564    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
17565
17566    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
17567
17568    if(ueContextReleaseCommand->protocolIEs.list.array)
17569    {
17570       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
17571       {
17572          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
17573          {
17574             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
17575             {
17576                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
17577                   {
17578                      gnbCuUeF1apId= ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17579                                     value.choice.GNB_CU_UE_F1AP_ID;
17580                      break;
17581                   }
17582
17583                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
17584                   {
17585                      gnbDuUeF1apId = ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17586                                      value.choice.GNB_DU_UE_F1AP_ID;
17587                      break;
17588                   }
17589
17590                case ProtocolIE_ID_id_Cause:
17591                   {
17592                      for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
17593                      {
17594                         for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
17595                         {
17596                            if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
17597                                  (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId))
17598                            {
17599                               cellId = duCb.actvCellLst[cellIdx]->cellId;
17600                               duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
17601                               ueIdxFound = true;
17602                               break;
17603                            }
17604                         }
17605                         if(ueIdxFound == true)
17606                         {
17607                            break;
17608                         }
17609                      }
17610                      
17611                      if(!ueIdxFound)
17612                      {
17613                         DU_LOG("\nERROR  -->  F1AP: procF1UeContextReleaseCommand(): Ue Information is not available");
17614                         ret = RFAILED;
17615                      }
17616                      break;
17617                   }
17618
17619                case ProtocolIE_ID_id_RRCContainer:
17620                   {
17621                      if(ueIdxFound == true)  
17622                      {
17623                         DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
17624                         if(duUeCb->f1UeDb)
17625                         {
17626                            memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
17627                            duUeCb->f1UeDb->actionType = UE_CTXT_RELEASE;
17628                            duUeCb->f1UeDb->cellIdx = cellIdx;
17629                            /* Filling Dl RRC Msg Info */
17630                            DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
17631                            if(!duUeCb->f1UeDb->dlRrcMsg)
17632                            {
17633                               DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17634                                     Memory allocation failed ");
17635                               ret = RFAILED;
17636                            }
17637                            else
17638                            {
17639                               duUeCb->f1UeDb->dlRrcMsgPres = true;
17640                               memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
17641                               ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
17642                                     &ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
17643                                     value.choice.RRCContainer);
17644                            }
17645
17646                         }
17647                         else
17648                         {
17649                            DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
17650                                  Memory allocation failed ");
17651                            ret = RFAILED;
17652
17653                         }
17654                      }
17655                      break;
17656                   }
17657                default :
17658                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
17659                         ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
17660                   break;
17661             }
17662          }
17663       }
17664    }
17665    if(ret != RFAILED)
17666    {
17667       duProcUeContextReleaseCommand(cellId, duUeCb);
17668    }
17669    freeAperDecodeUeContextReleaseCommand(f1apMsg);
17670    return ret;
17671 }
17672
17673 /**************************************************************
17674  *
17675  * @brief free the memory allocated by aper decoder for paging
17676  *
17677  * @details
17678  *
17679  *    Function : freeAperDecodePagingMsg
17680  *
17681  *    Functionality:
17682  *         - free the memory allocated by aper decoder for
17683  *         the paging f1ap msg
17684  *
17685  * @params[in] Paging_t   *paging
17686  * @return ROK     - success
17687  *         RFAILED - failure
17688  *
17689  ****************************************************************/
17690 void freeAperDecodePagingMsg(Paging_t   *paging)
17691 {
17692    uint8_t ieIdx, cellIdx;
17693    PagingCell_ItemIEs_t *pagingCellItemIes;
17694    PagingCell_Item_t *pagingCellItem;
17695    PagingCell_list_t  *pagingCelllist;
17696
17697    if(paging)
17698    {
17699       if(paging->protocolIEs.list.array)
17700       {
17701          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17702          {
17703             if(paging->protocolIEs.list.array[ieIdx])
17704             {
17705                switch(paging->protocolIEs.list.array[ieIdx]->id)
17706                {
17707                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17708                      {
17709                         free(paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10.buf);
17710                         break;
17711                      }
17712                   case ProtocolIE_ID_id_PagingIdentity:
17713                      {
17714                         if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present == PagingIdentity_PR_cNUEPagingIdentity)
17715                         {
17716                            if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)
17717                            {
17718                               if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->present == \
17719                                     CNUEPagingIdentity_PR_fiveG_S_TMSI)
17720                               {
17721                                  free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->choice.fiveG_S_TMSI.buf);
17722                               }
17723                               free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity);
17724                            }
17725                         }
17726                         break;
17727                      }
17728                   case ProtocolIE_ID_id_PagingCell_List:
17729                      {
17730                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list;
17731                         if(pagingCelllist->list.array)
17732                         {
17733                            for(cellIdx = 0; cellIdx < pagingCelllist->list.count; cellIdx++)
17734                            {
17735                               if(pagingCelllist->list.array[cellIdx])
17736                               {
17737                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellIdx];
17738                                  if(pagingCellItemIes->id == ProtocolIE_ID_id_PagingCell_Item)
17739                                  {
17740                                     pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17741                                     free(pagingCellItem->nRCGI.pLMN_Identity.buf);
17742                                     free(pagingCellItem->nRCGI.nRCellIdentity.buf);
17743                                  }
17744                                  free(pagingCelllist->list.array[cellIdx]);
17745                               }
17746                            }
17747                            free(pagingCelllist->list.array);
17748                         }
17749                         break;
17750                      }
17751                }
17752                free(paging->protocolIEs.list.array[ieIdx]);
17753             }
17754          }
17755          free(paging->protocolIEs.list.array);
17756
17757       }
17758    }
17759 }
17760
17761 /**************************************************************
17762  *
17763  * @brief processing the paging f1ap msg received from CU 
17764  *
17765  * @details
17766  *
17767  *    Function : procPagingMsg
17768  *
17769  *    Functionality:
17770  *         - processing the paging f1ap msg received from CU
17771  *
17772  * @params[in] F1AP_PDU_t *f1apMsg
17773  * @return ROK     - success
17774  *         RFAILED - failure
17775  *
17776  *
17777  ****************************************************************/
17778 uint8_t procPagingMsg(F1AP_PDU_t *f1apMsg) 
17779 {
17780    uint8_t ieIdx = 0, cellListIdx = 0;
17781    uint64_t cellId = 0;
17782    Paging_t   *paging = NULLP;
17783    PagingCell_list_t  *pagingCelllist = NULLP;
17784    PagingCell_ItemIEs_t *pagingCellItemIes = NULLP;
17785    PagingCell_Item_t *pagingCellItem = NULLP;
17786    DuPagingMsg *tmpPagingParam = NULLP;
17787
17788    paging = &f1apMsg->choice.initiatingMessage->value.choice.Paging;
17789    if(paging)
17790    {
17791       if(paging->protocolIEs.list.array)
17792       {
17793          DU_ALLOC(tmpPagingParam, sizeof(DuPagingMsg));
17794          if(tmpPagingParam == NULLP)
17795          {
17796             DU_LOG("\nERROR  --> DU APP : Memory Allocation Failure in procPagingMsg");
17797             freeAperDecodePagingMsg(paging);
17798             return RFAILED;
17799          }
17800          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17801          {
17802             if(paging->protocolIEs.list.array[ieIdx])
17803             {
17804                switch(paging->protocolIEs.list.array[ieIdx]->id)
17805                {
17806                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17807                      {
17808                         bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10,\
17809                                          &tmpPagingParam->pagUeId);
17810                         break;
17811                      }
17812
17813                   case ProtocolIE_ID_id_PagingIdentity:
17814                      {
17815                         switch(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present)
17816                         {
17817                            case PagingIdentity_PR_cNUEPagingIdentity: 
17818                               {
17819                                  if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)  
17820                                  {
17821                                     bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.\
17822                                           cNUEPagingIdentity->choice.fiveG_S_TMSI, &tmpPagingParam->sTmsi);
17823
17824                                  }
17825                                  break;
17826                               }
17827                             case PagingIdentity_PR_rANUEPagingIdentity:
17828                                {
17829                                   /*TODO: This Identifier is specific to RAN Initiated Paging â€“ Connected Mode Paging*/
17830                                   break;
17831                                }
17832                             default:
17833                                {
17834                                   DU_LOG("ERROR  -->  DU APP: Invalid UE Paging Identity, Skipping this Paging Message:");
17835                                   continue;
17836                                }
17837                         }
17838                      }
17839
17840                   case ProtocolIE_ID_id_PagingDRX:
17841                      {
17842                         tmpPagingParam->pagingDrxPres = TRUE;
17843                         tmpPagingParam->pagingDrx = convertPagingCycleEnumToValue(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingDRX);
17844                         break;
17845                      }
17846
17847                   case ProtocolIE_ID_id_PagingPriority:
17848                      {
17849                         tmpPagingParam->pagPriority = paging->protocolIEs.list.array[ieIdx]->value.choice.PagingPriority;
17850                         break;
17851                      }
17852
17853                   case ProtocolIE_ID_id_PagingCell_List:
17854                      {
17855                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list; 
17856                         if(pagingCelllist->list.array)
17857                         {
17858                            for(cellListIdx = 0; cellListIdx < pagingCelllist->list.count; cellListIdx++)
17859                            {
17860                               if(pagingCelllist->list.array[cellListIdx])
17861                               {
17862                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellListIdx];
17863                                  pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17864                                  bitStringToInt(&pagingCellItem->nRCGI.nRCellIdentity, &cellId);
17865                                  if(processPagingMsg(cellId, tmpPagingParam) != ROK)
17866                                  {
17867                                     DU_LOG("\nERROR  --> DU APP : Paging Processing Failed at CellId:%lu",cellId);
17868                                     continue;
17869                                  }
17870                               }
17871                            }
17872                         }
17873                         break;
17874                      }
17875                    default:
17876                      {
17877                          DU_LOG("\nERROR  --> F1AP : Incorrect Paging IE option");
17878                          break;
17879                      }
17880                }
17881             }
17882          }
17883       }
17884    }
17885    DU_FREE(tmpPagingParam, sizeof(DuPagingMsg));
17886    freeAperDecodePagingMsg(paging);
17887   
17888    return ROK;
17889 }
17890
17891 /**************************************************************
17892  *
17893  * @brief Handles received F1AP message and sends back response  
17894  *
17895  * @details
17896  *
17897  *    Function : F1APMsgHdlr
17898  *
17899  *    Functionality:
17900  *         - Decodes received F1AP control message
17901  *         - Prepares response message, encodes and sends to SCTP
17902  *
17903  * @params[in] 
17904  * @return ROK     - success
17905  *         RFAILED - failure
17906  *
17907  * ****************************************************************/
17908 void F1APMsgHdlr(Buffer *mBuf)
17909 {
17910    int i =0;
17911    char *recvBuf =NULLP;
17912    MsgLen copyCnt =0;
17913    MsgLen recvBufLen =0;
17914    F1AP_PDU_t *f1apMsg =NULLP;
17915    asn_dec_rval_t rval; /* Decoder return value */
17916    F1AP_PDU_t f1apasnmsg ;
17917    DU_LOG("\nINFO  -->  F1AP : Received F1AP message buffer");
17918    ODU_PRINT_MSG(mBuf, 0,0);
17919
17920    /* Copy mBuf into char array to decode it */
17921    ODU_GET_MSG_LEN(mBuf, &recvBufLen);
17922    DU_ALLOC(recvBuf, (Size)recvBufLen);
17923
17924    if(recvBuf == NULLP)
17925    {
17926       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed");
17927       return;
17928    }
17929    if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
17930    {
17931       DU_LOG("\nERROR   -->  F1AP : Failed while copying %d", copyCnt);
17932       return;
17933    }
17934
17935 #ifdef DEBUG_ASN_PRINT
17936    printf("\nDEBUG   -->  F1AP : Received flat buffer to be decoded : ");
17937    for(i=0; i< recvBufLen; i++)
17938    {
17939       printf("%x",recvBuf[i]);
17940    }
17941 #endif
17942
17943    /* Decoding flat buffer into F1AP messsage */
17944    f1apMsg = &f1apasnmsg;
17945    memset(f1apMsg, 0, sizeof(F1AP_PDU_t));
17946
17947    rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0);
17948
17949    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
17950    {
17951       DU_LOG("\nERROR  -->  F1AP : ASN decode failed");
17952       return;
17953    }
17954    printf("\n");
17955    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17956
17957    switch(f1apMsg->present)
17958    {
17959       case F1AP_PDU_PR_successfulOutcome:
17960          {
17961             switch(f1apMsg->choice.successfulOutcome->value.present)
17962             {
17963                case SuccessfulOutcome__value_PR_ResetAcknowledge:
17964                   {
17965                      DU_LOG("\nINFO   -->  F1AP : F1ResetAcknowledge is received successfully ");
17966                      break;
17967                   }
17968                case SuccessfulOutcome__value_PR_F1SetupResponse:
17969                   {                             
17970 #ifndef ODU_TEST_STUB
17971                      procF1SetupRsp(f1apMsg, recvBufLen, recvBuf);
17972 #endif
17973                      break;
17974                   }
17975
17976                case SuccessfulOutcome__value_PR_GNBDUConfigurationUpdateAcknowledge:
17977                   {
17978                      procF1GNBDUCfgUpdAck(f1apMsg, recvBufLen, recvBuf);
17979                      break;
17980                   }
17981
17982                default:
17983                   {
17984                      DU_LOG("\nERROR  -->  F1AP : Invalid type of SuccessfulOutcome__value_PR_ResetAcknowledge [%d]",\
17985                            f1apMsg->choice.successfulOutcome->value.present);
17986                      return;
17987                   }
17988             }/* End of switch(successfulOutcome) */
17989             free(f1apMsg->choice.successfulOutcome);
17990             break;
17991          }
17992       case F1AP_PDU_PR_initiatingMessage:
17993          {
17994             switch(f1apMsg->choice.initiatingMessage->value.present)
17995             {
17996                case InitiatingMessage__value_PR_Reset:
17997                   {
17998                      procF1ResetReq(f1apMsg);
17999                      break;
18000                   }
18001                case InitiatingMessage__value_PR_DLRRCMessageTransfer:
18002                   {
18003                      procF1DlRrcMsgTrans(f1apMsg);
18004                      break;
18005                   }
18006                case InitiatingMessage__value_PR_UEContextSetupRequest:
18007                   {
18008                      procF1UeContextSetupReq(f1apMsg);
18009                      break;
18010                   }
18011                case InitiatingMessage__value_PR_UEContextModificationRequest:
18012                   {
18013                      procF1UeContextModificationReq(f1apMsg);
18014                      break;
18015                   }
18016                case InitiatingMessage__value_PR_UEContextReleaseCommand:
18017                   {
18018                       procF1UeContextReleaseCommand(f1apMsg);
18019                       break;
18020                   }
18021                case InitiatingMessage__value_PR_Paging:
18022                   {
18023                      procPagingMsg(f1apMsg);
18024                      break;
18025                   }
18026                default:
18027                   {
18028                      DU_LOG("\nERROR  -->  F1AP : Invalid type of F1AP_PDU_PR_initiatingMessage [%d]",
18029                            f1apMsg->choice.initiatingMessage->value.present);
18030                      return;
18031                   }
18032             }/* End of switch(initiatingMessage) */
18033             free(f1apMsg->choice.initiatingMessage);
18034             break;
18035          }
18036
18037       default:
18038          {
18039             DU_LOG("\nERROR  -->  F1AP : Invalid type of f1apMsg->present [%d]",f1apMsg->present);
18040             return;
18041          }
18042          free(f1apMsg);
18043
18044    }/* End of switch(f1apMsg->present) */
18045    
18046    DU_FREE(recvBuf, (Size)recvBufLen);
18047 } /* End of F1APMsgHdlr */
18048
18049 /**********************************************************************
18050   End of file
18051  **********************************************************************/