[JIRA ID- ODUHIGH-462] [ISSUE ID ODUHIGH-477] Adding support for drx configuration...
[o-du/l2.git] / src / du_app / du_f1ap_msg_hdl.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /* This file contains F1AP message handler functions */
20 #include "common_def.h"
21 #include "ckw.h"
22 #include "ckw.x"
23 #include "kwu.h"
24 #include "kwu.x"
25 #include "lkw.h"
26 #include "lrg.h"
27 #include "legtp.h"
28 #include "lkw.x"
29 #include "lrg.x"
30 #include "F1AP-PDU.h"
31 #include "du_app_mac_inf.h"
32 #include "du_cfg.h"
33 #include "du_app_rlc_inf.h"
34 #include "du_mgr_main.h"
35 #include "du_mgr.h"
36 #include "du_utils.h"
37 #include "du_ue_mgr.h"
38 #include "RAT-Type.h"
39 #include "FeatureSetUplinkPerCC.h"
40 #include "FeatureSetDownlinkPerCC.h"
41 #include "FeatureSets.h"
42 #include "UE-NR-Capability.h"
43 #include "UE-CapabilityRAT-Container.h"
44 #include "UE-CapabilityRAT-ContainerListRRC.h"
45 #include "GNB-DU-System-Information.h"
46 #include "CellGroupConfigRrc.h"
47 #include "MAC-CellGroupConfig.h"
48 #include "SchedulingRequestConfig.h"
49 #include "SchedulingRequestToAddMod.h"
50 #include "BSR-Config.h"
51 #include "TAG-Config.h"
52 #include "TAG.h"
53 #include "PHR-Config.h"
54 #include "RLC-Config.h"
55 #include "UL-AM-RLC.h"
56 #include "DL-AM-RLC.h"
57 #include "LogicalChannelConfig.h"
58 #include "RLC-BearerConfig.h"
59 #include "PhysicalCellGroupConfig.h"
60 #include "SpCellConfig.h"
61 #include "TDD-UL-DL-ConfigDedicated.h"
62 #include "ServingCellConfig.h"
63 #include "ControlResourceSet.h"
64 #include "SearchSpace.h"
65 #include "PDCCH-Config.h"
66 #include "PDSCH-TimeDomainResourceAllocation.h"
67 #include "PDSCH-TimeDomainResourceAllocationList.h"
68 #include "PDSCH-CodeBlockGroupTransmission.h"
69 #include "PDSCH-ServingCellConfig.h"
70 #include "DMRS-DownlinkConfig.h"
71 #include "PDSCH-Config.h"
72 #include "BWP-DownlinkDedicated.h"
73 #include "BWP-Downlink.h"
74 #include "PUSCH-TimeDomainResourceAllocation.h"
75 #include "PUSCH-TimeDomainResourceAllocationList.h"
76 #include "DMRS-UplinkConfig.h"
77 #include "PUSCH-Config.h"
78 #include "SRS-ResourceId.h"
79 #include "SRS-Resource.h"
80 #include "SRS-ResourceSet.h"
81 #include "SRS-Config.h"
82 #include "BWP-UplinkDedicated.h"
83 #include "PUSCH-ServingCellConfig.h"
84 #include "UplinkConfig.h"
85 #include "DUtoCURRCContainer.h"
86 #include "GBR-QoSFlowInformation.h"
87 #include "QoSFlowLevelQoSParameters.h"
88 #include "PUCCH-Config.h"
89 #include "PUCCH-ResourceSet.h"
90 #include "PUCCH-Resource.h"
91 #include "PUCCH-PowerControl.h"
92 #include "P0-PUCCH.h"
93 #include "PUCCH-PathlossReferenceRS.h"
94 #include "PUCCH-format0.h"
95 #include "PUCCH-format1.h"
96 #include "PUCCH-format2.h"
97 #include "PUCCH-format3.h"
98 #include "PUCCH-format4.h"
99 #include "PUCCH-FormatConfig.h"
100 #include "SchedulingRequestResourceConfig.h"
101 #include<ProtocolIE-Field.h>
102 #include "ProtocolExtensionField.h"
103 #include "odu_common_codec.h"
104 #include "du_mgr.h"
105 #include "du_cell_mgr.h"
106 #include "du_f1ap_msg_hdl.h"
107 #include "DRBs-Setup-Item.h"
108 #include "DLUPTNLInformation-ToBeSetup-List.h"
109 #include "DLUPTNLInformation-ToBeSetup-Item.h"
110 #include "UPTransportLayerInformation.h"
111 #include "GTPTunnel.h"
112 #include "SupportedSULFreqBandItem.h"
113 #include "du_e2ap_msg_hdl.h"
114 #include "du_f1ap_conversions.h"
115 #include "CNUEPagingIdentity.h"
116 #include "PCCH-Config.h"
117 #include "SCS-SpecificCarrier.h"
118 #include "FrequencyInfoDL.h"
119 #include "DownlinkConfigCommon.h"
120 #include "FrequencyInfoUL.h"
121 #include "UplinkConfigCommon.h"
122 #include "TDD-UL-DL-ConfigCommon.h"
123 #include "RACH-ConfigDedicated.h"
124 #include "CFRA-SSB-Resource.h"
125 #include "BWP-UplinkCommon.h"
126 #include "ReconfigurationWithSync.h"
127 #include "du_sys_info_hdl.h"
128 #include "DRX-ConfigRrc.h"
129
130 #ifdef O1_ENABLE
131 #include "CmInterface.h"
132 extern StartupConfig g_cfg;
133 #endif
134
135 DuCfgParams duCfgParam;
136
137 /******************************************************************
138  *
139  * @brief Function to fetch lcId based on DRB Id
140  *
141  * @details
142  *
143  *    Function : fetchLcId
144  *
145  *    @params[in] drbId
146  *
147  *    Functionality: Function to fetch lcId based on DRB Id
148  *
149  * Returns: lcId - SUCCESS
150  *          RFAILED - FAILURE
151  *****************************************************************/
152
153 uint8_t fetchLcId(uint8_t drbId)
154 {
155    uint8_t cellIdx = 0, ueIdx = 0, lcIdx = 0, numLcs = 0, lcId = 0;
156
157    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
158    {
159       for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
160       {
161          if(duCb.actvCellLst[cellIdx] != NULLP)
162          {
163             numLcs = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg.numLcs;
164             for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
165             {
166                if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg.rlcLcCfg[lcIdx].rbId == drbId && \
167                   duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg.rlcLcCfg[lcIdx].rbType == RB_TYPE_DRB)
168                {
169                   lcId = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg.rlcLcCfg[lcIdx].lcId;
170                   return lcId;
171                }
172             }
173          }
174       }
175    }
176    DU_LOG("\nERROR   -->  DU_APP: fetchLcId() failed for drbId %d", drbId);
177    return RFAILED;
178 }
179
180 /*******************************************************************
181 *
182 * @brief Adding F1AP pdu to reserved pdu list
183 *
184 * @details
185 *
186 *    Function : addToReservedF1apPduList 
187 *
188 *    Functionality: Adding F1AP pdu to reserved pdu list.
189 *     These pdu are awaiting aknowledgment from CU
190 *
191 * @params[in] uint8_t transId, F1AP_PDU_t *f1apMsg
192 *
193 * @return ROK - success
194 *         RFAILED - failure
195 *
196 * ****************************************************************/
197 void addToReservedF1apPduList(uint8_t transId, F1AP_PDU_t *f1apPdu)
198 {
199    CmLList         *node = NULLP;
200    ReservedF1apPduInfo *pduInfo = NULLP;
201    DU_ALLOC(pduInfo, sizeof(ReservedF1apPduInfo));
202    if(pduInfo)
203    {
204       DU_ALLOC(node, sizeof(CmLList));
205       if(node)
206       {
207          pduInfo->transId = transId;
208          pduInfo->f1apMsg = (void*) f1apPdu;
209
210          node->node = (PTR)pduInfo;
211          cmLListAdd2Tail(&duCb.reservedF1apPduList, node);
212       }
213    }
214 }
215
216 /*******************************************************************
217 *
218 * @brief searching for F1AP pdu from ReservedF1apPduList 
219 *
220 * @details
221 *
222 *    Function : searchFromReservedF1apPduList 
223 *
224 *    Functionality: searching for F1AP pdu information
225 *
226 * @params[in] uint8_t transId
227 *
228 * @return pointer to F1AP_PDU_t
229 *
230 * ****************************************************************/
231
232 CmLList *searchFromReservedF1apPduList(uint8_t transId)
233 {
234    CmLList         *node;
235    ReservedF1apPduInfo *f1apPdu;
236    if(duCb.reservedF1apPduList.count)
237    {
238       CM_LLIST_FIRST_NODE(&duCb.reservedF1apPduList, node);
239       while(node)
240       {
241          f1apPdu = (ReservedF1apPduInfo*)node->node;
242          if(f1apPdu->transId == transId)
243          {
244             return node;
245          }
246          node = node->next;
247       }
248    }
249    return NULL;
250 }
251
252 /*******************************************************************
253 *
254 * @brief deleting F1AP pdu information from ReservedF1apPduList
255 *
256 * @details
257 *
258 *    Function : deleteFromReservedF1apPduList 
259 *
260 *    Functionality: deleting pdu information from ReservedF1apPduList
261 *
262 * @params[in] CmLList *node 
263 *
264 * @return void 
265 *
266 * ****************************************************************/
267
268 void deleteFromReservedF1apPduList(CmLList *node)
269 {
270    ReservedF1apPduInfo *f1apPdu;
271
272    if(node != NULL)
273    {
274       f1apPdu = (ReservedF1apPduInfo *)node->node;
275       cmLListDelFrm(&duCb.reservedF1apPduList, node);
276       DU_FREE(f1apPdu, sizeof(ReservedF1apPduInfo));
277       DU_FREE(node, sizeof(CmLList));
278       node = NULL;
279    }
280 }
281
282 /*******************************************************************
283  *
284  * @brief Builds Uplink Info for NR 
285  *
286  * @details
287  *
288  *    Function : BuildULNRInfo
289  *
290  *    Functionality: Building NR Uplink Info
291  *
292  * @params[in] NRFreqInfo_t *ulnrfreq
293  * @return ROK     - success
294  *         RFAILED - failure
295  *
296  * ****************************************************************/
297 uint8_t BuildULNRInfo(NRFreqInfo_t *ulnrfreq)
298 {
299    uint8_t idx=0;
300    ulnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
301                        fdd.ulNrFreqInfo.nrArfcn;
302    ulnrfreq->freqBandListNr.list.count = 1;
303    ulnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
304    DU_ALLOC(ulnrfreq->freqBandListNr.list.array,ulnrfreq->freqBandListNr.list.size);
305    if(ulnrfreq->freqBandListNr.list.array == NULLP)
306    {
307       return RFAILED;
308    }
309    for(idx=0;idx<ulnrfreq->freqBandListNr.list.count;idx++)
310    {
311       DU_ALLOC(ulnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
312       if(ulnrfreq->freqBandListNr.list.array[idx] == NULLP)
313       {
314          return RFAILED;
315       }
316    }
317    ulnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
318                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
319                                                                  freqBand[0].nrFreqBand;
320    ulnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
321    return ROK;
322 }
323 /*******************************************************************
324  *
325  * @brief Builds Downlink NR Info 
326  *
327  * @details
328  *
329  *    Function : BuildDLNRInfo
330  *
331  *    Functionality: Building Downlink NR Info
332  *    
333  * @params[in] NRFreqInfo_t *dlnrfreq
334  * @return ROK     - success
335  *         RFAILED - failure
336  *
337  * ****************************************************************/
338 uint8_t BuildDLNRInfo(NRFreqInfo_t *dlnrfreq)
339 {
340    uint8_t idx=0;
341    dlnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
342                        fdd.dlNrFreqInfo.nrArfcn;
343    dlnrfreq->freqBandListNr.list.count = 1;
344    dlnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
345    DU_ALLOC(dlnrfreq->freqBandListNr.list.array,dlnrfreq->freqBandListNr.list.size);
346    if(dlnrfreq->freqBandListNr.list.array == NULLP)
347    {
348       return RFAILED;   
349    }
350    for(idx=0;idx< dlnrfreq->freqBandListNr.list.count;idx++)
351    {
352       DU_ALLOC(dlnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
353       if(dlnrfreq->freqBandListNr.list.array[idx] == NULLP)
354       {
355          return RFAILED;
356       }
357    }   
358    dlnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
359                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
360                                                                  freqBand[0].nrFreqBand;
361    dlnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
362
363    return ROK;
364 }
365
366 /*******************************************************************
367  *
368  * @brief Builds Nrcgi 
369  *
370  * @details
371  *
372  *    Function : BuildNrcgi
373  *
374  *    Functionality: Building the PLMN ID and NR Cell id
375  *
376  * @params[in] NRCGI_t *nrcgi
377  * @return ROK     - success
378  *         RFAILED - failure
379  *
380  * ****************************************************************/
381 uint8_t BuildNrcgi(NRCGI_t *nrcgi)
382 {
383    uint8_t ret;
384    uint8_t byteSize = 5;
385    /* Allocate Buffer Memory */
386    nrcgi->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
387    DU_ALLOC(nrcgi->pLMN_Identity.buf, nrcgi->pLMN_Identity.size);
388    if(nrcgi->pLMN_Identity.buf == NULLP)
389    {
390       return RFAILED;
391    }
392    ret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
393          nrcgi->pLMN_Identity.buf); // Building PLMN function
394    if(ret != ROK)
395    {
396       return RFAILED;
397    }
398    /*nrCellIdentity*/
399    nrcgi->nRCellIdentity.size = byteSize * sizeof(uint8_t);
400    DU_ALLOC(nrcgi->nRCellIdentity.buf, nrcgi->nRCellIdentity.size); 
401    if(nrcgi->nRCellIdentity.buf == NULLP)
402    {
403       return RFAILED;
404    }
405    fillBitString(&nrcgi->nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
406
407    return ROK;
408 }
409 /*******************************************************************
410  *
411  * @brief Builds FiveGStac 
412  *
413  * @details
414  *
415  *    Function : BuildFiveGSTac
416  *
417  *    Functionality: Building the FiveGSTac
418  *
419  * @params[in] OCTET_STRING_t *fivegsTac
420  * @return ROK     - success
421  *         RFAILED - failure
422  *
423  * ****************************************************************/
424 uint8_t BuildFiveGSTac(Served_Cell_Information_t *servcell)
425 {
426    DU_ALLOC(servcell->fiveGS_TAC,sizeof(FiveGS_TAC_t));
427    if(servcell->fiveGS_TAC == NULLP)
428    {
429       return RFAILED;
430    }
431    servcell->fiveGS_TAC->size = 3 * sizeof(uint8_t);
432    DU_ALLOC(servcell->fiveGS_TAC->buf,\
433          sizeof(servcell->fiveGS_TAC->size));
434    if(servcell->fiveGS_TAC->buf == NULLP)
435    {
436       return RFAILED;
437    }
438    servcell->fiveGS_TAC->buf[0] = 0;
439    servcell->fiveGS_TAC->buf[1] = 0;
440    servcell->fiveGS_TAC->buf[2] = duCfgParam.srvdCellLst[0].duCellInfo.tac;
441    return ROK;  
442 }
443
444 /*******************************************************************
445  *
446  * @brief fill nr frequency information
447  *
448  * @details
449  *
450  *    Function : fillNrTddInfo 
451  *
452  *    Functionality: fill nr frequency information
453  *
454  * @params[in] NRFreqInfo_t freqInfo
455  * @return ROK     - success
456  *         RFAILED - failure
457  *
458  * ****************************************************************/
459 uint8_t fillNrTddInfo(TDD_Info_t *tddInfo)
460 {
461    uint8_t elementCnt = 1, freqBandListIdx = 0, supportedBandIdx = 0;
462    NRFreqInfo_t *freqInfo = NULLP;
463
464    if(tddInfo == NULLP)
465    {
466       DU_LOG("\nERROR  --> DU APP : Null pointer received at fillNrTddInfo");
467       return RFAILED;
468    }
469    
470    freqInfo = &tddInfo->nRFreqInfo;
471    freqInfo->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.nrArfcn; 
472
473    freqInfo->freqBandListNr.list.count = elementCnt; 
474    freqInfo->freqBandListNr.list.size = freqInfo->freqBandListNr.list.count  * sizeof(FreqBandNrItem_t *);
475    DU_ALLOC(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
476    if(!freqInfo->freqBandListNr.list.array)
477    {
478       DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
479       return RFAILED;
480    }
481
482    for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
483    {
484       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
485       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx])
486       {
487          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
488          return RFAILED;
489       }
490
491       freqInfo->freqBandListNr.list.array[freqBandListIdx]->freqBandIndicatorNr = duCfgParam.srvdCellLst[0].duCellInfo.\
492       f1Mode.mode.tdd.nrFreqInfo.freqBand[0].nrFreqBand;
493       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count = elementCnt;
494       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size = freqInfo->freqBandListNr.list.array[freqBandListIdx]->\
495       supportedSULBandList.list.count * sizeof(SupportedSULFreqBandItem_t*);
496
497       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
498             freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
499       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
500       {
501          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
502          return RFAILED;
503       }
504
505       for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
506       {
507          DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
508                sizeof(SupportedSULFreqBandItem_t));
509          if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx])
510          {
511             DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
512             return RFAILED;
513          }
514
515          freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx]->freqBandIndicatorNr =\
516          duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[0].sulBand[0];
517       }
518    }
519
520    tddInfo->transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrScs;
521    tddInfo->transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrb;
522
523    return ROK;
524 }
525
526 /*******************************************************************
527  *
528  * @brief Builds NR Mode 
529  *
530  * @details
531  *
532  *    Function : BuildNrMode
533  *
534  *    Functionality: Building the NR Mode
535  *
536  * @params[in] NR_Mode_Info_t *fdd
537  * @return ROK     - success
538  *         RFAILED - failure
539  *
540  * ****************************************************************/
541 uint8_t BuildNrMode(NR_Mode_Info_t *mode)
542 {
543    uint8_t BuildDLNRInforet=0;
544    uint8_t BuildULNRInforet=0; 
545    
546 #ifdef NR_TDD
547    mode->present = NR_Mode_Info_PR_tDD;
548 #else
549    mode->present = NR_Mode_Info_PR_fDD;
550 #endif   
551    
552    if(mode->present == NR_Mode_Info_PR_fDD)
553    {
554       DU_ALLOC(mode->choice.fDD,sizeof(FDD_Info_t));
555       if(mode->choice.fDD == NULLP)
556       {
557          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
558          return RFAILED;
559       }
560       BuildULNRInforet = BuildULNRInfo(&mode->choice.fDD->uL_NRFreqInfo);
561       if(BuildULNRInforet != ROK)
562       {
563          DU_LOG("\nERROR  --> Failed to build UlNrFreqInfo");
564          return RFAILED;    
565       }
566       BuildDLNRInforet = BuildDLNRInfo(&mode->choice.fDD->dL_NRFreqInfo);
567       if(BuildDLNRInforet != ROK)
568       {
569          DU_LOG("\nERROR  --> Failed to build DlNrFreqInfo");
570          return RFAILED;
571       }
572       mode->choice.fDD->uL_Transmission_Bandwidth.nRSCS = \
573                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
574                                                           f1Mode.mode.fdd.ulTxBw.nrScs;
575       mode->choice.fDD->uL_Transmission_Bandwidth.nRNRB = \
576                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
577                                                           f1Mode.mode.fdd.ulTxBw.nrb;
578       mode->choice.fDD->dL_Transmission_Bandwidth.nRSCS = \
579                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
580                                                           f1Mode.mode.fdd.dlTxBw.nrScs;
581       mode->choice.fDD->dL_Transmission_Bandwidth.nRNRB = \
582                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
583                                                           f1Mode.mode.fdd.dlTxBw.nrb;
584    }
585    else if(mode->present == NR_Mode_Info_PR_tDD) 
586    {
587       DU_ALLOC(mode->choice.tDD,sizeof(TDD_Info_t));
588       if(mode->choice.tDD == NULLP)
589       {
590          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
591          return RFAILED;
592       }
593
594       if(fillNrTddInfo(mode->choice.tDD) != ROK)
595       {
596          DU_LOG("\nERROR  --> Failed to fill Nr TDD information");
597          return RFAILED;
598       }
599
600    }
601
602    return ROK;
603 }
604 /*******************************************************************
605  *
606  * @brief Builds IE Extensions for Served PLMNs 
607  *
608  * @details
609  *
610  *    Function : BuildExtensions
611  *
612  *    Functionality: Building the IE Extensions
613  *
614  * @params[in] struct ProtocolExtensionContainer_4624P3 *buildextend
615  * @return ROK     - success
616  *         RFAILED - failure
617  *
618  * ****************************************************************/
619 uint8_t BuildExtensions(ProtocolExtensionContainer_4624P3_t **ieExtend)
620 {
621    uint8_t idx=0, plmnidx=0, sliceLstIdx=0;
622    uint8_t elementCnt=0, extensionCnt=0;
623
624    extensionCnt=IE_EXTENSION_LIST_COUNT;
625    DU_ALLOC(*ieExtend,sizeof(ProtocolExtensionContainer_4624P3_t));
626    if((*ieExtend) == NULLP)
627    {
628       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
629       return RFAILED;
630    }
631    (*ieExtend)->list.count = extensionCnt;
632    (*ieExtend)->list.size = \
633                             extensionCnt * sizeof(ServedPLMNs_ItemExtIEs_t *);
634    DU_ALLOC((*ieExtend)->list.array,(*ieExtend)->list.size);
635    if((*ieExtend)->list.array == NULLP)
636    {
637       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
638       return RFAILED;
639    }
640    for(plmnidx=0;plmnidx<extensionCnt;plmnidx++)
641    {
642       DU_ALLOC((*ieExtend)->list.array[plmnidx],\
643             sizeof(ServedPLMNs_ItemExtIEs_t));
644       if((*ieExtend)->list.array[plmnidx] == NULLP)
645       {
646          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
647          return RFAILED;
648       }
649    }
650    
651    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices;
652    idx = 0;
653    (*ieExtend)->list.array[idx]->id = ProtocolIE_ID_id_TAISliceSupportList;
654    (*ieExtend)->list.array[idx]->criticality = Criticality_ignore;
655    (*ieExtend)->list.array[idx]->extensionValue.present = \
656    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
657    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
658       list.count = elementCnt;
659    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
660       list.size = (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
661       list.count * sizeof(SliceSupportItem_t *);
662
663    DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
664          list.array, elementCnt * sizeof(SliceSupportItem_t *));
665    if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
666          list.array == NULLP)
667    {
668       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
669       return RFAILED;
670    }
671
672    for(sliceLstIdx =0; sliceLstIdx<elementCnt; sliceLstIdx++)
673    {
674       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
675             list.array[sliceLstIdx],sizeof(SliceSupportItem_t));
676       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
677             list.array[sliceLstIdx] == NULLP) 
678       {
679          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
680          return RFAILED;
681       }
682       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
683          list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
684       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
685             .list.array[sliceLstIdx]->sNSSAI.sST.buf,(*ieExtend)->list.array[idx]->\
686             extensionValue.choice.SliceSupportList.\
687             list.array[sliceLstIdx]->sNSSAI.sST.size);
688       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
689             .list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
690       {
691          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
692          return RFAILED;
693       }
694       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
695          list.array[sliceLstIdx]->sNSSAI.sST.buf[0] = duCfgParam.srvdCellLst[0].duCellInfo.\
696          cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
697       
698       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
699             list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
700       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
701             list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
702       {
703          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
704          return RFAILED;
705       }
706       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
707          list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
708       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
709             list.array[sliceLstIdx]->sNSSAI.sD->buf, (*ieExtend)->list.array[idx]->extensionValue.choice.\
710             SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
711       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
712             list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
713       {
714          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
715          return RFAILED;
716       }
717       memcpy((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
718       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[0].duCellInfo.\
719       cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sd, (*ieExtend)->list.array[idx]->\
720       extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
721    }
722    return ROK;
723 }
724 /*******************************************************************
725  *
726  * @brief Builds Served PLMN 
727  *
728  * @details
729  *
730  *    Function : BuildServedPlmn
731  *
732  *    Functionality: Building the Served PLMN
733  *
734  * @params[in] GNB_DU_Served_Cells_Item_t *srvCellItem
735  * @return ROK     - success
736  *         RFAILED - failure
737  *
738  * ****************************************************************/
739 uint8_t  BuildServedPlmn(ServedPLMNs_List_t *srvplmn)
740 {  
741    uint8_t  plmnidx;
742    uint8_t  servPlmnCnt=1;
743    uint8_t buildPlmnIdret=0;
744    uint8_t BuildExtensionsret=0;
745    srvplmn->list.count = servPlmnCnt;
746    srvplmn->list.size = \
747                         servPlmnCnt*sizeof(ServedPLMNs_Item_t *);
748    DU_ALLOC(srvplmn->list.array,srvplmn->list.size);
749    if(srvplmn->list.array == NULLP)
750    {
751       return RFAILED;
752    }
753    for(plmnidx=0; plmnidx<servPlmnCnt; plmnidx++)
754    {   
755       DU_ALLOC(srvplmn->list.array[plmnidx],\
756             sizeof(ServedPLMNs_Item_t));
757       if(srvplmn->list.array[plmnidx] == NULLP)
758       {
759          return RFAILED;
760       }  
761    }
762    srvplmn->list.array[0]->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
763    DU_ALLOC(srvplmn->list.array[0]->pLMN_Identity.buf, srvplmn->list.array[0]->pLMN_Identity.size);
764    buildPlmnIdret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
765          srvplmn->list.array[0]->pLMN_Identity.buf);
766    if(buildPlmnIdret!= ROK)
767    {
768       return RFAILED;
769    }
770    BuildExtensionsret = BuildExtensions(&srvplmn->list.array[0]->iE_Extensions);
771    if(BuildExtensionsret!= ROK)
772    {
773       return RFAILED;
774    }
775    return ROK;
776 }
777 /*******************************************************************
778  *
779  * @brief Builds Served Cell List
780  *
781  * @details
782  *
783  *    Function : BuildServedCellList
784  *
785  *    Functionality: Building Served Cell List
786  *
787  * @params[in] PLMNID plmn
788  * @return ROK     - success
789  *         RFAILED - failure
790  *
791  * ****************************************************************/
792
793 uint8_t BuildServedCellList(GNB_DU_Served_Cells_List_t *duServedCell)
794 {
795    uint8_t  BuildNrcgiret=0;
796    uint8_t  BuildFiveGSTacret=0;
797    uint8_t  BuildServedPlmnret=0;
798    uint8_t  BuildNrModeret=0;
799    uint8_t  idx;
800    uint8_t  plmnidx;
801    uint8_t  plmnCnt=1;
802    GNB_DU_Served_Cells_Item_t *srvCellItem;
803    duServedCell->list.size = plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t *);
804    duServedCell->list.count = plmnCnt;
805
806    DU_ALLOC(duServedCell->list.array, duServedCell->list.size);
807    if(duServedCell->list.array == NULLP)
808    {
809       return RFAILED;
810    }
811    for(plmnidx=0; plmnidx<plmnCnt; plmnidx++)
812    {
813       DU_ALLOC(duServedCell->list.array[plmnidx],\
814             sizeof(GNB_DU_Served_Cells_ItemIEs_t));
815       if(duServedCell->list.array[plmnidx] == NULLP)
816       {
817          return RFAILED;
818       }
819    }
820    idx = 0;
821    duServedCell->list.array[idx]->id = ProtocolIE_ID_id_GNB_DU_Served_Cells_Item;
822    duServedCell->list.array[idx]->criticality = Criticality_reject;
823    duServedCell->list.array[idx]->value.present = \
824                                                   GNB_DU_Served_Cells_ItemIEs__value_PR_GNB_DU_Served_Cells_Item;
825    srvCellItem = \
826                  &duServedCell->list.array[idx]->value.choice.GNB_DU_Served_Cells_Item;
827    /*nRCGI*/
828    BuildNrcgiret = BuildNrcgi(&srvCellItem->served_Cell_Information.nRCGI);
829    if(BuildNrcgiret != ROK)
830    {
831       return RFAILED;
832    }
833    /*nRPCI*/
834    srvCellItem->served_Cell_Information.nRPCI = \
835                                                 duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
836
837    /*fiveGS_TAC*/
838    BuildFiveGSTacret = BuildFiveGSTac(&srvCellItem->served_Cell_Information);
839    if(BuildFiveGSTacret != ROK)
840    {
841       return RFAILED;
842    }
843    /*Served PLMNs*/
844    BuildServedPlmnret = BuildServedPlmn(&srvCellItem->served_Cell_Information.servedPLMNs);
845    if(BuildServedPlmnret !=ROK)
846    {
847       return RFAILED;
848    }
849    /*nR Mode Info with FDD*/
850    BuildNrModeret = BuildNrMode(&srvCellItem->served_Cell_Information.nR_Mode_Info);
851    if(BuildNrModeret != ROK)
852    {
853       return RFAILED;
854    }
855    /*Measurement timing Config*/
856    srvCellItem->served_Cell_Information.measurementTimingConfiguration.\
857       size = sizeof(uint8_t);
858    DU_ALLOC(srvCellItem->served_Cell_Information.\
859          measurementTimingConfiguration.buf,srvCellItem->served_Cell_Information.measurementTimingConfiguration.size);
860    if(srvCellItem->served_Cell_Information.\
861          measurementTimingConfiguration.buf == NULLP)
862    {
863       return RFAILED;
864    }
865    srvCellItem->served_Cell_Information.measurementTimingConfiguration.buf[0] = \
866                                                                                 duCfgParam.srvdCellLst[0].duCellInfo.measTimeCfg;
867
868    /* GNB DU System Information */
869    DU_ALLOC(srvCellItem->gNB_DU_System_Information,
870          sizeof(GNB_DU_System_Information_t));
871    if(!srvCellItem->gNB_DU_System_Information)
872    {
873       return RFAILED;
874    }
875    /* MIB */
876    srvCellItem->gNB_DU_System_Information->mIB_message.size = duCfgParam.srvdCellLst[0].duSysInfo.mibLen;
877    DU_ALLOC(srvCellItem->gNB_DU_System_Information->mIB_message.buf,
878          srvCellItem->gNB_DU_System_Information->mIB_message.size);
879    if(!srvCellItem->gNB_DU_System_Information->mIB_message.buf)
880    {
881       return RFAILED;
882    }
883    memcpy(srvCellItem->gNB_DU_System_Information->mIB_message.buf, duCfgParam.srvdCellLst[0].duSysInfo.mibMsg, \
884                    srvCellItem->gNB_DU_System_Information->mIB_message.size);
885
886    /* SIB1 */
887    srvCellItem->gNB_DU_System_Information->sIB1_message.size =\
888                                                               duCfgParam.srvdCellLst[0].duSysInfo.sib1Len;
889
890    DU_ALLOC(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,
891          srvCellItem->gNB_DU_System_Information->sIB1_message.size);
892    if(!srvCellItem->gNB_DU_System_Information->sIB1_message.buf)
893    {
894       return RFAILED;
895    }
896    for(int x=0; x<srvCellItem->gNB_DU_System_Information->sIB1_message.size; x++)
897    {
898       srvCellItem->gNB_DU_System_Information->sIB1_message.buf[x]=\
899                                                                   duCfgParam.srvdCellLst[0].duSysInfo.sib1Msg[x];
900    }
901    return ROK; 
902 }                                                                                                                  
903 /*******************************************************************
904  *
905  * @brief Builds RRC Version 
906  *
907  * @details
908  *
909  *    Function : BuildRrcVer
910  *
911  *    Functionality: Building RRC Version
912  *
913  * @params[in] int idx,int elementCnt,RRC_Version_t *rrcver
914  * @return ROK     - success
915  *         RFAILED - failure
916  *
917  * ****************************************************************/
918 uint8_t BuildRrcVer(RRC_Version_t *rrcVer)
919 {
920    uint8_t rrcExt;
921    uint8_t rrcLatest;
922    rrcVer->latest_RRC_Version.size = sizeof(uint8_t);
923    DU_ALLOC(rrcVer->latest_RRC_Version.buf,sizeof(uint8_t));
924    if(rrcVer->latest_RRC_Version.buf == NULLP)
925    {
926       return RFAILED;
927    }
928    rrcVer->latest_RRC_Version.buf[0] = 0;
929    rrcVer->latest_RRC_Version.bits_unused = 5;
930    DU_ALLOC(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
931    if(rrcVer->iE_Extensions == NULLP)
932    {  
933       return RFAILED;
934    }
935    rrcVer->iE_Extensions->list.count = 1;
936    rrcVer->iE_Extensions->list.size = sizeof(RRC_Version_ExtIEs_t *);
937    DU_ALLOC(rrcVer->iE_Extensions->list.array,rrcVer->iE_Extensions->list.size);
938    if(rrcVer->iE_Extensions->list.array == NULLP)
939    {
940       return RFAILED;
941    }
942    rrcExt = 0;
943    DU_ALLOC(rrcVer->iE_Extensions->list.array[0],\
944          sizeof(RRC_Version_ExtIEs_t));
945    if(rrcVer->iE_Extensions->list.array[0] == NULLP)
946    {
947       return RFAILED;
948    }
949    rrcVer->iE_Extensions->list.array[rrcExt]->id = \
950                                                    ProtocolIE_ID_id_latest_RRC_Version_Enhanced;
951    rrcVer->iE_Extensions->list.array[rrcExt]->criticality = Criticality_reject;
952    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.present =\
953                                                                       RRC_Version_ExtIEs__extensionValue_PR_Latest_RRC_Version_Enhanced;
954    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
955       .Latest_RRC_Version_Enhanced.size = 3*sizeof(uint8_t);
956    DU_ALLOC(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
957          .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
958          array[rrcExt]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
959    if(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
960          .Latest_RRC_Version_Enhanced.buf == NULLP)
961    {
962       return RFAILED;
963    }
964    rrcLatest = 0;
965    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
966       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 15;
967    rrcLatest++;
968    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
969       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 5;
970    rrcLatest++;
971    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
972       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 0;
973    return ROK;
974 }
975 /*******************************************************************
976  *
977  * @brief Sends F1 msg over SCTP
978  *
979  * @details
980  *
981  *    Function : sendF1APMsg
982  *
983  *    Functionality: Sends F1 msg over SCTP
984  *
985  * @params[in] Region region
986  *             Pool pool
987  * @return ROK     - success
988  *         RFAILED - failure
989  *
990  * ****************************************************************/
991 uint8_t sendF1APMsg()
992 {
993    Buffer *mBuf = NULLP;
994   
995    if(ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) == ROK)
996    {
997       if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
998       {
999             ODU_PRINT_MSG(mBuf, 0,0);
1000
1001             if(sctpSend(mBuf, F1_INTERFACE) != ROK)
1002             {
1003                DU_LOG("\nERROR  -->  F1AP : SCTP Send failed");
1004                ODU_PUT_MSG_BUF(mBuf);
1005                return RFAILED;
1006             }
1007       }
1008       else
1009       {
1010          DU_LOG("\nERROR  -->  F1AP : ODU_ADD_POST_MSG_MULT failed");
1011          ODU_PUT_MSG_BUF(mBuf);
1012          return RFAILED;
1013       }
1014       ODU_PUT_MSG_BUF(mBuf);
1015    }
1016    else
1017    {
1018       DU_LOG("\nERROR  -->  F1AP : Failed to allocate memory");
1019       return RFAILED;
1020    }
1021    return ROK; 
1022 } /* sendF1APMsg */
1023
1024 /*******************************************************************
1025  *
1026  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1027  *
1028  * @details
1029  *
1030  *    Function :  FreeRrcVer
1031  *
1032  *    Functionality: deallocating the memory of function BuildRrcVer
1033  *
1034  * @params[in] RRC_Version_t *rrcVer
1035  * 
1036  * @return void
1037  *
1038  *****************************************************************/
1039 void FreeRrcVer(RRC_Version_t *rrcVer)
1040 {
1041    if(rrcVer->latest_RRC_Version.buf != NULLP)
1042    {
1043       if(rrcVer->iE_Extensions != NULLP)
1044       {
1045          if(rrcVer->iE_Extensions->list.array != NULLP)
1046          {
1047             if(rrcVer->iE_Extensions->list.array[0] != NULLP)
1048             {
1049                if(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf
1050                      != NULLP)
1051                {
1052                   DU_FREE(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice\
1053                         .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1054                         array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1055                }
1056                DU_FREE(rrcVer->iE_Extensions->list.array[0],sizeof(RRC_Version_ExtIEs_t));
1057             }
1058             DU_FREE(rrcVer->iE_Extensions->list.array,sizeof(RRC_Version_ExtIEs_t*));
1059          }
1060          DU_FREE(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1061       }
1062       DU_FREE(rrcVer->latest_RRC_Version.buf,rrcVer->latest_RRC_Version.size);
1063    }
1064 }
1065
1066 /*******************************************************************
1067  *
1068  * @brief Deallocating memory of TDD NrFreqInfo 
1069  *
1070  * @details
1071  *
1072  *    Function : freeTddNrFreqInfo 
1073  *
1074  *    Functionality: freeTddNrFreqInfo 
1075  *
1076  * @params[in]  F1AP_PDU_t *f1apDuCfg
1077  *
1078  * @return ROK     - void
1079  *
1080  * ****************************************************************/
1081 void freeTddNrFreqInfo(NRFreqInfo_t *freqInfo)
1082 {
1083    uint8_t freqBandListIdx = 0, supportedBandIdx = 0;
1084
1085    if(freqInfo->freqBandListNr.list.array)
1086    {
1087       for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
1088       {
1089          if(freqInfo->freqBandListNr.list.array[freqBandListIdx])
1090          {
1091             if(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
1092             {
1093                for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
1094                {
1095                   DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
1096                         sizeof(SupportedSULFreqBandItem_t));
1097                }
1098                DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
1099                      freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
1100
1101             }
1102             DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
1103          }
1104       }
1105       DU_FREE(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
1106    }
1107 }
1108
1109 /*******************************************************************
1110  *
1111  * @brief Deallocating memory allocated for Nr fdd frequencey mode 
1112  *
1113  * @details
1114  *
1115  *    Function : freeFddNrFreqInfo 
1116  *
1117  *    Functionality:Free memory allocated for Nr fdd frequencey mode 
1118  *
1119  * @params[in]  
1120  *
1121  * @return ROK     - void
1122  *
1123  * ****************************************************************/
1124 void freeFddNrFreqInfo(FDD_Info_t *fDD)
1125 {
1126    uint8_t arrIdx =0;
1127
1128    if(fDD != NULLP)
1129    {
1130       if(fDD->uL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1131       {
1132          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.\
1133                array[arrIdx], sizeof(FreqBandNrItem_t));
1134          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.array, \
1135                fDD->uL_NRFreqInfo.freqBandListNr.list.size);
1136       }
1137
1138       if(fDD->dL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1139       {
1140          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.\
1141                array[arrIdx], sizeof(FreqBandNrItem_t));
1142          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.array,\
1143                fDD->dL_NRFreqInfo.freqBandListNr.list.size);
1144       }
1145       DU_FREE(fDD,sizeof(FDD_Info_t));
1146    }
1147 }
1148
1149 /*******************************************************************
1150  *
1151  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1152  *
1153  * @details
1154  *
1155  *    Function :  FreeServedCellList
1156  *
1157  *    Functionality:  deallocating the memory of function BuildServedCellList
1158
1159  *
1160  * @params[in] GNB_DU_Served_Cells_List_t *duServedCell
1161  *
1162  * @return void
1163  *
1164  * ****************************************************************/
1165 void FreeServedCellList( GNB_DU_Served_Cells_List_t *duServedCell)
1166 {
1167    uint8_t   plmnCnt=MAX_PLMN;
1168    uint8_t  extensionCnt=IE_EXTENSION_LIST_COUNT;
1169    uint8_t  plmnIdx=0, sliceIdx=0;
1170    GNB_DU_Served_Cells_Item_t *srvCellItem;
1171    ServedPLMNs_Item_t  *servedPlmnItem;
1172    SliceSupportItem_t  *sliceSupportItem;
1173
1174    if(duServedCell->list.array!=NULLP)
1175    {
1176       if(duServedCell->list.array[0]!=NULLP)
1177       {
1178          srvCellItem= &duServedCell->list.array[0]->value.choice.GNB_DU_Served_Cells_Item;
1179
1180          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1181                srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.size * sizeof(uint8_t));
1182          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1183                srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.size * sizeof(uint8_t));
1184
1185          if(srvCellItem->served_Cell_Information.fiveGS_TAC!=NULLP)
1186          {
1187             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC->buf,\
1188                   sizeof(srvCellItem->served_Cell_Information.fiveGS_TAC->size));
1189             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC,sizeof(FiveGS_TAC_t));
1190          }
1191
1192          if(srvCellItem->served_Cell_Information.servedPLMNs.list.array!=NULLP)
1193          {
1194             if(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx] != NULLP)
1195             {
1196                servedPlmnItem = srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx];
1197                DU_FREE(servedPlmnItem->pLMN_Identity.buf, servedPlmnItem->pLMN_Identity.size);
1198
1199                if(servedPlmnItem->iE_Extensions != NULLP)
1200                {
1201                   if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1202                   {
1203                      if(servedPlmnItem->iE_Extensions->list.array[0] != NULLP)
1204                      {
1205                         if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1206                               SliceSupportList.list.array != NULLP)
1207                         {
1208                            for(sliceIdx =0; sliceIdx<servedPlmnItem->iE_Extensions->list.array[0]->\
1209                                  extensionValue.choice.SliceSupportList.list.count; sliceIdx++)
1210                            {
1211                               if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1212                                     SliceSupportList.list.array[sliceIdx] != NULLP)
1213                               {
1214                                  sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[0]->\
1215                                                     extensionValue.choice.SliceSupportList.list.array[sliceIdx];
1216
1217                                  DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sizeof(uint8_t));
1218
1219                                  if(sliceSupportItem->sNSSAI.sD != NULLP)
1220                                  {
1221                                     DU_FREE(sliceSupportItem->sNSSAI.sD->buf,\
1222                                           sliceSupportItem->sNSSAI.sD->size);
1223                                     DU_FREE(sliceSupportItem->sNSSAI.sD, sizeof(OCTET_STRING_t));
1224                                  }
1225
1226                                  DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.\
1227                                        choice.SliceSupportList.list.array[sliceIdx], sizeof(SliceSupportItem_t));
1228                               }
1229                            }
1230                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1231                                  SliceSupportList.list.array, servedPlmnItem->iE_Extensions->list.array[0]->\
1232                                  extensionValue.choice.SliceSupportList.list.size);
1233                         }
1234                         DU_FREE(servedPlmnItem->iE_Extensions->list.array[0],\
1235                               sizeof(ServedPLMNs_ItemExtIEs_t));
1236                      }
1237                      DU_FREE(servedPlmnItem->iE_Extensions->list.array,\
1238                            extensionCnt*sizeof(ServedPLMNs_ItemExtIEs_t*));
1239                   }
1240                   DU_FREE(servedPlmnItem->iE_Extensions, sizeof(ProtocolExtensionContainer_4624P3_t));
1241                }
1242                DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx],\
1243                      sizeof(ServedPLMNs_Item_t));
1244             }
1245             DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array,\
1246                   sizeof(ServedPLMNs_Item_t *));
1247          }
1248
1249          if(srvCellItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1250          {
1251             freeFddNrFreqInfo(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1252          }
1253          else   
1254          {
1255             if(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD != NULLP)
1256             {
1257                freeTddNrFreqInfo(&srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1258                DU_FREE(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1259             }
1260          }
1261          
1262          DU_FREE(srvCellItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1263                srvCellItem->served_Cell_Information.measurementTimingConfiguration.size);
1264
1265          if(srvCellItem->gNB_DU_System_Information != NULLP)
1266          {
1267             if(srvCellItem->gNB_DU_System_Information->mIB_message.buf != NULLP)
1268             {
1269                DU_FREE(srvCellItem->gNB_DU_System_Information->mIB_message.buf,\
1270                      srvCellItem->gNB_DU_System_Information->mIB_message.size);
1271             }
1272
1273             if(srvCellItem->gNB_DU_System_Information->sIB1_message.buf != NULLP)
1274             { 
1275                DU_FREE(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,\
1276                      srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1277             }
1278
1279             DU_FREE(srvCellItem->gNB_DU_System_Information, sizeof(GNB_DU_System_Information_t));
1280          }
1281
1282          DU_FREE(duServedCell->list.array[0], sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1283       }
1284       DU_FREE(duServedCell->list.array, plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t*));
1285    }
1286 }
1287
1288 /*******************************************************************
1289  *
1290  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1291  *
1292  * @details
1293  *
1294  *    Function :  FreeF1SetupReq
1295  *
1296  *    Functionality:  deallocating the memory of function BuildAndSendF1SetupReq
1297  *
1298  * @params[in] F1AP_PDU_t *f1apMsg
1299  *
1300  * @return void
1301  *
1302  * ****************************************************************/
1303 void FreeF1SetupReq(F1AP_PDU_t *f1apMsg)
1304 {
1305    uint8_t ieIdx, ieIdx2;
1306    F1SetupRequest_t *f1SetupReq=NULLP;
1307
1308    if(f1apMsg != NULLP)
1309    {
1310       if(f1apMsg->choice.initiatingMessage != NULLP)
1311       {
1312          f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1313          if(f1SetupReq->protocolIEs.list.array != NULLP)
1314          {
1315             for(ieIdx = 0; ieIdx < f1SetupReq->protocolIEs.list.count; ieIdx++)
1316             {
1317                if(f1SetupReq->protocolIEs.list.array[ieIdx] != NULLP)
1318                {
1319                   switch(f1SetupReq->protocolIEs.list.array[ieIdx]->id)
1320                   {
1321                      case ProtocolIE_ID_id_TransactionID:
1322                         break;
1323                      case ProtocolIE_ID_id_gNB_DU_ID:
1324                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1325                               f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1326                         break;
1327                      case ProtocolIE_ID_id_gNB_DU_Name:
1328                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,\
1329                               strlen((char *)duCfgParam.duName));
1330                         break;
1331                      case ProtocolIE_ID_id_gNB_DU_Served_Cells_List:
1332                         FreeServedCellList(&f1SetupReq->protocolIEs.list.\
1333                               array[ieIdx]->value.choice.GNB_DU_Served_Cells_List);
1334                         break;
1335                      case ProtocolIE_ID_id_GNB_DU_RRC_Version:
1336                         FreeRrcVer(&f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version);
1337                         break;
1338                      default:
1339                         DU_LOG("\nERROR  -->  Invalid Event Type %ld", f1SetupReq->protocolIEs.list.array[ieIdx]->id);
1340                         break;
1341                   }
1342                }
1343             }
1344             for(ieIdx2=0; ieIdx2< ieIdx; ieIdx2++)
1345             {
1346                DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx2],sizeof(F1SetupRequestIEs_t));
1347             }
1348             DU_FREE(f1SetupReq->protocolIEs.list.array,\
1349                   f1SetupReq->protocolIEs.list.size);
1350          }
1351          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1352       }
1353       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
1354    }
1355 }
1356 /*******************************************************************
1357  *
1358  * @brief Builds and Send the F1SetupRequest
1359  *
1360  * @details
1361  *
1362  *    Function : BuildAndSendF1SetupReq
1363  *
1364  * Functionality:Fills the F1SetupRequest
1365  *
1366  * @return ROK     - success
1367  *         RFAILED - failure
1368  *
1369  ******************************************************************/
1370 uint8_t BuildAndSendF1SetupReq()
1371 {
1372    uint8_t   ret, ieIdx, elementCnt;
1373    F1AP_PDU_t                 *f1apMsg = NULLP;
1374    F1SetupRequest_t           *f1SetupReq=NULLP;
1375    GNB_DU_Served_Cells_List_t *duServedCell=NULLP;
1376    RRC_Version_t              *rrcVer=NULLP;
1377    asn_enc_rval_t             encRetVal;        /* Encoder return value */
1378    ret= RFAILED;
1379
1380    DU_LOG("\nINFO   -->  F1AP : Building F1 Setup Request\n");
1381    do
1382    {
1383       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
1384       if(f1apMsg == NULLP)
1385       {
1386          break;
1387       }
1388       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
1389       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1390       if(f1apMsg->choice.initiatingMessage == NULLP)
1391       {
1392          break;
1393       }
1394       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_F1Setup;
1395       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
1396       f1apMsg->choice.initiatingMessage->value.present = \
1397                                                          InitiatingMessage__value_PR_F1SetupRequest;
1398
1399       f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1400
1401       elementCnt = (duCfgParam.duName != NULL) ? 5 : 4;
1402
1403       f1SetupReq->protocolIEs.list.count = elementCnt;
1404       f1SetupReq->protocolIEs.list.size = elementCnt * sizeof(F1SetupRequestIEs_t );
1405
1406       /* Initialize the F1Setup members */
1407       DU_ALLOC(f1SetupReq->protocolIEs.list.array,f1SetupReq->protocolIEs.list.size);
1408       if(f1SetupReq->protocolIEs.list.array == NULLP)
1409       {
1410          break;
1411       }
1412       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
1413       {
1414          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx],\
1415                sizeof(F1SetupRequestIEs_t));
1416          if(f1SetupReq->protocolIEs.list.array[ieIdx] == NULLP)
1417          {
1418             break;
1419          }
1420       }
1421
1422       ieIdx = 0;
1423       /*TransactionID*/
1424       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_TransactionID;
1425       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1426       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present =\
1427                                                                F1SetupRequestIEs__value_PR_TransactionID;
1428       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = \
1429                                                                              TRANS_ID;
1430
1431       /*DU ID*/
1432       ieIdx++;
1433       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
1434       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1435       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1436                                                                 F1SetupRequestIEs__value_PR_GNB_DU_ID;
1437       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size =\
1438                                                                              sizeof(uint8_t);
1439
1440       DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1441             f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1442       if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == \
1443             NULLP)
1444       {
1445          break;
1446       }
1447
1448       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] =\
1449          duCfgParam.duId;
1450
1451       /*DU Name*/
1452       if(duCfgParam.duName != NULL)
1453       {
1454          ieIdx++;
1455          f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_Name;
1456          f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_ignore;
1457          f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = F1SetupRequestIEs__value_PR_GNB_DU_Name;
1458          f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size =\
1459             strlen((char *)duCfgParam.duName);
1460          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.\
1461                GNB_DU_Name.buf, strlen((char *)duCfgParam.duName));
1462          if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.\
1463                buf == NULLP)
1464          {
1465             break;
1466          }
1467          strcpy((char*)f1SetupReq->protocolIEs.list.array[ieIdx]->value.\
1468                choice.GNB_DU_Name.buf,
1469                (char*)&duCfgParam.duName);
1470
1471       }
1472
1473       /*Served Cell list */
1474       ieIdx++;
1475       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1476                                                      ProtocolIE_ID_id_gNB_DU_Served_Cells_List;
1477       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1478       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1479                                                                 F1SetupRequestIEs__value_PR_GNB_DU_Served_Cells_List;
1480       duServedCell = &f1SetupReq->protocolIEs.list.\
1481                      array[ieIdx]->value.choice.GNB_DU_Served_Cells_List;
1482       if(BuildServedCellList(duServedCell))
1483       {
1484          break;
1485       }
1486       /*RRC Version*/
1487       ieIdx++;
1488       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1489                                                      ProtocolIE_ID_id_GNB_DU_RRC_Version ;
1490       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1491       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1492                                                                 F1SetupRequestIEs__value_PR_RRC_Version;
1493       rrcVer = &f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
1494       if(BuildRrcVer(rrcVer))
1495       {
1496          break;
1497       }
1498       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
1499
1500       /* Encode the F1SetupRequest type as APER */
1501       memset(encBuf, 0, ENC_BUF_MAX_LEN);
1502       encBufSize = 0;
1503       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
1504             encBuf);
1505
1506       /* Encode results */
1507       if(encRetVal.encoded == ENCODE_FAIL)
1508       {
1509          DU_LOG("\nERROR  -->  F1AP : Could not encode F1SetupRequest structure (at %s)\n",\
1510                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1511          break;
1512       }
1513       else
1514       {
1515          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1SetupRequest\n");
1516          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
1517          {
1518             printf("%x",encBuf[ieIdx]);
1519          }
1520          
1521          duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize = encBufSize;
1522          DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, encBufSize);
1523          if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
1524          {
1525              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the encoding of f1setup req");
1526              return RFAILED;
1527          }
1528          memcpy(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, &encBuf, duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize);
1529       }
1530
1531       /* Sending msg */
1532       if(sendF1APMsg() != ROK)
1533       {
1534          DU_LOG("\nERROR  -->  F1AP : Sending F1 Setup request failed");
1535          break;
1536       }
1537
1538       ret=ROK;
1539       break;
1540    }while(true);
1541
1542    FreeF1SetupReq(f1apMsg);
1543
1544    return ret;
1545 }/* End of BuildAndSendF1SetupReq */
1546
1547 /*******************************************************************
1548  *
1549  * @brief Deallocating memory allocated for Served_Cells_To_Modify_Item_t
1550  *
1551  * @details
1552  *
1553  *    Function : freeCellsToModifyItem 
1554  *
1555  *    Functionality: Deallocating memory of variables allocated in
1556  *                    BuildAndSendDUConfigUpdate function
1557  *
1558  * @params[in]  Served_Cells_To_Modify_Item_t *modifyItem
1559  *
1560  * @return ROK     - void
1561  *
1562  * ****************************************************************/
1563
1564 void freeCellsToModifyItem(Served_Cells_To_Modify_Item_t *modifyItem)
1565 {
1566    uint8_t arrIdx=0, servedPlmnIdx=0, sliceLstIdx=0;
1567    ServedPLMNs_Item_t *servedPlmnItem = NULLP;
1568    SliceSupportItem_t *sliceSupportItem = NULLP;
1569
1570    DU_FREE(modifyItem->oldNRCGI.pLMN_Identity.buf, modifyItem->oldNRCGI.pLMN_Identity.size);
1571    DU_FREE(modifyItem->oldNRCGI.nRCellIdentity.buf, modifyItem->oldNRCGI.nRCellIdentity.size);
1572
1573    DU_FREE(modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1574            modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.size);
1575    DU_FREE(modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1576          modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.size);
1577
1578    if(modifyItem->served_Cell_Information.servedPLMNs.list.array != NULLP)
1579    {
1580       if(modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx] != NULLP)
1581       {
1582          servedPlmnItem = modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx];
1583
1584          DU_FREE(servedPlmnItem->pLMN_Identity.buf,servedPlmnItem->pLMN_Identity.size);
1585
1586          if(servedPlmnItem->iE_Extensions != NULLP)
1587          {
1588             if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1589             {
1590                if(servedPlmnItem->iE_Extensions->list.array[arrIdx] != NULLP)
1591                {
1592                   if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1593                         list.array != NULLP)
1594                   {
1595                      for(sliceLstIdx =0; sliceLstIdx<servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1596                            extensionValue.choice.SliceSupportList.list.count; sliceLstIdx++)
1597                      {
1598                         if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1599                               list.array[sliceLstIdx] != NULLP)
1600                         {
1601
1602                            sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1603                                               SliceSupportList.list.array[sliceLstIdx];
1604
1605                            DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sliceSupportItem->sNSSAI.sST.size);
1606                            if(sliceSupportItem->sNSSAI.sD != NULLP)
1607                            {
1608                               DU_FREE(sliceSupportItem->sNSSAI.sD->buf, sliceSupportItem->sNSSAI.sD->size);
1609                               DU_FREE(sliceSupportItem->sNSSAI.sD,sizeof(OCTET_STRING_t));
1610                            }
1611                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1612                                  SliceSupportList.list.array[sliceLstIdx], sizeof(SliceSupportItem_t));
1613                         }
1614                      }
1615                      DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.\
1616                            choice.SliceSupportList.list.array,\
1617                            servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1618                            extensionValue.choice.SliceSupportList.list.size);
1619                   }
1620                }
1621                for(servedPlmnIdx=0; servedPlmnIdx< servedPlmnItem->iE_Extensions->list.count ; servedPlmnIdx++)
1622                {
1623                   DU_FREE(servedPlmnItem->iE_Extensions->list.array[servedPlmnIdx], sizeof(ServedPLMNs_ItemExtIEs_t ));
1624                }
1625                DU_FREE(servedPlmnItem->iE_Extensions->list.array, servedPlmnItem->iE_Extensions->list.size);
1626             }
1627             DU_FREE(servedPlmnItem->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1628          }
1629       }
1630       for(servedPlmnIdx=0; servedPlmnIdx<modifyItem->served_Cell_Information.servedPLMNs.list.count; servedPlmnIdx++)
1631       {
1632          DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array[servedPlmnIdx], sizeof(ServedPLMNs_Item_t));
1633       }
1634       DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array,\
1635          modifyItem->served_Cell_Information.servedPLMNs.list.size);
1636    }
1637    
1638    if(modifyItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1639    {
1640       freeFddNrFreqInfo(modifyItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1641    }  
1642    else
1643    {
1644       if(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD)
1645       {
1646          freeTddNrFreqInfo(&modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1647          DU_FREE(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1648       }
1649    }
1650    DU_FREE(modifyItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1651       modifyItem->served_Cell_Information.measurementTimingConfiguration.size);
1652 }
1653
1654 /*******************************************************************
1655  *
1656  * @brief Deallocating memory of BuildAndSendDUConfigUpdate
1657  *
1658  * @details
1659  *
1660  *    Function : FreeDUConfigUpdate
1661  *
1662  *    Functionality: Deallocating memory of variables allocated in
1663  *                    BuildAndSendDUConfigUpdate function
1664  *
1665  * @params[in]  F1AP_PDU_t *f1apDuCfg
1666  *
1667  * @return ROK     - void
1668  *
1669  * ****************************************************************/
1670 void FreeDUConfigUpdate(F1AP_PDU_t *f1apDuCfg)
1671 {
1672    uint8_t  ieIdx=0, cellModifyIdx=0, cellDeleteIdx=0;
1673    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
1674    Served_Cells_To_Modify_List_t  *cellsToModify=NULLP;
1675    Served_Cells_To_Delete_List_t  *cellsToDelete=NULLP;
1676    Served_Cells_To_Delete_Item_t  *deleteItem = NULLP;
1677    Served_Cells_To_Delete_ItemIEs_t *deleteItemIe = NULLP;
1678
1679    if(f1apDuCfg != NULLP)
1680    {
1681       if(f1apDuCfg->choice.initiatingMessage != NULLP)
1682       {
1683          duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->\
1684                        value.choice.GNBDUConfigurationUpdate;
1685          if(duCfgUpdate->protocolIEs.list.array != NULLP)
1686          {
1687             for(ieIdx=0; ieIdx<duCfgUpdate->protocolIEs.list.count; ieIdx++)
1688             {
1689                if(duCfgUpdate->protocolIEs.list.array[ieIdx] != NULLP)
1690                {
1691                   switch(duCfgUpdate->protocolIEs.list.array[ieIdx]->id)
1692                   {
1693                      case ProtocolIE_ID_id_Served_Cells_To_Modify_List:
1694                         {
1695                            cellsToModify = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1696                                            value.choice.Served_Cells_To_Modify_List;
1697                            if(cellsToModify->list.array != NULLP)
1698                            {
1699                               for(cellModifyIdx=0; cellModifyIdx<cellsToModify->list.count ;cellModifyIdx++)
1700                               {
1701                                  if(cellsToModify->list.array[cellModifyIdx] != NULLP)
1702                                  {
1703                                     freeCellsToModifyItem(&cellsToModify->list.array[cellModifyIdx]->value.choice.\
1704                                           Served_Cells_To_Modify_Item);
1705                                     DU_FREE(cellsToModify->list.array[cellModifyIdx],\
1706                                           sizeof(Served_Cells_To_Modify_ItemIEs_t));
1707                                  }
1708                               }
1709                               DU_FREE(cellsToModify->list.array,cellsToModify->list.size);
1710                            }
1711                            break;
1712                         }
1713                      case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
1714                         {
1715                            cellsToDelete = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1716                                            value.choice.Served_Cells_To_Delete_List;
1717                            if(cellsToDelete->list.array != NULLP)
1718                            {
1719                               for(cellDeleteIdx=0; cellDeleteIdx<cellsToDelete->list.count ;cellDeleteIdx++)
1720                               {
1721                                  if(cellsToDelete->list.array[cellDeleteIdx] != NULLP)
1722                                  {
1723                                     deleteItemIe = ((Served_Cells_To_Delete_ItemIEs_t*)\
1724                                           cellsToDelete->list.array[cellDeleteIdx]);
1725                                     deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
1726                                     DU_FREE(deleteItem->oldNRCGI.pLMN_Identity.buf,\
1727                                           deleteItem->oldNRCGI.pLMN_Identity.size); 
1728                                     DU_FREE(deleteItem->oldNRCGI.nRCellIdentity.buf,\
1729                                           deleteItem->oldNRCGI.nRCellIdentity.size);
1730                                     DU_FREE(cellsToDelete->list.array[cellDeleteIdx],\
1731                                           sizeof(Served_Cells_To_Delete_ItemIEs_t));
1732                                  }
1733                               }
1734                               DU_FREE(cellsToDelete->list.array,cellsToDelete->list.size);
1735                            }
1736
1737                            break;
1738                         }
1739                      case ProtocolIE_ID_id_gNB_DU_ID:
1740                         {
1741                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1742                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1743                            break;
1744                         }
1745                   }
1746                   DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx],\
1747                         sizeof(GNBDUConfigurationUpdateIEs_t));
1748                }
1749             }
1750             DU_FREE(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
1751          }
1752          DU_FREE(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
1753       }
1754       DU_FREE(f1apDuCfg, (Size)sizeof(F1AP_PDU_t));
1755    }
1756 }
1757
1758 /*******************************************************************
1759  *
1760  * @brief Fills Served Plmns required in ServCellInfo IE
1761  *
1762  * @details
1763  *
1764  *    Function : fillServedPlmns
1765  *
1766  *    Functionality: Fills Served Plmns required in ServCellInfo IE
1767  *
1768  * @params[in] Pointer to ServedPLMNs_List_t *
1769  *
1770  * @return ROK     - success
1771  *         RFAILED - failure
1772  *
1773  *****************************************************************/
1774
1775 uint8_t fillServedPlmns(ServedPLMNs_List_t *servedPlmn)
1776 {
1777    uint8_t ieIdx=0, arrayIdx=0, ieListCnt=0, elementCnt=0, sliceLstIdx=0;
1778
1779    servedPlmn->list.array[arrayIdx]->pLMN_Identity.size = 3*sizeof(uint8_t);
1780    DU_ALLOC(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf, servedPlmn->list.\
1781          array[arrayIdx]->pLMN_Identity.size);
1782    if(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf == NULLP)
1783    {
1784       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1785       return RFAILED;
1786    }
1787    buildPlmnId(duCfgParam.srvdCellLst[arrayIdx].duCellInfo.cellInfo.srvdPlmn[arrayIdx].plmn,\
1788          servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf);
1789    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1790    if(servedPlmn->list.array[arrayIdx]->iE_Extensions == NULLP)
1791    {
1792       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1793       return RFAILED;
1794    }
1795
1796    ieListCnt=1;
1797    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.count = ieListCnt;
1798    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.size = ieListCnt *sizeof(ServedPLMNs_ItemExtIEs_t *);
1799    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array,servedPlmn->list.array[arrayIdx]->\
1800          iE_Extensions->list.size);
1801    if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array == NULLP)
1802    {
1803       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1804       return RFAILED;
1805    }
1806    for(ieIdx=arrayIdx;ieIdx<ieListCnt;ieIdx++)
1807    {
1808       DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx],\
1809             sizeof(ServedPLMNs_ItemExtIEs_t));
1810       if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx] == NULLP)
1811       {
1812          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1813          return RFAILED;
1814       }
1815    }
1816    
1817    ieIdx = 0;
1818    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices; 
1819    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->id =ProtocolIE_ID_id_TAISliceSupportList;
1820    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->criticality = Criticality_ignore;
1821    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.present = \
1822    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
1823    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1824       list.count = elementCnt;
1825    servedPlmn->list.array[arrayIdx]->\
1826       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1827       list.size = elementCnt * sizeof(SliceSupportItem_t *);
1828    DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1829          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1830          list.array,servedPlmn->list.array[arrayIdx]->\
1831          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.size);
1832    if(servedPlmn->list.array[arrayIdx]->\
1833          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1834          list.array == NULLP)
1835    {
1836       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1837       return RFAILED;
1838    }
1839
1840    for(sliceLstIdx =0; sliceLstIdx< elementCnt; sliceLstIdx++)
1841    {
1842       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1843       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1844       list.array[sliceLstIdx],sizeof( SliceSupportItem_t));
1845       if(servedPlmn->list.array[arrayIdx]->\
1846       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1847       list.array[sliceLstIdx] == NULLP)
1848       {   
1849          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1850          return RFAILED;
1851       }
1852       
1853       servedPlmn->list.array[arrayIdx]->\
1854       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1855       list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
1856       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1857       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1858       list.array[sliceLstIdx]->sNSSAI.sST.buf,servedPlmn->list.array[arrayIdx]->\
1859       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->\
1860       sNSSAI.sST.size);
1861       
1862       if(servedPlmn->list.array[arrayIdx]->\
1863       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1864       list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
1865       {
1866          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1867          return RFAILED;
1868       }
1869       servedPlmn->list.array[arrayIdx]->\
1870       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1871       list.array[sliceLstIdx]->sNSSAI.sST.buf[arrayIdx] =  duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
1872       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
1873
1874       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1875       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1876       list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
1877       if(servedPlmn->list.array[arrayIdx]->\
1878       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1879       list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
1880       {
1881          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1882          return RFAILED;
1883       }
1884       servedPlmn->list.array[arrayIdx]->\
1885       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1886       list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
1887       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1888       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1889       list.array[sliceLstIdx]->sNSSAI.sD->buf,servedPlmn->list.array[arrayIdx]->\
1890       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1891       list.array[sliceLstIdx]->sNSSAI.sD->size);
1892       if(servedPlmn->list.array[arrayIdx]->\
1893       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1894       list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
1895       {
1896          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1897          return RFAILED;
1898       }
1899       memcpy(servedPlmn->list.array[arrayIdx]->\
1900       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1901       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
1902       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sd,\
1903       servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1904       list.array[sliceLstIdx]->sNSSAI.sD->size);
1905    }
1906    return ROK;
1907 }
1908
1909 /*******************************************************************
1910  *
1911  * @brief Fills Nr Fdd Info required in ServCellInfo IE
1912  *
1913  * @details
1914  *
1915  *    Function : fillNrFddInfo
1916  *
1917  *    Functionality: Fills Nr Fdd Info required in ServCellInfo IE
1918  *
1919  * @params[in] FDD_Info_t *fDD
1920  *
1921  * @return ROK     - success
1922  *         RFAILED - failure
1923  *
1924  *****************************************************************/
1925
1926 uint8_t fillNrFddInfo(FDD_Info_t *fDD)
1927 {
1928    fDD->uL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.\
1929       f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn;
1930    fDD->uL_NRFreqInfo.freqBandListNr.list.count = 1;
1931    fDD->uL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t*);
1932    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.\
1933          array, fDD->uL_NRFreqInfo.freqBandListNr.list.size);
1934    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array == NULLP)
1935    {
1936       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
1937       return RFAILED;
1938    }
1939
1940    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0], \
1941       sizeof(FreqBandNrItem_t));
1942    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
1943    {
1944       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
1945       return RFAILED;
1946    }
1947    
1948    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
1949       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
1950       freqBand[0].nrFreqBand;
1951    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
1952    fDD->dL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.\
1953       dlNrFreqInfo.nrArfcn;
1954    fDD->dL_NRFreqInfo.freqBandListNr.list.count = 1;
1955    fDD->dL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
1956    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array, fDD->dL_NRFreqInfo.freqBandListNr.list.size);
1957    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array == NULLP)
1958    {
1959       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
1960       return RFAILED;
1961    }
1962    
1963    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0],  sizeof(FreqBandNrItem_t));
1964    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
1965    {
1966       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
1967       return RFAILED;
1968    }
1969
1970    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
1971       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
1972       freqBand[0].nrFreqBand;
1973    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
1974    
1975    /*Transmission Bandwidth*/
1976    fDD->uL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
1977       f1Mode.mode.fdd.ulTxBw.nrScs;
1978    fDD->uL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
1979       f1Mode.mode.fdd.ulTxBw.nrb;
1980    fDD->dL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
1981       f1Mode.mode.fdd.dlTxBw.nrScs;
1982    fDD->dL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
1983       f1Mode.mode.fdd.dlTxBw.nrb;
1984
1985    return ROK;
1986 }
1987
1988 /*******************************************************************
1989  *
1990  * @brief Fills ServCellInfo IE
1991  *
1992  * @details
1993  *
1994  *    Function : fillServedCellInfo
1995  *
1996  *    Functionality: Fills ServCellInfo
1997  *
1998  * @params[in] Pointer to Served_Cell_Information_t *
1999  *
2000  * @return ROK     - success
2001  *         RFAILED - failure
2002  *
2003  *****************************************************************/
2004
2005 uint8_t fillServedCellInfo(Served_Cell_Information_t *srvCellInfo)
2006 {
2007    uint8_t ieIdx, ieListCnt;
2008
2009    /*nRCGI*/
2010    srvCellInfo->nRCGI.pLMN_Identity.size =3*sizeof(uint8_t);
2011    DU_ALLOC(srvCellInfo->nRCGI.pLMN_Identity.buf,\
2012          srvCellInfo->nRCGI.pLMN_Identity.size);
2013    if(srvCellInfo->nRCGI.pLMN_Identity.buf == NULLP)
2014    {
2015       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2016       return RFAILED;
2017    }
2018    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2019          srvCellInfo->nRCGI.pLMN_Identity.buf);
2020    srvCellInfo->nRCGI.nRCellIdentity.size =5*sizeof(uint8_t);
2021    DU_ALLOC(srvCellInfo->nRCGI.nRCellIdentity.buf,\
2022          srvCellInfo->nRCGI.nRCellIdentity.size);
2023    if(srvCellInfo->nRCGI.nRCellIdentity.buf == NULLP)
2024    {   
2025       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2026       return RFAILED;
2027    }
2028    
2029    fillBitString(&srvCellInfo->nRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2030    /*nRPCI*/
2031    srvCellInfo->nRPCI = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
2032
2033    /*servedPLMNs*/
2034    ieListCnt = 1;
2035    srvCellInfo->servedPLMNs.list.count = ieListCnt;
2036    srvCellInfo->servedPLMNs.list.size = ieListCnt*sizeof(ServedPLMNs_Item_t *);
2037    DU_ALLOC(srvCellInfo->servedPLMNs.list.array, srvCellInfo->servedPLMNs.list.size);
2038    if(srvCellInfo->servedPLMNs.list.array == NULLP)
2039    {
2040       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2041       return RFAILED;
2042    }
2043    for(ieIdx=0; ieIdx < ieListCnt; ieIdx++)
2044    {
2045       DU_ALLOC(srvCellInfo->servedPLMNs.list.array[ieIdx], sizeof(ServedPLMNs_Item_t));
2046       if(srvCellInfo->servedPLMNs.list.array[ieIdx]== NULLP)
2047       {
2048          DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2049          return RFAILED;
2050       }
2051    }
2052    if(fillServedPlmns(&srvCellInfo->servedPLMNs))
2053    {
2054       DU_LOG("\nERROR  --> Failed to fill Served Plmn info");
2055       return RFAILED;
2056    }
2057
2058 #ifndef NR_TDD
2059    /*nR Mode Info with FDD*/
2060    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_fDD;
2061    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.fDD, sizeof(FDD_Info_t));
2062    if(srvCellInfo->nR_Mode_Info.choice.fDD == NULLP)
2063    {
2064       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2065       return RFAILED;
2066    }
2067    if(fillNrFddInfo(srvCellInfo->nR_Mode_Info.choice.fDD))
2068    {
2069        DU_LOG("\nERROR  --> Failed to fill the Nr FDD information");
2070       return RFAILED;
2071    }
2072 #else
2073    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_tDD;   
2074    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
2075    if(srvCellInfo->nR_Mode_Info.choice.tDD == NULLP)
2076    {
2077       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2078       return RFAILED;
2079    }
2080    if(fillNrTddInfo(srvCellInfo->nR_Mode_Info.choice.tDD) != ROK)
2081    {
2082       DU_LOG("\nERROR  --> Failed to fill the Nr TDD information");
2083       return RFAILED;
2084    }
2085 #endif
2086
2087    /*Measurement timing Config*/
2088    srvCellInfo->measurementTimingConfiguration.size = sizeof(uint8_t);
2089    DU_ALLOC(srvCellInfo->measurementTimingConfiguration.\
2090          buf,srvCellInfo->measurementTimingConfiguration.size);
2091    if(srvCellInfo->measurementTimingConfiguration.buf == NULLP)
2092    {
2093       return RFAILED;
2094    }
2095    srvCellInfo->measurementTimingConfiguration.\
2096          buf[0] = duCfgParam.srvdCellLst[0].duCellInfo.measTimeCfg;
2097
2098    return ROK;
2099 }
2100
2101 /*******************************************************************
2102  *
2103  * @brief Fills ServCellToModItem IE
2104  *
2105  * @details
2106  *
2107  *    Function : fillServCellToModItem
2108  *
2109  *    Functionality: Fills ServCellToModItem IE
2110  *
2111  * @params[in] Pointer to Served_Cells_To_Modify_Item_t *
2112  *
2113  * @return ROK     - success
2114  *         RFAILED - failure
2115  *
2116  *****************************************************************/
2117
2118 uint8_t fillServCellToModItem(Served_Cells_To_Modify_Item_t *modifyItem)
2119 {
2120    /*pLMN_Identity*/
2121    modifyItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2122    DU_ALLOC(modifyItem->oldNRCGI.pLMN_Identity.buf,modifyItem->oldNRCGI.pLMN_Identity.size);
2123    if(modifyItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2124    {
2125       return RFAILED;
2126    }
2127    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2128          modifyItem->oldNRCGI.pLMN_Identity.buf);
2129
2130    /*nRCellIdentity*/
2131    modifyItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2132    DU_ALLOC(modifyItem->oldNRCGI.nRCellIdentity.buf,\
2133          modifyItem->oldNRCGI.nRCellIdentity.size);
2134    if(modifyItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2135    {
2136       return RFAILED;
2137    }
2138    fillBitString(&modifyItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2139
2140    if(fillServedCellInfo(&modifyItem->served_Cell_Information))
2141       return RFAILED;
2142    else
2143       return ROK;
2144 }
2145
2146 /*******************************************************************
2147  *
2148  * @brief Builds ServCellToModList
2149  *
2150  * @details
2151  *
2152  *    Function : buildServCellToModList
2153  *
2154  *    Functionality: Builds the serv cell to Mod List
2155  *
2156  * @params[in] Pointer to Served_Cells_To_Modify_List_t *
2157  *
2158  * @return ROK     - success
2159  *         RFAILED - failure
2160  *
2161  *****************************************************************/
2162
2163 uint8_t buildServCellToModList(Served_Cells_To_Modify_List_t *cellsToModify)
2164 {
2165    uint8_t ieListCnt, ieIdx;
2166    Served_Cells_To_Modify_Item_t *modifyItem = NULLP;
2167
2168    ieListCnt = 1;
2169    cellsToModify->list.count = ieListCnt;
2170    cellsToModify->list.size = ieListCnt*sizeof(Served_Cells_To_Modify_ItemIEs_t *);
2171    DU_ALLOC(cellsToModify->list.array,cellsToModify->list.size);
2172    if(cellsToModify->list.array == NULLP)
2173    {
2174       return RFAILED;
2175    }
2176    for(ieIdx=0; ieIdx< ieListCnt; ieIdx++)
2177    {
2178       DU_ALLOC(cellsToModify->list.array[ieIdx],sizeof(Served_Cells_To_Modify_ItemIEs_t));
2179       if(cellsToModify->list.array[ieIdx] == NULLP)
2180       {
2181          return RFAILED;
2182       }
2183    }
2184    cellsToModify->list.array[0]->id = ProtocolIE_ID_id_Served_Cells_To_Modify_Item;
2185    cellsToModify->list.array[0]->criticality = Criticality_reject;
2186    cellsToModify->list.array[0]->value.present =\
2187       Served_Cells_To_Modify_ItemIEs__value_PR_Served_Cells_To_Modify_Item;
2188    modifyItem=&cellsToModify->list.array[0]->value.choice.Served_Cells_To_Modify_Item;
2189
2190    if(fillServCellToModItem(modifyItem))
2191       return RFAILED;
2192    else
2193       return ROK;
2194 }
2195 /*******************************************************************
2196  *
2197  * @brief filling the DeleteItemList
2198  *
2199  * @details
2200  *
2201  *    Function : fillCellToDeleteItem 
2202  *
2203  *    Functionality: Filling the DeleteItemIe 
2204  *
2205  * @params[in] Pointer to Served_Cells_To_Delete_ItemIEs_t 
2206  *
2207  * @return ROK     - success
2208  *         RFAILED - failure
2209  *
2210  *****************************************************************/
2211 uint8_t fillCellToDeleteItem(struct Served_Cells_To_Delete_ItemIEs *deleteItemIe)
2212 {
2213    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
2214    
2215    deleteItemIe->id = ProtocolIE_ID_id_Served_Cells_To_Delete_Item;
2216    deleteItemIe->criticality = Criticality_reject;
2217    deleteItemIe->value.present =\
2218    Served_Cells_To_Delete_ItemIEs__value_PR_Served_Cells_To_Delete_Item;
2219    deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
2220
2221    /*pLMN_Identity*/
2222    deleteItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2223    DU_ALLOC(deleteItem->oldNRCGI.pLMN_Identity.buf,deleteItem->oldNRCGI.pLMN_Identity.size);
2224    if(deleteItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2225    {
2226       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2227       return RFAILED;
2228    }
2229    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2230          deleteItem->oldNRCGI.pLMN_Identity.buf);
2231
2232    /*nRCellIdentity*/
2233    deleteItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2234    DU_ALLOC(deleteItem->oldNRCGI.nRCellIdentity.buf,\
2235          deleteItem->oldNRCGI.nRCellIdentity.size);
2236    if(deleteItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2237    {
2238       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2239       return RFAILED;
2240    }
2241    fillBitString(&deleteItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2242    return ROK;
2243
2244 /*******************************************************************
2245  *
2246  * @brief Builds ServCellToDeleteList
2247  *
2248  * @details
2249  *
2250  *    Function : buildServCellToDeleteList
2251  *
2252  *    Functionality: Builds the serv cell to delete List
2253  *
2254  * @params[in] Pointer to Served_Cells_To_Delete_List_t *
2255  *
2256  * @return ROK     - success
2257  *         RFAILED - failure
2258  *
2259  *****************************************************************/
2260  
2261 uint8_t buildServCellToDeleteList(Served_Cells_To_Delete_List_t *cellsToDelete)
2262 {
2263    uint8_t ieListCnt, arrIdx;
2264    
2265    ieListCnt = 1;
2266    cellsToDelete->list.count = ieListCnt;
2267    cellsToDelete->list.size = ieListCnt*sizeof(Served_Cells_To_Delete_ItemIEs_t *);
2268    
2269    DU_ALLOC(cellsToDelete->list.array,cellsToDelete->list.size);
2270    if(cellsToDelete->list.array == NULLP)
2271    {
2272       DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2273       return RFAILED;
2274    }
2275    
2276    for(arrIdx=0; arrIdx< ieListCnt; arrIdx++)
2277    {
2278       DU_ALLOC(cellsToDelete->list.array[arrIdx],sizeof(Served_Cells_To_Delete_ItemIEs_t));
2279       if(cellsToDelete->list.array[arrIdx] == NULLP)
2280       {
2281          DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2282          return RFAILED;
2283       }
2284    }
2285    
2286    arrIdx=0;
2287    if(fillCellToDeleteItem((Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx]) !=ROK)
2288    {
2289       DU_LOG("\nERROR  -->  F1AP: buildServCellToDeleteList(): failed to fill Served_Cells_To_Delete_ItemIEs");
2290       return RFAILED;
2291    }
2292    return ROK;
2293 }
2294
2295 /*******************************************************************
2296  *
2297  * @brief Builds and sends the DUConfigUpdate
2298  *
2299  * @details
2300  *
2301  *    Function : BuildAndSendDUConfigUpdate
2302  *
2303  *    Functionality: Constructs the DU Update message and sends
2304  *                   it to the CU through SCTP.
2305  *
2306  * @params[in] void **buf,Buffer to which encoded pattern is written into
2307  * @params[in] int *size,size of buffer
2308  *
2309  * @return ROK     - success
2310  *         RFAILED - failure
2311  *
2312  * ****************************************************************/
2313 uint8_t BuildAndSendDUConfigUpdate(ServCellAction servCellAction)
2314 {
2315    uint8_t ret =0, ieIdx=0, elementCnt=0;
2316    bool memAlloctionFailure = false;
2317    F1AP_PDU_t                 *f1apDuCfg = NULLP;
2318    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
2319    asn_enc_rval_t encRetVal;     /* Encoder return value */
2320    
2321    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2322    ret= RFAILED;
2323
2324    while(true)
2325    {
2326       DU_LOG("\nINFO   -->  F1AP : Building DU config update\n");
2327       /* Allocate the memory for F1DuCfg */
2328       DU_ALLOC(f1apDuCfg, sizeof(F1AP_PDU_t));
2329       if(f1apDuCfg == NULLP)
2330       {
2331          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2332          break;
2333       }
2334
2335       f1apDuCfg->present = F1AP_PDU_PR_initiatingMessage;
2336       DU_ALLOC(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2337       if(f1apDuCfg->choice.initiatingMessage == NULLP)
2338       {
2339          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2340          break;
2341       }
2342
2343       f1apDuCfg->choice.initiatingMessage->procedureCode = \
2344                                                            ProcedureCode_id_gNBDUConfigurationUpdate;
2345       f1apDuCfg->choice.initiatingMessage->criticality = Criticality_reject;
2346       f1apDuCfg->choice.initiatingMessage->value.present = \
2347                                                            InitiatingMessage__value_PR_GNBDUConfigurationUpdate;
2348       duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->value.\
2349                     choice.GNBDUConfigurationUpdate;
2350       elementCnt = 3;
2351       duCfgUpdate->protocolIEs.list.count = elementCnt;
2352       duCfgUpdate->protocolIEs.list.size = \
2353                                            elementCnt * sizeof(GNBDUConfigurationUpdateIEs_t*);
2354
2355       /* Initialize the F1Setup members */
2356       DU_ALLOC(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2357       if(duCfgUpdate->protocolIEs.list.array == NULLP)
2358       {
2359          DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2360          break;
2361       }
2362       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
2363       {
2364          DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx],sizeof(GNBDUConfigurationUpdateIEs_t));
2365          if(duCfgUpdate->protocolIEs.list.array[ieIdx] == NULLP)
2366          {
2367             DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2368             memAlloctionFailure = true;
2369             break;
2370          }
2371       }
2372       
2373       if(memAlloctionFailure == true)
2374       {
2375          break;
2376       }
2377       /*TransactionID*/
2378       ieIdx = 0;
2379       duCfgUpdate->protocolIEs.list.array[ieIdx]->id=ProtocolIE_ID_id_TransactionID;
2380       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
2381       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2382       GNBDUConfigurationUpdateIEs__value_PR_TransactionID;
2383       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = TRANS_ID;
2384       
2385       ieIdx++;
2386       if(servCellAction == SERV_CELL_TO_MODIFY)
2387       {
2388          /*Served Cell to Modify */
2389          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2390          ProtocolIE_ID_id_Served_Cells_To_Modify_List;
2391          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2392          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2393          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Modify_List;
2394          if(buildServCellToModList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2395                   Served_Cells_To_Modify_List))
2396          {
2397             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToModList");
2398             break;
2399          }
2400       }
2401       else
2402       {
2403          /*Served Cell to Delete */ 
2404          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2405          ProtocolIE_ID_id_Served_Cells_To_Delete_List;
2406          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2407          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2408          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Delete_List;
2409          if(buildServCellToDeleteList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2410          Served_Cells_To_Delete_List)!=ROK)
2411          {
2412             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToDeleteList");
2413             break;
2414          }
2415          
2416       }
2417       // NOTE :GNB DU SYS INFO:MIB AND SIB1 INFORMATION TO BE BUILT AND FILLED HERE
2418       /*GNB DU ID */
2419       ieIdx++;
2420       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
2421       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2422       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2423       GNBDUConfigurationUpdateIEs__value_PR_GNB_DU_ID;
2424       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size = sizeof(uint8_t);
2425       DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
2426             duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
2427       if(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == NULLP)
2428       {
2429          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Memory allocation failed for GNB_DU_ID");
2430          break;
2431       }
2432       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] = duCfgParam.duId;
2433
2434       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apDuCfg);
2435
2436       /* Encode the DU Config Update type as APER */
2437       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
2438       encBufSize = 0;
2439       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apDuCfg, PrepFinalEncBuf, encBuf);
2440
2441       /* Checking encode results */
2442       if(encRetVal.encoded == ENCODE_FAIL)
2443       {
2444          DU_LOG("ERROR  -->  F1AP : Could not encode DUConfigUpdate structure (at %s)\n",\
2445                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2446          break;
2447       }
2448       else
2449       {
2450          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DUConfigUpdate\n");
2451          for(ieIdx =0; ieIdx < encBufSize; ieIdx++)
2452          {
2453             printf("%x",encBuf[ieIdx]);
2454          }
2455       }
2456       /* Sending msg */
2457       if(sendF1APMsg() != ROK)
2458       {
2459          DU_LOG("\nERROR  -->  F1AP : Sending GNB-DU Config Update failed");
2460          break;
2461       }
2462
2463       ret = ROK;
2464       break;
2465    }
2466   
2467    addToReservedF1apPduList(TRANS_ID,f1apDuCfg);
2468    return ret;
2469 }
2470
2471
2472 /*******************************************************************
2473  *
2474  * @brief free the ULRRCMessageTransfer
2475  *
2476  * @details
2477  *
2478  *    Function : FreeULRRCMessageTransfer
2479  *
2480  *    Functionality: Deallocating the memory of variable allocated in
2481  *                      FreeULRRCMessageTransfer
2482  *
2483  * @params[in]
2484  *
2485  * @return ROK     - void
2486  *
2487  ******************************************************************/
2488 void FreeULRRCMessageTransfer( F1AP_PDU_t *f1apMsg)
2489 {
2490    uint8_t idx1;
2491    ULRRCMessageTransfer_t  *ulRRCMsg;
2492
2493    if(f1apMsg != NULLP)
2494    { 
2495       if(f1apMsg->choice.initiatingMessage != NULLP)
2496       {
2497          ulRRCMsg = &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2498          if(ulRRCMsg->protocolIEs.list.array != NULLP)
2499          {
2500             for(idx1=0;idx1<ulRRCMsg->protocolIEs.list.count;idx1++)
2501             {
2502                if(ulRRCMsg->protocolIEs.list.array[idx1] != NULLP)
2503                {
2504                   if(ulRRCMsg->protocolIEs.list.array[idx1]->value.present ==
2505                         ULRRCMessageTransferIEs__value_PR_RRCContainer)
2506                   {
2507                      DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2508                            ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2509                   }
2510                   DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1],sizeof(ULRRCMessageTransferIEs_t));
2511                }
2512             }
2513             DU_FREE(ulRRCMsg->protocolIEs.list.array,ulRRCMsg->protocolIEs.list.size );
2514          }
2515          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2516       }
2517       DU_FREE(f1apMsg,sizeof(F1AP_PDU_t));
2518    }
2519 }
2520 /*******************************************************************
2521  *
2522  * @brief Builds and sends the ULRRCMessageTransfer 
2523  *
2524  * @details
2525  *
2526  *    Function : BuildAndSendULRRCMessageTransfer
2527  *
2528  *    Functionality: Constructs the UL RRC Message Transfer and sends
2529  *                   it to the CU through SCTP.
2530  *
2531  * @params[in] 
2532  *
2533  * @return ROK     - success
2534  *         RFAILED - failure
2535  *
2536  * ****************************************************************/
2537 uint8_t BuildAndSendULRRCMessageTransfer(DuUeCb  *ueCb, uint8_t lcId, \
2538       uint16_t msgLen, uint8_t *rrcMsg)
2539 {
2540    uint8_t                 elementCnt=0, idx1=0, idx=0;
2541    uint8_t                 ret = RFAILED;
2542    F1AP_PDU_t              *f1apMsg = NULLP;
2543    ULRRCMessageTransfer_t  *ulRRCMsg = NULLP;
2544    asn_enc_rval_t          encRetVal;        /* Encoder return value */
2545    
2546    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2547
2548    while(true)
2549    {
2550       DU_LOG("\n INFO   -->  F1AP : Building UL RRC Message Transfer Message\n");
2551
2552       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
2553       if(f1apMsg == NULLP)
2554       {
2555          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
2556          break;
2557       }
2558       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
2559       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2560       if(f1apMsg->choice.initiatingMessage == NULLP)
2561       {
2562          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
2563          break;
2564       }
2565       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_ULRRCMessageTransfer;
2566       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
2567       f1apMsg->choice.initiatingMessage->value.present = \
2568                                                          InitiatingMessage__value_PR_ULRRCMessageTransfer;
2569       ulRRCMsg =
2570          &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2571       elementCnt = 4;
2572       ulRRCMsg->protocolIEs.list.count = elementCnt;
2573       ulRRCMsg->protocolIEs.list.size = \
2574                                         elementCnt * sizeof(ULRRCMessageTransferIEs_t *);
2575
2576       /* Initialize the F1Setup members */
2577       DU_ALLOC(ulRRCMsg->protocolIEs.list.array, ulRRCMsg->protocolIEs.list.size);
2578       if(ulRRCMsg->protocolIEs.list.array == NULLP)
2579       {
2580          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UL RRC MessageTransferIEs failed");
2581          break;
2582       }
2583       for(idx=0; idx<elementCnt; idx++)
2584       {
2585          DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx],sizeof(ULRRCMessageTransferIEs_t));
2586          if(ulRRCMsg->protocolIEs.list.array[idx] == NULLP)
2587          {
2588             break;
2589          }
2590       }
2591
2592       idx1 = 0;
2593
2594       /*GNB CU UE F1AP ID*/
2595       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
2596       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2597       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2598                                                               ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
2599       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
2600
2601       /*GNB DU UE F1AP ID*/
2602       idx1++;
2603       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
2604       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2605       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2606                                                               ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
2607       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
2608
2609       /*SRBID*/
2610       idx1++;
2611       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
2612       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2613       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2614                                                               ULRRCMessageTransferIEs__value_PR_SRBID;
2615       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.SRBID = lcId;
2616
2617       /*RRCContainer*/
2618       idx1++;
2619       ulRRCMsg->protocolIEs.list.array[idx1]->id  = ProtocolIE_ID_id_RRCContainer;
2620       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2621       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2622                                                               ULRRCMessageTransferIEs__value_PR_RRCContainer;
2623       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size = msgLen;
2624       DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2625             ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size)
2626       if(!ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf)
2627       {
2628          DU_LOG(" ERROR  -->  F1AP : Memory allocation for BuildAndSendULRRCMessageTransfer failed");
2629          break;
2630       }
2631       memset(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, 0, msgLen);
2632       memcpy(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, \
2633             rrcMsg, ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2634
2635       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
2636
2637       /* Encode the F1SetupRequest type as APER */
2638       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2639       encBufSize = 0;
2640       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
2641             encBuf);
2642       /* Encode results */
2643       if(encRetVal.encoded == ENCODE_FAIL)
2644       {
2645          DU_LOG( "\nERROR  -->  F1AP : Could not encode ULRRCMessageTransfer structure (at %s)\n",\
2646                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2647          break;
2648       }
2649       else
2650       {
2651          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for ULRRCMessageTransfer\n");
2652          for(int i=0; i< encBufSize; i++)
2653          {
2654             printf("%x",encBuf[i]);
2655          }
2656       }
2657
2658       /* Sending  msg  */
2659       if(sendF1APMsg()  !=      ROK)
2660       {
2661          DU_LOG("\nERROR  -->   F1AP : Sending  UL RRC Message Transfer Failed");
2662          break;
2663       }
2664       ret = ROK;
2665       break;
2666    }
2667    FreeULRRCMessageTransfer(f1apMsg);
2668
2669    return ret;
2670 }/* End of BuildAndSendULRRCMessageTransfer*/
2671
2672 /*******************************************************************
2673  *
2674  * @brief Builds tag config 
2675  *
2676  * @details
2677  *
2678  *    Function : BuildTagConfig 
2679  *
2680  *    Functionality: Builds tag config in MacCellGroupConfig
2681  *
2682  * @params[in] TAG_Config *tag_Config
2683  *
2684  * @return ROK     - success
2685  *         RFAILED - failure
2686  *
2687  * ****************************************************************/
2688 uint8_t BuildTagConfig(DuUeCb *ueCb, struct TAG_Config *tagConfig)
2689 {
2690    struct TAG_Config__tag_ToAddModList *tagList;
2691    uint8_t                     idx, elementCnt;
2692
2693    tagConfig->tag_ToReleaseList = NULLP;
2694    tagConfig->tag_ToAddModList = NULLP;
2695    DU_ALLOC(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
2696    if(!tagConfig->tag_ToAddModList)
2697    {
2698       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2699       return RFAILED;
2700    }
2701
2702    if(ueCb == NULLP)
2703       elementCnt = ODU_VALUE_ONE;
2704    else
2705       elementCnt = ueCb->macUeCfg.macCellGrpCfg.tagCfg.addModListCount;
2706
2707    tagList = tagConfig->tag_ToAddModList;
2708    tagList->list.count = elementCnt;
2709    tagList->list.size  =  elementCnt * sizeof(struct TAG *);
2710
2711    tagList->list.array = NULLP;
2712    DU_ALLOC(tagList->list.array, tagList->list.size);
2713    if(!tagList->list.array)
2714    {
2715       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2716       return RFAILED;
2717    }
2718
2719    for(idx=0; idx<tagList->list.count; idx++)
2720    {
2721       tagList->list.array[idx] = NULLP;
2722       DU_ALLOC(tagList->list.array[idx], sizeof(struct TAG));
2723       if(!tagList->list.array[idx])
2724       {
2725          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2726          return RFAILED;
2727       }
2728    }
2729
2730    if(ueCb == NULLP)
2731    {
2732       idx = 0;
2733       tagList->list.array[idx]->tag_Id = TAG_ID;
2734       tagList->list.array[idx]->timeAlignmentTimer = TIME_ALIGNMENT_TMR;
2735    }
2736    else
2737    {
2738       for(idx=0; idx<tagList->list.count; idx++)
2739       {
2740          tagList->list.array[idx]->tag_Id = ueCb->macUeCfg.macCellGrpCfg.tagCfg.addModList[idx].tagId;
2741          tagList->list.array[idx]->timeAlignmentTimer = ueCb->macUeCfg.macCellGrpCfg.tagCfg.addModList[idx].timeAlignTimer;
2742       }
2743    }
2744
2745    return ROK;
2746 }
2747
2748 /*******************************************************************
2749  *
2750  * @brief Builds PHR Config 
2751  *
2752  * @details
2753  *
2754  *    Function : BuildPhrConfig
2755  *
2756  *    Functionality: Builds phrConfig in MacCellGroupConfig
2757  *
2758  * @params[in] PHR Config *
2759  *
2760  * @return ROK     - success
2761  *         RFAILED - failure
2762  *
2763  * ****************************************************************/
2764 uint8_t BuildPhrConfig(DuUeCb *ueCb, struct MAC_CellGroupConfig__phr_Config *phrConfig)
2765 {
2766
2767    phrConfig->present = MAC_CellGroupConfig__phr_Config_PR_setup;
2768    phrConfig->choice.setup = NULLP;
2769    DU_ALLOC(phrConfig->choice.setup, sizeof(struct PHR_Config));
2770    if(!phrConfig->choice.setup)
2771    {
2772       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhrConfig");
2773       return RFAILED;
2774    }
2775
2776    if(ueCb == NULLP)
2777    {
2778       phrConfig->choice.setup->phr_PeriodicTimer        = PHR_PERIODIC_TMR;
2779       phrConfig->choice.setup->phr_ProhibitTimer        = PHR_PROHIBHIT_TMR;
2780       phrConfig->choice.setup->phr_Tx_PowerFactorChange = PHR_PWR_FACTOR_CHANGE;
2781       phrConfig->choice.setup->multiplePHR              = false;
2782       phrConfig->choice.setup->dummy                    = false;
2783       phrConfig->choice.setup->phr_Type2OtherCell       = false;
2784       phrConfig->choice.setup->phr_ModeOtherCG          = PHR_MODE_OTHER_CG;
2785    }
2786    else
2787    {
2788       phrConfig->choice.setup->phr_PeriodicTimer        = ueCb->macUeCfg.macCellGrpCfg.phrCfg.periodicTimer;
2789       phrConfig->choice.setup->phr_ProhibitTimer        = ueCb->macUeCfg.macCellGrpCfg.phrCfg.prohibitTimer;
2790       phrConfig->choice.setup->phr_Tx_PowerFactorChange = ueCb->macUeCfg.macCellGrpCfg.phrCfg.txPowerFactor;
2791       phrConfig->choice.setup->multiplePHR              = ueCb->macUeCfg.macCellGrpCfg.phrCfg.multiplePHR;
2792       phrConfig->choice.setup->dummy                    = ueCb->macUeCfg.macCellGrpCfg.phrCfg.dummy;
2793       phrConfig->choice.setup->phr_Type2OtherCell       = ueCb->macUeCfg.macCellGrpCfg.phrCfg.phrType2OtherCell;
2794       phrConfig->choice.setup->phr_ModeOtherCG          = ueCb->macUeCfg.macCellGrpCfg.phrCfg.phrOtherCG;
2795    }
2796
2797    return ROK;
2798 }
2799
2800 /*******************************************************************
2801  *
2802  * @brief Builds BSR Config 
2803  *
2804  * @details
2805  *
2806  *    Function : BuildBsrConfig
2807  *
2808  *    Functionality: Builds BuildBsrConfig in MacCellGroupConfig
2809  *
2810  * @params[in] BSR_Config *bsrConfig
2811  *
2812  * @return ROK     - success
2813  *         RFAILED - failure
2814  *
2815  * ****************************************************************/
2816 uint8_t BuildBsrConfig(DuUeCb *ueCb, struct BSR_Config *bsrConfig)
2817 {
2818    if(ueCb == NULLP)
2819    {
2820       bsrConfig->periodicBSR_Timer = PERIODIC_BSR_TMR;
2821       bsrConfig->retxBSR_Timer     = RETX_BSR_TMR;
2822       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
2823    }
2824    else
2825    {
2826       bsrConfig->periodicBSR_Timer = convertBsrPeriodicTmrValueToEnum(ueCb->macUeCfg.macCellGrpCfg.bsrTmrCfg.periodicTimer);
2827       bsrConfig->retxBSR_Timer     = convertBsrRetxTmrValueToEnum(ueCb->macUeCfg.macCellGrpCfg.bsrTmrCfg.retxTimer);
2828
2829       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
2830       DU_ALLOC(bsrConfig->logicalChannelSR_DelayTimer, sizeof(long));
2831       if(bsrConfig->logicalChannelSR_DelayTimer == NULLP)
2832       {
2833          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildBsrConfig");
2834          return RFAILED;
2835       }
2836       *(bsrConfig->logicalChannelSR_DelayTimer) = convertLcSrDelayTmrValueToEnum(ueCb->macUeCfg.macCellGrpCfg.bsrTmrCfg.srDelayTimer);
2837    }
2838
2839    return ROK;
2840 }
2841
2842 /*******************************************************************
2843  *
2844  * @brief Builds scheduling request config 
2845  *
2846  * @details
2847  *
2848  *    Function : BuildSchedulingReqConfig 
2849  *
2850  *    Functionality: Builds BuildSchedulingReqConfig in MacCellGroupConfig
2851  *
2852  * @params[in] SchedulingRequestConfig *schedulingRequestConfig
2853  *
2854  * @return ROK     - success
2855  *         RFAILED - failure
2856  *
2857  * ****************************************************************/
2858 uint8_t BuildSchedulingReqConfig(DuUeCb *ueCb, struct SchedulingRequestConfig *schedulingRequestConfig)
2859 {
2860    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList;
2861    uint8_t                     idx, elementCnt;
2862
2863    schedulingRequestConfig->schedulingRequestToAddModList = NULLP;
2864    DU_ALLOC(schedulingRequestConfig->schedulingRequestToAddModList,
2865          sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));
2866    if(!schedulingRequestConfig->schedulingRequestToAddModList)
2867    {
2868       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2869       return RFAILED;
2870    }
2871
2872    if(ueCb == NULLP)
2873       elementCnt = ODU_VALUE_ONE;
2874    else
2875       elementCnt = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModListCount;
2876
2877    schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
2878    schReqList->list.count = elementCnt;
2879    schReqList->list.size  = elementCnt * sizeof(struct SchedulingRequestToAddMod *);
2880
2881    schReqList->list.array = NULLP;
2882    DU_ALLOC(schReqList->list.array, schReqList->list.size);
2883    if(!schReqList->list.array)
2884    {
2885       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2886       return RFAILED;
2887    }
2888
2889    for(idx=0; idx<schReqList->list.count; idx++)
2890    {
2891       schReqList->list.array[idx] = NULLP;
2892       DU_ALLOC(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
2893       if(!schReqList->list.array[idx])
2894       {
2895          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2896          return RFAILED;
2897       }
2898    }
2899
2900    if(ueCb == NULLP)
2901    {
2902       idx = 0;
2903       schReqList->list.array[idx]->schedulingRequestId = SCH_REQ_ID;
2904
2905       schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
2906       DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
2907       if(!schReqList->list.array[idx]->sr_ProhibitTimer)
2908       {
2909          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2910          return RFAILED;
2911       }
2912       *(schReqList->list.array[idx]->sr_ProhibitTimer) = SR_PROHIBIT_TMR;
2913       schReqList->list.array[idx]->sr_TransMax = SR_TRANS_MAX;
2914    }
2915    else
2916    {
2917       for(idx=0; idx<schReqList->list.count; idx++)
2918       {
2919          schReqList->list.array[idx]->schedulingRequestId = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].schedReqId;
2920
2921          schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
2922          DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
2923          if(!schReqList->list.array[idx]->sr_ProhibitTimer)
2924          {
2925             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2926             return RFAILED;
2927          }
2928          *(schReqList->list.array[idx]->sr_ProhibitTimer) = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srProhibitTmr;
2929          schReqList->list.array[idx]->sr_TransMax = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srTransMax;
2930       }
2931    }
2932
2933    schedulingRequestConfig->schedulingRequestToReleaseList = NULLP;
2934
2935    return ROK;
2936 }
2937
2938 /*******************************************************************
2939  *
2940  * @brief Builds RLC Configuration for AM mode
2941  *
2942  * @details
2943  *
2944  *    Function : BuildRlcConfigAm
2945  *
2946  *    Functionality: 
2947  *       Builds AM mode RLC Config in BuildRlcBearerToAddModList
2948  *
2949  * @params[in] AmBearerCfg *amCfg
2950  *             RLC_Config_t  *rlcConfig
2951  *
2952  * @return ROK     - success
2953  *         RFAILED - failure
2954  *
2955  * ****************************************************************/
2956 uint8_t BuildRlcConfigAm(AmBearerCfg *amCfg, struct RLC_Config *rlcConfig)
2957 {
2958    rlcConfig->choice.am = NULLP;
2959    DU_ALLOC(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
2960    if(!rlcConfig->choice.am)
2961    {
2962       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
2963       return RFAILED;
2964    }
2965
2966    /* Fill AM UL configuration */
2967    rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength = NULLP;
2968    DU_ALLOC(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
2969    if(!rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength)
2970    {
2971       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
2972       return RFAILED;
2973    }
2974
2975    /* Fill default AM UL configuration if input pointer to DU database is NULL */
2976    if(amCfg == NULLP)
2977    {
2978       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = SN_FIELD_LEN;
2979       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = T_POLL_RETRANSMIT;
2980       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = POLL_PDU;
2981       rlcConfig->choice.am->ul_AM_RLC.pollByte          = POLL_BYTE;
2982       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = MAX_RETX_THRESHOLD;
2983    }
2984    else
2985    {
2986       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->dlAmCfg.snLenDl);
2987       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = covertPollRetxTmrValueToEnum(amCfg->dlAmCfg.pollRetxTmr);
2988       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = covertPollPduValueToEnum(amCfg->dlAmCfg.pollPdu);
2989       rlcConfig->choice.am->ul_AM_RLC.pollByte          = covertPollByteValueToEnum(amCfg->dlAmCfg.pollByte);
2990       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = covertMaxRetxValueToEnum(amCfg->dlAmCfg.maxRetxTh);
2991    }
2992
2993    /* Fill AM DL configuraion */
2994    rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength = NULLP;
2995    DU_ALLOC(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
2996    if(!rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength)
2997    {
2998       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
2999       return RFAILED;
3000    }
3001
3002    /* Fill default AM DL configuration if input pointer to DU database is NULL */
3003    if(amCfg == NULLP)
3004    {
3005       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = SN_FIELD_LEN;
3006       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = T_REASSEMBLY;
3007       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = T_STATUS_PROHIBHIT;
3008    }
3009    else /* Fill AM configuration from DU database */
3010    {
3011       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->ulAmCfg.snLenUl);
3012       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = convertReasmblTmrValueToEnum(amCfg->ulAmCfg.reAssemTmr);
3013       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = convertProhibitTmrValueToEnum(amCfg->ulAmCfg.statProhTmr);
3014    }
3015    return ROK;
3016 }
3017
3018 /*******************************************************************
3019  *
3020  * @brief Builds RLC Config for UM Bidirection
3021  *
3022  * @details
3023  *
3024  *    Function : BuildRlcConfig UmBiDir
3025  *
3026  *    Functionality: 
3027  *       Builds RLC Config for UM Bidirection in BuildRlcBearerToAddModList 
3028  *
3029  * @params[in] UmBiDirBearerCfg *umBiDirCfg
3030  *             RLC_Config_t *rlcConfig
3031  *
3032  * @return ROK     - success
3033  *         RFAILED - failure
3034  *
3035  * ****************************************************************/
3036 uint8_t BuildRlcConfigUmBiDir(UmBiDirBearerCfg *umBiDirCfg, struct RLC_Config *rlcConfig)
3037 {
3038    rlcConfig->choice.um_Bi_Directional = NULLP;
3039    DU_ALLOC(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
3040    if(rlcConfig->choice.um_Bi_Directional == NULLP)
3041    {
3042       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3043       return RFAILED;
3044    }
3045
3046    /* Fill UM Bidirectional UL configuration */
3047    rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength = NULLP;
3048    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3049    if(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength == NULLP)
3050    {
3051       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3052       return RFAILED;
3053    }
3054
3055    if(umBiDirCfg != NULLP)
3056    {
3057       *(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->dlUmCfg.snLenDlUm);     
3058    }
3059
3060    /* Fill UM Bidirectional DL configuration */
3061    rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength = NULLP;
3062    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3063    if(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength == NULLP)
3064    {
3065       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3066       return RFAILED;
3067    }
3068
3069    if(umBiDirCfg != NULLP)
3070    {
3071       *(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->ulUmCfg.snLenUlUm);     
3072       rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umBiDirCfg->ulUmCfg.reAssemTmr);
3073    }
3074
3075    return ROK;
3076 }
3077
3078 /*******************************************************************
3079  *
3080  * @brief Builds RLC Config for UM Uni directional UL
3081  *
3082  * @details
3083  *
3084  *    Function : BuildRlcConfigUmUniDirUl
3085  *
3086  *    Functionality: 
3087  *       Builds RLC Config for UM Unidirection UL in BuildRlcBearerToAddModList 
3088  *
3089  * @params[in] UmUniDirDlBearerCfg *umUniDirDlCfg
3090  *             RLC_Config_t *rlcConfig
3091  *
3092  * @return ROK     - success
3093  *         RFAILED - failure
3094  *
3095  * ****************************************************************/
3096 uint8_t BuildRlcConfigUmUniDirUl(UmUniDirDlBearerCfg *umUniDirDlCfg, RLC_Config_t *rlcConfig)
3097 {
3098    rlcConfig->choice.um_Uni_Directional_UL = NULLP;
3099    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
3100    if(rlcConfig->choice.um_Uni_Directional_UL == NULLP)
3101    {
3102       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3103       return RFAILED;
3104    }
3105
3106    rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength = NULLP;
3107    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3108    if(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength == NULLP)
3109    {
3110       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3111       return RFAILED;
3112    }
3113
3114    if(umUniDirDlCfg != NULLP)
3115    {
3116       *(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirDlCfg->dlUmCfg.snLenDlUm);
3117    }
3118
3119    return ROK;
3120 }
3121
3122 /*******************************************************************
3123  *
3124  * @brief Builds RLC Config for UM Uni directional DL
3125  *
3126  * @details
3127  *
3128  *    Function : BuildRlcConfigUmUniDirDl
3129  *
3130  *    Functionality: 
3131  *       Builds RLC Config for UM Unidirection DL in BuildRlcBearerToAddModList 
3132  *
3133  * @params[in] UmUniDirUlBearerCfg *umUniDirUlCfg
3134  *             RLC_Config_t *rlcConfig
3135  *
3136  * @return ROK     - success
3137  *         RFAILED - failure
3138  *
3139  * ****************************************************************/
3140 uint8_t BuildRlcConfigUmUniDirDl(UmUniDirUlBearerCfg *umUniDirUlCfg, RLC_Config_t *rlcConfig)
3141 {
3142    rlcConfig->choice.um_Uni_Directional_DL = NULLP;
3143    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
3144    if(rlcConfig->choice.um_Uni_Directional_DL == NULLP)
3145    {
3146       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3147       return RFAILED;
3148    }
3149
3150    rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength = NULLP;
3151    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3152    if(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength == NULLP)
3153    {
3154       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3155       return RFAILED;
3156    }
3157
3158    if(umUniDirUlCfg != NULLP)
3159    {
3160       *(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirUlCfg->ulUmCfg.snLenUlUm);
3161       rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umUniDirUlCfg->ulUmCfg.reAssemTmr);
3162    }
3163
3164    return ROK;
3165 }
3166
3167 /*******************************************************************
3168  *
3169  * @brief Builds RLC Config
3170  *
3171  * @details
3172  *
3173  *    Function : BuildRlcConfig
3174  *
3175  *    Functionality: Builds RLC Config in BuildRlcBearerToAddModList 
3176  *
3177  * @params[in] RLC_Config_t *rlcConfig
3178  *
3179  * @return ROK     - success
3180  *         RFAILED - failure
3181  *
3182  * ****************************************************************/
3183 uint8_t BuildRlcConfig(RlcBearerCfg *rbCfg, struct RLC_Config *rlcConfig)
3184 {
3185    
3186    /* Fill default values if rbCfg is NULL */
3187    if(rbCfg == NULLP)
3188    {
3189       rlcConfig->present = RLC_Config_PR_am;
3190       BuildRlcConfigAm(NULLP, rlcConfig);
3191    }
3192    /* If RbCfg is present, fill RLC configurations from DU Database */
3193    else
3194    {
3195       rlcConfig->present = covertRlcModeFromIntEnumToRrcEnum(rbCfg->rlcMode);
3196       switch(rlcConfig->present)
3197       {
3198          case RLC_Config_PR_am:
3199             BuildRlcConfigAm(rbCfg->u.amCfg, rlcConfig);
3200             break;
3201          case RLC_Config_PR_um_Bi_Directional:
3202             BuildRlcConfigUmBiDir(rbCfg->u.umBiDirCfg, rlcConfig);
3203             break;
3204          case RLC_Config_PR_um_Uni_Directional_UL:
3205             BuildRlcConfigUmUniDirUl(rbCfg->u.umUniDirDlCfg, rlcConfig);
3206             break;
3207          case RLC_Config_PR_um_Uni_Directional_DL:
3208             BuildRlcConfigUmUniDirDl(rbCfg->u.umUniDirUlCfg, rlcConfig);
3209             break;
3210          case RLC_Config_PR_NOTHING:
3211          default:
3212             break;
3213       }
3214    }
3215
3216    return ROK;
3217 }
3218
3219 /*******************************************************************
3220  *
3221  * @brief Builds MAC LC Config
3222  *
3223  * @details
3224  *
3225  *    Function : BuildMacLCConfig 
3226  *
3227  *    Functionality: Builds MAC LC Config in BuildRlcBearerToAddModList 
3228  *
3229  * @params[in] struct LogicalChannelConfig macLcConfig
3230  *
3231  * @return ROK     - success
3232  *         RFAILED - failure
3233  *
3234  * ****************************************************************/
3235 uint8_t BuildMacLCConfig(LcCfg *lcCfgDb, struct LogicalChannelConfig *macLcConfig)
3236 {
3237    macLcConfig->ul_SpecificParameters = NULLP;
3238    DU_ALLOC(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
3239    if(!macLcConfig->ul_SpecificParameters)
3240    {
3241       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3242       return RFAILED;
3243    }
3244
3245    if(lcCfgDb == NULLP)
3246    {
3247       macLcConfig->ul_SpecificParameters->priority = MAC_LC_PRIORITY;
3248       macLcConfig->ul_SpecificParameters->prioritisedBitRate =  PRIORTISIED_BIT_RATE;
3249       macLcConfig->ul_SpecificParameters->bucketSizeDuration =  BUCKET_SIZE_DURATION;
3250    }
3251    else
3252    {
3253       macLcConfig->ul_SpecificParameters->priority = lcCfgDb->ulLcCfg.priority;
3254       macLcConfig->ul_SpecificParameters->prioritisedBitRate = lcCfgDb->ulLcCfg.pbr;
3255       macLcConfig->ul_SpecificParameters->bucketSizeDuration = lcCfgDb->ulLcCfg.bsd;
3256    }
3257
3258    macLcConfig->ul_SpecificParameters->allowedServingCells = NULLP;
3259    macLcConfig->ul_SpecificParameters->allowedSCS_List = NULLP;
3260    macLcConfig->ul_SpecificParameters->maxPUSCH_Duration = NULLP;
3261    macLcConfig->ul_SpecificParameters->configuredGrantType1Allowed = NULLP;
3262
3263    macLcConfig->ul_SpecificParameters->logicalChannelGroup = NULLP;
3264    DU_ALLOC(macLcConfig->ul_SpecificParameters->logicalChannelGroup,    sizeof(long));
3265    if(!macLcConfig->ul_SpecificParameters->logicalChannelGroup)
3266    {
3267       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3268       return RFAILED;
3269    }
3270
3271    if(lcCfgDb == NULLP)
3272       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = LC_GRP;
3273    else
3274       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = lcCfgDb->ulLcCfg.lcGroup;
3275
3276    macLcConfig->ul_SpecificParameters->schedulingRequestID = NULLP;
3277    DU_ALLOC(macLcConfig->ul_SpecificParameters->schedulingRequestID,    sizeof(SchedulingRequestId_t));
3278    if(!macLcConfig->ul_SpecificParameters->schedulingRequestID)
3279    {
3280       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3281       return RFAILED;
3282    }
3283
3284    if(lcCfgDb == NULLP)
3285       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = SCH_REQ_ID;
3286    else
3287       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = lcCfgDb->ulLcCfg.schReqId;
3288
3289    macLcConfig->ul_SpecificParameters->logicalChannelSR_Mask = false;
3290    macLcConfig->ul_SpecificParameters->logicalChannelSR_DelayTimerApplied = false;
3291    macLcConfig->ul_SpecificParameters->bitRateQueryProhibitTimer = NULLP;
3292
3293    return ROK;
3294 }
3295
3296 /*******************************************************************
3297  *
3298  * @brief Builds RLC Bearer to Add/Mod list
3299  *
3300  * @details
3301  *
3302  *    Function :BuildRlcBearerToAddModList 
3303  *
3304  *    Functionality: Builds RLC Bearer to Add/Mod list in DuToCuRrcContainer
3305  *
3306  * @params[in] rlc_BearerToAddModList
3307  *
3308  * @return ROK     - success
3309  *         RFAILED - failure
3310  *
3311  * ****************************************************************/
3312 uint8_t BuildRlcBearerToAddModList(DuUeCb *ueCb, struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList)
3313 {
3314    uint8_t  idx = 0, lcIdx=0, macLcIdx = 0, elementCnt = 0;
3315
3316    if(ueCb == NULLP)
3317       elementCnt = 1;
3318    else if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
3319       elementCnt = ueCb->rlcUeCfg.numLcs;
3320    else
3321    {
3322       for(lcIdx = 0; lcIdx<ueCb->rlcUeCfg.numLcs; lcIdx++)
3323       {
3324          if(ueCb->rlcUeCfg.rlcLcCfg[lcIdx].isLcAddModRspSent == false)
3325             elementCnt++;
3326       }
3327    }
3328    rlcBearerList->list.count = elementCnt;
3329    rlcBearerList->list.size  = elementCnt * sizeof(struct RLC_BearerConfig *);
3330
3331    rlcBearerList->list.array = NULLP;
3332    DU_ALLOC(rlcBearerList->list.array, rlcBearerList->list.size);
3333    if(!rlcBearerList->list.array)
3334    {
3335       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3336       return RFAILED;
3337    }
3338
3339    for(idx=0; idx<rlcBearerList->list.count; idx++)
3340    {
3341       rlcBearerList->list.array[idx] = NULLP;
3342       DU_ALLOC(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
3343       if(!rlcBearerList->list.array[idx])
3344       {
3345          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3346          return RFAILED;
3347       }
3348    }
3349
3350    if(ueCb == NULLP)
3351    {
3352       idx=0;
3353       rlcBearerList->list.array[idx]->logicalChannelIdentity = SRB1_LCID;
3354       DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3355       if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3356       {     
3357          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3358          return RFAILED;
3359       }     
3360       rlcBearerList->list.array[idx]->servedRadioBearer->present = RLC_BearerConfig__servedRadioBearer_PR_srb_Identity;
3361       rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = SRB1_LCID;
3362       rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3363
3364       /* Fill RLC related Configurations for this Radio Bearer */
3365       rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3366       DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3367       if(!rlcBearerList->list.array[idx]->rlc_Config)
3368       {
3369          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3370          return RFAILED;
3371       }
3372       if(BuildRlcConfig(NULLP, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3373       {
3374          DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3375          return RFAILED;
3376       }
3377
3378       /* Fill MAC related configurations for this Radio Bearer */
3379       rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3380       DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3381       if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3382       {
3383          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3384          return RFAILED;
3385       }
3386       if(BuildMacLCConfig(NULLP, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3387       {
3388          DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3389          return RFAILED;
3390       }
3391    }
3392    else
3393    {
3394       idx=0;
3395       for(lcIdx=0; lcIdx<ueCb->rlcUeCfg.numLcs; lcIdx++)
3396       {
3397          if((ueCb->f1UeDb->actionType != UE_CTXT_CFG_QUERY) && (ueCb->rlcUeCfg.rlcLcCfg[lcIdx].isLcAddModRspSent == true))
3398             continue;
3399
3400          /* Fill Logical channel identity */
3401          rlcBearerList->list.array[idx]->logicalChannelIdentity = ueCb->rlcUeCfg.rlcLcCfg[lcIdx].lcId;
3402
3403          /* Fill Radio Bearer Id and type (DRB/SRB) for this logical channel */
3404          DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3405          if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3406          {
3407             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3408             return RFAILED;
3409          }
3410          rlcBearerList->list.array[idx]->servedRadioBearer->present = \
3411                                                                       covertRbTypeFromIntEnumToRrcEnum(ueCb->rlcUeCfg.rlcLcCfg[lcIdx].rbType);
3412          switch(rlcBearerList->list.array[idx]->servedRadioBearer->present)
3413          {
3414             case RLC_BearerConfig__servedRadioBearer_PR_srb_Identity: 
3415                rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = ueCb->rlcUeCfg.rlcLcCfg[lcIdx].rbId;
3416                break;
3417             case RLC_BearerConfig__servedRadioBearer_PR_drb_Identity:
3418                rlcBearerList->list.array[idx]->servedRadioBearer->choice.drb_Identity = ueCb->rlcUeCfg.rlcLcCfg[lcIdx].rbId;
3419                break;
3420             case RLC_BearerConfig__servedRadioBearer_PR_NOTHING:
3421             default:
3422                break;
3423          }
3424          ueCb->rlcUeCfg.rlcLcCfg[lcIdx].isLcAddModRspSent = true;
3425
3426          rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3427
3428          /* Fill RLC related Configurations for this Radio Bearer */
3429          rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3430          DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3431          if(!rlcBearerList->list.array[idx]->rlc_Config)
3432          {
3433             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3434             return RFAILED;
3435          }
3436          if(BuildRlcConfig(&ueCb->rlcUeCfg.rlcLcCfg[lcIdx], rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3437          {
3438             DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3439             return RFAILED;
3440          }
3441
3442          /* Fill MAC related configurations for this Radio Bearer */
3443          rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3444          DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3445          if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3446          {
3447             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3448             return RFAILED;
3449          }
3450          for(macLcIdx = 0; macLcIdx < ueCb->macUeCfg.numLcs; macLcIdx++)
3451          {
3452             if(ueCb->macUeCfg.lcCfgList[macLcIdx].lcId == ueCb->rlcUeCfg.rlcLcCfg[lcIdx].lcId)
3453             {
3454                if(BuildMacLCConfig(&ueCb->macUeCfg.lcCfgList[macLcIdx], rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3455                {
3456                   DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3457                   return RFAILED;
3458                }
3459                break;
3460             }
3461          }
3462
3463          idx++;
3464       }
3465    }
3466    return ROK;
3467 }
3468
3469 /*******************************************************************
3470  *
3471  * @brief Build Control resource set to add/modify list 
3472  *
3473  * @details
3474  *
3475  *    Function : BuildControlRSetToAddModList
3476  *
3477  *    Functionality: Build Control resource set to add/modify list
3478  *
3479  * @params[in] 
3480  * struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList
3481  *
3482  * @return ROK     - success
3483  *         RFAILED - failure
3484  *
3485  * ****************************************************************/
3486 uint8_t BuildControlRSetToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList)
3487 {
3488    uint8_t idx;
3489    uint8_t elementCnt;
3490    uint8_t numBytes, bitsUnused;
3491    struct ControlResourceSet *controlRSet;
3492    uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
3493    uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
3494
3495    if(pdcchCfg == NULLP)
3496       elementCnt = 1;
3497    else
3498       elementCnt = pdcchCfg->numCRsetToAddMod;
3499
3500    controlRSetList->list.count = elementCnt;
3501    controlRSetList->list.size = elementCnt * sizeof(struct ControlResourceSet *);
3502
3503    controlRSetList->list.array = NULLP;
3504    DU_ALLOC(controlRSetList->list.array, controlRSetList->list.size);
3505    if(!controlRSetList->list.array)
3506    {
3507       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3508       return RFAILED;
3509    }
3510
3511    for(idx = 0; idx < elementCnt; idx++)
3512    {
3513       controlRSetList->list.array[idx] = NULLP;
3514       DU_ALLOC(controlRSetList->list.array[idx], sizeof(struct ControlResourceSet));
3515       if(!controlRSetList->list.array[idx])
3516       {
3517          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3518          return RFAILED;
3519       }
3520    }
3521
3522    for(idx = 0; idx < elementCnt; idx++)
3523    {
3524       controlRSet = controlRSetList->list.array[idx];
3525
3526       if(pdcchCfg == NULLP)
3527          controlRSet->controlResourceSetId = PDCCH_CTRL_RSRC_SET_ONE_ID;
3528       else
3529          controlRSet->controlResourceSetId = pdcchCfg->cRSetToAddModList[idx].cRSetId;
3530
3531       /* size 6 bytes
3532        * 3 LSBs unsued
3533        * Bit string stored ff0000000000
3534        */
3535       numBytes = 6;
3536       bitsUnused = 3;
3537       controlRSet->frequencyDomainResources.size = numBytes * sizeof(uint8_t);
3538
3539       controlRSet->frequencyDomainResources.buf = NULLP;
3540       DU_ALLOC(controlRSet->frequencyDomainResources.buf, controlRSet->frequencyDomainResources.size);
3541       if(!controlRSet->frequencyDomainResources.buf)
3542       {
3543          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3544          return RFAILED;
3545       }
3546
3547       memset(controlRSet->frequencyDomainResources.buf, 0, FREQ_DOM_RSRC_SIZE);
3548
3549       if(pdcchCfg == NULLP)
3550       {
3551          coreset0EndPrb = CORESET0_END_PRB;
3552          coreset1StartPrb = coreset0EndPrb + 6;
3553          coreset1NumPrb = CORESET1_NUM_PRB;
3554          /* calculate the PRBs */
3555          fillCoresetFeqDomAllocMap(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
3556          memcpy(controlRSet->frequencyDomainResources.buf, freqDomainResource, FREQ_DOM_RSRC_SIZE);
3557          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3558
3559          controlRSet->duration = PDCCH_CTRL_RSRC_SET_ONE_DURATION;
3560          controlRSet->cce_REG_MappingType.present = ControlResourceSet__cce_REG_MappingType_PR_nonInterleaved;
3561          controlRSet->precoderGranularity = PDCCH_CTRL_RSRC_SET_ONE_PRECOD_GRANULARITY;
3562       }
3563       else
3564       {
3565          memcpy(controlRSet->frequencyDomainResources.buf, pdcchCfg->cRSetToAddModList[idx].freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
3566          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3567          controlRSet->duration = pdcchCfg->cRSetToAddModList[idx].duration;
3568          controlRSet->cce_REG_MappingType.present = pdcchCfg->cRSetToAddModList[idx].cceRegMappingType;
3569          controlRSet->precoderGranularity = pdcchCfg->cRSetToAddModList[idx].precoderGranularity;
3570       }
3571       controlRSet->tci_StatesPDCCH_ToAddList = NULLP;
3572       controlRSet->tci_StatesPDCCH_ToReleaseList = NULLP;
3573       controlRSet->tci_PresentInDCI = NULLP;
3574
3575 #if 0
3576       uint8_t tciStateIdx;
3577
3578       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList, \
3579             sizeof(struct ControlResourceSet__tci_StatesPDCCH_ToAddList));
3580       if(!controlRset->tci_StatesPDCCH_ToAddList)
3581       {
3582          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3583          return RFAILED;
3584       }
3585
3586       elementCnt = 1;
3587       controlRset->tci_StatesPDCCH_ToAddList->list.count = elementCnt;
3588       controlRset->tci_StatesPDCCH_ToAddList->list.size = elementCnt * sizeof(TCI_StateId_t *);
3589       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array, \
3590             controlRset->tci_StatesPDCCH_ToAddList->list.size)
3591          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array)
3592          {
3593             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3594             return RFAILED;
3595          }
3596
3597       for(tciStateIdx = 0; tciStateIdx <elementCntl; tciStateIdx++)
3598       {
3599          DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx], sizeof(TCI_StateId_t));
3600          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx])
3601          {
3602             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3603             return RFAILED;
3604          }
3605       }
3606
3607       tciStateIdx = 0;
3608       /* TODO */
3609       *(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx]);
3610
3611       DU_ALLOC(controlRset->tci_PresentInDCI, sizeof(long));
3612       if(!controlRset->tci_PresentInDCI)
3613       {
3614          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3615          return RFAILED;
3616       }
3617       /* TODO */
3618       *(controlRset->tci_PresentInDCI);
3619 #endif
3620
3621       controlRSet->pdcch_DMRS_ScramblingID = NULLP;
3622       DU_ALLOC(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
3623       if(!controlRSet->pdcch_DMRS_ScramblingID)
3624       {
3625          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3626          return RFAILED;
3627       }
3628       if(pdcchCfg == NULLP)
3629          *(controlRSet->pdcch_DMRS_ScramblingID) = SCRAMBLING_ID;
3630       else
3631          *(controlRSet->pdcch_DMRS_ScramblingID) = pdcchCfg->cRSetToAddModList[idx].dmrsScramblingId;
3632    }
3633    return ROK;
3634 } /* End BuildControlRSetToAddModList */
3635
3636 /*******************************************************************
3637  *
3638  * @brief Build search space to add/modify list
3639  *
3640  * @details
3641  *
3642  *    Function : BuildSearchSpcToAddModList
3643  *
3644  *    Functionality: Build search space to add/modify list
3645  *
3646  * @params[in] 
3647  * @return ROK     - success
3648  *         RFAILED - failure
3649  *
3650  * ****************************************************************/
3651 uint8_t BuildSearchSpcToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
3652 {
3653    uint8_t idx;
3654    uint8_t numBytes;
3655    uint8_t byteIdx;
3656    uint8_t bitsUnused;
3657    uint8_t elementCnt;
3658    struct SearchSpace *searchSpc;
3659
3660    if(pdcchCfg == NULLP)
3661       elementCnt = 1;
3662    else
3663       elementCnt = pdcchCfg->numSearchSpcToAddMod;
3664
3665    searchSpcList->list.count = elementCnt;
3666    searchSpcList->list.size = elementCnt * sizeof(struct SearchSpace *);
3667
3668    searchSpcList->list.array = NULLP;
3669    DU_ALLOC(searchSpcList->list.array, searchSpcList->list.size);
3670    if(!searchSpcList->list.array)
3671    {
3672       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3673       return RFAILED;
3674    }
3675
3676    for(idx = 0; idx < elementCnt; idx++)
3677    {
3678       searchSpcList->list.array[idx] = NULLP;
3679       DU_ALLOC(searchSpcList->list.array[idx], sizeof(struct SearchSpace));
3680       if(!searchSpcList->list.array[idx])
3681       {
3682          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3683          return RFAILED;
3684       }
3685    }
3686
3687    for(idx = 0; idx < elementCnt; idx++)
3688    {
3689       searchSpc = searchSpcList->list.array[idx];
3690
3691       if(pdcchCfg == NULLP)
3692          searchSpc->searchSpaceId = PDCCH_SRCH_SPC_TWO_ID;
3693       else
3694          searchSpc->searchSpaceId = pdcchCfg->searchSpcToAddModList[idx].searchSpaceId;
3695
3696       searchSpc->controlResourceSetId = NULLP;
3697       DU_ALLOC(searchSpc->controlResourceSetId, sizeof(ControlResourceSetId_t));
3698       if(!searchSpc->controlResourceSetId)
3699       {
3700          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3701          return RFAILED;
3702       }
3703       if(pdcchCfg == NULLP)
3704          *(searchSpc->controlResourceSetId) = PDCCH_CTRL_RSRC_SET_ONE_ID;
3705       else
3706          *(searchSpc->controlResourceSetId) = pdcchCfg->searchSpcToAddModList[idx].cRSetId;
3707
3708       searchSpc->monitoringSlotPeriodicityAndOffset = NULLP;
3709       DU_ALLOC(searchSpc->monitoringSlotPeriodicityAndOffset, sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
3710       if(!searchSpc->monitoringSlotPeriodicityAndOffset)
3711       {
3712          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3713          return RFAILED;
3714       }
3715       if(pdcchCfg == NULLP)
3716          searchSpc->monitoringSlotPeriodicityAndOffset->present = SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
3717       else
3718          searchSpc->monitoringSlotPeriodicityAndOffset->present = pdcchCfg->searchSpcToAddModList[idx].mSlotPeriodicityAndOffset;
3719
3720       searchSpc->duration = NULLP;
3721       searchSpc->monitoringSymbolsWithinSlot = NULLP;
3722       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot, sizeof(BIT_STRING_t));
3723       if(!searchSpc->monitoringSymbolsWithinSlot)
3724       {
3725          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3726          return RFAILED;
3727       }
3728
3729       /* Values taken from reference logs :
3730        * size 2 bytes
3731        * 2 LSBs unsued
3732        * Bit string stores 8000
3733        */
3734       numBytes = 2;
3735       bitsUnused = 2;
3736       searchSpc->monitoringSymbolsWithinSlot->size = numBytes * sizeof(uint8_t);
3737       searchSpc->monitoringSymbolsWithinSlot->buf = NULLP;
3738       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot->buf, searchSpc->monitoringSymbolsWithinSlot->size);
3739       if(!searchSpc->monitoringSymbolsWithinSlot->buf)
3740       {
3741          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3742          return RFAILED;
3743       }
3744       if(pdcchCfg == NULLP)
3745       {
3746          byteIdx = 0;
3747          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = PDCCH_SYMBOL_WITHIN_SLOT /* setting MSB to 128 i.e. 0x80 */;
3748          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = 0;
3749       }
3750       else
3751          memcpy(searchSpc->monitoringSymbolsWithinSlot->buf, pdcchCfg->searchSpcToAddModList[idx].mSymbolsWithinSlot, numBytes);
3752       searchSpc->monitoringSymbolsWithinSlot->bits_unused = bitsUnused;
3753
3754       searchSpc->nrofCandidates = NULLP;
3755       DU_ALLOC(searchSpc->nrofCandidates, sizeof(struct SearchSpace__nrofCandidates));
3756       if(!searchSpc->nrofCandidates)
3757       {
3758          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3759          return RFAILED;
3760       }
3761
3762       if(pdcchCfg == NULLP)
3763       {
3764          searchSpc->nrofCandidates->aggregationLevel1 = PDCCH_SRCH_SPC_TWO_AGG_LVL1_CANDIDATE;
3765          searchSpc->nrofCandidates->aggregationLevel2 = PDCCH_SRCH_SPC_TWO_AGG_LVL2_CANDIDATE;
3766          searchSpc->nrofCandidates->aggregationLevel4 = PDCCH_SRCH_SPC_TWO_AGG_LVL4_CANDIDATE;
3767          searchSpc->nrofCandidates->aggregationLevel8 = PDCCH_SRCH_SPC_TWO_AGG_LVL8_CANDIDATE;
3768          searchSpc->nrofCandidates->aggregationLevel16 = PDCCH_SRCH_SPC_TWO_AGG_LVL16_CANDIDATE;
3769       }
3770       else
3771       {
3772          searchSpc->nrofCandidates->aggregationLevel1 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel1;
3773          searchSpc->nrofCandidates->aggregationLevel2 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel2;
3774          searchSpc->nrofCandidates->aggregationLevel4 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel4;
3775          searchSpc->nrofCandidates->aggregationLevel8 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel8;
3776          searchSpc->nrofCandidates->aggregationLevel16 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel16;
3777       }
3778
3779       searchSpc->searchSpaceType = NULLP;
3780       DU_ALLOC(searchSpc->searchSpaceType, sizeof(struct SearchSpace__searchSpaceType));
3781       if(!searchSpc->searchSpaceType)
3782       {
3783          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3784          return RFAILED;
3785       }
3786       if(pdcchCfg == NULLP)
3787          searchSpc->searchSpaceType->present = SearchSpace__searchSpaceType_PR_ue_Specific;
3788       else
3789          searchSpc->searchSpaceType->present = pdcchCfg->searchSpcToAddModList[idx].searchSpaceType;
3790
3791       searchSpc->searchSpaceType->choice.ue_Specific = NULLP;
3792       DU_ALLOC(searchSpc->searchSpaceType->choice.ue_Specific, sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
3793       if(!searchSpc->searchSpaceType->choice.ue_Specific)
3794       {
3795          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3796          return RFAILED;
3797       }  
3798       if(pdcchCfg == NULLP)
3799          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
3800       else
3801          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = pdcchCfg->searchSpcToAddModList[idx].ueSpecificDciFormat;
3802    }
3803    return ROK;
3804 }/* End BuildSearchSpcToAddModList */
3805
3806 /*******************************************************************
3807  *
3808  * @brief Builds BWP DL dedicated PDCCH config
3809  *
3810  * @details
3811  *
3812  *    Function : BuildBWPDlDedPdcchCfg
3813  *
3814  *    Functionality: Builds BWP DL dedicated PDCCH config
3815  *
3816  * @params[in] struct PDCCH_Config *pdcchCfg
3817  *
3818  * @return ROK     - success
3819  *         RFAILED - failure
3820  *
3821  * ****************************************************************/
3822 uint8_t BuildBWPDlDedPdcchCfg(PdcchConfig *pdcchCfgDb, struct PDCCH_Config *pdcchCfg)
3823 {
3824    pdcchCfg->controlResourceSetToAddModList = NULLP;
3825    DU_ALLOC(pdcchCfg->controlResourceSetToAddModList, sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
3826    if(!pdcchCfg->controlResourceSetToAddModList)
3827    {
3828       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
3829       return RFAILED;
3830    }
3831
3832    if(BuildControlRSetToAddModList(pdcchCfgDb, pdcchCfg->controlResourceSetToAddModList) != ROK)
3833    {
3834       DU_LOG("\nERROR  --> F1AP : Failed in BuildControlRSetToAddModList()");
3835       return RFAILED;
3836    }
3837
3838    pdcchCfg->controlResourceSetToReleaseList = NULLP;
3839
3840    pdcchCfg->searchSpacesToAddModList = NULLP;
3841    DU_ALLOC(pdcchCfg->searchSpacesToAddModList, sizeof(struct PDCCH_Config__searchSpacesToAddModList));
3842    if(!pdcchCfg->searchSpacesToAddModList)
3843    {
3844       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
3845       return RFAILED;
3846    }
3847
3848    if(BuildSearchSpcToAddModList(pdcchCfgDb, pdcchCfg->searchSpacesToAddModList) != ROK)
3849    {
3850       DU_LOG("\nERROR  --> F1AP : Failed in BuildSearchSpcToAddModList()");
3851       return RFAILED;
3852    }
3853
3854    pdcchCfg->searchSpacesToReleaseList = NULLP;
3855    pdcchCfg->downlinkPreemption = NULLP;
3856    pdcchCfg->tpc_PUSCH = NULLP;
3857    pdcchCfg->tpc_PUCCH = NULLP;
3858    pdcchCfg->tpc_SRS = NULLP;
3859
3860    return ROK;
3861 }
3862
3863 /*******************************************************************
3864  *
3865  * @brief Builds DMRS DL PDSCH Mapping type A
3866  *
3867  * @details
3868  *
3869  *    Function : BuildDMRSDLPdschMapTypeA
3870  *
3871  *    Functionality: Builds DMRS DL PDSCH Mapping type A
3872  *
3873  * @params[in]
3874  * struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg
3875  * @return ROK     - success
3876  *         RFAILED - failure
3877  *
3878  * ****************************************************************/
3879 uint8_t BuildDMRSDLPdschMapTypeA(PdschConfig *pdschCfg, struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg)
3880 {
3881    dmrsDlCfg->present = PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup;
3882    dmrsDlCfg->choice.setup = NULLP;
3883    DU_ALLOC(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
3884    if(!dmrsDlCfg->choice.setup)
3885    {
3886       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
3887       return RFAILED;
3888    }
3889
3890    dmrsDlCfg->choice.setup->dmrs_Type = NULLP;
3891    dmrsDlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
3892    DU_ALLOC(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
3893    if(!dmrsDlCfg->choice.setup->dmrs_AdditionalPosition)
3894    {
3895       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
3896       return RFAILED;
3897    }
3898    if(pdschCfg == NULLP)
3899       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS;
3900    else
3901       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = pdschCfg->dmrsDlCfgForPdschMapTypeA.addPos;
3902
3903    dmrsDlCfg->choice.setup->maxLength = NULLP;
3904    dmrsDlCfg->choice.setup->scramblingID0 = NULLP;
3905    dmrsDlCfg->choice.setup->scramblingID1 = NULLP;
3906    dmrsDlCfg->choice.setup->phaseTrackingRS = NULLP;
3907
3908    return ROK;
3909 }
3910
3911 /*******************************************************************
3912  *
3913  * @brief Builds TCI states to add/modify list
3914  *
3915  * @details
3916  *
3917  *    Function : BuildTCIStatesToAddModList
3918  *
3919  *    Functionality:Builds TCI states to add/modify list
3920  *
3921  * @params[in] 
3922  * struct PDSCH_Config__tci_StatesToAddModList *tciStatesList
3923  *
3924  * @return ROK     - success
3925  *         RFAILED - failure
3926  *
3927  * ****************************************************************/
3928 uint8_t BuildTCIStatesToAddModList(struct PDSCH_Config__tci_StatesToAddModList *tciStatesList)
3929 {
3930    return ROK;
3931 }
3932
3933 /*******************************************************************
3934  *
3935  * @brief Builds PDSCH time domain allocation list
3936  *
3937  * @details
3938  *
3939  *    Function : BuildPdschTimeDomAllocList
3940  *
3941  *    Functionality: Builds PDSCH time domain allocation list
3942  *
3943  * @params[in] 
3944  * struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
3945  *
3946  * @return ROK     - success
3947  *         RFAILED - failure
3948  *
3949  * ****************************************************************/
3950 uint8_t BuildPdschTimeDomAllocList(PdschConfig *pdschCfg, struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
3951 {
3952    uint8_t idx;
3953    uint8_t elementCnt;
3954    struct PDSCH_TimeDomainResourceAllocation *timeDomAlloc;
3955
3956    timeDomAllocList->present = PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup;
3957
3958    timeDomAllocList->choice.setup = NULLP;
3959    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PDSCH_TimeDomainResourceAllocationList));
3960    if(!timeDomAllocList->choice.setup)
3961    {
3962       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
3963       return RFAILED;
3964    }
3965
3966 if(pdschCfg == NULLP)
3967    elementCnt = 2;
3968 else
3969 elementCnt = pdschCfg->numTimeDomRsrcAlloc;
3970    timeDomAllocList->choice.setup->list.count = elementCnt;
3971    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(struct PDSCH_TimeDomainResourceAllocation *);
3972
3973    timeDomAllocList->choice.setup->list.array = NULLP;
3974    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
3975    if(!timeDomAllocList->choice.setup->list.array)
3976    {
3977       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
3978       return RFAILED;
3979    }
3980
3981    for(idx = 0; idx < elementCnt; idx++)
3982    {
3983       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
3984       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], \
3985             sizeof(struct PDSCH_TimeDomainResourceAllocation));
3986       if(!timeDomAllocList->choice.setup->list.array[idx])
3987       {
3988          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
3989          return RFAILED;
3990       }
3991    }
3992
3993    if(pdschCfg == NULLP)
3994    {
3995       idx = 0;
3996       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
3997       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
3998       if(!timeDomAlloc->k0)
3999       {
4000          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4001          return RFAILED;
4002       }
4003       *(timeDomAlloc->k0) = 0;
4004       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4005       timeDomAlloc->startSymbolAndLength = \
4006                                            calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4007
4008       idx++;
4009       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4010       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4011       if(!timeDomAlloc->k0)
4012       {
4013          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4014          return RFAILED;
4015       }
4016       *(timeDomAlloc->k0) = 1;
4017       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4018       timeDomAlloc->startSymbolAndLength = calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4019    }
4020    else
4021    {
4022       for(idx = 0; idx < elementCnt; idx++)
4023       {
4024          timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4025          DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4026          if(!timeDomAlloc->k0)
4027          {
4028             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4029             return RFAILED;
4030          }
4031          if(pdschCfg->timeDomRsrcAllociList[idx].k0)
4032             *(timeDomAlloc->k0) = *(pdschCfg->timeDomRsrcAllociList[idx].k0);
4033          timeDomAlloc->mappingType = pdschCfg->timeDomRsrcAllociList[idx].mappingType;
4034          timeDomAlloc->startSymbolAndLength = pdschCfg->timeDomRsrcAllociList[idx].startSymbolAndLength;
4035       }
4036    }
4037
4038    return ROK;
4039 }
4040
4041 /*******************************************************************
4042  *
4043  * @brief Builds PDSCH PRB Bundling type
4044  *
4045  * @details
4046  *
4047  *    Function : BuildPdschPrbBundlingType
4048  *
4049  *    Functionality: Builds PDSCH PRB Bundling type
4050  *
4051  * @params[in] 
4052  * struct PDSCH_Config__prb_BundlingType *prbBndlType
4053  *
4054  * @return ROK     - success
4055  *         RFAILED - failure
4056  *
4057  * ****************************************************************/
4058 uint8_t BuildPdschPrbBundlingType(PdschConfig *pdschCfg, struct PDSCH_Config__prb_BundlingType *prbBndlType)
4059 {
4060    if(pdschCfg == NULLP)
4061       prbBndlType->present = PDSCH_Config__prb_BundlingType_PR_staticBundling;
4062    else
4063       prbBndlType->present = pdschCfg->bundlingType;
4064
4065    prbBndlType->choice.staticBundling = NULLP;
4066    DU_ALLOC(prbBndlType->choice.staticBundling, \
4067          sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
4068    if(!prbBndlType->choice.staticBundling)
4069    {
4070       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschPrbBundlingType");
4071       return RFAILED;
4072    }
4073    prbBndlType->choice.staticBundling->bundleSize = NULLP;
4074
4075    return ROK;
4076 }
4077
4078 /*******************************************************************
4079  *
4080  * @brief Builds BWP DL dedicated PDSCH config 
4081  *
4082  * @details
4083  *
4084  *    Function : BuildBWPDlDedPdschCfg
4085  *
4086  *    Functionality: Builds BWP DL dedicated PDSCH config
4087  *
4088  * @params[in] struct PDSCH_Config *pdschCfg
4089  *
4090  * @return ROK     - success
4091  *         RFAILED - failure
4092  *
4093  * ****************************************************************/
4094 uint8_t BuildBWPDlDedPdschCfg(PdschConfig *pdschCfgDb, struct PDSCH_Config *pdschCfg)
4095 {
4096    pdschCfg->dataScramblingIdentityPDSCH = NULLP;
4097
4098    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA = NULLP;
4099    DU_ALLOC(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
4100    if(!pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
4101    {
4102       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4103       return RFAILED;
4104    }
4105
4106    if(BuildDMRSDLPdschMapTypeA(pdschCfgDb, pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA) != ROK)
4107    {
4108       return RFAILED;
4109    }
4110
4111    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeB = NULLP;
4112    pdschCfg->tci_StatesToAddModList = NULLP;
4113    pdschCfg->tci_StatesToReleaseList = NULLP;
4114    pdschCfg->vrb_ToPRB_Interleaver = NULLP;
4115 #if 0
4116    DU_ALLOC(pdschCfg->tci_StatesToAddModList, sizeof(struct PDSCH_Config__tci_StatesToAddModList));
4117    if(!pdschCfg->tci_StatesToAddModList)
4118    {
4119       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4120       return RFAILED;
4121    }
4122    if(BuildTCIStatesToAddModList(pdschCfg->tci_StatesToAddModList) != ROK)
4123    {
4124       return RFAILED;
4125    }
4126 #endif
4127
4128 if(pdschCfgDb == NULLP)
4129    pdschCfg->resourceAllocation = RES_ALLOC_TYPE;
4130 else
4131 pdschCfg->resourceAllocation = pdschCfgDb->resourceAllocType;
4132
4133    pdschCfg->pdsch_TimeDomainAllocationList = NULLP;
4134    DU_ALLOC(pdschCfg->pdsch_TimeDomainAllocationList, sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
4135    if(!pdschCfg->pdsch_TimeDomainAllocationList)
4136    {
4137       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4138       return RFAILED;
4139    }
4140    if(BuildPdschTimeDomAllocList(pdschCfgDb, pdschCfg->pdsch_TimeDomainAllocationList) != ROK)
4141    {
4142       return RFAILED;
4143    }
4144
4145    pdschCfg->pdsch_AggregationFactor = NULLP;
4146    pdschCfg->rateMatchPatternToAddModList = NULLP;
4147    pdschCfg->rateMatchPatternToReleaseList = NULLP;
4148    pdschCfg->rateMatchPatternGroup1 = NULLP;
4149    pdschCfg->rateMatchPatternGroup2 = NULLP;
4150    if(pdschCfgDb == NULLP)
4151       pdschCfg->rbg_Size = PDSCH_RBG_SIZE;
4152    else
4153       pdschCfg->rbg_Size = pdschCfgDb->rbgSize;
4154    pdschCfg->mcs_Table = NULLP;
4155
4156    pdschCfg->maxNrofCodeWordsScheduledByDCI = NULLP;
4157    DU_ALLOC(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
4158    if(!pdschCfg->maxNrofCodeWordsScheduledByDCI)
4159    {
4160       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4161       return RFAILED;
4162    }
4163    if(pdschCfgDb == NULLP)
4164       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = PDSCH_MAX_CODEWORD_SCH_BY_DCI;
4165    else
4166       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = pdschCfgDb->numCodeWordsSchByDci;
4167
4168    if(BuildPdschPrbBundlingType(pdschCfgDb, &pdschCfg->prb_BundlingType) != ROK)
4169    {
4170       return RFAILED;
4171    }
4172
4173    pdschCfg->zp_CSI_RS_ResourceToAddModList = NULLP;
4174    pdschCfg->zp_CSI_RS_ResourceToReleaseList = NULLP;
4175    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4176    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4177    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4178    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4179    pdschCfg->p_ZP_CSI_RS_ResourceSet = NULLP;
4180
4181    return ROK;
4182 }
4183
4184 /*******************************************************************
4185  *
4186  * @brief Builds intitial DL BWP
4187  * @details
4188  *
4189  *    Function : BuildInitialDlBWP 
4190  *
4191  *    Functionality: Builds intitial DL BWP in spCellCfgDed
4192  *
4193  * @params[in] BWP_DownlinkDedicated_t *dlBwp
4194  *
4195  * @return ROK     - success
4196  *         RFAILED - failure
4197  *
4198  * ****************************************************************/
4199 uint8_t BuildInitialDlBWP(InitialDlBwp *initiDlBwp, BWP_DownlinkDedicated_t *dlBwp)
4200 {
4201    PdcchConfig *pdcchCfg = NULLP;
4202    PdschConfig *pdschCfg = NULLP;
4203
4204    if(initiDlBwp)
4205    {
4206       if(initiDlBwp->pdcchPresent)
4207          pdcchCfg = &initiDlBwp->pdcchCfg;
4208       if(initiDlBwp->pdschPresent)
4209          pdschCfg = &initiDlBwp->pdschCfg;
4210    }
4211
4212    dlBwp->pdcch_Config = NULLP;
4213    DU_ALLOC(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
4214    if(!dlBwp->pdcch_Config)
4215    {
4216       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4217       return RFAILED;
4218    }
4219    dlBwp->pdcch_Config->present = BWP_DownlinkDedicated__pdcch_Config_PR_setup; 
4220
4221    dlBwp->pdcch_Config->choice.setup = NULLP;
4222    DU_ALLOC(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
4223    if(!dlBwp->pdcch_Config->choice.setup)
4224    {
4225       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4226       return RFAILED;
4227    }
4228    if(BuildBWPDlDedPdcchCfg(pdcchCfg, dlBwp->pdcch_Config->choice.setup) != ROK)
4229    {
4230       return RFAILED;
4231    }
4232
4233    dlBwp->pdsch_Config = NULLP;
4234    DU_ALLOC(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
4235    if(!dlBwp->pdsch_Config)
4236    {
4237       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4238       return RFAILED;
4239    }
4240    dlBwp->pdsch_Config->present = BWP_DownlinkDedicated__pdsch_Config_PR_setup;
4241
4242    dlBwp->pdsch_Config->choice.setup = NULLP;
4243    DU_ALLOC(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
4244    if(!dlBwp->pdsch_Config->choice.setup)
4245    {
4246       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4247       return RFAILED;
4248    }
4249
4250    if(BuildBWPDlDedPdschCfg(pdschCfg, dlBwp->pdsch_Config->choice.setup) != ROK)
4251    {
4252       return RFAILED;
4253    }
4254
4255    dlBwp->sps_Config = NULLP;
4256    dlBwp->radioLinkMonitoringConfig = NULLP; 
4257    return ROK;
4258 }
4259
4260 /*******************************************************************
4261  *
4262  * @brief Builds DMRS UL Pusch Mapping type A
4263  *
4264  * @details
4265  *
4266  *    Function : BuildDMRSULPuschMapTypeA
4267  *
4268  *    Functionality: Builds DMRS UL Pusch Mapping type A
4269  *
4270  * @params[in] 
4271  *    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg
4272  * @return ROK     - success
4273  *         RFAILED - failure
4274  *
4275  * ****************************************************************/
4276 uint8_t BuildDMRSULPuschMapTypeA(DmrsUlCfg *ulDmrsCfgDb, struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg)
4277 {
4278    dmrsUlCfg->present = PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup;
4279    dmrsUlCfg->choice.setup= NULLP;
4280    DU_ALLOC(dmrsUlCfg->choice.setup, sizeof(DMRS_UplinkConfig_t));
4281    if(!dmrsUlCfg->choice.setup)
4282    {
4283       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4284       return RFAILED;
4285    }
4286
4287    dmrsUlCfg->choice.setup->dmrs_Type = NULLP;
4288    dmrsUlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4289    DU_ALLOC(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4290    if(!dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
4291    {
4292       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4293       return RFAILED;
4294    }
4295    if(ulDmrsCfgDb == NULLP)
4296       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS; 
4297    else
4298       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = ulDmrsCfgDb->addPos;
4299
4300    dmrsUlCfg->choice.setup->phaseTrackingRS = NULLP;
4301    dmrsUlCfg->choice.setup->maxLength = NULLP;
4302    dmrsUlCfg->choice.setup->transformPrecodingDisabled = NULLP;
4303    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled, sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
4304    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled)
4305    {
4306       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4307       return RFAILED;
4308    }
4309
4310    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0 = NULLP;
4311    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
4312          sizeof(long));
4313    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0)
4314    {
4315       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4316       return RFAILED;
4317    }
4318    if(ulDmrsCfgDb == NULLP)
4319       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = SCRAMBLING_ID;
4320    else
4321       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = ulDmrsCfgDb->transPrecodDisabled.scramblingId0;
4322
4323    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID1 = NULLP;
4324    dmrsUlCfg->choice.setup->transformPrecodingEnabled = NULLP;
4325    return ROK;
4326 }
4327
4328 /*******************************************************************
4329  *
4330  * @brief Build PUSCH time domain allocation list
4331  *
4332  * @details
4333  *
4334  *    Function : BuildPuschTimeDomAllocList
4335  *
4336  *    Functionality: Build PUSCH time domain allocation list
4337  *
4338  * @params[in] 
4339  * struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList
4340  *
4341  * @return ROK     - success
4342  *         RFAILED - failure
4343  *
4344  * ****************************************************************/
4345 uint8_t BuildPuschTimeDomAllocList(PuschCfg *puschCfgDb, struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList)
4346 {
4347    uint8_t idx;
4348    uint8_t elementCnt;
4349    PUSCH_TimeDomainResourceAllocation_t  *timeDomAlloc;
4350
4351    timeDomAllocList->present = PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup;
4352    timeDomAllocList->choice.setup = NULLP;
4353    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PUSCH_TimeDomainResourceAllocationList));
4354    if(!timeDomAllocList->choice.setup)
4355    {
4356       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4357       return RFAILED;
4358    }
4359
4360    if(puschCfgDb == NULLP)
4361       elementCnt = 2;
4362    else
4363       elementCnt = puschCfgDb->numTimeDomRsrcAlloc;
4364
4365    timeDomAllocList->choice.setup->list.count = elementCnt;
4366    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(PUSCH_TimeDomainResourceAllocation_t *);
4367    timeDomAllocList->choice.setup->list.array = NULLP;
4368    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4369    if(!timeDomAllocList->choice.setup->list.array)
4370    {
4371       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4372       return RFAILED;
4373    }
4374
4375    for(idx = 0; idx < elementCnt; idx++)
4376    {
4377       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4378       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], sizeof(PUSCH_TimeDomainResourceAllocation_t));
4379       if(!timeDomAllocList->choice.setup->list.array[idx])
4380       {
4381          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4382          return RFAILED;
4383       }
4384    }
4385
4386    for(idx = 0; idx < elementCnt; idx++)
4387    {
4388       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4389       DU_ALLOC(timeDomAlloc->k2, sizeof(long));
4390       if(!timeDomAlloc->k2)
4391       {
4392          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4393          return RFAILED;
4394       }
4395       if(puschCfgDb == NULLP)
4396       {
4397          if(idx == 0)
4398             *(timeDomAlloc->k2) = PUSCH_K2_CFG1;
4399          else if(idx == 1)
4400             *(timeDomAlloc->k2) = PUSCH_K2_CFG2;
4401
4402          timeDomAlloc->mappingType = PUSCH_MAPPING_TYPE_A;
4403          timeDomAlloc->startSymbolAndLength = calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
4404       }
4405       else
4406       {
4407          *(timeDomAlloc->k2) = puschCfgDb->timeDomRsrcAllocList[idx].k2;
4408          timeDomAlloc->mappingType = puschCfgDb->timeDomRsrcAllocList[idx].mappingType;
4409          timeDomAlloc->startSymbolAndLength = puschCfgDb->timeDomRsrcAllocList[idx].startSymbolAndLength;
4410       }
4411    }
4412
4413    return ROK;
4414 }
4415
4416 /*******************************************************************
4417  *
4418  * @brief Builds BWP UL dedicated PUSCH Config
4419  *
4420  * @details
4421  *
4422  *    Function : BuildBWPUlDedPuschCfg
4423  *
4424  *    Functionality:
4425  *      Builds BWP UL dedicated PUSCH Config
4426  *
4427  * @params[in] : PUSCH_Config_t *puschCfg
4428  *    
4429  * @return ROK     - success
4430  *         RFAILED - failure
4431  *
4432  * ****************************************************************/
4433 uint8_t BuildBWPUlDedPuschCfg(PuschCfg *puschCfgDb, PUSCH_Config_t *puschCfg)
4434 {
4435    DmrsUlCfg *ulDmrsCfg = NULLP;
4436    
4437    if(puschCfgDb)
4438       ulDmrsCfg = &puschCfgDb->dmrsUlCfgForPuschMapTypeA;
4439
4440    puschCfg->dataScramblingIdentityPUSCH = NULLP;
4441    DU_ALLOC(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
4442    if(!puschCfg->dataScramblingIdentityPUSCH)
4443    {
4444       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4445       return RFAILED;
4446    }
4447    if(puschCfgDb == NULLP)
4448       *(puschCfg->dataScramblingIdentityPUSCH) = SCRAMBLING_ID;
4449    else
4450       *(puschCfg->dataScramblingIdentityPUSCH) = puschCfgDb->dataScramblingId;
4451
4452    puschCfg->txConfig = NULLP;
4453    puschCfg->dmrs_UplinkForPUSCH_MappingTypeA = NULLP;
4454    DU_ALLOC(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
4455    if(!puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
4456    {
4457       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4458       return RFAILED;
4459    }
4460
4461    if(BuildDMRSULPuschMapTypeA(ulDmrsCfg, puschCfg->dmrs_UplinkForPUSCH_MappingTypeA) != ROK)
4462    {
4463       return RFAILED;
4464    }
4465
4466    puschCfg->dmrs_UplinkForPUSCH_MappingTypeB = NULLP;
4467    puschCfg->pusch_PowerControl = NULLP;
4468    puschCfg->frequencyHopping = NULLP;
4469    puschCfg->frequencyHoppingOffsetLists = NULLP;
4470
4471    if(puschCfgDb == NULLP)
4472       puschCfg->resourceAllocation = RES_ALLOC_TYPE;
4473    else
4474       puschCfg->resourceAllocation = puschCfgDb->resourceAllocType;
4475
4476    puschCfg->pusch_TimeDomainAllocationList = NULLP;
4477    DU_ALLOC(puschCfg->pusch_TimeDomainAllocationList, sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
4478    if(!puschCfg->pusch_TimeDomainAllocationList)
4479    {
4480       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4481       return RFAILED;
4482    }
4483
4484    if(BuildPuschTimeDomAllocList(puschCfgDb, puschCfg->pusch_TimeDomainAllocationList) != ROK)
4485    {
4486       return RFAILED;
4487    }
4488
4489    puschCfg->pusch_AggregationFactor = NULLP;
4490    puschCfg->mcs_Table = NULLP;
4491    puschCfg->mcs_TableTransformPrecoder = NULLP;
4492    puschCfg->transformPrecoder = NULLP;
4493    DU_ALLOC(puschCfg->transformPrecoder, sizeof(long));
4494    if(!puschCfg->transformPrecoder)
4495    {
4496       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4497       return RFAILED;
4498    }
4499    if(puschCfgDb == NULLP)
4500       *(puschCfg->transformPrecoder) = PUSCH_TRANSFORM_PRECODER;
4501    else
4502       *(puschCfg->transformPrecoder) = puschCfgDb->transformPrecoder;
4503
4504    puschCfg->codebookSubset = NULLP;
4505    puschCfg->maxRank = NULLP;
4506    puschCfg->rbg_Size = NULLP;
4507    puschCfg->uci_OnPUSCH = NULLP;
4508    puschCfg->tp_pi2BPSK = NULLP;
4509
4510    return ROK;
4511 }
4512
4513 /*******************************************************************
4514  *
4515  * @brief Builds PUCCH resource set add/modify list
4516  *
4517  * @details
4518  *
4519  *    Function : BuildPucchRsrcSetAddModList
4520  *
4521  *    Functionality:
4522  *      Builds PUCCH resource set add/modify list
4523  *
4524  * @params[in] : PucchResrcSetCfg *rsrcSetCfgDb
4525  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4526  *
4527  * @return ROK     - success
4528  *         RFAILED - failure
4529  *
4530  * ****************************************************************/
4531 uint8_t BuildPucchRsrcSetAddModList(PucchResrcSetCfg *rsrcSetCfgDb, \
4532    struct PUCCH_Config__resourceSetToAddModList *resourceSetToAddModList)
4533 {
4534    uint8_t elementCnt = 0, rsrcSetIdx = 0, rsrcIdx = 0;
4535    PUCCH_ResourceSet_t *rsrcSet = NULLP;
4536
4537    if(rsrcSetCfgDb == NULLP)
4538       elementCnt = 1;
4539    else
4540       elementCnt = rsrcSetCfgDb->resrcSetToAddModListCount;
4541
4542    resourceSetToAddModList->list.count = elementCnt;
4543    resourceSetToAddModList->list.size = elementCnt * sizeof(PUCCH_ResourceSet_t *);
4544    DU_ALLOC(resourceSetToAddModList->list.array, resourceSetToAddModList->list.size);
4545    if(resourceSetToAddModList->list.array == NULLP)
4546    {
4547       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4548       return RFAILED;
4549    }
4550    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4551    {
4552       DU_ALLOC(resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
4553       if(resourceSetToAddModList->list.array[rsrcSetIdx] == NULLP)
4554       {
4555          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4556          return RFAILED;
4557       }
4558    }
4559
4560    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4561    {
4562       rsrcSet = resourceSetToAddModList->list.array[rsrcSetIdx];
4563
4564       /* Resource set Id */
4565       if(rsrcSetCfgDb == NULLP)
4566          rsrcSet->pucch_ResourceSetId = 1;
4567       else
4568          rsrcSet->pucch_ResourceSetId = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcSetId;
4569  
4570       /* Resource list of a resource set */
4571       if(rsrcSetCfgDb == NULLP)
4572          elementCnt = 1;
4573       else
4574          elementCnt = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcListCount;
4575       rsrcSet->resourceList.list.count = elementCnt;
4576       rsrcSet->resourceList.list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
4577       DU_ALLOC(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
4578       if(rsrcSet->resourceList.list.array == NULLP)
4579       {
4580          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4581          return RFAILED;
4582       }
4583
4584       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4585       {
4586          DU_ALLOC(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
4587          if(rsrcSet->resourceList.list.array[rsrcIdx] == NULLP)
4588          {
4589             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4590             return RFAILED;
4591          }
4592       }
4593       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4594       {
4595          if(rsrcSetCfgDb == NULLP)
4596             *(rsrcSet->resourceList.list.array[rsrcIdx]) = 1;
4597          else
4598             *(rsrcSet->resourceList.list.array[rsrcIdx]) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcList[rsrcIdx];
4599       }
4600
4601       /* Max payload size (minus 1) in a Resource set */
4602       rsrcSet->maxPayloadMinus1 = NULLP;
4603       if(rsrcSetCfgDb && rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize)
4604       {
4605          DU_ALLOC(rsrcSet->maxPayloadMinus1, sizeof(long));
4606          if(rsrcSet->maxPayloadMinus1 == NULLP)
4607          {
4608             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4609             return RFAILED;
4610          }
4611          *(rsrcSet->maxPayloadMinus1) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize;
4612       }
4613    }
4614    return ROK;
4615 }
4616
4617 /*******************************************************************
4618  *
4619  * @brief Builds PUCCH resource add/modify list
4620  *
4621  * @details
4622  *
4623  *    Function : BuildPucchRsrcAdddModList
4624  *
4625  *    Functionality:
4626  *      Builds PUCCH resource add/modify list
4627  *
4628  * @params[in] : PucchResrcCfg *rsrcSetCfgDb
4629  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4630  *
4631  * @return ROK     - success
4632  *         RFAILED - failure
4633  *
4634  * ****************************************************************/
4635 uint8_t BuildPucchRsrcAddModList(PucchResrcCfg *rsrcCfgDb, struct PUCCH_Config__resourceToAddModList  *resourceToAddModList)
4636 {
4637    uint8_t elementCnt = 0, rsrcIdx = 0;
4638    PUCCH_Resource_t *rsrc = NULLP;
4639
4640    if(rsrcCfgDb == NULLP)
4641       elementCnt = 1;
4642    else
4643       elementCnt = rsrcCfgDb->resrcToAddModListCount;
4644    resourceToAddModList->list.count = elementCnt;
4645    resourceToAddModList->list.size = elementCnt * sizeof(PUCCH_Resource_t *);
4646    DU_ALLOC(resourceToAddModList->list.array, resourceToAddModList->list.size);
4647    if(resourceToAddModList->list.array == NULLP)
4648    {
4649       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4650       return RFAILED;
4651    }
4652    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4653    {
4654       DU_ALLOC(resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
4655       if(resourceToAddModList->list.array[rsrcIdx] == NULLP)
4656       {
4657          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4658          return RFAILED;
4659       }
4660    }
4661
4662    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4663    {
4664       rsrc = resourceToAddModList->list.array[rsrcIdx];
4665
4666       if(rsrcCfgDb == NULLP)
4667       {
4668          rsrc->pucch_ResourceId = 1;
4669          rsrc->startingPRB = 0;
4670          rsrc->format.present = PUCCH_Resource__format_PR_format1; 
4671          DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4672          if(rsrc->format.choice.format1 == NULLP)
4673          {
4674             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4675             return RFAILED;
4676          }  
4677          rsrc->format.choice.format1->initialCyclicShift = 0;
4678          rsrc->format.choice.format1->nrofSymbols = 4;
4679          rsrc->format.choice.format1->startingSymbolIndex = 0;
4680          rsrc->format.choice.format1->timeDomainOCC = 0;
4681       }
4682       else
4683       {
4684          rsrc->pucch_ResourceId = rsrcCfgDb->resrcToAddModList[rsrcIdx].resrcId;
4685          rsrc->startingPRB = rsrcCfgDb->resrcToAddModList[rsrcIdx].startPrb;
4686          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop)
4687          {
4688             DU_ALLOC(rsrc->intraSlotFrequencyHopping, sizeof(long));
4689             if(rsrc->intraSlotFrequencyHopping == NULLP)
4690             {
4691                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4692                return RFAILED;
4693             }
4694             *(rsrc->intraSlotFrequencyHopping) = rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop;
4695          }
4696          else
4697             rsrc->intraSlotFrequencyHopping = NULLP;
4698
4699          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop)
4700          {
4701             DU_ALLOC(rsrc->secondHopPRB, sizeof(PRB_Id_t));
4702             if(rsrc->secondHopPRB == NULLP)
4703             {
4704                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4705                return RFAILED;
4706             }
4707             *(rsrc->secondHopPRB) = rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop;
4708          }
4709          else
4710             rsrc->secondHopPRB = NULLP;
4711          rsrc->format.present = covertPucchFormatIntEnumToRrcEnum(rsrcCfgDb->resrcToAddModList[rsrcIdx].pucchFormat); 
4712
4713          switch(rsrc->format.present)
4714          {
4715             case PUCCH_Resource__format_PR_NOTHING:
4716                break;
4717             case PUCCH_Resource__format_PR_format0:
4718                {
4719                   DU_ALLOC(rsrc->format.choice.format0, sizeof(PUCCH_format0_t));
4720                   if(rsrc->format.choice.format0 == NULLP)
4721                   {
4722                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4723                      return RFAILED;
4724                   }
4725                   rsrc->format.choice.format0->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->initialCyclicShift;
4726                   rsrc->format.choice.format0->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->numSymbols;
4727                   rsrc->format.choice.format0->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->startSymbolIdx;
4728                   break;
4729                }
4730
4731             case PUCCH_Resource__format_PR_format1:
4732                {
4733                   DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4734                   if(rsrc->format.choice.format1 == NULLP)
4735                   {
4736                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4737                      return RFAILED;
4738                   }  
4739                   rsrc->format.choice.format1->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->initialCyclicShift;
4740                   rsrc->format.choice.format1->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->numSymbols;
4741                   rsrc->format.choice.format1->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->startSymbolIdx;
4742                   rsrc->format.choice.format1->timeDomainOCC = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->timeDomOCC;
4743                   break;
4744                }
4745
4746             case PUCCH_Resource__format_PR_format2:
4747                {
4748                   DU_ALLOC(rsrc->format.choice.format2, sizeof(PUCCH_format2_t));
4749                   if(rsrc->format.choice.format2 == NULLP)
4750                   {
4751                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4752                      return RFAILED;
4753                   } 
4754                   rsrc->format.choice.format2->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numPrbs;
4755                   rsrc->format.choice.format2->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numSymbols;
4756                   rsrc->format.choice.format2->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->startSymbolIdx;
4757                   break;
4758                }
4759
4760             case PUCCH_Resource__format_PR_format3:
4761                {
4762                   DU_ALLOC(rsrc->format.choice.format3, sizeof(PUCCH_format3_t));
4763                   if(rsrc->format.choice.format3 == NULLP)
4764                   {
4765                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4766                      return RFAILED;
4767                   }
4768                   rsrc->format.choice.format3->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numPrbs;
4769                   rsrc->format.choice.format3->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numSymbols;
4770                   rsrc->format.choice.format3->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->startSymbolIdx;
4771                   break;
4772                }
4773
4774             case PUCCH_Resource__format_PR_format4:
4775                {
4776                   DU_ALLOC(rsrc->format.choice.format4, sizeof(PUCCH_format4_t));
4777                   if(rsrc->format.choice.format4 == NULLP)
4778                   {
4779                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4780                      return RFAILED;
4781                   }
4782                   rsrc->format.choice.format4->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->numSymbols;
4783                   rsrc->format.choice.format4->occ_Length = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occLen;
4784                   rsrc->format.choice.format4->occ_Index = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occIdx;
4785                   rsrc->format.choice.format4->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->startSymbolIdx;
4786                   break;
4787                }
4788          }
4789       }
4790    }
4791    return ROK;
4792 }
4793
4794 /*******************************************************************
4795  *
4796  * @brief Builds PUCCH format  config
4797  *
4798  * @details
4799  *
4800  *    Function : BuildPucchFormat
4801  *
4802  *    Functionality: Builds PUCCH format  config
4803  *
4804  * @params[in] : PucchFormatCfg *formatDb
4805  *               PUCCH_FormatConfig_t *format
4806  *
4807  * @return ROK     - success
4808  *         RFAILED - failure
4809  *
4810  * ****************************************************************/
4811 uint8_t BuildPucchFormat(PucchFormatCfg *formatDb, PUCCH_FormatConfig_t *format)
4812 {
4813    /* Inter Slot Fequency hopping */
4814    format->interslotFrequencyHopping = NULLP;
4815    if((formatDb != NULLP) && (formatDb->interSlotFreqHop == true))
4816    {
4817       DU_ALLOC(format->interslotFrequencyHopping, sizeof(long));
4818       if(format->interslotFrequencyHopping)
4819       {
4820          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4821          return RFAILED;
4822       }
4823       *(format->interslotFrequencyHopping) = PUCCH_FormatConfig__interslotFrequencyHopping_enabled;
4824    }
4825
4826    /* Additional DMRS */
4827    format->additionalDMRS = NULLP;
4828    if((formatDb != NULLP) && (formatDb->addDmrs == true))
4829    {
4830       DU_ALLOC(format->additionalDMRS, sizeof(long));
4831       if(format->additionalDMRS)
4832       {
4833          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4834          return RFAILED;
4835       }
4836       *(format->additionalDMRS) = PUCCH_FormatConfig__additionalDMRS_true;
4837    }
4838
4839     /* Maximum code rate */
4840    format->maxCodeRate = NULLP;
4841    if((formatDb != NULLP) && (formatDb->maxCodeRate != 0))
4842    {
4843       DU_ALLOC(format->maxCodeRate, sizeof(long));
4844       if(format->maxCodeRate)
4845       {
4846          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4847          return RFAILED;
4848       }  
4849       *(format->maxCodeRate) = formatDb->maxCodeRate;
4850    }
4851  
4852    /* Number of slots */
4853    format->nrofSlots = NULLP;
4854    if((formatDb == NULLP) || ((formatDb != NULLP) && (formatDb->numSlots != 0)))
4855    {
4856       DU_ALLOC(format->nrofSlots, sizeof(long));
4857       if(format->nrofSlots == NULLP)
4858       {
4859          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4860          return RFAILED;
4861       }
4862       if(formatDb == NULLP)
4863          *(format->nrofSlots) = PUCCH_FormatConfig__nrofSlots_n4;
4864       else
4865          *(format->nrofSlots) = formatDb->numSlots;
4866    }
4867
4868    /* Pi2BPSK*/
4869    format->pi2BPSK = NULLP;
4870    if((formatDb != NULLP) && (formatDb->pi2BPSK == true))
4871    {
4872       DU_ALLOC(format->pi2BPSK, sizeof(long));
4873       if(format->pi2BPSK)
4874       {     
4875          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4876          return RFAILED;
4877       }     
4878       *(format->pi2BPSK) = PUCCH_FormatConfig__pi2BPSK_enabled;
4879    }
4880
4881    /* Simultaneous HARQ ACK and CSI */
4882    format->simultaneousHARQ_ACK_CSI = NULLP;
4883    if((formatDb != NULLP) && (formatDb->harqAckCSI == true))
4884    {
4885       DU_ALLOC(format->simultaneousHARQ_ACK_CSI, sizeof(long));
4886       if(format->simultaneousHARQ_ACK_CSI)
4887       {     
4888          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4889          return RFAILED;
4890       }     
4891       *(format->simultaneousHARQ_ACK_CSI) = PUCCH_FormatConfig__simultaneousHARQ_ACK_CSI_true;
4892    }
4893
4894    return ROK;
4895 }
4896
4897
4898 /*******************************************************************
4899  *
4900  * @brief Builds PUCCH scheduling request list
4901  *
4902  * @details
4903  *
4904  *    Function : BuildPucchSchReqAddModList
4905  *
4906  *    Functionality:
4907  *      Builds PUCCH scheduling request list
4908  *
4909  * @params[in] : PucchSchedReqCfg *schReqDb
4910  *               struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList
4911  *
4912  * @return ROK     - success
4913  *         RFAILED - failure
4914  *
4915  * ****************************************************************/
4916 uint8_t BuildPucchSchReqAddModList(PucchSchedReqCfg *schReqDb, \
4917    struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList)
4918 {
4919    uint8_t elementCnt = 0, schReqIdx = 0;
4920    SchedulingRequestResourceConfig_t *schReqRsrc;
4921
4922    elementCnt = schReqDb->schedAddModListCount;
4923    schReqRsrcToAddModList->list.count = elementCnt;
4924    schReqRsrcToAddModList->list.size = elementCnt *sizeof(struct SchedulingRequestResourceConfig *);
4925
4926    schReqRsrcToAddModList->list.array = NULLP;
4927    DU_ALLOC(schReqRsrcToAddModList->list.array, schReqRsrcToAddModList->list.size);
4928    if(schReqRsrcToAddModList->list.array == NULLP)
4929    {
4930       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
4931       return RFAILED;
4932    }
4933
4934    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
4935    {
4936       DU_ALLOC(schReqRsrcToAddModList->list.array[schReqIdx], schReqRsrcToAddModList->list.size);
4937       if(schReqRsrcToAddModList->list.array[schReqIdx] == NULLP)
4938       {
4939          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
4940          return RFAILED;
4941       }
4942    }
4943
4944    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
4945    {
4946       schReqRsrc = schReqRsrcToAddModList->list.array[schReqIdx];
4947       schReqRsrc->schedulingRequestResourceId = schReqDb->schedAddModList[schReqIdx].resrcId;
4948       schReqRsrc->schedulingRequestID = schReqDb->schedAddModList[schReqIdx].requestId;
4949
4950       if(schReqDb->schedAddModList[schReqIdx].periodicity)
4951       {
4952          schReqRsrc->periodicityAndOffset = NULLP;
4953          DU_ALLOC(schReqRsrc->periodicityAndOffset, sizeof(struct SchedulingRequestResourceConfig__periodicityAndOffset));
4954          if(schReqRsrc->periodicityAndOffset == NULLP)
4955          {
4956             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
4957             return RFAILED;
4958          }
4959
4960          schReqRsrc->periodicityAndOffset->present = schReqDb->schedAddModList[schReqIdx].periodicity;
4961          switch(schReqRsrc->periodicityAndOffset->present)
4962          {
4963             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_NOTHING:
4964                break;
4965             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
4966                schReqRsrc->periodicityAndOffset->choice.sym2 = schReqDb->schedAddModList[schReqIdx].offset;
4967                break;
4968             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
4969                schReqRsrc->periodicityAndOffset->choice.sym6or7 = schReqDb->schedAddModList[schReqIdx].offset;
4970                break;
4971             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
4972                schReqRsrc->periodicityAndOffset->choice.sl1 = schReqDb->schedAddModList[schReqIdx].offset;
4973                break;
4974             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
4975                schReqRsrc->periodicityAndOffset->choice.sl2 = schReqDb->schedAddModList[schReqIdx].offset;
4976                break;
4977             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
4978                schReqRsrc->periodicityAndOffset->choice.sl4 = schReqDb->schedAddModList[schReqIdx].offset;
4979                break;
4980             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
4981                schReqRsrc->periodicityAndOffset->choice.sl5 = schReqDb->schedAddModList[schReqIdx].offset;
4982                break;
4983             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
4984                schReqRsrc->periodicityAndOffset->choice.sl8 = schReqDb->schedAddModList[schReqIdx].offset;
4985                break;
4986             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
4987                schReqRsrc->periodicityAndOffset->choice.sl10 = schReqDb->schedAddModList[schReqIdx].offset;
4988                break;
4989             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
4990                schReqRsrc->periodicityAndOffset->choice.sl16 = schReqDb->schedAddModList[schReqIdx].offset;
4991                break;
4992             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
4993                schReqRsrc->periodicityAndOffset->choice.sl20 = schReqDb->schedAddModList[schReqIdx].offset;
4994                break;
4995             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
4996                schReqRsrc->periodicityAndOffset->choice.sl40 = schReqDb->schedAddModList[schReqIdx].offset;
4997                break;
4998             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
4999                schReqRsrc->periodicityAndOffset->choice.sl80 = schReqDb->schedAddModList[schReqIdx].offset;
5000                break;
5001             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
5002                schReqRsrc->periodicityAndOffset->choice.sl160 = schReqDb->schedAddModList[schReqIdx].offset;
5003                break;
5004             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
5005                schReqRsrc->periodicityAndOffset->choice.sl320 = schReqDb->schedAddModList[schReqIdx].offset;
5006                break;
5007             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
5008                schReqRsrc->periodicityAndOffset->choice.sl640 = schReqDb->schedAddModList[schReqIdx].offset;
5009                break;
5010          }
5011       }
5012
5013       if(schReqDb->schedAddModList[schReqIdx].resrc)
5014       {
5015          schReqRsrc->resource = NULLP;
5016          DU_ALLOC(schReqRsrc->resource, sizeof(PUCCH_ResourceId_t));
5017          if(schReqRsrc->resource == NULLP)
5018          {
5019             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5020             return RFAILED;
5021          }
5022          *(schReqRsrc->resource) = schReqDb->schedAddModList[schReqIdx].resrc;
5023
5024       }
5025    }
5026    return ROK;
5027 }
5028
5029 /*******************************************************************
5030  *
5031  * @brief Builds PUCCH multi csi resource list
5032  *
5033  * @details
5034  *
5035  *    Function : BuildPucchMultiCsiRsrcList
5036  *
5037  *    Functionality:
5038  *      Builds PUCCH multi csi resource list
5039  *
5040  * @params[in] : PucchMultiCsiCfg *multiCsiDb
5041  *               struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList
5042  *
5043  * @return ROK     - success
5044  *         RFAILED - failure
5045  *
5046  * ****************************************************************/
5047 uint8_t BuildPucchMultiCsiRsrcList(PucchMultiCsiCfg *multiCsiDb, struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList)
5048 {
5049    uint8_t elementCnt = 0, rsrcIdx = 0;
5050
5051    elementCnt = multiCsiDb->multiCsiResrcListCount;
5052    multiCsiRsrcList->list.count = elementCnt;
5053    multiCsiRsrcList->list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
5054    multiCsiRsrcList->list.array = NULLP;
5055    DU_ALLOC(multiCsiRsrcList->list.array, multiCsiRsrcList->list.size);
5056    if(multiCsiRsrcList->list.array == NULLP)
5057    {
5058       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5059       return RFAILED;
5060    }
5061
5062    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5063    {
5064       DU_ALLOC(multiCsiRsrcList->list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
5065       if(multiCsiRsrcList->list.array[rsrcIdx] == NULLP)
5066       {
5067          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5068          return RFAILED;
5069       }
5070    }
5071
5072    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5073    {
5074       *(multiCsiRsrcList->list.array[rsrcIdx]) = multiCsiDb->multiCsiResrcList[rsrcIdx];
5075    }
5076    return ROK;
5077 }
5078
5079 /*******************************************************************
5080  *
5081  * @brief Builds DL data -to- Ul Ack list
5082  *
5083  * @details
5084  *
5085  *    Function : BuildDlDataToUlAckList
5086  *
5087  *    Functionality: Builds DL data -to- Ul Ack list
5088  *
5089  * @params[in] : PucchDlDataToUlAck *dlDataToUlAckDb
5090  *               struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList
5091  *
5092  * @return ROK     - success
5093  *         RFAILED - failure
5094  *
5095  * ****************************************************************/
5096 uint8_t BuildDlDataToUlAckList(PucchDlDataToUlAck *dlDataToUlAckDb, struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList)
5097 {
5098    uint8_t elementCnt = 0, arrIdx = 0;
5099
5100    if(dlDataToUlAckDb == NULLP)
5101       elementCnt = 2;
5102    else
5103       elementCnt = dlDataToUlAckDb->dlDataToUlAckListCount;
5104
5105    dlDataToUlACKList->list.count = elementCnt;
5106    dlDataToUlACKList->list.size = elementCnt * sizeof(long *);
5107    DU_ALLOC(dlDataToUlACKList->list.array, dlDataToUlACKList->list.size);
5108    if(dlDataToUlACKList->list.array == NULLP)
5109    {
5110       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5111       return RFAILED;
5112    }   
5113
5114    for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5115    {
5116       DU_ALLOC(dlDataToUlACKList->list.array[arrIdx], sizeof(long));
5117       if(dlDataToUlACKList->list.array[arrIdx] == NULLP)
5118       {
5119          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5120          return RFAILED;
5121       }   
5122    }
5123
5124    if(dlDataToUlAckDb == NULLP)
5125    {
5126       arrIdx = 0;
5127       *(dlDataToUlACKList->list.array[arrIdx++]) = 1;
5128       *(dlDataToUlACKList->list.array[arrIdx]) = 2;
5129    }
5130    else
5131    {
5132       for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5133       {
5134          *(dlDataToUlACKList->list.array[arrIdx]) = dlDataToUlAckDb->dlDataToUlAckList[arrIdx];
5135       }
5136    }
5137    return ROK;
5138 }
5139
5140 /*******************************************************************
5141  *
5142  * @brief Builds BWP UL dedicated PUCCH Config
5143  *
5144  * @details
5145  *
5146  *    Function : BuildBWPUlDedPucchCfg
5147  *
5148  *    Functionality:
5149  *      Builds BWP UL dedicated PUCCH Config
5150  *
5151  * @params[in] : PUCCH_Config_t *pucchCfg
5152  *
5153  * @return ROK     - success
5154  *         RFAILED - failure
5155  *
5156  * ****************************************************************/
5157 uint8_t BuildBWPUlDedPucchCfg(PucchCfg *pucchCfgDb, PUCCH_Config_t *pucchCfg)
5158 {
5159    PucchResrcSetCfg *rsrcSetCfgDb = NULLP;
5160    PucchResrcCfg *rsrcCfgDb = NULLP;
5161    PucchFormatCfg *format1Db = NULLP;
5162    PucchFormatCfg *format2Db = NULLP;
5163    PucchFormatCfg *format3Db = NULLP;
5164    PucchFormatCfg *format4Db = NULLP;
5165    PucchSchedReqCfg *schReqDb = NULLP;   
5166    PucchMultiCsiCfg  *multiCsiDb = NULLP;
5167    PucchDlDataToUlAck *dlDataToUlAckDb = NULLP;
5168
5169    if(pucchCfgDb)
5170    {
5171       rsrcSetCfgDb = pucchCfgDb->resrcSet;
5172       rsrcCfgDb = pucchCfgDb->resrc;
5173       format1Db = pucchCfgDb->format1;
5174       format2Db = pucchCfgDb->format2;
5175       format3Db = pucchCfgDb->format3;
5176       format4Db = pucchCfgDb->format4;
5177       schReqDb = pucchCfgDb->schedReq;
5178       multiCsiDb = pucchCfgDb->multiCsiCfg;
5179       dlDataToUlAckDb = pucchCfgDb->dlDataToUlAck;
5180    }
5181
5182    /* RESOURCE SET */
5183    DU_ALLOC(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
5184    if(pucchCfg->resourceSetToAddModList == NULL)
5185    {
5186       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5187       return RFAILED;
5188    }
5189
5190    if(BuildPucchRsrcSetAddModList(rsrcSetCfgDb, pucchCfg->resourceSetToAddModList) != ROK)
5191    {
5192       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5193       return RFAILED;
5194    }
5195
5196    /* PUCCH RESOURCE */
5197    DU_ALLOC(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
5198    if(pucchCfg->resourceToAddModList == NULLP)
5199    {
5200       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5201       return RFAILED;
5202    }
5203
5204    if(BuildPucchRsrcAddModList(rsrcCfgDb, pucchCfg->resourceToAddModList) != ROK)
5205    {
5206       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5207       return RFAILED;
5208    }
5209
5210    /* PUCCH Format 1 */
5211    DU_ALLOC(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
5212    if(pucchCfg->format1 == NULLP)
5213    {
5214       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5215       return RFAILED;
5216    }
5217    
5218    pucchCfg->format1->present = PUCCH_Config__format1_PR_setup;
5219    DU_ALLOC(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
5220    if(pucchCfg->format1->choice.setup == NULLP)
5221    {
5222       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5223       return RFAILED;
5224    }
5225
5226    if(BuildPucchFormat(format1Db, pucchCfg->format1->choice.setup) != ROK)
5227    {
5228       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5229       return RFAILED;
5230    }
5231
5232    /* PUCCH Format 2 */
5233    if(format2Db)
5234    {
5235       DU_ALLOC(pucchCfg->format2, sizeof(struct PUCCH_Config__format2));
5236       if(pucchCfg->format2 == NULLP)
5237       {
5238          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5239          return RFAILED;
5240       }
5241
5242       pucchCfg->format2->present = PUCCH_Config__format2_PR_setup;
5243       DU_ALLOC(pucchCfg->format2->choice.setup, sizeof(PUCCH_FormatConfig_t));
5244       if(pucchCfg->format2->choice.setup == NULLP)
5245       {
5246          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5247          return RFAILED;
5248       }
5249
5250       if(BuildPucchFormat(format2Db, pucchCfg->format2->choice.setup) != ROK)
5251       {
5252          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5253          return RFAILED;
5254       }
5255    }
5256
5257    /* PUCCH Format 3 */
5258    if(format3Db)
5259    {
5260       DU_ALLOC(pucchCfg->format3, sizeof(struct PUCCH_Config__format3));
5261       if(pucchCfg->format3 == NULLP)
5262       {
5263          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5264          return RFAILED;
5265       }
5266
5267       pucchCfg->format3->present = PUCCH_Config__format3_PR_setup;
5268       DU_ALLOC(pucchCfg->format3->choice.setup, sizeof(PUCCH_FormatConfig_t));
5269       if(pucchCfg->format3->choice.setup == NULLP)
5270       {
5271          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5272          return RFAILED;
5273       }
5274
5275       if(BuildPucchFormat(format3Db, pucchCfg->format3->choice.setup) != ROK)
5276       {
5277          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5278          return RFAILED;
5279       }
5280    }
5281
5282    /* PUCCH Format 4 */
5283    if(format4Db)
5284    {
5285       DU_ALLOC(pucchCfg->format4, sizeof(struct PUCCH_Config__format4));
5286       if(pucchCfg->format4 == NULLP)
5287       {
5288          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5289          return RFAILED;
5290       }
5291
5292       pucchCfg->format4->present = PUCCH_Config__format4_PR_setup;
5293       DU_ALLOC(pucchCfg->format4->choice.setup, sizeof(PUCCH_FormatConfig_t));
5294       if(pucchCfg->format4->choice.setup == NULLP)
5295       {
5296          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5297          return RFAILED;
5298       }
5299
5300       if(BuildPucchFormat(format4Db, pucchCfg->format4->choice.setup) != ROK)
5301       {
5302          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5303          return RFAILED;
5304       }
5305    }
5306
5307    /* Scheduling Request */
5308    if(schReqDb && (schReqDb->schedAddModListCount != 0))
5309    {
5310       pucchCfg->schedulingRequestResourceToAddModList = NULLP;
5311       DU_ALLOC(pucchCfg->schedulingRequestResourceToAddModList, sizeof(struct PUCCH_Config__schedulingRequestResourceToAddModList));
5312       if(pucchCfg->schedulingRequestResourceToAddModList == NULLP)
5313       {
5314          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5315          return RFAILED;
5316       }
5317
5318       if(BuildPucchSchReqAddModList(schReqDb, pucchCfg->schedulingRequestResourceToAddModList) != ROK)
5319       {
5320          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5321          return RFAILED;
5322       }
5323    }
5324
5325    /* Multi CSI */
5326    if(multiCsiDb && (multiCsiDb->multiCsiResrcListCount != 0))
5327    {
5328       pucchCfg->multi_CSI_PUCCH_ResourceList = NULLP;
5329       DU_ALLOC(pucchCfg->multi_CSI_PUCCH_ResourceList, sizeof(struct PUCCH_Config__multi_CSI_PUCCH_ResourceList));
5330       if(pucchCfg->multi_CSI_PUCCH_ResourceList == NULLP)
5331       {
5332          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5333          return RFAILED;
5334       }
5335
5336       if(BuildPucchMultiCsiRsrcList(multiCsiDb, pucchCfg->multi_CSI_PUCCH_ResourceList) != ROK)
5337       {
5338          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5339          return RFAILED;
5340       }
5341    }
5342
5343    /* DL DATA TO UL ACK */
5344    DU_ALLOC(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
5345    if(pucchCfg->dl_DataToUL_ACK == NULLP)
5346    {
5347       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5348       return RFAILED;
5349    }
5350
5351    if(BuildDlDataToUlAckList(dlDataToUlAckDb, pucchCfg->dl_DataToUL_ACK) != ROK)
5352    {
5353       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5354       return RFAILED;
5355    }
5356    
5357    /* TODO : spatial relation info add/mod list and power control*/
5358
5359    return ROK;
5360 }
5361
5362 /*******************************************************************
5363  *
5364  * @brief Fills SRS resource to add/modify list 
5365  *
5366  * @details
5367  *
5368  *    Function : BuildSrsRsrcAddModList
5369  *
5370  *    Functionality: Fills SRS resource to add/modify list
5371  *
5372  * @params[in] 
5373  * @return ROK     - success
5374  *         RFAILED - failure
5375  *
5376  * ****************************************************************/
5377 uint8_t BuildSrsRsrcAddModList(struct SRS_Config__srs_ResourceToAddModList *resourceList)
5378 {
5379    uint8_t   elementCnt;
5380    uint8_t   rsrcIdx;
5381
5382    elementCnt = 1;
5383    resourceList->list.count = elementCnt;
5384    resourceList->list.size = elementCnt * sizeof(SRS_Resource_t *);
5385    resourceList->list.array = NULLP;
5386    DU_ALLOC(resourceList->list.array, resourceList->list.size);
5387    if(!resourceList->list.array)
5388    {
5389       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5390       return RFAILED;
5391    }
5392
5393    for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
5394    {
5395       DU_ALLOC(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
5396       if(!resourceList->list.array[rsrcIdx])
5397       {
5398          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5399          return RFAILED;
5400       }
5401    }
5402
5403    rsrcIdx = 0;
5404    resourceList->list.array[rsrcIdx]->srs_ResourceId = SRS_RSRC_ID;
5405    resourceList->list.array[rsrcIdx]->nrofSRS_Ports = SRS_Resource__nrofSRS_Ports_port1;
5406    resourceList->list.array[rsrcIdx]->transmissionComb.present = SRS_Resource__transmissionComb_PR_n2;
5407
5408    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2 = NULLP;
5409    DU_ALLOC(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2, \
5410          sizeof(struct SRS_Resource__transmissionComb__n2));
5411    if(!resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2)
5412    {
5413       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5414       return RFAILED;
5415    }
5416    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->combOffset_n2\
5417       = SRS_COMB_OFFSET_N2;
5418    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->cyclicShift_n2\
5419       = SRS_CYCLIC_SHIFT_N2;
5420
5421    resourceList->list.array[rsrcIdx]->resourceMapping.startPosition = \
5422                                                                       PUSCH_START_SYMBOL;
5423    resourceList->list.array[rsrcIdx]->resourceMapping.nrofSymbols =  \
5424                                                                      SRS_Resource__resourceMapping__nrofSymbols_n1;
5425    resourceList->list.array[rsrcIdx]->resourceMapping.repetitionFactor = \
5426                                                                          SRS_Resource__resourceMapping__repetitionFactor_n1;
5427
5428    resourceList->list.array[rsrcIdx]->freqDomainPosition = SRS_FREQ_DOM_POS;
5429    resourceList->list.array[rsrcIdx]->freqDomainShift = SRS_FREQ_DOM_SHIFT;
5430    resourceList->list.array[rsrcIdx]->freqHopping.c_SRS = C_SRS;
5431    resourceList->list.array[rsrcIdx]->freqHopping.b_SRS = B_SRS;
5432    resourceList->list.array[rsrcIdx]->freqHopping.b_hop = B_HOP;
5433    resourceList->list.array[rsrcIdx]->groupOrSequenceHopping = \
5434                                                                SRS_Resource__groupOrSequenceHopping_neither;
5435
5436    /* Setting resource type to aperiodic for intergration purposes */
5437    resourceList->list.array[rsrcIdx]->resourceType.present = \
5438                                                              SRS_Resource__resourceType_PR_aperiodic;
5439    resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic = NULLP;
5440    DU_ALLOC(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,
5441          sizeof(struct SRS_Resource__resourceType__aperiodic));
5442    if(!resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic)
5443    {
5444       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5445       return RFAILED;
5446    }
5447    resourceList->list.array[rsrcIdx]->sequenceId = SRS_SEQ_ID;
5448
5449    return ROK;
5450 }
5451
5452 /*******************************************************************
5453  *
5454  * @brief Build SRS resource set Add/mod list
5455  *
5456  * @details
5457  *
5458  *    Function : BuildSrsRsrcSetAddModList
5459  *
5460  *    Functionality: Build SRS resource set Add/mod list
5461  *
5462  * @params[in] 
5463  * @return ROK     - success
5464  *         RFAILED - failure
5465  *
5466  * ****************************************************************/
5467    uint8_t BuildSrsRsrcSetAddModList
5468 (
5469  struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList
5470  )
5471 {
5472    uint8_t  elementCnt;
5473    uint8_t  rSetIdx;
5474    uint8_t  rsrcIdx;
5475    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList;
5476
5477    elementCnt = 1;
5478    rsrcSetList->list.count = elementCnt;
5479    rsrcSetList->list.size = elementCnt * sizeof(SRS_ResourceSet_t *);
5480    rsrcSetList->list.array = NULLP;
5481    DU_ALLOC(rsrcSetList->list.array, rsrcSetList->list.size);
5482    if(!rsrcSetList->list.array)
5483    {
5484       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5485       return RFAILED;
5486    }
5487
5488    for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
5489    {
5490       DU_ALLOC(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
5491       if(!rsrcSetList->list.array[rSetIdx])
5492       {
5493          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5494          return RFAILED;
5495       }
5496    }
5497
5498    rSetIdx = 0;
5499    rsrcSetList->list.array[rSetIdx]->srs_ResourceSetId = SRS_RSET_ID;
5500
5501    /* Fill Resource Id list in resource set */
5502    rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList = NULLP;
5503    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
5504          sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
5505    if(!rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
5506    {
5507       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5508       return RFAILED;
5509    }
5510
5511    elementCnt = 1;
5512    rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
5513    rsrcIdList->list.count = elementCnt;
5514    rsrcIdList->list.size = elementCnt * sizeof(SRS_ResourceId_t *);
5515    rsrcIdList->list.array = NULLP;
5516    DU_ALLOC(rsrcIdList->list.array, rsrcIdList->list.size);
5517    if(!rsrcIdList->list.array)
5518    {
5519       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5520       return RFAILED;
5521    }
5522
5523    for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
5524    {
5525       DU_ALLOC(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
5526       if(!rsrcIdList->list.array[rsrcIdx])
5527       {
5528          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5529          return RFAILED;
5530       }
5531    }
5532
5533    rsrcIdx = 0;
5534    *rsrcIdList->list.array[rsrcIdx] = SRS_RSRC_ID;
5535
5536    /* Fill resource type */
5537    rsrcSetList->list.array[rSetIdx]->resourceType.present = \
5538                                                             SRS_ResourceSet__resourceType_PR_aperiodic;
5539
5540    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic = NULLP;
5541    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
5542          sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
5543    if(!rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic)
5544    {
5545       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5546       return RFAILED;
5547    }
5548    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->aperiodicSRS_ResourceTrigger \
5549       = APERIODIC_SRS_RESRC_TRIGGER;
5550
5551    /* TODO : Fill values for below IEs as expected by Viavi */
5552    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->csi_RS = NULLP;
5553    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->slotOffset = NULLP;
5554
5555
5556    rsrcSetList->list.array[rSetIdx]->usage = SRS_ResourceSet__usage_codebook;
5557    rsrcSetList->list.array[rSetIdx]->alpha = NULLP;
5558    rsrcSetList->list.array[rSetIdx]->p0 = NULLP;
5559    rsrcSetList->list.array[rSetIdx]->pathlossReferenceRS = NULLP;
5560    rsrcSetList->list.array[rSetIdx]->srs_PowerControlAdjustmentStates = NULLP;
5561
5562    return ROK;
5563 }
5564
5565 /*******************************************************************
5566  *
5567  * @brief Builds BWP UL dedicated SRS Config
5568  *
5569  * @details
5570  *
5571  *    Function : BuildBWPUlDedSrsCfg
5572  *
5573  *    Functionality: Builds BWP UL dedicated SRS Config
5574  *
5575  * @params[in] SRS Config 
5576  * @return ROK     - success
5577  *         RFAILED - failure
5578  *
5579  * ****************************************************************/
5580 uint8_t BuildBWPUlDedSrsCfg(SRS_Config_t *srsCfg)
5581 {
5582    srsCfg->srs_ResourceSetToReleaseList = NULLP;
5583    srsCfg->srs_ResourceSetToAddModList = NULLP;
5584    DU_ALLOC(srsCfg->srs_ResourceSetToAddModList, \
5585          sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
5586    if(!srsCfg->srs_ResourceSetToAddModList)
5587    {
5588       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5589       return RFAILED;
5590    }
5591    if(BuildSrsRsrcSetAddModList(srsCfg->srs_ResourceSetToAddModList) != ROK)
5592    {
5593       return RFAILED;
5594    }
5595
5596    srsCfg->srs_ResourceToReleaseList = NULLP;
5597
5598    /* Resource to Add/Modify list */
5599    srsCfg->srs_ResourceToAddModList = NULLP;
5600    DU_ALLOC(srsCfg->srs_ResourceToAddModList, \
5601          sizeof(struct SRS_Config__srs_ResourceToAddModList));
5602    if(!srsCfg->srs_ResourceToAddModList)
5603    {
5604       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5605       return RFAILED;
5606    }
5607
5608    if(BuildSrsRsrcAddModList(srsCfg->srs_ResourceToAddModList) != ROK)
5609    {
5610       return RFAILED;
5611    }
5612
5613    srsCfg->tpc_Accumulation = NULLP;
5614
5615    return ROK;
5616 }
5617
5618
5619
5620 /*******************************************************************
5621  *
5622  * @brief Builds Pusch Serving cell Config
5623  *
5624  * @details
5625  *
5626  *    Function : BuildPuschSrvCellCfg
5627  *
5628  *    Functionality: Builds Pusch Serving cell Config
5629  *
5630  * @params[in] struct UplinkConfig__pusch_ServingCellConfig *puschCfg
5631  *
5632  * @return ROK     - success
5633  *         RFAILED - failure
5634  *
5635  * ****************************************************************/
5636 uint8_t BuildPuschSrvCellCfg(struct UplinkConfig__pusch_ServingCellConfig *puschCfg)
5637 {
5638    puschCfg->present = UplinkConfig__pusch_ServingCellConfig_PR_setup;
5639    puschCfg->choice.setup = NULLP;
5640    DU_ALLOC(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
5641    if(!puschCfg->choice.setup)
5642    {
5643       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5644       return RFAILED;
5645    }
5646
5647    puschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5648    puschCfg->choice.setup->rateMatching = NULLP;
5649    puschCfg->choice.setup->xOverhead = NULLP;
5650    puschCfg->choice.setup->ext1 = NULLP;
5651    DU_ALLOC(puschCfg->choice.setup->ext1, sizeof(struct PUSCH_ServingCellConfig__ext1));
5652    if(!puschCfg->choice.setup->ext1)
5653    {
5654       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5655       return RFAILED;
5656    }
5657
5658    puschCfg->choice.setup->ext1->maxMIMO_Layers = NULLP;
5659    DU_ALLOC(puschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5660    if(!puschCfg->choice.setup->ext1->maxMIMO_Layers)
5661    {
5662       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5663       return RFAILED;
5664    }
5665    *(puschCfg->choice.setup->ext1->maxMIMO_Layers) = PUSCH_MAX_MIMO_LAYERS;
5666
5667    puschCfg->choice.setup->ext1->processingType2Enabled= NULLP;
5668    DU_ALLOC(puschCfg->choice.setup->ext1->processingType2Enabled,sizeof(BOOLEAN_t));
5669    if(!puschCfg->choice.setup->ext1->processingType2Enabled)
5670    {
5671       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5672       return RFAILED;
5673    }
5674    *(puschCfg->choice.setup->ext1->processingType2Enabled) = PUSCH_PROCESS_TYPE2_ENABLED;
5675    return ROK;
5676 }
5677
5678 /*******************************************************************
5679  *
5680  * @brief Builds inital UL BWP
5681  *
5682  * @details
5683  *
5684  *    Function : BuildInitialUlBWP
5685  *
5686  *    Functionality: Builds initial UL BWP
5687  *
5688  * @params[in] BWP_UplinkDedicated_t *ulBwp
5689  * @return ROK     - success
5690  *         RFAILED - failure
5691  *
5692  * ****************************************************************/
5693 uint8_t BuildInitialUlBWP(InitialUlBwp *initUlBwp, BWP_UplinkDedicated_t *ulBwp)
5694 {
5695    PucchCfg *pucchCfg = NULLP;
5696    PuschCfg *puschCfg = NULLP;
5697
5698    if(initUlBwp)
5699    {
5700       if(initUlBwp->pucchPresent)
5701          pucchCfg = &initUlBwp->pucchCfg;
5702       if(initUlBwp->puschPresent)
5703          puschCfg = &initUlBwp->puschCfg;
5704    }
5705
5706    ulBwp->pucch_Config = NULLP;
5707    DU_ALLOC(ulBwp->pucch_Config, sizeof(struct BWP_UplinkDedicated__pucch_Config));
5708    if(!ulBwp->pucch_Config)
5709    {
5710       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5711       return RFAILED;
5712    }
5713
5714    ulBwp->pucch_Config->present = BWP_UplinkDedicated__pucch_Config_PR_setup;
5715    ulBwp->pucch_Config->choice.setup = NULLP;
5716    DU_ALLOC(ulBwp->pucch_Config->choice.setup, sizeof(PUCCH_Config_t));
5717    if(!ulBwp->pucch_Config->choice.setup)
5718    {
5719       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5720       return RFAILED;
5721    }
5722
5723    if(BuildBWPUlDedPucchCfg(pucchCfg, ulBwp->pucch_Config->choice.setup) != ROK)
5724    {
5725       return RFAILED;
5726    }
5727
5728    /* Fill BWP UL dedicated PUSCH config */
5729    ulBwp->pusch_Config = NULLP;
5730    DU_ALLOC(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
5731    if(!ulBwp->pusch_Config)
5732    {
5733       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5734       return RFAILED;
5735    }
5736
5737    ulBwp->pusch_Config->present = BWP_UplinkDedicated__pusch_Config_PR_setup;
5738    ulBwp->pusch_Config->choice.setup = NULLP;
5739    DU_ALLOC(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
5740    if(!ulBwp->pusch_Config->choice.setup)
5741    {
5742       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5743       return RFAILED;
5744    }
5745
5746    if(BuildBWPUlDedPuschCfg(puschCfg, ulBwp->pusch_Config->choice.setup) != ROK)
5747    {
5748       return RFAILED;
5749    }
5750
5751    ulBwp->configuredGrantConfig = NULLP;
5752
5753    /* Fill BPW UL dedicated SRS config */
5754    ulBwp->srs_Config = NULLP;
5755    DU_ALLOC(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
5756    if(!ulBwp->srs_Config)
5757    {
5758       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5759       return RFAILED;
5760    }
5761
5762    ulBwp->srs_Config->present = BWP_UplinkDedicated__srs_Config_PR_setup;
5763    ulBwp->srs_Config->choice.setup = NULLP;
5764    DU_ALLOC(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
5765    if(!ulBwp->srs_Config->choice.setup)
5766    {
5767       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5768       return RFAILED;
5769    }
5770
5771    if(BuildBWPUlDedSrsCfg(ulBwp->srs_Config->choice.setup) != ROK)
5772    {
5773       return RFAILED;   
5774    }
5775
5776    ulBwp->beamFailureRecoveryConfig = NULLP;
5777
5778    return ROK;
5779 }
5780
5781 /*******************************************************************
5782  *
5783  * @brief Builds UL config
5784  * @details
5785  *
5786  *    Function : BuildUlCfg 
5787  *
5788  *    Functionality: Builds UL config in spCellCfgDed
5789  *
5790  * @params[in] UplinkConfig_t *ulCfg
5791  *
5792  * @return ROK     - success
5793  *         RFAILED - failure
5794  *
5795  * ****************************************************************/
5796 uint8_t BuildUlCfg(ServCellCfgInfo *servCellCfg, UplinkConfig_t *ulCfg)
5797 {
5798    InitialUlBwp *initUlBwp = NULLP;
5799
5800    if(servCellCfg)
5801    {
5802       initUlBwp = &servCellCfg->initUlBwp;
5803    }
5804
5805    ulCfg->initialUplinkBWP = NULLP;
5806    DU_ALLOC(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
5807    if(!ulCfg->initialUplinkBWP)
5808    {
5809       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5810       return RFAILED;
5811    }
5812
5813    if(BuildInitialUlBWP(initUlBwp, ulCfg->initialUplinkBWP) != ROK)
5814    {
5815       return RFAILED;
5816    }
5817
5818    ulCfg->uplinkBWP_ToReleaseList = NULLP;
5819    ulCfg->uplinkBWP_ToAddModList = NULLP;
5820    ulCfg->firstActiveUplinkBWP_Id = NULLP;
5821    DU_ALLOC(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
5822    if(!ulCfg->firstActiveUplinkBWP_Id)
5823    {
5824       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5825       return RFAILED;
5826    }
5827    if(servCellCfg == NULLP)
5828       *(ulCfg->firstActiveUplinkBWP_Id) = ACTIVE_UL_BWP_ID;
5829    else
5830       *(ulCfg->firstActiveUplinkBWP_Id) = servCellCfg->firstActvUlBwpId;
5831
5832    ulCfg->pusch_ServingCellConfig = NULLP;
5833    DU_ALLOC(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
5834    if(!ulCfg->pusch_ServingCellConfig)
5835    {
5836       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5837       return RFAILED;
5838    }
5839
5840    if(BuildPuschSrvCellCfg(ulCfg->pusch_ServingCellConfig) != ROK)
5841    {
5842       return RFAILED;
5843    }
5844
5845    ulCfg->carrierSwitching = NULLP;
5846    ulCfg->ext1 = NULLP;
5847    return ROK;
5848 }
5849
5850 /*******************************************************************
5851  *
5852  * @brief Builds PDSCH serving cell config
5853  * @details
5854  *
5855  *    Function : BuildPdschSrvCellCfg
5856  *
5857  *    Functionality: Builds PDSCH serving cell config in spCellCfgDed
5858  *
5859  * @params[in] struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg 
5860  *
5861  * @return ROK     - success
5862  *         RFAILED - failure
5863  *
5864  * ****************************************************************/
5865 uint8_t BuildPdschSrvCellCfg(PdschServCellCfg *pdschServCellDb, struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg)
5866 {
5867    pdschCfg->present =  ServingCellConfig__pdsch_ServingCellConfig_PR_setup;
5868    pdschCfg->choice.setup = NULLP;
5869    DU_ALLOC(pdschCfg->choice.setup, sizeof( struct PDSCH_ServingCellConfig));
5870    if(!pdschCfg->choice.setup)
5871    {
5872       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5873       return RFAILED;
5874    }
5875
5876    /* Code Block Group Transmission */
5877    pdschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5878    if(pdschServCellDb && (pdschServCellDb->maxCodeBlkGrpPerTb || pdschServCellDb->codeBlkGrpFlushInd))
5879    {
5880       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission, sizeof(struct PDSCH_ServingCellConfig__codeBlockGroupTransmission));
5881       if(pdschCfg->choice.setup->codeBlockGroupTransmission == NULLP)
5882       {
5883          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5884          return RFAILED;
5885       }
5886
5887       pdschCfg->choice.setup->codeBlockGroupTransmission->present = PDSCH_ServingCellConfig__codeBlockGroupTransmission_PR_setup;
5888       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup = NULLP;
5889       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup, sizeof(struct PDSCH_CodeBlockGroupTransmission ));
5890       if(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup == NULLP)
5891       {
5892          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5893          return RFAILED;
5894       }
5895
5896       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock = \
5897          *(pdschServCellDb->maxCodeBlkGrpPerTb);
5898       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator = \
5899          *(pdschServCellDb->codeBlkGrpFlushInd);
5900    }
5901
5902    /* xOverhead */
5903    pdschCfg->choice.setup->xOverhead = NULLP;
5904    if(pdschServCellDb && pdschServCellDb->xOverhead)
5905    {
5906       DU_ALLOC(pdschCfg->choice.setup->xOverhead, sizeof(long));
5907       if(pdschCfg->choice.setup->xOverhead == NULLP)
5908       {
5909          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5910          return RFAILED;
5911       }
5912       *(pdschCfg->choice.setup->xOverhead) = *(pdschServCellDb->xOverhead);
5913    }
5914
5915    /* Number of HARQ processes */
5916    pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH = NULLP;
5917    DU_ALLOC(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH, sizeof(long));
5918    if(!pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH)
5919    {
5920       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5921       return RFAILED;
5922    }
5923
5924    if(pdschServCellDb == NULLP)
5925    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = PDSCH_NUM_HARQ_PROC;
5926    else
5927    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = pdschServCellDb->numHarqProcForPdsch;
5928
5929    pdschCfg->choice.setup->pucch_Cell = NULLP;
5930
5931    /* Extension */
5932    pdschCfg->choice.setup->ext1 = NULLP;
5933    if(pdschServCellDb && pdschServCellDb->maxMimoLayers)
5934    {
5935       DU_ALLOC(pdschCfg->choice.setup->ext1, sizeof(struct PDSCH_ServingCellConfig__ext1));
5936       if(pdschCfg->choice.setup->ext1 == NULLP)
5937       {
5938          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5939          return RFAILED;
5940       }
5941
5942       DU_ALLOC(pdschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5943       if(pdschCfg->choice.setup->ext1->maxMIMO_Layers == NULLP)
5944       {
5945          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5946          return RFAILED;
5947       }
5948       *(pdschCfg->choice.setup->ext1->maxMIMO_Layers) = *(pdschServCellDb->maxMimoLayers);
5949    }
5950
5951    return ROK;
5952 }
5953
5954 /*******************************************************************
5955  *
5956  * @brief Builds CSI Meas config
5957  * @details
5958  *
5959  *    Function : BuildCsiMeasCfg 
5960  *
5961  *    Functionality: Builds CSI Meas config in spCellCfgDed
5962  *
5963  * @params[in] struct ServingCellConfig__csi_MeasConfig *csiMeasCfg
5964  *
5965  * @return ROK     - success
5966  *         RFAILED - failure
5967  *
5968  * ****************************************************************/
5969 uint8_t BuildCsiMeasCfg(struct ServingCellConfig__csi_MeasConfig *csiMeasCfg)
5970 {
5971
5972    return ROK;
5973 }
5974
5975 /*******************************************************************
5976  *
5977  * @brief Builds DL BWP to add/modify list
5978  * @details
5979  *
5980  *    Function : BuildDlBwpToAddModList
5981  *
5982  *    Functionality: Builds DL BWP to add/modify list
5983  *
5984  * @params[in] ServCellCfgInfo *servCellCfg, 
5985  *             struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList
5986  *
5987  * @return ROK     - success
5988  *         RFAILED - failure
5989  *
5990  * ****************************************************************/ 
5991 uint8_t BuildDlBwpToAddModList(ServCellCfgInfo *servCellCfg, struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList)
5992 {
5993    uint8_t elementCnt, idx;
5994
5995    elementCnt = servCellCfg->numDlBwpToAdd;
5996    dlBwpAddModList->list.count = elementCnt;
5997    dlBwpAddModList->list.size = elementCnt * sizeof(struct BWP_Downlink *);
5998    dlBwpAddModList->list.array = NULLP;
5999    DU_ALLOC(dlBwpAddModList->list.array, dlBwpAddModList->list.size);
6000    if(dlBwpAddModList->list.array == NULLP)
6001    {
6002       DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6003       return RFAILED;
6004    }
6005
6006    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6007    {
6008       DU_ALLOC(dlBwpAddModList->list.array[idx], sizeof(BWP_Downlink_t));
6009       if(dlBwpAddModList->list.array[idx] == NULLP)
6010       {
6011          DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6012          return RFAILED;
6013       }
6014    }
6015
6016    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6017    {
6018       dlBwpAddModList->list.array[idx]->bwp_Id = servCellCfg->DlBwpToAddList[idx].bwpId;
6019       dlBwpAddModList->list.array[idx]->bwp_Common = NULLP;
6020       dlBwpAddModList->list.array[idx]->bwp_Dedicated = NULLP;
6021    }
6022    return ROK;
6023 }
6024
6025 /*******************************************************************
6026  *
6027  * @brief Builds Spcell config dedicated
6028  * @details
6029  *
6030  *    Function : BuildSpCellCfgDed
6031  *
6032  *    Functionality: Builds sp cell config dedicated in spCellCfg
6033  *
6034  * @params[in] ServingCellConfig_t srvCellCfg
6035  *
6036  * @return ROK     - success
6037  *         RFAILED - failure
6038  *
6039  * ****************************************************************/
6040 uint8_t BuildSpCellCfgDed(DuUeCb *ueCb, ServingCellConfig_t *srvCellCfg)
6041 {
6042    ServCellCfgInfo *servCellCfg = NULLP;
6043    InitialDlBwp *initDlBwp = NULLP;
6044    PdschServCellCfg *pdschServCellDb = NULLP;
6045
6046    if(ueCb)
6047    {
6048       servCellCfg = &ueCb->macUeCfg.spCellCfg.servCellCfg;
6049       initDlBwp = &servCellCfg->initDlBwp;
6050       pdschServCellDb = &servCellCfg->pdschServCellCfg;
6051    }
6052
6053    srvCellCfg->tdd_UL_DL_ConfigurationDedicated = NULLP;
6054    DU_ALLOC(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
6055    if(!srvCellCfg->tdd_UL_DL_ConfigurationDedicated)
6056    {
6057       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6058       return RFAILED;
6059    }
6060
6061    srvCellCfg->initialDownlinkBWP = NULLP;
6062    DU_ALLOC(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
6063    if(!srvCellCfg->initialDownlinkBWP)
6064    {
6065       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6066       return RFAILED;
6067    }
6068
6069    if(BuildInitialDlBWP(initDlBwp, srvCellCfg->initialDownlinkBWP) != ROK)
6070    {
6071       DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6072       return RFAILED;
6073    }
6074
6075    srvCellCfg->downlinkBWP_ToReleaseList = NULLP;
6076
6077    srvCellCfg->downlinkBWP_ToAddModList = NULLP;
6078    if(ueCb && ueCb->macUeCfg.spCellCfg.servCellCfg.numDlBwpToAdd)
6079    {
6080       DU_ALLOC(srvCellCfg->downlinkBWP_ToAddModList, sizeof(struct ServingCellConfig__downlinkBWP_ToAddModList));
6081       if(srvCellCfg->downlinkBWP_ToAddModList == NULLP)
6082       {
6083          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6084          return RFAILED;
6085       }
6086
6087       if(BuildDlBwpToAddModList(&ueCb->macUeCfg.spCellCfg.servCellCfg, srvCellCfg->downlinkBWP_ToAddModList) != ROK)
6088       {
6089          DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6090          return RFAILED;
6091       }
6092    }
6093
6094    srvCellCfg->firstActiveDownlinkBWP_Id = NULLP;
6095    DU_ALLOC(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
6096    if(!srvCellCfg->firstActiveDownlinkBWP_Id)
6097    {
6098       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6099       return RFAILED;
6100    }
6101    if(ueCb == NULLP)
6102       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6103    else
6104       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ueCb->macUeCfg.spCellCfg.servCellCfg.firstActvDlBwpId;
6105
6106    srvCellCfg->bwp_InactivityTimer = NULLP;
6107
6108    srvCellCfg->defaultDownlinkBWP_Id = NULLP;
6109    DU_ALLOC(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
6110    if(!srvCellCfg->defaultDownlinkBWP_Id)
6111    {
6112       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6113       return RFAILED;
6114    }
6115    if(ueCb == NULLP)
6116       *(srvCellCfg->defaultDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6117    else
6118       *(srvCellCfg->defaultDownlinkBWP_Id) = ueCb->macUeCfg.spCellCfg.servCellCfg.defaultDlBwpId;
6119
6120    srvCellCfg->uplinkConfig = NULLP;
6121    DU_ALLOC(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));
6122    if(!srvCellCfg->uplinkConfig)
6123    {
6124       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6125       return RFAILED;
6126    }
6127
6128    if(BuildUlCfg(servCellCfg, srvCellCfg->uplinkConfig) != ROK)
6129    {
6130       DU_LOG("\nERROR  -->  F1AP : BuildUlCfg failed");
6131       return RFAILED;
6132    }
6133    srvCellCfg->supplementaryUplink = NULLP;
6134    srvCellCfg->pdcch_ServingCellConfig = NULLP;
6135
6136    srvCellCfg->pdsch_ServingCellConfig = NULLP;
6137    DU_ALLOC(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct  ServingCellConfig__pdsch_ServingCellConfig));
6138    if(!srvCellCfg->pdsch_ServingCellConfig)
6139    {
6140       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6141       return RFAILED;
6142    }
6143
6144    if(BuildPdschSrvCellCfg(pdschServCellDb, srvCellCfg->pdsch_ServingCellConfig) != ROK)
6145    {
6146       DU_LOG("\nERROR  -->  F1AP : BuildPdschSrvCellCfg failed");
6147       return RFAILED;
6148    }
6149
6150    srvCellCfg->csi_MeasConfig = NULLP;
6151 #if 0
6152    DU_ALLOC(srvCellCfg->csi_MeasConfig, sizeof(struct   ServingCellConfig__csi_MeasConfig))
6153       if(!srvCellCfg->csi_MeasConfig)
6154       {
6155          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6156          return RFAILED;
6157       }
6158
6159    if(BuildCsiMeasCfg(srvCellCfg->csi_MeasConfig) != ROK)
6160    {
6161       DU_LOG("\nF1AP : BuildCsiMeasCfg failed");
6162       return RFAILED;
6163    }
6164 #endif
6165    srvCellCfg->sCellDeactivationTimer = NULLP;
6166    srvCellCfg->crossCarrierSchedulingConfig = NULLP;
6167    srvCellCfg->tag_Id = TAG_ID;
6168    srvCellCfg->dummy = NULLP;
6169    srvCellCfg->pathlossReferenceLinking = NULLP;
6170    srvCellCfg->servingCellMO = NULLP;
6171    srvCellCfg->ext1 = NULLP;
6172
6173    return ROK;
6174 }
6175
6176 /*******************************************************************
6177  *
6178  * @brief Fills SCS specific carrier list in DL frequency info
6179  *
6180  * @details
6181  *
6182  *    Function : BuildScsSpecificCarrierListDl
6183  *
6184  *    Functionality: Fills SCS specific carrier list in DL frequency info
6185  *
6186  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
6187  *
6188  * @return ROK     - success
6189  *         RFAILED - failure
6190  *
6191  * ****************************************************************/
6192 uint8_t BuildScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
6193 {
6194    uint8_t elementCnt = 0, listIdx = 0;
6195    ScsSpecCarrier duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.dlScsCarrier;
6196
6197    elementCnt = ODU_VALUE_ONE;
6198    scsCarrierList->list.count = elementCnt;
6199    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6200
6201    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6202    if(!scsCarrierList->list.array)
6203    {
6204       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for scs carrier list array \
6205          in BuildScsSpecificCarrierListDl()");
6206       return RFAILED;
6207    }
6208
6209    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6210    {
6211       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6212       if(!scsCarrierList->list.array[listIdx])
6213       {    
6214          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SCS Specific Carrier list array \
6215             element in BuildScsSpecificCarrierListDl()");
6216          return RFAILED;
6217       }    
6218    }
6219
6220    listIdx = 0;
6221    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6222    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6223    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6224
6225    return ROK;
6226 }
6227
6228 /*******************************************************************
6229  *
6230  * @brief Fills DL frequency info in DL config common
6231  *
6232  * @details
6233  *
6234  *    Function : BuildFreqInfoDl
6235  *
6236  *    Functionality: Fills DL frequency info in DL config common
6237  *
6238  * @params[in] Pointer to DownlinkConfigCommon_t
6239  *
6240  * @return ROK     - success
6241  *         RFAILED - failure
6242  *
6243  * ****************************************************************/
6244 uint8_t BuildFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
6245 {
6246    uint8_t freqBandIdx = 0, elementCnt = 0;
6247    DlCfgCommon  dlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg;
6248
6249    /* TODO : Fill SSB Absolute Frequency */
6250    /*
6251       DU_ALLOC(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
6252       if(!frequencyInfoDL->absoluteFrequencySSB)
6253       {
6254       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB Absolute Frequency in BuildFreqInfoDl()");
6255       return RFAILED;
6256       }
6257       frequencyInfoDL->absoluteFrequencySSB = ?;
6258       */
6259
6260    /* NR Multi Frequency Band List */
6261    elementCnt = ODU_VALUE_ONE;
6262    frequencyInfoDL->frequencyBandList.list.count = elementCnt;
6263    frequencyInfoDL->frequencyBandList.list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6264
6265    DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
6266    if(!frequencyInfoDL->frequencyBandList.list.array)
6267    {
6268       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for Frequency Band List array in BuildFreqInfoDl()");
6269       return RFAILED;
6270    }
6271
6272    for(freqBandIdx = 0; freqBandIdx < elementCnt; freqBandIdx++)
6273    {
6274       DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
6275       if(!frequencyInfoDL->frequencyBandList.list.array[freqBandIdx])
6276       {
6277          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoDl()");
6278          return RFAILED;
6279       }
6280    }
6281
6282    freqBandIdx = 0;
6283    *(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx]) = dlCfg.freqBandInd;
6284
6285    /* TODO : Absolute Frequency to Point A */
6286    //frequencyInfoDL->absoluteFrequencyPointA
6287
6288    /* Subcarrier Spacing specifc carrier List */
6289    if((BuildScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList)) != ROK)
6290    {
6291       DU_LOG("\nERROR  -->  DU APP : Failed to fill SCS specific carrier list DL in BuildFreqInfoDl()");
6292       return RFAILED;
6293    }
6294
6295    return ROK;
6296
6297 }
6298
6299 /*******************************************************************
6300  *
6301  * @brief Fills DL config common in Serving cell config common
6302  *
6303  * @details
6304  *
6305  *    Function : BuildDlConfigCommon
6306  *
6307  *    Functionality: Fills DL config common in Serving cell config common
6308  *
6309  * @params[in] Pointer to DownlinkConfigCommon_t
6310  *
6311  * @return ROK     - success
6312  *         RFAILED - failure
6313  *
6314  * ****************************************************************/
6315 uint8_t BuildDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
6316 {
6317    /* DL Frequency Info */
6318    DU_ALLOC(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
6319    if(!dlCfgCommon->frequencyInfoDL)
6320    {
6321       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL frequency info in BuildDlConfigCommon()");
6322       return RFAILED;
6323    }
6324    if((BuildFreqInfoDl(dlCfgCommon->frequencyInfoDL))!= ROK)
6325    {
6326       DU_LOG("\nERROR  --> DU APP : Failed to fill DL frequency info in BuildDlConfigCommon()");
6327       return RFAILED;
6328    }
6329
6330    /* DL BWP config common */
6331    DU_ALLOC(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
6332    if(!dlCfgCommon->initialDownlinkBWP)
6333    {
6334       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL BWP config common in BuildDlConfigCommon()");
6335       return RFAILED;
6336    }
6337    if((BuildBwpDlCommon(dlCfgCommon->initialDownlinkBWP)) != ROK)
6338    {
6339       DU_LOG("\nERROR  --> DU APP : Failed to fill DL DWP config common in BuildDlConfigCommon()");
6340       return RFAILED;
6341    }
6342
6343    return ROK;
6344 }
6345
6346 /*******************************************************************
6347  *
6348  * @brief Fills SCS specific carrier list in UL frequency Info
6349  *
6350  * @details
6351  *
6352  *    Function : BuildScsSpecificCarrierListUl
6353  *
6354  *    Functionality: Fills SCS specific carrier list in UL frequency Info
6355  *
6356  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
6357  *
6358  * @return ROK     - success
6359  *         RFAILED - failure
6360  *
6361  * ****************************************************************/
6362 uint8_t BuildScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
6363 {
6364    uint8_t elementCnt = 0, listIdx = 0; 
6365    ScsSpecCarrier   duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.ulScsCarrier;
6366
6367    elementCnt = ODU_VALUE_ONE;
6368    scsCarrierList->list.count = elementCnt;
6369    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6370
6371    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6372    if(!scsCarrierList->list.array)
6373    {
6374       DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6375       return RFAILED;
6376    }
6377
6378    for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
6379    {
6380       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6381       if(!scsCarrierList->list.array[listIdx])
6382       {    
6383          DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6384          return RFAILED;
6385       }    
6386    }
6387    listIdx = 0; 
6388    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6389    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6390    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6391
6392    return ROK;
6393 }
6394
6395 /*******************************************************************
6396  *
6397  * @brief Fills frequency info in UL config common
6398  *
6399  * @details
6400  *
6401  *    Function : BuildFreqInfoUl
6402  *
6403  *    Functionality: Fills frequency info in UL config common
6404  *
6405  * @params[in] Pointer to FrequencyInfoUL_t
6406  *
6407  * @return ROK     - success
6408  *         RFAILED - failure
6409  *
6410  * ****************************************************************/
6411 uint8_t BuildFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
6412 {
6413    uint8_t elementCnt = 0, listIdx= 0;
6414    UlCfgCommon  ulCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg;
6415
6416    /* NR Multi Frequency Band List */
6417    DU_ALLOC(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
6418    if(!frequencyInfoUL->frequencyBandList)
6419    {
6420       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band list in BuildFreqInfoUl()");
6421       return RFAILED;
6422    }
6423
6424    elementCnt = ODU_VALUE_ONE;
6425    frequencyInfoUL->frequencyBandList->list.count = elementCnt;
6426    frequencyInfoUL->frequencyBandList->list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6427
6428    DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
6429    if(!frequencyInfoUL->frequencyBandList->list.array)
6430    {
6431       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array in BuildFreqInfoUl()");
6432       return RFAILED;
6433    }
6434
6435    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6436    {
6437       DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
6438       if(!frequencyInfoUL->frequencyBandList->list.array[listIdx])
6439       {
6440          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoUl()");
6441          return RFAILED;
6442       }
6443    }
6444
6445    listIdx = 0;
6446    *(frequencyInfoUL->frequencyBandList->list.array[listIdx]) = ulCfg.freqBandInd;
6447
6448    /* TODO : Fill Absolute frequency point A */
6449    /*
6450       DU_ALLOC(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
6451       if(!frequencyInfoUL->absoluteFrequencyPointA)
6452       {
6453       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for absolute frequency point A in BuildFreqInfoUl()");
6454       return RFAILED;
6455       }
6456     *(frequencyInfoUL->absoluteFrequencyPointA) = ?;
6457     */
6458
6459    /* Subcarrier Spacing specifc carrier */
6460    if((BuildScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList)) != ROK) 
6461    {
6462       DU_LOG("\nERROR  --> DU APP : Failed to fill SCS Specific Carrier list UL in BuildFreqInfoUl()");
6463       return RFAILED;
6464    }
6465
6466    /* P-MAX */
6467    DU_ALLOC(frequencyInfoUL->p_Max, sizeof(P_Max_t));
6468    if(!frequencyInfoUL->p_Max)
6469    {
6470       DU_LOG("\nERROR  -->  DU APP : UL Frequency Infoo  memory allocation failure");
6471       return RFAILED;
6472    }
6473    *frequencyInfoUL->p_Max = ulCfg.pMax;
6474
6475    return ROK;
6476 }
6477
6478 /*******************************************************************
6479  *
6480  * @brief Fills UL config common in Serving cell config common
6481  *
6482  * @details
6483  *
6484  *    Function : BuildUlConfigCommon
6485  *
6486  *    Functionality: Fills UL config common in Serving cell config common
6487  *
6488  * @params[in] Pointer to UplinkConfigCommon_t
6489  *
6490  * @return ROK     - success
6491  *         RFAILED - failure
6492  *
6493  * ****************************************************************/
6494 uint8_t BuildUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
6495 {
6496    /* UL Frequency Info */
6497    DU_ALLOC(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
6498    if(!ulCfgCommon->frequencyInfoUL)
6499    {
6500       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for UL frequency info in BuildUlConfigCommon()");
6501       return RFAILED;
6502    }
6503
6504    if((BuildFreqInfoUl(ulCfgCommon->frequencyInfoUL)) != ROK)
6505    {
6506       DU_LOG("\nERROR  -->  DU APP : Failed to fill frequency info UL in BuildUlConfigCommon()");
6507       return RFAILED;
6508    }
6509
6510    /* UL BWP common */
6511    DU_ALLOC(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
6512    if(!ulCfgCommon->initialUplinkBWP)
6513    {
6514       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for initial UL BWP in BuildUlConfigCommon()");
6515       return RFAILED;
6516    }
6517
6518    if((BuildBwpUlCommon(ulCfgCommon->initialUplinkBWP)) != ROK)
6519    {
6520       DU_LOG("\nERROR  -->  DU APP : Failed to fill BWP UL common in BuildUlConfigCommon()");
6521       return RFAILED;
6522    }
6523
6524    /* Time Alignment timer */
6525    ulCfgCommon->dummy = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.timeAlignTimerComm;
6526
6527    return ROK;
6528 }
6529
6530 /*******************************************************************
6531  *
6532  * @brief Fills SSB position in burst in SP cell config common
6533  *
6534  * @details
6535  *
6536  *    Function : BuildSsbPosInBurst
6537  *
6538  *    Functionality: 
6539  *       Fills SSB position in burst in SP cell config common
6540  *
6541  * @params[in] Pointer to struct ServingCellConfigCommon__ssb_PositionsInBurst
6542  *
6543  * @return ROK     - success
6544  *         RFAILED - failure
6545  *
6546  * ****************************************************************/
6547 uint8_t BuildSsbPosInBurst(struct ServingCellConfigCommon__ssb_PositionsInBurst *ssbPosInBurst)
6548 {
6549    uint8_t bitStringSizeInBytes = 0;
6550
6551    ssbPosInBurst->present = ServingCellConfigCommon__ssb_PositionsInBurst_PR_mediumBitmap;
6552
6553    /* As per spec 38.331,in the definition of ServingCellConfigCommon */
6554    bitStringSizeInBytes = 1;
6555    ssbPosInBurst->choice.mediumBitmap.size = bitStringSizeInBytes * sizeof(uint8_t);
6556
6557    DU_ALLOC(ssbPosInBurst->choice.mediumBitmap.buf, ssbPosInBurst->choice.mediumBitmap.size);
6558    if(!ssbPosInBurst->choice.mediumBitmap.buf)
6559    {
6560       DU_LOG("\nERROR  -->  DU APP : Memory Allocation failed for medium bit map buffer in BuildSsbPosInBurst()");
6561       return RFAILED;
6562    }
6563
6564    if((fillBitString(&ssbPosInBurst->choice.mediumBitmap, 0, bitStringSizeInBytes, \
6565                duCfgParam.sib1Params.srvCellCfgCommSib.ssbPosInBurst)) != ROK)
6566    {
6567       DU_LOG("\nERROR  -->  DU APP : Failed to fill medium bit map in BuildSsbPosInBurst()");
6568       return RFAILED;
6569    }
6570
6571    return ROK;
6572 }
6573
6574 /*******************************************************************
6575  *
6576  * @brief Fills SP cell config common in Reconfig with Sync
6577  *
6578  * @details
6579  *
6580  *    Function : BuildSpCellConfigCommon
6581  *
6582  *    Functionality: Fills SP cell config common in Reconfig with Sync
6583  *
6584  * @params[in] Pointer to ServingCellConfigCommon_t
6585  *
6586  * @return ROK     - success
6587  *         RFAILED - failure
6588  *
6589  * ****************************************************************/
6590 uint8_t BuildSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
6591 {
6592    /* Physical Cell Identity */
6593    DU_ALLOC(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
6594    if(!spCellConfigCommon->physCellId)
6595    {
6596       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for physical cell id in BuildSpCellConfigCommon()");
6597       return RFAILED;
6598    } 
6599    *(spCellConfigCommon->physCellId) = NR_PCI;
6600
6601    /* Downlink Config Common */
6602    DU_ALLOC(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
6603    if(!spCellConfigCommon->downlinkConfigCommon)
6604    {
6605       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for DL Config Common in BuildSpCellConfigCommon()");
6606       return RFAILED;
6607    }
6608    if((BuildDlConfigCommon(spCellConfigCommon->downlinkConfigCommon)) != ROK)
6609    {
6610       DU_LOG("\nERROR  -->  DU APP : Failed to fill DL config commin in BuildSpCellConfigCommon()");
6611       return RFAILED;
6612    }
6613
6614    /* Uplinlink Config Common */
6615    DU_ALLOC(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
6616    if(!spCellConfigCommon->uplinkConfigCommon)
6617    {
6618       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for UL Config Common in BuildSpCellConfigCommon()");
6619       return RFAILED;
6620    }
6621    if((BuildUlConfigCommon(spCellConfigCommon->uplinkConfigCommon)) != ROK)
6622    {
6623       DU_LOG("\nERROR  -->  DU APP : Failed to fill UL config commin in BuildSpCellConfigCommon()");
6624       return RFAILED;
6625    }
6626
6627    /* Timing Advance offset */
6628    DU_ALLOC(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
6629    if(!spCellConfigCommon->n_TimingAdvanceOffset)
6630    {
6631       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for Timing Advance Offset in BuildSpCellConfigCommon()");
6632       return RFAILED;
6633    }
6634    *(spCellConfigCommon->n_TimingAdvanceOffset) = ServingCellConfigCommon__n_TimingAdvanceOffset_n0;
6635
6636    /* SSB Position In Burst */
6637    DU_ALLOC(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
6638    if(!spCellConfigCommon->ssb_PositionsInBurst)
6639    {
6640       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Position In Burst in BuildSpCellConfigCommon()");
6641       return RFAILED;
6642    }
6643    if((BuildSsbPosInBurst(spCellConfigCommon->ssb_PositionsInBurst)) != ROK)
6644    {
6645       DU_LOG("\nERROR  -->  DU APP : Failed to fill SSB Position In Burst in BuildSpCellConfigCommon()");
6646       return RFAILED;
6647    }
6648
6649    /* SSB Periodicity in Serving cell */
6650    DU_ALLOC(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
6651    if(!spCellConfigCommon->ssb_periodicityServingCell)
6652    {
6653       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Periodicity serving cell in \
6654          BuildSpCellConfigCommon()");
6655       return RFAILED;
6656    }
6657    *(spCellConfigCommon->ssb_periodicityServingCell) = \
6658       convertSsbPeriodicityValueToEnum(duCfgParam.sib1Params.srvCellCfgCommSib.ssbPrdServingCell);
6659
6660    /* DMRS Type A position */
6661    spCellConfigCommon->dmrs_TypeA_Position = convertDmrsTypeAPosValueToEnum(duCfgParam.macCellCfg.dmrsTypeAPos);
6662
6663    /* SSB subcarrier spacing */
6664    DU_ALLOC(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
6665    if(!spCellConfigCommon->ssbSubcarrierSpacing)
6666    {
6667       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for sub-carrier spacing in BuildSpCellConfigCommon()");
6668       return RFAILED;
6669    }
6670    *(spCellConfigCommon->ssbSubcarrierSpacing) = duCfgParam.sib1Params.srvCellCfgCommSib.scs;
6671
6672    /* TDD UL-DL configuration common */
6673    DU_ALLOC(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
6674    if(!spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)
6675    {
6676       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for TDD UL-DL config common in BuildSpCellConfigCommon()");
6677       return RFAILED;
6678    }
6679    if((BuildTddUlDlCfgComm(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)) != ROK)
6680    {
6681       DU_LOG("\nERROR  -->  DU APP : Failed to fill TDD UL-DL config common in BuildSpCellConfigCommon()");
6682       return RFAILED;
6683    }
6684
6685    /* SS PBCH Block Power */
6686    spCellConfigCommon->ss_PBCH_BlockPower = duCfgParam.sib1Params.srvCellCfgCommSib.ssPbchBlockPwr;
6687
6688    return ROK;
6689 }
6690
6691 /*******************************************************************
6692  *
6693  * @brief Fills dedicated RACH configuration in Reconfiguration with sync
6694  *
6695  * @details
6696  *
6697  *    Function : BuildRecfgWithSync
6698  *
6699  *    Functionality: 
6700  *       Fills dedicated RACH configuration in Reconfiguration with sync
6701  *
6702  * @params[in] DU UE CB
6703  *             Pointer to Rach config dedicated struct
6704  *
6705  * @return ROK     - success
6706  *         RFAILED - failure
6707  *
6708  * ****************************************************************/
6709 uint8_t BuildRachConfigDedicated(DuUeCb *ueCb, struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
6710 {
6711    uint8_t elementCnt = 0, listIdx = 0;
6712    CFRA_t *cfra = NULLP;
6713    struct CFRA__resources__ssb *ssbResource = NULLP;
6714    RachCfgCommon duRachCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.rachCfg;
6715
6716    rachCfgDed->present = ReconfigurationWithSync__rach_ConfigDedicated_PR_uplink;
6717
6718    /* Uplink */
6719    DU_ALLOC(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
6720    if(!rachCfgDed->choice.uplink)
6721    {
6722       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for RACH uplink configuration in BuildRachConfigDedicated()");
6723       return RFAILED;
6724    }
6725
6726    /* CFRA : Contention free Random Access */
6727    DU_ALLOC(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
6728    if(!rachCfgDed->choice.uplink->cfra)
6729    {
6730       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA in BuildRachConfigDedicated()");
6731       return RFAILED;
6732    }
6733    cfra = rachCfgDed->choice.uplink->cfra;
6734
6735    /* CFRA occassions */
6736    DU_ALLOC(cfra->occasions, sizeof(struct CFRA__occasions));
6737    if(!cfra->occasions)
6738    {
6739       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA occassion in BuildRachConfigDedicated()");
6740       return RFAILED;
6741    }
6742
6743    /* CFRA occassions : RACH generic configuration */
6744    cfra->occasions->rach_ConfigGeneric.prach_ConfigurationIndex = duRachCfg.prachCfgIdx;
6745    cfra->occasions->rach_ConfigGeneric.msg1_FDM = duRachCfg.msg1Fdm;
6746    cfra->occasions->rach_ConfigGeneric.msg1_FrequencyStart = duRachCfg.msg1FreqStart;
6747    cfra->occasions->rach_ConfigGeneric.zeroCorrelationZoneConfig = duRachCfg.zeroCorrZoneCfg;
6748    cfra->occasions->rach_ConfigGeneric.preambleReceivedTargetPower = duRachCfg.preambleRcvdTgtPwr;
6749    cfra->occasions->rach_ConfigGeneric.preambleTransMax = duRachCfg.preambleTransMax;
6750    cfra->occasions->rach_ConfigGeneric.powerRampingStep = duRachCfg.pwrRampingStep;
6751    cfra->occasions->rach_ConfigGeneric.ra_ResponseWindow = duRachCfg.raRspWindow;
6752
6753    /* CFRA occassions : SSB per RACH occasion */
6754    DU_ALLOC(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
6755    if(!cfra->occasions->ssb_perRACH_Occasion)
6756    {
6757       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB per RACH occassion in BuildRachConfigDedicated()");
6758       return RFAILED;
6759    }
6760    *(cfra->occasions->ssb_perRACH_Occasion) = convertCFRASsbPerRachOccasionValueToEnum(duCfgParam.macCellCfg.prachCfg.ssbPerRach);
6761
6762    /* CFRA resource */
6763    cfra->resources.present = CFRA__resources_PR_ssb;
6764
6765    /* CFRA resource : SSB */
6766    DU_ALLOC(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
6767    if(!cfra->resources.choice.ssb)
6768    {
6769       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA resource - SSB in BuildRachConfigDedicated()");
6770       return RFAILED;
6771    }
6772    ssbResource = cfra->resources.choice.ssb;
6773
6774    /* CFRA SSB resource list */
6775    elementCnt = ueCb->cfraResource.numSsb;
6776    ssbResource->ssb_ResourceList.list.count = elementCnt;
6777    ssbResource->ssb_ResourceList.list.size = elementCnt * sizeof(CFRA_SSB_Resource_t *);
6778
6779    DU_ALLOC(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
6780    if(!ssbResource->ssb_ResourceList.list.array)
6781    {
6782       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list in BuildRachConfigDedicated()");
6783       return RFAILED;
6784    }
6785
6786    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6787    {
6788       DU_ALLOC(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
6789       if(!ssbResource->ssb_ResourceList.list.array[listIdx])
6790       {
6791          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list element in BuildRachConfigDedicated()");  
6792          return RFAILED;
6793       }
6794       ssbResource->ssb_ResourceList.list.array[listIdx]->ssb = ueCb->cfraResource.ssbResource[listIdx].ssbIdx;
6795       ssbResource->ssb_ResourceList.list.array[listIdx]->ra_PreambleIndex = ueCb->cfraResource.ssbResource[listIdx].raPreambleIdx;
6796    }
6797
6798    return ROK;
6799 }
6800
6801 /*******************************************************************
6802  *
6803  * @brief Fills reconfiguration with sync in SP cell config
6804  *
6805  * @details
6806  *
6807  *    Function : BuildRecfgWithSync
6808  *
6809  *    Functionality: Fills reconfiguration with sync in SP cell config
6810  *
6811  * @params[in] DU UE CB
6812  *             Pointer to ReconfigurationWithSync_t
6813  *
6814  * @return ROK     - success
6815  *         RFAILED - failure
6816  *
6817  * ****************************************************************/
6818 uint8_t BuildRecfgWithSync(DuUeCb *ueCb, ReconfigurationWithSync_t *recfgWithSync)
6819 {
6820    /* SP Cell Config Common */  
6821    DU_ALLOC(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
6822    if(!recfgWithSync->spCellConfigCommon)
6823    {
6824       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for spCellConfigCommon in BuildRecfgWithSync()");
6825       return RFAILED;
6826    }
6827
6828    if((BuildSpCellConfigCommon(recfgWithSync->spCellConfigCommon)) != ROK)
6829    {
6830       DU_LOG("\nERROR  -->  DU APP : Failed to build SpCellConfigCommon in BuildRecfgWithSync()");
6831       return RFAILED;
6832    }
6833
6834    /* New UE Identity */
6835    recfgWithSync->newUE_Identity = ueCb->crnti;
6836
6837    /* T304 timer */
6838    recfgWithSync->t304 = ReconfigurationWithSync__t304_ms1000;
6839
6840    /* RACH configuration dedicated */
6841    DU_ALLOC(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
6842    if(!recfgWithSync->rach_ConfigDedicated)
6843    {
6844       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for RACH config dedicated in BuildRecfgWithSync()");
6845       return RFAILED;
6846    }
6847
6848    if((BuildRachConfigDedicated(ueCb, recfgWithSync->rach_ConfigDedicated)) != ROK)
6849    {
6850       DU_LOG("\nERROR  -->  DU APP : Failed to build RACH config dedicated in BuildRecfgWithSync()");
6851       return RFAILED;
6852    }
6853
6854    return ROK;
6855 }
6856
6857 /*******************************************************************
6858  *
6859  * @brief Builds Spcell config 
6860  *
6861  * @details
6862  *
6863  *    Function : BuildSpCellCfg 
6864  *
6865  *    Functionality: Builds sp cell config in DuToCuRrcContainer
6866  *
6867  * @params[in] SpCellConfig_t spCellCfg
6868  *
6869  * @return ROK     - success
6870  *         RFAILED - failure
6871  *
6872  * ****************************************************************/
6873 uint8_t BuildSpCellCfg(DuUeCb *ueCb, SpCellConfig_t *spCellCfg)
6874 {
6875    spCellCfg->servCellIndex = NULLP;
6876    DU_ALLOC(spCellCfg->servCellIndex, sizeof(long));
6877    if(!spCellCfg->servCellIndex)
6878    {
6879       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6880       return RFAILED;
6881    }
6882
6883    if(ueCb == NULLP)
6884       *(spCellCfg->servCellIndex) = SERV_CELL_IDX;
6885    else
6886       *(spCellCfg->servCellIndex) = ueCb->macUeCfg.spCellCfg.servCellIdx;
6887
6888    spCellCfg->reconfigurationWithSync = NULLP;
6889    if(ueCb && (ueCb->ueState == UE_HANDIN_IN_PROGRESS))
6890    {
6891       DU_ALLOC(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
6892       if(!spCellCfg->reconfigurationWithSync)
6893       {
6894          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6895          return RFAILED;
6896       }
6897
6898       if((BuildRecfgWithSync(ueCb, spCellCfg->reconfigurationWithSync)) != ROK)
6899       {
6900          DU_LOG("\nERROR  -->  F1AP : Building of reconfiguration with sync failed at BuildSpCellCfg");
6901          return RFAILED;
6902       }
6903    }
6904
6905    spCellCfg->rlf_TimersAndConstants = NULLP;
6906    spCellCfg->rlmInSyncOutOfSyncThreshold = NULLP;
6907
6908    DU_ALLOC(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
6909    if(!spCellCfg->rlmInSyncOutOfSyncThreshold)
6910    {
6911       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6912       return RFAILED;
6913    }
6914    *(spCellCfg->rlmInSyncOutOfSyncThreshold) = RLM_SYNC_OUT_SYNC_THRESHOLD;
6915
6916    spCellCfg->spCellConfigDedicated = NULLP;
6917    DU_ALLOC(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
6918    if(!spCellCfg->spCellConfigDedicated)
6919    {
6920       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6921       return RFAILED;
6922    }
6923    if(BuildSpCellCfgDed(ueCb, spCellCfg->spCellConfigDedicated) != ROK)
6924    {
6925       DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfgDed failed");
6926       return RFAILED;
6927    }
6928
6929    return ROK;
6930 }
6931
6932 /*******************************************************************
6933  *
6934  * @brief Builds Phy cell group config 
6935  *
6936  * @details
6937  *
6938  *    Function : BuildPhyCellGrpCfg 
6939  *
6940  *    Functionality: Builds Phy cell group config in DuToCuRrcContainer
6941  *
6942  * @params[in] PhysicalCellGroupConfig_t *phyCellGrpCfg 
6943  *
6944  * @return ROK     - success
6945  *         RFAILED - failure
6946  *
6947  * ****************************************************************/
6948 uint8_t BuildPhyCellGrpCfg(DuUeCb *ueCb, PhysicalCellGroupConfig_t *phyCellGrpCfg)
6949 {
6950    phyCellGrpCfg->harq_ACK_SpatialBundlingPUCCH = NULLP;
6951    phyCellGrpCfg->harq_ACK_SpatialBundlingPUSCH = NULLP;
6952
6953    phyCellGrpCfg->p_NR_FR1 = NULLP;
6954    DU_ALLOC(phyCellGrpCfg->p_NR_FR1, sizeof(long));
6955    if(!phyCellGrpCfg->p_NR_FR1)
6956    {
6957       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhyCellGrpCfg");
6958       return RFAILED;
6959    }
6960
6961    if(ueCb == NULLP)
6962    {
6963       *(phyCellGrpCfg->p_NR_FR1)             = P_NR_FR1;
6964       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = PDSCH_HARQ_ACK_CODEBOOK;
6965    }
6966    else
6967    {
6968       *(phyCellGrpCfg->p_NR_FR1) = ueCb->macUeCfg.phyCellGrpCfg.pNrFr1;
6969       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = ueCb->macUeCfg.phyCellGrpCfg.pdschHarqAckCodebook;
6970    }
6971
6972    phyCellGrpCfg->tpc_SRS_RNTI = NULLP;
6973    phyCellGrpCfg->tpc_PUCCH_RNTI = NULLP;
6974    phyCellGrpCfg->tpc_PUSCH_RNTI = NULLP;
6975    phyCellGrpCfg->sp_CSI_RNTI = NULLP;
6976    phyCellGrpCfg->cs_RNTI = NULLP;
6977    phyCellGrpCfg->ext1 = NULLP;
6978    phyCellGrpCfg->ext2 = NULLP;
6979
6980    return ROK;
6981 }
6982 #ifdef NR_DRX
6983 /*******************************************************************
6984  *
6985  * @brief fill long cycle offset value of drx
6986  *
6987  * @details
6988  *
6989  *    Function : fillLongCycleOffsetValFromDuCb 
6990  *
6991  *    Functionality: fill long cycle offset value of drx
6992  *
6993  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
6994  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
6995  *
6996  * @return ROK     - success
6997  *         RFAILED - failure
6998  *
6999  * ****************************************************************/
7000 void fillLongCycleOffsetValFromDuCb(DrxLongCycleStartOffset  drxLongCycleStartOffset,\
7001 struct DRX_ConfigRrc__drx_LongCycleStartOffset *drx_LongCycleStartOffset)
7002 {
7003    
7004    drx_LongCycleStartOffset->present = convertLongDrxCycleLengthValueToEnum(drxLongCycleStartOffset.drxLongCycleStartOffsetChoice); 
7005    switch(drx_LongCycleStartOffset->present)
7006    {
7007       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
7008          {
7009             drx_LongCycleStartOffset->choice.ms10 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7010             break;
7011          }
7012       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
7013          {
7014             drx_LongCycleStartOffset->choice.ms20 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7015             break;
7016          }
7017       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
7018          {
7019             drx_LongCycleStartOffset->choice.ms32 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7020             break;
7021          }
7022       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
7023          {
7024             drx_LongCycleStartOffset->choice.ms40 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7025             break;
7026          }
7027       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
7028          {
7029             drx_LongCycleStartOffset->choice.ms60 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7030             break;
7031          }
7032       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
7033          {
7034             drx_LongCycleStartOffset->choice.ms64 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7035             break;
7036          }
7037       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
7038          {
7039             drx_LongCycleStartOffset->choice.ms70 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7040             break;
7041          }
7042       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
7043          {
7044             drx_LongCycleStartOffset->choice.ms80 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7045             break;
7046          }
7047       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
7048          {
7049             drx_LongCycleStartOffset->choice.ms128 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7050             break;
7051          }
7052       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
7053          {
7054             drx_LongCycleStartOffset->choice.ms160 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7055             break;
7056          }
7057       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
7058          {
7059             drx_LongCycleStartOffset->choice.ms256 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7060             break;
7061          }
7062       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
7063          {
7064             drx_LongCycleStartOffset->choice.ms320 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7065             break;
7066          }
7067       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
7068          {
7069             drx_LongCycleStartOffset->choice.ms512 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7070             break;
7071          }
7072       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
7073          {
7074             drx_LongCycleStartOffset->choice.ms640 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7075             break;
7076          }
7077       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
7078          {
7079             drx_LongCycleStartOffset->choice.ms1024 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7080             break;
7081          }
7082       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
7083          {
7084             drx_LongCycleStartOffset->choice.ms1280 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7085             break;
7086          }
7087       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
7088          {
7089             drx_LongCycleStartOffset->choice.ms2048 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7090             break;
7091          }
7092       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
7093          {
7094             drx_LongCycleStartOffset->choice.ms2560 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7095             break;
7096          }
7097       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
7098          {
7099             drx_LongCycleStartOffset->choice.ms5120 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7100             break;
7101          }
7102       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
7103          {
7104             drx_LongCycleStartOffset->choice.ms10240 = drxLongCycleStartOffset.drxLongCycleStartOffsetVal;
7105             break;
7106          }
7107       default :
7108          break;
7109    }
7110 }
7111 /*******************************************************************
7112  *
7113  * @brief Builds drx config IE 
7114  *
7115  * @details
7116  *
7117  *    Function : BuildDrxConfigRrc 
7118  *
7119  *    Functionality: Build drx config in MacCellGrpCfg 
7120  *
7121  * @params[in] struct MAC_CellGroupConfig__drx_ConfigRrc 
7122  *
7123  * @return ROK     - success
7124  *         RFAILED - failure
7125  *
7126  * ****************************************************************/
7127 uint8_t BuildDrxConfigRrc(DuUeCb *ueCb, struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg)
7128 {
7129    drxCfg->present = MAC_CellGroupConfig__drx_ConfigRrc_PR_setup;
7130    DU_ALLOC(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
7131    if(!drxCfg->choice.setup)
7132    {
7133       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7134       return RFAILED;
7135    }
7136    if(ueCb->macUeCfg.macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationTimerValInMs)
7137    {
7138       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds;
7139       drxCfg->choice.setup->drx_onDurationTimer.choice.milliSeconds = convertOnDurationTimerMilliSecondsValueToEnum(ueCb->macUeCfg.\
7140       macCellGrpCfg.drxCfg.drxOnDurationTimer.onDurationtimerValue.milliSeconds);
7141    }
7142    else
7143    {
7144       drxCfg->choice.setup->drx_onDurationTimer.present = DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds;
7145       drxCfg->choice.setup->drx_onDurationTimer.choice.subMilliSeconds = ueCb->macUeCfg.macCellGrpCfg.drxCfg.\
7146       drxOnDurationTimer.onDurationtimerValue.subMilliSeconds;
7147    }
7148    drxCfg->choice.setup->drx_InactivityTimer = convertDrxInactivityTimerValueToEnum(ueCb->macUeCfg.macCellGrpCfg.drxCfg.drxInactivityTimer);
7149    drxCfg->choice.setup->drx_HARQ_RTT_TimerDL = ueCb->macUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerDl;
7150    drxCfg->choice.setup->drx_HARQ_RTT_TimerUL = ueCb->macUeCfg.macCellGrpCfg.drxCfg.drxHarqRttTimerUl;
7151    drxCfg->choice.setup->drx_RetransmissionTimerDL = convertDrxRetransmissionTimerDlValueToEnum(ueCb->macUeCfg.macCellGrpCfg.drxCfg.\
7152    drxRetransmissionTimerDl);
7153    drxCfg->choice.setup->drx_RetransmissionTimerUL = convertDrxRetransmissionTimerUlValueToEnum(ueCb->macUeCfg.macCellGrpCfg.drxCfg.\
7154    drxRetransmissionTimerUl);
7155    drxCfg->choice.setup->drx_SlotOffset = ueCb->macUeCfg.macCellGrpCfg.drxCfg.drxSlotOffset;
7156    fillLongCycleOffsetValFromDuCb(ueCb->macUeCfg.macCellGrpCfg.drxCfg.drxLongCycleStartOffset, &drxCfg->choice.setup->drx_LongCycleStartOffset);
7157    
7158    if(ueCb->macUeCfg.macCellGrpCfg.drxCfg.shortDrxPres)
7159    {
7160       DU_ALLOC(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));
7161       if(drxCfg->choice.setup->shortDRX)
7162       {
7163          drxCfg->choice.setup->shortDRX->drx_ShortCycle = convertShortDrxCycleLengthValueToEnum(ueCb->macUeCfg.macCellGrpCfg.drxCfg.\
7164          shortDrx.drxShortCycle);
7165          drxCfg->choice.setup->shortDRX->drx_ShortCycleTimer = ueCb->macUeCfg.macCellGrpCfg.drxCfg.shortDrx.drxShortCycleTimer;
7166       }
7167       else
7168       {
7169          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDrxConfigRrc");
7170          return RFAILED;
7171       }
7172    }
7173    return ROK;
7174 }
7175 #endif
7176 /*******************************************************************
7177  *
7178  * @brief Builds Mac cell group config 
7179  *
7180  * @details
7181  *
7182  *    Function : BuildMacCellGrpCfg 
7183  *
7184  *    Functionality: Builds Mac cell group config in DuToCuRrcContainer
7185  *
7186  * @params[in] MAC_CellGroupConfig_t *macCellGrpCfg
7187  *
7188  * @return ROK     - success
7189  *         RFAILED - failure
7190  *
7191  * ****************************************************************/
7192 uint8_t BuildMacCellGrpCfg(DuUeCb *ueCb, MAC_CellGroupConfig_t *macCellGrpCfg)
7193 {
7194    macCellGrpCfg->drx_ConfigRrc = NULLP;
7195 #ifdef NR_DRX   
7196    if(ueCb)
7197    {
7198       DU_ALLOC(macCellGrpCfg->drx_ConfigRrc, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
7199       if(!macCellGrpCfg->drx_ConfigRrc)
7200       {
7201          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7202          return RFAILED;
7203       }
7204       if(BuildDrxConfigRrc(ueCb, macCellGrpCfg->drx_ConfigRrc) != ROK)
7205       {
7206          DU_LOG("\nERROR  -->  F1AP : failed to build drx config");
7207          return RFAILED;
7208       }
7209    }
7210 #endif
7211    macCellGrpCfg->schedulingRequestConfig = NULLP;
7212    DU_ALLOC(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
7213    if(!macCellGrpCfg->schedulingRequestConfig)
7214    {
7215       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7216       return RFAILED;
7217    }
7218
7219    if(BuildSchedulingReqConfig(ueCb, macCellGrpCfg->schedulingRequestConfig) != ROK)
7220    {
7221       DU_LOG("\nERROR  -->  F1AP : BuildSchedulingReqConfig failed");
7222       return RFAILED;
7223    }
7224
7225    macCellGrpCfg->bsr_Config = NULLP;
7226    DU_ALLOC(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
7227    if(!macCellGrpCfg->bsr_Config)
7228    {
7229       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7230       return RFAILED;
7231    }
7232
7233    if(BuildBsrConfig(ueCb, macCellGrpCfg->bsr_Config) != ROK)
7234    {
7235       DU_LOG("\nERROR  -->  F1AP : BuildBsrConfig failed");
7236       return RFAILED;
7237    }
7238
7239    macCellGrpCfg->tag_Config = NULLP;
7240    DU_ALLOC(macCellGrpCfg->tag_Config, sizeof(struct TAG_Config));
7241    if(!macCellGrpCfg->tag_Config)
7242    {
7243       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7244       return RFAILED;
7245    }
7246
7247    if(BuildTagConfig(ueCb, macCellGrpCfg->tag_Config) != ROK)
7248    {
7249       DU_LOG("\nERROR  -->  F1AP : BuildTagConfig failed");
7250       return RFAILED;
7251    }
7252
7253    macCellGrpCfg->phr_Config = NULLP;
7254    DU_ALLOC(macCellGrpCfg->phr_Config, sizeof(struct MAC_CellGroupConfig__phr_Config));
7255    if(!macCellGrpCfg->phr_Config)
7256    {
7257       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7258       return RFAILED;
7259    }
7260
7261    if(BuildPhrConfig(ueCb, macCellGrpCfg->phr_Config) != ROK)
7262    {
7263       DU_LOG("\nERROR  -->  F1AP : BuildPhrConfig failed");
7264       return RFAILED;
7265    }
7266
7267    macCellGrpCfg->skipUplinkTxDynamic = false;
7268    macCellGrpCfg->ext1 = NULLP;
7269
7270    return ROK;
7271 }
7272 /*******************************************************************
7273  *
7274  * @brief Frees memeory allocated for SearchSpcToAddModList
7275  *
7276  * @details
7277  *
7278  *    Function : FreeSearchSpcToAddModList
7279  *
7280  *    Functionality: Deallocating memory of SearchSpcToAddModList
7281  *
7282  * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
7283  *
7284  * @return void
7285  *
7286  4221 * ****************************************************************/
7287 void FreeSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
7288 {
7289    uint8_t idx1=0;
7290    uint8_t idx2=0;
7291    struct  SearchSpace *searchSpc=NULLP;
7292
7293    if(searchSpcList->list.array)
7294    {
7295       if(searchSpcList->list.array[idx2])
7296       {
7297          searchSpc = searchSpcList->list.array[idx2];
7298          if(searchSpc->controlResourceSetId)
7299          {
7300             if(searchSpc->monitoringSlotPeriodicityAndOffset)
7301             {
7302                if(searchSpc->monitoringSymbolsWithinSlot)
7303                {
7304                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
7305                   {
7306                      if(searchSpc->nrofCandidates)
7307                      {
7308                         if(searchSpc->searchSpaceType)
7309                         {
7310                            DU_FREE(searchSpc->searchSpaceType->choice.ue_Specific,\
7311                                  sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
7312                            DU_FREE(searchSpc->searchSpaceType, sizeof(struct
7313                                     SearchSpace__searchSpaceType));
7314                         }
7315                         DU_FREE(searchSpc->nrofCandidates,
7316                               sizeof(struct SearchSpace__nrofCandidates));
7317                      }
7318                      DU_FREE(searchSpc->monitoringSymbolsWithinSlot->buf, \
7319                            searchSpc->monitoringSymbolsWithinSlot->size);
7320                   }
7321                   DU_FREE(searchSpc->monitoringSymbolsWithinSlot,
7322                         sizeof(BIT_STRING_t));
7323                }
7324                DU_FREE(searchSpc->monitoringSlotPeriodicityAndOffset, \
7325                      sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
7326             }
7327             DU_FREE(searchSpc->controlResourceSetId,
7328                   sizeof(ControlResourceSetId_t));
7329          }
7330       }
7331       for(idx1 = 0; idx1 < searchSpcList->list.count; idx1++)
7332       {
7333          DU_FREE(searchSpcList->list.array[idx1],
7334                sizeof(struct SearchSpace));
7335       }
7336       DU_FREE(searchSpcList->list.array,searchSpcList->list.size);
7337    }
7338 }
7339 /*******************************************************************
7340  *
7341  * @brief Frees memory allocated for PdschTimeDomAllocList
7342  *
7343  * @details
7344  *
7345  *    Function : FreePdschTimeDomAllocList
7346  *
7347  *    Functionality: Deallocating memory of PdschTimeDomAllocList
7348  *
7349  * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
7350  *
7351  * @return void
7352  *
7353  * ****************************************************************/
7354 void FreePdschTimeDomAllocList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
7355 {
7356    uint8_t idx1=0;
7357
7358    if(timeDomAllocList->choice.setup)
7359    {
7360       if(timeDomAllocList->choice.setup->list.array)
7361       {
7362          for(idx1 = 0; idx1 <timeDomAllocList->choice.setup->list.count ; idx1++)
7363          {
7364             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1]->k0, sizeof(long));
7365             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1],
7366                   sizeof(struct PDSCH_TimeDomainResourceAllocation));
7367          }
7368          DU_FREE(timeDomAllocList->choice.setup->list.array, \
7369                timeDomAllocList->choice.setup->list.size);
7370       }
7371       DU_FREE(timeDomAllocList->choice.setup,\
7372             sizeof(struct PDSCH_TimeDomainResourceAllocationList));
7373    }
7374 }
7375 /*******************************************************************
7376  *
7377  * @brief Frees memory allocated for PuschTimeDomAllocList
7378  *
7379  *@details
7380  *
7381  *    Function : FreePuschTimeDomAllocList
7382  *
7383  *    Functionality: Deallocating memory of PuschTimeDomAllocList
7384  *
7385  * @params[in] PUSCH_Config_t *puschCfg
7386  *
7387  * @return void
7388  *
7389  * ****************************************************************/
7390 void FreePuschTimeDomAllocList(PUSCH_Config_t *puschCfg)
7391 {
7392    uint8_t rsrcListIdx=0;
7393    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
7394
7395    if(puschCfg->pusch_TimeDomainAllocationList)
7396    {
7397       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
7398       if(timeDomAllocList_t->choice.setup)
7399       {
7400          if(timeDomAllocList_t->choice.setup->list.array)
7401          {
7402             for(rsrcListIdx = 0; rsrcListIdx<timeDomAllocList_t->choice.setup->list.count; rsrcListIdx++)
7403             {
7404                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx]->k2, sizeof(long));
7405                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx],\
7406                      sizeof(PUSCH_TimeDomainResourceAllocation_t));
7407             }
7408             DU_FREE(timeDomAllocList_t->choice.setup->list.array, \
7409                   timeDomAllocList_t->choice.setup->list.size);
7410          }
7411          DU_FREE(timeDomAllocList_t->choice.setup, \
7412                sizeof(struct PUSCH_TimeDomainResourceAllocationList));
7413       }
7414       DU_FREE(puschCfg->transformPrecoder, sizeof(long));
7415       DU_FREE(puschCfg->pusch_TimeDomainAllocationList, \
7416             sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
7417    }
7418
7419 }
7420
7421 /*******************************************************************
7422  *
7423  * @brief Frees memory allocated for Dedicated PUCCH config
7424  *
7425  * @details
7426  *
7427  *    Function : FreeBWPUlDedPucchCfg
7428  *
7429  *    Functionality: Deallocating memory of Dedicated PUCCH cfg
7430  *
7431  * @params[in] BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg
7432  *
7433  * @return void
7434  *
7435  * ****************************************************************/
7436 void FreeBWPUlDedPucchCfg(struct BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg)
7437 {
7438    uint8_t k1Idx, rsrcIdx, rsrcSetIdx;
7439    PUCCH_Config_t *pucchCfg = NULLP;
7440    PUCCH_ResourceSet_t *rsrcSet = NULLP;
7441    PUCCH_Resource_t *rsrc = NULLP;
7442
7443    if(ulBwpPucchCfg)
7444    {
7445       if(ulBwpPucchCfg->choice.setup)
7446       {
7447          pucchCfg = ulBwpPucchCfg->choice.setup;
7448
7449          //Free resource set list
7450          if(pucchCfg->resourceSetToAddModList)
7451          {
7452             if(pucchCfg->resourceSetToAddModList->list.array)
7453             {
7454                for(rsrcSetIdx=0; rsrcSetIdx < pucchCfg->resourceSetToAddModList->list.count; rsrcSetIdx++)
7455                {
7456                   rsrcSet = pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx];
7457                   if(rsrcSet->resourceList.list.array)
7458                   {
7459                      for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
7460                      {
7461                         DU_FREE(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
7462                      }
7463                      DU_FREE(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
7464                   }
7465                   DU_FREE(pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
7466                }
7467                DU_FREE(pucchCfg->resourceSetToAddModList->list.array, pucchCfg->resourceSetToAddModList->list.size);
7468             }
7469             DU_FREE(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
7470          }
7471
7472          //Free resource list
7473          if(pucchCfg->resourceToAddModList)
7474          {
7475             if(pucchCfg->resourceToAddModList->list.array)
7476             {
7477                for(rsrcIdx=0; rsrcIdx < pucchCfg->resourceToAddModList->list.count; rsrcIdx++)
7478                {
7479                   rsrc = pucchCfg->resourceToAddModList->list.array[rsrcIdx];
7480                   DU_FREE(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
7481                   DU_FREE(pucchCfg->resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
7482                }
7483                DU_FREE(pucchCfg->resourceToAddModList->list.array, pucchCfg->resourceToAddModList->list.size);
7484             }
7485             DU_FREE(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
7486          }
7487
7488          //PUCCH Format 1
7489          if(pucchCfg->format1)
7490          {
7491             if(pucchCfg->format1->choice.setup)
7492             {
7493                DU_FREE(pucchCfg->format1->choice.setup->nrofSlots, sizeof(long));
7494                DU_FREE(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
7495             }
7496             DU_FREE(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
7497          }
7498          
7499          //DL DATA TO UL ACK
7500          if(pucchCfg->dl_DataToUL_ACK)
7501          {
7502             if(pucchCfg->dl_DataToUL_ACK->list.array)
7503             {
7504                for(k1Idx = 0; k1Idx <  pucchCfg->dl_DataToUL_ACK->list.count; k1Idx++)
7505                {
7506                   DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array[k1Idx], sizeof(long));
7507                }
7508                DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array, pucchCfg->dl_DataToUL_ACK->list.size);
7509             }
7510             DU_FREE(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
7511          }
7512
7513          DU_FREE(ulBwpPucchCfg->choice.setup, sizeof(PUCCH_Config_t));
7514       }
7515       DU_FREE(ulBwpPucchCfg, sizeof(struct BWP_UplinkDedicated__pucch_Config));
7516    }
7517 }
7518
7519 /*******************************************************************
7520  *
7521  * @brief Frees memory allocated for InitialUlBWP
7522  *
7523  * @details
7524  *
7525  *    Function : FreeInitialUlBWP
7526  *
7527  *    Functionality: Deallocating memory of InitialUlBWP
7528  *
7529  * @params[in] BWP_UplinkDedicated_t *ulBwp
7530  *
7531  * @return void
7532  *
7533  * ****************************************************************/
7534 void FreeInitialUlBWP(BWP_UplinkDedicated_t *ulBwp)
7535 {
7536    uint8_t  rSetIdx, rsrcIdx;
7537    SRS_Config_t   *srsCfg = NULLP;
7538    PUSCH_Config_t *puschCfg = NULLP;
7539    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
7540    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
7541    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
7542    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
7543
7544    FreeBWPUlDedPucchCfg(ulBwp->pucch_Config);
7545
7546    if(ulBwp->pusch_Config)
7547    {
7548       if(ulBwp->pusch_Config->choice.setup)
7549       {
7550          puschCfg=ulBwp->pusch_Config->choice.setup;
7551          if(puschCfg->dataScramblingIdentityPUSCH)
7552          {
7553             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
7554             {
7555                FreePuschTimeDomAllocList(puschCfg);
7556                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
7557                if(dmrsUlCfg->choice.setup)
7558                {
7559                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
7560                   {
7561                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
7562                      {
7563                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
7564                               sizeof(long));
7565                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled,
7566                               sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
7567                      }
7568                      DU_FREE(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition,
7569                            sizeof(long));
7570                   }
7571                   DU_FREE(dmrsUlCfg->choice.setup,sizeof(DMRS_UplinkConfig_t));
7572                }
7573                DU_FREE(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, \
7574                      sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
7575             }
7576             DU_FREE(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
7577          }
7578          DU_FREE(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
7579       }
7580       DU_FREE(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
7581
7582       /* Free SRS-Config */
7583       if(ulBwp->srs_Config)
7584       {
7585          if(ulBwp->srs_Config->choice.setup)
7586          {
7587             srsCfg = ulBwp->srs_Config->choice.setup;
7588
7589             /* Free Resource Set to add/mod list */
7590             if(srsCfg->srs_ResourceSetToAddModList)
7591             {
7592                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
7593                if(rsrcSetList->list.array)
7594                {
7595                   rSetIdx = 0;
7596
7597                   /* Free SRS resource Id list in this SRS resource set */
7598                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
7599                   {
7600                      rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
7601
7602                      if(rsrcIdList->list.array)
7603                      {
7604                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
7605                         {
7606                            DU_FREE(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
7607                         }
7608                         DU_FREE(rsrcIdList->list.array, rsrcIdList->list.size);
7609                      }
7610                      DU_FREE(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
7611                            sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
7612                   }
7613
7614                   /* Free resource type info for this SRS resource set */
7615                   DU_FREE(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
7616                         sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
7617
7618                   /* Free memory for each resource set */
7619                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
7620                   {
7621                      DU_FREE(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
7622                   }
7623                   DU_FREE(rsrcSetList->list.array, rsrcSetList->list.size); 
7624                }
7625                DU_FREE(srsCfg->srs_ResourceSetToAddModList, \
7626                      sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
7627             }
7628
7629             /* Free resource to add/modd list */
7630             if(srsCfg->srs_ResourceToAddModList)
7631             {
7632                resourceList = srsCfg->srs_ResourceToAddModList;
7633                if(resourceList->list.array)
7634                {
7635                   rsrcIdx = 0;
7636                   DU_FREE(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2,\
7637                         sizeof(struct SRS_Resource__transmissionComb__n2));
7638                   DU_FREE(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,\
7639                         sizeof(struct SRS_Resource__resourceType__aperiodic));
7640
7641                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
7642                   {
7643                      DU_FREE(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
7644                   }
7645                   DU_FREE(resourceList->list.array, resourceList->list.size);
7646                }
7647                DU_FREE(srsCfg->srs_ResourceToAddModList, \
7648                      sizeof(struct SRS_Config__srs_ResourceToAddModList));
7649             }
7650
7651             DU_FREE(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
7652          }
7653          DU_FREE(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
7654       }
7655    }
7656 }       
7657 /*******************************************************************
7658  *
7659  * @brief Frees memory allocated for initialUplinkBWP
7660  *
7661  * @details
7662  *
7663  *    Function : FreeinitialUplinkBWP
7664  *
7665  *    Functionality: Deallocating memory of initialUplinkBWP
7666  *
7667  * @params[in] UplinkConfig_t *ulCfg
7668  *
7669  * @return void
7670  *         
7671  *
7672  * ****************************************************************/
7673 void FreeinitialUplinkBWP(UplinkConfig_t *ulCfg)
7674 {
7675    BWP_UplinkDedicated_t *ulBwp=NULLP; 
7676    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
7677
7678    if(ulCfg->initialUplinkBWP)
7679    {
7680       ulBwp=ulCfg->initialUplinkBWP;
7681       if(ulCfg->firstActiveUplinkBWP_Id)
7682       {
7683          if(ulCfg->pusch_ServingCellConfig)
7684          {
7685             puschCfg=ulCfg->pusch_ServingCellConfig;
7686             if(puschCfg->choice.setup)
7687             {
7688                if(puschCfg->choice.setup->ext1)
7689                {
7690                   DU_FREE(puschCfg->choice.setup->ext1->\
7691                         processingType2Enabled,sizeof(BOOLEAN_t));
7692                   DU_FREE(puschCfg->choice.setup->ext1->\
7693                         maxMIMO_Layers,sizeof(long));
7694                   DU_FREE(puschCfg->choice.setup->ext1, \
7695                         sizeof(struct PUSCH_ServingCellConfig__ext1));
7696                }
7697                DU_FREE(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
7698             }
7699             DU_FREE(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
7700          }
7701          DU_FREE(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
7702       }
7703       FreeInitialUlBWP(ulBwp);
7704       DU_FREE(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
7705    }
7706 }
7707 /*******************************************************************
7708  *
7709  * @brief Frees emmory allocated for BWPDlDedPdschCfg
7710  *
7711  * @details
7712  *
7713  *    Function : FreeBWPDlDedPdschCfg
7714  *
7715  *    Functionality: Deallocating memory of BWPDlDedPdschCfg
7716  *
7717  * @params[in] BWP_DownlinkDedicated_t *dlBwp
7718  *
7719  * @return void
7720  *
7721  *
7722  * ****************************************************************/
7723 void FreeBWPDlDedPdschCfg(BWP_DownlinkDedicated_t *dlBwp)
7724 {
7725    struct PDSCH_Config *pdschCfg=NULLP;
7726    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
7727    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
7728    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
7729
7730    if(dlBwp->pdsch_Config->choice.setup)
7731    {
7732       pdschCfg=dlBwp->pdsch_Config->choice.setup;
7733       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
7734       {
7735          if(pdschCfg->pdsch_TimeDomainAllocationList)
7736          {
7737             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
7738             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
7739             {
7740                prbBndlType=&pdschCfg->prb_BundlingType;
7741                DU_FREE(prbBndlType->choice.staticBundling,\
7742                      sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
7743                DU_FREE(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
7744             }
7745             FreePdschTimeDomAllocList(timeDomAllocList);
7746             DU_FREE(pdschCfg->pdsch_TimeDomainAllocationList, \
7747                   sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
7748          }
7749          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
7750          if(dmrsDlCfg->choice.setup)
7751          {
7752             DU_FREE(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition,
7753                   sizeof(long));
7754             DU_FREE(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
7755          }
7756          DU_FREE(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, \
7757                sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
7758       }
7759       DU_FREE(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
7760    }
7761 }
7762 /*******************************************************************
7763  *
7764  * @brief Frees emmory allocated for BWPDlDedPdcchCfg
7765  *
7766  * @details
7767  *
7768  *    Function : FreeBWPDlDedPdcchCfg
7769  *
7770  *    Functionality: Deallocating memory of BWPDlDedPdcchCfg
7771  *
7772  * @params[in] BWP_DownlinkDedicated_t *dlBwp
7773  *
7774  * @return void
7775  *         
7776  *
7777  * ****************************************************************/
7778 void FreeBWPDlDedPdcchCfg(BWP_DownlinkDedicated_t *dlBwp)
7779 {
7780    uint8_t idx1=0;
7781    uint8_t idx2=0;
7782    struct PDCCH_Config *pdcchCfg=NULLP;
7783    struct ControlResourceSet *controlRSet=NULLP;
7784    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
7785
7786    if(dlBwp->pdcch_Config->choice.setup)
7787    {
7788       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
7789       if(pdcchCfg->controlResourceSetToAddModList)
7790       {
7791          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
7792          if(controlRSetList->list.array)
7793          {
7794             controlRSet = controlRSetList->list.array[idx2];
7795             if(controlRSet)
7796             {
7797                if(controlRSet->frequencyDomainResources.buf)
7798                {
7799                   if(controlRSet->pdcch_DMRS_ScramblingID)
7800                   {
7801                      if(pdcchCfg->searchSpacesToAddModList)
7802                      {
7803                         FreeSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
7804                         DU_FREE(pdcchCfg->searchSpacesToAddModList, \
7805                               sizeof(struct PDCCH_Config__searchSpacesToAddModList));
7806                      }
7807                      DU_FREE(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
7808                   }
7809                   DU_FREE(controlRSet->frequencyDomainResources.buf, \
7810                         controlRSet->frequencyDomainResources.size);
7811                }
7812             }
7813             for(idx1 = 0; idx1 <controlRSetList->list.count; idx1++)
7814             {
7815                DU_FREE(controlRSetList->list.array[idx1], sizeof(struct ControlResourceSet));
7816             }
7817             DU_FREE(controlRSetList->list.array, controlRSetList->list.size);
7818          }
7819          DU_FREE(pdcchCfg->controlResourceSetToAddModList, \
7820                sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
7821       }
7822       DU_FREE(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
7823    }
7824 }       
7825
7826 /*******************************************************************
7827  *
7828  * @brief Free SCS specific carrier list in DL frequency info
7829  *
7830  * @details
7831  *
7832  *    Function : FreeScsSpecificCarrierListDl
7833  *
7834  *    Functionality: Free SCS specific carrier list in DL frequency info
7835  *
7836  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
7837  *
7838  * @return void
7839  *
7840  * ****************************************************************/
7841 void FreeScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
7842 {
7843    uint8_t listIdx = 0;
7844
7845    if(!scsCarrierList->list.array)
7846    {
7847       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
7848       {
7849          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
7850       }
7851       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
7852    }
7853 }
7854
7855 /*******************************************************************
7856  *
7857  * @brief Free DL frequency info in DL config common
7858  *
7859  * @details
7860  *
7861  *    Function : FreeFreqInfoDl
7862  *
7863  *    Functionality: Free DL frequency info in DL config common
7864  *
7865  * @params[in] Pointer to DownlinkConfigCommon_t
7866  *
7867  * @return void
7868  *
7869  * ****************************************************************/
7870 void FreeFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
7871 {
7872    uint8_t freqBandIdx = 0;
7873
7874    /* SSB Absolute Frequency */
7875    DU_FREE(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
7876
7877    /* NR Multi Frequency Band List */
7878    if(frequencyInfoDL->frequencyBandList.list.array)
7879    {
7880       for(freqBandIdx = 0; freqBandIdx < frequencyInfoDL->frequencyBandList.list.count; freqBandIdx++)
7881       {
7882          DU_FREE(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
7883       }
7884       DU_FREE(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
7885    }
7886
7887    /* Subcarrier Spacing specifc carrier List */
7888    FreeScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList);
7889 }
7890
7891 /*******************************************************************
7892  *
7893  * @brief Free DL config common in Serving cell config common
7894  *
7895  * @details
7896  *
7897  *    Function : FreeDlConfigCommon
7898  *
7899  *    Functionality: Free DL config common in Serving cell config common
7900  *
7901  * @params[in] Pointer to DownlinkConfigCommon_t
7902  *
7903  * @return void
7904  *
7905  * ****************************************************************/
7906 void FreeDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
7907 {
7908    /* DL Frequency Info */
7909    if(dlCfgCommon->frequencyInfoDL)
7910    {
7911       FreeFreqInfoDl(dlCfgCommon->frequencyInfoDL);
7912       DU_FREE(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
7913    }
7914
7915    /* DL BWP config common */
7916    if(dlCfgCommon->initialDownlinkBWP)
7917    {
7918       FreeBwpDlCommon(dlCfgCommon->initialDownlinkBWP);
7919       DU_FREE(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
7920    }
7921 }
7922
7923 /*******************************************************************
7924  *
7925  * @brief Free SCS specific carrier list in UL frequency Info
7926  *
7927  * @details
7928  *
7929  *    Function : FreeScsSpecificCarrierListUl
7930  *
7931  *    Functionality: Free SCS specific carrier list in UL frequency Info
7932  *
7933  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
7934  *
7935  * @return void
7936  *
7937  * ****************************************************************/
7938 void FreeScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
7939 {
7940    uint8_t listIdx = 0;
7941
7942    if(scsCarrierList->list.array)
7943    {
7944       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
7945       {
7946          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
7947       }
7948       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
7949    }
7950 }
7951
7952 /*******************************************************************
7953  *
7954  * @brief Free frequency info in UL config common
7955  *
7956  * @details
7957  *
7958  *    Function : FreeFreqInfoUl
7959  *
7960  *    Functionality: Free frequency info in UL config common
7961  *
7962  * @params[in] Pointer to FrequencyInfoUL_t
7963  *
7964  * @return void
7965  *
7966  * ****************************************************************/
7967 void FreeFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
7968 {
7969    uint8_t listIdx= 0;
7970
7971    /* NR Multi Frequency Band List */
7972    if(!frequencyInfoUL->frequencyBandList)
7973    {
7974       if(frequencyInfoUL->frequencyBandList->list.array)
7975       {
7976          for(listIdx = 0; listIdx < frequencyInfoUL->frequencyBandList->list.count; listIdx++)
7977          {
7978             DU_FREE(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
7979          }
7980          DU_FREE(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
7981       }
7982       DU_FREE(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
7983    }
7984
7985    /* Absolute frequency point A */
7986    DU_FREE(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
7987
7988    /* Subcarrier Spacing specifc carrier */
7989    FreeScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList);
7990
7991    /* P-MAX */
7992    DU_FREE(frequencyInfoUL->p_Max, sizeof(P_Max_t));
7993 }
7994
7995 /*******************************************************************
7996  *
7997  * @brief Free UL config common in Serving cell config common
7998  *
7999  * @details
8000  *
8001  *    Function : FreeUlConfigCommon
8002  *
8003  *    Functionality: Free UL config common in Serving cell config common
8004  *
8005  * @params[in] Pointer to UplinkConfigCommon_t
8006  *
8007  * @return void
8008  *
8009  * ****************************************************************/
8010 void FreeUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
8011 {
8012    /* UL Frequency Info */
8013    if(ulCfgCommon->frequencyInfoUL)
8014    {
8015       FreeFreqInfoUl(ulCfgCommon->frequencyInfoUL);
8016       DU_FREE(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
8017    }
8018
8019    /* UL BWP common */
8020    if(ulCfgCommon->initialUplinkBWP)
8021    {
8022       FreeBwpUlCommon(ulCfgCommon->initialUplinkBWP);
8023       DU_FREE(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
8024    }
8025 }
8026
8027 /*******************************************************************
8028  *
8029  * @brief Free SP cell config common in Reconfig with Sync
8030  *
8031  * @details
8032  *
8033  *    Function : FreeSpCellConfigCommon
8034  *
8035  *    Functionality: Free SP cell config common in Reconfig with Sync
8036  *
8037  * @params[in] Pointer to ServingCellConfigCommon_t
8038  *
8039  * @return void
8040  *
8041  * ****************************************************************/
8042 void FreeSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
8043 {
8044    /* Free Physical cell identity */
8045    DU_FREE(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
8046
8047    /* Free Downlink Config common */
8048    if(spCellConfigCommon->downlinkConfigCommon)
8049    {
8050       FreeDlConfigCommon(spCellConfigCommon->downlinkConfigCommon);
8051       DU_FREE(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
8052    }
8053
8054    /* Free Uplink Config common */
8055    if(spCellConfigCommon->uplinkConfigCommon)
8056    {
8057       FreeUlConfigCommon(spCellConfigCommon->uplinkConfigCommon);
8058       DU_FREE(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
8059    }
8060
8061    /* Free Timing Advance offset */
8062    DU_FREE(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
8063
8064    /* Free SSB Position in Burst */
8065    if(spCellConfigCommon->ssb_PositionsInBurst)
8066    {
8067       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.buf, \
8068          spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.size);
8069       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
8070    }
8071
8072    /* Free SSB Periodicity in Serving cell */
8073    DU_FREE(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
8074
8075    /* Free SSB subcarrier spacing */
8076    DU_FREE(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
8077
8078    /* TDD UL-DL configuration common */
8079    DU_FREE(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
8080 }
8081
8082 /*******************************************************************
8083  *
8084  * @brief Free dedicated RACH configuration in Reconfiguration with sync
8085  *
8086  * @details
8087  *
8088  *    Function : FreeRecfgWithSync
8089  *
8090  *    Functionality:
8091  *       Free dedicated RACH configuration in Reconfiguration with sync
8092  *
8093  * @params[in] Pinter to Rach config dedicated struct
8094  *
8095  * @return void
8096  *
8097  * ****************************************************************/
8098 void FreeRachConfigDedicated(struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
8099 {
8100    uint8_t listIdx = 0;
8101    CFRA_t *cfra = NULLP;
8102    struct CFRA__resources__ssb *ssbResource = NULLP;
8103
8104    /* Uplink */
8105    if(rachCfgDed->choice.uplink)
8106    {
8107       /* CFRA : Contention free Random Access */
8108       if(rachCfgDed->choice.uplink->cfra)
8109       {
8110          cfra = rachCfgDed->choice.uplink->cfra;
8111
8112          /* CFRA occassions */
8113          if(cfra->occasions)
8114          {
8115             /* CFRA occassions : SSB per RACH occasion */
8116             DU_FREE(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
8117             DU_FREE(cfra->occasions, sizeof(struct CFRA__occasions));
8118          }
8119
8120          /* CFRA resource */
8121          cfra->resources.present = CFRA__resources_PR_ssb;
8122
8123          /* CFRA resource : SSB */
8124          if(cfra->resources.choice.ssb)
8125          {
8126             ssbResource = cfra->resources.choice.ssb;
8127
8128             /* CFRA SSB resource list */
8129             if(ssbResource->ssb_ResourceList.list.array)
8130             {
8131                for(listIdx = 0; listIdx < ssbResource->ssb_ResourceList.list.count; listIdx++)
8132                {
8133                   DU_FREE(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
8134                }
8135                DU_FREE(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
8136             }
8137             DU_FREE(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
8138          }
8139          DU_FREE(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
8140       }
8141       DU_FREE(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
8142    }
8143 }
8144
8145 /*******************************************************************
8146  *
8147  * @brief Frees reconfiguration with sync in SP cell config
8148  *
8149  * @details
8150  *
8151  *    Function : FreeRecfgWithSync
8152  *
8153  *    Functionality: Fress reconfiguration with sync in SP cell config
8154  *
8155  * @params[in] Pointer to ReconfigurationWithSync_t
8156  *
8157  * @return void
8158  *
8159  * ****************************************************************/
8160 void FreeRecfgWithSync(ReconfigurationWithSync_t *recfgWithSync)
8161 {
8162    /* Free SP Cell config common */
8163    if(recfgWithSync->spCellConfigCommon)
8164    {
8165       FreeSpCellConfigCommon(recfgWithSync->spCellConfigCommon);
8166       DU_FREE(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
8167    }
8168
8169    /* Free Dedicated RACH configuration */
8170    if(recfgWithSync->rach_ConfigDedicated)
8171    {
8172       FreeRachConfigDedicated(recfgWithSync->rach_ConfigDedicated);
8173       DU_FREE(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
8174    }
8175 }
8176
8177 /*******************************************************************
8178  *
8179  * @brief Frees emmory allocated for DUToCURRCContainer 
8180  *
8181  * @details
8182  *
8183  *    Function : FreeMemDuToCuRrcCont
8184  *
8185  *    Functionality: Deallocating memory of DuToCuRrcContainer
8186  *
8187  * @params[in] DuToCuRRCContainer, DuToCuRRCContainer
8188  *
8189  * @return ROK     - success
8190  *         RFAILED - failure
8191  *
8192  * ****************************************************************/
8193 uint8_t FreeMemDuToCuRrcCont(CellGroupConfigRrc_t *cellGrpCfg)
8194 {
8195    uint8_t idx=0;
8196    SpCellConfig_t *spCellCfg=NULLP;
8197    ServingCellConfig_t *srvCellCfg=NULLP;
8198    BWP_DownlinkDedicated_t *dlBwp=NULLP;
8199    MAC_CellGroupConfig_t *macCellGrpCfg=NULLP;
8200    PhysicalCellGroupConfig_t *phyCellGrpCfg=NULLP;
8201    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList=NULLP;
8202    struct RLC_Config *rlcConfig=NULLP;
8203    struct LogicalChannelConfig *macLcConfig=NULLP;
8204    struct MAC_CellGroupConfig__drx_ConfigRrc *drxCfg=NULLP;
8205    struct SchedulingRequestConfig *schedulingRequestConfig=NULLP;
8206    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList=NULLP;
8207    struct TAG_Config *tagConfig=NULLP;
8208    struct TAG_Config__tag_ToAddModList *tagList=NULLP;
8209    struct MAC_CellGroupConfig__phr_Config *phrConfig=NULLP;
8210    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg=NULLP;
8211
8212    rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
8213    if(rlcBearerList)
8214    {
8215       if(rlcBearerList->list.array)
8216       {
8217          for(idx=0; idx<rlcBearerList->list.count; idx++)
8218          {
8219             if(rlcBearerList->list.array[idx])
8220             {  
8221                rlcConfig   = rlcBearerList->list.array[idx]->rlc_Config;
8222                macLcConfig = rlcBearerList->list.array[idx]->mac_LogicalChannelConfig;
8223                if(rlcConfig)
8224                {
8225                   switch(rlcConfig->present)
8226                   {
8227                      case RLC_Config_PR_NOTHING:
8228                         break;
8229
8230                      case RLC_Config_PR_am:
8231                         {
8232                            if(rlcConfig->choice.am)
8233                            {
8234                               DU_FREE(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
8235                               DU_FREE(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
8236                               DU_FREE(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
8237                            }
8238                            break;
8239                         }
8240                      case RLC_Config_PR_um_Bi_Directional:
8241                         {
8242                            if(rlcConfig->choice.um_Bi_Directional)
8243                            {
8244                               DU_FREE(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t)); 
8245                               DU_FREE(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8246                               DU_FREE(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
8247                            }
8248                            break;
8249                         }
8250                      case RLC_Config_PR_um_Uni_Directional_UL:
8251                         {
8252                            if(rlcConfig->choice.um_Uni_Directional_UL)
8253                            {
8254                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8255                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
8256                            }
8257                            break;
8258                         }
8259                      case RLC_Config_PR_um_Uni_Directional_DL:
8260                         {
8261                            if(rlcConfig->choice.um_Uni_Directional_DL )
8262                            {
8263                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8264                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
8265                            }
8266                            break;
8267                         }
8268                   }     
8269                   DU_FREE(rlcConfig, sizeof(struct RLC_Config));
8270                }
8271                DU_FREE(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
8272                if(macLcConfig)
8273                {
8274                   if(macLcConfig->ul_SpecificParameters)
8275                   {
8276                      DU_FREE(macLcConfig->ul_SpecificParameters->schedulingRequestID,   sizeof(SchedulingRequestId_t));
8277                      DU_FREE(macLcConfig->ul_SpecificParameters->logicalChannelGroup,   sizeof(long));
8278                      DU_FREE(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
8279                   }
8280                   DU_FREE(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
8281                }
8282                DU_FREE(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
8283             }   
8284          }
8285          DU_FREE(rlcBearerList->list.array, rlcBearerList->list.size);
8286       }
8287       DU_FREE(cellGrpCfg->rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8288    }
8289
8290    macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
8291    if(macCellGrpCfg)
8292    {
8293       drxCfg = macCellGrpCfg->drx_ConfigRrc;
8294
8295       if(drxCfg)
8296       {
8297           switch(drxCfg->present)
8298           {
8299             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
8300                break;
8301             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
8302             {
8303                if(drxCfg->choice.setup)
8304                {
8305                   DU_FREE(drxCfg->choice.setup->shortDRX, sizeof(struct DRX_ConfigRrc__shortDRX));  
8306                   DU_FREE(drxCfg->choice.setup, sizeof(struct DRX_ConfigRrc));
8307                }
8308             }
8309             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
8310                break;
8311           }
8312           DU_FREE(drxCfg, sizeof(struct MAC_CellGroupConfig__drx_ConfigRrc));
8313       }
8314       schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig; 
8315       if(schedulingRequestConfig)
8316       {
8317          schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
8318          if(schReqList)
8319          {
8320             if(schReqList->list.array)
8321             {
8322                for(idx=0;idx<schReqList->list.count; idx++)
8323                {
8324                   if(schReqList->list.array[idx])
8325                   {
8326                      DU_FREE(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
8327                      DU_FREE(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
8328                   }
8329                }
8330                DU_FREE(schReqList->list.array, schReqList->list.size);
8331             }
8332             DU_FREE(schedulingRequestConfig->schedulingRequestToAddModList,\
8333                   sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));    }
8334             DU_FREE(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
8335       }
8336       if(macCellGrpCfg->bsr_Config)
8337       {
8338          DU_FREE(macCellGrpCfg->bsr_Config->logicalChannelSR_DelayTimer, sizeof(long));
8339          DU_FREE(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
8340       }
8341       tagConfig = macCellGrpCfg->tag_Config;
8342       if(tagConfig)
8343       {
8344          tagList = tagConfig->tag_ToAddModList;
8345          if(tagList)
8346          {
8347             if(tagList->list.array)
8348             {
8349                for(idx=0; idx<tagList->list.count; idx++)
8350                {
8351                   DU_FREE(tagList->list.array[idx], sizeof(struct TAG));
8352                }
8353                DU_FREE(tagList->list.array, tagList->list.size);
8354             }
8355             DU_FREE(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
8356          }
8357          DU_FREE(tagConfig, sizeof(struct TAG_Config));
8358       }
8359
8360       phrConfig = macCellGrpCfg->phr_Config;
8361       if(phrConfig)
8362       {
8363          DU_FREE(phrConfig->choice.setup, sizeof(struct PHR_Config));
8364          DU_FREE(phrConfig, sizeof(struct MAC_CellGroupConfig__phr_Config));
8365       }
8366
8367       DU_FREE(macCellGrpCfg, sizeof(MAC_CellGroupConfig_t));
8368    }
8369
8370    phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
8371    if(phyCellGrpCfg)
8372    {
8373       DU_FREE(phyCellGrpCfg->p_NR_FR1, sizeof(long));
8374       DU_FREE(phyCellGrpCfg, sizeof(PhysicalCellGroupConfig_t));
8375    }
8376
8377    spCellCfg = cellGrpCfg->spCellConfig;
8378    if(spCellCfg)
8379    {
8380       /* Free serving cell index */
8381       DU_FREE(spCellCfg->servCellIndex, sizeof(long));
8382
8383       /* Free Reconfiguration with sync */
8384       if(spCellCfg->reconfigurationWithSync)
8385       {
8386          FreeRecfgWithSync(spCellCfg->reconfigurationWithSync);
8387          DU_FREE(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
8388       }
8389
8390       /* Free rlmInSyncOutOfSyncThreshold */
8391       DU_FREE(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
8392
8393       /* Free SP Cell config dedicated */
8394       if(spCellCfg->spCellConfigDedicated)
8395       {
8396          srvCellCfg = spCellCfg->spCellConfigDedicated;
8397
8398          /* Free TDD UL-DL config dedicated */
8399          DU_FREE(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
8400
8401          /* Free Initial Downlink BWP */
8402          if(srvCellCfg->initialDownlinkBWP)
8403          {
8404             dlBwp = srvCellCfg->initialDownlinkBWP;
8405
8406             /* Free DL BWP PDCCH Config */
8407             if(dlBwp->pdcch_Config)
8408             {
8409                FreeBWPDlDedPdcchCfg(dlBwp);
8410                DU_FREE(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
8411             }
8412
8413             /* Free DL BWP PDSCH config */
8414             if(dlBwp->pdsch_Config)
8415             {
8416                FreeBWPDlDedPdschCfg(dlBwp);
8417                DU_FREE(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
8418             }
8419             DU_FREE(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
8420          }
8421
8422          /* Free First Active Downlink BWP */
8423          DU_FREE(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
8424
8425          /* Free Default downlink BWP */
8426          DU_FREE(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
8427
8428          /* Free Uplink config */
8429          if(srvCellCfg->uplinkConfig)
8430          {
8431             FreeinitialUplinkBWP(srvCellCfg->uplinkConfig);
8432             DU_FREE(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));  
8433          }
8434
8435          /* Free PDSCH serving cell config */
8436          if(srvCellCfg->pdsch_ServingCellConfig)
8437          {
8438             pdschCfg= srvCellCfg->pdsch_ServingCellConfig;
8439             if(pdschCfg->choice.setup)
8440             {
8441                DU_FREE(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH,sizeof(long));
8442                DU_FREE(pdschCfg->choice.setup, sizeof(struct PDSCH_ServingCellConfig));
8443             }
8444             DU_FREE(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct ServingCellConfig__pdsch_ServingCellConfig));
8445          }
8446
8447          DU_FREE(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
8448       }
8449       DU_FREE(spCellCfg,sizeof(SpCellConfig_t));
8450    }
8451    return ROK;
8452 }
8453
8454 /*******************************************************************
8455  *
8456  * @brief Builds CellGroupConfigRrc for DU To CU RRC Container 
8457  *
8458  * @details
8459  *
8460  *    Function : BuildCellGroupConfigRrc
8461  *
8462  *    Functionality: Builds and copied Cell group config buffer into 
8463  *       DuToCuRrcContainer
8464  *
8465  * @params[in] idx, index in F1AP msg
8466  *             DuToCuRRCContainer, DuToCuRRCContainer
8467  *
8468  * @return ROK     - success
8469  *         RFAILED - failure
8470  *
8471  * ****************************************************************/
8472 uint8_t BuildCellGroupConfigRrc(DuUeCb *ueCb, OCTET_STRING_t *duToCuRrcContainer)
8473 {
8474    uint8_t  ret = ROK;
8475    CellGroupConfigRrc_t  cellGrpCfg;
8476    asn_enc_rval_t        encRetVal;
8477    memset(&cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
8478    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8479
8480    while(true)
8481    {
8482       cellGrpCfg.cellGroupId = CELL_GRP_ID;
8483
8484       cellGrpCfg.rlc_BearerToAddModList = NULLP;
8485       DU_ALLOC(cellGrpCfg.rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8486       if(!cellGrpCfg.rlc_BearerToAddModList)
8487       {
8488          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8489          ret = RFAILED;
8490          break;
8491       }
8492       if(BuildRlcBearerToAddModList(ueCb, cellGrpCfg.rlc_BearerToAddModList) != ROK)
8493       {
8494          DU_LOG("\nERROR  -->  F1AP : BuildRlcBearerToAddModList failed");
8495          ret = RFAILED;
8496          break;
8497       }
8498
8499       cellGrpCfg.rlc_BearerToReleaseList = NULLP;
8500       cellGrpCfg.mac_CellGroupConfig = NULLP;
8501       DU_ALLOC(cellGrpCfg.mac_CellGroupConfig, sizeof(MAC_CellGroupConfig_t));
8502       if(!cellGrpCfg.mac_CellGroupConfig)
8503       {
8504          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8505          ret = RFAILED;
8506          break;
8507       }
8508       if(BuildMacCellGrpCfg(ueCb, cellGrpCfg.mac_CellGroupConfig) != ROK)
8509       {
8510          DU_LOG("\nERROR  -->  F1AP : BuildMacCellGrpCfg failed");
8511          ret = RFAILED;
8512          break;
8513       }
8514
8515       cellGrpCfg.physicalCellGroupConfig = NULLP;
8516       DU_ALLOC(cellGrpCfg.physicalCellGroupConfig, sizeof(PhysicalCellGroupConfig_t));
8517       if(!cellGrpCfg.physicalCellGroupConfig)
8518       {
8519          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8520          ret = RFAILED;
8521          break;
8522       }
8523       if(BuildPhyCellGrpCfg(ueCb, cellGrpCfg.physicalCellGroupConfig) != ROK)
8524       {
8525          DU_LOG("\nERROR  -->  F1AP : BuildPhyCellGrpCfg failed");
8526          ret = RFAILED;
8527          break;
8528       }
8529
8530       cellGrpCfg.spCellConfig = NULLP;
8531       DU_ALLOC(cellGrpCfg.spCellConfig, sizeof(SpCellConfig_t));
8532       if(!cellGrpCfg.spCellConfig)
8533       {
8534          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8535          ret = RFAILED;
8536          break;
8537       }
8538       if(BuildSpCellCfg(ueCb, cellGrpCfg.spCellConfig) != ROK)
8539       {
8540          DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfg failed");
8541          ret = RFAILED;
8542          break;
8543       }
8544
8545       cellGrpCfg.sCellToAddModList = NULLP;
8546       cellGrpCfg.sCellToReleaseList = NULLP;
8547       cellGrpCfg.ext1 = NULLP;
8548
8549       /* encode cellGrpCfg into duToCuRrcContainer */
8550       xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, &cellGrpCfg);
8551       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8552       encBufSize = 0;
8553       encRetVal = aper_encode(&asn_DEF_CellGroupConfigRrc, 0, &cellGrpCfg, PrepFinalEncBuf, encBuf);
8554       /* Encode results */
8555       if(encRetVal.encoded == ENCODE_FAIL)
8556       {
8557          DU_LOG( "\nERROR  --> F1AP : Could not encode DuToCuRrcContainer (at %s)\n",\
8558                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
8559          ret = RFAILED;
8560          break;
8561       }
8562       else
8563       {
8564          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DuToCuRrcContainer\n");
8565          for(int i=0; i< encBufSize; i++)
8566          {
8567             printf("%x",encBuf[i]);
8568          }
8569       }
8570
8571       duToCuRrcContainer->size = encBufSize;
8572       DU_ALLOC(duToCuRrcContainer->buf, duToCuRrcContainer->size);
8573       if(!duToCuRrcContainer->buf)
8574       {
8575          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDuToCuRrcContainer");
8576          ret = RFAILED;
8577          break;
8578       }
8579       if(ret == ROK)
8580       {
8581          memcpy(duToCuRrcContainer->buf, encBuf, duToCuRrcContainer->size);
8582       }
8583       break;
8584    }
8585    FreeMemDuToCuRrcCont(&cellGrpCfg);
8586    return ret;
8587 }
8588
8589 /*******************************************************************
8590  *
8591  * @brief Free memory allocated in InitialULRRCMessage
8592  *
8593  * @details
8594  *
8595  *    Function : freeInitUlRrcMsgTransfer
8596  *
8597  *    Functionality: Free memory allocated in InitialULRRCMessage
8598  *
8599  * @params[in]F1AP_PDU_t  *f1apMsg)
8600  *
8601  * @return ROK     - success
8602  *         RFAILED - failure
8603  *
8604  * ****************************************************************/
8605
8606 uint8_t freeInitUlRrcMsgTransfer(F1AP_PDU_t  *f1apMsg)
8607 {
8608    uint8_t ieIdx, arrIdx;
8609    InitialULRRCMessageTransfer_t *initULRRCMsg=NULLP;
8610
8611    if(f1apMsg)
8612    {
8613       if(f1apMsg->choice.initiatingMessage)
8614       {
8615          initULRRCMsg = &f1apMsg->choice.initiatingMessage->value.\
8616             choice.InitialULRRCMessageTransfer;
8617          if(initULRRCMsg->protocolIEs.list.array)
8618          {
8619             for(ieIdx = 0; ieIdx < initULRRCMsg->protocolIEs.list.count; ieIdx++)
8620             {
8621                switch(initULRRCMsg->protocolIEs.list.array[ieIdx]->id)
8622                {
8623                   case ProtocolIE_ID_id_NRCGI:
8624                   {
8625                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf)
8626                      {
8627                         if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf)
8628                         {
8629                            DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf,\
8630                            initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.size);
8631                         }
8632                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf,\
8633                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.size);
8634                      }
8635                      break;
8636                   }
8637                   case ProtocolIE_ID_id_RRCContainer:
8638                   {
8639                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
8640                      {
8641                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,\
8642                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
8643                      }
8644                      break;
8645                   }
8646                   case ProtocolIE_ID_id_DUtoCURRCContainer:
8647                   {
8648                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf)
8649                      {
8650                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf,
8651                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.size);
8652                      }
8653                      break;
8654                   }
8655                   default:
8656                      break;
8657                }
8658              }
8659              for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
8660              {
8661                 if(initULRRCMsg->protocolIEs.list.array[arrIdx])
8662                 {
8663                    DU_FREE(initULRRCMsg->protocolIEs.list.array[arrIdx],\
8664                       sizeof(InitialULRRCMessageTransferIEs_t));
8665                 }
8666              }
8667              DU_FREE(initULRRCMsg->protocolIEs.list.array, initULRRCMsg->protocolIEs.list.size);
8668           }
8669          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8670       }
8671       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
8672    }
8673    else
8674    {
8675       DU_LOG("\nERROR  -->  DU_APP : Recevied F1ap Pdu is null at freeInitUlRrcMsgTransfer()");
8676       return RFAILED;
8677    }
8678    return ROK;
8679 }
8680
8681 /*******************************************************************
8682  *
8683  * @brief Builds and sends the InitialULRRCMessage 
8684  *
8685  * @details
8686  *
8687  *    Function : BuildAndSendInitialRrcMsgTransfer 
8688  *
8689  *    Functionality: Constructs the Initial UL RRC Message Transfer and sends
8690  *                   it to the CU through SCTP.
8691  *
8692  * @params[in] 
8693  *
8694  * @return ROK     - success
8695  *         RFAILED - failure
8696  *
8697  * ****************************************************************/
8698 uint8_t BuildAndSendInitialRrcMsgTransfer(uint32_t gnbDuUeF1apId, uint16_t crnti,
8699       uint16_t rrcContSize, uint8_t *rrcContainer)
8700 {
8701    uint8_t   ret;
8702    uint8_t   elementCnt;
8703    uint8_t   ieIdx, cellIdx, ueIdx;
8704    DuUeCb    *duUeCb = NULLP;
8705    asn_enc_rval_t  encRetVal;
8706    F1AP_PDU_t  *f1apMsg = NULLP;
8707    InitialULRRCMessageTransfer_t *initULRRCMsg = NULLP;
8708    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8709
8710    while(true)
8711    {
8712       DU_LOG("\n INFO   -->  F1AP : Building RRC Setup Request\n");
8713       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
8714       if(f1apMsg == NULLP)
8715       {
8716          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
8717          break;
8718       }
8719       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
8720       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8721       if(f1apMsg->choice.initiatingMessage == NULLP)
8722       {
8723          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU failed");
8724          break;
8725       }
8726       f1apMsg->choice.initiatingMessage->procedureCode =\
8727                                                         ProcedureCode_id_InitialULRRCMessageTransfer;
8728       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
8729       f1apMsg->choice.initiatingMessage->value.present = \
8730                                                          InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
8731       initULRRCMsg =\
8732                     &f1apMsg->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
8733       elementCnt = 5;
8734       initULRRCMsg->protocolIEs.list.count = elementCnt;
8735       initULRRCMsg->protocolIEs.list.size = \
8736                                             elementCnt * sizeof(InitialULRRCMessageTransferIEs_t *);
8737       /* Initialize the F1Setup members */
8738       DU_ALLOC(initULRRCMsg->protocolIEs.list.array,initULRRCMsg->protocolIEs.list.size);
8739       if(initULRRCMsg->protocolIEs.list.array == NULLP)
8740       {
8741          DU_LOG(" ERROR  -->  F1AP : Memory allocation for\
8742                RRCSetupRequestMessageTransferIEs failed");
8743          break;
8744       }
8745       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
8746       {
8747          DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx],\
8748                sizeof(InitialULRRCMessageTransferIEs_t));
8749          if(initULRRCMsg->protocolIEs.list.array[ieIdx] == NULLP)
8750          {
8751             break;
8752          }
8753       }
8754       ieIdx = 0;
8755       /*GNB DU UE F1AP ID*/
8756       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8757                                                         ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
8758       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  = Criticality_reject;
8759       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
8760                                                                   InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
8761       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
8762
8763
8764       /*NRCGI*/
8765       ieIdx++;
8766       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8767                                                         ProtocolIE_ID_id_NRCGI;
8768       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  =Criticality_reject;
8769       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
8770                                                                   InitialULRRCMessageTransferIEs__value_PR_NRCGI;
8771
8772       ret =\
8773            BuildNrcgi(&initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
8774       if(ret!=ROK)
8775       {
8776          break;
8777       }
8778
8779       /*CRNTI*/
8780       ieIdx++;
8781       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8782                                                         ProtocolIE_ID_id_C_RNTI;
8783       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
8784       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
8785                                                                  InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
8786       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.C_RNTI = crnti;
8787
8788       /*RRCContainer*/
8789       ieIdx++;
8790       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8791                                                         ProtocolIE_ID_id_RRCContainer;
8792       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
8793       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
8794                                                                  InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
8795
8796       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size = rrcContSize;
8797       DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,
8798             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size)
8799       if(!initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
8800       {
8801          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRCSetupRequestMessageTransferIEs failed");
8802          break;
8803       
8804       }
8805       memcpy(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, rrcContainer,
8806             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
8807
8808
8809       /*DUtoCURRCContainer*/
8810       ieIdx++;
8811       initULRRCMsg->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCContainer;
8812       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
8813       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
8814                                                                  InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
8815
8816       for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
8817       {
8818          for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
8819          {
8820             if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
8821                   (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti == crnti))
8822             {
8823                duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
8824             }
8825          }
8826       }
8827
8828       ret = BuildCellGroupConfigRrc(duUeCb, &initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer);
8829       if(ret != ROK)
8830       {
8831          break;
8832       }
8833
8834       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
8835
8836       /* Encode the Intial UL RRC Message transfer as APER */
8837       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8838       encBufSize = 0;
8839       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
8840       /* Encode results */
8841       if(encRetVal.encoded == ENCODE_FAIL)
8842       {
8843          DU_LOG( "\nERROR  --> F1AP : Could not encode Initial UL RRC Message Transfer\
8844                structure (at %s)\n",encRetVal.failed_type ? \
8845                encRetVal.failed_type->name : "unknown");
8846          ret = RFAILED;
8847          break;
8848       }
8849       else
8850       {
8851
8852          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Initial UL RRC\
8853                Message transfer\n");
8854          for(int i=0; i< encBufSize; i++)
8855          {
8856             printf("%x",encBuf[i]);
8857          }
8858       }
8859       /* Sending  msg  */
8860       if(sendF1APMsg() != ROK)
8861       {
8862          DU_LOG("\nERROR  -->  F1AP : Sending Initial UL RRC Message Transfer Failed");
8863          ret = RFAILED;
8864          break;
8865       }
8866       break;
8867    }
8868    freeInitUlRrcMsgTransfer(f1apMsg);
8869    return ret;
8870 }/* End of BuildAndSendInitialRrcMsgTransfer*/
8871
8872 /*****  UE SETUP REQUEST *****/
8873
8874 /*******************************************************************
8875  *
8876  * @brief Free Qos And Snssai Drb Info
8877  *
8878  * @details
8879  *
8880  *    Function : freeDrbQosAndSnssaiInfo
8881  *
8882  *    Functionality: Free Qos And Snssai Drb Info
8883  *
8884  * @params[in] LcCfg *lcCfg,
8885  * @return void
8886  *
8887  * ****************************************************************/
8888 void freeDrbQosAndSnssaiInfo(LcCfg *lcCfg)
8889 {
8890    if(lcCfg->snssai)
8891    {
8892       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
8893    }
8894    if(lcCfg->drbQos)
8895    {
8896       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
8897    }
8898 }
8899
8900 /******************************************************************
8901 *
8902 * @brief Function to delete the RLC Lc cfg from UE APP DB
8903 *
8904 * @details
8905 *
8906 *  Function : freeRlcLcCfg
8907 *
8908 *  Functionality: Function to delete the RLC Lc cfg from UE APP DB
8909 *
8910 *
8911  *****************************************************************/
8912
8913 void freeRlcLcCfg(RlcBearerCfg *lcCfg)
8914 {
8915    switch(lcCfg->rlcMode)
8916    {
8917       case RLC_AM :
8918          {
8919             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
8920             break;
8921          }
8922       case RLC_UM_BI_DIRECTIONAL :
8923          {
8924             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
8925             break;
8926          }
8927       case RLC_UM_UNI_DIRECTIONAL_UL :
8928          {
8929             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
8930             break;
8931          }
8932       case RLC_UM_UNI_DIRECTIONAL_DL :
8933          {
8934             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
8935             break;
8936          }
8937       default:
8938          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at freeRlcLcCfg()", lcCfg->rlcMode);
8939          break;
8940    }
8941    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
8942 }
8943
8944 /*******************************************************************
8945  *
8946  * @brief Function to free MacLcCfg
8947  *
8948  * @details
8949  *
8950  *    Function : freeMacLcCfg
8951  *
8952  *    Functionality: Function to free MacLcCfg
8953  *
8954  * @params[in] LcCfg *lcCfg,
8955  * @return void
8956  *
8957  * ****************************************************************/
8958
8959 void  freeMacLcCfg(LcCfg *lcCfg)
8960 {
8961     /* Deleting DRBQOS */
8962    if(lcCfg->drbQos)
8963    {
8964       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
8965    }
8966    /* Deleting SNSSAI */
8967    if(lcCfg->snssai)
8968    {
8969       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
8970    }
8971 }
8972 /*******************************************************************
8973  *
8974  * @brief Free UE NR Capability received in UE Context setup request
8975  *
8976  * @details
8977  *
8978  *    Function : freeAperDecodeUeNrCapability
8979  *
8980  *    Functionality:  
8981  *       Free UE NR Capability received in UE Context setup request
8982  *
8983  * @params[in] 
8984  * @return ROK     - success
8985  *         RFAILED - failure
8986  *
8987  * ****************************************************************/
8988 void freeAperDecodeUeNrCapability(void *ueNrCapability)
8989 {
8990    uint8_t arrIdx =0;
8991    FeatureSets_t *featureSets =NULLP;
8992    UE_NR_Capability_t *ueNrCap = (UE_NR_Capability_t *)ueNrCapability;
8993
8994    if(ueNrCap->rf_Parameters.supportedBandListNR.list.array)
8995    {
8996       for(arrIdx = 0; arrIdx < ueNrCap->rf_Parameters.supportedBandListNR.list.count; arrIdx++)
8997       {
8998          if(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx])
8999             free(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx]);
9000       }
9001       free(ueNrCap->rf_Parameters.supportedBandListNR.list.array);
9002    }
9003
9004    if(ueNrCap->featureSets)
9005    {
9006       featureSets = ueNrCap->featureSets;
9007       if(featureSets->featureSetsDownlinkPerCC)
9008       {
9009          if(featureSets->featureSetsDownlinkPerCC->list.array)
9010          {
9011             for(arrIdx = 0; arrIdx < featureSets->featureSetsDownlinkPerCC->list.count; arrIdx++)
9012             {
9013                if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx])
9014                {
9015                   if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL)
9016                      free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL);
9017                   free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]);
9018                }
9019             }
9020             free(featureSets->featureSetsDownlinkPerCC->list.array);
9021          }
9022          free(featureSets->featureSetsDownlinkPerCC);
9023       }
9024       if(featureSets->featureSetsUplinkPerCC)
9025       {
9026          if(featureSets->featureSetsUplinkPerCC->list.array)
9027          {
9028             for(arrIdx = 0; arrIdx < featureSets->featureSetsUplinkPerCC->list.count; arrIdx++)
9029             {
9030                if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx])
9031                {
9032                   if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL)
9033                      free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL);
9034                   free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]);
9035                }
9036             }
9037             free(featureSets->featureSetsUplinkPerCC->list.array);
9038          }
9039          free(featureSets->featureSetsUplinkPerCC);
9040       }
9041       free(ueNrCap->featureSets);
9042    }   
9043 }
9044
9045 /*******************************************************************
9046 *
9047 * @brief Function to free PdcchSearchSpcToAddModList
9048          where memory allocated by aper_decoder
9049 *
9050 * @details
9051 *
9052 *    Function : freeAperDecodePdcchSearchSpcToAddModList 
9053 *
9054 *    Functionality: Function to free PdcchSearchSpcToAddModList
9055 *
9056 * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
9057 * @return void
9058 *
9059 * ****************************************************************/
9060
9061 void freeAperDecodePdcchSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
9062 {
9063    uint8_t searchSpcArrIdx=0;
9064    uint8_t searchSpcArrIdx1=0;
9065    struct  SearchSpace *searchSpc=NULLP;
9066
9067
9068    if(searchSpcList->list.array)
9069    {
9070       if(searchSpcList->list.array[searchSpcArrIdx1])
9071       {
9072          searchSpc = searchSpcList->list.array[searchSpcArrIdx1];
9073          if(searchSpc->controlResourceSetId)
9074          {
9075             if(searchSpc->monitoringSlotPeriodicityAndOffset)
9076             {
9077                if(searchSpc->monitoringSymbolsWithinSlot)
9078                {
9079                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
9080                   {
9081                      if(searchSpc->nrofCandidates)
9082                      {
9083                         if(searchSpc->searchSpaceType)
9084                         {
9085                            free(searchSpc->searchSpaceType->choice.ue_Specific);
9086                            free(searchSpc->searchSpaceType);
9087                         }
9088                         free(searchSpc->nrofCandidates);
9089                      }
9090                      free(searchSpc->monitoringSymbolsWithinSlot->buf);
9091                   }
9092                   free(searchSpc->monitoringSymbolsWithinSlot);
9093                }
9094                free(searchSpc->monitoringSlotPeriodicityAndOffset);
9095             }
9096             free(searchSpc->controlResourceSetId);
9097          }
9098       }
9099       for(searchSpcArrIdx = 0; searchSpcArrIdx < searchSpcList->list.count; searchSpcArrIdx++)
9100       {
9101          free(searchSpcList->list.array[searchSpcArrIdx]);
9102       }
9103       free(searchSpcList->list.array);
9104    }
9105 }
9106 /*******************************************************************
9107 *
9108 * @brief Function for free part for the memory allocated by aper_decoder
9109
9110 * @details
9111 *
9112 *    Function : freeAperDecodeBWPDlDedPdcchConfig
9113 *
9114 *    Functionality: Function to free BWPDlDedPdcchConfig
9115 *
9116 * @params[in] 
9117 * @return void
9118 *
9119 * ****************************************************************/
9120
9121
9122 void freeAperDecodeBWPDlDedPdcchConfig(BWP_DownlinkDedicated_t *dlBwp)
9123 {
9124    uint8_t arrIdx1=0;
9125    uint8_t arrIdx2=0;
9126    struct PDCCH_Config *pdcchCfg=NULLP;
9127    struct ControlResourceSet *controlRSet=NULLP;
9128    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
9129    
9130    if(dlBwp->pdcch_Config->choice.setup)
9131    {
9132       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
9133       if(pdcchCfg->controlResourceSetToAddModList)
9134       {
9135          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
9136          if(controlRSetList->list.array)
9137          {
9138             controlRSet = controlRSetList->list.array[arrIdx2];
9139             if(controlRSet)
9140             {
9141                if(controlRSet->frequencyDomainResources.buf)
9142                {
9143                   if(controlRSet->pdcch_DMRS_ScramblingID)
9144                   {
9145                      if(pdcchCfg->searchSpacesToAddModList)
9146                      {
9147                         freeAperDecodePdcchSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
9148                         free(pdcchCfg->searchSpacesToAddModList);
9149                      }
9150                      free(controlRSet->pdcch_DMRS_ScramblingID);
9151                   }
9152                   free(controlRSet->frequencyDomainResources.buf);
9153                }
9154             }
9155             for(arrIdx1 = 0; arrIdx1 <controlRSetList->list.count; arrIdx1++)
9156             {
9157                free(controlRSetList->list.array[arrIdx1]);
9158             }
9159             free(controlRSetList->list.array);
9160          }
9161          free(pdcchCfg->controlResourceSetToAddModList);
9162       }
9163       free(dlBwp->pdcch_Config->choice.setup);
9164    }
9165 }
9166 /*******************************************************************
9167 *
9168 * @brief Function to free PdschTimeDomAllocationList 
9169 *     where the memory allocated by aper_decoder
9170
9171 * @details
9172 *
9173 *    Function : freeAperDecodePdschTimeDomAllocationList
9174 *
9175 *    Functionality: Function to free PdschTimeDomAllocationList
9176 *
9177 * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList 
9178 * @return void
9179 *
9180 * ****************************************************************/
9181
9182
9183 void freeAperDecodePdschTimeDomAllocationList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
9184 {
9185    uint8_t arrIdx=0;
9186
9187    if(timeDomAllocList->choice.setup)
9188    {
9189       if(timeDomAllocList->choice.setup->list.array)
9190       {
9191          for(arrIdx = 0; arrIdx <timeDomAllocList->choice.setup->list.count ; arrIdx++)
9192          {
9193             free(timeDomAllocList->choice.setup->list.array[arrIdx]);
9194          }
9195          free(timeDomAllocList->choice.setup->list.array);
9196       }
9197       free(timeDomAllocList->choice.setup);
9198    }
9199 }
9200
9201 /*******************************************************************
9202 *
9203 * @brief Function to free BWPDlDedPdschConfig 
9204 *        where the memory allocated by aper_decoder
9205 *  
9206 * @details
9207 *
9208 *    Function : freeAperDecodeBWPDlDedPdschConfig 
9209 *
9210 *    Functionality: Function to free BWPDlDedPdschConfig 
9211 *
9212 * @params[in] BWP_DownlinkDedicated_t *dlBwp 
9213 * @return void
9214 *
9215 * ****************************************************************/
9216
9217
9218 void freeAperDecodeBWPDlDedPdschConfig(BWP_DownlinkDedicated_t *dlBwp)
9219 {
9220    struct PDSCH_Config *pdschCfg=NULLP;
9221    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
9222    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
9223    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
9224
9225    if(dlBwp->pdsch_Config->choice.setup)
9226    {
9227       pdschCfg=dlBwp->pdsch_Config->choice.setup;
9228       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
9229       {
9230          if(pdschCfg->pdsch_TimeDomainAllocationList)
9231          {
9232             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
9233             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
9234             {
9235                prbBndlType=&pdschCfg->prb_BundlingType;
9236                free(prbBndlType->choice.staticBundling);
9237                free(pdschCfg->maxNrofCodeWordsScheduledByDCI);
9238             }
9239             freeAperDecodePdschTimeDomAllocationList(timeDomAllocList);
9240             free(pdschCfg->pdsch_TimeDomainAllocationList);
9241          }
9242          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
9243          if(dmrsDlCfg->choice.setup)
9244          {
9245             free(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition);
9246             free(dmrsDlCfg->choice.setup);
9247          }
9248          free(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA);
9249       }
9250       free(dlBwp->pdsch_Config->choice.setup);
9251    }
9252 }
9253 /*******************************************************************
9254 *
9255 * @brief Function to free PuschTimeDomAllocListCfg
9256                  where the memory allocated by aper_decoder
9257 *
9258 * @details
9259 *
9260 *    Function : freeAperDecodePuschTimeDomAllocListCfg
9261 *
9262 *    Functionality: Function to free PuschTimeDomAllocListCfg
9263 *
9264 * @params[in] PUSCH_Config_t *puschCfg 
9265 * @return void
9266 *
9267 * ****************************************************************/
9268
9269
9270 void freeAperDecodePuschTimeDomAllocListCfg(PUSCH_Config_t *puschCfg)
9271 {
9272    uint8_t arrIdx=0;
9273    uint8_t arrIdx1=0;
9274    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
9275
9276    if(puschCfg->pusch_TimeDomainAllocationList)
9277    {
9278       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
9279       if(timeDomAllocList_t->choice.setup)
9280       {
9281          if(timeDomAllocList_t->choice.setup->list.array)
9282          {
9283             free(timeDomAllocList_t->choice.setup->list.array[arrIdx1]->k2);
9284             for(arrIdx = 0; arrIdx<timeDomAllocList_t->choice.setup->list.count; arrIdx++)
9285             {
9286                free(timeDomAllocList_t->choice.setup->list.array[arrIdx]);
9287             }
9288             free(timeDomAllocList_t->choice.setup->list.array);
9289          }
9290          free(timeDomAllocList_t->choice.setup);
9291       }
9292       free(puschCfg->transformPrecoder);
9293       free(puschCfg->pusch_TimeDomainAllocationList);
9294    }
9295 }
9296 /*******************************************************************
9297 *
9298 * @brief Function to free InitialUlBWPConfig where memory allocated by aper_decoder
9299 *
9300 * @details
9301 *
9302 *    Function : freeAperDecodeInitialUlBWPConfig 
9303 *
9304 *    Functionality: Function to free InitialUlBWPConfig
9305 *
9306 * @params[in]  BWP_UplinkDedicated_t *ulBwp
9307 * @return void
9308 *
9309 * ****************************************************************/
9310
9311
9312 void freeAperDecodeInitialUlBWPConfig(BWP_UplinkDedicated_t *ulBwp)
9313 {
9314    uint8_t  rSetIdx =0;
9315    uint8_t  rsrcIdx =0;
9316    SRS_Config_t   *srsCfg = NULLP;
9317    PUSCH_Config_t *puschCfg = NULLP;
9318    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
9319    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
9320    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
9321    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
9322
9323    if(ulBwp->pusch_Config)
9324    {
9325       if(ulBwp->pusch_Config->choice.setup)
9326       {
9327          puschCfg=ulBwp->pusch_Config->choice.setup;
9328          if(puschCfg->dataScramblingIdentityPUSCH)
9329          {
9330             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
9331             {
9332                freeAperDecodePuschTimeDomAllocListCfg(puschCfg);
9333                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
9334                if(dmrsUlCfg->choice.setup)
9335                {
9336                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
9337                   {
9338                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
9339                      {
9340                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0);
9341                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled);
9342                      }
9343                      free(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition);
9344                   }
9345                   free(dmrsUlCfg->choice.setup);
9346                }
9347                free(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA);
9348             }
9349             free(puschCfg->dataScramblingIdentityPUSCH);
9350          }
9351          free(ulBwp->pusch_Config->choice.setup);
9352       }
9353       free(ulBwp->pusch_Config);
9354
9355       /* Free SRS-Config */
9356       if(ulBwp->srs_Config)
9357       {
9358          if(ulBwp->srs_Config->choice.setup)
9359          {
9360             srsCfg = ulBwp->srs_Config->choice.setup;
9361
9362             /* Free Resource Set to add/mod list */
9363             if(srsCfg->srs_ResourceSetToAddModList)
9364             {
9365                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
9366                if(rsrcSetList->list.array)
9367                {
9368                   rSetIdx = 0;
9369
9370                   /* Free SRS resource Id list in this SRS resource set */
9371                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
9372                   {
9373                      rsrcIdList =
9374                         rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
9375
9376                      if(rsrcIdList->list.array)
9377                      {
9378                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count;
9379                               rsrcIdx++)
9380                         {
9381                            free(rsrcIdList->list.array[rsrcIdx]);
9382                         }
9383                         free(rsrcIdList->list.array);
9384                      }
9385                      free(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList);
9386                   }
9387
9388                   /* Free resource type info for this SRS resource set */
9389
9390                   free(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic);
9391
9392                   /* Free memory for each resource set */
9393                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
9394                   {
9395                      free(rsrcSetList->list.array[rSetIdx]);
9396                   }
9397                   free(rsrcSetList->list.array);
9398                }
9399                free(srsCfg->srs_ResourceSetToAddModList);
9400             }
9401
9402             /* Free resource to add/modd list */
9403             if(srsCfg->srs_ResourceToAddModList)
9404             {
9405                resourceList = srsCfg->srs_ResourceToAddModList;
9406                if(resourceList->list.array)
9407                {
9408                   rsrcIdx = 0;
9409
9410                   free(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2);
9411                   free(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic);
9412
9413                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
9414                   {
9415                      free(resourceList->list.array[rsrcIdx]);
9416                   }
9417                   free(resourceList->list.array);
9418                }
9419                free(srsCfg->srs_ResourceToAddModList);
9420             }
9421
9422             free(ulBwp->srs_Config->choice.setup);
9423          }
9424          free(ulBwp->srs_Config);
9425       }
9426    }
9427 }
9428 /*******************************************************************
9429 *
9430 * @brief Function to free initialUplinkBWPConfig where memory allocated by aper_decoder
9431 *
9432 * @details
9433 *
9434 *    Function : freeAperDecodeinitialUplinkBWPConfig
9435 *
9436 *    Functionality: Function to free initialUplinkBWPConfig
9437 *
9438 * @params[in] UplinkConfig_t *ulCfg 
9439 * @return void
9440 *
9441 * ****************************************************************/
9442
9443
9444 void freeAperDecodeinitialUplinkBWPConfig(UplinkConfig_t *ulCfg)
9445 {
9446    BWP_UplinkDedicated_t *ulBwp=NULLP;
9447    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
9448    
9449    if(ulCfg->initialUplinkBWP)
9450    {
9451       ulBwp=ulCfg->initialUplinkBWP;
9452       if(ulCfg->firstActiveUplinkBWP_Id)
9453       {
9454          if(ulCfg->pusch_ServingCellConfig)
9455          {
9456             puschCfg=ulCfg->pusch_ServingCellConfig;
9457             if(puschCfg->choice.setup)
9458             {
9459                if(puschCfg->choice.setup->ext1)
9460                {
9461                   free(puschCfg->choice.setup->ext1->processingType2Enabled);
9462                   free(puschCfg->choice.setup->ext1->maxMIMO_Layers);
9463                   free(puschCfg->choice.setup->ext1);
9464                }
9465                free(puschCfg->choice.setup);
9466             }
9467             free(ulCfg->pusch_ServingCellConfig);
9468          }
9469          free(ulCfg->firstActiveUplinkBWP_Id);
9470       }
9471       freeAperDecodeInitialUlBWPConfig(ulBwp);
9472       free(ulCfg->initialUplinkBWP);
9473    }
9474 }
9475
9476 /*******************************************************************
9477  *
9478  * @brief Function to free DuUeCfg
9479  *
9480  * @details
9481  *
9482  *    Function : freeDuUeCfg
9483  *
9484  *    Functionality: Function to free DuUeCfg
9485  *
9486  * @params[in] DuUeCfg *ueCfg
9487  * @return void
9488  *
9489  * ****************************************************************/
9490 void freeDuUeCfg(UeCtxtActionType actionType, DuUeCfg *ueCfg)
9491 {
9492    uint8_t lcIdx = 0;
9493    uint8_t arrIdx = 0;
9494    SpCellConfig_t *spCellCfg = NULLP;
9495    ServingCellConfig_t *srvCellCfg = NULLP;
9496    BWP_DownlinkDedicated_t *dlBwp = NULLP;
9497    MAC_CellGroupConfig_t *macCellGrpCfg = NULLP;
9498    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
9499    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList = NULLP;
9500    struct RLC_Config *rlcConfig = NULLP;
9501    struct LogicalChannelConfig *macLcConfig = NULLP;
9502    struct SchedulingRequestConfig *schedulingRequestConfig = NULLP;
9503    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList = NULLP;
9504    struct TAG_Config *tagConfig = NULLP;
9505    struct TAG_Config__tag_ToAddModList *tagList = NULLP;
9506    struct MAC_CellGroupConfig__phr_Config *phrConfig = NULLP;
9507    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg = NULLP;
9508    CellGroupConfigRrc_t *cellGrpCfg = ueCfg->cellGrpCfg;
9509   
9510    if(ueCfg->ueNrCapability)
9511    {
9512       freeAperDecodeUeNrCapability(ueCfg->ueNrCapability);
9513       DU_FREE(ueCfg->ueNrCapability, sizeof(UE_NR_Capability_t));
9514       ueCfg->ueNrCapability = NULLP;
9515    }
9516
9517    if(ueCfg->cellGrpCfg)
9518    {
9519       rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
9520       if(rlcBearerList)
9521       {
9522          if(rlcBearerList->list.array)
9523          {
9524             for(arrIdx=0; arrIdx<rlcBearerList->list.count; arrIdx++)
9525             {
9526                if(rlcBearerList->list.array[arrIdx])
9527                {
9528                   rlcConfig   = rlcBearerList->list.array[arrIdx]->rlc_Config;
9529                   macLcConfig = rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig;
9530
9531                   if(rlcBearerList->list.array[arrIdx]->servedRadioBearer)
9532                   {
9533                      free(rlcBearerList->list.array[arrIdx]->servedRadioBearer);
9534                   }
9535                   if(rlcConfig)
9536                   {
9537                      if(rlcConfig->choice.am)
9538                      {
9539                         free(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength);
9540                         free(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength);
9541                         free(rlcConfig->choice.am);
9542                      }
9543                      free(rlcBearerList->list.array[arrIdx]->rlc_Config);
9544                   }
9545                   if(macLcConfig)
9546                   {
9547                      if(macLcConfig->ul_SpecificParameters)
9548                      {
9549                         free(macLcConfig->ul_SpecificParameters->schedulingRequestID);
9550                         free(macLcConfig->ul_SpecificParameters->logicalChannelGroup);
9551                         free(macLcConfig->ul_SpecificParameters);
9552                      }
9553                      free(rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig);
9554                   }
9555                   free(rlcBearerList->list.array[arrIdx]); 
9556                }
9557             }
9558             free(rlcBearerList->list.array);
9559          }
9560          free(cellGrpCfg->rlc_BearerToAddModList);
9561       }
9562
9563       macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
9564       if(macCellGrpCfg)
9565       {
9566          schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig;
9567          if(schedulingRequestConfig)
9568          {
9569             schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
9570             if(schReqList)
9571             {
9572                if(schReqList->list.array)
9573                {
9574                   for(arrIdx=0;arrIdx<schReqList->list.count; arrIdx++)
9575                   {
9576                      if(schReqList->list.array[arrIdx])
9577                      {
9578                         free(schReqList->list.array[arrIdx]->sr_ProhibitTimer); 
9579                         free(schReqList->list.array[arrIdx]);
9580                      }
9581                   }
9582                   free(schReqList->list.array);
9583                }
9584                free(schedulingRequestConfig->schedulingRequestToAddModList);
9585             }
9586             free(macCellGrpCfg->schedulingRequestConfig);
9587          }
9588          if(macCellGrpCfg->bsr_Config)
9589          {
9590             free(macCellGrpCfg->bsr_Config);
9591          }
9592          tagConfig = macCellGrpCfg->tag_Config;
9593          if(tagConfig)
9594          {
9595             tagList = tagConfig->tag_ToAddModList;
9596             if(tagList)
9597             {
9598                if(tagList->list.array)
9599                {
9600                   for(arrIdx=0; arrIdx<tagList->list.count; arrIdx++)
9601                   {
9602                      free(tagList->list.array[arrIdx]);
9603                   }
9604                   free(tagList->list.array);
9605                }
9606                free(tagConfig->tag_ToAddModList);
9607             }
9608             free(tagConfig); 
9609          }
9610
9611          phrConfig = macCellGrpCfg->phr_Config;
9612          if(phrConfig)
9613          {
9614             free(phrConfig->choice.setup); 
9615             free(phrConfig); 
9616          }
9617
9618          free(macCellGrpCfg); 
9619       }
9620
9621       phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
9622       if(phyCellGrpCfg)
9623       {
9624          free(phyCellGrpCfg->p_NR_FR1);
9625          free(phyCellGrpCfg); 
9626       }
9627
9628       spCellCfg = cellGrpCfg->spCellConfig;
9629       if(spCellCfg)
9630       {
9631          if(spCellCfg->servCellIndex)
9632          {
9633             if(spCellCfg->rlmInSyncOutOfSyncThreshold)
9634             {
9635                if(spCellCfg->spCellConfigDedicated)
9636                {
9637                   srvCellCfg = spCellCfg->spCellConfigDedicated;
9638                   if(srvCellCfg->initialDownlinkBWP)
9639                   {
9640                      dlBwp = srvCellCfg->initialDownlinkBWP;
9641                      if(srvCellCfg->firstActiveDownlinkBWP_Id)
9642                      {
9643                         if(srvCellCfg->defaultDownlinkBWP_Id)
9644                         {
9645                            if(srvCellCfg->uplinkConfig)
9646                            {
9647
9648                               if(srvCellCfg->pdsch_ServingCellConfig)
9649                               {
9650                                  pdschCfg=
9651                                     srvCellCfg->pdsch_ServingCellConfig;
9652                                  if(pdschCfg->choice.setup)
9653                                  {
9654
9655                                     free(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH);
9656                                     free(pdschCfg->choice.setup);
9657                                  }
9658
9659                                  free(srvCellCfg->pdsch_ServingCellConfig);
9660                               }
9661
9662                               freeAperDecodeinitialUplinkBWPConfig(srvCellCfg->uplinkConfig);
9663                               free(srvCellCfg->uplinkConfig);
9664                            }
9665                            free(srvCellCfg->defaultDownlinkBWP_Id);
9666                         }
9667
9668                         free(srvCellCfg->firstActiveDownlinkBWP_Id);
9669                      }
9670                      if(dlBwp->pdcch_Config)
9671                      {
9672                         if(dlBwp->pdsch_Config)
9673                         {
9674                            freeAperDecodeBWPDlDedPdschConfig(dlBwp);
9675                            free(dlBwp->pdsch_Config);
9676                         }
9677                         freeAperDecodeBWPDlDedPdcchConfig(dlBwp);
9678                         free(dlBwp->pdcch_Config);
9679                      }
9680                      free(srvCellCfg->initialDownlinkBWP);
9681                   }
9682
9683                   free(spCellCfg->spCellConfigDedicated);
9684                }
9685                free(spCellCfg->rlmInSyncOutOfSyncThreshold);
9686             }
9687             free(spCellCfg->servCellIndex); 
9688          }
9689          free(spCellCfg);
9690       }
9691       DU_FREE(ueCfg->cellGrpCfg, sizeof(CellGroupConfigRrc_t));
9692       ueCfg->cellGrpCfg = NULLP;
9693    }
9694
9695    if(ueCfg->ambrCfg)
9696    {
9697       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCfg->ambrCfg, sizeof(AmbrCfg));
9698    }
9699
9700    if(actionType != UE_CTXT_CFG_QUERY)
9701    {
9702       for(lcIdx = 0; lcIdx < ueCfg->numRlcLcs; lcIdx++)
9703       {
9704          freeRlcLcCfg(&ueCfg->rlcLcCfg[lcIdx]);
9705       }
9706    }
9707
9708    for(lcIdx = 0; lcIdx < ueCfg->numMacLcs; lcIdx++)
9709    {
9710       freeMacLcCfg(&ueCfg->macLcCfg[lcIdx]);
9711    }
9712
9713    for(lcIdx = 0; lcIdx < ueCfg->numDrb; lcIdx++)
9714    {
9715       DU_FREE(ueCfg->upTnlInfo[lcIdx].tnlCfg1, sizeof(GtpTnlCfg));
9716    }
9717 }
9718
9719 /*******************************************************************
9720  *
9721  * @brief Function to free UecontextSetupDb
9722  *
9723  * @details
9724  *
9725  *    Function : freeF1UeDb
9726  *
9727  *    Functionality: Function to free UecontextSetupDb
9728  *
9729  * @params[in] UecontextSetupDb *
9730  * @return void
9731  *
9732  * ****************************************************************/
9733
9734 void freeF1UeDb(F1UeContextSetupDb *f1UeDb)
9735 {
9736    
9737    if(f1UeDb->dlRrcMsg)
9738    {
9739       if(f1UeDb->dlRrcMsg->rrcMsgPdu)
9740       {
9741         //DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,\
9742                f1UeDb->dlRrcMsg->rrcMsgPdu, f1UeDb->dlRrcMsg->rrcMsgSize);
9743       }
9744       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
9745    }
9746    freeDuUeCfg(f1UeDb->actionType, &f1UeDb->duUeCfg);
9747    memset(f1UeDb, 0, sizeof(F1UeContextSetupDb));
9748    DU_FREE(f1UeDb, sizeof(F1UeContextSetupDb));
9749 }
9750
9751 /*******************************************************************
9752  *
9753  * @brief Function to build Am cfg Info
9754  *
9755  * @details
9756  *
9757  *    Function : extractRlcAmCfg
9758  *
9759  *    Functionality: Function to build Am cfg Info
9760  *
9761  * @params[in] AmBearerCfg *
9762  *             void *
9763  *
9764  * @return ROK/RFAILED
9765  *
9766  * ****************************************************************/
9767
9768 void extractRlcAmCfg(AmBearerCfg *amCfgToSet, struct RLC_Config__am *rlcAmCfg)
9769 {
9770    if(rlcAmCfg)
9771    {
9772       /* UL AM */
9773       if(rlcAmCfg->dl_AM_RLC.sn_FieldLength)
9774       {
9775          amCfgToSet->ulAmCfg.snLenUl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->dl_AM_RLC.sn_FieldLength));
9776          /*TODO: Check the timer value when sent by real CU */
9777          amCfgToSet->ulAmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_Reassembly); 
9778          amCfgToSet->ulAmCfg.statProhTmr = convertProhibitTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_StatusProhibit);
9779       }
9780
9781       /* DL AM */
9782       if(rlcAmCfg->ul_AM_RLC.sn_FieldLength)
9783       {
9784          amCfgToSet->dlAmCfg.snLenDl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->ul_AM_RLC.sn_FieldLength));
9785          amCfgToSet->dlAmCfg.pollRetxTmr = covertPollRetxTmrEnumToValue(rlcAmCfg->ul_AM_RLC.t_PollRetransmit);
9786          amCfgToSet->dlAmCfg.pollPdu   = covertPollPduEnumToValue(rlcAmCfg->ul_AM_RLC.pollPDU);
9787          amCfgToSet->dlAmCfg.pollByte  = covertPollByteEnumToValue(rlcAmCfg->ul_AM_RLC.pollByte);
9788          amCfgToSet->dlAmCfg.maxRetxTh = covertMaxRetxEnumToValue(rlcAmCfg->ul_AM_RLC.maxRetxThreshold);
9789       }
9790    }
9791 }
9792
9793 /*******************************************************************
9794  *
9795  * @brief Function to build Um Bi Info
9796  *
9797  * @details
9798  *
9799  *    Function : extractRlcUmBiCfg
9800  *
9801  *    Functionality: Function to build Um Bi Info
9802  *
9803  * @params[in] UmBiDirBearerCfg *
9804  *             void *
9805  *
9806  * @return ROK/RFAILED
9807  *
9808  * ****************************************************************/
9809
9810 void extractRlcUmBiCfg(UmBiDirBearerCfg *umBiCfgToSet, struct RLC_Config__um_Bi_Directional *rlcBiCfg)
9811 {
9812    if(rlcBiCfg)
9813    {
9814       /* UL UM BI DIR Cfg */
9815       if(rlcBiCfg->dl_UM_RLC.sn_FieldLength)
9816       {
9817          umBiCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->dl_UM_RLC.sn_FieldLength));
9818          umBiCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcBiCfg->dl_UM_RLC.t_Reassembly);
9819       }
9820
9821       /* DL UM BI DIR Cfg */
9822       if(rlcBiCfg->ul_UM_RLC.sn_FieldLength)
9823          umBiCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->ul_UM_RLC.sn_FieldLength));
9824    }
9825 }
9826
9827 /*******************************************************************
9828  *
9829  * @brief Function to build Um Ul Info
9830  *
9831  * @details
9832  *
9833  *    Function : extractRlcUmUlCfg
9834  *
9835  *    Functionality: Function to build Um Ul Info
9836  *
9837  * @params[in] UmUniDirUlBearerCfg *
9838  *             void *
9839  *
9840  * @return ROK/RFAILED
9841  *
9842  * ****************************************************************/
9843
9844 void extractRlcUmUlCfg(UmUniDirUlBearerCfg *umUlCfgToSet, struct RLC_Config__um_Uni_Directional_DL *umUlCfg)
9845 {
9846    if(umUlCfg)
9847    {
9848       if(umUlCfg->dl_UM_RLC.sn_FieldLength)
9849       {
9850          umUlCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umUlCfg->dl_UM_RLC.sn_FieldLength));
9851          umUlCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(umUlCfg->dl_UM_RLC.t_Reassembly);
9852       }
9853    }
9854 }
9855
9856 /*******************************************************************
9857  *
9858  * @brief Function to build Um Uni Dl Info
9859  *
9860  * @details
9861  *
9862  *    Function : extractRlcUmDlCfg
9863  *
9864  *    Functionality: Function to build Um Uni Dl Info
9865  *
9866  * @params[in] UmUniDirDlBearerCfg *
9867  *             void *
9868  *
9869  * @return ROK/RFAILED
9870  *
9871  * ****************************************************************/
9872 void extractRlcUmDlCfg(UmUniDirDlBearerCfg *umDlCfgToSet, struct RLC_Config__um_Uni_Directional_UL *umDlCfg)
9873 {
9874    if(umDlCfg)
9875    {
9876       if(umDlCfg->ul_UM_RLC.sn_FieldLength)
9877          umDlCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umDlCfg->ul_UM_RLC.sn_FieldLength));
9878    }
9879 }
9880
9881 /*******************************************************************
9882  *
9883  * @brief Function to extractRlcModeCfg
9884  *
9885  * @details
9886  *
9887  *    Function : extractRlcModeCfg
9888  *
9889  *    Functionality: Function to extractRlcModeCfg
9890  *
9891  * @params[in] RLC_Config_t *
9892  *             RlcBearerCfg *
9893  *             void  *    
9894  * @return ROK/RFAILED
9895  *
9896  * ****************************************************************/
9897 void extractRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *rlcDbCfg, RLC_Config_t *lcCfg)
9898 {
9899    if(lcCfg)
9900    {
9901       switch(rlcMode)
9902       {
9903          case RLC_AM :
9904             {
9905                if(lcCfg->choice.am)
9906                {
9907                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.amCfg, sizeof(AmBearerCfg));
9908                   if(rlcDbCfg->u.amCfg)
9909                      extractRlcAmCfg(rlcDbCfg->u.amCfg, lcCfg->choice.am);
9910                }
9911                break;
9912             }
9913          case RLC_UM_BI_DIRECTIONAL :
9914             {
9915                if(lcCfg->choice.um_Bi_Directional)
9916                {
9917                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
9918                   if(rlcDbCfg->u.umBiDirCfg)
9919                      extractRlcUmBiCfg(rlcDbCfg->u.umBiDirCfg, lcCfg->choice.um_Bi_Directional);
9920                }
9921                break;
9922             }
9923          case RLC_UM_UNI_DIRECTIONAL_UL :
9924             {
9925                if(lcCfg->choice.um_Uni_Directional_DL)
9926                {
9927                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
9928                   if(rlcDbCfg->u.umUniDirUlCfg)
9929                      extractRlcUmUlCfg(rlcDbCfg->u.umUniDirUlCfg, lcCfg->choice.um_Uni_Directional_DL);
9930                }
9931                break;
9932             }
9933          case RLC_UM_UNI_DIRECTIONAL_DL :
9934             {
9935                if(lcCfg->choice.um_Uni_Directional_UL)
9936                {
9937                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
9938                   if(rlcDbCfg->u.umUniDirDlCfg)
9939                      extractRlcUmDlCfg(rlcDbCfg->u.umUniDirDlCfg, lcCfg->choice.um_Uni_Directional_UL);
9940                }
9941                break;
9942             }
9943          default:
9944             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
9945             break;
9946       }
9947    }
9948 }
9949
9950 /*******************************************************************
9951  *
9952  * @brief Function to extract extractUlLcCfg
9953  *
9954  * @details
9955  *
9956  *    Function : extractUlLcCfg
9957  *
9958  *    Functionality: Function to extract extractUlLcCfg
9959  *
9960  * @params[in] UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg
9961  * @return void
9962  *
9963  * ****************************************************************/
9964
9965 void extractUlLcCfg(UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg)
9966 {
9967    if(ulLcCfg)
9968    {
9969       if(ulLcCfg->ul_SpecificParameters)
9970       {
9971          f1UlLcCfg->priority = \
9972             ulLcCfg->ul_SpecificParameters->priority;
9973       if(ulLcCfg->ul_SpecificParameters->logicalChannelGroup)
9974       {
9975          f1UlLcCfg->lcGroup = \
9976            *(ulLcCfg->ul_SpecificParameters->logicalChannelGroup);
9977       }
9978       if(ulLcCfg->ul_SpecificParameters->schedulingRequestID)
9979       {
9980          f1UlLcCfg->schReqId = \
9981            *(ulLcCfg->ul_SpecificParameters->schedulingRequestID);
9982       }
9983       f1UlLcCfg->pbr = \
9984          ulLcCfg->ul_SpecificParameters->prioritisedBitRate;
9985       f1UlLcCfg->bsd = \
9986          ulLcCfg->ul_SpecificParameters->bucketSizeDuration;
9987       }
9988    }
9989 }
9990
9991 /*******************************************************************
9992 *
9993 * @brief Function to extract Snssai Cfg Info from CU
9994 *
9995 * @details
9996 *
9997 *    Function : extractDrbSnssaiCfg
9998 *
9999 *    Functionality: Function to extract Drb Snssai Cfg Info from CU
10000 *
10001 * @params[in] DRB_Information_t *drbInfo, Snssai  *snssai
10002 * @return ROK/RFAILED
10003 *
10004 * ****************************************************************/
10005
10006 uint8_t extractDrbSnssaiCfg(SNSSAI_t *RecvSnssai, Snssai **snssaiToBeShared)
10007 {
10008    if(!(*snssaiToBeShared))
10009    {
10010       DU_ALLOC_SHRABL_BUF((*snssaiToBeShared), sizeof(Snssai));
10011       if(snssaiToBeShared == NULLP)
10012       {
10013          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Memory failed at allocating for SNSSAI ");
10014          return RFAILED;
10015       }
10016    }
10017    if(RecvSnssai)
10018    {
10019       memcpy(&(*snssaiToBeShared)->sst, RecvSnssai->sST.buf, RecvSnssai->sST.size);
10020       if(RecvSnssai->sD)
10021       {
10022          memcpy((*snssaiToBeShared)->sd, RecvSnssai->sD->buf,  RecvSnssai->sD->size);
10023       }
10024       else
10025       {
10026          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Received Null pointer of Snssai->SD");
10027          return RFAILED;
10028       }
10029    }
10030    return ROK;
10031 }
10032
10033 /*******************************************************************
10034  *
10035  * @brief Function to procRlcLcCfg
10036  *
10037  * @details
10038  *
10039  *    Function : procRlcLcCfg
10040  *
10041  *    Functionality: Function to procRlcLcCfg
10042  *
10043  * @params[in] rbId, lcId, rbType, rlcMod
10044  *             RLC_Config_t *, RlcBearerCfg * , 
10045  * @return void
10046  *
10047  * ****************************************************************/
10048
10049 void procRlcLcCfg(uint8_t rbId, uint8_t lcId, uint8_t rbType, uint8_t rlcMode,\
10050    uint8_t configType, RLC_Config_t *f1RlcCfg, RlcBearerCfg *lcCfg, QoSInformation_t *qoSInformation)
10051 {
10052    DRB_Information_t *drbInfo;
10053
10054    lcCfg->rbId   = rbId;
10055    lcCfg->configType = configType;
10056
10057    if(rbType == RB_TYPE_SRB)
10058    {
10059       lcCfg->rbType = RB_TYPE_SRB;
10060       lcCfg->lcId   = rbId;
10061       lcCfg->lcType = LCH_DCCH;
10062       lcCfg->rlcMode = RLC_AM;
10063    }
10064    else if(rbType == RB_TYPE_DRB)
10065    {
10066       lcCfg->rbType = RB_TYPE_DRB;
10067       lcCfg->lcId   = lcId;
10068       lcCfg->lcType = LCH_DTCH;
10069       lcCfg->rlcMode = rlcMode;
10070    }
10071    if(f1RlcCfg) /* rlc mode config recived */
10072    {
10073       extractRlcModeCfg(lcCfg->rlcMode, lcCfg, f1RlcCfg);
10074    }
10075    if(qoSInformation != NULLP)
10076    {
10077       if(qoSInformation->present == QoSInformation_PR_choice_extension)
10078       {
10079          if(qoSInformation->choice.choice_extension->value.present ==\
10080                QoSInformation_ExtIEs__value_PR_DRB_Information)
10081          {
10082             drbInfo = &qoSInformation->choice.choice_extension->value.choice.DRB_Information; 
10083             if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &lcCfg->snssai) != ROK)
10084             {
10085                DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information at procRlcLcCfg()");
10086                return;
10087             }
10088          }
10089       }
10090    }
10091 }
10092
10093 /*******************************************************************
10094  *
10095  * @brief Fills DrbQos Info received by CU
10096  *
10097  * @details
10098  *
10099  *    Function : extractQosInfo
10100  *
10101  *    Functionality: Fills DrbQos Info received  by CU
10102  *
10103  * @params[in] DrbQosInfo *qosToAdd, 
10104  *             QoSFlowLevelQoSParameters_t *qosFlowCfg
10105  * @return void
10106  *
10107  * ****************************************************************/
10108
10109 void extractQosInfo(DrbQosInfo *qosToAdd, QoSFlowLevelQoSParameters_t *qosFlowCfg)
10110 {
10111    uint8_t qosCntIdx = 0;
10112    ProtocolExtensionContainer_4624P74_t *qosIeExt = NULLP;
10113
10114    qosToAdd->fiveQiType = qosFlowCfg->qoS_Characteristics.present;
10115    qosToAdd->u.nonDyn5Qi.fiveQi     =\
10116                                      qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->fiveQI;
10117    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow)
10118    {
10119       qosToAdd->u.nonDyn5Qi.avgWindow = \
10120                                         *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
10121    }
10122
10123    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume)
10124    {
10125       qosToAdd->u.nonDyn5Qi.maxDataBurstVol = \
10126                                               *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
10127    }
10128
10129    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel)
10130    {
10131       qosToAdd->u.nonDyn5Qi.priorLevel = \
10132                                          *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel);
10133    }
10134    qosToAdd->ngRanRetPri.priorityLevel = \
10135                                          qosFlowCfg->nGRANallocationRetentionPriority.priorityLevel; 
10136    qosToAdd->ngRanRetPri.preEmptionCap = \
10137                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionCapability;
10138    qosToAdd->ngRanRetPri.preEmptionVul = \
10139                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionVulnerability;
10140    if(qosFlowCfg->gBR_QoS_Flow_Information)
10141    {
10142       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateDl, \
10143             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.buf, \
10144             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.size);
10145       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateUl, \
10146             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.buf, \
10147             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.size);
10148       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateDl,\
10149             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.buf, \
10150             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.size);
10151       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateUl,\
10152             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.buf, \
10153             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.size);
10154    }
10155    /*Extracting PDU_SESSION_ID*/
10156    qosIeExt = (ProtocolExtensionContainer_4624P74_t *)qosFlowCfg->iE_Extensions;
10157    if(qosIeExt)
10158    {
10159       for(qosCntIdx = 0; qosCntIdx < qosIeExt->list.count; qosCntIdx++)
10160       {
10161          if(qosIeExt->list.array[qosCntIdx]->extensionValue.present == \
10162                QoSFlowLevelQoSParameters_ExtIEs__extensionValue_PR_PDUSessionID)
10163          {
10164             qosToAdd->pduSessionId = qosIeExt->list.array[qosCntIdx]->extensionValue.choice.PDUSessionID;
10165             DU_LOG("\nDEBUG -->  DU_F1AP : extractQosInfo: PDU SessionID:%d",qosToAdd->pduSessionId);
10166          }
10167       }  
10168    }
10169    qosToAdd->ulPduSessAggMaxBitRate = 0;
10170 }
10171
10172 /*******************************************************************
10173  *
10174  * @brief Function to extract GTP Tunnel Info from CU
10175  *
10176  * @details
10177  *
10178  *    Function : extractUpTnlInfo
10179  *
10180  *    Functionality: Function to extract GTP Tunnel Info from CU
10181  *
10182  * @params[in] F1AP message
10183  * @return ROK/RFAILED
10184  *
10185  * ****************************************************************/
10186
10187 uint8_t extractUpTnlInfo(uint8_t drbId, uint8_t configType,\
10188    ULUPTNLInformation_ToBeSetup_List_t *tnlInfo, UpTnlCfg *upTnlInfo)
10189 {
10190    uint8_t tnlIdx;
10191    uint32_t ipv4_du = 0;
10192    GTPTunnel_t *gtpTunnel = NULLP;
10193
10194    upTnlInfo->drbId = drbId; 
10195    upTnlInfo->configType = configType;
10196 #ifdef O1_ENABLE
10197    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
10198 #else
10199    cmInetAddr((char *)DU_IP_V4_ADDR, &ipv4_du);
10200 #endif
10201
10202    for(tnlIdx=0; tnlIdx < tnlInfo->list.count; tnlIdx++)
10203    {
10204       if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.present == UPTransportLayerInformation_PR_gTPTunnel)
10205       {
10206          if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel)
10207          {
10208             gtpTunnel = tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel;
10209             DU_ALLOC(upTnlInfo->tnlCfg1, sizeof(GtpTnlCfg));
10210             if(upTnlInfo->tnlCfg1 == NULLP)
10211             {
10212                DU_LOG("\nERROR  -->  F1AP : extractUpTnlInfo: Failed to allocate mmeory for tunnel cfg 1");
10213                return RFAILED;
10214             }
10215             bitStringToInt(&gtpTunnel->transportLayerAddress, &upTnlInfo->tnlCfg1->ulTnlAddress);
10216             upTnlInfo->tnlCfg1->dlTnlAddress = ipv4_du;
10217             if(gtpTunnel->gTP_TEID.size > 0)
10218             {
10219                teIdStringToInt(gtpTunnel->gTP_TEID.buf, &upTnlInfo->tnlCfg1->teId);
10220             }
10221          }
10222          break;
10223       }
10224    }
10225    return ROK;
10226 }
10227
10228 /*******************************************************************
10229 *
10230 * @brief Function to extract Drb Qos Cfg Info from CU
10231 *
10232 * @details
10233 *
10234 *    Function : extractDrbQosCfg 
10235 *
10236 *    Functionality: Function to extract Drb Qos Cfg Info from CU
10237 *
10238 * @params[in] DRB_Information_t *drbInfo, LcCfg *macLcToAdd
10239 * @return ROK/RFAILED
10240 *
10241 * ****************************************************************/
10242
10243 uint8_t extractDrbQosCfg(DRB_Information_t *drbInfo, LcCfg *macLcToAdd ) 
10244 {
10245    if(!macLcToAdd->drbQos)
10246    {
10247       DU_ALLOC_SHRABL_BUF(macLcToAdd->drbQos, sizeof(DrbQosInfo));
10248       if(macLcToAdd->drbQos == NULLP)
10249       {
10250          DU_LOG("\nERROR  -->  DUAPP:Memory failed at allocating DrbQos at extractDrbQosCfg()");
10251          return RFAILED;
10252       }
10253
10254    }
10255    if(drbInfo->dRB_QoS.qoS_Characteristics.present == QoS_Characteristics_PR_non_Dynamic_5QI)
10256    {
10257       extractQosInfo(macLcToAdd->drbQos, &drbInfo->dRB_QoS);
10258       macLcToAdd->dlLcCfg.lcp = macLcToAdd->drbQos->ngRanRetPri.priorityLevel;
10259    }
10260    if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &macLcToAdd->snssai) != ROK)
10261    {
10262       DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information  at extractDrbQosCfg()");
10263       return RFAILED;
10264    }
10265    return ROK;
10266 }
10267 /*******************************************************************
10268  *
10269  * @brief Function to extract DRB info received from CU
10270  *
10271  * @details
10272  *
10273  *    Function : extractDrbCfg
10274  *
10275  *    Functionality: Function to extract DRB info received from CU
10276  *
10277  * @params[in] F1AP message
10278  * @return void
10279  *
10280  * ****************************************************************/
10281 uint8_t extractDrbCfg(DRBs_ToBeSetup_Item_t *drbItem, DRBs_ToBeSetupMod_Item_t *drbSetupModItem,\
10282 DRBs_ToBeModified_Item_t *drbModItem,  LcCfg *macLcToAdd, UpTnlCfg *upTnlInfo)
10283 {
10284    DRB_Information_t *drbInfo = NULLP;
10285
10286    if(drbItem != NULLP)
10287    {
10288       if(extractUpTnlInfo(drbItem->dRBID, CONFIG_ADD, &drbItem->uLUPTNLInformation_ToBeSetup_List, upTnlInfo) != ROK)
10289       {
10290          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10291          return RFAILED;
10292       }
10293       if(drbItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10294       {
10295          if(drbItem->qoSInformation.choice.choice_extension->value.present == QoSInformation_ExtIEs__value_PR_DRB_Information)
10296          {
10297             drbInfo = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10298             if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
10299             {
10300                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");
10301                return RFAILED;
10302             }
10303          }
10304       }
10305    }
10306    else if(drbSetupModItem != NULLP)
10307    {
10308       if(extractUpTnlInfo(drbSetupModItem->dRBID, CONFIG_ADD, &drbSetupModItem->uLUPTNLInformation_ToBeSetup_List,\
10309       upTnlInfo) != ROK)
10310       {
10311          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10312          return RFAILED;
10313       }
10314       if(drbSetupModItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10315       {
10316          if(drbSetupModItem->qoSInformation.choice.choice_extension->value.present ==\
10317          QoSInformation_ExtIEs__value_PR_DRB_Information)
10318          {
10319             drbInfo = &drbSetupModItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10320             if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
10321             {
10322                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10323                return RFAILED;
10324             }
10325
10326          }
10327       }
10328    }
10329    else if(drbModItem != NULLP)
10330    {
10331       if(extractUpTnlInfo(drbModItem->dRBID, CONFIG_MOD, &drbModItem->uLUPTNLInformation_ToBeSetup_List,\
10332       upTnlInfo) != ROK)
10333       {
10334          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10335          return RFAILED;
10336       }
10337       if(drbModItem->qoSInformation != NULLP)
10338       {
10339          if(drbModItem->qoSInformation->present == QoSInformation_PR_choice_extension)
10340          {
10341             if(drbModItem->qoSInformation->choice.choice_extension->value.present ==\
10342                   QoSInformation_ExtIEs__value_PR_DRB_Information)
10343             {
10344                drbInfo = &drbModItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information;
10345                if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
10346                {
10347                   DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10348                   return RFAILED;
10349                }
10350
10351             }
10352          }
10353       }
10354    }
10355    return ROK;
10356 }
10357
10358 /*******************************************************************
10359  *
10360  * @brief Function to extract RB info received from CU
10361  *
10362  * @details
10363  *
10364  *    Function : extractMacRbCfg
10365  *
10366  *    Functionality: Function to extract RB info received from CU
10367  *
10368  * @params[in] F1AP message
10369  * @return ROK/RFAILED
10370  *
10371  * ****************************************************************/
10372
10373 uint8_t extractMacRbCfg(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbCfg,\
10374 DRBs_ToBeSetupMod_Item_t *drbSetupModCfg,  DRBs_ToBeModified_Item_t *drbModCfg, LogicalChannelConfig_t *ulLcCfg, LcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10375 {
10376    if(drbCfg != NULLP)
10377    {
10378       if(extractDrbCfg(drbCfg, NULL, NULL, lcCfg, upTnlInfo) != ROK)
10379       {
10380          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10381          return RFAILED;
10382       }
10383    }
10384    else if(drbSetupModCfg != NULLP)
10385    { 
10386       if(extractDrbCfg(NULL, drbSetupModCfg, NULL, lcCfg, upTnlInfo) != ROK)
10387       {
10388          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10389          return RFAILED;
10390       }
10391    }
10392    else if(drbModCfg != NULLP)
10393    { 
10394       if(extractDrbCfg(NULL, NULL, drbModCfg, lcCfg, upTnlInfo) != ROK)
10395       {
10396          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10397          return RFAILED;
10398       }
10399    }
10400    else
10401    {
10402       lcCfg->drbQos = NULLP;
10403       lcCfg->snssai = NULLP;
10404       if(lcCfg->lcId == SRB2_LCID)
10405          lcCfg->dlLcCfg.lcp = LC_PRIORITY_3;
10406       else
10407          lcCfg->dlLcCfg.lcp = LC_PRIORITY_1;
10408    }
10409    if(ulLcCfg)
10410    {
10411       lcCfg->ulLcCfgPres = true;
10412       extractUlLcCfg(&lcCfg->ulLcCfg, ulLcCfg);
10413    }
10414    else
10415       lcCfg->ulLcCfgPres = false;
10416    return ROK;
10417 }
10418
10419 /*******************************************************************
10420  *
10421  * @brief Function processing LC config info received from CU
10422  *
10423  * @details
10424  *
10425  *    Function : procMacLcCfg
10426  *
10427  *    Functionality: Function processing LC config info received from CU
10428  *
10429  * @params[in] F1AP message
10430  * @return ROK/RFAILED
10431  *
10432  * ****************************************************************/
10433
10434 uint8_t procMacLcCfg(uint8_t lcId, uint8_t rbType, uint8_t configType, DRBs_ToBeSetup_Item_t *drbItem,\
10435 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LogicalChannelConfig_t *ulLcCfg,\
10436 LcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10437 {
10438    uint8_t ret = ROK;
10439
10440    lcCfg->lcId = lcId;
10441    lcCfg->configType = configType;
10442    if(rbType == RB_TYPE_SRB)
10443    {
10444       ret = extractMacRbCfg(lcId, NULL, NULL, NULL, ulLcCfg, lcCfg, NULL);
10445    }
10446    else if(rbType == RB_TYPE_DRB)
10447    {
10448       if(drbItem != NULL)
10449         ret = extractMacRbCfg(lcId, drbItem, NULL, NULL, ulLcCfg, lcCfg, upTnlInfo);
10450       else if(drbSetupModItem != NULL)
10451         ret = extractMacRbCfg(lcId, NULL, drbSetupModItem, NULL, ulLcCfg, lcCfg, upTnlInfo);
10452       else if(drbModItem != NULL)
10453         ret = extractMacRbCfg(lcId, NULL, NULL, drbModItem, ulLcCfg, lcCfg, upTnlInfo);
10454    }
10455    return ret;
10456 }
10457
10458 /*******************************************************************
10459  *
10460  * @brief Function to extract Rlc cfg To Add/Mod in CellGrp Info
10461  *
10462  * @details
10463  *
10464  *    Function : extractRlcCfgToAddMod
10465  *
10466  *    Functionality: Function to extract Rlc cfg To Add/Mod in CellGrp Info
10467  *
10468  * @params[in] CellGroupConfigRrc__rlc_BearerTo pointer
10469  *             DuUeCfg Pointer
10470  * @return ROK/RFAILED
10471  *
10472  * ****************************************************************/
10473
10474 uint8_t extractRlcCfgToAddMod(struct CellGroupConfigRrc__rlc_BearerToAddModList *lcCfg, DuUeCfg *ueCfgDb)
10475 {
10476   uint8_t idx, rbId, lcId, rlcMode, rbType;
10477   RLC_Config_t *f1RlcCfg = NULLP;
10478   LogicalChannelConfig_t *macUlLcCfg = NULLP;
10479
10480   for(idx = 0; idx < lcCfg->list.count; idx++)
10481   {
10482      lcId = lcCfg->list.array[idx]->logicalChannelIdentity;
10483      if(lcCfg->list.array[idx]->servedRadioBearer)
10484      {
10485         /* RadioBearer for SRB/DRB */
10486         if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10487         RLC_BearerConfig__servedRadioBearer_PR_srb_Identity)
10488         {
10489            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.srb_Identity;
10490            rbType = RB_TYPE_SRB;
10491         }
10492         else if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10493         RLC_BearerConfig__servedRadioBearer_PR_drb_Identity)
10494         {
10495            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.drb_Identity;
10496            rbType = RB_TYPE_DRB;
10497         }
10498         else
10499         {
10500            DU_LOG("\nERROR  -->  No components present in Bearer config to ADD/MOD");
10501            return RFAILED;
10502         }
10503         /* MAC UL LC Config */
10504         if(lcCfg->list.array[idx]->mac_LogicalChannelConfig)
10505         {
10506            macUlLcCfg = lcCfg->list.array[idx]->mac_LogicalChannelConfig;
10507         }
10508      }
10509      else
10510      {
10511         DU_LOG("\nERROR  -->  DUAPP: Received RadioBearer config is NULL");
10512         return RFAILED;
10513      }
10514      /* RLC Mode Config */
10515      if(lcCfg->list.array[idx]->rlc_Config)
10516      {
10517         rlcMode  = lcCfg->list.array[idx]->rlc_Config->present;
10518         f1RlcCfg = lcCfg->list.array[idx]->rlc_Config;
10519      }
10520      
10521      /* Filling RLC/MAC Config*/
10522      memset(&ueCfgDb->macLcCfg[idx], 0, sizeof(LcCfg));
10523      memset(&ueCfgDb->rlcLcCfg[idx], 0, sizeof(RlcBearerCfg));
10524      procRlcLcCfg(rbId, lcId, rbType, rlcMode, CONFIG_UNKNOWN, f1RlcCfg, &(ueCfgDb->rlcLcCfg[idx]), NULLP);
10525      if(procMacLcCfg(lcId, rbType, CONFIG_UNKNOWN, NULL, NULL, NULL, macUlLcCfg, &ueCfgDb->macLcCfg[idx], NULL) != ROK)
10526      {
10527         DU_LOG("\nERROR  -->  DU APP : Failed while filling MAC LC config at extractRlcCfgToAddMod()");
10528         return RFAILED;
10529      }
10530      (ueCfgDb->numRlcLcs)++;
10531      (ueCfgDb->numMacLcs)++;
10532      DU_LOG("\nDEBUG  -> DUAPP: extractRlcCfgToAddMod:RBType:%d, DrbID: %d,lcId:%d, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
10533         rbType, rbId, lcId, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
10534   }
10535   //TODO: To send the failure cause in UeContextSetupRsp 
10536   return ROK;
10537 }
10538
10539 /*******************************************************************
10540  *
10541  * @brief DeAlloc pdsch serv cell config info
10542  *
10543  * @details
10544  *
10545  *    Function : freeMacPdschServCellInfo
10546  *
10547  *    Functionality: DeAlloc pdsch serv cell config info
10548  *
10549  * @params[in] PdschServCellCfg pointer
10550  * @return void
10551  *
10552  * ****************************************************************/
10553
10554 void freeMacPdschServCellInfo(PdschServCellCfg *pdsch)
10555 {
10556    if(pdsch->xOverhead)
10557    {
10558       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->xOverhead, sizeof(PdschXOverhead));
10559    }
10560    if(pdsch->codeBlkGrpFlushInd)
10561    {
10562       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->codeBlkGrpFlushInd, sizeof(bool));
10563    }
10564    if(pdsch->maxCodeBlkGrpPerTb)
10565    {
10566       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10567    }
10568    if(pdsch->maxMimoLayers)
10569    {
10570       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxMimoLayers, sizeof(uint8_t));
10571    }
10572 }
10573
10574 /*******************************************************************
10575  *
10576  * @brief Free Serving cell Info
10577  *
10578  * @details
10579  *
10580  *    Function : freeMacServingCellInfo
10581  *
10582  *    Functionality: Free Serving cell Info
10583  *
10584  * @params[in] ServCellCfgInfo *srvCellCfg
10585  * @return void
10586  *
10587  * ****************************************************************/
10588 void freeMacServingCellInfo(ServCellCfgInfo *srvCellCfg)
10589 {
10590    uint8_t timeDomRsrcIdx;
10591
10592    if(srvCellCfg->initDlBwp.pdschPresent)
10593    {
10594       for(timeDomRsrcIdx = 0; timeDomRsrcIdx < srvCellCfg->initDlBwp.pdschCfg.numTimeDomRsrcAlloc; timeDomRsrcIdx++)
10595       {
10596          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, \
10597             srvCellCfg->initDlBwp.pdschCfg.timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
10598       }
10599    }
10600
10601    freeMacPdschServCellInfo(&srvCellCfg->pdschServCellCfg);
10602    if(srvCellCfg->bwpInactivityTmr)
10603    {
10604       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
10605    }
10606
10607    if(srvCellCfg->initUlBwp.pucchPresent)
10608    {
10609       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->initUlBwp.pucchCfg.dlDataToUlAck, sizeof(PucchDlDataToUlAck));
10610    }
10611 }
10612
10613 /*******************************************************************
10614  *
10615  * @brief Free cell Grp Cfg Info
10616  *
10617  * @details
10618  *
10619  *    Function : freeUeReCfgCellGrpInfo
10620  *
10621  *    Functionality: Free cell Grp Cfg Info
10622  *
10623  * @params[in] MacUeCfg*  duUeCfg
10624  * @return void
10625  *
10626  * ****************************************************************/
10627
10628 void freeUeReCfgCellGrpInfo(MacUeCfg *macUeCfg)
10629 {
10630    freeMacServingCellInfo(&macUeCfg->spCellCfg.servCellCfg);
10631 }
10632
10633 /*******************************************************************
10634  *
10635  * @brief Fills Reconfig SchReqReConfig
10636  *
10637  * @details
10638  *
10639  *    Function : extractSchReqReConfig
10640  *
10641  *    Functionality: Fills Reconfig SchReqReConfig
10642  *
10643  * @params[in] SchedulingRequestConfig_t *cuSchedReq
10644  *             SchedReqCfg*  macSchedReq
10645  * @return void
10646  *
10647  * ****************************************************************/
10648 void extractSchReqReConfig(SchedulingRequestConfig_t *cuSchedReq, SchedReqCfg *macSchedReq)
10649 {
10650    uint8_t schReqIdx = 0;
10651    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqListToAdd = NULLP;
10652    struct SchedulingRequestConfig__schedulingRequestToReleaseList *schReqListToRel = NULLP;
10653
10654    if(cuSchedReq->schedulingRequestToAddModList)
10655    {
10656       schReqListToAdd = cuSchedReq->schedulingRequestToAddModList;
10657       if(schReqListToAdd->list.count)
10658       {
10659          macSchedReq->addModListCount = schReqListToAdd->list.count;
10660          for(schReqIdx = 0; schReqIdx < schReqListToAdd->list.count; schReqIdx++)
10661          {
10662             macSchedReq->addModList[schReqIdx].schedReqId = \
10663                schReqListToAdd->list.array[schReqIdx]->schedulingRequestId;
10664             macSchedReq->addModList[schReqIdx].srProhibitTmr = \
10665                *(schReqListToAdd->list.array[schReqIdx]->sr_ProhibitTimer);
10666             macSchedReq->addModList[schReqIdx].srTransMax    =\
10667                schReqListToAdd->list.array[schReqIdx]->sr_TransMax;
10668          }
10669       }
10670    }
10671    /* Scheduling Req To release */
10672    if(cuSchedReq->schedulingRequestToReleaseList)
10673    {
10674       schReqListToRel = cuSchedReq->schedulingRequestToReleaseList;
10675       if(schReqListToRel->list.count)
10676       {
10677          macSchedReq->relListCount = schReqListToRel->list.count;
10678          for(schReqIdx = 0; schReqIdx < schReqListToRel->list.count; schReqIdx++)
10679          {
10680             macSchedReq->relList[schReqIdx] = \
10681                *schReqListToRel->list.array[schReqIdx];
10682          }
10683       }
10684    }
10685 }
10686
10687 /*******************************************************************
10688  *
10689  * @brief Fills TagReconfig
10690  *
10691  * @details
10692  *
10693  *    Function : extractTagReconfig
10694  *
10695  *    Functionality: Fills extractTagReconfig
10696  *
10697  * @params[in] TAG_Config_t *cuTagCfg
10698  *             TagCfg *macTagCfg
10699  * @return void
10700  *
10701  * ****************************************************************/
10702
10703 void extractTagReconfig(TAG_Config_t *cuTagCfg, TagCfg *macTagCfg)
10704 {
10705   uint8_t tagIdx = 0;
10706   struct TAG_Config__tag_ToAddModList  *tagListToAddMod = NULLP;
10707   struct TAG_Config__tag_ToReleaseList *tagListToRel = NULLP;
10708
10709   /* Tag config to AddMod */
10710   if(cuTagCfg->tag_ToAddModList)
10711   {
10712      tagListToAddMod = cuTagCfg->tag_ToAddModList; 
10713      if(tagListToAddMod->list.count)
10714      {
10715         macTagCfg->addModListCount = tagListToAddMod->list.count;
10716         for(tagIdx = 0; tagIdx < tagListToAddMod->list.count; tagIdx++)
10717         {
10718            macTagCfg->addModList[tagIdx].tagId =\
10719               tagListToAddMod->list.array[tagIdx]->tag_Id;     
10720            macTagCfg->addModList[tagIdx].timeAlignTimer = \
10721
10722               tagListToAddMod->list.array[tagIdx]->timeAlignmentTimer;
10723         }
10724      }
10725   }
10726   /* Tag config to release */
10727   if(cuTagCfg->tag_ToReleaseList)
10728   {
10729      tagListToRel = cuTagCfg->tag_ToReleaseList;
10730      if(tagListToRel->list.count)
10731      {
10732         macTagCfg->relListCount = tagListToRel->list.count;
10733         for(tagIdx = 0; tagIdx < tagListToRel->list.count; tagIdx++)
10734         {
10735            macTagCfg->relList[tagIdx] = *tagListToRel->list.array[tagIdx];     
10736         }
10737      }
10738   }
10739 }
10740
10741 /*******************************************************************
10742  *
10743  * @brief Fills PdcchCfg received by CU
10744  *
10745  * @details
10746  *
10747  *    Function : extractPdcchCfg
10748  *
10749  *    Functionality: Fills PdcchCfg received  by CU
10750  *
10751  * @params[in] PDCCH_Config_t *cuPdcchCfg,
10752  *             PdcchConfig *duPdcchCfg
10753  * @return void
10754  *
10755  * ****************************************************************/
10756
10757 void extractPdcchCfg(PDCCH_Config_t *cuPdcchCfg, PdcchConfig *macPdcchCfg)
10758 {
10759    uint8_t cRsetIdx = 0;
10760    uint8_t srchSpcIdx = 0;
10761
10762    struct PDCCH_Config__controlResourceSetToAddModList *cRsetToAddModList = NULLP;
10763    struct PDCCH_Config__controlResourceSetToReleaseList *cRsetToRelList = NULLP;
10764    struct PDCCH_Config__searchSpacesToAddModList *srchSpcToAddModList = NULLP;
10765    struct PDCCH_Config__searchSpacesToReleaseList *srchSpcToRelList = NULLP;
10766
10767
10768    /* Control Resource Set To Add/Mod List */
10769    if(cuPdcchCfg->controlResourceSetToAddModList)
10770    {
10771       cRsetToAddModList = cuPdcchCfg->controlResourceSetToAddModList;
10772       if(cRsetToAddModList->list.count)
10773       {
10774          macPdcchCfg->numCRsetToAddMod = cRsetToAddModList->list.count;
10775          for(cRsetIdx = 0; cRsetIdx < cRsetToAddModList->list.count; cRsetIdx++)
10776          {
10777             macPdcchCfg->cRSetToAddModList[cRsetIdx].cRSetId = \
10778                cRsetToAddModList->list.array[cRsetIdx]->controlResourceSetId;
10779             //freqDomRsrcBitStringToInt(&cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources,\
10780                   macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc);
10781             memcpy(macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc, \
10782                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.buf,
10783                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.size);
10784
10785             macPdcchCfg->cRSetToAddModList[cRsetIdx].duration = \
10786                 cRsetToAddModList->list.array[cRsetIdx]->duration;
10787
10788             macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType = \
10789                cRsetToAddModList->list.array[cRsetIdx]->cce_REG_MappingType.present;   
10790             if(macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType == CCE_REG_MAPPINGTYPE_PR_INTERLEAVED)
10791             {
10792                //TODO: handle the case for Interleaved
10793             }
10794             macPdcchCfg->cRSetToAddModList[cRsetIdx].precoderGranularity = \
10795                 cRsetToAddModList->list.array[cRsetIdx]->precoderGranularity;
10796             if(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID)
10797             {
10798                macPdcchCfg->cRSetToAddModList[cRsetIdx].dmrsScramblingId= \
10799                   *(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID);
10800             }
10801          }
10802       }
10803    }
10804    /* Control Resource Set To Release List */
10805    if(cuPdcchCfg->controlResourceSetToReleaseList)
10806    {
10807       cRsetToRelList = cuPdcchCfg->controlResourceSetToReleaseList;
10808       if(cRsetToRelList->list.count)
10809       {
10810          macPdcchCfg->numCRsetToRel = cRsetToRelList->list.count;
10811          for(cRsetIdx = 0; cRsetIdx < cRsetToRelList->list.count; cRsetIdx++)
10812          {
10813             macPdcchCfg->cRSetToRelList[cRsetIdx] = *(cRsetToRelList->list.array[cRsetIdx]);
10814          }
10815       }
10816    }
10817
10818    /* Search space To Add/Mod List */
10819    if(cuPdcchCfg->searchSpacesToAddModList)
10820    {
10821       srchSpcToAddModList = cuPdcchCfg->searchSpacesToAddModList;
10822       if(srchSpcToAddModList->list.count)
10823       {
10824          macPdcchCfg->numSearchSpcToAddMod = srchSpcToAddModList->list.count;
10825          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToAddModList->list.count; srchSpcIdx++)
10826          {
10827             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceId =\
10828                                                                           srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceId;
10829             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].cRSetId =\
10830                                                                     *(srchSpcToAddModList->list.array[srchSpcIdx]->controlResourceSetId);
10831             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset)
10832             {
10833                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSlotPeriodicityAndOffset =\
10834                                                                                          srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset->present;
10835             }
10836             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot)
10837             {
10838                bitStringToInt(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot,\
10839                      macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSymbolsWithinSlot);
10840             }
10841             if(srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates)
10842             {
10843                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel1 = \
10844                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel1;
10845                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel2 = \
10846                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel2;
10847                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel4 = \
10848                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel4;
10849
10850                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel8 = \
10851                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel8;
10852
10853                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel16 = \
10854                                                                                         srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel16;
10855             }
10856             if(srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType)
10857             {
10858                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType =\
10859                                                                                srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->present;
10860                if(macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType == SEARCHSPACETYPE_PR_UE_SPECIFIC)
10861                {
10862                   macPdcchCfg->searchSpcToAddModList[srchSpcIdx].ueSpecificDciFormat =\
10863                                                                                       srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->choice.ue_Specific->dci_Formats;
10864                }
10865
10866             }
10867          }
10868       }
10869    }
10870    /* Search space To Rel List */
10871    if(cuPdcchCfg->searchSpacesToReleaseList)
10872    {
10873       srchSpcToRelList = cuPdcchCfg->searchSpacesToReleaseList;
10874       if(srchSpcToRelList->list.count)
10875       {
10876          macPdcchCfg->numSearchSpcToRel = srchSpcToRelList->list.count;
10877          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToRelList->list.count; srchSpcIdx++)
10878          {
10879             macPdcchCfg->searchSpcToRelList[srchSpcIdx] =\
10880                                                          *(srchSpcToRelList->list.array[srchSpcIdx]);
10881          }
10882       }
10883    }
10884 }
10885
10886 /*******************************************************************
10887  *
10888  * @brief Fills PdschCfg received by CU
10889  *
10890  * @details
10891  *
10892  *    Function : extractPdschCfg
10893  *
10894  *    Functionality: Fills PdschCfg received  by CU
10895  *
10896  * @params[in] PDSCH_Config_t *cuPdschCfg = Information which is send by CU,
10897  *                   which we have stored in F1UeContextSetupDb,
10898  *             PdschConfig *macPdschCfg = Used to Store the information which
10899  *                   needs to send in other layer, as well as this can be the variable
10900  *                   which stores the information in DuCb,
10901  *             PdschConfig *storedPdschCfg =  Null in case of sending the
10902  *                   information to other layer else it will have stored pdsch 
10903  *                   configuration in copyOfmacUeCfg.
10904  * @return void
10905  *
10906  * ****************************************************************/
10907
10908 void extractPdschCfg(PDSCH_Config_t *cuPdschCfg, PdschConfig *macPdschCfg, PdschConfig *storedPdschCfg)
10909 {
10910    uint8_t timeDomIdx;
10911    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAlloc = NULLP;
10912
10913    if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
10914    {
10915       if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->present == \
10916             PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup)
10917       {
10918          if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup)
10919          {
10920             macPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
10921                *(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_AdditionalPosition);
10922          }
10923       }
10924    }
10925    macPdschCfg->resourceAllocType = cuPdschCfg->resourceAllocation;
10926    if(cuPdschCfg->pdsch_TimeDomainAllocationList)
10927    {
10928       timeDomAlloc = cuPdschCfg->pdsch_TimeDomainAllocationList;
10929       if(timeDomAlloc->present ==\
10930             PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup)
10931       {
10932          if(timeDomAlloc->choice.setup)
10933          {
10934             macPdschCfg->numTimeDomRsrcAlloc  = timeDomAlloc->choice.setup->list.count;
10935             for(timeDomIdx = 0; timeDomIdx < timeDomAlloc->choice.setup->list.count; timeDomIdx++)
10936             {
10937                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 = NULLP;
10938                if(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0)
10939                {
10940                   if(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 == NULL)
10941                   {
10942                      if(storedPdschCfg)
10943                      {
10944                         if(storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
10945                         {
10946                            macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 =\
10947                            storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0;
10948                         }
10949                         else
10950                         {
10951                            DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
10952                         }
10953                      }
10954                      else
10955                      {
10956                         DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
10957                      }
10958                      if(!macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
10959                      {
10960                         DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for k0 at extractPdschCfg()");
10961                         return;
10962                      }
10963                   }
10964                   *(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0) = \
10965                   *(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0);
10966                }
10967                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].mappingType = \
10968                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->mappingType;
10969                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].startSymbolAndLength = \
10970                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
10971             }
10972          }
10973       }
10974    }
10975    macPdschCfg->rbgSize = cuPdschCfg->rbg_Size;
10976    if(cuPdschCfg->maxNrofCodeWordsScheduledByDCI)
10977       macPdschCfg->numCodeWordsSchByDci = *(cuPdschCfg->maxNrofCodeWordsScheduledByDCI);
10978    if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_staticBundling)
10979    {
10980       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
10981       if(cuPdschCfg->prb_BundlingType.choice.staticBundling)
10982       {
10983          if(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize)
10984          {
10985             macPdschCfg->bundlingInfo.StaticBundling.size = \
10986                *(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize);
10987          }
10988       }
10989    }
10990    else if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_dynamicBundling)
10991    {
10992       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
10993    }
10994
10995 }
10996
10997 /*******************************************************************
10998  *
10999  * @brief Fills PdschServingCellCfg received by CU
11000  *
11001  * @details
11002  *
11003  *    Function : extractPdschServingCellCfg
11004  *
11005  *    Functionality: Fills PdschCfg received  by CU
11006  *
11007  * @params[in] PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg,
11008  *             PdschServCellCfg *macUePdschSrvCellCfg
11009  * @return ROK/RFAILED
11010  *
11011  * ****************************************************************/
11012
11013 uint8_t extractPdschServingCellCfg(PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg, PdschServCellCfg *macUePdschSrvCellCfg)
11014 {
11015    if(cuPdschSrvCellCfg->codeBlockGroupTransmission)
11016    {
11017       if(cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup)
11018       {
11019          if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11020          {
11021             *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11022                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11023          }
11024          else
11025          {
11026             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
11027             if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
11028             {
11029                *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
11030                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
11031             }
11032             else
11033             {
11034                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxCodeBlkGrpPerTb at extractPdschServingCellCfg()");
11035                return RFAILED;
11036             }
11037          }
11038          if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11039          {
11040             *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11041                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11042          }
11043          else
11044          {
11045             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->codeBlkGrpFlushInd , sizeof(bool));
11046             if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
11047             {
11048                *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
11049                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
11050             }
11051             else
11052             {
11053                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for codeBlkGrpFlushInd at extractPdschServingCellCfg()");
11054                return RFAILED;
11055             }
11056          }
11057       }
11058    }
11059    if(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH)
11060    {
11061       macUePdschSrvCellCfg->numHarqProcForPdsch = *(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH); 
11062    }
11063    if(cuPdschSrvCellCfg->ext1)
11064    {
11065       if(cuPdschSrvCellCfg->ext1->maxMIMO_Layers)
11066       {
11067         if(macUePdschSrvCellCfg->maxMimoLayers)
11068         {
11069            *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11070         }
11071         else
11072         {
11073            DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxMimoLayers, sizeof(uint8_t));
11074            if(macUePdschSrvCellCfg->maxMimoLayers)
11075            {
11076               *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
11077            }
11078            else
11079            {
11080               DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxMimoLayers at extractPdschServingCellCfg()");
11081               return RFAILED;
11082            }
11083         }
11084       }
11085    }
11086    if(cuPdschSrvCellCfg->xOverhead)
11087    {
11088       if(macUePdschSrvCellCfg->xOverhead)
11089       {
11090          *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11091       }
11092       else
11093       {
11094          DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->xOverhead, sizeof(PdschXOverhead));
11095          if(macUePdschSrvCellCfg->xOverhead)
11096          {
11097             *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
11098          }
11099          else
11100          {
11101             DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for xOverhead at extractPdschServingCellCfg()");
11102             return RFAILED;
11103          }
11104       }
11105    }
11106    return ROK;
11107 }
11108
11109 /*******************************************************************
11110  *
11111  * @brief Fills PuschCfg received by CU
11112  *
11113  * @details
11114  *
11115  *    Function : extractPuschCfg
11116  *
11117  *    Functionality: Fills PuschCfg received  by CU
11118  *
11119  * @params[in] BWP_UplinkDedicated__pusch_Config *cuPuschCfg,
11120  *             PuschCfg *macPuschCfg
11121  * @return void
11122  *
11123  * ****************************************************************/
11124
11125 void extractPuschCfg(struct BWP_UplinkDedicated__pusch_Config *cuPuschCfg, PuschCfg *macPuschCfg)
11126 {
11127    uint8_t timeDomIdx = 0;
11128    DMRS_UplinkConfig_t *dmrsUlCfg = NULLP;
11129    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList = NULLP;
11130
11131    if(cuPuschCfg->present == BWP_UplinkDedicated__pusch_Config_PR_setup)
11132    {
11133       if(cuPuschCfg->choice.setup)
11134       {
11135          if(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH)
11136          {
11137              macPuschCfg->dataScramblingId = \
11138                 *(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH);
11139          }
11140          if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA)
11141          {
11142             if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->present == PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup)
11143             {
11144                if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup)
11145                {
11146                   dmrsUlCfg = (cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup);
11147                   if(dmrsUlCfg->dmrs_AdditionalPosition)
11148                   {
11149                      macPuschCfg->dmrsUlCfgForPuschMapTypeA.addPos =\
11150                         *(dmrsUlCfg->dmrs_AdditionalPosition);
11151                   }
11152                   if(dmrsUlCfg->transformPrecodingDisabled)
11153                   {
11154                      if(dmrsUlCfg->transformPrecodingDisabled->scramblingID0)
11155                      {
11156                         macPuschCfg->dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0 = \
11157                            *(dmrsUlCfg->transformPrecodingDisabled->scramblingID0);
11158                      }
11159                   }
11160                }
11161             }
11162          }
11163          /*Res Alloc Type for UL */
11164          if(cuPuschCfg->choice.setup->resourceAllocation)
11165          {
11166             macPuschCfg->resourceAllocType = \
11167                cuPuschCfg->choice.setup->resourceAllocation;
11168          }
11169          if(cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList)
11170          {
11171             timeDomAllocList = cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList;
11172             if(timeDomAllocList->present == PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup)
11173             {
11174                if(timeDomAllocList->choice.setup)
11175                {
11176                   macPuschCfg->numTimeDomRsrcAlloc = timeDomAllocList->choice.setup->list.count;
11177                   for(timeDomIdx = 0; timeDomIdx <timeDomAllocList->choice.setup->list.count; timeDomIdx++)
11178                   {
11179                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].k2 = \
11180                         *(timeDomAllocList->choice.setup->list.array[timeDomIdx]->k2);
11181                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].mappingType = \
11182                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->mappingType;
11183                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].startSymbolAndLength = \
11184                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
11185                   }
11186                }
11187             }
11188          }
11189          if(cuPuschCfg->choice.setup->transformPrecoder)
11190             macPuschCfg->transformPrecoder = *(cuPuschCfg->choice.setup->transformPrecoder);
11191       }
11192    }
11193 }
11194
11195 /*******************************************************************
11196  *
11197  * @brief Function to fill pucch Power Control
11198  *
11199  * @details
11200  *
11201  *    Function : extractPucchPowerControl
11202  *
11203  *    Functionality: Function to fill pucch Power Control
11204  *
11205  * @params[in] PucchPowerControl *pwrCtrl,
11206  *             struct PUCCH_PowerControl *cuPwrCtrlCfg
11207  * @return void
11208  *
11209  * ****************************************************************/
11210
11211 void extractPucchPowerControl(PucchPowerControl *pwrCtrl, struct PUCCH_PowerControl *cuPwrCtrlCfg)
11212 {
11213    uint8_t arrIdx;
11214
11215    if(cuPwrCtrlCfg->deltaF_PUCCH_f0)
11216       pwrCtrl->deltaF_Format0 = *cuPwrCtrlCfg->deltaF_PUCCH_f0;
11217    if(cuPwrCtrlCfg->deltaF_PUCCH_f1)
11218       pwrCtrl->deltaF_Format1 = *cuPwrCtrlCfg->deltaF_PUCCH_f1;
11219    if(cuPwrCtrlCfg->deltaF_PUCCH_f2)
11220       pwrCtrl->deltaF_Format2 = *cuPwrCtrlCfg->deltaF_PUCCH_f2;
11221    if(cuPwrCtrlCfg->deltaF_PUCCH_f3)
11222       pwrCtrl->deltaF_Format3 = *cuPwrCtrlCfg->deltaF_PUCCH_f3;
11223    if(cuPwrCtrlCfg->deltaF_PUCCH_f4)
11224       pwrCtrl->deltaF_Format4 = *cuPwrCtrlCfg->deltaF_PUCCH_f4;
11225    if(cuPwrCtrlCfg->p0_Set)
11226    {
11227       pwrCtrl->p0SetCount = cuPwrCtrlCfg->p0_Set->list.count;
11228       for(arrIdx=0; arrIdx < pwrCtrl->p0SetCount; arrIdx++)
11229       {
11230          pwrCtrl->p0Set[arrIdx].p0PucchId =\
11231             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Id;
11232          pwrCtrl->p0Set[arrIdx].p0PucchVal =\
11233             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Value;
11234       }
11235    }
11236    if(cuPwrCtrlCfg->pathlossReferenceRSs)
11237    {
11238       pwrCtrl->pathLossRefRSListCount = cuPwrCtrlCfg->pathlossReferenceRSs->list.count;
11239       for(arrIdx = 0; arrIdx < pwrCtrl->pathLossRefRSListCount; arrIdx++)
11240       {
11241          pwrCtrl->pathLossRefRSList[arrIdx].pathLossRefRSId =\
11242             cuPwrCtrlCfg->pathlossReferenceRSs->list.array[arrIdx]->pucch_PathlossReferenceRS_Id;
11243       }
11244    }
11245 }
11246  
11247  /*******************************************************************
11248  *
11249  * @brief Function to extractResrcSetToAddModList sent by CU
11250  *
11251  * @details
11252  *
11253  *    Function : extractResrcSetToAddModList
11254  *
11255  *    Functionality: Fucntion to extractResrcSetToAddModList
11256  *
11257  * @params[in] PucchResrcSetCfg pointer,
11258  *             struct PUCCH_Config__resourceSetToAddModList pointer
11259  * @return void
11260  *
11261  * ****************************************************************/
11262
11263 void extractResrcSetToAddModList(PucchResrcSetCfg *macRsrcSetList, struct PUCCH_Config__resourceSetToAddModList *cuRsrcSetList)
11264 {
11265    uint8_t arrIdx, rsrcListIdx;
11266
11267    macRsrcSetList->resrcSetToAddModListCount = cuRsrcSetList->list.count; 
11268    for(arrIdx = 0; arrIdx < macRsrcSetList->resrcSetToAddModListCount; arrIdx++)
11269    {
11270       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcSetId     =\
11271          cuRsrcSetList->list.array[arrIdx]->pucch_ResourceSetId;
11272       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount =\
11273          cuRsrcSetList->list.array[arrIdx]->resourceList.list.count;
11274       for(rsrcListIdx = 0; rsrcListIdx < macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount; rsrcListIdx++)
11275       {
11276          macRsrcSetList->resrcSetToAddModList[arrIdx].resrcList[rsrcListIdx] =\
11277             *cuRsrcSetList->list.array[arrIdx]->resourceList.list.array[rsrcListIdx];
11278       }
11279
11280       if(cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1)
11281       {
11282          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize =\
11283             *cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1;
11284       }
11285       else
11286       {
11287          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize = 0;
11288       }
11289    }
11290 }/* End of extractResrcSetToAddModList */
11291
11292 /*******************************************************************
11293  *
11294  * @brief Fills extractResrcToAddModList sent by CU
11295  *
11296  * @details
11297  *
11298  *    Function : extractResrcToAddModList
11299  *
11300  *    Functionality: Fills extractResrcToAddModList
11301  *
11302  * @params[in] PucchResrcCfg pointer,
11303  *             struct PUCCH_Config__resourceToAddModList pointer
11304  * @return ROk/RFAILED
11305  *
11306  * ****************************************************************/
11307
11308 uint8_t extractResrcToAddModList(PucchResrcCfg *macResrcList, struct PUCCH_Config__resourceToAddModList *cuResrcList)
11309 {
11310    uint8_t arrIdx;
11311    
11312    macResrcList->resrcToAddModListCount = cuResrcList->list.count;
11313    for(arrIdx = 0; arrIdx < macResrcList->resrcToAddModListCount; arrIdx++)
11314    {
11315       macResrcList->resrcToAddModList[arrIdx].resrcId      =\
11316         cuResrcList->list.array[arrIdx]->pucch_ResourceId; 
11317       macResrcList->resrcToAddModList[arrIdx].startPrb     =\
11318         cuResrcList->list.array[arrIdx]->startingPRB;
11319       if(cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping)
11320       {
11321          macResrcList->resrcToAddModList[arrIdx].intraFreqHop =\
11322            *cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping;
11323       }
11324       if(cuResrcList->list.array[arrIdx]->secondHopPRB)
11325       {
11326          macResrcList->resrcToAddModList[arrIdx].secondPrbHop =\
11327            *cuResrcList->list.array[arrIdx]->secondHopPRB;
11328       }
11329       /* PUCCH RSRC FORMAT */
11330       if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format0)
11331       {
11332          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_0;
11333          if(cuResrcList->list.array[arrIdx]->format.choice.format0)
11334          {
11335             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0, sizeof(PucchFormat0));
11336             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0 == NULLP)
11337             {
11338                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format0 in extractResrcToAddModList()");
11339                return RFAILED;
11340             }
11341             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->initialCyclicShift =\
11342                cuResrcList->list.array[arrIdx]->format.choice.format0->initialCyclicShift;
11343             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->numSymbols =\
11344                cuResrcList->list.array[arrIdx]->format.choice.format0->nrofSymbols;
11345             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->startSymbolIdx =\
11346                cuResrcList->list.array[arrIdx]->format.choice.format0->startingSymbolIndex;
11347          }
11348       }
11349       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format1)
11350       {
11351          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_1;
11352          if(cuResrcList->list.array[arrIdx]->format.choice.format1)
11353          {
11354             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1, sizeof(PucchFormat1));
11355             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1 == NULLP)
11356             {
11357                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format1 in extractResrcToAddModList()");
11358                return RFAILED;
11359             }
11360             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->initialCyclicShift =\
11361                 cuResrcList->list.array[arrIdx]->format.choice.format1->initialCyclicShift;
11362             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->numSymbols =\
11363                 cuResrcList->list.array[arrIdx]->format.choice.format1->nrofSymbols;
11364             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->startSymbolIdx =\
11365                 cuResrcList->list.array[arrIdx]->format.choice.format1->startingSymbolIndex;
11366             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->timeDomOCC =\
11367                 cuResrcList->list.array[arrIdx]->format.choice.format1->timeDomainOCC;
11368          }
11369       }
11370       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format2)
11371       {
11372          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_2;
11373          if(cuResrcList->list.array[arrIdx]->format.choice.format2)
11374          {
11375             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
11376             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2 == NULLP)
11377             {
11378                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format2 in extractResrcToAddModList()");
11379                return RFAILED;
11380             }
11381             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numPrbs =\
11382                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofPRBs;
11383             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numSymbols =\
11384                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofSymbols;
11385             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->startSymbolIdx =\
11386                 cuResrcList->list.array[arrIdx]->format.choice.format2->startingSymbolIndex;
11387          }
11388       }
11389       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format3)
11390       {
11391          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_3;
11392          if(cuResrcList->list.array[arrIdx]->format.choice.format3)
11393          {
11394             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
11395             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3 == NULLP)
11396             {
11397                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format3 in extractResrcToAddModList()");
11398                return RFAILED;
11399             }
11400             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numPrbs =\
11401                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofPRBs;
11402             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numSymbols =\
11403                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofSymbols;
11404             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->startSymbolIdx =\
11405                 cuResrcList->list.array[arrIdx]->format.choice.format3->startingSymbolIndex;
11406          }
11407       }
11408       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format4)
11409       {
11410          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_4;
11411          if(cuResrcList->list.array[arrIdx]->format.choice.format4)
11412          {
11413             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4, sizeof(PucchFormat4));
11414             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4 == NULLP)
11415             {
11416                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format4 in extractResrcToAddModList()");
11417                return RFAILED;
11418             }
11419             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->numSymbols =\
11420                 cuResrcList->list.array[arrIdx]->format.choice.format4->nrofSymbols;
11421             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occLen =\
11422                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Length;
11423             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occIdx =\
11424                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Index;
11425             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->startSymbolIdx =\
11426                 cuResrcList->list.array[arrIdx]->format.choice.format4->startingSymbolIndex;
11427          }
11428       }
11429    }
11430    return ROK;
11431
11432 }/* End of extractResrcToAddModList */
11433
11434 /*******************************************************************
11435  *
11436  * @brief Fills fillPucchSchedReqPeriodAndOffset sent by CU
11437  *
11438  * @details
11439  *
11440  *    Function : fillPucchSchedReqPeriodAndOffset
11441  *
11442  *    Functionality: To fillPucchSchedReqPeriodAndOffset
11443  *
11444  * @params[in] macPeriodicty,
11445  *     SchedulingRequestResourceConfig__periodicityAndOffset pointer
11446  * @return void
11447  *
11448  * ****************************************************************/
11449
11450 void fillPucchSchedReqPeriodAndOffset(uint8_t macPeriodicty, uint16_t  macOffset,\
11451    struct SchedulingRequestResourceConfig__periodicityAndOffset *cuPeriodicty)
11452 {
11453    macPeriodicty = cuPeriodicty->present;
11454    switch(macPeriodicty)
11455    {
11456       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
11457          {
11458             macOffset     = cuPeriodicty->choice.sym2;
11459             break;
11460          }
11461       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
11462          {
11463             macOffset     = cuPeriodicty->choice.sym6or7;
11464             break;
11465          }
11466       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
11467          {
11468             macOffset     = cuPeriodicty->choice.sl1;
11469             break;
11470          }
11471       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
11472          {
11473             macOffset = cuPeriodicty->choice.sl2;
11474             break;
11475          }
11476       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
11477          {
11478             macOffset = cuPeriodicty->choice.sl4;
11479             break;
11480          }
11481       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
11482          {
11483             macOffset = cuPeriodicty->choice.sl5;
11484             break;
11485          }
11486       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
11487          {
11488             macOffset = cuPeriodicty->choice.sl8;
11489             break;
11490          }
11491       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
11492          {
11493             macOffset = cuPeriodicty->choice.sl10;
11494             break;
11495          }
11496       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
11497          {
11498             macOffset = cuPeriodicty->choice.sl16;
11499             break;
11500          }
11501       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
11502          {
11503             macOffset = cuPeriodicty->choice.sl20;
11504             break;
11505          }
11506       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
11507          {
11508             macOffset = cuPeriodicty->choice.sl40;
11509             break;
11510          }
11511       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
11512          {
11513             macOffset = cuPeriodicty->choice.sl80;
11514             break;
11515          }
11516       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
11517          {
11518             macOffset = cuPeriodicty->choice.sl160;
11519             break;
11520          }
11521       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
11522          {
11523             macOffset = cuPeriodicty->choice.sl320;
11524             break;
11525          }
11526       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
11527          {
11528             macOffset = cuPeriodicty->choice.sl640;
11529             break;
11530          }
11531       default :
11532          DU_LOG("\nERROR  -->  F1AP : Invalid periodicity %d", macPeriodicty);
11533    }
11534 }
11535
11536 /*******************************************************************
11537  *
11538  * @brief Function to extractPucchFormatCfg sent by CU
11539  *
11540  * @details
11541  *
11542  *    Function : extractPucchFormatCfg
11543  *
11544  *    Functionality: Function to extractPucchFormatCfg
11545  *
11546  * @params[in] PucchFormatCfg pointer,
11547  *             PUCCH_FormatConfig_t pointer
11548  * @return void
11549  *
11550  * ****************************************************************/
11551
11552 void extractPucchFormatCfg(PucchFormatCfg *macFormatCfg, PUCCH_FormatConfig_t *cuFormatCfg)
11553  {
11554     if(cuFormatCfg->interslotFrequencyHopping)
11555        macFormatCfg->interSlotFreqHop = *cuFormatCfg->interslotFrequencyHopping;
11556     if(cuFormatCfg->additionalDMRS)  
11557        macFormatCfg->addDmrs = *cuFormatCfg->additionalDMRS;
11558     if(cuFormatCfg->maxCodeRate)
11559        macFormatCfg->maxCodeRate = *cuFormatCfg->maxCodeRate;
11560     if(cuFormatCfg->nrofSlots)  
11561        macFormatCfg->numSlots = *cuFormatCfg->nrofSlots;
11562     if(cuFormatCfg->pi2BPSK)  
11563        macFormatCfg->pi2BPSK = *cuFormatCfg->pi2BPSK;
11564     if(cuFormatCfg->simultaneousHARQ_ACK_CSI)  
11565        macFormatCfg->harqAckCSI = *cuFormatCfg->simultaneousHARQ_ACK_CSI;
11566  }/* End of extractPucchFormatCfg */
11567
11568 /*******************************************************************
11569  *
11570  * @brief Function to extractSchedReqCfgToAddMod sent by CU
11571  *
11572  * @details
11573  *
11574  *    Function : extractSchedReqCfgToAddMod
11575  *
11576  *    Functionality: Function to extractSchedReqCfgToAddMod
11577  *
11578  * @params[in] PucchSchedReqCfg pointer,
11579  *      PUCCH_Config__schedulingRequestResourceToAddModList pointer
11580  * @return void
11581  *
11582  * ****************************************************************/
11583
11584 void extractSchedReqCfgToAddMod(PucchSchedReqCfg *macSchedReqCfg, struct PUCCH_Config__schedulingRequestResourceToAddModList *cuSchedReqList)
11585 {
11586    uint8_t arrIdx;
11587
11588    macSchedReqCfg->schedAddModListCount = cuSchedReqList->list.count;
11589    for(arrIdx = 0; arrIdx <  macSchedReqCfg->schedAddModListCount; arrIdx++)
11590    {
11591       macSchedReqCfg->schedAddModList[arrIdx].resrcId =\
11592          cuSchedReqList->list.array[arrIdx]->schedulingRequestResourceId;
11593       macSchedReqCfg->schedAddModList[arrIdx].requestId =\
11594          cuSchedReqList->list.array[arrIdx]->schedulingRequestID;
11595       if(cuSchedReqList->list.array[arrIdx]->periodicityAndOffset)
11596       {
11597          fillPucchSchedReqPeriodAndOffset(macSchedReqCfg->schedAddModList[arrIdx].periodicity,\
11598             macSchedReqCfg->schedAddModList[arrIdx].offset, cuSchedReqList->list.array[arrIdx]->periodicityAndOffset);
11599       }
11600       if(cuSchedReqList->list.array[arrIdx]->resource)
11601       {
11602          macSchedReqCfg->schedAddModList[arrIdx].resrc =\
11603             *cuSchedReqList->list.array[arrIdx]->resource;
11604       }
11605    }
11606
11607 }/* End of extractSchedReqCfgToAddMod */
11608
11609  /*******************************************************************
11610  *
11611  * @brief Fills PucchCfg received by CU
11612  *
11613  * @details
11614  *
11615  *    Function : extractPucchCfg
11616  *
11617  *    Functionality: Fills PucchCfg received  by CU
11618  *
11619  * @params[in] BWP_UplinkDedicated__pucch_Config *cuPucchCfg = Information which
11620  *                is send by CU, which we have stored in F1UeContextSetupDb,
11621  *             PucchCfg *macPucchCfg = Used to Store the information which
11622  *                needs to send in other layer, as well as this can be the variable
11623  *                which stores the information in DuCb,
11624  *             PucchCfg *storedPucchCfg = Null in case of sending the
11625  *                information to other layer else it will have Pucch Cfg which
11626  *                we have stored in copyOfmacUeCfg.
11627  * @return ROK/RFAILED
11628  *
11629  * ****************************************************************/
11630
11631 uint8_t extractPucchCfg(struct BWP_UplinkDedicated__pucch_Config *cuPucchCfg, PucchCfg *macPucchCfg,\
11632 PucchCfg *storedPucchCfg)        
11633 {
11634    uint8_t arrIdx;
11635
11636    if(cuPucchCfg->present == BWP_UplinkDedicated__pucch_Config_PR_setup)
11637    {
11638       if(cuPucchCfg->choice.setup)
11639       {
11640          /* Resource Set Cfg */ 
11641          if(cuPucchCfg->choice.setup->resourceSetToAddModList)
11642          {
11643             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrcSet, sizeof(PucchResrcSetCfg));
11644             if(macPucchCfg->resrcSet == NULLP)
11645             {
11646                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc set List in extractPucchCfg()");
11647                return RFAILED;
11648             }
11649             memset(macPucchCfg->resrcSet, 0, sizeof(PucchResrcSetCfg));
11650             extractResrcSetToAddModList(macPucchCfg->resrcSet, cuPucchCfg->choice.setup->resourceSetToAddModList);
11651          }
11652          
11653          /* Resource Cfg */ 
11654          if(cuPucchCfg->choice.setup->resourceToAddModList)
11655          {
11656             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrc, sizeof(PucchResrcCfg));
11657             if(macPucchCfg->resrc == NULLP)
11658             {
11659                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc List in extractPucchCfg()");
11660                return RFAILED;
11661             }
11662             memset(macPucchCfg->resrc, 0, sizeof(PucchResrcCfg));
11663             extractResrcToAddModList(macPucchCfg->resrc, cuPucchCfg->choice.setup->resourceToAddModList);
11664          }
11665          
11666          /* Format 1 Cfg */ 
11667          if(cuPucchCfg->choice.setup->format1)
11668          {
11669             DU_ALLOC_SHRABL_BUF(macPucchCfg->format1, sizeof(PucchFormatCfg));
11670             if(macPucchCfg->format1 == NULLP)
11671             {
11672                DU_LOG("\nERROR --> F1AP : Failed to extract format 1 Cfg in  extractPucchCfg()");
11673                return RFAILED;
11674             }
11675             memset(macPucchCfg->format1, 0, sizeof(PucchFormatCfg));
11676             extractPucchFormatCfg(macPucchCfg->format1,\
11677                cuPucchCfg->choice.setup->format1->choice.setup);
11678          }
11679          
11680          /* Format 2 Cfg */
11681          if(cuPucchCfg->choice.setup->format2)
11682          {
11683             DU_ALLOC_SHRABL_BUF(macPucchCfg->format2, sizeof(PucchFormatCfg));
11684             if(macPucchCfg->format2 == NULLP)
11685             {
11686                DU_LOG("\nERROR --> F1AP : Failed to extract format 2 Cfg in  extractPucchCfg()");
11687                return RFAILED;
11688             }
11689             memset(macPucchCfg->format2, 0, sizeof(PucchFormatCfg));
11690             extractPucchFormatCfg(macPucchCfg->format2,\
11691                cuPucchCfg->choice.setup->format2->choice.setup);
11692          }
11693          
11694          /* Format 3 Cfg */
11695          if(cuPucchCfg->choice.setup->format3)
11696          {
11697             DU_ALLOC_SHRABL_BUF(macPucchCfg->format3, sizeof(PucchFormatCfg));
11698             if(macPucchCfg->format3 == NULLP)
11699             {
11700                DU_LOG("\nERROR --> F1AP : Failed to extract format 3 Cfg in  extractPucchCfg()");
11701                return RFAILED;
11702             }
11703             memset(macPucchCfg->format3, 0, sizeof(PucchFormatCfg));
11704             extractPucchFormatCfg(macPucchCfg->format3,\
11705                cuPucchCfg->choice.setup->format3->choice.setup);
11706          }
11707
11708          /* Format 4 Cfg */
11709          if(cuPucchCfg->choice.setup->format4)
11710          {
11711             DU_ALLOC_SHRABL_BUF(macPucchCfg->format4, sizeof(PucchFormatCfg));
11712             if(macPucchCfg->format4 == NULLP)
11713             {
11714                DU_LOG("\nERROR --> F1AP : Failed to extract format 4 Cfg in  extractPucchCfg()");
11715                return RFAILED;
11716             }
11717             memset(macPucchCfg->format4, 0, sizeof(PucchFormatCfg));
11718             extractPucchFormatCfg(macPucchCfg->format4,\
11719                cuPucchCfg->choice.setup->format4->choice.setup);
11720          }
11721
11722          /* Sched Req List */
11723          if(cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList)
11724          {
11725             DU_ALLOC_SHRABL_BUF(macPucchCfg->schedReq, sizeof(PucchSchedReqCfg));
11726             if(macPucchCfg->schedReq == NULLP)
11727             {
11728                DU_LOG("\nERROR --> F1AP : Failed to extract schedReqCfg in  extractPucchCfg()");
11729                return RFAILED;
11730             }
11731             memset(macPucchCfg->schedReq, 0, sizeof(PucchSchedReqCfg));
11732             extractSchedReqCfgToAddMod(macPucchCfg->schedReq,\
11733             cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList);
11734          }
11735
11736          /*TODO: Add support for  Spatial Info */
11737
11738          /* MultiCsiCfg */
11739          if(cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList)
11740          {
11741             DU_ALLOC_SHRABL_BUF(macPucchCfg->multiCsiCfg, sizeof(PucchMultiCsiCfg));
11742             if(macPucchCfg->multiCsiCfg == NULLP)
11743             {
11744                DU_LOG("\nERROR --> F1AP : Failed to extract multiCsiCfg in  extractPucchCfg()");
11745                return RFAILED;
11746             }
11747             memset(macPucchCfg->multiCsiCfg, 0, sizeof(PucchMultiCsiCfg));
11748             macPucchCfg->multiCsiCfg->multiCsiResrcListCount = cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.count;
11749             for(arrIdx =0; arrIdx < macPucchCfg->multiCsiCfg->multiCsiResrcListCount; arrIdx++)
11750             {
11751                macPucchCfg->multiCsiCfg->multiCsiResrcList[arrIdx] =\
11752                  *cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.array[arrIdx];
11753             }
11754          }
11755
11756          /* Dl_DataToUL_ACK */ 
11757          if(cuPucchCfg->choice.setup->dl_DataToUL_ACK)
11758     {
11759        if(storedPucchCfg)
11760        {
11761           if(storedPucchCfg->dlDataToUlAck)
11762           {
11763              macPucchCfg->dlDataToUlAck = storedPucchCfg->dlDataToUlAck; 
11764           }
11765           else
11766           {
11767             DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
11768           }
11769        }
11770        else
11771        {
11772           DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
11773        }
11774        if(macPucchCfg->dlDataToUlAck == NULLP)
11775        {
11776           DU_LOG("\nERROR --> F1AP : Failed to extract Dl_DataToUL_ACK in extractPucchCfg()");
11777           return RFAILED;
11778        }
11779        memset(macPucchCfg->dlDataToUlAck, 0, sizeof(PucchDlDataToUlAck));
11780        macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount = cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.count;
11781        for(arrIdx = 0; arrIdx < macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; arrIdx++)
11782        {
11783           macPucchCfg->dlDataToUlAck->dlDataToUlAckList[arrIdx] =\
11784           *cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.array[arrIdx];
11785        }
11786          }
11787
11788          /* Power Control */
11789          if(cuPucchCfg->choice.setup->pucch_PowerControl)
11790          {
11791             DU_ALLOC_SHRABL_BUF(macPucchCfg->powerControl, sizeof(PucchPowerControl));
11792             if(macPucchCfg->powerControl == NULLP)
11793             {
11794                DU_LOG("\nERROR --> F1AP : Failed to extract power control in extractPucchCfg()");
11795                return RFAILED;
11796             }
11797             extractPucchPowerControl(macPucchCfg->powerControl,\
11798                cuPucchCfg->choice.setup->pucch_PowerControl);
11799          }
11800       }
11801    }
11802    return ROK;
11803 }
11804
11805 /*******************************************************************
11806  *
11807  * @brief Fills ServingCellReconfig received by CU
11808  *
11809  * @details
11810  *
11811  *    Function : extractSpCellDedicatedCfg
11812  *
11813  *    Functionality: Fills ServingCellReconfig received  by CU
11814  *
11815  * @params[in] ServingCellConfig_t *cuSrvCellCfg = Information which is send by
11816  *                  CU, which we have stored in F1UeContextSetupDb,
11817  *             ServCellCfgInfo *macSrvCellCfg = Used to Store the information
11818  *                  which  needs to send in other layer, as well as this can be the
11819  *                  variable which stores the information in DuCb, 
11820  *             ServCellCfgInfo *storedSrvCellCfg = Null in case of sending the
11821  *                  information to other layer else it will have ServCellCfgInfo which
11822  *                  we have stored in copyOfmacUeCfg.
11823  * @return ROK/RFAILD
11824  *
11825  * ****************************************************************/
11826 uint8_t extractSpCellDedicatedCfg(ServingCellConfig_t *cuSrvCellCfg, ServCellCfgInfo *macSrvCellCfg,\
11827 ServCellCfgInfo *storedSrvCellCfg)
11828 {
11829    uint8_t ret = ROK;
11830    BWP_DownlinkDedicated_t *dlBwp = NULLP;
11831    BWP_UplinkDedicated_t   *ulBwp = NULLP;
11832
11833    if(cuSrvCellCfg->initialDownlinkBWP)
11834    {
11835       dlBwp = ((BWP_DownlinkDedicated_t *)(cuSrvCellCfg->initialDownlinkBWP));
11836       if(dlBwp->pdcch_Config)
11837       {
11838          if(dlBwp->pdcch_Config->choice.setup)
11839          {
11840             macSrvCellCfg->initDlBwp.pdcchPresent = true;
11841             if(storedSrvCellCfg)
11842             {
11843                if(!storedSrvCellCfg->initDlBwp.pdcchPresent)
11844                {
11845                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11846                }
11847                else
11848                {
11849                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11850                }
11851             }
11852             else
11853             {
11854                extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11855             }
11856          }
11857       }
11858       if(dlBwp->pdsch_Config)
11859       {
11860          if(dlBwp->pdsch_Config->choice.setup)
11861          {
11862             macSrvCellCfg->initDlBwp.pdschPresent = true;
11863             
11864             if(storedSrvCellCfg)
11865             {
11866                if(!storedSrvCellCfg->initDlBwp.pdschPresent)
11867                {
11868                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
11869                }
11870                else
11871                {
11872                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg,\
11873                         &storedSrvCellCfg->initDlBwp.pdschCfg);
11874                }
11875             }
11876             else
11877             {
11878                extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
11879             }
11880          }
11881       }
11882    }
11883    if(cuSrvCellCfg->firstActiveDownlinkBWP_Id)
11884       macSrvCellCfg->firstActvDlBwpId = *(cuSrvCellCfg->firstActiveDownlinkBWP_Id);
11885    if(cuSrvCellCfg->defaultDownlinkBWP_Id)
11886       macSrvCellCfg->defaultDlBwpId = *(cuSrvCellCfg->defaultDownlinkBWP_Id);
11887    if(cuSrvCellCfg->bwp_InactivityTimer)
11888    {
11889       if(macSrvCellCfg->bwpInactivityTmr)
11890       {
11891          memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
11892       }
11893       else
11894       {
11895          macSrvCellCfg->bwpInactivityTmr = NULLP;
11896          DU_ALLOC_SHRABL_BUF(macSrvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
11897          if(macSrvCellCfg->bwpInactivityTmr)
11898          {
11899             memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
11900          }
11901          else
11902          {
11903             DU_LOG("\nERROR  --> F1AP : Memory Alloc failed for bwpInactivityTmr at extractSpCellDedicatedCfg()");
11904             return RFAILED;
11905          }
11906       }
11907    }
11908    if(cuSrvCellCfg->pdsch_ServingCellConfig)
11909    {
11910       if(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup)
11911       {
11912          ret = extractPdschServingCellCfg(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup, &macSrvCellCfg->pdschServCellCfg);
11913          if(ret == RFAILED)
11914          {
11915             DU_LOG("\nERROR --> F1AP : Failed at extractPdschServingCellCfg()");
11916             return RFAILED;
11917          }
11918       }
11919    }
11920    if(cuSrvCellCfg->uplinkConfig)
11921    {
11922       if(cuSrvCellCfg->uplinkConfig->initialUplinkBWP)
11923       {
11924          ulBwp = ((BWP_UplinkDedicated_t *)(cuSrvCellCfg->uplinkConfig->initialUplinkBWP));
11925          if(ulBwp->pusch_Config)
11926          {
11927             macSrvCellCfg->initUlBwp.puschPresent = true;
11928             extractPuschCfg(ulBwp->pusch_Config, &macSrvCellCfg->initUlBwp.puschCfg);
11929          }
11930          if(ulBwp->pucch_Config)
11931          {
11932             macSrvCellCfg->initUlBwp.pucchPresent = true;
11933             memset(&macSrvCellCfg->initUlBwp.pucchCfg, 0, sizeof(PucchCfg));
11934             if(storedSrvCellCfg)
11935             {
11936                if(!storedSrvCellCfg->initUlBwp.pucchPresent)
11937                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
11938                else
11939                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg,\
11940                   &storedSrvCellCfg->initUlBwp.pucchCfg);
11941             }
11942             else
11943             {
11944                extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
11945             }
11946          }
11947       }
11948       if(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id)
11949          macSrvCellCfg->firstActvUlBwpId = *(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id);
11950    }
11951    return ret;
11952 }
11953
11954 #ifdef NR_DRX
11955
11956 /*******************************************************************
11957  *
11958  * @brief fill long cycle offset value of drx in UE structure
11959  *
11960  * @details
11961  *
11962  *    Function : fillLongCycleOffsetValueInUeDb
11963  *
11964  *    Functionality: fill long cycle offset value of drx in UE structure
11965  *
11966  * @params[in] DrxLongCycleStartOffset  drxLongCycleStartOffset,
11967  * struct DRX_ConfigRrc__drx_LongCycleStartOffset drx_LongCycleStartOffset
11968  *
11969  * @return ROK     - success
11970  *         RFAILED - failure
11971  *
11972  * ****************************************************************/
11973 void fillLongCycleOffsetValueInUeDb(DrxLongCycleStartOffset *drxLongCycleStartOffset, struct DRX_ConfigRrc__drx_LongCycleStartOffset  *drx_LongCycleStartOffset)
11974 {
11975
11976    drxLongCycleStartOffset->drxLongCycleStartOffsetChoice = convertLongDrxCycleLengthEnumToValue(drx_LongCycleStartOffset->present);
11977    switch(drx_LongCycleStartOffset->present)
11978    {
11979       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10:
11980          {
11981             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10;
11982             break;
11983          }
11984       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms20:
11985          {
11986             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms20;
11987             break;
11988          }
11989       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms32:
11990          {
11991             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms32;
11992             break;
11993          }
11994       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms40:
11995         {
11996             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms40;
11997             break;
11998          }
11999       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms60:
12000          {
12001             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms60;
12002             break;
12003          }
12004       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms64:
12005          {
12006             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms64;
12007             break;
12008          }
12009       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms70:
12010          {
12011             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms70;
12012             break;
12013          }
12014       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms80:
12015          {
12016             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms80;
12017             break;
12018          }
12019       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms128:
12020          {
12021             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms128;
12022             break;
12023          }
12024       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms160:
12025          {
12026             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms160;
12027             break;
12028          }
12029       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms256:
12030          {
12031             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms256;
12032             break;
12033          }
12034       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms320:
12035          {
12036             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms320;
12037             break;
12038          }
12039       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms512:
12040          {
12041             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms512;
12042             break;
12043          }
12044       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms640:
12045          {
12046             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms640;
12047             break;
12048          }
12049       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1024:
12050          {
12051             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1024;
12052             break;
12053          }
12054       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms1280:
12055          {
12056             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms1280;
12057             break;
12058          }
12059       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2048:
12060          {
12061             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2048;
12062             break;
12063          }
12064       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms2560:
12065          {
12066             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms2560;
12067             break;
12068          }
12069        case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms5120:
12070          {
12071             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms5120;
12072             break;
12073          }
12074       case DRX_ConfigRrc__drx_LongCycleStartOffset_PR_ms10240:
12075          {
12076             drxLongCycleStartOffset->drxLongCycleStartOffsetVal = drx_LongCycleStartOffset->choice.ms10240;
12077             break;
12078          }
12079       default :
12080          break;
12081    }
12082 }
12083
12084 /*******************************************************************
12085  *
12086  * @brief Fills drx configuration structure with the help of drx_ConfigRrc
12087  *which recive from CU or storedDrxCfg which is already stored
12088  *
12089  * @details
12090  *
12091  *    Function : extractDrxConfiguration 
12092  *
12093  *    Functionality: Fills Reconfig Cell group Info received by CU
12094  *   
12095  * @params[in] cuMacCellGrpDrxConfig  = MAC_CellGroupConfig__drx_ConfigRrc information which
12096  *                       is send by CU, which we have stored in F1UeContextSetupDb
12097  *             DrxCfg * drxCfg  = Used to Store the information,
12098  *                      which needs to send in other layer, as well as this can be
12099  *                      the variable which stores the information in DuCb,
12100  *             DrxCfg *storedDrxCfg = Null in case of sending the
12101  *                      information to other layer else it will have the drx information 
12102  *                      stored in the copyOfmacUeCfg which we have stored in F1UeContextSetupDb.
12103  *
12104  * @return void
12105  *
12106  * ****************************************************************/
12107 void extractDrxConfiguration(struct MAC_CellGroupConfig__drx_ConfigRrc *cuMacCellGrpDrxConfig, DrxCfg * drxCfg, DrxCfg *storedDrxCfg)
12108 {
12109    struct DRX_ConfigRrc *cuDrxConfig;
12110
12111    if(storedDrxCfg)
12112    {
12113       memcpy(drxCfg, storedDrxCfg, sizeof(DrxCfg));
12114    }
12115    else
12116    {
12117       if(cuMacCellGrpDrxConfig)
12118       {
12119          switch(cuMacCellGrpDrxConfig->present)
12120          {
12121             case MAC_CellGroupConfig__drx_ConfigRrc_PR_NOTHING:
12122                break;
12123
12124             case MAC_CellGroupConfig__drx_ConfigRrc_PR_setup:
12125                {
12126                   cuDrxConfig = cuMacCellGrpDrxConfig->choice.setup;
12127                   if(cuDrxConfig)
12128                   {
12129                      switch(cuDrxConfig->drx_onDurationTimer.present)
12130                      {
12131                         case DRX_ConfigRrc__drx_onDurationTimer_PR_NOTHING:
12132                            break;
12133                         case DRX_ConfigRrc__drx_onDurationTimer_PR_milliSeconds:
12134                            {
12135                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = true;
12136                               drxCfg->drxOnDurationTimer.onDurationtimerValue.milliSeconds=convertOnDurationTimerMilliSecondsEnumToValue(cuDrxConfig->\
12137                               drx_onDurationTimer.choice.milliSeconds);
12138                               break;
12139                            }
12140                         case DRX_ConfigRrc__drx_onDurationTimer_PR_subMilliSeconds:
12141                            {
12142                               drxCfg->drxOnDurationTimer.onDurationTimerValInMs = false;
12143                               drxCfg->drxOnDurationTimer.onDurationtimerValue.subMilliSeconds = cuDrxConfig->drx_onDurationTimer.choice.subMilliSeconds;
12144                               break;
12145                            }
12146                      }
12147                   }
12148                   fillLongCycleOffsetValueInUeDb(&drxCfg->drxLongCycleStartOffset, &cuDrxConfig->drx_LongCycleStartOffset);
12149                   drxCfg->drxInactivityTimer = convertDrxInactivityTimerEnumToValue(cuDrxConfig->drx_InactivityTimer);
12150                   drxCfg->drxHarqRttTimerDl = cuDrxConfig->drx_HARQ_RTT_TimerDL;
12151                   drxCfg->drxHarqRttTimerUl = cuDrxConfig->drx_HARQ_RTT_TimerUL;
12152                   drxCfg->drxRetransmissionTimerDl = convertDrxRetransmissionTimerDlEnumToValue(cuDrxConfig->drx_RetransmissionTimerDL);
12153                   drxCfg->drxRetransmissionTimerUl = convertDrxRetransmissionTimerUlEnumToValue(cuDrxConfig->drx_RetransmissionTimerUL);
12154                   drxCfg->drxSlotOffset = cuDrxConfig->drx_SlotOffset;
12155                   if(cuDrxConfig->shortDRX)
12156                   {
12157                      drxCfg->shortDrxPres=true;
12158                      drxCfg->shortDrx.drxShortCycle = convertShortDrxCycleLengthEnumToValue(cuDrxConfig->shortDRX->drx_ShortCycle);
12159                      drxCfg->shortDrx.drxShortCycleTimer = cuDrxConfig->shortDRX->drx_ShortCycleTimer;
12160                   }
12161                   else
12162                      drxCfg->shortDrxPres=false;
12163
12164                   break;
12165                }
12166
12167             case MAC_CellGroupConfig__drx_ConfigRrc_PR_release:
12168                break;
12169          }
12170       }
12171    }
12172 }
12173 #endif
12174
12175 /*******************************************************************
12176  *
12177  * @brief Fills Reconfig Cell group Info received by CU
12178  *
12179  * @details
12180  *
12181  *    Function : extractUeReCfgCellInfo
12182  *
12183  *    Functionality: Fills Reconfig Cell group Info received by CU
12184  *   
12185  * @params[in] CellGroupConfigRrc_t *cellGrp = CellGroupConfigRrc_t information which
12186  *                       is send by CU, which we have stored in F1UeContextSetupDb
12187  *             MacUeCfg *MacUeCfg = Used to Store the information,
12188  *                      which needs to send in other layer, as well as this can be
12189  *                      the variable which stores the information in DuCb,
12190  *             MacUeCfg *storedMacUeCfg = Null in case of sending the
12191  *                      information to other layer else it will have copyOfmacUeCfg
12192  *                      which we have stored in F1UeContextSetupDb.
12193  *
12194  * @return ROK/RFAILED
12195  *
12196  * ****************************************************************/
12197 uint8_t extractUeReCfgCellInfo(CellGroupConfigRrc_t *cellGrp, MacUeCfg *macUeCfg, MacUeCfg *storedMacUeCfg)
12198 {
12199    uint8_t ret = ROK;
12200    MAC_CellGroupConfig_t     *macCellGroup = NULLP;
12201    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
12202    SpCellConfig_t            *spcellCfg = NULLP;
12203    ServingCellConfig_t       *servCellCfg = NULLP;
12204
12205    if(cellGrp)
12206    {
12207       /* Fill MacCell Group Reconfig  */
12208       if(cellGrp->mac_CellGroupConfig)
12209       {
12210          macUeCfg->macCellGrpCfgPres = true;
12211          macCellGroup = ((MAC_CellGroupConfig_t *)(cellGrp->mac_CellGroupConfig));
12212
12213 #ifdef NR_DRX         
12214          if(macCellGroup->drx_ConfigRrc)
12215          {
12216             if(storedMacUeCfg)
12217             {
12218                if(!storedMacUeCfg->macCellGrpCfgPres) 
12219                {
12220                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL);    
12221                }
12222                else
12223                {
12224                   extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg, &storedMacUeCfg->macCellGrpCfg.drxCfg);    
12225                }
12226             }
12227             else
12228             {
12229                extractDrxConfiguration(macCellGroup->drx_ConfigRrc, &macUeCfg->macCellGrpCfg.drxCfg,NULL); 
12230             }
12231          }
12232 #endif
12233
12234          if(macCellGroup->schedulingRequestConfig)
12235          {
12236             extractSchReqReConfig(macCellGroup->schedulingRequestConfig, &macUeCfg->macCellGrpCfg.schReqCfg);
12237          }
12238          if(macCellGroup->tag_Config)
12239          {
12240             extractTagReconfig(macCellGroup->tag_Config, &macUeCfg->macCellGrpCfg.tagCfg);
12241          }
12242          if(macCellGroup->bsr_Config)
12243          {
12244             macUeCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer = macCellGroup->bsr_Config->periodicBSR_Timer;
12245             macUeCfg->macCellGrpCfg.bsrTmrCfg.retxTimer     = macCellGroup->bsr_Config->retxBSR_Timer;
12246             if(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer)
12247             {
12248                macUeCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer  =\
12249                *(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer);
12250             }
12251          }
12252          if(macCellGroup->phr_Config)
12253          {
12254             if(macCellGroup->phr_Config->present == MAC_CellGroupConfig__phr_Config_PR_setup)
12255             {
12256                macUeCfg->macCellGrpCfg.phrCfgSetupPres = true;
12257                if(macCellGroup->phr_Config->choice.setup)
12258                {
12259                   macUeCfg->macCellGrpCfg.phrCfg.periodicTimer     = \
12260                   macCellGroup->phr_Config->choice.setup->phr_PeriodicTimer;
12261                   macUeCfg->macCellGrpCfg.phrCfg.prohibitTimer     = \
12262                   macCellGroup->phr_Config->choice.setup->phr_ProhibitTimer;
12263                   macUeCfg->macCellGrpCfg.phrCfg.txPowerFactor     = \
12264                   macCellGroup->phr_Config->choice.setup->phr_Tx_PowerFactorChange;
12265                   macUeCfg->macCellGrpCfg.phrCfg.multiplePHR       = \
12266                   macCellGroup->phr_Config->choice.setup->multiplePHR;
12267                   macUeCfg->macCellGrpCfg.phrCfg.dummy             = \
12268                   macCellGroup->phr_Config->choice.setup->dummy;
12269                   macUeCfg->macCellGrpCfg.phrCfg.phrType2OtherCell = \
12270                   macCellGroup->phr_Config->choice.setup->phr_Type2OtherCell;
12271                   macUeCfg->macCellGrpCfg.phrCfg.phrOtherCG        = \
12272                   macCellGroup->phr_Config->choice.setup->phr_ModeOtherCG;
12273                }
12274             }
12275          }
12276       }
12277       /* Fill Physical Cell Group Reconfig */
12278       if(cellGrp->physicalCellGroupConfig)
12279       {
12280          macUeCfg->phyCellGrpCfgPres = true;
12281          phyCellGrpCfg = ((PhysicalCellGroupConfig_t *)(cellGrp->physicalCellGroupConfig));
12282          if(phyCellGrpCfg->p_NR_FR1)
12283          {
12284             if(*(phyCellGrpCfg->p_NR_FR1) != macUeCfg->phyCellGrpCfg.pNrFr1)
12285                macUeCfg->phyCellGrpCfg.pNrFr1 = *(phyCellGrpCfg->p_NR_FR1);
12286          }
12287          macUeCfg->phyCellGrpCfg.pdschHarqAckCodebook = phyCellGrpCfg->pdsch_HARQ_ACK_Codebook;
12288       }
12289       /* Fill SpCell Reconfig */
12290       if(cellGrp->spCellConfig)
12291       {
12292          macUeCfg->spCellCfgPres = true;
12293          spcellCfg = ((SpCellConfig_t *)(cellGrp->spCellConfig));  
12294          if(spcellCfg->servCellIndex)
12295          {
12296             macUeCfg->spCellCfg.servCellIdx = *(spcellCfg->servCellIndex);
12297          }
12298          /* Fill Serving cell Reconfig info */
12299          if(cellGrp->spCellConfig->spCellConfigDedicated)
12300          {
12301             servCellCfg = ((ServingCellConfig_t *)(cellGrp->spCellConfig->spCellConfigDedicated));
12302             if(storedMacUeCfg)
12303             {
12304                if(!storedMacUeCfg->spCellCfgPres)
12305                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12306                else
12307                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg,\
12308                         &storedMacUeCfg->spCellCfg.servCellCfg);
12309             }
12310             else
12311             {
12312                ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
12313             }
12314             if(ret == RFAILED)
12315             {
12316                DU_LOG("\nERROR --> F1AP : Failed at extractSpCellDedicatedCfg()");
12317             }
12318          }
12319       }
12320    }
12321    return ret;
12322 }
12323 /*******************************************************************
12324 *
12325 * @brief free the memory allocated by decoder
12326 *
12327 * @details
12328 *
12329 *    Function : freeAperDecodeNrcgi 
12330 *
12331 *    Functionality: Free Nrcgi values
12332 *
12333 * @params[in] NRCGI_t *nrcgi
12334 * @return void
12335 *
12336 * ****************************************************************/
12337
12338
12339 void freeAperDecodeNrcgi(NRCGI_t *nrcgi)
12340 {
12341     if(nrcgi->pLMN_Identity.buf != NULLP)
12342     {
12343        free(nrcgi->pLMN_Identity.buf);
12344     }
12345     if(nrcgi->nRCellIdentity.buf != NULLP)
12346     {
12347        free(nrcgi->nRCellIdentity.buf);
12348     }
12349 }
12350 /*******************************************************************
12351 *
12352 * @brief free the memory allocated by decoder
12353 *
12354 * @details
12355 *
12356 *    Function : freeAperDecodeCuToDuInfo 
12357 *
12358 *    Functionality:  Free Cu To Du Information
12359 *
12360 * @params[in] CUtoDURRCInformation_t *rrcMsg
12361 * @return void
12362 *
12363 * ****************************************************************/
12364
12365
12366 void freeAperDecodeCuToDuInfo(CUtoDURRCInformation_t *rrcMsg)
12367 {
12368    uint8_t ieIdx =0;
12369    uint8_t arrIdx =0;
12370
12371    if(rrcMsg->uE_CapabilityRAT_ContainerList)
12372    {
12373       if(rrcMsg->uE_CapabilityRAT_ContainerList->buf)
12374          free(rrcMsg->uE_CapabilityRAT_ContainerList->buf);
12375       free(rrcMsg->uE_CapabilityRAT_ContainerList);
12376    }
12377
12378    if(rrcMsg->iE_Extensions)
12379    {
12380       if(rrcMsg->iE_Extensions->list.array)
12381       {
12382          for(ieIdx= 0; ieIdx < rrcMsg->iE_Extensions->list.count; ieIdx++)
12383          {
12384             if(rrcMsg->iE_Extensions->list.array[ieIdx])
12385             {
12386                switch(rrcMsg->iE_Extensions->list.array[ieIdx]->id)
12387                {
12388                   case ProtocolIE_ID_id_CellGroupConfig:
12389                      if(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf != NULLP)
12390                      {
12391                         free(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf);
12392                      }
12393                      break;
12394                   default:
12395                      DU_LOG("\nERROR  -->  F1AP : Invalid Event type %ld at FreeCuToDuInfo()", \
12396                            rrcMsg->iE_Extensions->list.array[ieIdx]->id);
12397                      break;
12398                }
12399             }
12400          }
12401          for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
12402          {
12403             free(rrcMsg->iE_Extensions->list.array[arrIdx]);
12404          }
12405          free(rrcMsg->iE_Extensions->list.array);
12406
12407       }
12408
12409       free(rrcMsg->iE_Extensions);
12410    }
12411 }
12412 /*******************************************************************
12413 *
12414 * @brief free the memory allocated by decoder
12415 *
12416 * @details 
12417 *
12418 *    Function : freeAperDecodeSplCellList
12419 *
12420 *    Functionality: Free Spl Cell List 
12421                     where memory allocated by aper_decoder
12422 *
12423 * @params[in]  SCell_ToBeSetup_List_t *spCellLst
12424 * @return void
12425 *
12426 * ****************************************************************/
12427
12428
12429 void freeAperDecodeSplCellList(SCell_ToBeSetup_List_t *spCellLst)
12430 {
12431     uint8_t  cellIdx =0;
12432
12433     if(spCellLst->list.array != NULLP)
12434     {
12435        for(cellIdx=0; cellIdx<spCellLst->list.count; cellIdx++)
12436        {
12437           if(cellIdx==0&&spCellLst->list.array[cellIdx]!=NULLP)
12438           {
12439              freeAperDecodeNrcgi(&spCellLst->list.array[cellIdx]->value.choice.SCell_ToBeSetup_Item.sCell_ID);
12440           }
12441           if(spCellLst->list.array[cellIdx]!=NULLP)
12442           {
12443              free(spCellLst->list.array[cellIdx]);
12444           }
12445        }
12446        free(spCellLst->list.array);
12447     }
12448 }
12449 /*******************************************************************
12450 *
12451 * @brief free the memory allocated by decoder
12452 *
12453 * @details
12454 *
12455 *    Function : freeAperDecodeSRBSetup 
12456 *
12457 *    Functionality: added free part for the memory allocated by aper_decoder
12458 *
12459 * @params[in] SRBs_ToBeSetup_List_t *srbSet
12460 * @return void
12461 *
12462 ****************************************************************/
12463
12464
12465 void freeAperDecodeSRBSetup(SRBs_ToBeSetup_List_t *srbSet)
12466 {
12467     uint8_t srbIdx =0;
12468     if(srbSet->list.array != NULLP)
12469     {
12470        for(srbIdx=0; srbIdx<srbSet->list.count; srbIdx++)
12471        {
12472           if(srbSet->list.array[srbIdx]!=NULLP)
12473           {
12474              free(srbSet->list.array[srbIdx]);
12475           }
12476        }
12477        free(srbSet->list.array);
12478     }
12479 }
12480
12481 /*******************************************************************
12482 *
12483 * @brief free the memory allocated by decoder
12484 *
12485 * @details
12486 *
12487 *    Function : freeAperDecodeULTnlInfo
12488 *
12489 *    Functionality: added free part for the memory allocated by aper_decoder
12490 *
12491 * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
12492 * @return void
12493 *
12494 * ****************************************************************/
12495
12496
12497 void freeAperDecodeULTnlInfo(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
12498 {
12499    uint8_t ulIdx=0;
12500    if(ulInfo->list.array != NULLP)
12501    {
12502       for(ulIdx=0; ulIdx<ulInfo->list.count; ulIdx++)
12503       {
12504          if(ulIdx==0&&ulInfo->list.array[ulIdx]!=NULLP)
12505          {
12506             if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel!=NULLP)
12507             {
12508                if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12509                      transportLayerAddress.buf != NULLP)
12510                {
12511                   if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf\
12512                         !=NULLP)
12513                   {
12514                      free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf);
12515                   }
12516                   free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12517                         transportLayerAddress.buf);
12518                }
12519                free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel);
12520             }
12521          }
12522          if(ulInfo->list.array[ulIdx]!=NULLP)
12523          {
12524             free(ulInfo->list.array[ulIdx]);
12525          }
12526       }
12527       free(ulInfo->list.array);
12528    }
12529 }
12530 /*******************************************************************
12531 *
12532 * @brief free the memory allocated by decoder
12533 *
12534 * @details
12535 *
12536 *    Function : freeAperDecodeDRBSetup  
12537 *
12538 *    Functionality: free DRBSetup which is allocated by decoder
12539 *
12540 * @params[in]  DRBs_ToBeSetup_List_t *drbSet
12541 * @return void
12542 *
12543 * ****************************************************************/
12544
12545 void freeAperDecodeDRBSetup(DRBs_ToBeSetup_List_t *drbSet)
12546 {
12547    DRBs_ToBeSetup_Item_t *drbSetItem = NULLP;
12548    uint8_t  flowIdx =0;
12549    uint8_t  drbIdx =0;
12550
12551    if(drbSet->list.array != NULLP)
12552    {
12553       for(drbIdx=0; drbIdx<drbSet->list.count; drbIdx++)
12554       {
12555          if(drbIdx==0&&drbSet->list.array[drbIdx] != NULLP)
12556          {
12557             drbSetItem =&drbSet->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12558             if(drbSetItem->qoSInformation.choice.choice_extension != NULLP)
12559             {
12560                if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12561                      qoS_Characteristics.choice.non_Dynamic_5QI !=NULLP)
12562                {
12563                   if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12564                         qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12565                   {
12566                      if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12567                            qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12568                      {
12569
12570                         if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf!=NULLP)
12571                         {
12572
12573                            if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD!=NULLP)
12574                            {
12575
12576                               if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD->\
12577                                     buf!=NULLP)
12578                               {
12579
12580                                  if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.\
12581                                        flows_Mapped_To_DRB_List.list.array != NULLP)
12582                                  {
12583
12584                                     for(flowIdx=0;flowIdx<drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12585                                           DRB_Information.flows_Mapped_To_DRB_List.list.count; flowIdx++)
12586                                     {
12587
12588                                        if(flowIdx==0&&drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12589                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12590                                        {
12591                                           if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12592                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12593                                                 qoSFlowLevelQoSParameters.\
12594                                                 qoS_Characteristics.choice.non_Dynamic_5QI!=NULLP)
12595                                           {
12596                                              if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12597                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12598                                                    qoSFlowLevelQoSParameters.\
12599                                                    qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12600                                              {
12601
12602                                                 if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12603                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12604                                                       qoSFlowLevelQoSParameters.\
12605                                                       qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12606                                                 {
12607
12608
12609                                                    free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12610                                                          DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12611                                                          qoSFlowLevelQoSParameters.\
12612                                                          qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12613                                                 }
12614
12615                                                 free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12616                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12617                                                       qoSFlowLevelQoSParameters.\
12618                                                       qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12619                                              }
12620
12621                                              free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12622
12623                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12624                                                    qoSFlowLevelQoSParameters.\
12625                                                    qoS_Characteristics.choice.non_Dynamic_5QI);
12626                                           }
12627                                        }
12628                                        if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12629                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12630                                        {
12631
12632                                           free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12633                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]);
12634                                        }
12635                                     }
12636
12637                                     free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12638                                           DRB_Information.flows_Mapped_To_DRB_List.list.array);
12639                                  }
12640
12641                                  free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12642                                        DRB_Information.sNSSAI.sD->buf);
12643                               }
12644
12645                               free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD);
12646                            }
12647
12648                            free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf);
12649
12650                         }
12651
12652                         free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12653
12654                               qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12655                      }
12656
12657                      free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12658                            qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12659                   }
12660
12661                   free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12662                         qoS_Characteristics.choice.non_Dynamic_5QI);
12663                }
12664                free(drbSetItem->qoSInformation.choice.choice_extension);
12665             }
12666             freeAperDecodeULTnlInfo(&drbSetItem->uLUPTNLInformation_ToBeSetup_List);
12667             if(drbSetItem->uLConfiguration)
12668             {
12669                free(drbSetItem->uLConfiguration);
12670             }
12671          }
12672          if(drbSet->list.array[drbIdx]!=NULLP)
12673          {
12674             free(drbSet->list.array[drbIdx]);
12675          }
12676       }
12677       free(drbSet->list.array);
12678    }
12679 }
12680
12681
12682 /*******************************************************************
12683  *
12684  * @brief builds Mac Cell Cfg
12685  *
12686  * @details
12687  *
12688  *    Function : procUeReCfgCellInfo
12689  *
12690  *    Functionality: builds Mac Cell Cfg
12691  *
12692  * @params[in] MacUeCfg *macUeCfgToSend = Used to Store the information which
12693  *                       needs to send in other layer, as well as this can be
12694  *                       the variable which stores the information in DuCb.
12695  *             MacUeCfg *storedMacUeCfg = Null in case of sending the
12696  *                       information to other layer else it will have copyOfmacUeCfg  
12697  *                       which we have stored in F1UeContextSetupDb
12698  *             void *cellInfo = CellGroupConfigRrc_t information which is send
12699  *                        by CU, which we have stored in F1UeContextSetupDb 
12700  *
12701  * @return void 
12702  *
12703  * ****************************************************************/
12704 uint8_t procUeReCfgCellInfo(MacUeCfg *macUeCfgToSend, MacUeCfg *storedMacUeCfg, void *cellInfo)
12705 {
12706    uint8_t ret = ROK;
12707    CellGroupConfigRrc_t *cellGrp = NULLP;
12708
12709    if(cellInfo)
12710    {
12711       cellGrp = (CellGroupConfigRrc_t *)cellInfo;
12712       ret = extractUeReCfgCellInfo(cellGrp, macUeCfgToSend, storedMacUeCfg);
12713       if(ret == RFAILED)
12714          DU_LOG("\nERROR  -->  F1AP : Failed at procUeReCfgCellInfo()");
12715    }
12716    if(ret == RFAILED)
12717    {
12718       freeUeReCfgCellGrpInfo(macUeCfgToSend);
12719    }
12720    return ret;
12721 }
12722
12723 /*******************************************************************
12724  *
12725  * @brief Filling modulation info in mac ue cfg
12726  *
12727  * @details
12728  *
12729  *    Function : duFillModulationDetails
12730  *
12731  *    Functionality: Filling modulation info in mac ue cfg
12732  *
12733  * @params[in] MAC UE Config to be updated
12734  *             Current UE configuration
12735  *             UE NR capability from CU
12736  * @return ROK     - success
12737  *         RFAILED - failure
12738  *
12739  * ****************************************************************/
12740 void duFillModulationDetails(MacUeCfg *ueCfg, MacUeCfg *oldUeCfg, void *ueCap)
12741 {
12742    UE_NR_Capability_t *ueNrCap=NULLP;
12743
12744    if(!ueCap && oldUeCfg)
12745    {
12746       memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));     
12747       memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12748    }
12749    else
12750    {
12751       ueNrCap = (UE_NR_Capability_t *)ueCap;
12752
12753       /* Filling DL modulation info */
12754       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsDownlinkPerCC && \
12755          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0] && \
12756          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL)
12757       {
12758          switch(*(ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL))
12759          {
12760             case ModulationOrder_qpsk:
12761                {
12762                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
12763                   break;
12764                }
12765             case ModulationOrder_qam16:
12766                {
12767                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM16;
12768                   break;
12769                }
12770             case ModulationOrder_qam64:
12771                {
12772                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM64;
12773                   ueCfg->dlModInfo.mcsIndex = PDSCH_MCS_INDEX;
12774                   ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64;
12775                   break;
12776                }
12777             case ModulationOrder_qam256:
12778                {
12779                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM256;
12780                   break;
12781                }
12782             default:
12783                {
12784                   DU_LOG("\nERROR  -->  DU APP: Incorrect downlink modulation order received. Reatining old modulation configuration");
12785                   if(oldUeCfg)
12786                      memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
12787                   break;
12788                }
12789          }
12790       }
12791       else
12792       {
12793          if(oldUeCfg)
12794             memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
12795       }
12796
12797       /* Filling UL modulation info */
12798       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsUplinkPerCC && \
12799          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0] && \
12800          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL)
12801       {
12802          switch(*(ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL))
12803          {
12804             case ModulationOrder_qpsk:
12805                {
12806                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
12807                   break;
12808                }
12809             case ModulationOrder_qam16:
12810                {
12811                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM16;
12812                   ueCfg->ulModInfo.mcsIndex = PUSCH_MCS_INDEX;
12813                   ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64;
12814                   break;
12815                }
12816             case ModulationOrder_qam64:
12817                {
12818                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM64;
12819                   break;
12820                }
12821             case ModulationOrder_qam256:
12822                {
12823                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM256;
12824                   break;
12825                }
12826             default:
12827                {
12828                   DU_LOG("\nERROR  -->  DU APP: Incorrect uplink modulation order received. Reatining old modulation configuration");
12829                   if(oldUeCfg)
12830                      memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12831                   break;
12832                }
12833          }
12834       }
12835       else
12836       {
12837          if(oldUeCfg)
12838             memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12839       }
12840    }
12841 }
12842
12843 /*******************************************************************
12844  *
12845  * @brief Function to extract info from CU to DU RRC container extension
12846  *
12847  * @details
12848  *
12849  *    Function : extractCuToDuRrcInfoExt
12850  *
12851  *    Functionality: Function to extract info from CU to DU RRC container
12852  *    extension
12853  *
12854  * @params[in] ProtocolExtensionContainer_4624P16_t pointer
12855  *
12856  * @return ROK
12857  *         RFAILED
12858  *
12859  * ****************************************************************/
12860 uint8_t extractCuToDuRrcInfoExt(ProtocolExtensionContainer_4624P16_t *protocolIeExtn, DuUeCfg *ueCfgDb)
12861 {
12862    uint8_t ieIdx =0;
12863    uint16_t recvBufLen =0;
12864    CellGroupConfigRrc_t *cellGrpCfg = NULLP;
12865    CUtoDURRCInformation_ExtIEs_t *extIeInfo = NULLP;
12866    asn_dec_rval_t rval; /* Decoder return value */
12867    memset(&rval, 0, sizeof(asn_dec_rval_t));
12868
12869    if(protocolIeExtn)
12870    {
12871       for(ieIdx = 0; ieIdx < protocolIeExtn->list.count; ieIdx++)
12872       {
12873          extIeInfo = ((CUtoDURRCInformation_ExtIEs_t *)(protocolIeExtn->list.array[ieIdx]));
12874          switch(extIeInfo->id)
12875          {
12876             case ProtocolIE_ID_id_CellGroupConfig:
12877                {
12878                   /* decoding the CellGroup Buf received */
12879                   recvBufLen = extIeInfo->extensionValue.choice.CellGroupConfig.size;
12880                   DU_ALLOC(cellGrpCfg, sizeof(CellGroupConfigRrc_t));
12881                   if(cellGrpCfg)
12882                   {
12883                      memset(cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
12884                      rval = aper_decode(0, &asn_DEF_CellGroupConfigRrc, (void **)&cellGrpCfg,
12885                            extIeInfo->extensionValue.choice.CellGroupConfig.buf, recvBufLen, 0, 0);
12886                      if(rval.code == RC_FAIL || rval.code == RC_WMORE)
12887                      {
12888                         DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
12889                         return RFAILED;
12890                      }
12891                      xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, cellGrpCfg);
12892
12893                      if(extractRlcCfgToAddMod(cellGrpCfg->rlc_BearerToAddModList, ueCfgDb))
12894                         return NULLP;
12895                      ueCfgDb->cellGrpCfg = cellGrpCfg;
12896                   }
12897                   break;
12898                }
12899
12900             case ProtocolIE_ID_id_HandoverPreparationInformation:
12901                {
12902                   DU_LOG("\nINFO -->  F1AP : Received HANDOVER PREPARATION INFO in UE CONTEXT SETUP REQUEST");
12903                   break;
12904                }
12905
12906             default:
12907                DU_LOG("\nERROR  -->  F1AP : Invalid IE received CUtoDURRCInformation: %ld at decodeCellGrpCfg()", extIeInfo->id);
12908                break;
12909          }
12910       }
12911    }
12912    return ROK;
12913 }
12914
12915 /*******************************************************************
12916  *
12917  * @brief Fills Srb List received by CU
12918  *
12919  * @details
12920  *
12921  *    Function : procSrbListToSetup
12922  *
12923  *    Functionality: Fills Srb List received  by CU
12924  *
12925  * @params[in] SRBs_ToBeSetup_Item_t *cuSrbItem
12926  *             LcCfg pointer
12927  *             RlcBearerCfg pointer
12928  * @return void
12929  *
12930  * ****************************************************************/
12931 uint8_t procSrbListToSetup(SRBs_ToBeSetup_Item_t * srbItem, LcCfg *macLcToAdd, RlcBearerCfg *rlcLcToAdd)
12932 {
12933
12934    /* Filling RLC INFO */
12935    procRlcLcCfg(srbItem->sRBID, srbItem->sRBID, RB_TYPE_SRB, RLC_AM, CONFIG_ADD, NULL, rlcLcToAdd, NULL);
12936
12937    /* Filling MAC INFO */
12938    if(procMacLcCfg(srbItem->sRBID, RB_TYPE_SRB, CONFIG_ADD, NULL,NULL, NULL, NULL, macLcToAdd, NULL)  != ROK)
12939    { 
12940       DU_LOG("\nERROR  -->  F1AP : Failed at MAC LC Cfg in procSrbListToSetup()");
12941       return RFAILED;
12942    }
12943
12944    return ROK;
12945 }
12946
12947
12948
12949 /*******************************************************************
12950  *
12951  * @brief extract Srb List received by CU
12952  *
12953  * @details
12954  *
12955  *    Function : extractSrbListToSetup
12956  *
12957  *    Functionality: extract Srb List received by CU
12958  *                   for both MAC and RLC
12959  *
12960  * @params[in] SRBs_ToBeSetup_Item_t pointer
12961  *             DuUeCfg pointer
12962  * @return ROK/RFAIED
12963  *
12964  * ****************************************************************/
12965
12966 uint8_t extractSrbListToSetup(SRBs_ToBeSetup_List_t *srbCfg, DuUeCfg *ueCfgDb)
12967 {
12968    uint8_t ret = ROK, srbIdx = 0, rlcLcIdx = 0;
12969    SRBs_ToBeSetup_Item_t *srbItem = NULLP;
12970    LcCfg *macLcCtxt = NULLP;
12971    RlcBearerCfg *rlcLcCtxt = NULLP;
12972
12973    if(srbCfg)
12974    {
12975       for(srbIdx = 0; srbIdx < srbCfg->list.count; srbIdx++)
12976       {
12977          macLcCtxt = NULL;
12978          rlcLcCtxt = NULL;
12979
12980          srbItem = &srbCfg->list.array[srbIdx]->value.choice.SRBs_ToBeSetup_Item;
12981          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
12982          { 
12983             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in MAC");
12984             ret = RFAILED;
12985             break;
12986          }
12987          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
12988          {
12989             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in RLC");
12990             ret = RFAILED;
12991             break;
12992          }
12993
12994          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numMacLcs; rlcLcIdx++)
12995          {
12996             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rbId == srbItem->sRBID && ueCfgDb->rlcLcCfg[rlcLcIdx].rbType == RB_TYPE_SRB)
12997             {
12998                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
12999                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13000                break;
13001             }
13002          }
13003          if(!macLcCtxt)
13004          {
13005             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(LcCfg));
13006             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13007             ueCfgDb->numMacLcs++;
13008          }
13009          if(!rlcLcCtxt)
13010          {
13011             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
13012             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13013             ueCfgDb->numRlcLcs++;
13014          }
13015
13016          ret = procSrbListToSetup(srbItem, macLcCtxt, rlcLcCtxt);
13017
13018          DU_LOG("\nDEBUG --> DUAPP: extractSrbListToSetup: SRBID: %ld [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13019                srbItem->sRBID, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13020          if(ret == RFAILED)
13021          {
13022             DU_LOG("\nERROR  -->  F1AP:  Failed at extractSrbListToSetup()");
13023             break;
13024          }
13025       }
13026    }
13027    else
13028       ret = RFAILED;
13029
13030    return ret;
13031 }
13032
13033 /*******************************************************************
13034  *
13035  * @brief Fills Drb List received by CU
13036  *
13037  * @details
13038  *
13039  *    Function : procDrbListToSetupMod
13040  *
13041  *    Functionality: Fills Drb List received by CU
13042  *                   for both MAC and RLC
13043  *
13044  * @params[in] DRBs_ToBeSetup_Item_t , DRBs_ToBeSetupMod_Item_t,
13045  *             DRBs_ToBeModified_Item_t , lcId, LcCfg pointer,
13046  *             RlcBearerCfg , UpTnlCfg, RlcUeCfg
13047  * @return void
13048  *
13049  * ****************************************************************/
13050
13051 uint8_t procDrbListToSetupMod(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbItem,\
13052 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LcCfg *macLcToAdd, RlcBearerCfg *rlcLcToAdd, UpTnlCfg *upTnlInfo, RlcUeCfg *storedRlcUeCfg)
13053 {
13054    uint8_t cfgIdx = 0;
13055    RlcMode rlcModeInfo;
13056
13057    if(drbItem != NULLP)
13058    {
13059       /* Filling RLC INFO */
13060       procRlcLcCfg(drbItem->dRBID, lcId, RB_TYPE_DRB, drbItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, &drbItem->\
13061       qoSInformation);
13062
13063       /* Filling MAC INFO */
13064       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, drbItem, NULL, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13065       { 
13066          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13067          return RFAILED;
13068       }
13069    }
13070    else if(drbSetupModItem != NULLP)
13071    {
13072       procRlcLcCfg(drbSetupModItem->dRBID, lcId, RB_TYPE_DRB, drbSetupModItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, 
13073       &drbSetupModItem->qoSInformation);
13074
13075       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, NULL, drbSetupModItem, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
13076       {
13077          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13078          return RFAILED;
13079       }
13080    }
13081    else if(drbModItem != NULLP)
13082    {
13083       /* Drb to Mod IEs doesnot have rlcMode to be modified
13084        * in ASN. Hence no change in RLC configurations */
13085       if(storedRlcUeCfg != NULLP)
13086       {
13087          for(cfgIdx = 0; cfgIdx < storedRlcUeCfg->numLcs; cfgIdx++)
13088          {
13089             if(storedRlcUeCfg->rlcLcCfg[cfgIdx].lcId == lcId)
13090             {
13091                rlcModeInfo = storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcMode;
13092                break;
13093             }
13094          }
13095       }
13096
13097       procRlcLcCfg(drbModItem->dRBID, lcId, RB_TYPE_DRB, rlcModeInfo, CONFIG_MOD, NULL, rlcLcToAdd, drbModItem->qoSInformation);
13098       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_MOD, NULL, NULL, drbModItem, NULL, macLcToAdd, upTnlInfo) != ROK)
13099       {
13100          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
13101          return RFAILED;
13102       }
13103    }
13104    return ROK;
13105 }
13106
13107 /*******************************************************************
13108  *
13109  * @brief extract Drb List received by CU
13110  *
13111  * @details
13112  *
13113  *    Function : extractDrbListToSetupMod
13114  *
13115  *    Functionality: extract Drb List received by CU
13116  *                   for both MAC and RLC
13117  *
13118  * @params[in] DRBs_ToBeSetup_Item_t pointer
13119  *             DuUeCfg pointer
13120  * @return ROK/RFAIED
13121  *
13122  * ****************************************************************/
13123
13124 uint8_t extractDrbListToSetupMod(DRBs_ToBeSetup_List_t *drbCfg, DRBs_ToBeSetupMod_List_t *drbSetupModCfg,\
13125  DRBs_ToBeModified_List_t *drbModCfg, uint8_t drbCount, DuUeCfg *ueCfgDb, uint32_t *drbBitMap, RlcUeCfg *rlcUeCfg)
13126 {
13127    uint8_t ret = ROK;
13128    uint8_t drbIdx = 0, rlcLcIdx = 0;
13129    uint8_t drbId = 0, lcId = 0;
13130    DRBs_ToBeSetup_Item_t *drbItem = NULLP;
13131    DRBs_ToBeSetupMod_ItemIEs_t *drbSetupModItem = NULLP;
13132    DRBs_ToBeModified_ItemIEs_t *drbModItem = NULLP;
13133    LcCfg *macLcCtxt = NULLP;
13134    RlcBearerCfg *rlcLcCtxt = NULLP;
13135
13136    ret = ROK;
13137    if(drbCount > 0)
13138    {
13139       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
13140       {
13141          macLcCtxt = NULL;
13142          rlcLcCtxt = NULL;
13143
13144          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
13145          { 
13146             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in MAC at extractDrbListToSetupMod()");
13147             ret = RFAILED;
13148             break;
13149          }
13150          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
13151          {
13152             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in RLC at extractDrbListToSetupMod()");
13153             ret = RFAILED;
13154             break;
13155          }
13156
13157          if(drbModCfg != NULLP)
13158          {
13159             drbModItem = (DRBs_ToBeModified_ItemIEs_t *) drbModCfg->list.array[drbIdx];
13160             drbId = drbModItem->value.choice.DRBs_ToBeModified_Item.dRBID;
13161          }
13162          else if(drbCfg != NULLP)
13163             drbId = drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item.dRBID;
13164          else if(drbSetupModCfg != NULL)
13165          {
13166             drbSetupModItem = (DRBs_ToBeSetupMod_ItemIEs_t *) drbSetupModCfg->list.array[drbIdx];
13167             drbId = drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item.dRBID;
13168          }
13169
13170          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
13171          {
13172             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rbId == drbId && ueCfgDb->rlcLcCfg[rlcLcIdx].rbType == RB_TYPE_DRB)
13173             {
13174                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
13175                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
13176                break;
13177             }
13178          }
13179          if(!macLcCtxt)
13180          {
13181             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(LcCfg));
13182             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
13183             ueCfgDb->numMacLcs++;
13184          }
13185          if(!rlcLcCtxt)
13186          {
13187             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
13188             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
13189             ueCfgDb->numRlcLcs++;
13190          }
13191
13192          if(drbModCfg != NULLP)
13193          {
13194             lcId = fetchLcId(drbId);
13195             if(lcId < MIN_DRB_LCID)
13196             {
13197                DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToSetupMod() for Modified List", lcId);
13198                break;
13199             } 
13200             ret = procDrbListToSetupMod(lcId, NULL, NULL, &(drbModItem->value.choice.DRBs_ToBeModified_Item),\
13201             macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13202             if(ret == RFAILED)
13203             {
13204                DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for Modified List");
13205                break;
13206             }
13207          }
13208          else
13209          {
13210             lcId = getDrbLcId(drbBitMap);
13211             if(lcId == RFAILED)
13212             {
13213                DU_LOG("\nERROR  -->  F1AP :  InCorrect LCID extractDrbListToSetupMod()");
13214                ret = RFAILED;
13215                break;
13216             }
13217             if(drbCfg != NULL)
13218             {
13219                drbItem = &drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
13220                ret = procDrbListToSetupMod(lcId, drbItem, NULL, NULL, macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13221                if(ret == RFAILED)
13222                {
13223                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetup List");
13224                   break;
13225                }
13226             }
13227             else if(drbSetupModCfg != NULL)
13228             {
13229                ret = procDrbListToSetupMod(lcId, NULL, &(drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item), NULL,\
13230                      macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
13231                if(ret == RFAILED)
13232                {
13233                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetupMod List");
13234                   break;
13235                }
13236                ueCfgDb->numDrbSetupMod++;
13237             }
13238          }
13239          ueCfgDb->numDrb++;
13240  
13241          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToSetupMod:lcId:%x ,BitMap:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
13242                             lcId,*drbBitMap, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
13243          if(ret == RFAILED)
13244          {
13245             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod()");
13246             break;
13247          }
13248       }
13249    }
13250    else
13251       ret = RFAILED;
13252
13253    return ret;
13254 }
13255
13256 /*******************************************************************
13257  *
13258  * @brief Function to extract Dl RRC Msg received from CU
13259  *
13260  * @details
13261  *
13262  *    Function : extractDlRrcMsg
13263  *
13264  *    Functionality: Function to extract Dl RRC Msg received from CU
13265  *
13266  * @params[in] F1AP message
13267  * @return ROK     - success
13268  *         RFAILED - failure
13269  *
13270  * ****************************************************************/
13271
13272 uint8_t extractDlRrcMsg(uint32_t gnbDuUeF1apId, uint32_t gnbCuUeF1apId, \
13273    F1DlRrcMsg *dlRrcMsg, RRCContainer_t *rrcContainer)
13274 {
13275    uint8_t ret = ROK;
13276    dlRrcMsg->rrcMsgSize = rrcContainer->size;
13277    if(dlRrcMsg->rrcMsgSize > 0)
13278    {
13279       DU_ALLOC_SHRABL_BUF(dlRrcMsg->rrcMsgPdu, dlRrcMsg->rrcMsgSize);
13280       if(!dlRrcMsg->rrcMsgPdu)
13281       {
13282          DU_LOG("\nERROR  --> DU APP : Memory allocation failed for RRC Msg in extractDlRrcMsg()");
13283          ret = RFAILED;
13284       }
13285       else
13286       {
13287          dlRrcMsg->gnbDuUeF1apId = gnbDuUeF1apId;
13288          dlRrcMsg->gnbCuUeF1apId = gnbCuUeF1apId;
13289          dlRrcMsg->srbId = SRB1_LCID;
13290          memcpy(dlRrcMsg->rrcMsgPdu, rrcContainer->buf, dlRrcMsg->rrcMsgSize);
13291       }
13292    }
13293    return ret;
13294 }
13295
13296 /*******************************************************************
13297  *
13298  * @brief Extract UE capability info 
13299  *
13300  * @details
13301  *
13302  *    Function : extractUeCapability
13303  *
13304  *    Functionality: Extract UE capability info and stores in ue Cb
13305  *
13306  * @params[in] Octet string of UE capability RAT container list
13307  * @return ROK     - success
13308  *         RFAILED - failure
13309  *
13310  * ****************************************************************/
13311 UE_NR_Capability_t *extractUeCapability(UE_CapabilityRAT_ContainerList_t *ueCapablityListBuf, DuUeCb *ueCb)
13312 {
13313    uint8_t  idx;
13314    uint16_t recvBufLen;
13315    asn_dec_rval_t rval;
13316    UE_NR_Capability_t  *ueNrCap = NULLP;
13317    UE_CapabilityRAT_ContainerListRRC_t  *ueCapRatContList = NULLP;
13318
13319    /* Decoding UE Capability RAT Container List */
13320    recvBufLen = ueCapablityListBuf->size;
13321    DU_ALLOC(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13322    if(!ueCapRatContList)
13323    {
13324       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13325       return NULLP;
13326    }
13327    memset(ueCapRatContList, 0, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13328    memset(&rval, 0, sizeof(asn_dec_rval_t));
13329    rval = aper_decode(0, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, (void **)&ueCapRatContList,
13330           ueCapablityListBuf->buf, recvBufLen, 0, 0);
13331    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13332    {
13333       DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13334       return NULLP;
13335    }
13336    xer_fprint(stdout, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, ueCapRatContList);
13337
13338    /* Free encoded buffer after decoding */
13339
13340    for(idx = 0; idx < ueCapRatContList->list.count; idx++)
13341    {
13342       if(ueCapRatContList->list.array[idx]->rat_Type == RAT_Type_nr)
13343       {
13344          /* Decoding UE NR Capability */
13345           recvBufLen = ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.size;
13346           DU_ALLOC(ueNrCap, sizeof(UE_NR_Capability_t));
13347           if(!ueNrCap)
13348           {
13349              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
13350              DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13351              return NULLP;
13352           } 
13353           memset(ueNrCap, 0, sizeof(UE_NR_Capability_t));
13354           memset(&rval, 0, sizeof(asn_dec_rval_t));
13355           rval = aper_decode(0, &asn_DEF_UE_NR_Capability, (void **)&ueNrCap,
13356                  ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf, recvBufLen, 0, 0);
13357           if(rval.code == RC_FAIL || rval.code == RC_WMORE)
13358           {
13359              DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
13360              return NULLP;
13361           }
13362           xer_fprint(stdout, &asn_DEF_UE_NR_Capability, ueNrCap);
13363           
13364           /* Free encoded buffer after decoding */
13365           free(ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf);
13366       }
13367       free(ueCapRatContList->list.array[idx]);
13368    }
13369
13370    /* Free Memory*/
13371    free(ueCapRatContList->list.array);
13372    DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
13373    return ueNrCap;
13374 }
13375  
13376 /*******************************************************************
13377 *
13378 * @brief free UE context setup request from CU
13379 *
13380 * @details
13381 *
13382 *    Function : freeAperDecodeF1UeContextSetupReq
13383 *
13384 *    Functionality: freeing part for the memory allocated by aper_decoder
13385 *
13386 * @params[in] F1AP message
13387 * @return ROK     - success
13388 *         RFAILED - failure
13389 *
13390 * ****************************************************************/
13391 void freeAperDecodeF1UeContextSetupReq(UEContextSetupRequest_t   *ueSetReq)
13392 {
13393    uint8_t ieIdx = 0;
13394
13395    if(ueSetReq->protocolIEs.list.array != NULLP)
13396    {
13397       for(ieIdx = 0; ieIdx < ueSetReq->protocolIEs.list.count; ieIdx++)
13398       {
13399          if(ueSetReq->protocolIEs.list.array[ieIdx])
13400          {
13401             switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13402             {
13403                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13404                   break;
13405                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13406                   break;
13407                case ProtocolIE_ID_id_SpCell_ID:
13408                   freeAperDecodeNrcgi(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
13409                   break;
13410                case ProtocolIE_ID_id_ServCellIndex:
13411                   break;
13412                case ProtocolIE_ID_id_SpCellULConfigured:
13413                   break;
13414                case ProtocolIE_ID_id_CUtoDURRCInformation:
13415
13416                   freeAperDecodeCuToDuInfo(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation);
13417                   break;
13418                case ProtocolIE_ID_id_SCell_ToBeSetup_List:
13419
13420                   freeAperDecodeSplCellList(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SCell_ToBeSetup_List);
13421                   break;
13422                case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
13423
13424                   freeAperDecodeSRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List);
13425                   break;
13426                case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
13427
13428                   freeAperDecodeDRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List);
13429                   break;
13430                case ProtocolIE_ID_id_RRCContainer:
13431                   {
13432
13433                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf != NULLP)
13434                      {
13435
13436                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
13437                      }
13438                      break;
13439                   }
13440                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13441                   break;
13442                case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
13443                   {
13444                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf)
13445                      {
13446                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf);
13447                      }
13448                      break;
13449                   }
13450                default:
13451                   DU_LOG("\nERROR  -->  F1AP: Invalid event type %ld " ,ueSetReq->protocolIEs.list.array[ieIdx]->id);
13452             } 
13453             free(ueSetReq->protocolIEs.list.array[ieIdx]);
13454          }
13455       }
13456       free(ueSetReq->protocolIEs.list.array);
13457    }
13458 }
13459 /*******************************************************************
13460  *
13461  * @brief Process UE context setup request from CU
13462  *
13463  * @details
13464  *
13465  *    Function : procF1UeContextSetupReq
13466  *
13467  *    Functionality: Process UE context setup request from CU
13468  *
13469  * @params[in] F1AP message
13470  * @return ROK     - success
13471  *         RFAILED - failure
13472  *
13473  * ****************************************************************/
13474 uint8_t procF1UeContextSetupReq(F1AP_PDU_t *f1apMsg)
13475 {
13476    int8_t ueIdx = -1;
13477    uint8_t  ret=0, ieIdx=0, ieExtIdx = 0, servCellIdx = 0;
13478    bool ueCbFound = false, hoInProgress = false;
13479    uint16_t cellIdx=0;
13480    uint64_t nrCellId = 0;
13481    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0, bitRateSize=0;
13482    DuUeCb   *duUeCb = NULL;
13483    UEContextSetupRequest_t   *ueSetReq = NULL;
13484    DRBs_ToBeSetup_List_t *drbCfg = NULL;
13485    CUtoDURRCInformation_t *rrcInfo = NULL;
13486    DRXCycle_t *drxCycle;
13487
13488    ret = ROK;
13489
13490    ueSetReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextSetupRequest;
13491    for(ieIdx=0; (ieIdx < ueSetReq->protocolIEs.list.count && ret == ROK); ieIdx++)
13492    {
13493       switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13494       {
13495          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13496             {
13497                gnbCuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
13498                break;
13499             }
13500
13501          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13502             {
13503                gnbDuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
13504                break;
13505             }
13506
13507          case ProtocolIE_ID_id_SpCell_ID:
13508             {
13509                bitStringToInt(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity, &nrCellId);
13510
13511                GET_CELL_IDX(nrCellId, cellIdx);
13512                if(!duCb.actvCellLst[cellIdx])
13513                {
13514                   DU_LOG("\nERROR  -->  F1AP : Cell Id [%lu] not found", nrCellId);
13515                   ret = RFAILED;
13516                }
13517                break;
13518             }
13519
13520          case ProtocolIE_ID_id_ServCellIndex:
13521             {
13522                servCellIdx = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.ServCellIndex;
13523                break;
13524             }
13525
13526          case ProtocolIE_ID_id_SpCellULConfigured:
13527             {
13528                /* Indicates whether the gNB-CU requests the gNB-DU to configure the uplink as no UL, 
13529                   UL, SUL or UL+SUL for the indicated cell for the UE */
13530                break;
13531             }
13532
13533          case ProtocolIE_ID_id_CUtoDURRCInformation:
13534             {
13535                rrcInfo = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation;
13536
13537                /* Search if UE context is present */
13538                for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
13539                {
13540                   if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId)
13541                   {
13542                      ueCbFound = true;
13543                      duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13544                      break;
13545                   }
13546                }
13547
13548                /* Check if UE Handover scenario */
13549                if(rrcInfo->iE_Extensions)
13550                {
13551                   for(ieExtIdx = 0; ieExtIdx < rrcInfo->iE_Extensions->list.count; ieExtIdx++)
13552                   {
13553                      if(rrcInfo->iE_Extensions->list.array[ieExtIdx]->id == ProtocolIE_ID_id_HandoverPreparationInformation)
13554                      {
13555                         hoInProgress = true;
13556                         break;
13557                      }
13558                   }
13559                }
13560                
13561                /* If UE context is not present, but UE is in handover */
13562                if(!ueCbFound && hoInProgress)
13563                {
13564                   ueIdx = getFreeBitFromUeBitMap(nrCellId);
13565                   if(ueIdx != -1)
13566                      gnbDuUeF1apId = ueIdx +1;
13567                   else
13568                   {
13569                      DU_LOG("\nERROR  -->  F1AP : No free UE IDX found in UE bit map of cell Id [%lu]", nrCellId);
13570                      ret = RFAILED;
13571                      break;
13572                   }
13573                   duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13574                   duUeCb->f1UeDb = NULL;
13575                   duUeCb->gnbCuUeF1apId = gnbCuUeF1apId;
13576                   duUeCb->gnbDuUeF1apId = gnbDuUeF1apId;
13577                   GET_CRNTI(duUeCb->crnti, duUeCb->gnbDuUeF1apId);
13578                   duUeCb->ueState = UE_HANDIN_IN_PROGRESS;
13579                }
13580
13581                if(duUeCb)
13582                {
13583                   DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
13584                   if(duUeCb->f1UeDb)
13585                   {
13586                      memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
13587                      duUeCb->f1UeDb->actionType = UE_CTXT_SETUP;
13588                      duUeCb->f1UeDb->cellIdx = cellIdx;
13589                   }
13590                   else
13591                   {
13592                      DU_LOG("\nERROR  -->  F1AP: Memory Alloc Failed at procF1UeContextSetupReq()");
13593                      ret = RFAILED;
13594                      break;
13595                   }
13596                }
13597                else
13598                {
13599                   DU_LOG("\nERROR  -->  F1AP: DuUeCb is not found at procF1UeContextSetupReq()");
13600                   ret = RFAILED;
13601                   break;
13602                }
13603                  
13604                /* Extract UE capability info */
13605                if(rrcInfo->uE_CapabilityRAT_ContainerList)
13606                {
13607                   duUeCb->f1UeDb->duUeCfg.ueNrCapability = extractUeCapability(rrcInfo->uE_CapabilityRAT_ContainerList, duUeCb);
13608                }
13609
13610                /* Extract IE extension */
13611                if(rrcInfo->iE_Extensions)
13612                {
13613                   if(extractCuToDuRrcInfoExt(rrcInfo->iE_Extensions, &duUeCb->f1UeDb->duUeCfg) != ROK)
13614                   {
13615                      DU_LOG("\nERROR  -->  F1AP: Failed to extract CU to DU RRC information extension IE");
13616                      //TODO: Update the failure cause in ue context Setup Response
13617                      ret = RFAILED;
13618                   }
13619                }
13620                break;
13621             } 
13622
13623 #ifdef NR_DRX
13624          case ProtocolIE_ID_id_DRXCycle:
13625             {
13626                duUeCb->f1UeDb->duUeCfg.drxCyclePres = true;
13627                drxCycle = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRXCycle;
13628                duUeCb->f1UeDb->duUeCfg.drxCycle.drxLongCycleLength =  convertLongDrxCycleLengthEnumToValue(drxCycle->longDRXCycleLength);
13629                if(drxCycle->shortDRXCycleLength)
13630                {
13631                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCyclePres = true;
13632                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycle = \
13633                   convertShortDrxCycleLengthEnumToValue(*(drxCycle->shortDRXCycleLength));
13634                }
13635                if(drxCycle->shortDRXCycleTimer)
13636                   duUeCb->f1UeDb->duUeCfg.drxCycle.shortDrxCycle.drxShortCycleTimer = *(drxCycle->shortDRXCycleTimer);   
13637
13638                break;
13639             }
13640
13641 #endif
13642          case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
13643             {
13644                if(extractSrbListToSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List,\
13645                         &duUeCb->f1UeDb->duUeCfg))
13646                {
13647                   DU_LOG("\nERROR  -->  DU APP : Failed at extractSrbListToSetup()");
13648                   //TODO: Update the failure cause in ue context Setup Response
13649                   ret = RFAILED;
13650                }
13651                break;
13652             }
13653
13654          case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
13655             {
13656                drbCfg = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List;
13657
13658                if(extractDrbListToSetupMod(drbCfg, NULL, NULL, drbCfg->list.count, &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULLP))
13659                {
13660                   DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod()");
13661                   //TODO: Update the failure cause in ue context Setup Response
13662                   ret = RFAILED;
13663                }
13664                break;
13665             }
13666          case ProtocolIE_ID_id_RRCContainer:
13667             {
13668                /* Filling Dl RRC Msg Info */
13669                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
13670                if(!duUeCb->f1UeDb->dlRrcMsg)
13671                {
13672                   DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for DL RRC Msg in procUeCtxtSetupReq()");
13673                   ret = RFAILED;
13674                }
13675                else
13676                {
13677                   duUeCb->f1UeDb->dlRrcMsgPres = true;
13678                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
13679                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
13680                         &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer);
13681                }          
13682                break;
13683             }
13684
13685          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13686             {
13687                if(duUeCb->f1UeDb->dlRrcMsg)
13688                {
13689                   if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
13690                   {
13691                      duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
13692                   }
13693                   else
13694                   {
13695                      DU_LOG("\nERROR  -->  Ignoring delivery report, since rrcContainer is not present");
13696                   }
13697                }
13698                break;
13699             }
13700
13701          case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
13702             {
13703                /* MaximumBitRate Uplink */
13704                bitRateSize = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.size;
13705                if(bitRateSize > 0)
13706                {
13707                   DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->duUeCfg.ambrCfg, bitRateSize);
13708                   if(!duUeCb->f1UeDb->duUeCfg.ambrCfg)
13709                   {
13710                      DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for bitRate in procUeCtxtSetupReq");
13711                      ret = RFAILED;
13712                   }
13713                   else
13714                   {
13715                      memset(duUeCb->f1UeDb->duUeCfg.ambrCfg, 0, sizeof(AmbrCfg)); 
13716                      memcpy(&duUeCb->f1UeDb->duUeCfg.ambrCfg->ulBr,
13717                            ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf, bitRateSize);
13718                   }
13719                }
13720                else
13721                   ret = RFAILED;
13722                break;
13723             }
13724
13725          default:
13726             {
13727                break;
13728             }
13729       } /* End of switch */
13730
13731       /* In case of any failure in any IE */
13732       if(ret == RFAILED)
13733       {
13734          // BuildAndSendUeContextSetupRsp(cellId,ueId);
13735          DU_LOG("\nERROR  -->  F1AP: Failed to process UE CNTXT SETUP REQ at procF1UeContextSetupReq()"); 
13736          break;
13737       }
13738    } /* End of for loop of IEs */
13739
13740    if(ret == ROK)
13741       ret = duProcUeContextSetupRequest(duUeCb);
13742
13743    freeAperDecodeF1UeContextSetupReq(ueSetReq); 
13744    return ret;
13745
13746 }
13747 /*******************************************************************
13748  * @brief Free the memory allocated for Dl Tunnel Info
13749  *
13750  * @details
13751  *
13752  *    Function : freeDlTnlInfo
13753  *
13754  *    Functionality:
13755  *       Free the memory allocated for Dl Tunnel Info
13756  *
13757  * @params[in] DLUPTNLInformation_ToBeSetup_List_t *
13758  * @return void
13759  *
13760  * ****************************************************************/
13761
13762 void freeDlTnlInfo(DLUPTNLInformation_ToBeSetup_List_t *tnlInfo)
13763 {
13764    uint8_t arrIdx = 0;
13765
13766    if(tnlInfo)
13767    {
13768       for(arrIdx=0; arrIdx < tnlInfo->list.count; arrIdx++)
13769       {
13770          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf,\
13771                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.size);
13772          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf,\
13773                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.size);
13774          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
13775          DU_FREE(tnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
13776       }
13777       DU_FREE(tnlInfo->list.array, tnlInfo->list.size);
13778    }
13779 }
13780
13781 /*******************************************************************
13782  * @brief Free the memory allocated for DRB setup List
13783  *
13784  * @details
13785  *
13786  *    Function : freeDrbSetupList
13787  *
13788  *    Functionality:
13789  *       Free the memory allocated for DRB setup list
13790  *
13791  * @params[in] DRBs_Setup_List_t *
13792  * @return void
13793  *
13794  * ****************************************************************/
13795 void freeDrbSetupList(DRBs_Setup_List_t *drbSetupList)
13796 {
13797    uint8_t arrIdx = 0;
13798    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
13799
13800    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
13801    {
13802       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
13803       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List);
13804       DU_FREE(drbSetupList->list.array[arrIdx],  sizeof(DRBs_Setup_Item_t));
13805    }
13806    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
13807 }
13808
13809 /*******************************************************************
13810  * @brief Free the memory allocated for UE Setup response
13811  *
13812  * @details
13813  *
13814  *    Function : FreeUeContextSetupRsp
13815  *
13816  *    Functionality:
13817  *       Free the memory allocated for UE Setup response
13818  *
13819  * @params[in] F1AP PDU for UE setup response
13820  * @return ROK     - success
13821  *         RFAILED - failure
13822  *
13823  * ****************************************************************/
13824 void FreeUeContextSetupRsp(F1AP_PDU_t *f1apMsg)
13825 {
13826    uint8_t idx;
13827    UEContextSetupResponse_t *ueSetRsp = NULLP;
13828
13829    if(f1apMsg)
13830    {
13831       if(f1apMsg->choice.successfulOutcome)
13832       {
13833          ueSetRsp = &f1apMsg->choice.successfulOutcome->value.choice.\
13834                     UEContextSetupResponse;
13835          if(ueSetRsp->protocolIEs.list.array)
13836          {
13837             for(idx = 0; idx < ueSetRsp->protocolIEs.list.count; idx++)
13838             {
13839                if(ueSetRsp->protocolIEs.list.array[idx])
13840                {
13841                   switch(ueSetRsp->protocolIEs.list.array[idx]->id)
13842                   {
13843                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13844                         break;
13845                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13846                         break;
13847                      case ProtocolIE_ID_id_DUtoCURRCInformation:
13848                         {
13849                            CellGroupConfig_t *cellGrpCfg = NULLP;
13850                            cellGrpCfg  = &ueSetRsp->protocolIEs.list.array[idx]->value.choice.\
13851                                          DUtoCURRCInformation.cellGroupConfig;
13852                            if(cellGrpCfg->buf != NULLP)
13853                            {
13854                               DU_FREE(cellGrpCfg->buf, cellGrpCfg->size);
13855                               cellGrpCfg = NULLP;
13856                            }
13857                            break;
13858                         }
13859                     case ProtocolIE_ID_id_DRBs_Setup_List:
13860                         {
13861                            freeDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List); 
13862                            break;
13863                         }
13864                      default:
13865                         DU_LOG("\nERROR  -->  DUAPP: Invalid Id %ld at FreeUeContextSetupRsp()",\
13866                         ueSetRsp->protocolIEs.list.array[idx]->id);
13867                         break;
13868                   }
13869                   DU_FREE(ueSetRsp->protocolIEs.list.array[idx],\
13870                         sizeof(UEContextSetupResponseIEs_t));
13871                }
13872             }
13873             DU_FREE(ueSetRsp->protocolIEs.list.array, \
13874                   ueSetRsp->protocolIEs.list.size);
13875          }
13876          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
13877       }
13878       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
13879    }
13880 }
13881
13882 /*******************************************************************
13883  *
13884  * @brief Builds Ue context Setup Rsp DU To CU Info
13885  *
13886  * @details
13887  *
13888  *    Function : EncodeUeCntxtDuToCuInfo
13889  *
13890  *    Functionality: Builds Ue context Setup Rsp DU To CU Info
13891  *
13892  * @params[in] CellGroupConfig_t *, CellGroupConfigRrc_t * 
13893  *
13894  * @return ROK     - success
13895  *         RFAILED - failure
13896  *
13897  ******************************************************************/
13898
13899 uint8_t EncodeUeCntxtDuToCuInfo(CellGroupConfig_t *duToCuCellGrp, CellGroupConfigRrc_t *duCellGrpCfg)
13900 {
13901    asn_enc_rval_t        encRetVal;
13902
13903    xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, duCellGrpCfg);
13904    memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
13905    encBufSize = 0;
13906    encRetVal = aper_encode(&asn_DEF_CellGroupConfigRrc, 0, duCellGrpCfg, PrepFinalEncBuf, encBuf);
13907    /* Encode results */
13908    if(encRetVal.encoded == ENCODE_FAIL)
13909    {
13910       DU_LOG( "\nERROR  -->  F1AP : Could not encode UeCntxtDuToCuInfo (at %s)\n",\
13911             encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
13912       return RFAILED;
13913    }
13914    else
13915    {
13916       DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UeCntxtDuToCuInfo\n");
13917       for(int i=0; i< encBufSize; i++)
13918       {
13919          printf("%x",encBuf[i]);
13920       }
13921    }
13922    duToCuCellGrp->size = encBufSize;
13923    DU_ALLOC(duToCuCellGrp->buf, duToCuCellGrp->size);
13924    if(!duToCuCellGrp->buf)
13925    {
13926       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in UeCntxtDuToCuInfo");
13927    }
13928    memcpy(duToCuCellGrp->buf, encBuf, duToCuCellGrp->size);
13929    return ROK;
13930 }
13931
13932 /*******************************************************************
13933  *
13934  * @brief Fills Dl Gtp tunnel Info
13935  *
13936  * @details
13937  *
13938  *    Function : fillGtpTunnelforDl
13939  *
13940  *    Functionality: Fills Dl Gtp tunnel Info
13941  *
13942  * @params[in] 
13943  *
13944  * @return ROK     - success
13945  *         RFAILED - failure
13946  *
13947  * ****************************************************************/
13948
13949 uint8_t fillGtpTunnelforDl(GTPTunnel_t *gtpDl, GtpTnlCfg *gtpUeCfg)
13950 {
13951    uint8_t bufSize = 0;
13952
13953    gtpDl->transportLayerAddress.size    = 4*sizeof(uint8_t);
13954    DU_ALLOC(gtpDl->transportLayerAddress.buf, gtpDl->transportLayerAddress.size);
13955    if(gtpDl->transportLayerAddress.buf == NULLP)
13956    {
13957       return RFAILED;
13958    }
13959    memcpy(gtpDl->transportLayerAddress.buf, &gtpUeCfg->dlTnlAddress, gtpDl->transportLayerAddress.size);
13960
13961    /*GTP TEID*/
13962    gtpDl->gTP_TEID.size = 4 * sizeof(uint8_t);
13963    DU_ALLOC(gtpDl->gTP_TEID.buf, gtpDl->gTP_TEID.size);
13964    if(gtpDl->gTP_TEID.buf == NULLP)
13965    {
13966       return RFAILED;
13967    }
13968    bufSize = 3; /*forming an Octect String*/
13969    fillTeIdString(bufSize, gtpUeCfg->teId, gtpDl->gTP_TEID.buf);
13970
13971    return ROK;
13972 }
13973
13974 /*******************************************************************
13975  *
13976  * @brief Fills DL Tunnel Setup List
13977  *
13978  * @details
13979  *
13980  *    Function : fillDlTnlSetupList
13981  *
13982  *    Functionality: Fills the DL Tunnel Setup List
13983  *
13984  * @params[in] 
13985  *
13986  * @return ROK     - success
13987  *         RFAILED - failure
13988  *
13989  * ****************************************************************/
13990
13991 uint8_t fillDlTnlSetupList(DLUPTNLInformation_ToBeSetup_List_t *dlTnlInfo, UpTnlCfg *tnlCfg)
13992 {
13993    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
13994
13995    eleCount = 1;
13996    dlTnlInfo->list.count = eleCount; 
13997    dlTnlInfo->list.size = (eleCount * sizeof(DLUPTNLInformation_ToBeSetup_Item_t *));
13998
13999    /* Initialize the DL Tnl Setup List Members */
14000    DU_ALLOC(dlTnlInfo->list.array, dlTnlInfo->list.size);
14001    if(dlTnlInfo->list.array == NULLP)
14002    {
14003       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL Tnl Setup List in fillDlTnlSetupList()");
14004       ret = RFAILED;
14005    }
14006    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14007    {
14008       DU_ALLOC(dlTnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
14009       if(dlTnlInfo->list.array[arrIdx] == NULLP)
14010       {
14011          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDlTnlSetupList()", arrIdx);
14012          return RFAILED;
14013       }
14014       dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.present = UPTransportLayerInformation_PR_gTPTunnel;
14015       DU_ALLOC(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
14016       if(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel == NULLP)
14017       {
14018          DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL tunnel info in fillDlTnlSetupList()");
14019          return RFAILED;
14020       }
14021       ret = fillGtpTunnelforDl(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel,\
14022                tnlCfg->tnlCfg1);
14023       if(ret != ROK)
14024          break;
14025    }
14026    return ret;
14027 }
14028
14029 /*******************************************************************
14030  *
14031  * @brief Fills the Drb Setup List for Ue Context Setup Response
14032  *
14033  * @details
14034  *
14035  *    Function : fillDrbSetupList
14036  *
14037  *    Functionality: Fills the Drb Setup List for Ue Context Setup Response
14038  *
14039  * @params[in] 
14040  *
14041  * @return ROK     - success
14042  *         RFAILED - failure
14043  *
14044  * ****************************************************************/
14045 uint8_t fillDrbSetupList(DRBs_Setup_List_t *drbSetupList, DuUeCfg *ueCfg)
14046 {
14047    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
14048    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
14049
14050    eleCount = ueCfg->numDrb;
14051    drbSetupList->list.count = eleCount;
14052    drbSetupList->list.size = \
14053         (eleCount * sizeof(DRBs_Setup_Item_t *));
14054
14055    /* Initialize the Drb Setup List Members */
14056    DU_ALLOC(drbSetupList->list.array, drbSetupList->list.size);
14057    if(drbSetupList->list.array == NULLP)
14058    {
14059       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DRB Setup List in fillDrbSetupList()");
14060       ret = RFAILED;
14061    }
14062
14063    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
14064    {
14065       DU_ALLOC(drbSetupList->list.array[arrIdx], sizeof(DRBs_Setup_Item_t));
14066       if(drbSetupList->list.array[arrIdx] == NULLP)
14067       {
14068          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDrbSetupList()", arrIdx);
14069          return RFAILED;
14070       }
14071       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
14072       drbItemIe->id = ProtocolIE_ID_id_DRBs_Setup_Item;
14073       drbItemIe->criticality = Criticality_reject;
14074       drbItemIe->value.present = DRBs_Setup_ItemIEs__value_PR_DRBs_Setup_Item;
14075       drbItemIe->value.choice.DRBs_Setup_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
14076       ret = fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List,\
14077           &ueCfg->upTnlInfo[arrIdx]);
14078       if(ret != ROK)
14079          break;
14080    }
14081    return ret;
14082 }
14083
14084 /*******************************************************************
14085  *
14086  * @brief Builds and sends the UE Setup Response
14087  *
14088  * @details
14089  *
14090  *    Function : BuildAndSendUeContextSetupRsp
14091  *
14092  *    Functionality: Constructs the UE Setup Response and sends
14093  *                   it to the DU through SCTP.
14094  *
14095  * @params[in] uint8_t cellId,uint8_t ueId
14096  *
14097  * @return ROK     - success
14098  *         RFAILED - failure
14099  *
14100  * ****************************************************************/
14101 uint8_t BuildAndSendUeContextSetupRsp(uint8_t cellId,uint8_t ueId)
14102 {
14103    uint8_t   idx, ret, cellIdx, elementCnt;
14104    uint32_t  gnbCuUeF1apId;   /* gNB-CU UE F1AP Id */
14105    uint32_t  gnbDuUeF1apId;   /* gNB-DU UE F1AP Id */
14106    asn_enc_rval_t  encRetVal;        /* Encoder return value */
14107    F1AP_PDU_t               *f1apMsg = NULLP;
14108    UEContextSetupResponse_t *ueSetRsp = NULLP;
14109    DuUeCb                   *ueCb = NULLP;
14110
14111    DU_LOG("\n INFO   -->  F1AP : Building UE Context Setup Response for cellId %d, ueId %d\n", cellId, ueId);
14112
14113    while(true)
14114    {
14115       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14116       if(f1apMsg == NULLP)
14117       {
14118          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14119          ret = RFAILED;
14120          break;
14121       }
14122
14123       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
14124       DU_ALLOC(f1apMsg->choice.successfulOutcome,
14125             sizeof(SuccessfulOutcome_t));
14126       if(f1apMsg->choice.successfulOutcome == NULLP)
14127       {
14128          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
14129          ret = RFAILED;
14130          break;
14131       }
14132
14133       f1apMsg->choice.successfulOutcome->procedureCode = \
14134                                                          ProcedureCode_id_UEContextSetup;
14135       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
14136       f1apMsg->choice.successfulOutcome->value.present = \
14137                                                          SuccessfulOutcome__value_PR_UEContextSetupResponse;
14138
14139       ueSetRsp =
14140          &f1apMsg->choice.successfulOutcome->value.choice.UEContextSetupResponse;
14141       elementCnt = 5;
14142       ueSetRsp->protocolIEs.list.count = elementCnt;
14143       ueSetRsp->protocolIEs.list.size = \
14144                                         elementCnt * sizeof(UEContextSetupResponse_t *);
14145
14146       /* Initialize the UESetup members */
14147       DU_ALLOC(ueSetRsp->protocolIEs.list.array, \
14148             ueSetRsp->protocolIEs.list.size);
14149       if(ueSetRsp->protocolIEs.list.array == NULLP)
14150       {
14151          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14152          ret = RFAILED;
14153          break;
14154       }
14155
14156       for(idx=0; idx<elementCnt; idx++)
14157       {
14158          DU_ALLOC(ueSetRsp->protocolIEs.list.array[idx],\
14159                sizeof(UEContextSetupResponseIEs_t));
14160          if(ueSetRsp->protocolIEs.list.array[idx] == NULLP)
14161          {
14162             DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
14163             ret = RFAILED;
14164             break;
14165          }
14166       }
14167       /* Fetching Ue Cb Info*/
14168       GET_CELL_IDX(cellId, cellIdx);
14169       gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
14170       gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
14171       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
14172
14173       idx = 0;
14174       /*GNB CU UE F1AP ID*/
14175       ueSetRsp->protocolIEs.list.array[idx]->id = \
14176                                                   ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
14177       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14178       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14179                                                              UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
14180       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
14181
14182       /*GNB DU UE F1AP ID*/
14183       idx++;
14184       ueSetRsp->protocolIEs.list.array[idx]->id = \
14185                                                   ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14186       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14187       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
14188                                                              UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
14189       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
14190
14191
14192       /*DUtoCURRC Information */
14193       idx++;
14194       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14195                                                    ProtocolIE_ID_id_DUtoCURRCInformation;
14196       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14197       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14198                                                             UEContextSetupResponseIEs__value_PR_DUtoCURRCInformation;
14199       BuildCellGroupConfigRrc(ueCb, &ueSetRsp->protocolIEs.list.array[idx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
14200
14201       /* CRNTI */
14202       idx++;
14203       ueSetRsp->protocolIEs.list.array[idx]->id  = ProtocolIE_ID_id_C_RNTI;
14204       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14205       ueSetRsp->protocolIEs.list.array[idx]->value.present = UEContextSetupResponseIEs__value_PR_C_RNTI;
14206       ueSetRsp->protocolIEs.list.array[idx]->value.choice.C_RNTI = ueCb->crnti; 
14207
14208
14209       /* Drb Setup List */
14210       idx++;
14211       ueSetRsp->protocolIEs.list.array[idx]->id  = \
14212                                                    ProtocolIE_ID_id_DRBs_Setup_List;
14213       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14214       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
14215                                                             UEContextSetupResponseIEs__value_PR_DRBs_Setup_List;
14216       ret = fillDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List,\
14217             &ueCb->f1UeDb->duUeCfg);
14218       if(ret == RFAILED)
14219       {
14220          DU_LOG("\nERROR  -->  F1AP : Failed to fillDrbSetupList in BuildAndSendUeContextSetupRsp()");
14221          freeF1UeDb(ueCb->f1UeDb);
14222          ueCb->f1UeDb = NULLP;
14223          break;
14224       }
14225
14226       /* Free UeContext Db created during Ue context Req */
14227       freeF1UeDb(ueCb->f1UeDb);
14228       ueCb->f1UeDb = NULLP;
14229
14230       /* TODO: To send Drb list */
14231       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14232
14233       /* Encode the UE context setup response type as APER */
14234       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
14235       encBufSize = 0;
14236       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14237             encBuf);
14238       /* Encode results */
14239       if(encRetVal.encoded == ENCODE_FAIL)
14240       {
14241          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Response structure (at %s)\n",\
14242                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14243          ret = RFAILED;
14244          break;
14245       }
14246       else
14247       {
14248          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Setup Response\n");
14249          for(int i=0; i< encBufSize; i++)
14250          {
14251             printf("%x",encBuf[i]);
14252          }
14253       }
14254
14255       /* Sending  msg  */
14256       if(sendF1APMsg()  != ROK)
14257       {
14258          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Response failed");
14259          ret = RFAILED;
14260          break;
14261       }
14262       break;
14263    }
14264    FreeUeContextSetupRsp(f1apMsg);
14265    return ret;
14266 }/* End of BuildAndSendUeContextSetupRsp */
14267 /*******************************************************************
14268 *
14269 * @brief  Build And Send Ue Context Rsp 
14270 *
14271 * @details
14272 *
14273 *    Function : BuildAndSendUeCtxtRsp 
14274 *
14275 *    Functionality : Build And Send Ue Context Rsp
14276
14277 * @params[in]
14278 * @return sucess = ROK
14279 *         failure = RFAILED
14280 *
14281 * ****************************************************************/
14282 uint8_t BuildAndSendUeCtxtRsp(uint8_t cellId, uint8_t ueId)
14283 {
14284    uint8_t cellIdx = 0, actionType = 0; 
14285
14286    GET_CELL_IDX(cellId, cellIdx);
14287    actionType = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].f1UeDb->actionType;
14288
14289    switch(actionType)
14290    {
14291       case UE_CTXT_SETUP:
14292          {
14293             if((BuildAndSendUeContextSetupRsp(cellId,ueId)) != ROK)
14294             {
14295                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextSetupRsp()");
14296                return RFAILED;
14297             }
14298             break;
14299          }
14300       case UE_CTXT_MOD:
14301          {
14302             if((BuildAndSendUeContextModRsp(&duCb.actvCellLst[cellIdx]->ueCb[ueId-1])) != ROK)
14303             {
14304                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextModRsp");
14305                return RFAILED;
14306             }
14307             break;
14308          }
14309       default:
14310          DU_LOG("ERROR  -->  F1AP: Invalid Action Type %d at BuildAndSendUeCtxtRsp()", actionType);
14311          break;
14312
14313    }
14314    return ROK;
14315 }
14316
14317 /*******************************************************************
14318  *
14319  * @brief deallocating the memory of  F1reset msg
14320  *
14321  * @details
14322  *
14323  *    Function : FreeF1ResetReq
14324  *
14325  *    Functionality :
14326  *         - freeing memory of F1reset request msg
14327  *
14328  * @params[in]
14329  * @return void
14330  *
14331  *
14332  * ****************************************************************/
14333 void FreeF1ResetReq(F1AP_PDU_t *f1apMsg)
14334 {
14335    uint8_t idx =0 ;
14336    Reset_t *f1ResetMsg;
14337
14338    if(f1apMsg)
14339    {
14340       if(f1apMsg->choice.initiatingMessage)
14341       {
14342          f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14343
14344          if(f1ResetMsg->protocolIEs.list.array)
14345          {
14346             for(idx=0 ;idx < f1ResetMsg->protocolIEs.list.count ; idx++)
14347             {
14348                if(f1ResetMsg->protocolIEs.list.array[idx])
14349                {
14350                   DU_FREE(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14351                }
14352             }
14353             DU_FREE(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14354          }
14355          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14356       }
14357       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14358    }
14359 }
14360 /*******************************************************************
14361  *
14362  * @brief Build and Send F1reset request 
14363  *
14364  * @details
14365  *
14366  *    Function : BuildAndSendF1ResetReq
14367  *
14368  *    Functionality:
14369  *         - Build and Send F1reset request msg
14370  *
14371  * @params[in]
14372  * @return ROK     - success
14373  *         RFAILED - failure
14374  *
14375  * ****************************************************************/
14376 uint8_t BuildAndSendF1ResetReq()
14377 {
14378    uint8_t          elementCnt=0;
14379    uint8_t          idx=0;
14380    uint8_t          ret= RFAILED;
14381    Reset_t          *f1ResetMsg = NULLP;
14382    F1AP_PDU_t       *f1apMsg = NULLP;
14383    asn_enc_rval_t   encRetVal;
14384    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset request \n");
14385    do
14386    {
14387       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14388       if(f1apMsg == NULLP)
14389       {
14390          break;
14391       }
14392       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
14393       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14394       if(f1apMsg->choice.initiatingMessage == NULLP)
14395       {
14396          break;
14397       }
14398       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_Reset;
14399       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
14400       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_Reset;
14401
14402       f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14403
14404       elementCnt = 3;
14405       f1ResetMsg->protocolIEs.list.count = elementCnt;
14406       f1ResetMsg->protocolIEs.list.size = elementCnt * sizeof(ResetIEs_t *);
14407
14408       /* Initialize the F1Setup members */
14409       DU_ALLOC(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
14410       if(f1ResetMsg->protocolIEs.list.array == NULLP)
14411       {
14412          break;
14413       }
14414       for(idx=0; idx<elementCnt; idx++)
14415       {
14416          DU_ALLOC(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
14417          if(f1ResetMsg->protocolIEs.list.array[idx] == NULLP)
14418          {
14419             break;
14420          }
14421       }
14422
14423       /*TransactionID*/
14424       idx=0;
14425       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
14426       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14427       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_TransactionID;
14428       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.TransactionID = 1;
14429
14430       /*Cause*/
14431       idx++;
14432       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_Cause;
14433       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_ignore;
14434       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_Cause;
14435       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.present = Cause_PR_radioNetwork;
14436       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.choice.radioNetwork = CauseRadioNetwork_action_desirable_for_radio_reasons;
14437
14438       /*Reset Type*/
14439       idx++;
14440       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_ResetType;
14441       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14442       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_ResetType;
14443       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.present = ResetType_PR_f1_Interface;
14444       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.choice.f1_Interface = ResetAll_reset_all;
14445
14446       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14447
14448       /* Encode the F1SetupRequest type as APER */
14449       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14450       encBufSize = 0;
14451       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14452             encBuf);
14453
14454       /* Encode results */
14455       if(encRetVal.encoded == ENCODE_FAIL)
14456       {
14457          DU_LOG("\nERROR  -->  F1AP : Could not encode F1Reset structure (at %s)\n",\
14458                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14459          break;
14460       }
14461       else
14462       {
14463          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1Reset\n");
14464          for(idx=0; idx< encBufSize; idx++)
14465          {
14466             printf("%x",encBuf[idx]);
14467          }
14468       }
14469
14470       if(sendF1APMsg() != ROK)
14471       {
14472          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset request failed");
14473          break;
14474       }
14475
14476       ret = ROK;
14477       break;
14478    }while(true);
14479
14480    FreeF1ResetReq(f1apMsg);
14481    return ret;
14482 }
14483 /*******************************************************************
14484  *
14485  * @brief Build And Send F1ResetAck
14486  *
14487  * @details
14488  *
14489  *    Function : BuildAndSendF1ResetAck
14490  *
14491  *    Functionality:
14492  *         - Build And Send  F1ResetRSP
14493  *
14494  * @return ROK     - success
14495  *         RFAILED - failure
14496  *
14497  * ****************************************************************/
14498 void FreeF1ResetAck(F1AP_PDU_t *f1apMsg)
14499 {
14500    uint8_t idx;
14501    ResetAcknowledge_t *f1ResetAck;
14502
14503    if(f1apMsg)
14504    {
14505       if(f1apMsg->choice.successfulOutcome)
14506       {
14507          f1ResetAck= &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14508
14509          if(f1ResetAck->protocolIEs.list.array)
14510          {
14511             for(idx=0; idx<f1ResetAck->protocolIEs.list.count ; idx++)
14512             {
14513                if(f1ResetAck->protocolIEs.list.array[idx])
14514                {
14515                   DU_FREE(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14516                }
14517             }
14518             DU_FREE(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14519          }
14520          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14521       }
14522       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14523    }
14524 }
14525
14526 /*******************************************************************
14527  *
14528  * @brief Build And Send F1ResetAck
14529  *
14530  * @details
14531  *
14532  *    Function : BuildAndSendF1ResetAck
14533  *
14534  *    Functionality:
14535  *         - Build And Send  F1ResetRSP
14536  *
14537  *  @params[in]
14538  * @return ROK     - success
14539  *         RFAILED - failure
14540  *
14541  * ****************************************************************/
14542 uint8_t BuildAndSendF1ResetAck()
14543 {
14544    uint8_t                idx = 0;
14545    uint8_t                elementCnt = 0;
14546    uint8_t                ret = RFAILED;
14547    F1AP_PDU_t             *f1apMsg = NULL;
14548    ResetAcknowledge_t     *f1ResetAck = NULLP;
14549    asn_enc_rval_t         encRetVal;
14550    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset Acknowledgment \n");
14551
14552    do{
14553       /* Allocate the memory for F1ResetRequest_t */
14554       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14555       if(f1apMsg == NULLP)
14556       {
14557          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14558          break;
14559       }
14560
14561       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
14562
14563       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14564       if(f1apMsg->choice.successfulOutcome == NULLP)
14565       {
14566          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14567          break;
14568       }
14569       f1apMsg->choice.successfulOutcome->criticality   = Criticality_reject;
14570       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetAcknowledge;
14571       f1ResetAck = &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14572
14573       elementCnt = 1;
14574
14575       f1ResetAck->protocolIEs.list.count = elementCnt;
14576       f1ResetAck->protocolIEs.list.size = elementCnt*sizeof(ResetAcknowledgeIEs_t *);
14577
14578       DU_ALLOC(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14579       if(f1ResetAck->protocolIEs.list.array == NULLP)
14580       {
14581          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1ResetAckIEs failed");
14582          break;
14583       }
14584
14585       for(idx=0; idx<elementCnt; idx++)
14586       {
14587          DU_ALLOC(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14588          if(f1ResetAck->protocolIEs.list.array[idx] == NULLP)
14589          {
14590             break;
14591          }
14592       }
14593       /*TransactionID*/
14594       idx = 0;
14595       f1ResetAck->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
14596       f1ResetAck->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14597       f1ResetAck->protocolIEs.list.array[idx]->value.present = ResetAcknowledgeIEs__value_PR_TransactionID;
14598       f1ResetAck->protocolIEs.list.array[idx]->value.choice.TransactionID = TRANS_ID;
14599
14600       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14601
14602       /* Encode the F1SetupRequest type as UPER */
14603       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14604       encBufSize = 0;
14605       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
14606
14607       /* Check encode results */
14608       if(encRetVal.encoded == ENCODE_FAIL)
14609       {
14610          DU_LOG("\nERROR  -->  F1AP : Could not encode F1ResetAck structure (at %s)\n",\
14611                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14612          break;
14613       }
14614       else
14615       {
14616          DU_LOG("\nDUBUG   -->  F1AP : Created APER encoded buffer for F1ResetAck\n");
14617          for(int i=0; i< encBufSize; i++)
14618          {
14619             printf("%x",encBuf[i]);
14620          }
14621       }
14622       /* Sending msg */
14623       if(sendF1APMsg() != ROK)
14624       {
14625          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset Acknowledgement failed");
14626          break;
14627       }
14628
14629       ret = ROK;
14630       break;
14631    }while(true);
14632
14633    FreeF1ResetAck(f1apMsg);
14634    return ret;
14635 }
14636 /******************************************************************
14637 *
14638 * @brief free F1 reset msg allocated by aper_decoder 
14639 *
14640 * @details
14641 *
14642 *    Function : freeAperDecodeF1ResetMsg 
14643 *
14644 *    Functionality: free F1 reset msg allocated by aper_decoder 
14645 *
14646 * @params[in] Reset_t *f1ResetMsg 
14647 * @return void 
14648 *
14649 * ****************************************************************/
14650
14651 void freeAperDecodeF1ResetMsg(Reset_t *f1ResetMsg)
14652 {
14653    uint8_t ieIdx =0;
14654    if(f1ResetMsg->protocolIEs.list.array)
14655    {
14656       for(ieIdx=0 ;ieIdx < f1ResetMsg->protocolIEs.list.count ; ieIdx++)
14657       {
14658          if(f1ResetMsg->protocolIEs.list.array[ieIdx])
14659          {
14660             free(f1ResetMsg->protocolIEs.list.array[ieIdx]);
14661          }
14662       }
14663       free(f1ResetMsg->protocolIEs.list.array);
14664    }
14665 }
14666
14667 /******************************************************************
14668  *
14669  * @brief Processes DL RRC Message Transfer  sent by CU
14670  *
14671  * @details
14672  *
14673  *    Function : procF1ResetReq
14674  *
14675  *    Functionality: Processes DL RRC Message Transfer sent by CU
14676  *
14677  * @params[in] F1AP_PDU_t ASN decoded F1AP message
14678  * @return ROK     - success
14679  *         RFAILED - failure
14680  *
14681  * ****************************************************************/
14682 uint8_t procF1ResetReq(F1AP_PDU_t *f1apMsg)
14683 {
14684    /* we are currently not supporting Ue release. right now we are supporting only init case of fireset */
14685    uint8_t       ieIdx = 0;
14686    uint8_t        ret = ROK;
14687    Reset_t       *f1ResetMsg = NULLP;
14688
14689    DU_LOG("\nINFO   -->  Processing F1 reset request");
14690    f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14691
14692    for(ieIdx=0; ieIdx<f1ResetMsg->protocolIEs.list.count; ieIdx++)
14693    {
14694       switch(f1ResetMsg->protocolIEs.list.array[ieIdx]->id)
14695       {
14696          case ProtocolIE_ID_id_TransactionID:
14697             break;
14698
14699          case ProtocolIE_ID_id_Cause:
14700             break;
14701
14702          case ProtocolIE_ID_id_ResetType:
14703             {
14704                break;
14705             }
14706
14707          default:
14708             break;
14709       }
14710    }
14711    ret = BuildAndSendF1ResetAck();
14712    DU_LOG("\nINFO   -->  UE release is not supported for now");
14713
14714    freeAperDecodeF1ResetMsg(f1ResetMsg);
14715
14716    return ret;
14717 }
14718
14719 /*******************************************************************
14720  *
14721  * @brief free the RRC delivery report
14722  *
14723  * @details
14724  *
14725  *    Function : freeRrcDeliveryReport
14726  *
14727  *    Functionality: free the RRC delivery report
14728  *
14729  * @params[in]
14730  * @return ROK     - success
14731  *         RFAILED - failure
14732  *
14733  * ****************************************************************/
14734 void freeRrcDeliveryReport(F1AP_PDU_t  *f1apMsg )
14735 {
14736    uint8_t idx=0;
14737    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
14738
14739    if(f1apMsg)
14740    {
14741       if(f1apMsg->choice.initiatingMessage)
14742       {
14743          rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
14744          if(rrcDeliveryReport->protocolIEs.list.array)
14745          {
14746             for(idx =0 ;idx <rrcDeliveryReport->protocolIEs.list.count ;
14747                   idx++)
14748             {
14749                if(rrcDeliveryReport->protocolIEs.list.array[idx])
14750                {
14751                   DU_FREE(rrcDeliveryReport->protocolIEs.list.array[idx],
14752                         sizeof(RRCDeliveryReportIEs_t));
14753                }   
14754             }
14755             DU_FREE(rrcDeliveryReport->protocolIEs.list.array,
14756                   rrcDeliveryReport->protocolIEs.list.size);
14757          }
14758          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
14759       }
14760       DU_FREE(f1apMsg,
14761             sizeof(F1AP_PDU_t));
14762    }
14763 }
14764
14765 /*******************************************************************
14766 *
14767 * @brief Builds and sends the RRC delivery report
14768 *
14769 * @details
14770 *
14771 *    Function : BuildAndSendRrcDeliveryReport
14772 *
14773 *    Functionality: Builds and sends the RRC delivery report
14774 *
14775 * @params[in]
14776 *
14777 * @return ROK     - success
14778 *         RFAILED - failure
14779 *
14780 * ****************************************************************/
14781 uint8_t BuildAndSendRrcDeliveryReport(uint32_t gnbCuUeF1apId, \
14782    uint32_t gnbDuUeF1apId, RrcDeliveryReport *rrcDelivery)
14783 {
14784    uint8_t             ret = RFAILED;
14785    uint8_t             idx    = 0;
14786    uint8_t             idx1   = 0;
14787    uint8_t             elementCnt = 0;
14788    F1AP_PDU_t          *f1apMsg = NULLP;
14789    asn_enc_rval_t      encRetVal;  
14790    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
14791
14792    do{
14793
14794       DU_LOG("\nINFO   -->  F1AP : Building RRC delivery Message Transfer Message\n");
14795       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14796       if(f1apMsg == NULLP)
14797       {
14798          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14799          break;
14800       }
14801       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
14802       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
14803       if(f1apMsg->choice.initiatingMessage == NULLP)
14804       {
14805          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU  failed");
14806          break;
14807       }
14808       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_RRCDeliveryReport;
14809       f1apMsg->choice.initiatingMessage->criticality   = Criticality_ignore;
14810       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_RRCDeliveryReport;
14811
14812       rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
14813       elementCnt = 4;
14814       rrcDeliveryReport->protocolIEs.list.count = elementCnt;
14815       rrcDeliveryReport->protocolIEs.list.size = elementCnt * sizeof(RRCDeliveryReportIEs_t *);
14816
14817       /* Initialize the F1Setup members */
14818       DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array, rrcDeliveryReport->protocolIEs.list.size);
14819       if(rrcDeliveryReport->protocolIEs.list.array == NULLP)
14820       {
14821          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRC Delivery  failed");
14822          break;
14823       }
14824       for(idx =0 ;idx <elementCnt; idx++)
14825       {
14826          DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array[idx], sizeof(RRCDeliveryReportIEs_t));
14827          if(rrcDeliveryReport->protocolIEs.list.array[idx] == NULLP)
14828          {
14829             break;
14830          }
14831       }
14832
14833       idx1 = 0;
14834
14835       /*GNB CU UE F1AP ID*/
14836       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
14837       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
14838       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_CU_UE_F1AP_ID;
14839       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
14840
14841       /*GNB DU UE F1AP ID*/
14842       idx1++;
14843       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14844       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
14845       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_DU_UE_F1AP_ID;
14846       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
14847
14848       /*RRC delivery status*/
14849       idx1++;
14850       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_RRCDeliveryStatus;
14851       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
14852       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_RRCDeliveryStatus;
14853       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.delivery_status =\
14854       rrcDelivery->rrcDeliveryStatus.deliveryStatus;
14855       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.triggering_message =\
14856       rrcDelivery->rrcDeliveryStatus.triggeringMessage;
14857
14858       /* SRB ID */ 
14859       idx1++;
14860       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
14861       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
14862       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_SRBID;
14863       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.SRBID =  rrcDelivery->srbId;
14864
14865       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14866
14867       /* Encode the RRC DELIVERY REPORT type as APER */
14868       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14869       encBufSize = 0;
14870       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14871             encBuf);
14872
14873       /* Encode results */
14874       if(encRetVal.encoded == ENCODE_FAIL)
14875       {
14876          DU_LOG("\nERROR  -->  F1AP : Could not encode RRC Delivery Msg structure (at %s)\n",\
14877                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14878          break;
14879       }
14880       else
14881       {
14882          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for RRC Delivery Msg \n");
14883          for(idx=0; idx< encBufSize; idx++)
14884          {
14885             printf("%x",encBuf[idx]);
14886          }
14887       }
14888
14889       /* Sending msg */
14890       if(sendF1APMsg() != ROK)
14891       {
14892          DU_LOG("\nERROR  -->  F1AP : Sending RRC delivery  msg request failed");
14893          break;
14894       }
14895       ret = ROK;
14896       break;
14897
14898    }while(true);
14899
14900    freeRrcDeliveryReport(f1apMsg);
14901    return ret;
14902 }
14903
14904 /*******************************************************************
14905  *
14906  * @brief Processes cells to be activated
14907  *
14908  * @details
14909  *
14910  *    Function : extractCellsToBeActivated
14911  *
14912  *    Functionality:
14913  *      - Processes cells to be activated list received in F1SetupRsp
14914  *
14915  * @params[in] void
14916  * @return ROK     - success
14917  *         RFAILED - failure
14918  *
14919  * ****************************************************************/
14920
14921 uint8_t extractCellsToBeActivated(Cells_to_be_Activated_List_t cellsToActivate)
14922 {
14923    uint8_t  ret = ROK;
14924    uint16_t idx, pci = 0;
14925    uint64_t nci;
14926    Cells_to_be_Activated_List_Item_t cell;
14927
14928    for(idx=0; idx<cellsToActivate.list.count; idx++)
14929    {
14930       nci = 0;
14931       cell = cellsToActivate.list.array[idx]->value.choice.Cells_to_be_Activated_List_Item;
14932       bitStringToInt(&cell.nRCGI.nRCellIdentity, &nci);
14933
14934       if(cell.nRPCI)
14935       {
14936          pci = *cell.nRPCI;
14937       }
14938       ret = duProcCellsToBeActivated(cell.nRCGI.pLMN_Identity.buf, nci, pci);
14939    }
14940    return ret;
14941 }
14942 /******************************************************************
14943 *
14944 * @brief Processes F1 Setup Response allocated by aper_decoder 
14945 *
14946 * @details
14947 *
14948 *    Function : freeF1SetupRsp 
14949 *
14950 *    Functionality: free F1 Setup Response allocated by aper_decoder 
14951 *
14952 * @params[in] F1SetupResponse_t *f1SetRspMsg 
14953 * @return void 
14954 *
14955 * ****************************************************************/
14956
14957 void freeAperDecodeF1SetupRsp(F1SetupResponse_t *f1SetRspMsg)
14958 {
14959    uint8_t ieIdx =0;
14960    uint8_t arrIdx =0;
14961    Cells_to_be_Activated_List_t *cellToActivate =NULLP;
14962    RRC_Version_t      *rrcVer =NULLP;
14963
14964    if(f1SetRspMsg->protocolIEs.list.array)
14965    {
14966       for(ieIdx=0; ieIdx<f1SetRspMsg->protocolIEs.list.count; ieIdx++)
14967       {
14968          if(f1SetRspMsg->protocolIEs.list.array[ieIdx])
14969          {
14970             switch(f1SetRspMsg->protocolIEs.list.array[ieIdx]->id)
14971             {
14972                case ProtocolIE_ID_id_Cells_to_be_Activated_List:
14973                   {
14974                      cellToActivate =
14975                         &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.Cells_to_be_Activated_List;
14976                      if(cellToActivate->list.array)
14977                      {
14978                         for(arrIdx=0; arrIdx<cellToActivate->list.count ; arrIdx++)
14979                         {
14980                            if(cellToActivate->list.array[arrIdx])
14981                            {
14982
14983                               if(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.nRCGI.\
14984                               pLMN_Identity.buf)
14985                               {
14986                                  if(cellToActivate->list.array[0]->value.choice.\
14987                                        Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf)
14988                                  {
14989                                     free(cellToActivate->list.array[0]->value.choice.\
14990                                           Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf);
14991                                  }
14992
14993                                  free(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
14994                                        nRCGI.pLMN_Identity.buf);
14995                               }
14996                               free(cellToActivate->list.array[arrIdx]);
14997                            }
14998                         }
14999                         free(cellToActivate->list.array);
15000                      }
15001                      break;
15002                   }
15003                case ProtocolIE_ID_id_TransactionID:
15004                   {
15005                      break;
15006                   }
15007                case ProtocolIE_ID_id_gNB_CU_Name:
15008                   {
15009                      free(f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_Name.buf);
15010                      break;
15011                   }
15012                case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15013                   {
15014                      rrcVer = &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
15015                      if(rrcVer->latest_RRC_Version.buf)
15016                      {
15017                         if(rrcVer->iE_Extensions)
15018                         {
15019                            if(rrcVer->iE_Extensions->list.array)
15020                            {
15021                               if(rrcVer->iE_Extensions->list.array[0])
15022                               {
15023                                  if(rrcVer->iE_Extensions->list.\
15024                                        array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf)
15025                                  {
15026                                     free(rrcVer->iE_Extensions->list.\
15027                                           array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf);
15028                                  }
15029                                  free(rrcVer->iE_Extensions->list.array[0]);
15030                               }
15031                               free(rrcVer->iE_Extensions->list.array);
15032                            }
15033                            free(rrcVer->iE_Extensions);
15034                         }
15035                         free(rrcVer->latest_RRC_Version.buf);
15036                      }
15037                      break;
15038
15039                   }
15040                default:
15041                   {
15042                      DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15043                            f1SetRspMsg->protocolIEs.list.array[ieIdx]->id);
15044                   }
15045             }
15046             free(f1SetRspMsg->protocolIEs.list.array[ieIdx]);
15047          }
15048       }
15049       free(f1SetRspMsg->protocolIEs.list.array);
15050    }
15051 }
15052 /******************************************************************
15053  *
15054  * @brief Processes F1 Setup Response sent by CU
15055  *
15056  * @details
15057  *
15058  *    Function : procF1SetupRsp
15059  *
15060  *    Functionality: Processes F1 Setup Response sent by CU
15061  *
15062  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15063  * @return ROK     - success
15064  *         RFAILED - failure
15065  *
15066  * ****************************************************************/
15067 uint8_t procF1SetupRsp(F1AP_PDU_t *f1apMsg, MsgLen recvBufLen, char *recvBuf)
15068 {
15069    uint8_t ret = ROK;
15070    uint16_t idx =0;
15071    F1SetupResponse_t *f1SetRspMsg = NULLP;
15072    GNB_CU_Name_t     *cuName = NULLP;
15073    F1SetupRsp  f1SetRspDb;
15074    RRC_Version_t      *rrcVer =NULLP;
15075    
15076    memset(&f1SetRspDb, 0, sizeof(F1SetupRsp));
15077
15078    DU_LOG("\nINFO   -->  F1AP : F1 Setup Response received");
15079    f1SetRspMsg = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
15080
15081    for(idx=0; idx<f1SetRspMsg->protocolIEs.list.count; idx++)
15082    {
15083       switch(f1SetRspMsg->protocolIEs.list.array[idx]->id)
15084       {
15085          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15086             {
15087                extractCellsToBeActivated(f1SetRspMsg->protocolIEs.list.array[idx]->\
15088                      value.choice.Cells_to_be_Activated_List);
15089                break;
15090             }
15091          case ProtocolIE_ID_id_TransactionID:
15092             {
15093                f1SetRspDb.transId = f1SetRspMsg->protocolIEs.list.array[idx]->\
15094                                     value.choice.TransactionID;
15095                break;
15096             }
15097          case ProtocolIE_ID_id_gNB_CU_Name:
15098             {
15099                cuName = &f1SetRspMsg->protocolIEs.list.array[idx]->\
15100                         value.choice.GNB_CU_Name;
15101                strcpy(f1SetRspDb.cuName, (const char*)cuName->buf);
15102                break;
15103             }
15104          case ProtocolIE_ID_id_GNB_CU_RRC_Version:
15105             {
15106                rrcVer = &f1SetRspMsg->protocolIEs.list.array[idx]->value.choice.RRC_Version;
15107                strcpy(f1SetRspDb.rrcVersion.rrcVer,
15108                      (const char*)rrcVer->latest_RRC_Version.buf);
15109                break;
15110             }
15111          default:
15112             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
15113                   f1SetRspMsg->protocolIEs.list.array[idx]->id);
15114       }
15115       duProcF1SetupRsp();
15116    }
15117    
15118    freeAperDecodeF1SetupRsp(f1SetRspMsg);
15119
15120    duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize = recvBufLen;
15121    DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize);
15122    if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
15123    {
15124       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the buf of F1setup response");
15125       return RFAILED;
15126    }
15127    memcpy(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, recvBuf, recvBufLen);
15128    
15129    if(BuildAndSendE2SetupReq() != ROK)
15130    {
15131       DU_LOG("\nERROR  -->  F1AP : Failed to build and send E2 setup request ");
15132       return RFAILED;
15133    }
15134    return ret;
15135 }
15136 /*******************************************************************
15137 *
15138 * @brief free GNB DU config update ack
15139 *
15140 * @details
15141 *
15142 *    Function : freeAperDecodeGnbDuAck 
15143 *
15144 *    Functionality: Processes GNB DU config update ack And
15145 *                     added free part for the memory allocated by aper_decoder
15146 *
15147 * @params[in] F1AP_PDU_t ASN decoded F1AP message
15148 * @return ROK     - success
15149 *         RFAILED - failure
15150 *
15151 * ****************************************************************/
15152
15153 void freeAperDecodeGnbDuAck(GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck)
15154 {
15155    uint8_t ieIdx = 0;
15156
15157    if(gnbDuAck->protocolIEs.list.array)
15158    {
15159       for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15160       {
15161          if(gnbDuAck->protocolIEs.list.array[ieIdx])
15162          {
15163             free(gnbDuAck->protocolIEs.list.array[ieIdx]);
15164          }
15165       }
15166       free(gnbDuAck->protocolIEs.list.array);
15167    }
15168 }
15169
15170 /*******************************************************************
15171 *
15172 * @brief Building  result of gnb-du config update ack output
15173 *
15174 * @details
15175 *
15176 *    Function : duProcGnbDuCfgUpdAckMsg 
15177 *
15178 *    Functionality: 
15179 *        Building output of gnb-du config update ack 
15180 *
15181 * @params[in] transId
15182 * @return void
15183 *
15184 * ****************************************************************/
15185
15186 uint8_t duProcGnbDuCfgUpdAckMsg(uint8_t transId)
15187 {
15188    uint8_t  ieIdx=0, arrIdx=0,ret=ROK;
15189    uint8_t  ueId =0 , ueIdx =0, totalActiveUe = 0;
15190    uint16_t cellIdx =0, crnti=0;
15191    uint64_t cellId =0;
15192    CmLList *f1apPduNode = NULLP;
15193    ReservedF1apPduInfo *f1apPduInfo =NULLP;
15194    F1AP_PDU_t *f1apMsgPdu = NULLP;
15195    GNBDUConfigurationUpdate_t *gnbDuConfigUpdate = NULLP;
15196    BIT_STRING_t *cellIdentity=NULLP;
15197    struct Served_Cells_To_Delete_ItemIEs *deleteItemIe=NULLP;
15198    Served_Cells_To_Delete_List_t *cellsToDelete=NULLP;
15199    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
15200
15201    DU_LOG("\nINFO   -->  DU APP: GNB-DU config update Ack received ");
15202    f1apPduNode = searchFromReservedF1apPduList(transId);
15203    f1apPduInfo = (ReservedF1apPduInfo *)f1apPduNode->node;
15204    f1apMsgPdu = (F1AP_PDU_t *)f1apPduInfo->f1apMsg;
15205
15206    if(f1apMsgPdu)
15207    {
15208       if(f1apMsgPdu->choice.initiatingMessage)
15209       {
15210          gnbDuConfigUpdate = &f1apMsgPdu->choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
15211          for(ieIdx=0; ieIdx < gnbDuConfigUpdate->protocolIEs.list.count; ieIdx++)
15212          {
15213             switch(gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->id)
15214             {
15215                case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
15216                   {
15217                      cellsToDelete = &gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
15218                                      Served_Cells_To_Delete_List;
15219                      if(cellsToDelete->list.array)
15220                      {
15221                         if(cellsToDelete->list.array[arrIdx])
15222                         {
15223                            deleteItemIe = (Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx];
15224                            deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
15225                            if(deleteItem->oldNRCGI.nRCellIdentity.buf)
15226                            {
15227                               cellIdentity = &deleteItem->oldNRCGI.nRCellIdentity;
15228                               bitStringToInt(cellIdentity, &cellId);
15229
15230                               GET_CELL_IDX(cellId, cellIdx);
15231                               if(duCb.actvCellLst[cellIdx] != NULLP)
15232                               {
15233                                  duCb.actvCellLst[cellId-1]->cellStatus = DELETION_IN_PROGRESS;
15234                               }
15235                            }
15236                         }
15237                      }
15238
15239                      if(duCb.actvCellLst[cellIdx] != NULLP)
15240                      {
15241                         if(duCb.actvCellLst[cellIdx]->numActvUes == 0)
15242                         {
15243                            ret = duSendCellDeletReq(cellId);
15244                            if(ret == RFAILED)
15245                            {
15246                               DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to send cell delete\
15247                               request for cellId[%lu]", cellId);
15248                            }
15249                         }
15250                         else
15251                         {
15252                            totalActiveUe = duCb.actvCellLst[cellIdx]->numActvUes;
15253                            while(totalActiveUe)
15254                            {
15255                               if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState != UE_ACTIVE)
15256                               {
15257                                  ueIdx++;
15258                                  continue;
15259                               }
15260
15261                               crnti = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti;
15262                               GET_UE_ID(crnti,ueId);
15263                               /* Sending Ue Context release request only for maximum supporting UEs */
15264                               ret = BuildAndSendUeContextReleaseReq(cellId, ueId);
15265                               if(ret == RFAILED)
15266                               {
15267                                  DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to build and send UE delete\
15268                                  request for cellId[%lu]", cellId);
15269                               }
15270                               ueIdx++;
15271                               totalActiveUe--;
15272                            }
15273                         }
15274                      }
15275                      else
15276                      {
15277                         DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): CellId [%lu] not found", cellId);
15278                         ret = RFAILED;
15279                      }
15280                      break;
15281                   }
15282
15283                default:
15284                   break;
15285             }
15286          }
15287       }
15288    }
15289    
15290    FreeDUConfigUpdate(f1apMsgPdu);
15291    deleteFromReservedF1apPduList(f1apPduNode);
15292    return ret;
15293 }
15294
15295 /*******************************************************************
15296 *
15297 * @brief Processes GNB DU config update ack
15298 *
15299 * @details
15300 *
15301 *    Function : procF1GNBDUCfgUpdAck
15302 *
15303 *    Functionality: added free part for the memory allocated by aper_decoder
15304 *
15305 * @params[in] F1AP_PDU_t *f1apMsg 
15306 * @return void 
15307 *
15308 * ****************************************************************/
15309 uint8_t procF1GNBDUCfgUpdAck(F1AP_PDU_t *f1apMsg)
15310 {
15311    uint8_t ieIdx=0,transId=0;
15312    GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck = NULLP;
15313
15314    DU_LOG("\nINFO   -->  F1AP : GNB-DU config update acknowledgment");
15315    gnbDuAck = &f1apMsg->choice.successfulOutcome->value.choice.GNBDUConfigurationUpdateAcknowledge;
15316
15317    for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
15318    {
15319       switch(gnbDuAck->protocolIEs.list.array[ieIdx]->id)
15320       {
15321          case ProtocolIE_ID_id_TransactionID:
15322             {
15323                transId = gnbDuAck->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
15324                break;
15325             }
15326          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
15327             {
15328                break;
15329             }
15330          default :
15331             {
15332                DU_LOG("\nERROR  -->  F1AP: procF1GNBDUCfgUpdAck(): Invalid IE Received: %ld", \
15333                      gnbDuAck->protocolIEs.list.array[ieIdx]->id);
15334                break;
15335             }
15336       }
15337    }
15338    
15339    duProcGnbDuCfgUpdAckMsg(transId);
15340     
15341 #if 0
15342    /* presently we are not supporting F1 Reset from DU to CU , we are only
15343     * supporting F1 Reset from CU to DU */
15344
15345    if(BuildAndSendF1ResetReq() != ROK)
15346    {
15347       return RFAILED;
15348    }
15349 #endif
15350
15351    freeAperDecodeGnbDuAck(gnbDuAck);
15352    return ROK;
15353 }
15354 /******************************************************************
15355 *
15356 * @brief free DL RRC Message Transfer allocated by aper_decoder 
15357 *
15358 * @details
15359 *
15360 *    Function : freeAperDecodef1DlRrcMsg 
15361 *
15362 *    Functionality: free DL RRC Message Transfer allocated by aper_decoder 
15363 *
15364 * @params[in] DLRRCMessageTransfer_t *f1DlRrcMsg 
15365 * @return ROK     - success
15366 *         RFAILED - failure
15367 *
15368 * ****************************************************************/
15369
15370 void freeAperDecodef1DlRrcMsg(DLRRCMessageTransfer_t *f1DlRrcMsg)
15371 {
15372    uint8_t ieIdx =0;
15373    RRCContainer_t *rrcContainer = NULLP;
15374
15375    if(f1DlRrcMsg->protocolIEs.list.array)
15376    {
15377       for(ieIdx=0; ieIdx<f1DlRrcMsg->protocolIEs.list.count; ieIdx++)
15378       {
15379          if(f1DlRrcMsg->protocolIEs.list.array[ieIdx])
15380          {
15381             switch(f1DlRrcMsg->protocolIEs.list.array[ieIdx]->id)
15382             {
15383                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15384                   break;
15385                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15386                   break;
15387                case ProtocolIE_ID_id_SRBID:
15388                   break;
15389                case ProtocolIE_ID_id_RRCContainer:
15390                   {
15391                      rrcContainer =&f1DlRrcMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer;
15392                      free(rrcContainer->buf);
15393                   }
15394                case ProtocolIE_ID_id_ExecuteDuplication:
15395                   break;
15396                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15397                   break;
15398                   break;
15399             }
15400             free(f1DlRrcMsg->protocolIEs.list.array[ieIdx]);
15401          }
15402       }
15403       free(f1DlRrcMsg->protocolIEs.list.array);
15404    }
15405 }
15406 /******************************************************************
15407  *
15408  * @brief Processes DL RRC Message Transfer  sent by CU
15409  *
15410  * @details
15411  *
15412  *    Function : procF1DlRrcMsgTrans
15413  *
15414  *    Functionality: Processes DL RRC Message Transfer sent by CU
15415  *
15416  * @params[in] F1AP_PDU_t ASN decoded F1AP message
15417  * @return ROK     - success
15418  *         RFAILED - failure
15419  *
15420  * ****************************************************************/
15421 uint8_t procF1DlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
15422 {
15423    uint8_t  idx, ret;
15424    DLRRCMessageTransfer_t *f1DlRrcMsg = NULLP;
15425    F1DlRrcMsg dlMsg;
15426    memset(&dlMsg, 0, sizeof(F1DlRrcMsg));
15427
15428    DU_LOG("\nINFO   -->  DU_APP : DL RRC message transfer Recevied");
15429    f1DlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
15430
15431    ret = ROK;
15432
15433    for(idx=0; idx<f1DlRrcMsg->protocolIEs.list.count; idx++)
15434    {
15435       switch(f1DlRrcMsg->protocolIEs.list.array[idx]->id)
15436       {
15437          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15438             {
15439                dlMsg.gnbCuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
15440                break;
15441             }
15442          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15443             {
15444                dlMsg.gnbDuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
15445                break;
15446             }
15447          case ProtocolIE_ID_id_SRBID:
15448             {
15449                dlMsg.srbId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
15450                break;
15451             }
15452          case ProtocolIE_ID_id_ExecuteDuplication:
15453             dlMsg.execDup = true;
15454             break;
15455
15456          case ProtocolIE_ID_id_RRCContainer:
15457             {
15458                if(f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
15459                {
15460                   dlMsg.rrcMsgSize = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
15461                   DU_ALLOC_SHRABL_BUF(dlMsg.rrcMsgPdu, dlMsg.rrcMsgSize);
15462                   if(dlMsg.rrcMsgPdu)
15463                   {
15464                      memcpy(dlMsg.rrcMsgPdu, f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf,\
15465                         dlMsg.rrcMsgSize);
15466                   }
15467                   else
15468                   {
15469                      DU_LOG("\nERROR  -->  DU APP : Memory alloc Failed at RRC Container at procF1DlRrcMsgTrans()");
15470                      return RFAILED;
15471                   }
15472                }
15473                else
15474                {
15475                   DU_LOG("\nERROR  -->  DU_APP : RRC Container Size is invalid:%ld",\
15476                   f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
15477                   return RFAILED;
15478                }
15479                break;
15480             }
15481          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15482             {
15483                dlMsg.deliveryStatRpt = true;
15484                break;
15485             }
15486          default:
15487             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
15488                   f1DlRrcMsg->protocolIEs.list.array[idx]->id);
15489       }
15490    }
15491
15492    ret = duProcDlRrcMsg(&dlMsg);
15493
15494    freeAperDecodef1DlRrcMsg(f1DlRrcMsg);
15495    return ret;
15496 }
15497 /*******************************************************************
15498  *
15499 * @brief Builds the DRB to be Setup Mod list
15500 *
15501 * @details
15502 *
15503 *    Function : 
15504 *
15505 *    Functionality: Constructs the DRB to be Setup Mod list
15506 *
15507 * @params[in] DRBs_SetupMod_List_t *drbSet
15508 *
15509 * @return ROK     - success
15510 *         RFAILED - failure
15511 *
15512 * ****************************************************************/
15513 uint8_t BuildSrbSetupModList(SRBs_SetupMod_List_t *srbList, DuUeCfg *ueCfg)
15514 {
15515    uint8_t srbIdx = 0;
15516    struct SRBs_SetupMod_ItemIEs *srbItemIe;
15517
15518    srbList->list.count = ueCfg->numRlcLcs;
15519    srbList->list.size = srbList->list.count * sizeof(SRBs_SetupMod_ItemIEs_t *);
15520
15521    DU_ALLOC(srbList->list.array, srbList->list.size);
15522    if(srbList->list.array == NULLP)
15523    {
15524       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15525       return RFAILED;
15526    }
15527
15528    for(srbIdx = 0; srbIdx < srbList->list.count; srbIdx++)
15529    {
15530       DU_ALLOC(srbList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15531       if(srbList->list.array[srbIdx] == NULLP)
15532       {
15533          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15534          return RFAILED;
15535       }
15536    } 
15537
15538    for(srbIdx=0; srbIdx < srbList->list.count; srbIdx++)
15539    {
15540       srbItemIe = (struct SRBs_SetupMod_ItemIEs *)srbList->list.array[srbIdx];
15541       srbItemIe->id = ProtocolIE_ID_id_SRBs_SetupMod_Item;
15542       srbItemIe->criticality = Criticality_reject;
15543       srbItemIe->value.present = SRBs_SetupMod_ItemIEs__value_PR_SRBs_SetupMod_Item;
15544       srbItemIe->value.choice.SRBs_SetupMod_Item.sRBID = ueCfg->rlcLcCfg[srbIdx].rbId;
15545       srbItemIe->value.choice.SRBs_SetupMod_Item.lCID = ueCfg->rlcLcCfg[srbIdx].lcId;
15546    }
15547    return ROK;
15548 }
15549
15550 /*******************************************************************
15551  *
15552 * @brief Builds the DRB to be Setup Mod list
15553 *
15554 * @details
15555 *
15556 *    Function : 
15557 *
15558 *    Functionality: Constructs the DRB to be Setup Mod list
15559 *
15560 * @params[in] DRBs_SetupMod_List_t *drbSet
15561 *
15562 * @return ROK     - success
15563 *         RFAILED - failure
15564 *
15565 * ****************************************************************/
15566
15567 uint8_t BuildDrbSetupModList(DRBs_SetupMod_List_t *drbSet , DuUeCfg *ueCfg)
15568 {
15569    uint8_t arrIdx =0;
15570    uint8_t drbCnt =0;
15571    struct DRBs_SetupMod_ItemIEs *drbItemIe;
15572
15573    drbCnt = ueCfg->numDrbSetupMod;
15574
15575    if(!drbCnt)
15576    {
15577       DU_LOG("\nINFO  -->  F1AP : BuildDrbToBeSetupModList(): No DRB information to avaialble to add");
15578       return ROK;
15579    }
15580
15581    drbSet->list.count = drbCnt;
15582    drbSet->list.size = drbCnt * sizeof(DRBs_SetupMod_ItemIEs_t *);
15583    DU_ALLOC(drbSet->list.array, drbSet->list.size);
15584    if(drbSet->list.array == NULLP)
15585    {
15586       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
15587       return  RFAILED;
15588    }
15589    for(arrIdx=0; arrIdx<drbCnt; arrIdx++)
15590    {
15591       DU_ALLOC(drbSet->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
15592       if(drbSet->list.array[arrIdx] == NULLP)
15593       {
15594               DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
15595               return  RFAILED;
15596       }
15597
15598       drbItemIe = (struct DRBs_SetupMod_ItemIEs *)drbSet->list.array[arrIdx];
15599       drbItemIe->id = ProtocolIE_ID_id_DRBs_SetupMod_Item;
15600       drbItemIe->criticality = Criticality_reject;
15601       drbItemIe->value.present = DRBs_SetupMod_ItemIEs__value_PR_DRBs_SetupMod_Item;
15602       drbItemIe->value.choice.DRBs_SetupMod_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
15603       if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List,\
15604       &ueCfg->upTnlInfo[arrIdx])!= ROK)
15605       {
15606          DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbToBeSetupModList");
15607          return RFAILED;
15608       }
15609       
15610    }
15611
15612    return ROK;
15613 }
15614 /*******************************************************************
15615 * @brief Free the memory allocated for DRB setup List
15616 *
15617 * @details
15618 *
15619 *    Function : FreeDrbSetupModList 
15620 *
15621 *    Functionality:
15622 *       Free the memory allocated for DRB setup list
15623 *
15624 * @params[in] DRBs_Setup_List_t *
15625 * @return void
15626 *
15627 * ****************************************************************/
15628 void FreeDrbSetupModList(DRBs_SetupMod_List_t *drbSetupList)
15629 {
15630    uint8_t arrIdx = 0;
15631    DRBs_SetupMod_ItemIEs_t *drbItemIe = NULLP;
15632
15633    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
15634    {
15635       drbItemIe = ((DRBs_SetupMod_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
15636       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List);
15637       DU_FREE(drbSetupList->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
15638    }
15639    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
15640 }
15641
15642 /*******************************************************************
15643 * @brief Free the memory allocated for SRB setup List
15644 *
15645 * @details
15646 *
15647 *    Function : FreeSrbSetupModList 
15648 *
15649 *    Functionality:
15650 *       Free the memory allocated for SRB setup list
15651 *
15652 * @params[in] SRBs_Setup_List_t *
15653 * @return void
15654 *
15655 * ****************************************************************/
15656 void FreeSrbSetupModList(SRBs_SetupMod_List_t *srbSetupList)
15657 {
15658    uint8_t srbIdx = 0;
15659    
15660    for(srbIdx = 0; srbIdx < srbSetupList->list.count; srbIdx++)
15661       DU_FREE(srbSetupList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15662    DU_FREE(srbSetupList->list.array, srbSetupList->list.size);
15663 }
15664
15665 /*******************************************************************
15666 * @brief Free the memory allocated for UE Context Mod Response
15667 *
15668 * @details
15669 *
15670 *    Function : FreeUeContextModResp 
15671 *
15672 *    Functionality:
15673 *       Free the memory allocated for UE Context Mod Response
15674 *
15675 * @params[in] F1AP_PDU_t *f1apMsg
15676 * @return void
15677 *
15678 * ****************************************************************/
15679
15680 void FreeUeContextModResp(F1AP_PDU_t *f1apMsg)
15681 {
15682    uint8_t ieIdx;
15683    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
15684    if(f1apMsg)
15685    {
15686       if(f1apMsg->choice.successfulOutcome)
15687       {
15688          ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
15689          if(ueContextModifyRes->protocolIEs.list.array)
15690          {
15691             for(ieIdx=0 ; ieIdx<ueContextModifyRes->protocolIEs.list.count; ieIdx++)
15692             {
15693                if(ueContextModifyRes->protocolIEs.list.array[ieIdx])
15694                {
15695                   switch(ueContextModifyRes->protocolIEs.list.array[ieIdx]->id)
15696                   {
15697                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15698                         break;
15699                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15700                         break;
15701                      case ProtocolIE_ID_id_DRBs_SetupMod_List:
15702                         {
15703                             FreeDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
15704                             value.choice.DRBs_SetupMod_List));
15705                             break;
15706                         }
15707                      case ProtocolIE_ID_id_SRBs_SetupMod_List:
15708                         {
15709                            FreeSrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
15710                               SRBs_SetupMod_List));
15711                            break; 
15712                         }
15713                   }
15714                   DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
15715                }
15716
15717             }
15718             DU_FREE(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
15719          }
15720          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
15721       }
15722       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
15723    }
15724 }
15725
15726 /*****************************************************************i
15727 *
15728 * @brief Creating the ue context modifcation response and sending
15729 *
15730 * @details
15731 *
15732 *    Function : BuildAndSendUeContextModRsp 
15733 *
15734 *    Functionality:
15735 *         - Creating the ue context modifcation response 
15736 *
15737 * @params[in] uint8_t cellId,uint8_t ueId
15738 * @return ROK     - success
15739 *         RFAILED - failure
15740 *
15741 * ****************************************************************/
15742 uint8_t BuildAndSendUeContextModRsp(DuUeCb *ueCb)
15743 {
15744    uint8_t   ieIdx = 0, tnlIdx = 0, rbIdx = 0;
15745    uint8_t   elementCnt = 0;
15746    uint8_t   ret = RFAILED;
15747    F1AP_PDU_t *f1apMsg = NULLP;
15748    asn_enc_rval_t  encRetVal;
15749    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
15750
15751    DU_LOG("\nINFO  -->  F1AP : Building UE context modification response\n");
15752
15753    while(true)
15754    {
15755       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15756       if(f1apMsg == NULLP)
15757       {
15758          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
15759          break;
15760       }
15761
15762       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
15763
15764       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
15765       if(f1apMsg->choice.successfulOutcome == NULLP)
15766       {
15767          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
15768          break;
15769       }
15770       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextModification;
15771       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
15772       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_UEContextModificationResponse;
15773
15774       ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
15775   
15776       if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
15777       {
15778          if(ueCb->f1UeDb->duUeCfg.numDrbSetupMod)
15779             elementCnt =3;
15780          else
15781             elementCnt =2;
15782       }
15783       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15784          elementCnt = 5;
15785       if(ueCb->f1UeDb->actionType == UE_CTXT_RRC_RECFG_COMPLETE)
15786          elementCnt = 2;
15787       ueContextModifyRes->protocolIEs.list.count = elementCnt;
15788       ueContextModifyRes->protocolIEs.list.size = elementCnt*sizeof(UEContextModificationResponse_t*);
15789
15790       /* Initialize the UE context modification members */
15791       DU_ALLOC(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
15792       if(ueContextModifyRes->protocolIEs.list.array == NULLP)
15793       {
15794          DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
15795          break;
15796       }
15797
15798       for(ieIdx=0 ; ieIdx<elementCnt; ieIdx++)
15799       {
15800          DU_ALLOC(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
15801          if(ueContextModifyRes->protocolIEs.list.array[ieIdx] == NULLP)
15802          {
15803             DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
15804             break;
15805          }
15806       }
15807
15808       ieIdx=0;
15809       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
15810       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15811       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
15812       UEContextModificationResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
15813       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
15814
15815       ieIdx++;
15816       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
15817       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15818       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present=\
15819       UEContextModificationResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
15820       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
15821
15822       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15823       {
15824          ieIdx++;
15825          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCInformation;
15826          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15827          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
15828          UEContextModificationResponseIEs__value_PR_DUtoCURRCInformation;
15829          BuildCellGroupConfigRrc(ueCb, &ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
15830       }
15831
15832       if((ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY) || ((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbSetupMod)))
15833       { 
15834          ieIdx++;
15835          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_SetupMod_List;
15836          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15837          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
15838                                                                            UEContextModificationResponseIEs__value_PR_DRBs_SetupMod_List;
15839          if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15840          {
15841             for(tnlIdx = 0; tnlIdx < duCb.numTeId; tnlIdx++)
15842             {
15843                if(duCb.upTnlCfg[tnlIdx]->ueId == ueCb->gnbDuUeF1apId)
15844                {
15845                   memcpy(&ueCb->f1UeDb->duUeCfg.upTnlInfo[ueCb->f1UeDb->duUeCfg.numDrbSetupMod++], duCb.upTnlCfg[tnlIdx], sizeof(UpTnlCfg));
15846                }
15847             }
15848          }
15849          ret = BuildDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
15850                   value.choice.DRBs_SetupMod_List) , &ueCb->f1UeDb->duUeCfg);
15851          if(ret != ROK)
15852          {
15853             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB setupmod List ");
15854             break;
15855          }
15856       }
15857
15858       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15859       {
15860          ieIdx++;
15861          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_SRBs_SetupMod_List;
15862          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15863          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
15864                                                                             UEContextModificationResponseIEs__value_PR_SRBs_SetupMod_List;
15865          for(rbIdx = 0; rbIdx < ueCb->rlcUeCfg.numLcs; rbIdx++)
15866          {
15867             if(ueCb->rlcUeCfg.rlcLcCfg[rbIdx].rbType == RB_TYPE_SRB)
15868             {
15869                memcpy(&ueCb->f1UeDb->duUeCfg.rlcLcCfg[ueCb->f1UeDb->duUeCfg.numRlcLcs++], &ueCb->rlcUeCfg.rlcLcCfg[rbIdx],\
15870                      sizeof(RlcBearerCfg));
15871             }
15872          }
15873          ret = BuildSrbSetupModList(&ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.SRBs_SetupMod_List, \
15874                &ueCb->f1UeDb->duUeCfg);
15875          if(ret != ROK)
15876          {
15877             DU_LOG( "\nERROR  -->  F1AP : Failed to build SRB setupmod List ");
15878             break;
15879          }
15880       }
15881
15882       freeF1UeDb(ueCb->f1UeDb);
15883       ueCb->f1UeDb = NULLP;
15884
15885       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15886
15887       /* Encode the F1SetupRequest type as APER */
15888       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15889       encBufSize = 0;
15890       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,encBuf);
15891
15892       /* Encode results */
15893       if(encRetVal.encoded == ENCODE_FAIL)
15894       {
15895          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Request structure (at %s)\n",\
15896                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15897          ret = RFAILED;
15898          break;
15899       }
15900       else
15901       {
15902          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Modification Response\n");
15903          for(int i=0; i< encBufSize; i++)
15904          {
15905             printf("%x",encBuf[i]);
15906          }
15907       }
15908
15909       /* Sending  msg  */
15910       if(sendF1APMsg() != ROK)
15911       {
15912          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Res Failed");
15913          ret = RFAILED;
15914          break;
15915       }
15916
15917       ret = ROK;
15918       break;
15919    }
15920    FreeUeContextModResp(f1apMsg);
15921    return ret;
15922 }
15923 /*******************************************************************
15924  *
15925  * @brief Deallocating the memory allocated by the aper decoder
15926  *          for QOSInfo
15927  *
15928  * @details
15929  *
15930  *    Function : freeAperDecodeQosInfo
15931  *
15932  *    Functionality:  Deallocating the memory allocated for QOSInfo
15933  *
15934  * @params[in] QoSFlowLevelQoSParameters_t *drbQos
15935  *
15936  * @return void
15937  *
15938  * ****************************************************************/
15939
15940 void freeAperDecodeQosInfo(QoSFlowLevelQoSParameters_t *drbQos)
15941 {
15942    if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI != NULLP)
15943    {
15944       if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
15945       {
15946          if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
15947          {
15948             free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
15949          }
15950          free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
15951       }
15952       free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI);
15953    }
15954 }
15955 /*******************************************************************
15956  *
15957  * @brief Deallocating the memory allocated by the aper decoder
15958  *          for UlTnlInfoforDrb
15959  *
15960  * @details
15961  *
15962  *    Function : freeAperDecodeUlTnlInfoforDrbSetupMod 
15963  *
15964  *    Functionality:  Deallocating memory allocated for UlTnlInfoforDrb
15965  *
15966  * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
15967  *
15968  * @return void
15969  *
15970  * ****************************************************************/
15971 void freeAperDecodeUlTnlInfoforDrbSetupMod(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
15972 {
15973    uint8_t arrIdx =0;
15974
15975    if(ulInfo->list.array)
15976    {
15977       for(arrIdx=0; arrIdx<ulInfo->list.count ; arrIdx++)
15978       {
15979          if(ulInfo->list.array[arrIdx])
15980          {
15981             if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel )
15982             {
15983                if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf)
15984                {
15985                   if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf)
15986                   {
15987                      free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
15988                            gTP_TEID.buf);
15989                   }
15990                   free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
15991                         transportLayerAddress.buf);
15992                }
15993                free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel);
15994             }
15995             free(ulInfo->list.array[arrIdx]);
15996          }
15997       }
15998       free(ulInfo->list.array);
15999    }
16000 }
16001 /*******************************************************************
16002  *
16003  * @brief Deallocating the memory allocated by the aper decoder
16004  *          for DrbSetupModItem  
16005  *
16006  * @details
16007  *
16008  *    Function : freeAperDecodeDrbSetupModItem 
16009  *
16010  *    Functionality:  Deallocating memory allocated for DrbSetupModItem
16011  *
16012  * @params[in] DRBs_ToBeSetupMod_Item_t *drbItem
16013  *
16014  * @return void
16015  *
16016  * ****************************************************************/
16017
16018 void freeAperDecodeDrbSetupModItem(DRBs_ToBeSetupMod_Item_t *drbItem)
16019 {
16020    uint8_t arrIdx =0;
16021    SNSSAI_t *snssai =NULLP;
16022    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
16023
16024    drbItem->qoSInformation.present = QoSInformation_PR_choice_extension;
16025    switch(drbItem->qoSInformation.present)
16026    {
16027       case QoSInformation_PR_NOTHING:
16028          break;
16029       case QoSInformation_PR_eUTRANQoS:
16030          {
16031             if(drbItem->qoSInformation.choice.eUTRANQoS)
16032             {
16033                free(drbItem->qoSInformation.choice.eUTRANQoS);
16034             }
16035             break;
16036          }
16037       case QoSInformation_PR_choice_extension:
16038          {
16039             if(drbItem->qoSInformation.choice.choice_extension)
16040             {
16041                freeAperDecodeQosInfo(&drbItem->qoSInformation.choice.choice_extension->value.choice.\
16042                      DRB_Information.dRB_QoS);
16043                snssai = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI;
16044                if(snssai->sST.buf)
16045                {
16046                   free(snssai->sST.buf);
16047                }
16048                if(snssai->sD)
16049                {
16050                   if(snssai->sD->buf)
16051                   {
16052                      free(snssai->sD->buf);
16053                   }
16054                   free(snssai->sD);
16055                }
16056
16057                flowMap = &drbItem->qoSInformation.choice.choice_extension->value.choice.\
16058                          DRB_Information.flows_Mapped_To_DRB_List;
16059                if(flowMap->list.array)
16060                {
16061                   for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
16062                   {
16063                      if(flowMap->list.array[arrIdx] )
16064                      {
16065                         freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
16066                         free(flowMap->list.array[arrIdx]);
16067                      }
16068                   }
16069                   free(flowMap->list.array);
16070                }
16071
16072                free(drbItem->qoSInformation.choice.choice_extension);
16073             }
16074             break;
16075          }
16076
16077    }
16078    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
16079    if(drbItem->uLConfiguration)
16080    {
16081       free(drbItem->uLConfiguration);
16082    }
16083 }
16084
16085 /*******************************************************************
16086  *
16087  * @brief Deallocating the memory allocated by the aper decoder
16088  *          for DrbToBeSetupModList
16089  *
16090  * @details
16091  *
16092  *    Function : freeAperDecodeDrbToBeSetupModList
16093  *
16094  *    Functionality:  Deallocating memory allocated for DrbToBeSetupModList
16095  *
16096  * @params[in] DRBs_ToBeSetupMod_List_t *drbSet
16097  *
16098  * @return void
16099  *
16100  * ****************************************************************/
16101
16102 void freeAperDecodeDrbToBeSetupModList(DRBs_ToBeSetupMod_List_t *drbSet)
16103 {
16104    uint8_t arrIdx =0;
16105    struct DRBs_ToBeSetupMod_ItemIEs *drbItemIe;
16106
16107    if(drbSet->list.array)
16108    {
16109       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
16110       {
16111          if(drbSet->list.array[arrIdx] != NULLP)
16112          {
16113             if(arrIdx == 0)
16114             {
16115                drbItemIe = (DRBs_ToBeSetupMod_ItemIEs_t *)drbSet->list.array[arrIdx];
16116                freeAperDecodeDrbSetupModItem(&(drbItemIe->value.choice.DRBs_ToBeSetupMod_Item));
16117             }
16118             free(drbSet->list.array[arrIdx]);
16119          }
16120       }
16121       free(drbSet->list.array);
16122    }
16123
16124 }
16125 /*******************************************************************
16126  *
16127  * @brief Deallocating the memory allocated by the aper decoder
16128  *          for UeContextModificationReqMsg
16129  *
16130  * @details
16131  *
16132  *    Function : freeAperDecodeUeContextModificationReqMsg
16133  *
16134  *    Functionality:  Deallocating memory allocated for
16135  *                  UeContextModificationReqMsg
16136  *
16137  * @params[in] UEContextModificationRequest_t *UeContextModifyReq
16138  *
16139  * @return void
16140  *
16141  * ****************************************************************/
16142 void freeAperDecodeUeContextModificationReqMsg(UEContextModificationRequest_t *ueContextModifyReq )
16143 {
16144    uint8_t arrIdx, ieId;
16145
16146    if(ueContextModifyReq->protocolIEs.list.array)
16147    {
16148       for( arrIdx = 0 ; arrIdx<ueContextModifyReq->protocolIEs.list.count ; arrIdx++)
16149       {
16150          if(ueContextModifyReq->protocolIEs.list.array[arrIdx])
16151          {
16152             ieId = ueContextModifyReq->protocolIEs.list.array[arrIdx]->id;
16153             switch(ieId)
16154             {
16155                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16156                   break;
16157                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16158                   break;
16159                case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
16160                   {
16161                      freeAperDecodeDrbToBeSetupModList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
16162                            value.choice.DRBs_ToBeSetupMod_List);
16163                      break;
16164                   }
16165                case ProtocolIE_ID_id_TransmissionActionIndicator:
16166                   break;
16167                case ProtocolIE_ID_id_RRCContainer:
16168                   {
16169                      free(ueContextModifyReq->protocolIEs.list.array[arrIdx]->value.choice.RRCContainer.buf);
16170                   }
16171             }
16172             free(ueContextModifyReq->protocolIEs.list.array[arrIdx]);
16173          }
16174       }
16175       free(ueContextModifyReq->protocolIEs.list.array);
16176    }
16177 }
16178 /*******************************************************************
16179  *
16180  * @brief processing the F1 UeContextModificationReq
16181  *
16182  * @details
16183  *
16184  *    Function : procF1UeContextModificationReq
16185  *
16186  *    Functionality:  processing the F1 UeContextModificationReq
16187  *
16188  * @params[in] F1AP_PDU_t *f1apMsg
16189  *
16190  * @return
16191  * ****************************************************************/
16192 uint8_t procF1UeContextModificationReq(F1AP_PDU_t *f1apMsg)
16193 {
16194    UEContextModificationRequest_t *ueContextModifyReq = NULLP;
16195    uint8_t  ret = ROK, ieIdx = 0, cellIdx=0;
16196    DuUeCb   *duUeCb = NULLP;
16197    DRBs_ToBeSetupMod_List_t *drbSetupModCfg;
16198    DRBs_ToBeModified_List_t *drbModifiedCfg;
16199    uint32_t gnbCuUeF1apId, gnbDuUeF1apId;
16200
16201    ueContextModifyReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextModificationRequest;
16202    for(ieIdx=0; (ieIdx < ueContextModifyReq->protocolIEs.list.count && ret == ROK); ieIdx++)
16203    {
16204       switch(ueContextModifyReq->protocolIEs.list.array[ieIdx]->id)
16205       {
16206          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16207             {
16208                gnbCuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
16209                break;
16210             }
16211          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16212             {
16213                gnbDuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
16214                for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
16215                {
16216                   if(duCb.actvCellLst[cellIdx])
16217                   {
16218                      if((duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbDuUeF1apId == gnbDuUeF1apId)&&\
16219                            (duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbCuUeF1apId == gnbCuUeF1apId))
16220                      {
16221                         duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1];
16222                         if(duUeCb->f1UeDb == NULLP)
16223                         {
16224                            DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
16225                            duUeCb->f1UeDb->cellIdx = cellIdx;
16226                            duUeCb->f1UeDb->actionType = UE_CTXT_MOD;
16227                         }
16228                         break;
16229                      }
16230                   }
16231                }
16232                if(duUeCb == NULLP)
16233                {
16234                   DU_LOG("\nERROR  -->  DU APP : wrong values of gnbCuUeF1apId and gnbDuUeF1apId ");
16235                   ret = RFAILED;
16236                }
16237                break;
16238             }
16239
16240          case ProtocolIE_ID_id_RRCContainer:
16241             {
16242                /* Filling Dl RRC Msg Info */
16243                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
16244                if(!duUeCb->f1UeDb->dlRrcMsg)
16245                {
16246                   DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16247                         Memory allocation failed ");
16248                   ret = RFAILED;
16249                }
16250                else
16251                {
16252                   duUeCb->f1UeDb->dlRrcMsgPres = true;
16253                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
16254                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
16255                         &ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
16256                         value.choice.RRCContainer);
16257                }
16258
16259                break;
16260             }
16261
16262          case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
16263          case ProtocolIE_ID_id_DRBs_ToBeModified_List:
16264             {
16265                if(duUeCb->f1UeDb)
16266                {
16267                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present ==\
16268                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List)
16269                   {
16270                      drbSetupModCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
16271                                       choice.DRBs_ToBeSetupMod_List;
16272
16273                      if(extractDrbListToSetupMod(NULL, drbSetupModCfg, NULL, drbSetupModCfg->list.count,\
16274                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULL))
16275                      {
16276                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbSetupModList");
16277                         ret = RFAILED;
16278                      }
16279                   }
16280
16281                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
16282                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List)
16283
16284                   {
16285                      drbModifiedCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
16286                                       choice.DRBs_ToBeModified_List;
16287                      if(extractDrbListToSetupMod(NULL, NULL, drbModifiedCfg, drbModifiedCfg->list.count,\
16288                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, &duUeCb->rlcUeCfg))
16289                      {
16290                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
16291                         ret = RFAILED;
16292                      }
16293                   }
16294                }
16295                break;
16296             }
16297
16298          case ProtocolIE_ID_id_GNB_DUConfigurationQuery:
16299             {
16300                DU_LOG("\nINFO  -->  DU APP : Received GNB DU Configuration Query in UE Context Modification Request from CU");
16301                if(duUeCb->f1UeDb)
16302                {
16303                   duUeCb->f1UeDb->actionType = UE_CTXT_CFG_QUERY;
16304                }
16305                break;
16306             }
16307
16308          case ProtocolIE_ID_id_RRCReconfigurationCompleteIndicator:
16309             {
16310                if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.RRCReconfigurationCompleteIndicator == \
16311                   RRCReconfigurationCompleteIndicator_true)
16312                {
16313                   duUeCb->f1UeDb->actionType = UE_CTXT_RRC_RECFG_COMPLETE;
16314                }
16315                break;
16316             }
16317          case ProtocolIE_ID_id_TransmissionActionIndicator:
16318             {
16319                if(duUeCb->f1UeDb)
16320                {
16321                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.TransmissionActionIndicator  == TransmissionActionIndicator_stop)
16322                   {
16323                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = STOP_TRANSMISSION; 
16324                   }
16325                   else 
16326                   {
16327                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = RESTART_TRANSMISSION; 
16328                   }
16329                }
16330                break;
16331             }
16332
16333          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
16334             {
16335                if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
16336                {
16337                   duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
16338                }
16339                break;
16340             }
16341               
16342       }
16343    }
16344
16345    if(ret != RFAILED) 
16346    {
16347       ret = duProcUeContextModReq(duUeCb);
16348    }
16349    freeAperDecodeUeContextModificationReqMsg(ueContextModifyReq);
16350    return ret; 
16351 }
16352
16353 /*****************************************************************i
16354 *
16355 * @brief Free memory allocated for UE Context Release Request
16356 *
16357 * @details
16358 *
16359 *    Function : FreeUeContextReleaseReq
16360 *
16361 *    Functionality:
16362 *         - Free memory allocated for UE Context Release Request
16363 *
16364 * @params[in] F1AP_PDU_t *f1apMsg
16365 * @return void 
16366 *
16367 * *************************************************************/
16368 void FreeUeContextReleaseReq(F1AP_PDU_t *f1apMsg)
16369 {
16370    uint8_t ieIdx;
16371    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
16372    
16373    if(f1apMsg)
16374    {
16375       if(f1apMsg->choice.initiatingMessage)
16376       {
16377          ueReleaseReq =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
16378          if(ueReleaseReq->protocolIEs.list.array)
16379          {
16380             for(ieIdx=0 ; ieIdx<ueReleaseReq->protocolIEs.list.count; ieIdx++)
16381             {
16382                DU_FREE(ueReleaseReq->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseRequest_t));
16383             }
16384             DU_FREE(ueReleaseReq->protocolIEs.list.array, ueReleaseReq->protocolIEs.list.size);
16385          }
16386          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
16387       }
16388       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
16389    }
16390
16391 }
16392 /*****************************************************************i
16393 *
16394 * @brief Build and Send UE Context Release Request  
16395 *
16396 * @details
16397 *
16398 *    Function : BuildAndSendUeContextReleaseReq
16399 *
16400 *    Functionality:
16401 *         - Build and Send UE Context Release Request 
16402 *
16403 * @params[in]
16404 * @return ROK     - success
16405 *         RFAILED - failure
16406 *
16407 * *************************************************************/
16408 uint8_t BuildAndSendUeContextReleaseReq(uint16_t cellId, uint8_t ueId)
16409 {
16410    bool memAllocFail = false;
16411    uint8_t ieIdx =0;
16412    uint8_t ret = RFAILED;
16413    uint16_t cellIdx =0;
16414    uint16_t crnti = 0;
16415    uint8_t  elementCnt = 0;
16416    uint32_t  gnbCuUeF1apId =0;   /* gNB-CU UE F1AP Id */
16417    uint32_t  gnbDuUeF1apId =0;   /* gNB-DU UE F1AP Id */
16418    asn_enc_rval_t encRetVal; 
16419    F1AP_PDU_t *f1apMsg = NULLP;
16420    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
16421
16422    DU_LOG("\nINFO  --> Building the UE Context Release Request");
16423    do
16424    {
16425       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
16426       if(f1apMsg == NULLP)
16427       {
16428          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for f1apMsg");
16429          break;
16430       }
16431
16432       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
16433       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
16434       if(f1apMsg->choice.initiatingMessage == NULLP)
16435       {
16436          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for\
16437          initiatingMessage");   
16438          break;
16439       }
16440       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_UEContextReleaseRequest;
16441       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
16442       f1apMsg->choice.initiatingMessage->value.present = \
16443       InitiatingMessage__value_PR_UEContextReleaseRequest;
16444
16445       ueReleaseReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
16446
16447       elementCnt = 2;
16448
16449       ueReleaseReq->protocolIEs.list.count = elementCnt;
16450       ueReleaseReq->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseRequest_t *);
16451
16452       /* Initialize the F1Setup members */
16453       DU_ALLOC(ueReleaseReq->protocolIEs.list.array,ueReleaseReq->protocolIEs.list.size);
16454       if(ueReleaseReq->protocolIEs.list.array == NULLP)
16455       {
16456          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE array");
16457          break;
16458       }
16459       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
16460       {
16461          DU_ALLOC(ueReleaseReq->protocolIEs.list.array[ieIdx],\
16462                sizeof(UEContextReleaseRequest_t));
16463          if(ueReleaseReq->protocolIEs.list.array[ieIdx] == NULLP)
16464          {
16465             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE elements");
16466             memAllocFail = true;  
16467             break;
16468          }
16469       }
16470       if(memAllocFail == true)
16471          break;
16472
16473       /* Fetching Ue Cb Info*/
16474       GET_CELL_IDX(cellId, cellIdx);
16475       if(duCb.actvCellLst[cellIdx] == NULLP)
16476       {
16477          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): CellId[%d] does not exist", cellId);
16478          break;
16479       }
16480       else
16481       {
16482          GET_CRNTI(crnti, ueId);
16483          if(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].crnti != crnti)
16484          {
16485             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): crnti[%d] does not exist", crnti);
16486             break;
16487          }
16488          gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
16489          gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
16490       }
16491
16492       ieIdx=0; 
16493       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID; 
16494       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16495       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present = \
16496       UEContextReleaseRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
16497       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
16498       
16499       ieIdx++;
16500       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16501       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16502       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present =\
16503       UEContextReleaseRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
16504       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
16505       
16506       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16507
16508       /* Encode the F1SetupRequest type as APER */
16509       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16510       encBufSize = 0;
16511       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
16512       /* Encode results */
16513       if(encRetVal.encoded == ENCODE_FAIL)
16514       {
16515          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseRequest structure (at %s)\n",\
16516                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16517          break;
16518       }
16519       else
16520       {
16521          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseRequest\n");
16522          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
16523          {
16524             printf("%x",encBuf[ieIdx]);
16525          }
16526       }
16527
16528       /* Sending msg */
16529       if(sendF1APMsg() != ROK)
16530       {
16531          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Request failed");
16532          break;
16533       }
16534       ret = ROK;
16535       break;
16536    }while(true);
16537
16538    FreeUeContextReleaseReq(f1apMsg);
16539    return ret;
16540 }
16541 /*****************************************************************i
16542  *
16543  * @brief Free memory allocated for UE Context Release Complete
16544  *
16545  * @details
16546  *
16547  *    Function : FreeUeContextReleaseComplete
16548  *
16549  *    Functionality:
16550  *         - Free memory allocated for UE Context Release Complete
16551  *
16552  * @params[in] F1AP_PDU_t *f1apMsg
16553  * @return void
16554  *
16555  * *************************************************************/
16556 void FreeUeContextReleaseComplete(F1AP_PDU_t *f1apMsg)
16557 {
16558    uint8_t ieIdx;
16559    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
16560
16561    if(f1apMsg)
16562    {
16563       if(f1apMsg->choice.successfulOutcome)
16564       {
16565          ueReleaseComplete =&f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
16566          if(ueReleaseComplete->protocolIEs.list.array)
16567          {
16568             for(ieIdx=0 ; ieIdx<ueReleaseComplete->protocolIEs.list.count; ieIdx++)
16569             {
16570                DU_FREE(ueReleaseComplete->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseComplete_t));
16571             }
16572             DU_FREE(ueReleaseComplete->protocolIEs.list.array, ueReleaseComplete->protocolIEs.list.size);
16573          }
16574          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16575       }
16576       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
16577    }
16578
16579 }
16580 /*****************************************************************i
16581  *
16582  * @brief Build and Send UE Context Release Complete
16583  *
16584  * @details
16585  *
16586  *    Function : BuildAndSendUeContextReleaseComplete
16587  *
16588  *    Functionality:
16589  *         - Build and Send UE Context Release Complete
16590  *
16591  * @params[in]  cellId,  gnbCuUeF1apId, gnbDuUeF1apId
16592  * @return ROK     - success
16593  *         RFAILED - failure
16594  *
16595  * *************************************************************/
16596 uint8_t BuildAndSendUeContextReleaseComplete(uint16_t cellId, uint32_t gnbCuUeF1apId, uint32_t gnbDuUeF1apId)
16597 {
16598    bool memAllocFail = false;
16599    uint8_t ieIdx =0, ret = RFAILED, elementCnt = 0;
16600    asn_enc_rval_t encRetVal;
16601    F1AP_PDU_t *f1apMsg = NULLP;
16602    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
16603
16604    DU_LOG("\nINFO  --> Building the UE Context Release Complete");
16605    do
16606    {
16607       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
16608       if(f1apMsg == NULLP)
16609       {
16610          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for f1apMsg");
16611          break;
16612       }
16613
16614       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
16615       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16616       if(f1apMsg->choice.successfulOutcome == NULLP)
16617       {
16618          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for\
16619                successfulOutcome");
16620          break;
16621       }
16622       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextRelease;
16623       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
16624       f1apMsg->choice.successfulOutcome->value.present = \
16625       SuccessfulOutcome__value_PR_UEContextReleaseComplete;
16626
16627       ueReleaseComplete = &f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
16628
16629       elementCnt = 2;
16630       ueReleaseComplete->protocolIEs.list.count = elementCnt;
16631       ueReleaseComplete->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseComplete_t *);
16632
16633       /* Initialize the UE Release Complete members */
16634       DU_ALLOC(ueReleaseComplete->protocolIEs.list.array,ueReleaseComplete->protocolIEs.list.size);
16635       if(ueReleaseComplete->protocolIEs.list.array == NULLP)
16636       {
16637          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE array");
16638          break;
16639       }
16640       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
16641       {
16642          DU_ALLOC(ueReleaseComplete->protocolIEs.list.array[ieIdx],\
16643                sizeof(UEContextReleaseComplete_t));
16644          if(ueReleaseComplete->protocolIEs.list.array[ieIdx] == NULLP)
16645          {
16646             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE\
16647             elements");
16648             memAllocFail = true;
16649             break;
16650          }
16651       }
16652       if(memAllocFail == true)
16653          break;
16654
16655
16656       ieIdx=0;
16657       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
16658       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16659       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present = \
16660       UEContextReleaseCompleteIEs__value_PR_GNB_CU_UE_F1AP_ID;
16661       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
16662
16663       ieIdx++;
16664       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16665       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16666       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present =\
16667       UEContextReleaseCompleteIEs__value_PR_GNB_DU_UE_F1AP_ID;
16668       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
16669
16670       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16671
16672       /* Encode the F1SetupComplete type as APER */
16673       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16674       encBufSize = 0;
16675       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
16676       /* Encode results */
16677       if(encRetVal.encoded == ENCODE_FAIL)
16678       {
16679          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseComplete structure (at %s)\n",\
16680                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16681          break;
16682       }
16683       else
16684       {
16685          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseComplete\n");
16686          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
16687          {
16688             printf("%x",encBuf[ieIdx]);
16689          }
16690       }
16691
16692       /* Sending msg */
16693       if(sendF1APMsg() != ROK)
16694       {
16695          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Complete failed");
16696          break;
16697       }
16698       ret = ROK;
16699       break;
16700    }while(true);
16701    
16702    if((ret == ROK) && (duCb.actvCellLst[cellId-1]) && (duCb.actvCellLst[cellId-1]->cellStatus == DELETION_IN_PROGRESS) 
16703          && (duCb.actvCellLst[cellId-1]->numActvUes == 0))
16704    {
16705       ret = duSendCellDeletReq(cellId);
16706       if(ret != ROK)
16707       {
16708          DU_LOG("\nERROR  -->  F1AP: BuildAndSendUeContextReleaseComplete(): Failed to process cell\
16709                Delete req for CellId");
16710       }
16711    }
16712    FreeUeContextReleaseComplete(f1apMsg);
16713    return ret;
16714
16715 }
16716
16717 /*******************************************************************
16718 *
16719 * @brief added free part for the memory allocated by aper_decoder 
16720 *
16721 * @details
16722 *
16723 *    Function : freeAperDecodeUeContextReleaseCommand 
16724 *
16725 *    Functionality: added free part for the memory allocated by aper_decoder
16726 *
16727 * @params[in] F1AP_PDU_t *f1apMsg
16728 * @return void
16729 *
16730 * ****************************************************************/
16731 void freeAperDecodeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
16732 {
16733    uint8_t ieIdx=0;
16734    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
16735
16736    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
16737    
16738    if(ueContextReleaseCommand->protocolIEs.list.array)
16739    {
16740       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
16741       {
16742          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
16743          {
16744             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
16745             {
16746                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16747                   break;
16748                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16749                   break;
16750                case ProtocolIE_ID_id_Cause:
16751                   break;
16752                case ProtocolIE_ID_id_RRCContainer:
16753                {
16754                   if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
16755                   {
16756                      free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
16757                   }
16758                   break;
16759                }
16760                default :
16761                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
16762                        ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
16763                   break;
16764             }
16765          }
16766          free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]);
16767       }
16768       free(ueContextReleaseCommand->protocolIEs.list.array);
16769    }
16770 }
16771 /*******************************************************************
16772 *
16773 * @brief processing of UE Context Release Command
16774 *
16775 * @details
16776 *
16777 *    Function : procF1UeContextReleaseCommand 
16778 *
16779 *    Functionality: processing of UE Context Release Command
16780 *
16781 * @params[in] F1AP_PDU_t *f1apMsg
16782 * @return void
16783 *
16784 * ****************************************************************/
16785 uint8_t procF1UeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
16786 {
16787    uint8_t  ieIdx=0, ret=ROK, ueIdx=0;
16788    uint16_t cellIdx =0, cellId = 0;
16789    bool ueIdxFound = false;
16790    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0;
16791    DuUeCb   *duUeCb = NULLP;
16792    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
16793
16794    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
16795
16796    if(ueContextReleaseCommand->protocolIEs.list.array)
16797    {
16798       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
16799       {
16800          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
16801          {
16802             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
16803             {
16804                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16805                   {
16806                      gnbCuUeF1apId= ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
16807                                     value.choice.GNB_CU_UE_F1AP_ID;
16808                      break;
16809                   }
16810
16811                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16812                   {
16813                      gnbDuUeF1apId = ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
16814                                      value.choice.GNB_DU_UE_F1AP_ID;
16815                      break;
16816                   }
16817
16818                case ProtocolIE_ID_id_Cause:
16819                   {
16820                      for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
16821                      {
16822                         for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
16823                         {
16824                            if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
16825                                  (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId))
16826                            {
16827                               cellId = duCb.actvCellLst[cellIdx]->cellId;
16828                               duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
16829                               ueIdxFound = true;
16830                               break;
16831                            }
16832                         }
16833                         if(ueIdxFound == true)
16834                         {
16835                            break;
16836                         }
16837                      }
16838                      
16839                      if(!ueIdxFound)
16840                      {
16841                         DU_LOG("\nERROR  -->  F1AP: procF1UeContextReleaseCommand(): Ue Information is not available");
16842                         ret = RFAILED;
16843                      }
16844                      break;
16845                   }
16846
16847                case ProtocolIE_ID_id_RRCContainer:
16848                   {
16849                      if(ueIdxFound == true)  
16850                      {
16851                         DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
16852                         if(duUeCb->f1UeDb)
16853                         {
16854                            memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
16855                            duUeCb->f1UeDb->actionType = UE_CTXT_RELEASE;
16856                            duUeCb->f1UeDb->cellIdx = cellIdx;
16857                            /* Filling Dl RRC Msg Info */
16858                            DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
16859                            if(!duUeCb->f1UeDb->dlRrcMsg)
16860                            {
16861                               DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16862                                     Memory allocation failed ");
16863                               ret = RFAILED;
16864                            }
16865                            else
16866                            {
16867                               duUeCb->f1UeDb->dlRrcMsgPres = true;
16868                               memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
16869                               ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
16870                                     &ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
16871                                     value.choice.RRCContainer);
16872                            }
16873
16874                         }
16875                         else
16876                         {
16877                            DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16878                                  Memory allocation failed ");
16879                            ret = RFAILED;
16880
16881                         }
16882                      }
16883                      break;
16884                   }
16885                default :
16886                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
16887                         ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
16888                   break;
16889             }
16890          }
16891       }
16892    }
16893    if(ret != RFAILED)
16894    {
16895       duProcUeContextReleaseCommand(cellId, duUeCb);
16896    }
16897    freeAperDecodeUeContextReleaseCommand(f1apMsg);
16898    return ret;
16899 }
16900
16901 /**************************************************************
16902  *
16903  * @brief free the memory allocated by aper decoder for paging
16904  *
16905  * @details
16906  *
16907  *    Function : freeAperDecodePagingMsg
16908  *
16909  *    Functionality:
16910  *         - free the memory allocated by aper decoder for
16911  *         the paging f1ap msg
16912  *
16913  * @params[in] Paging_t   *paging
16914  * @return ROK     - success
16915  *         RFAILED - failure
16916  *
16917  ****************************************************************/
16918 void freeAperDecodePagingMsg(Paging_t   *paging)
16919 {
16920    uint8_t ieIdx, cellIdx;
16921    PagingCell_ItemIEs_t *pagingCellItemIes;
16922    PagingCell_Item_t *pagingCellItem;
16923    PagingCell_list_t  *pagingCelllist;
16924
16925    if(paging)
16926    {
16927       if(paging->protocolIEs.list.array)
16928       {
16929          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
16930          {
16931             if(paging->protocolIEs.list.array[ieIdx])
16932             {
16933                switch(paging->protocolIEs.list.array[ieIdx]->id)
16934                {
16935                   case ProtocolIE_ID_id_UEIdentityIndexValue:
16936                      {
16937                         free(paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10.buf);
16938                         break;
16939                      }
16940                   case ProtocolIE_ID_id_PagingIdentity:
16941                      {
16942                         if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present == PagingIdentity_PR_cNUEPagingIdentity)
16943                         {
16944                            if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)
16945                            {
16946                               if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->present == \
16947                                     CNUEPagingIdentity_PR_fiveG_S_TMSI)
16948                               {
16949                                  free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->choice.fiveG_S_TMSI.buf);
16950                               }
16951                               free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity);
16952                            }
16953                         }
16954                         break;
16955                      }
16956                   case ProtocolIE_ID_id_PagingCell_List:
16957                      {
16958                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list;
16959                         if(pagingCelllist->list.array)
16960                         {
16961                            for(cellIdx = 0; cellIdx < pagingCelllist->list.count; cellIdx++)
16962                            {
16963                               if(pagingCelllist->list.array[cellIdx])
16964                               {
16965                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellIdx];
16966                                  if(pagingCellItemIes->id == ProtocolIE_ID_id_PagingCell_Item)
16967                                  {
16968                                     pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
16969                                     free(pagingCellItem->nRCGI.pLMN_Identity.buf);
16970                                     free(pagingCellItem->nRCGI.nRCellIdentity.buf);
16971                                  }
16972                                  free(pagingCelllist->list.array[cellIdx]);
16973                               }
16974                            }
16975                            free(pagingCelllist->list.array);
16976                         }
16977                         break;
16978                      }
16979                }
16980                free(paging->protocolIEs.list.array[ieIdx]);
16981             }
16982          }
16983          free(paging->protocolIEs.list.array);
16984
16985       }
16986    }
16987 }
16988
16989 /**************************************************************
16990  *
16991  * @brief processing the paging f1ap msg received from CU 
16992  *
16993  * @details
16994  *
16995  *    Function : procPagingMsg
16996  *
16997  *    Functionality:
16998  *         - processing the paging f1ap msg received from CU
16999  *
17000  * @params[in] F1AP_PDU_t *f1apMsg
17001  * @return ROK     - success
17002  *         RFAILED - failure
17003  *
17004  *
17005  ****************************************************************/
17006 uint8_t procPagingMsg(F1AP_PDU_t *f1apMsg) 
17007 {
17008    uint8_t ieIdx = 0, cellListIdx = 0;
17009    uint64_t cellId = 0;
17010    Paging_t   *paging = NULLP;
17011    PagingCell_list_t  *pagingCelllist = NULLP;
17012    PagingCell_ItemIEs_t *pagingCellItemIes = NULLP;
17013    PagingCell_Item_t *pagingCellItem = NULLP;
17014    DuPagingMsg *tmpPagingParam = NULLP;
17015
17016    paging = &f1apMsg->choice.initiatingMessage->value.choice.Paging;
17017    if(paging)
17018    {
17019       if(paging->protocolIEs.list.array)
17020       {
17021          DU_ALLOC(tmpPagingParam, sizeof(DuPagingMsg));
17022          if(tmpPagingParam == NULLP)
17023          {
17024             DU_LOG("\nERROR  --> DU APP : Memory Allocation Failure in procPagingMsg");
17025             freeAperDecodePagingMsg(paging);
17026             return RFAILED;
17027          }
17028          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
17029          {
17030             if(paging->protocolIEs.list.array[ieIdx])
17031             {
17032                switch(paging->protocolIEs.list.array[ieIdx]->id)
17033                {
17034                   case ProtocolIE_ID_id_UEIdentityIndexValue:
17035                      {
17036                         bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10,\
17037                                          &tmpPagingParam->pagUeId);
17038                         break;
17039                      }
17040
17041                   case ProtocolIE_ID_id_PagingIdentity:
17042                      {
17043                         switch(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present)
17044                         {
17045                            case PagingIdentity_PR_cNUEPagingIdentity: 
17046                               {
17047                                  if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)  
17048                                  {
17049                                     bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.\
17050                                           cNUEPagingIdentity->choice.fiveG_S_TMSI, &tmpPagingParam->sTmsi);
17051
17052                                  }
17053                                  break;
17054                               }
17055                             case PagingIdentity_PR_rANUEPagingIdentity:
17056                                {
17057                                   /*TODO: This Identifier is specific to RAN Initiated Paging â€“ Connected Mode Paging*/
17058                                   break;
17059                                }
17060                             default:
17061                                {
17062                                   DU_LOG("ERROR  -->  DU APP: Invalid UE Paging Identity, Skipping this Paging Message:");
17063                                   continue;
17064                                }
17065                         }
17066                      }
17067
17068                   case ProtocolIE_ID_id_PagingDRX:
17069                      {
17070                         tmpPagingParam->pagingDrxPres = TRUE;
17071                         tmpPagingParam->pagingDrx = convertPagingCycleEnumToValue(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingDRX);
17072                         break;
17073                      }
17074
17075                   case ProtocolIE_ID_id_PagingPriority:
17076                      {
17077                         tmpPagingParam->pagPriority = paging->protocolIEs.list.array[ieIdx]->value.choice.PagingPriority;
17078                         break;
17079                      }
17080
17081                   case ProtocolIE_ID_id_PagingCell_List:
17082                      {
17083                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list; 
17084                         if(pagingCelllist->list.array)
17085                         {
17086                            for(cellListIdx = 0; cellListIdx < pagingCelllist->list.count; cellListIdx++)
17087                            {
17088                               if(pagingCelllist->list.array[cellListIdx])
17089                               {
17090                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellListIdx];
17091                                  pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
17092                                  bitStringToInt(&pagingCellItem->nRCGI.nRCellIdentity, &cellId);
17093                                  if(processPagingMsg(cellId, tmpPagingParam) != ROK)
17094                                  {
17095                                     DU_LOG("\nERROR  --> DU APP : Paging Processing Failed at CellId:%lu",cellId);
17096                                     continue;
17097                                  }
17098                               }
17099                            }
17100                         }
17101                         break;
17102                      }
17103                    default:
17104                      {
17105                          DU_LOG("\nERROR  --> F1AP : Incorrect Paging IE option");
17106                          break;
17107                      }
17108                }
17109             }
17110          }
17111       }
17112    }
17113    DU_FREE(tmpPagingParam, sizeof(DuPagingMsg));
17114    freeAperDecodePagingMsg(paging);
17115   
17116    return ROK;
17117 }
17118
17119 /**************************************************************
17120  *
17121  * @brief Handles received F1AP message and sends back response  
17122  *
17123  * @details
17124  *
17125  *    Function : F1APMsgHdlr
17126  *
17127  *    Functionality:
17128  *         - Decodes received F1AP control message
17129  *         - Prepares response message, encodes and sends to SCTP
17130  *
17131  * @params[in] 
17132  * @return ROK     - success
17133  *         RFAILED - failure
17134  *
17135  * ****************************************************************/
17136 void F1APMsgHdlr(Buffer *mBuf)
17137 {
17138    int i =0;
17139    char *recvBuf =NULLP;
17140    MsgLen copyCnt =0;
17141    MsgLen recvBufLen =0;
17142    F1AP_PDU_t *f1apMsg =NULLP;
17143    asn_dec_rval_t rval; /* Decoder return value */
17144    F1AP_PDU_t f1apasnmsg ;
17145    DU_LOG("\nINFO  -->  F1AP : Received F1AP message buffer");
17146    ODU_PRINT_MSG(mBuf, 0,0);
17147
17148    /* Copy mBuf into char array to decode it */
17149    ODU_GET_MSG_LEN(mBuf, &recvBufLen);
17150    DU_ALLOC(recvBuf, (Size)recvBufLen);
17151
17152    if(recvBuf == NULLP)
17153    {
17154       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed");
17155       return;
17156    }
17157    if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
17158    {
17159       DU_LOG("\nERROR   -->  F1AP : Failed while copying %d", copyCnt);
17160       return;
17161    }
17162
17163    printf("\nDEBUG   -->  F1AP : Received flat buffer to be decoded : ");
17164    for(i=0; i< recvBufLen; i++)
17165    {
17166       printf("%x",recvBuf[i]);
17167    }
17168
17169    /* Decoding flat buffer into F1AP messsage */
17170    f1apMsg = &f1apasnmsg;
17171    memset(f1apMsg, 0, sizeof(F1AP_PDU_t));
17172
17173    rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0);
17174
17175    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
17176    {
17177       DU_LOG("\nERROR  -->  F1AP : ASN decode failed");
17178       return;
17179    }
17180    printf("\n");
17181    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
17182
17183    switch(f1apMsg->present)
17184    {
17185       case F1AP_PDU_PR_successfulOutcome:
17186          {
17187             switch(f1apMsg->choice.successfulOutcome->value.present)
17188             {
17189                case SuccessfulOutcome__value_PR_ResetAcknowledge:
17190                   {
17191                      DU_LOG("\nINFO   -->  F1AP : F1ResetAcknowledge is received successfully ");
17192                      break;
17193                   }
17194                case SuccessfulOutcome__value_PR_F1SetupResponse:
17195                   {                             
17196 #ifndef ODU_TEST_STUB
17197                      procF1SetupRsp(f1apMsg, recvBufLen, recvBuf);
17198 #endif
17199                      break;
17200                   }
17201
17202                case SuccessfulOutcome__value_PR_GNBDUConfigurationUpdateAcknowledge:
17203                   {
17204                      procF1GNBDUCfgUpdAck(f1apMsg);
17205                      break;
17206                   }
17207
17208                default:
17209                   {
17210                      DU_LOG("\nERROR  -->  F1AP : Invalid type of SuccessfulOutcome__value_PR_ResetAcknowledge [%d]",\
17211                            f1apMsg->choice.successfulOutcome->value.present);
17212                      return;
17213                   }
17214             }/* End of switch(successfulOutcome) */
17215             free(f1apMsg->choice.successfulOutcome);
17216             break;
17217          }
17218       case F1AP_PDU_PR_initiatingMessage:
17219          {
17220             switch(f1apMsg->choice.initiatingMessage->value.present)
17221             {
17222                case InitiatingMessage__value_PR_Reset:
17223                   {
17224                      procF1ResetReq(f1apMsg);
17225                      break;
17226                   }
17227                case InitiatingMessage__value_PR_DLRRCMessageTransfer:
17228                   {
17229                      procF1DlRrcMsgTrans(f1apMsg);
17230                      break;
17231                   }
17232                case InitiatingMessage__value_PR_UEContextSetupRequest:
17233                   {
17234                      procF1UeContextSetupReq(f1apMsg);
17235                      break;
17236                   }
17237                case InitiatingMessage__value_PR_UEContextModificationRequest:
17238                   {
17239                      procF1UeContextModificationReq(f1apMsg);
17240                      break;
17241                   }
17242                case InitiatingMessage__value_PR_UEContextReleaseCommand:
17243                   {
17244                       procF1UeContextReleaseCommand(f1apMsg);
17245                       break;
17246                   }
17247                case InitiatingMessage__value_PR_Paging:
17248                   {
17249                      procPagingMsg(f1apMsg);
17250                      break;
17251                   }
17252                default:
17253                   {
17254                      DU_LOG("\nERROR  -->  F1AP : Invalid type of F1AP_PDU_PR_initiatingMessage [%d]",
17255                            f1apMsg->choice.initiatingMessage->value.present);
17256                      return;
17257                   }
17258             }/* End of switch(initiatingMessage) */
17259             free(f1apMsg->choice.initiatingMessage);
17260             break;
17261          }
17262
17263       default:
17264          {
17265             DU_LOG("\nERROR  -->  F1AP : Invalid type of f1apMsg->present [%d]",f1apMsg->present);
17266             return;
17267          }
17268          free(f1apMsg);
17269
17270    }/* End of switch(f1apMsg->present) */
17271    
17272    DU_FREE(recvBuf, (Size)recvBufLen);
17273 } /* End of F1APMsgHdlr */
17274
17275 /**********************************************************************
17276   End of file
17277  **********************************************************************/