[Epic-ID: ODUHIGH-405][Task-ID: ODUHIGH-448]Memory handling fix in HO
[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
129 #ifdef O1_ENABLE
130 #include "CmInterface.h"
131 extern StartupConfig g_cfg;
132 #endif
133
134 DuCfgParams duCfgParam;
135
136 /******************************************************************
137  *
138  * @brief Function to fetch lcId based on DRB Id
139  *
140  * @details
141  *
142  *    Function : fetchLcId
143  *
144  *    @params[in] drbId
145  *
146  *    Functionality: Function to fetch lcId based on DRB Id
147  *
148  * Returns: lcId - SUCCESS
149  *          RFAILED - FAILURE
150  *****************************************************************/
151
152 uint8_t fetchLcId(uint8_t drbId)
153 {
154    uint8_t cellIdx = 0, ueIdx = 0, lcIdx = 0, numLcs = 0, lcId = 0;
155
156    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
157    {
158       for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
159       {
160          if(duCb.actvCellLst[cellIdx] != NULLP)
161          {
162             numLcs = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg.numLcs;
163             for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
164             {
165                if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg.rlcLcCfg[lcIdx].rbId == drbId && \
166                   duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg.rlcLcCfg[lcIdx].rbType == RB_TYPE_DRB)
167                {
168                   lcId = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg.rlcLcCfg[lcIdx].lcId;
169                   return lcId;
170                }
171             }
172          }
173       }
174    }
175    DU_LOG("\nERROR   -->  DU_APP: fetchLcId() failed for drbId %d", drbId);
176    return RFAILED;
177 }
178
179 /*******************************************************************
180 *
181 * @brief Adding F1AP pdu to reserved pdu list
182 *
183 * @details
184 *
185 *    Function : addToReservedF1apPduList 
186 *
187 *    Functionality: Adding F1AP pdu to reserved pdu list.
188 *     These pdu are awaiting aknowledgment from CU
189 *
190 * @params[in] uint8_t transId, F1AP_PDU_t *f1apMsg
191 *
192 * @return ROK - success
193 *         RFAILED - failure
194 *
195 * ****************************************************************/
196 void addToReservedF1apPduList(uint8_t transId, F1AP_PDU_t *f1apPdu)
197 {
198    CmLList         *node = NULLP;
199    ReservedF1apPduInfo *pduInfo = NULLP;
200    DU_ALLOC(pduInfo, sizeof(ReservedF1apPduInfo));
201    if(pduInfo)
202    {
203       DU_ALLOC(node, sizeof(CmLList));
204       if(node)
205       {
206          pduInfo->transId = transId;
207          pduInfo->f1apMsg = (void*) f1apPdu;
208
209          node->node = (PTR)pduInfo;
210          cmLListAdd2Tail(&duCb.reservedF1apPduList, node);
211       }
212    }
213 }
214
215 /*******************************************************************
216 *
217 * @brief searching for F1AP pdu from ReservedF1apPduList 
218 *
219 * @details
220 *
221 *    Function : searchFromReservedF1apPduList 
222 *
223 *    Functionality: searching for F1AP pdu information
224 *
225 * @params[in] uint8_t transId
226 *
227 * @return pointer to F1AP_PDU_t
228 *
229 * ****************************************************************/
230
231 CmLList *searchFromReservedF1apPduList(uint8_t transId)
232 {
233    CmLList         *node;
234    ReservedF1apPduInfo *f1apPdu;
235    if(duCb.reservedF1apPduList.count)
236    {
237       CM_LLIST_FIRST_NODE(&duCb.reservedF1apPduList, node);
238       while(node)
239       {
240          f1apPdu = (ReservedF1apPduInfo*)node->node;
241          if(f1apPdu->transId == transId)
242          {
243             return node;
244          }
245          node = node->next;
246       }
247    }
248    return NULL;
249 }
250
251 /*******************************************************************
252 *
253 * @brief deleting F1AP pdu information from ReservedF1apPduList
254 *
255 * @details
256 *
257 *    Function : deleteFromReservedF1apPduList 
258 *
259 *    Functionality: deleting pdu information from ReservedF1apPduList
260 *
261 * @params[in] CmLList *node 
262 *
263 * @return void 
264 *
265 * ****************************************************************/
266
267 void deleteFromReservedF1apPduList(CmLList *node)
268 {
269    ReservedF1apPduInfo *f1apPdu;
270
271    if(node != NULL)
272    {
273       f1apPdu = (ReservedF1apPduInfo *)node->node;
274       cmLListDelFrm(&duCb.reservedF1apPduList, node);
275       DU_FREE(f1apPdu, sizeof(ReservedF1apPduInfo));
276       DU_FREE(node, sizeof(CmLList));
277       node = NULL;
278    }
279 }
280
281 /*******************************************************************
282  *
283  * @brief Builds Uplink Info for NR 
284  *
285  * @details
286  *
287  *    Function : BuildULNRInfo
288  *
289  *    Functionality: Building NR Uplink Info
290  *
291  * @params[in] NRFreqInfo_t *ulnrfreq
292  * @return ROK     - success
293  *         RFAILED - failure
294  *
295  * ****************************************************************/
296 uint8_t BuildULNRInfo(NRFreqInfo_t *ulnrfreq)
297 {
298    uint8_t idx=0;
299    ulnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
300                        fdd.ulNrFreqInfo.nrArfcn;
301    ulnrfreq->freqBandListNr.list.count = 1;
302    ulnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
303    DU_ALLOC(ulnrfreq->freqBandListNr.list.array,ulnrfreq->freqBandListNr.list.size);
304    if(ulnrfreq->freqBandListNr.list.array == NULLP)
305    {
306       return RFAILED;
307    }
308    for(idx=0;idx<ulnrfreq->freqBandListNr.list.count;idx++)
309    {
310       DU_ALLOC(ulnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
311       if(ulnrfreq->freqBandListNr.list.array[idx] == NULLP)
312       {
313          return RFAILED;
314       }
315    }
316    ulnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
317                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
318                                                                  freqBand[0].nrFreqBand;
319    ulnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
320    return ROK;
321 }
322 /*******************************************************************
323  *
324  * @brief Builds Downlink NR Info 
325  *
326  * @details
327  *
328  *    Function : BuildDLNRInfo
329  *
330  *    Functionality: Building Downlink NR Info
331  *    
332  * @params[in] NRFreqInfo_t *dlnrfreq
333  * @return ROK     - success
334  *         RFAILED - failure
335  *
336  * ****************************************************************/
337 uint8_t BuildDLNRInfo(NRFreqInfo_t *dlnrfreq)
338 {
339    uint8_t idx=0;
340    dlnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
341                        fdd.dlNrFreqInfo.nrArfcn;
342    dlnrfreq->freqBandListNr.list.count = 1;
343    dlnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
344    DU_ALLOC(dlnrfreq->freqBandListNr.list.array,dlnrfreq->freqBandListNr.list.size);
345    if(dlnrfreq->freqBandListNr.list.array == NULLP)
346    {
347       return RFAILED;   
348    }
349    for(idx=0;idx< dlnrfreq->freqBandListNr.list.count;idx++)
350    {
351       DU_ALLOC(dlnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
352       if(dlnrfreq->freqBandListNr.list.array[idx] == NULLP)
353       {
354          return RFAILED;
355       }
356    }   
357    dlnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
358                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
359                                                                  freqBand[0].nrFreqBand;
360    dlnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
361
362    return ROK;
363 }
364
365 /*******************************************************************
366  *
367  * @brief Builds Nrcgi 
368  *
369  * @details
370  *
371  *    Function : BuildNrcgi
372  *
373  *    Functionality: Building the PLMN ID and NR Cell id
374  *
375  * @params[in] NRCGI_t *nrcgi
376  * @return ROK     - success
377  *         RFAILED - failure
378  *
379  * ****************************************************************/
380 uint8_t BuildNrcgi(NRCGI_t *nrcgi)
381 {
382    uint8_t ret;
383    uint8_t byteSize = 5;
384    /* Allocate Buffer Memory */
385    nrcgi->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
386    DU_ALLOC(nrcgi->pLMN_Identity.buf, nrcgi->pLMN_Identity.size);
387    if(nrcgi->pLMN_Identity.buf == NULLP)
388    {
389       return RFAILED;
390    }
391    ret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
392          nrcgi->pLMN_Identity.buf); // Building PLMN function
393    if(ret != ROK)
394    {
395       return RFAILED;
396    }
397    /*nrCellIdentity*/
398    nrcgi->nRCellIdentity.size = byteSize * sizeof(uint8_t);
399    DU_ALLOC(nrcgi->nRCellIdentity.buf, nrcgi->nRCellIdentity.size); 
400    if(nrcgi->nRCellIdentity.buf == NULLP)
401    {
402       return RFAILED;
403    }
404    fillBitString(&nrcgi->nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
405
406    return ROK;
407 }
408 /*******************************************************************
409  *
410  * @brief Builds FiveGStac 
411  *
412  * @details
413  *
414  *    Function : BuildFiveGSTac
415  *
416  *    Functionality: Building the FiveGSTac
417  *
418  * @params[in] OCTET_STRING_t *fivegsTac
419  * @return ROK     - success
420  *         RFAILED - failure
421  *
422  * ****************************************************************/
423 uint8_t BuildFiveGSTac(Served_Cell_Information_t *servcell)
424 {
425    DU_ALLOC(servcell->fiveGS_TAC,sizeof(FiveGS_TAC_t));
426    if(servcell->fiveGS_TAC == NULLP)
427    {
428       return RFAILED;
429    }
430    servcell->fiveGS_TAC->size = 3 * sizeof(uint8_t);
431    DU_ALLOC(servcell->fiveGS_TAC->buf,\
432          sizeof(servcell->fiveGS_TAC->size));
433    if(servcell->fiveGS_TAC->buf == NULLP)
434    {
435       return RFAILED;
436    }
437    servcell->fiveGS_TAC->buf[0] = 0;
438    servcell->fiveGS_TAC->buf[1] = 0;
439    servcell->fiveGS_TAC->buf[2] = duCfgParam.srvdCellLst[0].duCellInfo.tac;
440    return ROK;  
441 }
442
443 /*******************************************************************
444  *
445  * @brief fill nr frequency information
446  *
447  * @details
448  *
449  *    Function : fillNrTddInfo 
450  *
451  *    Functionality: fill nr frequency information
452  *
453  * @params[in] NRFreqInfo_t freqInfo
454  * @return ROK     - success
455  *         RFAILED - failure
456  *
457  * ****************************************************************/
458 uint8_t fillNrTddInfo(TDD_Info_t *tddInfo)
459 {
460    uint8_t elementCnt = 1, freqBandListIdx = 0, supportedBandIdx = 0;
461    NRFreqInfo_t *freqInfo = NULLP;
462
463    if(tddInfo == NULLP)
464    {
465       DU_LOG("\nERROR  --> DU APP : Null pointer received at fillNrTddInfo");
466       return RFAILED;
467    }
468    
469    freqInfo = &tddInfo->nRFreqInfo;
470    freqInfo->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.nrArfcn; 
471
472    freqInfo->freqBandListNr.list.count = elementCnt; 
473    freqInfo->freqBandListNr.list.size = freqInfo->freqBandListNr.list.count  * sizeof(FreqBandNrItem_t *);
474    DU_ALLOC(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
475    if(!freqInfo->freqBandListNr.list.array)
476    {
477       DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
478       return RFAILED;
479    }
480
481    for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
482    {
483       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
484       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx])
485       {
486          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
487          return RFAILED;
488       }
489
490       freqInfo->freqBandListNr.list.array[freqBandListIdx]->freqBandIndicatorNr = duCfgParam.srvdCellLst[0].duCellInfo.\
491       f1Mode.mode.tdd.nrFreqInfo.freqBand[0].nrFreqBand;
492       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count = elementCnt;
493       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size = freqInfo->freqBandListNr.list.array[freqBandListIdx]->\
494       supportedSULBandList.list.count * sizeof(SupportedSULFreqBandItem_t*);
495
496       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
497             freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
498       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
499       {
500          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
501          return RFAILED;
502       }
503
504       for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
505       {
506          DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
507                sizeof(SupportedSULFreqBandItem_t));
508          if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx])
509          {
510             DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
511             return RFAILED;
512          }
513
514          freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx]->freqBandIndicatorNr =\
515          duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[0].sulBand[0];
516       }
517    }
518
519    tddInfo->transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrScs;
520    tddInfo->transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrb;
521
522    return ROK;
523 }
524
525 /*******************************************************************
526  *
527  * @brief Builds NR Mode 
528  *
529  * @details
530  *
531  *    Function : BuildNrMode
532  *
533  *    Functionality: Building the NR Mode
534  *
535  * @params[in] NR_Mode_Info_t *fdd
536  * @return ROK     - success
537  *         RFAILED - failure
538  *
539  * ****************************************************************/
540 uint8_t BuildNrMode(NR_Mode_Info_t *mode)
541 {
542    uint8_t BuildDLNRInforet=0;
543    uint8_t BuildULNRInforet=0; 
544    
545 #ifdef NR_TDD
546    mode->present = NR_Mode_Info_PR_tDD;
547 #else
548    mode->present = NR_Mode_Info_PR_fDD;
549 #endif   
550    
551    if(mode->present == NR_Mode_Info_PR_fDD)
552    {
553       DU_ALLOC(mode->choice.fDD,sizeof(FDD_Info_t));
554       if(mode->choice.fDD == NULLP)
555       {
556          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
557          return RFAILED;
558       }
559       BuildULNRInforet = BuildULNRInfo(&mode->choice.fDD->uL_NRFreqInfo);
560       if(BuildULNRInforet != ROK)
561       {
562          DU_LOG("\nERROR  --> Failed to build UlNrFreqInfo");
563          return RFAILED;    
564       }
565       BuildDLNRInforet = BuildDLNRInfo(&mode->choice.fDD->dL_NRFreqInfo);
566       if(BuildDLNRInforet != ROK)
567       {
568          DU_LOG("\nERROR  --> Failed to build DlNrFreqInfo");
569          return RFAILED;
570       }
571       mode->choice.fDD->uL_Transmission_Bandwidth.nRSCS = \
572                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
573                                                           f1Mode.mode.fdd.ulTxBw.nrScs;
574       mode->choice.fDD->uL_Transmission_Bandwidth.nRNRB = \
575                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
576                                                           f1Mode.mode.fdd.ulTxBw.nrb;
577       mode->choice.fDD->dL_Transmission_Bandwidth.nRSCS = \
578                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
579                                                           f1Mode.mode.fdd.dlTxBw.nrScs;
580       mode->choice.fDD->dL_Transmission_Bandwidth.nRNRB = \
581                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
582                                                           f1Mode.mode.fdd.dlTxBw.nrb;
583    }
584    else if(mode->present == NR_Mode_Info_PR_tDD) 
585    {
586       DU_ALLOC(mode->choice.tDD,sizeof(TDD_Info_t));
587       if(mode->choice.tDD == NULLP)
588       {
589          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
590          return RFAILED;
591       }
592
593       if(fillNrTddInfo(mode->choice.tDD) != ROK)
594       {
595          DU_LOG("\nERROR  --> Failed to fill Nr TDD information");
596          return RFAILED;
597       }
598
599    }
600
601    return ROK;
602 }
603 /*******************************************************************
604  *
605  * @brief Builds IE Extensions for Served PLMNs 
606  *
607  * @details
608  *
609  *    Function : BuildExtensions
610  *
611  *    Functionality: Building the IE Extensions
612  *
613  * @params[in] struct ProtocolExtensionContainer_4624P3 *buildextend
614  * @return ROK     - success
615  *         RFAILED - failure
616  *
617  * ****************************************************************/
618 uint8_t BuildExtensions(ProtocolExtensionContainer_4624P3_t **ieExtend)
619 {
620    uint8_t idx=0, plmnidx=0, sliceLstIdx=0;
621    uint8_t elementCnt=0, extensionCnt=0;
622
623    extensionCnt=IE_EXTENSION_LIST_COUNT;
624    DU_ALLOC(*ieExtend,sizeof(ProtocolExtensionContainer_4624P3_t));
625    if((*ieExtend) == NULLP)
626    {
627       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
628       return RFAILED;
629    }
630    (*ieExtend)->list.count = extensionCnt;
631    (*ieExtend)->list.size = \
632                             extensionCnt * sizeof(ServedPLMNs_ItemExtIEs_t *);
633    DU_ALLOC((*ieExtend)->list.array,(*ieExtend)->list.size);
634    if((*ieExtend)->list.array == NULLP)
635    {
636       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
637       return RFAILED;
638    }
639    for(plmnidx=0;plmnidx<extensionCnt;plmnidx++)
640    {
641       DU_ALLOC((*ieExtend)->list.array[plmnidx],\
642             sizeof(ServedPLMNs_ItemExtIEs_t));
643       if((*ieExtend)->list.array[plmnidx] == NULLP)
644       {
645          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
646          return RFAILED;
647       }
648    }
649    
650    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices;
651    idx = 0;
652    (*ieExtend)->list.array[idx]->id = ProtocolIE_ID_id_TAISliceSupportList;
653    (*ieExtend)->list.array[idx]->criticality = Criticality_ignore;
654    (*ieExtend)->list.array[idx]->extensionValue.present = \
655    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
656    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
657       list.count = elementCnt;
658    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
659       list.size = (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
660       list.count * sizeof(SliceSupportItem_t *);
661
662    DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
663          list.array, elementCnt * sizeof(SliceSupportItem_t *));
664    if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
665          list.array == NULLP)
666    {
667       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
668       return RFAILED;
669    }
670
671    for(sliceLstIdx =0; sliceLstIdx<elementCnt; sliceLstIdx++)
672    {
673       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
674             list.array[sliceLstIdx],sizeof(SliceSupportItem_t));
675       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
676             list.array[sliceLstIdx] == NULLP) 
677       {
678          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
679          return RFAILED;
680       }
681       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
682          list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
683       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
684             .list.array[sliceLstIdx]->sNSSAI.sST.buf,(*ieExtend)->list.array[idx]->\
685             extensionValue.choice.SliceSupportList.\
686             list.array[sliceLstIdx]->sNSSAI.sST.size);
687       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
688             .list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
689       {
690          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
691          return RFAILED;
692       }
693       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
694          list.array[sliceLstIdx]->sNSSAI.sST.buf[0] = duCfgParam.srvdCellLst[0].duCellInfo.\
695          cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
696       
697       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
698             list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
699       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
700             list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
701       {
702          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
703          return RFAILED;
704       }
705       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
706          list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
707       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
708             list.array[sliceLstIdx]->sNSSAI.sD->buf, (*ieExtend)->list.array[idx]->extensionValue.choice.\
709             SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
710       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
711             list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
712       {
713          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
714          return RFAILED;
715       }
716       memcpy((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
717       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[0].duCellInfo.\
718       cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sd, (*ieExtend)->list.array[idx]->\
719       extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
720    }
721    return ROK;
722 }
723 /*******************************************************************
724  *
725  * @brief Builds Served PLMN 
726  *
727  * @details
728  *
729  *    Function : BuildServedPlmn
730  *
731  *    Functionality: Building the Served PLMN
732  *
733  * @params[in] GNB_DU_Served_Cells_Item_t *srvCellItem
734  * @return ROK     - success
735  *         RFAILED - failure
736  *
737  * ****************************************************************/
738 uint8_t  BuildServedPlmn(ServedPLMNs_List_t *srvplmn)
739 {  
740    uint8_t  plmnidx;
741    uint8_t  servPlmnCnt=1;
742    uint8_t buildPlmnIdret=0;
743    uint8_t BuildExtensionsret=0;
744    srvplmn->list.count = servPlmnCnt;
745    srvplmn->list.size = \
746                         servPlmnCnt*sizeof(ServedPLMNs_Item_t *);
747    DU_ALLOC(srvplmn->list.array,srvplmn->list.size);
748    if(srvplmn->list.array == NULLP)
749    {
750       return RFAILED;
751    }
752    for(plmnidx=0; plmnidx<servPlmnCnt; plmnidx++)
753    {   
754       DU_ALLOC(srvplmn->list.array[plmnidx],\
755             sizeof(ServedPLMNs_Item_t));
756       if(srvplmn->list.array[plmnidx] == NULLP)
757       {
758          return RFAILED;
759       }  
760    }
761    srvplmn->list.array[0]->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
762    DU_ALLOC(srvplmn->list.array[0]->pLMN_Identity.buf, srvplmn->list.array[0]->pLMN_Identity.size);
763    buildPlmnIdret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
764          srvplmn->list.array[0]->pLMN_Identity.buf);
765    if(buildPlmnIdret!= ROK)
766    {
767       return RFAILED;
768    }
769    BuildExtensionsret = BuildExtensions(&srvplmn->list.array[0]->iE_Extensions);
770    if(BuildExtensionsret!= ROK)
771    {
772       return RFAILED;
773    }
774    return ROK;
775 }
776 /*******************************************************************
777  *
778  * @brief Builds Served Cell List
779  *
780  * @details
781  *
782  *    Function : BuildServedCellList
783  *
784  *    Functionality: Building Served Cell List
785  *
786  * @params[in] PLMNID plmn
787  * @return ROK     - success
788  *         RFAILED - failure
789  *
790  * ****************************************************************/
791
792 uint8_t BuildServedCellList(GNB_DU_Served_Cells_List_t *duServedCell)
793 {
794    uint8_t  BuildNrcgiret=0;
795    uint8_t  BuildFiveGSTacret=0;
796    uint8_t  BuildServedPlmnret=0;
797    uint8_t  BuildNrModeret=0;
798    uint8_t  idx;
799    uint8_t  plmnidx;
800    uint8_t  plmnCnt=1;
801    GNB_DU_Served_Cells_Item_t *srvCellItem;
802    duServedCell->list.size = plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t *);
803    duServedCell->list.count = plmnCnt;
804
805    DU_ALLOC(duServedCell->list.array, duServedCell->list.size);
806    if(duServedCell->list.array == NULLP)
807    {
808       return RFAILED;
809    }
810    for(plmnidx=0; plmnidx<plmnCnt; plmnidx++)
811    {
812       DU_ALLOC(duServedCell->list.array[plmnidx],\
813             sizeof(GNB_DU_Served_Cells_ItemIEs_t));
814       if(duServedCell->list.array[plmnidx] == NULLP)
815       {
816          return RFAILED;
817       }
818    }
819    idx = 0;
820    duServedCell->list.array[idx]->id = ProtocolIE_ID_id_GNB_DU_Served_Cells_Item;
821    duServedCell->list.array[idx]->criticality = Criticality_reject;
822    duServedCell->list.array[idx]->value.present = \
823                                                   GNB_DU_Served_Cells_ItemIEs__value_PR_GNB_DU_Served_Cells_Item;
824    srvCellItem = \
825                  &duServedCell->list.array[idx]->value.choice.GNB_DU_Served_Cells_Item;
826    /*nRCGI*/
827    BuildNrcgiret = BuildNrcgi(&srvCellItem->served_Cell_Information.nRCGI);
828    if(BuildNrcgiret != ROK)
829    {
830       return RFAILED;
831    }
832    /*nRPCI*/
833    srvCellItem->served_Cell_Information.nRPCI = \
834                                                 duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
835
836    /*fiveGS_TAC*/
837    BuildFiveGSTacret = BuildFiveGSTac(&srvCellItem->served_Cell_Information);
838    if(BuildFiveGSTacret != ROK)
839    {
840       return RFAILED;
841    }
842    /*Served PLMNs*/
843    BuildServedPlmnret = BuildServedPlmn(&srvCellItem->served_Cell_Information.servedPLMNs);
844    if(BuildServedPlmnret !=ROK)
845    {
846       return RFAILED;
847    }
848    /*nR Mode Info with FDD*/
849    BuildNrModeret = BuildNrMode(&srvCellItem->served_Cell_Information.nR_Mode_Info);
850    if(BuildNrModeret != ROK)
851    {
852       return RFAILED;
853    }
854    /*Measurement timing Config*/
855    srvCellItem->served_Cell_Information.measurementTimingConfiguration.\
856       size = sizeof(uint8_t);
857    DU_ALLOC(srvCellItem->served_Cell_Information.\
858          measurementTimingConfiguration.buf,srvCellItem->served_Cell_Information.measurementTimingConfiguration.size);
859    if(srvCellItem->served_Cell_Information.\
860          measurementTimingConfiguration.buf == NULLP)
861    {
862       return RFAILED;
863    }
864    srvCellItem->served_Cell_Information.measurementTimingConfiguration.buf[0] = \
865                                                                                 duCfgParam.srvdCellLst[0].duCellInfo.measTimeCfg;
866
867    /* GNB DU System Information */
868    DU_ALLOC(srvCellItem->gNB_DU_System_Information,
869          sizeof(GNB_DU_System_Information_t));
870    if(!srvCellItem->gNB_DU_System_Information)
871    {
872       return RFAILED;
873    }
874    /* MIB */
875    srvCellItem->gNB_DU_System_Information->mIB_message.size = duCfgParam.srvdCellLst[0].duSysInfo.mibLen;
876    DU_ALLOC(srvCellItem->gNB_DU_System_Information->mIB_message.buf,
877          srvCellItem->gNB_DU_System_Information->mIB_message.size);
878    if(!srvCellItem->gNB_DU_System_Information->mIB_message.buf)
879    {
880       return RFAILED;
881    }
882    memcpy(srvCellItem->gNB_DU_System_Information->mIB_message.buf, duCfgParam.srvdCellLst[0].duSysInfo.mibMsg, \
883                    srvCellItem->gNB_DU_System_Information->mIB_message.size);
884
885    /* SIB1 */
886    srvCellItem->gNB_DU_System_Information->sIB1_message.size =\
887                                                               duCfgParam.srvdCellLst[0].duSysInfo.sib1Len;
888
889    DU_ALLOC(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,
890          srvCellItem->gNB_DU_System_Information->sIB1_message.size);
891    if(!srvCellItem->gNB_DU_System_Information->sIB1_message.buf)
892    {
893       return RFAILED;
894    }
895    for(int x=0; x<srvCellItem->gNB_DU_System_Information->sIB1_message.size; x++)
896    {
897       srvCellItem->gNB_DU_System_Information->sIB1_message.buf[x]=\
898                                                                   duCfgParam.srvdCellLst[0].duSysInfo.sib1Msg[x];
899    }
900    return ROK; 
901 }                                                                                                                  
902 /*******************************************************************
903  *
904  * @brief Builds RRC Version 
905  *
906  * @details
907  *
908  *    Function : BuildRrcVer
909  *
910  *    Functionality: Building RRC Version
911  *
912  * @params[in] int idx,int elementCnt,RRC_Version_t *rrcver
913  * @return ROK     - success
914  *         RFAILED - failure
915  *
916  * ****************************************************************/
917 uint8_t BuildRrcVer(RRC_Version_t *rrcVer)
918 {
919    uint8_t rrcExt;
920    uint8_t rrcLatest;
921    rrcVer->latest_RRC_Version.size = sizeof(uint8_t);
922    DU_ALLOC(rrcVer->latest_RRC_Version.buf,sizeof(uint8_t));
923    if(rrcVer->latest_RRC_Version.buf == NULLP)
924    {
925       return RFAILED;
926    }
927    rrcVer->latest_RRC_Version.buf[0] = 0;
928    rrcVer->latest_RRC_Version.bits_unused = 5;
929    DU_ALLOC(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
930    if(rrcVer->iE_Extensions == NULLP)
931    {  
932       return RFAILED;
933    }
934    rrcVer->iE_Extensions->list.count = 1;
935    rrcVer->iE_Extensions->list.size = sizeof(RRC_Version_ExtIEs_t *);
936    DU_ALLOC(rrcVer->iE_Extensions->list.array,rrcVer->iE_Extensions->list.size);
937    if(rrcVer->iE_Extensions->list.array == NULLP)
938    {
939       return RFAILED;
940    }
941    rrcExt = 0;
942    DU_ALLOC(rrcVer->iE_Extensions->list.array[0],\
943          sizeof(RRC_Version_ExtIEs_t));
944    if(rrcVer->iE_Extensions->list.array[0] == NULLP)
945    {
946       return RFAILED;
947    }
948    rrcVer->iE_Extensions->list.array[rrcExt]->id = \
949                                                    ProtocolIE_ID_id_latest_RRC_Version_Enhanced;
950    rrcVer->iE_Extensions->list.array[rrcExt]->criticality = Criticality_reject;
951    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.present =\
952                                                                       RRC_Version_ExtIEs__extensionValue_PR_Latest_RRC_Version_Enhanced;
953    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
954       .Latest_RRC_Version_Enhanced.size = 3*sizeof(uint8_t);
955    DU_ALLOC(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
956          .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
957          array[rrcExt]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
958    if(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
959          .Latest_RRC_Version_Enhanced.buf == NULLP)
960    {
961       return RFAILED;
962    }
963    rrcLatest = 0;
964    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
965       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 15;
966    rrcLatest++;
967    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
968       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 5;
969    rrcLatest++;
970    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
971       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 0;
972    return ROK;
973 }
974 /*******************************************************************
975  *
976  * @brief Sends F1 msg over SCTP
977  *
978  * @details
979  *
980  *    Function : sendF1APMsg
981  *
982  *    Functionality: Sends F1 msg over SCTP
983  *
984  * @params[in] Region region
985  *             Pool pool
986  * @return ROK     - success
987  *         RFAILED - failure
988  *
989  * ****************************************************************/
990 uint8_t sendF1APMsg()
991 {
992    Buffer *mBuf = NULLP;
993   
994    if(ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) == ROK)
995    {
996       if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
997       {
998             ODU_PRINT_MSG(mBuf, 0,0);
999
1000             if(sctpSend(mBuf, F1_INTERFACE) != ROK)
1001             {
1002                DU_LOG("\nERROR  -->  F1AP : SCTP Send failed");
1003                ODU_PUT_MSG_BUF(mBuf);
1004                return RFAILED;
1005             }
1006       }
1007       else
1008       {
1009          DU_LOG("\nERROR  -->  F1AP : ODU_ADD_POST_MSG_MULT failed");
1010          ODU_PUT_MSG_BUF(mBuf);
1011          return RFAILED;
1012       }
1013       ODU_PUT_MSG_BUF(mBuf);
1014    }
1015    else
1016    {
1017       DU_LOG("\nERROR  -->  F1AP : Failed to allocate memory");
1018       return RFAILED;
1019    }
1020    return ROK; 
1021 } /* sendF1APMsg */
1022
1023 /*******************************************************************
1024  *
1025  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1026  *
1027  * @details
1028  *
1029  *    Function :  FreeRrcVer
1030  *
1031  *    Functionality: deallocating the memory of function BuildRrcVer
1032  *
1033  * @params[in] RRC_Version_t *rrcVer
1034  * 
1035  * @return void
1036  *
1037  *****************************************************************/
1038 void FreeRrcVer(RRC_Version_t *rrcVer)
1039 {
1040    if(rrcVer->latest_RRC_Version.buf != NULLP)
1041    {
1042       if(rrcVer->iE_Extensions != NULLP)
1043       {
1044          if(rrcVer->iE_Extensions->list.array != NULLP)
1045          {
1046             if(rrcVer->iE_Extensions->list.array[0] != NULLP)
1047             {
1048                if(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf
1049                      != NULLP)
1050                {
1051                   DU_FREE(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice\
1052                         .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1053                         array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1054                }
1055                DU_FREE(rrcVer->iE_Extensions->list.array[0],sizeof(RRC_Version_ExtIEs_t));
1056             }
1057             DU_FREE(rrcVer->iE_Extensions->list.array,sizeof(RRC_Version_ExtIEs_t*));
1058          }
1059          DU_FREE(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1060       }
1061       DU_FREE(rrcVer->latest_RRC_Version.buf,rrcVer->latest_RRC_Version.size);
1062    }
1063 }
1064
1065 /*******************************************************************
1066  *
1067  * @brief Deallocating memory of TDD NrFreqInfo 
1068  *
1069  * @details
1070  *
1071  *    Function : freeTddNrFreqInfo 
1072  *
1073  *    Functionality: freeTddNrFreqInfo 
1074  *
1075  * @params[in]  F1AP_PDU_t *f1apDuCfg
1076  *
1077  * @return ROK     - void
1078  *
1079  * ****************************************************************/
1080 void freeTddNrFreqInfo(NRFreqInfo_t *freqInfo)
1081 {
1082    uint8_t freqBandListIdx = 0, supportedBandIdx = 0;
1083
1084    if(freqInfo->freqBandListNr.list.array)
1085    {
1086       for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
1087       {
1088          if(freqInfo->freqBandListNr.list.array[freqBandListIdx])
1089          {
1090             if(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
1091             {
1092                for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
1093                {
1094                   DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
1095                         sizeof(SupportedSULFreqBandItem_t));
1096                }
1097                DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
1098                      freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
1099
1100             }
1101             DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
1102          }
1103       }
1104       DU_FREE(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
1105    }
1106 }
1107
1108 /*******************************************************************
1109  *
1110  * @brief Deallocating memory allocated for Nr fdd frequencey mode 
1111  *
1112  * @details
1113  *
1114  *    Function : freeFddNrFreqInfo 
1115  *
1116  *    Functionality:Free memory allocated for Nr fdd frequencey mode 
1117  *
1118  * @params[in]  
1119  *
1120  * @return ROK     - void
1121  *
1122  * ****************************************************************/
1123 void freeFddNrFreqInfo(FDD_Info_t *fDD)
1124 {
1125    uint8_t arrIdx =0;
1126
1127    if(fDD != NULLP)
1128    {
1129       if(fDD->uL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1130       {
1131          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.\
1132                array[arrIdx], sizeof(FreqBandNrItem_t));
1133          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.array, \
1134                fDD->uL_NRFreqInfo.freqBandListNr.list.size);
1135       }
1136
1137       if(fDD->dL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1138       {
1139          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.\
1140                array[arrIdx], sizeof(FreqBandNrItem_t));
1141          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.array,\
1142                fDD->dL_NRFreqInfo.freqBandListNr.list.size);
1143       }
1144       DU_FREE(fDD,sizeof(FDD_Info_t));
1145    }
1146 }
1147
1148 /*******************************************************************
1149  *
1150  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1151  *
1152  * @details
1153  *
1154  *    Function :  FreeServedCellList
1155  *
1156  *    Functionality:  deallocating the memory of function BuildServedCellList
1157
1158  *
1159  * @params[in] GNB_DU_Served_Cells_List_t *duServedCell
1160  *
1161  * @return void
1162  *
1163  * ****************************************************************/
1164 void FreeServedCellList( GNB_DU_Served_Cells_List_t *duServedCell)
1165 {
1166    uint8_t   plmnCnt=MAX_PLMN;
1167    uint8_t  extensionCnt=IE_EXTENSION_LIST_COUNT;
1168    uint8_t  plmnIdx=0, sliceIdx=0;
1169    GNB_DU_Served_Cells_Item_t *srvCellItem;
1170    ServedPLMNs_Item_t  *servedPlmnItem;
1171    SliceSupportItem_t  *sliceSupportItem;
1172
1173    if(duServedCell->list.array!=NULLP)
1174    {
1175       if(duServedCell->list.array[0]!=NULLP)
1176       {
1177          srvCellItem= &duServedCell->list.array[0]->value.choice.GNB_DU_Served_Cells_Item;
1178
1179          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1180                srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.size * sizeof(uint8_t));
1181          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1182                srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.size * sizeof(uint8_t));
1183
1184          if(srvCellItem->served_Cell_Information.fiveGS_TAC!=NULLP)
1185          {
1186             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC->buf,\
1187                   sizeof(srvCellItem->served_Cell_Information.fiveGS_TAC->size));
1188             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC,sizeof(FiveGS_TAC_t));
1189          }
1190
1191          if(srvCellItem->served_Cell_Information.servedPLMNs.list.array!=NULLP)
1192          {
1193             if(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx] != NULLP)
1194             {
1195                servedPlmnItem = srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx];
1196                DU_FREE(servedPlmnItem->pLMN_Identity.buf, servedPlmnItem->pLMN_Identity.size);
1197
1198                if(servedPlmnItem->iE_Extensions != NULLP)
1199                {
1200                   if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1201                   {
1202                      if(servedPlmnItem->iE_Extensions->list.array[0] != NULLP)
1203                      {
1204                         if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1205                               SliceSupportList.list.array != NULLP)
1206                         {
1207                            for(sliceIdx =0; sliceIdx<servedPlmnItem->iE_Extensions->list.array[0]->\
1208                                  extensionValue.choice.SliceSupportList.list.count; sliceIdx++)
1209                            {
1210                               if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1211                                     SliceSupportList.list.array[sliceIdx] != NULLP)
1212                               {
1213                                  sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[0]->\
1214                                                     extensionValue.choice.SliceSupportList.list.array[sliceIdx];
1215
1216                                  DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sizeof(uint8_t));
1217
1218                                  if(sliceSupportItem->sNSSAI.sD != NULLP)
1219                                  {
1220                                     DU_FREE(sliceSupportItem->sNSSAI.sD->buf,\
1221                                           sliceSupportItem->sNSSAI.sD->size);
1222                                     DU_FREE(sliceSupportItem->sNSSAI.sD, sizeof(OCTET_STRING_t));
1223                                  }
1224
1225                                  DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.\
1226                                        choice.SliceSupportList.list.array[sliceIdx], sizeof(SliceSupportItem_t));
1227                               }
1228                            }
1229                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1230                                  SliceSupportList.list.array, servedPlmnItem->iE_Extensions->list.array[0]->\
1231                                  extensionValue.choice.SliceSupportList.list.size);
1232                         }
1233                         DU_FREE(servedPlmnItem->iE_Extensions->list.array[0],\
1234                               sizeof(ServedPLMNs_ItemExtIEs_t));
1235                      }
1236                      DU_FREE(servedPlmnItem->iE_Extensions->list.array,\
1237                            extensionCnt*sizeof(ServedPLMNs_ItemExtIEs_t*));
1238                   }
1239                   DU_FREE(servedPlmnItem->iE_Extensions, sizeof(ProtocolExtensionContainer_4624P3_t));
1240                }
1241                DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx],\
1242                      sizeof(ServedPLMNs_Item_t));
1243             }
1244             DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array,\
1245                   sizeof(ServedPLMNs_Item_t *));
1246          }
1247
1248          if(srvCellItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1249          {
1250             freeFddNrFreqInfo(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1251          }
1252          else   
1253          {
1254             if(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD != NULLP)
1255             {
1256                freeTddNrFreqInfo(&srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1257                DU_FREE(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1258             }
1259          }
1260          
1261          DU_FREE(srvCellItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1262                srvCellItem->served_Cell_Information.measurementTimingConfiguration.size);
1263
1264          if(srvCellItem->gNB_DU_System_Information != NULLP)
1265          {
1266             if(srvCellItem->gNB_DU_System_Information->mIB_message.buf != NULLP)
1267             {
1268                DU_FREE(srvCellItem->gNB_DU_System_Information->mIB_message.buf,\
1269                      srvCellItem->gNB_DU_System_Information->mIB_message.size);
1270             }
1271
1272             if(srvCellItem->gNB_DU_System_Information->sIB1_message.buf != NULLP)
1273             { 
1274                DU_FREE(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,\
1275                      srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1276             }
1277
1278             DU_FREE(srvCellItem->gNB_DU_System_Information, sizeof(GNB_DU_System_Information_t));
1279          }
1280
1281          DU_FREE(duServedCell->list.array[0], sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1282       }
1283       DU_FREE(duServedCell->list.array, plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t*));
1284    }
1285 }
1286
1287 /*******************************************************************
1288  *
1289  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1290  *
1291  * @details
1292  *
1293  *    Function :  FreeF1SetupReq
1294  *
1295  *    Functionality:  deallocating the memory of function BuildAndSendF1SetupReq
1296  *
1297  * @params[in] F1AP_PDU_t *f1apMsg
1298  *
1299  * @return void
1300  *
1301  * ****************************************************************/
1302 void FreeF1SetupReq(F1AP_PDU_t *f1apMsg)
1303 {
1304    uint8_t ieIdx, ieIdx2;
1305    F1SetupRequest_t *f1SetupReq=NULLP;
1306
1307    if(f1apMsg != NULLP)
1308    {
1309       if(f1apMsg->choice.initiatingMessage != NULLP)
1310       {
1311          f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1312          if(f1SetupReq->protocolIEs.list.array != NULLP)
1313          {
1314             for(ieIdx = 0; ieIdx < f1SetupReq->protocolIEs.list.count; ieIdx++)
1315             {
1316                if(f1SetupReq->protocolIEs.list.array[ieIdx] != NULLP)
1317                {
1318                   switch(f1SetupReq->protocolIEs.list.array[ieIdx]->id)
1319                   {
1320                      case ProtocolIE_ID_id_TransactionID:
1321                         break;
1322                      case ProtocolIE_ID_id_gNB_DU_ID:
1323                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1324                               f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1325                         break;
1326                      case ProtocolIE_ID_id_gNB_DU_Name:
1327                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,\
1328                               strlen((char *)duCfgParam.duName));
1329                         break;
1330                      case ProtocolIE_ID_id_gNB_DU_Served_Cells_List:
1331                         FreeServedCellList(&f1SetupReq->protocolIEs.list.\
1332                               array[ieIdx]->value.choice.GNB_DU_Served_Cells_List);
1333                         break;
1334                      case ProtocolIE_ID_id_GNB_DU_RRC_Version:
1335                         FreeRrcVer(&f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version);
1336                         break;
1337                      default:
1338                         DU_LOG("\nERROR  -->  Invalid Event Type %ld", f1SetupReq->protocolIEs.list.array[ieIdx]->id);
1339                         break;
1340                   }
1341                }
1342             }
1343             for(ieIdx2=0; ieIdx2< ieIdx; ieIdx2++)
1344             {
1345                DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx2],sizeof(F1SetupRequestIEs_t));
1346             }
1347             DU_FREE(f1SetupReq->protocolIEs.list.array,\
1348                   f1SetupReq->protocolIEs.list.size);
1349          }
1350          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1351       }
1352       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
1353    }
1354 }
1355 /*******************************************************************
1356  *
1357  * @brief Builds and Send the F1SetupRequest
1358  *
1359  * @details
1360  *
1361  *    Function : BuildAndSendF1SetupReq
1362  *
1363  * Functionality:Fills the F1SetupRequest
1364  *
1365  * @return ROK     - success
1366  *         RFAILED - failure
1367  *
1368  ******************************************************************/
1369 uint8_t BuildAndSendF1SetupReq()
1370 {
1371    uint8_t   ret, ieIdx, elementCnt;
1372    F1AP_PDU_t                 *f1apMsg = NULLP;
1373    F1SetupRequest_t           *f1SetupReq=NULLP;
1374    GNB_DU_Served_Cells_List_t *duServedCell=NULLP;
1375    RRC_Version_t              *rrcVer=NULLP;
1376    asn_enc_rval_t             encRetVal;        /* Encoder return value */
1377    ret= RFAILED;
1378
1379    DU_LOG("\nINFO   -->  F1AP : Building F1 Setup Request\n");
1380    do
1381    {
1382       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
1383       if(f1apMsg == NULLP)
1384       {
1385          break;
1386       }
1387       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
1388       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1389       if(f1apMsg->choice.initiatingMessage == NULLP)
1390       {
1391          break;
1392       }
1393       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_F1Setup;
1394       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
1395       f1apMsg->choice.initiatingMessage->value.present = \
1396                                                          InitiatingMessage__value_PR_F1SetupRequest;
1397
1398       f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1399
1400       elementCnt = (duCfgParam.duName != NULL) ? 5 : 4;
1401
1402       f1SetupReq->protocolIEs.list.count = elementCnt;
1403       f1SetupReq->protocolIEs.list.size = elementCnt * sizeof(F1SetupRequestIEs_t );
1404
1405       /* Initialize the F1Setup members */
1406       DU_ALLOC(f1SetupReq->protocolIEs.list.array,f1SetupReq->protocolIEs.list.size);
1407       if(f1SetupReq->protocolIEs.list.array == NULLP)
1408       {
1409          break;
1410       }
1411       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
1412       {
1413          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx],\
1414                sizeof(F1SetupRequestIEs_t));
1415          if(f1SetupReq->protocolIEs.list.array[ieIdx] == NULLP)
1416          {
1417             break;
1418          }
1419       }
1420
1421       ieIdx = 0;
1422       /*TransactionID*/
1423       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_TransactionID;
1424       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1425       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present =\
1426                                                                F1SetupRequestIEs__value_PR_TransactionID;
1427       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = \
1428                                                                              TRANS_ID;
1429
1430       /*DU ID*/
1431       ieIdx++;
1432       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
1433       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1434       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1435                                                                 F1SetupRequestIEs__value_PR_GNB_DU_ID;
1436       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size =\
1437                                                                              sizeof(uint8_t);
1438
1439       DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1440             f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1441       if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == \
1442             NULLP)
1443       {
1444          break;
1445       }
1446
1447       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] =\
1448          duCfgParam.duId;
1449
1450       /*DU Name*/
1451       if(duCfgParam.duName != NULL)
1452       {
1453          ieIdx++;
1454          f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_Name;
1455          f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_ignore;
1456          f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = F1SetupRequestIEs__value_PR_GNB_DU_Name;
1457          f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size =\
1458             strlen((char *)duCfgParam.duName);
1459          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.\
1460                GNB_DU_Name.buf, strlen((char *)duCfgParam.duName));
1461          if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.\
1462                buf == NULLP)
1463          {
1464             break;
1465          }
1466          strcpy((char*)f1SetupReq->protocolIEs.list.array[ieIdx]->value.\
1467                choice.GNB_DU_Name.buf,
1468                (char*)&duCfgParam.duName);
1469
1470       }
1471
1472       /*Served Cell list */
1473       ieIdx++;
1474       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1475                                                      ProtocolIE_ID_id_gNB_DU_Served_Cells_List;
1476       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1477       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1478                                                                 F1SetupRequestIEs__value_PR_GNB_DU_Served_Cells_List;
1479       duServedCell = &f1SetupReq->protocolIEs.list.\
1480                      array[ieIdx]->value.choice.GNB_DU_Served_Cells_List;
1481       if(BuildServedCellList(duServedCell))
1482       {
1483          break;
1484       }
1485       /*RRC Version*/
1486       ieIdx++;
1487       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1488                                                      ProtocolIE_ID_id_GNB_DU_RRC_Version ;
1489       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1490       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1491                                                                 F1SetupRequestIEs__value_PR_RRC_Version;
1492       rrcVer = &f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
1493       if(BuildRrcVer(rrcVer))
1494       {
1495          break;
1496       }
1497       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
1498
1499       /* Encode the F1SetupRequest type as APER */
1500       memset(encBuf, 0, ENC_BUF_MAX_LEN);
1501       encBufSize = 0;
1502       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
1503             encBuf);
1504
1505       /* Encode results */
1506       if(encRetVal.encoded == ENCODE_FAIL)
1507       {
1508          DU_LOG("\nERROR  -->  F1AP : Could not encode F1SetupRequest structure (at %s)\n",\
1509                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1510          break;
1511       }
1512       else
1513       {
1514          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1SetupRequest\n");
1515          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
1516          {
1517             printf("%x",encBuf[ieIdx]);
1518          }
1519          
1520          duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize = encBufSize;
1521          DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, encBufSize);
1522          if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
1523          {
1524              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the encoding of f1setup req");
1525              return RFAILED;
1526          }
1527          memcpy(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, &encBuf, duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize);
1528       }
1529
1530       /* Sending msg */
1531       if(sendF1APMsg() != ROK)
1532       {
1533          DU_LOG("\nERROR  -->  F1AP : Sending F1 Setup request failed");
1534          break;
1535       }
1536
1537       ret=ROK;
1538       break;
1539    }while(true);
1540
1541    FreeF1SetupReq(f1apMsg);
1542
1543    return ret;
1544 }/* End of BuildAndSendF1SetupReq */
1545
1546 /*******************************************************************
1547  *
1548  * @brief Deallocating memory allocated for Served_Cells_To_Modify_Item_t
1549  *
1550  * @details
1551  *
1552  *    Function : freeCellsToModifyItem 
1553  *
1554  *    Functionality: Deallocating memory of variables allocated in
1555  *                    BuildAndSendDUConfigUpdate function
1556  *
1557  * @params[in]  Served_Cells_To_Modify_Item_t *modifyItem
1558  *
1559  * @return ROK     - void
1560  *
1561  * ****************************************************************/
1562
1563 void freeCellsToModifyItem(Served_Cells_To_Modify_Item_t *modifyItem)
1564 {
1565    uint8_t arrIdx=0, servedPlmnIdx=0, sliceLstIdx=0;
1566    ServedPLMNs_Item_t *servedPlmnItem = NULLP;
1567    SliceSupportItem_t *sliceSupportItem = NULLP;
1568
1569    DU_FREE(modifyItem->oldNRCGI.pLMN_Identity.buf, modifyItem->oldNRCGI.pLMN_Identity.size);
1570    DU_FREE(modifyItem->oldNRCGI.nRCellIdentity.buf, modifyItem->oldNRCGI.nRCellIdentity.size);
1571
1572    DU_FREE(modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1573            modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.size);
1574    DU_FREE(modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1575          modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.size);
1576
1577    if(modifyItem->served_Cell_Information.servedPLMNs.list.array != NULLP)
1578    {
1579       if(modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx] != NULLP)
1580       {
1581          servedPlmnItem = modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx];
1582
1583          DU_FREE(servedPlmnItem->pLMN_Identity.buf,servedPlmnItem->pLMN_Identity.size);
1584
1585          if(servedPlmnItem->iE_Extensions != NULLP)
1586          {
1587             if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1588             {
1589                if(servedPlmnItem->iE_Extensions->list.array[arrIdx] != NULLP)
1590                {
1591                   if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1592                         list.array != NULLP)
1593                   {
1594                      for(sliceLstIdx =0; sliceLstIdx<servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1595                            extensionValue.choice.SliceSupportList.list.count; sliceLstIdx++)
1596                      {
1597                         if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1598                               list.array[sliceLstIdx] != NULLP)
1599                         {
1600
1601                            sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1602                                               SliceSupportList.list.array[sliceLstIdx];
1603
1604                            DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sliceSupportItem->sNSSAI.sST.size);
1605                            if(sliceSupportItem->sNSSAI.sD != NULLP)
1606                            {
1607                               DU_FREE(sliceSupportItem->sNSSAI.sD->buf, sliceSupportItem->sNSSAI.sD->size);
1608                               DU_FREE(sliceSupportItem->sNSSAI.sD,sizeof(OCTET_STRING_t));
1609                            }
1610                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1611                                  SliceSupportList.list.array[sliceLstIdx], sizeof(SliceSupportItem_t));
1612                         }
1613                      }
1614                      DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.\
1615                            choice.SliceSupportList.list.array,\
1616                            servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1617                            extensionValue.choice.SliceSupportList.list.size);
1618                   }
1619                }
1620                for(servedPlmnIdx=0; servedPlmnIdx< servedPlmnItem->iE_Extensions->list.count ; servedPlmnIdx++)
1621                {
1622                   DU_FREE(servedPlmnItem->iE_Extensions->list.array[servedPlmnIdx], sizeof(ServedPLMNs_ItemExtIEs_t ));
1623                }
1624                DU_FREE(servedPlmnItem->iE_Extensions->list.array, servedPlmnItem->iE_Extensions->list.size);
1625             }
1626             DU_FREE(servedPlmnItem->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1627          }
1628       }
1629       for(servedPlmnIdx=0; servedPlmnIdx<modifyItem->served_Cell_Information.servedPLMNs.list.count; servedPlmnIdx++)
1630       {
1631          DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array[servedPlmnIdx], sizeof(ServedPLMNs_Item_t));
1632       }
1633       DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array,\
1634          modifyItem->served_Cell_Information.servedPLMNs.list.size);
1635    }
1636    
1637    if(modifyItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1638    {
1639       freeFddNrFreqInfo(modifyItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1640    }  
1641    else
1642    {
1643       if(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD)
1644       {
1645          freeTddNrFreqInfo(&modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1646          DU_FREE(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1647       }
1648    }
1649    DU_FREE(modifyItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1650       modifyItem->served_Cell_Information.measurementTimingConfiguration.size);
1651 }
1652
1653 /*******************************************************************
1654  *
1655  * @brief Deallocating memory of BuildAndSendDUConfigUpdate
1656  *
1657  * @details
1658  *
1659  *    Function : FreeDUConfigUpdate
1660  *
1661  *    Functionality: Deallocating memory of variables allocated in
1662  *                    BuildAndSendDUConfigUpdate function
1663  *
1664  * @params[in]  F1AP_PDU_t *f1apDuCfg
1665  *
1666  * @return ROK     - void
1667  *
1668  * ****************************************************************/
1669 void FreeDUConfigUpdate(F1AP_PDU_t *f1apDuCfg)
1670 {
1671    uint8_t  ieIdx=0, cellModifyIdx=0, cellDeleteIdx=0;
1672    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
1673    Served_Cells_To_Modify_List_t  *cellsToModify=NULLP;
1674    Served_Cells_To_Delete_List_t  *cellsToDelete=NULLP;
1675    Served_Cells_To_Delete_Item_t  *deleteItem = NULLP;
1676    Served_Cells_To_Delete_ItemIEs_t *deleteItemIe = NULLP;
1677
1678    if(f1apDuCfg != NULLP)
1679    {
1680       if(f1apDuCfg->choice.initiatingMessage != NULLP)
1681       {
1682          duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->\
1683                        value.choice.GNBDUConfigurationUpdate;
1684          if(duCfgUpdate->protocolIEs.list.array != NULLP)
1685          {
1686             for(ieIdx=0; ieIdx<duCfgUpdate->protocolIEs.list.count; ieIdx++)
1687             {
1688                if(duCfgUpdate->protocolIEs.list.array[ieIdx] != NULLP)
1689                {
1690                   switch(duCfgUpdate->protocolIEs.list.array[ieIdx]->id)
1691                   {
1692                      case ProtocolIE_ID_id_Served_Cells_To_Modify_List:
1693                         {
1694                            cellsToModify = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1695                                            value.choice.Served_Cells_To_Modify_List;
1696                            if(cellsToModify->list.array != NULLP)
1697                            {
1698                               for(cellModifyIdx=0; cellModifyIdx<cellsToModify->list.count ;cellModifyIdx++)
1699                               {
1700                                  if(cellsToModify->list.array[cellModifyIdx] != NULLP)
1701                                  {
1702                                     freeCellsToModifyItem(&cellsToModify->list.array[cellModifyIdx]->value.choice.\
1703                                           Served_Cells_To_Modify_Item);
1704                                     DU_FREE(cellsToModify->list.array[cellModifyIdx],\
1705                                           sizeof(Served_Cells_To_Modify_ItemIEs_t));
1706                                  }
1707                               }
1708                               DU_FREE(cellsToModify->list.array,cellsToModify->list.size);
1709                            }
1710                            break;
1711                         }
1712                      case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
1713                         {
1714                            cellsToDelete = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1715                                            value.choice.Served_Cells_To_Delete_List;
1716                            if(cellsToDelete->list.array != NULLP)
1717                            {
1718                               for(cellDeleteIdx=0; cellDeleteIdx<cellsToDelete->list.count ;cellDeleteIdx++)
1719                               {
1720                                  if(cellsToDelete->list.array[cellDeleteIdx] != NULLP)
1721                                  {
1722                                     deleteItemIe = ((Served_Cells_To_Delete_ItemIEs_t*)\
1723                                           cellsToDelete->list.array[cellDeleteIdx]);
1724                                     deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
1725                                     DU_FREE(deleteItem->oldNRCGI.pLMN_Identity.buf,\
1726                                           deleteItem->oldNRCGI.pLMN_Identity.size); 
1727                                     DU_FREE(deleteItem->oldNRCGI.nRCellIdentity.buf,\
1728                                           deleteItem->oldNRCGI.nRCellIdentity.size);
1729                                     DU_FREE(cellsToDelete->list.array[cellDeleteIdx],\
1730                                           sizeof(Served_Cells_To_Delete_ItemIEs_t));
1731                                  }
1732                               }
1733                               DU_FREE(cellsToDelete->list.array,cellsToDelete->list.size);
1734                            }
1735
1736                            break;
1737                         }
1738                      case ProtocolIE_ID_id_gNB_DU_ID:
1739                         {
1740                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1741                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1742                            break;
1743                         }
1744                   }
1745                   DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx],\
1746                         sizeof(GNBDUConfigurationUpdateIEs_t));
1747                }
1748             }
1749             DU_FREE(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
1750          }
1751          DU_FREE(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
1752       }
1753       DU_FREE(f1apDuCfg, (Size)sizeof(F1AP_PDU_t));
1754    }
1755 }
1756
1757 /*******************************************************************
1758  *
1759  * @brief Fills Served Plmns required in ServCellInfo IE
1760  *
1761  * @details
1762  *
1763  *    Function : fillServedPlmns
1764  *
1765  *    Functionality: Fills Served Plmns required in ServCellInfo IE
1766  *
1767  * @params[in] Pointer to ServedPLMNs_List_t *
1768  *
1769  * @return ROK     - success
1770  *         RFAILED - failure
1771  *
1772  *****************************************************************/
1773
1774 uint8_t fillServedPlmns(ServedPLMNs_List_t *servedPlmn)
1775 {
1776    uint8_t ieIdx=0, arrayIdx=0, ieListCnt=0, elementCnt=0, sliceLstIdx=0;
1777
1778    servedPlmn->list.array[arrayIdx]->pLMN_Identity.size = 3*sizeof(uint8_t);
1779    DU_ALLOC(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf, servedPlmn->list.\
1780          array[arrayIdx]->pLMN_Identity.size);
1781    if(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf == NULLP)
1782    {
1783       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1784       return RFAILED;
1785    }
1786    buildPlmnId(duCfgParam.srvdCellLst[arrayIdx].duCellInfo.cellInfo.srvdPlmn[arrayIdx].plmn,\
1787          servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf);
1788    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1789    if(servedPlmn->list.array[arrayIdx]->iE_Extensions == NULLP)
1790    {
1791       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1792       return RFAILED;
1793    }
1794
1795    ieListCnt=1;
1796    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.count = ieListCnt;
1797    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.size = ieListCnt *sizeof(ServedPLMNs_ItemExtIEs_t *);
1798    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array,servedPlmn->list.array[arrayIdx]->\
1799          iE_Extensions->list.size);
1800    if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array == NULLP)
1801    {
1802       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1803       return RFAILED;
1804    }
1805    for(ieIdx=arrayIdx;ieIdx<ieListCnt;ieIdx++)
1806    {
1807       DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx],\
1808             sizeof(ServedPLMNs_ItemExtIEs_t));
1809       if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx] == NULLP)
1810       {
1811          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1812          return RFAILED;
1813       }
1814    }
1815    
1816    ieIdx = 0;
1817    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices; 
1818    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->id =ProtocolIE_ID_id_TAISliceSupportList;
1819    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->criticality = Criticality_ignore;
1820    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.present = \
1821    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
1822    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1823       list.count = elementCnt;
1824    servedPlmn->list.array[arrayIdx]->\
1825       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1826       list.size = elementCnt * sizeof(SliceSupportItem_t *);
1827    DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1828          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1829          list.array,servedPlmn->list.array[arrayIdx]->\
1830          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.size);
1831    if(servedPlmn->list.array[arrayIdx]->\
1832          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1833          list.array == NULLP)
1834    {
1835       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1836       return RFAILED;
1837    }
1838
1839    for(sliceLstIdx =0; sliceLstIdx< elementCnt; sliceLstIdx++)
1840    {
1841       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1842       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1843       list.array[sliceLstIdx],sizeof( SliceSupportItem_t));
1844       if(servedPlmn->list.array[arrayIdx]->\
1845       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1846       list.array[sliceLstIdx] == NULLP)
1847       {   
1848          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1849          return RFAILED;
1850       }
1851       
1852       servedPlmn->list.array[arrayIdx]->\
1853       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1854       list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
1855       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1856       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1857       list.array[sliceLstIdx]->sNSSAI.sST.buf,servedPlmn->list.array[arrayIdx]->\
1858       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->\
1859       sNSSAI.sST.size);
1860       
1861       if(servedPlmn->list.array[arrayIdx]->\
1862       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1863       list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
1864       {
1865          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1866          return RFAILED;
1867       }
1868       servedPlmn->list.array[arrayIdx]->\
1869       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1870       list.array[sliceLstIdx]->sNSSAI.sST.buf[arrayIdx] =  duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
1871       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
1872
1873       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1874       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1875       list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
1876       if(servedPlmn->list.array[arrayIdx]->\
1877       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1878       list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
1879       {
1880          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1881          return RFAILED;
1882       }
1883       servedPlmn->list.array[arrayIdx]->\
1884       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1885       list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
1886       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1887       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1888       list.array[sliceLstIdx]->sNSSAI.sD->buf,servedPlmn->list.array[arrayIdx]->\
1889       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1890       list.array[sliceLstIdx]->sNSSAI.sD->size);
1891       if(servedPlmn->list.array[arrayIdx]->\
1892       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1893       list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
1894       {
1895          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1896          return RFAILED;
1897       }
1898       memcpy(servedPlmn->list.array[arrayIdx]->\
1899       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1900       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
1901       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sd,\
1902       servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1903       list.array[sliceLstIdx]->sNSSAI.sD->size);
1904    }
1905    return ROK;
1906 }
1907
1908 /*******************************************************************
1909  *
1910  * @brief Fills Nr Fdd Info required in ServCellInfo IE
1911  *
1912  * @details
1913  *
1914  *    Function : fillNrFddInfo
1915  *
1916  *    Functionality: Fills Nr Fdd Info required in ServCellInfo IE
1917  *
1918  * @params[in] FDD_Info_t *fDD
1919  *
1920  * @return ROK     - success
1921  *         RFAILED - failure
1922  *
1923  *****************************************************************/
1924
1925 uint8_t fillNrFddInfo(FDD_Info_t *fDD)
1926 {
1927    fDD->uL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.\
1928       f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn;
1929    fDD->uL_NRFreqInfo.freqBandListNr.list.count = 1;
1930    fDD->uL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t*);
1931    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.\
1932          array, fDD->uL_NRFreqInfo.freqBandListNr.list.size);
1933    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array == NULLP)
1934    {
1935       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
1936       return RFAILED;
1937    }
1938
1939    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0], \
1940       sizeof(FreqBandNrItem_t));
1941    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
1942    {
1943       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
1944       return RFAILED;
1945    }
1946    
1947    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
1948       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
1949       freqBand[0].nrFreqBand;
1950    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
1951    fDD->dL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.\
1952       dlNrFreqInfo.nrArfcn;
1953    fDD->dL_NRFreqInfo.freqBandListNr.list.count = 1;
1954    fDD->dL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
1955    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array, fDD->dL_NRFreqInfo.freqBandListNr.list.size);
1956    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array == NULLP)
1957    {
1958       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
1959       return RFAILED;
1960    }
1961    
1962    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0],  sizeof(FreqBandNrItem_t));
1963    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
1964    {
1965       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
1966       return RFAILED;
1967    }
1968
1969    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
1970       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
1971       freqBand[0].nrFreqBand;
1972    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
1973    
1974    /*Transmission Bandwidth*/
1975    fDD->uL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
1976       f1Mode.mode.fdd.ulTxBw.nrScs;
1977    fDD->uL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
1978       f1Mode.mode.fdd.ulTxBw.nrb;
1979    fDD->dL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
1980       f1Mode.mode.fdd.dlTxBw.nrScs;
1981    fDD->dL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
1982       f1Mode.mode.fdd.dlTxBw.nrb;
1983
1984    return ROK;
1985 }
1986
1987 /*******************************************************************
1988  *
1989  * @brief Fills ServCellInfo IE
1990  *
1991  * @details
1992  *
1993  *    Function : fillServedCellInfo
1994  *
1995  *    Functionality: Fills ServCellInfo
1996  *
1997  * @params[in] Pointer to Served_Cell_Information_t *
1998  *
1999  * @return ROK     - success
2000  *         RFAILED - failure
2001  *
2002  *****************************************************************/
2003
2004 uint8_t fillServedCellInfo(Served_Cell_Information_t *srvCellInfo)
2005 {
2006    uint8_t ieIdx, ieListCnt;
2007
2008    /*nRCGI*/
2009    srvCellInfo->nRCGI.pLMN_Identity.size =3*sizeof(uint8_t);
2010    DU_ALLOC(srvCellInfo->nRCGI.pLMN_Identity.buf,\
2011          srvCellInfo->nRCGI.pLMN_Identity.size);
2012    if(srvCellInfo->nRCGI.pLMN_Identity.buf == NULLP)
2013    {
2014       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2015       return RFAILED;
2016    }
2017    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2018          srvCellInfo->nRCGI.pLMN_Identity.buf);
2019    srvCellInfo->nRCGI.nRCellIdentity.size =5*sizeof(uint8_t);
2020    DU_ALLOC(srvCellInfo->nRCGI.nRCellIdentity.buf,\
2021          srvCellInfo->nRCGI.nRCellIdentity.size);
2022    if(srvCellInfo->nRCGI.nRCellIdentity.buf == NULLP)
2023    {   
2024       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2025       return RFAILED;
2026    }
2027    
2028    fillBitString(&srvCellInfo->nRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2029    /*nRPCI*/
2030    srvCellInfo->nRPCI = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
2031
2032    /*servedPLMNs*/
2033    ieListCnt = 1;
2034    srvCellInfo->servedPLMNs.list.count = ieListCnt;
2035    srvCellInfo->servedPLMNs.list.size = ieListCnt*sizeof(ServedPLMNs_Item_t *);
2036    DU_ALLOC(srvCellInfo->servedPLMNs.list.array, srvCellInfo->servedPLMNs.list.size);
2037    if(srvCellInfo->servedPLMNs.list.array == NULLP)
2038    {
2039       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2040       return RFAILED;
2041    }
2042    for(ieIdx=0; ieIdx < ieListCnt; ieIdx++)
2043    {
2044       DU_ALLOC(srvCellInfo->servedPLMNs.list.array[ieIdx], sizeof(ServedPLMNs_Item_t));
2045       if(srvCellInfo->servedPLMNs.list.array[ieIdx]== NULLP)
2046       {
2047          DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2048          return RFAILED;
2049       }
2050    }
2051    if(fillServedPlmns(&srvCellInfo->servedPLMNs))
2052    {
2053       DU_LOG("\nERROR  --> Failed to fill Served Plmn info");
2054       return RFAILED;
2055    }
2056
2057 #ifndef NR_TDD
2058    /*nR Mode Info with FDD*/
2059    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_fDD;
2060    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.fDD, sizeof(FDD_Info_t));
2061    if(srvCellInfo->nR_Mode_Info.choice.fDD == NULLP)
2062    {
2063       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2064       return RFAILED;
2065    }
2066    if(fillNrFddInfo(srvCellInfo->nR_Mode_Info.choice.fDD))
2067    {
2068        DU_LOG("\nERROR  --> Failed to fill the Nr FDD information");
2069       return RFAILED;
2070    }
2071 #else
2072    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_tDD;   
2073    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
2074    if(srvCellInfo->nR_Mode_Info.choice.tDD == NULLP)
2075    {
2076       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2077       return RFAILED;
2078    }
2079    if(fillNrTddInfo(srvCellInfo->nR_Mode_Info.choice.tDD) != ROK)
2080    {
2081       DU_LOG("\nERROR  --> Failed to fill the Nr TDD information");
2082       return RFAILED;
2083    }
2084 #endif
2085
2086    /*Measurement timing Config*/
2087    srvCellInfo->measurementTimingConfiguration.size = sizeof(uint8_t);
2088    DU_ALLOC(srvCellInfo->measurementTimingConfiguration.\
2089          buf,srvCellInfo->measurementTimingConfiguration.size);
2090    if(srvCellInfo->measurementTimingConfiguration.buf == NULLP)
2091    {
2092       return RFAILED;
2093    }
2094    srvCellInfo->measurementTimingConfiguration.\
2095          buf[0] = duCfgParam.srvdCellLst[0].duCellInfo.measTimeCfg;
2096
2097    return ROK;
2098 }
2099
2100 /*******************************************************************
2101  *
2102  * @brief Fills ServCellToModItem IE
2103  *
2104  * @details
2105  *
2106  *    Function : fillServCellToModItem
2107  *
2108  *    Functionality: Fills ServCellToModItem IE
2109  *
2110  * @params[in] Pointer to Served_Cells_To_Modify_Item_t *
2111  *
2112  * @return ROK     - success
2113  *         RFAILED - failure
2114  *
2115  *****************************************************************/
2116
2117 uint8_t fillServCellToModItem(Served_Cells_To_Modify_Item_t *modifyItem)
2118 {
2119    /*pLMN_Identity*/
2120    modifyItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2121    DU_ALLOC(modifyItem->oldNRCGI.pLMN_Identity.buf,modifyItem->oldNRCGI.pLMN_Identity.size);
2122    if(modifyItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2123    {
2124       return RFAILED;
2125    }
2126    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2127          modifyItem->oldNRCGI.pLMN_Identity.buf);
2128
2129    /*nRCellIdentity*/
2130    modifyItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2131    DU_ALLOC(modifyItem->oldNRCGI.nRCellIdentity.buf,\
2132          modifyItem->oldNRCGI.nRCellIdentity.size);
2133    if(modifyItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2134    {
2135       return RFAILED;
2136    }
2137    fillBitString(&modifyItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2138
2139    if(fillServedCellInfo(&modifyItem->served_Cell_Information))
2140       return RFAILED;
2141    else
2142       return ROK;
2143 }
2144
2145 /*******************************************************************
2146  *
2147  * @brief Builds ServCellToModList
2148  *
2149  * @details
2150  *
2151  *    Function : buildServCellToModList
2152  *
2153  *    Functionality: Builds the serv cell to Mod List
2154  *
2155  * @params[in] Pointer to Served_Cells_To_Modify_List_t *
2156  *
2157  * @return ROK     - success
2158  *         RFAILED - failure
2159  *
2160  *****************************************************************/
2161
2162 uint8_t buildServCellToModList(Served_Cells_To_Modify_List_t *cellsToModify)
2163 {
2164    uint8_t ieListCnt, ieIdx;
2165    Served_Cells_To_Modify_Item_t *modifyItem = NULLP;
2166
2167    ieListCnt = 1;
2168    cellsToModify->list.count = ieListCnt;
2169    cellsToModify->list.size = ieListCnt*sizeof(Served_Cells_To_Modify_ItemIEs_t *);
2170    DU_ALLOC(cellsToModify->list.array,cellsToModify->list.size);
2171    if(cellsToModify->list.array == NULLP)
2172    {
2173       return RFAILED;
2174    }
2175    for(ieIdx=0; ieIdx< ieListCnt; ieIdx++)
2176    {
2177       DU_ALLOC(cellsToModify->list.array[ieIdx],sizeof(Served_Cells_To_Modify_ItemIEs_t));
2178       if(cellsToModify->list.array[ieIdx] == NULLP)
2179       {
2180          return RFAILED;
2181       }
2182    }
2183    cellsToModify->list.array[0]->id = ProtocolIE_ID_id_Served_Cells_To_Modify_Item;
2184    cellsToModify->list.array[0]->criticality = Criticality_reject;
2185    cellsToModify->list.array[0]->value.present =\
2186       Served_Cells_To_Modify_ItemIEs__value_PR_Served_Cells_To_Modify_Item;
2187    modifyItem=&cellsToModify->list.array[0]->value.choice.Served_Cells_To_Modify_Item;
2188
2189    if(fillServCellToModItem(modifyItem))
2190       return RFAILED;
2191    else
2192       return ROK;
2193 }
2194 /*******************************************************************
2195  *
2196  * @brief filling the DeleteItemList
2197  *
2198  * @details
2199  *
2200  *    Function : fillCellToDeleteItem 
2201  *
2202  *    Functionality: Filling the DeleteItemIe 
2203  *
2204  * @params[in] Pointer to Served_Cells_To_Delete_ItemIEs_t 
2205  *
2206  * @return ROK     - success
2207  *         RFAILED - failure
2208  *
2209  *****************************************************************/
2210 uint8_t fillCellToDeleteItem(struct Served_Cells_To_Delete_ItemIEs *deleteItemIe)
2211 {
2212    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
2213    
2214    deleteItemIe->id = ProtocolIE_ID_id_Served_Cells_To_Delete_Item;
2215    deleteItemIe->criticality = Criticality_reject;
2216    deleteItemIe->value.present =\
2217    Served_Cells_To_Delete_ItemIEs__value_PR_Served_Cells_To_Delete_Item;
2218    deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
2219
2220    /*pLMN_Identity*/
2221    deleteItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2222    DU_ALLOC(deleteItem->oldNRCGI.pLMN_Identity.buf,deleteItem->oldNRCGI.pLMN_Identity.size);
2223    if(deleteItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2224    {
2225       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2226       return RFAILED;
2227    }
2228    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2229          deleteItem->oldNRCGI.pLMN_Identity.buf);
2230
2231    /*nRCellIdentity*/
2232    deleteItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2233    DU_ALLOC(deleteItem->oldNRCGI.nRCellIdentity.buf,\
2234          deleteItem->oldNRCGI.nRCellIdentity.size);
2235    if(deleteItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2236    {
2237       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2238       return RFAILED;
2239    }
2240    fillBitString(&deleteItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2241    return ROK;
2242
2243 /*******************************************************************
2244  *
2245  * @brief Builds ServCellToDeleteList
2246  *
2247  * @details
2248  *
2249  *    Function : buildServCellToDeleteList
2250  *
2251  *    Functionality: Builds the serv cell to delete List
2252  *
2253  * @params[in] Pointer to Served_Cells_To_Delete_List_t *
2254  *
2255  * @return ROK     - success
2256  *         RFAILED - failure
2257  *
2258  *****************************************************************/
2259  
2260 uint8_t buildServCellToDeleteList(Served_Cells_To_Delete_List_t *cellsToDelete)
2261 {
2262    uint8_t ieListCnt, arrIdx;
2263    
2264    ieListCnt = 1;
2265    cellsToDelete->list.count = ieListCnt;
2266    cellsToDelete->list.size = ieListCnt*sizeof(Served_Cells_To_Delete_ItemIEs_t *);
2267    
2268    DU_ALLOC(cellsToDelete->list.array,cellsToDelete->list.size);
2269    if(cellsToDelete->list.array == NULLP)
2270    {
2271       DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2272       return RFAILED;
2273    }
2274    
2275    for(arrIdx=0; arrIdx< ieListCnt; arrIdx++)
2276    {
2277       DU_ALLOC(cellsToDelete->list.array[arrIdx],sizeof(Served_Cells_To_Delete_ItemIEs_t));
2278       if(cellsToDelete->list.array[arrIdx] == NULLP)
2279       {
2280          DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2281          return RFAILED;
2282       }
2283    }
2284    
2285    arrIdx=0;
2286    if(fillCellToDeleteItem((Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx]) !=ROK)
2287    {
2288       DU_LOG("\nERROR  -->  F1AP: buildServCellToDeleteList(): failed to fill Served_Cells_To_Delete_ItemIEs");
2289       return RFAILED;
2290    }
2291    return ROK;
2292 }
2293
2294 /*******************************************************************
2295  *
2296  * @brief Builds and sends the DUConfigUpdate
2297  *
2298  * @details
2299  *
2300  *    Function : BuildAndSendDUConfigUpdate
2301  *
2302  *    Functionality: Constructs the DU Update message and sends
2303  *                   it to the CU through SCTP.
2304  *
2305  * @params[in] void **buf,Buffer to which encoded pattern is written into
2306  * @params[in] int *size,size of buffer
2307  *
2308  * @return ROK     - success
2309  *         RFAILED - failure
2310  *
2311  * ****************************************************************/
2312 uint8_t BuildAndSendDUConfigUpdate(ServCellAction servCellAction)
2313 {
2314    uint8_t ret =0, ieIdx=0, elementCnt=0;
2315    bool memAlloctionFailure = false;
2316    F1AP_PDU_t                 *f1apDuCfg = NULLP;
2317    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
2318    asn_enc_rval_t encRetVal;     /* Encoder return value */
2319    
2320    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2321    ret= RFAILED;
2322
2323    while(true)
2324    {
2325       DU_LOG("\nINFO   -->  F1AP : Building DU config update\n");
2326       /* Allocate the memory for F1DuCfg */
2327       DU_ALLOC(f1apDuCfg, sizeof(F1AP_PDU_t));
2328       if(f1apDuCfg == NULLP)
2329       {
2330          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2331          break;
2332       }
2333
2334       f1apDuCfg->present = F1AP_PDU_PR_initiatingMessage;
2335       DU_ALLOC(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2336       if(f1apDuCfg->choice.initiatingMessage == NULLP)
2337       {
2338          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2339          break;
2340       }
2341
2342       f1apDuCfg->choice.initiatingMessage->procedureCode = \
2343                                                            ProcedureCode_id_gNBDUConfigurationUpdate;
2344       f1apDuCfg->choice.initiatingMessage->criticality = Criticality_reject;
2345       f1apDuCfg->choice.initiatingMessage->value.present = \
2346                                                            InitiatingMessage__value_PR_GNBDUConfigurationUpdate;
2347       duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->value.\
2348                     choice.GNBDUConfigurationUpdate;
2349       elementCnt = 3;
2350       duCfgUpdate->protocolIEs.list.count = elementCnt;
2351       duCfgUpdate->protocolIEs.list.size = \
2352                                            elementCnt * sizeof(GNBDUConfigurationUpdateIEs_t*);
2353
2354       /* Initialize the F1Setup members */
2355       DU_ALLOC(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2356       if(duCfgUpdate->protocolIEs.list.array == NULLP)
2357       {
2358          DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2359          break;
2360       }
2361       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
2362       {
2363          DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx],sizeof(GNBDUConfigurationUpdateIEs_t));
2364          if(duCfgUpdate->protocolIEs.list.array[ieIdx] == NULLP)
2365          {
2366             DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2367             memAlloctionFailure = true;
2368             break;
2369          }
2370       }
2371       
2372       if(memAlloctionFailure == true)
2373       {
2374          break;
2375       }
2376       /*TransactionID*/
2377       ieIdx = 0;
2378       duCfgUpdate->protocolIEs.list.array[ieIdx]->id=ProtocolIE_ID_id_TransactionID;
2379       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
2380       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2381       GNBDUConfigurationUpdateIEs__value_PR_TransactionID;
2382       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = TRANS_ID;
2383       
2384       ieIdx++;
2385       if(servCellAction == SERV_CELL_TO_MODIFY)
2386       {
2387          /*Served Cell to Modify */
2388          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2389          ProtocolIE_ID_id_Served_Cells_To_Modify_List;
2390          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2391          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2392          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Modify_List;
2393          if(buildServCellToModList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2394                   Served_Cells_To_Modify_List))
2395          {
2396             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToModList");
2397             break;
2398          }
2399       }
2400       else
2401       {
2402          /*Served Cell to Delete */ 
2403          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2404          ProtocolIE_ID_id_Served_Cells_To_Delete_List;
2405          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2406          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2407          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Delete_List;
2408          if(buildServCellToDeleteList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2409          Served_Cells_To_Delete_List)!=ROK)
2410          {
2411             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToDeleteList");
2412             break;
2413          }
2414          
2415       }
2416       // NOTE :GNB DU SYS INFO:MIB AND SIB1 INFORMATION TO BE BUILT AND FILLED HERE
2417       /*GNB DU ID */
2418       ieIdx++;
2419       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
2420       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2421       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2422       GNBDUConfigurationUpdateIEs__value_PR_GNB_DU_ID;
2423       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size = sizeof(uint8_t);
2424       DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
2425             duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
2426       if(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == NULLP)
2427       {
2428          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Memory allocation failed for GNB_DU_ID");
2429          break;
2430       }
2431       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] = duCfgParam.duId;
2432
2433       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apDuCfg);
2434
2435       /* Encode the DU Config Update type as APER */
2436       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
2437       encBufSize = 0;
2438       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apDuCfg, PrepFinalEncBuf, encBuf);
2439
2440       /* Checking encode results */
2441       if(encRetVal.encoded == ENCODE_FAIL)
2442       {
2443          DU_LOG("ERROR  -->  F1AP : Could not encode DUConfigUpdate structure (at %s)\n",\
2444                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2445          break;
2446       }
2447       else
2448       {
2449          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DUConfigUpdate\n");
2450          for(ieIdx =0; ieIdx < encBufSize; ieIdx++)
2451          {
2452             printf("%x",encBuf[ieIdx]);
2453          }
2454       }
2455       /* Sending msg */
2456       if(sendF1APMsg() != ROK)
2457       {
2458          DU_LOG("\nERROR  -->  F1AP : Sending GNB-DU Config Update failed");
2459          break;
2460       }
2461
2462       ret = ROK;
2463       break;
2464    }
2465   
2466    addToReservedF1apPduList(TRANS_ID,f1apDuCfg);
2467    return ret;
2468 }
2469
2470
2471 /*******************************************************************
2472  *
2473  * @brief free the ULRRCMessageTransfer
2474  *
2475  * @details
2476  *
2477  *    Function : FreeULRRCMessageTransfer
2478  *
2479  *    Functionality: Deallocating the memory of variable allocated in
2480  *                      FreeULRRCMessageTransfer
2481  *
2482  * @params[in]
2483  *
2484  * @return ROK     - void
2485  *
2486  ******************************************************************/
2487 void FreeULRRCMessageTransfer( F1AP_PDU_t *f1apMsg)
2488 {
2489    uint8_t idx1;
2490    ULRRCMessageTransfer_t  *ulRRCMsg;
2491
2492    if(f1apMsg != NULLP)
2493    { 
2494       if(f1apMsg->choice.initiatingMessage != NULLP)
2495       {
2496          ulRRCMsg = &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2497          if(ulRRCMsg->protocolIEs.list.array != NULLP)
2498          {
2499             for(idx1=0;idx1<ulRRCMsg->protocolIEs.list.count;idx1++)
2500             {
2501                if(ulRRCMsg->protocolIEs.list.array[idx1] != NULLP)
2502                {
2503                   if(ulRRCMsg->protocolIEs.list.array[idx1]->value.present ==
2504                         ULRRCMessageTransferIEs__value_PR_RRCContainer)
2505                   {
2506                      DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2507                            ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2508                   }
2509                   DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1],sizeof(ULRRCMessageTransferIEs_t));
2510                }
2511             }
2512             DU_FREE(ulRRCMsg->protocolIEs.list.array,ulRRCMsg->protocolIEs.list.size );
2513          }
2514          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2515       }
2516       DU_FREE(f1apMsg,sizeof(F1AP_PDU_t));
2517    }
2518 }
2519 /*******************************************************************
2520  *
2521  * @brief Builds and sends the ULRRCMessageTransfer 
2522  *
2523  * @details
2524  *
2525  *    Function : BuildAndSendULRRCMessageTransfer
2526  *
2527  *    Functionality: Constructs the UL RRC Message Transfer and sends
2528  *                   it to the CU through SCTP.
2529  *
2530  * @params[in] 
2531  *
2532  * @return ROK     - success
2533  *         RFAILED - failure
2534  *
2535  * ****************************************************************/
2536 uint8_t BuildAndSendULRRCMessageTransfer(DuUeCb  *ueCb, uint8_t lcId, \
2537       uint16_t msgLen, uint8_t *rrcMsg)
2538 {
2539    uint8_t                 elementCnt=0, idx1=0, idx=0;
2540    uint8_t                 ret = RFAILED;
2541    F1AP_PDU_t              *f1apMsg = NULLP;
2542    ULRRCMessageTransfer_t  *ulRRCMsg = NULLP;
2543    asn_enc_rval_t          encRetVal;        /* Encoder return value */
2544    
2545    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2546
2547    while(true)
2548    {
2549       DU_LOG("\n INFO   -->  F1AP : Building UL RRC Message Transfer Message\n");
2550
2551       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
2552       if(f1apMsg == NULLP)
2553       {
2554          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
2555          break;
2556       }
2557       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
2558       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2559       if(f1apMsg->choice.initiatingMessage == NULLP)
2560       {
2561          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
2562          break;
2563       }
2564       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_ULRRCMessageTransfer;
2565       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
2566       f1apMsg->choice.initiatingMessage->value.present = \
2567                                                          InitiatingMessage__value_PR_ULRRCMessageTransfer;
2568       ulRRCMsg =
2569          &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2570       elementCnt = 4;
2571       ulRRCMsg->protocolIEs.list.count = elementCnt;
2572       ulRRCMsg->protocolIEs.list.size = \
2573                                         elementCnt * sizeof(ULRRCMessageTransferIEs_t *);
2574
2575       /* Initialize the F1Setup members */
2576       DU_ALLOC(ulRRCMsg->protocolIEs.list.array, ulRRCMsg->protocolIEs.list.size);
2577       if(ulRRCMsg->protocolIEs.list.array == NULLP)
2578       {
2579          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UL RRC MessageTransferIEs failed");
2580          break;
2581       }
2582       for(idx=0; idx<elementCnt; idx++)
2583       {
2584          DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx],sizeof(ULRRCMessageTransferIEs_t));
2585          if(ulRRCMsg->protocolIEs.list.array[idx] == NULLP)
2586          {
2587             break;
2588          }
2589       }
2590
2591       idx1 = 0;
2592
2593       /*GNB CU UE F1AP ID*/
2594       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
2595       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2596       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2597                                                               ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
2598       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
2599
2600       /*GNB DU UE F1AP ID*/
2601       idx1++;
2602       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
2603       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2604       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2605                                                               ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
2606       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
2607
2608       /*SRBID*/
2609       idx1++;
2610       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
2611       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2612       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2613                                                               ULRRCMessageTransferIEs__value_PR_SRBID;
2614       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.SRBID = lcId;
2615
2616       /*RRCContainer*/
2617       idx1++;
2618       ulRRCMsg->protocolIEs.list.array[idx1]->id  = ProtocolIE_ID_id_RRCContainer;
2619       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2620       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2621                                                               ULRRCMessageTransferIEs__value_PR_RRCContainer;
2622       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size = msgLen;
2623       DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2624             ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size)
2625       if(!ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf)
2626       {
2627          DU_LOG(" ERROR  -->  F1AP : Memory allocation for BuildAndSendULRRCMessageTransfer failed");
2628          break;
2629       }
2630       memset(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, 0, msgLen);
2631       memcpy(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, \
2632             rrcMsg, ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2633
2634       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
2635
2636       /* Encode the F1SetupRequest type as APER */
2637       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2638       encBufSize = 0;
2639       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
2640             encBuf);
2641       /* Encode results */
2642       if(encRetVal.encoded == ENCODE_FAIL)
2643       {
2644          DU_LOG( "\nERROR  -->  F1AP : Could not encode ULRRCMessageTransfer structure (at %s)\n",\
2645                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2646          break;
2647       }
2648       else
2649       {
2650          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for ULRRCMessageTransfer\n");
2651          for(int i=0; i< encBufSize; i++)
2652          {
2653             printf("%x",encBuf[i]);
2654          }
2655       }
2656
2657       /* Sending  msg  */
2658       if(sendF1APMsg()  !=      ROK)
2659       {
2660          DU_LOG("\nERROR  -->   F1AP : Sending  UL RRC Message Transfer Failed");
2661          break;
2662       }
2663       ret = ROK;
2664       break;
2665    }
2666    FreeULRRCMessageTransfer(f1apMsg);
2667
2668    return ret;
2669 }/* End of BuildAndSendULRRCMessageTransfer*/
2670
2671 /*******************************************************************
2672  *
2673  * @brief Builds tag config 
2674  *
2675  * @details
2676  *
2677  *    Function : BuildTagConfig 
2678  *
2679  *    Functionality: Builds tag config in MacCellGroupConfig
2680  *
2681  * @params[in] TAG_Config *tag_Config
2682  *
2683  * @return ROK     - success
2684  *         RFAILED - failure
2685  *
2686  * ****************************************************************/
2687 uint8_t BuildTagConfig(DuUeCb *ueCb, struct TAG_Config *tagConfig)
2688 {
2689    struct TAG_Config__tag_ToAddModList *tagList;
2690    uint8_t                     idx, elementCnt;
2691
2692    tagConfig->tag_ToReleaseList = NULLP;
2693    tagConfig->tag_ToAddModList = NULLP;
2694    DU_ALLOC(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
2695    if(!tagConfig->tag_ToAddModList)
2696    {
2697       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2698       return RFAILED;
2699    }
2700
2701    if(ueCb == NULLP)
2702       elementCnt = ODU_VALUE_ONE;
2703    else
2704       elementCnt = ueCb->macUeCfg.macCellGrpCfg.tagCfg.addModListCount;
2705
2706    tagList = tagConfig->tag_ToAddModList;
2707    tagList->list.count = elementCnt;
2708    tagList->list.size  =  elementCnt * sizeof(struct TAG *);
2709
2710    tagList->list.array = NULLP;
2711    DU_ALLOC(tagList->list.array, tagList->list.size);
2712    if(!tagList->list.array)
2713    {
2714       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2715       return RFAILED;
2716    }
2717
2718    for(idx=0; idx<tagList->list.count; idx++)
2719    {
2720       tagList->list.array[idx] = NULLP;
2721       DU_ALLOC(tagList->list.array[idx], sizeof(struct TAG));
2722       if(!tagList->list.array[idx])
2723       {
2724          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2725          return RFAILED;
2726       }
2727    }
2728
2729    if(ueCb == NULLP)
2730    {
2731       idx = 0;
2732       tagList->list.array[idx]->tag_Id = TAG_ID;
2733       tagList->list.array[idx]->timeAlignmentTimer = TIME_ALIGNMENT_TMR;
2734    }
2735    else
2736    {
2737       for(idx=0; idx<tagList->list.count; idx++)
2738       {
2739          tagList->list.array[idx]->tag_Id = ueCb->macUeCfg.macCellGrpCfg.tagCfg.addModList[idx].tagId;
2740          tagList->list.array[idx]->timeAlignmentTimer = ueCb->macUeCfg.macCellGrpCfg.tagCfg.addModList[idx].timeAlignTimer;
2741       }
2742    }
2743
2744    return ROK;
2745 }
2746
2747 /*******************************************************************
2748  *
2749  * @brief Builds PHR Config 
2750  *
2751  * @details
2752  *
2753  *    Function : BuildPhrConfig
2754  *
2755  *    Functionality: Builds phrConfig in MacCellGroupConfig
2756  *
2757  * @params[in] PHR Config *
2758  *
2759  * @return ROK     - success
2760  *         RFAILED - failure
2761  *
2762  * ****************************************************************/
2763 uint8_t BuildPhrConfig(DuUeCb *ueCb, struct MAC_CellGroupConfig__phr_Config *phrConfig)
2764 {
2765
2766    phrConfig->present = MAC_CellGroupConfig__phr_Config_PR_setup;
2767    phrConfig->choice.setup = NULLP;
2768    DU_ALLOC(phrConfig->choice.setup, sizeof(struct PHR_Config));
2769    if(!phrConfig->choice.setup)
2770    {
2771       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhrConfig");
2772       return RFAILED;
2773    }
2774
2775    if(ueCb == NULLP)
2776    {
2777       phrConfig->choice.setup->phr_PeriodicTimer        = PHR_PERIODIC_TMR;
2778       phrConfig->choice.setup->phr_ProhibitTimer        = PHR_PROHIBHIT_TMR;
2779       phrConfig->choice.setup->phr_Tx_PowerFactorChange = PHR_PWR_FACTOR_CHANGE;
2780       phrConfig->choice.setup->multiplePHR              = false;
2781       phrConfig->choice.setup->dummy                    = false;
2782       phrConfig->choice.setup->phr_Type2OtherCell       = false;
2783       phrConfig->choice.setup->phr_ModeOtherCG          = PHR_MODE_OTHER_CG;
2784    }
2785    else
2786    {
2787       phrConfig->choice.setup->phr_PeriodicTimer        = ueCb->macUeCfg.macCellGrpCfg.phrCfg.periodicTimer;
2788       phrConfig->choice.setup->phr_ProhibitTimer        = ueCb->macUeCfg.macCellGrpCfg.phrCfg.prohibitTimer;
2789       phrConfig->choice.setup->phr_Tx_PowerFactorChange = ueCb->macUeCfg.macCellGrpCfg.phrCfg.txPowerFactor;
2790       phrConfig->choice.setup->multiplePHR              = ueCb->macUeCfg.macCellGrpCfg.phrCfg.multiplePHR;
2791       phrConfig->choice.setup->dummy                    = ueCb->macUeCfg.macCellGrpCfg.phrCfg.dummy;
2792       phrConfig->choice.setup->phr_Type2OtherCell       = ueCb->macUeCfg.macCellGrpCfg.phrCfg.phrType2OtherCell;
2793       phrConfig->choice.setup->phr_ModeOtherCG          = ueCb->macUeCfg.macCellGrpCfg.phrCfg.phrOtherCG;
2794    }
2795
2796    return ROK;
2797 }
2798
2799 /*******************************************************************
2800  *
2801  * @brief Builds BSR Config 
2802  *
2803  * @details
2804  *
2805  *    Function : BuildBsrConfig
2806  *
2807  *    Functionality: Builds BuildBsrConfig in MacCellGroupConfig
2808  *
2809  * @params[in] BSR_Config *bsrConfig
2810  *
2811  * @return ROK     - success
2812  *         RFAILED - failure
2813  *
2814  * ****************************************************************/
2815 uint8_t BuildBsrConfig(DuUeCb *ueCb, struct BSR_Config *bsrConfig)
2816 {
2817    if(ueCb == NULLP)
2818    {
2819       bsrConfig->periodicBSR_Timer = PERIODIC_BSR_TMR;
2820       bsrConfig->retxBSR_Timer     = RETX_BSR_TMR;
2821       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
2822    }
2823    else
2824    {
2825       bsrConfig->periodicBSR_Timer = convertBsrPeriodicTmrValueToEnum(ueCb->macUeCfg.macCellGrpCfg.bsrTmrCfg.periodicTimer);
2826       bsrConfig->retxBSR_Timer     = convertBsrRetxTmrValueToEnum(ueCb->macUeCfg.macCellGrpCfg.bsrTmrCfg.retxTimer);
2827
2828       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
2829       DU_ALLOC(bsrConfig->logicalChannelSR_DelayTimer, sizeof(long));
2830       if(bsrConfig->logicalChannelSR_DelayTimer == NULLP)
2831       {
2832          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildBsrConfig");
2833          return RFAILED;
2834       }
2835       *(bsrConfig->logicalChannelSR_DelayTimer) = convertLcSrDelayTmrValueToEnum(ueCb->macUeCfg.macCellGrpCfg.bsrTmrCfg.srDelayTimer);
2836    }
2837
2838    return ROK;
2839 }
2840
2841 /*******************************************************************
2842  *
2843  * @brief Builds scheduling request config 
2844  *
2845  * @details
2846  *
2847  *    Function : BuildSchedulingReqConfig 
2848  *
2849  *    Functionality: Builds BuildSchedulingReqConfig in MacCellGroupConfig
2850  *
2851  * @params[in] SchedulingRequestConfig *schedulingRequestConfig
2852  *
2853  * @return ROK     - success
2854  *         RFAILED - failure
2855  *
2856  * ****************************************************************/
2857 uint8_t BuildSchedulingReqConfig(DuUeCb *ueCb, struct SchedulingRequestConfig *schedulingRequestConfig)
2858 {
2859    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList;
2860    uint8_t                     idx, elementCnt;
2861
2862    schedulingRequestConfig->schedulingRequestToAddModList = NULLP;
2863    DU_ALLOC(schedulingRequestConfig->schedulingRequestToAddModList,
2864          sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));
2865    if(!schedulingRequestConfig->schedulingRequestToAddModList)
2866    {
2867       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2868       return RFAILED;
2869    }
2870
2871    if(ueCb == NULLP)
2872       elementCnt = ODU_VALUE_ONE;
2873    else
2874       elementCnt = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModListCount;
2875
2876    schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
2877    schReqList->list.count = elementCnt;
2878    schReqList->list.size  = elementCnt * sizeof(struct SchedulingRequestToAddMod *);
2879
2880    schReqList->list.array = NULLP;
2881    DU_ALLOC(schReqList->list.array, schReqList->list.size);
2882    if(!schReqList->list.array)
2883    {
2884       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2885       return RFAILED;
2886    }
2887
2888    for(idx=0; idx<schReqList->list.count; idx++)
2889    {
2890       schReqList->list.array[idx] = NULLP;
2891       DU_ALLOC(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
2892       if(!schReqList->list.array[idx])
2893       {
2894          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2895          return RFAILED;
2896       }
2897    }
2898
2899    if(ueCb == NULLP)
2900    {
2901       idx = 0;
2902       schReqList->list.array[idx]->schedulingRequestId = SCH_REQ_ID;
2903
2904       schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
2905       DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
2906       if(!schReqList->list.array[idx]->sr_ProhibitTimer)
2907       {
2908          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2909          return RFAILED;
2910       }
2911       *(schReqList->list.array[idx]->sr_ProhibitTimer) = SR_PROHIBIT_TMR;
2912       schReqList->list.array[idx]->sr_TransMax = SR_TRANS_MAX;
2913    }
2914    else
2915    {
2916       for(idx=0; idx<schReqList->list.count; idx++)
2917       {
2918          schReqList->list.array[idx]->schedulingRequestId = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].schedReqId;
2919
2920          schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
2921          DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
2922          if(!schReqList->list.array[idx]->sr_ProhibitTimer)
2923          {
2924             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2925             return RFAILED;
2926          }
2927          *(schReqList->list.array[idx]->sr_ProhibitTimer) = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srProhibitTmr;
2928          schReqList->list.array[idx]->sr_TransMax = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srTransMax;
2929       }
2930    }
2931
2932    schedulingRequestConfig->schedulingRequestToReleaseList = NULLP;
2933
2934    return ROK;
2935 }
2936
2937 /*******************************************************************
2938  *
2939  * @brief Builds RLC Configuration for AM mode
2940  *
2941  * @details
2942  *
2943  *    Function : BuildRlcConfigAm
2944  *
2945  *    Functionality: 
2946  *       Builds AM mode RLC Config in BuildRlcBearerToAddModList
2947  *
2948  * @params[in] AmBearerCfg *amCfg
2949  *             RLC_Config_t  *rlcConfig
2950  *
2951  * @return ROK     - success
2952  *         RFAILED - failure
2953  *
2954  * ****************************************************************/
2955 uint8_t BuildRlcConfigAm(AmBearerCfg *amCfg, struct RLC_Config *rlcConfig)
2956 {
2957    rlcConfig->choice.am = NULLP;
2958    DU_ALLOC(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
2959    if(!rlcConfig->choice.am)
2960    {
2961       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
2962       return RFAILED;
2963    }
2964
2965    /* Fill AM UL configuration */
2966    rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength = NULLP;
2967    DU_ALLOC(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
2968    if(!rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength)
2969    {
2970       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
2971       return RFAILED;
2972    }
2973
2974    /* Fill default AM UL configuration if input pointer to DU database is NULL */
2975    if(amCfg == NULLP)
2976    {
2977       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = SN_FIELD_LEN;
2978       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = T_POLL_RETRANSMIT;
2979       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = POLL_PDU;
2980       rlcConfig->choice.am->ul_AM_RLC.pollByte          = POLL_BYTE;
2981       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = MAX_RETX_THRESHOLD;
2982    }
2983    else
2984    {
2985       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->dlAmCfg.snLenDl);
2986       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = covertPollRetxTmrValueToEnum(amCfg->dlAmCfg.pollRetxTmr);
2987       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = covertPollPduValueToEnum(amCfg->dlAmCfg.pollPdu);
2988       rlcConfig->choice.am->ul_AM_RLC.pollByte          = covertPollByteValueToEnum(amCfg->dlAmCfg.pollByte);
2989       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = covertMaxRetxValueToEnum(amCfg->dlAmCfg.maxRetxTh);
2990    }
2991
2992    /* Fill AM DL configuraion */
2993    rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength = NULLP;
2994    DU_ALLOC(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
2995    if(!rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength)
2996    {
2997       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
2998       return RFAILED;
2999    }
3000
3001    /* Fill default AM DL configuration if input pointer to DU database is NULL */
3002    if(amCfg == NULLP)
3003    {
3004       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = SN_FIELD_LEN;
3005       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = T_REASSEMBLY;
3006       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = T_STATUS_PROHIBHIT;
3007    }
3008    else /* Fill AM configuration from DU database */
3009    {
3010       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->ulAmCfg.snLenUl);
3011       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = convertReasmblTmrValueToEnum(amCfg->ulAmCfg.reAssemTmr);
3012       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = convertProhibitTmrValueToEnum(amCfg->ulAmCfg.statProhTmr);
3013    }
3014    return ROK;
3015 }
3016
3017 /*******************************************************************
3018  *
3019  * @brief Builds RLC Config for UM Bidirection
3020  *
3021  * @details
3022  *
3023  *    Function : BuildRlcConfig UmBiDir
3024  *
3025  *    Functionality: 
3026  *       Builds RLC Config for UM Bidirection in BuildRlcBearerToAddModList 
3027  *
3028  * @params[in] UmBiDirBearerCfg *umBiDirCfg
3029  *             RLC_Config_t *rlcConfig
3030  *
3031  * @return ROK     - success
3032  *         RFAILED - failure
3033  *
3034  * ****************************************************************/
3035 uint8_t BuildRlcConfigUmBiDir(UmBiDirBearerCfg *umBiDirCfg, struct RLC_Config *rlcConfig)
3036 {
3037    rlcConfig->choice.um_Bi_Directional = NULLP;
3038    DU_ALLOC(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
3039    if(rlcConfig->choice.um_Bi_Directional == NULLP)
3040    {
3041       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3042       return RFAILED;
3043    }
3044
3045    /* Fill UM Bidirectional UL configuration */
3046    rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength = NULLP;
3047    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3048    if(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength == NULLP)
3049    {
3050       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3051       return RFAILED;
3052    }
3053
3054    if(umBiDirCfg != NULLP)
3055    {
3056       *(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->dlUmCfg.snLenDlUm);     
3057    }
3058
3059    /* Fill UM Bidirectional DL configuration */
3060    rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength = NULLP;
3061    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3062    if(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength == NULLP)
3063    {
3064       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3065       return RFAILED;
3066    }
3067
3068    if(umBiDirCfg != NULLP)
3069    {
3070       *(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->ulUmCfg.snLenUlUm);     
3071       rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umBiDirCfg->ulUmCfg.reAssemTmr);
3072    }
3073
3074    return ROK;
3075 }
3076
3077 /*******************************************************************
3078  *
3079  * @brief Builds RLC Config for UM Uni directional UL
3080  *
3081  * @details
3082  *
3083  *    Function : BuildRlcConfigUmUniDirUl
3084  *
3085  *    Functionality: 
3086  *       Builds RLC Config for UM Unidirection UL in BuildRlcBearerToAddModList 
3087  *
3088  * @params[in] UmUniDirDlBearerCfg *umUniDirDlCfg
3089  *             RLC_Config_t *rlcConfig
3090  *
3091  * @return ROK     - success
3092  *         RFAILED - failure
3093  *
3094  * ****************************************************************/
3095 uint8_t BuildRlcConfigUmUniDirUl(UmUniDirDlBearerCfg *umUniDirDlCfg, RLC_Config_t *rlcConfig)
3096 {
3097    rlcConfig->choice.um_Uni_Directional_UL = NULLP;
3098    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
3099    if(rlcConfig->choice.um_Uni_Directional_UL == NULLP)
3100    {
3101       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3102       return RFAILED;
3103    }
3104
3105    rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength = NULLP;
3106    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3107    if(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength == NULLP)
3108    {
3109       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3110       return RFAILED;
3111    }
3112
3113    if(umUniDirDlCfg != NULLP)
3114    {
3115       *(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirDlCfg->dlUmCfg.snLenDlUm);
3116    }
3117
3118    return ROK;
3119 }
3120
3121 /*******************************************************************
3122  *
3123  * @brief Builds RLC Config for UM Uni directional DL
3124  *
3125  * @details
3126  *
3127  *    Function : BuildRlcConfigUmUniDirDl
3128  *
3129  *    Functionality: 
3130  *       Builds RLC Config for UM Unidirection DL in BuildRlcBearerToAddModList 
3131  *
3132  * @params[in] UmUniDirUlBearerCfg *umUniDirUlCfg
3133  *             RLC_Config_t *rlcConfig
3134  *
3135  * @return ROK     - success
3136  *         RFAILED - failure
3137  *
3138  * ****************************************************************/
3139 uint8_t BuildRlcConfigUmUniDirDl(UmUniDirUlBearerCfg *umUniDirUlCfg, RLC_Config_t *rlcConfig)
3140 {
3141    rlcConfig->choice.um_Uni_Directional_DL = NULLP;
3142    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
3143    if(rlcConfig->choice.um_Uni_Directional_DL == NULLP)
3144    {
3145       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3146       return RFAILED;
3147    }
3148
3149    rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength = NULLP;
3150    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3151    if(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength == NULLP)
3152    {
3153       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3154       return RFAILED;
3155    }
3156
3157    if(umUniDirUlCfg != NULLP)
3158    {
3159       *(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirUlCfg->ulUmCfg.snLenUlUm);
3160       rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umUniDirUlCfg->ulUmCfg.reAssemTmr);
3161    }
3162
3163    return ROK;
3164 }
3165
3166 /*******************************************************************
3167  *
3168  * @brief Builds RLC Config
3169  *
3170  * @details
3171  *
3172  *    Function : BuildRlcConfig
3173  *
3174  *    Functionality: Builds RLC Config in BuildRlcBearerToAddModList 
3175  *
3176  * @params[in] RLC_Config_t *rlcConfig
3177  *
3178  * @return ROK     - success
3179  *         RFAILED - failure
3180  *
3181  * ****************************************************************/
3182 uint8_t BuildRlcConfig(RlcBearerCfg *rbCfg, struct RLC_Config *rlcConfig)
3183 {
3184    
3185    /* Fill default values if rbCfg is NULL */
3186    if(rbCfg == NULLP)
3187    {
3188       rlcConfig->present = RLC_Config_PR_am;
3189       BuildRlcConfigAm(NULLP, rlcConfig);
3190    }
3191    /* If RbCfg is present, fill RLC configurations from DU Database */
3192    else
3193    {
3194       rlcConfig->present = covertRlcModeFromIntEnumToRrcEnum(rbCfg->rlcMode);
3195       switch(rlcConfig->present)
3196       {
3197          case RLC_Config_PR_am:
3198             BuildRlcConfigAm(rbCfg->u.amCfg, rlcConfig);
3199             break;
3200          case RLC_Config_PR_um_Bi_Directional:
3201             BuildRlcConfigUmBiDir(rbCfg->u.umBiDirCfg, rlcConfig);
3202             break;
3203          case RLC_Config_PR_um_Uni_Directional_UL:
3204             BuildRlcConfigUmUniDirUl(rbCfg->u.umUniDirDlCfg, rlcConfig);
3205             break;
3206          case RLC_Config_PR_um_Uni_Directional_DL:
3207             BuildRlcConfigUmUniDirDl(rbCfg->u.umUniDirUlCfg, rlcConfig);
3208             break;
3209          case RLC_Config_PR_NOTHING:
3210          default:
3211             break;
3212       }
3213    }
3214
3215    return ROK;
3216 }
3217
3218 /*******************************************************************
3219  *
3220  * @brief Builds MAC LC Config
3221  *
3222  * @details
3223  *
3224  *    Function : BuildMacLCConfig 
3225  *
3226  *    Functionality: Builds MAC LC Config in BuildRlcBearerToAddModList 
3227  *
3228  * @params[in] struct LogicalChannelConfig macLcConfig
3229  *
3230  * @return ROK     - success
3231  *         RFAILED - failure
3232  *
3233  * ****************************************************************/
3234 uint8_t BuildMacLCConfig(LcCfg *lcCfgDb, struct LogicalChannelConfig *macLcConfig)
3235 {
3236    macLcConfig->ul_SpecificParameters = NULLP;
3237    DU_ALLOC(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
3238    if(!macLcConfig->ul_SpecificParameters)
3239    {
3240       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3241       return RFAILED;
3242    }
3243
3244    if(lcCfgDb == NULLP)
3245    {
3246       macLcConfig->ul_SpecificParameters->priority = MAC_LC_PRIORITY;
3247       macLcConfig->ul_SpecificParameters->prioritisedBitRate =  PRIORTISIED_BIT_RATE;
3248       macLcConfig->ul_SpecificParameters->bucketSizeDuration =  BUCKET_SIZE_DURATION;
3249    }
3250    else
3251    {
3252       macLcConfig->ul_SpecificParameters->priority = lcCfgDb->ulLcCfg.priority;
3253       macLcConfig->ul_SpecificParameters->prioritisedBitRate = lcCfgDb->ulLcCfg.pbr;
3254       macLcConfig->ul_SpecificParameters->bucketSizeDuration = lcCfgDb->ulLcCfg.bsd;
3255    }
3256
3257    macLcConfig->ul_SpecificParameters->allowedServingCells = NULLP;
3258    macLcConfig->ul_SpecificParameters->allowedSCS_List = NULLP;
3259    macLcConfig->ul_SpecificParameters->maxPUSCH_Duration = NULLP;
3260    macLcConfig->ul_SpecificParameters->configuredGrantType1Allowed = NULLP;
3261
3262    macLcConfig->ul_SpecificParameters->logicalChannelGroup = NULLP;
3263    DU_ALLOC(macLcConfig->ul_SpecificParameters->logicalChannelGroup,    sizeof(long));
3264    if(!macLcConfig->ul_SpecificParameters->logicalChannelGroup)
3265    {
3266       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3267       return RFAILED;
3268    }
3269
3270    if(lcCfgDb == NULLP)
3271       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = LC_GRP;
3272    else
3273       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = lcCfgDb->ulLcCfg.lcGroup;
3274
3275    macLcConfig->ul_SpecificParameters->schedulingRequestID = NULLP;
3276    DU_ALLOC(macLcConfig->ul_SpecificParameters->schedulingRequestID,    sizeof(SchedulingRequestId_t));
3277    if(!macLcConfig->ul_SpecificParameters->schedulingRequestID)
3278    {
3279       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3280       return RFAILED;
3281    }
3282
3283    if(lcCfgDb == NULLP)
3284       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = SCH_REQ_ID;
3285    else
3286       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = lcCfgDb->ulLcCfg.schReqId;
3287
3288    macLcConfig->ul_SpecificParameters->logicalChannelSR_Mask = false;
3289    macLcConfig->ul_SpecificParameters->logicalChannelSR_DelayTimerApplied = false;
3290    macLcConfig->ul_SpecificParameters->bitRateQueryProhibitTimer = NULLP;
3291
3292    return ROK;
3293 }
3294
3295 /*******************************************************************
3296  *
3297  * @brief Builds RLC Bearer to Add/Mod list
3298  *
3299  * @details
3300  *
3301  *    Function :BuildRlcBearerToAddModList 
3302  *
3303  *    Functionality: Builds RLC Bearer to Add/Mod list in DuToCuRrcContainer
3304  *
3305  * @params[in] rlc_BearerToAddModList
3306  *
3307  * @return ROK     - success
3308  *         RFAILED - failure
3309  *
3310  * ****************************************************************/
3311 uint8_t BuildRlcBearerToAddModList(DuUeCb *ueCb, struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList)
3312 {
3313    uint8_t  idx = 0, lcIdx=0, macLcIdx = 0, elementCnt = 0;
3314
3315    if(ueCb == NULLP)
3316       elementCnt = 1;
3317    else if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
3318       elementCnt = ueCb->rlcUeCfg.numLcs;
3319    else
3320    {
3321       for(lcIdx = 0; lcIdx<ueCb->rlcUeCfg.numLcs; lcIdx++)
3322       {
3323          if(ueCb->rlcUeCfg.rlcLcCfg[lcIdx].isLcAddModRspSent == false)
3324             elementCnt++;
3325       }
3326    }
3327    rlcBearerList->list.count = elementCnt;
3328    rlcBearerList->list.size  = elementCnt * sizeof(struct RLC_BearerConfig *);
3329
3330    rlcBearerList->list.array = NULLP;
3331    DU_ALLOC(rlcBearerList->list.array, rlcBearerList->list.size);
3332    if(!rlcBearerList->list.array)
3333    {
3334       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3335       return RFAILED;
3336    }
3337
3338    for(idx=0; idx<rlcBearerList->list.count; idx++)
3339    {
3340       rlcBearerList->list.array[idx] = NULLP;
3341       DU_ALLOC(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
3342       if(!rlcBearerList->list.array[idx])
3343       {
3344          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3345          return RFAILED;
3346       }
3347    }
3348
3349    if(ueCb == NULLP)
3350    {
3351       idx=0;
3352       rlcBearerList->list.array[idx]->logicalChannelIdentity = SRB1_LCID;
3353       DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3354       if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3355       {     
3356          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3357          return RFAILED;
3358       }     
3359       rlcBearerList->list.array[idx]->servedRadioBearer->present = RLC_BearerConfig__servedRadioBearer_PR_srb_Identity;
3360       rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = SRB1_LCID;
3361       rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3362
3363       /* Fill RLC related Configurations for this Radio Bearer */
3364       rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3365       DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3366       if(!rlcBearerList->list.array[idx]->rlc_Config)
3367       {
3368          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3369          return RFAILED;
3370       }
3371       if(BuildRlcConfig(NULLP, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3372       {
3373          DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3374          return RFAILED;
3375       }
3376
3377       /* Fill MAC related configurations for this Radio Bearer */
3378       rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3379       DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3380       if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3381       {
3382          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3383          return RFAILED;
3384       }
3385       if(BuildMacLCConfig(NULLP, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3386       {
3387          DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3388          return RFAILED;
3389       }
3390    }
3391    else
3392    {
3393       idx=0;
3394       for(lcIdx=0; lcIdx<ueCb->rlcUeCfg.numLcs; lcIdx++)
3395       {
3396          if((ueCb->f1UeDb->actionType != UE_CTXT_CFG_QUERY) && (ueCb->rlcUeCfg.rlcLcCfg[lcIdx].isLcAddModRspSent == true))
3397             continue;
3398
3399          /* Fill Logical channel identity */
3400          rlcBearerList->list.array[idx]->logicalChannelIdentity = ueCb->rlcUeCfg.rlcLcCfg[lcIdx].lcId;
3401
3402          /* Fill Radio Bearer Id and type (DRB/SRB) for this logical channel */
3403          DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3404          if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3405          {
3406             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3407             return RFAILED;
3408          }
3409          rlcBearerList->list.array[idx]->servedRadioBearer->present = \
3410                                                                       covertRbTypeFromIntEnumToRrcEnum(ueCb->rlcUeCfg.rlcLcCfg[lcIdx].rbType);
3411          switch(rlcBearerList->list.array[idx]->servedRadioBearer->present)
3412          {
3413             case RLC_BearerConfig__servedRadioBearer_PR_srb_Identity: 
3414                rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = ueCb->rlcUeCfg.rlcLcCfg[lcIdx].rbId;
3415                break;
3416             case RLC_BearerConfig__servedRadioBearer_PR_drb_Identity:
3417                rlcBearerList->list.array[idx]->servedRadioBearer->choice.drb_Identity = ueCb->rlcUeCfg.rlcLcCfg[lcIdx].rbId;
3418                break;
3419             case RLC_BearerConfig__servedRadioBearer_PR_NOTHING:
3420             default:
3421                break;
3422          }
3423          ueCb->rlcUeCfg.rlcLcCfg[lcIdx].isLcAddModRspSent = true;
3424
3425          rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3426
3427          /* Fill RLC related Configurations for this Radio Bearer */
3428          rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3429          DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3430          if(!rlcBearerList->list.array[idx]->rlc_Config)
3431          {
3432             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3433             return RFAILED;
3434          }
3435          if(BuildRlcConfig(&ueCb->rlcUeCfg.rlcLcCfg[lcIdx], rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3436          {
3437             DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3438             return RFAILED;
3439          }
3440
3441          /* Fill MAC related configurations for this Radio Bearer */
3442          rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3443          DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3444          if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3445          {
3446             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3447             return RFAILED;
3448          }
3449          for(macLcIdx = 0; macLcIdx < ueCb->macUeCfg.numLcs; macLcIdx++)
3450          {
3451             if(ueCb->macUeCfg.lcCfgList[macLcIdx].lcId == ueCb->rlcUeCfg.rlcLcCfg[lcIdx].lcId)
3452             {
3453                if(BuildMacLCConfig(&ueCb->macUeCfg.lcCfgList[macLcIdx], rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3454                {
3455                   DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3456                   return RFAILED;
3457                }
3458                break;
3459             }
3460          }
3461
3462          idx++;
3463       }
3464    }
3465    return ROK;
3466 }
3467
3468 /*******************************************************************
3469  *
3470  * @brief Build Control resource set to add/modify list 
3471  *
3472  * @details
3473  *
3474  *    Function : BuildControlRSetToAddModList
3475  *
3476  *    Functionality: Build Control resource set to add/modify list
3477  *
3478  * @params[in] 
3479  * struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList
3480  *
3481  * @return ROK     - success
3482  *         RFAILED - failure
3483  *
3484  * ****************************************************************/
3485 uint8_t BuildControlRSetToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList)
3486 {
3487    uint8_t idx;
3488    uint8_t elementCnt;
3489    uint8_t numBytes, bitsUnused;
3490    struct ControlResourceSet *controlRSet;
3491    uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
3492    uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
3493
3494    if(pdcchCfg == NULLP)
3495       elementCnt = 1;
3496    else
3497       elementCnt = pdcchCfg->numCRsetToAddMod;
3498
3499    controlRSetList->list.count = elementCnt;
3500    controlRSetList->list.size = elementCnt * sizeof(struct ControlResourceSet *);
3501
3502    controlRSetList->list.array = NULLP;
3503    DU_ALLOC(controlRSetList->list.array, controlRSetList->list.size);
3504    if(!controlRSetList->list.array)
3505    {
3506       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3507       return RFAILED;
3508    }
3509
3510    for(idx = 0; idx < elementCnt; idx++)
3511    {
3512       controlRSetList->list.array[idx] = NULLP;
3513       DU_ALLOC(controlRSetList->list.array[idx], sizeof(struct ControlResourceSet));
3514       if(!controlRSetList->list.array[idx])
3515       {
3516          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3517          return RFAILED;
3518       }
3519    }
3520
3521    for(idx = 0; idx < elementCnt; idx++)
3522    {
3523       controlRSet = controlRSetList->list.array[idx];
3524
3525       if(pdcchCfg == NULLP)
3526          controlRSet->controlResourceSetId = PDCCH_CTRL_RSRC_SET_ONE_ID;
3527       else
3528          controlRSet->controlResourceSetId = pdcchCfg->cRSetToAddModList[idx].cRSetId;
3529
3530       /* size 6 bytes
3531        * 3 LSBs unsued
3532        * Bit string stored ff0000000000
3533        */
3534       numBytes = 6;
3535       bitsUnused = 3;
3536       controlRSet->frequencyDomainResources.size = numBytes * sizeof(uint8_t);
3537
3538       controlRSet->frequencyDomainResources.buf = NULLP;
3539       DU_ALLOC(controlRSet->frequencyDomainResources.buf, controlRSet->frequencyDomainResources.size);
3540       if(!controlRSet->frequencyDomainResources.buf)
3541       {
3542          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3543          return RFAILED;
3544       }
3545
3546       memset(controlRSet->frequencyDomainResources.buf, 0, FREQ_DOM_RSRC_SIZE);
3547
3548       if(pdcchCfg == NULLP)
3549       {
3550          coreset0EndPrb = CORESET0_END_PRB;
3551          coreset1StartPrb = coreset0EndPrb + 6;
3552          coreset1NumPrb = CORESET1_NUM_PRB;
3553          /* calculate the PRBs */
3554          fillCoresetFeqDomAllocMap(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
3555          memcpy(controlRSet->frequencyDomainResources.buf, freqDomainResource, FREQ_DOM_RSRC_SIZE);
3556          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3557
3558          controlRSet->duration = PDCCH_CTRL_RSRC_SET_ONE_DURATION;
3559          controlRSet->cce_REG_MappingType.present = ControlResourceSet__cce_REG_MappingType_PR_nonInterleaved;
3560          controlRSet->precoderGranularity = PDCCH_CTRL_RSRC_SET_ONE_PRECOD_GRANULARITY;
3561       }
3562       else
3563       {
3564          memcpy(controlRSet->frequencyDomainResources.buf, pdcchCfg->cRSetToAddModList[idx].freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
3565          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3566          controlRSet->duration = pdcchCfg->cRSetToAddModList[idx].duration;
3567          controlRSet->cce_REG_MappingType.present = pdcchCfg->cRSetToAddModList[idx].cceRegMappingType;
3568          controlRSet->precoderGranularity = pdcchCfg->cRSetToAddModList[idx].precoderGranularity;
3569       }
3570       controlRSet->tci_StatesPDCCH_ToAddList = NULLP;
3571       controlRSet->tci_StatesPDCCH_ToReleaseList = NULLP;
3572       controlRSet->tci_PresentInDCI = NULLP;
3573
3574 #if 0
3575       uint8_t tciStateIdx;
3576
3577       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList, \
3578             sizeof(struct ControlResourceSet__tci_StatesPDCCH_ToAddList));
3579       if(!controlRset->tci_StatesPDCCH_ToAddList)
3580       {
3581          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3582          return RFAILED;
3583       }
3584
3585       elementCnt = 1;
3586       controlRset->tci_StatesPDCCH_ToAddList->list.count = elementCnt;
3587       controlRset->tci_StatesPDCCH_ToAddList->list.size = elementCnt * sizeof(TCI_StateId_t *);
3588       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array, \
3589             controlRset->tci_StatesPDCCH_ToAddList->list.size)
3590          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array)
3591          {
3592             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3593             return RFAILED;
3594          }
3595
3596       for(tciStateIdx = 0; tciStateIdx <elementCntl; tciStateIdx++)
3597       {
3598          DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx], sizeof(TCI_StateId_t));
3599          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx])
3600          {
3601             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3602             return RFAILED;
3603          }
3604       }
3605
3606       tciStateIdx = 0;
3607       /* TODO */
3608       *(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx]);
3609
3610       DU_ALLOC(controlRset->tci_PresentInDCI, sizeof(long));
3611       if(!controlRset->tci_PresentInDCI)
3612       {
3613          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3614          return RFAILED;
3615       }
3616       /* TODO */
3617       *(controlRset->tci_PresentInDCI);
3618 #endif
3619
3620       controlRSet->pdcch_DMRS_ScramblingID = NULLP;
3621       DU_ALLOC(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
3622       if(!controlRSet->pdcch_DMRS_ScramblingID)
3623       {
3624          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3625          return RFAILED;
3626       }
3627       if(pdcchCfg == NULLP)
3628          *(controlRSet->pdcch_DMRS_ScramblingID) = SCRAMBLING_ID;
3629       else
3630          *(controlRSet->pdcch_DMRS_ScramblingID) = pdcchCfg->cRSetToAddModList[idx].dmrsScramblingId;
3631    }
3632    return ROK;
3633 } /* End BuildControlRSetToAddModList */
3634
3635 /*******************************************************************
3636  *
3637  * @brief Build search space to add/modify list
3638  *
3639  * @details
3640  *
3641  *    Function : BuildSearchSpcToAddModList
3642  *
3643  *    Functionality: Build search space to add/modify list
3644  *
3645  * @params[in] 
3646  * @return ROK     - success
3647  *         RFAILED - failure
3648  *
3649  * ****************************************************************/
3650 uint8_t BuildSearchSpcToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
3651 {
3652    uint8_t idx;
3653    uint8_t numBytes;
3654    uint8_t byteIdx;
3655    uint8_t bitsUnused;
3656    uint8_t elementCnt;
3657    struct SearchSpace *searchSpc;
3658
3659    if(pdcchCfg == NULLP)
3660       elementCnt = 1;
3661    else
3662       elementCnt = pdcchCfg->numSearchSpcToAddMod;
3663
3664    searchSpcList->list.count = elementCnt;
3665    searchSpcList->list.size = elementCnt * sizeof(struct SearchSpace *);
3666
3667    searchSpcList->list.array = NULLP;
3668    DU_ALLOC(searchSpcList->list.array, searchSpcList->list.size);
3669    if(!searchSpcList->list.array)
3670    {
3671       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3672       return RFAILED;
3673    }
3674
3675    for(idx = 0; idx < elementCnt; idx++)
3676    {
3677       searchSpcList->list.array[idx] = NULLP;
3678       DU_ALLOC(searchSpcList->list.array[idx], sizeof(struct SearchSpace));
3679       if(!searchSpcList->list.array[idx])
3680       {
3681          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3682          return RFAILED;
3683       }
3684    }
3685
3686    for(idx = 0; idx < elementCnt; idx++)
3687    {
3688       searchSpc = searchSpcList->list.array[idx];
3689
3690       if(pdcchCfg == NULLP)
3691          searchSpc->searchSpaceId = PDCCH_SRCH_SPC_TWO_ID;
3692       else
3693          searchSpc->searchSpaceId = pdcchCfg->searchSpcToAddModList[idx].searchSpaceId;
3694
3695       searchSpc->controlResourceSetId = NULLP;
3696       DU_ALLOC(searchSpc->controlResourceSetId, sizeof(ControlResourceSetId_t));
3697       if(!searchSpc->controlResourceSetId)
3698       {
3699          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3700          return RFAILED;
3701       }
3702       if(pdcchCfg == NULLP)
3703          *(searchSpc->controlResourceSetId) = PDCCH_CTRL_RSRC_SET_ONE_ID;
3704       else
3705          *(searchSpc->controlResourceSetId) = pdcchCfg->searchSpcToAddModList[idx].cRSetId;
3706
3707       searchSpc->monitoringSlotPeriodicityAndOffset = NULLP;
3708       DU_ALLOC(searchSpc->monitoringSlotPeriodicityAndOffset, sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
3709       if(!searchSpc->monitoringSlotPeriodicityAndOffset)
3710       {
3711          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3712          return RFAILED;
3713       }
3714       if(pdcchCfg == NULLP)
3715          searchSpc->monitoringSlotPeriodicityAndOffset->present = SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
3716       else
3717          searchSpc->monitoringSlotPeriodicityAndOffset->present = pdcchCfg->searchSpcToAddModList[idx].mSlotPeriodicityAndOffset;
3718
3719       searchSpc->duration = NULLP;
3720       searchSpc->monitoringSymbolsWithinSlot = NULLP;
3721       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot, sizeof(BIT_STRING_t));
3722       if(!searchSpc->monitoringSymbolsWithinSlot)
3723       {
3724          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3725          return RFAILED;
3726       }
3727
3728       /* Values taken from reference logs :
3729        * size 2 bytes
3730        * 2 LSBs unsued
3731        * Bit string stores 8000
3732        */
3733       numBytes = 2;
3734       bitsUnused = 2;
3735       searchSpc->monitoringSymbolsWithinSlot->size = numBytes * sizeof(uint8_t);
3736       searchSpc->monitoringSymbolsWithinSlot->buf = NULLP;
3737       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot->buf, searchSpc->monitoringSymbolsWithinSlot->size);
3738       if(!searchSpc->monitoringSymbolsWithinSlot->buf)
3739       {
3740          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3741          return RFAILED;
3742       }
3743       if(pdcchCfg == NULLP)
3744       {
3745          byteIdx = 0;
3746          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = PDCCH_SYMBOL_WITHIN_SLOT /* setting MSB to 128 i.e. 0x80 */;
3747          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = 0;
3748       }
3749       else
3750          memcpy(searchSpc->monitoringSymbolsWithinSlot->buf, pdcchCfg->searchSpcToAddModList[idx].mSymbolsWithinSlot, numBytes);
3751       searchSpc->monitoringSymbolsWithinSlot->bits_unused = bitsUnused;
3752
3753       searchSpc->nrofCandidates = NULLP;
3754       DU_ALLOC(searchSpc->nrofCandidates, sizeof(struct SearchSpace__nrofCandidates));
3755       if(!searchSpc->nrofCandidates)
3756       {
3757          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3758          return RFAILED;
3759       }
3760
3761       if(pdcchCfg == NULLP)
3762       {
3763          searchSpc->nrofCandidates->aggregationLevel1 = PDCCH_SRCH_SPC_TWO_AGG_LVL1_CANDIDATE;
3764          searchSpc->nrofCandidates->aggregationLevel2 = PDCCH_SRCH_SPC_TWO_AGG_LVL2_CANDIDATE;
3765          searchSpc->nrofCandidates->aggregationLevel4 = PDCCH_SRCH_SPC_TWO_AGG_LVL4_CANDIDATE;
3766          searchSpc->nrofCandidates->aggregationLevel8 = PDCCH_SRCH_SPC_TWO_AGG_LVL8_CANDIDATE;
3767          searchSpc->nrofCandidates->aggregationLevel16 = PDCCH_SRCH_SPC_TWO_AGG_LVL16_CANDIDATE;
3768       }
3769       else
3770       {
3771          searchSpc->nrofCandidates->aggregationLevel1 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel1;
3772          searchSpc->nrofCandidates->aggregationLevel2 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel2;
3773          searchSpc->nrofCandidates->aggregationLevel4 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel4;
3774          searchSpc->nrofCandidates->aggregationLevel8 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel8;
3775          searchSpc->nrofCandidates->aggregationLevel16 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel16;
3776       }
3777
3778       searchSpc->searchSpaceType = NULLP;
3779       DU_ALLOC(searchSpc->searchSpaceType, sizeof(struct SearchSpace__searchSpaceType));
3780       if(!searchSpc->searchSpaceType)
3781       {
3782          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3783          return RFAILED;
3784       }
3785       if(pdcchCfg == NULLP)
3786          searchSpc->searchSpaceType->present = SearchSpace__searchSpaceType_PR_ue_Specific;
3787       else
3788          searchSpc->searchSpaceType->present = pdcchCfg->searchSpcToAddModList[idx].searchSpaceType;
3789
3790       searchSpc->searchSpaceType->choice.ue_Specific = NULLP;
3791       DU_ALLOC(searchSpc->searchSpaceType->choice.ue_Specific, sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
3792       if(!searchSpc->searchSpaceType->choice.ue_Specific)
3793       {
3794          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3795          return RFAILED;
3796       }  
3797       if(pdcchCfg == NULLP)
3798          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
3799       else
3800          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = pdcchCfg->searchSpcToAddModList[idx].ueSpecificDciFormat;
3801    }
3802    return ROK;
3803 }/* End BuildSearchSpcToAddModList */
3804
3805 /*******************************************************************
3806  *
3807  * @brief Builds BWP DL dedicated PDCCH config
3808  *
3809  * @details
3810  *
3811  *    Function : BuildBWPDlDedPdcchCfg
3812  *
3813  *    Functionality: Builds BWP DL dedicated PDCCH config
3814  *
3815  * @params[in] struct PDCCH_Config *pdcchCfg
3816  *
3817  * @return ROK     - success
3818  *         RFAILED - failure
3819  *
3820  * ****************************************************************/
3821 uint8_t BuildBWPDlDedPdcchCfg(PdcchConfig *pdcchCfgDb, struct PDCCH_Config *pdcchCfg)
3822 {
3823    pdcchCfg->controlResourceSetToAddModList = NULLP;
3824    DU_ALLOC(pdcchCfg->controlResourceSetToAddModList, sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
3825    if(!pdcchCfg->controlResourceSetToAddModList)
3826    {
3827       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
3828       return RFAILED;
3829    }
3830
3831    if(BuildControlRSetToAddModList(pdcchCfgDb, pdcchCfg->controlResourceSetToAddModList) != ROK)
3832    {
3833       DU_LOG("\nERROR  --> F1AP : Failed in BuildControlRSetToAddModList()");
3834       return RFAILED;
3835    }
3836
3837    pdcchCfg->controlResourceSetToReleaseList = NULLP;
3838
3839    pdcchCfg->searchSpacesToAddModList = NULLP;
3840    DU_ALLOC(pdcchCfg->searchSpacesToAddModList, sizeof(struct PDCCH_Config__searchSpacesToAddModList));
3841    if(!pdcchCfg->searchSpacesToAddModList)
3842    {
3843       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
3844       return RFAILED;
3845    }
3846
3847    if(BuildSearchSpcToAddModList(pdcchCfgDb, pdcchCfg->searchSpacesToAddModList) != ROK)
3848    {
3849       DU_LOG("\nERROR  --> F1AP : Failed in BuildSearchSpcToAddModList()");
3850       return RFAILED;
3851    }
3852
3853    pdcchCfg->searchSpacesToReleaseList = NULLP;
3854    pdcchCfg->downlinkPreemption = NULLP;
3855    pdcchCfg->tpc_PUSCH = NULLP;
3856    pdcchCfg->tpc_PUCCH = NULLP;
3857    pdcchCfg->tpc_SRS = NULLP;
3858
3859    return ROK;
3860 }
3861
3862 /*******************************************************************
3863  *
3864  * @brief Builds DMRS DL PDSCH Mapping type A
3865  *
3866  * @details
3867  *
3868  *    Function : BuildDMRSDLPdschMapTypeA
3869  *
3870  *    Functionality: Builds DMRS DL PDSCH Mapping type A
3871  *
3872  * @params[in]
3873  * struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg
3874  * @return ROK     - success
3875  *         RFAILED - failure
3876  *
3877  * ****************************************************************/
3878 uint8_t BuildDMRSDLPdschMapTypeA(PdschConfig *pdschCfg, struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg)
3879 {
3880    dmrsDlCfg->present = PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup;
3881    dmrsDlCfg->choice.setup = NULLP;
3882    DU_ALLOC(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
3883    if(!dmrsDlCfg->choice.setup)
3884    {
3885       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
3886       return RFAILED;
3887    }
3888
3889    dmrsDlCfg->choice.setup->dmrs_Type = NULLP;
3890    dmrsDlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
3891    DU_ALLOC(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
3892    if(!dmrsDlCfg->choice.setup->dmrs_AdditionalPosition)
3893    {
3894       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
3895       return RFAILED;
3896    }
3897    if(pdschCfg == NULLP)
3898       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS;
3899    else
3900       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = pdschCfg->dmrsDlCfgForPdschMapTypeA.addPos;
3901
3902    dmrsDlCfg->choice.setup->maxLength = NULLP;
3903    dmrsDlCfg->choice.setup->scramblingID0 = NULLP;
3904    dmrsDlCfg->choice.setup->scramblingID1 = NULLP;
3905    dmrsDlCfg->choice.setup->phaseTrackingRS = NULLP;
3906
3907    return ROK;
3908 }
3909
3910 /*******************************************************************
3911  *
3912  * @brief Builds TCI states to add/modify list
3913  *
3914  * @details
3915  *
3916  *    Function : BuildTCIStatesToAddModList
3917  *
3918  *    Functionality:Builds TCI states to add/modify list
3919  *
3920  * @params[in] 
3921  * struct PDSCH_Config__tci_StatesToAddModList *tciStatesList
3922  *
3923  * @return ROK     - success
3924  *         RFAILED - failure
3925  *
3926  * ****************************************************************/
3927 uint8_t BuildTCIStatesToAddModList(struct PDSCH_Config__tci_StatesToAddModList *tciStatesList)
3928 {
3929    return ROK;
3930 }
3931
3932 /*******************************************************************
3933  *
3934  * @brief Builds PDSCH time domain allocation list
3935  *
3936  * @details
3937  *
3938  *    Function : BuildPdschTimeDomAllocList
3939  *
3940  *    Functionality: Builds PDSCH time domain allocation list
3941  *
3942  * @params[in] 
3943  * struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
3944  *
3945  * @return ROK     - success
3946  *         RFAILED - failure
3947  *
3948  * ****************************************************************/
3949 uint8_t BuildPdschTimeDomAllocList(PdschConfig *pdschCfg, struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
3950 {
3951    uint8_t idx;
3952    uint8_t elementCnt;
3953    struct PDSCH_TimeDomainResourceAllocation *timeDomAlloc;
3954
3955    timeDomAllocList->present = PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup;
3956
3957    timeDomAllocList->choice.setup = NULLP;
3958    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PDSCH_TimeDomainResourceAllocationList));
3959    if(!timeDomAllocList->choice.setup)
3960    {
3961       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
3962       return RFAILED;
3963    }
3964
3965 if(pdschCfg == NULLP)
3966    elementCnt = 2;
3967 else
3968 elementCnt = pdschCfg->numTimeDomRsrcAlloc;
3969    timeDomAllocList->choice.setup->list.count = elementCnt;
3970    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(struct PDSCH_TimeDomainResourceAllocation *);
3971
3972    timeDomAllocList->choice.setup->list.array = NULLP;
3973    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
3974    if(!timeDomAllocList->choice.setup->list.array)
3975    {
3976       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
3977       return RFAILED;
3978    }
3979
3980    for(idx = 0; idx < elementCnt; idx++)
3981    {
3982       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
3983       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], \
3984             sizeof(struct PDSCH_TimeDomainResourceAllocation));
3985       if(!timeDomAllocList->choice.setup->list.array[idx])
3986       {
3987          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
3988          return RFAILED;
3989       }
3990    }
3991
3992    if(pdschCfg == NULLP)
3993    {
3994       idx = 0;
3995       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
3996       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
3997       if(!timeDomAlloc->k0)
3998       {
3999          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4000          return RFAILED;
4001       }
4002       *(timeDomAlloc->k0) = 0;
4003       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4004       timeDomAlloc->startSymbolAndLength = \
4005                                            calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4006
4007       idx++;
4008       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4009       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4010       if(!timeDomAlloc->k0)
4011       {
4012          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4013          return RFAILED;
4014       }
4015       *(timeDomAlloc->k0) = 1;
4016       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4017       timeDomAlloc->startSymbolAndLength = calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4018    }
4019    else
4020    {
4021       for(idx = 0; idx < elementCnt; idx++)
4022       {
4023          timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4024          DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4025          if(!timeDomAlloc->k0)
4026          {
4027             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4028             return RFAILED;
4029          }
4030          if(pdschCfg->timeDomRsrcAllociList[idx].k0)
4031             *(timeDomAlloc->k0) = *(pdschCfg->timeDomRsrcAllociList[idx].k0);
4032          timeDomAlloc->mappingType = pdschCfg->timeDomRsrcAllociList[idx].mappingType;
4033          timeDomAlloc->startSymbolAndLength = pdschCfg->timeDomRsrcAllociList[idx].startSymbolAndLength;
4034       }
4035    }
4036
4037    return ROK;
4038 }
4039
4040 /*******************************************************************
4041  *
4042  * @brief Builds PDSCH PRB Bundling type
4043  *
4044  * @details
4045  *
4046  *    Function : BuildPdschPrbBundlingType
4047  *
4048  *    Functionality: Builds PDSCH PRB Bundling type
4049  *
4050  * @params[in] 
4051  * struct PDSCH_Config__prb_BundlingType *prbBndlType
4052  *
4053  * @return ROK     - success
4054  *         RFAILED - failure
4055  *
4056  * ****************************************************************/
4057 uint8_t BuildPdschPrbBundlingType(PdschConfig *pdschCfg, struct PDSCH_Config__prb_BundlingType *prbBndlType)
4058 {
4059    if(pdschCfg == NULLP)
4060       prbBndlType->present = PDSCH_Config__prb_BundlingType_PR_staticBundling;
4061    else
4062       prbBndlType->present = pdschCfg->bundlingType;
4063
4064    prbBndlType->choice.staticBundling = NULLP;
4065    DU_ALLOC(prbBndlType->choice.staticBundling, \
4066          sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
4067    if(!prbBndlType->choice.staticBundling)
4068    {
4069       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschPrbBundlingType");
4070       return RFAILED;
4071    }
4072    prbBndlType->choice.staticBundling->bundleSize = NULLP;
4073
4074    return ROK;
4075 }
4076
4077 /*******************************************************************
4078  *
4079  * @brief Builds BWP DL dedicated PDSCH config 
4080  *
4081  * @details
4082  *
4083  *    Function : BuildBWPDlDedPdschCfg
4084  *
4085  *    Functionality: Builds BWP DL dedicated PDSCH config
4086  *
4087  * @params[in] struct PDSCH_Config *pdschCfg
4088  *
4089  * @return ROK     - success
4090  *         RFAILED - failure
4091  *
4092  * ****************************************************************/
4093 uint8_t BuildBWPDlDedPdschCfg(PdschConfig *pdschCfgDb, struct PDSCH_Config *pdschCfg)
4094 {
4095    pdschCfg->dataScramblingIdentityPDSCH = NULLP;
4096
4097    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA = NULLP;
4098    DU_ALLOC(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
4099    if(!pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
4100    {
4101       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4102       return RFAILED;
4103    }
4104
4105    if(BuildDMRSDLPdschMapTypeA(pdschCfgDb, pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA) != ROK)
4106    {
4107       return RFAILED;
4108    }
4109
4110    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeB = NULLP;
4111    pdschCfg->tci_StatesToAddModList = NULLP;
4112    pdschCfg->tci_StatesToReleaseList = NULLP;
4113    pdschCfg->vrb_ToPRB_Interleaver = NULLP;
4114 #if 0
4115    DU_ALLOC(pdschCfg->tci_StatesToAddModList, sizeof(struct PDSCH_Config__tci_StatesToAddModList));
4116    if(!pdschCfg->tci_StatesToAddModList)
4117    {
4118       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4119       return RFAILED;
4120    }
4121    if(BuildTCIStatesToAddModList(pdschCfg->tci_StatesToAddModList) != ROK)
4122    {
4123       return RFAILED;
4124    }
4125 #endif
4126
4127 if(pdschCfgDb == NULLP)
4128    pdschCfg->resourceAllocation = RES_ALLOC_TYPE;
4129 else
4130 pdschCfg->resourceAllocation = pdschCfgDb->resourceAllocType;
4131
4132    pdschCfg->pdsch_TimeDomainAllocationList = NULLP;
4133    DU_ALLOC(pdschCfg->pdsch_TimeDomainAllocationList, sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
4134    if(!pdschCfg->pdsch_TimeDomainAllocationList)
4135    {
4136       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4137       return RFAILED;
4138    }
4139    if(BuildPdschTimeDomAllocList(pdschCfgDb, pdschCfg->pdsch_TimeDomainAllocationList) != ROK)
4140    {
4141       return RFAILED;
4142    }
4143
4144    pdschCfg->pdsch_AggregationFactor = NULLP;
4145    pdschCfg->rateMatchPatternToAddModList = NULLP;
4146    pdschCfg->rateMatchPatternToReleaseList = NULLP;
4147    pdschCfg->rateMatchPatternGroup1 = NULLP;
4148    pdschCfg->rateMatchPatternGroup2 = NULLP;
4149    if(pdschCfgDb == NULLP)
4150       pdschCfg->rbg_Size = PDSCH_RBG_SIZE;
4151    else
4152       pdschCfg->rbg_Size = pdschCfgDb->rbgSize;
4153    pdschCfg->mcs_Table = NULLP;
4154
4155    pdschCfg->maxNrofCodeWordsScheduledByDCI = NULLP;
4156    DU_ALLOC(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
4157    if(!pdschCfg->maxNrofCodeWordsScheduledByDCI)
4158    {
4159       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4160       return RFAILED;
4161    }
4162    if(pdschCfgDb == NULLP)
4163       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = PDSCH_MAX_CODEWORD_SCH_BY_DCI;
4164    else
4165       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = pdschCfgDb->numCodeWordsSchByDci;
4166
4167    if(BuildPdschPrbBundlingType(pdschCfgDb, &pdschCfg->prb_BundlingType) != ROK)
4168    {
4169       return RFAILED;
4170    }
4171
4172    pdschCfg->zp_CSI_RS_ResourceToAddModList = NULLP;
4173    pdschCfg->zp_CSI_RS_ResourceToReleaseList = NULLP;
4174    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4175    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4176    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4177    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4178    pdschCfg->p_ZP_CSI_RS_ResourceSet = NULLP;
4179
4180    return ROK;
4181 }
4182
4183 /*******************************************************************
4184  *
4185  * @brief Builds intitial DL BWP
4186  * @details
4187  *
4188  *    Function : BuildInitialDlBWP 
4189  *
4190  *    Functionality: Builds intitial DL BWP in spCellCfgDed
4191  *
4192  * @params[in] BWP_DownlinkDedicated_t *dlBwp
4193  *
4194  * @return ROK     - success
4195  *         RFAILED - failure
4196  *
4197  * ****************************************************************/
4198 uint8_t BuildInitialDlBWP(InitialDlBwp *initiDlBwp, BWP_DownlinkDedicated_t *dlBwp)
4199 {
4200    PdcchConfig *pdcchCfg = NULLP;
4201    PdschConfig *pdschCfg = NULLP;
4202
4203    if(initiDlBwp)
4204    {
4205       if(initiDlBwp->pdcchPresent)
4206          pdcchCfg = &initiDlBwp->pdcchCfg;
4207       if(initiDlBwp->pdschPresent)
4208          pdschCfg = &initiDlBwp->pdschCfg;
4209    }
4210
4211    dlBwp->pdcch_Config = NULLP;
4212    DU_ALLOC(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
4213    if(!dlBwp->pdcch_Config)
4214    {
4215       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4216       return RFAILED;
4217    }
4218    dlBwp->pdcch_Config->present = BWP_DownlinkDedicated__pdcch_Config_PR_setup; 
4219
4220    dlBwp->pdcch_Config->choice.setup = NULLP;
4221    DU_ALLOC(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
4222    if(!dlBwp->pdcch_Config->choice.setup)
4223    {
4224       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4225       return RFAILED;
4226    }
4227    if(BuildBWPDlDedPdcchCfg(pdcchCfg, dlBwp->pdcch_Config->choice.setup) != ROK)
4228    {
4229       return RFAILED;
4230    }
4231
4232    dlBwp->pdsch_Config = NULLP;
4233    DU_ALLOC(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
4234    if(!dlBwp->pdsch_Config)
4235    {
4236       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4237       return RFAILED;
4238    }
4239    dlBwp->pdsch_Config->present = BWP_DownlinkDedicated__pdsch_Config_PR_setup;
4240
4241    dlBwp->pdsch_Config->choice.setup = NULLP;
4242    DU_ALLOC(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
4243    if(!dlBwp->pdsch_Config->choice.setup)
4244    {
4245       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4246       return RFAILED;
4247    }
4248
4249    if(BuildBWPDlDedPdschCfg(pdschCfg, dlBwp->pdsch_Config->choice.setup) != ROK)
4250    {
4251       return RFAILED;
4252    }
4253
4254    dlBwp->sps_Config = NULLP;
4255    dlBwp->radioLinkMonitoringConfig = NULLP; 
4256    return ROK;
4257 }
4258
4259 /*******************************************************************
4260  *
4261  * @brief Builds DMRS UL Pusch Mapping type A
4262  *
4263  * @details
4264  *
4265  *    Function : BuildDMRSULPuschMapTypeA
4266  *
4267  *    Functionality: Builds DMRS UL Pusch Mapping type A
4268  *
4269  * @params[in] 
4270  *    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg
4271  * @return ROK     - success
4272  *         RFAILED - failure
4273  *
4274  * ****************************************************************/
4275 uint8_t BuildDMRSULPuschMapTypeA(DmrsUlCfg *ulDmrsCfgDb, struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg)
4276 {
4277    dmrsUlCfg->present = PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup;
4278    dmrsUlCfg->choice.setup= NULLP;
4279    DU_ALLOC(dmrsUlCfg->choice.setup, sizeof(DMRS_UplinkConfig_t));
4280    if(!dmrsUlCfg->choice.setup)
4281    {
4282       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4283       return RFAILED;
4284    }
4285
4286    dmrsUlCfg->choice.setup->dmrs_Type = NULLP;
4287    dmrsUlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4288    DU_ALLOC(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4289    if(!dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
4290    {
4291       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4292       return RFAILED;
4293    }
4294    if(ulDmrsCfgDb == NULLP)
4295       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS; 
4296    else
4297       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = ulDmrsCfgDb->addPos;
4298
4299    dmrsUlCfg->choice.setup->phaseTrackingRS = NULLP;
4300    dmrsUlCfg->choice.setup->maxLength = NULLP;
4301    dmrsUlCfg->choice.setup->transformPrecodingDisabled = NULLP;
4302    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled, sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
4303    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled)
4304    {
4305       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4306       return RFAILED;
4307    }
4308
4309    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0 = NULLP;
4310    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
4311          sizeof(long));
4312    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0)
4313    {
4314       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4315       return RFAILED;
4316    }
4317    if(ulDmrsCfgDb == NULLP)
4318       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = SCRAMBLING_ID;
4319    else
4320       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = ulDmrsCfgDb->transPrecodDisabled.scramblingId0;
4321
4322    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID1 = NULLP;
4323    dmrsUlCfg->choice.setup->transformPrecodingEnabled = NULLP;
4324    return ROK;
4325 }
4326
4327 /*******************************************************************
4328  *
4329  * @brief Build PUSCH time domain allocation list
4330  *
4331  * @details
4332  *
4333  *    Function : BuildPuschTimeDomAllocList
4334  *
4335  *    Functionality: Build PUSCH time domain allocation list
4336  *
4337  * @params[in] 
4338  * struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList
4339  *
4340  * @return ROK     - success
4341  *         RFAILED - failure
4342  *
4343  * ****************************************************************/
4344 uint8_t BuildPuschTimeDomAllocList(PuschCfg *puschCfgDb, struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList)
4345 {
4346    uint8_t idx;
4347    uint8_t elementCnt;
4348    PUSCH_TimeDomainResourceAllocation_t  *timeDomAlloc;
4349
4350    timeDomAllocList->present = PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup;
4351    timeDomAllocList->choice.setup = NULLP;
4352    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PUSCH_TimeDomainResourceAllocationList));
4353    if(!timeDomAllocList->choice.setup)
4354    {
4355       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4356       return RFAILED;
4357    }
4358
4359    if(puschCfgDb == NULLP)
4360       elementCnt = 2;
4361    else
4362       elementCnt = puschCfgDb->numTimeDomRsrcAlloc;
4363
4364    timeDomAllocList->choice.setup->list.count = elementCnt;
4365    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(PUSCH_TimeDomainResourceAllocation_t *);
4366    timeDomAllocList->choice.setup->list.array = NULLP;
4367    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4368    if(!timeDomAllocList->choice.setup->list.array)
4369    {
4370       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4371       return RFAILED;
4372    }
4373
4374    for(idx = 0; idx < elementCnt; idx++)
4375    {
4376       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4377       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], sizeof(PUSCH_TimeDomainResourceAllocation_t));
4378       if(!timeDomAllocList->choice.setup->list.array[idx])
4379       {
4380          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4381          return RFAILED;
4382       }
4383    }
4384
4385    for(idx = 0; idx < elementCnt; idx++)
4386    {
4387       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4388       DU_ALLOC(timeDomAlloc->k2, sizeof(long));
4389       if(!timeDomAlloc->k2)
4390       {
4391          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4392          return RFAILED;
4393       }
4394       if(puschCfgDb == NULLP)
4395       {
4396          if(idx == 0)
4397             *(timeDomAlloc->k2) = PUSCH_K2_CFG1;
4398          else if(idx == 1)
4399             *(timeDomAlloc->k2) = PUSCH_K2_CFG2;
4400
4401          timeDomAlloc->mappingType = PUSCH_MAPPING_TYPE_A;
4402          timeDomAlloc->startSymbolAndLength = calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
4403       }
4404       else
4405       {
4406          *(timeDomAlloc->k2) = puschCfgDb->timeDomRsrcAllocList[idx].k2;
4407          timeDomAlloc->mappingType = puschCfgDb->timeDomRsrcAllocList[idx].mappingType;
4408          timeDomAlloc->startSymbolAndLength = puschCfgDb->timeDomRsrcAllocList[idx].startSymbolAndLength;
4409       }
4410    }
4411
4412    return ROK;
4413 }
4414
4415 /*******************************************************************
4416  *
4417  * @brief Builds BWP UL dedicated PUSCH Config
4418  *
4419  * @details
4420  *
4421  *    Function : BuildBWPUlDedPuschCfg
4422  *
4423  *    Functionality:
4424  *      Builds BWP UL dedicated PUSCH Config
4425  *
4426  * @params[in] : PUSCH_Config_t *puschCfg
4427  *    
4428  * @return ROK     - success
4429  *         RFAILED - failure
4430  *
4431  * ****************************************************************/
4432 uint8_t BuildBWPUlDedPuschCfg(PuschCfg *puschCfgDb, PUSCH_Config_t *puschCfg)
4433 {
4434    DmrsUlCfg *ulDmrsCfg = NULLP;
4435    
4436    if(puschCfgDb)
4437       ulDmrsCfg = &puschCfgDb->dmrsUlCfgForPuschMapTypeA;
4438
4439    puschCfg->dataScramblingIdentityPUSCH = NULLP;
4440    DU_ALLOC(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
4441    if(!puschCfg->dataScramblingIdentityPUSCH)
4442    {
4443       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4444       return RFAILED;
4445    }
4446    if(puschCfgDb == NULLP)
4447       *(puschCfg->dataScramblingIdentityPUSCH) = SCRAMBLING_ID;
4448    else
4449       *(puschCfg->dataScramblingIdentityPUSCH) = puschCfgDb->dataScramblingId;
4450
4451    puschCfg->txConfig = NULLP;
4452    puschCfg->dmrs_UplinkForPUSCH_MappingTypeA = NULLP;
4453    DU_ALLOC(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
4454    if(!puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
4455    {
4456       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4457       return RFAILED;
4458    }
4459
4460    if(BuildDMRSULPuschMapTypeA(ulDmrsCfg, puschCfg->dmrs_UplinkForPUSCH_MappingTypeA) != ROK)
4461    {
4462       return RFAILED;
4463    }
4464
4465    puschCfg->dmrs_UplinkForPUSCH_MappingTypeB = NULLP;
4466    puschCfg->pusch_PowerControl = NULLP;
4467    puschCfg->frequencyHopping = NULLP;
4468    puschCfg->frequencyHoppingOffsetLists = NULLP;
4469
4470    if(puschCfgDb == NULLP)
4471       puschCfg->resourceAllocation = RES_ALLOC_TYPE;
4472    else
4473       puschCfg->resourceAllocation = puschCfgDb->resourceAllocType;
4474
4475    puschCfg->pusch_TimeDomainAllocationList = NULLP;
4476    DU_ALLOC(puschCfg->pusch_TimeDomainAllocationList, sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
4477    if(!puschCfg->pusch_TimeDomainAllocationList)
4478    {
4479       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4480       return RFAILED;
4481    }
4482
4483    if(BuildPuschTimeDomAllocList(puschCfgDb, puschCfg->pusch_TimeDomainAllocationList) != ROK)
4484    {
4485       return RFAILED;
4486    }
4487
4488    puschCfg->pusch_AggregationFactor = NULLP;
4489    puschCfg->mcs_Table = NULLP;
4490    puschCfg->mcs_TableTransformPrecoder = NULLP;
4491    puschCfg->transformPrecoder = NULLP;
4492    DU_ALLOC(puschCfg->transformPrecoder, sizeof(long));
4493    if(!puschCfg->transformPrecoder)
4494    {
4495       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4496       return RFAILED;
4497    }
4498    if(puschCfgDb == NULLP)
4499       *(puschCfg->transformPrecoder) = PUSCH_TRANSFORM_PRECODER;
4500    else
4501       *(puschCfg->transformPrecoder) = puschCfgDb->transformPrecoder;
4502
4503    puschCfg->codebookSubset = NULLP;
4504    puschCfg->maxRank = NULLP;
4505    puschCfg->rbg_Size = NULLP;
4506    puschCfg->uci_OnPUSCH = NULLP;
4507    puschCfg->tp_pi2BPSK = NULLP;
4508
4509    return ROK;
4510 }
4511
4512 /*******************************************************************
4513  *
4514  * @brief Builds PUCCH resource set add/modify list
4515  *
4516  * @details
4517  *
4518  *    Function : BuildPucchRsrcSetAddModList
4519  *
4520  *    Functionality:
4521  *      Builds PUCCH resource set add/modify list
4522  *
4523  * @params[in] : PucchResrcSetCfg *rsrcSetCfgDb
4524  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4525  *
4526  * @return ROK     - success
4527  *         RFAILED - failure
4528  *
4529  * ****************************************************************/
4530 uint8_t BuildPucchRsrcSetAddModList(PucchResrcSetCfg *rsrcSetCfgDb, \
4531    struct PUCCH_Config__resourceSetToAddModList *resourceSetToAddModList)
4532 {
4533    uint8_t elementCnt = 0, rsrcSetIdx = 0, rsrcIdx = 0;
4534    PUCCH_ResourceSet_t *rsrcSet = NULLP;
4535
4536    if(rsrcSetCfgDb == NULLP)
4537       elementCnt = 1;
4538    else
4539       elementCnt = rsrcSetCfgDb->resrcSetToAddModListCount;
4540
4541    resourceSetToAddModList->list.count = elementCnt;
4542    resourceSetToAddModList->list.size = elementCnt * sizeof(PUCCH_ResourceSet_t *);
4543    DU_ALLOC(resourceSetToAddModList->list.array, resourceSetToAddModList->list.size);
4544    if(resourceSetToAddModList->list.array == NULLP)
4545    {
4546       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4547       return RFAILED;
4548    }
4549    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4550    {
4551       DU_ALLOC(resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
4552       if(resourceSetToAddModList->list.array[rsrcSetIdx] == NULLP)
4553       {
4554          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4555          return RFAILED;
4556       }
4557    }
4558
4559    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4560    {
4561       rsrcSet = resourceSetToAddModList->list.array[rsrcSetIdx];
4562
4563       /* Resource set Id */
4564       if(rsrcSetCfgDb == NULLP)
4565          rsrcSet->pucch_ResourceSetId = 1;
4566       else
4567          rsrcSet->pucch_ResourceSetId = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcSetId;
4568  
4569       /* Resource list of a resource set */
4570       if(rsrcSetCfgDb == NULLP)
4571          elementCnt = 1;
4572       else
4573          elementCnt = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcListCount;
4574       rsrcSet->resourceList.list.count = elementCnt;
4575       rsrcSet->resourceList.list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
4576       DU_ALLOC(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
4577       if(rsrcSet->resourceList.list.array == NULLP)
4578       {
4579          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4580          return RFAILED;
4581       }
4582
4583       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4584       {
4585          DU_ALLOC(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
4586          if(rsrcSet->resourceList.list.array[rsrcIdx] == NULLP)
4587          {
4588             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4589             return RFAILED;
4590          }
4591       }
4592       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4593       {
4594          if(rsrcSetCfgDb == NULLP)
4595             *(rsrcSet->resourceList.list.array[rsrcIdx]) = 1;
4596          else
4597             *(rsrcSet->resourceList.list.array[rsrcIdx]) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcList[rsrcIdx];
4598       }
4599
4600       /* Max payload size (minus 1) in a Resource set */
4601       rsrcSet->maxPayloadMinus1 = NULLP;
4602       if(rsrcSetCfgDb && rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize)
4603       {
4604          DU_ALLOC(rsrcSet->maxPayloadMinus1, sizeof(long));
4605          if(rsrcSet->maxPayloadMinus1 == NULLP)
4606          {
4607             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4608             return RFAILED;
4609          }
4610          *(rsrcSet->maxPayloadMinus1) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize;
4611       }
4612    }
4613    return ROK;
4614 }
4615
4616 /*******************************************************************
4617  *
4618  * @brief Builds PUCCH resource add/modify list
4619  *
4620  * @details
4621  *
4622  *    Function : BuildPucchRsrcAdddModList
4623  *
4624  *    Functionality:
4625  *      Builds PUCCH resource add/modify list
4626  *
4627  * @params[in] : PucchResrcCfg *rsrcSetCfgDb
4628  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4629  *
4630  * @return ROK     - success
4631  *         RFAILED - failure
4632  *
4633  * ****************************************************************/
4634 uint8_t BuildPucchRsrcAddModList(PucchResrcCfg *rsrcCfgDb, struct PUCCH_Config__resourceToAddModList  *resourceToAddModList)
4635 {
4636    uint8_t elementCnt = 0, rsrcIdx = 0;
4637    PUCCH_Resource_t *rsrc = NULLP;
4638
4639    if(rsrcCfgDb == NULLP)
4640       elementCnt = 1;
4641    else
4642       elementCnt = rsrcCfgDb->resrcToAddModListCount;
4643    resourceToAddModList->list.count = elementCnt;
4644    resourceToAddModList->list.size = elementCnt * sizeof(PUCCH_Resource_t *);
4645    DU_ALLOC(resourceToAddModList->list.array, resourceToAddModList->list.size);
4646    if(resourceToAddModList->list.array == NULLP)
4647    {
4648       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4649       return RFAILED;
4650    }
4651    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4652    {
4653       DU_ALLOC(resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
4654       if(resourceToAddModList->list.array[rsrcIdx] == NULLP)
4655       {
4656          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4657          return RFAILED;
4658       }
4659    }
4660
4661    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4662    {
4663       rsrc = resourceToAddModList->list.array[rsrcIdx];
4664
4665       if(rsrcCfgDb == NULLP)
4666       {
4667          rsrc->pucch_ResourceId = 1;
4668          rsrc->startingPRB = 0;
4669          rsrc->format.present = PUCCH_Resource__format_PR_format1; 
4670          DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4671          if(rsrc->format.choice.format1 == NULLP)
4672          {
4673             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4674             return RFAILED;
4675          }  
4676          rsrc->format.choice.format1->initialCyclicShift = 0;
4677          rsrc->format.choice.format1->nrofSymbols = 4;
4678          rsrc->format.choice.format1->startingSymbolIndex = 0;
4679          rsrc->format.choice.format1->timeDomainOCC = 0;
4680       }
4681       else
4682       {
4683          rsrc->pucch_ResourceId = rsrcCfgDb->resrcToAddModList[rsrcIdx].resrcId;
4684          rsrc->startingPRB = rsrcCfgDb->resrcToAddModList[rsrcIdx].startPrb;
4685          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop)
4686          {
4687             DU_ALLOC(rsrc->intraSlotFrequencyHopping, sizeof(long));
4688             if(rsrc->intraSlotFrequencyHopping == NULLP)
4689             {
4690                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4691                return RFAILED;
4692             }
4693             *(rsrc->intraSlotFrequencyHopping) = rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop;
4694          }
4695          else
4696             rsrc->intraSlotFrequencyHopping = NULLP;
4697
4698          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop)
4699          {
4700             DU_ALLOC(rsrc->secondHopPRB, sizeof(PRB_Id_t));
4701             if(rsrc->secondHopPRB == NULLP)
4702             {
4703                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4704                return RFAILED;
4705             }
4706             *(rsrc->secondHopPRB) = rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop;
4707          }
4708          else
4709             rsrc->secondHopPRB = NULLP;
4710          rsrc->format.present = covertPucchFormatIntEnumToRrcEnum(rsrcCfgDb->resrcToAddModList[rsrcIdx].pucchFormat); 
4711
4712          switch(rsrc->format.present)
4713          {
4714             case PUCCH_Resource__format_PR_NOTHING:
4715                break;
4716             case PUCCH_Resource__format_PR_format0:
4717                {
4718                   DU_ALLOC(rsrc->format.choice.format0, sizeof(PUCCH_format0_t));
4719                   if(rsrc->format.choice.format0 == NULLP)
4720                   {
4721                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4722                      return RFAILED;
4723                   }
4724                   rsrc->format.choice.format0->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->initialCyclicShift;
4725                   rsrc->format.choice.format0->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->numSymbols;
4726                   rsrc->format.choice.format0->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->startSymbolIdx;
4727                   break;
4728                }
4729
4730             case PUCCH_Resource__format_PR_format1:
4731                {
4732                   DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4733                   if(rsrc->format.choice.format1 == NULLP)
4734                   {
4735                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4736                      return RFAILED;
4737                   }  
4738                   rsrc->format.choice.format1->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->initialCyclicShift;
4739                   rsrc->format.choice.format1->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->numSymbols;
4740                   rsrc->format.choice.format1->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->startSymbolIdx;
4741                   rsrc->format.choice.format1->timeDomainOCC = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->timeDomOCC;
4742                   break;
4743                }
4744
4745             case PUCCH_Resource__format_PR_format2:
4746                {
4747                   DU_ALLOC(rsrc->format.choice.format2, sizeof(PUCCH_format2_t));
4748                   if(rsrc->format.choice.format2 == NULLP)
4749                   {
4750                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4751                      return RFAILED;
4752                   } 
4753                   rsrc->format.choice.format2->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numPrbs;
4754                   rsrc->format.choice.format2->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numSymbols;
4755                   rsrc->format.choice.format2->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->startSymbolIdx;
4756                   break;
4757                }
4758
4759             case PUCCH_Resource__format_PR_format3:
4760                {
4761                   DU_ALLOC(rsrc->format.choice.format3, sizeof(PUCCH_format3_t));
4762                   if(rsrc->format.choice.format3 == NULLP)
4763                   {
4764                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4765                      return RFAILED;
4766                   }
4767                   rsrc->format.choice.format3->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numPrbs;
4768                   rsrc->format.choice.format3->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numSymbols;
4769                   rsrc->format.choice.format3->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->startSymbolIdx;
4770                   break;
4771                }
4772
4773             case PUCCH_Resource__format_PR_format4:
4774                {
4775                   DU_ALLOC(rsrc->format.choice.format4, sizeof(PUCCH_format4_t));
4776                   if(rsrc->format.choice.format4 == NULLP)
4777                   {
4778                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4779                      return RFAILED;
4780                   }
4781                   rsrc->format.choice.format4->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->numSymbols;
4782                   rsrc->format.choice.format4->occ_Length = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occLen;
4783                   rsrc->format.choice.format4->occ_Index = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occIdx;
4784                   rsrc->format.choice.format4->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->startSymbolIdx;
4785                   break;
4786                }
4787          }
4788       }
4789    }
4790    return ROK;
4791 }
4792
4793 /*******************************************************************
4794  *
4795  * @brief Builds PUCCH format  config
4796  *
4797  * @details
4798  *
4799  *    Function : BuildPucchFormat
4800  *
4801  *    Functionality: Builds PUCCH format  config
4802  *
4803  * @params[in] : PucchFormatCfg *formatDb
4804  *               PUCCH_FormatConfig_t *format
4805  *
4806  * @return ROK     - success
4807  *         RFAILED - failure
4808  *
4809  * ****************************************************************/
4810 uint8_t BuildPucchFormat(PucchFormatCfg *formatDb, PUCCH_FormatConfig_t *format)
4811 {
4812    /* Inter Slot Fequency hopping */
4813    format->interslotFrequencyHopping = NULLP;
4814    if((formatDb != NULLP) && (formatDb->interSlotFreqHop == true))
4815    {
4816       DU_ALLOC(format->interslotFrequencyHopping, sizeof(long));
4817       if(format->interslotFrequencyHopping)
4818       {
4819          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4820          return RFAILED;
4821       }
4822       *(format->interslotFrequencyHopping) = PUCCH_FormatConfig__interslotFrequencyHopping_enabled;
4823    }
4824
4825    /* Additional DMRS */
4826    format->additionalDMRS = NULLP;
4827    if((formatDb != NULLP) && (formatDb->addDmrs == true))
4828    {
4829       DU_ALLOC(format->additionalDMRS, sizeof(long));
4830       if(format->additionalDMRS)
4831       {
4832          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4833          return RFAILED;
4834       }
4835       *(format->additionalDMRS) = PUCCH_FormatConfig__additionalDMRS_true;
4836    }
4837
4838     /* Maximum code rate */
4839    format->maxCodeRate = NULLP;
4840    if((formatDb != NULLP) && (formatDb->maxCodeRate != 0))
4841    {
4842       DU_ALLOC(format->maxCodeRate, sizeof(long));
4843       if(format->maxCodeRate)
4844       {
4845          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4846          return RFAILED;
4847       }  
4848       *(format->maxCodeRate) = formatDb->maxCodeRate;
4849    }
4850  
4851    /* Number of slots */
4852    format->nrofSlots = NULLP;
4853    if((formatDb == NULLP) || ((formatDb != NULLP) && (formatDb->numSlots != 0)))
4854    {
4855       DU_ALLOC(format->nrofSlots, sizeof(long));
4856       if(format->nrofSlots == NULLP)
4857       {
4858          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4859          return RFAILED;
4860       }
4861       if(formatDb == NULLP)
4862          *(format->nrofSlots) = PUCCH_FormatConfig__nrofSlots_n4;
4863       else
4864          *(format->nrofSlots) = formatDb->numSlots;
4865    }
4866
4867    /* Pi2BPSK*/
4868    format->pi2BPSK = NULLP;
4869    if((formatDb != NULLP) && (formatDb->pi2BPSK == true))
4870    {
4871       DU_ALLOC(format->pi2BPSK, sizeof(long));
4872       if(format->pi2BPSK)
4873       {     
4874          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4875          return RFAILED;
4876       }     
4877       *(format->pi2BPSK) = PUCCH_FormatConfig__pi2BPSK_enabled;
4878    }
4879
4880    /* Simultaneous HARQ ACK and CSI */
4881    format->simultaneousHARQ_ACK_CSI = NULLP;
4882    if((formatDb != NULLP) && (formatDb->harqAckCSI == true))
4883    {
4884       DU_ALLOC(format->simultaneousHARQ_ACK_CSI, sizeof(long));
4885       if(format->simultaneousHARQ_ACK_CSI)
4886       {     
4887          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4888          return RFAILED;
4889       }     
4890       *(format->simultaneousHARQ_ACK_CSI) = PUCCH_FormatConfig__simultaneousHARQ_ACK_CSI_true;
4891    }
4892
4893    return ROK;
4894 }
4895
4896
4897 /*******************************************************************
4898  *
4899  * @brief Builds PUCCH scheduling request list
4900  *
4901  * @details
4902  *
4903  *    Function : BuildPucchSchReqAddModList
4904  *
4905  *    Functionality:
4906  *      Builds PUCCH scheduling request list
4907  *
4908  * @params[in] : PucchSchedReqCfg *schReqDb
4909  *               struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList
4910  *
4911  * @return ROK     - success
4912  *         RFAILED - failure
4913  *
4914  * ****************************************************************/
4915 uint8_t BuildPucchSchReqAddModList(PucchSchedReqCfg *schReqDb, \
4916    struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList)
4917 {
4918    uint8_t elementCnt = 0, schReqIdx = 0;
4919    SchedulingRequestResourceConfig_t *schReqRsrc;
4920
4921    elementCnt = schReqDb->schedAddModListCount;
4922    schReqRsrcToAddModList->list.count = elementCnt;
4923    schReqRsrcToAddModList->list.size = elementCnt *sizeof(struct SchedulingRequestResourceConfig *);
4924
4925    schReqRsrcToAddModList->list.array = NULLP;
4926    DU_ALLOC(schReqRsrcToAddModList->list.array, schReqRsrcToAddModList->list.size);
4927    if(schReqRsrcToAddModList->list.array == NULLP)
4928    {
4929       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
4930       return RFAILED;
4931    }
4932
4933    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
4934    {
4935       DU_ALLOC(schReqRsrcToAddModList->list.array[schReqIdx], schReqRsrcToAddModList->list.size);
4936       if(schReqRsrcToAddModList->list.array[schReqIdx] == NULLP)
4937       {
4938          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
4939          return RFAILED;
4940       }
4941    }
4942
4943    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
4944    {
4945       schReqRsrc = schReqRsrcToAddModList->list.array[schReqIdx];
4946       schReqRsrc->schedulingRequestResourceId = schReqDb->schedAddModList[schReqIdx].resrcId;
4947       schReqRsrc->schedulingRequestID = schReqDb->schedAddModList[schReqIdx].requestId;
4948
4949       if(schReqDb->schedAddModList[schReqIdx].periodicity)
4950       {
4951          schReqRsrc->periodicityAndOffset = NULLP;
4952          DU_ALLOC(schReqRsrc->periodicityAndOffset, sizeof(struct SchedulingRequestResourceConfig__periodicityAndOffset));
4953          if(schReqRsrc->periodicityAndOffset == NULLP)
4954          {
4955             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
4956             return RFAILED;
4957          }
4958
4959          schReqRsrc->periodicityAndOffset->present = schReqDb->schedAddModList[schReqIdx].periodicity;
4960          switch(schReqRsrc->periodicityAndOffset->present)
4961          {
4962             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_NOTHING:
4963                break;
4964             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
4965                schReqRsrc->periodicityAndOffset->choice.sym2 = schReqDb->schedAddModList[schReqIdx].offset;
4966                break;
4967             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
4968                schReqRsrc->periodicityAndOffset->choice.sym6or7 = schReqDb->schedAddModList[schReqIdx].offset;
4969                break;
4970             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
4971                schReqRsrc->periodicityAndOffset->choice.sl1 = schReqDb->schedAddModList[schReqIdx].offset;
4972                break;
4973             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
4974                schReqRsrc->periodicityAndOffset->choice.sl2 = schReqDb->schedAddModList[schReqIdx].offset;
4975                break;
4976             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
4977                schReqRsrc->periodicityAndOffset->choice.sl4 = schReqDb->schedAddModList[schReqIdx].offset;
4978                break;
4979             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
4980                schReqRsrc->periodicityAndOffset->choice.sl5 = schReqDb->schedAddModList[schReqIdx].offset;
4981                break;
4982             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
4983                schReqRsrc->periodicityAndOffset->choice.sl8 = schReqDb->schedAddModList[schReqIdx].offset;
4984                break;
4985             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
4986                schReqRsrc->periodicityAndOffset->choice.sl10 = schReqDb->schedAddModList[schReqIdx].offset;
4987                break;
4988             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
4989                schReqRsrc->periodicityAndOffset->choice.sl16 = schReqDb->schedAddModList[schReqIdx].offset;
4990                break;
4991             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
4992                schReqRsrc->periodicityAndOffset->choice.sl20 = schReqDb->schedAddModList[schReqIdx].offset;
4993                break;
4994             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
4995                schReqRsrc->periodicityAndOffset->choice.sl40 = schReqDb->schedAddModList[schReqIdx].offset;
4996                break;
4997             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
4998                schReqRsrc->periodicityAndOffset->choice.sl80 = schReqDb->schedAddModList[schReqIdx].offset;
4999                break;
5000             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
5001                schReqRsrc->periodicityAndOffset->choice.sl160 = schReqDb->schedAddModList[schReqIdx].offset;
5002                break;
5003             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
5004                schReqRsrc->periodicityAndOffset->choice.sl320 = schReqDb->schedAddModList[schReqIdx].offset;
5005                break;
5006             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
5007                schReqRsrc->periodicityAndOffset->choice.sl640 = schReqDb->schedAddModList[schReqIdx].offset;
5008                break;
5009          }
5010       }
5011
5012       if(schReqDb->schedAddModList[schReqIdx].resrc)
5013       {
5014          schReqRsrc->resource = NULLP;
5015          DU_ALLOC(schReqRsrc->resource, sizeof(PUCCH_ResourceId_t));
5016          if(schReqRsrc->resource == NULLP)
5017          {
5018             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5019             return RFAILED;
5020          }
5021          *(schReqRsrc->resource) = schReqDb->schedAddModList[schReqIdx].resrc;
5022
5023       }
5024    }
5025    return ROK;
5026 }
5027
5028 /*******************************************************************
5029  *
5030  * @brief Builds PUCCH multi csi resource list
5031  *
5032  * @details
5033  *
5034  *    Function : BuildPucchMultiCsiRsrcList
5035  *
5036  *    Functionality:
5037  *      Builds PUCCH multi csi resource list
5038  *
5039  * @params[in] : PucchMultiCsiCfg *multiCsiDb
5040  *               struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList
5041  *
5042  * @return ROK     - success
5043  *         RFAILED - failure
5044  *
5045  * ****************************************************************/
5046 uint8_t BuildPucchMultiCsiRsrcList(PucchMultiCsiCfg *multiCsiDb, struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList)
5047 {
5048    uint8_t elementCnt = 0, rsrcIdx = 0;
5049
5050    elementCnt = multiCsiDb->multiCsiResrcListCount;
5051    multiCsiRsrcList->list.count = elementCnt;
5052    multiCsiRsrcList->list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
5053    multiCsiRsrcList->list.array = NULLP;
5054    DU_ALLOC(multiCsiRsrcList->list.array, multiCsiRsrcList->list.size);
5055    if(multiCsiRsrcList->list.array == NULLP)
5056    {
5057       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5058       return RFAILED;
5059    }
5060
5061    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5062    {
5063       DU_ALLOC(multiCsiRsrcList->list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
5064       if(multiCsiRsrcList->list.array[rsrcIdx] == NULLP)
5065       {
5066          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5067          return RFAILED;
5068       }
5069    }
5070
5071    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5072    {
5073       *(multiCsiRsrcList->list.array[rsrcIdx]) = multiCsiDb->multiCsiResrcList[rsrcIdx];
5074    }
5075    return ROK;
5076 }
5077
5078 /*******************************************************************
5079  *
5080  * @brief Builds DL data -to- Ul Ack list
5081  *
5082  * @details
5083  *
5084  *    Function : BuildDlDataToUlAckList
5085  *
5086  *    Functionality: Builds DL data -to- Ul Ack list
5087  *
5088  * @params[in] : PucchDlDataToUlAck *dlDataToUlAckDb
5089  *               struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList
5090  *
5091  * @return ROK     - success
5092  *         RFAILED - failure
5093  *
5094  * ****************************************************************/
5095 uint8_t BuildDlDataToUlAckList(PucchDlDataToUlAck *dlDataToUlAckDb, struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList)
5096 {
5097    uint8_t elementCnt = 0, arrIdx = 0;
5098
5099    if(dlDataToUlAckDb == NULLP)
5100       elementCnt = 2;
5101    else
5102       elementCnt = dlDataToUlAckDb->dlDataToUlAckListCount;
5103
5104    dlDataToUlACKList->list.count = elementCnt;
5105    dlDataToUlACKList->list.size = elementCnt * sizeof(long *);
5106    DU_ALLOC(dlDataToUlACKList->list.array, dlDataToUlACKList->list.size);
5107    if(dlDataToUlACKList->list.array == NULLP)
5108    {
5109       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5110       return RFAILED;
5111    }   
5112
5113    for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5114    {
5115       DU_ALLOC(dlDataToUlACKList->list.array[arrIdx], sizeof(long));
5116       if(dlDataToUlACKList->list.array[arrIdx] == NULLP)
5117       {
5118          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5119          return RFAILED;
5120       }   
5121    }
5122
5123    if(dlDataToUlAckDb == NULLP)
5124    {
5125       arrIdx = 0;
5126       *(dlDataToUlACKList->list.array[arrIdx++]) = 1;
5127       *(dlDataToUlACKList->list.array[arrIdx]) = 2;
5128    }
5129    else
5130    {
5131       for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5132       {
5133          *(dlDataToUlACKList->list.array[arrIdx]) = dlDataToUlAckDb->dlDataToUlAckList[arrIdx];
5134       }
5135    }
5136    return ROK;
5137 }
5138
5139 /*******************************************************************
5140  *
5141  * @brief Builds BWP UL dedicated PUCCH Config
5142  *
5143  * @details
5144  *
5145  *    Function : BuildBWPUlDedPucchCfg
5146  *
5147  *    Functionality:
5148  *      Builds BWP UL dedicated PUCCH Config
5149  *
5150  * @params[in] : PUCCH_Config_t *pucchCfg
5151  *
5152  * @return ROK     - success
5153  *         RFAILED - failure
5154  *
5155  * ****************************************************************/
5156 uint8_t BuildBWPUlDedPucchCfg(PucchCfg *pucchCfgDb, PUCCH_Config_t *pucchCfg)
5157 {
5158    PucchResrcSetCfg *rsrcSetCfgDb = NULLP;
5159    PucchResrcCfg *rsrcCfgDb = NULLP;
5160    PucchFormatCfg *format1Db = NULLP;
5161    PucchFormatCfg *format2Db = NULLP;
5162    PucchFormatCfg *format3Db = NULLP;
5163    PucchFormatCfg *format4Db = NULLP;
5164    PucchSchedReqCfg *schReqDb = NULLP;   
5165    PucchMultiCsiCfg  *multiCsiDb = NULLP;
5166    PucchDlDataToUlAck *dlDataToUlAckDb = NULLP;
5167
5168    if(pucchCfgDb)
5169    {
5170       rsrcSetCfgDb = pucchCfgDb->resrcSet;
5171       rsrcCfgDb = pucchCfgDb->resrc;
5172       format1Db = pucchCfgDb->format1;
5173       format2Db = pucchCfgDb->format2;
5174       format3Db = pucchCfgDb->format3;
5175       format4Db = pucchCfgDb->format4;
5176       schReqDb = pucchCfgDb->schedReq;
5177       multiCsiDb = pucchCfgDb->multiCsiCfg;
5178       dlDataToUlAckDb = pucchCfgDb->dlDataToUlAck;
5179    }
5180
5181    /* RESOURCE SET */
5182    DU_ALLOC(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
5183    if(pucchCfg->resourceSetToAddModList == NULL)
5184    {
5185       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5186       return RFAILED;
5187    }
5188
5189    if(BuildPucchRsrcSetAddModList(rsrcSetCfgDb, pucchCfg->resourceSetToAddModList) != ROK)
5190    {
5191       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5192       return RFAILED;
5193    }
5194
5195    /* PUCCH RESOURCE */
5196    DU_ALLOC(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
5197    if(pucchCfg->resourceToAddModList == NULLP)
5198    {
5199       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5200       return RFAILED;
5201    }
5202
5203    if(BuildPucchRsrcAddModList(rsrcCfgDb, pucchCfg->resourceToAddModList) != ROK)
5204    {
5205       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5206       return RFAILED;
5207    }
5208
5209    /* PUCCH Format 1 */
5210    DU_ALLOC(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
5211    if(pucchCfg->format1 == NULLP)
5212    {
5213       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5214       return RFAILED;
5215    }
5216    
5217    pucchCfg->format1->present = PUCCH_Config__format1_PR_setup;
5218    DU_ALLOC(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
5219    if(pucchCfg->format1->choice.setup == NULLP)
5220    {
5221       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5222       return RFAILED;
5223    }
5224
5225    if(BuildPucchFormat(format1Db, pucchCfg->format1->choice.setup) != ROK)
5226    {
5227       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5228       return RFAILED;
5229    }
5230
5231    /* PUCCH Format 2 */
5232    if(format2Db)
5233    {
5234       DU_ALLOC(pucchCfg->format2, sizeof(struct PUCCH_Config__format2));
5235       if(pucchCfg->format2 == NULLP)
5236       {
5237          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5238          return RFAILED;
5239       }
5240
5241       pucchCfg->format2->present = PUCCH_Config__format2_PR_setup;
5242       DU_ALLOC(pucchCfg->format2->choice.setup, sizeof(PUCCH_FormatConfig_t));
5243       if(pucchCfg->format2->choice.setup == NULLP)
5244       {
5245          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5246          return RFAILED;
5247       }
5248
5249       if(BuildPucchFormat(format2Db, pucchCfg->format2->choice.setup) != ROK)
5250       {
5251          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5252          return RFAILED;
5253       }
5254    }
5255
5256    /* PUCCH Format 3 */
5257    if(format3Db)
5258    {
5259       DU_ALLOC(pucchCfg->format3, sizeof(struct PUCCH_Config__format3));
5260       if(pucchCfg->format3 == NULLP)
5261       {
5262          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5263          return RFAILED;
5264       }
5265
5266       pucchCfg->format3->present = PUCCH_Config__format3_PR_setup;
5267       DU_ALLOC(pucchCfg->format3->choice.setup, sizeof(PUCCH_FormatConfig_t));
5268       if(pucchCfg->format3->choice.setup == NULLP)
5269       {
5270          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5271          return RFAILED;
5272       }
5273
5274       if(BuildPucchFormat(format3Db, pucchCfg->format3->choice.setup) != ROK)
5275       {
5276          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5277          return RFAILED;
5278       }
5279    }
5280
5281    /* PUCCH Format 4 */
5282    if(format4Db)
5283    {
5284       DU_ALLOC(pucchCfg->format4, sizeof(struct PUCCH_Config__format4));
5285       if(pucchCfg->format4 == NULLP)
5286       {
5287          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5288          return RFAILED;
5289       }
5290
5291       pucchCfg->format4->present = PUCCH_Config__format4_PR_setup;
5292       DU_ALLOC(pucchCfg->format4->choice.setup, sizeof(PUCCH_FormatConfig_t));
5293       if(pucchCfg->format4->choice.setup == NULLP)
5294       {
5295          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5296          return RFAILED;
5297       }
5298
5299       if(BuildPucchFormat(format4Db, pucchCfg->format4->choice.setup) != ROK)
5300       {
5301          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5302          return RFAILED;
5303       }
5304    }
5305
5306    /* Scheduling Request */
5307    if(schReqDb && (schReqDb->schedAddModListCount != 0))
5308    {
5309       pucchCfg->schedulingRequestResourceToAddModList = NULLP;
5310       DU_ALLOC(pucchCfg->schedulingRequestResourceToAddModList, sizeof(struct PUCCH_Config__schedulingRequestResourceToAddModList));
5311       if(pucchCfg->schedulingRequestResourceToAddModList == NULLP)
5312       {
5313          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5314          return RFAILED;
5315       }
5316
5317       if(BuildPucchSchReqAddModList(schReqDb, pucchCfg->schedulingRequestResourceToAddModList) != ROK)
5318       {
5319          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5320          return RFAILED;
5321       }
5322    }
5323
5324    /* Multi CSI */
5325    if(multiCsiDb && (multiCsiDb->multiCsiResrcListCount != 0))
5326    {
5327       pucchCfg->multi_CSI_PUCCH_ResourceList = NULLP;
5328       DU_ALLOC(pucchCfg->multi_CSI_PUCCH_ResourceList, sizeof(struct PUCCH_Config__multi_CSI_PUCCH_ResourceList));
5329       if(pucchCfg->multi_CSI_PUCCH_ResourceList == NULLP)
5330       {
5331          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5332          return RFAILED;
5333       }
5334
5335       if(BuildPucchMultiCsiRsrcList(multiCsiDb, pucchCfg->multi_CSI_PUCCH_ResourceList) != ROK)
5336       {
5337          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5338          return RFAILED;
5339       }
5340    }
5341
5342    /* DL DATA TO UL ACK */
5343    DU_ALLOC(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
5344    if(pucchCfg->dl_DataToUL_ACK == NULLP)
5345    {
5346       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5347       return RFAILED;
5348    }
5349
5350    if(BuildDlDataToUlAckList(dlDataToUlAckDb, pucchCfg->dl_DataToUL_ACK) != ROK)
5351    {
5352       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5353       return RFAILED;
5354    }
5355    
5356    /* TODO : spatial relation info add/mod list and power control*/
5357
5358    return ROK;
5359 }
5360
5361 /*******************************************************************
5362  *
5363  * @brief Fills SRS resource to add/modify list 
5364  *
5365  * @details
5366  *
5367  *    Function : BuildSrsRsrcAddModList
5368  *
5369  *    Functionality: Fills SRS resource to add/modify list
5370  *
5371  * @params[in] 
5372  * @return ROK     - success
5373  *         RFAILED - failure
5374  *
5375  * ****************************************************************/
5376 uint8_t BuildSrsRsrcAddModList(struct SRS_Config__srs_ResourceToAddModList *resourceList)
5377 {
5378    uint8_t   elementCnt;
5379    uint8_t   rsrcIdx;
5380
5381    elementCnt = 1;
5382    resourceList->list.count = elementCnt;
5383    resourceList->list.size = elementCnt * sizeof(SRS_Resource_t *);
5384    resourceList->list.array = NULLP;
5385    DU_ALLOC(resourceList->list.array, resourceList->list.size);
5386    if(!resourceList->list.array)
5387    {
5388       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5389       return RFAILED;
5390    }
5391
5392    for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
5393    {
5394       DU_ALLOC(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
5395       if(!resourceList->list.array[rsrcIdx])
5396       {
5397          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5398          return RFAILED;
5399       }
5400    }
5401
5402    rsrcIdx = 0;
5403    resourceList->list.array[rsrcIdx]->srs_ResourceId = SRS_RSRC_ID;
5404    resourceList->list.array[rsrcIdx]->nrofSRS_Ports = SRS_Resource__nrofSRS_Ports_port1;
5405    resourceList->list.array[rsrcIdx]->transmissionComb.present = SRS_Resource__transmissionComb_PR_n2;
5406
5407    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2 = NULLP;
5408    DU_ALLOC(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2, \
5409          sizeof(struct SRS_Resource__transmissionComb__n2));
5410    if(!resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2)
5411    {
5412       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5413       return RFAILED;
5414    }
5415    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->combOffset_n2\
5416       = SRS_COMB_OFFSET_N2;
5417    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->cyclicShift_n2\
5418       = SRS_CYCLIC_SHIFT_N2;
5419
5420    resourceList->list.array[rsrcIdx]->resourceMapping.startPosition = \
5421                                                                       PUSCH_START_SYMBOL;
5422    resourceList->list.array[rsrcIdx]->resourceMapping.nrofSymbols =  \
5423                                                                      SRS_Resource__resourceMapping__nrofSymbols_n1;
5424    resourceList->list.array[rsrcIdx]->resourceMapping.repetitionFactor = \
5425                                                                          SRS_Resource__resourceMapping__repetitionFactor_n1;
5426
5427    resourceList->list.array[rsrcIdx]->freqDomainPosition = SRS_FREQ_DOM_POS;
5428    resourceList->list.array[rsrcIdx]->freqDomainShift = SRS_FREQ_DOM_SHIFT;
5429    resourceList->list.array[rsrcIdx]->freqHopping.c_SRS = C_SRS;
5430    resourceList->list.array[rsrcIdx]->freqHopping.b_SRS = B_SRS;
5431    resourceList->list.array[rsrcIdx]->freqHopping.b_hop = B_HOP;
5432    resourceList->list.array[rsrcIdx]->groupOrSequenceHopping = \
5433                                                                SRS_Resource__groupOrSequenceHopping_neither;
5434
5435    /* Setting resource type to aperiodic for intergration purposes */
5436    resourceList->list.array[rsrcIdx]->resourceType.present = \
5437                                                              SRS_Resource__resourceType_PR_aperiodic;
5438    resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic = NULLP;
5439    DU_ALLOC(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,
5440          sizeof(struct SRS_Resource__resourceType__aperiodic));
5441    if(!resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic)
5442    {
5443       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5444       return RFAILED;
5445    }
5446    resourceList->list.array[rsrcIdx]->sequenceId = SRS_SEQ_ID;
5447
5448    return ROK;
5449 }
5450
5451 /*******************************************************************
5452  *
5453  * @brief Build SRS resource set Add/mod list
5454  *
5455  * @details
5456  *
5457  *    Function : BuildSrsRsrcSetAddModList
5458  *
5459  *    Functionality: Build SRS resource set Add/mod list
5460  *
5461  * @params[in] 
5462  * @return ROK     - success
5463  *         RFAILED - failure
5464  *
5465  * ****************************************************************/
5466    uint8_t BuildSrsRsrcSetAddModList
5467 (
5468  struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList
5469  )
5470 {
5471    uint8_t  elementCnt;
5472    uint8_t  rSetIdx;
5473    uint8_t  rsrcIdx;
5474    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList;
5475
5476    elementCnt = 1;
5477    rsrcSetList->list.count = elementCnt;
5478    rsrcSetList->list.size = elementCnt * sizeof(SRS_ResourceSet_t *);
5479    rsrcSetList->list.array = NULLP;
5480    DU_ALLOC(rsrcSetList->list.array, rsrcSetList->list.size);
5481    if(!rsrcSetList->list.array)
5482    {
5483       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5484       return RFAILED;
5485    }
5486
5487    for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
5488    {
5489       DU_ALLOC(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
5490       if(!rsrcSetList->list.array[rSetIdx])
5491       {
5492          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5493          return RFAILED;
5494       }
5495    }
5496
5497    rSetIdx = 0;
5498    rsrcSetList->list.array[rSetIdx]->srs_ResourceSetId = SRS_RSET_ID;
5499
5500    /* Fill Resource Id list in resource set */
5501    rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList = NULLP;
5502    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
5503          sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
5504    if(!rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
5505    {
5506       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5507       return RFAILED;
5508    }
5509
5510    elementCnt = 1;
5511    rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
5512    rsrcIdList->list.count = elementCnt;
5513    rsrcIdList->list.size = elementCnt * sizeof(SRS_ResourceId_t *);
5514    rsrcIdList->list.array = NULLP;
5515    DU_ALLOC(rsrcIdList->list.array, rsrcIdList->list.size);
5516    if(!rsrcIdList->list.array)
5517    {
5518       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5519       return RFAILED;
5520    }
5521
5522    for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
5523    {
5524       DU_ALLOC(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
5525       if(!rsrcIdList->list.array[rsrcIdx])
5526       {
5527          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5528          return RFAILED;
5529       }
5530    }
5531
5532    rsrcIdx = 0;
5533    *rsrcIdList->list.array[rsrcIdx] = SRS_RSRC_ID;
5534
5535    /* Fill resource type */
5536    rsrcSetList->list.array[rSetIdx]->resourceType.present = \
5537                                                             SRS_ResourceSet__resourceType_PR_aperiodic;
5538
5539    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic = NULLP;
5540    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
5541          sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
5542    if(!rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic)
5543    {
5544       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5545       return RFAILED;
5546    }
5547    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->aperiodicSRS_ResourceTrigger \
5548       = APERIODIC_SRS_RESRC_TRIGGER;
5549
5550    /* TODO : Fill values for below IEs as expected by Viavi */
5551    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->csi_RS = NULLP;
5552    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->slotOffset = NULLP;
5553
5554
5555    rsrcSetList->list.array[rSetIdx]->usage = SRS_ResourceSet__usage_codebook;
5556    rsrcSetList->list.array[rSetIdx]->alpha = NULLP;
5557    rsrcSetList->list.array[rSetIdx]->p0 = NULLP;
5558    rsrcSetList->list.array[rSetIdx]->pathlossReferenceRS = NULLP;
5559    rsrcSetList->list.array[rSetIdx]->srs_PowerControlAdjustmentStates = NULLP;
5560
5561    return ROK;
5562 }
5563
5564 /*******************************************************************
5565  *
5566  * @brief Builds BWP UL dedicated SRS Config
5567  *
5568  * @details
5569  *
5570  *    Function : BuildBWPUlDedSrsCfg
5571  *
5572  *    Functionality: Builds BWP UL dedicated SRS Config
5573  *
5574  * @params[in] SRS Config 
5575  * @return ROK     - success
5576  *         RFAILED - failure
5577  *
5578  * ****************************************************************/
5579 uint8_t BuildBWPUlDedSrsCfg(SRS_Config_t *srsCfg)
5580 {
5581    srsCfg->srs_ResourceSetToReleaseList = NULLP;
5582    srsCfg->srs_ResourceSetToAddModList = NULLP;
5583    DU_ALLOC(srsCfg->srs_ResourceSetToAddModList, \
5584          sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
5585    if(!srsCfg->srs_ResourceSetToAddModList)
5586    {
5587       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5588       return RFAILED;
5589    }
5590    if(BuildSrsRsrcSetAddModList(srsCfg->srs_ResourceSetToAddModList) != ROK)
5591    {
5592       return RFAILED;
5593    }
5594
5595    srsCfg->srs_ResourceToReleaseList = NULLP;
5596
5597    /* Resource to Add/Modify list */
5598    srsCfg->srs_ResourceToAddModList = NULLP;
5599    DU_ALLOC(srsCfg->srs_ResourceToAddModList, \
5600          sizeof(struct SRS_Config__srs_ResourceToAddModList));
5601    if(!srsCfg->srs_ResourceToAddModList)
5602    {
5603       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5604       return RFAILED;
5605    }
5606
5607    if(BuildSrsRsrcAddModList(srsCfg->srs_ResourceToAddModList) != ROK)
5608    {
5609       return RFAILED;
5610    }
5611
5612    srsCfg->tpc_Accumulation = NULLP;
5613
5614    return ROK;
5615 }
5616
5617
5618
5619 /*******************************************************************
5620  *
5621  * @brief Builds Pusch Serving cell Config
5622  *
5623  * @details
5624  *
5625  *    Function : BuildPuschSrvCellCfg
5626  *
5627  *    Functionality: Builds Pusch Serving cell Config
5628  *
5629  * @params[in] struct UplinkConfig__pusch_ServingCellConfig *puschCfg
5630  *
5631  * @return ROK     - success
5632  *         RFAILED - failure
5633  *
5634  * ****************************************************************/
5635 uint8_t BuildPuschSrvCellCfg(struct UplinkConfig__pusch_ServingCellConfig *puschCfg)
5636 {
5637    puschCfg->present = UplinkConfig__pusch_ServingCellConfig_PR_setup;
5638    puschCfg->choice.setup = NULLP;
5639    DU_ALLOC(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
5640    if(!puschCfg->choice.setup)
5641    {
5642       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5643       return RFAILED;
5644    }
5645
5646    puschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5647    puschCfg->choice.setup->rateMatching = NULLP;
5648    puschCfg->choice.setup->xOverhead = NULLP;
5649    puschCfg->choice.setup->ext1 = NULLP;
5650    DU_ALLOC(puschCfg->choice.setup->ext1, sizeof(struct PUSCH_ServingCellConfig__ext1));
5651    if(!puschCfg->choice.setup->ext1)
5652    {
5653       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5654       return RFAILED;
5655    }
5656
5657    puschCfg->choice.setup->ext1->maxMIMO_Layers = NULLP;
5658    DU_ALLOC(puschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5659    if(!puschCfg->choice.setup->ext1->maxMIMO_Layers)
5660    {
5661       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5662       return RFAILED;
5663    }
5664    *(puschCfg->choice.setup->ext1->maxMIMO_Layers) = PUSCH_MAX_MIMO_LAYERS;
5665
5666    puschCfg->choice.setup->ext1->processingType2Enabled= NULLP;
5667    DU_ALLOC(puschCfg->choice.setup->ext1->processingType2Enabled,sizeof(BOOLEAN_t));
5668    if(!puschCfg->choice.setup->ext1->processingType2Enabled)
5669    {
5670       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5671       return RFAILED;
5672    }
5673    *(puschCfg->choice.setup->ext1->processingType2Enabled) = PUSCH_PROCESS_TYPE2_ENABLED;
5674    return ROK;
5675 }
5676
5677 /*******************************************************************
5678  *
5679  * @brief Builds inital UL BWP
5680  *
5681  * @details
5682  *
5683  *    Function : BuildInitialUlBWP
5684  *
5685  *    Functionality: Builds initial UL BWP
5686  *
5687  * @params[in] BWP_UplinkDedicated_t *ulBwp
5688  * @return ROK     - success
5689  *         RFAILED - failure
5690  *
5691  * ****************************************************************/
5692 uint8_t BuildInitialUlBWP(InitialUlBwp *initUlBwp, BWP_UplinkDedicated_t *ulBwp)
5693 {
5694    PucchCfg *pucchCfg = NULLP;
5695    PuschCfg *puschCfg = NULLP;
5696
5697    if(initUlBwp)
5698    {
5699       if(initUlBwp->pucchPresent)
5700          pucchCfg = &initUlBwp->pucchCfg;
5701       if(initUlBwp->puschPresent)
5702          puschCfg = &initUlBwp->puschCfg;
5703    }
5704
5705    ulBwp->pucch_Config = NULLP;
5706    DU_ALLOC(ulBwp->pucch_Config, sizeof(struct BWP_UplinkDedicated__pucch_Config));
5707    if(!ulBwp->pucch_Config)
5708    {
5709       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5710       return RFAILED;
5711    }
5712
5713    ulBwp->pucch_Config->present = BWP_UplinkDedicated__pucch_Config_PR_setup;
5714    ulBwp->pucch_Config->choice.setup = NULLP;
5715    DU_ALLOC(ulBwp->pucch_Config->choice.setup, sizeof(PUCCH_Config_t));
5716    if(!ulBwp->pucch_Config->choice.setup)
5717    {
5718       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5719       return RFAILED;
5720    }
5721
5722    if(BuildBWPUlDedPucchCfg(pucchCfg, ulBwp->pucch_Config->choice.setup) != ROK)
5723    {
5724       return RFAILED;
5725    }
5726
5727    /* Fill BWP UL dedicated PUSCH config */
5728    ulBwp->pusch_Config = NULLP;
5729    DU_ALLOC(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
5730    if(!ulBwp->pusch_Config)
5731    {
5732       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5733       return RFAILED;
5734    }
5735
5736    ulBwp->pusch_Config->present = BWP_UplinkDedicated__pusch_Config_PR_setup;
5737    ulBwp->pusch_Config->choice.setup = NULLP;
5738    DU_ALLOC(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
5739    if(!ulBwp->pusch_Config->choice.setup)
5740    {
5741       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5742       return RFAILED;
5743    }
5744
5745    if(BuildBWPUlDedPuschCfg(puschCfg, ulBwp->pusch_Config->choice.setup) != ROK)
5746    {
5747       return RFAILED;
5748    }
5749
5750    ulBwp->configuredGrantConfig = NULLP;
5751
5752    /* Fill BPW UL dedicated SRS config */
5753    ulBwp->srs_Config = NULLP;
5754    DU_ALLOC(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
5755    if(!ulBwp->srs_Config)
5756    {
5757       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5758       return RFAILED;
5759    }
5760
5761    ulBwp->srs_Config->present = BWP_UplinkDedicated__srs_Config_PR_setup;
5762    ulBwp->srs_Config->choice.setup = NULLP;
5763    DU_ALLOC(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
5764    if(!ulBwp->srs_Config->choice.setup)
5765    {
5766       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5767       return RFAILED;
5768    }
5769
5770    if(BuildBWPUlDedSrsCfg(ulBwp->srs_Config->choice.setup) != ROK)
5771    {
5772       return RFAILED;   
5773    }
5774
5775    ulBwp->beamFailureRecoveryConfig = NULLP;
5776
5777    return ROK;
5778 }
5779
5780 /*******************************************************************
5781  *
5782  * @brief Builds UL config
5783  * @details
5784  *
5785  *    Function : BuildUlCfg 
5786  *
5787  *    Functionality: Builds UL config in spCellCfgDed
5788  *
5789  * @params[in] UplinkConfig_t *ulCfg
5790  *
5791  * @return ROK     - success
5792  *         RFAILED - failure
5793  *
5794  * ****************************************************************/
5795 uint8_t BuildUlCfg(ServCellCfgInfo *servCellCfg, UplinkConfig_t *ulCfg)
5796 {
5797    InitialUlBwp *initUlBwp = NULLP;
5798
5799    if(servCellCfg)
5800    {
5801       initUlBwp = &servCellCfg->initUlBwp;
5802    }
5803
5804    ulCfg->initialUplinkBWP = NULLP;
5805    DU_ALLOC(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
5806    if(!ulCfg->initialUplinkBWP)
5807    {
5808       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5809       return RFAILED;
5810    }
5811
5812    if(BuildInitialUlBWP(initUlBwp, ulCfg->initialUplinkBWP) != ROK)
5813    {
5814       return RFAILED;
5815    }
5816
5817    ulCfg->uplinkBWP_ToReleaseList = NULLP;
5818    ulCfg->uplinkBWP_ToAddModList = NULLP;
5819    ulCfg->firstActiveUplinkBWP_Id = NULLP;
5820    DU_ALLOC(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
5821    if(!ulCfg->firstActiveUplinkBWP_Id)
5822    {
5823       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5824       return RFAILED;
5825    }
5826    if(servCellCfg == NULLP)
5827       *(ulCfg->firstActiveUplinkBWP_Id) = ACTIVE_UL_BWP_ID;
5828    else
5829       *(ulCfg->firstActiveUplinkBWP_Id) = servCellCfg->firstActvUlBwpId;
5830
5831    ulCfg->pusch_ServingCellConfig = NULLP;
5832    DU_ALLOC(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
5833    if(!ulCfg->pusch_ServingCellConfig)
5834    {
5835       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5836       return RFAILED;
5837    }
5838
5839    if(BuildPuschSrvCellCfg(ulCfg->pusch_ServingCellConfig) != ROK)
5840    {
5841       return RFAILED;
5842    }
5843
5844    ulCfg->carrierSwitching = NULLP;
5845    ulCfg->ext1 = NULLP;
5846    return ROK;
5847 }
5848
5849 /*******************************************************************
5850  *
5851  * @brief Builds PDSCH serving cell config
5852  * @details
5853  *
5854  *    Function : BuildPdschSrvCellCfg
5855  *
5856  *    Functionality: Builds PDSCH serving cell config in spCellCfgDed
5857  *
5858  * @params[in] struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg 
5859  *
5860  * @return ROK     - success
5861  *         RFAILED - failure
5862  *
5863  * ****************************************************************/
5864 uint8_t BuildPdschSrvCellCfg(PdschServCellCfg *pdschServCellDb, struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg)
5865 {
5866    pdschCfg->present =  ServingCellConfig__pdsch_ServingCellConfig_PR_setup;
5867    pdschCfg->choice.setup = NULLP;
5868    DU_ALLOC(pdschCfg->choice.setup, sizeof( struct PDSCH_ServingCellConfig));
5869    if(!pdschCfg->choice.setup)
5870    {
5871       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5872       return RFAILED;
5873    }
5874
5875    /* Code Block Group Transmission */
5876    pdschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5877    if(pdschServCellDb && (pdschServCellDb->maxCodeBlkGrpPerTb || pdschServCellDb->codeBlkGrpFlushInd))
5878    {
5879       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission, sizeof(struct PDSCH_ServingCellConfig__codeBlockGroupTransmission));
5880       if(pdschCfg->choice.setup->codeBlockGroupTransmission == NULLP)
5881       {
5882          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5883          return RFAILED;
5884       }
5885
5886       pdschCfg->choice.setup->codeBlockGroupTransmission->present = PDSCH_ServingCellConfig__codeBlockGroupTransmission_PR_setup;
5887       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup = NULLP;
5888       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup, sizeof(struct PDSCH_CodeBlockGroupTransmission ));
5889       if(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup == NULLP)
5890       {
5891          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5892          return RFAILED;
5893       }
5894
5895       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock = \
5896          *(pdschServCellDb->maxCodeBlkGrpPerTb);
5897       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator = \
5898          *(pdschServCellDb->codeBlkGrpFlushInd);
5899    }
5900
5901    /* xOverhead */
5902    pdschCfg->choice.setup->xOverhead = NULLP;
5903    if(pdschServCellDb && pdschServCellDb->xOverhead)
5904    {
5905       DU_ALLOC(pdschCfg->choice.setup->xOverhead, sizeof(long));
5906       if(pdschCfg->choice.setup->xOverhead == NULLP)
5907       {
5908          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5909          return RFAILED;
5910       }
5911       *(pdschCfg->choice.setup->xOverhead) = *(pdschServCellDb->xOverhead);
5912    }
5913
5914    /* Number of HARQ processes */
5915    pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH = NULLP;
5916    DU_ALLOC(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH, sizeof(long));
5917    if(!pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH)
5918    {
5919       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5920       return RFAILED;
5921    }
5922
5923    if(pdschServCellDb == NULLP)
5924    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = PDSCH_NUM_HARQ_PROC;
5925    else
5926    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = pdschServCellDb->numHarqProcForPdsch;
5927
5928    pdschCfg->choice.setup->pucch_Cell = NULLP;
5929
5930    /* Extension */
5931    pdschCfg->choice.setup->ext1 = NULLP;
5932    if(pdschServCellDb && pdschServCellDb->maxMimoLayers)
5933    {
5934       DU_ALLOC(pdschCfg->choice.setup->ext1, sizeof(struct PDSCH_ServingCellConfig__ext1));
5935       if(pdschCfg->choice.setup->ext1 == NULLP)
5936       {
5937          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5938          return RFAILED;
5939       }
5940
5941       DU_ALLOC(pdschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5942       if(pdschCfg->choice.setup->ext1->maxMIMO_Layers == NULLP)
5943       {
5944          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5945          return RFAILED;
5946       }
5947       *(pdschCfg->choice.setup->ext1->maxMIMO_Layers) = *(pdschServCellDb->maxMimoLayers);
5948    }
5949
5950    return ROK;
5951 }
5952
5953 /*******************************************************************
5954  *
5955  * @brief Builds CSI Meas config
5956  * @details
5957  *
5958  *    Function : BuildCsiMeasCfg 
5959  *
5960  *    Functionality: Builds CSI Meas config in spCellCfgDed
5961  *
5962  * @params[in] struct ServingCellConfig__csi_MeasConfig *csiMeasCfg
5963  *
5964  * @return ROK     - success
5965  *         RFAILED - failure
5966  *
5967  * ****************************************************************/
5968 uint8_t BuildCsiMeasCfg(struct ServingCellConfig__csi_MeasConfig *csiMeasCfg)
5969 {
5970
5971    return ROK;
5972 }
5973
5974 /*******************************************************************
5975  *
5976  * @brief Builds DL BWP to add/modify list
5977  * @details
5978  *
5979  *    Function : BuildDlBwpToAddModList
5980  *
5981  *    Functionality: Builds DL BWP to add/modify list
5982  *
5983  * @params[in] ServCellCfgInfo *servCellCfg, 
5984  *             struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList
5985  *
5986  * @return ROK     - success
5987  *         RFAILED - failure
5988  *
5989  * ****************************************************************/ 
5990 uint8_t BuildDlBwpToAddModList(ServCellCfgInfo *servCellCfg, struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList)
5991 {
5992    uint8_t elementCnt, idx;
5993
5994    elementCnt = servCellCfg->numDlBwpToAdd;
5995    dlBwpAddModList->list.count = elementCnt;
5996    dlBwpAddModList->list.size = elementCnt * sizeof(struct BWP_Downlink *);
5997    dlBwpAddModList->list.array = NULLP;
5998    DU_ALLOC(dlBwpAddModList->list.array, dlBwpAddModList->list.size);
5999    if(dlBwpAddModList->list.array == NULLP)
6000    {
6001       DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6002       return RFAILED;
6003    }
6004
6005    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6006    {
6007       DU_ALLOC(dlBwpAddModList->list.array[idx], sizeof(BWP_Downlink_t));
6008       if(dlBwpAddModList->list.array[idx] == NULLP)
6009       {
6010          DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6011          return RFAILED;
6012       }
6013    }
6014
6015    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6016    {
6017       dlBwpAddModList->list.array[idx]->bwp_Id = servCellCfg->DlBwpToAddList[idx].bwpId;
6018       dlBwpAddModList->list.array[idx]->bwp_Common = NULLP;
6019       dlBwpAddModList->list.array[idx]->bwp_Dedicated = NULLP;
6020    }
6021    return ROK;
6022 }
6023
6024 /*******************************************************************
6025  *
6026  * @brief Builds Spcell config dedicated
6027  * @details
6028  *
6029  *    Function : BuildSpCellCfgDed
6030  *
6031  *    Functionality: Builds sp cell config dedicated in spCellCfg
6032  *
6033  * @params[in] ServingCellConfig_t srvCellCfg
6034  *
6035  * @return ROK     - success
6036  *         RFAILED - failure
6037  *
6038  * ****************************************************************/
6039 uint8_t BuildSpCellCfgDed(DuUeCb *ueCb, ServingCellConfig_t *srvCellCfg)
6040 {
6041    ServCellCfgInfo *servCellCfg = NULLP;
6042    InitialDlBwp *initDlBwp = NULLP;
6043    PdschServCellCfg *pdschServCellDb = NULLP;
6044
6045    if(ueCb)
6046    {
6047       servCellCfg = &ueCb->macUeCfg.spCellCfg.servCellCfg;
6048       initDlBwp = &servCellCfg->initDlBwp;
6049       pdschServCellDb = &servCellCfg->pdschServCellCfg;
6050    }
6051
6052    srvCellCfg->tdd_UL_DL_ConfigurationDedicated = NULLP;
6053    DU_ALLOC(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
6054    if(!srvCellCfg->tdd_UL_DL_ConfigurationDedicated)
6055    {
6056       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6057       return RFAILED;
6058    }
6059
6060    srvCellCfg->initialDownlinkBWP = NULLP;
6061    DU_ALLOC(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
6062    if(!srvCellCfg->initialDownlinkBWP)
6063    {
6064       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6065       return RFAILED;
6066    }
6067
6068    if(BuildInitialDlBWP(initDlBwp, srvCellCfg->initialDownlinkBWP) != ROK)
6069    {
6070       DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6071       return RFAILED;
6072    }
6073
6074    srvCellCfg->downlinkBWP_ToReleaseList = NULLP;
6075
6076    srvCellCfg->downlinkBWP_ToAddModList = NULLP;
6077    if(ueCb && ueCb->macUeCfg.spCellCfg.servCellCfg.numDlBwpToAdd)
6078    {
6079       DU_ALLOC(srvCellCfg->downlinkBWP_ToAddModList, sizeof(struct ServingCellConfig__downlinkBWP_ToAddModList));
6080       if(srvCellCfg->downlinkBWP_ToAddModList == NULLP)
6081       {
6082          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6083          return RFAILED;
6084       }
6085
6086       if(BuildDlBwpToAddModList(&ueCb->macUeCfg.spCellCfg.servCellCfg, srvCellCfg->downlinkBWP_ToAddModList) != ROK)
6087       {
6088          DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6089          return RFAILED;
6090       }
6091    }
6092
6093    srvCellCfg->firstActiveDownlinkBWP_Id = NULLP;
6094    DU_ALLOC(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
6095    if(!srvCellCfg->firstActiveDownlinkBWP_Id)
6096    {
6097       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6098       return RFAILED;
6099    }
6100    if(ueCb == NULLP)
6101       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6102    else
6103       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ueCb->macUeCfg.spCellCfg.servCellCfg.firstActvDlBwpId;
6104
6105    srvCellCfg->bwp_InactivityTimer = NULLP;
6106
6107    srvCellCfg->defaultDownlinkBWP_Id = NULLP;
6108    DU_ALLOC(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
6109    if(!srvCellCfg->defaultDownlinkBWP_Id)
6110    {
6111       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6112       return RFAILED;
6113    }
6114    if(ueCb == NULLP)
6115       *(srvCellCfg->defaultDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6116    else
6117       *(srvCellCfg->defaultDownlinkBWP_Id) = ueCb->macUeCfg.spCellCfg.servCellCfg.defaultDlBwpId;
6118
6119    srvCellCfg->uplinkConfig = NULLP;
6120    DU_ALLOC(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));
6121    if(!srvCellCfg->uplinkConfig)
6122    {
6123       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6124       return RFAILED;
6125    }
6126
6127    if(BuildUlCfg(servCellCfg, srvCellCfg->uplinkConfig) != ROK)
6128    {
6129       DU_LOG("\nERROR  -->  F1AP : BuildUlCfg failed");
6130       return RFAILED;
6131    }
6132    srvCellCfg->supplementaryUplink = NULLP;
6133    srvCellCfg->pdcch_ServingCellConfig = NULLP;
6134
6135    srvCellCfg->pdsch_ServingCellConfig = NULLP;
6136    DU_ALLOC(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct  ServingCellConfig__pdsch_ServingCellConfig));
6137    if(!srvCellCfg->pdsch_ServingCellConfig)
6138    {
6139       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6140       return RFAILED;
6141    }
6142
6143    if(BuildPdschSrvCellCfg(pdschServCellDb, srvCellCfg->pdsch_ServingCellConfig) != ROK)
6144    {
6145       DU_LOG("\nERROR  -->  F1AP : BuildPdschSrvCellCfg failed");
6146       return RFAILED;
6147    }
6148
6149    srvCellCfg->csi_MeasConfig = NULLP;
6150 #if 0
6151    DU_ALLOC(srvCellCfg->csi_MeasConfig, sizeof(struct   ServingCellConfig__csi_MeasConfig))
6152       if(!srvCellCfg->csi_MeasConfig)
6153       {
6154          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6155          return RFAILED;
6156       }
6157
6158    if(BuildCsiMeasCfg(srvCellCfg->csi_MeasConfig) != ROK)
6159    {
6160       DU_LOG("\nF1AP : BuildCsiMeasCfg failed");
6161       return RFAILED;
6162    }
6163 #endif
6164    srvCellCfg->sCellDeactivationTimer = NULLP;
6165    srvCellCfg->crossCarrierSchedulingConfig = NULLP;
6166    srvCellCfg->tag_Id = TAG_ID;
6167    srvCellCfg->dummy = NULLP;
6168    srvCellCfg->pathlossReferenceLinking = NULLP;
6169    srvCellCfg->servingCellMO = NULLP;
6170    srvCellCfg->ext1 = NULLP;
6171
6172    return ROK;
6173 }
6174
6175 /*******************************************************************
6176  *
6177  * @brief Fills SCS specific carrier list in DL frequency info
6178  *
6179  * @details
6180  *
6181  *    Function : BuildScsSpecificCarrierListDl
6182  *
6183  *    Functionality: Fills SCS specific carrier list in DL frequency info
6184  *
6185  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
6186  *
6187  * @return ROK     - success
6188  *         RFAILED - failure
6189  *
6190  * ****************************************************************/
6191 uint8_t BuildScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
6192 {
6193    uint8_t elementCnt = 0, listIdx = 0;
6194    ScsSpecCarrier duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.dlScsCarrier;
6195
6196    elementCnt = ODU_VALUE_ONE;
6197    scsCarrierList->list.count = elementCnt;
6198    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6199
6200    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6201    if(!scsCarrierList->list.array)
6202    {
6203       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for scs carrier list array \
6204          in BuildScsSpecificCarrierListDl()");
6205       return RFAILED;
6206    }
6207
6208    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6209    {
6210       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6211       if(!scsCarrierList->list.array[listIdx])
6212       {    
6213          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SCS Specific Carrier list array \
6214             element in BuildScsSpecificCarrierListDl()");
6215          return RFAILED;
6216       }    
6217    }
6218
6219    listIdx = 0;
6220    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6221    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6222    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6223
6224    return ROK;
6225 }
6226
6227 /*******************************************************************
6228  *
6229  * @brief Fills DL frequency info in DL config common
6230  *
6231  * @details
6232  *
6233  *    Function : BuildFreqInfoDl
6234  *
6235  *    Functionality: Fills DL frequency info in DL config common
6236  *
6237  * @params[in] Pointer to DownlinkConfigCommon_t
6238  *
6239  * @return ROK     - success
6240  *         RFAILED - failure
6241  *
6242  * ****************************************************************/
6243 uint8_t BuildFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
6244 {
6245    uint8_t freqBandIdx = 0, elementCnt = 0;
6246    DlCfgCommon  dlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg;
6247
6248    /* TODO : Fill SSB Absolute Frequency */
6249    /*
6250       DU_ALLOC(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
6251       if(!frequencyInfoDL->absoluteFrequencySSB)
6252       {
6253       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB Absolute Frequency in BuildFreqInfoDl()");
6254       return RFAILED;
6255       }
6256       frequencyInfoDL->absoluteFrequencySSB = ?;
6257       */
6258
6259    /* NR Multi Frequency Band List */
6260    elementCnt = ODU_VALUE_ONE;
6261    frequencyInfoDL->frequencyBandList.list.count = elementCnt;
6262    frequencyInfoDL->frequencyBandList.list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6263
6264    DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
6265    if(!frequencyInfoDL->frequencyBandList.list.array)
6266    {
6267       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for Frequency Band List array in BuildFreqInfoDl()");
6268       return RFAILED;
6269    }
6270
6271    for(freqBandIdx = 0; freqBandIdx < elementCnt; freqBandIdx++)
6272    {
6273       DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
6274       if(!frequencyInfoDL->frequencyBandList.list.array[freqBandIdx])
6275       {
6276          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoDl()");
6277          return RFAILED;
6278       }
6279    }
6280
6281    freqBandIdx = 0;
6282    *(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx]) = dlCfg.freqBandInd;
6283
6284    /* TODO : Absolute Frequency to Point A */
6285    //frequencyInfoDL->absoluteFrequencyPointA
6286
6287    /* Subcarrier Spacing specifc carrier List */
6288    if((BuildScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList)) != ROK)
6289    {
6290       DU_LOG("\nERROR  -->  DU APP : Failed to fill SCS specific carrier list DL in BuildFreqInfoDl()");
6291       return RFAILED;
6292    }
6293
6294    return ROK;
6295
6296 }
6297
6298 /*******************************************************************
6299  *
6300  * @brief Fills DL config common in Serving cell config common
6301  *
6302  * @details
6303  *
6304  *    Function : BuildDlConfigCommon
6305  *
6306  *    Functionality: Fills DL config common in Serving cell config common
6307  *
6308  * @params[in] Pointer to DownlinkConfigCommon_t
6309  *
6310  * @return ROK     - success
6311  *         RFAILED - failure
6312  *
6313  * ****************************************************************/
6314 uint8_t BuildDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
6315 {
6316    /* DL Frequency Info */
6317    DU_ALLOC(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
6318    if(!dlCfgCommon->frequencyInfoDL)
6319    {
6320       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL frequency info in BuildDlConfigCommon()");
6321       return RFAILED;
6322    }
6323    if((BuildFreqInfoDl(dlCfgCommon->frequencyInfoDL))!= ROK)
6324    {
6325       DU_LOG("\nERROR  --> DU APP : Failed to fill DL frequency info in BuildDlConfigCommon()");
6326       return RFAILED;
6327    }
6328
6329    /* DL BWP config common */
6330    DU_ALLOC(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
6331    if(!dlCfgCommon->initialDownlinkBWP)
6332    {
6333       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL BWP config common in BuildDlConfigCommon()");
6334       return RFAILED;
6335    }
6336    if((BuildBwpDlCommon(dlCfgCommon->initialDownlinkBWP)) != ROK)
6337    {
6338       DU_LOG("\nERROR  --> DU APP : Failed to fill DL DWP config common in BuildDlConfigCommon()");
6339       return RFAILED;
6340    }
6341
6342    return ROK;
6343 }
6344
6345 /*******************************************************************
6346  *
6347  * @brief Fills SCS specific carrier list in UL frequency Info
6348  *
6349  * @details
6350  *
6351  *    Function : BuildScsSpecificCarrierListUl
6352  *
6353  *    Functionality: Fills SCS specific carrier list in UL frequency Info
6354  *
6355  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
6356  *
6357  * @return ROK     - success
6358  *         RFAILED - failure
6359  *
6360  * ****************************************************************/
6361 uint8_t BuildScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
6362 {
6363    uint8_t elementCnt = 0, listIdx = 0; 
6364    ScsSpecCarrier   duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.ulScsCarrier;
6365
6366    elementCnt = ODU_VALUE_ONE;
6367    scsCarrierList->list.count = elementCnt;
6368    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6369
6370    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6371    if(!scsCarrierList->list.array)
6372    {
6373       DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6374       return RFAILED;
6375    }
6376
6377    for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
6378    {
6379       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6380       if(!scsCarrierList->list.array[listIdx])
6381       {    
6382          DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6383          return RFAILED;
6384       }    
6385    }
6386    listIdx = 0; 
6387    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6388    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6389    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6390
6391    return ROK;
6392 }
6393
6394 /*******************************************************************
6395  *
6396  * @brief Fills frequency info in UL config common
6397  *
6398  * @details
6399  *
6400  *    Function : BuildFreqInfoUl
6401  *
6402  *    Functionality: Fills frequency info in UL config common
6403  *
6404  * @params[in] Pointer to FrequencyInfoUL_t
6405  *
6406  * @return ROK     - success
6407  *         RFAILED - failure
6408  *
6409  * ****************************************************************/
6410 uint8_t BuildFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
6411 {
6412    uint8_t elementCnt = 0, listIdx= 0;
6413    UlCfgCommon  ulCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg;
6414
6415    /* NR Multi Frequency Band List */
6416    DU_ALLOC(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
6417    if(!frequencyInfoUL->frequencyBandList)
6418    {
6419       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band list in BuildFreqInfoUl()");
6420       return RFAILED;
6421    }
6422
6423    elementCnt = ODU_VALUE_ONE;
6424    frequencyInfoUL->frequencyBandList->list.count = elementCnt;
6425    frequencyInfoUL->frequencyBandList->list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6426
6427    DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
6428    if(!frequencyInfoUL->frequencyBandList->list.array)
6429    {
6430       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array in BuildFreqInfoUl()");
6431       return RFAILED;
6432    }
6433
6434    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6435    {
6436       DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
6437       if(!frequencyInfoUL->frequencyBandList->list.array[listIdx])
6438       {
6439          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoUl()");
6440          return RFAILED;
6441       }
6442    }
6443
6444    listIdx = 0;
6445    *(frequencyInfoUL->frequencyBandList->list.array[listIdx]) = ulCfg.freqBandInd;
6446
6447    /* TODO : Fill Absolute frequency point A */
6448    /*
6449       DU_ALLOC(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
6450       if(!frequencyInfoUL->absoluteFrequencyPointA)
6451       {
6452       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for absolute frequency point A in BuildFreqInfoUl()");
6453       return RFAILED;
6454       }
6455     *(frequencyInfoUL->absoluteFrequencyPointA) = ?;
6456     */
6457
6458    /* Subcarrier Spacing specifc carrier */
6459    if((BuildScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList)) != ROK) 
6460    {
6461       DU_LOG("\nERROR  --> DU APP : Failed to fill SCS Specific Carrier list UL in BuildFreqInfoUl()");
6462       return RFAILED;
6463    }
6464
6465    /* P-MAX */
6466    DU_ALLOC(frequencyInfoUL->p_Max, sizeof(P_Max_t));
6467    if(!frequencyInfoUL->p_Max)
6468    {
6469       DU_LOG("\nERROR  -->  DU APP : UL Frequency Infoo  memory allocation failure");
6470       return RFAILED;
6471    }
6472    *frequencyInfoUL->p_Max = ulCfg.pMax;
6473
6474    return ROK;
6475 }
6476
6477 /*******************************************************************
6478  *
6479  * @brief Fills UL config common in Serving cell config common
6480  *
6481  * @details
6482  *
6483  *    Function : BuildUlConfigCommon
6484  *
6485  *    Functionality: Fills UL config common in Serving cell config common
6486  *
6487  * @params[in] Pointer to UplinkConfigCommon_t
6488  *
6489  * @return ROK     - success
6490  *         RFAILED - failure
6491  *
6492  * ****************************************************************/
6493 uint8_t BuildUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
6494 {
6495    /* UL Frequency Info */
6496    DU_ALLOC(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
6497    if(!ulCfgCommon->frequencyInfoUL)
6498    {
6499       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for UL frequency info in BuildUlConfigCommon()");
6500       return RFAILED;
6501    }
6502
6503    if((BuildFreqInfoUl(ulCfgCommon->frequencyInfoUL)) != ROK)
6504    {
6505       DU_LOG("\nERROR  -->  DU APP : Failed to fill frequency info UL in BuildUlConfigCommon()");
6506       return RFAILED;
6507    }
6508
6509    /* UL BWP common */
6510    DU_ALLOC(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
6511    if(!ulCfgCommon->initialUplinkBWP)
6512    {
6513       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for initial UL BWP in BuildUlConfigCommon()");
6514       return RFAILED;
6515    }
6516
6517    if((BuildBwpUlCommon(ulCfgCommon->initialUplinkBWP)) != ROK)
6518    {
6519       DU_LOG("\nERROR  -->  DU APP : Failed to fill BWP UL common in BuildUlConfigCommon()");
6520       return RFAILED;
6521    }
6522
6523    /* Time Alignment timer */
6524    ulCfgCommon->dummy = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.timeAlignTimerComm;
6525
6526    return ROK;
6527 }
6528
6529 /*******************************************************************
6530  *
6531  * @brief Fills SSB position in burst in SP cell config common
6532  *
6533  * @details
6534  *
6535  *    Function : BuildSsbPosInBurst
6536  *
6537  *    Functionality: 
6538  *       Fills SSB position in burst in SP cell config common
6539  *
6540  * @params[in] Pointer to struct ServingCellConfigCommon__ssb_PositionsInBurst
6541  *
6542  * @return ROK     - success
6543  *         RFAILED - failure
6544  *
6545  * ****************************************************************/
6546 uint8_t BuildSsbPosInBurst(struct ServingCellConfigCommon__ssb_PositionsInBurst *ssbPosInBurst)
6547 {
6548    uint8_t bitStringSizeInBytes = 0;
6549
6550    ssbPosInBurst->present = ServingCellConfigCommon__ssb_PositionsInBurst_PR_mediumBitmap;
6551
6552    /* As per spec 38.331,in the definition of ServingCellConfigCommon */
6553    bitStringSizeInBytes = 1;
6554    ssbPosInBurst->choice.mediumBitmap.size = bitStringSizeInBytes * sizeof(uint8_t);
6555
6556    DU_ALLOC(ssbPosInBurst->choice.mediumBitmap.buf, ssbPosInBurst->choice.mediumBitmap.size);
6557    if(!ssbPosInBurst->choice.mediumBitmap.buf)
6558    {
6559       DU_LOG("\nERROR  -->  DU APP : Memory Allocation failed for medium bit map buffer in BuildSsbPosInBurst()");
6560       return RFAILED;
6561    }
6562
6563    if((fillBitString(&ssbPosInBurst->choice.mediumBitmap, 0, bitStringSizeInBytes, \
6564                duCfgParam.sib1Params.srvCellCfgCommSib.ssbPosInBurst)) != ROK)
6565    {
6566       DU_LOG("\nERROR  -->  DU APP : Failed to fill medium bit map in BuildSsbPosInBurst()");
6567       return RFAILED;
6568    }
6569
6570    return ROK;
6571 }
6572
6573 /*******************************************************************
6574  *
6575  * @brief Fills SP cell config common in Reconfig with Sync
6576  *
6577  * @details
6578  *
6579  *    Function : BuildSpCellConfigCommon
6580  *
6581  *    Functionality: Fills SP cell config common in Reconfig with Sync
6582  *
6583  * @params[in] Pointer to ServingCellConfigCommon_t
6584  *
6585  * @return ROK     - success
6586  *         RFAILED - failure
6587  *
6588  * ****************************************************************/
6589 uint8_t BuildSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
6590 {
6591    /* Physical Cell Identity */
6592    DU_ALLOC(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
6593    if(!spCellConfigCommon->physCellId)
6594    {
6595       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for physical cell id in BuildSpCellConfigCommon()");
6596       return RFAILED;
6597    } 
6598    *(spCellConfigCommon->physCellId) = NR_PCI;
6599
6600    /* Downlink Config Common */
6601    DU_ALLOC(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
6602    if(!spCellConfigCommon->downlinkConfigCommon)
6603    {
6604       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for DL Config Common in BuildSpCellConfigCommon()");
6605       return RFAILED;
6606    }
6607    if((BuildDlConfigCommon(spCellConfigCommon->downlinkConfigCommon)) != ROK)
6608    {
6609       DU_LOG("\nERROR  -->  DU APP : Failed to fill DL config commin in BuildSpCellConfigCommon()");
6610       return RFAILED;
6611    }
6612
6613    /* Uplinlink Config Common */
6614    DU_ALLOC(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
6615    if(!spCellConfigCommon->uplinkConfigCommon)
6616    {
6617       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for UL Config Common in BuildSpCellConfigCommon()");
6618       return RFAILED;
6619    }
6620    if((BuildUlConfigCommon(spCellConfigCommon->uplinkConfigCommon)) != ROK)
6621    {
6622       DU_LOG("\nERROR  -->  DU APP : Failed to fill UL config commin in BuildSpCellConfigCommon()");
6623       return RFAILED;
6624    }
6625
6626    /* Timing Advance offset */
6627    DU_ALLOC(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
6628    if(!spCellConfigCommon->n_TimingAdvanceOffset)
6629    {
6630       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for Timing Advance Offset in BuildSpCellConfigCommon()");
6631       return RFAILED;
6632    }
6633    *(spCellConfigCommon->n_TimingAdvanceOffset) = ServingCellConfigCommon__n_TimingAdvanceOffset_n0;
6634
6635    /* SSB Position In Burst */
6636    DU_ALLOC(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
6637    if(!spCellConfigCommon->ssb_PositionsInBurst)
6638    {
6639       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Position In Burst in BuildSpCellConfigCommon()");
6640       return RFAILED;
6641    }
6642    if((BuildSsbPosInBurst(spCellConfigCommon->ssb_PositionsInBurst)) != ROK)
6643    {
6644       DU_LOG("\nERROR  -->  DU APP : Failed to fill SSB Position In Burst in BuildSpCellConfigCommon()");
6645       return RFAILED;
6646    }
6647
6648    /* SSB Periodicity in Serving cell */
6649    DU_ALLOC(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
6650    if(!spCellConfigCommon->ssb_periodicityServingCell)
6651    {
6652       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Periodicity serving cell in \
6653          BuildSpCellConfigCommon()");
6654       return RFAILED;
6655    }
6656    *(spCellConfigCommon->ssb_periodicityServingCell) = \
6657       convertSsbPeriodicityValueToEnum(duCfgParam.sib1Params.srvCellCfgCommSib.ssbPrdServingCell);
6658
6659    /* DMRS Type A position */
6660    spCellConfigCommon->dmrs_TypeA_Position = convertDmrsTypeAPosValueToEnum(duCfgParam.macCellCfg.dmrsTypeAPos);
6661
6662    /* SSB subcarrier spacing */
6663    DU_ALLOC(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
6664    if(!spCellConfigCommon->ssbSubcarrierSpacing)
6665    {
6666       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for sub-carrier spacing in BuildSpCellConfigCommon()");
6667       return RFAILED;
6668    }
6669    *(spCellConfigCommon->ssbSubcarrierSpacing) = duCfgParam.sib1Params.srvCellCfgCommSib.scs;
6670
6671    /* TDD UL-DL configuration common */
6672    DU_ALLOC(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
6673    if(!spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)
6674    {
6675       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for TDD UL-DL config common in BuildSpCellConfigCommon()");
6676       return RFAILED;
6677    }
6678    if((BuildTddUlDlCfgComm(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)) != ROK)
6679    {
6680       DU_LOG("\nERROR  -->  DU APP : Failed to fill TDD UL-DL config common in BuildSpCellConfigCommon()");
6681       return RFAILED;
6682    }
6683
6684    /* SS PBCH Block Power */
6685    spCellConfigCommon->ss_PBCH_BlockPower = duCfgParam.sib1Params.srvCellCfgCommSib.ssPbchBlockPwr;
6686
6687    return ROK;
6688 }
6689
6690 /*******************************************************************
6691  *
6692  * @brief Fills dedicated RACH configuration in Reconfiguration with sync
6693  *
6694  * @details
6695  *
6696  *    Function : BuildRecfgWithSync
6697  *
6698  *    Functionality: 
6699  *       Fills dedicated RACH configuration in Reconfiguration with sync
6700  *
6701  * @params[in] DU UE CB
6702  *             Pointer to Rach config dedicated struct
6703  *
6704  * @return ROK     - success
6705  *         RFAILED - failure
6706  *
6707  * ****************************************************************/
6708 uint8_t BuildRachConfigDedicated(DuUeCb *ueCb, struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
6709 {
6710    uint8_t elementCnt = 0, listIdx = 0;
6711    CFRA_t *cfra = NULLP;
6712    struct CFRA__resources__ssb *ssbResource = NULLP;
6713    RachCfgCommon duRachCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.rachCfg;
6714
6715    rachCfgDed->present = ReconfigurationWithSync__rach_ConfigDedicated_PR_uplink;
6716
6717    /* Uplink */
6718    DU_ALLOC(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
6719    if(!rachCfgDed->choice.uplink)
6720    {
6721       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for RACH uplink configuration in BuildRachConfigDedicated()");
6722       return RFAILED;
6723    }
6724
6725    /* CFRA : Contention free Random Access */
6726    DU_ALLOC(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
6727    if(!rachCfgDed->choice.uplink->cfra)
6728    {
6729       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA in BuildRachConfigDedicated()");
6730       return RFAILED;
6731    }
6732    cfra = rachCfgDed->choice.uplink->cfra;
6733
6734    /* CFRA occassions */
6735    DU_ALLOC(cfra->occasions, sizeof(struct CFRA__occasions));
6736    if(!cfra->occasions)
6737    {
6738       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA occassion in BuildRachConfigDedicated()");
6739       return RFAILED;
6740    }
6741
6742    /* CFRA occassions : RACH generic configuration */
6743    cfra->occasions->rach_ConfigGeneric.prach_ConfigurationIndex = duRachCfg.prachCfgIdx;
6744    cfra->occasions->rach_ConfigGeneric.msg1_FDM = duRachCfg.msg1Fdm;
6745    cfra->occasions->rach_ConfigGeneric.msg1_FrequencyStart = duRachCfg.msg1FreqStart;
6746    cfra->occasions->rach_ConfigGeneric.zeroCorrelationZoneConfig = duRachCfg.zeroCorrZoneCfg;
6747    cfra->occasions->rach_ConfigGeneric.preambleReceivedTargetPower = duRachCfg.preambleRcvdTgtPwr;
6748    cfra->occasions->rach_ConfigGeneric.preambleTransMax = duRachCfg.preambleTransMax;
6749    cfra->occasions->rach_ConfigGeneric.powerRampingStep = duRachCfg.pwrRampingStep;
6750    cfra->occasions->rach_ConfigGeneric.ra_ResponseWindow = duRachCfg.raRspWindow;
6751
6752    /* CFRA occassions : SSB per RACH occasion */
6753    DU_ALLOC(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
6754    if(!cfra->occasions->ssb_perRACH_Occasion)
6755    {
6756       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB per RACH occassion in BuildRachConfigDedicated()");
6757       return RFAILED;
6758    }
6759    *(cfra->occasions->ssb_perRACH_Occasion) = convertCFRASsbPerRachOccasionValueToEnum(duCfgParam.macCellCfg.prachCfg.ssbPerRach);
6760
6761    /* CFRA resource */
6762    cfra->resources.present = CFRA__resources_PR_ssb;
6763
6764    /* CFRA resource : SSB */
6765    DU_ALLOC(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
6766    if(!cfra->resources.choice.ssb)
6767    {
6768       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA resource - SSB in BuildRachConfigDedicated()");
6769       return RFAILED;
6770    }
6771    ssbResource = cfra->resources.choice.ssb;
6772
6773    /* CFRA SSB resource list */
6774    elementCnt = ueCb->cfraResource.numSsb;
6775    ssbResource->ssb_ResourceList.list.count = elementCnt;
6776    ssbResource->ssb_ResourceList.list.size = elementCnt * sizeof(CFRA_SSB_Resource_t *);
6777
6778    DU_ALLOC(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
6779    if(!ssbResource->ssb_ResourceList.list.array)
6780    {
6781       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list in BuildRachConfigDedicated()");
6782       return RFAILED;
6783    }
6784
6785    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6786    {
6787       DU_ALLOC(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
6788       if(!ssbResource->ssb_ResourceList.list.array[listIdx])
6789       {
6790          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list element in BuildRachConfigDedicated()");  
6791          return RFAILED;
6792       }
6793       ssbResource->ssb_ResourceList.list.array[listIdx]->ssb = ueCb->cfraResource.ssbResource[listIdx].ssbIdx;
6794       ssbResource->ssb_ResourceList.list.array[listIdx]->ra_PreambleIndex = ueCb->cfraResource.ssbResource[listIdx].raPreambleIdx;
6795    }
6796
6797    return ROK;
6798 }
6799
6800 /*******************************************************************
6801  *
6802  * @brief Fills reconfiguration with sync in SP cell config
6803  *
6804  * @details
6805  *
6806  *    Function : BuildRecfgWithSync
6807  *
6808  *    Functionality: Fills reconfiguration with sync in SP cell config
6809  *
6810  * @params[in] DU UE CB
6811  *             Pointer to ReconfigurationWithSync_t
6812  *
6813  * @return ROK     - success
6814  *         RFAILED - failure
6815  *
6816  * ****************************************************************/
6817 uint8_t BuildRecfgWithSync(DuUeCb *ueCb, ReconfigurationWithSync_t *recfgWithSync)
6818 {
6819    /* SP Cell Config Common */  
6820    DU_ALLOC(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
6821    if(!recfgWithSync->spCellConfigCommon)
6822    {
6823       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for spCellConfigCommon in BuildRecfgWithSync()");
6824       return RFAILED;
6825    }
6826
6827    if((BuildSpCellConfigCommon(recfgWithSync->spCellConfigCommon)) != ROK)
6828    {
6829       DU_LOG("\nERROR  -->  DU APP : Failed to build SpCellConfigCommon in BuildRecfgWithSync()");
6830       return RFAILED;
6831    }
6832
6833    /* New UE Identity */
6834    recfgWithSync->newUE_Identity = ueCb->crnti;
6835
6836    /* T304 timer */
6837    recfgWithSync->t304 = ReconfigurationWithSync__t304_ms1000;
6838
6839    /* RACH configuration dedicated */
6840    DU_ALLOC(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
6841    if(!recfgWithSync->rach_ConfigDedicated)
6842    {
6843       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for RACH config dedicated in BuildRecfgWithSync()");
6844       return RFAILED;
6845    }
6846
6847    if((BuildRachConfigDedicated(ueCb, recfgWithSync->rach_ConfigDedicated)) != ROK)
6848    {
6849       DU_LOG("\nERROR  -->  DU APP : Failed to build RACH config dedicated in BuildRecfgWithSync()");
6850       return RFAILED;
6851    }
6852
6853    return ROK;
6854 }
6855
6856 /*******************************************************************
6857  *
6858  * @brief Builds Spcell config 
6859  *
6860  * @details
6861  *
6862  *    Function : BuildSpCellCfg 
6863  *
6864  *    Functionality: Builds sp cell config in DuToCuRrcContainer
6865  *
6866  * @params[in] SpCellConfig_t spCellCfg
6867  *
6868  * @return ROK     - success
6869  *         RFAILED - failure
6870  *
6871  * ****************************************************************/
6872 uint8_t BuildSpCellCfg(DuUeCb *ueCb, SpCellConfig_t *spCellCfg)
6873 {
6874    spCellCfg->servCellIndex = NULLP;
6875    DU_ALLOC(spCellCfg->servCellIndex, sizeof(long));
6876    if(!spCellCfg->servCellIndex)
6877    {
6878       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6879       return RFAILED;
6880    }
6881
6882    if(ueCb == NULLP)
6883       *(spCellCfg->servCellIndex) = SERV_CELL_IDX;
6884    else
6885       *(spCellCfg->servCellIndex) = ueCb->macUeCfg.spCellCfg.servCellIdx;
6886
6887    spCellCfg->reconfigurationWithSync = NULLP;
6888    if(ueCb && (ueCb->ueState == UE_HANDIN_IN_PROGRESS))
6889    {
6890       DU_ALLOC(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
6891       if(!spCellCfg->reconfigurationWithSync)
6892       {
6893          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6894          return RFAILED;
6895       }
6896
6897       if((BuildRecfgWithSync(ueCb, spCellCfg->reconfigurationWithSync)) != ROK)
6898       {
6899          DU_LOG("\nERROR  -->  F1AP : Building of reconfiguration with sync failed at BuildSpCellCfg");
6900          return RFAILED;
6901       }
6902    }
6903
6904    spCellCfg->rlf_TimersAndConstants = NULLP;
6905    spCellCfg->rlmInSyncOutOfSyncThreshold = NULLP;
6906
6907    DU_ALLOC(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
6908    if(!spCellCfg->rlmInSyncOutOfSyncThreshold)
6909    {
6910       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6911       return RFAILED;
6912    }
6913    *(spCellCfg->rlmInSyncOutOfSyncThreshold) = RLM_SYNC_OUT_SYNC_THRESHOLD;
6914
6915    spCellCfg->spCellConfigDedicated = NULLP;
6916    DU_ALLOC(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
6917    if(!spCellCfg->spCellConfigDedicated)
6918    {
6919       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6920       return RFAILED;
6921    }
6922    if(BuildSpCellCfgDed(ueCb, spCellCfg->spCellConfigDedicated) != ROK)
6923    {
6924       DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfgDed failed");
6925       return RFAILED;
6926    }
6927
6928    return ROK;
6929 }
6930
6931 /*******************************************************************
6932  *
6933  * @brief Builds Phy cell group config 
6934  *
6935  * @details
6936  *
6937  *    Function : BuildPhyCellGrpCfg 
6938  *
6939  *    Functionality: Builds Phy cell group config in DuToCuRrcContainer
6940  *
6941  * @params[in] PhysicalCellGroupConfig_t *phyCellGrpCfg 
6942  *
6943  * @return ROK     - success
6944  *         RFAILED - failure
6945  *
6946  * ****************************************************************/
6947 uint8_t BuildPhyCellGrpCfg(DuUeCb *ueCb, PhysicalCellGroupConfig_t *phyCellGrpCfg)
6948 {
6949    phyCellGrpCfg->harq_ACK_SpatialBundlingPUCCH = NULLP;
6950    phyCellGrpCfg->harq_ACK_SpatialBundlingPUSCH = NULLP;
6951
6952    phyCellGrpCfg->p_NR_FR1 = NULLP;
6953    DU_ALLOC(phyCellGrpCfg->p_NR_FR1, sizeof(long));
6954    if(!phyCellGrpCfg->p_NR_FR1)
6955    {
6956       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhyCellGrpCfg");
6957       return RFAILED;
6958    }
6959
6960    if(ueCb == NULLP)
6961    {
6962       *(phyCellGrpCfg->p_NR_FR1)             = P_NR_FR1;
6963       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = PDSCH_HARQ_ACK_CODEBOOK;
6964    }
6965    else
6966    {
6967       *(phyCellGrpCfg->p_NR_FR1) = ueCb->macUeCfg.phyCellGrpCfg.pNrFr1;
6968       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = ueCb->macUeCfg.phyCellGrpCfg.pdschHarqAckCodebook;
6969    }
6970
6971    phyCellGrpCfg->tpc_SRS_RNTI = NULLP;
6972    phyCellGrpCfg->tpc_PUCCH_RNTI = NULLP;
6973    phyCellGrpCfg->tpc_PUSCH_RNTI = NULLP;
6974    phyCellGrpCfg->sp_CSI_RNTI = NULLP;
6975    phyCellGrpCfg->cs_RNTI = NULLP;
6976    phyCellGrpCfg->ext1 = NULLP;
6977    phyCellGrpCfg->ext2 = NULLP;
6978
6979    return ROK;
6980 }
6981
6982 /*******************************************************************
6983  *
6984  * @brief Builds Mac cell group config 
6985  *
6986  * @details
6987  *
6988  *    Function : BuildMacCellGrpCfg 
6989  *
6990  *    Functionality: Builds Mac cell group config in DuToCuRrcContainer
6991  *
6992  * @params[in] MAC_CellGroupConfig_t *macCellGrpCfg
6993  *
6994  * @return ROK     - success
6995  *         RFAILED - failure
6996  *
6997  * ****************************************************************/
6998 uint8_t BuildMacCellGrpCfg(DuUeCb *ueCb, MAC_CellGroupConfig_t *macCellGrpCfg)
6999 {
7000    macCellGrpCfg->drx_Config = NULLP;
7001    macCellGrpCfg->schedulingRequestConfig = NULLP;
7002    DU_ALLOC(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
7003    if(!macCellGrpCfg->schedulingRequestConfig)
7004    {
7005       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7006       return RFAILED;
7007    }
7008
7009    if(BuildSchedulingReqConfig(ueCb, macCellGrpCfg->schedulingRequestConfig) != ROK)
7010    {
7011       DU_LOG("\nERROR  -->  F1AP : BuildSchedulingReqConfig failed");
7012       return RFAILED;
7013    }
7014
7015    macCellGrpCfg->bsr_Config = NULLP;
7016    DU_ALLOC(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
7017    if(!macCellGrpCfg->bsr_Config)
7018    {
7019       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7020       return RFAILED;
7021    }
7022
7023    if(BuildBsrConfig(ueCb, macCellGrpCfg->bsr_Config) != ROK)
7024    {
7025       DU_LOG("\nERROR  -->  F1AP : BuildBsrConfig failed");
7026       return RFAILED;
7027    }
7028
7029    macCellGrpCfg->tag_Config = NULLP;
7030    DU_ALLOC(macCellGrpCfg->tag_Config, sizeof(struct TAG_Config));
7031    if(!macCellGrpCfg->tag_Config)
7032    {
7033       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7034       return RFAILED;
7035    }
7036
7037    if(BuildTagConfig(ueCb, macCellGrpCfg->tag_Config) != ROK)
7038    {
7039       DU_LOG("\nERROR  -->  F1AP : BuildTagConfig failed");
7040       return RFAILED;
7041    }
7042
7043    macCellGrpCfg->phr_Config = NULLP;
7044    DU_ALLOC(macCellGrpCfg->phr_Config, sizeof(struct MAC_CellGroupConfig__phr_Config));
7045    if(!macCellGrpCfg->phr_Config)
7046    {
7047       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7048       return RFAILED;
7049    }
7050
7051    if(BuildPhrConfig(ueCb, macCellGrpCfg->phr_Config) != ROK)
7052    {
7053       DU_LOG("\nERROR  -->  F1AP : BuildPhrConfig failed");
7054       return RFAILED;
7055    }
7056
7057    macCellGrpCfg->skipUplinkTxDynamic = false;
7058    macCellGrpCfg->ext1 = NULLP;
7059
7060    return ROK;
7061 }
7062 /*******************************************************************
7063  *
7064  * @brief Frees memeory allocated for SearchSpcToAddModList
7065  *
7066  * @details
7067  *
7068  *    Function : FreeSearchSpcToAddModList
7069  *
7070  *    Functionality: Deallocating memory of SearchSpcToAddModList
7071  *
7072  * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
7073  *
7074  * @return void
7075  *
7076  4221 * ****************************************************************/
7077 void FreeSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
7078 {
7079    uint8_t idx1=0;
7080    uint8_t idx2=0;
7081    struct  SearchSpace *searchSpc=NULLP;
7082
7083    if(searchSpcList->list.array)
7084    {
7085       if(searchSpcList->list.array[idx2])
7086       {
7087          searchSpc = searchSpcList->list.array[idx2];
7088          if(searchSpc->controlResourceSetId)
7089          {
7090             if(searchSpc->monitoringSlotPeriodicityAndOffset)
7091             {
7092                if(searchSpc->monitoringSymbolsWithinSlot)
7093                {
7094                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
7095                   {
7096                      if(searchSpc->nrofCandidates)
7097                      {
7098                         if(searchSpc->searchSpaceType)
7099                         {
7100                            DU_FREE(searchSpc->searchSpaceType->choice.ue_Specific,\
7101                                  sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
7102                            DU_FREE(searchSpc->searchSpaceType, sizeof(struct
7103                                     SearchSpace__searchSpaceType));
7104                         }
7105                         DU_FREE(searchSpc->nrofCandidates,
7106                               sizeof(struct SearchSpace__nrofCandidates));
7107                      }
7108                      DU_FREE(searchSpc->monitoringSymbolsWithinSlot->buf, \
7109                            searchSpc->monitoringSymbolsWithinSlot->size);
7110                   }
7111                   DU_FREE(searchSpc->monitoringSymbolsWithinSlot,
7112                         sizeof(BIT_STRING_t));
7113                }
7114                DU_FREE(searchSpc->monitoringSlotPeriodicityAndOffset, \
7115                      sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
7116             }
7117             DU_FREE(searchSpc->controlResourceSetId,
7118                   sizeof(ControlResourceSetId_t));
7119          }
7120       }
7121       for(idx1 = 0; idx1 < searchSpcList->list.count; idx1++)
7122       {
7123          DU_FREE(searchSpcList->list.array[idx1],
7124                sizeof(struct SearchSpace));
7125       }
7126       DU_FREE(searchSpcList->list.array,searchSpcList->list.size);
7127    }
7128 }
7129 /*******************************************************************
7130  *
7131  * @brief Frees memory allocated for PdschTimeDomAllocList
7132  *
7133  * @details
7134  *
7135  *    Function : FreePdschTimeDomAllocList
7136  *
7137  *    Functionality: Deallocating memory of PdschTimeDomAllocList
7138  *
7139  * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
7140  *
7141  * @return void
7142  *
7143  * ****************************************************************/
7144 void FreePdschTimeDomAllocList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
7145 {
7146    uint8_t idx1=0;
7147
7148    if(timeDomAllocList->choice.setup)
7149    {
7150       if(timeDomAllocList->choice.setup->list.array)
7151       {
7152          for(idx1 = 0; idx1 <timeDomAllocList->choice.setup->list.count ; idx1++)
7153          {
7154             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1]->k0, sizeof(long));
7155             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1],
7156                   sizeof(struct PDSCH_TimeDomainResourceAllocation));
7157          }
7158          DU_FREE(timeDomAllocList->choice.setup->list.array, \
7159                timeDomAllocList->choice.setup->list.size);
7160       }
7161       DU_FREE(timeDomAllocList->choice.setup,\
7162             sizeof(struct PDSCH_TimeDomainResourceAllocationList));
7163    }
7164 }
7165 /*******************************************************************
7166  *
7167  * @brief Frees memory allocated for PuschTimeDomAllocList
7168  *
7169  *@details
7170  *
7171  *    Function : FreePuschTimeDomAllocList
7172  *
7173  *    Functionality: Deallocating memory of PuschTimeDomAllocList
7174  *
7175  * @params[in] PUSCH_Config_t *puschCfg
7176  *
7177  * @return void
7178  *
7179  * ****************************************************************/
7180 void FreePuschTimeDomAllocList(PUSCH_Config_t *puschCfg)
7181 {
7182    uint8_t rsrcListIdx=0;
7183    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
7184
7185    if(puschCfg->pusch_TimeDomainAllocationList)
7186    {
7187       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
7188       if(timeDomAllocList_t->choice.setup)
7189       {
7190          if(timeDomAllocList_t->choice.setup->list.array)
7191          {
7192             for(rsrcListIdx = 0; rsrcListIdx<timeDomAllocList_t->choice.setup->list.count; rsrcListIdx++)
7193             {
7194                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx]->k2, sizeof(long));
7195                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx],\
7196                      sizeof(PUSCH_TimeDomainResourceAllocation_t));
7197             }
7198             DU_FREE(timeDomAllocList_t->choice.setup->list.array, \
7199                   timeDomAllocList_t->choice.setup->list.size);
7200          }
7201          DU_FREE(timeDomAllocList_t->choice.setup, \
7202                sizeof(struct PUSCH_TimeDomainResourceAllocationList));
7203       }
7204       DU_FREE(puschCfg->transformPrecoder, sizeof(long));
7205       DU_FREE(puschCfg->pusch_TimeDomainAllocationList, \
7206             sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
7207    }
7208
7209 }
7210
7211 /*******************************************************************
7212  *
7213  * @brief Frees memory allocated for Dedicated PUCCH config
7214  *
7215  * @details
7216  *
7217  *    Function : FreeBWPUlDedPucchCfg
7218  *
7219  *    Functionality: Deallocating memory of Dedicated PUCCH cfg
7220  *
7221  * @params[in] BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg
7222  *
7223  * @return void
7224  *
7225  * ****************************************************************/
7226 void FreeBWPUlDedPucchCfg(struct BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg)
7227 {
7228    uint8_t k1Idx, rsrcIdx, rsrcSetIdx;
7229    PUCCH_Config_t *pucchCfg = NULLP;
7230    PUCCH_ResourceSet_t *rsrcSet = NULLP;
7231    PUCCH_Resource_t *rsrc = NULLP;
7232
7233    if(ulBwpPucchCfg)
7234    {
7235       if(ulBwpPucchCfg->choice.setup)
7236       {
7237          pucchCfg = ulBwpPucchCfg->choice.setup;
7238
7239          //Free resource set list
7240          if(pucchCfg->resourceSetToAddModList)
7241          {
7242             if(pucchCfg->resourceSetToAddModList->list.array)
7243             {
7244                for(rsrcSetIdx=0; rsrcSetIdx < pucchCfg->resourceSetToAddModList->list.count; rsrcSetIdx++)
7245                {
7246                   rsrcSet = pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx];
7247                   if(rsrcSet->resourceList.list.array)
7248                   {
7249                      for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
7250                      {
7251                         DU_FREE(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
7252                      }
7253                      DU_FREE(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
7254                   }
7255                   DU_FREE(pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
7256                }
7257                DU_FREE(pucchCfg->resourceSetToAddModList->list.array, pucchCfg->resourceSetToAddModList->list.size);
7258             }
7259             DU_FREE(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
7260          }
7261
7262          //Free resource list
7263          if(pucchCfg->resourceToAddModList)
7264          {
7265             if(pucchCfg->resourceToAddModList->list.array)
7266             {
7267                for(rsrcIdx=0; rsrcIdx < pucchCfg->resourceToAddModList->list.count; rsrcIdx++)
7268                {
7269                   rsrc = pucchCfg->resourceToAddModList->list.array[rsrcIdx];
7270                   DU_FREE(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
7271                   DU_FREE(pucchCfg->resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
7272                }
7273                DU_FREE(pucchCfg->resourceToAddModList->list.array, pucchCfg->resourceToAddModList->list.size);
7274             }
7275             DU_FREE(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
7276          }
7277
7278          //PUCCH Format 1
7279          if(pucchCfg->format1)
7280          {
7281             if(pucchCfg->format1->choice.setup)
7282             {
7283                DU_FREE(pucchCfg->format1->choice.setup->nrofSlots, sizeof(long));
7284                DU_FREE(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
7285             }
7286             DU_FREE(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
7287          }
7288          
7289          //DL DATA TO UL ACK
7290          if(pucchCfg->dl_DataToUL_ACK)
7291          {
7292             if(pucchCfg->dl_DataToUL_ACK->list.array)
7293             {
7294                for(k1Idx = 0; k1Idx <  pucchCfg->dl_DataToUL_ACK->list.count; k1Idx++)
7295                {
7296                   DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array[k1Idx], sizeof(long));
7297                }
7298                DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array, pucchCfg->dl_DataToUL_ACK->list.size);
7299             }
7300             DU_FREE(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
7301          }
7302
7303          DU_FREE(ulBwpPucchCfg->choice.setup, sizeof(PUCCH_Config_t));
7304       }
7305       DU_FREE(ulBwpPucchCfg, sizeof(struct BWP_UplinkDedicated__pucch_Config));
7306    }
7307 }
7308
7309 /*******************************************************************
7310  *
7311  * @brief Frees memory allocated for InitialUlBWP
7312  *
7313  * @details
7314  *
7315  *    Function : FreeInitialUlBWP
7316  *
7317  *    Functionality: Deallocating memory of InitialUlBWP
7318  *
7319  * @params[in] BWP_UplinkDedicated_t *ulBwp
7320  *
7321  * @return void
7322  *
7323  * ****************************************************************/
7324 void FreeInitialUlBWP(BWP_UplinkDedicated_t *ulBwp)
7325 {
7326    uint8_t  rSetIdx, rsrcIdx;
7327    SRS_Config_t   *srsCfg = NULLP;
7328    PUSCH_Config_t *puschCfg = NULLP;
7329    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
7330    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
7331    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
7332    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
7333
7334    FreeBWPUlDedPucchCfg(ulBwp->pucch_Config);
7335
7336    if(ulBwp->pusch_Config)
7337    {
7338       if(ulBwp->pusch_Config->choice.setup)
7339       {
7340          puschCfg=ulBwp->pusch_Config->choice.setup;
7341          if(puschCfg->dataScramblingIdentityPUSCH)
7342          {
7343             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
7344             {
7345                FreePuschTimeDomAllocList(puschCfg);
7346                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
7347                if(dmrsUlCfg->choice.setup)
7348                {
7349                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
7350                   {
7351                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
7352                      {
7353                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
7354                               sizeof(long));
7355                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled,
7356                               sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
7357                      }
7358                      DU_FREE(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition,
7359                            sizeof(long));
7360                   }
7361                   DU_FREE(dmrsUlCfg->choice.setup,sizeof(DMRS_UplinkConfig_t));
7362                }
7363                DU_FREE(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, \
7364                      sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
7365             }
7366             DU_FREE(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
7367          }
7368          DU_FREE(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
7369       }
7370       DU_FREE(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
7371
7372       /* Free SRS-Config */
7373       if(ulBwp->srs_Config)
7374       {
7375          if(ulBwp->srs_Config->choice.setup)
7376          {
7377             srsCfg = ulBwp->srs_Config->choice.setup;
7378
7379             /* Free Resource Set to add/mod list */
7380             if(srsCfg->srs_ResourceSetToAddModList)
7381             {
7382                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
7383                if(rsrcSetList->list.array)
7384                {
7385                   rSetIdx = 0;
7386
7387                   /* Free SRS resource Id list in this SRS resource set */
7388                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
7389                   {
7390                      rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
7391
7392                      if(rsrcIdList->list.array)
7393                      {
7394                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
7395                         {
7396                            DU_FREE(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
7397                         }
7398                         DU_FREE(rsrcIdList->list.array, rsrcIdList->list.size);
7399                      }
7400                      DU_FREE(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
7401                            sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
7402                   }
7403
7404                   /* Free resource type info for this SRS resource set */
7405                   DU_FREE(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
7406                         sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
7407
7408                   /* Free memory for each resource set */
7409                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
7410                   {
7411                      DU_FREE(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
7412                   }
7413                   DU_FREE(rsrcSetList->list.array, rsrcSetList->list.size); 
7414                }
7415                DU_FREE(srsCfg->srs_ResourceSetToAddModList, \
7416                      sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
7417             }
7418
7419             /* Free resource to add/modd list */
7420             if(srsCfg->srs_ResourceToAddModList)
7421             {
7422                resourceList = srsCfg->srs_ResourceToAddModList;
7423                if(resourceList->list.array)
7424                {
7425                   rsrcIdx = 0;
7426                   DU_FREE(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2,\
7427                         sizeof(struct SRS_Resource__transmissionComb__n2));
7428                   DU_FREE(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,\
7429                         sizeof(struct SRS_Resource__resourceType__aperiodic));
7430
7431                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
7432                   {
7433                      DU_FREE(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
7434                   }
7435                   DU_FREE(resourceList->list.array, resourceList->list.size);
7436                }
7437                DU_FREE(srsCfg->srs_ResourceToAddModList, \
7438                      sizeof(struct SRS_Config__srs_ResourceToAddModList));
7439             }
7440
7441             DU_FREE(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
7442          }
7443          DU_FREE(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
7444       }
7445    }
7446 }       
7447 /*******************************************************************
7448  *
7449  * @brief Frees memory allocated for initialUplinkBWP
7450  *
7451  * @details
7452  *
7453  *    Function : FreeinitialUplinkBWP
7454  *
7455  *    Functionality: Deallocating memory of initialUplinkBWP
7456  *
7457  * @params[in] UplinkConfig_t *ulCfg
7458  *
7459  * @return void
7460  *         
7461  *
7462  * ****************************************************************/
7463 void FreeinitialUplinkBWP(UplinkConfig_t *ulCfg)
7464 {
7465    BWP_UplinkDedicated_t *ulBwp=NULLP; 
7466    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
7467
7468    if(ulCfg->initialUplinkBWP)
7469    {
7470       ulBwp=ulCfg->initialUplinkBWP;
7471       if(ulCfg->firstActiveUplinkBWP_Id)
7472       {
7473          if(ulCfg->pusch_ServingCellConfig)
7474          {
7475             puschCfg=ulCfg->pusch_ServingCellConfig;
7476             if(puschCfg->choice.setup)
7477             {
7478                if(puschCfg->choice.setup->ext1)
7479                {
7480                   DU_FREE(puschCfg->choice.setup->ext1->\
7481                         processingType2Enabled,sizeof(BOOLEAN_t));
7482                   DU_FREE(puschCfg->choice.setup->ext1->\
7483                         maxMIMO_Layers,sizeof(long));
7484                   DU_FREE(puschCfg->choice.setup->ext1, \
7485                         sizeof(struct PUSCH_ServingCellConfig__ext1));
7486                }
7487                DU_FREE(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
7488             }
7489             DU_FREE(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
7490          }
7491          DU_FREE(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
7492       }
7493       FreeInitialUlBWP(ulBwp);
7494       DU_FREE(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
7495    }
7496 }
7497 /*******************************************************************
7498  *
7499  * @brief Frees emmory allocated for BWPDlDedPdschCfg
7500  *
7501  * @details
7502  *
7503  *    Function : FreeBWPDlDedPdschCfg
7504  *
7505  *    Functionality: Deallocating memory of BWPDlDedPdschCfg
7506  *
7507  * @params[in] BWP_DownlinkDedicated_t *dlBwp
7508  *
7509  * @return void
7510  *
7511  *
7512  * ****************************************************************/
7513 void FreeBWPDlDedPdschCfg(BWP_DownlinkDedicated_t *dlBwp)
7514 {
7515    struct PDSCH_Config *pdschCfg=NULLP;
7516    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
7517    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
7518    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
7519
7520    if(dlBwp->pdsch_Config->choice.setup)
7521    {
7522       pdschCfg=dlBwp->pdsch_Config->choice.setup;
7523       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
7524       {
7525          if(pdschCfg->pdsch_TimeDomainAllocationList)
7526          {
7527             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
7528             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
7529             {
7530                prbBndlType=&pdschCfg->prb_BundlingType;
7531                DU_FREE(prbBndlType->choice.staticBundling,\
7532                      sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
7533                DU_FREE(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
7534             }
7535             FreePdschTimeDomAllocList(timeDomAllocList);
7536             DU_FREE(pdschCfg->pdsch_TimeDomainAllocationList, \
7537                   sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
7538          }
7539          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
7540          if(dmrsDlCfg->choice.setup)
7541          {
7542             DU_FREE(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition,
7543                   sizeof(long));
7544             DU_FREE(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
7545          }
7546          DU_FREE(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, \
7547                sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
7548       }
7549       DU_FREE(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
7550    }
7551 }
7552 /*******************************************************************
7553  *
7554  * @brief Frees emmory allocated for BWPDlDedPdcchCfg
7555  *
7556  * @details
7557  *
7558  *    Function : FreeBWPDlDedPdcchCfg
7559  *
7560  *    Functionality: Deallocating memory of BWPDlDedPdcchCfg
7561  *
7562  * @params[in] BWP_DownlinkDedicated_t *dlBwp
7563  *
7564  * @return void
7565  *         
7566  *
7567  * ****************************************************************/
7568 void FreeBWPDlDedPdcchCfg(BWP_DownlinkDedicated_t *dlBwp)
7569 {
7570    uint8_t idx1=0;
7571    uint8_t idx2=0;
7572    struct PDCCH_Config *pdcchCfg=NULLP;
7573    struct ControlResourceSet *controlRSet=NULLP;
7574    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
7575
7576    if(dlBwp->pdcch_Config->choice.setup)
7577    {
7578       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
7579       if(pdcchCfg->controlResourceSetToAddModList)
7580       {
7581          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
7582          if(controlRSetList->list.array)
7583          {
7584             controlRSet = controlRSetList->list.array[idx2];
7585             if(controlRSet)
7586             {
7587                if(controlRSet->frequencyDomainResources.buf)
7588                {
7589                   if(controlRSet->pdcch_DMRS_ScramblingID)
7590                   {
7591                      if(pdcchCfg->searchSpacesToAddModList)
7592                      {
7593                         FreeSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
7594                         DU_FREE(pdcchCfg->searchSpacesToAddModList, \
7595                               sizeof(struct PDCCH_Config__searchSpacesToAddModList));
7596                      }
7597                      DU_FREE(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
7598                   }
7599                   DU_FREE(controlRSet->frequencyDomainResources.buf, \
7600                         controlRSet->frequencyDomainResources.size);
7601                }
7602             }
7603             for(idx1 = 0; idx1 <controlRSetList->list.count; idx1++)
7604             {
7605                DU_FREE(controlRSetList->list.array[idx1], sizeof(struct ControlResourceSet));
7606             }
7607             DU_FREE(controlRSetList->list.array, controlRSetList->list.size);
7608          }
7609          DU_FREE(pdcchCfg->controlResourceSetToAddModList, \
7610                sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
7611       }
7612       DU_FREE(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
7613    }
7614 }       
7615
7616 /*******************************************************************
7617  *
7618  * @brief Free SCS specific carrier list in DL frequency info
7619  *
7620  * @details
7621  *
7622  *    Function : FreeScsSpecificCarrierListDl
7623  *
7624  *    Functionality: Free SCS specific carrier list in DL frequency info
7625  *
7626  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
7627  *
7628  * @return void
7629  *
7630  * ****************************************************************/
7631 void FreeScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
7632 {
7633    uint8_t listIdx = 0;
7634
7635    if(!scsCarrierList->list.array)
7636    {
7637       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
7638       {
7639          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
7640       }
7641       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
7642    }
7643 }
7644
7645 /*******************************************************************
7646  *
7647  * @brief Free DL frequency info in DL config common
7648  *
7649  * @details
7650  *
7651  *    Function : FreeFreqInfoDl
7652  *
7653  *    Functionality: Free DL frequency info in DL config common
7654  *
7655  * @params[in] Pointer to DownlinkConfigCommon_t
7656  *
7657  * @return void
7658  *
7659  * ****************************************************************/
7660 void FreeFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
7661 {
7662    uint8_t freqBandIdx = 0;
7663
7664    /* SSB Absolute Frequency */
7665    DU_FREE(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
7666
7667    /* NR Multi Frequency Band List */
7668    if(frequencyInfoDL->frequencyBandList.list.array)
7669    {
7670       for(freqBandIdx = 0; freqBandIdx < frequencyInfoDL->frequencyBandList.list.count; freqBandIdx++)
7671       {
7672          DU_FREE(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
7673       }
7674       DU_FREE(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
7675    }
7676
7677    /* Subcarrier Spacing specifc carrier List */
7678    FreeScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList);
7679 }
7680
7681 /*******************************************************************
7682  *
7683  * @brief Free DL config common in Serving cell config common
7684  *
7685  * @details
7686  *
7687  *    Function : FreeDlConfigCommon
7688  *
7689  *    Functionality: Free DL config common in Serving cell config common
7690  *
7691  * @params[in] Pointer to DownlinkConfigCommon_t
7692  *
7693  * @return void
7694  *
7695  * ****************************************************************/
7696 void FreeDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
7697 {
7698    /* DL Frequency Info */
7699    if(dlCfgCommon->frequencyInfoDL)
7700    {
7701       FreeFreqInfoDl(dlCfgCommon->frequencyInfoDL);
7702       DU_FREE(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
7703    }
7704
7705    /* DL BWP config common */
7706    if(dlCfgCommon->initialDownlinkBWP)
7707    {
7708       FreeBwpDlCommon(dlCfgCommon->initialDownlinkBWP);
7709       DU_FREE(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
7710    }
7711 }
7712
7713 /*******************************************************************
7714  *
7715  * @brief Free SCS specific carrier list in UL frequency Info
7716  *
7717  * @details
7718  *
7719  *    Function : FreeScsSpecificCarrierListUl
7720  *
7721  *    Functionality: Free SCS specific carrier list in UL frequency Info
7722  *
7723  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
7724  *
7725  * @return void
7726  *
7727  * ****************************************************************/
7728 void FreeScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
7729 {
7730    uint8_t listIdx = 0;
7731
7732    if(scsCarrierList->list.array)
7733    {
7734       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
7735       {
7736          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
7737       }
7738       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
7739    }
7740 }
7741
7742 /*******************************************************************
7743  *
7744  * @brief Free frequency info in UL config common
7745  *
7746  * @details
7747  *
7748  *    Function : FreeFreqInfoUl
7749  *
7750  *    Functionality: Free frequency info in UL config common
7751  *
7752  * @params[in] Pointer to FrequencyInfoUL_t
7753  *
7754  * @return void
7755  *
7756  * ****************************************************************/
7757 void FreeFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
7758 {
7759    uint8_t listIdx= 0;
7760
7761    /* NR Multi Frequency Band List */
7762    if(!frequencyInfoUL->frequencyBandList)
7763    {
7764       if(frequencyInfoUL->frequencyBandList->list.array)
7765       {
7766          for(listIdx = 0; listIdx < frequencyInfoUL->frequencyBandList->list.count; listIdx++)
7767          {
7768             DU_FREE(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
7769          }
7770          DU_FREE(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
7771       }
7772       DU_FREE(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
7773    }
7774
7775    /* Absolute frequency point A */
7776    DU_FREE(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
7777
7778    /* Subcarrier Spacing specifc carrier */
7779    FreeScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList);
7780
7781    /* P-MAX */
7782    DU_FREE(frequencyInfoUL->p_Max, sizeof(P_Max_t));
7783 }
7784
7785 /*******************************************************************
7786  *
7787  * @brief Free UL config common in Serving cell config common
7788  *
7789  * @details
7790  *
7791  *    Function : FreeUlConfigCommon
7792  *
7793  *    Functionality: Free UL config common in Serving cell config common
7794  *
7795  * @params[in] Pointer to UplinkConfigCommon_t
7796  *
7797  * @return void
7798  *
7799  * ****************************************************************/
7800 void FreeUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
7801 {
7802    /* UL Frequency Info */
7803    if(ulCfgCommon->frequencyInfoUL)
7804    {
7805       FreeFreqInfoUl(ulCfgCommon->frequencyInfoUL);
7806       DU_FREE(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
7807    }
7808
7809    /* UL BWP common */
7810    if(ulCfgCommon->initialUplinkBWP)
7811    {
7812       FreeBwpUlCommon(ulCfgCommon->initialUplinkBWP);
7813       DU_FREE(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
7814    }
7815 }
7816
7817 /*******************************************************************
7818  *
7819  * @brief Free SP cell config common in Reconfig with Sync
7820  *
7821  * @details
7822  *
7823  *    Function : FreeSpCellConfigCommon
7824  *
7825  *    Functionality: Free SP cell config common in Reconfig with Sync
7826  *
7827  * @params[in] Pointer to ServingCellConfigCommon_t
7828  *
7829  * @return void
7830  *
7831  * ****************************************************************/
7832 void FreeSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
7833 {
7834    /* Free Physical cell identity */
7835    DU_FREE(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
7836
7837    /* Free Downlink Config common */
7838    if(spCellConfigCommon->downlinkConfigCommon)
7839    {
7840       FreeDlConfigCommon(spCellConfigCommon->downlinkConfigCommon);
7841       DU_FREE(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
7842    }
7843
7844    /* Free Uplink Config common */
7845    if(spCellConfigCommon->uplinkConfigCommon)
7846    {
7847       FreeUlConfigCommon(spCellConfigCommon->uplinkConfigCommon);
7848       DU_FREE(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
7849    }
7850
7851    /* Free Timing Advance offset */
7852    DU_FREE(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
7853
7854    /* Free SSB Position in Burst */
7855    if(spCellConfigCommon->ssb_PositionsInBurst)
7856    {
7857       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.buf, \
7858          spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.size);
7859       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
7860    }
7861
7862    /* Free SSB Periodicity in Serving cell */
7863    DU_FREE(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
7864
7865    /* Free SSB subcarrier spacing */
7866    DU_FREE(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
7867
7868    /* TDD UL-DL configuration common */
7869    DU_FREE(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
7870 }
7871
7872 /*******************************************************************
7873  *
7874  * @brief Free dedicated RACH configuration in Reconfiguration with sync
7875  *
7876  * @details
7877  *
7878  *    Function : FreeRecfgWithSync
7879  *
7880  *    Functionality:
7881  *       Free dedicated RACH configuration in Reconfiguration with sync
7882  *
7883  * @params[in] Pinter to Rach config dedicated struct
7884  *
7885  * @return void
7886  *
7887  * ****************************************************************/
7888 void FreeRachConfigDedicated(struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
7889 {
7890    uint8_t listIdx = 0;
7891    CFRA_t *cfra = NULLP;
7892    struct CFRA__resources__ssb *ssbResource = NULLP;
7893
7894    /* Uplink */
7895    if(rachCfgDed->choice.uplink)
7896    {
7897       /* CFRA : Contention free Random Access */
7898       if(rachCfgDed->choice.uplink->cfra)
7899       {
7900          cfra = rachCfgDed->choice.uplink->cfra;
7901
7902          /* CFRA occassions */
7903          if(cfra->occasions)
7904          {
7905             /* CFRA occassions : SSB per RACH occasion */
7906             DU_FREE(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
7907             DU_FREE(cfra->occasions, sizeof(struct CFRA__occasions));
7908          }
7909
7910          /* CFRA resource */
7911          cfra->resources.present = CFRA__resources_PR_ssb;
7912
7913          /* CFRA resource : SSB */
7914          if(cfra->resources.choice.ssb)
7915          {
7916             ssbResource = cfra->resources.choice.ssb;
7917
7918             /* CFRA SSB resource list */
7919             if(ssbResource->ssb_ResourceList.list.array)
7920             {
7921                for(listIdx = 0; listIdx < ssbResource->ssb_ResourceList.list.count; listIdx++)
7922                {
7923                   DU_FREE(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
7924                }
7925                DU_FREE(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
7926             }
7927             DU_FREE(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
7928          }
7929          DU_FREE(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
7930       }
7931       DU_FREE(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
7932    }
7933 }
7934
7935 /*******************************************************************
7936  *
7937  * @brief Frees reconfiguration with sync in SP cell config
7938  *
7939  * @details
7940  *
7941  *    Function : FreeRecfgWithSync
7942  *
7943  *    Functionality: Fress reconfiguration with sync in SP cell config
7944  *
7945  * @params[in] Pointer to ReconfigurationWithSync_t
7946  *
7947  * @return void
7948  *
7949  * ****************************************************************/
7950 void FreeRecfgWithSync(ReconfigurationWithSync_t *recfgWithSync)
7951 {
7952    /* Free SP Cell config common */
7953    if(recfgWithSync->spCellConfigCommon)
7954    {
7955       FreeSpCellConfigCommon(recfgWithSync->spCellConfigCommon);
7956       DU_FREE(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
7957    }
7958
7959    /* Free Dedicated RACH configuration */
7960    if(recfgWithSync->rach_ConfigDedicated)
7961    {
7962       FreeRachConfigDedicated(recfgWithSync->rach_ConfigDedicated);
7963       DU_FREE(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
7964    }
7965 }
7966
7967 /*******************************************************************
7968  *
7969  * @brief Frees emmory allocated for DUToCURRCContainer 
7970  *
7971  * @details
7972  *
7973  *    Function : FreeMemDuToCuRrcCont
7974  *
7975  *    Functionality: Deallocating memory of DuToCuRrcContainer
7976  *
7977  * @params[in] DuToCuRRCContainer, DuToCuRRCContainer
7978  *
7979  * @return ROK     - success
7980  *         RFAILED - failure
7981  *
7982  * ****************************************************************/
7983 uint8_t FreeMemDuToCuRrcCont(CellGroupConfigRrc_t *cellGrpCfg)
7984 {
7985    uint8_t idx=0;
7986    SpCellConfig_t *spCellCfg=NULLP;
7987    ServingCellConfig_t *srvCellCfg=NULLP;
7988    BWP_DownlinkDedicated_t *dlBwp=NULLP;
7989    MAC_CellGroupConfig_t *macCellGrpCfg=NULLP;
7990    PhysicalCellGroupConfig_t *phyCellGrpCfg=NULLP;
7991    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList=NULLP;
7992    struct RLC_Config *rlcConfig=NULLP;
7993    struct LogicalChannelConfig *macLcConfig=NULLP;
7994    struct SchedulingRequestConfig *schedulingRequestConfig=NULLP;
7995    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList=NULLP;
7996    struct TAG_Config *tagConfig=NULLP;
7997    struct TAG_Config__tag_ToAddModList *tagList=NULLP;
7998    struct MAC_CellGroupConfig__phr_Config *phrConfig=NULLP;
7999    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg=NULLP;
8000
8001    rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
8002    if(rlcBearerList)
8003    {
8004       if(rlcBearerList->list.array)
8005       {
8006          for(idx=0; idx<rlcBearerList->list.count; idx++)
8007          {
8008             if(rlcBearerList->list.array[idx])
8009             {  
8010                rlcConfig   = rlcBearerList->list.array[idx]->rlc_Config;
8011                macLcConfig = rlcBearerList->list.array[idx]->mac_LogicalChannelConfig;
8012                if(rlcConfig)
8013                {
8014                   switch(rlcConfig->present)
8015                   {
8016                      case RLC_Config_PR_am:
8017                         {
8018                            if(rlcConfig->choice.am)
8019                            {
8020                               DU_FREE(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
8021                               DU_FREE(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
8022                               DU_FREE(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
8023                            }
8024                            break;
8025                         }
8026                      case RLC_Config_PR_um_Bi_Directional:
8027                         {
8028                            if(rlcConfig->choice.um_Bi_Directional)
8029                            {
8030                               DU_FREE(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t)); 
8031                               DU_FREE(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8032                               DU_FREE(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
8033                            }
8034                            break;
8035                         }
8036                      case RLC_Config_PR_um_Uni_Directional_UL:
8037                         {
8038                            if(rlcConfig->choice.um_Uni_Directional_UL)
8039                            {
8040                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8041                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
8042                            }
8043                            break;
8044                         }
8045                      case RLC_Config_PR_um_Uni_Directional_DL:
8046                         {
8047                            if(rlcConfig->choice.um_Uni_Directional_DL )
8048                            {
8049                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8050                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
8051                            }
8052                            break;
8053                         }
8054                   }     
8055                   DU_FREE(rlcConfig, sizeof(struct RLC_Config));
8056                }
8057                DU_FREE(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
8058                if(macLcConfig)
8059                {
8060                   if(macLcConfig->ul_SpecificParameters)
8061                   {
8062                      DU_FREE(macLcConfig->ul_SpecificParameters->schedulingRequestID,   sizeof(SchedulingRequestId_t));
8063                      DU_FREE(macLcConfig->ul_SpecificParameters->logicalChannelGroup,   sizeof(long));
8064                      DU_FREE(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
8065                   }
8066                   DU_FREE(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
8067                }
8068                DU_FREE(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
8069             }   
8070          }
8071          DU_FREE(rlcBearerList->list.array, rlcBearerList->list.size);
8072       }
8073       DU_FREE(cellGrpCfg->rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8074    }
8075
8076    macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
8077    if(macCellGrpCfg)
8078    {
8079       schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig; 
8080       if(schedulingRequestConfig)
8081       {
8082          schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
8083          if(schReqList)
8084          {
8085             if(schReqList->list.array)
8086             {
8087                for(idx=0;idx<schReqList->list.count; idx++)
8088                {
8089                   if(schReqList->list.array[idx])
8090                   {
8091                      DU_FREE(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
8092                      DU_FREE(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
8093                   }
8094                }
8095                DU_FREE(schReqList->list.array, schReqList->list.size);
8096             }
8097             DU_FREE(schedulingRequestConfig->schedulingRequestToAddModList,\
8098                   sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));    }
8099             DU_FREE(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
8100       }
8101       if(macCellGrpCfg->bsr_Config)
8102       {
8103          DU_FREE(macCellGrpCfg->bsr_Config->logicalChannelSR_DelayTimer, sizeof(long));
8104          DU_FREE(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
8105       }
8106       tagConfig = macCellGrpCfg->tag_Config;
8107       if(tagConfig)
8108       {
8109          tagList = tagConfig->tag_ToAddModList;
8110          if(tagList)
8111          {
8112             if(tagList->list.array)
8113             {
8114                for(idx=0; idx<tagList->list.count; idx++)
8115                {
8116                   DU_FREE(tagList->list.array[idx], sizeof(struct TAG));
8117                }
8118                DU_FREE(tagList->list.array, tagList->list.size);
8119             }
8120             DU_FREE(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
8121          }
8122          DU_FREE(tagConfig, sizeof(struct TAG_Config));
8123       }
8124
8125       phrConfig = macCellGrpCfg->phr_Config;
8126       if(phrConfig)
8127       {
8128          DU_FREE(phrConfig->choice.setup, sizeof(struct PHR_Config));
8129          DU_FREE(phrConfig, sizeof(struct MAC_CellGroupConfig__phr_Config));
8130       }
8131
8132       DU_FREE(macCellGrpCfg, sizeof(MAC_CellGroupConfig_t));
8133    }
8134
8135    phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
8136    if(phyCellGrpCfg)
8137    {
8138       DU_FREE(phyCellGrpCfg->p_NR_FR1, sizeof(long));
8139       DU_FREE(phyCellGrpCfg, sizeof(PhysicalCellGroupConfig_t));
8140    }
8141
8142    spCellCfg = cellGrpCfg->spCellConfig;
8143    if(spCellCfg)
8144    {
8145       /* Free serving cell index */
8146       DU_FREE(spCellCfg->servCellIndex, sizeof(long));
8147
8148       /* Free Reconfiguration with sync */
8149       if(spCellCfg->reconfigurationWithSync)
8150       {
8151          FreeRecfgWithSync(spCellCfg->reconfigurationWithSync);
8152          DU_FREE(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
8153       }
8154
8155       /* Free rlmInSyncOutOfSyncThreshold */
8156       DU_FREE(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
8157
8158       /* Free SP Cell config dedicated */
8159       if(spCellCfg->spCellConfigDedicated)
8160       {
8161          srvCellCfg = spCellCfg->spCellConfigDedicated;
8162
8163          /* Free TDD UL-DL config dedicated */
8164          DU_FREE(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
8165
8166          /* Free Initial Downlink BWP */
8167          if(srvCellCfg->initialDownlinkBWP)
8168          {
8169             dlBwp = srvCellCfg->initialDownlinkBWP;
8170
8171             /* Free DL BWP PDCCH Config */
8172             if(dlBwp->pdcch_Config)
8173             {
8174                FreeBWPDlDedPdcchCfg(dlBwp);
8175                DU_FREE(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
8176             }
8177
8178             /* Free DL BWP PDSCH config */
8179             if(dlBwp->pdsch_Config)
8180             {
8181                FreeBWPDlDedPdschCfg(dlBwp);
8182                DU_FREE(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
8183             }
8184             DU_FREE(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
8185          }
8186
8187          /* Free First Active Downlink BWP */
8188          DU_FREE(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
8189
8190          /* Free Default downlink BWP */
8191          DU_FREE(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
8192
8193          /* Free Uplink config */
8194          if(srvCellCfg->uplinkConfig)
8195          {
8196             FreeinitialUplinkBWP(srvCellCfg->uplinkConfig);
8197             DU_FREE(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));  
8198          }
8199
8200          /* Free PDSCH serving cell config */
8201          if(srvCellCfg->pdsch_ServingCellConfig)
8202          {
8203             pdschCfg= srvCellCfg->pdsch_ServingCellConfig;
8204             if(pdschCfg->choice.setup)
8205             {
8206                DU_FREE(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH,sizeof(long));
8207                DU_FREE(pdschCfg->choice.setup, sizeof(struct PDSCH_ServingCellConfig));
8208             }
8209             DU_FREE(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct ServingCellConfig__pdsch_ServingCellConfig));
8210          }
8211
8212          DU_FREE(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
8213       }
8214       DU_FREE(spCellCfg,sizeof(SpCellConfig_t));
8215    }
8216    return ROK;
8217 }
8218
8219 /*******************************************************************
8220  *
8221  * @brief Builds CellGroupConfigRrc for DU To CU RRC Container 
8222  *
8223  * @details
8224  *
8225  *    Function : BuildCellGroupConfigRrc
8226  *
8227  *    Functionality: Builds and copied Cell group config buffer into 
8228  *       DuToCuRrcContainer
8229  *
8230  * @params[in] idx, index in F1AP msg
8231  *             DuToCuRRCContainer, DuToCuRRCContainer
8232  *
8233  * @return ROK     - success
8234  *         RFAILED - failure
8235  *
8236  * ****************************************************************/
8237 uint8_t BuildCellGroupConfigRrc(DuUeCb *ueCb, OCTET_STRING_t *duToCuRrcContainer)
8238 {
8239    uint8_t  ret = ROK;
8240    CellGroupConfigRrc_t  cellGrpCfg;
8241    asn_enc_rval_t        encRetVal;
8242    memset(&cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
8243    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8244
8245    while(true)
8246    {
8247       cellGrpCfg.cellGroupId = CELL_GRP_ID;
8248
8249       cellGrpCfg.rlc_BearerToAddModList = NULLP;
8250       DU_ALLOC(cellGrpCfg.rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8251       if(!cellGrpCfg.rlc_BearerToAddModList)
8252       {
8253          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8254          ret = RFAILED;
8255          break;
8256       }
8257       if(BuildRlcBearerToAddModList(ueCb, cellGrpCfg.rlc_BearerToAddModList) != ROK)
8258       {
8259          DU_LOG("\nERROR  -->  F1AP : BuildRlcBearerToAddModList failed");
8260          ret = RFAILED;
8261          break;
8262       }
8263
8264       cellGrpCfg.rlc_BearerToReleaseList = NULLP;
8265       cellGrpCfg.mac_CellGroupConfig = NULLP;
8266       DU_ALLOC(cellGrpCfg.mac_CellGroupConfig, sizeof(MAC_CellGroupConfig_t));
8267       if(!cellGrpCfg.mac_CellGroupConfig)
8268       {
8269          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8270          ret = RFAILED;
8271          break;
8272       }
8273       if(BuildMacCellGrpCfg(ueCb, cellGrpCfg.mac_CellGroupConfig) != ROK)
8274       {
8275          DU_LOG("\nERROR  -->  F1AP : BuildMacCellGrpCfg failed");
8276          ret = RFAILED;
8277          break;
8278       }
8279
8280       cellGrpCfg.physicalCellGroupConfig = NULLP;
8281       DU_ALLOC(cellGrpCfg.physicalCellGroupConfig, sizeof(PhysicalCellGroupConfig_t));
8282       if(!cellGrpCfg.physicalCellGroupConfig)
8283       {
8284          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8285          ret = RFAILED;
8286          break;
8287       }
8288       if(BuildPhyCellGrpCfg(ueCb, cellGrpCfg.physicalCellGroupConfig) != ROK)
8289       {
8290          DU_LOG("\nERROR  -->  F1AP : BuildPhyCellGrpCfg failed");
8291          ret = RFAILED;
8292          break;
8293       }
8294
8295       cellGrpCfg.spCellConfig = NULLP;
8296       DU_ALLOC(cellGrpCfg.spCellConfig, sizeof(SpCellConfig_t));
8297       if(!cellGrpCfg.spCellConfig)
8298       {
8299          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8300          ret = RFAILED;
8301          break;
8302       }
8303       if(BuildSpCellCfg(ueCb, cellGrpCfg.spCellConfig) != ROK)
8304       {
8305          DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfg failed");
8306          ret = RFAILED;
8307          break;
8308       }
8309
8310       cellGrpCfg.sCellToAddModList = NULLP;
8311       cellGrpCfg.sCellToReleaseList = NULLP;
8312       cellGrpCfg.ext1 = NULLP;
8313
8314       /* encode cellGrpCfg into duToCuRrcContainer */
8315       xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, &cellGrpCfg);
8316       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8317       encBufSize = 0;
8318       encRetVal = aper_encode(&asn_DEF_CellGroupConfigRrc, 0, &cellGrpCfg, PrepFinalEncBuf, encBuf);
8319       /* Encode results */
8320       if(encRetVal.encoded == ENCODE_FAIL)
8321       {
8322          DU_LOG( "\nERROR  --> F1AP : Could not encode DuToCuRrcContainer (at %s)\n",\
8323                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
8324          ret = RFAILED;
8325          break;
8326       }
8327       else
8328       {
8329          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DuToCuRrcContainer\n");
8330          for(int i=0; i< encBufSize; i++)
8331          {
8332             printf("%x",encBuf[i]);
8333          }
8334       }
8335
8336       duToCuRrcContainer->size = encBufSize;
8337       DU_ALLOC(duToCuRrcContainer->buf, duToCuRrcContainer->size);
8338       if(!duToCuRrcContainer->buf)
8339       {
8340          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDuToCuRrcContainer");
8341          ret = RFAILED;
8342          break;
8343       }
8344       if(ret == ROK)
8345       {
8346          memcpy(duToCuRrcContainer->buf, encBuf, duToCuRrcContainer->size);
8347       }
8348       break;
8349    }
8350    FreeMemDuToCuRrcCont(&cellGrpCfg);
8351    return ret;
8352 }
8353
8354 /*******************************************************************
8355  *
8356  * @brief Free memory allocated in InitialULRRCMessage
8357  *
8358  * @details
8359  *
8360  *    Function : freeInitUlRrcMsgTransfer
8361  *
8362  *    Functionality: Free memory allocated in InitialULRRCMessage
8363  *
8364  * @params[in]F1AP_PDU_t  *f1apMsg)
8365  *
8366  * @return ROK     - success
8367  *         RFAILED - failure
8368  *
8369  * ****************************************************************/
8370
8371 uint8_t freeInitUlRrcMsgTransfer(F1AP_PDU_t  *f1apMsg)
8372 {
8373    uint8_t ieIdx, arrIdx;
8374    InitialULRRCMessageTransfer_t *initULRRCMsg=NULLP;
8375
8376    if(f1apMsg)
8377    {
8378       if(f1apMsg->choice.initiatingMessage)
8379       {
8380          initULRRCMsg = &f1apMsg->choice.initiatingMessage->value.\
8381             choice.InitialULRRCMessageTransfer;
8382          if(initULRRCMsg->protocolIEs.list.array)
8383          {
8384             for(ieIdx = 0; ieIdx < initULRRCMsg->protocolIEs.list.count; ieIdx++)
8385             {
8386                switch(initULRRCMsg->protocolIEs.list.array[ieIdx]->id)
8387                {
8388                   case ProtocolIE_ID_id_NRCGI:
8389                   {
8390                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf)
8391                      {
8392                         if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf)
8393                         {
8394                            DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf,\
8395                            initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.size);
8396                         }
8397                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf,\
8398                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.size);
8399                      }
8400                      break;
8401                   }
8402                   case ProtocolIE_ID_id_RRCContainer:
8403                   {
8404                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
8405                      {
8406                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,\
8407                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
8408                      }
8409                      break;
8410                   }
8411                   case ProtocolIE_ID_id_DUtoCURRCContainer:
8412                   {
8413                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf)
8414                      {
8415                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf,
8416                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.size);
8417                      }
8418                      break;
8419                   }
8420                   default:
8421                      break;
8422                }
8423              }
8424              for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
8425              {
8426                 if(initULRRCMsg->protocolIEs.list.array[arrIdx])
8427                 {
8428                    DU_FREE(initULRRCMsg->protocolIEs.list.array[arrIdx],\
8429                       sizeof(InitialULRRCMessageTransferIEs_t));
8430                 }
8431              }
8432              DU_FREE(initULRRCMsg->protocolIEs.list.array, initULRRCMsg->protocolIEs.list.size);
8433           }
8434          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8435       }
8436       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
8437    }
8438    else
8439    {
8440       DU_LOG("\nERROR  -->  DU_APP : Recevied F1ap Pdu is null at freeInitUlRrcMsgTransfer()");
8441       return RFAILED;
8442    }
8443    return ROK;
8444 }
8445
8446 /*******************************************************************
8447  *
8448  * @brief Builds and sends the InitialULRRCMessage 
8449  *
8450  * @details
8451  *
8452  *    Function : BuildAndSendInitialRrcMsgTransfer 
8453  *
8454  *    Functionality: Constructs the Initial UL RRC Message Transfer and sends
8455  *                   it to the CU through SCTP.
8456  *
8457  * @params[in] 
8458  *
8459  * @return ROK     - success
8460  *         RFAILED - failure
8461  *
8462  * ****************************************************************/
8463 uint8_t BuildAndSendInitialRrcMsgTransfer(uint32_t gnbDuUeF1apId, uint16_t crnti,
8464       uint16_t rrcContSize, uint8_t *rrcContainer)
8465 {
8466    uint8_t   ret;
8467    uint8_t   elementCnt;
8468    uint8_t   ieIdx, cellIdx, ueIdx;
8469    DuUeCb    *duUeCb = NULLP;
8470    asn_enc_rval_t  encRetVal;
8471    F1AP_PDU_t  *f1apMsg = NULLP;
8472    InitialULRRCMessageTransfer_t *initULRRCMsg = NULLP;
8473    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8474
8475    while(true)
8476    {
8477       DU_LOG("\n INFO   -->  F1AP : Building RRC Setup Request\n");
8478       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
8479       if(f1apMsg == NULLP)
8480       {
8481          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
8482          break;
8483       }
8484       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
8485       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8486       if(f1apMsg->choice.initiatingMessage == NULLP)
8487       {
8488          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU failed");
8489          break;
8490       }
8491       f1apMsg->choice.initiatingMessage->procedureCode =\
8492                                                         ProcedureCode_id_InitialULRRCMessageTransfer;
8493       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
8494       f1apMsg->choice.initiatingMessage->value.present = \
8495                                                          InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
8496       initULRRCMsg =\
8497                     &f1apMsg->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
8498       elementCnt = 5;
8499       initULRRCMsg->protocolIEs.list.count = elementCnt;
8500       initULRRCMsg->protocolIEs.list.size = \
8501                                             elementCnt * sizeof(InitialULRRCMessageTransferIEs_t *);
8502       /* Initialize the F1Setup members */
8503       DU_ALLOC(initULRRCMsg->protocolIEs.list.array,initULRRCMsg->protocolIEs.list.size);
8504       if(initULRRCMsg->protocolIEs.list.array == NULLP)
8505       {
8506          DU_LOG(" ERROR  -->  F1AP : Memory allocation for\
8507                RRCSetupRequestMessageTransferIEs failed");
8508          break;
8509       }
8510       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
8511       {
8512          DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx],\
8513                sizeof(InitialULRRCMessageTransferIEs_t));
8514          if(initULRRCMsg->protocolIEs.list.array[ieIdx] == NULLP)
8515          {
8516             break;
8517          }
8518       }
8519       ieIdx = 0;
8520       /*GNB DU UE F1AP ID*/
8521       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8522                                                         ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
8523       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  = Criticality_reject;
8524       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
8525                                                                   InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
8526       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
8527
8528
8529       /*NRCGI*/
8530       ieIdx++;
8531       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8532                                                         ProtocolIE_ID_id_NRCGI;
8533       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  =Criticality_reject;
8534       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
8535                                                                   InitialULRRCMessageTransferIEs__value_PR_NRCGI;
8536
8537       ret =\
8538            BuildNrcgi(&initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
8539       if(ret!=ROK)
8540       {
8541          break;
8542       }
8543
8544       /*CRNTI*/
8545       ieIdx++;
8546       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8547                                                         ProtocolIE_ID_id_C_RNTI;
8548       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
8549       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
8550                                                                  InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
8551       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.C_RNTI = crnti;
8552
8553       /*RRCContainer*/
8554       ieIdx++;
8555       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8556                                                         ProtocolIE_ID_id_RRCContainer;
8557       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
8558       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
8559                                                                  InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
8560
8561       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size = rrcContSize;
8562       DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,
8563             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size)
8564       if(!initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
8565       {
8566          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRCSetupRequestMessageTransferIEs failed");
8567          break;
8568       
8569       }
8570       memcpy(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, rrcContainer,
8571             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
8572
8573
8574       /*DUtoCURRCContainer*/
8575       ieIdx++;
8576       initULRRCMsg->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCContainer;
8577       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
8578       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
8579                                                                  InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
8580
8581       for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
8582       {
8583          for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
8584          {
8585             if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
8586                   (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti == crnti))
8587             {
8588                duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
8589             }
8590          }
8591       }
8592
8593       ret = BuildCellGroupConfigRrc(duUeCb, &initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer);
8594       if(ret != ROK)
8595       {
8596          break;
8597       }
8598
8599       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
8600
8601       /* Encode the Intial UL RRC Message transfer as APER */
8602       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8603       encBufSize = 0;
8604       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
8605       /* Encode results */
8606       if(encRetVal.encoded == ENCODE_FAIL)
8607       {
8608          DU_LOG( "\nERROR  --> F1AP : Could not encode Initial UL RRC Message Transfer\
8609                structure (at %s)\n",encRetVal.failed_type ? \
8610                encRetVal.failed_type->name : "unknown");
8611          ret = RFAILED;
8612          break;
8613       }
8614       else
8615       {
8616
8617          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Initial UL RRC\
8618                Message transfer\n");
8619          for(int i=0; i< encBufSize; i++)
8620          {
8621             printf("%x",encBuf[i]);
8622          }
8623       }
8624       /* Sending  msg  */
8625       if(sendF1APMsg() != ROK)
8626       {
8627          DU_LOG("\nERROR  -->  F1AP : Sending Initial UL RRC Message Transfer Failed");
8628          ret = RFAILED;
8629          break;
8630       }
8631       break;
8632    }
8633    freeInitUlRrcMsgTransfer(f1apMsg);
8634    return ret;
8635 }/* End of BuildAndSendInitialRrcMsgTransfer*/
8636
8637 /*****  UE SETUP REQUEST *****/
8638
8639 /*******************************************************************
8640  *
8641  * @brief Free Qos And Snssai Drb Info
8642  *
8643  * @details
8644  *
8645  *    Function : freeDrbQosAndSnssaiInfo
8646  *
8647  *    Functionality: Free Qos And Snssai Drb Info
8648  *
8649  * @params[in] LcCfg *lcCfg,
8650  * @return void
8651  *
8652  * ****************************************************************/
8653 void freeDrbQosAndSnssaiInfo(LcCfg *lcCfg)
8654 {
8655    if(lcCfg->snssai)
8656    {
8657       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
8658    }
8659    if(lcCfg->drbQos)
8660    {
8661       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
8662    }
8663 }
8664
8665 /******************************************************************
8666 *
8667 * @brief Function to delete the RLC Lc cfg from UE APP DB
8668 *
8669 * @details
8670 *
8671 *  Function : freeRlcLcCfg
8672 *
8673 *  Functionality: Function to delete the RLC Lc cfg from UE APP DB
8674 *
8675 *
8676  *****************************************************************/
8677
8678 void freeRlcLcCfg(RlcBearerCfg *lcCfg)
8679 {
8680    switch(lcCfg->rlcMode)
8681    {
8682       case RLC_AM :
8683          {
8684             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
8685             break;
8686          }
8687       case RLC_UM_BI_DIRECTIONAL :
8688          {
8689             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
8690             break;
8691          }
8692       case RLC_UM_UNI_DIRECTIONAL_UL :
8693          {
8694             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
8695             break;
8696          }
8697       case RLC_UM_UNI_DIRECTIONAL_DL :
8698          {
8699             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
8700             break;
8701          }
8702       default:
8703          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at freeRlcLcCfg()", lcCfg->rlcMode);
8704          break;
8705    }
8706    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
8707 }
8708
8709 /*******************************************************************
8710  *
8711  * @brief Function to free MacLcCfg
8712  *
8713  * @details
8714  *
8715  *    Function : freeMacLcCfg
8716  *
8717  *    Functionality: Function to free MacLcCfg
8718  *
8719  * @params[in] LcCfg *lcCfg,
8720  * @return void
8721  *
8722  * ****************************************************************/
8723
8724 void  freeMacLcCfg(LcCfg *lcCfg)
8725 {
8726     /* Deleting DRBQOS */
8727    if(lcCfg->drbQos)
8728    {
8729       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
8730    }
8731    /* Deleting SNSSAI */
8732    if(lcCfg->snssai)
8733    {
8734       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
8735    }
8736 }
8737 /*******************************************************************
8738  *
8739  * @brief Free UE NR Capability received in UE Context setup request
8740  *
8741  * @details
8742  *
8743  *    Function : freeAperDecodeUeNrCapability
8744  *
8745  *    Functionality:  
8746  *       Free UE NR Capability received in UE Context setup request
8747  *
8748  * @params[in] 
8749  * @return ROK     - success
8750  *         RFAILED - failure
8751  *
8752  * ****************************************************************/
8753 void freeAperDecodeUeNrCapability(void *ueNrCapability)
8754 {
8755    uint8_t arrIdx =0;
8756    FeatureSets_t *featureSets =NULLP;
8757    UE_NR_Capability_t *ueNrCap = (UE_NR_Capability_t *)ueNrCapability;
8758
8759    if(ueNrCap->rf_Parameters.supportedBandListNR.list.array)
8760    {
8761       for(arrIdx = 0; arrIdx < ueNrCap->rf_Parameters.supportedBandListNR.list.count; arrIdx++)
8762       {
8763          if(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx])
8764             free(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx]);
8765       }
8766       free(ueNrCap->rf_Parameters.supportedBandListNR.list.array);
8767    }
8768
8769    if(ueNrCap->featureSets)
8770    {
8771       featureSets = ueNrCap->featureSets;
8772       if(featureSets->featureSetsDownlinkPerCC)
8773       {
8774          if(featureSets->featureSetsDownlinkPerCC->list.array)
8775          {
8776             for(arrIdx = 0; arrIdx < featureSets->featureSetsDownlinkPerCC->list.count; arrIdx++)
8777             {
8778                if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx])
8779                {
8780                   if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL)
8781                      free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL);
8782                   free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]);
8783                }
8784             }
8785             free(featureSets->featureSetsDownlinkPerCC->list.array);
8786          }
8787          free(featureSets->featureSetsDownlinkPerCC);
8788       }
8789       if(featureSets->featureSetsUplinkPerCC)
8790       {
8791          if(featureSets->featureSetsUplinkPerCC->list.array)
8792          {
8793             for(arrIdx = 0; arrIdx < featureSets->featureSetsUplinkPerCC->list.count; arrIdx++)
8794             {
8795                if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx])
8796                {
8797                   if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL)
8798                      free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL);
8799                   free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]);
8800                }
8801             }
8802             free(featureSets->featureSetsUplinkPerCC->list.array);
8803          }
8804          free(featureSets->featureSetsUplinkPerCC);
8805       }
8806       free(ueNrCap->featureSets);
8807    }   
8808 }
8809
8810 /*******************************************************************
8811 *
8812 * @brief Function to free PdcchSearchSpcToAddModList
8813          where memory allocated by aper_decoder
8814 *
8815 * @details
8816 *
8817 *    Function : freeAperDecodePdcchSearchSpcToAddModList 
8818 *
8819 *    Functionality: Function to free PdcchSearchSpcToAddModList
8820 *
8821 * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
8822 * @return void
8823 *
8824 * ****************************************************************/
8825
8826 void freeAperDecodePdcchSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
8827 {
8828    uint8_t searchSpcArrIdx=0;
8829    uint8_t searchSpcArrIdx1=0;
8830    struct  SearchSpace *searchSpc=NULLP;
8831
8832
8833    if(searchSpcList->list.array)
8834    {
8835       if(searchSpcList->list.array[searchSpcArrIdx1])
8836       {
8837          searchSpc = searchSpcList->list.array[searchSpcArrIdx1];
8838          if(searchSpc->controlResourceSetId)
8839          {
8840             if(searchSpc->monitoringSlotPeriodicityAndOffset)
8841             {
8842                if(searchSpc->monitoringSymbolsWithinSlot)
8843                {
8844                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
8845                   {
8846                      if(searchSpc->nrofCandidates)
8847                      {
8848                         if(searchSpc->searchSpaceType)
8849                         {
8850                            free(searchSpc->searchSpaceType->choice.ue_Specific);
8851                            free(searchSpc->searchSpaceType);
8852                         }
8853                         free(searchSpc->nrofCandidates);
8854                      }
8855                      free(searchSpc->monitoringSymbolsWithinSlot->buf);
8856                   }
8857                   free(searchSpc->monitoringSymbolsWithinSlot);
8858                }
8859                free(searchSpc->monitoringSlotPeriodicityAndOffset);
8860             }
8861             free(searchSpc->controlResourceSetId);
8862          }
8863       }
8864       for(searchSpcArrIdx = 0; searchSpcArrIdx < searchSpcList->list.count; searchSpcArrIdx++)
8865       {
8866          free(searchSpcList->list.array[searchSpcArrIdx]);
8867       }
8868       free(searchSpcList->list.array);
8869    }
8870 }
8871 /*******************************************************************
8872 *
8873 * @brief Function for free part for the memory allocated by aper_decoder
8874
8875 * @details
8876 *
8877 *    Function : freeAperDecodeBWPDlDedPdcchConfig
8878 *
8879 *    Functionality: Function to free BWPDlDedPdcchConfig
8880 *
8881 * @params[in] 
8882 * @return void
8883 *
8884 * ****************************************************************/
8885
8886
8887 void freeAperDecodeBWPDlDedPdcchConfig(BWP_DownlinkDedicated_t *dlBwp)
8888 {
8889    uint8_t arrIdx1=0;
8890    uint8_t arrIdx2=0;
8891    struct PDCCH_Config *pdcchCfg=NULLP;
8892    struct ControlResourceSet *controlRSet=NULLP;
8893    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
8894    
8895    if(dlBwp->pdcch_Config->choice.setup)
8896    {
8897       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
8898       if(pdcchCfg->controlResourceSetToAddModList)
8899       {
8900          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
8901          if(controlRSetList->list.array)
8902          {
8903             controlRSet = controlRSetList->list.array[arrIdx2];
8904             if(controlRSet)
8905             {
8906                if(controlRSet->frequencyDomainResources.buf)
8907                {
8908                   if(controlRSet->pdcch_DMRS_ScramblingID)
8909                   {
8910                      if(pdcchCfg->searchSpacesToAddModList)
8911                      {
8912                         freeAperDecodePdcchSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
8913                         free(pdcchCfg->searchSpacesToAddModList);
8914                      }
8915                      free(controlRSet->pdcch_DMRS_ScramblingID);
8916                   }
8917                   free(controlRSet->frequencyDomainResources.buf);
8918                }
8919             }
8920             for(arrIdx1 = 0; arrIdx1 <controlRSetList->list.count; arrIdx1++)
8921             {
8922                free(controlRSetList->list.array[arrIdx1]);
8923             }
8924             free(controlRSetList->list.array);
8925          }
8926          free(pdcchCfg->controlResourceSetToAddModList);
8927       }
8928       free(dlBwp->pdcch_Config->choice.setup);
8929    }
8930 }
8931 /*******************************************************************
8932 *
8933 * @brief Function to free PdschTimeDomAllocationList 
8934 *     where the memory allocated by aper_decoder
8935
8936 * @details
8937 *
8938 *    Function : freeAperDecodePdschTimeDomAllocationList
8939 *
8940 *    Functionality: Function to free PdschTimeDomAllocationList
8941 *
8942 * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList 
8943 * @return void
8944 *
8945 * ****************************************************************/
8946
8947
8948 void freeAperDecodePdschTimeDomAllocationList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
8949 {
8950    uint8_t arrIdx=0;
8951
8952    if(timeDomAllocList->choice.setup)
8953    {
8954       if(timeDomAllocList->choice.setup->list.array)
8955       {
8956          for(arrIdx = 0; arrIdx <timeDomAllocList->choice.setup->list.count ; arrIdx++)
8957          {
8958             free(timeDomAllocList->choice.setup->list.array[arrIdx]);
8959          }
8960          free(timeDomAllocList->choice.setup->list.array);
8961       }
8962       free(timeDomAllocList->choice.setup);
8963    }
8964 }
8965
8966 /*******************************************************************
8967 *
8968 * @brief Function to free BWPDlDedPdschConfig 
8969 *        where the memory allocated by aper_decoder
8970 *  
8971 * @details
8972 *
8973 *    Function : freeAperDecodeBWPDlDedPdschConfig 
8974 *
8975 *    Functionality: Function to free BWPDlDedPdschConfig 
8976 *
8977 * @params[in] BWP_DownlinkDedicated_t *dlBwp 
8978 * @return void
8979 *
8980 * ****************************************************************/
8981
8982
8983 void freeAperDecodeBWPDlDedPdschConfig(BWP_DownlinkDedicated_t *dlBwp)
8984 {
8985    struct PDSCH_Config *pdschCfg=NULLP;
8986    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
8987    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
8988    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
8989
8990    if(dlBwp->pdsch_Config->choice.setup)
8991    {
8992       pdschCfg=dlBwp->pdsch_Config->choice.setup;
8993       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
8994       {
8995          if(pdschCfg->pdsch_TimeDomainAllocationList)
8996          {
8997             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
8998             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
8999             {
9000                prbBndlType=&pdschCfg->prb_BundlingType;
9001                free(prbBndlType->choice.staticBundling);
9002                free(pdschCfg->maxNrofCodeWordsScheduledByDCI);
9003             }
9004             freeAperDecodePdschTimeDomAllocationList(timeDomAllocList);
9005             free(pdschCfg->pdsch_TimeDomainAllocationList);
9006          }
9007          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
9008          if(dmrsDlCfg->choice.setup)
9009          {
9010             free(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition);
9011             free(dmrsDlCfg->choice.setup);
9012          }
9013          free(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA);
9014       }
9015       free(dlBwp->pdsch_Config->choice.setup);
9016    }
9017 }
9018 /*******************************************************************
9019 *
9020 * @brief Function to free PuschTimeDomAllocListCfg
9021                  where the memory allocated by aper_decoder
9022 *
9023 * @details
9024 *
9025 *    Function : freeAperDecodePuschTimeDomAllocListCfg
9026 *
9027 *    Functionality: Function to free PuschTimeDomAllocListCfg
9028 *
9029 * @params[in] PUSCH_Config_t *puschCfg 
9030 * @return void
9031 *
9032 * ****************************************************************/
9033
9034
9035 void freeAperDecodePuschTimeDomAllocListCfg(PUSCH_Config_t *puschCfg)
9036 {
9037    uint8_t arrIdx=0;
9038    uint8_t arrIdx1=0;
9039    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
9040
9041    if(puschCfg->pusch_TimeDomainAllocationList)
9042    {
9043       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
9044       if(timeDomAllocList_t->choice.setup)
9045       {
9046          if(timeDomAllocList_t->choice.setup->list.array)
9047          {
9048             free(timeDomAllocList_t->choice.setup->list.array[arrIdx1]->k2);
9049             for(arrIdx = 0; arrIdx<timeDomAllocList_t->choice.setup->list.count; arrIdx++)
9050             {
9051                free(timeDomAllocList_t->choice.setup->list.array[arrIdx]);
9052             }
9053             free(timeDomAllocList_t->choice.setup->list.array);
9054          }
9055          free(timeDomAllocList_t->choice.setup);
9056       }
9057       free(puschCfg->transformPrecoder);
9058       free(puschCfg->pusch_TimeDomainAllocationList);
9059    }
9060 }
9061 /*******************************************************************
9062 *
9063 * @brief Function to free InitialUlBWPConfig where memory allocated by aper_decoder
9064 *
9065 * @details
9066 *
9067 *    Function : freeAperDecodeInitialUlBWPConfig 
9068 *
9069 *    Functionality: Function to free InitialUlBWPConfig
9070 *
9071 * @params[in]  BWP_UplinkDedicated_t *ulBwp
9072 * @return void
9073 *
9074 * ****************************************************************/
9075
9076
9077 void freeAperDecodeInitialUlBWPConfig(BWP_UplinkDedicated_t *ulBwp)
9078 {
9079    uint8_t  rSetIdx =0;
9080    uint8_t  rsrcIdx =0;
9081    SRS_Config_t   *srsCfg = NULLP;
9082    PUSCH_Config_t *puschCfg = NULLP;
9083    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
9084    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
9085    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
9086    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
9087
9088    if(ulBwp->pusch_Config)
9089    {
9090       if(ulBwp->pusch_Config->choice.setup)
9091       {
9092          puschCfg=ulBwp->pusch_Config->choice.setup;
9093          if(puschCfg->dataScramblingIdentityPUSCH)
9094          {
9095             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
9096             {
9097                freeAperDecodePuschTimeDomAllocListCfg(puschCfg);
9098                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
9099                if(dmrsUlCfg->choice.setup)
9100                {
9101                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
9102                   {
9103                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
9104                      {
9105                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0);
9106                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled);
9107                      }
9108                      free(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition);
9109                   }
9110                   free(dmrsUlCfg->choice.setup);
9111                }
9112                free(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA);
9113             }
9114             free(puschCfg->dataScramblingIdentityPUSCH);
9115          }
9116          free(ulBwp->pusch_Config->choice.setup);
9117       }
9118       free(ulBwp->pusch_Config);
9119
9120       /* Free SRS-Config */
9121       if(ulBwp->srs_Config)
9122       {
9123          if(ulBwp->srs_Config->choice.setup)
9124          {
9125             srsCfg = ulBwp->srs_Config->choice.setup;
9126
9127             /* Free Resource Set to add/mod list */
9128             if(srsCfg->srs_ResourceSetToAddModList)
9129             {
9130                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
9131                if(rsrcSetList->list.array)
9132                {
9133                   rSetIdx = 0;
9134
9135                   /* Free SRS resource Id list in this SRS resource set */
9136                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
9137                   {
9138                      rsrcIdList =
9139                         rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
9140
9141                      if(rsrcIdList->list.array)
9142                      {
9143                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count;
9144                               rsrcIdx++)
9145                         {
9146                            free(rsrcIdList->list.array[rsrcIdx]);
9147                         }
9148                         free(rsrcIdList->list.array);
9149                      }
9150                      free(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList);
9151                   }
9152
9153                   /* Free resource type info for this SRS resource set */
9154
9155                   free(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic);
9156
9157                   /* Free memory for each resource set */
9158                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
9159                   {
9160                      free(rsrcSetList->list.array[rSetIdx]);
9161                   }
9162                   free(rsrcSetList->list.array);
9163                }
9164                free(srsCfg->srs_ResourceSetToAddModList);
9165             }
9166
9167             /* Free resource to add/modd list */
9168             if(srsCfg->srs_ResourceToAddModList)
9169             {
9170                resourceList = srsCfg->srs_ResourceToAddModList;
9171                if(resourceList->list.array)
9172                {
9173                   rsrcIdx = 0;
9174
9175                   free(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2);
9176                   free(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic);
9177
9178                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
9179                   {
9180                      free(resourceList->list.array[rsrcIdx]);
9181                   }
9182                   free(resourceList->list.array);
9183                }
9184                free(srsCfg->srs_ResourceToAddModList);
9185             }
9186
9187             free(ulBwp->srs_Config->choice.setup);
9188          }
9189          free(ulBwp->srs_Config);
9190       }
9191    }
9192 }
9193 /*******************************************************************
9194 *
9195 * @brief Function to free initialUplinkBWPConfig where memory allocated by aper_decoder
9196 *
9197 * @details
9198 *
9199 *    Function : freeAperDecodeinitialUplinkBWPConfig
9200 *
9201 *    Functionality: Function to free initialUplinkBWPConfig
9202 *
9203 * @params[in] UplinkConfig_t *ulCfg 
9204 * @return void
9205 *
9206 * ****************************************************************/
9207
9208
9209 void freeAperDecodeinitialUplinkBWPConfig(UplinkConfig_t *ulCfg)
9210 {
9211    BWP_UplinkDedicated_t *ulBwp=NULLP;
9212    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
9213    
9214    if(ulCfg->initialUplinkBWP)
9215    {
9216       ulBwp=ulCfg->initialUplinkBWP;
9217       if(ulCfg->firstActiveUplinkBWP_Id)
9218       {
9219          if(ulCfg->pusch_ServingCellConfig)
9220          {
9221             puschCfg=ulCfg->pusch_ServingCellConfig;
9222             if(puschCfg->choice.setup)
9223             {
9224                if(puschCfg->choice.setup->ext1)
9225                {
9226                   free(puschCfg->choice.setup->ext1->processingType2Enabled);
9227                   free(puschCfg->choice.setup->ext1->maxMIMO_Layers);
9228                   free(puschCfg->choice.setup->ext1);
9229                }
9230                free(puschCfg->choice.setup);
9231             }
9232             free(ulCfg->pusch_ServingCellConfig);
9233          }
9234          free(ulCfg->firstActiveUplinkBWP_Id);
9235       }
9236       freeAperDecodeInitialUlBWPConfig(ulBwp);
9237       free(ulCfg->initialUplinkBWP);
9238    }
9239 }
9240
9241 /*******************************************************************
9242  *
9243  * @brief Function to free DuUeCfg
9244  *
9245  * @details
9246  *
9247  *    Function : freeDuUeCfg
9248  *
9249  *    Functionality: Function to free DuUeCfg
9250  *
9251  * @params[in] DuUeCfg *ueCfg
9252  * @return void
9253  *
9254  * ****************************************************************/
9255 void freeDuUeCfg(UeCtxtActionType actionType, DuUeCfg *ueCfg)
9256 {
9257    uint8_t lcIdx = 0;
9258    uint8_t arrIdx = 0;
9259    SpCellConfig_t *spCellCfg = NULLP;
9260    ServingCellConfig_t *srvCellCfg = NULLP;
9261    BWP_DownlinkDedicated_t *dlBwp = NULLP;
9262    MAC_CellGroupConfig_t *macCellGrpCfg = NULLP;
9263    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
9264    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList = NULLP;
9265    struct RLC_Config *rlcConfig = NULLP;
9266    struct LogicalChannelConfig *macLcConfig = NULLP;
9267    struct SchedulingRequestConfig *schedulingRequestConfig = NULLP;
9268    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList = NULLP;
9269    struct TAG_Config *tagConfig = NULLP;
9270    struct TAG_Config__tag_ToAddModList *tagList = NULLP;
9271    struct MAC_CellGroupConfig__phr_Config *phrConfig = NULLP;
9272    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg = NULLP;
9273    CellGroupConfigRrc_t *cellGrpCfg = ueCfg->cellGrpCfg;
9274   
9275    if(ueCfg->ueNrCapability)
9276    {
9277       freeAperDecodeUeNrCapability(ueCfg->ueNrCapability);
9278       DU_FREE(ueCfg->ueNrCapability, sizeof(UE_NR_Capability_t));
9279       ueCfg->ueNrCapability = NULLP;
9280    }
9281
9282    if(ueCfg->cellGrpCfg)
9283    {
9284       rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
9285       if(rlcBearerList)
9286       {
9287          if(rlcBearerList->list.array)
9288          {
9289             for(arrIdx=0; arrIdx<rlcBearerList->list.count; arrIdx++)
9290             {
9291                if(rlcBearerList->list.array[arrIdx])
9292                {
9293                   rlcConfig   = rlcBearerList->list.array[arrIdx]->rlc_Config;
9294                   macLcConfig = rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig;
9295
9296                   if(rlcBearerList->list.array[arrIdx]->servedRadioBearer)
9297                   {
9298                      free(rlcBearerList->list.array[arrIdx]->servedRadioBearer);
9299                   }
9300                   if(rlcConfig)
9301                   {
9302                      if(rlcConfig->choice.am)
9303                      {
9304                         free(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength);
9305                         free(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength);
9306                         free(rlcConfig->choice.am);
9307                      }
9308                      free(rlcBearerList->list.array[arrIdx]->rlc_Config);
9309                   }
9310                   if(macLcConfig)
9311                   {
9312                      if(macLcConfig->ul_SpecificParameters)
9313                      {
9314                         free(macLcConfig->ul_SpecificParameters->schedulingRequestID);
9315                         free(macLcConfig->ul_SpecificParameters->logicalChannelGroup);
9316                         free(macLcConfig->ul_SpecificParameters);
9317                      }
9318                      free(rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig);
9319                   }
9320                   free(rlcBearerList->list.array[arrIdx]); 
9321                }
9322             }
9323             free(rlcBearerList->list.array);
9324          }
9325          free(cellGrpCfg->rlc_BearerToAddModList);
9326       }
9327
9328       macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
9329       if(macCellGrpCfg)
9330       {
9331          schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig;
9332          if(schedulingRequestConfig)
9333          {
9334             schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
9335             if(schReqList)
9336             {
9337                if(schReqList->list.array)
9338                {
9339                   for(arrIdx=0;arrIdx<schReqList->list.count; arrIdx++)
9340                   {
9341                      if(schReqList->list.array[arrIdx])
9342                      {
9343                         free(schReqList->list.array[arrIdx]->sr_ProhibitTimer); 
9344                         free(schReqList->list.array[arrIdx]);
9345                      }
9346                   }
9347                   free(schReqList->list.array);
9348                }
9349                free(schedulingRequestConfig->schedulingRequestToAddModList);
9350             }
9351             free(macCellGrpCfg->schedulingRequestConfig);
9352          }
9353          if(macCellGrpCfg->bsr_Config)
9354          {
9355             free(macCellGrpCfg->bsr_Config);
9356          }
9357          tagConfig = macCellGrpCfg->tag_Config;
9358          if(tagConfig)
9359          {
9360             tagList = tagConfig->tag_ToAddModList;
9361             if(tagList)
9362             {
9363                if(tagList->list.array)
9364                {
9365                   for(arrIdx=0; arrIdx<tagList->list.count; arrIdx++)
9366                   {
9367                      free(tagList->list.array[arrIdx]);
9368                   }
9369                   free(tagList->list.array);
9370                }
9371                free(tagConfig->tag_ToAddModList);
9372             }
9373             free(tagConfig); 
9374          }
9375
9376          phrConfig = macCellGrpCfg->phr_Config;
9377          if(phrConfig)
9378          {
9379             free(phrConfig->choice.setup); 
9380             free(phrConfig); 
9381          }
9382
9383          free(macCellGrpCfg); 
9384       }
9385
9386       phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
9387       if(phyCellGrpCfg)
9388       {
9389          free(phyCellGrpCfg->p_NR_FR1);
9390          free(phyCellGrpCfg); 
9391       }
9392
9393       spCellCfg = cellGrpCfg->spCellConfig;
9394       if(spCellCfg)
9395       {
9396          if(spCellCfg->servCellIndex)
9397          {
9398             if(spCellCfg->rlmInSyncOutOfSyncThreshold)
9399             {
9400                if(spCellCfg->spCellConfigDedicated)
9401                {
9402                   srvCellCfg = spCellCfg->spCellConfigDedicated;
9403                   if(srvCellCfg->initialDownlinkBWP)
9404                   {
9405                      dlBwp = srvCellCfg->initialDownlinkBWP;
9406                      if(srvCellCfg->firstActiveDownlinkBWP_Id)
9407                      {
9408                         if(srvCellCfg->defaultDownlinkBWP_Id)
9409                         {
9410                            if(srvCellCfg->uplinkConfig)
9411                            {
9412
9413                               if(srvCellCfg->pdsch_ServingCellConfig)
9414                               {
9415                                  pdschCfg=
9416                                     srvCellCfg->pdsch_ServingCellConfig;
9417                                  if(pdschCfg->choice.setup)
9418                                  {
9419
9420                                     free(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH);
9421                                     free(pdschCfg->choice.setup);
9422                                  }
9423
9424                                  free(srvCellCfg->pdsch_ServingCellConfig);
9425                               }
9426
9427                               freeAperDecodeinitialUplinkBWPConfig(srvCellCfg->uplinkConfig);
9428                               free(srvCellCfg->uplinkConfig);
9429                            }
9430                            free(srvCellCfg->defaultDownlinkBWP_Id);
9431                         }
9432
9433                         free(srvCellCfg->firstActiveDownlinkBWP_Id);
9434                      }
9435                      if(dlBwp->pdcch_Config)
9436                      {
9437                         if(dlBwp->pdsch_Config)
9438                         {
9439                            freeAperDecodeBWPDlDedPdschConfig(dlBwp);
9440                            free(dlBwp->pdsch_Config);
9441                         }
9442                         freeAperDecodeBWPDlDedPdcchConfig(dlBwp);
9443                         free(dlBwp->pdcch_Config);
9444                      }
9445                      free(srvCellCfg->initialDownlinkBWP);
9446                   }
9447
9448                   free(spCellCfg->spCellConfigDedicated);
9449                }
9450                free(spCellCfg->rlmInSyncOutOfSyncThreshold);
9451             }
9452             free(spCellCfg->servCellIndex); 
9453          }
9454          free(spCellCfg);
9455       }
9456       DU_FREE(ueCfg->cellGrpCfg, sizeof(CellGroupConfigRrc_t));
9457       ueCfg->cellGrpCfg = NULLP;
9458    }
9459
9460    if(ueCfg->ambrCfg)
9461    {
9462       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCfg->ambrCfg, sizeof(AmbrCfg));
9463    }
9464
9465    if(actionType != UE_CTXT_CFG_QUERY)
9466    {
9467       for(lcIdx = 0; lcIdx < ueCfg->numRlcLcs; lcIdx++)
9468       {
9469          freeRlcLcCfg(&ueCfg->rlcLcCfg[lcIdx]);
9470       }
9471    }
9472
9473    for(lcIdx = 0; lcIdx < ueCfg->numMacLcs; lcIdx++)
9474    {
9475       freeMacLcCfg(&ueCfg->macLcCfg[lcIdx]);
9476    }
9477
9478    for(lcIdx = 0; lcIdx < ueCfg->numDrb; lcIdx++)
9479    {
9480       DU_FREE(ueCfg->upTnlInfo[lcIdx].tnlCfg1, sizeof(GtpTnlCfg));
9481    }
9482 }
9483
9484 /*******************************************************************
9485  *
9486  * @brief Function to free UecontextSetupDb
9487  *
9488  * @details
9489  *
9490  *    Function : freeF1UeDb
9491  *
9492  *    Functionality: Function to free UecontextSetupDb
9493  *
9494  * @params[in] UecontextSetupDb *
9495  * @return void
9496  *
9497  * ****************************************************************/
9498
9499 void freeF1UeDb(F1UeContextSetupDb *f1UeDb)
9500 {
9501    
9502    if(f1UeDb->dlRrcMsg)
9503    {
9504       if(f1UeDb->dlRrcMsg->rrcMsgPdu)
9505       {
9506         //DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,\
9507                f1UeDb->dlRrcMsg->rrcMsgPdu, f1UeDb->dlRrcMsg->rrcMsgSize);
9508       }
9509       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
9510    }
9511    freeDuUeCfg(f1UeDb->actionType, &f1UeDb->duUeCfg);
9512    memset(f1UeDb, 0, sizeof(F1UeContextSetupDb));
9513    DU_FREE(f1UeDb, sizeof(F1UeContextSetupDb));
9514 }
9515
9516 /*******************************************************************
9517  *
9518  * @brief Function to build Am cfg Info
9519  *
9520  * @details
9521  *
9522  *    Function : extractRlcAmCfg
9523  *
9524  *    Functionality: Function to build Am cfg Info
9525  *
9526  * @params[in] AmBearerCfg *
9527  *             void *
9528  *
9529  * @return ROK/RFAILED
9530  *
9531  * ****************************************************************/
9532
9533 void extractRlcAmCfg(AmBearerCfg *amCfgToSet, struct RLC_Config__am *rlcAmCfg)
9534 {
9535    if(rlcAmCfg)
9536    {
9537       /* UL AM */
9538       if(rlcAmCfg->dl_AM_RLC.sn_FieldLength)
9539       {
9540          amCfgToSet->ulAmCfg.snLenUl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->dl_AM_RLC.sn_FieldLength));
9541          /*TODO: Check the timer value when sent by real CU */
9542          amCfgToSet->ulAmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_Reassembly); 
9543          amCfgToSet->ulAmCfg.statProhTmr = convertProhibitTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_StatusProhibit);
9544       }
9545
9546       /* DL AM */
9547       if(rlcAmCfg->ul_AM_RLC.sn_FieldLength)
9548       {
9549          amCfgToSet->dlAmCfg.snLenDl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->ul_AM_RLC.sn_FieldLength));
9550          amCfgToSet->dlAmCfg.pollRetxTmr = covertPollRetxTmrEnumToValue(rlcAmCfg->ul_AM_RLC.t_PollRetransmit);
9551          amCfgToSet->dlAmCfg.pollPdu   = covertPollPduEnumToValue(rlcAmCfg->ul_AM_RLC.pollPDU);
9552          amCfgToSet->dlAmCfg.pollByte  = covertPollByteEnumToValue(rlcAmCfg->ul_AM_RLC.pollByte);
9553          amCfgToSet->dlAmCfg.maxRetxTh = covertMaxRetxEnumToValue(rlcAmCfg->ul_AM_RLC.maxRetxThreshold);
9554       }
9555    }
9556 }
9557
9558 /*******************************************************************
9559  *
9560  * @brief Function to build Um Bi Info
9561  *
9562  * @details
9563  *
9564  *    Function : extractRlcUmBiCfg
9565  *
9566  *    Functionality: Function to build Um Bi Info
9567  *
9568  * @params[in] UmBiDirBearerCfg *
9569  *             void *
9570  *
9571  * @return ROK/RFAILED
9572  *
9573  * ****************************************************************/
9574
9575 void extractRlcUmBiCfg(UmBiDirBearerCfg *umBiCfgToSet, struct RLC_Config__um_Bi_Directional *rlcBiCfg)
9576 {
9577    if(rlcBiCfg)
9578    {
9579       /* UL UM BI DIR Cfg */
9580       if(rlcBiCfg->dl_UM_RLC.sn_FieldLength)
9581       {
9582          umBiCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->dl_UM_RLC.sn_FieldLength));
9583          umBiCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcBiCfg->dl_UM_RLC.t_Reassembly);
9584       }
9585
9586       /* DL UM BI DIR Cfg */
9587       if(rlcBiCfg->ul_UM_RLC.sn_FieldLength)
9588          umBiCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->ul_UM_RLC.sn_FieldLength));
9589    }
9590 }
9591
9592 /*******************************************************************
9593  *
9594  * @brief Function to build Um Ul Info
9595  *
9596  * @details
9597  *
9598  *    Function : extractRlcUmUlCfg
9599  *
9600  *    Functionality: Function to build Um Ul Info
9601  *
9602  * @params[in] UmUniDirUlBearerCfg *
9603  *             void *
9604  *
9605  * @return ROK/RFAILED
9606  *
9607  * ****************************************************************/
9608
9609 void extractRlcUmUlCfg(UmUniDirUlBearerCfg *umUlCfgToSet, struct RLC_Config__um_Uni_Directional_DL *umUlCfg)
9610 {
9611    if(umUlCfg)
9612    {
9613       if(umUlCfg->dl_UM_RLC.sn_FieldLength)
9614       {
9615          umUlCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umUlCfg->dl_UM_RLC.sn_FieldLength));
9616          umUlCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(umUlCfg->dl_UM_RLC.t_Reassembly);
9617       }
9618    }
9619 }
9620
9621 /*******************************************************************
9622  *
9623  * @brief Function to build Um Uni Dl Info
9624  *
9625  * @details
9626  *
9627  *    Function : extractRlcUmDlCfg
9628  *
9629  *    Functionality: Function to build Um Uni Dl Info
9630  *
9631  * @params[in] UmUniDirDlBearerCfg *
9632  *             void *
9633  *
9634  * @return ROK/RFAILED
9635  *
9636  * ****************************************************************/
9637 void extractRlcUmDlCfg(UmUniDirDlBearerCfg *umDlCfgToSet, struct RLC_Config__um_Uni_Directional_UL *umDlCfg)
9638 {
9639    if(umDlCfg)
9640    {
9641       if(umDlCfg->ul_UM_RLC.sn_FieldLength)
9642          umDlCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umDlCfg->ul_UM_RLC.sn_FieldLength));
9643    }
9644 }
9645
9646 /*******************************************************************
9647  *
9648  * @brief Function to extractRlcModeCfg
9649  *
9650  * @details
9651  *
9652  *    Function : extractRlcModeCfg
9653  *
9654  *    Functionality: Function to extractRlcModeCfg
9655  *
9656  * @params[in] RLC_Config_t *
9657  *             RlcBearerCfg *
9658  *             void  *    
9659  * @return ROK/RFAILED
9660  *
9661  * ****************************************************************/
9662 void extractRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *rlcDbCfg, RLC_Config_t *lcCfg)
9663 {
9664    if(lcCfg)
9665    {
9666       switch(rlcMode)
9667       {
9668          case RLC_AM :
9669             {
9670                if(lcCfg->choice.am)
9671                {
9672                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.amCfg, sizeof(AmBearerCfg));
9673                   if(rlcDbCfg->u.amCfg)
9674                      extractRlcAmCfg(rlcDbCfg->u.amCfg, lcCfg->choice.am);
9675                }
9676                break;
9677             }
9678          case RLC_UM_BI_DIRECTIONAL :
9679             {
9680                if(lcCfg->choice.um_Bi_Directional)
9681                {
9682                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
9683                   if(rlcDbCfg->u.umBiDirCfg)
9684                      extractRlcUmBiCfg(rlcDbCfg->u.umBiDirCfg, lcCfg->choice.um_Bi_Directional);
9685                }
9686                break;
9687             }
9688          case RLC_UM_UNI_DIRECTIONAL_UL :
9689             {
9690                if(lcCfg->choice.um_Uni_Directional_DL)
9691                {
9692                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
9693                   if(rlcDbCfg->u.umUniDirUlCfg)
9694                      extractRlcUmUlCfg(rlcDbCfg->u.umUniDirUlCfg, lcCfg->choice.um_Uni_Directional_DL);
9695                }
9696                break;
9697             }
9698          case RLC_UM_UNI_DIRECTIONAL_DL :
9699             {
9700                if(lcCfg->choice.um_Uni_Directional_UL)
9701                {
9702                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
9703                   if(rlcDbCfg->u.umUniDirDlCfg)
9704                      extractRlcUmDlCfg(rlcDbCfg->u.umUniDirDlCfg, lcCfg->choice.um_Uni_Directional_UL);
9705                }
9706                break;
9707             }
9708          default:
9709             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
9710             break;
9711       }
9712    }
9713 }
9714
9715 /*******************************************************************
9716  *
9717  * @brief Function to extract extractUlLcCfg
9718  *
9719  * @details
9720  *
9721  *    Function : extractUlLcCfg
9722  *
9723  *    Functionality: Function to extract extractUlLcCfg
9724  *
9725  * @params[in] UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg
9726  * @return void
9727  *
9728  * ****************************************************************/
9729
9730 void extractUlLcCfg(UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg)
9731 {
9732    if(ulLcCfg)
9733    {
9734       if(ulLcCfg->ul_SpecificParameters)
9735       {
9736          f1UlLcCfg->priority = \
9737             ulLcCfg->ul_SpecificParameters->priority;
9738       if(ulLcCfg->ul_SpecificParameters->logicalChannelGroup)
9739       {
9740          f1UlLcCfg->lcGroup = \
9741            *(ulLcCfg->ul_SpecificParameters->logicalChannelGroup);
9742       }
9743       if(ulLcCfg->ul_SpecificParameters->schedulingRequestID)
9744       {
9745          f1UlLcCfg->schReqId = \
9746            *(ulLcCfg->ul_SpecificParameters->schedulingRequestID);
9747       }
9748       f1UlLcCfg->pbr = \
9749          ulLcCfg->ul_SpecificParameters->prioritisedBitRate;
9750       f1UlLcCfg->bsd = \
9751          ulLcCfg->ul_SpecificParameters->bucketSizeDuration;
9752       }
9753    }
9754 }
9755
9756 /*******************************************************************
9757 *
9758 * @brief Function to extract Snssai Cfg Info from CU
9759 *
9760 * @details
9761 *
9762 *    Function : extractDrbSnssaiCfg
9763 *
9764 *    Functionality: Function to extract Drb Snssai Cfg Info from CU
9765 *
9766 * @params[in] DRB_Information_t *drbInfo, Snssai  *snssai
9767 * @return ROK/RFAILED
9768 *
9769 * ****************************************************************/
9770
9771 uint8_t extractDrbSnssaiCfg(SNSSAI_t *RecvSnssai, Snssai **snssaiToBeShared)
9772 {
9773    if(!(*snssaiToBeShared))
9774    {
9775       DU_ALLOC_SHRABL_BUF((*snssaiToBeShared), sizeof(Snssai));
9776       if(snssaiToBeShared == NULLP)
9777       {
9778          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Memory failed at allocating for SNSSAI ");
9779          return RFAILED;
9780       }
9781    }
9782    if(RecvSnssai)
9783    {
9784       memcpy(&(*snssaiToBeShared)->sst, RecvSnssai->sST.buf, RecvSnssai->sST.size);
9785       if(RecvSnssai->sD)
9786       {
9787          memcpy((*snssaiToBeShared)->sd, RecvSnssai->sD->buf,  RecvSnssai->sD->size);
9788       }
9789       else
9790       {
9791          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Received Null pointer of Snssai->SD");
9792          return RFAILED;
9793       }
9794    }
9795    return ROK;
9796 }
9797
9798 /*******************************************************************
9799  *
9800  * @brief Function to procRlcLcCfg
9801  *
9802  * @details
9803  *
9804  *    Function : procRlcLcCfg
9805  *
9806  *    Functionality: Function to procRlcLcCfg
9807  *
9808  * @params[in] rbId, lcId, rbType, rlcMod
9809  *             RLC_Config_t *, RlcBearerCfg * , 
9810  * @return void
9811  *
9812  * ****************************************************************/
9813
9814 void procRlcLcCfg(uint8_t rbId, uint8_t lcId, uint8_t rbType, uint8_t rlcMode,\
9815    uint8_t configType, RLC_Config_t *f1RlcCfg, RlcBearerCfg *lcCfg, QoSInformation_t *qoSInformation)
9816 {
9817    DRB_Information_t *drbInfo;
9818
9819    lcCfg->rbId   = rbId;
9820    lcCfg->configType = configType;
9821
9822    if(rbType == RB_TYPE_SRB)
9823    {
9824       lcCfg->rbType = RB_TYPE_SRB;
9825       lcCfg->lcId   = rbId;
9826       lcCfg->lcType = LCH_DCCH;
9827       lcCfg->rlcMode = RLC_AM;
9828    }
9829    else if(rbType == RB_TYPE_DRB)
9830    {
9831       lcCfg->rbType = RB_TYPE_DRB;
9832       lcCfg->lcId   = lcId;
9833       lcCfg->lcType = LCH_DTCH;
9834       lcCfg->rlcMode = rlcMode;
9835    }
9836    if(f1RlcCfg) /* rlc mode config recived */
9837    {
9838       extractRlcModeCfg(lcCfg->rlcMode, lcCfg, f1RlcCfg);
9839    }
9840    if(qoSInformation != NULLP)
9841    {
9842       if(qoSInformation->present == QoSInformation_PR_choice_extension)
9843       {
9844          if(qoSInformation->choice.choice_extension->value.present ==\
9845                QoSInformation_ExtIEs__value_PR_DRB_Information)
9846          {
9847             drbInfo = &qoSInformation->choice.choice_extension->value.choice.DRB_Information; 
9848             if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &lcCfg->snssai) != ROK)
9849             {
9850                DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information at procRlcLcCfg()");
9851                return;
9852             }
9853          }
9854       }
9855    }
9856 }
9857
9858 /*******************************************************************
9859  *
9860  * @brief Fills DrbQos Info received by CU
9861  *
9862  * @details
9863  *
9864  *    Function : extractQosInfo
9865  *
9866  *    Functionality: Fills DrbQos Info received  by CU
9867  *
9868  * @params[in] DrbQosInfo *qosToAdd, 
9869  *             QoSFlowLevelQoSParameters_t *qosFlowCfg
9870  * @return void
9871  *
9872  * ****************************************************************/
9873
9874 void extractQosInfo(DrbQosInfo *qosToAdd, QoSFlowLevelQoSParameters_t *qosFlowCfg)
9875 {
9876    uint8_t qosCntIdx = 0;
9877    ProtocolExtensionContainer_4624P74_t *qosIeExt = NULLP;
9878
9879    qosToAdd->fiveQiType = qosFlowCfg->qoS_Characteristics.present;
9880    qosToAdd->u.nonDyn5Qi.fiveQi     =\
9881                                      qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->fiveQI;
9882    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow)
9883    {
9884       qosToAdd->u.nonDyn5Qi.avgWindow = \
9885                                         *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
9886    }
9887
9888    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume)
9889    {
9890       qosToAdd->u.nonDyn5Qi.maxDataBurstVol = \
9891                                               *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
9892    }
9893
9894    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel)
9895    {
9896       qosToAdd->u.nonDyn5Qi.priorLevel = \
9897                                          *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel);
9898    }
9899    qosToAdd->ngRanRetPri.priorityLevel = \
9900                                          qosFlowCfg->nGRANallocationRetentionPriority.priorityLevel; 
9901    qosToAdd->ngRanRetPri.preEmptionCap = \
9902                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionCapability;
9903    qosToAdd->ngRanRetPri.preEmptionVul = \
9904                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionVulnerability;
9905    if(qosFlowCfg->gBR_QoS_Flow_Information)
9906    {
9907       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateDl, \
9908             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.buf, \
9909             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.size);
9910       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateUl, \
9911             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.buf, \
9912             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.size);
9913       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateDl,\
9914             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.buf, \
9915             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.size);
9916       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateUl,\
9917             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.buf, \
9918             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.size);
9919    }
9920    /*Extracting PDU_SESSION_ID*/
9921    qosIeExt = (ProtocolExtensionContainer_4624P74_t *)qosFlowCfg->iE_Extensions;
9922    if(qosIeExt)
9923    {
9924       for(qosCntIdx = 0; qosCntIdx < qosIeExt->list.count; qosCntIdx++)
9925       {
9926          if(qosIeExt->list.array[qosCntIdx]->extensionValue.present == \
9927                QoSFlowLevelQoSParameters_ExtIEs__extensionValue_PR_PDUSessionID)
9928          {
9929             qosToAdd->pduSessionId = qosIeExt->list.array[qosCntIdx]->extensionValue.choice.PDUSessionID;
9930             DU_LOG("\nDEBUG -->  DU_F1AP : extractQosInfo: PDU SessionID:%d",qosToAdd->pduSessionId);
9931          }
9932       }  
9933    }
9934    qosToAdd->ulPduSessAggMaxBitRate = 0;
9935 }
9936
9937 /*******************************************************************
9938  *
9939  * @brief Function to extract GTP Tunnel Info from CU
9940  *
9941  * @details
9942  *
9943  *    Function : extractUpTnlInfo
9944  *
9945  *    Functionality: Function to extract GTP Tunnel Info from CU
9946  *
9947  * @params[in] F1AP message
9948  * @return ROK/RFAILED
9949  *
9950  * ****************************************************************/
9951
9952 uint8_t extractUpTnlInfo(uint8_t drbId, uint8_t configType,\
9953    ULUPTNLInformation_ToBeSetup_List_t *tnlInfo, UpTnlCfg *upTnlInfo)
9954 {
9955    uint8_t tnlIdx;
9956    uint32_t ipv4_du = 0;
9957    GTPTunnel_t *gtpTunnel = NULLP;
9958
9959    upTnlInfo->drbId = drbId; 
9960    upTnlInfo->configType = configType;
9961 #ifdef O1_ENABLE
9962    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
9963 #else
9964    cmInetAddr((char *)DU_IP_V4_ADDR, &ipv4_du);
9965 #endif
9966
9967    for(tnlIdx=0; tnlIdx < tnlInfo->list.count; tnlIdx++)
9968    {
9969       if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.present == UPTransportLayerInformation_PR_gTPTunnel)
9970       {
9971          if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel)
9972          {
9973             gtpTunnel = tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel;
9974             DU_ALLOC(upTnlInfo->tnlCfg1, sizeof(GtpTnlCfg));
9975             if(upTnlInfo->tnlCfg1 == NULLP)
9976             {
9977                DU_LOG("\nERROR  -->  F1AP : extractUpTnlInfo: Failed to allocate mmeory for tunnel cfg 1");
9978                return RFAILED;
9979             }
9980             bitStringToInt(&gtpTunnel->transportLayerAddress, &upTnlInfo->tnlCfg1->ulTnlAddress);
9981             upTnlInfo->tnlCfg1->dlTnlAddress = ipv4_du;
9982             if(gtpTunnel->gTP_TEID.size > 0)
9983             {
9984                teIdStringToInt(gtpTunnel->gTP_TEID.buf, &upTnlInfo->tnlCfg1->teId);
9985             }
9986          }
9987          break;
9988       }
9989    }
9990    return ROK;
9991 }
9992
9993 /*******************************************************************
9994 *
9995 * @brief Function to extract Drb Qos Cfg Info from CU
9996 *
9997 * @details
9998 *
9999 *    Function : extractDrbQosCfg 
10000 *
10001 *    Functionality: Function to extract Drb Qos Cfg Info from CU
10002 *
10003 * @params[in] DRB_Information_t *drbInfo, LcCfg *macLcToAdd
10004 * @return ROK/RFAILED
10005 *
10006 * ****************************************************************/
10007
10008 uint8_t extractDrbQosCfg(DRB_Information_t *drbInfo, LcCfg *macLcToAdd ) 
10009 {
10010    if(!macLcToAdd->drbQos)
10011    {
10012       DU_ALLOC_SHRABL_BUF(macLcToAdd->drbQos, sizeof(DrbQosInfo));
10013       if(macLcToAdd->drbQos == NULLP)
10014       {
10015          DU_LOG("\nERROR  -->  DUAPP:Memory failed at allocating DrbQos at extractDrbQosCfg()");
10016          return RFAILED;
10017       }
10018
10019    }
10020    if(drbInfo->dRB_QoS.qoS_Characteristics.present == QoS_Characteristics_PR_non_Dynamic_5QI)
10021    {
10022       extractQosInfo(macLcToAdd->drbQos, &drbInfo->dRB_QoS);
10023       macLcToAdd->dlLcCfg.lcp = macLcToAdd->drbQos->ngRanRetPri.priorityLevel;
10024    }
10025    if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &macLcToAdd->snssai) != ROK)
10026    {
10027       DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information  at extractDrbQosCfg()");
10028       return RFAILED;
10029    }
10030    return ROK;
10031 }
10032 /*******************************************************************
10033  *
10034  * @brief Function to extract DRB info received from CU
10035  *
10036  * @details
10037  *
10038  *    Function : extractDrbCfg
10039  *
10040  *    Functionality: Function to extract DRB info received from CU
10041  *
10042  * @params[in] F1AP message
10043  * @return void
10044  *
10045  * ****************************************************************/
10046 uint8_t extractDrbCfg(DRBs_ToBeSetup_Item_t *drbItem, DRBs_ToBeSetupMod_Item_t *drbSetupModItem,\
10047 DRBs_ToBeModified_Item_t *drbModItem,  LcCfg *macLcToAdd, UpTnlCfg *upTnlInfo)
10048 {
10049    DRB_Information_t *drbInfo = NULLP;
10050
10051    if(drbItem != NULLP)
10052    {
10053       if(extractUpTnlInfo(drbItem->dRBID, CONFIG_ADD, &drbItem->uLUPTNLInformation_ToBeSetup_List, upTnlInfo) != ROK)
10054       {
10055          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10056          return RFAILED;
10057       }
10058       if(drbItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10059       {
10060          if(drbItem->qoSInformation.choice.choice_extension->value.present == QoSInformation_ExtIEs__value_PR_DRB_Information)
10061          {
10062             drbInfo = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10063             if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
10064             {
10065                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");
10066                return RFAILED;
10067             }
10068          }
10069       }
10070    }
10071    else if(drbSetupModItem != NULLP)
10072    {
10073       if(extractUpTnlInfo(drbSetupModItem->dRBID, CONFIG_ADD, &drbSetupModItem->uLUPTNLInformation_ToBeSetup_List,\
10074       upTnlInfo) != ROK)
10075       {
10076          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10077          return RFAILED;
10078       }
10079       if(drbSetupModItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10080       {
10081          if(drbSetupModItem->qoSInformation.choice.choice_extension->value.present ==\
10082          QoSInformation_ExtIEs__value_PR_DRB_Information)
10083          {
10084             drbInfo = &drbSetupModItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10085             if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
10086             {
10087                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10088                return RFAILED;
10089             }
10090
10091          }
10092       }
10093    }
10094    else if(drbModItem != NULLP)
10095    {
10096       if(extractUpTnlInfo(drbModItem->dRBID, CONFIG_MOD, &drbModItem->uLUPTNLInformation_ToBeSetup_List,\
10097       upTnlInfo) != ROK)
10098       {
10099          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10100          return RFAILED;
10101       }
10102       if(drbModItem->qoSInformation != NULLP)
10103       {
10104          if(drbModItem->qoSInformation->present == QoSInformation_PR_choice_extension)
10105          {
10106             if(drbModItem->qoSInformation->choice.choice_extension->value.present ==\
10107                   QoSInformation_ExtIEs__value_PR_DRB_Information)
10108             {
10109                drbInfo = &drbModItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information;
10110                if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
10111                {
10112                   DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10113                   return RFAILED;
10114                }
10115
10116             }
10117          }
10118       }
10119    }
10120    return ROK;
10121 }
10122
10123 /*******************************************************************
10124  *
10125  * @brief Function to extract RB info received from CU
10126  *
10127  * @details
10128  *
10129  *    Function : extractMacRbCfg
10130  *
10131  *    Functionality: Function to extract RB info received from CU
10132  *
10133  * @params[in] F1AP message
10134  * @return ROK/RFAILED
10135  *
10136  * ****************************************************************/
10137
10138 uint8_t extractMacRbCfg(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbCfg,\
10139 DRBs_ToBeSetupMod_Item_t *drbSetupModCfg,  DRBs_ToBeModified_Item_t *drbModCfg, LogicalChannelConfig_t *ulLcCfg, LcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10140 {
10141    if(drbCfg != NULLP)
10142    {
10143       if(extractDrbCfg(drbCfg, NULL, NULL, lcCfg, upTnlInfo) != ROK)
10144       {
10145          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10146          return RFAILED;
10147       }
10148    }
10149    else if(drbSetupModCfg != NULLP)
10150    { 
10151       if(extractDrbCfg(NULL, drbSetupModCfg, NULL, lcCfg, upTnlInfo) != ROK)
10152       {
10153          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10154          return RFAILED;
10155       }
10156    }
10157    else if(drbModCfg != NULLP)
10158    { 
10159       if(extractDrbCfg(NULL, NULL, drbModCfg, lcCfg, upTnlInfo) != ROK)
10160       {
10161          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10162          return RFAILED;
10163       }
10164    }
10165    else
10166    {
10167       lcCfg->drbQos = NULLP;
10168       lcCfg->snssai = NULLP;
10169       if(lcCfg->lcId == SRB2_LCID)
10170          lcCfg->dlLcCfg.lcp = LC_PRIORITY_3;
10171       else
10172          lcCfg->dlLcCfg.lcp = LC_PRIORITY_1;
10173    }
10174    if(ulLcCfg)
10175    {
10176       lcCfg->ulLcCfgPres = true;
10177       extractUlLcCfg(&lcCfg->ulLcCfg, ulLcCfg);
10178    }
10179    else
10180       lcCfg->ulLcCfgPres = false;
10181    return ROK;
10182 }
10183
10184 /*******************************************************************
10185  *
10186  * @brief Function processing LC config info received from CU
10187  *
10188  * @details
10189  *
10190  *    Function : procMacLcCfg
10191  *
10192  *    Functionality: Function processing LC config info received from CU
10193  *
10194  * @params[in] F1AP message
10195  * @return ROK/RFAILED
10196  *
10197  * ****************************************************************/
10198
10199 uint8_t procMacLcCfg(uint8_t lcId, uint8_t rbType, uint8_t configType, DRBs_ToBeSetup_Item_t *drbItem,\
10200 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LogicalChannelConfig_t *ulLcCfg,\
10201 LcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10202 {
10203    uint8_t ret = ROK;
10204
10205    lcCfg->lcId = lcId;
10206    lcCfg->configType = configType;
10207    if(rbType == RB_TYPE_SRB)
10208    {
10209       ret = extractMacRbCfg(lcId, NULL, NULL, NULL, ulLcCfg, lcCfg, NULL);
10210    }
10211    else if(rbType == RB_TYPE_DRB)
10212    {
10213       if(drbItem != NULL)
10214         ret = extractMacRbCfg(lcId, drbItem, NULL, NULL, ulLcCfg, lcCfg, upTnlInfo);
10215       else if(drbSetupModItem != NULL)
10216         ret = extractMacRbCfg(lcId, NULL, drbSetupModItem, NULL, ulLcCfg, lcCfg, upTnlInfo);
10217       else if(drbModItem != NULL)
10218         ret = extractMacRbCfg(lcId, NULL, NULL, drbModItem, ulLcCfg, lcCfg, upTnlInfo);
10219    }
10220    return ret;
10221 }
10222
10223 /*******************************************************************
10224  *
10225  * @brief Function to extract Rlc cfg To Add/Mod in CellGrp Info
10226  *
10227  * @details
10228  *
10229  *    Function : extractRlcCfgToAddMod
10230  *
10231  *    Functionality: Function to extract Rlc cfg To Add/Mod in CellGrp Info
10232  *
10233  * @params[in] CellGroupConfigRrc__rlc_BearerTo pointer
10234  *             DuUeCfg Pointer
10235  * @return ROK/RFAILED
10236  *
10237  * ****************************************************************/
10238
10239 uint8_t extractRlcCfgToAddMod(struct CellGroupConfigRrc__rlc_BearerToAddModList *lcCfg, DuUeCfg *ueCfgDb)
10240 {
10241   uint8_t idx, rbId, lcId, rlcMode, rbType;
10242   RLC_Config_t *f1RlcCfg = NULLP;
10243   LogicalChannelConfig_t *macUlLcCfg = NULLP;
10244
10245   for(idx = 0; idx < lcCfg->list.count; idx++)
10246   {
10247      lcId = lcCfg->list.array[idx]->logicalChannelIdentity;
10248      if(lcCfg->list.array[idx]->servedRadioBearer)
10249      {
10250         /* RadioBearer for SRB/DRB */
10251         if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10252         RLC_BearerConfig__servedRadioBearer_PR_srb_Identity)
10253         {
10254            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.srb_Identity;
10255            rbType = RB_TYPE_SRB;
10256         }
10257         else if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10258         RLC_BearerConfig__servedRadioBearer_PR_drb_Identity)
10259         {
10260            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.drb_Identity;
10261            rbType = RB_TYPE_DRB;
10262         }
10263         else
10264         {
10265            DU_LOG("\nERROR  -->  No components present in Bearer config to ADD/MOD");
10266            return RFAILED;
10267         }
10268         /* MAC UL LC Config */
10269         if(lcCfg->list.array[idx]->mac_LogicalChannelConfig)
10270         {
10271            macUlLcCfg = lcCfg->list.array[idx]->mac_LogicalChannelConfig;
10272         }
10273      }
10274      else
10275      {
10276         DU_LOG("\nERROR  -->  DUAPP: Received RadioBearer config is NULL");
10277         return RFAILED;
10278      }
10279      /* RLC Mode Config */
10280      if(lcCfg->list.array[idx]->rlc_Config)
10281      {
10282         rlcMode  = lcCfg->list.array[idx]->rlc_Config->present;
10283         f1RlcCfg = lcCfg->list.array[idx]->rlc_Config;
10284      }
10285      
10286      /* Filling RLC/MAC Config*/
10287      memset(&ueCfgDb->macLcCfg[idx], 0, sizeof(LcCfg));
10288      memset(&ueCfgDb->rlcLcCfg[idx], 0, sizeof(RlcBearerCfg));
10289      procRlcLcCfg(rbId, lcId, rbType, rlcMode, CONFIG_UNKNOWN, f1RlcCfg, &(ueCfgDb->rlcLcCfg[idx]), NULLP);
10290      if(procMacLcCfg(lcId, rbType, CONFIG_UNKNOWN, NULL, NULL, NULL, macUlLcCfg, &ueCfgDb->macLcCfg[idx], NULL) != ROK)
10291      {
10292         DU_LOG("\nERROR  -->  DU APP : Failed while filling MAC LC config at extractRlcCfgToAddMod()");
10293         return RFAILED;
10294      }
10295      (ueCfgDb->numRlcLcs)++;
10296      (ueCfgDb->numMacLcs)++;
10297      DU_LOG("\nDEBUG  -> DUAPP: extractRlcCfgToAddMod:RBType:%d, DrbID: %d,lcId:%d, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
10298         rbType, rbId, lcId, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
10299   }
10300   //TODO: To send the failure cause in UeContextSetupRsp 
10301   return ROK;
10302 }
10303
10304 /*******************************************************************
10305  *
10306  * @brief DeAlloc pdsch serv cell config info
10307  *
10308  * @details
10309  *
10310  *    Function : freeMacPdschServCellInfo
10311  *
10312  *    Functionality: DeAlloc pdsch serv cell config info
10313  *
10314  * @params[in] PdschServCellCfg pointer
10315  * @return void
10316  *
10317  * ****************************************************************/
10318
10319 void freeMacPdschServCellInfo(PdschServCellCfg *pdsch)
10320 {
10321    if(pdsch->xOverhead)
10322    {
10323       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->xOverhead, sizeof(PdschXOverhead));
10324    }
10325    if(pdsch->codeBlkGrpFlushInd)
10326    {
10327       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->codeBlkGrpFlushInd, sizeof(bool));
10328    }
10329    if(pdsch->maxCodeBlkGrpPerTb)
10330    {
10331       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10332    }
10333    if(pdsch->maxMimoLayers)
10334    {
10335       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxMimoLayers, sizeof(uint8_t));
10336    }
10337 }
10338
10339 /*******************************************************************
10340  *
10341  * @brief Free Serving cell Info
10342  *
10343  * @details
10344  *
10345  *    Function : freeMacServingCellInfo
10346  *
10347  *    Functionality: Free Serving cell Info
10348  *
10349  * @params[in] ServCellCfgInfo *srvCellCfg
10350  * @return void
10351  *
10352  * ****************************************************************/
10353 void freeMacServingCellInfo(ServCellCfgInfo *srvCellCfg)
10354 {
10355    uint8_t timeDomRsrcIdx;
10356
10357    if(srvCellCfg->initDlBwp.pdschPresent)
10358    {
10359       for(timeDomRsrcIdx = 0; timeDomRsrcIdx < srvCellCfg->initDlBwp.pdschCfg.numTimeDomRsrcAlloc; timeDomRsrcIdx++)
10360       {
10361          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, \
10362             srvCellCfg->initDlBwp.pdschCfg.timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
10363       }
10364    }
10365
10366    freeMacPdschServCellInfo(&srvCellCfg->pdschServCellCfg);
10367    if(srvCellCfg->bwpInactivityTmr)
10368    {
10369       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
10370    }
10371
10372    if(srvCellCfg->initUlBwp.pucchPresent)
10373    {
10374       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->initUlBwp.pucchCfg.dlDataToUlAck, sizeof(PucchDlDataToUlAck));
10375    }
10376 }
10377
10378 /*******************************************************************
10379  *
10380  * @brief Free cell Grp Cfg Info
10381  *
10382  * @details
10383  *
10384  *    Function : freeUeReCfgCellGrpInfo
10385  *
10386  *    Functionality: Free cell Grp Cfg Info
10387  *
10388  * @params[in] MacUeCfg*  duUeCfg
10389  * @return void
10390  *
10391  * ****************************************************************/
10392
10393 void freeUeReCfgCellGrpInfo(MacUeCfg *macUeCfg)
10394 {
10395    freeMacServingCellInfo(&macUeCfg->spCellCfg.servCellCfg);
10396 }
10397
10398 /*******************************************************************
10399  *
10400  * @brief Fills Reconfig SchReqReConfig
10401  *
10402  * @details
10403  *
10404  *    Function : extractSchReqReConfig
10405  *
10406  *    Functionality: Fills Reconfig SchReqReConfig
10407  *
10408  * @params[in] SchedulingRequestConfig_t *cuSchedReq
10409  *             SchedReqCfg*  macSchedReq
10410  * @return void
10411  *
10412  * ****************************************************************/
10413 void extractSchReqReConfig(SchedulingRequestConfig_t *cuSchedReq, SchedReqCfg *macSchedReq)
10414 {
10415    uint8_t schReqIdx = 0;
10416    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqListToAdd = NULLP;
10417    struct SchedulingRequestConfig__schedulingRequestToReleaseList *schReqListToRel = NULLP;
10418
10419    if(cuSchedReq->schedulingRequestToAddModList)
10420    {
10421       schReqListToAdd = cuSchedReq->schedulingRequestToAddModList;
10422       if(schReqListToAdd->list.count)
10423       {
10424          macSchedReq->addModListCount = schReqListToAdd->list.count;
10425          for(schReqIdx = 0; schReqIdx < schReqListToAdd->list.count; schReqIdx++)
10426          {
10427             macSchedReq->addModList[schReqIdx].schedReqId = \
10428                schReqListToAdd->list.array[schReqIdx]->schedulingRequestId;
10429             macSchedReq->addModList[schReqIdx].srProhibitTmr = \
10430                *(schReqListToAdd->list.array[schReqIdx]->sr_ProhibitTimer);
10431             macSchedReq->addModList[schReqIdx].srTransMax    =\
10432                schReqListToAdd->list.array[schReqIdx]->sr_TransMax;
10433          }
10434       }
10435    }
10436    /* Scheduling Req To release */
10437    if(cuSchedReq->schedulingRequestToReleaseList)
10438    {
10439       schReqListToRel = cuSchedReq->schedulingRequestToReleaseList;
10440       if(schReqListToRel->list.count)
10441       {
10442          macSchedReq->relListCount = schReqListToRel->list.count;
10443          for(schReqIdx = 0; schReqIdx < schReqListToRel->list.count; schReqIdx++)
10444          {
10445             macSchedReq->relList[schReqIdx] = \
10446                *schReqListToRel->list.array[schReqIdx];
10447          }
10448       }
10449    }
10450 }
10451
10452 /*******************************************************************
10453  *
10454  * @brief Fills TagReconfig
10455  *
10456  * @details
10457  *
10458  *    Function : extractTagReconfig
10459  *
10460  *    Functionality: Fills extractTagReconfig
10461  *
10462  * @params[in] TAG_Config_t *cuTagCfg
10463  *             TagCfg *macTagCfg
10464  * @return void
10465  *
10466  * ****************************************************************/
10467
10468 void extractTagReconfig(TAG_Config_t *cuTagCfg, TagCfg *macTagCfg)
10469 {
10470   uint8_t tagIdx = 0;
10471   struct TAG_Config__tag_ToAddModList  *tagListToAddMod = NULLP;
10472   struct TAG_Config__tag_ToReleaseList *tagListToRel = NULLP;
10473
10474   /* Tag config to AddMod */
10475   if(cuTagCfg->tag_ToAddModList)
10476   {
10477      tagListToAddMod = cuTagCfg->tag_ToAddModList; 
10478      if(tagListToAddMod->list.count)
10479      {
10480         macTagCfg->addModListCount = tagListToAddMod->list.count;
10481         for(tagIdx = 0; tagIdx < tagListToAddMod->list.count; tagIdx++)
10482         {
10483            macTagCfg->addModList[tagIdx].tagId =\
10484               tagListToAddMod->list.array[tagIdx]->tag_Id;     
10485            macTagCfg->addModList[tagIdx].timeAlignTimer = \
10486
10487               tagListToAddMod->list.array[tagIdx]->timeAlignmentTimer;
10488         }
10489      }
10490   }
10491   /* Tag config to release */
10492   if(cuTagCfg->tag_ToReleaseList)
10493   {
10494      tagListToRel = cuTagCfg->tag_ToReleaseList;
10495      if(tagListToRel->list.count)
10496      {
10497         macTagCfg->relListCount = tagListToRel->list.count;
10498         for(tagIdx = 0; tagIdx < tagListToRel->list.count; tagIdx++)
10499         {
10500            macTagCfg->relList[tagIdx] = *tagListToRel->list.array[tagIdx];     
10501         }
10502      }
10503   }
10504 }
10505
10506 /*******************************************************************
10507  *
10508  * @brief Fills PdcchCfg received by CU
10509  *
10510  * @details
10511  *
10512  *    Function : extractPdcchCfg
10513  *
10514  *    Functionality: Fills PdcchCfg received  by CU
10515  *
10516  * @params[in] PDCCH_Config_t *cuPdcchCfg,
10517  *             PdcchConfig *duPdcchCfg
10518  * @return void
10519  *
10520  * ****************************************************************/
10521
10522 void extractPdcchCfg(PDCCH_Config_t *cuPdcchCfg, PdcchConfig *macPdcchCfg)
10523 {
10524    uint8_t cRsetIdx = 0;
10525    uint8_t srchSpcIdx = 0;
10526
10527    struct PDCCH_Config__controlResourceSetToAddModList *cRsetToAddModList = NULLP;
10528    struct PDCCH_Config__controlResourceSetToReleaseList *cRsetToRelList = NULLP;
10529    struct PDCCH_Config__searchSpacesToAddModList *srchSpcToAddModList = NULLP;
10530    struct PDCCH_Config__searchSpacesToReleaseList *srchSpcToRelList = NULLP;
10531
10532
10533    /* Control Resource Set To Add/Mod List */
10534    if(cuPdcchCfg->controlResourceSetToAddModList)
10535    {
10536       cRsetToAddModList = cuPdcchCfg->controlResourceSetToAddModList;
10537       if(cRsetToAddModList->list.count)
10538       {
10539          macPdcchCfg->numCRsetToAddMod = cRsetToAddModList->list.count;
10540          for(cRsetIdx = 0; cRsetIdx < cRsetToAddModList->list.count; cRsetIdx++)
10541          {
10542             macPdcchCfg->cRSetToAddModList[cRsetIdx].cRSetId = \
10543                cRsetToAddModList->list.array[cRsetIdx]->controlResourceSetId;
10544             //freqDomRsrcBitStringToInt(&cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources,\
10545                   macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc);
10546             memcpy(macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc, \
10547                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.buf,
10548                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.size);
10549
10550             macPdcchCfg->cRSetToAddModList[cRsetIdx].duration = \
10551                 cRsetToAddModList->list.array[cRsetIdx]->duration;
10552
10553             macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType = \
10554                cRsetToAddModList->list.array[cRsetIdx]->cce_REG_MappingType.present;   
10555             if(macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType == CCE_REG_MAPPINGTYPE_PR_INTERLEAVED)
10556             {
10557                //TODO: handle the case for Interleaved
10558             }
10559             macPdcchCfg->cRSetToAddModList[cRsetIdx].precoderGranularity = \
10560                 cRsetToAddModList->list.array[cRsetIdx]->precoderGranularity;
10561             if(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID)
10562             {
10563                macPdcchCfg->cRSetToAddModList[cRsetIdx].dmrsScramblingId= \
10564                   *(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID);
10565             }
10566          }
10567       }
10568    }
10569    /* Control Resource Set To Release List */
10570    if(cuPdcchCfg->controlResourceSetToReleaseList)
10571    {
10572       cRsetToRelList = cuPdcchCfg->controlResourceSetToReleaseList;
10573       if(cRsetToRelList->list.count)
10574       {
10575          macPdcchCfg->numCRsetToRel = cRsetToRelList->list.count;
10576          for(cRsetIdx = 0; cRsetIdx < cRsetToRelList->list.count; cRsetIdx++)
10577          {
10578             macPdcchCfg->cRSetToRelList[cRsetIdx] = *(cRsetToRelList->list.array[cRsetIdx]);
10579          }
10580       }
10581    }
10582
10583    /* Search space To Add/Mod List */
10584    if(cuPdcchCfg->searchSpacesToAddModList)
10585    {
10586       srchSpcToAddModList = cuPdcchCfg->searchSpacesToAddModList;
10587       if(srchSpcToAddModList->list.count)
10588       {
10589          macPdcchCfg->numSearchSpcToAddMod = srchSpcToAddModList->list.count;
10590          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToAddModList->list.count; srchSpcIdx++)
10591          {
10592             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceId =\
10593                                                                           srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceId;
10594             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].cRSetId =\
10595                                                                     *(srchSpcToAddModList->list.array[srchSpcIdx]->controlResourceSetId);
10596             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset)
10597             {
10598                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSlotPeriodicityAndOffset =\
10599                                                                                          srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset->present;
10600             }
10601             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot)
10602             {
10603                bitStringToInt(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot,\
10604                      macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSymbolsWithinSlot);
10605             }
10606             if(srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates)
10607             {
10608                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel1 = \
10609                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel1;
10610                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel2 = \
10611                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel2;
10612                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel4 = \
10613                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel4;
10614
10615                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel8 = \
10616                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel8;
10617
10618                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel16 = \
10619                                                                                         srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel16;
10620             }
10621             if(srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType)
10622             {
10623                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType =\
10624                                                                                srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->present;
10625                if(macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType == SEARCHSPACETYPE_PR_UE_SPECIFIC)
10626                {
10627                   macPdcchCfg->searchSpcToAddModList[srchSpcIdx].ueSpecificDciFormat =\
10628                                                                                       srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->choice.ue_Specific->dci_Formats;
10629                }
10630
10631             }
10632          }
10633       }
10634    }
10635    /* Search space To Rel List */
10636    if(cuPdcchCfg->searchSpacesToReleaseList)
10637    {
10638       srchSpcToRelList = cuPdcchCfg->searchSpacesToReleaseList;
10639       if(srchSpcToRelList->list.count)
10640       {
10641          macPdcchCfg->numSearchSpcToRel = srchSpcToRelList->list.count;
10642          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToRelList->list.count; srchSpcIdx++)
10643          {
10644             macPdcchCfg->searchSpcToRelList[srchSpcIdx] =\
10645                                                          *(srchSpcToRelList->list.array[srchSpcIdx]);
10646          }
10647       }
10648    }
10649 }
10650
10651 /*******************************************************************
10652  *
10653  * @brief Fills PdschCfg received by CU
10654  *
10655  * @details
10656  *
10657  *    Function : extractPdschCfg
10658  *
10659  *    Functionality: Fills PdschCfg received  by CU
10660  *
10661  * @params[in] PDSCH_Config_t *cuPdschCfg = Information which is send by CU,
10662  *                   which we have stored in F1UeContextSetupDb,
10663  *             PdschConfig *macPdschCfg = Used to Store the information which
10664  *                   needs to send in other layer, as well as this can be the variable
10665  *                   which stores the information in DuCb,
10666  *             PdschConfig *storedPdschCfg =  Null in case of sending the
10667  *                   information to other layer else it will have stored pdsch 
10668  *                   configuration in copyOfmacUeCfg.
10669  * @return void
10670  *
10671  * ****************************************************************/
10672
10673 void extractPdschCfg(PDSCH_Config_t *cuPdschCfg, PdschConfig *macPdschCfg, PdschConfig *storedPdschCfg)
10674 {
10675    uint8_t timeDomIdx;
10676    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAlloc = NULLP;
10677
10678    if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
10679    {
10680       if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->present == \
10681             PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup)
10682       {
10683          if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup)
10684          {
10685             macPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
10686                *(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_AdditionalPosition);
10687          }
10688       }
10689    }
10690    macPdschCfg->resourceAllocType = cuPdschCfg->resourceAllocation;
10691    if(cuPdschCfg->pdsch_TimeDomainAllocationList)
10692    {
10693       timeDomAlloc = cuPdschCfg->pdsch_TimeDomainAllocationList;
10694       if(timeDomAlloc->present ==\
10695             PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup)
10696       {
10697          if(timeDomAlloc->choice.setup)
10698          {
10699             macPdschCfg->numTimeDomRsrcAlloc  = timeDomAlloc->choice.setup->list.count;
10700             for(timeDomIdx = 0; timeDomIdx < timeDomAlloc->choice.setup->list.count; timeDomIdx++)
10701             {
10702                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 = NULLP;
10703                if(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0)
10704                {
10705                   if(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 == NULL)
10706                   {
10707                      if(storedPdschCfg)
10708                      {
10709                         if(storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
10710                         {
10711                            macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 =\
10712                            storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0;
10713                         }
10714                         else
10715                         {
10716                            DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
10717                         }
10718                      }
10719                      else
10720                      {
10721                         DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
10722                      }
10723                      if(!macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
10724                      {
10725                         DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for k0 at extractPdschCfg()");
10726                         return;
10727                      }
10728                   }
10729                   *(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0) = \
10730                   *(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0);
10731                }
10732                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].mappingType = \
10733                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->mappingType;
10734                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].startSymbolAndLength = \
10735                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
10736             }
10737          }
10738       }
10739    }
10740    macPdschCfg->rbgSize = cuPdschCfg->rbg_Size;
10741    if(cuPdschCfg->maxNrofCodeWordsScheduledByDCI)
10742       macPdschCfg->numCodeWordsSchByDci = *(cuPdschCfg->maxNrofCodeWordsScheduledByDCI);
10743    if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_staticBundling)
10744    {
10745       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
10746       if(cuPdschCfg->prb_BundlingType.choice.staticBundling)
10747       {
10748          if(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize)
10749          {
10750             macPdschCfg->bundlingInfo.StaticBundling.size = \
10751                *(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize);
10752          }
10753       }
10754    }
10755    else if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_dynamicBundling)
10756    {
10757       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
10758    }
10759
10760 }
10761
10762 /*******************************************************************
10763  *
10764  * @brief Fills PdschServingCellCfg received by CU
10765  *
10766  * @details
10767  *
10768  *    Function : extractPdschServingCellCfg
10769  *
10770  *    Functionality: Fills PdschCfg received  by CU
10771  *
10772  * @params[in] PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg,
10773  *             PdschServCellCfg *macUePdschSrvCellCfg
10774  * @return ROK/RFAILED
10775  *
10776  * ****************************************************************/
10777
10778 uint8_t extractPdschServingCellCfg(PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg, PdschServCellCfg *macUePdschSrvCellCfg)
10779 {
10780    if(cuPdschSrvCellCfg->codeBlockGroupTransmission)
10781    {
10782       if(cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup)
10783       {
10784          if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
10785          {
10786             *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
10787                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
10788          }
10789          else
10790          {
10791             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10792             if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
10793             {
10794                *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
10795                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
10796             }
10797             else
10798             {
10799                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxCodeBlkGrpPerTb at extractPdschServingCellCfg()");
10800                return RFAILED;
10801             }
10802          }
10803          if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
10804          {
10805             *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
10806                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
10807          }
10808          else
10809          {
10810             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->codeBlkGrpFlushInd , sizeof(bool));
10811             if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
10812             {
10813                *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
10814                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
10815             }
10816             else
10817             {
10818                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for codeBlkGrpFlushInd at extractPdschServingCellCfg()");
10819                return RFAILED;
10820             }
10821          }
10822       }
10823    }
10824    if(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH)
10825    {
10826       macUePdschSrvCellCfg->numHarqProcForPdsch = *(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH); 
10827    }
10828    if(cuPdschSrvCellCfg->ext1)
10829    {
10830       if(cuPdschSrvCellCfg->ext1->maxMIMO_Layers)
10831       {
10832         if(macUePdschSrvCellCfg->maxMimoLayers)
10833         {
10834            *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
10835         }
10836         else
10837         {
10838            DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxMimoLayers, sizeof(uint8_t));
10839            if(macUePdschSrvCellCfg->maxMimoLayers)
10840            {
10841               *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
10842            }
10843            else
10844            {
10845               DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxMimoLayers at extractPdschServingCellCfg()");
10846               return RFAILED;
10847            }
10848         }
10849       }
10850    }
10851    if(cuPdschSrvCellCfg->xOverhead)
10852    {
10853       if(macUePdschSrvCellCfg->xOverhead)
10854       {
10855          *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
10856       }
10857       else
10858       {
10859          DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->xOverhead, sizeof(PdschXOverhead));
10860          if(macUePdschSrvCellCfg->xOverhead)
10861          {
10862             *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
10863          }
10864          else
10865          {
10866             DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for xOverhead at extractPdschServingCellCfg()");
10867             return RFAILED;
10868          }
10869       }
10870    }
10871    return ROK;
10872 }
10873
10874 /*******************************************************************
10875  *
10876  * @brief Fills PuschCfg received by CU
10877  *
10878  * @details
10879  *
10880  *    Function : extractPuschCfg
10881  *
10882  *    Functionality: Fills PuschCfg received  by CU
10883  *
10884  * @params[in] BWP_UplinkDedicated__pusch_Config *cuPuschCfg,
10885  *             PuschCfg *macPuschCfg
10886  * @return void
10887  *
10888  * ****************************************************************/
10889
10890 void extractPuschCfg(struct BWP_UplinkDedicated__pusch_Config *cuPuschCfg, PuschCfg *macPuschCfg)
10891 {
10892    uint8_t timeDomIdx = 0;
10893    DMRS_UplinkConfig_t *dmrsUlCfg = NULLP;
10894    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList = NULLP;
10895
10896    if(cuPuschCfg->present == BWP_UplinkDedicated__pusch_Config_PR_setup)
10897    {
10898       if(cuPuschCfg->choice.setup)
10899       {
10900          if(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH)
10901          {
10902              macPuschCfg->dataScramblingId = \
10903                 *(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH);
10904          }
10905          if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA)
10906          {
10907             if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->present == PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup)
10908             {
10909                if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup)
10910                {
10911                   dmrsUlCfg = (cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup);
10912                   if(dmrsUlCfg->dmrs_AdditionalPosition)
10913                   {
10914                      macPuschCfg->dmrsUlCfgForPuschMapTypeA.addPos =\
10915                         *(dmrsUlCfg->dmrs_AdditionalPosition);
10916                   }
10917                   if(dmrsUlCfg->transformPrecodingDisabled)
10918                   {
10919                      if(dmrsUlCfg->transformPrecodingDisabled->scramblingID0)
10920                      {
10921                         macPuschCfg->dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0 = \
10922                            *(dmrsUlCfg->transformPrecodingDisabled->scramblingID0);
10923                      }
10924                   }
10925                }
10926             }
10927          }
10928          /*Res Alloc Type for UL */
10929          if(cuPuschCfg->choice.setup->resourceAllocation)
10930          {
10931             macPuschCfg->resourceAllocType = \
10932                cuPuschCfg->choice.setup->resourceAllocation;
10933          }
10934          if(cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList)
10935          {
10936             timeDomAllocList = cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList;
10937             if(timeDomAllocList->present == PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup)
10938             {
10939                if(timeDomAllocList->choice.setup)
10940                {
10941                   macPuschCfg->numTimeDomRsrcAlloc = timeDomAllocList->choice.setup->list.count;
10942                   for(timeDomIdx = 0; timeDomIdx <timeDomAllocList->choice.setup->list.count; timeDomIdx++)
10943                   {
10944                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].k2 = \
10945                         *(timeDomAllocList->choice.setup->list.array[timeDomIdx]->k2);
10946                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].mappingType = \
10947                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->mappingType;
10948                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].startSymbolAndLength = \
10949                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
10950                   }
10951                }
10952             }
10953          }
10954          if(cuPuschCfg->choice.setup->transformPrecoder)
10955             macPuschCfg->transformPrecoder = *(cuPuschCfg->choice.setup->transformPrecoder);
10956       }
10957    }
10958 }
10959
10960 /*******************************************************************
10961  *
10962  * @brief Function to fill pucch Power Control
10963  *
10964  * @details
10965  *
10966  *    Function : extractPucchPowerControl
10967  *
10968  *    Functionality: Function to fill pucch Power Control
10969  *
10970  * @params[in] PucchPowerControl *pwrCtrl,
10971  *             struct PUCCH_PowerControl *cuPwrCtrlCfg
10972  * @return void
10973  *
10974  * ****************************************************************/
10975
10976 void extractPucchPowerControl(PucchPowerControl *pwrCtrl, struct PUCCH_PowerControl *cuPwrCtrlCfg)
10977 {
10978    uint8_t arrIdx;
10979
10980    if(cuPwrCtrlCfg->deltaF_PUCCH_f0)
10981       pwrCtrl->deltaF_Format0 = *cuPwrCtrlCfg->deltaF_PUCCH_f0;
10982    if(cuPwrCtrlCfg->deltaF_PUCCH_f1)
10983       pwrCtrl->deltaF_Format1 = *cuPwrCtrlCfg->deltaF_PUCCH_f1;
10984    if(cuPwrCtrlCfg->deltaF_PUCCH_f2)
10985       pwrCtrl->deltaF_Format2 = *cuPwrCtrlCfg->deltaF_PUCCH_f2;
10986    if(cuPwrCtrlCfg->deltaF_PUCCH_f3)
10987       pwrCtrl->deltaF_Format3 = *cuPwrCtrlCfg->deltaF_PUCCH_f3;
10988    if(cuPwrCtrlCfg->deltaF_PUCCH_f4)
10989       pwrCtrl->deltaF_Format4 = *cuPwrCtrlCfg->deltaF_PUCCH_f4;
10990    if(cuPwrCtrlCfg->p0_Set)
10991    {
10992       pwrCtrl->p0SetCount = cuPwrCtrlCfg->p0_Set->list.count;
10993       for(arrIdx=0; arrIdx < pwrCtrl->p0SetCount; arrIdx++)
10994       {
10995          pwrCtrl->p0Set[arrIdx].p0PucchId =\
10996             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Id;
10997          pwrCtrl->p0Set[arrIdx].p0PucchVal =\
10998             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Value;
10999       }
11000    }
11001    if(cuPwrCtrlCfg->pathlossReferenceRSs)
11002    {
11003       pwrCtrl->pathLossRefRSListCount = cuPwrCtrlCfg->pathlossReferenceRSs->list.count;
11004       for(arrIdx = 0; arrIdx < pwrCtrl->pathLossRefRSListCount; arrIdx++)
11005       {
11006          pwrCtrl->pathLossRefRSList[arrIdx].pathLossRefRSId =\
11007             cuPwrCtrlCfg->pathlossReferenceRSs->list.array[arrIdx]->pucch_PathlossReferenceRS_Id;
11008       }
11009    }
11010 }
11011  
11012  /*******************************************************************
11013  *
11014  * @brief Function to extractResrcSetToAddModList sent by CU
11015  *
11016  * @details
11017  *
11018  *    Function : extractResrcSetToAddModList
11019  *
11020  *    Functionality: Fucntion to extractResrcSetToAddModList
11021  *
11022  * @params[in] PucchResrcSetCfg pointer,
11023  *             struct PUCCH_Config__resourceSetToAddModList pointer
11024  * @return void
11025  *
11026  * ****************************************************************/
11027
11028 void extractResrcSetToAddModList(PucchResrcSetCfg *macRsrcSetList, struct PUCCH_Config__resourceSetToAddModList *cuRsrcSetList)
11029 {
11030    uint8_t arrIdx, rsrcListIdx;
11031
11032    macRsrcSetList->resrcSetToAddModListCount = cuRsrcSetList->list.count; 
11033    for(arrIdx = 0; arrIdx < macRsrcSetList->resrcSetToAddModListCount; arrIdx++)
11034    {
11035       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcSetId     =\
11036          cuRsrcSetList->list.array[arrIdx]->pucch_ResourceSetId;
11037       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount =\
11038          cuRsrcSetList->list.array[arrIdx]->resourceList.list.count;
11039       for(rsrcListIdx = 0; rsrcListIdx < macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount; rsrcListIdx++)
11040       {
11041          macRsrcSetList->resrcSetToAddModList[arrIdx].resrcList[rsrcListIdx] =\
11042             *cuRsrcSetList->list.array[arrIdx]->resourceList.list.array[rsrcListIdx];
11043       }
11044
11045       if(cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1)
11046       {
11047          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize =\
11048             *cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1;
11049       }
11050       else
11051       {
11052          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize = 0;
11053       }
11054    }
11055 }/* End of extractResrcSetToAddModList */
11056
11057 /*******************************************************************
11058  *
11059  * @brief Fills extractResrcToAddModList sent by CU
11060  *
11061  * @details
11062  *
11063  *    Function : extractResrcToAddModList
11064  *
11065  *    Functionality: Fills extractResrcToAddModList
11066  *
11067  * @params[in] PucchResrcCfg pointer,
11068  *             struct PUCCH_Config__resourceToAddModList pointer
11069  * @return ROk/RFAILED
11070  *
11071  * ****************************************************************/
11072
11073 uint8_t extractResrcToAddModList(PucchResrcCfg *macResrcList, struct PUCCH_Config__resourceToAddModList *cuResrcList)
11074 {
11075    uint8_t arrIdx;
11076    
11077    macResrcList->resrcToAddModListCount = cuResrcList->list.count;
11078    for(arrIdx = 0; arrIdx < macResrcList->resrcToAddModListCount; arrIdx++)
11079    {
11080       macResrcList->resrcToAddModList[arrIdx].resrcId      =\
11081         cuResrcList->list.array[arrIdx]->pucch_ResourceId; 
11082       macResrcList->resrcToAddModList[arrIdx].startPrb     =\
11083         cuResrcList->list.array[arrIdx]->startingPRB;
11084       if(cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping)
11085       {
11086          macResrcList->resrcToAddModList[arrIdx].intraFreqHop =\
11087            *cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping;
11088       }
11089       if(cuResrcList->list.array[arrIdx]->secondHopPRB)
11090       {
11091          macResrcList->resrcToAddModList[arrIdx].secondPrbHop =\
11092            *cuResrcList->list.array[arrIdx]->secondHopPRB;
11093       }
11094       /* PUCCH RSRC FORMAT */
11095       if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format0)
11096       {
11097          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_0;
11098          if(cuResrcList->list.array[arrIdx]->format.choice.format0)
11099          {
11100             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0, sizeof(PucchFormat0));
11101             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0 == NULLP)
11102             {
11103                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format0 in extractResrcToAddModList()");
11104                return RFAILED;
11105             }
11106             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->initialCyclicShift =\
11107                cuResrcList->list.array[arrIdx]->format.choice.format0->initialCyclicShift;
11108             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->numSymbols =\
11109                cuResrcList->list.array[arrIdx]->format.choice.format0->nrofSymbols;
11110             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->startSymbolIdx =\
11111                cuResrcList->list.array[arrIdx]->format.choice.format0->startingSymbolIndex;
11112          }
11113       }
11114       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format1)
11115       {
11116          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_1;
11117          if(cuResrcList->list.array[arrIdx]->format.choice.format1)
11118          {
11119             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1, sizeof(PucchFormat1));
11120             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1 == NULLP)
11121             {
11122                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format1 in extractResrcToAddModList()");
11123                return RFAILED;
11124             }
11125             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->initialCyclicShift =\
11126                 cuResrcList->list.array[arrIdx]->format.choice.format1->initialCyclicShift;
11127             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->numSymbols =\
11128                 cuResrcList->list.array[arrIdx]->format.choice.format1->nrofSymbols;
11129             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->startSymbolIdx =\
11130                 cuResrcList->list.array[arrIdx]->format.choice.format1->startingSymbolIndex;
11131             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->timeDomOCC =\
11132                 cuResrcList->list.array[arrIdx]->format.choice.format1->timeDomainOCC;
11133          }
11134       }
11135       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format2)
11136       {
11137          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_2;
11138          if(cuResrcList->list.array[arrIdx]->format.choice.format2)
11139          {
11140             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
11141             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2 == NULLP)
11142             {
11143                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format2 in extractResrcToAddModList()");
11144                return RFAILED;
11145             }
11146             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numPrbs =\
11147                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofPRBs;
11148             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numSymbols =\
11149                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofSymbols;
11150             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->startSymbolIdx =\
11151                 cuResrcList->list.array[arrIdx]->format.choice.format2->startingSymbolIndex;
11152          }
11153       }
11154       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format3)
11155       {
11156          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_3;
11157          if(cuResrcList->list.array[arrIdx]->format.choice.format3)
11158          {
11159             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
11160             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3 == NULLP)
11161             {
11162                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format3 in extractResrcToAddModList()");
11163                return RFAILED;
11164             }
11165             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numPrbs =\
11166                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofPRBs;
11167             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numSymbols =\
11168                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofSymbols;
11169             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->startSymbolIdx =\
11170                 cuResrcList->list.array[arrIdx]->format.choice.format3->startingSymbolIndex;
11171          }
11172       }
11173       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format4)
11174       {
11175          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_4;
11176          if(cuResrcList->list.array[arrIdx]->format.choice.format4)
11177          {
11178             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4, sizeof(PucchFormat4));
11179             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4 == NULLP)
11180             {
11181                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format4 in extractResrcToAddModList()");
11182                return RFAILED;
11183             }
11184             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->numSymbols =\
11185                 cuResrcList->list.array[arrIdx]->format.choice.format4->nrofSymbols;
11186             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occLen =\
11187                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Length;
11188             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occIdx =\
11189                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Index;
11190             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->startSymbolIdx =\
11191                 cuResrcList->list.array[arrIdx]->format.choice.format4->startingSymbolIndex;
11192          }
11193       }
11194    }
11195    return ROK;
11196
11197 }/* End of extractResrcToAddModList */
11198
11199 /*******************************************************************
11200  *
11201  * @brief Fills fillPucchSchedReqPeriodAndOffset sent by CU
11202  *
11203  * @details
11204  *
11205  *    Function : fillPucchSchedReqPeriodAndOffset
11206  *
11207  *    Functionality: To fillPucchSchedReqPeriodAndOffset
11208  *
11209  * @params[in] macPeriodicty,
11210  *     SchedulingRequestResourceConfig__periodicityAndOffset pointer
11211  * @return void
11212  *
11213  * ****************************************************************/
11214
11215 void fillPucchSchedReqPeriodAndOffset(uint8_t macPeriodicty, uint16_t  macOffset,\
11216    struct SchedulingRequestResourceConfig__periodicityAndOffset *cuPeriodicty)
11217 {
11218    macPeriodicty = cuPeriodicty->present;
11219    switch(macPeriodicty)
11220    {
11221       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
11222          {
11223             macOffset     = cuPeriodicty->choice.sym2;
11224             break;
11225          }
11226       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
11227          {
11228             macOffset     = cuPeriodicty->choice.sym6or7;
11229             break;
11230          }
11231       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
11232          {
11233             macOffset     = cuPeriodicty->choice.sl1;
11234             break;
11235          }
11236       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
11237          {
11238             macOffset = cuPeriodicty->choice.sl2;
11239             break;
11240          }
11241       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
11242          {
11243             macOffset = cuPeriodicty->choice.sl4;
11244             break;
11245          }
11246       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
11247          {
11248             macOffset = cuPeriodicty->choice.sl5;
11249             break;
11250          }
11251       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
11252          {
11253             macOffset = cuPeriodicty->choice.sl8;
11254             break;
11255          }
11256       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
11257          {
11258             macOffset = cuPeriodicty->choice.sl10;
11259             break;
11260          }
11261       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
11262          {
11263             macOffset = cuPeriodicty->choice.sl16;
11264             break;
11265          }
11266       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
11267          {
11268             macOffset = cuPeriodicty->choice.sl20;
11269             break;
11270          }
11271       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
11272          {
11273             macOffset = cuPeriodicty->choice.sl40;
11274             break;
11275          }
11276       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
11277          {
11278             macOffset = cuPeriodicty->choice.sl80;
11279             break;
11280          }
11281       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
11282          {
11283             macOffset = cuPeriodicty->choice.sl160;
11284             break;
11285          }
11286       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
11287          {
11288             macOffset = cuPeriodicty->choice.sl320;
11289             break;
11290          }
11291       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
11292          {
11293             macOffset = cuPeriodicty->choice.sl640;
11294             break;
11295          }
11296       default :
11297          DU_LOG("\nERROR  -->  F1AP : Invalid periodicity %d", macPeriodicty);
11298    }
11299 }
11300
11301 /*******************************************************************
11302  *
11303  * @brief Function to extractPucchFormatCfg sent by CU
11304  *
11305  * @details
11306  *
11307  *    Function : extractPucchFormatCfg
11308  *
11309  *    Functionality: Function to extractPucchFormatCfg
11310  *
11311  * @params[in] PucchFormatCfg pointer,
11312  *             PUCCH_FormatConfig_t pointer
11313  * @return void
11314  *
11315  * ****************************************************************/
11316
11317 void extractPucchFormatCfg(PucchFormatCfg *macFormatCfg, PUCCH_FormatConfig_t *cuFormatCfg)
11318  {
11319     if(cuFormatCfg->interslotFrequencyHopping)
11320        macFormatCfg->interSlotFreqHop = *cuFormatCfg->interslotFrequencyHopping;
11321     if(cuFormatCfg->additionalDMRS)  
11322        macFormatCfg->addDmrs = *cuFormatCfg->additionalDMRS;
11323     if(cuFormatCfg->maxCodeRate)
11324        macFormatCfg->maxCodeRate = *cuFormatCfg->maxCodeRate;
11325     if(cuFormatCfg->nrofSlots)  
11326        macFormatCfg->numSlots = *cuFormatCfg->nrofSlots;
11327     if(cuFormatCfg->pi2BPSK)  
11328        macFormatCfg->pi2BPSK = *cuFormatCfg->pi2BPSK;
11329     if(cuFormatCfg->simultaneousHARQ_ACK_CSI)  
11330        macFormatCfg->harqAckCSI = *cuFormatCfg->simultaneousHARQ_ACK_CSI;
11331  }/* End of extractPucchFormatCfg */
11332
11333 /*******************************************************************
11334  *
11335  * @brief Function to extractSchedReqCfgToAddMod sent by CU
11336  *
11337  * @details
11338  *
11339  *    Function : extractSchedReqCfgToAddMod
11340  *
11341  *    Functionality: Function to extractSchedReqCfgToAddMod
11342  *
11343  * @params[in] PucchSchedReqCfg pointer,
11344  *      PUCCH_Config__schedulingRequestResourceToAddModList pointer
11345  * @return void
11346  *
11347  * ****************************************************************/
11348
11349 void extractSchedReqCfgToAddMod(PucchSchedReqCfg *macSchedReqCfg, struct PUCCH_Config__schedulingRequestResourceToAddModList *cuSchedReqList)
11350 {
11351    uint8_t arrIdx;
11352
11353    macSchedReqCfg->schedAddModListCount = cuSchedReqList->list.count;
11354    for(arrIdx = 0; arrIdx <  macSchedReqCfg->schedAddModListCount; arrIdx++)
11355    {
11356       macSchedReqCfg->schedAddModList[arrIdx].resrcId =\
11357          cuSchedReqList->list.array[arrIdx]->schedulingRequestResourceId;
11358       macSchedReqCfg->schedAddModList[arrIdx].requestId =\
11359          cuSchedReqList->list.array[arrIdx]->schedulingRequestID;
11360       if(cuSchedReqList->list.array[arrIdx]->periodicityAndOffset)
11361       {
11362          fillPucchSchedReqPeriodAndOffset(macSchedReqCfg->schedAddModList[arrIdx].periodicity,\
11363             macSchedReqCfg->schedAddModList[arrIdx].offset, cuSchedReqList->list.array[arrIdx]->periodicityAndOffset);
11364       }
11365       if(cuSchedReqList->list.array[arrIdx]->resource)
11366       {
11367          macSchedReqCfg->schedAddModList[arrIdx].resrc =\
11368             *cuSchedReqList->list.array[arrIdx]->resource;
11369       }
11370    }
11371
11372 }/* End of extractSchedReqCfgToAddMod */
11373
11374  /*******************************************************************
11375  *
11376  * @brief Fills PucchCfg received by CU
11377  *
11378  * @details
11379  *
11380  *    Function : extractPucchCfg
11381  *
11382  *    Functionality: Fills PucchCfg received  by CU
11383  *
11384  * @params[in] BWP_UplinkDedicated__pucch_Config *cuPucchCfg = Information which
11385  *                is send by CU, which we have stored in F1UeContextSetupDb,
11386  *             PucchCfg *macPucchCfg = Used to Store the information which
11387  *                needs to send in other layer, as well as this can be the variable
11388  *                which stores the information in DuCb,
11389  *             PucchCfg *storedPucchCfg = Null in case of sending the
11390  *                information to other layer else it will have Pucch Cfg which
11391  *                we have stored in copyOfmacUeCfg.
11392  * @return ROK/RFAILED
11393  *
11394  * ****************************************************************/
11395
11396 uint8_t extractPucchCfg(struct BWP_UplinkDedicated__pucch_Config *cuPucchCfg, PucchCfg *macPucchCfg,\
11397 PucchCfg *storedPucchCfg)        
11398 {
11399    uint8_t arrIdx;
11400
11401    if(cuPucchCfg->present == BWP_UplinkDedicated__pucch_Config_PR_setup)
11402    {
11403       if(cuPucchCfg->choice.setup)
11404       {
11405          /* Resource Set Cfg */ 
11406          if(cuPucchCfg->choice.setup->resourceSetToAddModList)
11407          {
11408             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrcSet, sizeof(PucchResrcSetCfg));
11409             if(macPucchCfg->resrcSet == NULLP)
11410             {
11411                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc set List in extractPucchCfg()");
11412                return RFAILED;
11413             }
11414             memset(macPucchCfg->resrcSet, 0, sizeof(PucchResrcSetCfg));
11415             extractResrcSetToAddModList(macPucchCfg->resrcSet, cuPucchCfg->choice.setup->resourceSetToAddModList);
11416          }
11417          
11418          /* Resource Cfg */ 
11419          if(cuPucchCfg->choice.setup->resourceToAddModList)
11420          {
11421             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrc, sizeof(PucchResrcCfg));
11422             if(macPucchCfg->resrc == NULLP)
11423             {
11424                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc List in extractPucchCfg()");
11425                return RFAILED;
11426             }
11427             memset(macPucchCfg->resrc, 0, sizeof(PucchResrcCfg));
11428             extractResrcToAddModList(macPucchCfg->resrc, cuPucchCfg->choice.setup->resourceToAddModList);
11429          }
11430          
11431          /* Format 1 Cfg */ 
11432          if(cuPucchCfg->choice.setup->format1)
11433          {
11434             DU_ALLOC_SHRABL_BUF(macPucchCfg->format1, sizeof(PucchFormatCfg));
11435             if(macPucchCfg->format1 == NULLP)
11436             {
11437                DU_LOG("\nERROR --> F1AP : Failed to extract format 1 Cfg in  extractPucchCfg()");
11438                return RFAILED;
11439             }
11440             memset(macPucchCfg->format1, 0, sizeof(PucchFormatCfg));
11441             extractPucchFormatCfg(macPucchCfg->format1,\
11442                cuPucchCfg->choice.setup->format1->choice.setup);
11443          }
11444          
11445          /* Format 2 Cfg */
11446          if(cuPucchCfg->choice.setup->format2)
11447          {
11448             DU_ALLOC_SHRABL_BUF(macPucchCfg->format2, sizeof(PucchFormatCfg));
11449             if(macPucchCfg->format2 == NULLP)
11450             {
11451                DU_LOG("\nERROR --> F1AP : Failed to extract format 2 Cfg in  extractPucchCfg()");
11452                return RFAILED;
11453             }
11454             memset(macPucchCfg->format2, 0, sizeof(PucchFormatCfg));
11455             extractPucchFormatCfg(macPucchCfg->format2,\
11456                cuPucchCfg->choice.setup->format2->choice.setup);
11457          }
11458          
11459          /* Format 3 Cfg */
11460          if(cuPucchCfg->choice.setup->format3)
11461          {
11462             DU_ALLOC_SHRABL_BUF(macPucchCfg->format3, sizeof(PucchFormatCfg));
11463             if(macPucchCfg->format3 == NULLP)
11464             {
11465                DU_LOG("\nERROR --> F1AP : Failed to extract format 3 Cfg in  extractPucchCfg()");
11466                return RFAILED;
11467             }
11468             memset(macPucchCfg->format3, 0, sizeof(PucchFormatCfg));
11469             extractPucchFormatCfg(macPucchCfg->format3,\
11470                cuPucchCfg->choice.setup->format3->choice.setup);
11471          }
11472
11473          /* Format 4 Cfg */
11474          if(cuPucchCfg->choice.setup->format4)
11475          {
11476             DU_ALLOC_SHRABL_BUF(macPucchCfg->format4, sizeof(PucchFormatCfg));
11477             if(macPucchCfg->format4 == NULLP)
11478             {
11479                DU_LOG("\nERROR --> F1AP : Failed to extract format 4 Cfg in  extractPucchCfg()");
11480                return RFAILED;
11481             }
11482             memset(macPucchCfg->format4, 0, sizeof(PucchFormatCfg));
11483             extractPucchFormatCfg(macPucchCfg->format4,\
11484                cuPucchCfg->choice.setup->format4->choice.setup);
11485          }
11486
11487          /* Sched Req List */
11488          if(cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList)
11489          {
11490             DU_ALLOC_SHRABL_BUF(macPucchCfg->schedReq, sizeof(PucchSchedReqCfg));
11491             if(macPucchCfg->schedReq == NULLP)
11492             {
11493                DU_LOG("\nERROR --> F1AP : Failed to extract schedReqCfg in  extractPucchCfg()");
11494                return RFAILED;
11495             }
11496             memset(macPucchCfg->schedReq, 0, sizeof(PucchSchedReqCfg));
11497             extractSchedReqCfgToAddMod(macPucchCfg->schedReq,\
11498             cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList);
11499          }
11500
11501          /*TODO: Add support for  Spatial Info */
11502
11503          /* MultiCsiCfg */
11504          if(cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList)
11505          {
11506             DU_ALLOC_SHRABL_BUF(macPucchCfg->multiCsiCfg, sizeof(PucchMultiCsiCfg));
11507             if(macPucchCfg->multiCsiCfg == NULLP)
11508             {
11509                DU_LOG("\nERROR --> F1AP : Failed to extract multiCsiCfg in  extractPucchCfg()");
11510                return RFAILED;
11511             }
11512             memset(macPucchCfg->multiCsiCfg, 0, sizeof(PucchMultiCsiCfg));
11513             macPucchCfg->multiCsiCfg->multiCsiResrcListCount = cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.count;
11514             for(arrIdx =0; arrIdx < macPucchCfg->multiCsiCfg->multiCsiResrcListCount; arrIdx++)
11515             {
11516                macPucchCfg->multiCsiCfg->multiCsiResrcList[arrIdx] =\
11517                  *cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.array[arrIdx];
11518             }
11519          }
11520
11521          /* Dl_DataToUL_ACK */ 
11522          if(cuPucchCfg->choice.setup->dl_DataToUL_ACK)
11523     {
11524        if(storedPucchCfg)
11525        {
11526           if(storedPucchCfg->dlDataToUlAck)
11527           {
11528              macPucchCfg->dlDataToUlAck = storedPucchCfg->dlDataToUlAck; 
11529           }
11530           else
11531           {
11532             DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
11533           }
11534        }
11535        else
11536        {
11537           DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
11538        }
11539        if(macPucchCfg->dlDataToUlAck == NULLP)
11540        {
11541           DU_LOG("\nERROR --> F1AP : Failed to extract Dl_DataToUL_ACK in extractPucchCfg()");
11542           return RFAILED;
11543        }
11544        memset(macPucchCfg->dlDataToUlAck, 0, sizeof(PucchDlDataToUlAck));
11545        macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount = cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.count;
11546        for(arrIdx = 0; arrIdx < macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; arrIdx++)
11547        {
11548           macPucchCfg->dlDataToUlAck->dlDataToUlAckList[arrIdx] =\
11549           *cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.array[arrIdx];
11550        }
11551          }
11552
11553          /* Power Control */
11554          if(cuPucchCfg->choice.setup->pucch_PowerControl)
11555          {
11556             DU_ALLOC_SHRABL_BUF(macPucchCfg->powerControl, sizeof(PucchPowerControl));
11557             if(macPucchCfg->powerControl == NULLP)
11558             {
11559                DU_LOG("\nERROR --> F1AP : Failed to extract power control in extractPucchCfg()");
11560                return RFAILED;
11561             }
11562             extractPucchPowerControl(macPucchCfg->powerControl,\
11563                cuPucchCfg->choice.setup->pucch_PowerControl);
11564          }
11565       }
11566    }
11567    return ROK;
11568 }
11569
11570 /*******************************************************************
11571  *
11572  * @brief Fills ServingCellReconfig received by CU
11573  *
11574  * @details
11575  *
11576  *    Function : extractSpCellDedicatedCfg
11577  *
11578  *    Functionality: Fills ServingCellReconfig received  by CU
11579  *
11580  * @params[in] ServingCellConfig_t *cuSrvCellCfg = Information which is send by
11581  *                  CU, which we have stored in F1UeContextSetupDb,
11582  *             ServCellCfgInfo *macSrvCellCfg = Used to Store the information
11583  *                  which  needs to send in other layer, as well as this can be the
11584  *                  variable which stores the information in DuCb, 
11585  *             ServCellCfgInfo *storedSrvCellCfg = Null in case of sending the
11586  *                  information to other layer else it will have ServCellCfgInfo which
11587  *                  we have stored in copyOfmacUeCfg.
11588  * @return ROK/RFAILD
11589  *
11590  * ****************************************************************/
11591 uint8_t extractSpCellDedicatedCfg(ServingCellConfig_t *cuSrvCellCfg, ServCellCfgInfo *macSrvCellCfg,\
11592 ServCellCfgInfo *storedSrvCellCfg)
11593 {
11594    uint8_t ret = ROK;
11595    BWP_DownlinkDedicated_t *dlBwp = NULLP;
11596    BWP_UplinkDedicated_t   *ulBwp = NULLP;
11597
11598    if(cuSrvCellCfg->initialDownlinkBWP)
11599    {
11600       dlBwp = ((BWP_DownlinkDedicated_t *)(cuSrvCellCfg->initialDownlinkBWP));
11601       if(dlBwp->pdcch_Config)
11602       {
11603          if(dlBwp->pdcch_Config->choice.setup)
11604          {
11605             macSrvCellCfg->initDlBwp.pdcchPresent = true;
11606             if(storedSrvCellCfg)
11607             {
11608                if(!storedSrvCellCfg->initDlBwp.pdcchPresent)
11609                {
11610                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11611                }
11612                else
11613                {
11614                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11615                }
11616             }
11617             else
11618             {
11619                extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11620             }
11621          }
11622       }
11623       if(dlBwp->pdsch_Config)
11624       {
11625          if(dlBwp->pdsch_Config->choice.setup)
11626          {
11627             macSrvCellCfg->initDlBwp.pdschPresent = true;
11628             
11629             if(storedSrvCellCfg)
11630             {
11631                if(!storedSrvCellCfg->initDlBwp.pdschPresent)
11632                {
11633                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
11634                }
11635                else
11636                {
11637                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg,\
11638                         &storedSrvCellCfg->initDlBwp.pdschCfg);
11639                }
11640             }
11641             else
11642             {
11643                extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
11644             }
11645          }
11646       }
11647    }
11648    if(cuSrvCellCfg->firstActiveDownlinkBWP_Id)
11649       macSrvCellCfg->firstActvDlBwpId = *(cuSrvCellCfg->firstActiveDownlinkBWP_Id);
11650    if(cuSrvCellCfg->defaultDownlinkBWP_Id)
11651       macSrvCellCfg->defaultDlBwpId = *(cuSrvCellCfg->defaultDownlinkBWP_Id);
11652    if(cuSrvCellCfg->bwp_InactivityTimer)
11653    {
11654       if(macSrvCellCfg->bwpInactivityTmr)
11655       {
11656          memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
11657       }
11658       else
11659       {
11660          macSrvCellCfg->bwpInactivityTmr = NULLP;
11661          DU_ALLOC_SHRABL_BUF(macSrvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
11662          if(macSrvCellCfg->bwpInactivityTmr)
11663          {
11664             memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
11665          }
11666          else
11667          {
11668             DU_LOG("\nERROR  --> F1AP : Memory Alloc failed for bwpInactivityTmr at extractSpCellDedicatedCfg()");
11669             return RFAILED;
11670          }
11671       }
11672    }
11673    if(cuSrvCellCfg->pdsch_ServingCellConfig)
11674    {
11675       if(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup)
11676       {
11677          ret = extractPdschServingCellCfg(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup, &macSrvCellCfg->pdschServCellCfg);
11678          if(ret == RFAILED)
11679          {
11680             DU_LOG("\nERROR --> F1AP : Failed at extractPdschServingCellCfg()");
11681             return RFAILED;
11682          }
11683       }
11684    }
11685    if(cuSrvCellCfg->uplinkConfig)
11686    {
11687       if(cuSrvCellCfg->uplinkConfig->initialUplinkBWP)
11688       {
11689          ulBwp = ((BWP_UplinkDedicated_t *)(cuSrvCellCfg->uplinkConfig->initialUplinkBWP));
11690          if(ulBwp->pusch_Config)
11691          {
11692             macSrvCellCfg->initUlBwp.puschPresent = true;
11693             extractPuschCfg(ulBwp->pusch_Config, &macSrvCellCfg->initUlBwp.puschCfg);
11694          }
11695          if(ulBwp->pucch_Config)
11696          {
11697             macSrvCellCfg->initUlBwp.pucchPresent = true;
11698             memset(&macSrvCellCfg->initUlBwp.pucchCfg, 0, sizeof(PucchCfg));
11699             if(storedSrvCellCfg)
11700             {
11701                if(!storedSrvCellCfg->initUlBwp.pucchPresent)
11702                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
11703                else
11704                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg,\
11705                   &storedSrvCellCfg->initUlBwp.pucchCfg);
11706             }
11707             else
11708             {
11709                extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
11710             }
11711          }
11712       }
11713       if(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id)
11714          macSrvCellCfg->firstActvUlBwpId = *(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id);
11715    }
11716    return ret;
11717 }
11718 /*******************************************************************
11719  *
11720  * @brief Fills Reconfig Cell group Info received by CU
11721  *
11722  * @details
11723  *
11724  *    Function : extractUeReCfgCellInfo
11725  *
11726  *    Functionality: Fills Reconfig Cell group Info received by CU
11727  *   
11728  * @params[in] CellGroupConfigRrc_t *cellGrp = CellGroupConfigRrc_t information which
11729  *                       is send by CU, which we have stored in F1UeContextSetupDb
11730  *             MacUeCfg *MacUeCfg = Used to Store the information,
11731  *                      which needs to send in other layer, as well as this can be
11732  *                      the variable which stores the information in DuCb,
11733  *             MacUeCfg *storedMacUeCfg = Null in case of sending the
11734  *                      information to other layer else it will have copyOfmacUeCfg
11735  *                      which we have stored in F1UeContextSetupDb.
11736  *
11737  * @return ROK/RFAILED
11738  *
11739  * ****************************************************************/
11740 uint8_t extractUeReCfgCellInfo(CellGroupConfigRrc_t *cellGrp, MacUeCfg *macUeCfg, MacUeCfg *storedMacUeCfg)
11741 {
11742    uint8_t ret = ROK;
11743    MAC_CellGroupConfig_t     *macCellGroup = NULLP;
11744    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
11745    SpCellConfig_t            *spcellCfg = NULLP;
11746    ServingCellConfig_t       *servCellCfg = NULLP;
11747
11748    if(cellGrp)
11749    {
11750       /* Fill MacCell Group Reconfig  */
11751       if(cellGrp->mac_CellGroupConfig)
11752       {
11753          macUeCfg->macCellGrpCfgPres = true;
11754          macCellGroup = ((MAC_CellGroupConfig_t *)(cellGrp->mac_CellGroupConfig));
11755          if(macCellGroup->schedulingRequestConfig)
11756          {
11757             extractSchReqReConfig(macCellGroup->schedulingRequestConfig, &macUeCfg->macCellGrpCfg.schReqCfg);
11758          }
11759          if(macCellGroup->tag_Config)
11760          {
11761             extractTagReconfig(macCellGroup->tag_Config, &macUeCfg->macCellGrpCfg.tagCfg);
11762          }
11763          if(macCellGroup->bsr_Config)
11764          {
11765             macUeCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer = macCellGroup->bsr_Config->periodicBSR_Timer;
11766             macUeCfg->macCellGrpCfg.bsrTmrCfg.retxTimer     = macCellGroup->bsr_Config->retxBSR_Timer;
11767             if(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer)
11768             {
11769                macUeCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer  =\
11770                *(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer);
11771             }
11772          }
11773          if(macCellGroup->phr_Config)
11774          {
11775             if(macCellGroup->phr_Config->present == MAC_CellGroupConfig__phr_Config_PR_setup)
11776             {
11777                macUeCfg->macCellGrpCfg.phrCfgSetupPres = true;
11778                if(macCellGroup->phr_Config->choice.setup)
11779                {
11780                   macUeCfg->macCellGrpCfg.phrCfg.periodicTimer     = \
11781                   macCellGroup->phr_Config->choice.setup->phr_PeriodicTimer;
11782                   macUeCfg->macCellGrpCfg.phrCfg.prohibitTimer     = \
11783                   macCellGroup->phr_Config->choice.setup->phr_ProhibitTimer;
11784                   macUeCfg->macCellGrpCfg.phrCfg.txPowerFactor     = \
11785                   macCellGroup->phr_Config->choice.setup->phr_Tx_PowerFactorChange;
11786                   macUeCfg->macCellGrpCfg.phrCfg.multiplePHR       = \
11787                   macCellGroup->phr_Config->choice.setup->multiplePHR;
11788                   macUeCfg->macCellGrpCfg.phrCfg.dummy             = \
11789                   macCellGroup->phr_Config->choice.setup->dummy;
11790                   macUeCfg->macCellGrpCfg.phrCfg.phrType2OtherCell = \
11791                   macCellGroup->phr_Config->choice.setup->phr_Type2OtherCell;
11792                   macUeCfg->macCellGrpCfg.phrCfg.phrOtherCG        = \
11793                   macCellGroup->phr_Config->choice.setup->phr_ModeOtherCG;
11794                }
11795             }
11796          }
11797       }
11798       /* Fill Physical Cell Group Reconfig */
11799       if(cellGrp->physicalCellGroupConfig)
11800       {
11801          macUeCfg->phyCellGrpCfgPres = true;
11802          phyCellGrpCfg = ((PhysicalCellGroupConfig_t *)(cellGrp->physicalCellGroupConfig));
11803          if(phyCellGrpCfg->p_NR_FR1)
11804          {
11805             if(*(phyCellGrpCfg->p_NR_FR1) != macUeCfg->phyCellGrpCfg.pNrFr1)
11806                macUeCfg->phyCellGrpCfg.pNrFr1 = *(phyCellGrpCfg->p_NR_FR1);
11807          }
11808          macUeCfg->phyCellGrpCfg.pdschHarqAckCodebook = phyCellGrpCfg->pdsch_HARQ_ACK_Codebook;
11809       }
11810       /* Fill SpCell Reconfig */
11811       if(cellGrp->spCellConfig)
11812       {
11813          macUeCfg->spCellCfgPres = true;
11814          spcellCfg = ((SpCellConfig_t *)(cellGrp->spCellConfig));  
11815          if(spcellCfg->servCellIndex)
11816          {
11817             macUeCfg->spCellCfg.servCellIdx = *(spcellCfg->servCellIndex);
11818          }
11819          /* Fill Serving cell Reconfig info */
11820          if(cellGrp->spCellConfig->spCellConfigDedicated)
11821          {
11822             servCellCfg = ((ServingCellConfig_t *)(cellGrp->spCellConfig->spCellConfigDedicated));
11823             if(storedMacUeCfg)
11824             {
11825                if(!storedMacUeCfg->spCellCfgPres)
11826                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
11827                else
11828                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg,\
11829                         &storedMacUeCfg->spCellCfg.servCellCfg);
11830             }
11831             else
11832             {
11833                ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
11834             }
11835             if(ret == RFAILED)
11836             {
11837                DU_LOG("\nERROR --> F1AP : Failed at extractSpCellDedicatedCfg()");
11838             }
11839          }
11840       }
11841    }
11842    return ret;
11843 }
11844 /*******************************************************************
11845 *
11846 * @brief free the memory allocated by decoder
11847 *
11848 * @details
11849 *
11850 *    Function : freeAperDecodeNrcgi 
11851 *
11852 *    Functionality: Free Nrcgi values
11853 *
11854 * @params[in] NRCGI_t *nrcgi
11855 * @return void
11856 *
11857 * ****************************************************************/
11858
11859
11860 void freeAperDecodeNrcgi(NRCGI_t *nrcgi)
11861 {
11862     if(nrcgi->pLMN_Identity.buf != NULLP)
11863     {
11864        free(nrcgi->pLMN_Identity.buf);
11865     }
11866     if(nrcgi->nRCellIdentity.buf != NULLP)
11867     {
11868        free(nrcgi->nRCellIdentity.buf);
11869     }
11870 }
11871 /*******************************************************************
11872 *
11873 * @brief free the memory allocated by decoder
11874 *
11875 * @details
11876 *
11877 *    Function : freeAperDecodeCuToDuInfo 
11878 *
11879 *    Functionality:  Free Cu To Du Information
11880 *
11881 * @params[in] CUtoDURRCInformation_t *rrcMsg
11882 * @return void
11883 *
11884 * ****************************************************************/
11885
11886
11887 void freeAperDecodeCuToDuInfo(CUtoDURRCInformation_t *rrcMsg)
11888 {
11889    uint8_t ieIdx =0;
11890    uint8_t arrIdx =0;
11891
11892    if(rrcMsg->uE_CapabilityRAT_ContainerList)
11893    {
11894       if(rrcMsg->uE_CapabilityRAT_ContainerList->buf)
11895          free(rrcMsg->uE_CapabilityRAT_ContainerList->buf);
11896       free(rrcMsg->uE_CapabilityRAT_ContainerList);
11897    }
11898
11899    if(rrcMsg->iE_Extensions)
11900    {
11901       if(rrcMsg->iE_Extensions->list.array)
11902       {
11903          for(ieIdx= 0; ieIdx < rrcMsg->iE_Extensions->list.count; ieIdx++)
11904          {
11905             if(rrcMsg->iE_Extensions->list.array[ieIdx])
11906             {
11907                switch(rrcMsg->iE_Extensions->list.array[ieIdx]->id)
11908                {
11909                   case ProtocolIE_ID_id_CellGroupConfig:
11910                      if(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf != NULLP)
11911                      {
11912                         free(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf);
11913                      }
11914                      break;
11915                   default:
11916                      DU_LOG("\nERROR  -->  F1AP : Invalid Event type %ld at FreeCuToDuInfo()", \
11917                            rrcMsg->iE_Extensions->list.array[ieIdx]->id);
11918                      break;
11919                }
11920             }
11921          }
11922          for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
11923          {
11924             free(rrcMsg->iE_Extensions->list.array[arrIdx]);
11925          }
11926          free(rrcMsg->iE_Extensions->list.array);
11927
11928       }
11929
11930       free(rrcMsg->iE_Extensions);
11931    }
11932 }
11933 /*******************************************************************
11934 *
11935 * @brief free the memory allocated by decoder
11936 *
11937 * @details 
11938 *
11939 *    Function : freeAperDecodeSplCellList
11940 *
11941 *    Functionality: Free Spl Cell List 
11942                     where memory allocated by aper_decoder
11943 *
11944 * @params[in]  SCell_ToBeSetup_List_t *spCellLst
11945 * @return void
11946 *
11947 * ****************************************************************/
11948
11949
11950 void freeAperDecodeSplCellList(SCell_ToBeSetup_List_t *spCellLst)
11951 {
11952     uint8_t  cellIdx =0;
11953
11954     if(spCellLst->list.array != NULLP)
11955     {
11956        for(cellIdx=0; cellIdx<spCellLst->list.count; cellIdx++)
11957        {
11958           if(cellIdx==0&&spCellLst->list.array[cellIdx]!=NULLP)
11959           {
11960              freeAperDecodeNrcgi(&spCellLst->list.array[cellIdx]->value.choice.SCell_ToBeSetup_Item.sCell_ID);
11961           }
11962           if(spCellLst->list.array[cellIdx]!=NULLP)
11963           {
11964              free(spCellLst->list.array[cellIdx]);
11965           }
11966        }
11967        free(spCellLst->list.array);
11968     }
11969 }
11970 /*******************************************************************
11971 *
11972 * @brief free the memory allocated by decoder
11973 *
11974 * @details
11975 *
11976 *    Function : freeAperDecodeSRBSetup 
11977 *
11978 *    Functionality: added free part for the memory allocated by aper_decoder
11979 *
11980 * @params[in] SRBs_ToBeSetup_List_t *srbSet
11981 * @return void
11982 *
11983 ****************************************************************/
11984
11985
11986 void freeAperDecodeSRBSetup(SRBs_ToBeSetup_List_t *srbSet)
11987 {
11988     uint8_t srbIdx =0;
11989     if(srbSet->list.array != NULLP)
11990     {
11991        for(srbIdx=0; srbIdx<srbSet->list.count; srbIdx++)
11992        {
11993           if(srbSet->list.array[srbIdx]!=NULLP)
11994           {
11995              free(srbSet->list.array[srbIdx]);
11996           }
11997        }
11998        free(srbSet->list.array);
11999     }
12000 }
12001
12002 /*******************************************************************
12003 *
12004 * @brief free the memory allocated by decoder
12005 *
12006 * @details
12007 *
12008 *    Function : freeAperDecodeULTnlInfo
12009 *
12010 *    Functionality: added free part for the memory allocated by aper_decoder
12011 *
12012 * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
12013 * @return void
12014 *
12015 * ****************************************************************/
12016
12017
12018 void freeAperDecodeULTnlInfo(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
12019 {
12020    uint8_t ulIdx=0;
12021    if(ulInfo->list.array != NULLP)
12022    {
12023       for(ulIdx=0; ulIdx<ulInfo->list.count; ulIdx++)
12024       {
12025          if(ulIdx==0&&ulInfo->list.array[ulIdx]!=NULLP)
12026          {
12027             if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel!=NULLP)
12028             {
12029                if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12030                      transportLayerAddress.buf != NULLP)
12031                {
12032                   if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf\
12033                         !=NULLP)
12034                   {
12035                      free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf);
12036                   }
12037                   free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12038                         transportLayerAddress.buf);
12039                }
12040                free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel);
12041             }
12042          }
12043          if(ulInfo->list.array[ulIdx]!=NULLP)
12044          {
12045             free(ulInfo->list.array[ulIdx]);
12046          }
12047       }
12048       free(ulInfo->list.array);
12049    }
12050 }
12051 /*******************************************************************
12052 *
12053 * @brief free the memory allocated by decoder
12054 *
12055 * @details
12056 *
12057 *    Function : freeAperDecodeDRBSetup  
12058 *
12059 *    Functionality: free DRBSetup which is allocated by decoder
12060 *
12061 * @params[in]  DRBs_ToBeSetup_List_t *drbSet
12062 * @return void
12063 *
12064 * ****************************************************************/
12065
12066 void freeAperDecodeDRBSetup(DRBs_ToBeSetup_List_t *drbSet)
12067 {
12068    DRBs_ToBeSetup_Item_t *drbSetItem = NULLP;
12069    uint8_t  flowIdx =0;
12070    uint8_t  drbIdx =0;
12071
12072    if(drbSet->list.array != NULLP)
12073    {
12074       for(drbIdx=0; drbIdx<drbSet->list.count; drbIdx++)
12075       {
12076          if(drbIdx==0&&drbSet->list.array[drbIdx] != NULLP)
12077          {
12078             drbSetItem =&drbSet->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12079             if(drbSetItem->qoSInformation.choice.choice_extension != NULLP)
12080             {
12081                if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12082                      qoS_Characteristics.choice.non_Dynamic_5QI !=NULLP)
12083                {
12084                   if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12085                         qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12086                   {
12087                      if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12088                            qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12089                      {
12090
12091                         if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf!=NULLP)
12092                         {
12093
12094                            if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD!=NULLP)
12095                            {
12096
12097                               if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD->\
12098                                     buf!=NULLP)
12099                               {
12100
12101                                  if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.\
12102                                        flows_Mapped_To_DRB_List.list.array != NULLP)
12103                                  {
12104
12105                                     for(flowIdx=0;flowIdx<drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12106                                           DRB_Information.flows_Mapped_To_DRB_List.list.count; flowIdx++)
12107                                     {
12108
12109                                        if(flowIdx==0&&drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12110                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12111                                        {
12112                                           if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12113                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12114                                                 qoSFlowLevelQoSParameters.\
12115                                                 qoS_Characteristics.choice.non_Dynamic_5QI!=NULLP)
12116                                           {
12117                                              if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12118                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12119                                                    qoSFlowLevelQoSParameters.\
12120                                                    qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12121                                              {
12122
12123                                                 if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12124                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12125                                                       qoSFlowLevelQoSParameters.\
12126                                                       qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12127                                                 {
12128
12129
12130                                                    free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12131                                                          DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12132                                                          qoSFlowLevelQoSParameters.\
12133                                                          qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12134                                                 }
12135
12136                                                 free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12137                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12138                                                       qoSFlowLevelQoSParameters.\
12139                                                       qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12140                                              }
12141
12142                                              free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12143
12144                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12145                                                    qoSFlowLevelQoSParameters.\
12146                                                    qoS_Characteristics.choice.non_Dynamic_5QI);
12147                                           }
12148                                        }
12149                                        if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12150                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12151                                        {
12152
12153                                           free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12154                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]);
12155                                        }
12156                                     }
12157
12158                                     free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12159                                           DRB_Information.flows_Mapped_To_DRB_List.list.array);
12160                                  }
12161
12162                                  free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12163                                        DRB_Information.sNSSAI.sD->buf);
12164                               }
12165
12166                               free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD);
12167                            }
12168
12169                            free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf);
12170
12171                         }
12172
12173                         free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12174
12175                               qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12176                      }
12177
12178                      free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12179                            qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12180                   }
12181
12182                   free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12183                         qoS_Characteristics.choice.non_Dynamic_5QI);
12184                }
12185                free(drbSetItem->qoSInformation.choice.choice_extension);
12186             }
12187             freeAperDecodeULTnlInfo(&drbSetItem->uLUPTNLInformation_ToBeSetup_List);
12188             if(drbSetItem->uLConfiguration)
12189             {
12190                free(drbSetItem->uLConfiguration);
12191             }
12192          }
12193          if(drbSet->list.array[drbIdx]!=NULLP)
12194          {
12195             free(drbSet->list.array[drbIdx]);
12196          }
12197       }
12198       free(drbSet->list.array);
12199    }
12200 }
12201
12202
12203 /*******************************************************************
12204  *
12205  * @brief builds Mac Cell Cfg
12206  *
12207  * @details
12208  *
12209  *    Function : procUeReCfgCellInfo
12210  *
12211  *    Functionality: builds Mac Cell Cfg
12212  *
12213  * @params[in] MacUeCfg *macUeCfgToSend = Used to Store the information which
12214  *                       needs to send in other layer, as well as this can be
12215  *                       the variable which stores the information in DuCb.
12216  *             MacUeCfg *storedMacUeCfg = Null in case of sending the
12217  *                       information to other layer else it will have copyOfmacUeCfg  
12218  *                       which we have stored in F1UeContextSetupDb
12219  *             void *cellInfo = CellGroupConfigRrc_t information which is send
12220  *                        by CU, which we have stored in F1UeContextSetupDb 
12221  *
12222  * @return void 
12223  *
12224  * ****************************************************************/
12225 uint8_t procUeReCfgCellInfo(MacUeCfg *macUeCfgToSend, MacUeCfg *storedMacUeCfg, void *cellInfo)
12226 {
12227    uint8_t ret = ROK;
12228    CellGroupConfigRrc_t *cellGrp = NULLP;
12229
12230    if(cellInfo)
12231    {
12232       cellGrp = (CellGroupConfigRrc_t *)cellInfo;
12233       ret = extractUeReCfgCellInfo(cellGrp, macUeCfgToSend, storedMacUeCfg);
12234       if(ret == RFAILED)
12235          DU_LOG("\nERROR  -->  F1AP : Failed at procUeReCfgCellInfo()");
12236    }
12237    if(ret == RFAILED)
12238    {
12239       freeUeReCfgCellGrpInfo(macUeCfgToSend);
12240    }
12241    return ret;
12242 }
12243
12244 /*******************************************************************
12245  *
12246  * @brief Filling modulation info in mac ue cfg
12247  *
12248  * @details
12249  *
12250  *    Function : duFillModulationDetails
12251  *
12252  *    Functionality: Filling modulation info in mac ue cfg
12253  *
12254  * @params[in] MAC UE Config to be updated
12255  *             Current UE configuration
12256  *             UE NR capability from CU
12257  * @return ROK     - success
12258  *         RFAILED - failure
12259  *
12260  * ****************************************************************/
12261 void duFillModulationDetails(MacUeCfg *ueCfg, MacUeCfg *oldUeCfg, void *ueCap)
12262 {
12263    UE_NR_Capability_t *ueNrCap=NULLP;
12264
12265    if(!ueCap && oldUeCfg)
12266    {
12267       memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));     
12268       memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12269    }
12270    else
12271    {
12272       ueNrCap = (UE_NR_Capability_t *)ueCap;
12273
12274       /* Filling DL modulation info */
12275       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsDownlinkPerCC && \
12276          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0] && \
12277          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL)
12278       {
12279          switch(*(ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL))
12280          {
12281             case ModulationOrder_qpsk:
12282                {
12283                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
12284                   break;
12285                }
12286             case ModulationOrder_qam16:
12287                {
12288                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM16;
12289                   break;
12290                }
12291             case ModulationOrder_qam64:
12292                {
12293                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM64;
12294                   ueCfg->dlModInfo.mcsIndex = PDSCH_MCS_INDEX;
12295                   ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64;
12296                   break;
12297                }
12298             case ModulationOrder_qam256:
12299                {
12300                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM256;
12301                   break;
12302                }
12303             default:
12304                {
12305                   DU_LOG("\nERROR  -->  DU APP: Incorrect downlink modulation order received. Reatining old modulation configuration");
12306                   if(oldUeCfg)
12307                      memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
12308                   break;
12309                }
12310          }
12311       }
12312       else
12313       {
12314          if(oldUeCfg)
12315             memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
12316       }
12317
12318       /* Filling UL modulation info */
12319       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsUplinkPerCC && \
12320          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0] && \
12321          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL)
12322       {
12323          switch(*(ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL))
12324          {
12325             case ModulationOrder_qpsk:
12326                {
12327                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
12328                   break;
12329                }
12330             case ModulationOrder_qam16:
12331                {
12332                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM16;
12333                   ueCfg->ulModInfo.mcsIndex = PUSCH_MCS_INDEX;
12334                   ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64;
12335                   break;
12336                }
12337             case ModulationOrder_qam64:
12338                {
12339                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM64;
12340                   break;
12341                }
12342             case ModulationOrder_qam256:
12343                {
12344                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM256;
12345                   break;
12346                }
12347             default:
12348                {
12349                   DU_LOG("\nERROR  -->  DU APP: Incorrect uplink modulation order received. Reatining old modulation configuration");
12350                   if(oldUeCfg)
12351                      memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12352                   break;
12353                }
12354          }
12355       }
12356       else
12357       {
12358          if(oldUeCfg)
12359             memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12360       }
12361    }
12362 }
12363
12364 /*******************************************************************
12365  *
12366  * @brief Function to extract info from CU to DU RRC container extension
12367  *
12368  * @details
12369  *
12370  *    Function : extractCuToDuRrcInfoExt
12371  *
12372  *    Functionality: Function to extract info from CU to DU RRC container
12373  *    extension
12374  *
12375  * @params[in] ProtocolExtensionContainer_4624P16_t pointer
12376  *
12377  * @return ROK
12378  *         RFAILED
12379  *
12380  * ****************************************************************/
12381 uint8_t extractCuToDuRrcInfoExt(ProtocolExtensionContainer_4624P16_t *protocolIeExtn, DuUeCfg *ueCfgDb)
12382 {
12383    uint8_t ieIdx =0;
12384    uint16_t recvBufLen =0;
12385    CellGroupConfigRrc_t *cellGrpCfg = NULLP;
12386    CUtoDURRCInformation_ExtIEs_t *extIeInfo = NULLP;
12387    asn_dec_rval_t rval; /* Decoder return value */
12388    memset(&rval, 0, sizeof(asn_dec_rval_t));
12389
12390    if(protocolIeExtn)
12391    {
12392       for(ieIdx = 0; ieIdx < protocolIeExtn->list.count; ieIdx++)
12393       {
12394          extIeInfo = ((CUtoDURRCInformation_ExtIEs_t *)(protocolIeExtn->list.array[ieIdx]));
12395          switch(extIeInfo->id)
12396          {
12397             case ProtocolIE_ID_id_CellGroupConfig:
12398                {
12399                   /* decoding the CellGroup Buf received */
12400                   recvBufLen = extIeInfo->extensionValue.choice.CellGroupConfig.size;
12401                   DU_ALLOC(cellGrpCfg, sizeof(CellGroupConfigRrc_t));
12402                   if(cellGrpCfg)
12403                   {
12404                      memset(cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
12405                      rval = aper_decode(0, &asn_DEF_CellGroupConfigRrc, (void **)&cellGrpCfg,
12406                            extIeInfo->extensionValue.choice.CellGroupConfig.buf, recvBufLen, 0, 0);
12407                      if(rval.code == RC_FAIL || rval.code == RC_WMORE)
12408                      {
12409                         DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
12410                         return RFAILED;
12411                      }
12412                      xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, cellGrpCfg);
12413
12414                      if(extractRlcCfgToAddMod(cellGrpCfg->rlc_BearerToAddModList, ueCfgDb))
12415                         return NULLP;
12416                      ueCfgDb->cellGrpCfg = cellGrpCfg;
12417                   }
12418                   break;
12419                }
12420
12421             case ProtocolIE_ID_id_HandoverPreparationInformation:
12422                {
12423                   DU_LOG("\nINFO -->  F1AP : Received HANDOVER PREPARATION INFO in UE CONTEXT SETUP REQUEST");
12424                   break;
12425                }
12426
12427             default:
12428                DU_LOG("\nERROR  -->  F1AP : Invalid IE received CUtoDURRCInformation: %ld at decodeCellGrpCfg()", extIeInfo->id);
12429                break;
12430          }
12431       }
12432    }
12433    return ROK;
12434 }
12435
12436 /*******************************************************************
12437  *
12438  * @brief Fills Srb List received by CU
12439  *
12440  * @details
12441  *
12442  *    Function : procSrbListToSetup
12443  *
12444  *    Functionality: Fills Srb List received  by CU
12445  *
12446  * @params[in] SRBs_ToBeSetup_Item_t *cuSrbItem
12447  *             LcCfg pointer
12448  *             RlcBearerCfg pointer
12449  * @return void
12450  *
12451  * ****************************************************************/
12452 uint8_t procSrbListToSetup(SRBs_ToBeSetup_Item_t * srbItem, LcCfg *macLcToAdd, RlcBearerCfg *rlcLcToAdd)
12453 {
12454
12455    /* Filling RLC INFO */
12456    procRlcLcCfg(srbItem->sRBID, srbItem->sRBID, RB_TYPE_SRB, RLC_AM, CONFIG_ADD, NULL, rlcLcToAdd, NULL);
12457
12458    /* Filling MAC INFO */
12459    if(procMacLcCfg(srbItem->sRBID, RB_TYPE_SRB, CONFIG_ADD, NULL,NULL, NULL, NULL, macLcToAdd, NULL)  != ROK)
12460    { 
12461       DU_LOG("\nERROR  -->  F1AP : Failed at MAC LC Cfg in procSrbListToSetup()");
12462       return RFAILED;
12463    }
12464
12465    return ROK;
12466 }
12467
12468
12469
12470 /*******************************************************************
12471  *
12472  * @brief extract Srb List received by CU
12473  *
12474  * @details
12475  *
12476  *    Function : extractSrbListToSetup
12477  *
12478  *    Functionality: extract Srb List received by CU
12479  *                   for both MAC and RLC
12480  *
12481  * @params[in] SRBs_ToBeSetup_Item_t pointer
12482  *             DuUeCfg pointer
12483  * @return ROK/RFAIED
12484  *
12485  * ****************************************************************/
12486
12487 uint8_t extractSrbListToSetup(SRBs_ToBeSetup_List_t *srbCfg, DuUeCfg *ueCfgDb)
12488 {
12489    uint8_t ret = ROK, srbIdx = 0, rlcLcIdx = 0;
12490    SRBs_ToBeSetup_Item_t *srbItem = NULLP;
12491    LcCfg *macLcCtxt = NULLP;
12492    RlcBearerCfg *rlcLcCtxt = NULLP;
12493
12494    if(srbCfg)
12495    {
12496       for(srbIdx = 0; srbIdx < srbCfg->list.count; srbIdx++)
12497       {
12498          macLcCtxt = NULL;
12499          rlcLcCtxt = NULL;
12500
12501          srbItem = &srbCfg->list.array[srbIdx]->value.choice.SRBs_ToBeSetup_Item;
12502          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
12503          { 
12504             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in MAC");
12505             ret = RFAILED;
12506             break;
12507          }
12508          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
12509          {
12510             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in RLC");
12511             ret = RFAILED;
12512             break;
12513          }
12514
12515          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numMacLcs; rlcLcIdx++)
12516          {
12517             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rbId == srbItem->sRBID && ueCfgDb->rlcLcCfg[rlcLcIdx].rbType == RB_TYPE_SRB)
12518             {
12519                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
12520                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
12521                break;
12522             }
12523          }
12524          if(!macLcCtxt)
12525          {
12526             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(LcCfg));
12527             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
12528             ueCfgDb->numMacLcs++;
12529          }
12530          if(!rlcLcCtxt)
12531          {
12532             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
12533             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
12534             ueCfgDb->numRlcLcs++;
12535          }
12536
12537          ret = procSrbListToSetup(srbItem, macLcCtxt, rlcLcCtxt);
12538
12539          DU_LOG("\nDEBUG --> DUAPP: extractSrbListToSetup: SRBID: %ld [RLC,MAC,NumDrb]:[%x,%x,%x]",\
12540                srbItem->sRBID, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
12541          if(ret == RFAILED)
12542          {
12543             DU_LOG("\nERROR  -->  F1AP:  Failed at extractSrbListToSetup()");
12544             break;
12545          }
12546       }
12547    }
12548    else
12549       ret = RFAILED;
12550
12551    return ret;
12552 }
12553
12554 /*******************************************************************
12555  *
12556  * @brief Fills Drb List received by CU
12557  *
12558  * @details
12559  *
12560  *    Function : procDrbListToSetupMod
12561  *
12562  *    Functionality: Fills Drb List received by CU
12563  *                   for both MAC and RLC
12564  *
12565  * @params[in] DRBs_ToBeSetup_Item_t , DRBs_ToBeSetupMod_Item_t,
12566  *             DRBs_ToBeModified_Item_t , lcId, LcCfg pointer,
12567  *             RlcBearerCfg , UpTnlCfg, RlcUeCfg
12568  * @return void
12569  *
12570  * ****************************************************************/
12571
12572 uint8_t procDrbListToSetupMod(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbItem,\
12573 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LcCfg *macLcToAdd, RlcBearerCfg *rlcLcToAdd, UpTnlCfg *upTnlInfo, RlcUeCfg *storedRlcUeCfg)
12574 {
12575    uint8_t cfgIdx = 0;
12576    RlcMode rlcModeInfo;
12577
12578    if(drbItem != NULLP)
12579    {
12580       /* Filling RLC INFO */
12581       procRlcLcCfg(drbItem->dRBID, lcId, RB_TYPE_DRB, drbItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, &drbItem->\
12582       qoSInformation);
12583
12584       /* Filling MAC INFO */
12585       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, drbItem, NULL, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
12586       { 
12587          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
12588          return RFAILED;
12589       }
12590    }
12591    else if(drbSetupModItem != NULLP)
12592    {
12593       procRlcLcCfg(drbSetupModItem->dRBID, lcId, RB_TYPE_DRB, drbSetupModItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, 
12594       &drbSetupModItem->qoSInformation);
12595
12596       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, NULL, drbSetupModItem, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
12597       {
12598          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
12599          return RFAILED;
12600       }
12601    }
12602    else if(drbModItem != NULLP)
12603    {
12604       /* Drb to Mod IEs doesnot have rlcMode to be modified
12605        * in ASN. Hence no change in RLC configurations */
12606       if(storedRlcUeCfg != NULLP)
12607       {
12608          for(cfgIdx = 0; cfgIdx < storedRlcUeCfg->numLcs; cfgIdx++)
12609          {
12610             if(storedRlcUeCfg->rlcLcCfg[cfgIdx].lcId == lcId)
12611             {
12612                rlcModeInfo = storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcMode;
12613                break;
12614             }
12615          }
12616       }
12617
12618       procRlcLcCfg(drbModItem->dRBID, lcId, RB_TYPE_DRB, rlcModeInfo, CONFIG_MOD, NULL, rlcLcToAdd, drbModItem->qoSInformation);
12619       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_MOD, NULL, NULL, drbModItem, NULL, macLcToAdd, upTnlInfo) != ROK)
12620       {
12621          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
12622          return RFAILED;
12623       }
12624    }
12625    return ROK;
12626 }
12627
12628 /*******************************************************************
12629  *
12630  * @brief extract Drb List received by CU
12631  *
12632  * @details
12633  *
12634  *    Function : extractDrbListToSetupMod
12635  *
12636  *    Functionality: extract Drb List received by CU
12637  *                   for both MAC and RLC
12638  *
12639  * @params[in] DRBs_ToBeSetup_Item_t pointer
12640  *             DuUeCfg pointer
12641  * @return ROK/RFAIED
12642  *
12643  * ****************************************************************/
12644
12645 uint8_t extractDrbListToSetupMod(DRBs_ToBeSetup_List_t *drbCfg, DRBs_ToBeSetupMod_List_t *drbSetupModCfg,\
12646  DRBs_ToBeModified_List_t *drbModCfg, uint8_t drbCount, DuUeCfg *ueCfgDb, uint32_t *drbBitMap, RlcUeCfg *rlcUeCfg)
12647 {
12648    uint8_t ret = ROK;
12649    uint8_t drbIdx = 0, rlcLcIdx = 0;
12650    uint8_t drbId = 0, lcId = 0;
12651    DRBs_ToBeSetup_Item_t *drbItem = NULLP;
12652    DRBs_ToBeSetupMod_ItemIEs_t *drbSetupModItem = NULLP;
12653    DRBs_ToBeModified_ItemIEs_t *drbModItem = NULLP;
12654    LcCfg *macLcCtxt = NULLP;
12655    RlcBearerCfg *rlcLcCtxt = NULLP;
12656
12657    ret = ROK;
12658    if(drbCount > 0)
12659    {
12660       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
12661       {
12662          macLcCtxt = NULL;
12663          rlcLcCtxt = NULL;
12664
12665          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
12666          { 
12667             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in MAC at extractDrbListToSetupMod()");
12668             ret = RFAILED;
12669             break;
12670          }
12671          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
12672          {
12673             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in RLC at extractDrbListToSetupMod()");
12674             ret = RFAILED;
12675             break;
12676          }
12677
12678          if(drbModCfg != NULLP)
12679          {
12680             drbModItem = (DRBs_ToBeModified_ItemIEs_t *) drbModCfg->list.array[drbIdx];
12681             drbId = drbModItem->value.choice.DRBs_ToBeModified_Item.dRBID;
12682          }
12683          else if(drbCfg != NULLP)
12684             drbId = drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item.dRBID;
12685          else if(drbSetupModCfg != NULL)
12686          {
12687             drbSetupModItem = (DRBs_ToBeSetupMod_ItemIEs_t *) drbSetupModCfg->list.array[drbIdx];
12688             drbId = drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item.dRBID;
12689          }
12690
12691          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
12692          {
12693             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rbId == drbId && ueCfgDb->rlcLcCfg[rlcLcIdx].rbType == RB_TYPE_DRB)
12694             {
12695                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
12696                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
12697                break;
12698             }
12699          }
12700          if(!macLcCtxt)
12701          {
12702             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(LcCfg));
12703             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
12704             ueCfgDb->numMacLcs++;
12705          }
12706          if(!rlcLcCtxt)
12707          {
12708             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
12709             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
12710             ueCfgDb->numRlcLcs++;
12711          }
12712
12713          if(drbModCfg != NULLP)
12714          {
12715             lcId = fetchLcId(drbId);
12716             if(lcId < MIN_DRB_LCID)
12717             {
12718                DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToSetupMod() for Modified List", lcId);
12719                break;
12720             } 
12721             ret = procDrbListToSetupMod(lcId, NULL, NULL, &(drbModItem->value.choice.DRBs_ToBeModified_Item),\
12722             macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
12723             if(ret == RFAILED)
12724             {
12725                DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for Modified List");
12726                break;
12727             }
12728          }
12729          else
12730          {
12731             lcId = getDrbLcId(drbBitMap);
12732             if(lcId == RFAILED)
12733             {
12734                DU_LOG("\nERROR  -->  F1AP :  InCorrect LCID extractDrbListToSetupMod()");
12735                ret = RFAILED;
12736                break;
12737             }
12738             if(drbCfg != NULL)
12739             {
12740                drbItem = &drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12741                ret = procDrbListToSetupMod(lcId, drbItem, NULL, NULL, macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
12742                if(ret == RFAILED)
12743                {
12744                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetup List");
12745                   break;
12746                }
12747             }
12748             else if(drbSetupModCfg != NULL)
12749             {
12750                ret = procDrbListToSetupMod(lcId, NULL, &(drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item), NULL,\
12751                      macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
12752                if(ret == RFAILED)
12753                {
12754                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetupMod List");
12755                   break;
12756                }
12757                ueCfgDb->numDrbSetupMod++;
12758             }
12759          }
12760          ueCfgDb->numDrb++;
12761  
12762          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToSetupMod:lcId:%x ,BitMap:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
12763                             lcId,*drbBitMap, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
12764          if(ret == RFAILED)
12765          {
12766             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod()");
12767             break;
12768          }
12769       }
12770    }
12771    else
12772       ret = RFAILED;
12773
12774    return ret;
12775 }
12776
12777 /*******************************************************************
12778  *
12779  * @brief Function to extract Dl RRC Msg received from CU
12780  *
12781  * @details
12782  *
12783  *    Function : extractDlRrcMsg
12784  *
12785  *    Functionality: Function to extract Dl RRC Msg received from CU
12786  *
12787  * @params[in] F1AP message
12788  * @return ROK     - success
12789  *         RFAILED - failure
12790  *
12791  * ****************************************************************/
12792
12793 uint8_t extractDlRrcMsg(uint32_t gnbDuUeF1apId, uint32_t gnbCuUeF1apId, \
12794    F1DlRrcMsg *dlRrcMsg, RRCContainer_t *rrcContainer)
12795 {
12796    uint8_t ret = ROK;
12797    dlRrcMsg->rrcMsgSize = rrcContainer->size;
12798    if(dlRrcMsg->rrcMsgSize > 0)
12799    {
12800       DU_ALLOC_SHRABL_BUF(dlRrcMsg->rrcMsgPdu, dlRrcMsg->rrcMsgSize);
12801       if(!dlRrcMsg->rrcMsgPdu)
12802       {
12803          DU_LOG("\nERROR  --> DU APP : Memory allocation failed for RRC Msg in extractDlRrcMsg()");
12804          ret = RFAILED;
12805       }
12806       else
12807       {
12808          dlRrcMsg->gnbDuUeF1apId = gnbDuUeF1apId;
12809          dlRrcMsg->gnbCuUeF1apId = gnbCuUeF1apId;
12810          dlRrcMsg->srbId = SRB1_LCID;
12811          memcpy(dlRrcMsg->rrcMsgPdu, rrcContainer->buf, dlRrcMsg->rrcMsgSize);
12812       }
12813    }
12814    return ret;
12815 }
12816
12817 /*******************************************************************
12818  *
12819  * @brief Extract UE capability info 
12820  *
12821  * @details
12822  *
12823  *    Function : extractUeCapability
12824  *
12825  *    Functionality: Extract UE capability info and stores in ue Cb
12826  *
12827  * @params[in] Octet string of UE capability RAT container list
12828  * @return ROK     - success
12829  *         RFAILED - failure
12830  *
12831  * ****************************************************************/
12832 UE_NR_Capability_t *extractUeCapability(UE_CapabilityRAT_ContainerList_t *ueCapablityListBuf, DuUeCb *ueCb)
12833 {
12834    uint8_t  idx;
12835    uint16_t recvBufLen;
12836    asn_dec_rval_t rval;
12837    UE_NR_Capability_t  *ueNrCap = NULLP;
12838    UE_CapabilityRAT_ContainerListRRC_t  *ueCapRatContList = NULLP;
12839
12840    /* Decoding UE Capability RAT Container List */
12841    recvBufLen = ueCapablityListBuf->size;
12842    DU_ALLOC(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
12843    if(!ueCapRatContList)
12844    {
12845       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
12846       return NULLP;
12847    }
12848    memset(ueCapRatContList, 0, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
12849    memset(&rval, 0, sizeof(asn_dec_rval_t));
12850    rval = aper_decode(0, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, (void **)&ueCapRatContList,
12851           ueCapablityListBuf->buf, recvBufLen, 0, 0);
12852    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
12853    {
12854       DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
12855       return NULLP;
12856    }
12857    xer_fprint(stdout, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, ueCapRatContList);
12858
12859    /* Free encoded buffer after decoding */
12860
12861    for(idx = 0; idx < ueCapRatContList->list.count; idx++)
12862    {
12863       if(ueCapRatContList->list.array[idx]->rat_Type == RAT_Type_nr)
12864       {
12865          /* Decoding UE NR Capability */
12866           recvBufLen = ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.size;
12867           DU_ALLOC(ueNrCap, sizeof(UE_NR_Capability_t));
12868           if(!ueNrCap)
12869           {
12870              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
12871              DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
12872              return NULLP;
12873           } 
12874           memset(ueNrCap, 0, sizeof(UE_NR_Capability_t));
12875           memset(&rval, 0, sizeof(asn_dec_rval_t));
12876           rval = aper_decode(0, &asn_DEF_UE_NR_Capability, (void **)&ueNrCap,
12877                  ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf, recvBufLen, 0, 0);
12878           if(rval.code == RC_FAIL || rval.code == RC_WMORE)
12879           {
12880              DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
12881              return NULLP;
12882           }
12883           xer_fprint(stdout, &asn_DEF_UE_NR_Capability, ueNrCap);
12884           
12885           /* Free encoded buffer after decoding */
12886           free(ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf);
12887       }
12888       free(ueCapRatContList->list.array[idx]);
12889    }
12890
12891    /* Free Memory*/
12892    free(ueCapRatContList->list.array);
12893    DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
12894    return ueNrCap;
12895 }
12896  
12897 /*******************************************************************
12898 *
12899 * @brief free UE context setup request from CU
12900 *
12901 * @details
12902 *
12903 *    Function : freeAperDecodeF1UeContextSetupReq
12904 *
12905 *    Functionality: freeing part for the memory allocated by aper_decoder
12906 *
12907 * @params[in] F1AP message
12908 * @return ROK     - success
12909 *         RFAILED - failure
12910 *
12911 * ****************************************************************/
12912 void freeAperDecodeF1UeContextSetupReq(UEContextSetupRequest_t   *ueSetReq)
12913 {
12914    uint8_t ieIdx = 0;
12915
12916    if(ueSetReq->protocolIEs.list.array != NULLP)
12917    {
12918       for(ieIdx = 0; ieIdx < ueSetReq->protocolIEs.list.count; ieIdx++)
12919       {
12920          if(ueSetReq->protocolIEs.list.array[ieIdx])
12921          {
12922             switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
12923             {
12924                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
12925                   break;
12926                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
12927                   break;
12928                case ProtocolIE_ID_id_SpCell_ID:
12929                   freeAperDecodeNrcgi(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
12930                   break;
12931                case ProtocolIE_ID_id_ServCellIndex:
12932                   break;
12933                case ProtocolIE_ID_id_SpCellULConfigured:
12934                   break;
12935                case ProtocolIE_ID_id_CUtoDURRCInformation:
12936
12937                   freeAperDecodeCuToDuInfo(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation);
12938                   break;
12939                case ProtocolIE_ID_id_SCell_ToBeSetup_List:
12940
12941                   freeAperDecodeSplCellList(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SCell_ToBeSetup_List);
12942                   break;
12943                case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
12944
12945                   freeAperDecodeSRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List);
12946                   break;
12947                case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
12948
12949                   freeAperDecodeDRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List);
12950                   break;
12951                case ProtocolIE_ID_id_RRCContainer:
12952                   {
12953
12954                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf != NULLP)
12955                      {
12956
12957                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
12958                      }
12959                      break;
12960                   }
12961                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
12962                   break;
12963                case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
12964                   {
12965                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf)
12966                      {
12967                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf);
12968                      }
12969                      break;
12970                   }
12971                default:
12972                   DU_LOG("\nERROR  -->  F1AP: Invalid event type %ld " ,ueSetReq->protocolIEs.list.array[ieIdx]->id);
12973             } 
12974             free(ueSetReq->protocolIEs.list.array[ieIdx]);
12975          }
12976       }
12977       free(ueSetReq->protocolIEs.list.array);
12978    }
12979 }
12980 /*******************************************************************
12981  *
12982  * @brief Process UE context setup request from CU
12983  *
12984  * @details
12985  *
12986  *    Function : procF1UeContextSetupReq
12987  *
12988  *    Functionality: Process UE context setup request from CU
12989  *
12990  * @params[in] F1AP message
12991  * @return ROK     - success
12992  *         RFAILED - failure
12993  *
12994  * ****************************************************************/
12995 uint8_t procF1UeContextSetupReq(F1AP_PDU_t *f1apMsg)
12996 {
12997    int8_t ueIdx = -1;
12998    uint8_t  ret=0, ieIdx=0, ieExtIdx = 0, servCellIdx = 0;
12999    bool ueCbFound = false, hoInProgress = false;
13000    uint16_t cellIdx=0;
13001    uint64_t nrCellId = 0;
13002    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0, bitRateSize=0;
13003    DuUeCb   *duUeCb = NULL;
13004    UEContextSetupRequest_t   *ueSetReq = NULL;
13005    DRBs_ToBeSetup_List_t *drbCfg = NULL;
13006    CUtoDURRCInformation_t *rrcInfo = NULL;
13007
13008    ret = ROK;
13009
13010    ueSetReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextSetupRequest;
13011    for(ieIdx=0; (ieIdx < ueSetReq->protocolIEs.list.count && ret == ROK); ieIdx++)
13012    {
13013       switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13014       {
13015          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13016             {
13017                gnbCuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
13018                break;
13019             }
13020
13021          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13022             {
13023                gnbDuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
13024                break;
13025             }
13026
13027          case ProtocolIE_ID_id_SpCell_ID:
13028             {
13029                bitStringToInt(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity, &nrCellId);
13030
13031                GET_CELL_IDX(nrCellId, cellIdx);
13032                if(!duCb.actvCellLst[cellIdx])
13033                {
13034                   DU_LOG("\nERROR  -->  F1AP : Cell Id [%d] not found", nrCellId);
13035                   ret = RFAILED;
13036                }
13037                break;
13038             }
13039
13040          case ProtocolIE_ID_id_ServCellIndex:
13041             {
13042                servCellIdx = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.ServCellIndex;
13043                break;
13044             }
13045
13046          case ProtocolIE_ID_id_SpCellULConfigured:
13047             {
13048                /* Indicates whether the gNB-CU requests the gNB-DU to configure the uplink as no UL, 
13049                   UL, SUL or UL+SUL for the indicated cell for the UE */
13050                break;
13051             }
13052
13053          case ProtocolIE_ID_id_CUtoDURRCInformation:
13054             {
13055                rrcInfo = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation;
13056
13057                /* Search if UE context is present */
13058                for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
13059                {
13060                   if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId)
13061                   {
13062                      ueCbFound = true;
13063                      duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13064                      break;
13065                   }
13066                }
13067
13068                /* Check if UE Handover scenario */
13069                if(rrcInfo->iE_Extensions)
13070                {
13071                   for(ieExtIdx = 0; ieExtIdx < rrcInfo->iE_Extensions->list.count; ieExtIdx++)
13072                   {
13073                      if(rrcInfo->iE_Extensions->list.array[ieExtIdx]->id == ProtocolIE_ID_id_HandoverPreparationInformation)
13074                      {
13075                         hoInProgress = true;
13076                         break;
13077                      }
13078                   }
13079                }
13080                
13081                /* If UE context is not present, but UE is in handover */
13082                if(!ueCbFound && hoInProgress)
13083                {
13084                   ueIdx = getFreeBitFromUeBitMap(nrCellId);
13085                   if(ueIdx != -1)
13086                      gnbDuUeF1apId = ueIdx +1;
13087                   else
13088                   {
13089                      DU_LOG("\nERROR  -->  F1AP : No free UE IDX found in UE bit map of cell Id [%d]", nrCellId);
13090                      ret = RFAILED;
13091                      break;
13092                   }
13093                   duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13094                   duUeCb->f1UeDb = NULL;
13095                   duUeCb->gnbCuUeF1apId = gnbCuUeF1apId;
13096                   duUeCb->gnbDuUeF1apId = gnbDuUeF1apId;
13097                   GET_CRNTI(duUeCb->crnti, duUeCb->gnbDuUeF1apId);
13098                   duUeCb->ueState = UE_HANDIN_IN_PROGRESS;
13099                }
13100
13101                if(duUeCb)
13102                {
13103                   DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
13104                   if(duUeCb->f1UeDb)
13105                   {
13106                      memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
13107                      duUeCb->f1UeDb->actionType = UE_CTXT_SETUP;
13108                      duUeCb->f1UeDb->cellIdx = cellIdx;
13109                   }
13110                   else
13111                   {
13112                      DU_LOG("\nERROR  -->  F1AP: Memory Alloc Failed at procF1UeContextSetupReq()");
13113                      ret = RFAILED;
13114                      break;
13115                   }
13116                }
13117                else
13118                {
13119                   DU_LOG("\nERROR  -->  F1AP: DuUeCb is not found at procF1UeContextSetupReq()");
13120                   ret = RFAILED;
13121                   break;
13122                }
13123                  
13124                /* Extract UE capability info */
13125                if(rrcInfo->uE_CapabilityRAT_ContainerList)
13126                {
13127                   duUeCb->f1UeDb->duUeCfg.ueNrCapability = extractUeCapability(rrcInfo->uE_CapabilityRAT_ContainerList, duUeCb);
13128                }
13129
13130                /* Extract IE extension */
13131                if(rrcInfo->iE_Extensions)
13132                {
13133                   if(extractCuToDuRrcInfoExt(rrcInfo->iE_Extensions, &duUeCb->f1UeDb->duUeCfg) != ROK)
13134                   {
13135                      DU_LOG("\nERROR  -->  F1AP: Failed to extract CU to DU RRC information extension IE");
13136                      //TODO: Update the failure cause in ue context Setup Response
13137                      ret = RFAILED;
13138                   }
13139                }
13140                break;
13141             } 
13142
13143          case ProtocolIE_ID_id_SCell_ToBeSetup_List:
13144             {
13145                DU_LOG("\nINFO   -->  DU_APP: Received SCell_ToBeSetup_List but  Not processing the list");
13146                break;
13147             }
13148
13149          case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
13150             {
13151                if(extractSrbListToSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List,\
13152                         &duUeCb->f1UeDb->duUeCfg))
13153                {
13154                   DU_LOG("\nERROR  -->  DU APP : Failed at extractSrbListToSetup()");
13155                   //TODO: Update the failure cause in ue context Setup Response
13156                   ret = RFAILED;
13157                }
13158                break;
13159             }
13160
13161          case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
13162             {
13163                drbCfg = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List;
13164
13165                if(extractDrbListToSetupMod(drbCfg, NULL, NULL, drbCfg->list.count, &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULLP))
13166                {
13167                   DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod()");
13168                   //TODO: Update the failure cause in ue context Setup Response
13169                   ret = RFAILED;
13170                }
13171                break;
13172             }
13173
13174          case ProtocolIE_ID_id_RRCContainer:
13175             {
13176                /* Filling Dl RRC Msg Info */
13177                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
13178                if(!duUeCb->f1UeDb->dlRrcMsg)
13179                {
13180                   DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for DL RRC Msg in procUeCtxtSetupReq()");
13181                   ret = RFAILED;
13182                }
13183                else
13184                {
13185                   duUeCb->f1UeDb->dlRrcMsgPres = true;
13186                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
13187                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
13188                         &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer);
13189                }          
13190                break;
13191             }
13192
13193          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13194             {
13195                if(duUeCb->f1UeDb->dlRrcMsg)
13196                {
13197                   if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
13198                   {
13199                      duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
13200                   }
13201                   else
13202                   {
13203                      DU_LOG("\nERROR  -->  Ignoring delivery report, since rrcContainer is not present");
13204                   }
13205                }
13206                break;
13207             }
13208
13209          case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
13210             {
13211                /* MaximumBitRate Uplink */
13212                bitRateSize = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.size;
13213                if(bitRateSize > 0)
13214                {
13215                   DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->duUeCfg.ambrCfg, bitRateSize);
13216                   if(!duUeCb->f1UeDb->duUeCfg.ambrCfg)
13217                   {
13218                      DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for bitRate in procUeCtxtSetupReq");
13219                      ret = RFAILED;
13220                   }
13221                   else
13222                   {
13223                      memset(duUeCb->f1UeDb->duUeCfg.ambrCfg, 0, sizeof(AmbrCfg)); 
13224                      memcpy(&duUeCb->f1UeDb->duUeCfg.ambrCfg->ulBr,
13225                            ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf, bitRateSize);
13226                   }
13227                }
13228                else
13229                   ret = RFAILED;
13230                break;
13231             }
13232
13233          default:
13234             {
13235                break;
13236             }
13237       } /* End of switch */
13238
13239       /* In case of any failure in any IE */
13240       if(ret == RFAILED)
13241       {
13242          // BuildAndSendUeContextSetupRsp(cellId,ueId);
13243          DU_LOG("\nERROR  -->  F1AP: Failed to process UE CNTXT SETUP REQ at procF1UeContextSetupReq()"); 
13244          break;
13245       }
13246    } /* End of for loop of IEs */
13247
13248    if(ret == ROK)
13249       ret = duProcUeContextSetupRequest(duUeCb);
13250
13251    freeAperDecodeF1UeContextSetupReq(ueSetReq); 
13252    return ret;
13253
13254 }
13255 /*******************************************************************
13256  * @brief Free the memory allocated for Dl Tunnel Info
13257  *
13258  * @details
13259  *
13260  *    Function : freeDlTnlInfo
13261  *
13262  *    Functionality:
13263  *       Free the memory allocated for Dl Tunnel Info
13264  *
13265  * @params[in] DLUPTNLInformation_ToBeSetup_List_t *
13266  * @return void
13267  *
13268  * ****************************************************************/
13269
13270 void freeDlTnlInfo(DLUPTNLInformation_ToBeSetup_List_t *tnlInfo)
13271 {
13272    uint8_t arrIdx = 0;
13273
13274    if(tnlInfo)
13275    {
13276       for(arrIdx=0; arrIdx < tnlInfo->list.count; arrIdx++)
13277       {
13278          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf,\
13279                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.size);
13280          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf,\
13281                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.size);
13282          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
13283          DU_FREE(tnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
13284       }
13285       DU_FREE(tnlInfo->list.array, tnlInfo->list.size);
13286    }
13287 }
13288
13289 /*******************************************************************
13290  * @brief Free the memory allocated for DRB setup List
13291  *
13292  * @details
13293  *
13294  *    Function : freeDrbSetupList
13295  *
13296  *    Functionality:
13297  *       Free the memory allocated for DRB setup list
13298  *
13299  * @params[in] DRBs_Setup_List_t *
13300  * @return void
13301  *
13302  * ****************************************************************/
13303 void freeDrbSetupList(DRBs_Setup_List_t *drbSetupList)
13304 {
13305    uint8_t arrIdx = 0;
13306    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
13307
13308    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
13309    {
13310       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
13311       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List);
13312       DU_FREE(drbSetupList->list.array[arrIdx],  sizeof(DRBs_Setup_Item_t));
13313    }
13314    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
13315 }
13316
13317 /*******************************************************************
13318  * @brief Free the memory allocated for UE Setup response
13319  *
13320  * @details
13321  *
13322  *    Function : FreeUeContextSetupRsp
13323  *
13324  *    Functionality:
13325  *       Free the memory allocated for UE Setup response
13326  *
13327  * @params[in] F1AP PDU for UE setup response
13328  * @return ROK     - success
13329  *         RFAILED - failure
13330  *
13331  * ****************************************************************/
13332 void FreeUeContextSetupRsp(F1AP_PDU_t *f1apMsg)
13333 {
13334    uint8_t idx;
13335    UEContextSetupResponse_t *ueSetRsp = NULLP;
13336
13337    if(f1apMsg)
13338    {
13339       if(f1apMsg->choice.successfulOutcome)
13340       {
13341          ueSetRsp = &f1apMsg->choice.successfulOutcome->value.choice.\
13342                     UEContextSetupResponse;
13343          if(ueSetRsp->protocolIEs.list.array)
13344          {
13345             for(idx = 0; idx < ueSetRsp->protocolIEs.list.count; idx++)
13346             {
13347                if(ueSetRsp->protocolIEs.list.array[idx])
13348                {
13349                   switch(ueSetRsp->protocolIEs.list.array[idx]->id)
13350                   {
13351                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13352                         break;
13353                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13354                         break;
13355                      case ProtocolIE_ID_id_DUtoCURRCInformation:
13356                         {
13357                            CellGroupConfig_t *cellGrpCfg = NULLP;
13358                            cellGrpCfg  = &ueSetRsp->protocolIEs.list.array[idx]->value.choice.\
13359                                          DUtoCURRCInformation.cellGroupConfig;
13360                            if(cellGrpCfg->buf != NULLP)
13361                            {
13362                               DU_FREE(cellGrpCfg->buf, cellGrpCfg->size);
13363                               cellGrpCfg = NULLP;
13364                            }
13365                            break;
13366                         }
13367                     case ProtocolIE_ID_id_DRBs_Setup_List:
13368                         {
13369                            freeDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List); 
13370                            break;
13371                         }
13372                      default:
13373                         DU_LOG("\nERROR  -->  DUAPP: Invalid Id %ld at FreeUeContextSetupRsp()",\
13374                         ueSetRsp->protocolIEs.list.array[idx]->id);
13375                         break;
13376                   }
13377                   DU_FREE(ueSetRsp->protocolIEs.list.array[idx],\
13378                         sizeof(UEContextSetupResponseIEs_t));
13379                }
13380             }
13381             DU_FREE(ueSetRsp->protocolIEs.list.array, \
13382                   ueSetRsp->protocolIEs.list.size);
13383          }
13384          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
13385       }
13386       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
13387    }
13388 }
13389
13390 /*******************************************************************
13391  *
13392  * @brief Builds Ue context Setup Rsp DU To CU Info
13393  *
13394  * @details
13395  *
13396  *    Function : EncodeUeCntxtDuToCuInfo
13397  *
13398  *    Functionality: Builds Ue context Setup Rsp DU To CU Info
13399  *
13400  * @params[in] CellGroupConfig_t *, CellGroupConfigRrc_t * 
13401  *
13402  * @return ROK     - success
13403  *         RFAILED - failure
13404  *
13405  ******************************************************************/
13406
13407 uint8_t EncodeUeCntxtDuToCuInfo(CellGroupConfig_t *duToCuCellGrp, CellGroupConfigRrc_t *duCellGrpCfg)
13408 {
13409    asn_enc_rval_t        encRetVal;
13410
13411    xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, duCellGrpCfg);
13412    memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
13413    encBufSize = 0;
13414    encRetVal = aper_encode(&asn_DEF_CellGroupConfigRrc, 0, duCellGrpCfg, PrepFinalEncBuf, encBuf);
13415    /* Encode results */
13416    if(encRetVal.encoded == ENCODE_FAIL)
13417    {
13418       DU_LOG( "\nERROR  -->  F1AP : Could not encode UeCntxtDuToCuInfo (at %s)\n",\
13419             encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
13420       return RFAILED;
13421    }
13422    else
13423    {
13424       DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UeCntxtDuToCuInfo\n");
13425       for(int i=0; i< encBufSize; i++)
13426       {
13427          printf("%x",encBuf[i]);
13428       }
13429    }
13430    duToCuCellGrp->size = encBufSize;
13431    DU_ALLOC(duToCuCellGrp->buf, duToCuCellGrp->size);
13432    if(!duToCuCellGrp->buf)
13433    {
13434       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in UeCntxtDuToCuInfo");
13435    }
13436    memcpy(duToCuCellGrp->buf, encBuf, duToCuCellGrp->size);
13437    return ROK;
13438 }
13439
13440 /*******************************************************************
13441  *
13442  * @brief Fills Dl Gtp tunnel Info
13443  *
13444  * @details
13445  *
13446  *    Function : fillGtpTunnelforDl
13447  *
13448  *    Functionality: Fills Dl Gtp tunnel Info
13449  *
13450  * @params[in] 
13451  *
13452  * @return ROK     - success
13453  *         RFAILED - failure
13454  *
13455  * ****************************************************************/
13456
13457 uint8_t fillGtpTunnelforDl(GTPTunnel_t *gtpDl, GtpTnlCfg *gtpUeCfg)
13458 {
13459    uint8_t bufSize = 0;
13460
13461    gtpDl->transportLayerAddress.size    = 4*sizeof(uint8_t);
13462    DU_ALLOC(gtpDl->transportLayerAddress.buf, gtpDl->transportLayerAddress.size);
13463    if(gtpDl->transportLayerAddress.buf == NULLP)
13464    {
13465       return RFAILED;
13466    }
13467    memcpy(gtpDl->transportLayerAddress.buf, &gtpUeCfg->dlTnlAddress, gtpDl->transportLayerAddress.size);
13468
13469    /*GTP TEID*/
13470    gtpDl->gTP_TEID.size = 4 * sizeof(uint8_t);
13471    DU_ALLOC(gtpDl->gTP_TEID.buf, gtpDl->gTP_TEID.size);
13472    if(gtpDl->gTP_TEID.buf == NULLP)
13473    {
13474       return RFAILED;
13475    }
13476    bufSize = 3; /*forming an Octect String*/
13477    fillTeIdString(bufSize, gtpUeCfg->teId, gtpDl->gTP_TEID.buf);
13478
13479    return ROK;
13480 }
13481
13482 /*******************************************************************
13483  *
13484  * @brief Fills DL Tunnel Setup List
13485  *
13486  * @details
13487  *
13488  *    Function : fillDlTnlSetupList
13489  *
13490  *    Functionality: Fills the DL Tunnel Setup List
13491  *
13492  * @params[in] 
13493  *
13494  * @return ROK     - success
13495  *         RFAILED - failure
13496  *
13497  * ****************************************************************/
13498
13499 uint8_t fillDlTnlSetupList(DLUPTNLInformation_ToBeSetup_List_t *dlTnlInfo, UpTnlCfg *tnlCfg)
13500 {
13501    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
13502
13503    eleCount = 1;
13504    dlTnlInfo->list.count = eleCount; 
13505    dlTnlInfo->list.size = (eleCount * sizeof(DLUPTNLInformation_ToBeSetup_Item_t *));
13506
13507    /* Initialize the DL Tnl Setup List Members */
13508    DU_ALLOC(dlTnlInfo->list.array, dlTnlInfo->list.size);
13509    if(dlTnlInfo->list.array == NULLP)
13510    {
13511       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL Tnl Setup List in fillDlTnlSetupList()");
13512       ret = RFAILED;
13513    }
13514    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
13515    {
13516       DU_ALLOC(dlTnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
13517       if(dlTnlInfo->list.array[arrIdx] == NULLP)
13518       {
13519          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDlTnlSetupList()", arrIdx);
13520          return RFAILED;
13521       }
13522       dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.present = UPTransportLayerInformation_PR_gTPTunnel;
13523       DU_ALLOC(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
13524       if(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel == NULLP)
13525       {
13526          DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL tunnel info in fillDlTnlSetupList()");
13527          return RFAILED;
13528       }
13529       ret = fillGtpTunnelforDl(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel,\
13530                tnlCfg->tnlCfg1);
13531       if(ret != ROK)
13532          break;
13533    }
13534    return ret;
13535 }
13536
13537 /*******************************************************************
13538  *
13539  * @brief Fills the Drb Setup List for Ue Context Setup Response
13540  *
13541  * @details
13542  *
13543  *    Function : fillDrbSetupList
13544  *
13545  *    Functionality: Fills the Drb Setup List for Ue Context Setup Response
13546  *
13547  * @params[in] 
13548  *
13549  * @return ROK     - success
13550  *         RFAILED - failure
13551  *
13552  * ****************************************************************/
13553 uint8_t fillDrbSetupList(DRBs_Setup_List_t *drbSetupList, DuUeCfg *ueCfg)
13554 {
13555    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
13556    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
13557
13558    eleCount = ueCfg->numDrb;
13559    drbSetupList->list.count = eleCount;
13560    drbSetupList->list.size = \
13561         (eleCount * sizeof(DRBs_Setup_Item_t *));
13562
13563    /* Initialize the Drb Setup List Members */
13564    DU_ALLOC(drbSetupList->list.array, drbSetupList->list.size);
13565    if(drbSetupList->list.array == NULLP)
13566    {
13567       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DRB Setup List in fillDrbSetupList()");
13568       ret = RFAILED;
13569    }
13570
13571    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
13572    {
13573       DU_ALLOC(drbSetupList->list.array[arrIdx], sizeof(DRBs_Setup_Item_t));
13574       if(drbSetupList->list.array[arrIdx] == NULLP)
13575       {
13576          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDrbSetupList()", arrIdx);
13577          return RFAILED;
13578       }
13579       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
13580       drbItemIe->id = ProtocolIE_ID_id_DRBs_Setup_Item;
13581       drbItemIe->criticality = Criticality_reject;
13582       drbItemIe->value.present = DRBs_Setup_ItemIEs__value_PR_DRBs_Setup_Item;
13583       drbItemIe->value.choice.DRBs_Setup_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
13584       ret = fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List,\
13585           &ueCfg->upTnlInfo[arrIdx]);
13586       if(ret != ROK)
13587          break;
13588    }
13589    return ret;
13590 }
13591
13592 /*******************************************************************
13593  *
13594  * @brief Builds and sends the UE Setup Response
13595  *
13596  * @details
13597  *
13598  *    Function : BuildAndSendUeContextSetupRsp
13599  *
13600  *    Functionality: Constructs the UE Setup Response and sends
13601  *                   it to the DU through SCTP.
13602  *
13603  * @params[in] uint8_t cellId,uint8_t ueId
13604  *
13605  * @return ROK     - success
13606  *         RFAILED - failure
13607  *
13608  * ****************************************************************/
13609 uint8_t BuildAndSendUeContextSetupRsp(uint8_t cellId,uint8_t ueId)
13610 {
13611    uint8_t   idx, ret, cellIdx, elementCnt;
13612    uint32_t  gnbCuUeF1apId;   /* gNB-CU UE F1AP Id */
13613    uint32_t  gnbDuUeF1apId;   /* gNB-DU UE F1AP Id */
13614    asn_enc_rval_t  encRetVal;        /* Encoder return value */
13615    F1AP_PDU_t               *f1apMsg = NULLP;
13616    UEContextSetupResponse_t *ueSetRsp = NULLP;
13617    DuUeCb                   *ueCb = NULLP;
13618
13619    DU_LOG("\n INFO   -->  F1AP : Building UE Context Setup Response for cellId %d, ueId %d\n", cellId, ueId);
13620
13621    while(true)
13622    {
13623       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
13624       if(f1apMsg == NULLP)
13625       {
13626          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
13627          ret = RFAILED;
13628          break;
13629       }
13630
13631       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
13632       DU_ALLOC(f1apMsg->choice.successfulOutcome,
13633             sizeof(SuccessfulOutcome_t));
13634       if(f1apMsg->choice.successfulOutcome == NULLP)
13635       {
13636          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
13637          ret = RFAILED;
13638          break;
13639       }
13640
13641       f1apMsg->choice.successfulOutcome->procedureCode = \
13642                                                          ProcedureCode_id_UEContextSetup;
13643       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
13644       f1apMsg->choice.successfulOutcome->value.present = \
13645                                                          SuccessfulOutcome__value_PR_UEContextSetupResponse;
13646
13647       ueSetRsp =
13648          &f1apMsg->choice.successfulOutcome->value.choice.UEContextSetupResponse;
13649       elementCnt = 5;
13650       ueSetRsp->protocolIEs.list.count = elementCnt;
13651       ueSetRsp->protocolIEs.list.size = \
13652                                         elementCnt * sizeof(UEContextSetupResponse_t *);
13653
13654       /* Initialize the UESetup members */
13655       DU_ALLOC(ueSetRsp->protocolIEs.list.array, \
13656             ueSetRsp->protocolIEs.list.size);
13657       if(ueSetRsp->protocolIEs.list.array == NULLP)
13658       {
13659          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
13660          ret = RFAILED;
13661          break;
13662       }
13663
13664       for(idx=0; idx<elementCnt; idx++)
13665       {
13666          DU_ALLOC(ueSetRsp->protocolIEs.list.array[idx],\
13667                sizeof(UEContextSetupResponseIEs_t));
13668          if(ueSetRsp->protocolIEs.list.array[idx] == NULLP)
13669          {
13670             DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
13671             ret = RFAILED;
13672             break;
13673          }
13674       }
13675       /* Fetching Ue Cb Info*/
13676       GET_CELL_IDX(cellId, cellIdx);
13677       gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
13678       gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
13679       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
13680
13681       idx = 0;
13682       /*GNB CU UE F1AP ID*/
13683       ueSetRsp->protocolIEs.list.array[idx]->id = \
13684                                                   ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
13685       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13686       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
13687                                                              UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
13688       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
13689
13690       /*GNB DU UE F1AP ID*/
13691       idx++;
13692       ueSetRsp->protocolIEs.list.array[idx]->id = \
13693                                                   ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
13694       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13695       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
13696                                                              UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
13697       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
13698
13699
13700       /*DUtoCURRC Information */
13701       idx++;
13702       ueSetRsp->protocolIEs.list.array[idx]->id  = \
13703                                                    ProtocolIE_ID_id_DUtoCURRCInformation;
13704       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13705       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
13706                                                             UEContextSetupResponseIEs__value_PR_DUtoCURRCInformation;
13707       BuildCellGroupConfigRrc(ueCb, &ueSetRsp->protocolIEs.list.array[idx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
13708
13709       /* CRNTI */
13710       idx++;
13711       ueSetRsp->protocolIEs.list.array[idx]->id  = ProtocolIE_ID_id_C_RNTI;
13712       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13713       ueSetRsp->protocolIEs.list.array[idx]->value.present = UEContextSetupResponseIEs__value_PR_C_RNTI;
13714       ueSetRsp->protocolIEs.list.array[idx]->value.choice.C_RNTI = ueCb->crnti; 
13715
13716
13717       /* Drb Setup List */
13718       idx++;
13719       ueSetRsp->protocolIEs.list.array[idx]->id  = \
13720                                                    ProtocolIE_ID_id_DRBs_Setup_List;
13721       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13722       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
13723                                                             UEContextSetupResponseIEs__value_PR_DRBs_Setup_List;
13724       ret = fillDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List,\
13725             &ueCb->f1UeDb->duUeCfg);
13726       if(ret == RFAILED)
13727       {
13728          DU_LOG("\nERROR  -->  F1AP : Failed to fillDrbSetupList in BuildAndSendUeContextSetupRsp()");
13729          freeF1UeDb(ueCb->f1UeDb);
13730          ueCb->f1UeDb = NULLP;
13731          break;
13732       }
13733
13734       /* Free UeContext Db created during Ue context Req */
13735       freeF1UeDb(ueCb->f1UeDb);
13736       ueCb->f1UeDb = NULLP;
13737
13738       /* TODO: To send Drb list */
13739       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
13740
13741       /* Encode the UE context setup response type as APER */
13742       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
13743       encBufSize = 0;
13744       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
13745             encBuf);
13746       /* Encode results */
13747       if(encRetVal.encoded == ENCODE_FAIL)
13748       {
13749          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Response structure (at %s)\n",\
13750                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
13751          ret = RFAILED;
13752          break;
13753       }
13754       else
13755       {
13756          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Setup Response\n");
13757          for(int i=0; i< encBufSize; i++)
13758          {
13759             printf("%x",encBuf[i]);
13760          }
13761       }
13762
13763       /* Sending  msg  */
13764       if(sendF1APMsg()  != ROK)
13765       {
13766          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Response failed");
13767          ret = RFAILED;
13768          break;
13769       }
13770       break;
13771    }
13772    FreeUeContextSetupRsp(f1apMsg);
13773    return ret;
13774 }/* End of BuildAndSendUeContextSetupRsp */
13775 /*******************************************************************
13776 *
13777 * @brief  Build And Send Ue Context Rsp 
13778 *
13779 * @details
13780 *
13781 *    Function : BuildAndSendUeCtxtRsp 
13782 *
13783 *    Functionality : Build And Send Ue Context Rsp
13784
13785 * @params[in]
13786 * @return sucess = ROK
13787 *         failure = RFAILED
13788 *
13789 * ****************************************************************/
13790 uint8_t BuildAndSendUeCtxtRsp(uint8_t cellId, uint8_t ueId)
13791 {
13792    uint8_t cellIdx = 0, actionType = 0; 
13793
13794    GET_CELL_IDX(cellId, cellIdx);
13795    actionType = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].f1UeDb->actionType;
13796
13797    switch(actionType)
13798    {
13799       case UE_CTXT_SETUP:
13800          {
13801             if((BuildAndSendUeContextSetupRsp(cellId,ueId)) != ROK)
13802             {
13803                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextSetupRsp()");
13804                return RFAILED;
13805             }
13806             break;
13807          }
13808       case UE_CTXT_MOD:
13809          {
13810             if((BuildAndSendUeContextModRsp(&duCb.actvCellLst[cellIdx]->ueCb[ueId-1])) != ROK)
13811             {
13812                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextModRsp");
13813                return RFAILED;
13814             }
13815             break;
13816          }
13817       default:
13818          DU_LOG("ERROR  -->  F1AP: Invalid Action Type %d at BuildAndSendUeCtxtRsp()", actionType);
13819          break;
13820
13821    }
13822    return ROK;
13823 }
13824
13825 /*******************************************************************
13826  *
13827  * @brief deallocating the memory of  F1reset msg
13828  *
13829  * @details
13830  *
13831  *    Function : FreeF1ResetReq
13832  *
13833  *    Functionality :
13834  *         - freeing memory of F1reset request msg
13835  *
13836  * @params[in]
13837  * @return void
13838  *
13839  *
13840  * ****************************************************************/
13841 void FreeF1ResetReq(F1AP_PDU_t *f1apMsg)
13842 {
13843    uint8_t idx =0 ;
13844    Reset_t *f1ResetMsg;
13845
13846    if(f1apMsg)
13847    {
13848       if(f1apMsg->choice.initiatingMessage)
13849       {
13850          f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
13851
13852          if(f1ResetMsg->protocolIEs.list.array)
13853          {
13854             for(idx=0 ;idx < f1ResetMsg->protocolIEs.list.count ; idx++)
13855             {
13856                if(f1ResetMsg->protocolIEs.list.array[idx])
13857                {
13858                   DU_FREE(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
13859                }
13860             }
13861             DU_FREE(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
13862          }
13863          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
13864       }
13865       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
13866    }
13867 }
13868 /*******************************************************************
13869  *
13870  * @brief Build and Send F1reset request 
13871  *
13872  * @details
13873  *
13874  *    Function : BuildAndSendF1ResetReq
13875  *
13876  *    Functionality:
13877  *         - Build and Send F1reset request msg
13878  *
13879  * @params[in]
13880  * @return ROK     - success
13881  *         RFAILED - failure
13882  *
13883  * ****************************************************************/
13884 uint8_t BuildAndSendF1ResetReq()
13885 {
13886    uint8_t          elementCnt=0;
13887    uint8_t          idx=0;
13888    uint8_t          ret= RFAILED;
13889    Reset_t          *f1ResetMsg = NULLP;
13890    F1AP_PDU_t       *f1apMsg = NULLP;
13891    asn_enc_rval_t   encRetVal;
13892    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset request \n");
13893    do
13894    {
13895       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
13896       if(f1apMsg == NULLP)
13897       {
13898          break;
13899       }
13900       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
13901       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
13902       if(f1apMsg->choice.initiatingMessage == NULLP)
13903       {
13904          break;
13905       }
13906       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_Reset;
13907       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
13908       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_Reset;
13909
13910       f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
13911
13912       elementCnt = 3;
13913       f1ResetMsg->protocolIEs.list.count = elementCnt;
13914       f1ResetMsg->protocolIEs.list.size = elementCnt * sizeof(ResetIEs_t *);
13915
13916       /* Initialize the F1Setup members */
13917       DU_ALLOC(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
13918       if(f1ResetMsg->protocolIEs.list.array == NULLP)
13919       {
13920          break;
13921       }
13922       for(idx=0; idx<elementCnt; idx++)
13923       {
13924          DU_ALLOC(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
13925          if(f1ResetMsg->protocolIEs.list.array[idx] == NULLP)
13926          {
13927             break;
13928          }
13929       }
13930
13931       /*TransactionID*/
13932       idx=0;
13933       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
13934       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13935       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_TransactionID;
13936       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.TransactionID = 1;
13937
13938       /*Cause*/
13939       idx++;
13940       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_Cause;
13941       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_ignore;
13942       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_Cause;
13943       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.present = Cause_PR_radioNetwork;
13944       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.choice.radioNetwork = CauseRadioNetwork_action_desirable_for_radio_reasons;
13945
13946       /*Reset Type*/
13947       idx++;
13948       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_ResetType;
13949       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13950       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_ResetType;
13951       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.present = ResetType_PR_f1_Interface;
13952       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.choice.f1_Interface = ResetAll_reset_all;
13953
13954       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
13955
13956       /* Encode the F1SetupRequest type as APER */
13957       memset(encBuf, 0, ENC_BUF_MAX_LEN);
13958       encBufSize = 0;
13959       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
13960             encBuf);
13961
13962       /* Encode results */
13963       if(encRetVal.encoded == ENCODE_FAIL)
13964       {
13965          DU_LOG("\nERROR  -->  F1AP : Could not encode F1Reset structure (at %s)\n",\
13966                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
13967          break;
13968       }
13969       else
13970       {
13971          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1Reset\n");
13972          for(idx=0; idx< encBufSize; idx++)
13973          {
13974             printf("%x",encBuf[idx]);
13975          }
13976       }
13977
13978       if(sendF1APMsg() != ROK)
13979       {
13980          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset request failed");
13981          break;
13982       }
13983
13984       ret = ROK;
13985       break;
13986    }while(true);
13987
13988    FreeF1ResetReq(f1apMsg);
13989    return ret;
13990 }
13991 /*******************************************************************
13992  *
13993  * @brief Build And Send F1ResetAck
13994  *
13995  * @details
13996  *
13997  *    Function : BuildAndSendF1ResetAck
13998  *
13999  *    Functionality:
14000  *         - Build And Send  F1ResetRSP
14001  *
14002  * @return ROK     - success
14003  *         RFAILED - failure
14004  *
14005  * ****************************************************************/
14006 void FreeF1ResetAck(F1AP_PDU_t *f1apMsg)
14007 {
14008    uint8_t idx;
14009    ResetAcknowledge_t *f1ResetAck;
14010
14011    if(f1apMsg)
14012    {
14013       if(f1apMsg->choice.successfulOutcome)
14014       {
14015          f1ResetAck= &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14016
14017          if(f1ResetAck->protocolIEs.list.array)
14018          {
14019             for(idx=0; idx<f1ResetAck->protocolIEs.list.count ; idx++)
14020             {
14021                if(f1ResetAck->protocolIEs.list.array[idx])
14022                {
14023                   DU_FREE(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14024                }
14025             }
14026             DU_FREE(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14027          }
14028          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14029       }
14030       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14031    }
14032 }
14033
14034 /*******************************************************************
14035  *
14036  * @brief Build And Send F1ResetAck
14037  *
14038  * @details
14039  *
14040  *    Function : BuildAndSendF1ResetAck
14041  *
14042  *    Functionality:
14043  *         - Build And Send  F1ResetRSP
14044  *
14045  *  @params[in]
14046  * @return ROK     - success
14047  *         RFAILED - failure
14048  *
14049  * ****************************************************************/
14050 uint8_t BuildAndSendF1ResetAck()
14051 {
14052    uint8_t                idx = 0;
14053    uint8_t                elementCnt = 0;
14054    uint8_t                ret = RFAILED;
14055    F1AP_PDU_t             *f1apMsg = NULL;
14056    ResetAcknowledge_t     *f1ResetAck = NULLP;
14057    asn_enc_rval_t         encRetVal;
14058    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset Acknowledgment \n");
14059
14060    do{
14061       /* Allocate the memory for F1ResetRequest_t */
14062       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14063       if(f1apMsg == NULLP)
14064       {
14065          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14066          break;
14067       }
14068
14069       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
14070
14071       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14072       if(f1apMsg->choice.successfulOutcome == NULLP)
14073       {
14074          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14075          break;
14076       }
14077       f1apMsg->choice.successfulOutcome->criticality   = Criticality_reject;
14078       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetAcknowledge;
14079       f1ResetAck = &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14080
14081       elementCnt = 1;
14082
14083       f1ResetAck->protocolIEs.list.count = elementCnt;
14084       f1ResetAck->protocolIEs.list.size = elementCnt*sizeof(ResetAcknowledgeIEs_t *);
14085
14086       DU_ALLOC(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14087       if(f1ResetAck->protocolIEs.list.array == NULLP)
14088       {
14089          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1ResetAckIEs failed");
14090          break;
14091       }
14092
14093       for(idx=0; idx<elementCnt; idx++)
14094       {
14095          DU_ALLOC(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14096          if(f1ResetAck->protocolIEs.list.array[idx] == NULLP)
14097          {
14098             break;
14099          }
14100       }
14101       /*TransactionID*/
14102       idx = 0;
14103       f1ResetAck->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
14104       f1ResetAck->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14105       f1ResetAck->protocolIEs.list.array[idx]->value.present = ResetAcknowledgeIEs__value_PR_TransactionID;
14106       f1ResetAck->protocolIEs.list.array[idx]->value.choice.TransactionID = TRANS_ID;
14107
14108       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14109
14110       /* Encode the F1SetupRequest type as UPER */
14111       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14112       encBufSize = 0;
14113       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
14114
14115       /* Check encode results */
14116       if(encRetVal.encoded == ENCODE_FAIL)
14117       {
14118          DU_LOG("\nERROR  -->  F1AP : Could not encode F1ResetAck structure (at %s)\n",\
14119                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14120          break;
14121       }
14122       else
14123       {
14124          DU_LOG("\nDUBUG   -->  F1AP : Created APER encoded buffer for F1ResetAck\n");
14125          for(int i=0; i< encBufSize; i++)
14126          {
14127             printf("%x",encBuf[i]);
14128          }
14129       }
14130       /* Sending msg */
14131       if(sendF1APMsg() != ROK)
14132       {
14133          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset Acknowledgement failed");
14134          break;
14135       }
14136
14137       ret = ROK;
14138       break;
14139    }while(true);
14140
14141    FreeF1ResetAck(f1apMsg);
14142    return ret;
14143 }
14144 /******************************************************************
14145 *
14146 * @brief free F1 reset msg allocated by aper_decoder 
14147 *
14148 * @details
14149 *
14150 *    Function : freeAperDecodeF1ResetMsg 
14151 *
14152 *    Functionality: free F1 reset msg allocated by aper_decoder 
14153 *
14154 * @params[in] Reset_t *f1ResetMsg 
14155 * @return void 
14156 *
14157 * ****************************************************************/
14158
14159 void freeAperDecodeF1ResetMsg(Reset_t *f1ResetMsg)
14160 {
14161    uint8_t ieIdx =0;
14162    if(f1ResetMsg->protocolIEs.list.array)
14163    {
14164       for(ieIdx=0 ;ieIdx < f1ResetMsg->protocolIEs.list.count ; ieIdx++)
14165       {
14166          if(f1ResetMsg->protocolIEs.list.array[ieIdx])
14167          {
14168             free(f1ResetMsg->protocolIEs.list.array[ieIdx]);
14169          }
14170       }
14171       free(f1ResetMsg->protocolIEs.list.array);
14172    }
14173 }
14174
14175 /******************************************************************
14176  *
14177  * @brief Processes DL RRC Message Transfer  sent by CU
14178  *
14179  * @details
14180  *
14181  *    Function : procF1ResetReq
14182  *
14183  *    Functionality: Processes DL RRC Message Transfer sent by CU
14184  *
14185  * @params[in] F1AP_PDU_t ASN decoded F1AP message
14186  * @return ROK     - success
14187  *         RFAILED - failure
14188  *
14189  * ****************************************************************/
14190 uint8_t procF1ResetReq(F1AP_PDU_t *f1apMsg)
14191 {
14192    /* we are currently not supporting Ue release. right now we are supporting only init case of fireset */
14193    uint8_t       ieIdx = 0;
14194    uint8_t        ret = ROK;
14195    Reset_t       *f1ResetMsg = NULLP;
14196
14197    DU_LOG("\nINFO   -->  Processing F1 reset request");
14198    f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14199
14200    for(ieIdx=0; ieIdx<f1ResetMsg->protocolIEs.list.count; ieIdx++)
14201    {
14202       switch(f1ResetMsg->protocolIEs.list.array[ieIdx]->id)
14203       {
14204          case ProtocolIE_ID_id_TransactionID:
14205             break;
14206
14207          case ProtocolIE_ID_id_Cause:
14208             break;
14209
14210          case ProtocolIE_ID_id_ResetType:
14211             {
14212                break;
14213             }
14214
14215          default:
14216             break;
14217       }
14218    }
14219    ret = BuildAndSendF1ResetAck();
14220    DU_LOG("\nINFO   -->  UE release is not supported for now");
14221
14222    freeAperDecodeF1ResetMsg(f1ResetMsg);
14223
14224    return ret;
14225 }
14226
14227 /*******************************************************************
14228  *
14229  * @brief free the RRC delivery report
14230  *
14231  * @details
14232  *
14233  *    Function : freeRrcDeliveryReport
14234  *
14235  *    Functionality: free the RRC delivery report
14236  *
14237  * @params[in]
14238  * @return ROK     - success
14239  *         RFAILED - failure
14240  *
14241  * ****************************************************************/
14242 void freeRrcDeliveryReport(F1AP_PDU_t  *f1apMsg )
14243 {
14244    uint8_t idx=0;
14245    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
14246
14247    if(f1apMsg)
14248    {
14249       if(f1apMsg->choice.initiatingMessage)
14250       {
14251          rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
14252          if(rrcDeliveryReport->protocolIEs.list.array)
14253          {
14254             for(idx =0 ;idx <rrcDeliveryReport->protocolIEs.list.count ;
14255                   idx++)
14256             {
14257                if(rrcDeliveryReport->protocolIEs.list.array[idx])
14258                {
14259                   DU_FREE(rrcDeliveryReport->protocolIEs.list.array[idx],
14260                         sizeof(RRCDeliveryReportIEs_t));
14261                }   
14262             }
14263             DU_FREE(rrcDeliveryReport->protocolIEs.list.array,
14264                   rrcDeliveryReport->protocolIEs.list.size);
14265          }
14266          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
14267       }
14268       DU_FREE(f1apMsg,
14269             sizeof(F1AP_PDU_t));
14270    }
14271 }
14272
14273 /*******************************************************************
14274 *
14275 * @brief Builds and sends the RRC delivery report
14276 *
14277 * @details
14278 *
14279 *    Function : BuildAndSendRrcDeliveryReport
14280 *
14281 *    Functionality: Builds and sends the RRC delivery report
14282 *
14283 * @params[in]
14284 *
14285 * @return ROK     - success
14286 *         RFAILED - failure
14287 *
14288 * ****************************************************************/
14289 uint8_t BuildAndSendRrcDeliveryReport(uint32_t gnbCuUeF1apId, \
14290    uint32_t gnbDuUeF1apId, RrcDeliveryReport *rrcDelivery)
14291 {
14292    uint8_t             ret = RFAILED;
14293    uint8_t             idx    = 0;
14294    uint8_t             idx1   = 0;
14295    uint8_t             elementCnt = 0;
14296    F1AP_PDU_t          *f1apMsg = NULLP;
14297    asn_enc_rval_t      encRetVal;  
14298    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
14299
14300    do{
14301
14302       DU_LOG("\nINFO   -->  F1AP : Building RRC delivery Message Transfer Message\n");
14303       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14304       if(f1apMsg == NULLP)
14305       {
14306          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14307          break;
14308       }
14309       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
14310       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
14311       if(f1apMsg->choice.initiatingMessage == NULLP)
14312       {
14313          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU  failed");
14314          break;
14315       }
14316       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_RRCDeliveryReport;
14317       f1apMsg->choice.initiatingMessage->criticality   = Criticality_ignore;
14318       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_RRCDeliveryReport;
14319
14320       rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
14321       elementCnt = 4;
14322       rrcDeliveryReport->protocolIEs.list.count = elementCnt;
14323       rrcDeliveryReport->protocolIEs.list.size = elementCnt * sizeof(RRCDeliveryReportIEs_t *);
14324
14325       /* Initialize the F1Setup members */
14326       DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array, rrcDeliveryReport->protocolIEs.list.size);
14327       if(rrcDeliveryReport->protocolIEs.list.array == NULLP)
14328       {
14329          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRC Delivery  failed");
14330          break;
14331       }
14332       for(idx =0 ;idx <elementCnt; idx++)
14333       {
14334          DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array[idx], sizeof(RRCDeliveryReportIEs_t));
14335          if(rrcDeliveryReport->protocolIEs.list.array[idx] == NULLP)
14336          {
14337             break;
14338          }
14339       }
14340
14341       idx1 = 0;
14342
14343       /*GNB CU UE F1AP ID*/
14344       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
14345       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
14346       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_CU_UE_F1AP_ID;
14347       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
14348
14349       /*GNB DU UE F1AP ID*/
14350       idx1++;
14351       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14352       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
14353       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_DU_UE_F1AP_ID;
14354       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
14355
14356       /*RRC delivery status*/
14357       idx1++;
14358       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_RRCDeliveryStatus;
14359       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
14360       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_RRCDeliveryStatus;
14361       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.delivery_status =\
14362       rrcDelivery->rrcDeliveryStatus.deliveryStatus;
14363       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.triggering_message =\
14364       rrcDelivery->rrcDeliveryStatus.triggeringMessage;
14365
14366       /* SRB ID */ 
14367       idx1++;
14368       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
14369       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
14370       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_SRBID;
14371       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.SRBID =  rrcDelivery->srbId;
14372
14373       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14374
14375       /* Encode the RRC DELIVERY REPORT type as APER */
14376       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14377       encBufSize = 0;
14378       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14379             encBuf);
14380
14381       /* Encode results */
14382       if(encRetVal.encoded == ENCODE_FAIL)
14383       {
14384          DU_LOG("\nERROR  -->  F1AP : Could not encode RRC Delivery Msg structure (at %s)\n",\
14385                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14386          break;
14387       }
14388       else
14389       {
14390          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for RRC Delivery Msg \n");
14391          for(idx=0; idx< encBufSize; idx++)
14392          {
14393             printf("%x",encBuf[idx]);
14394          }
14395       }
14396
14397       /* Sending msg */
14398       if(sendF1APMsg() != ROK)
14399       {
14400          DU_LOG("\nERROR  -->  F1AP : Sending RRC delivery  msg request failed");
14401          break;
14402       }
14403       ret = ROK;
14404       break;
14405
14406    }while(true);
14407
14408    freeRrcDeliveryReport(f1apMsg);
14409    return ret;
14410 }
14411
14412 /*******************************************************************
14413  *
14414  * @brief Processes cells to be activated
14415  *
14416  * @details
14417  *
14418  *    Function : extractCellsToBeActivated
14419  *
14420  *    Functionality:
14421  *      - Processes cells to be activated list received in F1SetupRsp
14422  *
14423  * @params[in] void
14424  * @return ROK     - success
14425  *         RFAILED - failure
14426  *
14427  * ****************************************************************/
14428
14429 uint8_t extractCellsToBeActivated(Cells_to_be_Activated_List_t cellsToActivate)
14430 {
14431    uint8_t  ret = ROK;
14432    uint16_t idx, pci = 0;
14433    uint64_t nci;
14434    Cells_to_be_Activated_List_Item_t cell;
14435
14436    for(idx=0; idx<cellsToActivate.list.count; idx++)
14437    {
14438       nci = 0;
14439       cell = cellsToActivate.list.array[idx]->value.choice.Cells_to_be_Activated_List_Item;
14440       bitStringToInt(&cell.nRCGI.nRCellIdentity, &nci);
14441
14442       if(cell.nRPCI)
14443       {
14444          pci = *cell.nRPCI;
14445       }
14446       ret = duProcCellsToBeActivated(cell.nRCGI.pLMN_Identity.buf, nci, pci);
14447    }
14448    return ret;
14449 }
14450 /******************************************************************
14451 *
14452 * @brief Processes F1 Setup Response allocated by aper_decoder 
14453 *
14454 * @details
14455 *
14456 *    Function : freeF1SetupRsp 
14457 *
14458 *    Functionality: free F1 Setup Response allocated by aper_decoder 
14459 *
14460 * @params[in] F1SetupResponse_t *f1SetRspMsg 
14461 * @return void 
14462 *
14463 * ****************************************************************/
14464
14465 void freeAperDecodeF1SetupRsp(F1SetupResponse_t *f1SetRspMsg)
14466 {
14467    uint8_t ieIdx =0;
14468    uint8_t arrIdx =0;
14469    Cells_to_be_Activated_List_t *cellToActivate =NULLP;
14470    RRC_Version_t      *rrcVer =NULLP;
14471
14472    if(f1SetRspMsg->protocolIEs.list.array)
14473    {
14474       for(ieIdx=0; ieIdx<f1SetRspMsg->protocolIEs.list.count; ieIdx++)
14475       {
14476          if(f1SetRspMsg->protocolIEs.list.array[ieIdx])
14477          {
14478             switch(f1SetRspMsg->protocolIEs.list.array[ieIdx]->id)
14479             {
14480                case ProtocolIE_ID_id_Cells_to_be_Activated_List:
14481                   {
14482                      cellToActivate =
14483                         &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.Cells_to_be_Activated_List;
14484                      if(cellToActivate->list.array)
14485                      {
14486                         for(arrIdx=0; arrIdx<cellToActivate->list.count ; arrIdx++)
14487                         {
14488                            if(cellToActivate->list.array[arrIdx])
14489                            {
14490
14491                               if(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.nRCGI.\
14492                               pLMN_Identity.buf)
14493                               {
14494                                  if(cellToActivate->list.array[0]->value.choice.\
14495                                        Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf)
14496                                  {
14497                                     free(cellToActivate->list.array[0]->value.choice.\
14498                                           Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf);
14499                                  }
14500
14501                                  free(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
14502                                        nRCGI.pLMN_Identity.buf);
14503                               }
14504                               free(cellToActivate->list.array[arrIdx]);
14505                            }
14506                         }
14507                         free(cellToActivate->list.array);
14508                      }
14509                      break;
14510                   }
14511                case ProtocolIE_ID_id_TransactionID:
14512                   {
14513                      break;
14514                   }
14515                case ProtocolIE_ID_id_gNB_CU_Name:
14516                   {
14517                      free(f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_Name.buf);
14518                      break;
14519                   }
14520                case ProtocolIE_ID_id_GNB_CU_RRC_Version:
14521                   {
14522                      rrcVer = &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
14523                      if(rrcVer->latest_RRC_Version.buf)
14524                      {
14525                         if(rrcVer->iE_Extensions)
14526                         {
14527                            if(rrcVer->iE_Extensions->list.array)
14528                            {
14529                               if(rrcVer->iE_Extensions->list.array[0])
14530                               {
14531                                  if(rrcVer->iE_Extensions->list.\
14532                                        array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf)
14533                                  {
14534                                     free(rrcVer->iE_Extensions->list.\
14535                                           array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf);
14536                                  }
14537                                  free(rrcVer->iE_Extensions->list.array[0]);
14538                               }
14539                               free(rrcVer->iE_Extensions->list.array);
14540                            }
14541                            free(rrcVer->iE_Extensions);
14542                         }
14543                         free(rrcVer->latest_RRC_Version.buf);
14544                      }
14545                      break;
14546
14547                   }
14548                default:
14549                   {
14550                      DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
14551                            f1SetRspMsg->protocolIEs.list.array[ieIdx]->id);
14552                   }
14553             }
14554             free(f1SetRspMsg->protocolIEs.list.array[ieIdx]);
14555          }
14556       }
14557       free(f1SetRspMsg->protocolIEs.list.array);
14558    }
14559 }
14560 /******************************************************************
14561  *
14562  * @brief Processes F1 Setup Response sent by CU
14563  *
14564  * @details
14565  *
14566  *    Function : procF1SetupRsp
14567  *
14568  *    Functionality: Processes F1 Setup Response sent by CU
14569  *
14570  * @params[in] F1AP_PDU_t ASN decoded F1AP message
14571  * @return ROK     - success
14572  *         RFAILED - failure
14573  *
14574  * ****************************************************************/
14575 uint8_t procF1SetupRsp(F1AP_PDU_t *f1apMsg, MsgLen recvBufLen, char *recvBuf)
14576 {
14577    uint8_t ret = ROK;
14578    uint16_t idx =0;
14579    F1SetupResponse_t *f1SetRspMsg = NULLP;
14580    GNB_CU_Name_t     *cuName = NULLP;
14581    F1SetupRsp  f1SetRspDb;
14582    RRC_Version_t      *rrcVer =NULLP;
14583    
14584    memset(&f1SetRspDb, 0, sizeof(F1SetupRsp));
14585
14586    DU_LOG("\nINFO   -->  F1AP : F1 Setup Response received");
14587    f1SetRspMsg = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
14588
14589    for(idx=0; idx<f1SetRspMsg->protocolIEs.list.count; idx++)
14590    {
14591       switch(f1SetRspMsg->protocolIEs.list.array[idx]->id)
14592       {
14593          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
14594             {
14595                extractCellsToBeActivated(f1SetRspMsg->protocolIEs.list.array[idx]->\
14596                      value.choice.Cells_to_be_Activated_List);
14597                break;
14598             }
14599          case ProtocolIE_ID_id_TransactionID:
14600             {
14601                f1SetRspDb.transId = f1SetRspMsg->protocolIEs.list.array[idx]->\
14602                                     value.choice.TransactionID;
14603                break;
14604             }
14605          case ProtocolIE_ID_id_gNB_CU_Name:
14606             {
14607                cuName = &f1SetRspMsg->protocolIEs.list.array[idx]->\
14608                         value.choice.GNB_CU_Name;
14609                strcpy(f1SetRspDb.cuName, (const char*)cuName->buf);
14610                break;
14611             }
14612          case ProtocolIE_ID_id_GNB_CU_RRC_Version:
14613             {
14614                rrcVer = &f1SetRspMsg->protocolIEs.list.array[idx]->value.choice.RRC_Version;
14615                strcpy(f1SetRspDb.rrcVersion.rrcVer,
14616                      (const char*)rrcVer->latest_RRC_Version.buf);
14617                break;
14618             }
14619          default:
14620             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
14621                   f1SetRspMsg->protocolIEs.list.array[idx]->id);
14622       }
14623       duProcF1SetupRsp();
14624    }
14625    
14626    freeAperDecodeF1SetupRsp(f1SetRspMsg);
14627
14628    duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize = recvBufLen;
14629    DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize);
14630    if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
14631    {
14632       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the buf of F1setup response");
14633       return RFAILED;
14634    }
14635    memcpy(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, recvBuf, recvBufLen);
14636    
14637    if(BuildAndSendE2SetupReq() != ROK)
14638    {
14639       DU_LOG("\nERROR  -->  F1AP : Failed to build and send E2 setup request ");
14640       return RFAILED;
14641    }
14642    return ret;
14643 }
14644 /*******************************************************************
14645 *
14646 * @brief free GNB DU config update ack
14647 *
14648 * @details
14649 *
14650 *    Function : freeAperDecodeGnbDuAck 
14651 *
14652 *    Functionality: Processes GNB DU config update ack And
14653 *                     added free part for the memory allocated by aper_decoder
14654 *
14655 * @params[in] F1AP_PDU_t ASN decoded F1AP message
14656 * @return ROK     - success
14657 *         RFAILED - failure
14658 *
14659 * ****************************************************************/
14660
14661 void freeAperDecodeGnbDuAck(GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck)
14662 {
14663    uint8_t ieIdx = 0;
14664
14665    if(gnbDuAck->protocolIEs.list.array)
14666    {
14667       for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
14668       {
14669          if(gnbDuAck->protocolIEs.list.array[ieIdx])
14670          {
14671             free(gnbDuAck->protocolIEs.list.array[ieIdx]);
14672          }
14673       }
14674       free(gnbDuAck->protocolIEs.list.array);
14675    }
14676 }
14677
14678 /*******************************************************************
14679 *
14680 * @brief Building  result of gnb-du config update ack output
14681 *
14682 * @details
14683 *
14684 *    Function : duProcGnbDuCfgUpdAckMsg 
14685 *
14686 *    Functionality: 
14687 *        Building output of gnb-du config update ack 
14688 *
14689 * @params[in] transId
14690 * @return void
14691 *
14692 * ****************************************************************/
14693
14694 uint8_t duProcGnbDuCfgUpdAckMsg(uint8_t transId)
14695 {
14696    uint8_t  ieIdx=0, arrIdx=0,ret=ROK;
14697    uint8_t  ueId =0 , ueIdx =0, totalActiveUe = 0;
14698    uint16_t cellIdx =0, crnti=0;
14699    uint64_t cellId =0;
14700    CmLList *f1apPduNode = NULLP;
14701    ReservedF1apPduInfo *f1apPduInfo =NULLP;
14702    F1AP_PDU_t *f1apMsgPdu = NULLP;
14703    GNBDUConfigurationUpdate_t *gnbDuConfigUpdate = NULLP;
14704    BIT_STRING_t *cellIdentity=NULLP;
14705    struct Served_Cells_To_Delete_ItemIEs *deleteItemIe=NULLP;
14706    Served_Cells_To_Delete_List_t *cellsToDelete=NULLP;
14707    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
14708
14709    DU_LOG("\nINFO   -->  DU APP: GNB-DU config update Ack received ");
14710    f1apPduNode = searchFromReservedF1apPduList(transId);
14711    f1apPduInfo = (ReservedF1apPduInfo *)f1apPduNode->node;
14712    f1apMsgPdu = (F1AP_PDU_t *)f1apPduInfo->f1apMsg;
14713
14714    if(f1apMsgPdu)
14715    {
14716       if(f1apMsgPdu->choice.initiatingMessage)
14717       {
14718          gnbDuConfigUpdate = &f1apMsgPdu->choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
14719          for(ieIdx=0; ieIdx < gnbDuConfigUpdate->protocolIEs.list.count; ieIdx++)
14720          {
14721             switch(gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->id)
14722             {
14723                case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
14724                   {
14725                      cellsToDelete = &gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
14726                                      Served_Cells_To_Delete_List;
14727                      if(cellsToDelete->list.array)
14728                      {
14729                         if(cellsToDelete->list.array[arrIdx])
14730                         {
14731                            deleteItemIe = (Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx];
14732                            deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
14733                            if(deleteItem->oldNRCGI.nRCellIdentity.buf)
14734                            {
14735                               cellIdentity = &deleteItem->oldNRCGI.nRCellIdentity;
14736                               bitStringToInt(cellIdentity, &cellId);
14737
14738                               GET_CELL_IDX(cellId, cellIdx);
14739                               if(duCb.actvCellLst[cellIdx] != NULLP)
14740                               {
14741                                  duCb.actvCellLst[cellId-1]->cellStatus = DELETION_IN_PROGRESS;
14742                               }
14743                            }
14744                         }
14745                      }
14746
14747                      if(duCb.actvCellLst[cellIdx] != NULLP)
14748                      {
14749                         if(duCb.actvCellLst[cellIdx]->numActvUes == 0)
14750                         {
14751                            ret = duSendCellDeletReq(cellId);
14752                            if(ret == RFAILED)
14753                            {
14754                               DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to send cell delete\
14755                               request for cellId[%d]", cellId);
14756                            }
14757                         }
14758                         else
14759                         {
14760                            totalActiveUe = duCb.actvCellLst[cellIdx]->numActvUes;
14761                            while(totalActiveUe)
14762                            {
14763                               if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState != UE_ACTIVE)
14764                               {
14765                                  ueIdx++;
14766                                  continue;
14767                               }
14768
14769                               crnti = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti;
14770                               GET_UE_ID(crnti,ueId);
14771                               /* Sending Ue Context release request only for maximum supporting UEs */
14772                               ret = BuildAndSendUeContextReleaseReq(cellId, ueId);
14773                               if(ret == RFAILED)
14774                               {
14775                                  DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to build and send UE delete\
14776                                  request for cellId[%d]", cellId);
14777                               }
14778                               ueIdx++;
14779                               totalActiveUe--;
14780                            }
14781                         }
14782                      }
14783                      else
14784                      {
14785                         DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): CellId [%d] not found", cellId);
14786                         ret = RFAILED;
14787                      }
14788                      break;
14789                   }
14790
14791                default:
14792                   break;
14793             }
14794          }
14795       }
14796    }
14797    
14798    FreeDUConfigUpdate(f1apMsgPdu);
14799    deleteFromReservedF1apPduList(f1apPduNode);
14800    return ret;
14801 }
14802
14803 /*******************************************************************
14804 *
14805 * @brief Processes GNB DU config update ack
14806 *
14807 * @details
14808 *
14809 *    Function : procF1GNBDUCfgUpdAck
14810 *
14811 *    Functionality: added free part for the memory allocated by aper_decoder
14812 *
14813 * @params[in] F1AP_PDU_t *f1apMsg 
14814 * @return void 
14815 *
14816 * ****************************************************************/
14817 uint8_t procF1GNBDUCfgUpdAck(F1AP_PDU_t *f1apMsg)
14818 {
14819    uint8_t ieIdx=0,transId=0;
14820    GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck = NULLP;
14821
14822    DU_LOG("\nINFO   -->  F1AP : GNB-DU config update acknowledgment");
14823    gnbDuAck = &f1apMsg->choice.successfulOutcome->value.choice.GNBDUConfigurationUpdateAcknowledge;
14824
14825    for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
14826    {
14827       switch(gnbDuAck->protocolIEs.list.array[ieIdx]->id)
14828       {
14829          case ProtocolIE_ID_id_TransactionID:
14830             {
14831                transId = gnbDuAck->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
14832                break;
14833             }
14834          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
14835             {
14836                break;
14837             }
14838          default :
14839             {
14840                DU_LOG("\nERROR  -->  F1AP: procF1GNBDUCfgUpdAck(): Invalid IE Received: %ld", \
14841                      gnbDuAck->protocolIEs.list.array[ieIdx]->id);
14842                break;
14843             }
14844       }
14845    }
14846    
14847    duProcGnbDuCfgUpdAckMsg(transId);
14848     
14849 #if 0
14850    /* presently we are not supporting F1 Reset from DU to CU , we are only
14851     * supporting F1 Reset from CU to DU */
14852
14853    if(BuildAndSendF1ResetReq() != ROK)
14854    {
14855       return RFAILED;
14856    }
14857 #endif
14858
14859    freeAperDecodeGnbDuAck(gnbDuAck);
14860    return ROK;
14861 }
14862 /******************************************************************
14863 *
14864 * @brief free DL RRC Message Transfer allocated by aper_decoder 
14865 *
14866 * @details
14867 *
14868 *    Function : freeAperDecodef1DlRrcMsg 
14869 *
14870 *    Functionality: free DL RRC Message Transfer allocated by aper_decoder 
14871 *
14872 * @params[in] DLRRCMessageTransfer_t *f1DlRrcMsg 
14873 * @return ROK     - success
14874 *         RFAILED - failure
14875 *
14876 * ****************************************************************/
14877
14878 void freeAperDecodef1DlRrcMsg(DLRRCMessageTransfer_t *f1DlRrcMsg)
14879 {
14880    uint8_t ieIdx =0;
14881    RRCContainer_t *rrcContainer = NULLP;
14882
14883    if(f1DlRrcMsg->protocolIEs.list.array)
14884    {
14885       for(ieIdx=0; ieIdx<f1DlRrcMsg->protocolIEs.list.count; ieIdx++)
14886       {
14887          if(f1DlRrcMsg->protocolIEs.list.array[ieIdx])
14888          {
14889             switch(f1DlRrcMsg->protocolIEs.list.array[ieIdx]->id)
14890             {
14891                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14892                   break;
14893                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14894                   break;
14895                case ProtocolIE_ID_id_SRBID:
14896                   break;
14897                case ProtocolIE_ID_id_RRCContainer:
14898                   {
14899                      rrcContainer =&f1DlRrcMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer;
14900                      free(rrcContainer->buf);
14901                   }
14902                case ProtocolIE_ID_id_ExecuteDuplication:
14903                   break;
14904                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
14905                   break;
14906                   break;
14907             }
14908             free(f1DlRrcMsg->protocolIEs.list.array[ieIdx]);
14909          }
14910       }
14911       free(f1DlRrcMsg->protocolIEs.list.array);
14912    }
14913 }
14914 /******************************************************************
14915  *
14916  * @brief Processes DL RRC Message Transfer  sent by CU
14917  *
14918  * @details
14919  *
14920  *    Function : procF1DlRrcMsgTrans
14921  *
14922  *    Functionality: Processes DL RRC Message Transfer sent by CU
14923  *
14924  * @params[in] F1AP_PDU_t ASN decoded F1AP message
14925  * @return ROK     - success
14926  *         RFAILED - failure
14927  *
14928  * ****************************************************************/
14929 uint8_t procF1DlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
14930 {
14931    uint8_t  idx, ret;
14932    DLRRCMessageTransfer_t *f1DlRrcMsg = NULLP;
14933    F1DlRrcMsg dlMsg;
14934    memset(&dlMsg, 0, sizeof(F1DlRrcMsg));
14935
14936    DU_LOG("\nINFO   -->  DU_APP : DL RRC message transfer Recevied");
14937    f1DlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
14938
14939    ret = ROK;
14940
14941    for(idx=0; idx<f1DlRrcMsg->protocolIEs.list.count; idx++)
14942    {
14943       switch(f1DlRrcMsg->protocolIEs.list.array[idx]->id)
14944       {
14945          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14946             {
14947                dlMsg.gnbCuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
14948                break;
14949             }
14950          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14951             {
14952                dlMsg.gnbDuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
14953                break;
14954             }
14955          case ProtocolIE_ID_id_SRBID:
14956             {
14957                dlMsg.srbId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
14958                break;
14959             }
14960          case ProtocolIE_ID_id_ExecuteDuplication:
14961             dlMsg.execDup = true;
14962             break;
14963
14964          case ProtocolIE_ID_id_RRCContainer:
14965             {
14966                if(f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
14967                {
14968                   dlMsg.rrcMsgSize = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
14969                   DU_ALLOC_SHRABL_BUF(dlMsg.rrcMsgPdu, dlMsg.rrcMsgSize);
14970                   if(dlMsg.rrcMsgPdu)
14971                   {
14972                      memcpy(dlMsg.rrcMsgPdu, f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf,\
14973                         dlMsg.rrcMsgSize);
14974                   }
14975                   else
14976                   {
14977                      DU_LOG("\nERROR  -->  DU APP : Memory alloc Failed at RRC Container at procF1DlRrcMsgTrans()");
14978                      return RFAILED;
14979                   }
14980                }
14981                else
14982                {
14983                   DU_LOG("\nERROR  -->  DU_APP : RRC Container Size is invalid:%ld",\
14984                   f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
14985                   return RFAILED;
14986                }
14987                break;
14988             }
14989          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
14990             {
14991                dlMsg.deliveryStatRpt = true;
14992                break;
14993             }
14994          default:
14995             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
14996                   f1DlRrcMsg->protocolIEs.list.array[idx]->id);
14997       }
14998    }
14999
15000    ret = duProcDlRrcMsg(&dlMsg);
15001
15002    freeAperDecodef1DlRrcMsg(f1DlRrcMsg);
15003    return ret;
15004 }
15005 /*******************************************************************
15006  *
15007 * @brief Builds the DRB to be Setup Mod list
15008 *
15009 * @details
15010 *
15011 *    Function : 
15012 *
15013 *    Functionality: Constructs the DRB to be Setup Mod list
15014 *
15015 * @params[in] DRBs_SetupMod_List_t *drbSet
15016 *
15017 * @return ROK     - success
15018 *         RFAILED - failure
15019 *
15020 * ****************************************************************/
15021 uint8_t BuildSrbSetupModList(SRBs_SetupMod_List_t *srbList, DuUeCfg *ueCfg)
15022 {
15023    uint8_t srbIdx = 0;
15024    struct SRBs_SetupMod_ItemIEs *srbItemIe;
15025
15026    srbList->list.count = ueCfg->numRlcLcs;
15027    srbList->list.size = srbList->list.count * sizeof(SRBs_SetupMod_ItemIEs_t *);
15028
15029    DU_ALLOC(srbList->list.array, srbList->list.size);
15030    if(srbList->list.array == NULLP)
15031    {
15032       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15033       return RFAILED;
15034    }
15035
15036    for(srbIdx = 0; srbIdx < srbList->list.count; srbIdx++)
15037    {
15038       DU_ALLOC(srbList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15039       if(srbList->list.array[srbIdx] == NULLP)
15040       {
15041          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15042          return RFAILED;
15043       }
15044    } 
15045
15046    for(srbIdx=0; srbIdx < srbList->list.count; srbIdx++)
15047    {
15048       srbItemIe = (struct SRBs_SetupMod_ItemIEs *)srbList->list.array[srbIdx];
15049       srbItemIe->id = ProtocolIE_ID_id_SRBs_SetupMod_Item;
15050       srbItemIe->criticality = Criticality_reject;
15051       srbItemIe->value.present = SRBs_SetupMod_ItemIEs__value_PR_SRBs_SetupMod_Item;
15052       srbItemIe->value.choice.SRBs_SetupMod_Item.sRBID = ueCfg->rlcLcCfg[srbIdx].rbId;
15053       srbItemIe->value.choice.SRBs_SetupMod_Item.lCID = ueCfg->rlcLcCfg[srbIdx].lcId;
15054    }
15055    return ROK;
15056 }
15057
15058 /*******************************************************************
15059  *
15060 * @brief Builds the DRB to be Setup Mod list
15061 *
15062 * @details
15063 *
15064 *    Function : 
15065 *
15066 *    Functionality: Constructs the DRB to be Setup Mod list
15067 *
15068 * @params[in] DRBs_SetupMod_List_t *drbSet
15069 *
15070 * @return ROK     - success
15071 *         RFAILED - failure
15072 *
15073 * ****************************************************************/
15074
15075 uint8_t BuildDrbSetupModList(DRBs_SetupMod_List_t *drbSet , DuUeCfg *ueCfg)
15076 {
15077    uint8_t arrIdx =0;
15078    uint8_t drbCnt =0;
15079    struct DRBs_SetupMod_ItemIEs *drbItemIe;
15080
15081    drbCnt = ueCfg->numDrbSetupMod;
15082
15083    if(!drbCnt)
15084    {
15085       DU_LOG("\nINFO  -->  F1AP : BuildDrbToBeSetupModList(): No DRB information to avaialble to add");
15086       return ROK;
15087    }
15088
15089    drbSet->list.count = drbCnt;
15090    drbSet->list.size = drbCnt * sizeof(DRBs_SetupMod_ItemIEs_t *);
15091    DU_ALLOC(drbSet->list.array, drbSet->list.size);
15092    if(drbSet->list.array == NULLP)
15093    {
15094       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
15095       return  RFAILED;
15096    }
15097    for(arrIdx=0; arrIdx<drbCnt; arrIdx++)
15098    {
15099       DU_ALLOC(drbSet->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
15100       if(drbSet->list.array[arrIdx] == NULLP)
15101       {
15102               DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
15103               return  RFAILED;
15104       }
15105
15106       drbItemIe = (struct DRBs_SetupMod_ItemIEs *)drbSet->list.array[arrIdx];
15107       drbItemIe->id = ProtocolIE_ID_id_DRBs_SetupMod_Item;
15108       drbItemIe->criticality = Criticality_reject;
15109       drbItemIe->value.present = DRBs_SetupMod_ItemIEs__value_PR_DRBs_SetupMod_Item;
15110       drbItemIe->value.choice.DRBs_SetupMod_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
15111       if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List,\
15112       &ueCfg->upTnlInfo[arrIdx])!= ROK)
15113       {
15114          DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbToBeSetupModList");
15115          return RFAILED;
15116       }
15117       
15118    }
15119
15120    return ROK;
15121 }
15122 /*******************************************************************
15123 * @brief Free the memory allocated for DRB setup List
15124 *
15125 * @details
15126 *
15127 *    Function : FreeDrbSetupModList 
15128 *
15129 *    Functionality:
15130 *       Free the memory allocated for DRB setup list
15131 *
15132 * @params[in] DRBs_Setup_List_t *
15133 * @return void
15134 *
15135 * ****************************************************************/
15136 void FreeDrbSetupModList(DRBs_SetupMod_List_t *drbSetupList)
15137 {
15138    uint8_t arrIdx = 0;
15139    DRBs_SetupMod_ItemIEs_t *drbItemIe = NULLP;
15140
15141    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
15142    {
15143       drbItemIe = ((DRBs_SetupMod_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
15144       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List);
15145       DU_FREE(drbSetupList->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
15146    }
15147    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
15148 }
15149
15150 /*******************************************************************
15151 * @brief Free the memory allocated for SRB setup List
15152 *
15153 * @details
15154 *
15155 *    Function : FreeSrbSetupModList 
15156 *
15157 *    Functionality:
15158 *       Free the memory allocated for SRB setup list
15159 *
15160 * @params[in] SRBs_Setup_List_t *
15161 * @return void
15162 *
15163 * ****************************************************************/
15164 void FreeSrbSetupModList(SRBs_SetupMod_List_t *srbSetupList)
15165 {
15166    uint8_t srbIdx = 0;
15167    
15168    for(srbIdx = 0; srbIdx < srbSetupList->list.count; srbIdx++)
15169       DU_FREE(srbSetupList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15170    DU_FREE(srbSetupList->list.array, srbSetupList->list.size);
15171 }
15172
15173 /*******************************************************************
15174 * @brief Free the memory allocated for UE Context Mod Response
15175 *
15176 * @details
15177 *
15178 *    Function : FreeUeContextModResp 
15179 *
15180 *    Functionality:
15181 *       Free the memory allocated for UE Context Mod Response
15182 *
15183 * @params[in] F1AP_PDU_t *f1apMsg
15184 * @return void
15185 *
15186 * ****************************************************************/
15187
15188 void FreeUeContextModResp(F1AP_PDU_t *f1apMsg)
15189 {
15190    uint8_t ieIdx;
15191    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
15192    if(f1apMsg)
15193    {
15194       if(f1apMsg->choice.successfulOutcome)
15195       {
15196          ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
15197          if(ueContextModifyRes->protocolIEs.list.array)
15198          {
15199             for(ieIdx=0 ; ieIdx<ueContextModifyRes->protocolIEs.list.count; ieIdx++)
15200             {
15201                if(ueContextModifyRes->protocolIEs.list.array[ieIdx])
15202                {
15203                   switch(ueContextModifyRes->protocolIEs.list.array[ieIdx]->id)
15204                   {
15205                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15206                         break;
15207                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15208                         break;
15209                      case ProtocolIE_ID_id_DRBs_SetupMod_List:
15210                         {
15211                             FreeDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
15212                             value.choice.DRBs_SetupMod_List));
15213                             break;
15214                         }
15215                      case ProtocolIE_ID_id_SRBs_SetupMod_List:
15216                         {
15217                            FreeSrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
15218                               SRBs_SetupMod_List));
15219                            break; 
15220                         }
15221                   }
15222                   DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
15223                }
15224
15225             }
15226             DU_FREE(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
15227          }
15228          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
15229       }
15230       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
15231    }
15232 }
15233
15234 /*****************************************************************i
15235 *
15236 * @brief Creating the ue context modifcation response and sending
15237 *
15238 * @details
15239 *
15240 *    Function : BuildAndSendUeContextModRsp 
15241 *
15242 *    Functionality:
15243 *         - Creating the ue context modifcation response 
15244 *
15245 * @params[in] uint8_t cellId,uint8_t ueId
15246 * @return ROK     - success
15247 *         RFAILED - failure
15248 *
15249 * ****************************************************************/
15250 uint8_t BuildAndSendUeContextModRsp(DuUeCb *ueCb)
15251 {
15252    uint8_t   ieIdx = 0, tnlIdx = 0, rbIdx = 0;
15253    uint8_t   elementCnt = 0;
15254    uint8_t   ret = RFAILED;
15255    F1AP_PDU_t *f1apMsg = NULLP;
15256    asn_enc_rval_t  encRetVal;
15257    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
15258
15259    DU_LOG("\nINFO  -->  F1AP : Building UE context modification response\n");
15260
15261    while(true)
15262    {
15263       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15264       if(f1apMsg == NULLP)
15265       {
15266          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
15267          break;
15268       }
15269
15270       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
15271
15272       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
15273       if(f1apMsg->choice.successfulOutcome == NULLP)
15274       {
15275          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
15276          break;
15277       }
15278       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextModification;
15279       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
15280       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_UEContextModificationResponse;
15281
15282       ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
15283   
15284       if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
15285       {
15286          if(ueCb->f1UeDb->duUeCfg.numDrbSetupMod)
15287             elementCnt =3;
15288          else
15289             elementCnt =2;
15290       }
15291       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15292          elementCnt = 5;
15293       if(ueCb->f1UeDb->actionType == UE_CTXT_RRC_RECFG_COMPLETE)
15294          elementCnt = 2;
15295       ueContextModifyRes->protocolIEs.list.count = elementCnt;
15296       ueContextModifyRes->protocolIEs.list.size = elementCnt*sizeof(UEContextModificationResponse_t*);
15297
15298       /* Initialize the UE context modification members */
15299       DU_ALLOC(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
15300       if(ueContextModifyRes->protocolIEs.list.array == NULLP)
15301       {
15302          DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
15303          break;
15304       }
15305
15306       for(ieIdx=0 ; ieIdx<elementCnt; ieIdx++)
15307       {
15308          DU_ALLOC(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
15309          if(ueContextModifyRes->protocolIEs.list.array[ieIdx] == NULLP)
15310          {
15311             DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
15312             break;
15313          }
15314       }
15315
15316       ieIdx=0;
15317       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
15318       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15319       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
15320       UEContextModificationResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
15321       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
15322
15323       ieIdx++;
15324       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
15325       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15326       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present=\
15327       UEContextModificationResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
15328       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
15329
15330       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15331       {
15332          ieIdx++;
15333          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCInformation;
15334          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15335          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
15336          UEContextModificationResponseIEs__value_PR_DUtoCURRCInformation;
15337          BuildCellGroupConfigRrc(ueCb, &ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
15338       }
15339
15340       if((ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY) || ((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbSetupMod)))
15341       { 
15342          ieIdx++;
15343          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_SetupMod_List;
15344          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15345          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
15346                                                                            UEContextModificationResponseIEs__value_PR_DRBs_SetupMod_List;
15347          if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15348          {
15349             for(tnlIdx = 0; tnlIdx < duCb.numTeId; tnlIdx++)
15350             {
15351                if(duCb.upTnlCfg[tnlIdx]->ueId == ueCb->gnbDuUeF1apId)
15352                {
15353                   memcpy(&ueCb->f1UeDb->duUeCfg.upTnlInfo[ueCb->f1UeDb->duUeCfg.numDrbSetupMod++], duCb.upTnlCfg[tnlIdx], sizeof(UpTnlCfg));
15354                }
15355             }
15356          }
15357          ret = BuildDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
15358                   value.choice.DRBs_SetupMod_List) , &ueCb->f1UeDb->duUeCfg);
15359          if(ret != ROK)
15360          {
15361             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB setupmod List ");
15362             break;
15363          }
15364       }
15365
15366       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15367       {
15368          ieIdx++;
15369          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_SRBs_SetupMod_List;
15370          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15371          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
15372                                                                             UEContextModificationResponseIEs__value_PR_SRBs_SetupMod_List;
15373          for(rbIdx = 0; rbIdx < ueCb->rlcUeCfg.numLcs; rbIdx++)
15374          {
15375             if(ueCb->rlcUeCfg.rlcLcCfg[rbIdx].rbType == RB_TYPE_SRB)
15376             {
15377                memcpy(&ueCb->f1UeDb->duUeCfg.rlcLcCfg[ueCb->f1UeDb->duUeCfg.numRlcLcs++], &ueCb->rlcUeCfg.rlcLcCfg[rbIdx],\
15378                      sizeof(RlcBearerCfg));
15379             }
15380          }
15381          ret = BuildSrbSetupModList(&ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.SRBs_SetupMod_List, \
15382                &ueCb->f1UeDb->duUeCfg);
15383          if(ret != ROK)
15384          {
15385             DU_LOG( "\nERROR  -->  F1AP : Failed to build SRB setupmod List ");
15386             break;
15387          }
15388       }
15389
15390       freeF1UeDb(ueCb->f1UeDb);
15391       ueCb->f1UeDb = NULLP;
15392
15393       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15394
15395       /* Encode the F1SetupRequest type as APER */
15396       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15397       encBufSize = 0;
15398       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,encBuf);
15399
15400       /* Encode results */
15401       if(encRetVal.encoded == ENCODE_FAIL)
15402       {
15403          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Request structure (at %s)\n",\
15404                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15405          ret = RFAILED;
15406          break;
15407       }
15408       else
15409       {
15410          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Modification Response\n");
15411          for(int i=0; i< encBufSize; i++)
15412          {
15413             printf("%x",encBuf[i]);
15414          }
15415       }
15416
15417       /* Sending  msg  */
15418       if(sendF1APMsg() != ROK)
15419       {
15420          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Res Failed");
15421          ret = RFAILED;
15422          break;
15423       }
15424
15425       ret = ROK;
15426       break;
15427    }
15428    FreeUeContextModResp(f1apMsg);
15429    return ret;
15430 }
15431 /*******************************************************************
15432  *
15433  * @brief Deallocating the memory allocated by the aper decoder
15434  *          for QOSInfo
15435  *
15436  * @details
15437  *
15438  *    Function : freeAperDecodeQosInfo
15439  *
15440  *    Functionality:  Deallocating the memory allocated for QOSInfo
15441  *
15442  * @params[in] QoSFlowLevelQoSParameters_t *drbQos
15443  *
15444  * @return void
15445  *
15446  * ****************************************************************/
15447
15448 void freeAperDecodeQosInfo(QoSFlowLevelQoSParameters_t *drbQos)
15449 {
15450    if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI != NULLP)
15451    {
15452       if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
15453       {
15454          if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
15455          {
15456             free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
15457          }
15458          free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
15459       }
15460       free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI);
15461    }
15462 }
15463 /*******************************************************************
15464  *
15465  * @brief Deallocating the memory allocated by the aper decoder
15466  *          for UlTnlInfoforDrb
15467  *
15468  * @details
15469  *
15470  *    Function : freeAperDecodeUlTnlInfoforDrbSetupMod 
15471  *
15472  *    Functionality:  Deallocating memory allocated for UlTnlInfoforDrb
15473  *
15474  * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
15475  *
15476  * @return void
15477  *
15478  * ****************************************************************/
15479 void freeAperDecodeUlTnlInfoforDrbSetupMod(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
15480 {
15481    uint8_t arrIdx =0;
15482
15483    if(ulInfo->list.array)
15484    {
15485       for(arrIdx=0; arrIdx<ulInfo->list.count ; arrIdx++)
15486       {
15487          if(ulInfo->list.array[arrIdx])
15488          {
15489             if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel )
15490             {
15491                if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf)
15492                {
15493                   if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf)
15494                   {
15495                      free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
15496                            gTP_TEID.buf);
15497                   }
15498                   free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
15499                         transportLayerAddress.buf);
15500                }
15501                free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel);
15502             }
15503             free(ulInfo->list.array[arrIdx]);
15504          }
15505       }
15506       free(ulInfo->list.array);
15507    }
15508 }
15509 /*******************************************************************
15510  *
15511  * @brief Deallocating the memory allocated by the aper decoder
15512  *          for DrbSetupModItem  
15513  *
15514  * @details
15515  *
15516  *    Function : freeAperDecodeDrbSetupModItem 
15517  *
15518  *    Functionality:  Deallocating memory allocated for DrbSetupModItem
15519  *
15520  * @params[in] DRBs_ToBeSetupMod_Item_t *drbItem
15521  *
15522  * @return void
15523  *
15524  * ****************************************************************/
15525
15526 void freeAperDecodeDrbSetupModItem(DRBs_ToBeSetupMod_Item_t *drbItem)
15527 {
15528    uint8_t arrIdx =0;
15529    SNSSAI_t *snssai =NULLP;
15530    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
15531
15532    drbItem->qoSInformation.present = QoSInformation_PR_choice_extension;
15533    switch(drbItem->qoSInformation.present)
15534    {
15535       case QoSInformation_PR_NOTHING:
15536          break;
15537       case QoSInformation_PR_eUTRANQoS:
15538          {
15539             if(drbItem->qoSInformation.choice.eUTRANQoS)
15540             {
15541                free(drbItem->qoSInformation.choice.eUTRANQoS);
15542             }
15543             break;
15544          }
15545       case QoSInformation_PR_choice_extension:
15546          {
15547             if(drbItem->qoSInformation.choice.choice_extension)
15548             {
15549                freeAperDecodeQosInfo(&drbItem->qoSInformation.choice.choice_extension->value.choice.\
15550                      DRB_Information.dRB_QoS);
15551                snssai = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI;
15552                if(snssai->sST.buf)
15553                {
15554                   free(snssai->sST.buf);
15555                }
15556                if(snssai->sD)
15557                {
15558                   if(snssai->sD->buf)
15559                   {
15560                      free(snssai->sD->buf);
15561                   }
15562                   free(snssai->sD);
15563                }
15564
15565                flowMap = &drbItem->qoSInformation.choice.choice_extension->value.choice.\
15566                          DRB_Information.flows_Mapped_To_DRB_List;
15567                if(flowMap->list.array)
15568                {
15569                   for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
15570                   {
15571                      if(flowMap->list.array[arrIdx] )
15572                      {
15573                         freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
15574                         free(flowMap->list.array[arrIdx]);
15575                      }
15576                   }
15577                   free(flowMap->list.array);
15578                }
15579
15580                free(drbItem->qoSInformation.choice.choice_extension);
15581             }
15582             break;
15583          }
15584
15585    }
15586    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
15587    if(drbItem->uLConfiguration)
15588    {
15589       free(drbItem->uLConfiguration);
15590    }
15591 }
15592
15593 /*******************************************************************
15594  *
15595  * @brief Deallocating the memory allocated by the aper decoder
15596  *          for DrbToBeSetupModList
15597  *
15598  * @details
15599  *
15600  *    Function : freeAperDecodeDrbToBeSetupModList
15601  *
15602  *    Functionality:  Deallocating memory allocated for DrbToBeSetupModList
15603  *
15604  * @params[in] DRBs_ToBeSetupMod_List_t *drbSet
15605  *
15606  * @return void
15607  *
15608  * ****************************************************************/
15609
15610 void freeAperDecodeDrbToBeSetupModList(DRBs_ToBeSetupMod_List_t *drbSet)
15611 {
15612    uint8_t arrIdx =0;
15613    struct DRBs_ToBeSetupMod_ItemIEs *drbItemIe;
15614
15615    if(drbSet->list.array)
15616    {
15617       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
15618       {
15619          if(drbSet->list.array[arrIdx] != NULLP)
15620          {
15621             if(arrIdx == 0)
15622             {
15623                drbItemIe = (DRBs_ToBeSetupMod_ItemIEs_t *)drbSet->list.array[arrIdx];
15624                freeAperDecodeDrbSetupModItem(&(drbItemIe->value.choice.DRBs_ToBeSetupMod_Item));
15625             }
15626             free(drbSet->list.array[arrIdx]);
15627          }
15628       }
15629       free(drbSet->list.array);
15630    }
15631
15632 }
15633 /*******************************************************************
15634  *
15635  * @brief Deallocating the memory allocated by the aper decoder
15636  *          for UeContextModificationReqMsg
15637  *
15638  * @details
15639  *
15640  *    Function : freeAperDecodeUeContextModificationReqMsg
15641  *
15642  *    Functionality:  Deallocating memory allocated for
15643  *                  UeContextModificationReqMsg
15644  *
15645  * @params[in] UEContextModificationRequest_t *UeContextModifyReq
15646  *
15647  * @return void
15648  *
15649  * ****************************************************************/
15650 void freeAperDecodeUeContextModificationReqMsg(UEContextModificationRequest_t *ueContextModifyReq )
15651 {
15652    uint8_t arrIdx, ieId;
15653
15654    if(ueContextModifyReq->protocolIEs.list.array)
15655    {
15656       for( arrIdx = 0 ; arrIdx<ueContextModifyReq->protocolIEs.list.count ; arrIdx++)
15657       {
15658          if(ueContextModifyReq->protocolIEs.list.array[arrIdx])
15659          {
15660             ieId = ueContextModifyReq->protocolIEs.list.array[arrIdx]->id;
15661             switch(ieId)
15662             {
15663                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15664                   break;
15665                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15666                   break;
15667                case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
15668                   {
15669                      freeAperDecodeDrbToBeSetupModList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
15670                            value.choice.DRBs_ToBeSetupMod_List);
15671                      break;
15672                   }
15673                case ProtocolIE_ID_id_TransmissionActionIndicator:
15674                   break;
15675                case ProtocolIE_ID_id_RRCContainer:
15676                   {
15677                      free(ueContextModifyReq->protocolIEs.list.array[arrIdx]->value.choice.RRCContainer.buf);
15678                   }
15679             }
15680             free(ueContextModifyReq->protocolIEs.list.array[arrIdx]);
15681          }
15682       }
15683       free(ueContextModifyReq->protocolIEs.list.array);
15684    }
15685 }
15686 /*******************************************************************
15687  *
15688  * @brief processing the F1 UeContextModificationReq
15689  *
15690  * @details
15691  *
15692  *    Function : procF1UeContextModificationReq
15693  *
15694  *    Functionality:  processing the F1 UeContextModificationReq
15695  *
15696  * @params[in] F1AP_PDU_t *f1apMsg
15697  *
15698  * @return
15699  * ****************************************************************/
15700 uint8_t procF1UeContextModificationReq(F1AP_PDU_t *f1apMsg)
15701 {
15702    UEContextModificationRequest_t *ueContextModifyReq = NULLP;
15703    uint8_t  ret = ROK, ieIdx = 0, cellIdx=0;
15704    DuUeCb   *duUeCb = NULLP;
15705    DRBs_ToBeSetupMod_List_t *drbSetupModCfg;
15706    DRBs_ToBeModified_List_t *drbModifiedCfg;
15707    uint32_t gnbCuUeF1apId, gnbDuUeF1apId;
15708
15709    ueContextModifyReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextModificationRequest;
15710    for(ieIdx=0; (ieIdx < ueContextModifyReq->protocolIEs.list.count && ret == ROK); ieIdx++)
15711    {
15712       switch(ueContextModifyReq->protocolIEs.list.array[ieIdx]->id)
15713       {
15714          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15715             {
15716                gnbCuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
15717                break;
15718             }
15719          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15720             {
15721                gnbDuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
15722                for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
15723                {
15724                   if(duCb.actvCellLst[cellIdx])
15725                   {
15726                      if((duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbDuUeF1apId == gnbDuUeF1apId)&&\
15727                            (duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbCuUeF1apId == gnbCuUeF1apId))
15728                      {
15729                         duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1];
15730                         if(duUeCb->f1UeDb == NULLP)
15731                         {
15732                            DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
15733                            duUeCb->f1UeDb->cellIdx = cellIdx;
15734                            duUeCb->f1UeDb->actionType = UE_CTXT_MOD;
15735                         }
15736                         break;
15737                      }
15738                   }
15739                }
15740                if(duUeCb == NULLP)
15741                {
15742                   DU_LOG("\nERROR  -->  DU APP : wrong values of gnbCuUeF1apId and gnbDuUeF1apId ");
15743                   ret = RFAILED;
15744                }
15745                break;
15746             }
15747
15748          case ProtocolIE_ID_id_RRCContainer:
15749             {
15750                /* Filling Dl RRC Msg Info */
15751                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
15752                if(!duUeCb->f1UeDb->dlRrcMsg)
15753                {
15754                   DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
15755                         Memory allocation failed ");
15756                   ret = RFAILED;
15757                }
15758                else
15759                {
15760                   duUeCb->f1UeDb->dlRrcMsgPres = true;
15761                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
15762                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
15763                         &ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
15764                         value.choice.RRCContainer);
15765                }
15766
15767                break;
15768             }
15769
15770          case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
15771          case ProtocolIE_ID_id_DRBs_ToBeModified_List:
15772             {
15773                if(duUeCb->f1UeDb)
15774                {
15775                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present ==\
15776                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List)
15777                   {
15778                      drbSetupModCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
15779                                       choice.DRBs_ToBeSetupMod_List;
15780
15781                      if(extractDrbListToSetupMod(NULL, drbSetupModCfg, NULL, drbSetupModCfg->list.count,\
15782                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULL))
15783                      {
15784                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbSetupModList");
15785                         ret = RFAILED;
15786                      }
15787                   }
15788
15789                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
15790                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List)
15791
15792                   {
15793                      drbModifiedCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
15794                                       choice.DRBs_ToBeModified_List;
15795                      if(extractDrbListToSetupMod(NULL, NULL, drbModifiedCfg, drbModifiedCfg->list.count,\
15796                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, &duUeCb->rlcUeCfg))
15797                      {
15798                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
15799                         ret = RFAILED;
15800                      }
15801                   }
15802                }
15803                break;
15804             }
15805
15806          case ProtocolIE_ID_id_GNB_DUConfigurationQuery:
15807             {
15808                DU_LOG("\nINFO  -->  DU APP : Received GNB DU Configuration Query in UE Context Modification Request from CU");
15809                if(duUeCb->f1UeDb)
15810                {
15811                   duUeCb->f1UeDb->actionType = UE_CTXT_CFG_QUERY;
15812                }
15813                break;
15814             }
15815
15816          case ProtocolIE_ID_id_RRCReconfigurationCompleteIndicator:
15817             {
15818                if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.RRCReconfigurationCompleteIndicator == \
15819                   RRCReconfigurationCompleteIndicator_true)
15820                {
15821                   duUeCb->f1UeDb->actionType = UE_CTXT_RRC_RECFG_COMPLETE;
15822                }
15823                break;
15824             }
15825          case ProtocolIE_ID_id_TransmissionActionIndicator:
15826             {
15827                if(duUeCb->f1UeDb)
15828                {
15829                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.TransmissionActionIndicator  == TransmissionActionIndicator_stop)
15830                   {
15831                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = STOP_TRANSMISSION; 
15832                   }
15833                   else 
15834                   {
15835                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = RESTART_TRANSMISSION; 
15836                   }
15837                }
15838                break;
15839             }
15840
15841          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15842             {
15843                if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
15844                {
15845                   duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
15846                }
15847                break;
15848             }
15849               
15850       }
15851    }
15852
15853    if(ret != RFAILED) 
15854    {
15855       ret = duProcUeContextModReq(duUeCb);
15856    }
15857    freeAperDecodeUeContextModificationReqMsg(ueContextModifyReq);
15858    return ret; 
15859 }
15860
15861 /*****************************************************************i
15862 *
15863 * @brief Free memory allocated for UE Context Release Request
15864 *
15865 * @details
15866 *
15867 *    Function : FreeUeContextReleaseReq
15868 *
15869 *    Functionality:
15870 *         - Free memory allocated for UE Context Release Request
15871 *
15872 * @params[in] F1AP_PDU_t *f1apMsg
15873 * @return void 
15874 *
15875 * *************************************************************/
15876 void FreeUeContextReleaseReq(F1AP_PDU_t *f1apMsg)
15877 {
15878    uint8_t ieIdx;
15879    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
15880    
15881    if(f1apMsg)
15882    {
15883       if(f1apMsg->choice.initiatingMessage)
15884       {
15885          ueReleaseReq =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
15886          if(ueReleaseReq->protocolIEs.list.array)
15887          {
15888             for(ieIdx=0 ; ieIdx<ueReleaseReq->protocolIEs.list.count; ieIdx++)
15889             {
15890                DU_FREE(ueReleaseReq->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseRequest_t));
15891             }
15892             DU_FREE(ueReleaseReq->protocolIEs.list.array, ueReleaseReq->protocolIEs.list.size);
15893          }
15894          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
15895       }
15896       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
15897    }
15898
15899 }
15900 /*****************************************************************i
15901 *
15902 * @brief Build and Send UE Context Release Request  
15903 *
15904 * @details
15905 *
15906 *    Function : BuildAndSendUeContextReleaseReq
15907 *
15908 *    Functionality:
15909 *         - Build and Send UE Context Release Request 
15910 *
15911 * @params[in]
15912 * @return ROK     - success
15913 *         RFAILED - failure
15914 *
15915 * *************************************************************/
15916 uint8_t BuildAndSendUeContextReleaseReq(uint16_t cellId, uint8_t ueId)
15917 {
15918    bool memAllocFail = false;
15919    uint8_t ieIdx =0;
15920    uint8_t ret = RFAILED;
15921    uint16_t cellIdx =0;
15922    uint16_t crnti = 0;
15923    uint8_t  elementCnt = 0;
15924    uint32_t  gnbCuUeF1apId =0;   /* gNB-CU UE F1AP Id */
15925    uint32_t  gnbDuUeF1apId =0;   /* gNB-DU UE F1AP Id */
15926    asn_enc_rval_t encRetVal; 
15927    F1AP_PDU_t *f1apMsg = NULLP;
15928    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
15929
15930    DU_LOG("\nINFO  --> Building the UE Context Release Request");
15931    do
15932    {
15933       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15934       if(f1apMsg == NULLP)
15935       {
15936          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for f1apMsg");
15937          break;
15938       }
15939
15940       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
15941       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
15942       if(f1apMsg->choice.initiatingMessage == NULLP)
15943       {
15944          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for\
15945          initiatingMessage");   
15946          break;
15947       }
15948       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_UEContextReleaseRequest;
15949       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
15950       f1apMsg->choice.initiatingMessage->value.present = \
15951       InitiatingMessage__value_PR_UEContextReleaseRequest;
15952
15953       ueReleaseReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
15954
15955       elementCnt = 2;
15956
15957       ueReleaseReq->protocolIEs.list.count = elementCnt;
15958       ueReleaseReq->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseRequest_t *);
15959
15960       /* Initialize the F1Setup members */
15961       DU_ALLOC(ueReleaseReq->protocolIEs.list.array,ueReleaseReq->protocolIEs.list.size);
15962       if(ueReleaseReq->protocolIEs.list.array == NULLP)
15963       {
15964          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE array");
15965          break;
15966       }
15967       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
15968       {
15969          DU_ALLOC(ueReleaseReq->protocolIEs.list.array[ieIdx],\
15970                sizeof(UEContextReleaseRequest_t));
15971          if(ueReleaseReq->protocolIEs.list.array[ieIdx] == NULLP)
15972          {
15973             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE elements");
15974             memAllocFail = true;  
15975             break;
15976          }
15977       }
15978       if(memAllocFail == true)
15979          break;
15980
15981       /* Fetching Ue Cb Info*/
15982       GET_CELL_IDX(cellId, cellIdx);
15983       if(duCb.actvCellLst[cellIdx] == NULLP)
15984       {
15985          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): CellId[%d] does not exist", cellId);
15986          break;
15987       }
15988       else
15989       {
15990          GET_CRNTI(crnti, ueId);
15991          if(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].crnti != crnti)
15992          {
15993             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): crnti[%d] does not exist", crnti);
15994             break;
15995          }
15996          gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
15997          gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
15998       }
15999
16000       ieIdx=0; 
16001       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID; 
16002       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16003       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present = \
16004       UEContextReleaseRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
16005       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
16006       
16007       ieIdx++;
16008       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16009       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16010       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present =\
16011       UEContextReleaseRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
16012       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
16013       
16014       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16015
16016       /* Encode the F1SetupRequest type as APER */
16017       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16018       encBufSize = 0;
16019       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
16020       /* Encode results */
16021       if(encRetVal.encoded == ENCODE_FAIL)
16022       {
16023          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseRequest structure (at %s)\n",\
16024                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16025          break;
16026       }
16027       else
16028       {
16029          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseRequest\n");
16030          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
16031          {
16032             printf("%x",encBuf[ieIdx]);
16033          }
16034       }
16035
16036       /* Sending msg */
16037       if(sendF1APMsg() != ROK)
16038       {
16039          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Request failed");
16040          break;
16041       }
16042       ret = ROK;
16043       break;
16044    }while(true);
16045
16046    FreeUeContextReleaseReq(f1apMsg);
16047    return ret;
16048 }
16049 /*****************************************************************i
16050  *
16051  * @brief Free memory allocated for UE Context Release Complete
16052  *
16053  * @details
16054  *
16055  *    Function : FreeUeContextReleaseComplete
16056  *
16057  *    Functionality:
16058  *         - Free memory allocated for UE Context Release Complete
16059  *
16060  * @params[in] F1AP_PDU_t *f1apMsg
16061  * @return void
16062  *
16063  * *************************************************************/
16064 void FreeUeContextReleaseComplete(F1AP_PDU_t *f1apMsg)
16065 {
16066    uint8_t ieIdx;
16067    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
16068
16069    if(f1apMsg)
16070    {
16071       if(f1apMsg->choice.successfulOutcome)
16072       {
16073          ueReleaseComplete =&f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
16074          if(ueReleaseComplete->protocolIEs.list.array)
16075          {
16076             for(ieIdx=0 ; ieIdx<ueReleaseComplete->protocolIEs.list.count; ieIdx++)
16077             {
16078                DU_FREE(ueReleaseComplete->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseComplete_t));
16079             }
16080             DU_FREE(ueReleaseComplete->protocolIEs.list.array, ueReleaseComplete->protocolIEs.list.size);
16081          }
16082          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16083       }
16084       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
16085    }
16086
16087 }
16088 /*****************************************************************i
16089  *
16090  * @brief Build and Send UE Context Release Complete
16091  *
16092  * @details
16093  *
16094  *    Function : BuildAndSendUeContextReleaseComplete
16095  *
16096  *    Functionality:
16097  *         - Build and Send UE Context Release Complete
16098  *
16099  * @params[in]  cellId,  gnbCuUeF1apId, gnbDuUeF1apId
16100  * @return ROK     - success
16101  *         RFAILED - failure
16102  *
16103  * *************************************************************/
16104 uint8_t BuildAndSendUeContextReleaseComplete(uint16_t cellId, uint32_t gnbCuUeF1apId, uint32_t gnbDuUeF1apId)
16105 {
16106    bool memAllocFail = false;
16107    uint8_t ieIdx =0, ret = RFAILED, elementCnt = 0;
16108    asn_enc_rval_t encRetVal;
16109    F1AP_PDU_t *f1apMsg = NULLP;
16110    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
16111
16112    DU_LOG("\nINFO  --> Building the UE Context Release Complete");
16113    do
16114    {
16115       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
16116       if(f1apMsg == NULLP)
16117       {
16118          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for f1apMsg");
16119          break;
16120       }
16121
16122       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
16123       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16124       if(f1apMsg->choice.successfulOutcome == NULLP)
16125       {
16126          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for\
16127                successfulOutcome");
16128          break;
16129       }
16130       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextRelease;
16131       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
16132       f1apMsg->choice.successfulOutcome->value.present = \
16133       SuccessfulOutcome__value_PR_UEContextReleaseComplete;
16134
16135       ueReleaseComplete = &f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
16136
16137       elementCnt = 2;
16138       ueReleaseComplete->protocolIEs.list.count = elementCnt;
16139       ueReleaseComplete->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseComplete_t *);
16140
16141       /* Initialize the UE Release Complete members */
16142       DU_ALLOC(ueReleaseComplete->protocolIEs.list.array,ueReleaseComplete->protocolIEs.list.size);
16143       if(ueReleaseComplete->protocolIEs.list.array == NULLP)
16144       {
16145          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE array");
16146          break;
16147       }
16148       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
16149       {
16150          DU_ALLOC(ueReleaseComplete->protocolIEs.list.array[ieIdx],\
16151                sizeof(UEContextReleaseComplete_t));
16152          if(ueReleaseComplete->protocolIEs.list.array[ieIdx] == NULLP)
16153          {
16154             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE\
16155             elements");
16156             memAllocFail = true;
16157             break;
16158          }
16159       }
16160       if(memAllocFail == true)
16161          break;
16162
16163
16164       ieIdx=0;
16165       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
16166       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16167       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present = \
16168       UEContextReleaseCompleteIEs__value_PR_GNB_CU_UE_F1AP_ID;
16169       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
16170
16171       ieIdx++;
16172       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16173       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16174       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present =\
16175       UEContextReleaseCompleteIEs__value_PR_GNB_DU_UE_F1AP_ID;
16176       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
16177
16178       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16179
16180       /* Encode the F1SetupComplete type as APER */
16181       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16182       encBufSize = 0;
16183       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
16184       /* Encode results */
16185       if(encRetVal.encoded == ENCODE_FAIL)
16186       {
16187          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseComplete structure (at %s)\n",\
16188                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16189          break;
16190       }
16191       else
16192       {
16193          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseComplete\n");
16194          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
16195          {
16196             printf("%x",encBuf[ieIdx]);
16197          }
16198       }
16199
16200       /* Sending msg */
16201       if(sendF1APMsg() != ROK)
16202       {
16203          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Complete failed");
16204          break;
16205       }
16206       ret = ROK;
16207       break;
16208    }while(true);
16209    
16210    if((ret == ROK) && (duCb.actvCellLst[cellId-1]) && (duCb.actvCellLst[cellId-1]->cellStatus == DELETION_IN_PROGRESS) 
16211          && (duCb.actvCellLst[cellId-1]->numActvUes == 0))
16212    {
16213       ret = duSendCellDeletReq(cellId);
16214       if(ret != ROK)
16215       {
16216          DU_LOG("\nERROR  -->  F1AP: BuildAndSendUeContextReleaseComplete(): Failed to process cell\
16217                Delete req for CellId");
16218       }
16219    }
16220    FreeUeContextReleaseComplete(f1apMsg);
16221    return ret;
16222
16223 }
16224
16225 /*******************************************************************
16226 *
16227 * @brief added free part for the memory allocated by aper_decoder 
16228 *
16229 * @details
16230 *
16231 *    Function : freeAperDecodeUeContextReleaseCommand 
16232 *
16233 *    Functionality: added free part for the memory allocated by aper_decoder
16234 *
16235 * @params[in] F1AP_PDU_t *f1apMsg
16236 * @return void
16237 *
16238 * ****************************************************************/
16239 void freeAperDecodeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
16240 {
16241    uint8_t ieIdx=0;
16242    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
16243
16244    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
16245    
16246    if(ueContextReleaseCommand->protocolIEs.list.array)
16247    {
16248       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
16249       {
16250          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
16251          {
16252             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
16253             {
16254                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16255                   break;
16256                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16257                   break;
16258                case ProtocolIE_ID_id_Cause:
16259                   break;
16260                case ProtocolIE_ID_id_RRCContainer:
16261                {
16262                   if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
16263                   {
16264                      free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
16265                   }
16266                   break;
16267                }
16268                default :
16269                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
16270                        ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
16271                   break;
16272             }
16273          }
16274          free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]);
16275       }
16276       free(ueContextReleaseCommand->protocolIEs.list.array);
16277    }
16278 }
16279 /*******************************************************************
16280 *
16281 * @brief processing of UE Context Release Command
16282 *
16283 * @details
16284 *
16285 *    Function : procF1UeContextReleaseCommand 
16286 *
16287 *    Functionality: processing of UE Context Release Command
16288 *
16289 * @params[in] F1AP_PDU_t *f1apMsg
16290 * @return void
16291 *
16292 * ****************************************************************/
16293 uint8_t procF1UeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
16294 {
16295    uint8_t  ieIdx=0, ret=ROK, ueIdx=0;
16296    uint16_t cellIdx =0, cellId = 0;
16297    bool ueIdxFound = false;
16298    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0;
16299    DuUeCb   *duUeCb = NULLP;
16300    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
16301
16302    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
16303
16304    if(ueContextReleaseCommand->protocolIEs.list.array)
16305    {
16306       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
16307       {
16308          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
16309          {
16310             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
16311             {
16312                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16313                   {
16314                      gnbCuUeF1apId= ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
16315                                     value.choice.GNB_CU_UE_F1AP_ID;
16316                      break;
16317                   }
16318
16319                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16320                   {
16321                      gnbDuUeF1apId = ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
16322                                      value.choice.GNB_DU_UE_F1AP_ID;
16323                      break;
16324                   }
16325
16326                case ProtocolIE_ID_id_Cause:
16327                   {
16328                      for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
16329                      {
16330                         for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
16331                         {
16332                            if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
16333                                  (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId))
16334                            {
16335                               cellId = duCb.actvCellLst[cellIdx]->cellId;
16336                               duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
16337                               ueIdxFound = true;
16338                               break;
16339                            }
16340                         }
16341                         if(ueIdxFound == true)
16342                         {
16343                            break;
16344                         }
16345                      }
16346                      
16347                      if(!ueIdxFound)
16348                      {
16349                         DU_LOG("\nERROR  -->  F1AP: procF1UeContextReleaseCommand(): Ue Information is not available");
16350                         ret = RFAILED;
16351                      }
16352                      break;
16353                   }
16354
16355                case ProtocolIE_ID_id_RRCContainer:
16356                   {
16357                      if(ueIdxFound == true)  
16358                      {
16359                         DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
16360                         if(duUeCb->f1UeDb)
16361                         {
16362                            memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
16363                            duUeCb->f1UeDb->actionType = UE_CTXT_RELEASE;
16364                            duUeCb->f1UeDb->cellIdx = cellIdx;
16365                            /* Filling Dl RRC Msg Info */
16366                            DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
16367                            if(!duUeCb->f1UeDb->dlRrcMsg)
16368                            {
16369                               DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16370                                     Memory allocation failed ");
16371                               ret = RFAILED;
16372                            }
16373                            else
16374                            {
16375                               duUeCb->f1UeDb->dlRrcMsgPres = true;
16376                               memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
16377                               ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
16378                                     &ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
16379                                     value.choice.RRCContainer);
16380                            }
16381
16382                         }
16383                         else
16384                         {
16385                            DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16386                                  Memory allocation failed ");
16387                            ret = RFAILED;
16388
16389                         }
16390                      }
16391                      break;
16392                   }
16393                default :
16394                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
16395                         ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
16396                   break;
16397             }
16398          }
16399       }
16400    }
16401    if(ret != RFAILED)
16402    {
16403       duProcUeContextReleaseCommand(cellId, duUeCb);
16404    }
16405    freeAperDecodeUeContextReleaseCommand(f1apMsg);
16406    return ret;
16407 }
16408
16409 /**************************************************************
16410  *
16411  * @brief free the memory allocated by aper decoder for paging
16412  *
16413  * @details
16414  *
16415  *    Function : freeAperDecodePagingMsg
16416  *
16417  *    Functionality:
16418  *         - free the memory allocated by aper decoder for
16419  *         the paging f1ap msg
16420  *
16421  * @params[in] Paging_t   *paging
16422  * @return ROK     - success
16423  *         RFAILED - failure
16424  *
16425  ****************************************************************/
16426 void freeAperDecodePagingMsg(Paging_t   *paging)
16427 {
16428    uint8_t ieIdx, cellIdx;
16429    PagingCell_ItemIEs_t *pagingCellItemIes;
16430    PagingCell_Item_t *pagingCellItem;
16431    PagingCell_list_t  *pagingCelllist;
16432
16433    if(paging)
16434    {
16435       if(paging->protocolIEs.list.array)
16436       {
16437          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
16438          {
16439             if(paging->protocolIEs.list.array[ieIdx])
16440             {
16441                switch(paging->protocolIEs.list.array[ieIdx]->id)
16442                {
16443                   case ProtocolIE_ID_id_UEIdentityIndexValue:
16444                      {
16445                         free(paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10.buf);
16446                         break;
16447                      }
16448                   case ProtocolIE_ID_id_PagingIdentity:
16449                      {
16450                         if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present == PagingIdentity_PR_cNUEPagingIdentity)
16451                         {
16452                            if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)
16453                            {
16454                               if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->present == \
16455                                     CNUEPagingIdentity_PR_fiveG_S_TMSI)
16456                               {
16457                                  free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->choice.fiveG_S_TMSI.buf);
16458                               }
16459                               free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity);
16460                            }
16461                         }
16462                         break;
16463                      }
16464                   case ProtocolIE_ID_id_PagingCell_List:
16465                      {
16466                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list;
16467                         if(pagingCelllist->list.array)
16468                         {
16469                            for(cellIdx = 0; cellIdx < pagingCelllist->list.count; cellIdx++)
16470                            {
16471                               if(pagingCelllist->list.array[cellIdx])
16472                               {
16473                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellIdx];
16474                                  if(pagingCellItemIes->id == ProtocolIE_ID_id_PagingCell_Item)
16475                                  {
16476                                     pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
16477                                     free(pagingCellItem->nRCGI.pLMN_Identity.buf);
16478                                     free(pagingCellItem->nRCGI.nRCellIdentity.buf);
16479                                  }
16480                                  free(pagingCelllist->list.array[cellIdx]);
16481                               }
16482                            }
16483                            free(pagingCelllist->list.array);
16484                         }
16485                         break;
16486                      }
16487                }
16488                free(paging->protocolIEs.list.array[ieIdx]);
16489             }
16490          }
16491          free(paging->protocolIEs.list.array);
16492
16493       }
16494    }
16495 }
16496
16497 /**************************************************************
16498  *
16499  * @brief processing the paging f1ap msg received from CU 
16500  *
16501  * @details
16502  *
16503  *    Function : procPagingMsg
16504  *
16505  *    Functionality:
16506  *         - processing the paging f1ap msg received from CU
16507  *
16508  * @params[in] F1AP_PDU_t *f1apMsg
16509  * @return ROK     - success
16510  *         RFAILED - failure
16511  *
16512  *
16513  ****************************************************************/
16514 uint8_t procPagingMsg(F1AP_PDU_t *f1apMsg) 
16515 {
16516    uint8_t ieIdx = 0, cellListIdx = 0;
16517    uint64_t cellId = 0;
16518    Paging_t   *paging = NULLP;
16519    PagingCell_list_t  *pagingCelllist = NULLP;
16520    PagingCell_ItemIEs_t *pagingCellItemIes = NULLP;
16521    PagingCell_Item_t *pagingCellItem = NULLP;
16522    DuPagingMsg *tmpPagingParam = NULLP;
16523
16524    DU_LOG("\nINFO  --> DU APP : Processing the Paging Message");
16525    paging = &f1apMsg->choice.initiatingMessage->value.choice.Paging;
16526    if(paging)
16527    {
16528       if(paging->protocolIEs.list.array)
16529       {
16530          DU_ALLOC(tmpPagingParam, sizeof(DuPagingMsg));
16531          if(tmpPagingParam == NULLP)
16532          {
16533             DU_LOG("\nERROR  --> DU APP : Memory Allocation Failure in procPagingMsg");
16534             freeAperDecodePagingMsg(paging);
16535             return RFAILED;
16536          }
16537          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
16538          {
16539             if(paging->protocolIEs.list.array[ieIdx])
16540             {
16541                switch(paging->protocolIEs.list.array[ieIdx]->id)
16542                {
16543                   case ProtocolIE_ID_id_UEIdentityIndexValue:
16544                      {
16545                         bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10,\
16546                                          &tmpPagingParam->pagUeId);
16547                         break;
16548                      }
16549
16550                   case ProtocolIE_ID_id_PagingIdentity:
16551                      {
16552                         switch(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present)
16553                         {
16554                            case PagingIdentity_PR_cNUEPagingIdentity: 
16555                               {
16556                                  if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)  
16557                                  {
16558                                     bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.\
16559                                           cNUEPagingIdentity->choice.fiveG_S_TMSI, &tmpPagingParam->sTmsi);
16560
16561                                  }
16562                                  break;
16563                               }
16564                             case PagingIdentity_PR_rANUEPagingIdentity:
16565                                {
16566                                   /*TODO: This Identifier is specific to RAN Initiated Paging â€“ Connected Mode Paging*/
16567                                   break;
16568                                }
16569                             default:
16570                                {
16571                                   DU_LOG("ERROR  -->  DU APP: Invalid UE Paging Identity, Skipping this Paging Message:");
16572                                   continue;
16573                                }
16574                         }
16575                      }
16576
16577                   case ProtocolIE_ID_id_PagingDRX:
16578                      {
16579                         tmpPagingParam->pagingDrxPres = TRUE;
16580                         tmpPagingParam->pagingDrx = convertPagingCycleEnumToValue(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingDRX);
16581                         break;
16582                      }
16583
16584                   case ProtocolIE_ID_id_PagingPriority:
16585                      {
16586                         tmpPagingParam->pagPriority = paging->protocolIEs.list.array[ieIdx]->value.choice.PagingPriority;
16587                         break;
16588                      }
16589
16590                   case ProtocolIE_ID_id_PagingCell_List:
16591                      {
16592                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list; 
16593                         if(pagingCelllist->list.array)
16594                         {
16595                            for(cellListIdx = 0; cellListIdx < pagingCelllist->list.count; cellListIdx++)
16596                            {
16597                               if(pagingCelllist->list.array[cellListIdx])
16598                               {
16599                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellListIdx];
16600                                  pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
16601                                  bitStringToInt(&pagingCellItem->nRCGI.nRCellIdentity, &cellId);
16602                                  if(processPagingMsg(cellId, tmpPagingParam) != ROK)
16603                                  {
16604                                     DU_LOG("\nERROR  --> DU APP : Paging Processing Failed at CellId:%d",cellId);
16605                                     continue;
16606                                  }
16607                               }
16608                            }
16609                         }
16610                         break;
16611                      }
16612                    default:
16613                      {
16614                          DU_LOG("\nERROR  --> F1AP : Incorrect Paging IE option");
16615                          break;
16616                      }
16617                }
16618             }
16619          }
16620       }
16621    }
16622    DU_FREE(tmpPagingParam, sizeof(DuPagingMsg));
16623    freeAperDecodePagingMsg(paging);
16624   
16625    return ROK;
16626 }
16627
16628 /**************************************************************
16629  *
16630  * @brief Handles received F1AP message and sends back response  
16631  *
16632  * @details
16633  *
16634  *    Function : F1APMsgHdlr
16635  *
16636  *    Functionality:
16637  *         - Decodes received F1AP control message
16638  *         - Prepares response message, encodes and sends to SCTP
16639  *
16640  * @params[in] 
16641  * @return ROK     - success
16642  *         RFAILED - failure
16643  *
16644  * ****************************************************************/
16645 void F1APMsgHdlr(Buffer *mBuf)
16646 {
16647    int i =0;
16648    char *recvBuf =NULLP;
16649    MsgLen copyCnt =0;
16650    MsgLen recvBufLen =0;
16651    F1AP_PDU_t *f1apMsg =NULLP;
16652    asn_dec_rval_t rval; /* Decoder return value */
16653    F1AP_PDU_t f1apasnmsg ;
16654    DU_LOG("\nINFO  -->  F1AP : Received F1AP message buffer");
16655    ODU_PRINT_MSG(mBuf, 0,0);
16656
16657    /* Copy mBuf into char array to decode it */
16658    ODU_GET_MSG_LEN(mBuf, &recvBufLen);
16659    DU_ALLOC(recvBuf, (Size)recvBufLen);
16660
16661    if(recvBuf == NULLP)
16662    {
16663       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed");
16664       return;
16665    }
16666    if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
16667    {
16668       DU_LOG("\nERROR   -->  F1AP : Failed while copying %d", copyCnt);
16669       return;
16670    }
16671
16672    printf("\nDEBUG   -->  F1AP : Received flat buffer to be decoded : ");
16673    for(i=0; i< recvBufLen; i++)
16674    {
16675       printf("%x",recvBuf[i]);
16676    }
16677
16678    /* Decoding flat buffer into F1AP messsage */
16679    f1apMsg = &f1apasnmsg;
16680    memset(f1apMsg, 0, sizeof(F1AP_PDU_t));
16681
16682    rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0);
16683
16684    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
16685    {
16686       DU_LOG("\nERROR  -->  F1AP : ASN decode failed");
16687       return;
16688    }
16689    printf("\n");
16690    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16691
16692    switch(f1apMsg->present)
16693    {
16694       case F1AP_PDU_PR_successfulOutcome:
16695          {
16696             switch(f1apMsg->choice.successfulOutcome->value.present)
16697             {
16698                case SuccessfulOutcome__value_PR_ResetAcknowledge:
16699                   {
16700                      DU_LOG("\nINFO   -->  F1AP : F1ResetAcknowledge is received successfully ");
16701                      break;
16702                   }
16703                case SuccessfulOutcome__value_PR_F1SetupResponse:
16704                   {                             
16705 #ifndef ODU_TEST_STUB
16706                      procF1SetupRsp(f1apMsg, recvBufLen, recvBuf);
16707 #endif
16708                      break;
16709                   }
16710
16711                case SuccessfulOutcome__value_PR_GNBDUConfigurationUpdateAcknowledge:
16712                   {
16713                      procF1GNBDUCfgUpdAck(f1apMsg);
16714                      break;
16715                   }
16716
16717                default:
16718                   {
16719                      DU_LOG("\nERROR  -->  F1AP : Invalid type of SuccessfulOutcome__value_PR_ResetAcknowledge [%d]",\
16720                            f1apMsg->choice.successfulOutcome->value.present);
16721                      return;
16722                   }
16723             }/* End of switch(successfulOutcome) */
16724             free(f1apMsg->choice.successfulOutcome);
16725             break;
16726          }
16727       case F1AP_PDU_PR_initiatingMessage:
16728          {
16729             switch(f1apMsg->choice.initiatingMessage->value.present)
16730             {
16731                case InitiatingMessage__value_PR_Reset:
16732                   {
16733                      procF1ResetReq(f1apMsg);
16734                      break;
16735                   }
16736                case InitiatingMessage__value_PR_DLRRCMessageTransfer:
16737                   {
16738                      procF1DlRrcMsgTrans(f1apMsg);
16739                      break;
16740                   }
16741                case InitiatingMessage__value_PR_UEContextSetupRequest:
16742                   {
16743                      procF1UeContextSetupReq(f1apMsg);
16744                      break;
16745                   }
16746                case InitiatingMessage__value_PR_UEContextModificationRequest:
16747                   {
16748                      procF1UeContextModificationReq(f1apMsg);
16749                      break;
16750                   }
16751                case InitiatingMessage__value_PR_UEContextReleaseCommand:
16752                   {
16753                       procF1UeContextReleaseCommand(f1apMsg);
16754                       break;
16755                   }
16756                case InitiatingMessage__value_PR_Paging:
16757                   {
16758                      procPagingMsg(f1apMsg);
16759                      break;
16760                   }
16761                default:
16762                   {
16763                      DU_LOG("\nERROR  -->  F1AP : Invalid type of F1AP_PDU_PR_initiatingMessage [%d]",
16764                            f1apMsg->choice.initiatingMessage->value.present);
16765                      return;
16766                   }
16767             }/* End of switch(initiatingMessage) */
16768             free(f1apMsg->choice.initiatingMessage);
16769             break;
16770          }
16771
16772       default:
16773          {
16774             DU_LOG("\nERROR  -->  F1AP : Invalid type of f1apMsg->present [%d]",f1apMsg->present);
16775             return;
16776          }
16777          free(f1apMsg);
16778
16779    }/* End of switch(f1apMsg->present) */
16780    
16781    DU_FREE(recvBuf, (Size)recvBufLen);
16782 } /* End of F1APMsgHdlr */
16783
16784 /**********************************************************************
16785   End of file
16786  **********************************************************************/