[Epic-ID: ODUHIGH-406][Task-ID: ODUHIGH-452] Documentation for Idle Mode Paging
[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             if(lcCfg->u.amCfg)
8685             {
8686                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
8687             }
8688             break;
8689          }
8690       case RLC_UM_BI_DIRECTIONAL :
8691          {
8692             if(lcCfg->u.umBiDirCfg)
8693             {
8694                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
8695             }
8696             break;
8697          }
8698       case RLC_UM_UNI_DIRECTIONAL_UL :
8699          {
8700             if(lcCfg->u.umUniDirUlCfg)
8701             {
8702                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
8703             }
8704             break;
8705
8706          }
8707       case RLC_UM_UNI_DIRECTIONAL_DL :
8708          {
8709             if(lcCfg->u.umUniDirDlCfg)
8710             {
8711                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
8712             }
8713             break;
8714          }
8715       default:
8716          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at freeRlcLcCfg()", lcCfg->rlcMode);
8717          break;
8718    }
8719    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
8720 }
8721
8722 /*******************************************************************
8723  *
8724  * @brief Function to free MacLcCfg
8725  *
8726  * @details
8727  *
8728  *    Function : freeMacLcCfg
8729  *
8730  *    Functionality: Function to free MacLcCfg
8731  *
8732  * @params[in] LcCfg *lcCfg,
8733  * @return void
8734  *
8735  * ****************************************************************/
8736
8737 void  freeMacLcCfg(LcCfg *lcCfg)
8738 {
8739     /* Deleting DRBQOS */
8740    if(lcCfg->drbQos)
8741    {
8742       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
8743    }
8744    /* Deleting SNSSAI */
8745    if(lcCfg->snssai)
8746    {
8747       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
8748    }
8749 }
8750 /*******************************************************************
8751  *
8752  * @brief Free UE NR Capability received in UE Context setup request
8753  *
8754  * @details
8755  *
8756  *    Function : freeAperDecodeUeNrCapability
8757  *
8758  *    Functionality:  
8759  *       Free UE NR Capability received in UE Context setup request
8760  *
8761  * @params[in] 
8762  * @return ROK     - success
8763  *         RFAILED - failure
8764  *
8765  * ****************************************************************/
8766 void freeAperDecodeUeNrCapability(void *ueNrCapability)
8767 {
8768    uint8_t arrIdx =0;
8769    FeatureSets_t *featureSets =NULLP;
8770    UE_NR_Capability_t *ueNrCap = (UE_NR_Capability_t *)ueNrCapability;
8771
8772    if(ueNrCap->rf_Parameters.supportedBandListNR.list.array)
8773    {
8774       for(arrIdx = 0; arrIdx < ueNrCap->rf_Parameters.supportedBandListNR.list.count; arrIdx++)
8775       {
8776          if(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx])
8777             free(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx]);
8778       }
8779       free(ueNrCap->rf_Parameters.supportedBandListNR.list.array);
8780    }
8781
8782    if(ueNrCap->featureSets)
8783    {
8784       featureSets = ueNrCap->featureSets;
8785       if(featureSets->featureSetsDownlinkPerCC)
8786       {
8787          if(featureSets->featureSetsDownlinkPerCC->list.array)
8788          {
8789             for(arrIdx = 0; arrIdx < featureSets->featureSetsDownlinkPerCC->list.count; arrIdx++)
8790             {
8791                if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx])
8792                {
8793                   if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL)
8794                      free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL);
8795                   free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]);
8796                }
8797             }
8798             free(featureSets->featureSetsDownlinkPerCC->list.array);
8799          }
8800          free(featureSets->featureSetsDownlinkPerCC);
8801       }
8802       if(featureSets->featureSetsUplinkPerCC)
8803       {
8804          if(featureSets->featureSetsUplinkPerCC->list.array)
8805          {
8806             for(arrIdx = 0; arrIdx < featureSets->featureSetsUplinkPerCC->list.count; arrIdx++)
8807             {
8808                if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx])
8809                {
8810                   if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL)
8811                      free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL);
8812                   free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]);
8813                }
8814             }
8815             free(featureSets->featureSetsUplinkPerCC->list.array);
8816          }
8817          free(featureSets->featureSetsUplinkPerCC);
8818       }
8819       free(ueNrCap->featureSets);
8820    }   
8821 }
8822
8823 /*******************************************************************
8824 *
8825 * @brief Function to free PdcchSearchSpcToAddModList
8826          where memory allocated by aper_decoder
8827 *
8828 * @details
8829 *
8830 *    Function : freeAperDecodePdcchSearchSpcToAddModList 
8831 *
8832 *    Functionality: Function to free PdcchSearchSpcToAddModList
8833 *
8834 * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
8835 * @return void
8836 *
8837 * ****************************************************************/
8838
8839 void freeAperDecodePdcchSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
8840 {
8841    uint8_t searchSpcArrIdx=0;
8842    uint8_t searchSpcArrIdx1=0;
8843    struct  SearchSpace *searchSpc=NULLP;
8844
8845
8846    if(searchSpcList->list.array)
8847    {
8848       if(searchSpcList->list.array[searchSpcArrIdx1])
8849       {
8850          searchSpc = searchSpcList->list.array[searchSpcArrIdx1];
8851          if(searchSpc->controlResourceSetId)
8852          {
8853             if(searchSpc->monitoringSlotPeriodicityAndOffset)
8854             {
8855                if(searchSpc->monitoringSymbolsWithinSlot)
8856                {
8857                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
8858                   {
8859                      if(searchSpc->nrofCandidates)
8860                      {
8861                         if(searchSpc->searchSpaceType)
8862                         {
8863                            free(searchSpc->searchSpaceType->choice.ue_Specific);
8864                            free(searchSpc->searchSpaceType);
8865                         }
8866                         free(searchSpc->nrofCandidates);
8867                      }
8868                      free(searchSpc->monitoringSymbolsWithinSlot->buf);
8869                   }
8870                   free(searchSpc->monitoringSymbolsWithinSlot);
8871                }
8872                free(searchSpc->monitoringSlotPeriodicityAndOffset);
8873             }
8874             free(searchSpc->controlResourceSetId);
8875          }
8876       }
8877       for(searchSpcArrIdx = 0; searchSpcArrIdx < searchSpcList->list.count; searchSpcArrIdx++)
8878       {
8879          free(searchSpcList->list.array[searchSpcArrIdx]);
8880       }
8881       free(searchSpcList->list.array);
8882    }
8883 }
8884 /*******************************************************************
8885 *
8886 * @brief Function for free part for the memory allocated by aper_decoder
8887
8888 * @details
8889 *
8890 *    Function : freeAperDecodeBWPDlDedPdcchConfig
8891 *
8892 *    Functionality: Function to free BWPDlDedPdcchConfig
8893 *
8894 * @params[in] 
8895 * @return void
8896 *
8897 * ****************************************************************/
8898
8899
8900 void freeAperDecodeBWPDlDedPdcchConfig(BWP_DownlinkDedicated_t *dlBwp)
8901 {
8902    uint8_t arrIdx1=0;
8903    uint8_t arrIdx2=0;
8904    struct PDCCH_Config *pdcchCfg=NULLP;
8905    struct ControlResourceSet *controlRSet=NULLP;
8906    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
8907    
8908    if(dlBwp->pdcch_Config->choice.setup)
8909    {
8910       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
8911       if(pdcchCfg->controlResourceSetToAddModList)
8912       {
8913          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
8914          if(controlRSetList->list.array)
8915          {
8916             controlRSet = controlRSetList->list.array[arrIdx2];
8917             if(controlRSet)
8918             {
8919                if(controlRSet->frequencyDomainResources.buf)
8920                {
8921                   if(controlRSet->pdcch_DMRS_ScramblingID)
8922                   {
8923                      if(pdcchCfg->searchSpacesToAddModList)
8924                      {
8925                         freeAperDecodePdcchSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
8926                         free(pdcchCfg->searchSpacesToAddModList);
8927                      }
8928                      free(controlRSet->pdcch_DMRS_ScramblingID);
8929                   }
8930                   free(controlRSet->frequencyDomainResources.buf);
8931                }
8932             }
8933             for(arrIdx1 = 0; arrIdx1 <controlRSetList->list.count; arrIdx1++)
8934             {
8935                free(controlRSetList->list.array[arrIdx1]);
8936             }
8937             free(controlRSetList->list.array);
8938          }
8939          free(pdcchCfg->controlResourceSetToAddModList);
8940       }
8941       free(dlBwp->pdcch_Config->choice.setup);
8942    }
8943 }
8944 /*******************************************************************
8945 *
8946 * @brief Function to free PdschTimeDomAllocationList 
8947 *     where the memory allocated by aper_decoder
8948
8949 * @details
8950 *
8951 *    Function : freeAperDecodePdschTimeDomAllocationList
8952 *
8953 *    Functionality: Function to free PdschTimeDomAllocationList
8954 *
8955 * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList 
8956 * @return void
8957 *
8958 * ****************************************************************/
8959
8960
8961 void freeAperDecodePdschTimeDomAllocationList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
8962 {
8963    uint8_t arrIdx=0;
8964
8965    if(timeDomAllocList->choice.setup)
8966    {
8967       if(timeDomAllocList->choice.setup->list.array)
8968       {
8969          for(arrIdx = 0; arrIdx <timeDomAllocList->choice.setup->list.count ; arrIdx++)
8970          {
8971             free(timeDomAllocList->choice.setup->list.array[arrIdx]);
8972          }
8973          free(timeDomAllocList->choice.setup->list.array);
8974       }
8975       free(timeDomAllocList->choice.setup);
8976    }
8977 }
8978
8979 /*******************************************************************
8980 *
8981 * @brief Function to free BWPDlDedPdschConfig 
8982 *        where the memory allocated by aper_decoder
8983 *  
8984 * @details
8985 *
8986 *    Function : freeAperDecodeBWPDlDedPdschConfig 
8987 *
8988 *    Functionality: Function to free BWPDlDedPdschConfig 
8989 *
8990 * @params[in] BWP_DownlinkDedicated_t *dlBwp 
8991 * @return void
8992 *
8993 * ****************************************************************/
8994
8995
8996 void freeAperDecodeBWPDlDedPdschConfig(BWP_DownlinkDedicated_t *dlBwp)
8997 {
8998    struct PDSCH_Config *pdschCfg=NULLP;
8999    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
9000    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
9001    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
9002
9003    if(dlBwp->pdsch_Config->choice.setup)
9004    {
9005       pdschCfg=dlBwp->pdsch_Config->choice.setup;
9006       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
9007       {
9008          if(pdschCfg->pdsch_TimeDomainAllocationList)
9009          {
9010             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
9011             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
9012             {
9013                prbBndlType=&pdschCfg->prb_BundlingType;
9014                free(prbBndlType->choice.staticBundling);
9015                free(pdschCfg->maxNrofCodeWordsScheduledByDCI);
9016             }
9017             freeAperDecodePdschTimeDomAllocationList(timeDomAllocList);
9018             free(pdschCfg->pdsch_TimeDomainAllocationList);
9019          }
9020          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
9021          if(dmrsDlCfg->choice.setup)
9022          {
9023             free(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition);
9024             free(dmrsDlCfg->choice.setup);
9025          }
9026          free(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA);
9027       }
9028       free(dlBwp->pdsch_Config->choice.setup);
9029    }
9030 }
9031 /*******************************************************************
9032 *
9033 * @brief Function to free PuschTimeDomAllocListCfg
9034                  where the memory allocated by aper_decoder
9035 *
9036 * @details
9037 *
9038 *    Function : freeAperDecodePuschTimeDomAllocListCfg
9039 *
9040 *    Functionality: Function to free PuschTimeDomAllocListCfg
9041 *
9042 * @params[in] PUSCH_Config_t *puschCfg 
9043 * @return void
9044 *
9045 * ****************************************************************/
9046
9047
9048 void freeAperDecodePuschTimeDomAllocListCfg(PUSCH_Config_t *puschCfg)
9049 {
9050    uint8_t arrIdx=0;
9051    uint8_t arrIdx1=0;
9052    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
9053
9054    if(puschCfg->pusch_TimeDomainAllocationList)
9055    {
9056       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
9057       if(timeDomAllocList_t->choice.setup)
9058       {
9059          if(timeDomAllocList_t->choice.setup->list.array)
9060          {
9061             free(timeDomAllocList_t->choice.setup->list.array[arrIdx1]->k2);
9062             for(arrIdx = 0; arrIdx<timeDomAllocList_t->choice.setup->list.count; arrIdx++)
9063             {
9064                free(timeDomAllocList_t->choice.setup->list.array[arrIdx]);
9065             }
9066             free(timeDomAllocList_t->choice.setup->list.array);
9067          }
9068          free(timeDomAllocList_t->choice.setup);
9069       }
9070       free(puschCfg->transformPrecoder);
9071       free(puschCfg->pusch_TimeDomainAllocationList);
9072    }
9073 }
9074 /*******************************************************************
9075 *
9076 * @brief Function to free InitialUlBWPConfig where memory allocated by aper_decoder
9077 *
9078 * @details
9079 *
9080 *    Function : freeAperDecodeInitialUlBWPConfig 
9081 *
9082 *    Functionality: Function to free InitialUlBWPConfig
9083 *
9084 * @params[in]  BWP_UplinkDedicated_t *ulBwp
9085 * @return void
9086 *
9087 * ****************************************************************/
9088
9089
9090 void freeAperDecodeInitialUlBWPConfig(BWP_UplinkDedicated_t *ulBwp)
9091 {
9092    uint8_t  rSetIdx =0;
9093    uint8_t  rsrcIdx =0;
9094    SRS_Config_t   *srsCfg = NULLP;
9095    PUSCH_Config_t *puschCfg = NULLP;
9096    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
9097    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
9098    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
9099    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
9100
9101    if(ulBwp->pusch_Config)
9102    {
9103       if(ulBwp->pusch_Config->choice.setup)
9104       {
9105          puschCfg=ulBwp->pusch_Config->choice.setup;
9106          if(puschCfg->dataScramblingIdentityPUSCH)
9107          {
9108             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
9109             {
9110                freeAperDecodePuschTimeDomAllocListCfg(puschCfg);
9111                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
9112                if(dmrsUlCfg->choice.setup)
9113                {
9114                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
9115                   {
9116                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
9117                      {
9118                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0);
9119                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled);
9120                      }
9121                      free(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition);
9122                   }
9123                   free(dmrsUlCfg->choice.setup);
9124                }
9125                free(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA);
9126             }
9127             free(puschCfg->dataScramblingIdentityPUSCH);
9128          }
9129          free(ulBwp->pusch_Config->choice.setup);
9130       }
9131       free(ulBwp->pusch_Config);
9132
9133       /* Free SRS-Config */
9134       if(ulBwp->srs_Config)
9135       {
9136          if(ulBwp->srs_Config->choice.setup)
9137          {
9138             srsCfg = ulBwp->srs_Config->choice.setup;
9139
9140             /* Free Resource Set to add/mod list */
9141             if(srsCfg->srs_ResourceSetToAddModList)
9142             {
9143                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
9144                if(rsrcSetList->list.array)
9145                {
9146                   rSetIdx = 0;
9147
9148                   /* Free SRS resource Id list in this SRS resource set */
9149                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
9150                   {
9151                      rsrcIdList =
9152                         rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
9153
9154                      if(rsrcIdList->list.array)
9155                      {
9156                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count;
9157                               rsrcIdx++)
9158                         {
9159                            free(rsrcIdList->list.array[rsrcIdx]);
9160                         }
9161                         free(rsrcIdList->list.array);
9162                      }
9163                      free(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList);
9164                   }
9165
9166                   /* Free resource type info for this SRS resource set */
9167
9168                   free(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic);
9169
9170                   /* Free memory for each resource set */
9171                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
9172                   {
9173                      free(rsrcSetList->list.array[rSetIdx]);
9174                   }
9175                   free(rsrcSetList->list.array);
9176                }
9177                free(srsCfg->srs_ResourceSetToAddModList);
9178             }
9179
9180             /* Free resource to add/modd list */
9181             if(srsCfg->srs_ResourceToAddModList)
9182             {
9183                resourceList = srsCfg->srs_ResourceToAddModList;
9184                if(resourceList->list.array)
9185                {
9186                   rsrcIdx = 0;
9187
9188                   free(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2);
9189                   free(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic);
9190
9191                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
9192                   {
9193                      free(resourceList->list.array[rsrcIdx]);
9194                   }
9195                   free(resourceList->list.array);
9196                }
9197                free(srsCfg->srs_ResourceToAddModList);
9198             }
9199
9200             free(ulBwp->srs_Config->choice.setup);
9201          }
9202          free(ulBwp->srs_Config);
9203       }
9204    }
9205 }
9206 /*******************************************************************
9207 *
9208 * @brief Function to free initialUplinkBWPConfig where memory allocated by aper_decoder
9209 *
9210 * @details
9211 *
9212 *    Function : freeAperDecodeinitialUplinkBWPConfig
9213 *
9214 *    Functionality: Function to free initialUplinkBWPConfig
9215 *
9216 * @params[in] UplinkConfig_t *ulCfg 
9217 * @return void
9218 *
9219 * ****************************************************************/
9220
9221
9222 void freeAperDecodeinitialUplinkBWPConfig(UplinkConfig_t *ulCfg)
9223 {
9224    BWP_UplinkDedicated_t *ulBwp=NULLP;
9225    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
9226    
9227    if(ulCfg->initialUplinkBWP)
9228    {
9229       ulBwp=ulCfg->initialUplinkBWP;
9230       if(ulCfg->firstActiveUplinkBWP_Id)
9231       {
9232          if(ulCfg->pusch_ServingCellConfig)
9233          {
9234             puschCfg=ulCfg->pusch_ServingCellConfig;
9235             if(puschCfg->choice.setup)
9236             {
9237                if(puschCfg->choice.setup->ext1)
9238                {
9239                   free(puschCfg->choice.setup->ext1->processingType2Enabled);
9240                   free(puschCfg->choice.setup->ext1->maxMIMO_Layers);
9241                   free(puschCfg->choice.setup->ext1);
9242                }
9243                free(puschCfg->choice.setup);
9244             }
9245             free(ulCfg->pusch_ServingCellConfig);
9246          }
9247          free(ulCfg->firstActiveUplinkBWP_Id);
9248       }
9249       freeAperDecodeInitialUlBWPConfig(ulBwp);
9250       free(ulCfg->initialUplinkBWP);
9251    }
9252 }
9253
9254 /*******************************************************************
9255  *
9256  * @brief Function to free DuUeCfg
9257  *
9258  * @details
9259  *
9260  *    Function : freeDuUeCfg
9261  *
9262  *    Functionality: Function to free DuUeCfg
9263  *
9264  * @params[in] DuUeCfg *ueCfg
9265  * @return void
9266  *
9267  * ****************************************************************/
9268 void freeDuUeCfg(DuUeCfg *ueCfg)
9269 {
9270    uint8_t lcIdx = 0;
9271    uint8_t arrIdx = 0;
9272    SpCellConfig_t *spCellCfg = NULLP;
9273    ServingCellConfig_t *srvCellCfg = NULLP;
9274    BWP_DownlinkDedicated_t *dlBwp = NULLP;
9275    MAC_CellGroupConfig_t *macCellGrpCfg = NULLP;
9276    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
9277    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList = NULLP;
9278    struct RLC_Config *rlcConfig = NULLP;
9279    struct LogicalChannelConfig *macLcConfig = NULLP;
9280    struct SchedulingRequestConfig *schedulingRequestConfig = NULLP;
9281    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList = NULLP;
9282    struct TAG_Config *tagConfig = NULLP;
9283    struct TAG_Config__tag_ToAddModList *tagList = NULLP;
9284    struct MAC_CellGroupConfig__phr_Config *phrConfig = NULLP;
9285    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg = NULLP;
9286    CellGroupConfigRrc_t *cellGrpCfg = ueCfg->cellGrpCfg;
9287   
9288    if(ueCfg->ueNrCapability)
9289    {
9290       freeAperDecodeUeNrCapability(ueCfg->ueNrCapability);
9291       DU_FREE(ueCfg->ueNrCapability, sizeof(UE_NR_Capability_t));
9292       ueCfg->ueNrCapability = NULLP;
9293    }
9294
9295    if(ueCfg->cellGrpCfg)
9296    {
9297       
9298       rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
9299       if(rlcBearerList)
9300       {
9301          if(rlcBearerList->list.array)
9302          {
9303             for(arrIdx=0; arrIdx<rlcBearerList->list.count; arrIdx++)
9304             {
9305                if(rlcBearerList->list.array[arrIdx])
9306                {
9307                   rlcConfig   = rlcBearerList->list.array[arrIdx]->rlc_Config;
9308                   macLcConfig = rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig;
9309                   
9310                   if(rlcBearerList->list.array[arrIdx]->servedRadioBearer)
9311                   {
9312                      free(rlcBearerList->list.array[arrIdx]->servedRadioBearer);
9313                   }
9314                   if(rlcConfig)
9315                   {
9316                      if(rlcConfig->choice.am)
9317                      {
9318                         free(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength);
9319                         free(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength);
9320                         free(rlcConfig->choice.am);
9321                      }
9322                      free(rlcBearerList->list.array[arrIdx]->rlc_Config);
9323                   }
9324                   if(macLcConfig)
9325                   {
9326                      if(macLcConfig->ul_SpecificParameters)
9327                      {
9328                         free(macLcConfig->ul_SpecificParameters->schedulingRequestID);
9329                         free(macLcConfig->ul_SpecificParameters->logicalChannelGroup);
9330                         free(macLcConfig->ul_SpecificParameters);
9331                      }
9332                      free(rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig);
9333                   }
9334                   free(rlcBearerList->list.array[arrIdx]); 
9335                }
9336             }
9337             free(rlcBearerList->list.array);
9338          }
9339          free(cellGrpCfg->rlc_BearerToAddModList);
9340       }
9341
9342       macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
9343       if(macCellGrpCfg)
9344       {
9345          schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig;
9346          if(schedulingRequestConfig)
9347          {
9348             schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
9349             if(schReqList)
9350             {
9351                if(schReqList->list.array)
9352                {
9353                   for(arrIdx=0;arrIdx<schReqList->list.count; arrIdx++)
9354                   {
9355                      if(schReqList->list.array[arrIdx])
9356                      {
9357                         free(schReqList->list.array[arrIdx]->sr_ProhibitTimer); 
9358                         free(schReqList->list.array[arrIdx]);
9359                      }
9360                   }
9361                   free(schReqList->list.array);
9362                }
9363                free(schedulingRequestConfig->schedulingRequestToAddModList);
9364             }
9365             free(macCellGrpCfg->schedulingRequestConfig);
9366          }
9367          if(macCellGrpCfg->bsr_Config)
9368          {
9369             free(macCellGrpCfg->bsr_Config);
9370          }
9371          tagConfig = macCellGrpCfg->tag_Config;
9372          if(tagConfig)
9373          {
9374             tagList = tagConfig->tag_ToAddModList;
9375             if(tagList)
9376             {
9377                if(tagList->list.array)
9378                {
9379                   for(arrIdx=0; arrIdx<tagList->list.count; arrIdx++)
9380                   {
9381                      free(tagList->list.array[arrIdx]);
9382                   }
9383                   free(tagList->list.array);
9384                }
9385                free(tagConfig->tag_ToAddModList);
9386             }
9387             free(tagConfig); 
9388          }
9389
9390          phrConfig = macCellGrpCfg->phr_Config;
9391          if(phrConfig)
9392          {
9393             free(phrConfig->choice.setup); 
9394             free(phrConfig); 
9395          }
9396
9397          free(macCellGrpCfg); 
9398       }
9399
9400       phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
9401       if(phyCellGrpCfg)
9402       {
9403          free(phyCellGrpCfg->p_NR_FR1);
9404          free(phyCellGrpCfg); 
9405       }
9406
9407       spCellCfg = cellGrpCfg->spCellConfig;
9408       if(spCellCfg)
9409       {
9410          if(spCellCfg->servCellIndex)
9411          {
9412             if(spCellCfg->rlmInSyncOutOfSyncThreshold)
9413             {
9414                if(spCellCfg->spCellConfigDedicated)
9415                {
9416                   srvCellCfg = spCellCfg->spCellConfigDedicated;
9417                   if(srvCellCfg->initialDownlinkBWP)
9418                   {
9419                      dlBwp = srvCellCfg->initialDownlinkBWP;
9420                      if(srvCellCfg->firstActiveDownlinkBWP_Id)
9421                      {
9422                         if(srvCellCfg->defaultDownlinkBWP_Id)
9423                         {
9424                            if(srvCellCfg->uplinkConfig)
9425                            {
9426
9427                               if(srvCellCfg->pdsch_ServingCellConfig)
9428                               {
9429                                  pdschCfg=
9430                                     srvCellCfg->pdsch_ServingCellConfig;
9431                                  if(pdschCfg->choice.setup)
9432                                  {
9433
9434                                     free(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH);
9435                                     free(pdschCfg->choice.setup);
9436                                  }
9437
9438                                  free(srvCellCfg->pdsch_ServingCellConfig);
9439                               }
9440
9441                               freeAperDecodeinitialUplinkBWPConfig(srvCellCfg->uplinkConfig);
9442                               free(srvCellCfg->uplinkConfig);
9443                            }
9444                            free(srvCellCfg->defaultDownlinkBWP_Id);
9445                         }
9446
9447                         free(srvCellCfg->firstActiveDownlinkBWP_Id);
9448                      }
9449                      if(dlBwp->pdcch_Config)
9450                      {
9451                         if(dlBwp->pdsch_Config)
9452                         {
9453                            freeAperDecodeBWPDlDedPdschConfig(dlBwp);
9454                            free(dlBwp->pdsch_Config);
9455                         }
9456                         freeAperDecodeBWPDlDedPdcchConfig(dlBwp);
9457                         free(dlBwp->pdcch_Config);
9458                      }
9459                      free(srvCellCfg->initialDownlinkBWP);
9460                   }
9461
9462                   free(spCellCfg->spCellConfigDedicated);
9463                }
9464                free(spCellCfg->rlmInSyncOutOfSyncThreshold);
9465             }
9466             free(spCellCfg->servCellIndex); 
9467          }
9468          free(spCellCfg);
9469       }
9470       DU_FREE(ueCfg->cellGrpCfg, sizeof(CellGroupConfigRrc_t));
9471       ueCfg->cellGrpCfg = NULLP;
9472    }
9473    if(ueCfg->ambrCfg)
9474    {
9475       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCfg->ambrCfg, sizeof(AmbrCfg));
9476    }
9477    for(lcIdx = 0; lcIdx < ueCfg->numRlcLcs; lcIdx++)
9478    {
9479       freeRlcLcCfg(&ueCfg->rlcLcCfg[lcIdx]);
9480    }
9481    for(lcIdx = 0; lcIdx < ueCfg->numMacLcs; lcIdx++)
9482    {
9483       freeMacLcCfg(&ueCfg->macLcCfg[lcIdx]);
9484    }
9485    for(lcIdx = 0; lcIdx < ueCfg->numDrb; lcIdx++)
9486    {
9487       DU_FREE(ueCfg->upTnlInfo[lcIdx].tnlCfg1, sizeof(GtpTnlCfg));
9488    }
9489 }
9490
9491 /*******************************************************************
9492  *
9493  * @brief Function to free UecontextSetupDb
9494  *
9495  * @details
9496  *
9497  *    Function : freeF1UeDb
9498  *
9499  *    Functionality: Function to free UecontextSetupDb
9500  *
9501  * @params[in] UecontextSetupDb *
9502  * @return void
9503  *
9504  * ****************************************************************/
9505
9506 void freeF1UeDb(F1UeContextSetupDb *f1UeDb)
9507 {
9508    
9509    if(f1UeDb->dlRrcMsg)
9510    {
9511       if(f1UeDb->dlRrcMsg->rrcMsgPdu)
9512       {
9513         //DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,\
9514                f1UeDb->dlRrcMsg->rrcMsgPdu, f1UeDb->dlRrcMsg->rrcMsgSize);
9515       }
9516       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
9517    }
9518    freeDuUeCfg(&f1UeDb->duUeCfg);
9519    memset(f1UeDb, 0, sizeof(F1UeContextSetupDb));
9520    DU_FREE(f1UeDb, sizeof(F1UeContextSetupDb));
9521 }
9522
9523 /*******************************************************************
9524  *
9525  * @brief Function to build Am cfg Info
9526  *
9527  * @details
9528  *
9529  *    Function : extractRlcAmCfg
9530  *
9531  *    Functionality: Function to build Am cfg Info
9532  *
9533  * @params[in] AmBearerCfg *
9534  *             void *
9535  *
9536  * @return ROK/RFAILED
9537  *
9538  * ****************************************************************/
9539
9540 void extractRlcAmCfg(AmBearerCfg *amCfgToSet, struct RLC_Config__am *rlcAmCfg)
9541 {
9542    if(rlcAmCfg)
9543    {
9544       /* UL AM */
9545       if(rlcAmCfg->dl_AM_RLC.sn_FieldLength)
9546       {
9547          amCfgToSet->ulAmCfg.snLenUl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->dl_AM_RLC.sn_FieldLength));
9548          /*TODO: Check the timer value when sent by real CU */
9549          amCfgToSet->ulAmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_Reassembly); 
9550          amCfgToSet->ulAmCfg.statProhTmr = convertProhibitTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_StatusProhibit);
9551       }
9552
9553       /* DL AM */
9554       if(rlcAmCfg->ul_AM_RLC.sn_FieldLength)
9555       {
9556          amCfgToSet->dlAmCfg.snLenDl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->ul_AM_RLC.sn_FieldLength));
9557          amCfgToSet->dlAmCfg.pollRetxTmr = covertPollRetxTmrEnumToValue(rlcAmCfg->ul_AM_RLC.t_PollRetransmit);
9558          amCfgToSet->dlAmCfg.pollPdu   = covertPollPduEnumToValue(rlcAmCfg->ul_AM_RLC.pollPDU);
9559          amCfgToSet->dlAmCfg.pollByte  = covertPollByteEnumToValue(rlcAmCfg->ul_AM_RLC.pollByte);
9560          amCfgToSet->dlAmCfg.maxRetxTh = covertMaxRetxEnumToValue(rlcAmCfg->ul_AM_RLC.maxRetxThreshold);
9561       }
9562    }
9563 }
9564
9565 /*******************************************************************
9566  *
9567  * @brief Function to build Um Bi Info
9568  *
9569  * @details
9570  *
9571  *    Function : extractRlcUmBiCfg
9572  *
9573  *    Functionality: Function to build Um Bi Info
9574  *
9575  * @params[in] UmBiDirBearerCfg *
9576  *             void *
9577  *
9578  * @return ROK/RFAILED
9579  *
9580  * ****************************************************************/
9581
9582 void extractRlcUmBiCfg(UmBiDirBearerCfg *umBiCfgToSet, struct RLC_Config__um_Bi_Directional *rlcBiCfg)
9583 {
9584    if(rlcBiCfg)
9585    {
9586       /* UL UM BI DIR Cfg */
9587       if(rlcBiCfg->dl_UM_RLC.sn_FieldLength)
9588       {
9589          umBiCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->dl_UM_RLC.sn_FieldLength));
9590          umBiCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcBiCfg->dl_UM_RLC.t_Reassembly);
9591       }
9592
9593       /* DL UM BI DIR Cfg */
9594       if(rlcBiCfg->ul_UM_RLC.sn_FieldLength)
9595          umBiCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->ul_UM_RLC.sn_FieldLength));
9596    }
9597 }
9598
9599 /*******************************************************************
9600  *
9601  * @brief Function to build Um Ul Info
9602  *
9603  * @details
9604  *
9605  *    Function : extractRlcUmUlCfg
9606  *
9607  *    Functionality: Function to build Um Ul Info
9608  *
9609  * @params[in] UmUniDirUlBearerCfg *
9610  *             void *
9611  *
9612  * @return ROK/RFAILED
9613  *
9614  * ****************************************************************/
9615
9616 void extractRlcUmUlCfg(UmUniDirUlBearerCfg *umUlCfgToSet, struct RLC_Config__um_Uni_Directional_DL *umUlCfg)
9617 {
9618    if(umUlCfg)
9619    {
9620       if(umUlCfg->dl_UM_RLC.sn_FieldLength)
9621       {
9622          umUlCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umUlCfg->dl_UM_RLC.sn_FieldLength));
9623          umUlCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(umUlCfg->dl_UM_RLC.t_Reassembly);
9624       }
9625    }
9626 }
9627
9628 /*******************************************************************
9629  *
9630  * @brief Function to build Um Uni Dl Info
9631  *
9632  * @details
9633  *
9634  *    Function : extractRlcUmDlCfg
9635  *
9636  *    Functionality: Function to build Um Uni Dl Info
9637  *
9638  * @params[in] UmUniDirDlBearerCfg *
9639  *             void *
9640  *
9641  * @return ROK/RFAILED
9642  *
9643  * ****************************************************************/
9644 void extractRlcUmDlCfg(UmUniDirDlBearerCfg *umDlCfgToSet, struct RLC_Config__um_Uni_Directional_UL *umDlCfg)
9645 {
9646    if(umDlCfg)
9647    {
9648       if(umDlCfg->ul_UM_RLC.sn_FieldLength)
9649          umDlCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umDlCfg->ul_UM_RLC.sn_FieldLength));
9650    }
9651 }
9652
9653 /*******************************************************************
9654  *
9655  * @brief Function to extractRlcModeCfg
9656  *
9657  * @details
9658  *
9659  *    Function : extractRlcModeCfg
9660  *
9661  *    Functionality: Function to extractRlcModeCfg
9662  *
9663  * @params[in] RLC_Config_t *
9664  *             RlcBearerCfg *
9665  *             void  *    
9666  * @return ROK/RFAILED
9667  *
9668  * ****************************************************************/
9669 void extractRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *rlcDbCfg, RLC_Config_t *lcCfg)
9670 {
9671    if(lcCfg)
9672    {
9673       switch(rlcMode)
9674       {
9675          case RLC_AM :
9676             {
9677                if(lcCfg->choice.am)
9678                {
9679                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.amCfg, sizeof(AmBearerCfg));
9680                   if(rlcDbCfg->u.amCfg)
9681                      extractRlcAmCfg(rlcDbCfg->u.amCfg, lcCfg->choice.am);
9682                }
9683                break;
9684             }
9685          case RLC_UM_BI_DIRECTIONAL :
9686             {
9687                if(lcCfg->choice.um_Bi_Directional)
9688                {
9689                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
9690                   if(rlcDbCfg->u.umBiDirCfg)
9691                      extractRlcUmBiCfg(rlcDbCfg->u.umBiDirCfg, lcCfg->choice.um_Bi_Directional);
9692                }
9693                break;
9694             }
9695          case RLC_UM_UNI_DIRECTIONAL_UL :
9696             {
9697                if(lcCfg->choice.um_Uni_Directional_DL)
9698                {
9699                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
9700                   if(rlcDbCfg->u.umUniDirUlCfg)
9701                      extractRlcUmUlCfg(rlcDbCfg->u.umUniDirUlCfg, lcCfg->choice.um_Uni_Directional_DL);
9702                }
9703                break;
9704             }
9705          case RLC_UM_UNI_DIRECTIONAL_DL :
9706             {
9707                if(lcCfg->choice.um_Uni_Directional_UL)
9708                {
9709                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
9710                   if(rlcDbCfg->u.umUniDirDlCfg)
9711                      extractRlcUmDlCfg(rlcDbCfg->u.umUniDirDlCfg, lcCfg->choice.um_Uni_Directional_UL);
9712                }
9713                break;
9714             }
9715          default:
9716             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
9717             break;
9718       }
9719    }
9720 }
9721
9722 /*******************************************************************
9723  *
9724  * @brief Function to extract extractUlLcCfg
9725  *
9726  * @details
9727  *
9728  *    Function : extractUlLcCfg
9729  *
9730  *    Functionality: Function to extract extractUlLcCfg
9731  *
9732  * @params[in] UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg
9733  * @return void
9734  *
9735  * ****************************************************************/
9736
9737 void extractUlLcCfg(UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg)
9738 {
9739    if(ulLcCfg)
9740    {
9741       if(ulLcCfg->ul_SpecificParameters)
9742       {
9743          f1UlLcCfg->priority = \
9744             ulLcCfg->ul_SpecificParameters->priority;
9745       if(ulLcCfg->ul_SpecificParameters->logicalChannelGroup)
9746       {
9747          f1UlLcCfg->lcGroup = \
9748            *(ulLcCfg->ul_SpecificParameters->logicalChannelGroup);
9749       }
9750       if(ulLcCfg->ul_SpecificParameters->schedulingRequestID)
9751       {
9752          f1UlLcCfg->schReqId = \
9753            *(ulLcCfg->ul_SpecificParameters->schedulingRequestID);
9754       }
9755       f1UlLcCfg->pbr = \
9756          ulLcCfg->ul_SpecificParameters->prioritisedBitRate;
9757       f1UlLcCfg->bsd = \
9758          ulLcCfg->ul_SpecificParameters->bucketSizeDuration;
9759       }
9760    }
9761 }
9762
9763 /*******************************************************************
9764 *
9765 * @brief Function to extract Snssai Cfg Info from CU
9766 *
9767 * @details
9768 *
9769 *    Function : extractDrbSnssaiCfg
9770 *
9771 *    Functionality: Function to extract Drb Snssai Cfg Info from CU
9772 *
9773 * @params[in] DRB_Information_t *drbInfo, Snssai  *snssai
9774 * @return ROK/RFAILED
9775 *
9776 * ****************************************************************/
9777
9778 uint8_t extractDrbSnssaiCfg(SNSSAI_t *RecvSnssai, Snssai **snssaiToBeShared)
9779 {
9780    if(!(*snssaiToBeShared))
9781    {
9782       DU_ALLOC_SHRABL_BUF((*snssaiToBeShared), sizeof(Snssai));
9783       if(snssaiToBeShared == NULLP)
9784       {
9785          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Memory failed at allocating for SNSSAI ");
9786          return RFAILED;
9787       }
9788    }
9789    if(RecvSnssai)
9790    {
9791       memcpy(&(*snssaiToBeShared)->sst, RecvSnssai->sST.buf, RecvSnssai->sST.size);
9792       if(RecvSnssai->sD)
9793       {
9794          memcpy((*snssaiToBeShared)->sd, RecvSnssai->sD->buf,  RecvSnssai->sD->size);
9795       }
9796       else
9797       {
9798          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Received Null pointer of Snssai->SD");
9799          return RFAILED;
9800       }
9801    }
9802    return ROK;
9803 }
9804
9805 /*******************************************************************
9806  *
9807  * @brief Function to procRlcLcCfg
9808  *
9809  * @details
9810  *
9811  *    Function : procRlcLcCfg
9812  *
9813  *    Functionality: Function to procRlcLcCfg
9814  *
9815  * @params[in] rbId, lcId, rbType, rlcMod
9816  *             RLC_Config_t *, RlcBearerCfg * , 
9817  * @return void
9818  *
9819  * ****************************************************************/
9820
9821 void procRlcLcCfg(uint8_t rbId, uint8_t lcId, uint8_t rbType, uint8_t rlcMode,\
9822    uint8_t configType, RLC_Config_t *f1RlcCfg, RlcBearerCfg *lcCfg, QoSInformation_t *qoSInformation)
9823 {
9824    DRB_Information_t *drbInfo;
9825
9826    lcCfg->rbId   = rbId;
9827    lcCfg->configType = configType;
9828
9829    if(rbType == RB_TYPE_SRB)
9830    {
9831       lcCfg->rbType = RB_TYPE_SRB;
9832       lcCfg->lcId   = rbId;
9833       lcCfg->lcType = LCH_DCCH;
9834       lcCfg->rlcMode = RLC_AM;
9835    }
9836    else if(rbType == RB_TYPE_DRB)
9837    {
9838       lcCfg->rbType = RB_TYPE_DRB;
9839       lcCfg->lcId   = lcId;
9840       lcCfg->lcType = LCH_DTCH;
9841       lcCfg->rlcMode = rlcMode;
9842    }
9843    if(f1RlcCfg) /* rlc mode config recived */
9844    {
9845       extractRlcModeCfg(lcCfg->rlcMode, lcCfg, f1RlcCfg);
9846    }
9847    if(qoSInformation != NULLP)
9848    {
9849       if(qoSInformation->present == QoSInformation_PR_choice_extension)
9850       {
9851          if(qoSInformation->choice.choice_extension->value.present ==\
9852                QoSInformation_ExtIEs__value_PR_DRB_Information)
9853          {
9854             drbInfo = &qoSInformation->choice.choice_extension->value.choice.DRB_Information; 
9855             if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &lcCfg->snssai) != ROK)
9856             {
9857                DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information at procRlcLcCfg()");
9858                return;
9859             }
9860          }
9861       }
9862    }
9863 }
9864
9865 /*******************************************************************
9866  *
9867  * @brief Fills DrbQos Info received by CU
9868  *
9869  * @details
9870  *
9871  *    Function : extractQosInfo
9872  *
9873  *    Functionality: Fills DrbQos Info received  by CU
9874  *
9875  * @params[in] DrbQosInfo *qosToAdd, 
9876  *             QoSFlowLevelQoSParameters_t *qosFlowCfg
9877  * @return void
9878  *
9879  * ****************************************************************/
9880
9881 void extractQosInfo(DrbQosInfo *qosToAdd, QoSFlowLevelQoSParameters_t *qosFlowCfg)
9882 {
9883    uint8_t qosCntIdx = 0;
9884    ProtocolExtensionContainer_4624P74_t *qosIeExt = NULLP;
9885
9886    qosToAdd->fiveQiType = qosFlowCfg->qoS_Characteristics.present;
9887    qosToAdd->u.nonDyn5Qi.fiveQi     =\
9888                                      qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->fiveQI;
9889    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow)
9890    {
9891       qosToAdd->u.nonDyn5Qi.avgWindow = \
9892                                         *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
9893    }
9894
9895    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume)
9896    {
9897       qosToAdd->u.nonDyn5Qi.maxDataBurstVol = \
9898                                               *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
9899    }
9900
9901    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel)
9902    {
9903       qosToAdd->u.nonDyn5Qi.priorLevel = \
9904                                          *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel);
9905    }
9906    qosToAdd->ngRanRetPri.priorityLevel = \
9907                                          qosFlowCfg->nGRANallocationRetentionPriority.priorityLevel; 
9908    qosToAdd->ngRanRetPri.preEmptionCap = \
9909                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionCapability;
9910    qosToAdd->ngRanRetPri.preEmptionVul = \
9911                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionVulnerability;
9912    if(qosFlowCfg->gBR_QoS_Flow_Information)
9913    {
9914       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateDl, \
9915             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.buf, \
9916             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.size);
9917       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateUl, \
9918             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.buf, \
9919             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.size);
9920       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateDl,\
9921             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.buf, \
9922             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.size);
9923       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateUl,\
9924             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.buf, \
9925             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.size);
9926    }
9927    /*Extracting PDU_SESSION_ID*/
9928    qosIeExt = (ProtocolExtensionContainer_4624P74_t *)qosFlowCfg->iE_Extensions;
9929    if(qosIeExt)
9930    {
9931       for(qosCntIdx = 0; qosCntIdx < qosIeExt->list.count; qosCntIdx++)
9932       {
9933          if(qosIeExt->list.array[qosCntIdx]->extensionValue.present == \
9934                QoSFlowLevelQoSParameters_ExtIEs__extensionValue_PR_PDUSessionID)
9935          {
9936             qosToAdd->pduSessionId = qosIeExt->list.array[qosCntIdx]->extensionValue.choice.PDUSessionID;
9937             DU_LOG("\nDEBUG -->  DU_F1AP : extractQosInfo: PDU SessionID:%d",qosToAdd->pduSessionId);
9938          }
9939       }  
9940    }
9941    qosToAdd->ulPduSessAggMaxBitRate = 0;
9942 }
9943
9944 /*******************************************************************
9945  *
9946  * @brief Function to extract GTP Tunnel Info from CU
9947  *
9948  * @details
9949  *
9950  *    Function : extractUpTnlInfo
9951  *
9952  *    Functionality: Function to extract GTP Tunnel Info from CU
9953  *
9954  * @params[in] F1AP message
9955  * @return ROK/RFAILED
9956  *
9957  * ****************************************************************/
9958
9959 uint8_t extractUpTnlInfo(uint8_t drbId, uint8_t configType,\
9960    ULUPTNLInformation_ToBeSetup_List_t *tnlInfo, UpTnlCfg *upTnlInfo)
9961 {
9962    uint8_t tnlIdx;
9963    uint32_t ipv4_du = 0;
9964    GTPTunnel_t *gtpTunnel = NULLP;
9965
9966    upTnlInfo->drbId = drbId; 
9967    upTnlInfo->configType = configType;
9968 #ifdef O1_ENABLE
9969    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
9970 #else
9971    cmInetAddr((char *)DU_IP_V4_ADDR, &ipv4_du);
9972 #endif
9973
9974    for(tnlIdx=0; tnlIdx < tnlInfo->list.count; tnlIdx++)
9975    {
9976       if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.present == UPTransportLayerInformation_PR_gTPTunnel)
9977       {
9978          if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel)
9979          {
9980             gtpTunnel = tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel;
9981             DU_ALLOC(upTnlInfo->tnlCfg1, sizeof(GtpTnlCfg));
9982             if(upTnlInfo->tnlCfg1 == NULLP)
9983             {
9984                DU_LOG("\nERROR  -->  F1AP : extractUpTnlInfo: Failed to allocate mmeory for tunnel cfg 1");
9985                return RFAILED;
9986             }
9987             bitStringToInt(&gtpTunnel->transportLayerAddress, &upTnlInfo->tnlCfg1->ulTnlAddress);
9988             upTnlInfo->tnlCfg1->dlTnlAddress = ipv4_du;
9989             if(gtpTunnel->gTP_TEID.size > 0)
9990             {
9991                teIdStringToInt(gtpTunnel->gTP_TEID.buf, &upTnlInfo->tnlCfg1->teId);
9992             }
9993          }
9994          break;
9995       }
9996    }
9997    return ROK;
9998 }
9999
10000 /*******************************************************************
10001 *
10002 * @brief Function to extract Drb Qos Cfg Info from CU
10003 *
10004 * @details
10005 *
10006 *    Function : extractDrbQosCfg 
10007 *
10008 *    Functionality: Function to extract Drb Qos Cfg Info from CU
10009 *
10010 * @params[in] DRB_Information_t *drbInfo, LcCfg *macLcToAdd
10011 * @return ROK/RFAILED
10012 *
10013 * ****************************************************************/
10014
10015 uint8_t extractDrbQosCfg(DRB_Information_t *drbInfo, LcCfg *macLcToAdd ) 
10016 {
10017    if(!macLcToAdd->drbQos)
10018    {
10019       DU_ALLOC_SHRABL_BUF(macLcToAdd->drbQos, sizeof(DrbQosInfo));
10020       if(macLcToAdd->drbQos == NULLP)
10021       {
10022          DU_LOG("\nERROR  -->  DUAPP:Memory failed at allocating DrbQos at extractDrbQosCfg()");
10023          return RFAILED;
10024       }
10025
10026    }
10027    if(drbInfo->dRB_QoS.qoS_Characteristics.present == QoS_Characteristics_PR_non_Dynamic_5QI)
10028    {
10029       extractQosInfo(macLcToAdd->drbQos, &drbInfo->dRB_QoS);
10030       macLcToAdd->dlLcCfg.lcp = macLcToAdd->drbQos->ngRanRetPri.priorityLevel;
10031    }
10032    if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &macLcToAdd->snssai) != ROK)
10033    {
10034       DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information  at extractDrbQosCfg()");
10035       return RFAILED;
10036    }
10037    return ROK;
10038 }
10039 /*******************************************************************
10040  *
10041  * @brief Function to extract DRB info received from CU
10042  *
10043  * @details
10044  *
10045  *    Function : extractDrbCfg
10046  *
10047  *    Functionality: Function to extract DRB info received from CU
10048  *
10049  * @params[in] F1AP message
10050  * @return void
10051  *
10052  * ****************************************************************/
10053 uint8_t extractDrbCfg(DRBs_ToBeSetup_Item_t *drbItem, DRBs_ToBeSetupMod_Item_t *drbSetupModItem,\
10054 DRBs_ToBeModified_Item_t *drbModItem,  LcCfg *macLcToAdd, UpTnlCfg *upTnlInfo)
10055 {
10056    DRB_Information_t *drbInfo = NULLP;
10057
10058    if(drbItem != NULLP)
10059    {
10060       if(extractUpTnlInfo(drbItem->dRBID, CONFIG_ADD, &drbItem->uLUPTNLInformation_ToBeSetup_List, upTnlInfo) != ROK)
10061       {
10062          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10063          return RFAILED;
10064       }
10065       if(drbItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10066       {
10067          if(drbItem->qoSInformation.choice.choice_extension->value.present == QoSInformation_ExtIEs__value_PR_DRB_Information)
10068          {
10069             drbInfo = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10070             if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
10071             {
10072                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");
10073                return RFAILED;
10074             }
10075          }
10076       }
10077    }
10078    else if(drbSetupModItem != NULLP)
10079    {
10080       if(extractUpTnlInfo(drbSetupModItem->dRBID, CONFIG_ADD, &drbSetupModItem->uLUPTNLInformation_ToBeSetup_List,\
10081       upTnlInfo) != ROK)
10082       {
10083          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10084          return RFAILED;
10085       }
10086       if(drbSetupModItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10087       {
10088          if(drbSetupModItem->qoSInformation.choice.choice_extension->value.present ==\
10089          QoSInformation_ExtIEs__value_PR_DRB_Information)
10090          {
10091             drbInfo = &drbSetupModItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10092             if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
10093             {
10094                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10095                return RFAILED;
10096             }
10097
10098          }
10099       }
10100    }
10101    else if(drbModItem != NULLP)
10102    {
10103       if(extractUpTnlInfo(drbModItem->dRBID, CONFIG_MOD, &drbModItem->uLUPTNLInformation_ToBeSetup_List,\
10104       upTnlInfo) != ROK)
10105       {
10106          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10107          return RFAILED;
10108       }
10109       if(drbModItem->qoSInformation != NULLP)
10110       {
10111          if(drbModItem->qoSInformation->present == QoSInformation_PR_choice_extension)
10112          {
10113             if(drbModItem->qoSInformation->choice.choice_extension->value.present ==\
10114                   QoSInformation_ExtIEs__value_PR_DRB_Information)
10115             {
10116                drbInfo = &drbModItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information;
10117                if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
10118                {
10119                   DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10120                   return RFAILED;
10121                }
10122
10123             }
10124          }
10125       }
10126    }
10127    return ROK;
10128 }
10129
10130 /*******************************************************************
10131  *
10132  * @brief Function to extract RB info received from CU
10133  *
10134  * @details
10135  *
10136  *    Function : extractMacRbCfg
10137  *
10138  *    Functionality: Function to extract RB info received from CU
10139  *
10140  * @params[in] F1AP message
10141  * @return ROK/RFAILED
10142  *
10143  * ****************************************************************/
10144
10145 uint8_t extractMacRbCfg(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbCfg,\
10146 DRBs_ToBeSetupMod_Item_t *drbSetupModCfg,  DRBs_ToBeModified_Item_t *drbModCfg, LogicalChannelConfig_t *ulLcCfg, LcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10147 {
10148    if(drbCfg != NULLP)
10149    {
10150       if(extractDrbCfg(drbCfg, NULL, NULL, lcCfg, upTnlInfo) != ROK)
10151       {
10152          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10153          return RFAILED;
10154       }
10155    }
10156    else if(drbSetupModCfg != NULLP)
10157    { 
10158       if(extractDrbCfg(NULL, drbSetupModCfg, NULL, lcCfg, upTnlInfo) != ROK)
10159       {
10160          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10161          return RFAILED;
10162       }
10163    }
10164    else if(drbModCfg != NULLP)
10165    { 
10166       if(extractDrbCfg(NULL, NULL, drbModCfg, lcCfg, upTnlInfo) != ROK)
10167       {
10168          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10169          return RFAILED;
10170       }
10171    }
10172    else
10173    {
10174       lcCfg->drbQos = NULLP;
10175       lcCfg->snssai = NULLP;
10176       if(lcCfg->lcId == SRB2_LCID)
10177          lcCfg->dlLcCfg.lcp = LC_PRIORITY_3;
10178       else
10179          lcCfg->dlLcCfg.lcp = LC_PRIORITY_1;
10180    }
10181    if(ulLcCfg)
10182    {
10183       lcCfg->ulLcCfgPres = true;
10184       extractUlLcCfg(&lcCfg->ulLcCfg, ulLcCfg);
10185    }
10186    else
10187       lcCfg->ulLcCfgPres = false;
10188    return ROK;
10189 }
10190
10191 /*******************************************************************
10192  *
10193  * @brief Function processing LC config info received from CU
10194  *
10195  * @details
10196  *
10197  *    Function : procMacLcCfg
10198  *
10199  *    Functionality: Function processing LC config info received from CU
10200  *
10201  * @params[in] F1AP message
10202  * @return ROK/RFAILED
10203  *
10204  * ****************************************************************/
10205
10206 uint8_t procMacLcCfg(uint8_t lcId, uint8_t rbType, uint8_t configType, DRBs_ToBeSetup_Item_t *drbItem,\
10207 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LogicalChannelConfig_t *ulLcCfg,\
10208 LcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10209 {
10210    uint8_t ret = ROK;
10211
10212    lcCfg->lcId = lcId;
10213    lcCfg->configType = configType;
10214    if(rbType == RB_TYPE_SRB)
10215    {
10216       ret = extractMacRbCfg(lcId, NULL, NULL, NULL, ulLcCfg, lcCfg, NULL);
10217    }
10218    else if(rbType == RB_TYPE_DRB)
10219    {
10220       if(drbItem != NULL)
10221         ret = extractMacRbCfg(lcId, drbItem, NULL, NULL, ulLcCfg, lcCfg, upTnlInfo);
10222       else if(drbSetupModItem != NULL)
10223         ret = extractMacRbCfg(lcId, NULL, drbSetupModItem, NULL, ulLcCfg, lcCfg, upTnlInfo);
10224       else if(drbModItem != NULL)
10225         ret = extractMacRbCfg(lcId, NULL, NULL, drbModItem, ulLcCfg, lcCfg, upTnlInfo);
10226    }
10227    return ret;
10228 }
10229
10230 /*******************************************************************
10231  *
10232  * @brief Function to extract Rlc cfg To Add/Mod in CellGrp Info
10233  *
10234  * @details
10235  *
10236  *    Function : extractRlcCfgToAddMod
10237  *
10238  *    Functionality: Function to extract Rlc cfg To Add/Mod in CellGrp Info
10239  *
10240  * @params[in] CellGroupConfigRrc__rlc_BearerTo pointer
10241  *             DuUeCfg Pointer
10242  * @return ROK/RFAILED
10243  *
10244  * ****************************************************************/
10245
10246 uint8_t extractRlcCfgToAddMod(struct CellGroupConfigRrc__rlc_BearerToAddModList *lcCfg, DuUeCfg *ueCfgDb)
10247 {
10248   uint8_t idx, rbId, lcId, rlcMode, rbType;
10249   RLC_Config_t *f1RlcCfg = NULLP;
10250   LogicalChannelConfig_t *macUlLcCfg = NULLP;
10251
10252   for(idx = 0; idx < lcCfg->list.count; idx++)
10253   {
10254      lcId = lcCfg->list.array[idx]->logicalChannelIdentity;
10255      if(lcCfg->list.array[idx]->servedRadioBearer)
10256      {
10257         /* RadioBearer for SRB/DRB */
10258         if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10259         RLC_BearerConfig__servedRadioBearer_PR_srb_Identity)
10260         {
10261            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.srb_Identity;
10262            rbType = RB_TYPE_SRB;
10263         }
10264         else if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10265         RLC_BearerConfig__servedRadioBearer_PR_drb_Identity)
10266         {
10267            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.drb_Identity;
10268            rbType = RB_TYPE_DRB;
10269         }
10270         else
10271         {
10272            DU_LOG("\nERROR  -->  No components present in Bearer config to ADD/MOD");
10273            return RFAILED;
10274         }
10275         /* MAC UL LC Config */
10276         if(lcCfg->list.array[idx]->mac_LogicalChannelConfig)
10277         {
10278            macUlLcCfg = lcCfg->list.array[idx]->mac_LogicalChannelConfig;
10279         }
10280      }
10281      else
10282      {
10283         DU_LOG("\nERROR  -->  DUAPP: Received RadioBearer config is NULL");
10284         return RFAILED;
10285      }
10286      /* RLC Mode Config */
10287      if(lcCfg->list.array[idx]->rlc_Config)
10288      {
10289         rlcMode  = lcCfg->list.array[idx]->rlc_Config->present;
10290         f1RlcCfg = lcCfg->list.array[idx]->rlc_Config;
10291      }
10292      
10293      /* Filling RLC/MAC Config*/
10294      memset(&ueCfgDb->macLcCfg[idx], 0, sizeof(LcCfg));
10295      memset(&ueCfgDb->rlcLcCfg[idx], 0, sizeof(RlcBearerCfg));
10296      procRlcLcCfg(rbId, lcId, rbType, rlcMode, CONFIG_UNKNOWN, f1RlcCfg, &(ueCfgDb->rlcLcCfg[idx]), NULLP);
10297      if(procMacLcCfg(lcId, rbType, CONFIG_UNKNOWN, NULL, NULL, NULL, macUlLcCfg, &ueCfgDb->macLcCfg[idx], NULL) != ROK)
10298      {
10299         DU_LOG("\nERROR  -->  DU APP : Failed while filling MAC LC config at extractRlcCfgToAddMod()");
10300         return RFAILED;
10301      }
10302      (ueCfgDb->numRlcLcs)++;
10303      (ueCfgDb->numMacLcs)++;
10304      DU_LOG("\nDEBUG  -> DUAPP: extractRlcCfgToAddMod:RBType:%d, DrbID: %d,lcId:%d, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
10305         rbType, rbId, lcId, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
10306   }
10307   //TODO: To send the failure cause in UeContextSetupRsp 
10308   return ROK;
10309 }
10310
10311 /*******************************************************************
10312  *
10313  * @brief DeAlloc pdsch serv cell config info
10314  *
10315  * @details
10316  *
10317  *    Function : freeMacPdschServCellInfo
10318  *
10319  *    Functionality: DeAlloc pdsch serv cell config info
10320  *
10321  * @params[in] PdschServCellCfg pointer
10322  * @return void
10323  *
10324  * ****************************************************************/
10325
10326 void freeMacPdschServCellInfo(PdschServCellCfg *pdsch)
10327 {
10328    if(pdsch->xOverhead)
10329    {
10330       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->xOverhead, sizeof(PdschXOverhead));
10331    }
10332    if(pdsch->codeBlkGrpFlushInd)
10333    {
10334       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->codeBlkGrpFlushInd, sizeof(bool));
10335    }
10336    if(pdsch->maxCodeBlkGrpPerTb)
10337    {
10338       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10339    }
10340    if(pdsch->maxMimoLayers)
10341    {
10342       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxMimoLayers, sizeof(uint8_t));
10343    }
10344 }
10345
10346 /*******************************************************************
10347  *
10348  * @brief Free Serving cell Info
10349  *
10350  * @details
10351  *
10352  *    Function : freeMacServingCellInfo
10353  *
10354  *    Functionality: Free Serving cell Info
10355  *
10356  * @params[in] ServCellCfgInfo *srvCellCfg
10357  * @return void
10358  *
10359  * ****************************************************************/
10360 void freeMacServingCellInfo(ServCellCfgInfo *srvCellCfg)
10361 {
10362    uint8_t timeDomRsrcIdx;
10363
10364    if(srvCellCfg->initDlBwp.pdschPresent)
10365    {
10366       for(timeDomRsrcIdx = 0; timeDomRsrcIdx < srvCellCfg->initDlBwp.pdschCfg.numTimeDomRsrcAlloc; timeDomRsrcIdx++)
10367       {
10368          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, \
10369             srvCellCfg->initDlBwp.pdschCfg.timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
10370       }
10371    }
10372
10373    freeMacPdschServCellInfo(&srvCellCfg->pdschServCellCfg);
10374    if(srvCellCfg->bwpInactivityTmr)
10375    {
10376       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
10377    }
10378
10379    if(srvCellCfg->initUlBwp.pucchPresent)
10380    {
10381       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->initUlBwp.pucchCfg.dlDataToUlAck, sizeof(PucchDlDataToUlAck));
10382    }
10383 }
10384
10385 /*******************************************************************
10386  *
10387  * @brief Free cell Grp Cfg Info
10388  *
10389  * @details
10390  *
10391  *    Function : freeUeReCfgCellGrpInfo
10392  *
10393  *    Functionality: Free cell Grp Cfg Info
10394  *
10395  * @params[in] MacUeCfg*  duUeCfg
10396  * @return void
10397  *
10398  * ****************************************************************/
10399
10400 void freeUeReCfgCellGrpInfo(MacUeCfg *macUeCfg)
10401 {
10402    freeMacServingCellInfo(&macUeCfg->spCellCfg.servCellCfg);
10403 }
10404
10405 /*******************************************************************
10406  *
10407  * @brief Fills Reconfig SchReqReConfig
10408  *
10409  * @details
10410  *
10411  *    Function : extractSchReqReConfig
10412  *
10413  *    Functionality: Fills Reconfig SchReqReConfig
10414  *
10415  * @params[in] SchedulingRequestConfig_t *cuSchedReq
10416  *             SchedReqCfg*  macSchedReq
10417  * @return void
10418  *
10419  * ****************************************************************/
10420 void extractSchReqReConfig(SchedulingRequestConfig_t *cuSchedReq, SchedReqCfg *macSchedReq)
10421 {
10422    uint8_t schReqIdx = 0;
10423    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqListToAdd = NULLP;
10424    struct SchedulingRequestConfig__schedulingRequestToReleaseList *schReqListToRel = NULLP;
10425
10426    if(cuSchedReq->schedulingRequestToAddModList)
10427    {
10428       schReqListToAdd = cuSchedReq->schedulingRequestToAddModList;
10429       if(schReqListToAdd->list.count)
10430       {
10431          macSchedReq->addModListCount = schReqListToAdd->list.count;
10432          for(schReqIdx = 0; schReqIdx < schReqListToAdd->list.count; schReqIdx++)
10433          {
10434             macSchedReq->addModList[schReqIdx].schedReqId = \
10435                schReqListToAdd->list.array[schReqIdx]->schedulingRequestId;
10436             macSchedReq->addModList[schReqIdx].srProhibitTmr = \
10437                *(schReqListToAdd->list.array[schReqIdx]->sr_ProhibitTimer);
10438             macSchedReq->addModList[schReqIdx].srTransMax    =\
10439                schReqListToAdd->list.array[schReqIdx]->sr_TransMax;
10440          }
10441       }
10442    }
10443    /* Scheduling Req To release */
10444    if(cuSchedReq->schedulingRequestToReleaseList)
10445    {
10446       schReqListToRel = cuSchedReq->schedulingRequestToReleaseList;
10447       if(schReqListToRel->list.count)
10448       {
10449          macSchedReq->relListCount = schReqListToRel->list.count;
10450          for(schReqIdx = 0; schReqIdx < schReqListToRel->list.count; schReqIdx++)
10451          {
10452             macSchedReq->relList[schReqIdx] = \
10453                *schReqListToRel->list.array[schReqIdx];
10454          }
10455       }
10456    }
10457 }
10458
10459 /*******************************************************************
10460  *
10461  * @brief Fills TagReconfig
10462  *
10463  * @details
10464  *
10465  *    Function : extractTagReconfig
10466  *
10467  *    Functionality: Fills extractTagReconfig
10468  *
10469  * @params[in] TAG_Config_t *cuTagCfg
10470  *             TagCfg *macTagCfg
10471  * @return void
10472  *
10473  * ****************************************************************/
10474
10475 void extractTagReconfig(TAG_Config_t *cuTagCfg, TagCfg *macTagCfg)
10476 {
10477   uint8_t tagIdx = 0;
10478   struct TAG_Config__tag_ToAddModList  *tagListToAddMod = NULLP;
10479   struct TAG_Config__tag_ToReleaseList *tagListToRel = NULLP;
10480
10481   /* Tag config to AddMod */
10482   if(cuTagCfg->tag_ToAddModList)
10483   {
10484      tagListToAddMod = cuTagCfg->tag_ToAddModList; 
10485      if(tagListToAddMod->list.count)
10486      {
10487         macTagCfg->addModListCount = tagListToAddMod->list.count;
10488         for(tagIdx = 0; tagIdx < tagListToAddMod->list.count; tagIdx++)
10489         {
10490            macTagCfg->addModList[tagIdx].tagId =\
10491               tagListToAddMod->list.array[tagIdx]->tag_Id;     
10492            macTagCfg->addModList[tagIdx].timeAlignTimer = \
10493
10494               tagListToAddMod->list.array[tagIdx]->timeAlignmentTimer;
10495         }
10496      }
10497   }
10498   /* Tag config to release */
10499   if(cuTagCfg->tag_ToReleaseList)
10500   {
10501      tagListToRel = cuTagCfg->tag_ToReleaseList;
10502      if(tagListToRel->list.count)
10503      {
10504         macTagCfg->relListCount = tagListToRel->list.count;
10505         for(tagIdx = 0; tagIdx < tagListToRel->list.count; tagIdx++)
10506         {
10507            macTagCfg->relList[tagIdx] = *tagListToRel->list.array[tagIdx];     
10508         }
10509      }
10510   }
10511 }
10512
10513 /*******************************************************************
10514  *
10515  * @brief Fills PdcchCfg received by CU
10516  *
10517  * @details
10518  *
10519  *    Function : extractPdcchCfg
10520  *
10521  *    Functionality: Fills PdcchCfg received  by CU
10522  *
10523  * @params[in] PDCCH_Config_t *cuPdcchCfg,
10524  *             PdcchConfig *duPdcchCfg
10525  * @return void
10526  *
10527  * ****************************************************************/
10528
10529 void extractPdcchCfg(PDCCH_Config_t *cuPdcchCfg, PdcchConfig *macPdcchCfg)
10530 {
10531    uint8_t cRsetIdx = 0;
10532    uint8_t srchSpcIdx = 0;
10533
10534    struct PDCCH_Config__controlResourceSetToAddModList *cRsetToAddModList = NULLP;
10535    struct PDCCH_Config__controlResourceSetToReleaseList *cRsetToRelList = NULLP;
10536    struct PDCCH_Config__searchSpacesToAddModList *srchSpcToAddModList = NULLP;
10537    struct PDCCH_Config__searchSpacesToReleaseList *srchSpcToRelList = NULLP;
10538
10539
10540    /* Control Resource Set To Add/Mod List */
10541    if(cuPdcchCfg->controlResourceSetToAddModList)
10542    {
10543       cRsetToAddModList = cuPdcchCfg->controlResourceSetToAddModList;
10544       if(cRsetToAddModList->list.count)
10545       {
10546          macPdcchCfg->numCRsetToAddMod = cRsetToAddModList->list.count;
10547          for(cRsetIdx = 0; cRsetIdx < cRsetToAddModList->list.count; cRsetIdx++)
10548          {
10549             macPdcchCfg->cRSetToAddModList[cRsetIdx].cRSetId = \
10550                cRsetToAddModList->list.array[cRsetIdx]->controlResourceSetId;
10551             //freqDomRsrcBitStringToInt(&cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources,\
10552                   macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc);
10553             memcpy(macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc, \
10554                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.buf,
10555                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.size);
10556
10557             macPdcchCfg->cRSetToAddModList[cRsetIdx].duration = \
10558                 cRsetToAddModList->list.array[cRsetIdx]->duration;
10559
10560             macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType = \
10561                cRsetToAddModList->list.array[cRsetIdx]->cce_REG_MappingType.present;   
10562             if(macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType == CCE_REG_MAPPINGTYPE_PR_INTERLEAVED)
10563             {
10564                //TODO: handle the case for Interleaved
10565             }
10566             macPdcchCfg->cRSetToAddModList[cRsetIdx].precoderGranularity = \
10567                 cRsetToAddModList->list.array[cRsetIdx]->precoderGranularity;
10568             if(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID)
10569             {
10570                macPdcchCfg->cRSetToAddModList[cRsetIdx].dmrsScramblingId= \
10571                   *(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID);
10572             }
10573          }
10574       }
10575    }
10576    /* Control Resource Set To Release List */
10577    if(cuPdcchCfg->controlResourceSetToReleaseList)
10578    {
10579       cRsetToRelList = cuPdcchCfg->controlResourceSetToReleaseList;
10580       if(cRsetToRelList->list.count)
10581       {
10582          macPdcchCfg->numCRsetToRel = cRsetToRelList->list.count;
10583          for(cRsetIdx = 0; cRsetIdx < cRsetToRelList->list.count; cRsetIdx++)
10584          {
10585             macPdcchCfg->cRSetToRelList[cRsetIdx] = *(cRsetToRelList->list.array[cRsetIdx]);
10586          }
10587       }
10588    }
10589
10590    /* Search space To Add/Mod List */
10591    if(cuPdcchCfg->searchSpacesToAddModList)
10592    {
10593       srchSpcToAddModList = cuPdcchCfg->searchSpacesToAddModList;
10594       if(srchSpcToAddModList->list.count)
10595       {
10596          macPdcchCfg->numSearchSpcToAddMod = srchSpcToAddModList->list.count;
10597          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToAddModList->list.count; srchSpcIdx++)
10598          {
10599             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceId =\
10600                                                                           srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceId;
10601             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].cRSetId =\
10602                                                                     *(srchSpcToAddModList->list.array[srchSpcIdx]->controlResourceSetId);
10603             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset)
10604             {
10605                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSlotPeriodicityAndOffset =\
10606                                                                                          srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset->present;
10607             }
10608             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot)
10609             {
10610                bitStringToInt(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot,\
10611                      macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSymbolsWithinSlot);
10612             }
10613             if(srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates)
10614             {
10615                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel1 = \
10616                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel1;
10617                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel2 = \
10618                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel2;
10619                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel4 = \
10620                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel4;
10621
10622                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel8 = \
10623                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel8;
10624
10625                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel16 = \
10626                                                                                         srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel16;
10627             }
10628             if(srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType)
10629             {
10630                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType =\
10631                                                                                srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->present;
10632                if(macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType == SEARCHSPACETYPE_PR_UE_SPECIFIC)
10633                {
10634                   macPdcchCfg->searchSpcToAddModList[srchSpcIdx].ueSpecificDciFormat =\
10635                                                                                       srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->choice.ue_Specific->dci_Formats;
10636                }
10637
10638             }
10639          }
10640       }
10641    }
10642    /* Search space To Rel List */
10643    if(cuPdcchCfg->searchSpacesToReleaseList)
10644    {
10645       srchSpcToRelList = cuPdcchCfg->searchSpacesToReleaseList;
10646       if(srchSpcToRelList->list.count)
10647       {
10648          macPdcchCfg->numSearchSpcToRel = srchSpcToRelList->list.count;
10649          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToRelList->list.count; srchSpcIdx++)
10650          {
10651             macPdcchCfg->searchSpcToRelList[srchSpcIdx] =\
10652                                                          *(srchSpcToRelList->list.array[srchSpcIdx]);
10653          }
10654       }
10655    }
10656 }
10657
10658 /*******************************************************************
10659  *
10660  * @brief Fills PdschCfg received by CU
10661  *
10662  * @details
10663  *
10664  *    Function : extractPdschCfg
10665  *
10666  *    Functionality: Fills PdschCfg received  by CU
10667  *
10668  * @params[in] PDSCH_Config_t *cuPdschCfg = Information which is send by CU,
10669  *                   which we have stored in F1UeContextSetupDb,
10670  *             PdschConfig *macPdschCfg = Used to Store the information which
10671  *                   needs to send in other layer, as well as this can be the variable
10672  *                   which stores the information in DuCb,
10673  *             PdschConfig *storedPdschCfg =  Null in case of sending the
10674  *                   information to other layer else it will have stored pdsch 
10675  *                   configuration in copyOfmacUeCfg.
10676  * @return void
10677  *
10678  * ****************************************************************/
10679
10680 void extractPdschCfg(PDSCH_Config_t *cuPdschCfg, PdschConfig *macPdschCfg, PdschConfig *storedPdschCfg)
10681 {
10682    uint8_t timeDomIdx;
10683    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAlloc = NULLP;
10684
10685    if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
10686    {
10687       if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->present == \
10688             PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup)
10689       {
10690          if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup)
10691          {
10692             macPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
10693                *(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_AdditionalPosition);
10694          }
10695       }
10696    }
10697    macPdschCfg->resourceAllocType = cuPdschCfg->resourceAllocation;
10698    if(cuPdschCfg->pdsch_TimeDomainAllocationList)
10699    {
10700       timeDomAlloc = cuPdschCfg->pdsch_TimeDomainAllocationList;
10701       if(timeDomAlloc->present ==\
10702             PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup)
10703       {
10704          if(timeDomAlloc->choice.setup)
10705          {
10706             macPdschCfg->numTimeDomRsrcAlloc  = timeDomAlloc->choice.setup->list.count;
10707             for(timeDomIdx = 0; timeDomIdx < timeDomAlloc->choice.setup->list.count; timeDomIdx++)
10708             {
10709                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 = NULLP;
10710                if(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0)
10711                {
10712                   if(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 == NULL)
10713                   {
10714                      if(storedPdschCfg)
10715                      {
10716                         if(storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
10717                         {
10718                            macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 =\
10719                            storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0;
10720                         }
10721                         else
10722                         {
10723                            DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
10724                         }
10725                      }
10726                      else
10727                      {
10728                         DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
10729                      }
10730                      if(!macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
10731                      {
10732                         DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for k0 at extractPdschCfg()");
10733                         return;
10734                      }
10735                   }
10736                   *(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0) = \
10737                   *(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0);
10738                }
10739                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].mappingType = \
10740                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->mappingType;
10741                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].startSymbolAndLength = \
10742                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
10743             }
10744          }
10745       }
10746    }
10747    macPdschCfg->rbgSize = cuPdschCfg->rbg_Size;
10748    if(cuPdschCfg->maxNrofCodeWordsScheduledByDCI)
10749       macPdschCfg->numCodeWordsSchByDci = *(cuPdschCfg->maxNrofCodeWordsScheduledByDCI);
10750    if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_staticBundling)
10751    {
10752       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
10753       if(cuPdschCfg->prb_BundlingType.choice.staticBundling)
10754       {
10755          if(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize)
10756          {
10757             macPdschCfg->bundlingInfo.StaticBundling.size = \
10758                *(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize);
10759          }
10760       }
10761    }
10762    else if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_dynamicBundling)
10763    {
10764       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
10765    }
10766
10767 }
10768
10769 /*******************************************************************
10770  *
10771  * @brief Fills PdschServingCellCfg received by CU
10772  *
10773  * @details
10774  *
10775  *    Function : extractPdschServingCellCfg
10776  *
10777  *    Functionality: Fills PdschCfg received  by CU
10778  *
10779  * @params[in] PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg,
10780  *             PdschServCellCfg *macUePdschSrvCellCfg
10781  * @return ROK/RFAILED
10782  *
10783  * ****************************************************************/
10784
10785 uint8_t extractPdschServingCellCfg(PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg, PdschServCellCfg *macUePdschSrvCellCfg)
10786 {
10787    if(cuPdschSrvCellCfg->codeBlockGroupTransmission)
10788    {
10789       if(cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup)
10790       {
10791          if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
10792          {
10793             *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
10794                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
10795          }
10796          else
10797          {
10798             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10799             if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
10800             {
10801                *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
10802                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
10803             }
10804             else
10805             {
10806                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxCodeBlkGrpPerTb at extractPdschServingCellCfg()");
10807                return RFAILED;
10808             }
10809          }
10810          if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
10811          {
10812             *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
10813                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
10814          }
10815          else
10816          {
10817             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->codeBlkGrpFlushInd , sizeof(bool));
10818             if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
10819             {
10820                *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
10821                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
10822             }
10823             else
10824             {
10825                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for codeBlkGrpFlushInd at extractPdschServingCellCfg()");
10826                return RFAILED;
10827             }
10828          }
10829       }
10830    }
10831    if(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH)
10832    {
10833       macUePdschSrvCellCfg->numHarqProcForPdsch = *(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH); 
10834    }
10835    if(cuPdschSrvCellCfg->ext1)
10836    {
10837       if(cuPdschSrvCellCfg->ext1->maxMIMO_Layers)
10838       {
10839         if(macUePdschSrvCellCfg->maxMimoLayers)
10840         {
10841            *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
10842         }
10843         else
10844         {
10845            DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxMimoLayers, sizeof(uint8_t));
10846            if(macUePdschSrvCellCfg->maxMimoLayers)
10847            {
10848               *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
10849            }
10850            else
10851            {
10852               DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxMimoLayers at extractPdschServingCellCfg()");
10853               return RFAILED;
10854            }
10855         }
10856       }
10857    }
10858    if(cuPdschSrvCellCfg->xOverhead)
10859    {
10860       if(macUePdschSrvCellCfg->xOverhead)
10861       {
10862          *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
10863       }
10864       else
10865       {
10866          DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->xOverhead, sizeof(PdschXOverhead));
10867          if(macUePdschSrvCellCfg->xOverhead)
10868          {
10869             *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
10870          }
10871          else
10872          {
10873             DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for xOverhead at extractPdschServingCellCfg()");
10874             return RFAILED;
10875          }
10876       }
10877    }
10878    return ROK;
10879 }
10880
10881 /*******************************************************************
10882  *
10883  * @brief Fills PuschCfg received by CU
10884  *
10885  * @details
10886  *
10887  *    Function : extractPuschCfg
10888  *
10889  *    Functionality: Fills PuschCfg received  by CU
10890  *
10891  * @params[in] BWP_UplinkDedicated__pusch_Config *cuPuschCfg,
10892  *             PuschCfg *macPuschCfg
10893  * @return void
10894  *
10895  * ****************************************************************/
10896
10897 void extractPuschCfg(struct BWP_UplinkDedicated__pusch_Config *cuPuschCfg, PuschCfg *macPuschCfg)
10898 {
10899    uint8_t timeDomIdx = 0;
10900    DMRS_UplinkConfig_t *dmrsUlCfg = NULLP;
10901    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList = NULLP;
10902
10903    if(cuPuschCfg->present == BWP_UplinkDedicated__pusch_Config_PR_setup)
10904    {
10905       if(cuPuschCfg->choice.setup)
10906       {
10907          if(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH)
10908          {
10909              macPuschCfg->dataScramblingId = \
10910                 *(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH);
10911          }
10912          if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA)
10913          {
10914             if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->present == PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup)
10915             {
10916                if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup)
10917                {
10918                   dmrsUlCfg = (cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup);
10919                   if(dmrsUlCfg->dmrs_AdditionalPosition)
10920                   {
10921                      macPuschCfg->dmrsUlCfgForPuschMapTypeA.addPos =\
10922                         *(dmrsUlCfg->dmrs_AdditionalPosition);
10923                   }
10924                   if(dmrsUlCfg->transformPrecodingDisabled)
10925                   {
10926                      if(dmrsUlCfg->transformPrecodingDisabled->scramblingID0)
10927                      {
10928                         macPuschCfg->dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0 = \
10929                            *(dmrsUlCfg->transformPrecodingDisabled->scramblingID0);
10930                      }
10931                   }
10932                }
10933             }
10934          }
10935          /*Res Alloc Type for UL */
10936          if(cuPuschCfg->choice.setup->resourceAllocation)
10937          {
10938             macPuschCfg->resourceAllocType = \
10939                cuPuschCfg->choice.setup->resourceAllocation;
10940          }
10941          if(cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList)
10942          {
10943             timeDomAllocList = cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList;
10944             if(timeDomAllocList->present == PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup)
10945             {
10946                if(timeDomAllocList->choice.setup)
10947                {
10948                   macPuschCfg->numTimeDomRsrcAlloc = timeDomAllocList->choice.setup->list.count;
10949                   for(timeDomIdx = 0; timeDomIdx <timeDomAllocList->choice.setup->list.count; timeDomIdx++)
10950                   {
10951                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].k2 = \
10952                         *(timeDomAllocList->choice.setup->list.array[timeDomIdx]->k2);
10953                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].mappingType = \
10954                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->mappingType;
10955                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].startSymbolAndLength = \
10956                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
10957                   }
10958                }
10959             }
10960          }
10961          if(cuPuschCfg->choice.setup->transformPrecoder)
10962             macPuschCfg->transformPrecoder = *(cuPuschCfg->choice.setup->transformPrecoder);
10963       }
10964    }
10965 }
10966
10967 /*******************************************************************
10968  *
10969  * @brief Function to fill pucch Power Control
10970  *
10971  * @details
10972  *
10973  *    Function : extractPucchPowerControl
10974  *
10975  *    Functionality: Function to fill pucch Power Control
10976  *
10977  * @params[in] PucchPowerControl *pwrCtrl,
10978  *             struct PUCCH_PowerControl *cuPwrCtrlCfg
10979  * @return void
10980  *
10981  * ****************************************************************/
10982
10983 void extractPucchPowerControl(PucchPowerControl *pwrCtrl, struct PUCCH_PowerControl *cuPwrCtrlCfg)
10984 {
10985    uint8_t arrIdx;
10986
10987    if(cuPwrCtrlCfg->deltaF_PUCCH_f0)
10988       pwrCtrl->deltaF_Format0 = *cuPwrCtrlCfg->deltaF_PUCCH_f0;
10989    if(cuPwrCtrlCfg->deltaF_PUCCH_f1)
10990       pwrCtrl->deltaF_Format1 = *cuPwrCtrlCfg->deltaF_PUCCH_f1;
10991    if(cuPwrCtrlCfg->deltaF_PUCCH_f2)
10992       pwrCtrl->deltaF_Format2 = *cuPwrCtrlCfg->deltaF_PUCCH_f2;
10993    if(cuPwrCtrlCfg->deltaF_PUCCH_f3)
10994       pwrCtrl->deltaF_Format3 = *cuPwrCtrlCfg->deltaF_PUCCH_f3;
10995    if(cuPwrCtrlCfg->deltaF_PUCCH_f4)
10996       pwrCtrl->deltaF_Format4 = *cuPwrCtrlCfg->deltaF_PUCCH_f4;
10997    if(cuPwrCtrlCfg->p0_Set)
10998    {
10999       pwrCtrl->p0SetCount = cuPwrCtrlCfg->p0_Set->list.count;
11000       for(arrIdx=0; arrIdx < pwrCtrl->p0SetCount; arrIdx++)
11001       {
11002          pwrCtrl->p0Set[arrIdx].p0PucchId =\
11003             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Id;
11004          pwrCtrl->p0Set[arrIdx].p0PucchVal =\
11005             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Value;
11006       }
11007    }
11008    if(cuPwrCtrlCfg->pathlossReferenceRSs)
11009    {
11010       pwrCtrl->pathLossRefRSListCount = cuPwrCtrlCfg->pathlossReferenceRSs->list.count;
11011       for(arrIdx = 0; arrIdx < pwrCtrl->pathLossRefRSListCount; arrIdx++)
11012       {
11013          pwrCtrl->pathLossRefRSList[arrIdx].pathLossRefRSId =\
11014             cuPwrCtrlCfg->pathlossReferenceRSs->list.array[arrIdx]->pucch_PathlossReferenceRS_Id;
11015       }
11016    }
11017 }
11018  
11019  /*******************************************************************
11020  *
11021  * @brief Function to extractResrcSetToAddModList sent by CU
11022  *
11023  * @details
11024  *
11025  *    Function : extractResrcSetToAddModList
11026  *
11027  *    Functionality: Fucntion to extractResrcSetToAddModList
11028  *
11029  * @params[in] PucchResrcSetCfg pointer,
11030  *             struct PUCCH_Config__resourceSetToAddModList pointer
11031  * @return void
11032  *
11033  * ****************************************************************/
11034
11035 void extractResrcSetToAddModList(PucchResrcSetCfg *macRsrcSetList, struct PUCCH_Config__resourceSetToAddModList *cuRsrcSetList)
11036 {
11037    uint8_t arrIdx, rsrcListIdx;
11038
11039    macRsrcSetList->resrcSetToAddModListCount = cuRsrcSetList->list.count; 
11040    for(arrIdx = 0; arrIdx < macRsrcSetList->resrcSetToAddModListCount; arrIdx++)
11041    {
11042       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcSetId     =\
11043          cuRsrcSetList->list.array[arrIdx]->pucch_ResourceSetId;
11044       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount =\
11045          cuRsrcSetList->list.array[arrIdx]->resourceList.list.count;
11046       for(rsrcListIdx = 0; rsrcListIdx < macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount; rsrcListIdx++)
11047       {
11048          macRsrcSetList->resrcSetToAddModList[arrIdx].resrcList[rsrcListIdx] =\
11049             *cuRsrcSetList->list.array[arrIdx]->resourceList.list.array[rsrcListIdx];
11050       }
11051
11052       if(cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1)
11053       {
11054          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize =\
11055             *cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1;
11056       }
11057       else
11058       {
11059          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize = 0;
11060       }
11061    }
11062 }/* End of extractResrcSetToAddModList */
11063
11064 /*******************************************************************
11065  *
11066  * @brief Fills extractResrcToAddModList sent by CU
11067  *
11068  * @details
11069  *
11070  *    Function : extractResrcToAddModList
11071  *
11072  *    Functionality: Fills extractResrcToAddModList
11073  *
11074  * @params[in] PucchResrcCfg pointer,
11075  *             struct PUCCH_Config__resourceToAddModList pointer
11076  * @return ROk/RFAILED
11077  *
11078  * ****************************************************************/
11079
11080 uint8_t extractResrcToAddModList(PucchResrcCfg *macResrcList, struct PUCCH_Config__resourceToAddModList *cuResrcList)
11081 {
11082    uint8_t arrIdx;
11083    
11084    macResrcList->resrcToAddModListCount = cuResrcList->list.count;
11085    for(arrIdx = 0; arrIdx < macResrcList->resrcToAddModListCount; arrIdx++)
11086    {
11087       macResrcList->resrcToAddModList[arrIdx].resrcId      =\
11088         cuResrcList->list.array[arrIdx]->pucch_ResourceId; 
11089       macResrcList->resrcToAddModList[arrIdx].startPrb     =\
11090         cuResrcList->list.array[arrIdx]->startingPRB;
11091       if(cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping)
11092       {
11093          macResrcList->resrcToAddModList[arrIdx].intraFreqHop =\
11094            *cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping;
11095       }
11096       if(cuResrcList->list.array[arrIdx]->secondHopPRB)
11097       {
11098          macResrcList->resrcToAddModList[arrIdx].secondPrbHop =\
11099            *cuResrcList->list.array[arrIdx]->secondHopPRB;
11100       }
11101       /* PUCCH RSRC FORMAT */
11102       if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format0)
11103       {
11104          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_0;
11105          if(cuResrcList->list.array[arrIdx]->format.choice.format0)
11106          {
11107             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0, sizeof(PucchFormat0));
11108             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0 == NULLP)
11109             {
11110                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format0 in extractResrcToAddModList()");
11111                return RFAILED;
11112             }
11113             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->initialCyclicShift =\
11114                cuResrcList->list.array[arrIdx]->format.choice.format0->initialCyclicShift;
11115             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->numSymbols =\
11116                cuResrcList->list.array[arrIdx]->format.choice.format0->nrofSymbols;
11117             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->startSymbolIdx =\
11118                cuResrcList->list.array[arrIdx]->format.choice.format0->startingSymbolIndex;
11119          }
11120       }
11121       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format1)
11122       {
11123          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_1;
11124          if(cuResrcList->list.array[arrIdx]->format.choice.format1)
11125          {
11126             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1, sizeof(PucchFormat1));
11127             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1 == NULLP)
11128             {
11129                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format1 in extractResrcToAddModList()");
11130                return RFAILED;
11131             }
11132             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->initialCyclicShift =\
11133                 cuResrcList->list.array[arrIdx]->format.choice.format1->initialCyclicShift;
11134             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->numSymbols =\
11135                 cuResrcList->list.array[arrIdx]->format.choice.format1->nrofSymbols;
11136             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->startSymbolIdx =\
11137                 cuResrcList->list.array[arrIdx]->format.choice.format1->startingSymbolIndex;
11138             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->timeDomOCC =\
11139                 cuResrcList->list.array[arrIdx]->format.choice.format1->timeDomainOCC;
11140          }
11141       }
11142       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format2)
11143       {
11144          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_2;
11145          if(cuResrcList->list.array[arrIdx]->format.choice.format2)
11146          {
11147             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
11148             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2 == NULLP)
11149             {
11150                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format2 in extractResrcToAddModList()");
11151                return RFAILED;
11152             }
11153             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numPrbs =\
11154                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofPRBs;
11155             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numSymbols =\
11156                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofSymbols;
11157             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->startSymbolIdx =\
11158                 cuResrcList->list.array[arrIdx]->format.choice.format2->startingSymbolIndex;
11159          }
11160       }
11161       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format3)
11162       {
11163          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_3;
11164          if(cuResrcList->list.array[arrIdx]->format.choice.format3)
11165          {
11166             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
11167             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3 == NULLP)
11168             {
11169                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format3 in extractResrcToAddModList()");
11170                return RFAILED;
11171             }
11172             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numPrbs =\
11173                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofPRBs;
11174             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numSymbols =\
11175                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofSymbols;
11176             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->startSymbolIdx =\
11177                 cuResrcList->list.array[arrIdx]->format.choice.format3->startingSymbolIndex;
11178          }
11179       }
11180       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format4)
11181       {
11182          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_4;
11183          if(cuResrcList->list.array[arrIdx]->format.choice.format4)
11184          {
11185             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4, sizeof(PucchFormat4));
11186             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4 == NULLP)
11187             {
11188                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format4 in extractResrcToAddModList()");
11189                return RFAILED;
11190             }
11191             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->numSymbols =\
11192                 cuResrcList->list.array[arrIdx]->format.choice.format4->nrofSymbols;
11193             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occLen =\
11194                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Length;
11195             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occIdx =\
11196                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Index;
11197             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->startSymbolIdx =\
11198                 cuResrcList->list.array[arrIdx]->format.choice.format4->startingSymbolIndex;
11199          }
11200       }
11201    }
11202    return ROK;
11203
11204 }/* End of extractResrcToAddModList */
11205
11206 /*******************************************************************
11207  *
11208  * @brief Fills fillPucchSchedReqPeriodAndOffset sent by CU
11209  *
11210  * @details
11211  *
11212  *    Function : fillPucchSchedReqPeriodAndOffset
11213  *
11214  *    Functionality: To fillPucchSchedReqPeriodAndOffset
11215  *
11216  * @params[in] macPeriodicty,
11217  *     SchedulingRequestResourceConfig__periodicityAndOffset pointer
11218  * @return void
11219  *
11220  * ****************************************************************/
11221
11222 void fillPucchSchedReqPeriodAndOffset(uint8_t macPeriodicty, uint16_t  macOffset,\
11223    struct SchedulingRequestResourceConfig__periodicityAndOffset *cuPeriodicty)
11224 {
11225    macPeriodicty = cuPeriodicty->present;
11226    switch(macPeriodicty)
11227    {
11228       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
11229          {
11230             macOffset     = cuPeriodicty->choice.sym2;
11231             break;
11232          }
11233       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
11234          {
11235             macOffset     = cuPeriodicty->choice.sym6or7;
11236             break;
11237          }
11238       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
11239          {
11240             macOffset     = cuPeriodicty->choice.sl1;
11241             break;
11242          }
11243       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
11244          {
11245             macOffset = cuPeriodicty->choice.sl2;
11246             break;
11247          }
11248       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
11249          {
11250             macOffset = cuPeriodicty->choice.sl4;
11251             break;
11252          }
11253       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
11254          {
11255             macOffset = cuPeriodicty->choice.sl5;
11256             break;
11257          }
11258       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
11259          {
11260             macOffset = cuPeriodicty->choice.sl8;
11261             break;
11262          }
11263       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
11264          {
11265             macOffset = cuPeriodicty->choice.sl10;
11266             break;
11267          }
11268       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
11269          {
11270             macOffset = cuPeriodicty->choice.sl16;
11271             break;
11272          }
11273       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
11274          {
11275             macOffset = cuPeriodicty->choice.sl20;
11276             break;
11277          }
11278       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
11279          {
11280             macOffset = cuPeriodicty->choice.sl40;
11281             break;
11282          }
11283       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
11284          {
11285             macOffset = cuPeriodicty->choice.sl80;
11286             break;
11287          }
11288       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
11289          {
11290             macOffset = cuPeriodicty->choice.sl160;
11291             break;
11292          }
11293       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
11294          {
11295             macOffset = cuPeriodicty->choice.sl320;
11296             break;
11297          }
11298       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
11299          {
11300             macOffset = cuPeriodicty->choice.sl640;
11301             break;
11302          }
11303       default :
11304          DU_LOG("\nERROR  -->  F1AP : Invalid periodicity %d", macPeriodicty);
11305    }
11306 }
11307
11308 /*******************************************************************
11309  *
11310  * @brief Function to extractPucchFormatCfg sent by CU
11311  *
11312  * @details
11313  *
11314  *    Function : extractPucchFormatCfg
11315  *
11316  *    Functionality: Function to extractPucchFormatCfg
11317  *
11318  * @params[in] PucchFormatCfg pointer,
11319  *             PUCCH_FormatConfig_t pointer
11320  * @return void
11321  *
11322  * ****************************************************************/
11323
11324 void extractPucchFormatCfg(PucchFormatCfg *macFormatCfg, PUCCH_FormatConfig_t *cuFormatCfg)
11325  {
11326     if(cuFormatCfg->interslotFrequencyHopping)
11327        macFormatCfg->interSlotFreqHop = *cuFormatCfg->interslotFrequencyHopping;
11328     if(cuFormatCfg->additionalDMRS)  
11329        macFormatCfg->addDmrs = *cuFormatCfg->additionalDMRS;
11330     if(cuFormatCfg->maxCodeRate)
11331        macFormatCfg->maxCodeRate = *cuFormatCfg->maxCodeRate;
11332     if(cuFormatCfg->nrofSlots)  
11333        macFormatCfg->numSlots = *cuFormatCfg->nrofSlots;
11334     if(cuFormatCfg->pi2BPSK)  
11335        macFormatCfg->pi2BPSK = *cuFormatCfg->pi2BPSK;
11336     if(cuFormatCfg->simultaneousHARQ_ACK_CSI)  
11337        macFormatCfg->harqAckCSI = *cuFormatCfg->simultaneousHARQ_ACK_CSI;
11338  }/* End of extractPucchFormatCfg */
11339
11340 /*******************************************************************
11341  *
11342  * @brief Function to extractSchedReqCfgToAddMod sent by CU
11343  *
11344  * @details
11345  *
11346  *    Function : extractSchedReqCfgToAddMod
11347  *
11348  *    Functionality: Function to extractSchedReqCfgToAddMod
11349  *
11350  * @params[in] PucchSchedReqCfg pointer,
11351  *      PUCCH_Config__schedulingRequestResourceToAddModList pointer
11352  * @return void
11353  *
11354  * ****************************************************************/
11355
11356 void extractSchedReqCfgToAddMod(PucchSchedReqCfg *macSchedReqCfg, struct PUCCH_Config__schedulingRequestResourceToAddModList *cuSchedReqList)
11357 {
11358    uint8_t arrIdx;
11359
11360    macSchedReqCfg->schedAddModListCount = cuSchedReqList->list.count;
11361    for(arrIdx = 0; arrIdx <  macSchedReqCfg->schedAddModListCount; arrIdx++)
11362    {
11363       macSchedReqCfg->schedAddModList[arrIdx].resrcId =\
11364          cuSchedReqList->list.array[arrIdx]->schedulingRequestResourceId;
11365       macSchedReqCfg->schedAddModList[arrIdx].requestId =\
11366          cuSchedReqList->list.array[arrIdx]->schedulingRequestID;
11367       if(cuSchedReqList->list.array[arrIdx]->periodicityAndOffset)
11368       {
11369          fillPucchSchedReqPeriodAndOffset(macSchedReqCfg->schedAddModList[arrIdx].periodicity,\
11370             macSchedReqCfg->schedAddModList[arrIdx].offset, cuSchedReqList->list.array[arrIdx]->periodicityAndOffset);
11371       }
11372       if(cuSchedReqList->list.array[arrIdx]->resource)
11373       {
11374          macSchedReqCfg->schedAddModList[arrIdx].resrc =\
11375             *cuSchedReqList->list.array[arrIdx]->resource;
11376       }
11377    }
11378
11379 }/* End of extractSchedReqCfgToAddMod */
11380
11381  /*******************************************************************
11382  *
11383  * @brief Fills PucchCfg received by CU
11384  *
11385  * @details
11386  *
11387  *    Function : extractPucchCfg
11388  *
11389  *    Functionality: Fills PucchCfg received  by CU
11390  *
11391  * @params[in] BWP_UplinkDedicated__pucch_Config *cuPucchCfg = Information which
11392  *                is send by CU, which we have stored in F1UeContextSetupDb,
11393  *             PucchCfg *macPucchCfg = Used to Store the information which
11394  *                needs to send in other layer, as well as this can be the variable
11395  *                which stores the information in DuCb,
11396  *             PucchCfg *storedPucchCfg = Null in case of sending the
11397  *                information to other layer else it will have Pucch Cfg which
11398  *                we have stored in copyOfmacUeCfg.
11399  * @return ROK/RFAILED
11400  *
11401  * ****************************************************************/
11402
11403 uint8_t extractPucchCfg(struct BWP_UplinkDedicated__pucch_Config *cuPucchCfg, PucchCfg *macPucchCfg,\
11404 PucchCfg *storedPucchCfg)        
11405 {
11406    uint8_t arrIdx;
11407
11408    if(cuPucchCfg->present == BWP_UplinkDedicated__pucch_Config_PR_setup)
11409    {
11410       if(cuPucchCfg->choice.setup)
11411       {
11412          /* Resource Set Cfg */ 
11413          if(cuPucchCfg->choice.setup->resourceSetToAddModList)
11414          {
11415             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrcSet, sizeof(PucchResrcSetCfg));
11416             if(macPucchCfg->resrcSet == NULLP)
11417             {
11418                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc set List in extractPucchCfg()");
11419                return RFAILED;
11420             }
11421             memset(macPucchCfg->resrcSet, 0, sizeof(PucchResrcSetCfg));
11422             extractResrcSetToAddModList(macPucchCfg->resrcSet, cuPucchCfg->choice.setup->resourceSetToAddModList);
11423          }
11424          
11425          /* Resource Cfg */ 
11426          if(cuPucchCfg->choice.setup->resourceToAddModList)
11427          {
11428             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrc, sizeof(PucchResrcCfg));
11429             if(macPucchCfg->resrc == NULLP)
11430             {
11431                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc List in extractPucchCfg()");
11432                return RFAILED;
11433             }
11434             memset(macPucchCfg->resrc, 0, sizeof(PucchResrcCfg));
11435             extractResrcToAddModList(macPucchCfg->resrc, cuPucchCfg->choice.setup->resourceToAddModList);
11436          }
11437          
11438          /* Format 1 Cfg */ 
11439          if(cuPucchCfg->choice.setup->format1)
11440          {
11441             DU_ALLOC_SHRABL_BUF(macPucchCfg->format1, sizeof(PucchFormatCfg));
11442             if(macPucchCfg->format1 == NULLP)
11443             {
11444                DU_LOG("\nERROR --> F1AP : Failed to extract format 1 Cfg in  extractPucchCfg()");
11445                return RFAILED;
11446             }
11447             memset(macPucchCfg->format1, 0, sizeof(PucchFormatCfg));
11448             extractPucchFormatCfg(macPucchCfg->format1,\
11449                cuPucchCfg->choice.setup->format1->choice.setup);
11450          }
11451          
11452          /* Format 2 Cfg */
11453          if(cuPucchCfg->choice.setup->format2)
11454          {
11455             DU_ALLOC_SHRABL_BUF(macPucchCfg->format2, sizeof(PucchFormatCfg));
11456             if(macPucchCfg->format2 == NULLP)
11457             {
11458                DU_LOG("\nERROR --> F1AP : Failed to extract format 2 Cfg in  extractPucchCfg()");
11459                return RFAILED;
11460             }
11461             memset(macPucchCfg->format2, 0, sizeof(PucchFormatCfg));
11462             extractPucchFormatCfg(macPucchCfg->format2,\
11463                cuPucchCfg->choice.setup->format2->choice.setup);
11464          }
11465          
11466          /* Format 3 Cfg */
11467          if(cuPucchCfg->choice.setup->format3)
11468          {
11469             DU_ALLOC_SHRABL_BUF(macPucchCfg->format3, sizeof(PucchFormatCfg));
11470             if(macPucchCfg->format3 == NULLP)
11471             {
11472                DU_LOG("\nERROR --> F1AP : Failed to extract format 3 Cfg in  extractPucchCfg()");
11473                return RFAILED;
11474             }
11475             memset(macPucchCfg->format3, 0, sizeof(PucchFormatCfg));
11476             extractPucchFormatCfg(macPucchCfg->format3,\
11477                cuPucchCfg->choice.setup->format3->choice.setup);
11478          }
11479
11480          /* Format 4 Cfg */
11481          if(cuPucchCfg->choice.setup->format4)
11482          {
11483             DU_ALLOC_SHRABL_BUF(macPucchCfg->format4, sizeof(PucchFormatCfg));
11484             if(macPucchCfg->format4 == NULLP)
11485             {
11486                DU_LOG("\nERROR --> F1AP : Failed to extract format 4 Cfg in  extractPucchCfg()");
11487                return RFAILED;
11488             }
11489             memset(macPucchCfg->format4, 0, sizeof(PucchFormatCfg));
11490             extractPucchFormatCfg(macPucchCfg->format4,\
11491                cuPucchCfg->choice.setup->format4->choice.setup);
11492          }
11493
11494          /* Sched Req List */
11495          if(cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList)
11496          {
11497             DU_ALLOC_SHRABL_BUF(macPucchCfg->schedReq, sizeof(PucchSchedReqCfg));
11498             if(macPucchCfg->schedReq == NULLP)
11499             {
11500                DU_LOG("\nERROR --> F1AP : Failed to extract schedReqCfg in  extractPucchCfg()");
11501                return RFAILED;
11502             }
11503             memset(macPucchCfg->schedReq, 0, sizeof(PucchSchedReqCfg));
11504             extractSchedReqCfgToAddMod(macPucchCfg->schedReq,\
11505             cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList);
11506          }
11507
11508          /*TODO: Add support for  Spatial Info */
11509
11510          /* MultiCsiCfg */
11511          if(cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList)
11512          {
11513             DU_ALLOC_SHRABL_BUF(macPucchCfg->multiCsiCfg, sizeof(PucchMultiCsiCfg));
11514             if(macPucchCfg->multiCsiCfg == NULLP)
11515             {
11516                DU_LOG("\nERROR --> F1AP : Failed to extract multiCsiCfg in  extractPucchCfg()");
11517                return RFAILED;
11518             }
11519             memset(macPucchCfg->multiCsiCfg, 0, sizeof(PucchMultiCsiCfg));
11520             macPucchCfg->multiCsiCfg->multiCsiResrcListCount = cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.count;
11521             for(arrIdx =0; arrIdx < macPucchCfg->multiCsiCfg->multiCsiResrcListCount; arrIdx++)
11522             {
11523                macPucchCfg->multiCsiCfg->multiCsiResrcList[arrIdx] =\
11524                  *cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.array[arrIdx];
11525             }
11526          }
11527
11528          /* Dl_DataToUL_ACK */ 
11529          if(cuPucchCfg->choice.setup->dl_DataToUL_ACK)
11530     {
11531        if(storedPucchCfg)
11532        {
11533           if(storedPucchCfg->dlDataToUlAck)
11534           {
11535              macPucchCfg->dlDataToUlAck = storedPucchCfg->dlDataToUlAck; 
11536           }
11537           else
11538           {
11539             DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
11540           }
11541        }
11542        else
11543        {
11544           DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
11545        }
11546        if(macPucchCfg->dlDataToUlAck == NULLP)
11547        {
11548           DU_LOG("\nERROR --> F1AP : Failed to extract Dl_DataToUL_ACK in extractPucchCfg()");
11549           return RFAILED;
11550        }
11551        memset(macPucchCfg->dlDataToUlAck, 0, sizeof(PucchDlDataToUlAck));
11552        macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount = cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.count;
11553        for(arrIdx = 0; arrIdx < macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; arrIdx++)
11554        {
11555           macPucchCfg->dlDataToUlAck->dlDataToUlAckList[arrIdx] =\
11556           *cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.array[arrIdx];
11557        }
11558          }
11559
11560          /* Power Control */
11561          if(cuPucchCfg->choice.setup->pucch_PowerControl)
11562          {
11563             DU_ALLOC_SHRABL_BUF(macPucchCfg->powerControl, sizeof(PucchPowerControl));
11564             if(macPucchCfg->powerControl == NULLP)
11565             {
11566                DU_LOG("\nERROR --> F1AP : Failed to extract power control in extractPucchCfg()");
11567                return RFAILED;
11568             }
11569             extractPucchPowerControl(macPucchCfg->powerControl,\
11570                cuPucchCfg->choice.setup->pucch_PowerControl);
11571          }
11572       }
11573    }
11574    return ROK;
11575 }
11576
11577 /*******************************************************************
11578  *
11579  * @brief Fills ServingCellReconfig received by CU
11580  *
11581  * @details
11582  *
11583  *    Function : extractSpCellDedicatedCfg
11584  *
11585  *    Functionality: Fills ServingCellReconfig received  by CU
11586  *
11587  * @params[in] ServingCellConfig_t *cuSrvCellCfg = Information which is send by
11588  *                  CU, which we have stored in F1UeContextSetupDb,
11589  *             ServCellCfgInfo *macSrvCellCfg = Used to Store the information
11590  *                  which  needs to send in other layer, as well as this can be the
11591  *                  variable which stores the information in DuCb, 
11592  *             ServCellCfgInfo *storedSrvCellCfg = Null in case of sending the
11593  *                  information to other layer else it will have ServCellCfgInfo which
11594  *                  we have stored in copyOfmacUeCfg.
11595  * @return ROK/RFAILD
11596  *
11597  * ****************************************************************/
11598 uint8_t extractSpCellDedicatedCfg(ServingCellConfig_t *cuSrvCellCfg, ServCellCfgInfo *macSrvCellCfg,\
11599 ServCellCfgInfo *storedSrvCellCfg)
11600 {
11601    uint8_t ret = ROK;
11602    BWP_DownlinkDedicated_t *dlBwp = NULLP;
11603    BWP_UplinkDedicated_t   *ulBwp = NULLP;
11604
11605    if(cuSrvCellCfg->initialDownlinkBWP)
11606    {
11607       dlBwp = ((BWP_DownlinkDedicated_t *)(cuSrvCellCfg->initialDownlinkBWP));
11608       if(dlBwp->pdcch_Config)
11609       {
11610          if(dlBwp->pdcch_Config->choice.setup)
11611          {
11612             macSrvCellCfg->initDlBwp.pdcchPresent = true;
11613             if(storedSrvCellCfg)
11614             {
11615                if(!storedSrvCellCfg->initDlBwp.pdcchPresent)
11616                {
11617                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11618                }
11619                else
11620                {
11621                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11622                }
11623             }
11624             else
11625             {
11626                extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11627             }
11628          }
11629       }
11630       if(dlBwp->pdsch_Config)
11631       {
11632          if(dlBwp->pdsch_Config->choice.setup)
11633          {
11634             macSrvCellCfg->initDlBwp.pdschPresent = true;
11635             
11636             if(storedSrvCellCfg)
11637             {
11638                if(!storedSrvCellCfg->initDlBwp.pdschPresent)
11639                {
11640                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
11641                }
11642                else
11643                {
11644                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg,\
11645                         &storedSrvCellCfg->initDlBwp.pdschCfg);
11646                }
11647             }
11648             else
11649             {
11650                extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
11651             }
11652          }
11653       }
11654    }
11655    if(cuSrvCellCfg->firstActiveDownlinkBWP_Id)
11656       macSrvCellCfg->firstActvDlBwpId = *(cuSrvCellCfg->firstActiveDownlinkBWP_Id);
11657    if(cuSrvCellCfg->defaultDownlinkBWP_Id)
11658       macSrvCellCfg->defaultDlBwpId = *(cuSrvCellCfg->defaultDownlinkBWP_Id);
11659    if(cuSrvCellCfg->bwp_InactivityTimer)
11660    {
11661       if(macSrvCellCfg->bwpInactivityTmr)
11662       {
11663          memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
11664       }
11665       else
11666       {
11667          macSrvCellCfg->bwpInactivityTmr = NULLP;
11668          DU_ALLOC_SHRABL_BUF(macSrvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
11669          if(macSrvCellCfg->bwpInactivityTmr)
11670          {
11671             memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
11672          }
11673          else
11674          {
11675             DU_LOG("\nERROR  --> F1AP : Memory Alloc failed for bwpInactivityTmr at extractSpCellDedicatedCfg()");
11676             return RFAILED;
11677          }
11678       }
11679    }
11680    if(cuSrvCellCfg->pdsch_ServingCellConfig)
11681    {
11682       if(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup)
11683       {
11684          ret = extractPdschServingCellCfg(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup, &macSrvCellCfg->pdschServCellCfg);
11685          if(ret == RFAILED)
11686          {
11687             DU_LOG("\nERROR --> F1AP : Failed at extractPdschServingCellCfg()");
11688             return RFAILED;
11689          }
11690       }
11691    }
11692    if(cuSrvCellCfg->uplinkConfig)
11693    {
11694       if(cuSrvCellCfg->uplinkConfig->initialUplinkBWP)
11695       {
11696          ulBwp = ((BWP_UplinkDedicated_t *)(cuSrvCellCfg->uplinkConfig->initialUplinkBWP));
11697          if(ulBwp->pusch_Config)
11698          {
11699             macSrvCellCfg->initUlBwp.puschPresent = true;
11700             extractPuschCfg(ulBwp->pusch_Config, &macSrvCellCfg->initUlBwp.puschCfg);
11701          }
11702          if(ulBwp->pucch_Config)
11703          {
11704             macSrvCellCfg->initUlBwp.pucchPresent = true;
11705             memset(&macSrvCellCfg->initUlBwp.pucchCfg, 0, sizeof(PucchCfg));
11706             if(storedSrvCellCfg)
11707             {
11708                if(!storedSrvCellCfg->initUlBwp.pucchPresent)
11709                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
11710                else
11711                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg,\
11712                   &storedSrvCellCfg->initUlBwp.pucchCfg);
11713             }
11714             else
11715             {
11716                extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
11717             }
11718          }
11719       }
11720       if(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id)
11721          macSrvCellCfg->firstActvUlBwpId = *(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id);
11722    }
11723    return ret;
11724 }
11725 /*******************************************************************
11726  *
11727  * @brief Fills Reconfig Cell group Info received by CU
11728  *
11729  * @details
11730  *
11731  *    Function : extractUeReCfgCellInfo
11732  *
11733  *    Functionality: Fills Reconfig Cell group Info received by CU
11734  *   
11735  * @params[in] CellGroupConfigRrc_t *cellGrp = CellGroupConfigRrc_t information which
11736  *                       is send by CU, which we have stored in F1UeContextSetupDb
11737  *             MacUeCfg *MacUeCfg = Used to Store the information,
11738  *                      which needs to send in other layer, as well as this can be
11739  *                      the variable which stores the information in DuCb,
11740  *             MacUeCfg *storedMacUeCfg = Null in case of sending the
11741  *                      information to other layer else it will have copyOfmacUeCfg
11742  *                      which we have stored in F1UeContextSetupDb.
11743  *
11744  * @return ROK/RFAILED
11745  *
11746  * ****************************************************************/
11747 uint8_t extractUeReCfgCellInfo(CellGroupConfigRrc_t *cellGrp, MacUeCfg *macUeCfg, MacUeCfg *storedMacUeCfg)
11748 {
11749    uint8_t ret = ROK;
11750    MAC_CellGroupConfig_t     *macCellGroup = NULLP;
11751    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
11752    SpCellConfig_t            *spcellCfg = NULLP;
11753    ServingCellConfig_t       *servCellCfg = NULLP;
11754
11755    if(cellGrp)
11756    {
11757       /* Fill MacCell Group Reconfig  */
11758       if(cellGrp->mac_CellGroupConfig)
11759       {
11760          macUeCfg->macCellGrpCfgPres = true;
11761          macCellGroup = ((MAC_CellGroupConfig_t *)(cellGrp->mac_CellGroupConfig));
11762          if(macCellGroup->schedulingRequestConfig)
11763          {
11764             extractSchReqReConfig(macCellGroup->schedulingRequestConfig, &macUeCfg->macCellGrpCfg.schReqCfg);
11765          }
11766          if(macCellGroup->tag_Config)
11767          {
11768             extractTagReconfig(macCellGroup->tag_Config, &macUeCfg->macCellGrpCfg.tagCfg);
11769          }
11770          if(macCellGroup->bsr_Config)
11771          {
11772             macUeCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer = macCellGroup->bsr_Config->periodicBSR_Timer;
11773             macUeCfg->macCellGrpCfg.bsrTmrCfg.retxTimer     = macCellGroup->bsr_Config->retxBSR_Timer;
11774             if(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer)
11775             {
11776                macUeCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer  =\
11777                *(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer);
11778             }
11779          }
11780          if(macCellGroup->phr_Config)
11781          {
11782             if(macCellGroup->phr_Config->present == MAC_CellGroupConfig__phr_Config_PR_setup)
11783             {
11784                macUeCfg->macCellGrpCfg.phrCfgSetupPres = true;
11785                if(macCellGroup->phr_Config->choice.setup)
11786                {
11787                   macUeCfg->macCellGrpCfg.phrCfg.periodicTimer     = \
11788                   macCellGroup->phr_Config->choice.setup->phr_PeriodicTimer;
11789                   macUeCfg->macCellGrpCfg.phrCfg.prohibitTimer     = \
11790                   macCellGroup->phr_Config->choice.setup->phr_ProhibitTimer;
11791                   macUeCfg->macCellGrpCfg.phrCfg.txPowerFactor     = \
11792                   macCellGroup->phr_Config->choice.setup->phr_Tx_PowerFactorChange;
11793                   macUeCfg->macCellGrpCfg.phrCfg.multiplePHR       = \
11794                   macCellGroup->phr_Config->choice.setup->multiplePHR;
11795                   macUeCfg->macCellGrpCfg.phrCfg.dummy             = \
11796                   macCellGroup->phr_Config->choice.setup->dummy;
11797                   macUeCfg->macCellGrpCfg.phrCfg.phrType2OtherCell = \
11798                   macCellGroup->phr_Config->choice.setup->phr_Type2OtherCell;
11799                   macUeCfg->macCellGrpCfg.phrCfg.phrOtherCG        = \
11800                   macCellGroup->phr_Config->choice.setup->phr_ModeOtherCG;
11801                }
11802             }
11803          }
11804       }
11805       /* Fill Physical Cell Group Reconfig */
11806       if(cellGrp->physicalCellGroupConfig)
11807       {
11808          macUeCfg->phyCellGrpCfgPres = true;
11809          phyCellGrpCfg = ((PhysicalCellGroupConfig_t *)(cellGrp->physicalCellGroupConfig));
11810          if(phyCellGrpCfg->p_NR_FR1)
11811          {
11812             if(*(phyCellGrpCfg->p_NR_FR1) != macUeCfg->phyCellGrpCfg.pNrFr1)
11813                macUeCfg->phyCellGrpCfg.pNrFr1 = *(phyCellGrpCfg->p_NR_FR1);
11814          }
11815          macUeCfg->phyCellGrpCfg.pdschHarqAckCodebook = phyCellGrpCfg->pdsch_HARQ_ACK_Codebook;
11816       }
11817       /* Fill SpCell Reconfig */
11818       if(cellGrp->spCellConfig)
11819       {
11820          macUeCfg->spCellCfgPres = true;
11821          spcellCfg = ((SpCellConfig_t *)(cellGrp->spCellConfig));  
11822          if(spcellCfg->servCellIndex)
11823          {
11824             macUeCfg->spCellCfg.servCellIdx = *(spcellCfg->servCellIndex);
11825          }
11826          /* Fill Serving cell Reconfig info */
11827          if(cellGrp->spCellConfig->spCellConfigDedicated)
11828          {
11829             servCellCfg = ((ServingCellConfig_t *)(cellGrp->spCellConfig->spCellConfigDedicated));
11830             if(storedMacUeCfg)
11831             {
11832                if(!storedMacUeCfg->spCellCfgPres)
11833                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
11834                else
11835                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg,\
11836                         &storedMacUeCfg->spCellCfg.servCellCfg);
11837             }
11838             else
11839             {
11840                ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
11841             }
11842             if(ret == RFAILED)
11843             {
11844                DU_LOG("\nERROR --> F1AP : Failed at extractSpCellDedicatedCfg()");
11845             }
11846          }
11847       }
11848    }
11849    return ret;
11850 }
11851 /*******************************************************************
11852 *
11853 * @brief free the memory allocated by decoder
11854 *
11855 * @details
11856 *
11857 *    Function : freeAperDecodeNrcgi 
11858 *
11859 *    Functionality: Free Nrcgi values
11860 *
11861 * @params[in] NRCGI_t *nrcgi
11862 * @return void
11863 *
11864 * ****************************************************************/
11865
11866
11867 void freeAperDecodeNrcgi(NRCGI_t *nrcgi)
11868 {
11869     if(nrcgi->pLMN_Identity.buf != NULLP)
11870     {
11871        free(nrcgi->pLMN_Identity.buf);
11872     }
11873     if(nrcgi->nRCellIdentity.buf != NULLP)
11874     {
11875        free(nrcgi->nRCellIdentity.buf);
11876     }
11877 }
11878 /*******************************************************************
11879 *
11880 * @brief free the memory allocated by decoder
11881 *
11882 * @details
11883 *
11884 *    Function : freeAperDecodeCuToDuInfo 
11885 *
11886 *    Functionality:  Free Cu To Du Information
11887 *
11888 * @params[in] CUtoDURRCInformation_t *rrcMsg
11889 * @return void
11890 *
11891 * ****************************************************************/
11892
11893
11894 void freeAperDecodeCuToDuInfo(CUtoDURRCInformation_t *rrcMsg)
11895 {
11896    uint8_t ieIdx =0;
11897    uint8_t arrIdx =0;
11898
11899    if(rrcMsg->uE_CapabilityRAT_ContainerList)
11900    {
11901       if(rrcMsg->uE_CapabilityRAT_ContainerList->buf)
11902          free(rrcMsg->uE_CapabilityRAT_ContainerList->buf);
11903       free(rrcMsg->uE_CapabilityRAT_ContainerList);
11904    }
11905
11906    if(rrcMsg->iE_Extensions)
11907    {
11908       if(rrcMsg->iE_Extensions->list.array)
11909       {
11910          for(ieIdx= 0; ieIdx < rrcMsg->iE_Extensions->list.count; ieIdx++)
11911          {
11912             if(rrcMsg->iE_Extensions->list.array[ieIdx])
11913             {
11914                switch(rrcMsg->iE_Extensions->list.array[ieIdx]->id)
11915                {
11916                   case ProtocolIE_ID_id_CellGroupConfig:
11917                      if(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf != NULLP)
11918                      {
11919                         free(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf);
11920                      }
11921                      break;
11922                   default:
11923                      DU_LOG("\nERROR  -->  F1AP : Invalid Event type %ld at FreeCuToDuInfo()", \
11924                            rrcMsg->iE_Extensions->list.array[ieIdx]->id);
11925                      break;
11926                }
11927             }
11928          }
11929          for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
11930          {
11931             free(rrcMsg->iE_Extensions->list.array[arrIdx]);
11932          }
11933          free(rrcMsg->iE_Extensions->list.array);
11934
11935       }
11936
11937       free(rrcMsg->iE_Extensions);
11938    }
11939 }
11940 /*******************************************************************
11941 *
11942 * @brief free the memory allocated by decoder
11943 *
11944 * @details 
11945 *
11946 *    Function : freeAperDecodeSplCellList
11947 *
11948 *    Functionality: Free Spl Cell List 
11949                     where memory allocated by aper_decoder
11950 *
11951 * @params[in]  SCell_ToBeSetup_List_t *spCellLst
11952 * @return void
11953 *
11954 * ****************************************************************/
11955
11956
11957 void freeAperDecodeSplCellList(SCell_ToBeSetup_List_t *spCellLst)
11958 {
11959     uint8_t  cellIdx =0;
11960
11961     if(spCellLst->list.array != NULLP)
11962     {
11963        for(cellIdx=0; cellIdx<spCellLst->list.count; cellIdx++)
11964        {
11965           if(cellIdx==0&&spCellLst->list.array[cellIdx]!=NULLP)
11966           {
11967              freeAperDecodeNrcgi(&spCellLst->list.array[cellIdx]->value.choice.SCell_ToBeSetup_Item.sCell_ID);
11968           }
11969           if(spCellLst->list.array[cellIdx]!=NULLP)
11970           {
11971              free(spCellLst->list.array[cellIdx]);
11972           }
11973        }
11974        free(spCellLst->list.array);
11975     }
11976 }
11977 /*******************************************************************
11978 *
11979 * @brief free the memory allocated by decoder
11980 *
11981 * @details
11982 *
11983 *    Function : freeAperDecodeSRBSetup 
11984 *
11985 *    Functionality: added free part for the memory allocated by aper_decoder
11986 *
11987 * @params[in] SRBs_ToBeSetup_List_t *srbSet
11988 * @return void
11989 *
11990 ****************************************************************/
11991
11992
11993 void freeAperDecodeSRBSetup(SRBs_ToBeSetup_List_t *srbSet)
11994 {
11995     uint8_t srbIdx =0;
11996     if(srbSet->list.array != NULLP)
11997     {
11998        for(srbIdx=0; srbIdx<srbSet->list.count; srbIdx++)
11999        {
12000           if(srbSet->list.array[srbIdx]!=NULLP)
12001           {
12002              free(srbSet->list.array[srbIdx]);
12003           }
12004        }
12005        free(srbSet->list.array);
12006     }
12007 }
12008
12009 /*******************************************************************
12010 *
12011 * @brief free the memory allocated by decoder
12012 *
12013 * @details
12014 *
12015 *    Function : freeAperDecodeULTnlInfo
12016 *
12017 *    Functionality: added free part for the memory allocated by aper_decoder
12018 *
12019 * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
12020 * @return void
12021 *
12022 * ****************************************************************/
12023
12024
12025 void freeAperDecodeULTnlInfo(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
12026 {
12027    uint8_t ulIdx=0;
12028    if(ulInfo->list.array != NULLP)
12029    {
12030       for(ulIdx=0; ulIdx<ulInfo->list.count; ulIdx++)
12031       {
12032          if(ulIdx==0&&ulInfo->list.array[ulIdx]!=NULLP)
12033          {
12034             if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel!=NULLP)
12035             {
12036                if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12037                      transportLayerAddress.buf != NULLP)
12038                {
12039                   if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf\
12040                         !=NULLP)
12041                   {
12042                      free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf);
12043                   }
12044                   free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12045                         transportLayerAddress.buf);
12046                }
12047                free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel);
12048             }
12049          }
12050          if(ulInfo->list.array[ulIdx]!=NULLP)
12051          {
12052             free(ulInfo->list.array[ulIdx]);
12053          }
12054       }
12055       free(ulInfo->list.array);
12056    }
12057 }
12058 /*******************************************************************
12059 *
12060 * @brief free the memory allocated by decoder
12061 *
12062 * @details
12063 *
12064 *    Function : freeAperDecodeDRBSetup  
12065 *
12066 *    Functionality: free DRBSetup which is allocated by decoder
12067 *
12068 * @params[in]  DRBs_ToBeSetup_List_t *drbSet
12069 * @return void
12070 *
12071 * ****************************************************************/
12072
12073 void freeAperDecodeDRBSetup(DRBs_ToBeSetup_List_t *drbSet)
12074 {
12075    DRBs_ToBeSetup_Item_t *drbSetItem = NULLP;
12076    uint8_t  flowIdx =0;
12077    uint8_t  drbIdx =0;
12078
12079    if(drbSet->list.array != NULLP)
12080    {
12081       for(drbIdx=0; drbIdx<drbSet->list.count; drbIdx++)
12082       {
12083          if(drbIdx==0&&drbSet->list.array[drbIdx] != NULLP)
12084          {
12085             drbSetItem =&drbSet->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12086             if(drbSetItem->qoSInformation.choice.choice_extension != NULLP)
12087             {
12088                if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12089                      qoS_Characteristics.choice.non_Dynamic_5QI !=NULLP)
12090                {
12091                   if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12092                         qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12093                   {
12094                      if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12095                            qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12096                      {
12097
12098                         if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf!=NULLP)
12099                         {
12100
12101                            if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD!=NULLP)
12102                            {
12103
12104                               if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD->\
12105                                     buf!=NULLP)
12106                               {
12107
12108                                  if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.\
12109                                        flows_Mapped_To_DRB_List.list.array != NULLP)
12110                                  {
12111
12112                                     for(flowIdx=0;flowIdx<drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12113                                           DRB_Information.flows_Mapped_To_DRB_List.list.count; flowIdx++)
12114                                     {
12115
12116                                        if(flowIdx==0&&drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12117                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12118                                        {
12119                                           if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12120                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12121                                                 qoSFlowLevelQoSParameters.\
12122                                                 qoS_Characteristics.choice.non_Dynamic_5QI!=NULLP)
12123                                           {
12124                                              if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12125                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12126                                                    qoSFlowLevelQoSParameters.\
12127                                                    qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12128                                              {
12129
12130                                                 if(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!=NULLP)
12134                                                 {
12135
12136
12137                                                    free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12138                                                          DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12139                                                          qoSFlowLevelQoSParameters.\
12140                                                          qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12141                                                 }
12142
12143                                                 free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12144                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12145                                                       qoSFlowLevelQoSParameters.\
12146                                                       qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12147                                              }
12148
12149                                              free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12150
12151                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12152                                                    qoSFlowLevelQoSParameters.\
12153                                                    qoS_Characteristics.choice.non_Dynamic_5QI);
12154                                           }
12155                                        }
12156                                        if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12157                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12158                                        {
12159
12160                                           free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12161                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]);
12162                                        }
12163                                     }
12164
12165                                     free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12166                                           DRB_Information.flows_Mapped_To_DRB_List.list.array);
12167                                  }
12168
12169                                  free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12170                                        DRB_Information.sNSSAI.sD->buf);
12171                               }
12172
12173                               free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD);
12174                            }
12175
12176                            free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf);
12177
12178                         }
12179
12180                         free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12181
12182                               qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12183                      }
12184
12185                      free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12186                            qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12187                   }
12188
12189                   free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12190                         qoS_Characteristics.choice.non_Dynamic_5QI);
12191                }
12192                free(drbSetItem->qoSInformation.choice.choice_extension);
12193             }
12194             freeAperDecodeULTnlInfo(&drbSetItem->uLUPTNLInformation_ToBeSetup_List);
12195             if(drbSetItem->uLConfiguration)
12196             {
12197                free(drbSetItem->uLConfiguration);
12198             }
12199          }
12200          if(drbSet->list.array[drbIdx]!=NULLP)
12201          {
12202             free(drbSet->list.array[drbIdx]);
12203          }
12204       }
12205       free(drbSet->list.array);
12206    }
12207 }
12208
12209
12210 /*******************************************************************
12211  *
12212  * @brief builds Mac Cell Cfg
12213  *
12214  * @details
12215  *
12216  *    Function : procUeReCfgCellInfo
12217  *
12218  *    Functionality: builds Mac Cell Cfg
12219  *
12220  * @params[in] MacUeCfg *macUeCfgToSend = Used to Store the information which
12221  *                       needs to send in other layer, as well as this can be
12222  *                       the variable which stores the information in DuCb.
12223  *             MacUeCfg *storedMacUeCfg = Null in case of sending the
12224  *                       information to other layer else it will have copyOfmacUeCfg  
12225  *                       which we have stored in F1UeContextSetupDb
12226  *             void *cellInfo = CellGroupConfigRrc_t information which is send
12227  *                        by CU, which we have stored in F1UeContextSetupDb 
12228  *
12229  * @return void 
12230  *
12231  * ****************************************************************/
12232 uint8_t procUeReCfgCellInfo(MacUeCfg *macUeCfgToSend, MacUeCfg *storedMacUeCfg, void *cellInfo)
12233 {
12234    uint8_t ret = ROK;
12235    CellGroupConfigRrc_t *cellGrp = NULLP;
12236
12237    if(cellInfo)
12238    {
12239       cellGrp = (CellGroupConfigRrc_t *)cellInfo;
12240       ret = extractUeReCfgCellInfo(cellGrp, macUeCfgToSend, storedMacUeCfg);
12241       if(ret == RFAILED)
12242          DU_LOG("\nERROR  -->  F1AP : Failed at procUeReCfgCellInfo()");
12243    }
12244    if(ret == RFAILED)
12245    {
12246       freeUeReCfgCellGrpInfo(macUeCfgToSend);
12247    }
12248    return ret;
12249 }
12250
12251 /*******************************************************************
12252  *
12253  * @brief Filling modulation info in mac ue cfg
12254  *
12255  * @details
12256  *
12257  *    Function : duFillModulationDetails
12258  *
12259  *    Functionality: Filling modulation info in mac ue cfg
12260  *
12261  * @params[in] MAC UE Config to be updated
12262  *             Current UE configuration
12263  *             UE NR capability from CU
12264  * @return ROK     - success
12265  *         RFAILED - failure
12266  *
12267  * ****************************************************************/
12268 void duFillModulationDetails(MacUeCfg *ueCfg, MacUeCfg *oldUeCfg, void *ueCap)
12269 {
12270    UE_NR_Capability_t *ueNrCap=NULLP;
12271
12272    if(!ueCap && oldUeCfg)
12273    {
12274       memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));     
12275       memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12276    }
12277    else
12278    {
12279       ueNrCap = (UE_NR_Capability_t *)ueCap;
12280
12281       /* Filling DL modulation info */
12282       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsDownlinkPerCC && \
12283          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0] && \
12284          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL)
12285       {
12286          switch(*(ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL))
12287          {
12288             case ModulationOrder_qpsk:
12289                {
12290                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
12291                   break;
12292                }
12293             case ModulationOrder_qam16:
12294                {
12295                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM16;
12296                   break;
12297                }
12298             case ModulationOrder_qam64:
12299                {
12300                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM64;
12301                   ueCfg->dlModInfo.mcsIndex = PDSCH_MCS_INDEX;
12302                   ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64;
12303                   break;
12304                }
12305             case ModulationOrder_qam256:
12306                {
12307                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM256;
12308                   break;
12309                }
12310             default:
12311                {
12312                   DU_LOG("\nERROR  -->  DU APP: Incorrect downlink modulation order received. Reatining old modulation configuration");
12313                   if(oldUeCfg)
12314                      memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
12315                   break;
12316                }
12317          }
12318       }
12319       else
12320       {
12321          if(oldUeCfg)
12322             memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
12323       }
12324
12325       /* Filling UL modulation info */
12326       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsUplinkPerCC && \
12327          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0] && \
12328          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL)
12329       {
12330          switch(*(ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL))
12331          {
12332             case ModulationOrder_qpsk:
12333                {
12334                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
12335                   break;
12336                }
12337             case ModulationOrder_qam16:
12338                {
12339                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM16;
12340                   ueCfg->ulModInfo.mcsIndex = PUSCH_MCS_INDEX;
12341                   ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64;
12342                   break;
12343                }
12344             case ModulationOrder_qam64:
12345                {
12346                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM64;
12347                   break;
12348                }
12349             case ModulationOrder_qam256:
12350                {
12351                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM256;
12352                   break;
12353                }
12354             default:
12355                {
12356                   DU_LOG("\nERROR  -->  DU APP: Incorrect uplink modulation order received. Reatining old modulation configuration");
12357                   if(oldUeCfg)
12358                      memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12359                   break;
12360                }
12361          }
12362       }
12363       else
12364       {
12365          if(oldUeCfg)
12366             memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12367       }
12368    }
12369 }
12370
12371 /*******************************************************************
12372  *
12373  * @brief Function to extract info from CU to DU RRC container extension
12374  *
12375  * @details
12376  *
12377  *    Function : extractCuToDuRrcInfoExt
12378  *
12379  *    Functionality: Function to extract info from CU to DU RRC container
12380  *    extension
12381  *
12382  * @params[in] ProtocolExtensionContainer_4624P16_t pointer
12383  *
12384  * @return ROK
12385  *         RFAILED
12386  *
12387  * ****************************************************************/
12388 uint8_t extractCuToDuRrcInfoExt(ProtocolExtensionContainer_4624P16_t *protocolIeExtn, DuUeCfg *ueCfgDb)
12389 {
12390    uint8_t ieIdx =0;
12391    uint16_t recvBufLen =0;
12392    CellGroupConfigRrc_t *cellGrpCfg = NULLP;
12393    CUtoDURRCInformation_ExtIEs_t *extIeInfo = NULLP;
12394    asn_dec_rval_t rval; /* Decoder return value */
12395    memset(&rval, 0, sizeof(asn_dec_rval_t));
12396
12397    if(protocolIeExtn)
12398    {
12399       for(ieIdx = 0; ieIdx < protocolIeExtn->list.count; ieIdx++)
12400       {
12401          extIeInfo = ((CUtoDURRCInformation_ExtIEs_t *)(protocolIeExtn->list.array[ieIdx]));
12402          switch(extIeInfo->id)
12403          {
12404             case ProtocolIE_ID_id_CellGroupConfig:
12405                {
12406                   /* decoding the CellGroup Buf received */
12407                   recvBufLen = extIeInfo->extensionValue.choice.CellGroupConfig.size;
12408                   DU_ALLOC(cellGrpCfg, sizeof(CellGroupConfigRrc_t));
12409                   if(cellGrpCfg)
12410                   {
12411                      memset(cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
12412                      rval = aper_decode(0, &asn_DEF_CellGroupConfigRrc, (void **)&cellGrpCfg,
12413                            extIeInfo->extensionValue.choice.CellGroupConfig.buf, recvBufLen, 0, 0);
12414                      if(rval.code == RC_FAIL || rval.code == RC_WMORE)
12415                      {
12416                         DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
12417                         return RFAILED;
12418                      }
12419                      xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, cellGrpCfg);
12420
12421                      if(extractRlcCfgToAddMod(cellGrpCfg->rlc_BearerToAddModList, ueCfgDb))
12422                         return NULLP;
12423                      ueCfgDb->cellGrpCfg = cellGrpCfg;
12424                   }
12425                   break;
12426                }
12427
12428             case ProtocolIE_ID_id_HandoverPreparationInformation:
12429                {
12430                   DU_LOG("\nINFO -->  F1AP : Received HANDOVER PREPARATION INFO in UE CONTEXT SETUP REQUEST");
12431                   break;
12432                }
12433
12434             default:
12435                DU_LOG("\nERROR  -->  F1AP : Invalid IE received CUtoDURRCInformation: %ld at decodeCellGrpCfg()", extIeInfo->id);
12436                break;
12437          }
12438       }
12439    }
12440    return ROK;
12441 }
12442
12443 /*******************************************************************
12444  *
12445  * @brief Fills Srb List received by CU
12446  *
12447  * @details
12448  *
12449  *    Function : procSrbListToSetup
12450  *
12451  *    Functionality: Fills Srb List received  by CU
12452  *
12453  * @params[in] SRBs_ToBeSetup_Item_t *cuSrbItem
12454  *             LcCfg pointer
12455  *             RlcBearerCfg pointer
12456  * @return void
12457  *
12458  * ****************************************************************/
12459 uint8_t procSrbListToSetup(SRBs_ToBeSetup_Item_t * srbItem, LcCfg *macLcToAdd, RlcBearerCfg *rlcLcToAdd)
12460 {
12461
12462    /* Filling RLC INFO */
12463    procRlcLcCfg(srbItem->sRBID, srbItem->sRBID, RB_TYPE_SRB, RLC_AM, CONFIG_ADD, NULL, rlcLcToAdd, NULL);
12464
12465    /* Filling MAC INFO */
12466    if(procMacLcCfg(srbItem->sRBID, RB_TYPE_SRB, CONFIG_ADD, NULL,NULL, NULL, NULL, macLcToAdd, NULL)  != ROK)
12467    { 
12468       DU_LOG("\nERROR  -->  F1AP : Failed at MAC LC Cfg in procSrbListToSetup()");
12469       return RFAILED;
12470    }
12471
12472    return ROK;
12473 }
12474
12475
12476
12477 /*******************************************************************
12478  *
12479  * @brief extract Srb List received by CU
12480  *
12481  * @details
12482  *
12483  *    Function : extractSrbListToSetup
12484  *
12485  *    Functionality: extract Srb List received by CU
12486  *                   for both MAC and RLC
12487  *
12488  * @params[in] SRBs_ToBeSetup_Item_t pointer
12489  *             DuUeCfg pointer
12490  * @return ROK/RFAIED
12491  *
12492  * ****************************************************************/
12493
12494 uint8_t extractSrbListToSetup(SRBs_ToBeSetup_List_t *srbCfg, DuUeCfg *ueCfgDb)
12495 {
12496    uint8_t ret = ROK, srbIdx = 0, rlcLcIdx = 0;
12497    SRBs_ToBeSetup_Item_t *srbItem = NULLP;
12498    LcCfg *macLcCtxt = NULLP;
12499    RlcBearerCfg *rlcLcCtxt = NULLP;
12500
12501    if(srbCfg)
12502    {
12503       for(srbIdx = 0; srbIdx < srbCfg->list.count; srbIdx++)
12504       {
12505          macLcCtxt = NULL;
12506          rlcLcCtxt = NULL;
12507
12508          srbItem = &srbCfg->list.array[srbIdx]->value.choice.SRBs_ToBeSetup_Item;
12509          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
12510          { 
12511             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in MAC");
12512             ret = RFAILED;
12513             break;
12514          }
12515          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
12516          {
12517             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in RLC");
12518             ret = RFAILED;
12519             break;
12520          }
12521
12522          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numMacLcs; rlcLcIdx++)
12523          {
12524             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rbId == srbItem->sRBID && ueCfgDb->rlcLcCfg[rlcLcIdx].rbType == RB_TYPE_SRB)
12525             {
12526                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
12527                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
12528                break;
12529             }
12530          }
12531          if(!macLcCtxt)
12532          {
12533             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(LcCfg));
12534             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
12535             ueCfgDb->numMacLcs++;
12536          }
12537          if(!rlcLcCtxt)
12538          {
12539             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
12540             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
12541             ueCfgDb->numRlcLcs++;
12542          }
12543
12544          ret = procSrbListToSetup(srbItem, macLcCtxt, rlcLcCtxt);
12545
12546          DU_LOG("\nDEBUG --> DUAPP: extractSrbListToSetup: SRBID: %ld [RLC,MAC,NumDrb]:[%x,%x,%x]",\
12547                srbItem->sRBID, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
12548          if(ret == RFAILED)
12549          {
12550             DU_LOG("\nERROR  -->  F1AP:  Failed at extractSrbListToSetup()");
12551             break;
12552          }
12553       }
12554    }
12555    else
12556       ret = RFAILED;
12557
12558    return ret;
12559 }
12560
12561 /*******************************************************************
12562  *
12563  * @brief Fills Drb List received by CU
12564  *
12565  * @details
12566  *
12567  *    Function : procDrbListToSetupMod
12568  *
12569  *    Functionality: Fills Drb List received by CU
12570  *                   for both MAC and RLC
12571  *
12572  * @params[in] DRBs_ToBeSetup_Item_t , DRBs_ToBeSetupMod_Item_t,
12573  *             DRBs_ToBeModified_Item_t , lcId, LcCfg pointer,
12574  *             RlcBearerCfg , UpTnlCfg, RlcUeCfg
12575  * @return void
12576  *
12577  * ****************************************************************/
12578
12579 uint8_t procDrbListToSetupMod(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbItem,\
12580 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LcCfg *macLcToAdd, RlcBearerCfg *rlcLcToAdd, UpTnlCfg *upTnlInfo, RlcUeCfg *storedRlcUeCfg)
12581 {
12582    uint8_t cfgIdx = 0;
12583    RlcMode rlcModeInfo;
12584
12585    if(drbItem != NULLP)
12586    {
12587       /* Filling RLC INFO */
12588       procRlcLcCfg(drbItem->dRBID, lcId, RB_TYPE_DRB, drbItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, &drbItem->\
12589       qoSInformation);
12590
12591       /* Filling MAC INFO */
12592       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, drbItem, NULL, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
12593       { 
12594          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
12595          return RFAILED;
12596       }
12597    }
12598    else if(drbSetupModItem != NULLP)
12599    {
12600       procRlcLcCfg(drbSetupModItem->dRBID, lcId, RB_TYPE_DRB, drbSetupModItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, 
12601       &drbSetupModItem->qoSInformation);
12602
12603       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, NULL, drbSetupModItem, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
12604       {
12605          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
12606          return RFAILED;
12607       }
12608    }
12609    else if(drbModItem != NULLP)
12610    {
12611       /* Drb to Mod IEs doesnot have rlcMode to be modified
12612        * in ASN. Hence no change in RLC configurations */
12613       if(storedRlcUeCfg != NULLP)
12614       {
12615          for(cfgIdx = 0; cfgIdx < storedRlcUeCfg->numLcs; cfgIdx++)
12616          {
12617             if(storedRlcUeCfg->rlcLcCfg[cfgIdx].lcId == lcId)
12618             {
12619                rlcModeInfo = storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcMode;
12620                break;
12621             }
12622          }
12623       }
12624
12625       procRlcLcCfg(drbModItem->dRBID, lcId, RB_TYPE_DRB, rlcModeInfo, CONFIG_MOD, NULL, rlcLcToAdd, drbModItem->qoSInformation);
12626       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_MOD, NULL, NULL, drbModItem, NULL, macLcToAdd, upTnlInfo) != ROK)
12627       {
12628          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
12629          return RFAILED;
12630       }
12631    }
12632    return ROK;
12633 }
12634
12635 /*******************************************************************
12636  *
12637  * @brief extract Drb List received by CU
12638  *
12639  * @details
12640  *
12641  *    Function : extractDrbListToSetupMod
12642  *
12643  *    Functionality: extract Drb List received by CU
12644  *                   for both MAC and RLC
12645  *
12646  * @params[in] DRBs_ToBeSetup_Item_t pointer
12647  *             DuUeCfg pointer
12648  * @return ROK/RFAIED
12649  *
12650  * ****************************************************************/
12651
12652 uint8_t extractDrbListToSetupMod(DRBs_ToBeSetup_List_t *drbCfg, DRBs_ToBeSetupMod_List_t *drbSetupModCfg,\
12653  DRBs_ToBeModified_List_t *drbModCfg, uint8_t drbCount, DuUeCfg *ueCfgDb, uint32_t *drbBitMap, RlcUeCfg *rlcUeCfg)
12654 {
12655    uint8_t ret = ROK;
12656    uint8_t drbIdx = 0, rlcLcIdx = 0;
12657    uint8_t drbId = 0, lcId = 0;
12658    DRBs_ToBeSetup_Item_t *drbItem = NULLP;
12659    DRBs_ToBeSetupMod_ItemIEs_t *drbSetupModItem = NULLP;
12660    DRBs_ToBeModified_ItemIEs_t *drbModItem = NULLP;
12661    LcCfg *macLcCtxt = NULLP;
12662    RlcBearerCfg *rlcLcCtxt = NULLP;
12663
12664    ret = ROK;
12665    if(drbCount > 0)
12666    {
12667       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
12668       {
12669          macLcCtxt = NULL;
12670          rlcLcCtxt = NULL;
12671
12672          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
12673          { 
12674             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in MAC at extractDrbListToSetupMod()");
12675             ret = RFAILED;
12676             break;
12677          }
12678          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
12679          {
12680             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in RLC at extractDrbListToSetupMod()");
12681             ret = RFAILED;
12682             break;
12683          }
12684
12685          if(drbModCfg != NULLP)
12686          {
12687             drbModItem = (DRBs_ToBeModified_ItemIEs_t *) drbModCfg->list.array[drbIdx];
12688             drbId = drbModItem->value.choice.DRBs_ToBeModified_Item.dRBID;
12689          }
12690          else if(drbCfg != NULLP)
12691             drbId = drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item.dRBID;
12692          else if(drbSetupModCfg != NULL)
12693          {
12694             drbSetupModItem = (DRBs_ToBeSetupMod_ItemIEs_t *) drbSetupModCfg->list.array[drbIdx];
12695             drbId = drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item.dRBID;
12696          }
12697
12698          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
12699          {
12700             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rbId == drbId && ueCfgDb->rlcLcCfg[rlcLcIdx].rbType == RB_TYPE_DRB)
12701             {
12702                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
12703                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
12704                break;
12705             }
12706          }
12707          if(!macLcCtxt)
12708          {
12709             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(LcCfg));
12710             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
12711             ueCfgDb->numMacLcs++;
12712          }
12713          if(!rlcLcCtxt)
12714          {
12715             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
12716             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
12717             ueCfgDb->numRlcLcs++;
12718          }
12719
12720          if(drbModCfg != NULLP)
12721          {
12722             lcId = fetchLcId(drbId);
12723             if(lcId < MIN_DRB_LCID)
12724             {
12725                DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToSetupMod() for Modified List", lcId);
12726                break;
12727             } 
12728             ret = procDrbListToSetupMod(lcId, NULL, NULL, &(drbModItem->value.choice.DRBs_ToBeModified_Item),\
12729             macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
12730             if(ret == RFAILED)
12731             {
12732                DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for Modified List");
12733                break;
12734             }
12735          }
12736          else
12737          {
12738             lcId = getDrbLcId(drbBitMap);
12739             if(lcId == RFAILED)
12740             {
12741                DU_LOG("\nERROR  -->  F1AP :  InCorrect LCID extractDrbListToSetupMod()");
12742                ret = RFAILED;
12743                break;
12744             }
12745             if(drbCfg != NULL)
12746             {
12747                drbItem = &drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12748                ret = procDrbListToSetupMod(lcId, drbItem, NULL, NULL, macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
12749                if(ret == RFAILED)
12750                {
12751                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetup List");
12752                   break;
12753                }
12754             }
12755             else if(drbSetupModCfg != NULL)
12756             {
12757                ret = procDrbListToSetupMod(lcId, NULL, &(drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item), NULL,\
12758                      macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
12759                if(ret == RFAILED)
12760                {
12761                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetupMod List");
12762                   break;
12763                }
12764                ueCfgDb->numDrbSetupMod++;
12765             }
12766          }
12767          ueCfgDb->numDrb++;
12768  
12769          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToSetupMod:lcId:%x ,BitMap:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
12770                             lcId,*drbBitMap, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
12771          if(ret == RFAILED)
12772          {
12773             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod()");
12774             break;
12775          }
12776       }
12777    }
12778    else
12779       ret = RFAILED;
12780
12781    return ret;
12782 }
12783
12784 /*******************************************************************
12785  *
12786  * @brief Function to extract Dl RRC Msg received from CU
12787  *
12788  * @details
12789  *
12790  *    Function : extractDlRrcMsg
12791  *
12792  *    Functionality: Function to extract Dl RRC Msg received from CU
12793  *
12794  * @params[in] F1AP message
12795  * @return ROK     - success
12796  *         RFAILED - failure
12797  *
12798  * ****************************************************************/
12799
12800 uint8_t extractDlRrcMsg(uint32_t gnbDuUeF1apId, uint32_t gnbCuUeF1apId, \
12801    F1DlRrcMsg *dlRrcMsg, RRCContainer_t *rrcContainer)
12802 {
12803    uint8_t ret = ROK;
12804    dlRrcMsg->rrcMsgSize = rrcContainer->size;
12805    if(dlRrcMsg->rrcMsgSize > 0)
12806    {
12807       DU_ALLOC_SHRABL_BUF(dlRrcMsg->rrcMsgPdu, dlRrcMsg->rrcMsgSize);
12808       if(!dlRrcMsg->rrcMsgPdu)
12809       {
12810          DU_LOG("\nERROR  --> DU APP : Memory allocation failed for RRC Msg in extractDlRrcMsg()");
12811          ret = RFAILED;
12812       }
12813       else
12814       {
12815          dlRrcMsg->gnbDuUeF1apId = gnbDuUeF1apId;
12816          dlRrcMsg->gnbCuUeF1apId = gnbCuUeF1apId;
12817          dlRrcMsg->srbId = SRB1_LCID;
12818          memcpy(dlRrcMsg->rrcMsgPdu, rrcContainer->buf, dlRrcMsg->rrcMsgSize);
12819       }
12820    }
12821    return ret;
12822 }
12823
12824 /*******************************************************************
12825  *
12826  * @brief Extract UE capability info 
12827  *
12828  * @details
12829  *
12830  *    Function : extractUeCapability
12831  *
12832  *    Functionality: Extract UE capability info and stores in ue Cb
12833  *
12834  * @params[in] Octet string of UE capability RAT container list
12835  * @return ROK     - success
12836  *         RFAILED - failure
12837  *
12838  * ****************************************************************/
12839 UE_NR_Capability_t *extractUeCapability(UE_CapabilityRAT_ContainerList_t *ueCapablityListBuf, DuUeCb *ueCb)
12840 {
12841    uint8_t  idx;
12842    uint16_t recvBufLen;
12843    asn_dec_rval_t rval;
12844    UE_NR_Capability_t  *ueNrCap = NULLP;
12845    UE_CapabilityRAT_ContainerListRRC_t  *ueCapRatContList = NULLP;
12846
12847    /* Decoding UE Capability RAT Container List */
12848    recvBufLen = ueCapablityListBuf->size;
12849    DU_ALLOC(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
12850    if(!ueCapRatContList)
12851    {
12852       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
12853       return NULLP;
12854    }
12855    memset(ueCapRatContList, 0, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
12856    memset(&rval, 0, sizeof(asn_dec_rval_t));
12857    rval = aper_decode(0, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, (void **)&ueCapRatContList,
12858           ueCapablityListBuf->buf, recvBufLen, 0, 0);
12859    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
12860    {
12861       DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
12862       return NULLP;
12863    }
12864    xer_fprint(stdout, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, ueCapRatContList);
12865
12866    /* Free encoded buffer after decoding */
12867
12868    for(idx = 0; idx < ueCapRatContList->list.count; idx++)
12869    {
12870       if(ueCapRatContList->list.array[idx]->rat_Type == RAT_Type_nr)
12871       {
12872          /* Decoding UE NR Capability */
12873           recvBufLen = ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.size;
12874           DU_ALLOC(ueNrCap, sizeof(UE_NR_Capability_t));
12875           if(!ueNrCap)
12876           {
12877              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
12878              DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
12879              return NULLP;
12880           } 
12881           memset(ueNrCap, 0, sizeof(UE_NR_Capability_t));
12882           memset(&rval, 0, sizeof(asn_dec_rval_t));
12883           rval = aper_decode(0, &asn_DEF_UE_NR_Capability, (void **)&ueNrCap,
12884                  ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf, recvBufLen, 0, 0);
12885           if(rval.code == RC_FAIL || rval.code == RC_WMORE)
12886           {
12887              DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
12888              return NULLP;
12889           }
12890           xer_fprint(stdout, &asn_DEF_UE_NR_Capability, ueNrCap);
12891           
12892           /* Free encoded buffer after decoding */
12893           free(ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf);
12894       }
12895       free(ueCapRatContList->list.array[idx]);
12896    }
12897
12898    /* Free Memory*/
12899    free(ueCapRatContList->list.array);
12900    DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
12901    return ueNrCap;
12902 }
12903  
12904 /*******************************************************************
12905 *
12906 * @brief free UE context setup request from CU
12907 *
12908 * @details
12909 *
12910 *    Function : freeAperDecodeF1UeContextSetupReq
12911 *
12912 *    Functionality: freeing part for the memory allocated by aper_decoder
12913 *
12914 * @params[in] F1AP message
12915 * @return ROK     - success
12916 *         RFAILED - failure
12917 *
12918 * ****************************************************************/
12919 void freeAperDecodeF1UeContextSetupReq(UEContextSetupRequest_t   *ueSetReq)
12920 {
12921    uint8_t ieIdx = 0;
12922
12923    if(ueSetReq->protocolIEs.list.array != NULLP)
12924    {
12925       for(ieIdx = 0; ieIdx < ueSetReq->protocolIEs.list.count; ieIdx++)
12926       {
12927          if(ueSetReq->protocolIEs.list.array[ieIdx])
12928          {
12929             switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
12930             {
12931                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
12932                   break;
12933                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
12934                   break;
12935                case ProtocolIE_ID_id_SpCell_ID:
12936                   freeAperDecodeNrcgi(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
12937                   break;
12938                case ProtocolIE_ID_id_ServCellIndex:
12939                   break;
12940                case ProtocolIE_ID_id_SpCellULConfigured:
12941                   break;
12942                case ProtocolIE_ID_id_CUtoDURRCInformation:
12943
12944                   freeAperDecodeCuToDuInfo(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation);
12945                   break;
12946                case ProtocolIE_ID_id_SCell_ToBeSetup_List:
12947
12948                   freeAperDecodeSplCellList(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SCell_ToBeSetup_List);
12949                   break;
12950                case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
12951
12952                   freeAperDecodeSRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List);
12953                   break;
12954                case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
12955
12956                   freeAperDecodeDRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List);
12957                   break;
12958                case ProtocolIE_ID_id_RRCContainer:
12959                   {
12960
12961                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf != NULLP)
12962                      {
12963
12964                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
12965                      }
12966                      break;
12967                   }
12968                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
12969                   break;
12970                case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
12971                   {
12972                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf)
12973                      {
12974                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf);
12975                      }
12976                      break;
12977                   }
12978                default:
12979                   DU_LOG("\nERROR  -->  F1AP: Invalid event type %ld " ,ueSetReq->protocolIEs.list.array[ieIdx]->id);
12980             } 
12981             free(ueSetReq->protocolIEs.list.array[ieIdx]);
12982          }
12983       }
12984       free(ueSetReq->protocolIEs.list.array);
12985    }
12986 }
12987 /*******************************************************************
12988  *
12989  * @brief Process UE context setup request from CU
12990  *
12991  * @details
12992  *
12993  *    Function : procF1UeContextSetupReq
12994  *
12995  *    Functionality: Process UE context setup request from CU
12996  *
12997  * @params[in] F1AP message
12998  * @return ROK     - success
12999  *         RFAILED - failure
13000  *
13001  * ****************************************************************/
13002 uint8_t procF1UeContextSetupReq(F1AP_PDU_t *f1apMsg)
13003 {
13004    int8_t ueIdx = -1;
13005    uint8_t  ret=0, ieIdx=0, ieExtIdx = 0, servCellIdx = 0;
13006    bool ueCbFound = false, hoInProgress = false;
13007    uint16_t cellIdx=0;
13008    uint64_t nrCellId = 0;
13009    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0, bitRateSize=0;
13010    DuUeCb   *duUeCb = NULL;
13011    UEContextSetupRequest_t   *ueSetReq = NULL;
13012    DRBs_ToBeSetup_List_t *drbCfg = NULL;
13013    CUtoDURRCInformation_t *rrcInfo = NULL;
13014
13015    ret = ROK;
13016
13017    ueSetReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextSetupRequest;
13018    for(ieIdx=0; (ieIdx < ueSetReq->protocolIEs.list.count && ret == ROK); ieIdx++)
13019    {
13020       switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13021       {
13022          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13023             {
13024                gnbCuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
13025                break;
13026             }
13027
13028          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13029             {
13030                gnbDuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
13031                break;
13032             }
13033
13034          case ProtocolIE_ID_id_SpCell_ID:
13035             {
13036                bitStringToInt(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity, &nrCellId);
13037
13038                GET_CELL_IDX(nrCellId, cellIdx);
13039                if(!duCb.actvCellLst[cellIdx])
13040                {
13041                   DU_LOG("\nERROR  -->  F1AP : Cell Id [%d] not found", nrCellId);
13042                   ret = RFAILED;
13043                }
13044                break;
13045             }
13046
13047          case ProtocolIE_ID_id_ServCellIndex:
13048             {
13049                servCellIdx = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.ServCellIndex;
13050                break;
13051             }
13052
13053          case ProtocolIE_ID_id_SpCellULConfigured:
13054             {
13055                /* Indicates whether the gNB-CU requests the gNB-DU to configure the uplink as no UL, 
13056                   UL, SUL or UL+SUL for the indicated cell for the UE */
13057                break;
13058             }
13059
13060          case ProtocolIE_ID_id_CUtoDURRCInformation:
13061             {
13062                rrcInfo = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation;
13063
13064                /* Search if UE context is present */
13065                for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
13066                {
13067                   if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId)
13068                   {
13069                      ueCbFound = true;
13070                      duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13071                      break;
13072                   }
13073                }
13074
13075                /* Check if UE Handover scenario */
13076                if(rrcInfo->iE_Extensions)
13077                {
13078                   for(ieExtIdx = 0; ieExtIdx < rrcInfo->iE_Extensions->list.count; ieExtIdx++)
13079                   {
13080                      if(rrcInfo->iE_Extensions->list.array[ieExtIdx]->id == ProtocolIE_ID_id_HandoverPreparationInformation)
13081                      {
13082                         hoInProgress = true;
13083                         break;
13084                      }
13085                   }
13086                }
13087                
13088                /* If UE context is not present, but UE is in handover */
13089                if(!ueCbFound && hoInProgress)
13090                {
13091                   ueIdx = getFreeBitFromUeBitMap(nrCellId);
13092                   if(ueIdx != -1)
13093                      gnbDuUeF1apId = ueIdx +1;
13094                   else
13095                   {
13096                      DU_LOG("\nERROR  -->  F1AP : No free UE IDX found in UE bit map of cell Id [%d]", nrCellId);
13097                      ret = RFAILED;
13098                      break;
13099                   }
13100                   duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13101                   duUeCb->f1UeDb = NULL;
13102                   duUeCb->gnbCuUeF1apId = gnbCuUeF1apId;
13103                   duUeCb->gnbDuUeF1apId = gnbDuUeF1apId;
13104                   GET_CRNTI(duUeCb->crnti, duUeCb->gnbDuUeF1apId);
13105                   duUeCb->ueState = UE_HANDIN_IN_PROGRESS;
13106                }
13107
13108                if(duUeCb)
13109                {
13110                   DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
13111                   if(duUeCb->f1UeDb)
13112                   {
13113                      memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
13114                      duUeCb->f1UeDb->actionType = UE_CTXT_SETUP;
13115                      duUeCb->f1UeDb->cellIdx = cellIdx;
13116                   }
13117                   else
13118                   {
13119                      DU_LOG("\nERROR  -->  F1AP: Memory Alloc Failed at procF1UeContextSetupReq()");
13120                      ret = RFAILED;
13121                      break;
13122                   }
13123                }
13124                else
13125                {
13126                   DU_LOG("\nERROR  -->  F1AP: DuUeCb is not found at procF1UeContextSetupReq()");
13127                   ret = RFAILED;
13128                   break;
13129                }
13130                  
13131                /* Extract UE capability info */
13132                if(rrcInfo->uE_CapabilityRAT_ContainerList)
13133                {
13134                   duUeCb->f1UeDb->duUeCfg.ueNrCapability = extractUeCapability(rrcInfo->uE_CapabilityRAT_ContainerList, duUeCb);
13135                }
13136
13137                /* Extract IE extension */
13138                if(rrcInfo->iE_Extensions)
13139                {
13140                   if(extractCuToDuRrcInfoExt(rrcInfo->iE_Extensions, &duUeCb->f1UeDb->duUeCfg) != ROK)
13141                   {
13142                      DU_LOG("\nERROR  -->  F1AP: Failed to extract CU to DU RRC information extension IE");
13143                      //TODO: Update the failure cause in ue context Setup Response
13144                      ret = RFAILED;
13145                   }
13146                }
13147                break;
13148             } 
13149
13150          case ProtocolIE_ID_id_SCell_ToBeSetup_List:
13151             {
13152                DU_LOG("\nINFO   -->  DU_APP: Received SCell_ToBeSetup_List but  Not processing the list");
13153                break;
13154             }
13155
13156          case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
13157             {
13158                if(extractSrbListToSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List,\
13159                         &duUeCb->f1UeDb->duUeCfg))
13160                {
13161                   DU_LOG("\nERROR  -->  DU APP : Failed at extractSrbListToSetup()");
13162                   //TODO: Update the failure cause in ue context Setup Response
13163                   ret = RFAILED;
13164                }
13165                break;
13166             }
13167
13168          case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
13169             {
13170                drbCfg = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List;
13171
13172                if(extractDrbListToSetupMod(drbCfg, NULL, NULL, drbCfg->list.count, &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULLP))
13173                {
13174                   DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod()");
13175                   //TODO: Update the failure cause in ue context Setup Response
13176                   ret = RFAILED;
13177                }
13178                break;
13179             }
13180
13181          case ProtocolIE_ID_id_RRCContainer:
13182             {
13183                /* Filling Dl RRC Msg Info */
13184                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
13185                if(!duUeCb->f1UeDb->dlRrcMsg)
13186                {
13187                   DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for DL RRC Msg in procUeCtxtSetupReq()");
13188                   ret = RFAILED;
13189                }
13190                else
13191                {
13192                   duUeCb->f1UeDb->dlRrcMsgPres = true;
13193                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
13194                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
13195                         &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer);
13196                }          
13197                break;
13198             }
13199
13200          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13201             {
13202                if(duUeCb->f1UeDb->dlRrcMsg)
13203                {
13204                   if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
13205                   {
13206                      duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
13207                   }
13208                   else
13209                   {
13210                      DU_LOG("\nERROR  -->  Ignoring delivery report, since rrcContainer is not present");
13211                   }
13212                }
13213                break;
13214             }
13215
13216          case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
13217             {
13218                /* MaximumBitRate Uplink */
13219                bitRateSize = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.size;
13220                if(bitRateSize > 0)
13221                {
13222                   DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->duUeCfg.ambrCfg, bitRateSize);
13223                   if(!duUeCb->f1UeDb->duUeCfg.ambrCfg)
13224                   {
13225                      DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for bitRate in procUeCtxtSetupReq");
13226                      ret = RFAILED;
13227                   }
13228                   else
13229                   {
13230                      memset(duUeCb->f1UeDb->duUeCfg.ambrCfg, 0, sizeof(AmbrCfg)); 
13231                      memcpy(&duUeCb->f1UeDb->duUeCfg.ambrCfg->ulBr,
13232                            ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf, bitRateSize);
13233                   }
13234                }
13235                else
13236                   ret = RFAILED;
13237                break;
13238             }
13239
13240          default:
13241             {
13242                break;
13243             }
13244       } /* End of switch */
13245
13246       /* In case of any failure in any IE */
13247       if(ret == RFAILED)
13248       {
13249          // BuildAndSendUeContextSetupRsp(cellId,ueId);
13250          DU_LOG("\nERROR  -->  F1AP: Failed to process UE CNTXT SETUP REQ at procF1UeContextSetupReq()"); 
13251          break;
13252       }
13253    } /* End of for loop of IEs */
13254
13255    if(ret == ROK)
13256       ret = duProcUeContextSetupRequest(duUeCb);
13257
13258    freeAperDecodeF1UeContextSetupReq(ueSetReq); 
13259    return ret;
13260
13261 }
13262 /*******************************************************************
13263  * @brief Free the memory allocated for Dl Tunnel Info
13264  *
13265  * @details
13266  *
13267  *    Function : freeDlTnlInfo
13268  *
13269  *    Functionality:
13270  *       Free the memory allocated for Dl Tunnel Info
13271  *
13272  * @params[in] DLUPTNLInformation_ToBeSetup_List_t *
13273  * @return void
13274  *
13275  * ****************************************************************/
13276
13277 void freeDlTnlInfo(DLUPTNLInformation_ToBeSetup_List_t *tnlInfo)
13278 {
13279    uint8_t arrIdx = 0;
13280
13281    if(tnlInfo)
13282    {
13283       for(arrIdx=0; arrIdx < tnlInfo->list.count; arrIdx++)
13284       {
13285          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf,\
13286                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.size);
13287          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf,\
13288                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.size);
13289          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
13290          DU_FREE(tnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
13291       }
13292       DU_FREE(tnlInfo->list.array, tnlInfo->list.size);
13293    }
13294 }
13295
13296 /*******************************************************************
13297  * @brief Free the memory allocated for DRB setup List
13298  *
13299  * @details
13300  *
13301  *    Function : freeDrbSetupList
13302  *
13303  *    Functionality:
13304  *       Free the memory allocated for DRB setup list
13305  *
13306  * @params[in] DRBs_Setup_List_t *
13307  * @return void
13308  *
13309  * ****************************************************************/
13310 void freeDrbSetupList(DRBs_Setup_List_t *drbSetupList)
13311 {
13312    uint8_t arrIdx = 0;
13313    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
13314
13315    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
13316    {
13317       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
13318       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List);
13319       DU_FREE(drbSetupList->list.array[arrIdx],  sizeof(DRBs_Setup_Item_t));
13320    }
13321    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
13322 }
13323
13324 /*******************************************************************
13325  * @brief Free the memory allocated for UE Setup response
13326  *
13327  * @details
13328  *
13329  *    Function : FreeUeContextSetupRsp
13330  *
13331  *    Functionality:
13332  *       Free the memory allocated for UE Setup response
13333  *
13334  * @params[in] F1AP PDU for UE setup response
13335  * @return ROK     - success
13336  *         RFAILED - failure
13337  *
13338  * ****************************************************************/
13339 void FreeUeContextSetupRsp(F1AP_PDU_t *f1apMsg)
13340 {
13341    uint8_t idx;
13342    UEContextSetupResponse_t *ueSetRsp = NULLP;
13343
13344    if(f1apMsg)
13345    {
13346       if(f1apMsg->choice.successfulOutcome)
13347       {
13348          ueSetRsp = &f1apMsg->choice.successfulOutcome->value.choice.\
13349                     UEContextSetupResponse;
13350          if(ueSetRsp->protocolIEs.list.array)
13351          {
13352             for(idx = 0; idx < ueSetRsp->protocolIEs.list.count; idx++)
13353             {
13354                if(ueSetRsp->protocolIEs.list.array[idx])
13355                {
13356                   switch(ueSetRsp->protocolIEs.list.array[idx]->id)
13357                   {
13358                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13359                         break;
13360                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13361                         break;
13362                      case ProtocolIE_ID_id_DUtoCURRCInformation:
13363                         {
13364                            CellGroupConfig_t *cellGrpCfg = NULLP;
13365                            cellGrpCfg  = &ueSetRsp->protocolIEs.list.array[idx]->value.choice.\
13366                                          DUtoCURRCInformation.cellGroupConfig;
13367                            if(cellGrpCfg->buf != NULLP)
13368                            {
13369                               DU_FREE(cellGrpCfg->buf, cellGrpCfg->size);
13370                               cellGrpCfg = NULLP;
13371                            }
13372                            break;
13373                         }
13374                     case ProtocolIE_ID_id_DRBs_Setup_List:
13375                         {
13376                            freeDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List); 
13377                            break;
13378                         }
13379                      default:
13380                         DU_LOG("\nERROR  -->  DUAPP: Invalid Id %ld at FreeUeContextSetupRsp()",\
13381                         ueSetRsp->protocolIEs.list.array[idx]->id);
13382                         break;
13383                   }
13384                   DU_FREE(ueSetRsp->protocolIEs.list.array[idx],\
13385                         sizeof(UEContextSetupResponseIEs_t));
13386                }
13387             }
13388             DU_FREE(ueSetRsp->protocolIEs.list.array, \
13389                   ueSetRsp->protocolIEs.list.size);
13390          }
13391          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
13392       }
13393       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
13394    }
13395 }
13396
13397 /*******************************************************************
13398  *
13399  * @brief Builds Ue context Setup Rsp DU To CU Info
13400  *
13401  * @details
13402  *
13403  *    Function : EncodeUeCntxtDuToCuInfo
13404  *
13405  *    Functionality: Builds Ue context Setup Rsp DU To CU Info
13406  *
13407  * @params[in] CellGroupConfig_t *, CellGroupConfigRrc_t * 
13408  *
13409  * @return ROK     - success
13410  *         RFAILED - failure
13411  *
13412  ******************************************************************/
13413
13414 uint8_t EncodeUeCntxtDuToCuInfo(CellGroupConfig_t *duToCuCellGrp, CellGroupConfigRrc_t *duCellGrpCfg)
13415 {
13416    asn_enc_rval_t        encRetVal;
13417
13418    xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, duCellGrpCfg);
13419    memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
13420    encBufSize = 0;
13421    encRetVal = aper_encode(&asn_DEF_CellGroupConfigRrc, 0, duCellGrpCfg, PrepFinalEncBuf, encBuf);
13422    /* Encode results */
13423    if(encRetVal.encoded == ENCODE_FAIL)
13424    {
13425       DU_LOG( "\nERROR  -->  F1AP : Could not encode UeCntxtDuToCuInfo (at %s)\n",\
13426             encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
13427       return RFAILED;
13428    }
13429    else
13430    {
13431       DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UeCntxtDuToCuInfo\n");
13432       for(int i=0; i< encBufSize; i++)
13433       {
13434          printf("%x",encBuf[i]);
13435       }
13436    }
13437    duToCuCellGrp->size = encBufSize;
13438    DU_ALLOC(duToCuCellGrp->buf, duToCuCellGrp->size);
13439    if(!duToCuCellGrp->buf)
13440    {
13441       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in UeCntxtDuToCuInfo");
13442    }
13443    memcpy(duToCuCellGrp->buf, encBuf, duToCuCellGrp->size);
13444    return ROK;
13445 }
13446
13447 /*******************************************************************
13448  *
13449  * @brief Fills Dl Gtp tunnel Info
13450  *
13451  * @details
13452  *
13453  *    Function : fillGtpTunnelforDl
13454  *
13455  *    Functionality: Fills Dl Gtp tunnel Info
13456  *
13457  * @params[in] 
13458  *
13459  * @return ROK     - success
13460  *         RFAILED - failure
13461  *
13462  * ****************************************************************/
13463
13464 uint8_t fillGtpTunnelforDl(GTPTunnel_t *gtpDl, GtpTnlCfg *gtpUeCfg)
13465 {
13466    uint8_t bufSize = 0;
13467
13468    gtpDl->transportLayerAddress.size    = 4*sizeof(uint8_t);
13469    DU_ALLOC(gtpDl->transportLayerAddress.buf, gtpDl->transportLayerAddress.size);
13470    if(gtpDl->transportLayerAddress.buf == NULLP)
13471    {
13472       return RFAILED;
13473    }
13474    memcpy(gtpDl->transportLayerAddress.buf, &gtpUeCfg->dlTnlAddress, gtpDl->transportLayerAddress.size);
13475
13476    /*GTP TEID*/
13477    gtpDl->gTP_TEID.size = 4 * sizeof(uint8_t);
13478    DU_ALLOC(gtpDl->gTP_TEID.buf, gtpDl->gTP_TEID.size);
13479    if(gtpDl->gTP_TEID.buf == NULLP)
13480    {
13481       return RFAILED;
13482    }
13483    bufSize = 3; /*forming an Octect String*/
13484    fillTeIdString(bufSize, gtpUeCfg->teId, gtpDl->gTP_TEID.buf);
13485
13486    return ROK;
13487 }
13488
13489 /*******************************************************************
13490  *
13491  * @brief Fills DL Tunnel Setup List
13492  *
13493  * @details
13494  *
13495  *    Function : fillDlTnlSetupList
13496  *
13497  *    Functionality: Fills the DL Tunnel Setup List
13498  *
13499  * @params[in] 
13500  *
13501  * @return ROK     - success
13502  *         RFAILED - failure
13503  *
13504  * ****************************************************************/
13505
13506 uint8_t fillDlTnlSetupList(DLUPTNLInformation_ToBeSetup_List_t *dlTnlInfo, UpTnlCfg *tnlCfg)
13507 {
13508    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
13509
13510    eleCount = 1;
13511    dlTnlInfo->list.count = eleCount; 
13512    dlTnlInfo->list.size = (eleCount * sizeof(DLUPTNLInformation_ToBeSetup_Item_t *));
13513
13514    /* Initialize the DL Tnl Setup List Members */
13515    DU_ALLOC(dlTnlInfo->list.array, dlTnlInfo->list.size);
13516    if(dlTnlInfo->list.array == NULLP)
13517    {
13518       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL Tnl Setup List in fillDlTnlSetupList()");
13519       ret = RFAILED;
13520    }
13521    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
13522    {
13523       DU_ALLOC(dlTnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
13524       if(dlTnlInfo->list.array[arrIdx] == NULLP)
13525       {
13526          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDlTnlSetupList()", arrIdx);
13527          return RFAILED;
13528       }
13529       dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.present = UPTransportLayerInformation_PR_gTPTunnel;
13530       DU_ALLOC(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
13531       if(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel == NULLP)
13532       {
13533          DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL tunnel info in fillDlTnlSetupList()");
13534          return RFAILED;
13535       }
13536       ret = fillGtpTunnelforDl(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel,\
13537                tnlCfg->tnlCfg1);
13538       if(ret != ROK)
13539          break;
13540    }
13541    return ret;
13542 }
13543
13544 /*******************************************************************
13545  *
13546  * @brief Fills the Drb Setup List for Ue Context Setup Response
13547  *
13548  * @details
13549  *
13550  *    Function : fillDrbSetupList
13551  *
13552  *    Functionality: Fills the Drb Setup List for Ue Context Setup Response
13553  *
13554  * @params[in] 
13555  *
13556  * @return ROK     - success
13557  *         RFAILED - failure
13558  *
13559  * ****************************************************************/
13560 uint8_t fillDrbSetupList(DRBs_Setup_List_t *drbSetupList, DuUeCfg *ueCfg)
13561 {
13562    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
13563    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
13564
13565    eleCount = ueCfg->numDrb;
13566    drbSetupList->list.count = eleCount;
13567    drbSetupList->list.size = \
13568         (eleCount * sizeof(DRBs_Setup_Item_t *));
13569
13570    /* Initialize the Drb Setup List Members */
13571    DU_ALLOC(drbSetupList->list.array, drbSetupList->list.size);
13572    if(drbSetupList->list.array == NULLP)
13573    {
13574       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DRB Setup List in fillDrbSetupList()");
13575       ret = RFAILED;
13576    }
13577
13578    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
13579    {
13580       DU_ALLOC(drbSetupList->list.array[arrIdx], sizeof(DRBs_Setup_Item_t));
13581       if(drbSetupList->list.array[arrIdx] == NULLP)
13582       {
13583          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDrbSetupList()", arrIdx);
13584          return RFAILED;
13585       }
13586       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
13587       drbItemIe->id = ProtocolIE_ID_id_DRBs_Setup_Item;
13588       drbItemIe->criticality = Criticality_reject;
13589       drbItemIe->value.present = DRBs_Setup_ItemIEs__value_PR_DRBs_Setup_Item;
13590       drbItemIe->value.choice.DRBs_Setup_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
13591       ret = fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List,\
13592           &ueCfg->upTnlInfo[arrIdx]);
13593       if(ret != ROK)
13594          break;
13595    }
13596    return ret;
13597 }
13598
13599 /*******************************************************************
13600  *
13601  * @brief Builds and sends the UE Setup Response
13602  *
13603  * @details
13604  *
13605  *    Function : BuildAndSendUeContextSetupRsp
13606  *
13607  *    Functionality: Constructs the UE Setup Response and sends
13608  *                   it to the DU through SCTP.
13609  *
13610  * @params[in] uint8_t cellId,uint8_t ueId
13611  *
13612  * @return ROK     - success
13613  *         RFAILED - failure
13614  *
13615  * ****************************************************************/
13616 uint8_t BuildAndSendUeContextSetupRsp(uint8_t cellId,uint8_t ueId)
13617 {
13618    uint8_t   idx, ret, cellIdx, elementCnt;
13619    uint32_t  gnbCuUeF1apId;   /* gNB-CU UE F1AP Id */
13620    uint32_t  gnbDuUeF1apId;   /* gNB-DU UE F1AP Id */
13621    asn_enc_rval_t  encRetVal;        /* Encoder return value */
13622    F1AP_PDU_t               *f1apMsg = NULLP;
13623    UEContextSetupResponse_t *ueSetRsp = NULLP;
13624    DuUeCb                   *ueCb = NULLP;
13625
13626    DU_LOG("\n INFO   -->  F1AP : Building UE Context Setup Response for cellId %d, ueId %d\n", cellId, ueId);
13627
13628    while(true)
13629    {
13630       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
13631       if(f1apMsg == NULLP)
13632       {
13633          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
13634          ret = RFAILED;
13635          break;
13636       }
13637
13638       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
13639       DU_ALLOC(f1apMsg->choice.successfulOutcome,
13640             sizeof(SuccessfulOutcome_t));
13641       if(f1apMsg->choice.successfulOutcome == NULLP)
13642       {
13643          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
13644          ret = RFAILED;
13645          break;
13646       }
13647
13648       f1apMsg->choice.successfulOutcome->procedureCode = \
13649                                                          ProcedureCode_id_UEContextSetup;
13650       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
13651       f1apMsg->choice.successfulOutcome->value.present = \
13652                                                          SuccessfulOutcome__value_PR_UEContextSetupResponse;
13653
13654       ueSetRsp =
13655          &f1apMsg->choice.successfulOutcome->value.choice.UEContextSetupResponse;
13656       elementCnt = 5;
13657       ueSetRsp->protocolIEs.list.count = elementCnt;
13658       ueSetRsp->protocolIEs.list.size = \
13659                                         elementCnt * sizeof(UEContextSetupResponse_t *);
13660
13661       /* Initialize the UESetup members */
13662       DU_ALLOC(ueSetRsp->protocolIEs.list.array, \
13663             ueSetRsp->protocolIEs.list.size);
13664       if(ueSetRsp->protocolIEs.list.array == NULLP)
13665       {
13666          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
13667          ret = RFAILED;
13668          break;
13669       }
13670
13671       for(idx=0; idx<elementCnt; idx++)
13672       {
13673          DU_ALLOC(ueSetRsp->protocolIEs.list.array[idx],\
13674                sizeof(UEContextSetupResponseIEs_t));
13675          if(ueSetRsp->protocolIEs.list.array[idx] == NULLP)
13676          {
13677             DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
13678             ret = RFAILED;
13679             break;
13680          }
13681       }
13682       /* Fetching Ue Cb Info*/
13683       GET_CELL_IDX(cellId, cellIdx);
13684       gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
13685       gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
13686       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
13687
13688       idx = 0;
13689       /*GNB CU UE F1AP ID*/
13690       ueSetRsp->protocolIEs.list.array[idx]->id = \
13691                                                   ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
13692       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13693       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
13694                                                              UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
13695       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
13696
13697       /*GNB DU UE F1AP ID*/
13698       idx++;
13699       ueSetRsp->protocolIEs.list.array[idx]->id = \
13700                                                   ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
13701       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13702       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
13703                                                              UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
13704       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
13705
13706
13707       /*DUtoCURRC Information */
13708       idx++;
13709       ueSetRsp->protocolIEs.list.array[idx]->id  = \
13710                                                    ProtocolIE_ID_id_DUtoCURRCInformation;
13711       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13712       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
13713                                                             UEContextSetupResponseIEs__value_PR_DUtoCURRCInformation;
13714       BuildCellGroupConfigRrc(ueCb, &ueSetRsp->protocolIEs.list.array[idx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
13715
13716       /* CRNTI */
13717       idx++;
13718       ueSetRsp->protocolIEs.list.array[idx]->id  = ProtocolIE_ID_id_C_RNTI;
13719       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13720       ueSetRsp->protocolIEs.list.array[idx]->value.present = UEContextSetupResponseIEs__value_PR_C_RNTI;
13721       ueSetRsp->protocolIEs.list.array[idx]->value.choice.C_RNTI = ueCb->crnti; 
13722
13723
13724       /* Drb Setup List */
13725       idx++;
13726       ueSetRsp->protocolIEs.list.array[idx]->id  = \
13727                                                    ProtocolIE_ID_id_DRBs_Setup_List;
13728       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13729       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
13730                                                             UEContextSetupResponseIEs__value_PR_DRBs_Setup_List;
13731       ret = fillDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List,\
13732             &ueCb->f1UeDb->duUeCfg);
13733       if(ret == RFAILED)
13734       {
13735          DU_LOG("\nERROR  -->  F1AP : Failed to fillDrbSetupList in BuildAndSendUeContextSetupRsp()");
13736          freeF1UeDb(ueCb->f1UeDb);
13737          ueCb->f1UeDb = NULLP;
13738          break;
13739       }
13740
13741       /* Free UeContext Db created during Ue context Req */
13742       freeF1UeDb(ueCb->f1UeDb);
13743       ueCb->f1UeDb = NULLP;
13744
13745       /* TODO: To send Drb list */
13746       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
13747
13748       /* Encode the UE context setup response type as APER */
13749       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
13750       encBufSize = 0;
13751       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
13752             encBuf);
13753       /* Encode results */
13754       if(encRetVal.encoded == ENCODE_FAIL)
13755       {
13756          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Response structure (at %s)\n",\
13757                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
13758          ret = RFAILED;
13759          break;
13760       }
13761       else
13762       {
13763          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Setup Response\n");
13764          for(int i=0; i< encBufSize; i++)
13765          {
13766             printf("%x",encBuf[i]);
13767          }
13768       }
13769
13770       /* Sending  msg  */
13771       if(sendF1APMsg()  != ROK)
13772       {
13773          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Response failed");
13774          ret = RFAILED;
13775          break;
13776       }
13777       break;
13778    }
13779    FreeUeContextSetupRsp(f1apMsg);
13780    return ret;
13781 }/* End of BuildAndSendUeContextSetupRsp */
13782 /*******************************************************************
13783 *
13784 * @brief  Build And Send Ue Context Rsp 
13785 *
13786 * @details
13787 *
13788 *    Function : BuildAndSendUeCtxtRsp 
13789 *
13790 *    Functionality : Build And Send Ue Context Rsp
13791
13792 * @params[in]
13793 * @return sucess = ROK
13794 *         failure = RFAILED
13795 *
13796 * ****************************************************************/
13797 uint8_t BuildAndSendUeCtxtRsp(uint8_t cellId, uint8_t ueId)
13798 {
13799    uint8_t cellIdx = 0, actionType = 0; 
13800
13801    GET_CELL_IDX(cellId, cellIdx);
13802    actionType = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].f1UeDb->actionType;
13803
13804    switch(actionType)
13805    {
13806       case UE_CTXT_SETUP:
13807          {
13808             if((BuildAndSendUeContextSetupRsp(cellId,ueId)) != ROK)
13809             {
13810                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextSetupRsp()");
13811                return RFAILED;
13812             }
13813             break;
13814          }
13815       case UE_CTXT_MOD:
13816          {
13817             if((BuildAndSendUeContextModRsp(&duCb.actvCellLst[cellIdx]->ueCb[ueId-1])) != ROK)
13818             {
13819                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextModRsp");
13820                return RFAILED;
13821             }
13822             break;
13823          }
13824       default:
13825          DU_LOG("ERROR  -->  F1AP: Invalid Action Type %d at BuildAndSendUeCtxtRsp()", actionType);
13826          break;
13827
13828    }
13829    return ROK;
13830 }
13831
13832 /*******************************************************************
13833  *
13834  * @brief deallocating the memory of  F1reset msg
13835  *
13836  * @details
13837  *
13838  *    Function : FreeF1ResetReq
13839  *
13840  *    Functionality :
13841  *         - freeing memory of F1reset request msg
13842  *
13843  * @params[in]
13844  * @return void
13845  *
13846  *
13847  * ****************************************************************/
13848 void FreeF1ResetReq(F1AP_PDU_t *f1apMsg)
13849 {
13850    uint8_t idx =0 ;
13851    Reset_t *f1ResetMsg;
13852
13853    if(f1apMsg)
13854    {
13855       if(f1apMsg->choice.initiatingMessage)
13856       {
13857          f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
13858
13859          if(f1ResetMsg->protocolIEs.list.array)
13860          {
13861             for(idx=0 ;idx < f1ResetMsg->protocolIEs.list.count ; idx++)
13862             {
13863                if(f1ResetMsg->protocolIEs.list.array[idx])
13864                {
13865                   DU_FREE(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
13866                }
13867             }
13868             DU_FREE(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
13869          }
13870          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
13871       }
13872       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
13873    }
13874 }
13875 /*******************************************************************
13876  *
13877  * @brief Build and Send F1reset request 
13878  *
13879  * @details
13880  *
13881  *    Function : BuildAndSendF1ResetReq
13882  *
13883  *    Functionality:
13884  *         - Build and Send F1reset request msg
13885  *
13886  * @params[in]
13887  * @return ROK     - success
13888  *         RFAILED - failure
13889  *
13890  * ****************************************************************/
13891 uint8_t BuildAndSendF1ResetReq()
13892 {
13893    uint8_t          elementCnt=0;
13894    uint8_t          idx=0;
13895    uint8_t          ret= RFAILED;
13896    Reset_t          *f1ResetMsg = NULLP;
13897    F1AP_PDU_t       *f1apMsg = NULLP;
13898    asn_enc_rval_t   encRetVal;
13899    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset request \n");
13900    do
13901    {
13902       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
13903       if(f1apMsg == NULLP)
13904       {
13905          break;
13906       }
13907       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
13908       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
13909       if(f1apMsg->choice.initiatingMessage == NULLP)
13910       {
13911          break;
13912       }
13913       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_Reset;
13914       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
13915       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_Reset;
13916
13917       f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
13918
13919       elementCnt = 3;
13920       f1ResetMsg->protocolIEs.list.count = elementCnt;
13921       f1ResetMsg->protocolIEs.list.size = elementCnt * sizeof(ResetIEs_t *);
13922
13923       /* Initialize the F1Setup members */
13924       DU_ALLOC(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
13925       if(f1ResetMsg->protocolIEs.list.array == NULLP)
13926       {
13927          break;
13928       }
13929       for(idx=0; idx<elementCnt; idx++)
13930       {
13931          DU_ALLOC(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
13932          if(f1ResetMsg->protocolIEs.list.array[idx] == NULLP)
13933          {
13934             break;
13935          }
13936       }
13937
13938       /*TransactionID*/
13939       idx=0;
13940       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
13941       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13942       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_TransactionID;
13943       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.TransactionID = 1;
13944
13945       /*Cause*/
13946       idx++;
13947       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_Cause;
13948       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_ignore;
13949       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_Cause;
13950       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.present = Cause_PR_radioNetwork;
13951       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.choice.radioNetwork = CauseRadioNetwork_action_desirable_for_radio_reasons;
13952
13953       /*Reset Type*/
13954       idx++;
13955       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_ResetType;
13956       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13957       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_ResetType;
13958       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.present = ResetType_PR_f1_Interface;
13959       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.choice.f1_Interface = ResetAll_reset_all;
13960
13961       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
13962
13963       /* Encode the F1SetupRequest type as APER */
13964       memset(encBuf, 0, ENC_BUF_MAX_LEN);
13965       encBufSize = 0;
13966       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
13967             encBuf);
13968
13969       /* Encode results */
13970       if(encRetVal.encoded == ENCODE_FAIL)
13971       {
13972          DU_LOG("\nERROR  -->  F1AP : Could not encode F1Reset structure (at %s)\n",\
13973                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
13974          break;
13975       }
13976       else
13977       {
13978          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1Reset\n");
13979          for(idx=0; idx< encBufSize; idx++)
13980          {
13981             printf("%x",encBuf[idx]);
13982          }
13983       }
13984
13985       if(sendF1APMsg() != ROK)
13986       {
13987          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset request failed");
13988          break;
13989       }
13990
13991       ret = ROK;
13992       break;
13993    }while(true);
13994
13995    FreeF1ResetReq(f1apMsg);
13996    return ret;
13997 }
13998 /*******************************************************************
13999  *
14000  * @brief Build And Send F1ResetAck
14001  *
14002  * @details
14003  *
14004  *    Function : BuildAndSendF1ResetAck
14005  *
14006  *    Functionality:
14007  *         - Build And Send  F1ResetRSP
14008  *
14009  * @return ROK     - success
14010  *         RFAILED - failure
14011  *
14012  * ****************************************************************/
14013 void FreeF1ResetAck(F1AP_PDU_t *f1apMsg)
14014 {
14015    uint8_t idx;
14016    ResetAcknowledge_t *f1ResetAck;
14017
14018    if(f1apMsg)
14019    {
14020       if(f1apMsg->choice.successfulOutcome)
14021       {
14022          f1ResetAck= &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14023
14024          if(f1ResetAck->protocolIEs.list.array)
14025          {
14026             for(idx=0; idx<f1ResetAck->protocolIEs.list.count ; idx++)
14027             {
14028                if(f1ResetAck->protocolIEs.list.array[idx])
14029                {
14030                   DU_FREE(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14031                }
14032             }
14033             DU_FREE(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14034          }
14035          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14036       }
14037       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14038    }
14039 }
14040
14041 /*******************************************************************
14042  *
14043  * @brief Build And Send F1ResetAck
14044  *
14045  * @details
14046  *
14047  *    Function : BuildAndSendF1ResetAck
14048  *
14049  *    Functionality:
14050  *         - Build And Send  F1ResetRSP
14051  *
14052  *  @params[in]
14053  * @return ROK     - success
14054  *         RFAILED - failure
14055  *
14056  * ****************************************************************/
14057 uint8_t BuildAndSendF1ResetAck()
14058 {
14059    uint8_t                idx = 0;
14060    uint8_t                elementCnt = 0;
14061    uint8_t                ret = RFAILED;
14062    F1AP_PDU_t             *f1apMsg = NULL;
14063    ResetAcknowledge_t     *f1ResetAck = NULLP;
14064    asn_enc_rval_t         encRetVal;
14065    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset Acknowledgment \n");
14066
14067    do{
14068       /* Allocate the memory for F1ResetRequest_t */
14069       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14070       if(f1apMsg == NULLP)
14071       {
14072          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14073          break;
14074       }
14075
14076       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
14077
14078       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14079       if(f1apMsg->choice.successfulOutcome == NULLP)
14080       {
14081          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14082          break;
14083       }
14084       f1apMsg->choice.successfulOutcome->criticality   = Criticality_reject;
14085       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetAcknowledge;
14086       f1ResetAck = &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14087
14088       elementCnt = 1;
14089
14090       f1ResetAck->protocolIEs.list.count = elementCnt;
14091       f1ResetAck->protocolIEs.list.size = elementCnt*sizeof(ResetAcknowledgeIEs_t *);
14092
14093       DU_ALLOC(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14094       if(f1ResetAck->protocolIEs.list.array == NULLP)
14095       {
14096          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1ResetAckIEs failed");
14097          break;
14098       }
14099
14100       for(idx=0; idx<elementCnt; idx++)
14101       {
14102          DU_ALLOC(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14103          if(f1ResetAck->protocolIEs.list.array[idx] == NULLP)
14104          {
14105             break;
14106          }
14107       }
14108       /*TransactionID*/
14109       idx = 0;
14110       f1ResetAck->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
14111       f1ResetAck->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14112       f1ResetAck->protocolIEs.list.array[idx]->value.present = ResetAcknowledgeIEs__value_PR_TransactionID;
14113       f1ResetAck->protocolIEs.list.array[idx]->value.choice.TransactionID = TRANS_ID;
14114
14115       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14116
14117       /* Encode the F1SetupRequest type as UPER */
14118       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14119       encBufSize = 0;
14120       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
14121
14122       /* Check encode results */
14123       if(encRetVal.encoded == ENCODE_FAIL)
14124       {
14125          DU_LOG("\nERROR  -->  F1AP : Could not encode F1ResetAck structure (at %s)\n",\
14126                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14127          break;
14128       }
14129       else
14130       {
14131          DU_LOG("\nDUBUG   -->  F1AP : Created APER encoded buffer for F1ResetAck\n");
14132          for(int i=0; i< encBufSize; i++)
14133          {
14134             printf("%x",encBuf[i]);
14135          }
14136       }
14137       /* Sending msg */
14138       if(sendF1APMsg() != ROK)
14139       {
14140          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset Acknowledgement failed");
14141          break;
14142       }
14143
14144       ret = ROK;
14145       break;
14146    }while(true);
14147
14148    FreeF1ResetAck(f1apMsg);
14149    return ret;
14150 }
14151 /******************************************************************
14152 *
14153 * @brief free F1 reset msg allocated by aper_decoder 
14154 *
14155 * @details
14156 *
14157 *    Function : freeAperDecodeF1ResetMsg 
14158 *
14159 *    Functionality: free F1 reset msg allocated by aper_decoder 
14160 *
14161 * @params[in] Reset_t *f1ResetMsg 
14162 * @return void 
14163 *
14164 * ****************************************************************/
14165
14166 void freeAperDecodeF1ResetMsg(Reset_t *f1ResetMsg)
14167 {
14168    uint8_t ieIdx =0;
14169    if(f1ResetMsg->protocolIEs.list.array)
14170    {
14171       for(ieIdx=0 ;ieIdx < f1ResetMsg->protocolIEs.list.count ; ieIdx++)
14172       {
14173          if(f1ResetMsg->protocolIEs.list.array[ieIdx])
14174          {
14175             free(f1ResetMsg->protocolIEs.list.array[ieIdx]);
14176          }
14177       }
14178       free(f1ResetMsg->protocolIEs.list.array);
14179    }
14180 }
14181
14182 /******************************************************************
14183  *
14184  * @brief Processes DL RRC Message Transfer  sent by CU
14185  *
14186  * @details
14187  *
14188  *    Function : procF1ResetReq
14189  *
14190  *    Functionality: Processes DL RRC Message Transfer sent by CU
14191  *
14192  * @params[in] F1AP_PDU_t ASN decoded F1AP message
14193  * @return ROK     - success
14194  *         RFAILED - failure
14195  *
14196  * ****************************************************************/
14197 uint8_t procF1ResetReq(F1AP_PDU_t *f1apMsg)
14198 {
14199    /* we are currently not supporting Ue release. right now we are supporting only init case of fireset */
14200    uint8_t       ieIdx = 0;
14201    uint8_t        ret = ROK;
14202    Reset_t       *f1ResetMsg = NULLP;
14203
14204    DU_LOG("\nINFO   -->  Processing F1 reset request");
14205    f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14206
14207    for(ieIdx=0; ieIdx<f1ResetMsg->protocolIEs.list.count; ieIdx++)
14208    {
14209       switch(f1ResetMsg->protocolIEs.list.array[ieIdx]->id)
14210       {
14211          case ProtocolIE_ID_id_TransactionID:
14212             break;
14213
14214          case ProtocolIE_ID_id_Cause:
14215             break;
14216
14217          case ProtocolIE_ID_id_ResetType:
14218             {
14219                break;
14220             }
14221
14222          default:
14223             break;
14224       }
14225    }
14226    ret = BuildAndSendF1ResetAck();
14227    DU_LOG("\nINFO   -->  UE release is not supported for now");
14228
14229    freeAperDecodeF1ResetMsg(f1ResetMsg);
14230
14231    return ret;
14232 }
14233
14234 /*******************************************************************
14235  *
14236  * @brief free the RRC delivery report
14237  *
14238  * @details
14239  *
14240  *    Function : freeRrcDeliveryReport
14241  *
14242  *    Functionality: free the RRC delivery report
14243  *
14244  * @params[in]
14245  * @return ROK     - success
14246  *         RFAILED - failure
14247  *
14248  * ****************************************************************/
14249 void freeRrcDeliveryReport(F1AP_PDU_t  *f1apMsg )
14250 {
14251    uint8_t idx=0;
14252    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
14253
14254    if(f1apMsg)
14255    {
14256       if(f1apMsg->choice.initiatingMessage)
14257       {
14258          rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
14259          if(rrcDeliveryReport->protocolIEs.list.array)
14260          {
14261             for(idx =0 ;idx <rrcDeliveryReport->protocolIEs.list.count ;
14262                   idx++)
14263             {
14264                if(rrcDeliveryReport->protocolIEs.list.array[idx])
14265                {
14266                   DU_FREE(rrcDeliveryReport->protocolIEs.list.array[idx],
14267                         sizeof(RRCDeliveryReportIEs_t));
14268                }   
14269             }
14270             DU_FREE(rrcDeliveryReport->protocolIEs.list.array,
14271                   rrcDeliveryReport->protocolIEs.list.size);
14272          }
14273          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
14274       }
14275       DU_FREE(f1apMsg,
14276             sizeof(F1AP_PDU_t));
14277    }
14278 }
14279
14280 /*******************************************************************
14281 *
14282 * @brief Builds and sends the RRC delivery report
14283 *
14284 * @details
14285 *
14286 *    Function : BuildAndSendRrcDeliveryReport
14287 *
14288 *    Functionality: Builds and sends the RRC delivery report
14289 *
14290 * @params[in]
14291 *
14292 * @return ROK     - success
14293 *         RFAILED - failure
14294 *
14295 * ****************************************************************/
14296 uint8_t BuildAndSendRrcDeliveryReport(uint32_t gnbCuUeF1apId, \
14297    uint32_t gnbDuUeF1apId, RrcDeliveryReport *rrcDelivery)
14298 {
14299    uint8_t             ret = RFAILED;
14300    uint8_t             idx    = 0;
14301    uint8_t             idx1   = 0;
14302    uint8_t             elementCnt = 0;
14303    F1AP_PDU_t          *f1apMsg = NULLP;
14304    asn_enc_rval_t      encRetVal;  
14305    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
14306
14307    do{
14308
14309       DU_LOG("\nINFO   -->  F1AP : Building RRC delivery Message Transfer Message\n");
14310       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14311       if(f1apMsg == NULLP)
14312       {
14313          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14314          break;
14315       }
14316       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
14317       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
14318       if(f1apMsg->choice.initiatingMessage == NULLP)
14319       {
14320          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU  failed");
14321          break;
14322       }
14323       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_RRCDeliveryReport;
14324       f1apMsg->choice.initiatingMessage->criticality   = Criticality_ignore;
14325       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_RRCDeliveryReport;
14326
14327       rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
14328       elementCnt = 4;
14329       rrcDeliveryReport->protocolIEs.list.count = elementCnt;
14330       rrcDeliveryReport->protocolIEs.list.size = elementCnt * sizeof(RRCDeliveryReportIEs_t *);
14331
14332       /* Initialize the F1Setup members */
14333       DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array, rrcDeliveryReport->protocolIEs.list.size);
14334       if(rrcDeliveryReport->protocolIEs.list.array == NULLP)
14335       {
14336          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRC Delivery  failed");
14337          break;
14338       }
14339       for(idx =0 ;idx <elementCnt; idx++)
14340       {
14341          DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array[idx], sizeof(RRCDeliveryReportIEs_t));
14342          if(rrcDeliveryReport->protocolIEs.list.array[idx] == NULLP)
14343          {
14344             break;
14345          }
14346       }
14347
14348       idx1 = 0;
14349
14350       /*GNB CU UE F1AP ID*/
14351       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
14352       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
14353       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_CU_UE_F1AP_ID;
14354       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
14355
14356       /*GNB DU UE F1AP ID*/
14357       idx1++;
14358       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14359       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
14360       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_DU_UE_F1AP_ID;
14361       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
14362
14363       /*RRC delivery status*/
14364       idx1++;
14365       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_RRCDeliveryStatus;
14366       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
14367       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_RRCDeliveryStatus;
14368       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.delivery_status =\
14369       rrcDelivery->rrcDeliveryStatus.deliveryStatus;
14370       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.triggering_message =\
14371       rrcDelivery->rrcDeliveryStatus.triggeringMessage;
14372
14373       /* SRB ID */ 
14374       idx1++;
14375       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
14376       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
14377       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_SRBID;
14378       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.SRBID =  rrcDelivery->srbId;
14379
14380       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14381
14382       /* Encode the RRC DELIVERY REPORT type as APER */
14383       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14384       encBufSize = 0;
14385       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14386             encBuf);
14387
14388       /* Encode results */
14389       if(encRetVal.encoded == ENCODE_FAIL)
14390       {
14391          DU_LOG("\nERROR  -->  F1AP : Could not encode RRC Delivery Msg structure (at %s)\n",\
14392                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14393          break;
14394       }
14395       else
14396       {
14397          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for RRC Delivery Msg \n");
14398          for(idx=0; idx< encBufSize; idx++)
14399          {
14400             printf("%x",encBuf[idx]);
14401          }
14402       }
14403
14404       /* Sending msg */
14405       if(sendF1APMsg() != ROK)
14406       {
14407          DU_LOG("\nERROR  -->  F1AP : Sending RRC delivery  msg request failed");
14408          break;
14409       }
14410       ret = ROK;
14411       break;
14412
14413    }while(true);
14414
14415    freeRrcDeliveryReport(f1apMsg);
14416    return ret;
14417 }
14418
14419 /*******************************************************************
14420  *
14421  * @brief Processes cells to be activated
14422  *
14423  * @details
14424  *
14425  *    Function : extractCellsToBeActivated
14426  *
14427  *    Functionality:
14428  *      - Processes cells to be activated list received in F1SetupRsp
14429  *
14430  * @params[in] void
14431  * @return ROK     - success
14432  *         RFAILED - failure
14433  *
14434  * ****************************************************************/
14435
14436 uint8_t extractCellsToBeActivated(Cells_to_be_Activated_List_t cellsToActivate)
14437 {
14438    uint8_t  ret = ROK;
14439    uint16_t idx, pci = 0;
14440    uint64_t nci;
14441    Cells_to_be_Activated_List_Item_t cell;
14442
14443    for(idx=0; idx<cellsToActivate.list.count; idx++)
14444    {
14445       nci = 0;
14446       cell = cellsToActivate.list.array[idx]->value.choice.Cells_to_be_Activated_List_Item;
14447       bitStringToInt(&cell.nRCGI.nRCellIdentity, &nci);
14448
14449       if(cell.nRPCI)
14450       {
14451          pci = *cell.nRPCI;
14452       }
14453       ret = duProcCellsToBeActivated(cell.nRCGI.pLMN_Identity.buf, nci, pci);
14454    }
14455    return ret;
14456 }
14457 /******************************************************************
14458 *
14459 * @brief Processes F1 Setup Response allocated by aper_decoder 
14460 *
14461 * @details
14462 *
14463 *    Function : freeF1SetupRsp 
14464 *
14465 *    Functionality: free F1 Setup Response allocated by aper_decoder 
14466 *
14467 * @params[in] F1SetupResponse_t *f1SetRspMsg 
14468 * @return void 
14469 *
14470 * ****************************************************************/
14471
14472 void freeAperDecodeF1SetupRsp(F1SetupResponse_t *f1SetRspMsg)
14473 {
14474    uint8_t ieIdx =0;
14475    uint8_t arrIdx =0;
14476    Cells_to_be_Activated_List_t *cellToActivate =NULLP;
14477    RRC_Version_t      *rrcVer =NULLP;
14478
14479    if(f1SetRspMsg->protocolIEs.list.array)
14480    {
14481       for(ieIdx=0; ieIdx<f1SetRspMsg->protocolIEs.list.count; ieIdx++)
14482       {
14483          if(f1SetRspMsg->protocolIEs.list.array[ieIdx])
14484          {
14485             switch(f1SetRspMsg->protocolIEs.list.array[ieIdx]->id)
14486             {
14487                case ProtocolIE_ID_id_Cells_to_be_Activated_List:
14488                   {
14489                      cellToActivate =
14490                         &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.Cells_to_be_Activated_List;
14491                      if(cellToActivate->list.array)
14492                      {
14493                         for(arrIdx=0; arrIdx<cellToActivate->list.count ; arrIdx++)
14494                         {
14495                            if(cellToActivate->list.array[arrIdx])
14496                            {
14497
14498                               if(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.nRCGI.\
14499                               pLMN_Identity.buf)
14500                               {
14501                                  if(cellToActivate->list.array[0]->value.choice.\
14502                                        Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf)
14503                                  {
14504                                     free(cellToActivate->list.array[0]->value.choice.\
14505                                           Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf);
14506                                  }
14507
14508                                  free(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
14509                                        nRCGI.pLMN_Identity.buf);
14510                               }
14511                               free(cellToActivate->list.array[arrIdx]);
14512                            }
14513                         }
14514                         free(cellToActivate->list.array);
14515                      }
14516                      break;
14517                   }
14518                case ProtocolIE_ID_id_TransactionID:
14519                   {
14520                      break;
14521                   }
14522                case ProtocolIE_ID_id_gNB_CU_Name:
14523                   {
14524                      free(f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_Name.buf);
14525                      break;
14526                   }
14527                case ProtocolIE_ID_id_GNB_CU_RRC_Version:
14528                   {
14529                      rrcVer = &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
14530                      if(rrcVer->latest_RRC_Version.buf)
14531                      {
14532                         if(rrcVer->iE_Extensions)
14533                         {
14534                            if(rrcVer->iE_Extensions->list.array)
14535                            {
14536                               if(rrcVer->iE_Extensions->list.array[0])
14537                               {
14538                                  if(rrcVer->iE_Extensions->list.\
14539                                        array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf)
14540                                  {
14541                                     free(rrcVer->iE_Extensions->list.\
14542                                           array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf);
14543                                  }
14544                                  free(rrcVer->iE_Extensions->list.array[0]);
14545                               }
14546                               free(rrcVer->iE_Extensions->list.array);
14547                            }
14548                            free(rrcVer->iE_Extensions);
14549                         }
14550                         free(rrcVer->latest_RRC_Version.buf);
14551                      }
14552                      break;
14553
14554                   }
14555                default:
14556                   {
14557                      DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
14558                            f1SetRspMsg->protocolIEs.list.array[ieIdx]->id);
14559                   }
14560             }
14561             free(f1SetRspMsg->protocolIEs.list.array[ieIdx]);
14562          }
14563       }
14564       free(f1SetRspMsg->protocolIEs.list.array);
14565    }
14566 }
14567 /******************************************************************
14568  *
14569  * @brief Processes F1 Setup Response sent by CU
14570  *
14571  * @details
14572  *
14573  *    Function : procF1SetupRsp
14574  *
14575  *    Functionality: Processes F1 Setup Response sent by CU
14576  *
14577  * @params[in] F1AP_PDU_t ASN decoded F1AP message
14578  * @return ROK     - success
14579  *         RFAILED - failure
14580  *
14581  * ****************************************************************/
14582 uint8_t procF1SetupRsp(F1AP_PDU_t *f1apMsg, MsgLen recvBufLen, char *recvBuf)
14583 {
14584    uint8_t ret = ROK;
14585    uint16_t idx =0;
14586    F1SetupResponse_t *f1SetRspMsg = NULLP;
14587    GNB_CU_Name_t     *cuName = NULLP;
14588    F1SetupRsp  f1SetRspDb;
14589    RRC_Version_t      *rrcVer =NULLP;
14590    
14591    memset(&f1SetRspDb, 0, sizeof(F1SetupRsp));
14592
14593    DU_LOG("\nINFO   -->  F1AP : F1 Setup Response received");
14594    f1SetRspMsg = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
14595
14596    for(idx=0; idx<f1SetRspMsg->protocolIEs.list.count; idx++)
14597    {
14598       switch(f1SetRspMsg->protocolIEs.list.array[idx]->id)
14599       {
14600          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
14601             {
14602                extractCellsToBeActivated(f1SetRspMsg->protocolIEs.list.array[idx]->\
14603                      value.choice.Cells_to_be_Activated_List);
14604                break;
14605             }
14606          case ProtocolIE_ID_id_TransactionID:
14607             {
14608                f1SetRspDb.transId = f1SetRspMsg->protocolIEs.list.array[idx]->\
14609                                     value.choice.TransactionID;
14610                break;
14611             }
14612          case ProtocolIE_ID_id_gNB_CU_Name:
14613             {
14614                cuName = &f1SetRspMsg->protocolIEs.list.array[idx]->\
14615                         value.choice.GNB_CU_Name;
14616                strcpy(f1SetRspDb.cuName, (const char*)cuName->buf);
14617                break;
14618             }
14619          case ProtocolIE_ID_id_GNB_CU_RRC_Version:
14620             {
14621                rrcVer = &f1SetRspMsg->protocolIEs.list.array[idx]->value.choice.RRC_Version;
14622                strcpy(f1SetRspDb.rrcVersion.rrcVer,
14623                      (const char*)rrcVer->latest_RRC_Version.buf);
14624                break;
14625             }
14626          default:
14627             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
14628                   f1SetRspMsg->protocolIEs.list.array[idx]->id);
14629       }
14630       duProcF1SetupRsp();
14631    }
14632    
14633    freeAperDecodeF1SetupRsp(f1SetRspMsg);
14634
14635    duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize = recvBufLen;
14636    DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize);
14637    if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
14638    {
14639       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the buf of F1setup response");
14640       return RFAILED;
14641    }
14642    memcpy(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, recvBuf, recvBufLen);
14643    
14644    if(BuildAndSendE2SetupReq() != ROK)
14645    {
14646       DU_LOG("\nERROR  -->  F1AP : Failed to build and send E2 setup request ");
14647       return RFAILED;
14648    }
14649    return ret;
14650 }
14651 /*******************************************************************
14652 *
14653 * @brief free GNB DU config update ack
14654 *
14655 * @details
14656 *
14657 *    Function : freeAperDecodeGnbDuAck 
14658 *
14659 *    Functionality: Processes GNB DU config update ack And
14660 *                     added free part for the memory allocated by aper_decoder
14661 *
14662 * @params[in] F1AP_PDU_t ASN decoded F1AP message
14663 * @return ROK     - success
14664 *         RFAILED - failure
14665 *
14666 * ****************************************************************/
14667
14668 void freeAperDecodeGnbDuAck(GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck)
14669 {
14670    uint8_t ieIdx = 0;
14671
14672    if(gnbDuAck->protocolIEs.list.array)
14673    {
14674       for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
14675       {
14676          if(gnbDuAck->protocolIEs.list.array[ieIdx])
14677          {
14678             free(gnbDuAck->protocolIEs.list.array[ieIdx]);
14679          }
14680       }
14681       free(gnbDuAck->protocolIEs.list.array);
14682    }
14683 }
14684
14685 /*******************************************************************
14686 *
14687 * @brief Building  result of gnb-du config update ack output
14688 *
14689 * @details
14690 *
14691 *    Function : duProcGnbDuCfgUpdAckMsg 
14692 *
14693 *    Functionality: 
14694 *        Building output of gnb-du config update ack 
14695 *
14696 * @params[in] transId
14697 * @return void
14698 *
14699 * ****************************************************************/
14700
14701 uint8_t duProcGnbDuCfgUpdAckMsg(uint8_t transId)
14702 {
14703    uint8_t  ieIdx=0, arrIdx=0,ret=ROK;
14704    uint8_t  ueId =0 , ueIdx =0, totalActiveUe = 0;
14705    uint16_t cellIdx =0, crnti=0;
14706    uint64_t cellId =0;
14707    CmLList *f1apPduNode = NULLP;
14708    ReservedF1apPduInfo *f1apPduInfo =NULLP;
14709    F1AP_PDU_t *f1apMsgPdu = NULLP;
14710    GNBDUConfigurationUpdate_t *gnbDuConfigUpdate = NULLP;
14711    BIT_STRING_t *cellIdentity=NULLP;
14712    struct Served_Cells_To_Delete_ItemIEs *deleteItemIe=NULLP;
14713    Served_Cells_To_Delete_List_t *cellsToDelete=NULLP;
14714    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
14715
14716    DU_LOG("\nINFO   -->  DU APP: GNB-DU config update Ack received ");
14717    f1apPduNode = searchFromReservedF1apPduList(transId);
14718    f1apPduInfo = (ReservedF1apPduInfo *)f1apPduNode->node;
14719    f1apMsgPdu = (F1AP_PDU_t *)f1apPduInfo->f1apMsg;
14720
14721    if(f1apMsgPdu)
14722    {
14723       if(f1apMsgPdu->choice.initiatingMessage)
14724       {
14725          gnbDuConfigUpdate = &f1apMsgPdu->choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
14726          for(ieIdx=0; ieIdx < gnbDuConfigUpdate->protocolIEs.list.count; ieIdx++)
14727          {
14728             switch(gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->id)
14729             {
14730                case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
14731                   {
14732                      cellsToDelete = &gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
14733                                      Served_Cells_To_Delete_List;
14734                      if(cellsToDelete->list.array)
14735                      {
14736                         if(cellsToDelete->list.array[arrIdx])
14737                         {
14738                            deleteItemIe = (Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx];
14739                            deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
14740                            if(deleteItem->oldNRCGI.nRCellIdentity.buf)
14741                            {
14742                               cellIdentity = &deleteItem->oldNRCGI.nRCellIdentity;
14743                               bitStringToInt(cellIdentity, &cellId);
14744
14745                               GET_CELL_IDX(cellId, cellIdx);
14746                               if(duCb.actvCellLst[cellIdx] != NULLP)
14747                               {
14748                                  duCb.actvCellLst[cellId-1]->cellStatus = DELETION_IN_PROGRESS;
14749                               }
14750                            }
14751                         }
14752                      }
14753
14754                      if(duCb.actvCellLst[cellIdx] != NULLP)
14755                      {
14756                         if(duCb.actvCellLst[cellIdx]->numActvUes == 0)
14757                         {
14758                            ret = duSendCellDeletReq(cellId);
14759                            if(ret == RFAILED)
14760                            {
14761                               DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to send cell delete\
14762                               request for cellId[%d]", cellId);
14763                            }
14764                         }
14765                         else
14766                         {
14767                            totalActiveUe = duCb.actvCellLst[cellIdx]->numActvUes;
14768                            while(totalActiveUe)
14769                            {
14770                               if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState != UE_ACTIVE)
14771                               {
14772                                  ueIdx++;
14773                                  continue;
14774                               }
14775
14776                               crnti = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti;
14777                               GET_UE_ID(crnti,ueId);
14778                               /* Sending Ue Context release request only for maximum supporting UEs */
14779                               ret = BuildAndSendUeContextReleaseReq(cellId, ueId);
14780                               if(ret == RFAILED)
14781                               {
14782                                  DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to build and send UE delete\
14783                                  request for cellId[%d]", cellId);
14784                               }
14785                               ueIdx++;
14786                               totalActiveUe--;
14787                            }
14788                         }
14789                      }
14790                      else
14791                      {
14792                         DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): CellId [%d] not found", cellId);
14793                         ret = RFAILED;
14794                      }
14795                      break;
14796                   }
14797
14798                default:
14799                   break;
14800             }
14801          }
14802       }
14803    }
14804    
14805    FreeDUConfigUpdate(f1apMsgPdu);
14806    deleteFromReservedF1apPduList(f1apPduNode);
14807    return ret;
14808 }
14809
14810 /*******************************************************************
14811 *
14812 * @brief Processes GNB DU config update ack
14813 *
14814 * @details
14815 *
14816 *    Function : procF1GNBDUCfgUpdAck
14817 *
14818 *    Functionality: added free part for the memory allocated by aper_decoder
14819 *
14820 * @params[in] F1AP_PDU_t *f1apMsg 
14821 * @return void 
14822 *
14823 * ****************************************************************/
14824 uint8_t procF1GNBDUCfgUpdAck(F1AP_PDU_t *f1apMsg)
14825 {
14826    uint8_t ieIdx=0,transId=0;
14827    GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck = NULLP;
14828
14829    DU_LOG("\nINFO   -->  F1AP : GNB-DU config update acknowledgment");
14830    gnbDuAck = &f1apMsg->choice.successfulOutcome->value.choice.GNBDUConfigurationUpdateAcknowledge;
14831
14832    for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
14833    {
14834       switch(gnbDuAck->protocolIEs.list.array[ieIdx]->id)
14835       {
14836          case ProtocolIE_ID_id_TransactionID:
14837             {
14838                transId = gnbDuAck->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
14839                break;
14840             }
14841          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
14842             {
14843                break;
14844             }
14845          default :
14846             {
14847                DU_LOG("\nERROR  -->  F1AP: procF1GNBDUCfgUpdAck(): Invalid IE Received: %ld", \
14848                      gnbDuAck->protocolIEs.list.array[ieIdx]->id);
14849                break;
14850             }
14851       }
14852    }
14853    
14854    duProcGnbDuCfgUpdAckMsg(transId);
14855     
14856 #if 0
14857    /* presently we are not supporting F1 Reset from DU to CU , we are only
14858     * supporting F1 Reset from CU to DU */
14859
14860    if(BuildAndSendF1ResetReq() != ROK)
14861    {
14862       return RFAILED;
14863    }
14864 #endif
14865
14866    freeAperDecodeGnbDuAck(gnbDuAck);
14867    return ROK;
14868 }
14869 /******************************************************************
14870 *
14871 * @brief free DL RRC Message Transfer allocated by aper_decoder 
14872 *
14873 * @details
14874 *
14875 *    Function : freeAperDecodef1DlRrcMsg 
14876 *
14877 *    Functionality: free DL RRC Message Transfer allocated by aper_decoder 
14878 *
14879 * @params[in] DLRRCMessageTransfer_t *f1DlRrcMsg 
14880 * @return ROK     - success
14881 *         RFAILED - failure
14882 *
14883 * ****************************************************************/
14884
14885 void freeAperDecodef1DlRrcMsg(DLRRCMessageTransfer_t *f1DlRrcMsg)
14886 {
14887    uint8_t ieIdx =0;
14888    RRCContainer_t *rrcContainer = NULLP;
14889
14890    if(f1DlRrcMsg->protocolIEs.list.array)
14891    {
14892       for(ieIdx=0; ieIdx<f1DlRrcMsg->protocolIEs.list.count; ieIdx++)
14893       {
14894          if(f1DlRrcMsg->protocolIEs.list.array[ieIdx])
14895          {
14896             switch(f1DlRrcMsg->protocolIEs.list.array[ieIdx]->id)
14897             {
14898                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14899                   break;
14900                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14901                   break;
14902                case ProtocolIE_ID_id_SRBID:
14903                   break;
14904                case ProtocolIE_ID_id_RRCContainer:
14905                   {
14906                      rrcContainer =&f1DlRrcMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer;
14907                      free(rrcContainer->buf);
14908                   }
14909                case ProtocolIE_ID_id_ExecuteDuplication:
14910                   break;
14911                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
14912                   break;
14913                   break;
14914             }
14915             free(f1DlRrcMsg->protocolIEs.list.array[ieIdx]);
14916          }
14917       }
14918       free(f1DlRrcMsg->protocolIEs.list.array);
14919    }
14920 }
14921 /******************************************************************
14922  *
14923  * @brief Processes DL RRC Message Transfer  sent by CU
14924  *
14925  * @details
14926  *
14927  *    Function : procF1DlRrcMsgTrans
14928  *
14929  *    Functionality: Processes DL RRC Message Transfer sent by CU
14930  *
14931  * @params[in] F1AP_PDU_t ASN decoded F1AP message
14932  * @return ROK     - success
14933  *         RFAILED - failure
14934  *
14935  * ****************************************************************/
14936 uint8_t procF1DlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
14937 {
14938    uint8_t  idx, ret;
14939    DLRRCMessageTransfer_t *f1DlRrcMsg = NULLP;
14940    F1DlRrcMsg dlMsg;
14941    memset(&dlMsg, 0, sizeof(F1DlRrcMsg));
14942
14943    DU_LOG("\nINFO   -->  DU_APP : DL RRC message transfer Recevied");
14944    f1DlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
14945
14946    ret = ROK;
14947
14948    for(idx=0; idx<f1DlRrcMsg->protocolIEs.list.count; idx++)
14949    {
14950       switch(f1DlRrcMsg->protocolIEs.list.array[idx]->id)
14951       {
14952          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14953             {
14954                dlMsg.gnbCuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
14955                break;
14956             }
14957          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14958             {
14959                dlMsg.gnbDuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
14960                break;
14961             }
14962          case ProtocolIE_ID_id_SRBID:
14963             {
14964                dlMsg.srbId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
14965                break;
14966             }
14967          case ProtocolIE_ID_id_ExecuteDuplication:
14968             dlMsg.execDup = true;
14969             break;
14970
14971          case ProtocolIE_ID_id_RRCContainer:
14972             {
14973                if(f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
14974                {
14975                   dlMsg.rrcMsgSize = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
14976                   DU_ALLOC_SHRABL_BUF(dlMsg.rrcMsgPdu, dlMsg.rrcMsgSize);
14977                   if(dlMsg.rrcMsgPdu)
14978                   {
14979                      memcpy(dlMsg.rrcMsgPdu, f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf,\
14980                         dlMsg.rrcMsgSize);
14981                   }
14982                   else
14983                   {
14984                      DU_LOG("\nERROR  -->  DU APP : Memory alloc Failed at RRC Container at procF1DlRrcMsgTrans()");
14985                      return RFAILED;
14986                   }
14987                }
14988                else
14989                {
14990                   DU_LOG("\nERROR  -->  DU_APP : RRC Container Size is invalid:%ld",\
14991                   f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
14992                   return RFAILED;
14993                }
14994                break;
14995             }
14996          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
14997             {
14998                dlMsg.deliveryStatRpt = true;
14999                break;
15000             }
15001          default:
15002             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
15003                   f1DlRrcMsg->protocolIEs.list.array[idx]->id);
15004       }
15005    }
15006
15007    ret = duProcDlRrcMsg(&dlMsg);
15008
15009    freeAperDecodef1DlRrcMsg(f1DlRrcMsg);
15010    return ret;
15011 }
15012 /*******************************************************************
15013  *
15014 * @brief Builds the DRB to be Setup Mod list
15015 *
15016 * @details
15017 *
15018 *    Function : 
15019 *
15020 *    Functionality: Constructs the DRB to be Setup Mod list
15021 *
15022 * @params[in] DRBs_SetupMod_List_t *drbSet
15023 *
15024 * @return ROK     - success
15025 *         RFAILED - failure
15026 *
15027 * ****************************************************************/
15028 uint8_t BuildSrbSetupModList(SRBs_SetupMod_List_t *srbList, DuUeCfg *ueCfg)
15029 {
15030    uint8_t srbIdx = 0;
15031    struct SRBs_SetupMod_ItemIEs *srbItemIe;
15032
15033    srbList->list.count = ueCfg->numRlcLcs;
15034    srbList->list.size = srbList->list.count * sizeof(SRBs_SetupMod_ItemIEs_t *);
15035
15036    DU_ALLOC(srbList->list.array, srbList->list.size);
15037    if(srbList->list.array == NULLP)
15038    {
15039       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15040       return RFAILED;
15041    }
15042
15043    for(srbIdx = 0; srbIdx < srbList->list.count; srbIdx++)
15044    {
15045       DU_ALLOC(srbList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15046       if(srbList->list.array[srbIdx] == NULLP)
15047       {
15048          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15049          return RFAILED;
15050       }
15051    } 
15052
15053    for(srbIdx=0; srbIdx < srbList->list.count; srbIdx++)
15054    {
15055       srbItemIe = (struct SRBs_SetupMod_ItemIEs *)srbList->list.array[srbIdx];
15056       srbItemIe->id = ProtocolIE_ID_id_SRBs_SetupMod_Item;
15057       srbItemIe->criticality = Criticality_reject;
15058       srbItemIe->value.present = SRBs_SetupMod_ItemIEs__value_PR_SRBs_SetupMod_Item;
15059       srbItemIe->value.choice.SRBs_SetupMod_Item.sRBID = ueCfg->rlcLcCfg[srbIdx].rbId;
15060       srbItemIe->value.choice.SRBs_SetupMod_Item.lCID = ueCfg->rlcLcCfg[srbIdx].lcId;
15061    }
15062    return ROK;
15063 }
15064
15065 /*******************************************************************
15066  *
15067 * @brief Builds the DRB to be Setup Mod list
15068 *
15069 * @details
15070 *
15071 *    Function : 
15072 *
15073 *    Functionality: Constructs the DRB to be Setup Mod list
15074 *
15075 * @params[in] DRBs_SetupMod_List_t *drbSet
15076 *
15077 * @return ROK     - success
15078 *         RFAILED - failure
15079 *
15080 * ****************************************************************/
15081
15082 uint8_t BuildDrbSetupModList(DRBs_SetupMod_List_t *drbSet , DuUeCfg *ueCfg)
15083 {
15084    uint8_t arrIdx =0;
15085    uint8_t drbCnt =0;
15086    struct DRBs_SetupMod_ItemIEs *drbItemIe;
15087
15088    drbCnt = ueCfg->numDrbSetupMod;
15089
15090    if(!drbCnt)
15091    {
15092       DU_LOG("\nINFO  -->  F1AP : BuildDrbToBeSetupModList(): No DRB information to avaialble to add");
15093       return ROK;
15094    }
15095
15096    drbSet->list.count = drbCnt;
15097    drbSet->list.size = drbCnt * sizeof(DRBs_SetupMod_ItemIEs_t *);
15098    DU_ALLOC(drbSet->list.array, drbSet->list.size);
15099    if(drbSet->list.array == NULLP)
15100    {
15101       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
15102       return  RFAILED;
15103    }
15104    for(arrIdx=0; arrIdx<drbCnt; arrIdx++)
15105    {
15106       DU_ALLOC(drbSet->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
15107       if(drbSet->list.array[arrIdx] == NULLP)
15108       {
15109               DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
15110               return  RFAILED;
15111       }
15112
15113       drbItemIe = (struct DRBs_SetupMod_ItemIEs *)drbSet->list.array[arrIdx];
15114       drbItemIe->id = ProtocolIE_ID_id_DRBs_SetupMod_Item;
15115       drbItemIe->criticality = Criticality_reject;
15116       drbItemIe->value.present = DRBs_SetupMod_ItemIEs__value_PR_DRBs_SetupMod_Item;
15117       drbItemIe->value.choice.DRBs_SetupMod_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
15118       if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List,\
15119       &ueCfg->upTnlInfo[arrIdx])!= ROK)
15120       {
15121          DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbToBeSetupModList");
15122          return RFAILED;
15123       }
15124       
15125    }
15126
15127    return ROK;
15128 }
15129 /*******************************************************************
15130 * @brief Free the memory allocated for DRB setup List
15131 *
15132 * @details
15133 *
15134 *    Function : FreeDrbSetupModList 
15135 *
15136 *    Functionality:
15137 *       Free the memory allocated for DRB setup list
15138 *
15139 * @params[in] DRBs_Setup_List_t *
15140 * @return void
15141 *
15142 * ****************************************************************/
15143 void FreeDrbSetupModList(DRBs_SetupMod_List_t *drbSetupList)
15144 {
15145    uint8_t arrIdx = 0;
15146    DRBs_SetupMod_ItemIEs_t *drbItemIe = NULLP;
15147
15148    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
15149    {
15150       drbItemIe = ((DRBs_SetupMod_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
15151       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List);
15152       DU_FREE(drbSetupList->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
15153    }
15154    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
15155 }
15156
15157 /*******************************************************************
15158 * @brief Free the memory allocated for SRB setup List
15159 *
15160 * @details
15161 *
15162 *    Function : FreeSrbSetupModList 
15163 *
15164 *    Functionality:
15165 *       Free the memory allocated for SRB setup list
15166 *
15167 * @params[in] SRBs_Setup_List_t *
15168 * @return void
15169 *
15170 * ****************************************************************/
15171 void FreeSrbSetupModList(SRBs_SetupMod_List_t *srbSetupList)
15172 {
15173    uint8_t srbIdx = 0;
15174    
15175    for(srbIdx = 0; srbIdx < srbSetupList->list.count; srbIdx++)
15176       DU_FREE(srbSetupList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15177    DU_FREE(srbSetupList->list.array, srbSetupList->list.size);
15178 }
15179
15180 /*******************************************************************
15181 * @brief Free the memory allocated for UE Context Mod Response
15182 *
15183 * @details
15184 *
15185 *    Function : FreeUeContextModResp 
15186 *
15187 *    Functionality:
15188 *       Free the memory allocated for UE Context Mod Response
15189 *
15190 * @params[in] F1AP_PDU_t *f1apMsg
15191 * @return void
15192 *
15193 * ****************************************************************/
15194
15195 void FreeUeContextModResp(F1AP_PDU_t *f1apMsg)
15196 {
15197    uint8_t ieIdx;
15198    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
15199    if(f1apMsg)
15200    {
15201       if(f1apMsg->choice.successfulOutcome)
15202       {
15203          ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
15204          if(ueContextModifyRes->protocolIEs.list.array)
15205          {
15206             for(ieIdx=0 ; ieIdx<ueContextModifyRes->protocolIEs.list.count; ieIdx++)
15207             {
15208                if(ueContextModifyRes->protocolIEs.list.array[ieIdx])
15209                {
15210                   switch(ueContextModifyRes->protocolIEs.list.array[ieIdx]->id)
15211                   {
15212                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15213                         break;
15214                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15215                         break;
15216                      case ProtocolIE_ID_id_DRBs_SetupMod_List:
15217                         {
15218                             FreeDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
15219                             value.choice.DRBs_SetupMod_List));
15220                             break;
15221                         }
15222                      case ProtocolIE_ID_id_SRBs_SetupMod_List:
15223                         {
15224                            FreeSrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
15225                               SRBs_SetupMod_List));
15226                            break; 
15227                         }
15228                   }
15229                   DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
15230                }
15231
15232             }
15233             DU_FREE(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
15234          }
15235          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
15236       }
15237       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
15238    }
15239 }
15240
15241 /*****************************************************************i
15242 *
15243 * @brief Creating the ue context modifcation response and sending
15244 *
15245 * @details
15246 *
15247 *    Function : BuildAndSendUeContextModRsp 
15248 *
15249 *    Functionality:
15250 *         - Creating the ue context modifcation response 
15251 *
15252 * @params[in] uint8_t cellId,uint8_t ueId
15253 * @return ROK     - success
15254 *         RFAILED - failure
15255 *
15256 * ****************************************************************/
15257 uint8_t BuildAndSendUeContextModRsp(DuUeCb *ueCb)
15258 {
15259    uint8_t   ieIdx = 0, tnlIdx = 0, rbIdx = 0;
15260    uint8_t   elementCnt = 0;
15261    uint8_t   ret = RFAILED;
15262    F1AP_PDU_t *f1apMsg = NULLP;
15263    asn_enc_rval_t  encRetVal;
15264    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
15265
15266    DU_LOG("\nINFO  -->  F1AP : Building UE context modification response\n");
15267
15268    while(1)
15269    {
15270       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15271       if(f1apMsg == NULLP)
15272       {
15273          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
15274          break;
15275       }
15276
15277       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
15278
15279       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
15280       if(f1apMsg->choice.successfulOutcome == NULLP)
15281       {
15282          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
15283          break;
15284       }
15285       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextModification;
15286       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
15287       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_UEContextModificationResponse;
15288
15289       ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
15290   
15291       if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
15292       {
15293          if(ueCb->f1UeDb->duUeCfg.numDrbSetupMod)
15294             elementCnt =3;
15295          else
15296             elementCnt =2;
15297       }
15298       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15299          elementCnt = 5;
15300       if(ueCb->f1UeDb->actionType == UE_CTXT_RRC_RECFG_COMPLETE)
15301          elementCnt = 2;
15302       ueContextModifyRes->protocolIEs.list.count = elementCnt;
15303       ueContextModifyRes->protocolIEs.list.size = elementCnt*sizeof(UEContextModificationResponse_t*);
15304
15305       /* Initialize the UE context modification members */
15306       DU_ALLOC(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
15307       if(ueContextModifyRes->protocolIEs.list.array == NULLP)
15308       {
15309          DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
15310          break;
15311       }
15312
15313       for(ieIdx=0 ; ieIdx<elementCnt; ieIdx++)
15314       {
15315          DU_ALLOC(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
15316          if(ueContextModifyRes->protocolIEs.list.array[ieIdx] == NULLP)
15317          {
15318             DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
15319             break;
15320          }
15321       }
15322
15323       ieIdx=0;
15324       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_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_CU_UE_F1AP_ID;
15328       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
15329
15330       ieIdx++;
15331       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
15332       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15333       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present=\
15334       UEContextModificationResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
15335       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
15336
15337       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15338       {
15339          ieIdx++;
15340          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCInformation;
15341          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15342          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
15343          UEContextModificationResponseIEs__value_PR_DUtoCURRCInformation;
15344          BuildCellGroupConfigRrc(ueCb, &ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
15345       }
15346
15347       if((ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY) || ((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbSetupMod)))
15348       { 
15349          ieIdx++;
15350          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_SetupMod_List;
15351          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15352          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
15353                                                                            UEContextModificationResponseIEs__value_PR_DRBs_SetupMod_List;
15354          if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15355          {
15356             for(tnlIdx = 0; tnlIdx < duCb.numTeId; tnlIdx++)
15357             {
15358                if(duCb.upTnlCfg[tnlIdx]->ueId == ueCb->gnbDuUeF1apId)
15359                {
15360                   memcpy(&ueCb->f1UeDb->duUeCfg.upTnlInfo[ueCb->f1UeDb->duUeCfg.numDrbSetupMod++], duCb.upTnlCfg[tnlIdx], sizeof(UpTnlCfg));
15361                }
15362             }
15363          }
15364          ret = BuildDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
15365                   value.choice.DRBs_SetupMod_List) , &ueCb->f1UeDb->duUeCfg);
15366          if(ret != ROK)
15367          {
15368             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB setupmod List ");
15369             break;
15370          }
15371       }
15372
15373       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15374       {
15375          ieIdx++;
15376          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_SRBs_SetupMod_List;
15377          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15378          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
15379                                                                             UEContextModificationResponseIEs__value_PR_SRBs_SetupMod_List;
15380          for(rbIdx = 0; rbIdx < ueCb->rlcUeCfg.numLcs; rbIdx++)
15381          {
15382             if(ueCb->rlcUeCfg.rlcLcCfg[rbIdx].rbType == RB_TYPE_SRB)
15383             {
15384                memcpy(&ueCb->f1UeDb->duUeCfg.rlcLcCfg[ueCb->f1UeDb->duUeCfg.numRlcLcs++], &ueCb->rlcUeCfg.rlcLcCfg[rbIdx],\
15385                      sizeof(RlcBearerCfg));
15386             }
15387          }
15388          ret = BuildSrbSetupModList(&ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.SRBs_SetupMod_List, \
15389                &ueCb->f1UeDb->duUeCfg);
15390          if(ret != ROK)
15391          {
15392             DU_LOG( "\nERROR  -->  F1AP : Failed to build SRB setupmod List ");
15393             break;
15394          }
15395       }
15396
15397       freeF1UeDb(ueCb->f1UeDb);
15398       ueCb->f1UeDb = NULLP;
15399
15400       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15401
15402       /* Encode the F1SetupRequest type as APER */
15403       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15404       encBufSize = 0;
15405       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,encBuf);
15406
15407       /* Encode results */
15408       if(encRetVal.encoded == ENCODE_FAIL)
15409       {
15410          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Request structure (at %s)\n",\
15411                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15412          ret = RFAILED;
15413          break;
15414       }
15415       else
15416       {
15417          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Modification Response\n");
15418          for(int i=0; i< encBufSize; i++)
15419          {
15420             printf("%x",encBuf[i]);
15421          }
15422       }
15423
15424       /* Sending  msg  */
15425       if(sendF1APMsg() != ROK)
15426       {
15427          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Res Failed");
15428          ret = RFAILED;
15429          break;
15430       }
15431
15432       ret = ROK;
15433       break;
15434    }
15435    FreeUeContextModResp(f1apMsg);
15436    return ret;
15437 }
15438 /*******************************************************************
15439  *
15440  * @brief Deallocating the memory allocated by the aper decoder
15441  *          for QOSInfo
15442  *
15443  * @details
15444  *
15445  *    Function : freeAperDecodeQosInfo
15446  *
15447  *    Functionality:  Deallocating the memory allocated for QOSInfo
15448  *
15449  * @params[in] QoSFlowLevelQoSParameters_t *drbQos
15450  *
15451  * @return void
15452  *
15453  * ****************************************************************/
15454
15455 void freeAperDecodeQosInfo(QoSFlowLevelQoSParameters_t *drbQos)
15456 {
15457    if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI != NULLP)
15458    {
15459       if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
15460       {
15461          if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
15462          {
15463             free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
15464          }
15465          free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
15466       }
15467       free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI);
15468    }
15469 }
15470 /*******************************************************************
15471  *
15472  * @brief Deallocating the memory allocated by the aper decoder
15473  *          for UlTnlInfoforDrb
15474  *
15475  * @details
15476  *
15477  *    Function : freeAperDecodeUlTnlInfoforDrbSetupMod 
15478  *
15479  *    Functionality:  Deallocating memory allocated for UlTnlInfoforDrb
15480  *
15481  * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
15482  *
15483  * @return void
15484  *
15485  * ****************************************************************/
15486 void freeAperDecodeUlTnlInfoforDrbSetupMod(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
15487 {
15488    uint8_t arrIdx =0;
15489
15490    if(ulInfo->list.array)
15491    {
15492       for(arrIdx=0; arrIdx<ulInfo->list.count ; arrIdx++)
15493       {
15494          if(ulInfo->list.array[arrIdx])
15495          {
15496             if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel )
15497             {
15498                if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf)
15499                {
15500                   if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf)
15501                   {
15502                      free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
15503                            gTP_TEID.buf);
15504                   }
15505                   free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
15506                         transportLayerAddress.buf);
15507                }
15508                free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel);
15509             }
15510             free(ulInfo->list.array[arrIdx]);
15511          }
15512       }
15513       free(ulInfo->list.array);
15514    }
15515 }
15516 /*******************************************************************
15517  *
15518  * @brief Deallocating the memory allocated by the aper decoder
15519  *          for DrbSetupModItem  
15520  *
15521  * @details
15522  *
15523  *    Function : freeAperDecodeDrbSetupModItem 
15524  *
15525  *    Functionality:  Deallocating memory allocated for DrbSetupModItem
15526  *
15527  * @params[in] DRBs_ToBeSetupMod_Item_t *drbItem
15528  *
15529  * @return void
15530  *
15531  * ****************************************************************/
15532
15533 void freeAperDecodeDrbSetupModItem(DRBs_ToBeSetupMod_Item_t *drbItem)
15534 {
15535    uint8_t arrIdx =0;
15536    SNSSAI_t *snssai =NULLP;
15537    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
15538
15539    drbItem->qoSInformation.present = QoSInformation_PR_choice_extension;
15540    switch(drbItem->qoSInformation.present)
15541    {
15542       case QoSInformation_PR_NOTHING:
15543          break;
15544       case QoSInformation_PR_eUTRANQoS:
15545          {
15546             if(drbItem->qoSInformation.choice.eUTRANQoS)
15547             {
15548                free(drbItem->qoSInformation.choice.eUTRANQoS);
15549             }
15550             break;
15551          }
15552       case QoSInformation_PR_choice_extension:
15553          {
15554             if(drbItem->qoSInformation.choice.choice_extension)
15555             {
15556                freeAperDecodeQosInfo(&drbItem->qoSInformation.choice.choice_extension->value.choice.\
15557                      DRB_Information.dRB_QoS);
15558                snssai = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI;
15559                if(snssai->sST.buf)
15560                {
15561                   free(snssai->sST.buf);
15562                }
15563                if(snssai->sD)
15564                {
15565                   if(snssai->sD->buf)
15566                   {
15567                      free(snssai->sD->buf);
15568                   }
15569                   free(snssai->sD);
15570                }
15571
15572                flowMap = &drbItem->qoSInformation.choice.choice_extension->value.choice.\
15573                          DRB_Information.flows_Mapped_To_DRB_List;
15574                if(flowMap->list.array)
15575                {
15576                   for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
15577                   {
15578                      if(flowMap->list.array[arrIdx] )
15579                      {
15580                         freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
15581                         free(flowMap->list.array[arrIdx]);
15582                      }
15583                   }
15584                   free(flowMap->list.array);
15585                }
15586
15587                free(drbItem->qoSInformation.choice.choice_extension);
15588             }
15589             break;
15590          }
15591
15592    }
15593    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
15594    if(drbItem->uLConfiguration)
15595    {
15596       free(drbItem->uLConfiguration);
15597    }
15598 }
15599
15600 /*******************************************************************
15601  *
15602  * @brief Deallocating the memory allocated by the aper decoder
15603  *          for DrbToBeSetupModList
15604  *
15605  * @details
15606  *
15607  *    Function : freeAperDecodeDrbToBeSetupModList
15608  *
15609  *    Functionality:  Deallocating memory allocated for DrbToBeSetupModList
15610  *
15611  * @params[in] DRBs_ToBeSetupMod_List_t *drbSet
15612  *
15613  * @return void
15614  *
15615  * ****************************************************************/
15616
15617 void freeAperDecodeDrbToBeSetupModList(DRBs_ToBeSetupMod_List_t *drbSet)
15618 {
15619    uint8_t arrIdx =0;
15620    struct DRBs_ToBeSetupMod_ItemIEs *drbItemIe;
15621
15622    if(drbSet->list.array)
15623    {
15624       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
15625       {
15626          if(drbSet->list.array[arrIdx] != NULLP)
15627          {
15628             if(arrIdx == 0)
15629             {
15630                drbItemIe = (DRBs_ToBeSetupMod_ItemIEs_t *)drbSet->list.array[arrIdx];
15631                freeAperDecodeDrbSetupModItem(&(drbItemIe->value.choice.DRBs_ToBeSetupMod_Item));
15632             }
15633             free(drbSet->list.array[arrIdx]);
15634          }
15635       }
15636       free(drbSet->list.array);
15637    }
15638
15639 }
15640 /*******************************************************************
15641  *
15642  * @brief Deallocating the memory allocated by the aper decoder
15643  *          for UeContextModificationReqMsg
15644  *
15645  * @details
15646  *
15647  *    Function : freeAperDecodeUeContextModificationReqMsg
15648  *
15649  *    Functionality:  Deallocating memory allocated for
15650  *                  UeContextModificationReqMsg
15651  *
15652  * @params[in] UEContextModificationRequest_t *UeContextModifyReq
15653  *
15654  * @return void
15655  *
15656  * ****************************************************************/
15657 void freeAperDecodeUeContextModificationReqMsg(UEContextModificationRequest_t *ueContextModifyReq )
15658 {
15659    uint8_t arrIdx, ieId;
15660
15661    if(ueContextModifyReq->protocolIEs.list.array)
15662    {
15663       for( arrIdx = 0 ; arrIdx<ueContextModifyReq->protocolIEs.list.count ; arrIdx++)
15664       {
15665          if(ueContextModifyReq->protocolIEs.list.array[arrIdx])
15666          {
15667             ieId = ueContextModifyReq->protocolIEs.list.array[arrIdx]->id;
15668             switch(ieId)
15669             {
15670                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15671                   break;
15672                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15673                   break;
15674                case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
15675                   {
15676                      freeAperDecodeDrbToBeSetupModList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
15677                            value.choice.DRBs_ToBeSetupMod_List);
15678                      break;
15679                   }
15680                case ProtocolIE_ID_id_TransmissionActionIndicator:
15681                   break;
15682                case ProtocolIE_ID_id_RRCContainer:
15683                   {
15684                      free(ueContextModifyReq->protocolIEs.list.array[arrIdx]->value.choice.RRCContainer.buf);
15685                   }
15686             }
15687             free(ueContextModifyReq->protocolIEs.list.array[arrIdx]);
15688          }
15689       }
15690       free(ueContextModifyReq->protocolIEs.list.array);
15691    }
15692 }
15693 /*******************************************************************
15694  *
15695  * @brief processing the F1 UeContextModificationReq
15696  *
15697  * @details
15698  *
15699  *    Function : procF1UeContextModificationReq
15700  *
15701  *    Functionality:  processing the F1 UeContextModificationReq
15702  *
15703  * @params[in] F1AP_PDU_t *f1apMsg
15704  *
15705  * @return
15706  * ****************************************************************/
15707 uint8_t procF1UeContextModificationReq(F1AP_PDU_t *f1apMsg)
15708 {
15709    UEContextModificationRequest_t *ueContextModifyReq = NULLP;
15710    uint8_t  ret = ROK, ieIdx = 0, cellIdx=0;
15711    DuUeCb   *duUeCb = NULLP;
15712    DRBs_ToBeSetupMod_List_t *drbSetupModCfg;
15713    DRBs_ToBeModified_List_t *drbModifiedCfg;
15714    uint32_t gnbCuUeF1apId, gnbDuUeF1apId;
15715
15716    ueContextModifyReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextModificationRequest;
15717    for(ieIdx=0; (ieIdx < ueContextModifyReq->protocolIEs.list.count && ret == ROK); ieIdx++)
15718    {
15719       switch(ueContextModifyReq->protocolIEs.list.array[ieIdx]->id)
15720       {
15721          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15722             {
15723                gnbCuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
15724                break;
15725             }
15726          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15727             {
15728                gnbDuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
15729                for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
15730                {
15731                   if(duCb.actvCellLst[cellIdx])
15732                   {
15733                      if((duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbDuUeF1apId == gnbDuUeF1apId)&&\
15734                            (duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbCuUeF1apId == gnbCuUeF1apId))
15735                      {
15736                         duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1];
15737                         if(duUeCb->f1UeDb == NULLP)
15738                         {
15739                            DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
15740                            duUeCb->f1UeDb->cellIdx = cellIdx;
15741                            duUeCb->f1UeDb->actionType = UE_CTXT_MOD;
15742                         }
15743                         break;
15744                      }
15745                   }
15746                }
15747                if(duUeCb == NULLP)
15748                {
15749                   DU_LOG("\nERROR  -->  DU APP : wrong values of gnbCuUeF1apId and gnbDuUeF1apId ");
15750                   ret = RFAILED;
15751                }
15752                break;
15753             }
15754
15755          case ProtocolIE_ID_id_RRCContainer:
15756             {
15757                /* Filling Dl RRC Msg Info */
15758                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
15759                if(!duUeCb->f1UeDb->dlRrcMsg)
15760                {
15761                   DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
15762                         Memory allocation failed ");
15763                   ret = RFAILED;
15764                }
15765                else
15766                {
15767                   duUeCb->f1UeDb->dlRrcMsgPres = true;
15768                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
15769                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
15770                         &ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
15771                         value.choice.RRCContainer);
15772                }
15773
15774                break;
15775             }
15776
15777          case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
15778          case ProtocolIE_ID_id_DRBs_ToBeModified_List:
15779             {
15780                if(duUeCb->f1UeDb)
15781                {
15782                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present ==\
15783                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List)
15784                   {
15785                      drbSetupModCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
15786                                       choice.DRBs_ToBeSetupMod_List;
15787
15788                      if(extractDrbListToSetupMod(NULL, drbSetupModCfg, NULL, drbSetupModCfg->list.count,\
15789                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULL))
15790                      {
15791                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbSetupModList");
15792                         ret = RFAILED;
15793                      }
15794                   }
15795
15796                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
15797                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List)
15798
15799                   {
15800                      drbModifiedCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
15801                                       choice.DRBs_ToBeModified_List;
15802                      if(extractDrbListToSetupMod(NULL, NULL, drbModifiedCfg, drbModifiedCfg->list.count,\
15803                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, &duUeCb->rlcUeCfg))
15804                      {
15805                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
15806                         ret = RFAILED;
15807                      }
15808                   }
15809                }
15810                break;
15811             }
15812
15813          case ProtocolIE_ID_id_GNB_DUConfigurationQuery:
15814             {
15815                DU_LOG("\nINFO  -->  DU APP : Received GNB DU Configuration Query in UE Context Modification Request from CU");
15816                if(duUeCb->f1UeDb)
15817                {
15818                   duUeCb->f1UeDb->actionType = UE_CTXT_CFG_QUERY;
15819                }
15820                break;
15821             }
15822
15823          case ProtocolIE_ID_id_RRCReconfigurationCompleteIndicator:
15824             {
15825                if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.RRCReconfigurationCompleteIndicator == \
15826                   RRCReconfigurationCompleteIndicator_true)
15827                {
15828                   duUeCb->f1UeDb->actionType = UE_CTXT_RRC_RECFG_COMPLETE;
15829                }
15830                break;
15831             }
15832          case ProtocolIE_ID_id_TransmissionActionIndicator:
15833             {
15834                if(duUeCb->f1UeDb)
15835                {
15836                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.TransmissionActionIndicator  == TransmissionActionIndicator_stop)
15837                   {
15838                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = STOP_TRANSMISSION; 
15839                   }
15840                   else 
15841                   {
15842                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = RESTART_TRANSMISSION; 
15843                   }
15844                }
15845                break;
15846             }
15847
15848          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15849             {
15850                if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
15851                {
15852                   duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
15853                }
15854                break;
15855             }
15856               
15857       }
15858    }
15859
15860    if(ret != RFAILED) 
15861    {
15862       ret = duProcUeContextModReq(duUeCb);
15863    }
15864    freeAperDecodeUeContextModificationReqMsg(ueContextModifyReq);
15865    return ret; 
15866 }
15867
15868 /*****************************************************************i
15869 *
15870 * @brief Free memory allocated for UE Context Release Request
15871 *
15872 * @details
15873 *
15874 *    Function : FreeUeContextReleaseReq
15875 *
15876 *    Functionality:
15877 *         - Free memory allocated for UE Context Release Request
15878 *
15879 * @params[in] F1AP_PDU_t *f1apMsg
15880 * @return void 
15881 *
15882 * *************************************************************/
15883 void FreeUeContextReleaseReq(F1AP_PDU_t *f1apMsg)
15884 {
15885    uint8_t ieIdx;
15886    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
15887    
15888    if(f1apMsg)
15889    {
15890       if(f1apMsg->choice.initiatingMessage)
15891       {
15892          ueReleaseReq =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
15893          if(ueReleaseReq->protocolIEs.list.array)
15894          {
15895             for(ieIdx=0 ; ieIdx<ueReleaseReq->protocolIEs.list.count; ieIdx++)
15896             {
15897                DU_FREE(ueReleaseReq->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseRequest_t));
15898             }
15899             DU_FREE(ueReleaseReq->protocolIEs.list.array, ueReleaseReq->protocolIEs.list.size);
15900          }
15901          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
15902       }
15903       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
15904    }
15905
15906 }
15907 /*****************************************************************i
15908 *
15909 * @brief Build and Send UE Context Release Request  
15910 *
15911 * @details
15912 *
15913 *    Function : BuildAndSendUeContextReleaseReq
15914 *
15915 *    Functionality:
15916 *         - Build and Send UE Context Release Request 
15917 *
15918 * @params[in]
15919 * @return ROK     - success
15920 *         RFAILED - failure
15921 *
15922 * *************************************************************/
15923 uint8_t BuildAndSendUeContextReleaseReq(uint16_t cellId, uint8_t ueId)
15924 {
15925    bool memAllocFail = false;
15926    uint8_t ieIdx =0;
15927    uint8_t ret = RFAILED;
15928    uint16_t cellIdx =0;
15929    uint16_t crnti = 0;
15930    uint8_t  elementCnt = 0;
15931    uint32_t  gnbCuUeF1apId =0;   /* gNB-CU UE F1AP Id */
15932    uint32_t  gnbDuUeF1apId =0;   /* gNB-DU UE F1AP Id */
15933    asn_enc_rval_t encRetVal; 
15934    F1AP_PDU_t *f1apMsg = NULLP;
15935    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
15936
15937    DU_LOG("\nINFO  --> Building the UE Context Release Request");
15938    do
15939    {
15940       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15941       if(f1apMsg == NULLP)
15942       {
15943          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for f1apMsg");
15944          break;
15945       }
15946
15947       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
15948       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
15949       if(f1apMsg->choice.initiatingMessage == NULLP)
15950       {
15951          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for\
15952          initiatingMessage");   
15953          break;
15954       }
15955       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_UEContextReleaseRequest;
15956       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
15957       f1apMsg->choice.initiatingMessage->value.present = \
15958       InitiatingMessage__value_PR_UEContextReleaseRequest;
15959
15960       ueReleaseReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
15961
15962       elementCnt = 2;
15963
15964       ueReleaseReq->protocolIEs.list.count = elementCnt;
15965       ueReleaseReq->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseRequest_t *);
15966
15967       /* Initialize the F1Setup members */
15968       DU_ALLOC(ueReleaseReq->protocolIEs.list.array,ueReleaseReq->protocolIEs.list.size);
15969       if(ueReleaseReq->protocolIEs.list.array == NULLP)
15970       {
15971          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE array");
15972          break;
15973       }
15974       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
15975       {
15976          DU_ALLOC(ueReleaseReq->protocolIEs.list.array[ieIdx],\
15977                sizeof(UEContextReleaseRequest_t));
15978          if(ueReleaseReq->protocolIEs.list.array[ieIdx] == NULLP)
15979          {
15980             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE elements");
15981             memAllocFail = true;  
15982             break;
15983          }
15984       }
15985       if(memAllocFail == true)
15986          break;
15987
15988       /* Fetching Ue Cb Info*/
15989       GET_CELL_IDX(cellId, cellIdx);
15990       if(duCb.actvCellLst[cellIdx] == NULLP)
15991       {
15992          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): CellId[%d] does not exist", cellId);
15993          break;
15994       }
15995       else
15996       {
15997          GET_CRNTI(crnti, ueId);
15998          if(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].crnti != crnti)
15999          {
16000             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): crnti[%d] does not exist", crnti);
16001             break;
16002          }
16003          gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
16004          gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
16005       }
16006
16007       ieIdx=0; 
16008       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_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_CU_UE_F1AP_ID;
16012       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
16013       
16014       ieIdx++;
16015       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16016       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16017       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present =\
16018       UEContextReleaseRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
16019       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
16020       
16021       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16022
16023       /* Encode the F1SetupRequest type as APER */
16024       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16025       encBufSize = 0;
16026       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
16027       /* Encode results */
16028       if(encRetVal.encoded == ENCODE_FAIL)
16029       {
16030          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseRequest structure (at %s)\n",\
16031                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16032          break;
16033       }
16034       else
16035       {
16036          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseRequest\n");
16037          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
16038          {
16039             printf("%x",encBuf[ieIdx]);
16040          }
16041       }
16042
16043       /* Sending msg */
16044       if(sendF1APMsg() != ROK)
16045       {
16046          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Request failed");
16047          break;
16048       }
16049       ret = ROK;
16050       break;
16051    }while(true);
16052
16053    FreeUeContextReleaseReq(f1apMsg);
16054    return ret;
16055 }
16056 /*****************************************************************i
16057  *
16058  * @brief Free memory allocated for UE Context Release Complete
16059  *
16060  * @details
16061  *
16062  *    Function : FreeUeContextReleaseComplete
16063  *
16064  *    Functionality:
16065  *         - Free memory allocated for UE Context Release Complete
16066  *
16067  * @params[in] F1AP_PDU_t *f1apMsg
16068  * @return void
16069  *
16070  * *************************************************************/
16071 void FreeUeContextReleaseComplete(F1AP_PDU_t *f1apMsg)
16072 {
16073    uint8_t ieIdx;
16074    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
16075
16076    if(f1apMsg)
16077    {
16078       if(f1apMsg->choice.successfulOutcome)
16079       {
16080          ueReleaseComplete =&f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
16081          if(ueReleaseComplete->protocolIEs.list.array)
16082          {
16083             for(ieIdx=0 ; ieIdx<ueReleaseComplete->protocolIEs.list.count; ieIdx++)
16084             {
16085                DU_FREE(ueReleaseComplete->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseComplete_t));
16086             }
16087             DU_FREE(ueReleaseComplete->protocolIEs.list.array, ueReleaseComplete->protocolIEs.list.size);
16088          }
16089          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16090       }
16091       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
16092    }
16093
16094 }
16095 /*****************************************************************i
16096  *
16097  * @brief Build and Send UE Context Release Complete
16098  *
16099  * @details
16100  *
16101  *    Function : BuildAndSendUeContextReleaseComplete
16102  *
16103  *    Functionality:
16104  *         - Build and Send UE Context Release Complete
16105  *
16106  * @params[in]  cellId,  gnbCuUeF1apId, gnbDuUeF1apId
16107  * @return ROK     - success
16108  *         RFAILED - failure
16109  *
16110  * *************************************************************/
16111 uint8_t BuildAndSendUeContextReleaseComplete(uint16_t cellId, uint32_t gnbCuUeF1apId, uint32_t gnbDuUeF1apId)
16112 {
16113    bool memAllocFail = false;
16114    uint8_t ieIdx =0, ret = RFAILED, elementCnt = 0;
16115    asn_enc_rval_t encRetVal;
16116    F1AP_PDU_t *f1apMsg = NULLP;
16117    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
16118
16119    DU_LOG("\nINFO  --> Building the UE Context Release Complete");
16120    do
16121    {
16122       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
16123       if(f1apMsg == NULLP)
16124       {
16125          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for f1apMsg");
16126          break;
16127       }
16128
16129       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
16130       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16131       if(f1apMsg->choice.successfulOutcome == NULLP)
16132       {
16133          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for\
16134                successfulOutcome");
16135          break;
16136       }
16137       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextRelease;
16138       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
16139       f1apMsg->choice.successfulOutcome->value.present = \
16140       SuccessfulOutcome__value_PR_UEContextReleaseComplete;
16141
16142       ueReleaseComplete = &f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
16143
16144       elementCnt = 2;
16145       ueReleaseComplete->protocolIEs.list.count = elementCnt;
16146       ueReleaseComplete->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseComplete_t *);
16147
16148       /* Initialize the UE Release Complete members */
16149       DU_ALLOC(ueReleaseComplete->protocolIEs.list.array,ueReleaseComplete->protocolIEs.list.size);
16150       if(ueReleaseComplete->protocolIEs.list.array == NULLP)
16151       {
16152          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE array");
16153          break;
16154       }
16155       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
16156       {
16157          DU_ALLOC(ueReleaseComplete->protocolIEs.list.array[ieIdx],\
16158                sizeof(UEContextReleaseComplete_t));
16159          if(ueReleaseComplete->protocolIEs.list.array[ieIdx] == NULLP)
16160          {
16161             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE\
16162             elements");
16163             memAllocFail = true;
16164             break;
16165          }
16166       }
16167       if(memAllocFail == true)
16168          break;
16169
16170
16171       ieIdx=0;
16172       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_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_CU_UE_F1AP_ID;
16176       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
16177
16178       ieIdx++;
16179       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16180       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16181       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present =\
16182       UEContextReleaseCompleteIEs__value_PR_GNB_DU_UE_F1AP_ID;
16183       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
16184
16185       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16186
16187       /* Encode the F1SetupComplete type as APER */
16188       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16189       encBufSize = 0;
16190       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
16191       /* Encode results */
16192       if(encRetVal.encoded == ENCODE_FAIL)
16193       {
16194          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseComplete structure (at %s)\n",\
16195                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16196          break;
16197       }
16198       else
16199       {
16200          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseComplete\n");
16201          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
16202          {
16203             printf("%x",encBuf[ieIdx]);
16204          }
16205       }
16206
16207       /* Sending msg */
16208       if(sendF1APMsg() != ROK)
16209       {
16210          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Complete failed");
16211          break;
16212       }
16213       ret = ROK;
16214       break;
16215    }while(true);
16216    
16217    if((ret == ROK) && (duCb.actvCellLst[cellId-1]) && (duCb.actvCellLst[cellId-1]->cellStatus == DELETION_IN_PROGRESS) 
16218          && (duCb.actvCellLst[cellId-1]->numActvUes == 0))
16219    {
16220       ret = duSendCellDeletReq(cellId);
16221       if(ret != ROK)
16222       {
16223          DU_LOG("\nERROR  -->  F1AP: BuildAndSendUeContextReleaseComplete(): Failed to process cell\
16224                Delete req for CellId");
16225       }
16226    }
16227    FreeUeContextReleaseComplete(f1apMsg);
16228    return ret;
16229
16230 }
16231
16232 /*******************************************************************
16233 *
16234 * @brief added free part for the memory allocated by aper_decoder 
16235 *
16236 * @details
16237 *
16238 *    Function : freeAperDecodeUeContextReleaseCommand 
16239 *
16240 *    Functionality: added free part for the memory allocated by aper_decoder
16241 *
16242 * @params[in] F1AP_PDU_t *f1apMsg
16243 * @return void
16244 *
16245 * ****************************************************************/
16246 void freeAperDecodeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
16247 {
16248    uint8_t ieIdx=0;
16249    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
16250
16251    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
16252    
16253    if(ueContextReleaseCommand->protocolIEs.list.array)
16254    {
16255       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
16256       {
16257          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
16258          {
16259             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
16260             {
16261                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16262                   break;
16263                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16264                   break;
16265                case ProtocolIE_ID_id_Cause:
16266                   break;
16267                case ProtocolIE_ID_id_RRCContainer:
16268                {
16269                   if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
16270                   {
16271                      free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
16272                   }
16273                   break;
16274                }
16275                default :
16276                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
16277                        ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
16278                   break;
16279             }
16280          }
16281          free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]);
16282       }
16283       free(ueContextReleaseCommand->protocolIEs.list.array);
16284    }
16285 }
16286 /*******************************************************************
16287 *
16288 * @brief processing of UE Context Release Command
16289 *
16290 * @details
16291 *
16292 *    Function : procF1UeContextReleaseCommand 
16293 *
16294 *    Functionality: processing of UE Context Release Command
16295 *
16296 * @params[in] F1AP_PDU_t *f1apMsg
16297 * @return void
16298 *
16299 * ****************************************************************/
16300 uint8_t procF1UeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
16301 {
16302    uint8_t  ieIdx=0, ret=ROK, ueIdx=0;
16303    uint16_t cellIdx =0, cellId = 0;
16304    bool ueIdxFound = false;
16305    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0;
16306    DuUeCb   *duUeCb = NULLP;
16307    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
16308
16309    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
16310
16311    if(ueContextReleaseCommand->protocolIEs.list.array)
16312    {
16313       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
16314       {
16315          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
16316          {
16317             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
16318             {
16319                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16320                   {
16321                      gnbCuUeF1apId= ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
16322                                     value.choice.GNB_CU_UE_F1AP_ID;
16323                      break;
16324                   }
16325
16326                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16327                   {
16328                      gnbDuUeF1apId = ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
16329                                      value.choice.GNB_DU_UE_F1AP_ID;
16330                      break;
16331                   }
16332
16333                case ProtocolIE_ID_id_Cause:
16334                   {
16335                      for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
16336                      {
16337                         for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
16338                         {
16339                            if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
16340                                  (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId))
16341                            {
16342                               cellId = duCb.actvCellLst[cellIdx]->cellId;
16343                               duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
16344                               ueIdxFound = true;
16345                               break;
16346                            }
16347                         }
16348                         if(ueIdxFound == true)
16349                         {
16350                            break;
16351                         }
16352                      }
16353                      
16354                      if(!ueIdxFound)
16355                      {
16356                         DU_LOG("\nERROR  -->  F1AP: procF1UeContextReleaseCommand(): Ue Information is not available");
16357                         ret = RFAILED;
16358                      }
16359                      break;
16360                   }
16361
16362                case ProtocolIE_ID_id_RRCContainer:
16363                   {
16364                      if(ueIdxFound == true)  
16365                      {
16366                         DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
16367                         if(duUeCb->f1UeDb)
16368                         {
16369                            memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
16370                            duUeCb->f1UeDb->actionType = UE_CTXT_RELEASE;
16371                            duUeCb->f1UeDb->cellIdx = cellIdx;
16372                            /* Filling Dl RRC Msg Info */
16373                            DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
16374                            if(!duUeCb->f1UeDb->dlRrcMsg)
16375                            {
16376                               DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16377                                     Memory allocation failed ");
16378                               ret = RFAILED;
16379                            }
16380                            else
16381                            {
16382                               duUeCb->f1UeDb->dlRrcMsgPres = true;
16383                               memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
16384                               ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
16385                                     &ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
16386                                     value.choice.RRCContainer);
16387                            }
16388
16389                         }
16390                         else
16391                         {
16392                            DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16393                                  Memory allocation failed ");
16394                            ret = RFAILED;
16395
16396                         }
16397                      }
16398                      break;
16399                   }
16400                default :
16401                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
16402                         ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
16403                   break;
16404             }
16405          }
16406       }
16407    }
16408    if(ret != RFAILED)
16409    {
16410       duProcUeContextReleaseCommand(cellId, duUeCb);
16411    }
16412    freeAperDecodeUeContextReleaseCommand(f1apMsg);
16413    return ret;
16414 }
16415
16416 /**************************************************************
16417  *
16418  * @brief free the memory allocated by aper decoder for paging
16419  *
16420  * @details
16421  *
16422  *    Function : freeAperDecodePagingMsg
16423  *
16424  *    Functionality:
16425  *         - free the memory allocated by aper decoder for
16426  *         the paging f1ap msg
16427  *
16428  * @params[in] Paging_t   *paging
16429  * @return ROK     - success
16430  *         RFAILED - failure
16431  *
16432  ****************************************************************/
16433 void freeAperDecodePagingMsg(Paging_t   *paging)
16434 {
16435    uint8_t ieIdx, cellIdx;
16436    PagingCell_ItemIEs_t *pagingCellItemIes;
16437    PagingCell_Item_t *pagingCellItem;
16438    PagingCell_list_t  *pagingCelllist;
16439
16440    if(paging)
16441    {
16442       if(paging->protocolIEs.list.array)
16443       {
16444          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
16445          {
16446             if(paging->protocolIEs.list.array[ieIdx])
16447             {
16448                switch(paging->protocolIEs.list.array[ieIdx]->id)
16449                {
16450                   case ProtocolIE_ID_id_UEIdentityIndexValue:
16451                      {
16452                         free(paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10.buf);
16453                         break;
16454                      }
16455                   case ProtocolIE_ID_id_PagingIdentity:
16456                      {
16457                         if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present == PagingIdentity_PR_cNUEPagingIdentity)
16458                         {
16459                            if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)
16460                            {
16461                               if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->present == \
16462                                     CNUEPagingIdentity_PR_fiveG_S_TMSI)
16463                               {
16464                                  free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->choice.fiveG_S_TMSI.buf);
16465                               }
16466                               free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity);
16467                            }
16468                         }
16469                         break;
16470                      }
16471                   case ProtocolIE_ID_id_PagingCell_List:
16472                      {
16473                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list;
16474                         if(pagingCelllist->list.array)
16475                         {
16476                            for(cellIdx = 0; cellIdx < pagingCelllist->list.count; cellIdx++)
16477                            {
16478                               if(pagingCelllist->list.array[cellIdx])
16479                               {
16480                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellIdx];
16481                                  if(pagingCellItemIes->id == ProtocolIE_ID_id_PagingCell_Item)
16482                                  {
16483                                     pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
16484                                     free(pagingCellItem->nRCGI.pLMN_Identity.buf);
16485                                     free(pagingCellItem->nRCGI.nRCellIdentity.buf);
16486                                  }
16487                                  free(pagingCelllist->list.array[cellIdx]);
16488                               }
16489                            }
16490                            free(pagingCelllist->list.array);
16491                         }
16492                         break;
16493                      }
16494                }
16495                free(paging->protocolIEs.list.array[ieIdx]);
16496             }
16497          }
16498          free(paging->protocolIEs.list.array);
16499
16500       }
16501    }
16502 }
16503
16504 /**************************************************************
16505  *
16506  * @brief processing the paging f1ap msg received from CU 
16507  *
16508  * @details
16509  *
16510  *    Function : procPagingMsg
16511  *
16512  *    Functionality:
16513  *         - processing the paging f1ap msg received from CU
16514  *
16515  * @params[in] F1AP_PDU_t *f1apMsg
16516  * @return ROK     - success
16517  *         RFAILED - failure
16518  *
16519  *
16520  ****************************************************************/
16521 uint8_t procPagingMsg(F1AP_PDU_t *f1apMsg) 
16522 {
16523    uint8_t ieIdx = 0, cellListIdx = 0;
16524    uint64_t cellId = 0;
16525    Paging_t   *paging = NULLP;
16526    PagingCell_list_t  *pagingCelllist = NULLP;
16527    PagingCell_ItemIEs_t *pagingCellItemIes = NULLP;
16528    PagingCell_Item_t *pagingCellItem = NULLP;
16529    DuPagingMsg *tmpPagingParam = NULLP;
16530
16531    paging = &f1apMsg->choice.initiatingMessage->value.choice.Paging;
16532    if(paging)
16533    {
16534       if(paging->protocolIEs.list.array)
16535       {
16536          DU_ALLOC(tmpPagingParam, sizeof(DuPagingMsg));
16537          if(tmpPagingParam == NULLP)
16538          {
16539             DU_LOG("\nERROR  --> DU APP : Memory Allocation Failure in procPagingMsg");
16540             freeAperDecodePagingMsg(paging);
16541             return RFAILED;
16542          }
16543          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
16544          {
16545             if(paging->protocolIEs.list.array[ieIdx])
16546             {
16547                switch(paging->protocolIEs.list.array[ieIdx]->id)
16548                {
16549                   case ProtocolIE_ID_id_UEIdentityIndexValue:
16550                      {
16551                         bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10,\
16552                                          &tmpPagingParam->pagUeId);
16553                         break;
16554                      }
16555
16556                   case ProtocolIE_ID_id_PagingIdentity:
16557                      {
16558                         switch(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present)
16559                         {
16560                            case PagingIdentity_PR_cNUEPagingIdentity: 
16561                               {
16562                                  if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)  
16563                                  {
16564                                     bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.\
16565                                           cNUEPagingIdentity->choice.fiveG_S_TMSI, &tmpPagingParam->sTmsi);
16566
16567                                  }
16568                                  break;
16569                               }
16570                             case PagingIdentity_PR_rANUEPagingIdentity:
16571                                {
16572                                   /*TODO: This Identifier is specific to RAN Initiated Paging â€“ Connected Mode Paging*/
16573                                   break;
16574                                }
16575                             default:
16576                                {
16577                                   DU_LOG("ERROR  -->  DU APP: Invalid UE Paging Identity, Skipping this Paging Message:");
16578                                   continue;
16579                                }
16580                         }
16581                      }
16582
16583                   case ProtocolIE_ID_id_PagingDRX:
16584                      {
16585                         tmpPagingParam->pagingDrxPres = TRUE;
16586                         tmpPagingParam->pagingDrx = convertPagingCycleEnumToValue(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingDRX);
16587                         break;
16588                      }
16589
16590                   case ProtocolIE_ID_id_PagingPriority:
16591                      {
16592                         tmpPagingParam->pagPriority = paging->protocolIEs.list.array[ieIdx]->value.choice.PagingPriority;
16593                         break;
16594                      }
16595
16596                   case ProtocolIE_ID_id_PagingCell_List:
16597                      {
16598                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list; 
16599                         if(pagingCelllist->list.array)
16600                         {
16601                            for(cellListIdx = 0; cellListIdx < pagingCelllist->list.count; cellListIdx++)
16602                            {
16603                               if(pagingCelllist->list.array[cellListIdx])
16604                               {
16605                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellListIdx];
16606                                  pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
16607                                  bitStringToInt(&pagingCellItem->nRCGI.nRCellIdentity, &cellId);
16608                                  if(processPagingMsg(cellId, tmpPagingParam) != ROK)
16609                                  {
16610                                     DU_LOG("\nERROR  --> DU APP : Paging Processing Failed at CellId:%d",cellId);
16611                                     continue;
16612                                  }
16613                               }
16614                            }
16615                         }
16616                         break;
16617                      }
16618                    default:
16619                      {
16620                          DU_LOG("\nERROR  --> F1AP : Incorrect Paging IE option");
16621                          break;
16622                      }
16623                }
16624             }
16625          }
16626       }
16627    }
16628    DU_FREE(tmpPagingParam, sizeof(DuPagingMsg));
16629    freeAperDecodePagingMsg(paging);
16630   
16631    return ROK;
16632 }
16633
16634 /**************************************************************
16635  *
16636  * @brief Handles received F1AP message and sends back response  
16637  *
16638  * @details
16639  *
16640  *    Function : F1APMsgHdlr
16641  *
16642  *    Functionality:
16643  *         - Decodes received F1AP control message
16644  *         - Prepares response message, encodes and sends to SCTP
16645  *
16646  * @params[in] 
16647  * @return ROK     - success
16648  *         RFAILED - failure
16649  *
16650  * ****************************************************************/
16651 void F1APMsgHdlr(Buffer *mBuf)
16652 {
16653    int i =0;
16654    char *recvBuf =NULLP;
16655    MsgLen copyCnt =0;
16656    MsgLen recvBufLen =0;
16657    F1AP_PDU_t *f1apMsg =NULLP;
16658    asn_dec_rval_t rval; /* Decoder return value */
16659    F1AP_PDU_t f1apasnmsg ;
16660    DU_LOG("\nINFO  -->  F1AP : Received F1AP message buffer");
16661    ODU_PRINT_MSG(mBuf, 0,0);
16662
16663    /* Copy mBuf into char array to decode it */
16664    ODU_GET_MSG_LEN(mBuf, &recvBufLen);
16665    DU_ALLOC(recvBuf, (Size)recvBufLen);
16666
16667    if(recvBuf == NULLP)
16668    {
16669       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed");
16670       return;
16671    }
16672    if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
16673    {
16674       DU_LOG("\nERROR   -->  F1AP : Failed while copying %d", copyCnt);
16675       return;
16676    }
16677
16678    printf("\nDEBUG   -->  F1AP : Received flat buffer to be decoded : ");
16679    for(i=0; i< recvBufLen; i++)
16680    {
16681       printf("%x",recvBuf[i]);
16682    }
16683
16684    /* Decoding flat buffer into F1AP messsage */
16685    f1apMsg = &f1apasnmsg;
16686    memset(f1apMsg, 0, sizeof(F1AP_PDU_t));
16687
16688    rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0);
16689
16690    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
16691    {
16692       DU_LOG("\nERROR  -->  F1AP : ASN decode failed");
16693       return;
16694    }
16695    printf("\n");
16696    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16697
16698    switch(f1apMsg->present)
16699    {
16700       case F1AP_PDU_PR_successfulOutcome:
16701          {
16702             switch(f1apMsg->choice.successfulOutcome->value.present)
16703             {
16704                case SuccessfulOutcome__value_PR_ResetAcknowledge:
16705                   {
16706                      DU_LOG("\nINFO   -->  F1AP : F1ResetAcknowledge is received successfully ");
16707                      break;
16708                   }
16709                case SuccessfulOutcome__value_PR_F1SetupResponse:
16710                   {                             
16711 #ifndef ODU_TEST_STUB
16712                      procF1SetupRsp(f1apMsg, recvBufLen, recvBuf);
16713 #endif
16714                      break;
16715                   }
16716
16717                case SuccessfulOutcome__value_PR_GNBDUConfigurationUpdateAcknowledge:
16718                   {
16719                      procF1GNBDUCfgUpdAck(f1apMsg);
16720                      break;
16721                   }
16722
16723                default:
16724                   {
16725                      DU_LOG("\nERROR  -->  F1AP : Invalid type of SuccessfulOutcome__value_PR_ResetAcknowledge [%d]",\
16726                            f1apMsg->choice.successfulOutcome->value.present);
16727                      return;
16728                   }
16729             }/* End of switch(successfulOutcome) */
16730             free(f1apMsg->choice.successfulOutcome);
16731             break;
16732          }
16733       case F1AP_PDU_PR_initiatingMessage:
16734          {
16735             switch(f1apMsg->choice.initiatingMessage->value.present)
16736             {
16737                case InitiatingMessage__value_PR_Reset:
16738                   {
16739                      procF1ResetReq(f1apMsg);
16740                      break;
16741                   }
16742                case InitiatingMessage__value_PR_DLRRCMessageTransfer:
16743                   {
16744                      procF1DlRrcMsgTrans(f1apMsg);
16745                      break;
16746                   }
16747                case InitiatingMessage__value_PR_UEContextSetupRequest:
16748                   {
16749                      procF1UeContextSetupReq(f1apMsg);
16750                      break;
16751                   }
16752                case InitiatingMessage__value_PR_UEContextModificationRequest:
16753                   {
16754                      procF1UeContextModificationReq(f1apMsg);
16755                      break;
16756                   }
16757                case InitiatingMessage__value_PR_UEContextReleaseCommand:
16758                   {
16759                       procF1UeContextReleaseCommand(f1apMsg);
16760                       break;
16761                   }
16762                case InitiatingMessage__value_PR_Paging:
16763                   {
16764                      procPagingMsg(f1apMsg);
16765                      break;
16766                   }
16767                default:
16768                   {
16769                      DU_LOG("\nERROR  -->  F1AP : Invalid type of F1AP_PDU_PR_initiatingMessage [%d]",
16770                            f1apMsg->choice.initiatingMessage->value.present);
16771                      return;
16772                   }
16773             }/* End of switch(initiatingMessage) */
16774             free(f1apMsg->choice.initiatingMessage);
16775             break;
16776          }
16777
16778       default:
16779          {
16780             DU_LOG("\nERROR  -->  F1AP : Invalid type of f1apMsg->present [%d]",f1apMsg->present);
16781             return;
16782          }
16783          free(f1apMsg);
16784
16785    }/* End of switch(f1apMsg->present) */
16786    
16787    DU_FREE(recvBuf, (Size)recvBufLen);
16788 } /* End of F1APMsgHdlr */
16789
16790 /**********************************************************************
16791   End of file
16792  **********************************************************************/