[Issue Id- ODUHIGH-451] Fixes in F1 Setup procedure and UE attach call flow
[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;
2540    uint8_t   idx1 =0;
2541    uint8_t   idx =0;
2542    F1AP_PDU_t                   *f1apMsg = NULLP;
2543    ULRRCMessageTransfer_t       *ulRRCMsg = NULLP;
2544    asn_enc_rval_t               encRetVal;        /* Encoder return value */
2545    uint8_t ret =RFAILED;
2546    
2547    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2548
2549    while(true)
2550    {
2551       DU_LOG("\n INFO   -->  F1AP : Building UL RRC Message Transfer Message\n");
2552
2553       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
2554       if(f1apMsg == NULLP)
2555       {
2556          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
2557          break;
2558       }
2559       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
2560       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2561       if(f1apMsg->choice.initiatingMessage == NULLP)
2562       {
2563          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
2564          break;
2565       }
2566       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_ULRRCMessageTransfer;
2567       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
2568       f1apMsg->choice.initiatingMessage->value.present = \
2569                                                          InitiatingMessage__value_PR_ULRRCMessageTransfer;
2570       ulRRCMsg =
2571          &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2572       elementCnt = 4;
2573       ulRRCMsg->protocolIEs.list.count = elementCnt;
2574       ulRRCMsg->protocolIEs.list.size = \
2575                                         elementCnt * sizeof(ULRRCMessageTransferIEs_t *);
2576
2577       /* Initialize the F1Setup members */
2578       DU_ALLOC(ulRRCMsg->protocolIEs.list.array, ulRRCMsg->protocolIEs.list.size);
2579       if(ulRRCMsg->protocolIEs.list.array == NULLP)
2580       {
2581          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UL RRC MessageTransferIEs failed");
2582          break;
2583       }
2584       for(idx=0; idx<elementCnt; idx++)
2585       {
2586          DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx],sizeof(ULRRCMessageTransferIEs_t));
2587          if(ulRRCMsg->protocolIEs.list.array[idx] == NULLP)
2588          {
2589             break;
2590          }
2591       }
2592
2593       idx1 = 0;
2594
2595       /*GNB CU UE F1AP ID*/
2596       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
2597       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2598       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2599                                                               ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
2600       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = ueCb.gnbCuUeF1apId;
2601
2602       /*GNB DU UE F1AP ID*/
2603       idx1++;
2604       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
2605       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2606       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2607                                                               ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
2608       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = ueCb.gnbDuUeF1apId;
2609
2610       /*SRBID*/
2611       idx1++;
2612       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
2613       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2614       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2615                                                               ULRRCMessageTransferIEs__value_PR_SRBID;
2616       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.SRBID = lcId;
2617
2618       /*RRCContainer*/
2619       idx1++;
2620       ulRRCMsg->protocolIEs.list.array[idx1]->id  = ProtocolIE_ID_id_RRCContainer;
2621       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2622       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2623                                                               ULRRCMessageTransferIEs__value_PR_RRCContainer;
2624       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size = msgLen;
2625       DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2626             ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size)
2627       if(!ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf)
2628       {
2629          DU_LOG(" ERROR  -->  F1AP : Memory allocation for BuildAndSendULRRCMessageTransfer failed");
2630          break;
2631       }
2632       memset(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, 0, msgLen);
2633       memcpy(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, \
2634             rrcMsg, ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2635
2636       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
2637
2638       /* Encode the F1SetupRequest type as APER */
2639       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2640       encBufSize = 0;
2641       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
2642             encBuf);
2643       /* Encode results */
2644       if(encRetVal.encoded == ENCODE_FAIL)
2645       {
2646          DU_LOG( "\nERROR  -->  F1AP : Could not encode ULRRCMessageTransfer structure (at %s)\n",\
2647                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2648          break;
2649       }
2650       else
2651       {
2652          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for ULRRCMessageTransfer\n");
2653          for(int i=0; i< encBufSize; i++)
2654          {
2655             printf("%x",encBuf[i]);
2656          }
2657       }
2658
2659       /* Sending  msg  */
2660       if(sendF1APMsg()  !=      ROK)
2661       {
2662          DU_LOG("\nERROR  -->   F1AP : Sending  UL RRC Message Transfer Failed");
2663          break;
2664       }
2665       ret = ROK;
2666       break;
2667    }
2668    FreeULRRCMessageTransfer(f1apMsg);
2669
2670    return ret;
2671 }/* End of BuildAndSendULRRCMessageTransfer*/
2672
2673 /*******************************************************************
2674  *
2675  * @brief Builds tag config 
2676  *
2677  * @details
2678  *
2679  *    Function : BuildTagConfig 
2680  *
2681  *    Functionality: Builds tag config in MacCellGroupConfig
2682  *
2683  * @params[in] TAG_Config *tag_Config
2684  *
2685  * @return ROK     - success
2686  *         RFAILED - failure
2687  *
2688  * ****************************************************************/
2689 uint8_t BuildTagConfig(DuUeCb *ueCb, struct TAG_Config *tagConfig)
2690 {
2691    struct TAG_Config__tag_ToAddModList *tagList;
2692    uint8_t                     idx, elementCnt;
2693
2694    tagConfig->tag_ToReleaseList = NULLP;
2695    tagConfig->tag_ToAddModList = NULLP;
2696    DU_ALLOC(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
2697    if(!tagConfig->tag_ToAddModList)
2698    {
2699       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2700       return RFAILED;
2701    }
2702
2703    if(ueCb == NULLP)
2704       elementCnt = ODU_VALUE_ONE;
2705    else
2706       elementCnt = ueCb->macUeCfg.macCellGrpCfg.tagCfg.addModListCount;
2707
2708    tagList = tagConfig->tag_ToAddModList;
2709    tagList->list.count = elementCnt;
2710    tagList->list.size  =  elementCnt * sizeof(struct TAG *);
2711
2712    tagList->list.array = NULLP;
2713    DU_ALLOC(tagList->list.array, tagList->list.size);
2714    if(!tagList->list.array)
2715    {
2716       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2717       return RFAILED;
2718    }
2719
2720    for(idx=0; idx<tagList->list.count; idx++)
2721    {
2722       tagList->list.array[idx] = NULLP;
2723       DU_ALLOC(tagList->list.array[idx], sizeof(struct TAG));
2724       if(!tagList->list.array[idx])
2725       {
2726          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2727          return RFAILED;
2728       }
2729    }
2730
2731    if(ueCb == NULLP)
2732    {
2733       idx = 0;
2734       tagList->list.array[idx]->tag_Id = TAG_ID;
2735       tagList->list.array[idx]->timeAlignmentTimer = TIME_ALIGNMENT_TMR;
2736    }
2737    else
2738    {
2739       for(idx=0; idx<tagList->list.count; idx++)
2740       {
2741          tagList->list.array[idx]->tag_Id = ueCb->macUeCfg.macCellGrpCfg.tagCfg.addModList[idx].tagId;
2742          tagList->list.array[idx]->timeAlignmentTimer = ueCb->macUeCfg.macCellGrpCfg.tagCfg.addModList[idx].timeAlignTimer;
2743       }
2744    }
2745
2746    return ROK;
2747 }
2748
2749 /*******************************************************************
2750  *
2751  * @brief Builds PHR Config 
2752  *
2753  * @details
2754  *
2755  *    Function : BuildPhrConfig
2756  *
2757  *    Functionality: Builds phrConfig in MacCellGroupConfig
2758  *
2759  * @params[in] PHR Config *
2760  *
2761  * @return ROK     - success
2762  *         RFAILED - failure
2763  *
2764  * ****************************************************************/
2765 uint8_t BuildPhrConfig(DuUeCb *ueCb, struct MAC_CellGroupConfig__phr_Config *phrConfig)
2766 {
2767
2768    phrConfig->present = MAC_CellGroupConfig__phr_Config_PR_setup;
2769    phrConfig->choice.setup = NULLP;
2770    DU_ALLOC(phrConfig->choice.setup, sizeof(struct PHR_Config));
2771    if(!phrConfig->choice.setup)
2772    {
2773       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhrConfig");
2774       return RFAILED;
2775    }
2776
2777    if(ueCb == NULLP)
2778    {
2779       phrConfig->choice.setup->phr_PeriodicTimer        = PHR_PERIODIC_TMR;
2780       phrConfig->choice.setup->phr_ProhibitTimer        = PHR_PROHIBHIT_TMR;
2781       phrConfig->choice.setup->phr_Tx_PowerFactorChange = PHR_PWR_FACTOR_CHANGE;
2782       phrConfig->choice.setup->multiplePHR              = false;
2783       phrConfig->choice.setup->dummy                    = false;
2784       phrConfig->choice.setup->phr_Type2OtherCell       = false;
2785       phrConfig->choice.setup->phr_ModeOtherCG          = PHR_MODE_OTHER_CG;
2786    }
2787    else
2788    {
2789       phrConfig->choice.setup->phr_PeriodicTimer        = ueCb->macUeCfg.macCellGrpCfg.phrCfg.periodicTimer;
2790       phrConfig->choice.setup->phr_ProhibitTimer        = ueCb->macUeCfg.macCellGrpCfg.phrCfg.prohibitTimer;
2791       phrConfig->choice.setup->phr_Tx_PowerFactorChange = ueCb->macUeCfg.macCellGrpCfg.phrCfg.txPowerFactor;
2792       phrConfig->choice.setup->multiplePHR              = ueCb->macUeCfg.macCellGrpCfg.phrCfg.multiplePHR;
2793       phrConfig->choice.setup->dummy                    = ueCb->macUeCfg.macCellGrpCfg.phrCfg.dummy;
2794       phrConfig->choice.setup->phr_Type2OtherCell       = ueCb->macUeCfg.macCellGrpCfg.phrCfg.phrType2OtherCell;
2795       phrConfig->choice.setup->phr_ModeOtherCG          = ueCb->macUeCfg.macCellGrpCfg.phrCfg.phrOtherCG;
2796    }
2797
2798    return ROK;
2799 }
2800
2801 /*******************************************************************
2802  *
2803  * @brief Builds BSR Config 
2804  *
2805  * @details
2806  *
2807  *    Function : BuildBsrConfig
2808  *
2809  *    Functionality: Builds BuildBsrConfig in MacCellGroupConfig
2810  *
2811  * @params[in] BSR_Config *bsrConfig
2812  *
2813  * @return ROK     - success
2814  *         RFAILED - failure
2815  *
2816  * ****************************************************************/
2817 uint8_t BuildBsrConfig(DuUeCb *ueCb, struct BSR_Config *bsrConfig)
2818 {
2819    if(ueCb == NULLP)
2820    {
2821       bsrConfig->periodicBSR_Timer = PERIODIC_BSR_TMR;
2822       bsrConfig->retxBSR_Timer     = RETX_BSR_TMR;
2823       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
2824    }
2825    else
2826    {
2827       bsrConfig->periodicBSR_Timer = convertBsrPeriodicTmrValueToEnum(ueCb->macUeCfg.macCellGrpCfg.bsrTmrCfg.periodicTimer);
2828       bsrConfig->retxBSR_Timer     = convertBsrRetxTmrValueToEnum(ueCb->macUeCfg.macCellGrpCfg.bsrTmrCfg.retxTimer);
2829
2830       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
2831       DU_ALLOC(bsrConfig->logicalChannelSR_DelayTimer, sizeof(long));
2832       if(bsrConfig->logicalChannelSR_DelayTimer == NULLP)
2833       {
2834          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildBsrConfig");
2835          return RFAILED;
2836       }
2837       *(bsrConfig->logicalChannelSR_DelayTimer) = convertLcSrDelayTmrValueToEnum(ueCb->macUeCfg.macCellGrpCfg.bsrTmrCfg.srDelayTimer);
2838    }
2839
2840    return ROK;
2841 }
2842
2843 /*******************************************************************
2844  *
2845  * @brief Builds scheduling request config 
2846  *
2847  * @details
2848  *
2849  *    Function : BuildSchedulingReqConfig 
2850  *
2851  *    Functionality: Builds BuildSchedulingReqConfig in MacCellGroupConfig
2852  *
2853  * @params[in] SchedulingRequestConfig *schedulingRequestConfig
2854  *
2855  * @return ROK     - success
2856  *         RFAILED - failure
2857  *
2858  * ****************************************************************/
2859 uint8_t BuildSchedulingReqConfig(DuUeCb *ueCb, struct SchedulingRequestConfig *schedulingRequestConfig)
2860 {
2861    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList;
2862    uint8_t                     idx, elementCnt;
2863
2864    schedulingRequestConfig->schedulingRequestToAddModList = NULLP;
2865    DU_ALLOC(schedulingRequestConfig->schedulingRequestToAddModList,
2866          sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));
2867    if(!schedulingRequestConfig->schedulingRequestToAddModList)
2868    {
2869       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2870       return RFAILED;
2871    }
2872
2873    if(ueCb == NULLP)
2874       elementCnt = ODU_VALUE_ONE;
2875    else
2876       elementCnt = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModListCount;
2877
2878    schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
2879    schReqList->list.count = elementCnt;
2880    schReqList->list.size  = elementCnt * sizeof(struct SchedulingRequestToAddMod *);
2881
2882    schReqList->list.array = NULLP;
2883    DU_ALLOC(schReqList->list.array, schReqList->list.size);
2884    if(!schReqList->list.array)
2885    {
2886       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2887       return RFAILED;
2888    }
2889
2890    for(idx=0; idx<schReqList->list.count; idx++)
2891    {
2892       schReqList->list.array[idx] = NULLP;
2893       DU_ALLOC(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
2894       if(!schReqList->list.array[idx])
2895       {
2896          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2897          return RFAILED;
2898       }
2899    }
2900
2901    if(ueCb == NULLP)
2902    {
2903       idx = 0;
2904       schReqList->list.array[idx]->schedulingRequestId = SCH_REQ_ID;
2905
2906       schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
2907       DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
2908       if(!schReqList->list.array[idx]->sr_ProhibitTimer)
2909       {
2910          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2911          return RFAILED;
2912       }
2913       *(schReqList->list.array[idx]->sr_ProhibitTimer) = SR_PROHIBIT_TMR;
2914       schReqList->list.array[idx]->sr_TransMax = SR_TRANS_MAX;
2915    }
2916    else
2917    {
2918       for(idx=0; idx<schReqList->list.count; idx++)
2919       {
2920          schReqList->list.array[idx]->schedulingRequestId = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].schedReqId;
2921
2922          schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
2923          DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
2924          if(!schReqList->list.array[idx]->sr_ProhibitTimer)
2925          {
2926             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2927             return RFAILED;
2928          }
2929          *(schReqList->list.array[idx]->sr_ProhibitTimer) = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srProhibitTmr;
2930          schReqList->list.array[idx]->sr_TransMax = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srTransMax;
2931       }
2932    }
2933
2934    schedulingRequestConfig->schedulingRequestToReleaseList = NULLP;
2935
2936    return ROK;
2937 }
2938
2939 /*******************************************************************
2940  *
2941  * @brief Builds RLC Configuration for AM mode
2942  *
2943  * @details
2944  *
2945  *    Function : BuildRlcConfigAm
2946  *
2947  *    Functionality: 
2948  *       Builds AM mode RLC Config in BuildRlcBearerToAddModList
2949  *
2950  * @params[in] AmBearerCfg *amCfg
2951  *             RLC_Config_t  *rlcConfig
2952  *
2953  * @return ROK     - success
2954  *         RFAILED - failure
2955  *
2956  * ****************************************************************/
2957 uint8_t BuildRlcConfigAm(AmBearerCfg *amCfg, struct RLC_Config *rlcConfig)
2958 {
2959    rlcConfig->choice.am = NULLP;
2960    DU_ALLOC(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
2961    if(!rlcConfig->choice.am)
2962    {
2963       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
2964       return RFAILED;
2965    }
2966
2967    /* Fill AM UL configuration */
2968    rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength = NULLP;
2969    DU_ALLOC(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
2970    if(!rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength)
2971    {
2972       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
2973       return RFAILED;
2974    }
2975
2976    /* Fill default AM UL configuration if input pointer to DU database is NULL */
2977    if(amCfg == NULLP)
2978    {
2979       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = SN_FIELD_LEN;
2980       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = T_POLL_RETRANSMIT;
2981       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = POLL_PDU;
2982       rlcConfig->choice.am->ul_AM_RLC.pollByte          = POLL_BYTE;
2983       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = MAX_RETX_THRESHOLD;
2984    }
2985    else
2986    {
2987       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->dlAmCfg.snLenDl);
2988       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = covertPollRetxTmrValueToEnum(amCfg->dlAmCfg.pollRetxTmr);
2989       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = covertPollPduValueToEnum(amCfg->dlAmCfg.pollPdu);
2990       rlcConfig->choice.am->ul_AM_RLC.pollByte          = covertPollByteValueToEnum(amCfg->dlAmCfg.pollByte);
2991       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = covertMaxRetxValueToEnum(amCfg->dlAmCfg.maxRetxTh);
2992    }
2993
2994    /* Fill AM DL configuraion */
2995    rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength = NULLP;
2996    DU_ALLOC(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
2997    if(!rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength)
2998    {
2999       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3000       return RFAILED;
3001    }
3002
3003    /* Fill default AM DL configuration if input pointer to DU database is NULL */
3004    if(amCfg == NULLP)
3005    {
3006       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = SN_FIELD_LEN;
3007       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = T_REASSEMBLY;
3008       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = T_STATUS_PROHIBHIT;
3009    }
3010    else /* Fill AM configuration from DU database */
3011    {
3012       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->ulAmCfg.snLenUl);
3013       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = convertReasmblTmrValueToEnum(amCfg->ulAmCfg.reAssemTmr);
3014       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = convertProhibitTmrValueToEnum(amCfg->ulAmCfg.statProhTmr);
3015    }
3016    return ROK;
3017 }
3018
3019 /*******************************************************************
3020  *
3021  * @brief Builds RLC Config for UM Bidirection
3022  *
3023  * @details
3024  *
3025  *    Function : BuildRlcConfig UmBiDir
3026  *
3027  *    Functionality: 
3028  *       Builds RLC Config for UM Bidirection in BuildRlcBearerToAddModList 
3029  *
3030  * @params[in] UmBiDirBearerCfg *umBiDirCfg
3031  *             RLC_Config_t *rlcConfig
3032  *
3033  * @return ROK     - success
3034  *         RFAILED - failure
3035  *
3036  * ****************************************************************/
3037 uint8_t BuildRlcConfigUmBiDir(UmBiDirBearerCfg *umBiDirCfg, struct RLC_Config *rlcConfig)
3038 {
3039    rlcConfig->choice.um_Bi_Directional = NULLP;
3040    DU_ALLOC(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
3041    if(rlcConfig->choice.um_Bi_Directional == NULLP)
3042    {
3043       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3044       return RFAILED;
3045    }
3046
3047    /* Fill UM Bidirectional UL configuration */
3048    rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength = NULLP;
3049    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3050    if(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength == NULLP)
3051    {
3052       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3053       return RFAILED;
3054    }
3055
3056    if(umBiDirCfg != NULLP)
3057    {
3058       *(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->dlUmCfg.snLenDlUm);     
3059    }
3060
3061    /* Fill UM Bidirectional DL configuration */
3062    rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength = NULLP;
3063    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3064    if(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength == NULLP)
3065    {
3066       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3067       return RFAILED;
3068    }
3069
3070    if(umBiDirCfg != NULLP)
3071    {
3072       *(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->ulUmCfg.snLenUlUm);     
3073       rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umBiDirCfg->ulUmCfg.reAssemTmr);
3074    }
3075
3076    return ROK;
3077 }
3078
3079 /*******************************************************************
3080  *
3081  * @brief Builds RLC Config for UM Uni directional UL
3082  *
3083  * @details
3084  *
3085  *    Function : BuildRlcConfigUmUniDirUl
3086  *
3087  *    Functionality: 
3088  *       Builds RLC Config for UM Unidirection UL in BuildRlcBearerToAddModList 
3089  *
3090  * @params[in] UmUniDirDlBearerCfg *umUniDirDlCfg
3091  *             RLC_Config_t *rlcConfig
3092  *
3093  * @return ROK     - success
3094  *         RFAILED - failure
3095  *
3096  * ****************************************************************/
3097 uint8_t BuildRlcConfigUmUniDirUl(UmUniDirDlBearerCfg *umUniDirDlCfg, RLC_Config_t *rlcConfig)
3098 {
3099    rlcConfig->choice.um_Uni_Directional_UL = NULLP;
3100    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
3101    if(rlcConfig->choice.um_Uni_Directional_UL == NULLP)
3102    {
3103       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3104       return RFAILED;
3105    }
3106
3107    rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength = NULLP;
3108    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3109    if(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength == NULLP)
3110    {
3111       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3112       return RFAILED;
3113    }
3114
3115    if(umUniDirDlCfg != NULLP)
3116    {
3117       *(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirDlCfg->dlUmCfg.snLenDlUm);
3118    }
3119
3120    return ROK;
3121 }
3122
3123 /*******************************************************************
3124  *
3125  * @brief Builds RLC Config for UM Uni directional DL
3126  *
3127  * @details
3128  *
3129  *    Function : BuildRlcConfigUmUniDirDl
3130  *
3131  *    Functionality: 
3132  *       Builds RLC Config for UM Unidirection DL in BuildRlcBearerToAddModList 
3133  *
3134  * @params[in] UmUniDirUlBearerCfg *umUniDirUlCfg
3135  *             RLC_Config_t *rlcConfig
3136  *
3137  * @return ROK     - success
3138  *         RFAILED - failure
3139  *
3140  * ****************************************************************/
3141 uint8_t BuildRlcConfigUmUniDirDl(UmUniDirUlBearerCfg *umUniDirUlCfg, RLC_Config_t *rlcConfig)
3142 {
3143    rlcConfig->choice.um_Uni_Directional_DL = NULLP;
3144    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
3145    if(rlcConfig->choice.um_Uni_Directional_DL == NULLP)
3146    {
3147       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3148       return RFAILED;
3149    }
3150
3151    rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength = NULLP;
3152    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3153    if(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength == NULLP)
3154    {
3155       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3156       return RFAILED;
3157    }
3158
3159    if(umUniDirUlCfg != NULLP)
3160    {
3161       *(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirUlCfg->ulUmCfg.snLenUlUm);
3162       rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umUniDirUlCfg->ulUmCfg.reAssemTmr);
3163    }
3164
3165    return ROK;
3166 }
3167
3168 /*******************************************************************
3169  *
3170  * @brief Builds RLC Config
3171  *
3172  * @details
3173  *
3174  *    Function : BuildRlcConfig
3175  *
3176  *    Functionality: Builds RLC Config in BuildRlcBearerToAddModList 
3177  *
3178  * @params[in] RLC_Config_t *rlcConfig
3179  *
3180  * @return ROK     - success
3181  *         RFAILED - failure
3182  *
3183  * ****************************************************************/
3184 uint8_t BuildRlcConfig(RlcBearerCfg *rbCfg, struct RLC_Config *rlcConfig)
3185 {
3186    
3187    /* Fill default values if rbCfg is NULL */
3188    if(rbCfg == NULLP)
3189    {
3190       rlcConfig->present = RLC_Config_PR_am;
3191       BuildRlcConfigAm(NULLP, rlcConfig);
3192    }
3193    /* If RbCfg is present, fill RLC configurations from DU Database */
3194    else
3195    {
3196       rlcConfig->present = covertRlcModeFromIntEnumToRrcEnum(rbCfg->rlcMode);
3197       switch(rlcConfig->present)
3198       {
3199          case RLC_Config_PR_am:
3200             BuildRlcConfigAm(rbCfg->u.amCfg, rlcConfig);
3201             break;
3202          case RLC_Config_PR_um_Bi_Directional:
3203             BuildRlcConfigUmBiDir(rbCfg->u.umBiDirCfg, rlcConfig);
3204             break;
3205          case RLC_Config_PR_um_Uni_Directional_UL:
3206             BuildRlcConfigUmUniDirUl(rbCfg->u.umUniDirDlCfg, rlcConfig);
3207             break;
3208          case RLC_Config_PR_um_Uni_Directional_DL:
3209             BuildRlcConfigUmUniDirDl(rbCfg->u.umUniDirUlCfg, rlcConfig);
3210             break;
3211          case RLC_Config_PR_NOTHING:
3212          default:
3213             break;
3214       }
3215    }
3216
3217    return ROK;
3218 }
3219
3220 /*******************************************************************
3221  *
3222  * @brief Builds MAC LC Config
3223  *
3224  * @details
3225  *
3226  *    Function : BuildMacLCConfig 
3227  *
3228  *    Functionality: Builds MAC LC Config in BuildRlcBearerToAddModList 
3229  *
3230  * @params[in] struct LogicalChannelConfig macLcConfig
3231  *
3232  * @return ROK     - success
3233  *         RFAILED - failure
3234  *
3235  * ****************************************************************/
3236 uint8_t BuildMacLCConfig(LcCfg *lcCfgDb, struct LogicalChannelConfig *macLcConfig)
3237 {
3238    macLcConfig->ul_SpecificParameters = NULLP;
3239    DU_ALLOC(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
3240    if(!macLcConfig->ul_SpecificParameters)
3241    {
3242       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3243       return RFAILED;
3244    }
3245
3246    if(lcCfgDb == NULLP)
3247    {
3248       macLcConfig->ul_SpecificParameters->priority = MAC_LC_PRIORITY;
3249       macLcConfig->ul_SpecificParameters->prioritisedBitRate =  PRIORTISIED_BIT_RATE;
3250       macLcConfig->ul_SpecificParameters->bucketSizeDuration =  BUCKET_SIZE_DURATION;
3251    }
3252    else
3253    {
3254       macLcConfig->ul_SpecificParameters->priority = lcCfgDb->ulLcCfg.priority;
3255       macLcConfig->ul_SpecificParameters->prioritisedBitRate = lcCfgDb->ulLcCfg.pbr;
3256       macLcConfig->ul_SpecificParameters->bucketSizeDuration = lcCfgDb->ulLcCfg.bsd;
3257    }
3258
3259    macLcConfig->ul_SpecificParameters->allowedServingCells = NULLP;
3260    macLcConfig->ul_SpecificParameters->allowedSCS_List = NULLP;
3261    macLcConfig->ul_SpecificParameters->maxPUSCH_Duration = NULLP;
3262    macLcConfig->ul_SpecificParameters->configuredGrantType1Allowed = NULLP;
3263
3264    macLcConfig->ul_SpecificParameters->logicalChannelGroup = NULLP;
3265    DU_ALLOC(macLcConfig->ul_SpecificParameters->logicalChannelGroup,    sizeof(long));
3266    if(!macLcConfig->ul_SpecificParameters->logicalChannelGroup)
3267    {
3268       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3269       return RFAILED;
3270    }
3271
3272    if(lcCfgDb == NULLP)
3273       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = LC_GRP;
3274    else
3275       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = lcCfgDb->ulLcCfg.lcGroup;
3276
3277    macLcConfig->ul_SpecificParameters->schedulingRequestID = NULLP;
3278    DU_ALLOC(macLcConfig->ul_SpecificParameters->schedulingRequestID,    sizeof(SchedulingRequestId_t));
3279    if(!macLcConfig->ul_SpecificParameters->schedulingRequestID)
3280    {
3281       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3282       return RFAILED;
3283    }
3284
3285    if(lcCfgDb == NULLP)
3286       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = SCH_REQ_ID;
3287    else
3288       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = lcCfgDb->ulLcCfg.schReqId;
3289
3290    macLcConfig->ul_SpecificParameters->logicalChannelSR_Mask = false;
3291    macLcConfig->ul_SpecificParameters->logicalChannelSR_DelayTimerApplied = false;
3292    macLcConfig->ul_SpecificParameters->bitRateQueryProhibitTimer = NULLP;
3293
3294    return ROK;
3295 }
3296
3297 /*******************************************************************
3298  *
3299  * @brief Builds RLC Bearer to Add/Mod list
3300  *
3301  * @details
3302  *
3303  *    Function :BuildRlcBearerToAddModList 
3304  *
3305  *    Functionality: Builds RLC Bearer to Add/Mod list in DuToCuRrcContainer
3306  *
3307  * @params[in] rlc_BearerToAddModList
3308  *
3309  * @return ROK     - success
3310  *         RFAILED - failure
3311  *
3312  * ****************************************************************/
3313 uint8_t BuildRlcBearerToAddModList(DuUeCb *ueCb, struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList)
3314 {
3315    uint8_t  idx = 0, lcIdx=0, macLcIdx = 0, elementCnt = 0;
3316
3317    if(ueCb == NULLP)
3318       elementCnt = 1;
3319    else if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
3320       elementCnt = ueCb->rlcUeCfg.numLcs;
3321    else
3322    {
3323       for(lcIdx = 0; lcIdx<ueCb->rlcUeCfg.numLcs; lcIdx++)
3324       {
3325          if(ueCb->rlcUeCfg.rlcLcCfg[lcIdx].isLcAddModRspSent == false)
3326             elementCnt++;
3327       }
3328    }
3329    rlcBearerList->list.count = elementCnt;
3330    rlcBearerList->list.size  = elementCnt * sizeof(struct RLC_BearerConfig *);
3331
3332    rlcBearerList->list.array = NULLP;
3333    DU_ALLOC(rlcBearerList->list.array, rlcBearerList->list.size);
3334    if(!rlcBearerList->list.array)
3335    {
3336       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3337       return RFAILED;
3338    }
3339
3340    for(idx=0; idx<rlcBearerList->list.count; idx++)
3341    {
3342       rlcBearerList->list.array[idx] = NULLP;
3343       DU_ALLOC(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
3344       if(!rlcBearerList->list.array[idx])
3345       {
3346          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3347          return RFAILED;
3348       }
3349    }
3350
3351    if(ueCb == NULLP)
3352    {
3353       idx=0;
3354       rlcBearerList->list.array[idx]->logicalChannelIdentity = SRB1_LCID;
3355       DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3356       if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3357       {     
3358          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3359          return RFAILED;
3360       }     
3361       rlcBearerList->list.array[idx]->servedRadioBearer->present = RLC_BearerConfig__servedRadioBearer_PR_srb_Identity;
3362       rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = SRB1_LCID;
3363       rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3364
3365       /* Fill RLC related Configurations for this Radio Bearer */
3366       rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3367       DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3368       if(!rlcBearerList->list.array[idx]->rlc_Config)
3369       {
3370          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3371          return RFAILED;
3372       }
3373       if(BuildRlcConfig(NULLP, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3374       {
3375          DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3376          return RFAILED;
3377       }
3378
3379       /* Fill MAC related configurations for this Radio Bearer */
3380       rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3381       DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3382       if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3383       {
3384          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3385          return RFAILED;
3386       }
3387       if(BuildMacLCConfig(NULLP, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3388       {
3389          DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3390          return RFAILED;
3391       }
3392    }
3393    else
3394    {
3395       idx=0;
3396       for(lcIdx=0; lcIdx<ueCb->rlcUeCfg.numLcs; lcIdx++)
3397       {
3398          if((ueCb->f1UeDb->actionType != UE_CTXT_CFG_QUERY) && (ueCb->rlcUeCfg.rlcLcCfg[lcIdx].isLcAddModRspSent == true))
3399             continue;
3400
3401          /* Fill Logical channel identity */
3402          rlcBearerList->list.array[idx]->logicalChannelIdentity = ueCb->rlcUeCfg.rlcLcCfg[lcIdx].lcId;
3403
3404          /* Fill Radio Bearer Id and type (DRB/SRB) for this logical channel */
3405          DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3406          if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3407          {
3408             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3409             return RFAILED;
3410          }
3411          rlcBearerList->list.array[idx]->servedRadioBearer->present = \
3412                                                                       covertRbTypeFromIntEnumToRrcEnum(ueCb->rlcUeCfg.rlcLcCfg[lcIdx].rbType);
3413          switch(rlcBearerList->list.array[idx]->servedRadioBearer->present)
3414          {
3415             case RLC_BearerConfig__servedRadioBearer_PR_srb_Identity: 
3416                rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = ueCb->rlcUeCfg.rlcLcCfg[lcIdx].rbId;
3417                break;
3418             case RLC_BearerConfig__servedRadioBearer_PR_drb_Identity:
3419                rlcBearerList->list.array[idx]->servedRadioBearer->choice.drb_Identity = ueCb->rlcUeCfg.rlcLcCfg[lcIdx].rbId;
3420                break;
3421             case RLC_BearerConfig__servedRadioBearer_PR_NOTHING:
3422             default:
3423                break;
3424          }
3425          ueCb->rlcUeCfg.rlcLcCfg[lcIdx].isLcAddModRspSent = true;
3426
3427          rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3428
3429          /* Fill RLC related Configurations for this Radio Bearer */
3430          rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3431          DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3432          if(!rlcBearerList->list.array[idx]->rlc_Config)
3433          {
3434             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3435             return RFAILED;
3436          }
3437          if(BuildRlcConfig(&ueCb->rlcUeCfg.rlcLcCfg[lcIdx], rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3438          {
3439             DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3440             return RFAILED;
3441          }
3442
3443          /* Fill MAC related configurations for this Radio Bearer */
3444          rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3445          DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3446          if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3447          {
3448             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3449             return RFAILED;
3450          }
3451          for(macLcIdx = 0; macLcIdx < ueCb->macUeCfg.numLcs; macLcIdx++)
3452          {
3453             if(ueCb->macUeCfg.lcCfgList[macLcIdx].lcId == ueCb->rlcUeCfg.rlcLcCfg[lcIdx].lcId)
3454             {
3455                if(BuildMacLCConfig(&ueCb->macUeCfg.lcCfgList[macLcIdx], rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3456                {
3457                   DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3458                   return RFAILED;
3459                }
3460                break;
3461             }
3462          }
3463
3464          idx++;
3465       }
3466    }
3467    return ROK;
3468 }
3469
3470 /*******************************************************************
3471  *
3472  * @brief Build Control resource set to add/modify list 
3473  *
3474  * @details
3475  *
3476  *    Function : BuildControlRSetToAddModList
3477  *
3478  *    Functionality: Build Control resource set to add/modify list
3479  *
3480  * @params[in] 
3481  * struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList
3482  *
3483  * @return ROK     - success
3484  *         RFAILED - failure
3485  *
3486  * ****************************************************************/
3487 uint8_t BuildControlRSetToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList)
3488 {
3489    uint8_t idx;
3490    uint8_t elementCnt;
3491    uint8_t numBytes, bitsUnused;
3492    struct ControlResourceSet *controlRSet;
3493    uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
3494    uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
3495
3496    if(pdcchCfg == NULLP)
3497       elementCnt = 1;
3498    else
3499       elementCnt = pdcchCfg->numCRsetToAddMod;
3500
3501    controlRSetList->list.count = elementCnt;
3502    controlRSetList->list.size = elementCnt * sizeof(struct ControlResourceSet *);
3503
3504    controlRSetList->list.array = NULLP;
3505    DU_ALLOC(controlRSetList->list.array, controlRSetList->list.size);
3506    if(!controlRSetList->list.array)
3507    {
3508       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3509       return RFAILED;
3510    }
3511
3512    for(idx = 0; idx < elementCnt; idx++)
3513    {
3514       controlRSetList->list.array[idx] = NULLP;
3515       DU_ALLOC(controlRSetList->list.array[idx], sizeof(struct ControlResourceSet));
3516       if(!controlRSetList->list.array[idx])
3517       {
3518          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3519          return RFAILED;
3520       }
3521    }
3522
3523    for(idx = 0; idx < elementCnt; idx++)
3524    {
3525       controlRSet = controlRSetList->list.array[idx];
3526
3527       if(pdcchCfg == NULLP)
3528          controlRSet->controlResourceSetId = PDCCH_CTRL_RSRC_SET_ONE_ID;
3529       else
3530          controlRSet->controlResourceSetId = pdcchCfg->cRSetToAddModList[idx].cRSetId;
3531
3532       /* size 6 bytes
3533        * 3 LSBs unsued
3534        * Bit string stored ff0000000000
3535        */
3536       numBytes = 6;
3537       bitsUnused = 3;
3538       controlRSet->frequencyDomainResources.size = numBytes * sizeof(uint8_t);
3539
3540       controlRSet->frequencyDomainResources.buf = NULLP;
3541       DU_ALLOC(controlRSet->frequencyDomainResources.buf, controlRSet->frequencyDomainResources.size);
3542       if(!controlRSet->frequencyDomainResources.buf)
3543       {
3544          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3545          return RFAILED;
3546       }
3547
3548       memset(controlRSet->frequencyDomainResources.buf, 0, FREQ_DOM_RSRC_SIZE);
3549
3550       if(pdcchCfg == NULLP)
3551       {
3552          coreset0EndPrb = CORESET0_END_PRB;
3553          coreset1StartPrb = coreset0EndPrb + 6;
3554          coreset1NumPrb = CORESET1_NUM_PRB;
3555          /* calculate the PRBs */
3556          fillCoresetFeqDomAllocMap(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
3557          memcpy(controlRSet->frequencyDomainResources.buf, freqDomainResource, FREQ_DOM_RSRC_SIZE);
3558          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3559
3560          controlRSet->duration = PDCCH_CTRL_RSRC_SET_ONE_DURATION;
3561          controlRSet->cce_REG_MappingType.present = ControlResourceSet__cce_REG_MappingType_PR_nonInterleaved;
3562          controlRSet->precoderGranularity = PDCCH_CTRL_RSRC_SET_ONE_PRECOD_GRANULARITY;
3563       }
3564       else
3565       {
3566          memcpy(controlRSet->frequencyDomainResources.buf, pdcchCfg->cRSetToAddModList[idx].freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
3567          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3568          controlRSet->duration = pdcchCfg->cRSetToAddModList[idx].duration;
3569          controlRSet->cce_REG_MappingType.present = pdcchCfg->cRSetToAddModList[idx].cceRegMappingType;
3570          controlRSet->precoderGranularity = pdcchCfg->cRSetToAddModList[idx].precoderGranularity;
3571       }
3572       controlRSet->tci_StatesPDCCH_ToAddList = NULLP;
3573       controlRSet->tci_StatesPDCCH_ToReleaseList = NULLP;
3574       controlRSet->tci_PresentInDCI = NULLP;
3575
3576 #if 0
3577       uint8_t tciStateIdx;
3578
3579       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList, \
3580             sizeof(struct ControlResourceSet__tci_StatesPDCCH_ToAddList));
3581       if(!controlRset->tci_StatesPDCCH_ToAddList)
3582       {
3583          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3584          return RFAILED;
3585       }
3586
3587       elementCnt = 1;
3588       controlRset->tci_StatesPDCCH_ToAddList->list.count = elementCnt;
3589       controlRset->tci_StatesPDCCH_ToAddList->list.size = elementCnt * sizeof(TCI_StateId_t *);
3590       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array, \
3591             controlRset->tci_StatesPDCCH_ToAddList->list.size)
3592          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array)
3593          {
3594             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3595             return RFAILED;
3596          }
3597
3598       for(tciStateIdx = 0; tciStateIdx <elementCntl; tciStateIdx++)
3599       {
3600          DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx], sizeof(TCI_StateId_t));
3601          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx])
3602          {
3603             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3604             return RFAILED;
3605          }
3606       }
3607
3608       tciStateIdx = 0;
3609       /* TODO */
3610       *(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx]);
3611
3612       DU_ALLOC(controlRset->tci_PresentInDCI, sizeof(long));
3613       if(!controlRset->tci_PresentInDCI)
3614       {
3615          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3616          return RFAILED;
3617       }
3618       /* TODO */
3619       *(controlRset->tci_PresentInDCI);
3620 #endif
3621
3622       controlRSet->pdcch_DMRS_ScramblingID = NULLP;
3623       DU_ALLOC(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
3624       if(!controlRSet->pdcch_DMRS_ScramblingID)
3625       {
3626          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3627          return RFAILED;
3628       }
3629       if(pdcchCfg == NULLP)
3630          *(controlRSet->pdcch_DMRS_ScramblingID) = SCRAMBLING_ID;
3631       else
3632          *(controlRSet->pdcch_DMRS_ScramblingID) = pdcchCfg->cRSetToAddModList[idx].dmrsScramblingId;
3633    }
3634    return ROK;
3635 } /* End BuildControlRSetToAddModList */
3636
3637 /*******************************************************************
3638  *
3639  * @brief Build search space to add/modify list
3640  *
3641  * @details
3642  *
3643  *    Function : BuildSearchSpcToAddModList
3644  *
3645  *    Functionality: Build search space to add/modify list
3646  *
3647  * @params[in] 
3648  * @return ROK     - success
3649  *         RFAILED - failure
3650  *
3651  * ****************************************************************/
3652 uint8_t BuildSearchSpcToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
3653 {
3654    uint8_t idx;
3655    uint8_t numBytes;
3656    uint8_t byteIdx;
3657    uint8_t bitsUnused;
3658    uint8_t elementCnt;
3659    struct SearchSpace *searchSpc;
3660
3661    if(pdcchCfg == NULLP)
3662       elementCnt = 1;
3663    else
3664       elementCnt = pdcchCfg->numSearchSpcToAddMod;
3665
3666    searchSpcList->list.count = elementCnt;
3667    searchSpcList->list.size = elementCnt * sizeof(struct SearchSpace *);
3668
3669    searchSpcList->list.array = NULLP;
3670    DU_ALLOC(searchSpcList->list.array, searchSpcList->list.size);
3671    if(!searchSpcList->list.array)
3672    {
3673       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3674       return RFAILED;
3675    }
3676
3677    for(idx = 0; idx < elementCnt; idx++)
3678    {
3679       searchSpcList->list.array[idx] = NULLP;
3680       DU_ALLOC(searchSpcList->list.array[idx], sizeof(struct SearchSpace));
3681       if(!searchSpcList->list.array[idx])
3682       {
3683          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3684          return RFAILED;
3685       }
3686    }
3687
3688    for(idx = 0; idx < elementCnt; idx++)
3689    {
3690       searchSpc = searchSpcList->list.array[idx];
3691
3692       if(pdcchCfg == NULLP)
3693          searchSpc->searchSpaceId = PDCCH_SRCH_SPC_TWO_ID;
3694       else
3695          searchSpc->searchSpaceId = pdcchCfg->searchSpcToAddModList[idx].searchSpaceId;
3696
3697       searchSpc->controlResourceSetId = NULLP;
3698       DU_ALLOC(searchSpc->controlResourceSetId, sizeof(ControlResourceSetId_t));
3699       if(!searchSpc->controlResourceSetId)
3700       {
3701          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3702          return RFAILED;
3703       }
3704       if(pdcchCfg == NULLP)
3705          *(searchSpc->controlResourceSetId) = PDCCH_CTRL_RSRC_SET_ONE_ID;
3706       else
3707          *(searchSpc->controlResourceSetId) = pdcchCfg->searchSpcToAddModList[idx].cRSetId;
3708
3709       searchSpc->monitoringSlotPeriodicityAndOffset = NULLP;
3710       DU_ALLOC(searchSpc->monitoringSlotPeriodicityAndOffset, sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
3711       if(!searchSpc->monitoringSlotPeriodicityAndOffset)
3712       {
3713          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3714          return RFAILED;
3715       }
3716       if(pdcchCfg == NULLP)
3717          searchSpc->monitoringSlotPeriodicityAndOffset->present = SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
3718       else
3719          searchSpc->monitoringSlotPeriodicityAndOffset->present = pdcchCfg->searchSpcToAddModList[idx].mSlotPeriodicityAndOffset;
3720
3721       searchSpc->duration = NULLP;
3722       searchSpc->monitoringSymbolsWithinSlot = NULLP;
3723       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot, sizeof(BIT_STRING_t));
3724       if(!searchSpc->monitoringSymbolsWithinSlot)
3725       {
3726          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3727          return RFAILED;
3728       }
3729
3730       /* Values taken from reference logs :
3731        * size 2 bytes
3732        * 2 LSBs unsued
3733        * Bit string stores 8000
3734        */
3735       numBytes = 2;
3736       bitsUnused = 2;
3737       searchSpc->monitoringSymbolsWithinSlot->size = numBytes * sizeof(uint8_t);
3738       searchSpc->monitoringSymbolsWithinSlot->buf = NULLP;
3739       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot->buf, searchSpc->monitoringSymbolsWithinSlot->size);
3740       if(!searchSpc->monitoringSymbolsWithinSlot->buf)
3741       {
3742          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3743          return RFAILED;
3744       }
3745       if(pdcchCfg == NULLP)
3746       {
3747          byteIdx = 0;
3748          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = PDCCH_SYMBOL_WITHIN_SLOT /* setting MSB to 128 i.e. 0x80 */;
3749          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = 0;
3750       }
3751       else
3752          memcpy(searchSpc->monitoringSymbolsWithinSlot->buf, pdcchCfg->searchSpcToAddModList[idx].mSymbolsWithinSlot, numBytes);
3753       searchSpc->monitoringSymbolsWithinSlot->bits_unused = bitsUnused;
3754
3755       searchSpc->nrofCandidates = NULLP;
3756       DU_ALLOC(searchSpc->nrofCandidates, sizeof(struct SearchSpace__nrofCandidates));
3757       if(!searchSpc->nrofCandidates)
3758       {
3759          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3760          return RFAILED;
3761       }
3762
3763       if(pdcchCfg == NULLP)
3764       {
3765          searchSpc->nrofCandidates->aggregationLevel1 = PDCCH_SRCH_SPC_TWO_AGG_LVL1_CANDIDATE;
3766          searchSpc->nrofCandidates->aggregationLevel2 = PDCCH_SRCH_SPC_TWO_AGG_LVL2_CANDIDATE;
3767          searchSpc->nrofCandidates->aggregationLevel4 = PDCCH_SRCH_SPC_TWO_AGG_LVL4_CANDIDATE;
3768          searchSpc->nrofCandidates->aggregationLevel8 = PDCCH_SRCH_SPC_TWO_AGG_LVL8_CANDIDATE;
3769          searchSpc->nrofCandidates->aggregationLevel16 = PDCCH_SRCH_SPC_TWO_AGG_LVL16_CANDIDATE;
3770       }
3771       else
3772       {
3773          searchSpc->nrofCandidates->aggregationLevel1 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel1;
3774          searchSpc->nrofCandidates->aggregationLevel2 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel2;
3775          searchSpc->nrofCandidates->aggregationLevel4 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel4;
3776          searchSpc->nrofCandidates->aggregationLevel8 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel8;
3777          searchSpc->nrofCandidates->aggregationLevel16 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel16;
3778       }
3779
3780       searchSpc->searchSpaceType = NULLP;
3781       DU_ALLOC(searchSpc->searchSpaceType, sizeof(struct SearchSpace__searchSpaceType));
3782       if(!searchSpc->searchSpaceType)
3783       {
3784          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3785          return RFAILED;
3786       }
3787       if(pdcchCfg == NULLP)
3788          searchSpc->searchSpaceType->present = SearchSpace__searchSpaceType_PR_ue_Specific;
3789       else
3790          searchSpc->searchSpaceType->present = pdcchCfg->searchSpcToAddModList[idx].searchSpaceType;
3791
3792       searchSpc->searchSpaceType->choice.ue_Specific = NULLP;
3793       DU_ALLOC(searchSpc->searchSpaceType->choice.ue_Specific, sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
3794       if(!searchSpc->searchSpaceType->choice.ue_Specific)
3795       {
3796          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3797          return RFAILED;
3798       }  
3799       if(pdcchCfg == NULLP)
3800          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
3801       else
3802          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = pdcchCfg->searchSpcToAddModList[idx].ueSpecificDciFormat;
3803    }
3804    return ROK;
3805 }/* End BuildSearchSpcToAddModList */
3806
3807 /*******************************************************************
3808  *
3809  * @brief Builds BWP DL dedicated PDCCH config
3810  *
3811  * @details
3812  *
3813  *    Function : BuildBWPDlDedPdcchCfg
3814  *
3815  *    Functionality: Builds BWP DL dedicated PDCCH config
3816  *
3817  * @params[in] struct PDCCH_Config *pdcchCfg
3818  *
3819  * @return ROK     - success
3820  *         RFAILED - failure
3821  *
3822  * ****************************************************************/
3823 uint8_t BuildBWPDlDedPdcchCfg(PdcchConfig *pdcchCfgDb, struct PDCCH_Config *pdcchCfg)
3824 {
3825    pdcchCfg->controlResourceSetToAddModList = NULLP;
3826    DU_ALLOC(pdcchCfg->controlResourceSetToAddModList, sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
3827    if(!pdcchCfg->controlResourceSetToAddModList)
3828    {
3829       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
3830       return RFAILED;
3831    }
3832
3833    if(BuildControlRSetToAddModList(pdcchCfgDb, pdcchCfg->controlResourceSetToAddModList) != ROK)
3834    {
3835       DU_LOG("\nERROR  --> F1AP : Failed in BuildControlRSetToAddModList()");
3836       return RFAILED;
3837    }
3838
3839    pdcchCfg->controlResourceSetToReleaseList = NULLP;
3840
3841    pdcchCfg->searchSpacesToAddModList = NULLP;
3842    DU_ALLOC(pdcchCfg->searchSpacesToAddModList, sizeof(struct PDCCH_Config__searchSpacesToAddModList));
3843    if(!pdcchCfg->searchSpacesToAddModList)
3844    {
3845       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
3846       return RFAILED;
3847    }
3848
3849    if(BuildSearchSpcToAddModList(pdcchCfgDb, pdcchCfg->searchSpacesToAddModList) != ROK)
3850    {
3851       DU_LOG("\nERROR  --> F1AP : Failed in BuildSearchSpcToAddModList()");
3852       return RFAILED;
3853    }
3854
3855    pdcchCfg->searchSpacesToReleaseList = NULLP;
3856    pdcchCfg->downlinkPreemption = NULLP;
3857    pdcchCfg->tpc_PUSCH = NULLP;
3858    pdcchCfg->tpc_PUCCH = NULLP;
3859    pdcchCfg->tpc_SRS = NULLP;
3860
3861    return ROK;
3862 }
3863
3864 /*******************************************************************
3865  *
3866  * @brief Builds DMRS DL PDSCH Mapping type A
3867  *
3868  * @details
3869  *
3870  *    Function : BuildDMRSDLPdschMapTypeA
3871  *
3872  *    Functionality: Builds DMRS DL PDSCH Mapping type A
3873  *
3874  * @params[in]
3875  * struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg
3876  * @return ROK     - success
3877  *         RFAILED - failure
3878  *
3879  * ****************************************************************/
3880 uint8_t BuildDMRSDLPdschMapTypeA(PdschConfig *pdschCfg, struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg)
3881 {
3882    dmrsDlCfg->present = PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup;
3883    dmrsDlCfg->choice.setup = NULLP;
3884    DU_ALLOC(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
3885    if(!dmrsDlCfg->choice.setup)
3886    {
3887       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
3888       return RFAILED;
3889    }
3890
3891    dmrsDlCfg->choice.setup->dmrs_Type = NULLP;
3892    dmrsDlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
3893    DU_ALLOC(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
3894    if(!dmrsDlCfg->choice.setup->dmrs_AdditionalPosition)
3895    {
3896       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
3897       return RFAILED;
3898    }
3899    if(pdschCfg == NULLP)
3900       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS;
3901    else
3902       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = pdschCfg->dmrsDlCfgForPdschMapTypeA.addPos;
3903
3904    dmrsDlCfg->choice.setup->maxLength = NULLP;
3905    dmrsDlCfg->choice.setup->scramblingID0 = NULLP;
3906    dmrsDlCfg->choice.setup->scramblingID1 = NULLP;
3907    dmrsDlCfg->choice.setup->phaseTrackingRS = NULLP;
3908
3909    return ROK;
3910 }
3911
3912 /*******************************************************************
3913  *
3914  * @brief Builds TCI states to add/modify list
3915  *
3916  * @details
3917  *
3918  *    Function : BuildTCIStatesToAddModList
3919  *
3920  *    Functionality:Builds TCI states to add/modify list
3921  *
3922  * @params[in] 
3923  * struct PDSCH_Config__tci_StatesToAddModList *tciStatesList
3924  *
3925  * @return ROK     - success
3926  *         RFAILED - failure
3927  *
3928  * ****************************************************************/
3929 uint8_t BuildTCIStatesToAddModList(struct PDSCH_Config__tci_StatesToAddModList *tciStatesList)
3930 {
3931    return ROK;
3932 }
3933
3934 /*******************************************************************
3935  *
3936  * @brief Builds PDSCH time domain allocation list
3937  *
3938  * @details
3939  *
3940  *    Function : BuildPdschTimeDomAllocList
3941  *
3942  *    Functionality: Builds PDSCH time domain allocation list
3943  *
3944  * @params[in] 
3945  * struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
3946  *
3947  * @return ROK     - success
3948  *         RFAILED - failure
3949  *
3950  * ****************************************************************/
3951 uint8_t BuildPdschTimeDomAllocList(PdschConfig *pdschCfg, struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
3952 {
3953    uint8_t idx;
3954    uint8_t elementCnt;
3955    struct PDSCH_TimeDomainResourceAllocation *timeDomAlloc;
3956
3957    timeDomAllocList->present = PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup;
3958
3959    timeDomAllocList->choice.setup = NULLP;
3960    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PDSCH_TimeDomainResourceAllocationList));
3961    if(!timeDomAllocList->choice.setup)
3962    {
3963       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
3964       return RFAILED;
3965    }
3966
3967 if(pdschCfg == NULLP)
3968    elementCnt = 2;
3969 else
3970 elementCnt = pdschCfg->numTimeDomRsrcAlloc;
3971    timeDomAllocList->choice.setup->list.count = elementCnt;
3972    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(struct PDSCH_TimeDomainResourceAllocation *);
3973
3974    timeDomAllocList->choice.setup->list.array = NULLP;
3975    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
3976    if(!timeDomAllocList->choice.setup->list.array)
3977    {
3978       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
3979       return RFAILED;
3980    }
3981
3982    for(idx = 0; idx < elementCnt; idx++)
3983    {
3984       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
3985       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], \
3986             sizeof(struct PDSCH_TimeDomainResourceAllocation));
3987       if(!timeDomAllocList->choice.setup->list.array[idx])
3988       {
3989          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
3990          return RFAILED;
3991       }
3992    }
3993
3994    if(pdschCfg == NULLP)
3995    {
3996       idx = 0;
3997       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
3998       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
3999       if(!timeDomAlloc->k0)
4000       {
4001          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4002          return RFAILED;
4003       }
4004       *(timeDomAlloc->k0) = 0;
4005       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4006       timeDomAlloc->startSymbolAndLength = \
4007                                            calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4008
4009       idx++;
4010       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4011       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4012       if(!timeDomAlloc->k0)
4013       {
4014          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4015          return RFAILED;
4016       }
4017       *(timeDomAlloc->k0) = 1;
4018       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4019       timeDomAlloc->startSymbolAndLength = calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4020    }
4021    else
4022    {
4023       for(idx = 0; idx < elementCnt; idx++)
4024       {
4025          timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4026          DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4027          if(!timeDomAlloc->k0)
4028          {
4029             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4030             return RFAILED;
4031          }
4032          if(pdschCfg->timeDomRsrcAllociList[idx].k0)
4033             *(timeDomAlloc->k0) = *(pdschCfg->timeDomRsrcAllociList[idx].k0);
4034          timeDomAlloc->mappingType = pdschCfg->timeDomRsrcAllociList[idx].mappingType;
4035          timeDomAlloc->startSymbolAndLength = pdschCfg->timeDomRsrcAllociList[idx].startSymbolAndLength;
4036       }
4037    }
4038
4039    return ROK;
4040 }
4041
4042 /*******************************************************************
4043  *
4044  * @brief Builds PDSCH PRB Bundling type
4045  *
4046  * @details
4047  *
4048  *    Function : BuildPdschPrbBundlingType
4049  *
4050  *    Functionality: Builds PDSCH PRB Bundling type
4051  *
4052  * @params[in] 
4053  * struct PDSCH_Config__prb_BundlingType *prbBndlType
4054  *
4055  * @return ROK     - success
4056  *         RFAILED - failure
4057  *
4058  * ****************************************************************/
4059 uint8_t BuildPdschPrbBundlingType(PdschConfig *pdschCfg, struct PDSCH_Config__prb_BundlingType *prbBndlType)
4060 {
4061    if(pdschCfg == NULLP)
4062       prbBndlType->present = PDSCH_Config__prb_BundlingType_PR_staticBundling;
4063    else
4064       prbBndlType->present = pdschCfg->bundlingType;
4065
4066    prbBndlType->choice.staticBundling = NULLP;
4067    DU_ALLOC(prbBndlType->choice.staticBundling, \
4068          sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
4069    if(!prbBndlType->choice.staticBundling)
4070    {
4071       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschPrbBundlingType");
4072       return RFAILED;
4073    }
4074    prbBndlType->choice.staticBundling->bundleSize = NULLP;
4075
4076    return ROK;
4077 }
4078
4079 /*******************************************************************
4080  *
4081  * @brief Builds BWP DL dedicated PDSCH config 
4082  *
4083  * @details
4084  *
4085  *    Function : BuildBWPDlDedPdschCfg
4086  *
4087  *    Functionality: Builds BWP DL dedicated PDSCH config
4088  *
4089  * @params[in] struct PDSCH_Config *pdschCfg
4090  *
4091  * @return ROK     - success
4092  *         RFAILED - failure
4093  *
4094  * ****************************************************************/
4095 uint8_t BuildBWPDlDedPdschCfg(PdschConfig *pdschCfgDb, struct PDSCH_Config *pdschCfg)
4096 {
4097    pdschCfg->dataScramblingIdentityPDSCH = NULLP;
4098
4099    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA = NULLP;
4100    DU_ALLOC(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
4101    if(!pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
4102    {
4103       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4104       return RFAILED;
4105    }
4106
4107    if(BuildDMRSDLPdschMapTypeA(pdschCfgDb, pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA) != ROK)
4108    {
4109       return RFAILED;
4110    }
4111
4112    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeB = NULLP;
4113    pdschCfg->tci_StatesToAddModList = NULLP;
4114    pdschCfg->tci_StatesToReleaseList = NULLP;
4115    pdschCfg->vrb_ToPRB_Interleaver = NULLP;
4116 #if 0
4117    DU_ALLOC(pdschCfg->tci_StatesToAddModList, sizeof(struct PDSCH_Config__tci_StatesToAddModList));
4118    if(!pdschCfg->tci_StatesToAddModList)
4119    {
4120       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4121       return RFAILED;
4122    }
4123    if(BuildTCIStatesToAddModList(pdschCfg->tci_StatesToAddModList) != ROK)
4124    {
4125       return RFAILED;
4126    }
4127 #endif
4128
4129 if(pdschCfgDb == NULLP)
4130    pdschCfg->resourceAllocation = RES_ALLOC_TYPE;
4131 else
4132 pdschCfg->resourceAllocation = pdschCfgDb->resourceAllocType;
4133
4134    pdschCfg->pdsch_TimeDomainAllocationList = NULLP;
4135    DU_ALLOC(pdschCfg->pdsch_TimeDomainAllocationList, sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
4136    if(!pdschCfg->pdsch_TimeDomainAllocationList)
4137    {
4138       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4139       return RFAILED;
4140    }
4141    if(BuildPdschTimeDomAllocList(pdschCfgDb, pdschCfg->pdsch_TimeDomainAllocationList) != ROK)
4142    {
4143       return RFAILED;
4144    }
4145
4146    pdschCfg->pdsch_AggregationFactor = NULLP;
4147    pdschCfg->rateMatchPatternToAddModList = NULLP;
4148    pdschCfg->rateMatchPatternToReleaseList = NULLP;
4149    pdschCfg->rateMatchPatternGroup1 = NULLP;
4150    pdschCfg->rateMatchPatternGroup2 = NULLP;
4151    if(pdschCfgDb == NULLP)
4152       pdschCfg->rbg_Size = PDSCH_RBG_SIZE;
4153    else
4154       pdschCfg->rbg_Size = pdschCfgDb->rbgSize;
4155    pdschCfg->mcs_Table = NULLP;
4156
4157    pdschCfg->maxNrofCodeWordsScheduledByDCI = NULLP;
4158    DU_ALLOC(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
4159    if(!pdschCfg->maxNrofCodeWordsScheduledByDCI)
4160    {
4161       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4162       return RFAILED;
4163    }
4164    if(pdschCfgDb == NULLP)
4165       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = PDSCH_MAX_CODEWORD_SCH_BY_DCI;
4166    else
4167       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = pdschCfgDb->numCodeWordsSchByDci;
4168
4169    if(BuildPdschPrbBundlingType(pdschCfgDb, &pdschCfg->prb_BundlingType) != ROK)
4170    {
4171       return RFAILED;
4172    }
4173
4174    pdschCfg->zp_CSI_RS_ResourceToAddModList = NULLP;
4175    pdschCfg->zp_CSI_RS_ResourceToReleaseList = NULLP;
4176    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4177    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4178    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4179    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4180    pdschCfg->p_ZP_CSI_RS_ResourceSet = NULLP;
4181
4182    return ROK;
4183 }
4184
4185 /*******************************************************************
4186  *
4187  * @brief Builds intitial DL BWP
4188  * @details
4189  *
4190  *    Function : BuildInitialDlBWP 
4191  *
4192  *    Functionality: Builds intitial DL BWP in spCellCfgDed
4193  *
4194  * @params[in] BWP_DownlinkDedicated_t *dlBwp
4195  *
4196  * @return ROK     - success
4197  *         RFAILED - failure
4198  *
4199  * ****************************************************************/
4200 uint8_t BuildInitialDlBWP(InitialDlBwp *initiDlBwp, BWP_DownlinkDedicated_t *dlBwp)
4201 {
4202    PdcchConfig *pdcchCfg = NULLP;
4203    PdschConfig *pdschCfg = NULLP;
4204
4205    if(initiDlBwp)
4206    {
4207       if(initiDlBwp->pdcchPresent)
4208          pdcchCfg = &initiDlBwp->pdcchCfg;
4209       if(initiDlBwp->pdschPresent)
4210          pdschCfg = &initiDlBwp->pdschCfg;
4211    }
4212
4213    dlBwp->pdcch_Config = NULLP;
4214    DU_ALLOC(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
4215    if(!dlBwp->pdcch_Config)
4216    {
4217       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4218       return RFAILED;
4219    }
4220    dlBwp->pdcch_Config->present = BWP_DownlinkDedicated__pdcch_Config_PR_setup; 
4221
4222    dlBwp->pdcch_Config->choice.setup = NULLP;
4223    DU_ALLOC(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
4224    if(!dlBwp->pdcch_Config->choice.setup)
4225    {
4226       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4227       return RFAILED;
4228    }
4229    if(BuildBWPDlDedPdcchCfg(pdcchCfg, dlBwp->pdcch_Config->choice.setup) != ROK)
4230    {
4231       return RFAILED;
4232    }
4233
4234    dlBwp->pdsch_Config = NULLP;
4235    DU_ALLOC(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
4236    if(!dlBwp->pdsch_Config)
4237    {
4238       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4239       return RFAILED;
4240    }
4241    dlBwp->pdsch_Config->present = BWP_DownlinkDedicated__pdsch_Config_PR_setup;
4242
4243    dlBwp->pdsch_Config->choice.setup = NULLP;
4244    DU_ALLOC(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
4245    if(!dlBwp->pdsch_Config->choice.setup)
4246    {
4247       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4248       return RFAILED;
4249    }
4250
4251    if(BuildBWPDlDedPdschCfg(pdschCfg, dlBwp->pdsch_Config->choice.setup) != ROK)
4252    {
4253       return RFAILED;
4254    }
4255
4256    dlBwp->sps_Config = NULLP;
4257    dlBwp->radioLinkMonitoringConfig = NULLP; 
4258    return ROK;
4259 }
4260
4261 /*******************************************************************
4262  *
4263  * @brief Builds DMRS UL Pusch Mapping type A
4264  *
4265  * @details
4266  *
4267  *    Function : BuildDMRSULPuschMapTypeA
4268  *
4269  *    Functionality: Builds DMRS UL Pusch Mapping type A
4270  *
4271  * @params[in] 
4272  *    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg
4273  * @return ROK     - success
4274  *         RFAILED - failure
4275  *
4276  * ****************************************************************/
4277 uint8_t BuildDMRSULPuschMapTypeA(DmrsUlCfg *ulDmrsCfgDb, struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg)
4278 {
4279    dmrsUlCfg->present = PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup;
4280    dmrsUlCfg->choice.setup= NULLP;
4281    DU_ALLOC(dmrsUlCfg->choice.setup, sizeof(DMRS_UplinkConfig_t));
4282    if(!dmrsUlCfg->choice.setup)
4283    {
4284       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4285       return RFAILED;
4286    }
4287
4288    dmrsUlCfg->choice.setup->dmrs_Type = NULLP;
4289    dmrsUlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4290    DU_ALLOC(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4291    if(!dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
4292    {
4293       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4294       return RFAILED;
4295    }
4296    if(ulDmrsCfgDb == NULLP)
4297       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS; 
4298    else
4299       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = ulDmrsCfgDb->addPos;
4300
4301    dmrsUlCfg->choice.setup->phaseTrackingRS = NULLP;
4302    dmrsUlCfg->choice.setup->maxLength = NULLP;
4303    dmrsUlCfg->choice.setup->transformPrecodingDisabled = NULLP;
4304    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled, sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
4305    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled)
4306    {
4307       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4308       return RFAILED;
4309    }
4310
4311    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0 = NULLP;
4312    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
4313          sizeof(long));
4314    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0)
4315    {
4316       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4317       return RFAILED;
4318    }
4319    if(ulDmrsCfgDb == NULLP)
4320       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = SCRAMBLING_ID;
4321    else
4322       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = ulDmrsCfgDb->transPrecodDisabled.scramblingId0;
4323
4324    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID1 = NULLP;
4325    dmrsUlCfg->choice.setup->transformPrecodingEnabled = NULLP;
4326    return ROK;
4327 }
4328
4329 /*******************************************************************
4330  *
4331  * @brief Build PUSCH time domain allocation list
4332  *
4333  * @details
4334  *
4335  *    Function : BuildPuschTimeDomAllocList
4336  *
4337  *    Functionality: Build PUSCH time domain allocation list
4338  *
4339  * @params[in] 
4340  * struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList
4341  *
4342  * @return ROK     - success
4343  *         RFAILED - failure
4344  *
4345  * ****************************************************************/
4346 uint8_t BuildPuschTimeDomAllocList(PuschCfg *puschCfgDb, struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList)
4347 {
4348    uint8_t idx;
4349    uint8_t elementCnt;
4350    PUSCH_TimeDomainResourceAllocation_t  *timeDomAlloc;
4351
4352    timeDomAllocList->present = PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup;
4353    timeDomAllocList->choice.setup = NULLP;
4354    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PUSCH_TimeDomainResourceAllocationList));
4355    if(!timeDomAllocList->choice.setup)
4356    {
4357       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4358       return RFAILED;
4359    }
4360
4361    if(puschCfgDb == NULLP)
4362       elementCnt = 2;
4363    else
4364       elementCnt = puschCfgDb->numTimeDomRsrcAlloc;
4365
4366    timeDomAllocList->choice.setup->list.count = elementCnt;
4367    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(PUSCH_TimeDomainResourceAllocation_t *);
4368    timeDomAllocList->choice.setup->list.array = NULLP;
4369    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4370    if(!timeDomAllocList->choice.setup->list.array)
4371    {
4372       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4373       return RFAILED;
4374    }
4375
4376    for(idx = 0; idx < elementCnt; idx++)
4377    {
4378       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4379       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], sizeof(PUSCH_TimeDomainResourceAllocation_t));
4380       if(!timeDomAllocList->choice.setup->list.array[idx])
4381       {
4382          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4383          return RFAILED;
4384       }
4385    }
4386
4387    for(idx = 0; idx < elementCnt; idx++)
4388    {
4389       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4390       DU_ALLOC(timeDomAlloc->k2, sizeof(long));
4391       if(!timeDomAlloc->k2)
4392       {
4393          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4394          return RFAILED;
4395       }
4396       if(puschCfgDb == NULLP)
4397       {
4398          if(idx == 0)
4399             *(timeDomAlloc->k2) = PUSCH_K2_CFG1;
4400          else if(idx == 1)
4401             *(timeDomAlloc->k2) = PUSCH_K2_CFG2;
4402
4403          timeDomAlloc->mappingType = PUSCH_MAPPING_TYPE_A;
4404          timeDomAlloc->startSymbolAndLength = calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
4405       }
4406       else
4407       {
4408          *(timeDomAlloc->k2) = puschCfgDb->timeDomRsrcAllocList[idx].k2;
4409          timeDomAlloc->mappingType = puschCfgDb->timeDomRsrcAllocList[idx].mappingType;
4410          timeDomAlloc->startSymbolAndLength = puschCfgDb->timeDomRsrcAllocList[idx].startSymbolAndLength;
4411       }
4412    }
4413
4414    return ROK;
4415 }
4416
4417 /*******************************************************************
4418  *
4419  * @brief Builds BWP UL dedicated PUSCH Config
4420  *
4421  * @details
4422  *
4423  *    Function : BuildBWPUlDedPuschCfg
4424  *
4425  *    Functionality:
4426  *      Builds BWP UL dedicated PUSCH Config
4427  *
4428  * @params[in] : PUSCH_Config_t *puschCfg
4429  *    
4430  * @return ROK     - success
4431  *         RFAILED - failure
4432  *
4433  * ****************************************************************/
4434 uint8_t BuildBWPUlDedPuschCfg(PuschCfg *puschCfgDb, PUSCH_Config_t *puschCfg)
4435 {
4436    DmrsUlCfg *ulDmrsCfg = NULLP;
4437    
4438    if(puschCfgDb)
4439       ulDmrsCfg = &puschCfgDb->dmrsUlCfgForPuschMapTypeA;
4440
4441    puschCfg->dataScramblingIdentityPUSCH = NULLP;
4442    DU_ALLOC(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
4443    if(!puschCfg->dataScramblingIdentityPUSCH)
4444    {
4445       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4446       return RFAILED;
4447    }
4448    if(puschCfgDb == NULLP)
4449       *(puschCfg->dataScramblingIdentityPUSCH) = SCRAMBLING_ID;
4450    else
4451       *(puschCfg->dataScramblingIdentityPUSCH) = puschCfgDb->dataScramblingId;
4452
4453    puschCfg->txConfig = NULLP;
4454    puschCfg->dmrs_UplinkForPUSCH_MappingTypeA = NULLP;
4455    DU_ALLOC(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
4456    if(!puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
4457    {
4458       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4459       return RFAILED;
4460    }
4461
4462    if(BuildDMRSULPuschMapTypeA(ulDmrsCfg, puschCfg->dmrs_UplinkForPUSCH_MappingTypeA) != ROK)
4463    {
4464       return RFAILED;
4465    }
4466
4467    puschCfg->dmrs_UplinkForPUSCH_MappingTypeB = NULLP;
4468    puschCfg->pusch_PowerControl = NULLP;
4469    puschCfg->frequencyHopping = NULLP;
4470    puschCfg->frequencyHoppingOffsetLists = NULLP;
4471
4472    if(puschCfgDb == NULLP)
4473       puschCfg->resourceAllocation = RES_ALLOC_TYPE;
4474    else
4475       puschCfg->resourceAllocation = puschCfgDb->resourceAllocType;
4476
4477    puschCfg->pusch_TimeDomainAllocationList = NULLP;
4478    DU_ALLOC(puschCfg->pusch_TimeDomainAllocationList, sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
4479    if(!puschCfg->pusch_TimeDomainAllocationList)
4480    {
4481       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4482       return RFAILED;
4483    }
4484
4485    if(BuildPuschTimeDomAllocList(puschCfgDb, puschCfg->pusch_TimeDomainAllocationList) != ROK)
4486    {
4487       return RFAILED;
4488    }
4489
4490    puschCfg->pusch_AggregationFactor = NULLP;
4491    puschCfg->mcs_Table = NULLP;
4492    puschCfg->mcs_TableTransformPrecoder = NULLP;
4493    puschCfg->transformPrecoder = NULLP;
4494    DU_ALLOC(puschCfg->transformPrecoder, sizeof(long));
4495    if(!puschCfg->transformPrecoder)
4496    {
4497       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4498       return RFAILED;
4499    }
4500    if(puschCfgDb == NULLP)
4501       *(puschCfg->transformPrecoder) = PUSCH_TRANSFORM_PRECODER;
4502    else
4503       *(puschCfg->transformPrecoder) = puschCfgDb->transformPrecoder;
4504
4505    puschCfg->codebookSubset = NULLP;
4506    puschCfg->maxRank = NULLP;
4507    puschCfg->rbg_Size = NULLP;
4508    puschCfg->uci_OnPUSCH = NULLP;
4509    puschCfg->tp_pi2BPSK = NULLP;
4510
4511    return ROK;
4512 }
4513
4514 /*******************************************************************
4515  *
4516  * @brief Builds PUCCH resource set add/modify list
4517  *
4518  * @details
4519  *
4520  *    Function : BuildPucchRsrcSetAddModList
4521  *
4522  *    Functionality:
4523  *      Builds PUCCH resource set add/modify list
4524  *
4525  * @params[in] : PucchResrcSetCfg *rsrcSetCfgDb
4526  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4527  *
4528  * @return ROK     - success
4529  *         RFAILED - failure
4530  *
4531  * ****************************************************************/
4532 uint8_t BuildPucchRsrcSetAddModList(PucchResrcSetCfg *rsrcSetCfgDb, \
4533    struct PUCCH_Config__resourceSetToAddModList *resourceSetToAddModList)
4534 {
4535    uint8_t elementCnt = 0, rsrcSetIdx = 0, rsrcIdx = 0;
4536    PUCCH_ResourceSet_t *rsrcSet = NULLP;
4537
4538    if(rsrcSetCfgDb == NULLP)
4539       elementCnt = 1;
4540    else
4541       elementCnt = rsrcSetCfgDb->resrcSetToAddModListCount;
4542
4543    resourceSetToAddModList->list.count = elementCnt;
4544    resourceSetToAddModList->list.size = elementCnt * sizeof(PUCCH_ResourceSet_t *);
4545    DU_ALLOC(resourceSetToAddModList->list.array, resourceSetToAddModList->list.size);
4546    if(resourceSetToAddModList->list.array == NULLP)
4547    {
4548       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4549       return RFAILED;
4550    }
4551    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4552    {
4553       DU_ALLOC(resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
4554       if(resourceSetToAddModList->list.array[rsrcSetIdx] == NULLP)
4555       {
4556          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4557          return RFAILED;
4558       }
4559    }
4560
4561    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4562    {
4563       rsrcSet = resourceSetToAddModList->list.array[rsrcSetIdx];
4564
4565       /* Resource set Id */
4566       if(rsrcSetCfgDb == NULLP)
4567          rsrcSet->pucch_ResourceSetId = 1;
4568       else
4569          rsrcSet->pucch_ResourceSetId = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcSetId;
4570  
4571       /* Resource list of a resource set */
4572       if(rsrcSetCfgDb == NULLP)
4573          elementCnt = 1;
4574       else
4575          elementCnt = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcListCount;
4576       rsrcSet->resourceList.list.count = elementCnt;
4577       rsrcSet->resourceList.list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
4578       DU_ALLOC(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
4579       if(rsrcSet->resourceList.list.array == NULLP)
4580       {
4581          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4582          return RFAILED;
4583       }
4584
4585       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4586       {
4587          DU_ALLOC(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
4588          if(rsrcSet->resourceList.list.array[rsrcIdx] == NULLP)
4589          {
4590             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4591             return RFAILED;
4592          }
4593       }
4594       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4595       {
4596          if(rsrcSetCfgDb == NULLP)
4597             *(rsrcSet->resourceList.list.array[rsrcIdx]) = 1;
4598          else
4599             *(rsrcSet->resourceList.list.array[rsrcIdx]) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcList[rsrcIdx];
4600       }
4601
4602       /* Max payload size (minus 1) in a Resource set */
4603       rsrcSet->maxPayloadMinus1 = NULLP;
4604       if(rsrcSetCfgDb && rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize)
4605       {
4606          DU_ALLOC(rsrcSet->maxPayloadMinus1, sizeof(long));
4607          if(rsrcSet->maxPayloadMinus1 == NULLP)
4608          {
4609             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4610             return RFAILED;
4611          }
4612          *(rsrcSet->maxPayloadMinus1) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize;
4613       }
4614    }
4615    return ROK;
4616 }
4617
4618 /*******************************************************************
4619  *
4620  * @brief Builds PUCCH resource add/modify list
4621  *
4622  * @details
4623  *
4624  *    Function : BuildPucchRsrcAdddModList
4625  *
4626  *    Functionality:
4627  *      Builds PUCCH resource add/modify list
4628  *
4629  * @params[in] : PucchResrcCfg *rsrcSetCfgDb
4630  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4631  *
4632  * @return ROK     - success
4633  *         RFAILED - failure
4634  *
4635  * ****************************************************************/
4636 uint8_t BuildPucchRsrcAddModList(PucchResrcCfg *rsrcCfgDb, struct PUCCH_Config__resourceToAddModList  *resourceToAddModList)
4637 {
4638    uint8_t elementCnt = 0, rsrcIdx = 0;
4639    PUCCH_Resource_t *rsrc = NULLP;
4640
4641    if(rsrcCfgDb == NULLP)
4642       elementCnt = 1;
4643    else
4644       elementCnt = rsrcCfgDb->resrcToAddModListCount;
4645    resourceToAddModList->list.count = elementCnt;
4646    resourceToAddModList->list.size = elementCnt * sizeof(PUCCH_Resource_t *);
4647    DU_ALLOC(resourceToAddModList->list.array, resourceToAddModList->list.size);
4648    if(resourceToAddModList->list.array == NULLP)
4649    {
4650       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4651       return RFAILED;
4652    }
4653    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4654    {
4655       DU_ALLOC(resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
4656       if(resourceToAddModList->list.array[rsrcIdx] == NULLP)
4657       {
4658          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4659          return RFAILED;
4660       }
4661    }
4662
4663    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4664    {
4665       rsrc = resourceToAddModList->list.array[rsrcIdx];
4666
4667       if(rsrcCfgDb == NULLP)
4668       {
4669          rsrc->pucch_ResourceId = 1;
4670          rsrc->startingPRB = 0;
4671          rsrc->format.present = PUCCH_Resource__format_PR_format1; 
4672          DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4673          if(rsrc->format.choice.format1 == NULLP)
4674          {
4675             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4676             return RFAILED;
4677          }  
4678          rsrc->format.choice.format1->initialCyclicShift = 0;
4679          rsrc->format.choice.format1->nrofSymbols = 4;
4680          rsrc->format.choice.format1->startingSymbolIndex = 0;
4681          rsrc->format.choice.format1->timeDomainOCC = 0;
4682       }
4683       else
4684       {
4685          rsrc->pucch_ResourceId = rsrcCfgDb->resrcToAddModList[rsrcIdx].resrcId;
4686          rsrc->startingPRB = rsrcCfgDb->resrcToAddModList[rsrcIdx].startPrb;
4687          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop)
4688          {
4689             DU_ALLOC(rsrc->intraSlotFrequencyHopping, sizeof(long));
4690             if(rsrc->intraSlotFrequencyHopping == NULLP)
4691             {
4692                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4693                return RFAILED;
4694             }
4695             *(rsrc->intraSlotFrequencyHopping) = rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop;
4696          }
4697          else
4698             rsrc->intraSlotFrequencyHopping = NULLP;
4699
4700          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop)
4701          {
4702             DU_ALLOC(rsrc->secondHopPRB, sizeof(PRB_Id_t));
4703             if(rsrc->secondHopPRB == NULLP)
4704             {
4705                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4706                return RFAILED;
4707             }
4708             *(rsrc->secondHopPRB) = rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop;
4709          }
4710          else
4711             rsrc->secondHopPRB = NULLP;
4712          rsrc->format.present = covertPucchFormatIntEnumToRrcEnum(rsrcCfgDb->resrcToAddModList[rsrcIdx].pucchFormat); 
4713
4714          switch(rsrc->format.present)
4715          {
4716             case PUCCH_Resource__format_PR_NOTHING:
4717                break;
4718             case PUCCH_Resource__format_PR_format0:
4719                {
4720                   DU_ALLOC(rsrc->format.choice.format0, sizeof(PUCCH_format0_t));
4721                   if(rsrc->format.choice.format0 == NULLP)
4722                   {
4723                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4724                      return RFAILED;
4725                   }
4726                   rsrc->format.choice.format0->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->initialCyclicShift;
4727                   rsrc->format.choice.format0->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->numSymbols;
4728                   rsrc->format.choice.format0->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->startSymbolIdx;
4729                   break;
4730                }
4731
4732             case PUCCH_Resource__format_PR_format1:
4733                {
4734                   DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4735                   if(rsrc->format.choice.format1 == NULLP)
4736                   {
4737                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4738                      return RFAILED;
4739                   }  
4740                   rsrc->format.choice.format1->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->initialCyclicShift;
4741                   rsrc->format.choice.format1->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->numSymbols;
4742                   rsrc->format.choice.format1->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->startSymbolIdx;
4743                   rsrc->format.choice.format1->timeDomainOCC = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->timeDomOCC;
4744                   break;
4745                }
4746
4747             case PUCCH_Resource__format_PR_format2:
4748                {
4749                   DU_ALLOC(rsrc->format.choice.format2, sizeof(PUCCH_format2_t));
4750                   if(rsrc->format.choice.format2 == NULLP)
4751                   {
4752                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4753                      return RFAILED;
4754                   } 
4755                   rsrc->format.choice.format2->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numPrbs;
4756                   rsrc->format.choice.format2->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numSymbols;
4757                   rsrc->format.choice.format2->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->startSymbolIdx;
4758                   break;
4759                }
4760
4761             case PUCCH_Resource__format_PR_format3:
4762                {
4763                   DU_ALLOC(rsrc->format.choice.format3, sizeof(PUCCH_format3_t));
4764                   if(rsrc->format.choice.format3 == NULLP)
4765                   {
4766                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4767                      return RFAILED;
4768                   }
4769                   rsrc->format.choice.format3->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numPrbs;
4770                   rsrc->format.choice.format3->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numSymbols;
4771                   rsrc->format.choice.format3->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->startSymbolIdx;
4772                   break;
4773                }
4774
4775             case PUCCH_Resource__format_PR_format4:
4776                {
4777                   DU_ALLOC(rsrc->format.choice.format4, sizeof(PUCCH_format4_t));
4778                   if(rsrc->format.choice.format4 == NULLP)
4779                   {
4780                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4781                      return RFAILED;
4782                   }
4783                   rsrc->format.choice.format4->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->numSymbols;
4784                   rsrc->format.choice.format4->occ_Length = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occLen;
4785                   rsrc->format.choice.format4->occ_Index = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occIdx;
4786                   rsrc->format.choice.format4->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->startSymbolIdx;
4787                   break;
4788                }
4789          }
4790       }
4791    }
4792    return ROK;
4793 }
4794
4795 /*******************************************************************
4796  *
4797  * @brief Builds PUCCH format  config
4798  *
4799  * @details
4800  *
4801  *    Function : BuildPucchFormat
4802  *
4803  *    Functionality: Builds PUCCH format  config
4804  *
4805  * @params[in] : PucchFormatCfg *formatDb
4806  *               PUCCH_FormatConfig_t *format
4807  *
4808  * @return ROK     - success
4809  *         RFAILED - failure
4810  *
4811  * ****************************************************************/
4812 uint8_t BuildPucchFormat(PucchFormatCfg *formatDb, PUCCH_FormatConfig_t *format)
4813 {
4814    /* Inter Slot Fequency hopping */
4815    format->interslotFrequencyHopping = NULLP;
4816    if((formatDb != NULLP) && (formatDb->interSlotFreqHop == true))
4817    {
4818       DU_ALLOC(format->interslotFrequencyHopping, sizeof(long));
4819       if(format->interslotFrequencyHopping)
4820       {
4821          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4822          return RFAILED;
4823       }
4824       *(format->interslotFrequencyHopping) = PUCCH_FormatConfig__interslotFrequencyHopping_enabled;
4825    }
4826
4827    /* Additional DMRS */
4828    format->additionalDMRS = NULLP;
4829    if((formatDb != NULLP) && (formatDb->addDmrs == true))
4830    {
4831       DU_ALLOC(format->additionalDMRS, sizeof(long));
4832       if(format->additionalDMRS)
4833       {
4834          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4835          return RFAILED;
4836       }
4837       *(format->additionalDMRS) = PUCCH_FormatConfig__additionalDMRS_true;
4838    }
4839
4840     /* Maximum code rate */
4841    format->maxCodeRate = NULLP;
4842    if((formatDb != NULLP) && (formatDb->maxCodeRate != 0))
4843    {
4844       DU_ALLOC(format->maxCodeRate, sizeof(long));
4845       if(format->maxCodeRate)
4846       {
4847          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4848          return RFAILED;
4849       }  
4850       *(format->maxCodeRate) = formatDb->maxCodeRate;
4851    }
4852  
4853    /* Number of slots */
4854    format->nrofSlots = NULLP;
4855    if((formatDb == NULLP) || ((formatDb != NULLP) && (formatDb->numSlots != 0)))
4856    {
4857       DU_ALLOC(format->nrofSlots, sizeof(long));
4858       if(format->nrofSlots == NULLP)
4859       {
4860          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4861          return RFAILED;
4862       }
4863       if(formatDb == NULLP)
4864          *(format->nrofSlots) = PUCCH_FormatConfig__nrofSlots_n4;
4865       else
4866          *(format->nrofSlots) = formatDb->numSlots;
4867    }
4868
4869    /* Pi2BPSK*/
4870    format->pi2BPSK = NULLP;
4871    if((formatDb != NULLP) && (formatDb->pi2BPSK == true))
4872    {
4873       DU_ALLOC(format->pi2BPSK, sizeof(long));
4874       if(format->pi2BPSK)
4875       {     
4876          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4877          return RFAILED;
4878       }     
4879       *(format->pi2BPSK) = PUCCH_FormatConfig__pi2BPSK_enabled;
4880    }
4881
4882    /* Simultaneous HARQ ACK and CSI */
4883    format->simultaneousHARQ_ACK_CSI = NULLP;
4884    if((formatDb != NULLP) && (formatDb->harqAckCSI == true))
4885    {
4886       DU_ALLOC(format->simultaneousHARQ_ACK_CSI, sizeof(long));
4887       if(format->simultaneousHARQ_ACK_CSI)
4888       {     
4889          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4890          return RFAILED;
4891       }     
4892       *(format->simultaneousHARQ_ACK_CSI) = PUCCH_FormatConfig__simultaneousHARQ_ACK_CSI_true;
4893    }
4894
4895    return ROK;
4896 }
4897
4898
4899 /*******************************************************************
4900  *
4901  * @brief Builds PUCCH scheduling request list
4902  *
4903  * @details
4904  *
4905  *    Function : BuildPucchSchReqAddModList
4906  *
4907  *    Functionality:
4908  *      Builds PUCCH scheduling request list
4909  *
4910  * @params[in] : PucchSchedReqCfg *schReqDb
4911  *               struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList
4912  *
4913  * @return ROK     - success
4914  *         RFAILED - failure
4915  *
4916  * ****************************************************************/
4917 uint8_t BuildPucchSchReqAddModList(PucchSchedReqCfg *schReqDb, \
4918    struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList)
4919 {
4920    uint8_t elementCnt = 0, schReqIdx = 0;
4921    SchedulingRequestResourceConfig_t *schReqRsrc;
4922
4923    elementCnt = schReqDb->schedAddModListCount;
4924    schReqRsrcToAddModList->list.count = elementCnt;
4925    schReqRsrcToAddModList->list.size = elementCnt *sizeof(struct SchedulingRequestResourceConfig *);
4926
4927    schReqRsrcToAddModList->list.array = NULLP;
4928    DU_ALLOC(schReqRsrcToAddModList->list.array, schReqRsrcToAddModList->list.size);
4929    if(schReqRsrcToAddModList->list.array == NULLP)
4930    {
4931       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
4932       return RFAILED;
4933    }
4934
4935    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
4936    {
4937       DU_ALLOC(schReqRsrcToAddModList->list.array[schReqIdx], schReqRsrcToAddModList->list.size);
4938       if(schReqRsrcToAddModList->list.array[schReqIdx] == NULLP)
4939       {
4940          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
4941          return RFAILED;
4942       }
4943    }
4944
4945    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
4946    {
4947       schReqRsrc = schReqRsrcToAddModList->list.array[schReqIdx];
4948       schReqRsrc->schedulingRequestResourceId = schReqDb->schedAddModList[schReqIdx].resrcId;
4949       schReqRsrc->schedulingRequestID = schReqDb->schedAddModList[schReqIdx].requestId;
4950
4951       if(schReqDb->schedAddModList[schReqIdx].periodicity)
4952       {
4953          schReqRsrc->periodicityAndOffset = NULLP;
4954          DU_ALLOC(schReqRsrc->periodicityAndOffset, sizeof(struct SchedulingRequestResourceConfig__periodicityAndOffset));
4955          if(schReqRsrc->periodicityAndOffset == NULLP)
4956          {
4957             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
4958             return RFAILED;
4959          }
4960
4961          schReqRsrc->periodicityAndOffset->present = schReqDb->schedAddModList[schReqIdx].periodicity;
4962          switch(schReqRsrc->periodicityAndOffset->present)
4963          {
4964             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_NOTHING:
4965                break;
4966             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
4967                schReqRsrc->periodicityAndOffset->choice.sym2 = schReqDb->schedAddModList[schReqIdx].offset;
4968                break;
4969             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
4970                schReqRsrc->periodicityAndOffset->choice.sym6or7 = schReqDb->schedAddModList[schReqIdx].offset;
4971                break;
4972             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
4973                schReqRsrc->periodicityAndOffset->choice.sl1 = schReqDb->schedAddModList[schReqIdx].offset;
4974                break;
4975             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
4976                schReqRsrc->periodicityAndOffset->choice.sl2 = schReqDb->schedAddModList[schReqIdx].offset;
4977                break;
4978             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
4979                schReqRsrc->periodicityAndOffset->choice.sl4 = schReqDb->schedAddModList[schReqIdx].offset;
4980                break;
4981             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
4982                schReqRsrc->periodicityAndOffset->choice.sl5 = schReqDb->schedAddModList[schReqIdx].offset;
4983                break;
4984             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
4985                schReqRsrc->periodicityAndOffset->choice.sl8 = schReqDb->schedAddModList[schReqIdx].offset;
4986                break;
4987             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
4988                schReqRsrc->periodicityAndOffset->choice.sl10 = schReqDb->schedAddModList[schReqIdx].offset;
4989                break;
4990             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
4991                schReqRsrc->periodicityAndOffset->choice.sl16 = schReqDb->schedAddModList[schReqIdx].offset;
4992                break;
4993             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
4994                schReqRsrc->periodicityAndOffset->choice.sl20 = schReqDb->schedAddModList[schReqIdx].offset;
4995                break;
4996             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
4997                schReqRsrc->periodicityAndOffset->choice.sl40 = schReqDb->schedAddModList[schReqIdx].offset;
4998                break;
4999             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
5000                schReqRsrc->periodicityAndOffset->choice.sl80 = schReqDb->schedAddModList[schReqIdx].offset;
5001                break;
5002             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
5003                schReqRsrc->periodicityAndOffset->choice.sl160 = schReqDb->schedAddModList[schReqIdx].offset;
5004                break;
5005             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
5006                schReqRsrc->periodicityAndOffset->choice.sl320 = schReqDb->schedAddModList[schReqIdx].offset;
5007                break;
5008             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
5009                schReqRsrc->periodicityAndOffset->choice.sl640 = schReqDb->schedAddModList[schReqIdx].offset;
5010                break;
5011          }
5012       }
5013
5014       if(schReqDb->schedAddModList[schReqIdx].resrc)
5015       {
5016          schReqRsrc->resource = NULLP;
5017          DU_ALLOC(schReqRsrc->resource, sizeof(PUCCH_ResourceId_t));
5018          if(schReqRsrc->resource == NULLP)
5019          {
5020             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5021             return RFAILED;
5022          }
5023          *(schReqRsrc->resource) = schReqDb->schedAddModList[schReqIdx].resrc;
5024
5025       }
5026    }
5027    return ROK;
5028 }
5029
5030 /*******************************************************************
5031  *
5032  * @brief Builds PUCCH multi csi resource list
5033  *
5034  * @details
5035  *
5036  *    Function : BuildPucchMultiCsiRsrcList
5037  *
5038  *    Functionality:
5039  *      Builds PUCCH multi csi resource list
5040  *
5041  * @params[in] : PucchMultiCsiCfg *multiCsiDb
5042  *               struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList
5043  *
5044  * @return ROK     - success
5045  *         RFAILED - failure
5046  *
5047  * ****************************************************************/
5048 uint8_t BuildPucchMultiCsiRsrcList(PucchMultiCsiCfg *multiCsiDb, struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList)
5049 {
5050    uint8_t elementCnt = 0, rsrcIdx = 0;
5051
5052    elementCnt = multiCsiDb->multiCsiResrcListCount;
5053    multiCsiRsrcList->list.count = elementCnt;
5054    multiCsiRsrcList->list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
5055    multiCsiRsrcList->list.array = NULLP;
5056    DU_ALLOC(multiCsiRsrcList->list.array, multiCsiRsrcList->list.size);
5057    if(multiCsiRsrcList->list.array == NULLP)
5058    {
5059       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5060       return RFAILED;
5061    }
5062
5063    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5064    {
5065       DU_ALLOC(multiCsiRsrcList->list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
5066       if(multiCsiRsrcList->list.array[rsrcIdx] == NULLP)
5067       {
5068          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5069          return RFAILED;
5070       }
5071    }
5072
5073    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5074    {
5075       *(multiCsiRsrcList->list.array[rsrcIdx]) = multiCsiDb->multiCsiResrcList[rsrcIdx];
5076    }
5077    return ROK;
5078 }
5079
5080 /*******************************************************************
5081  *
5082  * @brief Builds DL data -to- Ul Ack list
5083  *
5084  * @details
5085  *
5086  *    Function : BuildDlDataToUlAckList
5087  *
5088  *    Functionality: Builds DL data -to- Ul Ack list
5089  *
5090  * @params[in] : PucchDlDataToUlAck *dlDataToUlAckDb
5091  *               struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList
5092  *
5093  * @return ROK     - success
5094  *         RFAILED - failure
5095  *
5096  * ****************************************************************/
5097 uint8_t BuildDlDataToUlAckList(PucchDlDataToUlAck *dlDataToUlAckDb, struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList)
5098 {
5099    uint8_t elementCnt = 0, arrIdx = 0;
5100
5101    if(dlDataToUlAckDb == NULLP)
5102       elementCnt = 2;
5103    else
5104       elementCnt = dlDataToUlAckDb->dlDataToUlAckListCount;
5105
5106    dlDataToUlACKList->list.count = elementCnt;
5107    dlDataToUlACKList->list.size = elementCnt * sizeof(long *);
5108    DU_ALLOC(dlDataToUlACKList->list.array, dlDataToUlACKList->list.size);
5109    if(dlDataToUlACKList->list.array == NULLP)
5110    {
5111       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5112       return RFAILED;
5113    }   
5114
5115    for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5116    {
5117       DU_ALLOC(dlDataToUlACKList->list.array[arrIdx], sizeof(long));
5118       if(dlDataToUlACKList->list.array[arrIdx] == NULLP)
5119       {
5120          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5121          return RFAILED;
5122       }   
5123    }
5124
5125    if(dlDataToUlAckDb == NULLP)
5126    {
5127       arrIdx = 0;
5128       *(dlDataToUlACKList->list.array[arrIdx++]) = 1;
5129       *(dlDataToUlACKList->list.array[arrIdx]) = 2;
5130    }
5131    else
5132    {
5133       for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5134       {
5135          *(dlDataToUlACKList->list.array[arrIdx]) = dlDataToUlAckDb->dlDataToUlAckList[arrIdx];
5136       }
5137    }
5138    return ROK;
5139 }
5140
5141 /*******************************************************************
5142  *
5143  * @brief Builds BWP UL dedicated PUCCH Config
5144  *
5145  * @details
5146  *
5147  *    Function : BuildBWPUlDedPucchCfg
5148  *
5149  *    Functionality:
5150  *      Builds BWP UL dedicated PUCCH Config
5151  *
5152  * @params[in] : PUCCH_Config_t *pucchCfg
5153  *
5154  * @return ROK     - success
5155  *         RFAILED - failure
5156  *
5157  * ****************************************************************/
5158 uint8_t BuildBWPUlDedPucchCfg(PucchCfg *pucchCfgDb, PUCCH_Config_t *pucchCfg)
5159 {
5160    PucchResrcSetCfg *rsrcSetCfgDb = NULLP;
5161    PucchResrcCfg *rsrcCfgDb = NULLP;
5162    PucchFormatCfg *format1Db = NULLP;
5163    PucchFormatCfg *format2Db = NULLP;
5164    PucchFormatCfg *format3Db = NULLP;
5165    PucchFormatCfg *format4Db = NULLP;
5166    PucchSchedReqCfg *schReqDb = NULLP;   
5167    PucchMultiCsiCfg  *multiCsiDb = NULLP;
5168    PucchDlDataToUlAck *dlDataToUlAckDb = NULLP;
5169
5170    if(pucchCfgDb)
5171    {
5172       rsrcSetCfgDb = pucchCfgDb->resrcSet;
5173       rsrcCfgDb = pucchCfgDb->resrc;
5174       format1Db = pucchCfgDb->format1;
5175       format2Db = pucchCfgDb->format2;
5176       format3Db = pucchCfgDb->format3;
5177       format4Db = pucchCfgDb->format4;
5178       schReqDb = pucchCfgDb->schedReq;
5179       multiCsiDb = pucchCfgDb->multiCsiCfg;
5180       dlDataToUlAckDb = pucchCfgDb->dlDataToUlAck;
5181    }
5182
5183    /* RESOURCE SET */
5184    DU_ALLOC(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
5185    if(pucchCfg->resourceSetToAddModList == NULL)
5186    {
5187       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5188       return RFAILED;
5189    }
5190
5191    if(BuildPucchRsrcSetAddModList(rsrcSetCfgDb, pucchCfg->resourceSetToAddModList) != ROK)
5192    {
5193       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5194       return RFAILED;
5195    }
5196
5197    /* PUCCH RESOURCE */
5198    DU_ALLOC(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
5199    if(pucchCfg->resourceToAddModList == NULLP)
5200    {
5201       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5202       return RFAILED;
5203    }
5204
5205    if(BuildPucchRsrcAddModList(rsrcCfgDb, pucchCfg->resourceToAddModList) != ROK)
5206    {
5207       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5208       return RFAILED;
5209    }
5210
5211    /* PUCCH Format 1 */
5212    DU_ALLOC(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
5213    if(pucchCfg->format1 == NULLP)
5214    {
5215       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5216       return RFAILED;
5217    }
5218    
5219    pucchCfg->format1->present = PUCCH_Config__format1_PR_setup;
5220    DU_ALLOC(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
5221    if(pucchCfg->format1->choice.setup == NULLP)
5222    {
5223       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5224       return RFAILED;
5225    }
5226
5227    if(BuildPucchFormat(format1Db, pucchCfg->format1->choice.setup) != ROK)
5228    {
5229       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5230       return RFAILED;
5231    }
5232
5233    /* PUCCH Format 2 */
5234    if(format2Db)
5235    {
5236       DU_ALLOC(pucchCfg->format2, sizeof(struct PUCCH_Config__format2));
5237       if(pucchCfg->format2 == NULLP)
5238       {
5239          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5240          return RFAILED;
5241       }
5242
5243       pucchCfg->format2->present = PUCCH_Config__format2_PR_setup;
5244       DU_ALLOC(pucchCfg->format2->choice.setup, sizeof(PUCCH_FormatConfig_t));
5245       if(pucchCfg->format2->choice.setup == NULLP)
5246       {
5247          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5248          return RFAILED;
5249       }
5250
5251       if(BuildPucchFormat(format2Db, pucchCfg->format2->choice.setup) != ROK)
5252       {
5253          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5254          return RFAILED;
5255       }
5256    }
5257
5258    /* PUCCH Format 3 */
5259    if(format3Db)
5260    {
5261       DU_ALLOC(pucchCfg->format3, sizeof(struct PUCCH_Config__format3));
5262       if(pucchCfg->format3 == NULLP)
5263       {
5264          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5265          return RFAILED;
5266       }
5267
5268       pucchCfg->format3->present = PUCCH_Config__format3_PR_setup;
5269       DU_ALLOC(pucchCfg->format3->choice.setup, sizeof(PUCCH_FormatConfig_t));
5270       if(pucchCfg->format3->choice.setup == NULLP)
5271       {
5272          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5273          return RFAILED;
5274       }
5275
5276       if(BuildPucchFormat(format3Db, pucchCfg->format3->choice.setup) != ROK)
5277       {
5278          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5279          return RFAILED;
5280       }
5281    }
5282
5283    /* PUCCH Format 4 */
5284    if(format4Db)
5285    {
5286       DU_ALLOC(pucchCfg->format4, sizeof(struct PUCCH_Config__format4));
5287       if(pucchCfg->format4 == NULLP)
5288       {
5289          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5290          return RFAILED;
5291       }
5292
5293       pucchCfg->format4->present = PUCCH_Config__format4_PR_setup;
5294       DU_ALLOC(pucchCfg->format4->choice.setup, sizeof(PUCCH_FormatConfig_t));
5295       if(pucchCfg->format4->choice.setup == NULLP)
5296       {
5297          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5298          return RFAILED;
5299       }
5300
5301       if(BuildPucchFormat(format4Db, pucchCfg->format4->choice.setup) != ROK)
5302       {
5303          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5304          return RFAILED;
5305       }
5306    }
5307
5308    /* Scheduling Request */
5309    if(schReqDb && (schReqDb->schedAddModListCount != 0))
5310    {
5311       pucchCfg->schedulingRequestResourceToAddModList = NULLP;
5312       DU_ALLOC(pucchCfg->schedulingRequestResourceToAddModList, sizeof(struct PUCCH_Config__schedulingRequestResourceToAddModList));
5313       if(pucchCfg->schedulingRequestResourceToAddModList == NULLP)
5314       {
5315          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5316          return RFAILED;
5317       }
5318
5319       if(BuildPucchSchReqAddModList(schReqDb, pucchCfg->schedulingRequestResourceToAddModList) != ROK)
5320       {
5321          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5322          return RFAILED;
5323       }
5324    }
5325
5326    /* Multi CSI */
5327    if(multiCsiDb && (multiCsiDb->multiCsiResrcListCount != 0))
5328    {
5329       pucchCfg->multi_CSI_PUCCH_ResourceList = NULLP;
5330       DU_ALLOC(pucchCfg->multi_CSI_PUCCH_ResourceList, sizeof(struct PUCCH_Config__multi_CSI_PUCCH_ResourceList));
5331       if(pucchCfg->multi_CSI_PUCCH_ResourceList == NULLP)
5332       {
5333          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5334          return RFAILED;
5335       }
5336
5337       if(BuildPucchMultiCsiRsrcList(multiCsiDb, pucchCfg->multi_CSI_PUCCH_ResourceList) != ROK)
5338       {
5339          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5340          return RFAILED;
5341       }
5342    }
5343
5344    /* DL DATA TO UL ACK */
5345    DU_ALLOC(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
5346    if(pucchCfg->dl_DataToUL_ACK == NULLP)
5347    {
5348       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5349       return RFAILED;
5350    }
5351
5352    if(BuildDlDataToUlAckList(dlDataToUlAckDb, pucchCfg->dl_DataToUL_ACK) != ROK)
5353    {
5354       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5355       return RFAILED;
5356    }
5357    
5358    /* TODO : spatial relation info add/mod list and power control*/
5359
5360    return ROK;
5361 }
5362
5363 /*******************************************************************
5364  *
5365  * @brief Fills SRS resource to add/modify list 
5366  *
5367  * @details
5368  *
5369  *    Function : BuildSrsRsrcAddModList
5370  *
5371  *    Functionality: Fills SRS resource to add/modify list
5372  *
5373  * @params[in] 
5374  * @return ROK     - success
5375  *         RFAILED - failure
5376  *
5377  * ****************************************************************/
5378 uint8_t BuildSrsRsrcAddModList(struct SRS_Config__srs_ResourceToAddModList *resourceList)
5379 {
5380    uint8_t   elementCnt;
5381    uint8_t   rsrcIdx;
5382
5383    elementCnt = 1;
5384    resourceList->list.count = elementCnt;
5385    resourceList->list.size = elementCnt * sizeof(SRS_Resource_t *);
5386    resourceList->list.array = NULLP;
5387    DU_ALLOC(resourceList->list.array, resourceList->list.size);
5388    if(!resourceList->list.array)
5389    {
5390       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5391       return RFAILED;
5392    }
5393
5394    for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
5395    {
5396       DU_ALLOC(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
5397       if(!resourceList->list.array[rsrcIdx])
5398       {
5399          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5400          return RFAILED;
5401       }
5402    }
5403
5404    rsrcIdx = 0;
5405    resourceList->list.array[rsrcIdx]->srs_ResourceId = SRS_RSRC_ID;
5406    resourceList->list.array[rsrcIdx]->nrofSRS_Ports = SRS_Resource__nrofSRS_Ports_port1;
5407    resourceList->list.array[rsrcIdx]->transmissionComb.present = SRS_Resource__transmissionComb_PR_n2;
5408
5409    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2 = NULLP;
5410    DU_ALLOC(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2, \
5411          sizeof(struct SRS_Resource__transmissionComb__n2));
5412    if(!resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2)
5413    {
5414       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5415       return RFAILED;
5416    }
5417    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->combOffset_n2\
5418       = SRS_COMB_OFFSET_N2;
5419    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->cyclicShift_n2\
5420       = SRS_CYCLIC_SHIFT_N2;
5421
5422    resourceList->list.array[rsrcIdx]->resourceMapping.startPosition = \
5423                                                                       PUSCH_START_SYMBOL;
5424    resourceList->list.array[rsrcIdx]->resourceMapping.nrofSymbols =  \
5425                                                                      SRS_Resource__resourceMapping__nrofSymbols_n1;
5426    resourceList->list.array[rsrcIdx]->resourceMapping.repetitionFactor = \
5427                                                                          SRS_Resource__resourceMapping__repetitionFactor_n1;
5428
5429    resourceList->list.array[rsrcIdx]->freqDomainPosition = SRS_FREQ_DOM_POS;
5430    resourceList->list.array[rsrcIdx]->freqDomainShift = SRS_FREQ_DOM_SHIFT;
5431    resourceList->list.array[rsrcIdx]->freqHopping.c_SRS = C_SRS;
5432    resourceList->list.array[rsrcIdx]->freqHopping.b_SRS = B_SRS;
5433    resourceList->list.array[rsrcIdx]->freqHopping.b_hop = B_HOP;
5434    resourceList->list.array[rsrcIdx]->groupOrSequenceHopping = \
5435                                                                SRS_Resource__groupOrSequenceHopping_neither;
5436
5437    /* Setting resource type to aperiodic for intergration purposes */
5438    resourceList->list.array[rsrcIdx]->resourceType.present = \
5439                                                              SRS_Resource__resourceType_PR_aperiodic;
5440    resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic = NULLP;
5441    DU_ALLOC(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,
5442          sizeof(struct SRS_Resource__resourceType__aperiodic));
5443    if(!resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic)
5444    {
5445       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5446       return RFAILED;
5447    }
5448    resourceList->list.array[rsrcIdx]->sequenceId = SRS_SEQ_ID;
5449
5450    return ROK;
5451 }
5452
5453 /*******************************************************************
5454  *
5455  * @brief Build SRS resource set Add/mod list
5456  *
5457  * @details
5458  *
5459  *    Function : BuildSrsRsrcSetAddModList
5460  *
5461  *    Functionality: Build SRS resource set Add/mod list
5462  *
5463  * @params[in] 
5464  * @return ROK     - success
5465  *         RFAILED - failure
5466  *
5467  * ****************************************************************/
5468    uint8_t BuildSrsRsrcSetAddModList
5469 (
5470  struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList
5471  )
5472 {
5473    uint8_t  elementCnt;
5474    uint8_t  rSetIdx;
5475    uint8_t  rsrcIdx;
5476    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList;
5477
5478    elementCnt = 1;
5479    rsrcSetList->list.count = elementCnt;
5480    rsrcSetList->list.size = elementCnt * sizeof(SRS_ResourceSet_t *);
5481    rsrcSetList->list.array = NULLP;
5482    DU_ALLOC(rsrcSetList->list.array, rsrcSetList->list.size);
5483    if(!rsrcSetList->list.array)
5484    {
5485       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5486       return RFAILED;
5487    }
5488
5489    for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
5490    {
5491       DU_ALLOC(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
5492       if(!rsrcSetList->list.array[rSetIdx])
5493       {
5494          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5495          return RFAILED;
5496       }
5497    }
5498
5499    rSetIdx = 0;
5500    rsrcSetList->list.array[rSetIdx]->srs_ResourceSetId = SRS_RSET_ID;
5501
5502    /* Fill Resource Id list in resource set */
5503    rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList = NULLP;
5504    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
5505          sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
5506    if(!rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
5507    {
5508       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5509       return RFAILED;
5510    }
5511
5512    elementCnt = 1;
5513    rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
5514    rsrcIdList->list.count = elementCnt;
5515    rsrcIdList->list.size = elementCnt * sizeof(SRS_ResourceId_t *);
5516    rsrcIdList->list.array = NULLP;
5517    DU_ALLOC(rsrcIdList->list.array, rsrcIdList->list.size);
5518    if(!rsrcIdList->list.array)
5519    {
5520       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5521       return RFAILED;
5522    }
5523
5524    for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
5525    {
5526       DU_ALLOC(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
5527       if(!rsrcIdList->list.array[rsrcIdx])
5528       {
5529          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5530          return RFAILED;
5531       }
5532    }
5533
5534    rsrcIdx = 0;
5535    *rsrcIdList->list.array[rsrcIdx] = SRS_RSRC_ID;
5536
5537    /* Fill resource type */
5538    rsrcSetList->list.array[rSetIdx]->resourceType.present = \
5539                                                             SRS_ResourceSet__resourceType_PR_aperiodic;
5540
5541    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic = NULLP;
5542    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
5543          sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
5544    if(!rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic)
5545    {
5546       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5547       return RFAILED;
5548    }
5549    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->aperiodicSRS_ResourceTrigger \
5550       = APERIODIC_SRS_RESRC_TRIGGER;
5551
5552    /* TODO : Fill values for below IEs as expected by Viavi */
5553    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->csi_RS = NULLP;
5554    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->slotOffset = NULLP;
5555
5556
5557    rsrcSetList->list.array[rSetIdx]->usage = SRS_ResourceSet__usage_codebook;
5558    rsrcSetList->list.array[rSetIdx]->alpha = NULLP;
5559    rsrcSetList->list.array[rSetIdx]->p0 = NULLP;
5560    rsrcSetList->list.array[rSetIdx]->pathlossReferenceRS = NULLP;
5561    rsrcSetList->list.array[rSetIdx]->srs_PowerControlAdjustmentStates = NULLP;
5562
5563    return ROK;
5564 }
5565
5566 /*******************************************************************
5567  *
5568  * @brief Builds BWP UL dedicated SRS Config
5569  *
5570  * @details
5571  *
5572  *    Function : BuildBWPUlDedSrsCfg
5573  *
5574  *    Functionality: Builds BWP UL dedicated SRS Config
5575  *
5576  * @params[in] SRS Config 
5577  * @return ROK     - success
5578  *         RFAILED - failure
5579  *
5580  * ****************************************************************/
5581 uint8_t BuildBWPUlDedSrsCfg(SRS_Config_t *srsCfg)
5582 {
5583    srsCfg->srs_ResourceSetToReleaseList = NULLP;
5584    srsCfg->srs_ResourceSetToAddModList = NULLP;
5585    DU_ALLOC(srsCfg->srs_ResourceSetToAddModList, \
5586          sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
5587    if(!srsCfg->srs_ResourceSetToAddModList)
5588    {
5589       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5590       return RFAILED;
5591    }
5592    if(BuildSrsRsrcSetAddModList(srsCfg->srs_ResourceSetToAddModList) != ROK)
5593    {
5594       return RFAILED;
5595    }
5596
5597    srsCfg->srs_ResourceToReleaseList = NULLP;
5598
5599    /* Resource to Add/Modify list */
5600    srsCfg->srs_ResourceToAddModList = NULLP;
5601    DU_ALLOC(srsCfg->srs_ResourceToAddModList, \
5602          sizeof(struct SRS_Config__srs_ResourceToAddModList));
5603    if(!srsCfg->srs_ResourceToAddModList)
5604    {
5605       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5606       return RFAILED;
5607    }
5608
5609    if(BuildSrsRsrcAddModList(srsCfg->srs_ResourceToAddModList) != ROK)
5610    {
5611       return RFAILED;
5612    }
5613
5614    srsCfg->tpc_Accumulation = NULLP;
5615
5616    return ROK;
5617 }
5618
5619
5620
5621 /*******************************************************************
5622  *
5623  * @brief Builds Pusch Serving cell Config
5624  *
5625  * @details
5626  *
5627  *    Function : BuildPuschSrvCellCfg
5628  *
5629  *    Functionality: Builds Pusch Serving cell Config
5630  *
5631  * @params[in] struct UplinkConfig__pusch_ServingCellConfig *puschCfg
5632  *
5633  * @return ROK     - success
5634  *         RFAILED - failure
5635  *
5636  * ****************************************************************/
5637 uint8_t BuildPuschSrvCellCfg(struct UplinkConfig__pusch_ServingCellConfig *puschCfg)
5638 {
5639    puschCfg->present = UplinkConfig__pusch_ServingCellConfig_PR_setup;
5640    puschCfg->choice.setup = NULLP;
5641    DU_ALLOC(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
5642    if(!puschCfg->choice.setup)
5643    {
5644       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5645       return RFAILED;
5646    }
5647
5648    puschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5649    puschCfg->choice.setup->rateMatching = NULLP;
5650    puschCfg->choice.setup->xOverhead = NULLP;
5651    puschCfg->choice.setup->ext1 = NULLP;
5652    DU_ALLOC(puschCfg->choice.setup->ext1, sizeof(struct PUSCH_ServingCellConfig__ext1));
5653    if(!puschCfg->choice.setup->ext1)
5654    {
5655       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5656       return RFAILED;
5657    }
5658
5659    puschCfg->choice.setup->ext1->maxMIMO_Layers = NULLP;
5660    DU_ALLOC(puschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5661    if(!puschCfg->choice.setup->ext1->maxMIMO_Layers)
5662    {
5663       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5664       return RFAILED;
5665    }
5666    *(puschCfg->choice.setup->ext1->maxMIMO_Layers) = PUSCH_MAX_MIMO_LAYERS;
5667
5668    puschCfg->choice.setup->ext1->processingType2Enabled= NULLP;
5669    DU_ALLOC(puschCfg->choice.setup->ext1->processingType2Enabled,sizeof(BOOLEAN_t));
5670    if(!puschCfg->choice.setup->ext1->processingType2Enabled)
5671    {
5672       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5673       return RFAILED;
5674    }
5675    *(puschCfg->choice.setup->ext1->processingType2Enabled) = PUSCH_PROCESS_TYPE2_ENABLED;
5676    return ROK;
5677 }
5678
5679 /*******************************************************************
5680  *
5681  * @brief Builds inital UL BWP
5682  *
5683  * @details
5684  *
5685  *    Function : BuildInitialUlBWP
5686  *
5687  *    Functionality: Builds initial UL BWP
5688  *
5689  * @params[in] BWP_UplinkDedicated_t *ulBwp
5690  * @return ROK     - success
5691  *         RFAILED - failure
5692  *
5693  * ****************************************************************/
5694 uint8_t BuildInitialUlBWP(InitialUlBwp *initUlBwp, BWP_UplinkDedicated_t *ulBwp)
5695 {
5696    PucchCfg *pucchCfg = NULLP;
5697    PuschCfg *puschCfg = NULLP;
5698
5699    if(initUlBwp)
5700    {
5701       if(initUlBwp->pucchPresent)
5702          pucchCfg = &initUlBwp->pucchCfg;
5703       if(initUlBwp->puschPresent)
5704          puschCfg = &initUlBwp->puschCfg;
5705    }
5706
5707    ulBwp->pucch_Config = NULLP;
5708    DU_ALLOC(ulBwp->pucch_Config, sizeof(struct BWP_UplinkDedicated__pucch_Config));
5709    if(!ulBwp->pucch_Config)
5710    {
5711       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5712       return RFAILED;
5713    }
5714
5715    ulBwp->pucch_Config->present = BWP_UplinkDedicated__pucch_Config_PR_setup;
5716    ulBwp->pucch_Config->choice.setup = NULLP;
5717    DU_ALLOC(ulBwp->pucch_Config->choice.setup, sizeof(PUCCH_Config_t));
5718    if(!ulBwp->pucch_Config->choice.setup)
5719    {
5720       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5721       return RFAILED;
5722    }
5723
5724    if(BuildBWPUlDedPucchCfg(pucchCfg, ulBwp->pucch_Config->choice.setup) != ROK)
5725    {
5726       return RFAILED;
5727    }
5728
5729    /* Fill BWP UL dedicated PUSCH config */
5730    ulBwp->pusch_Config = NULLP;
5731    DU_ALLOC(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
5732    if(!ulBwp->pusch_Config)
5733    {
5734       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5735       return RFAILED;
5736    }
5737
5738    ulBwp->pusch_Config->present = BWP_UplinkDedicated__pusch_Config_PR_setup;
5739    ulBwp->pusch_Config->choice.setup = NULLP;
5740    DU_ALLOC(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
5741    if(!ulBwp->pusch_Config->choice.setup)
5742    {
5743       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5744       return RFAILED;
5745    }
5746
5747    if(BuildBWPUlDedPuschCfg(puschCfg, ulBwp->pusch_Config->choice.setup) != ROK)
5748    {
5749       return RFAILED;
5750    }
5751
5752    ulBwp->configuredGrantConfig = NULLP;
5753
5754    /* Fill BPW UL dedicated SRS config */
5755    ulBwp->srs_Config = NULLP;
5756    DU_ALLOC(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
5757    if(!ulBwp->srs_Config)
5758    {
5759       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5760       return RFAILED;
5761    }
5762
5763    ulBwp->srs_Config->present = BWP_UplinkDedicated__srs_Config_PR_setup;
5764    ulBwp->srs_Config->choice.setup = NULLP;
5765    DU_ALLOC(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
5766    if(!ulBwp->srs_Config->choice.setup)
5767    {
5768       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5769       return RFAILED;
5770    }
5771
5772    if(BuildBWPUlDedSrsCfg(ulBwp->srs_Config->choice.setup) != ROK)
5773    {
5774       return RFAILED;   
5775    }
5776
5777    ulBwp->beamFailureRecoveryConfig = NULLP;
5778
5779    return ROK;
5780 }
5781
5782 /*******************************************************************
5783  *
5784  * @brief Builds UL config
5785  * @details
5786  *
5787  *    Function : BuildUlCfg 
5788  *
5789  *    Functionality: Builds UL config in spCellCfgDed
5790  *
5791  * @params[in] UplinkConfig_t *ulCfg
5792  *
5793  * @return ROK     - success
5794  *         RFAILED - failure
5795  *
5796  * ****************************************************************/
5797 uint8_t BuildUlCfg(ServCellCfgInfo *servCellCfg, UplinkConfig_t *ulCfg)
5798 {
5799    InitialUlBwp *initUlBwp = NULLP;
5800
5801    if(servCellCfg)
5802    {
5803       initUlBwp = &servCellCfg->initUlBwp;
5804    }
5805
5806    ulCfg->initialUplinkBWP = NULLP;
5807    DU_ALLOC(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
5808    if(!ulCfg->initialUplinkBWP)
5809    {
5810       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5811       return RFAILED;
5812    }
5813
5814    if(BuildInitialUlBWP(initUlBwp, ulCfg->initialUplinkBWP) != ROK)
5815    {
5816       return RFAILED;
5817    }
5818
5819    ulCfg->uplinkBWP_ToReleaseList = NULLP;
5820    ulCfg->uplinkBWP_ToAddModList = NULLP;
5821    ulCfg->firstActiveUplinkBWP_Id = NULLP;
5822    DU_ALLOC(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
5823    if(!ulCfg->firstActiveUplinkBWP_Id)
5824    {
5825       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5826       return RFAILED;
5827    }
5828    if(servCellCfg == NULLP)
5829       *(ulCfg->firstActiveUplinkBWP_Id) = ACTIVE_UL_BWP_ID;
5830    else
5831       *(ulCfg->firstActiveUplinkBWP_Id) = servCellCfg->firstActvUlBwpId;
5832
5833    ulCfg->pusch_ServingCellConfig = NULLP;
5834    DU_ALLOC(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
5835    if(!ulCfg->pusch_ServingCellConfig)
5836    {
5837       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5838       return RFAILED;
5839    }
5840
5841    if(BuildPuschSrvCellCfg(ulCfg->pusch_ServingCellConfig) != ROK)
5842    {
5843       return RFAILED;
5844    }
5845
5846    ulCfg->carrierSwitching = NULLP;
5847    ulCfg->ext1 = NULLP;
5848    return ROK;
5849 }
5850
5851 /*******************************************************************
5852  *
5853  * @brief Builds PDSCH serving cell config
5854  * @details
5855  *
5856  *    Function : BuildPdschSrvCellCfg
5857  *
5858  *    Functionality: Builds PDSCH serving cell config in spCellCfgDed
5859  *
5860  * @params[in] struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg 
5861  *
5862  * @return ROK     - success
5863  *         RFAILED - failure
5864  *
5865  * ****************************************************************/
5866 uint8_t BuildPdschSrvCellCfg(PdschServCellCfg *pdschServCellDb, struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg)
5867 {
5868    pdschCfg->present =  ServingCellConfig__pdsch_ServingCellConfig_PR_setup;
5869    pdschCfg->choice.setup = NULLP;
5870    DU_ALLOC(pdschCfg->choice.setup, sizeof( struct PDSCH_ServingCellConfig));
5871    if(!pdschCfg->choice.setup)
5872    {
5873       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5874       return RFAILED;
5875    }
5876
5877    /* Code Block Group Transmission */
5878    pdschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5879    if(pdschServCellDb && (pdschServCellDb->maxCodeBlkGrpPerTb || pdschServCellDb->codeBlkGrpFlushInd))
5880    {
5881       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission, sizeof(struct PDSCH_ServingCellConfig__codeBlockGroupTransmission));
5882       if(pdschCfg->choice.setup->codeBlockGroupTransmission == NULLP)
5883       {
5884          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5885          return RFAILED;
5886       }
5887
5888       pdschCfg->choice.setup->codeBlockGroupTransmission->present = PDSCH_ServingCellConfig__codeBlockGroupTransmission_PR_setup;
5889       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup = NULLP;
5890       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup, sizeof(struct PDSCH_CodeBlockGroupTransmission ));
5891       if(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup == NULLP)
5892       {
5893          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5894          return RFAILED;
5895       }
5896
5897       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock = \
5898          *(pdschServCellDb->maxCodeBlkGrpPerTb);
5899       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator = \
5900          *(pdschServCellDb->codeBlkGrpFlushInd);
5901    }
5902
5903    /* xOverhead */
5904    pdschCfg->choice.setup->xOverhead = NULLP;
5905    if(pdschServCellDb && pdschServCellDb->xOverhead)
5906    {
5907       DU_ALLOC(pdschCfg->choice.setup->xOverhead, sizeof(long));
5908       if(pdschCfg->choice.setup->xOverhead == NULLP)
5909       {
5910          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5911          return RFAILED;
5912       }
5913       *(pdschCfg->choice.setup->xOverhead) = *(pdschServCellDb->xOverhead);
5914    }
5915
5916    /* Number of HARQ processes */
5917    pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH = NULLP;
5918    DU_ALLOC(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH, sizeof(long));
5919    if(!pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH)
5920    {
5921       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5922       return RFAILED;
5923    }
5924
5925    if(pdschServCellDb == NULLP)
5926    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = PDSCH_NUM_HARQ_PROC;
5927    else
5928    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = pdschServCellDb->numHarqProcForPdsch;
5929
5930    pdschCfg->choice.setup->pucch_Cell = NULLP;
5931
5932    /* Extension */
5933    pdschCfg->choice.setup->ext1 = NULLP;
5934    if(pdschServCellDb && pdschServCellDb->maxMimoLayers)
5935    {
5936       DU_ALLOC(pdschCfg->choice.setup->ext1, sizeof(struct PDSCH_ServingCellConfig__ext1));
5937       if(pdschCfg->choice.setup->ext1 == NULLP)
5938       {
5939          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5940          return RFAILED;
5941       }
5942
5943       DU_ALLOC(pdschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5944       if(pdschCfg->choice.setup->ext1->maxMIMO_Layers == NULLP)
5945       {
5946          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5947          return RFAILED;
5948       }
5949       *(pdschCfg->choice.setup->ext1->maxMIMO_Layers) = *(pdschServCellDb->maxMimoLayers);
5950    }
5951
5952    return ROK;
5953 }
5954
5955 /*******************************************************************
5956  *
5957  * @brief Builds CSI Meas config
5958  * @details
5959  *
5960  *    Function : BuildCsiMeasCfg 
5961  *
5962  *    Functionality: Builds CSI Meas config in spCellCfgDed
5963  *
5964  * @params[in] struct ServingCellConfig__csi_MeasConfig *csiMeasCfg
5965  *
5966  * @return ROK     - success
5967  *         RFAILED - failure
5968  *
5969  * ****************************************************************/
5970 uint8_t BuildCsiMeasCfg(struct ServingCellConfig__csi_MeasConfig *csiMeasCfg)
5971 {
5972
5973    return ROK;
5974 }
5975
5976 /*******************************************************************
5977  *
5978  * @brief Builds DL BWP to add/modify list
5979  * @details
5980  *
5981  *    Function : BuildDlBwpToAddModList
5982  *
5983  *    Functionality: Builds DL BWP to add/modify list
5984  *
5985  * @params[in] ServCellCfgInfo *servCellCfg, 
5986  *             struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList
5987  *
5988  * @return ROK     - success
5989  *         RFAILED - failure
5990  *
5991  * ****************************************************************/ 
5992 uint8_t BuildDlBwpToAddModList(ServCellCfgInfo *servCellCfg, struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList)
5993 {
5994    uint8_t elementCnt, idx;
5995
5996    elementCnt = servCellCfg->numDlBwpToAdd;
5997    dlBwpAddModList->list.count = elementCnt;
5998    dlBwpAddModList->list.size = elementCnt * sizeof(struct BWP_Downlink *);
5999    dlBwpAddModList->list.array = NULLP;
6000    DU_ALLOC(dlBwpAddModList->list.array, dlBwpAddModList->list.size);
6001    if(dlBwpAddModList->list.array == NULLP)
6002    {
6003       DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6004       return RFAILED;
6005    }
6006
6007    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6008    {
6009       DU_ALLOC(dlBwpAddModList->list.array[idx], sizeof(BWP_Downlink_t));
6010       if(dlBwpAddModList->list.array[idx] == NULLP)
6011       {
6012          DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6013          return RFAILED;
6014       }
6015    }
6016
6017    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6018    {
6019       dlBwpAddModList->list.array[idx]->bwp_Id = servCellCfg->DlBwpToAddList[idx].bwpId;
6020       dlBwpAddModList->list.array[idx]->bwp_Common = NULLP;
6021       dlBwpAddModList->list.array[idx]->bwp_Dedicated = NULLP;
6022    }
6023    return ROK;
6024 }
6025
6026 /*******************************************************************
6027  *
6028  * @brief Builds Spcell config dedicated
6029  * @details
6030  *
6031  *    Function : BuildSpCellCfgDed
6032  *
6033  *    Functionality: Builds sp cell config dedicated in spCellCfg
6034  *
6035  * @params[in] ServingCellConfig_t srvCellCfg
6036  *
6037  * @return ROK     - success
6038  *         RFAILED - failure
6039  *
6040  * ****************************************************************/
6041 uint8_t BuildSpCellCfgDed(DuUeCb *ueCb, ServingCellConfig_t *srvCellCfg)
6042 {
6043    ServCellCfgInfo *servCellCfg = NULLP;
6044    InitialDlBwp *initDlBwp = NULLP;
6045    PdschServCellCfg *pdschServCellDb = NULLP;
6046
6047    if(ueCb)
6048    {
6049       servCellCfg = &ueCb->macUeCfg.spCellCfg.servCellCfg;
6050       initDlBwp = &servCellCfg->initDlBwp;
6051       pdschServCellDb = &servCellCfg->pdschServCellCfg;
6052    }
6053
6054    srvCellCfg->tdd_UL_DL_ConfigurationDedicated = NULLP;
6055    DU_ALLOC(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
6056    if(!srvCellCfg->tdd_UL_DL_ConfigurationDedicated)
6057    {
6058       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6059       return RFAILED;
6060    }
6061
6062    srvCellCfg->initialDownlinkBWP = NULLP;
6063    DU_ALLOC(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
6064    if(!srvCellCfg->initialDownlinkBWP)
6065    {
6066       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6067       return RFAILED;
6068    }
6069
6070    if(BuildInitialDlBWP(initDlBwp, srvCellCfg->initialDownlinkBWP) != ROK)
6071    {
6072       DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6073       return RFAILED;
6074    }
6075
6076    srvCellCfg->downlinkBWP_ToReleaseList = NULLP;
6077
6078    srvCellCfg->downlinkBWP_ToAddModList = NULLP;
6079    if(ueCb && ueCb->macUeCfg.spCellCfg.servCellCfg.numDlBwpToAdd)
6080    {
6081       DU_ALLOC(srvCellCfg->downlinkBWP_ToAddModList, sizeof(struct ServingCellConfig__downlinkBWP_ToAddModList));
6082       if(srvCellCfg->downlinkBWP_ToAddModList == NULLP)
6083       {
6084          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6085          return RFAILED;
6086       }
6087
6088       if(BuildDlBwpToAddModList(&ueCb->macUeCfg.spCellCfg.servCellCfg, srvCellCfg->downlinkBWP_ToAddModList) != ROK)
6089       {
6090          DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6091          return RFAILED;
6092       }
6093    }
6094
6095    srvCellCfg->firstActiveDownlinkBWP_Id = NULLP;
6096    DU_ALLOC(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
6097    if(!srvCellCfg->firstActiveDownlinkBWP_Id)
6098    {
6099       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6100       return RFAILED;
6101    }
6102    if(ueCb == NULLP)
6103       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6104    else
6105       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ueCb->macUeCfg.spCellCfg.servCellCfg.firstActvDlBwpId;
6106
6107    srvCellCfg->bwp_InactivityTimer = NULLP;
6108
6109    srvCellCfg->defaultDownlinkBWP_Id = NULLP;
6110    DU_ALLOC(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
6111    if(!srvCellCfg->defaultDownlinkBWP_Id)
6112    {
6113       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6114       return RFAILED;
6115    }
6116    if(ueCb == NULLP)
6117       *(srvCellCfg->defaultDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6118    else
6119       *(srvCellCfg->defaultDownlinkBWP_Id) = ueCb->macUeCfg.spCellCfg.servCellCfg.defaultDlBwpId;
6120
6121    srvCellCfg->uplinkConfig = NULLP;
6122    DU_ALLOC(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));
6123    if(!srvCellCfg->uplinkConfig)
6124    {
6125       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6126       return RFAILED;
6127    }
6128
6129    if(BuildUlCfg(servCellCfg, srvCellCfg->uplinkConfig) != ROK)
6130    {
6131       DU_LOG("\nERROR  -->  F1AP : BuildUlCfg failed");
6132       return RFAILED;
6133    }
6134    srvCellCfg->supplementaryUplink = NULLP;
6135    srvCellCfg->pdcch_ServingCellConfig = NULLP;
6136
6137    srvCellCfg->pdsch_ServingCellConfig = NULLP;
6138    DU_ALLOC(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct  ServingCellConfig__pdsch_ServingCellConfig));
6139    if(!srvCellCfg->pdsch_ServingCellConfig)
6140    {
6141       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6142       return RFAILED;
6143    }
6144
6145    if(BuildPdschSrvCellCfg(pdschServCellDb, srvCellCfg->pdsch_ServingCellConfig) != ROK)
6146    {
6147       DU_LOG("\nERROR  -->  F1AP : BuildPdschSrvCellCfg failed");
6148       return RFAILED;
6149    }
6150
6151    srvCellCfg->csi_MeasConfig = NULLP;
6152 #if 0
6153    DU_ALLOC(srvCellCfg->csi_MeasConfig, sizeof(struct   ServingCellConfig__csi_MeasConfig))
6154       if(!srvCellCfg->csi_MeasConfig)
6155       {
6156          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6157          return RFAILED;
6158       }
6159
6160    if(BuildCsiMeasCfg(srvCellCfg->csi_MeasConfig) != ROK)
6161    {
6162       DU_LOG("\nF1AP : BuildCsiMeasCfg failed");
6163       return RFAILED;
6164    }
6165 #endif
6166    srvCellCfg->sCellDeactivationTimer = NULLP;
6167    srvCellCfg->crossCarrierSchedulingConfig = NULLP;
6168    srvCellCfg->tag_Id = TAG_ID;
6169    srvCellCfg->dummy = NULLP;
6170    srvCellCfg->pathlossReferenceLinking = NULLP;
6171    srvCellCfg->servingCellMO = NULLP;
6172    srvCellCfg->ext1 = NULLP;
6173
6174    return ROK;
6175 }
6176
6177 /*******************************************************************
6178  *
6179  * @brief Fills SCS specific carrier list in DL frequency info
6180  *
6181  * @details
6182  *
6183  *    Function : BuildScsSpecificCarrierListDl
6184  *
6185  *    Functionality: Fills SCS specific carrier list in DL frequency info
6186  *
6187  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
6188  *
6189  * @return ROK     - success
6190  *         RFAILED - failure
6191  *
6192  * ****************************************************************/
6193 uint8_t BuildScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
6194 {
6195    uint8_t elementCnt = 0, listIdx = 0;
6196    ScsSpecCarrier duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.dlScsCarrier;
6197
6198    elementCnt = ODU_VALUE_ONE;
6199    scsCarrierList->list.count = elementCnt;
6200    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6201
6202    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6203    if(!scsCarrierList->list.array)
6204    {
6205       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for scs carrier list array \
6206          in BuildScsSpecificCarrierListDl()");
6207       return RFAILED;
6208    }
6209
6210    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6211    {
6212       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6213       if(!scsCarrierList->list.array[listIdx])
6214       {    
6215          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SCS Specific Carrier list array \
6216             element in BuildScsSpecificCarrierListDl()");
6217          return RFAILED;
6218       }    
6219    }
6220
6221    listIdx = 0;
6222    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6223    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6224    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6225
6226    return ROK;
6227 }
6228
6229 /*******************************************************************
6230  *
6231  * @brief Fills DL frequency info in DL config common
6232  *
6233  * @details
6234  *
6235  *    Function : BuildFreqInfoDl
6236  *
6237  *    Functionality: Fills DL frequency info in DL config common
6238  *
6239  * @params[in] Pointer to DownlinkConfigCommon_t
6240  *
6241  * @return ROK     - success
6242  *         RFAILED - failure
6243  *
6244  * ****************************************************************/
6245 uint8_t BuildFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
6246 {
6247    uint8_t freqBandIdx = 0, elementCnt = 0;
6248    DlCfgCommon  dlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg;
6249
6250    /* TODO : Fill SSB Absolute Frequency */
6251    /*
6252       DU_ALLOC(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
6253       if(!frequencyInfoDL->absoluteFrequencySSB)
6254       {
6255       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB Absolute Frequency in BuildFreqInfoDl()");
6256       return RFAILED;
6257       }
6258       frequencyInfoDL->absoluteFrequencySSB = ?;
6259       */
6260
6261    /* NR Multi Frequency Band List */
6262    elementCnt = ODU_VALUE_ONE;
6263    frequencyInfoDL->frequencyBandList.list.count = elementCnt;
6264    frequencyInfoDL->frequencyBandList.list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6265
6266    DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
6267    if(!frequencyInfoDL->frequencyBandList.list.array)
6268    {
6269       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for Frequency Band List array in BuildFreqInfoDl()");
6270       return RFAILED;
6271    }
6272
6273    for(freqBandIdx = 0; freqBandIdx < elementCnt; freqBandIdx++)
6274    {
6275       DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
6276       if(!frequencyInfoDL->frequencyBandList.list.array[freqBandIdx])
6277       {
6278          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoDl()");
6279          return RFAILED;
6280       }
6281    }
6282
6283    freqBandIdx = 0;
6284    *(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx]) = dlCfg.freqBandInd;
6285
6286    /* TODO : Absolute Frequency to Point A */
6287    //frequencyInfoDL->absoluteFrequencyPointA
6288
6289    /* Subcarrier Spacing specifc carrier List */
6290    if((BuildScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList)) != ROK)
6291    {
6292       DU_LOG("\nERROR  -->  DU APP : Failed to fill SCS specific carrier list DL in BuildFreqInfoDl()");
6293       return RFAILED;
6294    }
6295
6296    return ROK;
6297
6298 }
6299
6300 /*******************************************************************
6301  *
6302  * @brief Fills DL config common in Serving cell config common
6303  *
6304  * @details
6305  *
6306  *    Function : BuildDlConfigCommon
6307  *
6308  *    Functionality: Fills DL config common in Serving cell config common
6309  *
6310  * @params[in] Pointer to DownlinkConfigCommon_t
6311  *
6312  * @return ROK     - success
6313  *         RFAILED - failure
6314  *
6315  * ****************************************************************/
6316 uint8_t BuildDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
6317 {
6318    /* DL Frequency Info */
6319    DU_ALLOC(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
6320    if(!dlCfgCommon->frequencyInfoDL)
6321    {
6322       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL frequency info in BuildDlConfigCommon()");
6323       return RFAILED;
6324    }
6325    if((BuildFreqInfoDl(dlCfgCommon->frequencyInfoDL))!= ROK)
6326    {
6327       DU_LOG("\nERROR  --> DU APP : Failed to fill DL frequency info in BuildDlConfigCommon()");
6328       return RFAILED;
6329    }
6330
6331    /* DL BWP config common */
6332    DU_ALLOC(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
6333    if(!dlCfgCommon->initialDownlinkBWP)
6334    {
6335       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL BWP config common in BuildDlConfigCommon()");
6336       return RFAILED;
6337    }
6338    if((BuildBwpDlCommon(dlCfgCommon->initialDownlinkBWP)) != ROK)
6339    {
6340       DU_LOG("\nERROR  --> DU APP : Failed to fill DL DWP config common in BuildDlConfigCommon()");
6341       return RFAILED;
6342    }
6343
6344    return ROK;
6345 }
6346
6347 /*******************************************************************
6348  *
6349  * @brief Fills SCS specific carrier list in UL frequency Info
6350  *
6351  * @details
6352  *
6353  *    Function : BuildScsSpecificCarrierListUl
6354  *
6355  *    Functionality: Fills SCS specific carrier list in UL frequency Info
6356  *
6357  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
6358  *
6359  * @return ROK     - success
6360  *         RFAILED - failure
6361  *
6362  * ****************************************************************/
6363 uint8_t BuildScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
6364 {
6365    uint8_t elementCnt = 0, listIdx = 0; 
6366    ScsSpecCarrier   duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.ulScsCarrier;
6367
6368    elementCnt = ODU_VALUE_ONE;
6369    scsCarrierList->list.count = elementCnt;
6370    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6371
6372    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6373    if(!scsCarrierList->list.array)
6374    {
6375       DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6376       return RFAILED;
6377    }
6378
6379    for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
6380    {
6381       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6382       if(!scsCarrierList->list.array[listIdx])
6383       {    
6384          DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6385          return RFAILED;
6386       }    
6387    }
6388    listIdx = 0; 
6389    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6390    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6391    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6392
6393    return ROK;
6394 }
6395
6396 /*******************************************************************
6397  *
6398  * @brief Fills frequency info in UL config common
6399  *
6400  * @details
6401  *
6402  *    Function : BuildFreqInfoUl
6403  *
6404  *    Functionality: Fills frequency info in UL config common
6405  *
6406  * @params[in] Pointer to FrequencyInfoUL_t
6407  *
6408  * @return ROK     - success
6409  *         RFAILED - failure
6410  *
6411  * ****************************************************************/
6412 uint8_t BuildFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
6413 {
6414    uint8_t elementCnt = 0, listIdx= 0;
6415    UlCfgCommon  ulCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg;
6416
6417    /* NR Multi Frequency Band List */
6418    DU_ALLOC(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
6419    if(!frequencyInfoUL->frequencyBandList)
6420    {
6421       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band list in BuildFreqInfoUl()");
6422       return RFAILED;
6423    }
6424
6425    elementCnt = ODU_VALUE_ONE;
6426    frequencyInfoUL->frequencyBandList->list.count = elementCnt;
6427    frequencyInfoUL->frequencyBandList->list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6428
6429    DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
6430    if(!frequencyInfoUL->frequencyBandList->list.array)
6431    {
6432       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array in BuildFreqInfoUl()");
6433       return RFAILED;
6434    }
6435
6436    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6437    {
6438       DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
6439       if(!frequencyInfoUL->frequencyBandList->list.array[listIdx])
6440       {
6441          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoUl()");
6442          return RFAILED;
6443       }
6444    }
6445
6446    listIdx = 0;
6447    *(frequencyInfoUL->frequencyBandList->list.array[listIdx]) = ulCfg.freqBandInd;
6448
6449    /* TODO : Fill Absolute frequency point A */
6450    /*
6451       DU_ALLOC(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
6452       if(!frequencyInfoUL->absoluteFrequencyPointA)
6453       {
6454       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for absolute frequency point A in BuildFreqInfoUl()");
6455       return RFAILED;
6456       }
6457     *(frequencyInfoUL->absoluteFrequencyPointA) = ?;
6458     */
6459
6460    /* Subcarrier Spacing specifc carrier */
6461    if((BuildScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList)) != ROK) 
6462    {
6463       DU_LOG("\nERROR  --> DU APP : Failed to fill SCS Specific Carrier list UL in BuildFreqInfoUl()");
6464       return RFAILED;
6465    }
6466
6467    /* P-MAX */
6468    DU_ALLOC(frequencyInfoUL->p_Max, sizeof(P_Max_t));
6469    if(!frequencyInfoUL->p_Max)
6470    {
6471       DU_LOG("\nERROR  -->  DU APP : UL Frequency Infoo  memory allocation failure");
6472       return RFAILED;
6473    }
6474    *frequencyInfoUL->p_Max = ulCfg.pMax;
6475
6476    return ROK;
6477 }
6478
6479 /*******************************************************************
6480  *
6481  * @brief Fills UL config common in Serving cell config common
6482  *
6483  * @details
6484  *
6485  *    Function : BuildUlConfigCommon
6486  *
6487  *    Functionality: Fills UL config common in Serving cell config common
6488  *
6489  * @params[in] Pointer to UplinkConfigCommon_t
6490  *
6491  * @return ROK     - success
6492  *         RFAILED - failure
6493  *
6494  * ****************************************************************/
6495 uint8_t BuildUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
6496 {
6497    /* UL Frequency Info */
6498    DU_ALLOC(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
6499    if(!ulCfgCommon->frequencyInfoUL)
6500    {
6501       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for UL frequency info in BuildUlConfigCommon()");
6502       return RFAILED;
6503    }
6504
6505    if((BuildFreqInfoUl(ulCfgCommon->frequencyInfoUL)) != ROK)
6506    {
6507       DU_LOG("\nERROR  -->  DU APP : Failed to fill frequency info UL in BuildUlConfigCommon()");
6508       return RFAILED;
6509    }
6510
6511    /* UL BWP common */
6512    DU_ALLOC(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
6513    if(!ulCfgCommon->initialUplinkBWP)
6514    {
6515       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for initial UL BWP in BuildUlConfigCommon()");
6516       return RFAILED;
6517    }
6518
6519    if((BuildBwpUlCommon(ulCfgCommon->initialUplinkBWP)) != ROK)
6520    {
6521       DU_LOG("\nERROR  -->  DU APP : Failed to fill BWP UL common in BuildUlConfigCommon()");
6522       return RFAILED;
6523    }
6524
6525    /* Time Alignment timer */
6526    ulCfgCommon->dummy = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.timeAlignTimerComm;
6527
6528    return ROK;
6529 }
6530
6531 /*******************************************************************
6532  *
6533  * @brief Fills SSB position in burst in SP cell config common
6534  *
6535  * @details
6536  *
6537  *    Function : BuildSsbPosInBurst
6538  *
6539  *    Functionality: 
6540  *       Fills SSB position in burst in SP cell config common
6541  *
6542  * @params[in] Pointer to struct ServingCellConfigCommon__ssb_PositionsInBurst
6543  *
6544  * @return ROK     - success
6545  *         RFAILED - failure
6546  *
6547  * ****************************************************************/
6548 uint8_t BuildSsbPosInBurst(struct ServingCellConfigCommon__ssb_PositionsInBurst *ssbPosInBurst)
6549 {
6550    uint8_t bitStringSizeInBytes = 0;
6551
6552    ssbPosInBurst->present = ServingCellConfigCommon__ssb_PositionsInBurst_PR_mediumBitmap;
6553
6554    /* As per spec 38.331,in the definition of ServingCellConfigCommon */
6555    bitStringSizeInBytes = 1;
6556    ssbPosInBurst->choice.mediumBitmap.size = bitStringSizeInBytes * sizeof(uint8_t);
6557
6558    DU_ALLOC(ssbPosInBurst->choice.mediumBitmap.buf, ssbPosInBurst->choice.mediumBitmap.size);
6559    if(!ssbPosInBurst->choice.mediumBitmap.buf)
6560    {
6561       DU_LOG("\nERROR  -->  DU APP : Memory Allocation failed for medium bit map buffer in BuildSsbPosInBurst()");
6562       return RFAILED;
6563    }
6564
6565    if((fillBitString(&ssbPosInBurst->choice.mediumBitmap, 0, bitStringSizeInBytes, \
6566                duCfgParam.sib1Params.srvCellCfgCommSib.ssbPosInBurst)) != ROK)
6567    {
6568       DU_LOG("\nERROR  -->  DU APP : Failed to fill medium bit map in BuildSsbPosInBurst()");
6569       return RFAILED;
6570    }
6571
6572    return ROK;
6573 }
6574
6575 /*******************************************************************
6576  *
6577  * @brief Fills SP cell config common in Reconfig with Sync
6578  *
6579  * @details
6580  *
6581  *    Function : BuildSpCellConfigCommon
6582  *
6583  *    Functionality: Fills SP cell config common in Reconfig with Sync
6584  *
6585  * @params[in] Pointer to ServingCellConfigCommon_t
6586  *
6587  * @return ROK     - success
6588  *         RFAILED - failure
6589  *
6590  * ****************************************************************/
6591 uint8_t BuildSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
6592 {
6593    /* Physical Cell Identity */
6594    DU_ALLOC(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
6595    if(!spCellConfigCommon->physCellId)
6596    {
6597       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for physical cell id in BuildSpCellConfigCommon()");
6598       return RFAILED;
6599    } 
6600    *(spCellConfigCommon->physCellId) = NR_PCI;
6601
6602    /* Downlink Config Common */
6603    DU_ALLOC(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
6604    if(!spCellConfigCommon->downlinkConfigCommon)
6605    {
6606       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for DL Config Common in BuildSpCellConfigCommon()");
6607       return RFAILED;
6608    }
6609    if((BuildDlConfigCommon(spCellConfigCommon->downlinkConfigCommon)) != ROK)
6610    {
6611       DU_LOG("\nERROR  -->  DU APP : Failed to fill DL config commin in BuildSpCellConfigCommon()");
6612       return RFAILED;
6613    }
6614
6615    /* Uplinlink Config Common */
6616    DU_ALLOC(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
6617    if(!spCellConfigCommon->uplinkConfigCommon)
6618    {
6619       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for UL Config Common in BuildSpCellConfigCommon()");
6620       return RFAILED;
6621    }
6622    if((BuildUlConfigCommon(spCellConfigCommon->uplinkConfigCommon)) != ROK)
6623    {
6624       DU_LOG("\nERROR  -->  DU APP : Failed to fill UL config commin in BuildSpCellConfigCommon()");
6625       return RFAILED;
6626    }
6627
6628    /* Timing Advance offset */
6629    DU_ALLOC(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
6630    if(!spCellConfigCommon->n_TimingAdvanceOffset)
6631    {
6632       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for Timing Advance Offset in BuildSpCellConfigCommon()");
6633       return RFAILED;
6634    }
6635    *(spCellConfigCommon->n_TimingAdvanceOffset) = ServingCellConfigCommon__n_TimingAdvanceOffset_n0;
6636
6637    /* SSB Position In Burst */
6638    DU_ALLOC(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
6639    if(!spCellConfigCommon->ssb_PositionsInBurst)
6640    {
6641       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Position In Burst in BuildSpCellConfigCommon()");
6642       return RFAILED;
6643    }
6644    if((BuildSsbPosInBurst(spCellConfigCommon->ssb_PositionsInBurst)) != ROK)
6645    {
6646       DU_LOG("\nERROR  -->  DU APP : Failed to fill SSB Position In Burst in BuildSpCellConfigCommon()");
6647       return RFAILED;
6648    }
6649
6650    /* SSB Periodicity in Serving cell */
6651    DU_ALLOC(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
6652    if(!spCellConfigCommon->ssb_periodicityServingCell)
6653    {
6654       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Periodicity serving cell in \
6655          BuildSpCellConfigCommon()");
6656       return RFAILED;
6657    }
6658    *(spCellConfigCommon->ssb_periodicityServingCell) = \
6659       convertSsbPeriodicityValueToEnum(duCfgParam.sib1Params.srvCellCfgCommSib.ssbPrdServingCell);
6660
6661    /* DMRS Type A position */
6662    spCellConfigCommon->dmrs_TypeA_Position = convertDmrsTypeAPosValueToEnum(duCfgParam.macCellCfg.dmrsTypeAPos);
6663
6664    /* SSB subcarrier spacing */
6665    DU_ALLOC(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
6666    if(!spCellConfigCommon->ssbSubcarrierSpacing)
6667    {
6668       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for sub-carrier spacing in BuildSpCellConfigCommon()");
6669       return RFAILED;
6670    }
6671    *(spCellConfigCommon->ssbSubcarrierSpacing) = duCfgParam.sib1Params.srvCellCfgCommSib.scs;
6672
6673    /* TDD UL-DL configuration common */
6674    DU_ALLOC(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
6675    if(!spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)
6676    {
6677       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for TDD UL-DL config common in BuildSpCellConfigCommon()");
6678       return RFAILED;
6679    }
6680    if((BuildTddUlDlCfgComm(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)) != ROK)
6681    {
6682       DU_LOG("\nERROR  -->  DU APP : Failed to fill TDD UL-DL config common in BuildSpCellConfigCommon()");
6683       return RFAILED;
6684    }
6685
6686    /* SS PBCH Block Power */
6687    spCellConfigCommon->ss_PBCH_BlockPower = duCfgParam.sib1Params.srvCellCfgCommSib.ssPbchBlockPwr;
6688
6689    return ROK;
6690 }
6691
6692 /*******************************************************************
6693  *
6694  * @brief Fills dedicated RACH configuration in Reconfiguration with sync
6695  *
6696  * @details
6697  *
6698  *    Function : BuildRecfgWithSync
6699  *
6700  *    Functionality: 
6701  *       Fills dedicated RACH configuration in Reconfiguration with sync
6702  *
6703  * @params[in] DU UE CB
6704  *             Pointer to Rach config dedicated struct
6705  *
6706  * @return ROK     - success
6707  *         RFAILED - failure
6708  *
6709  * ****************************************************************/
6710 uint8_t BuildRachConfigDedicated(DuUeCb *ueCb, struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
6711 {
6712    uint8_t elementCnt = 0, listIdx = 0;
6713    CFRA_t *cfra = NULLP;
6714    struct CFRA__resources__ssb *ssbResource = NULLP;
6715    RachCfgCommon duRachCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.rachCfg;
6716
6717    rachCfgDed->present = ReconfigurationWithSync__rach_ConfigDedicated_PR_uplink;
6718
6719    /* Uplink */
6720    DU_ALLOC(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
6721    if(!rachCfgDed->choice.uplink)
6722    {
6723       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for RACH uplink configuration in BuildRachConfigDedicated()");
6724       return RFAILED;
6725    }
6726
6727    /* CFRA : Contention free Random Access */
6728    DU_ALLOC(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
6729    if(!rachCfgDed->choice.uplink->cfra)
6730    {
6731       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA in BuildRachConfigDedicated()");
6732       return RFAILED;
6733    }
6734    cfra = rachCfgDed->choice.uplink->cfra;
6735
6736    /* CFRA occassions */
6737    DU_ALLOC(cfra->occasions, sizeof(struct CFRA__occasions));
6738    if(!cfra->occasions)
6739    {
6740       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA occassion in BuildRachConfigDedicated()");
6741       return RFAILED;
6742    }
6743
6744    /* CFRA occassions : RACH generic configuration */
6745    cfra->occasions->rach_ConfigGeneric.prach_ConfigurationIndex = duRachCfg.prachCfgIdx;
6746    cfra->occasions->rach_ConfigGeneric.msg1_FDM = duRachCfg.msg1Fdm;
6747    cfra->occasions->rach_ConfigGeneric.msg1_FrequencyStart = duRachCfg.msg1FreqStart;
6748    cfra->occasions->rach_ConfigGeneric.zeroCorrelationZoneConfig = duRachCfg.zeroCorrZoneCfg;
6749    cfra->occasions->rach_ConfigGeneric.preambleReceivedTargetPower = duRachCfg.preambleRcvdTgtPwr;
6750    cfra->occasions->rach_ConfigGeneric.preambleTransMax = duRachCfg.preambleTransMax;
6751    cfra->occasions->rach_ConfigGeneric.powerRampingStep = duRachCfg.pwrRampingStep;
6752    cfra->occasions->rach_ConfigGeneric.ra_ResponseWindow = duRachCfg.raRspWindow;
6753
6754    /* CFRA occassions : SSB per RACH occasion */
6755    DU_ALLOC(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
6756    if(!cfra->occasions->ssb_perRACH_Occasion)
6757    {
6758       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB per RACH occassion in BuildRachConfigDedicated()");
6759       return RFAILED;
6760    }
6761    *(cfra->occasions->ssb_perRACH_Occasion) = convertCFRASsbPerRachOccasionValueToEnum(duCfgParam.macCellCfg.prachCfg.ssbPerRach);
6762
6763    /* CFRA resource */
6764    cfra->resources.present = CFRA__resources_PR_ssb;
6765
6766    /* CFRA resource : SSB */
6767    DU_ALLOC(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
6768    if(!cfra->resources.choice.ssb)
6769    {
6770       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA resource - SSB in BuildRachConfigDedicated()");
6771       return RFAILED;
6772    }
6773    ssbResource = cfra->resources.choice.ssb;
6774
6775    /* CFRA SSB resource list */
6776    elementCnt = ueCb->cfraResource.numSsb;
6777    ssbResource->ssb_ResourceList.list.count = elementCnt;
6778    ssbResource->ssb_ResourceList.list.size = elementCnt * sizeof(CFRA_SSB_Resource_t *);
6779
6780    DU_ALLOC(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
6781    if(!ssbResource->ssb_ResourceList.list.array)
6782    {
6783       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list in BuildRachConfigDedicated()");
6784       return RFAILED;
6785    }
6786
6787    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6788    {
6789       DU_ALLOC(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
6790       if(!ssbResource->ssb_ResourceList.list.array[listIdx])
6791       {
6792          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list element in BuildRachConfigDedicated()");  
6793          return RFAILED;
6794       }
6795       ssbResource->ssb_ResourceList.list.array[listIdx]->ssb = ueCb->cfraResource.ssbResource[listIdx].ssbIdx;
6796       ssbResource->ssb_ResourceList.list.array[listIdx]->ra_PreambleIndex = ueCb->cfraResource.ssbResource[listIdx].raPreambleIdx;
6797    }
6798
6799    return ROK;
6800 }
6801
6802 /*******************************************************************
6803  *
6804  * @brief Fills reconfiguration with sync in SP cell config
6805  *
6806  * @details
6807  *
6808  *    Function : BuildRecfgWithSync
6809  *
6810  *    Functionality: Fills reconfiguration with sync in SP cell config
6811  *
6812  * @params[in] DU UE CB
6813  *             Pointer to ReconfigurationWithSync_t
6814  *
6815  * @return ROK     - success
6816  *         RFAILED - failure
6817  *
6818  * ****************************************************************/
6819 uint8_t BuildRecfgWithSync(DuUeCb *ueCb, ReconfigurationWithSync_t *recfgWithSync)
6820 {
6821    /* SP Cell Config Common */  
6822    DU_ALLOC(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
6823    if(!recfgWithSync->spCellConfigCommon)
6824    {
6825       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for spCellConfigCommon in BuildRecfgWithSync()");
6826       return RFAILED;
6827    }
6828
6829    if((BuildSpCellConfigCommon(recfgWithSync->spCellConfigCommon)) != ROK)
6830    {
6831       DU_LOG("\nERROR  -->  DU APP : Failed to build SpCellConfigCommon in BuildRecfgWithSync()");
6832       return RFAILED;
6833    }
6834
6835    /* New UE Identity */
6836    recfgWithSync->newUE_Identity = ueCb->crnti;
6837
6838    /* T304 timer */
6839    recfgWithSync->t304 = ReconfigurationWithSync__t304_ms1000;
6840
6841    /* RACH configuration dedicated */
6842    DU_ALLOC(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
6843    if(!recfgWithSync->rach_ConfigDedicated)
6844    {
6845       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for RACH config dedicated in BuildRecfgWithSync()");
6846       return RFAILED;
6847    }
6848
6849    if((BuildRachConfigDedicated(ueCb, recfgWithSync->rach_ConfigDedicated)) != ROK)
6850    {
6851       DU_LOG("\nERROR  -->  DU APP : Failed to build RACH config dedicated in BuildRecfgWithSync()");
6852       return RFAILED;
6853    }
6854
6855    return ROK;
6856 }
6857
6858 /*******************************************************************
6859  *
6860  * @brief Builds Spcell config 
6861  *
6862  * @details
6863  *
6864  *    Function : BuildSpCellCfg 
6865  *
6866  *    Functionality: Builds sp cell config in DuToCuRrcContainer
6867  *
6868  * @params[in] SpCellConfig_t spCellCfg
6869  *
6870  * @return ROK     - success
6871  *         RFAILED - failure
6872  *
6873  * ****************************************************************/
6874 uint8_t BuildSpCellCfg(DuUeCb *ueCb, SpCellConfig_t *spCellCfg)
6875 {
6876    spCellCfg->servCellIndex = NULLP;
6877    DU_ALLOC(spCellCfg->servCellIndex, sizeof(long));
6878    if(!spCellCfg->servCellIndex)
6879    {
6880       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6881       return RFAILED;
6882    }
6883
6884    if(ueCb == NULLP)
6885       *(spCellCfg->servCellIndex) = SERV_CELL_IDX;
6886    else
6887       *(spCellCfg->servCellIndex) = ueCb->macUeCfg.spCellCfg.servCellIdx;
6888
6889    spCellCfg->reconfigurationWithSync = NULLP;
6890    if(ueCb && (ueCb->ueState == UE_HANDIN_IN_PROGRESS))
6891    {
6892       DU_ALLOC(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
6893       if(!spCellCfg->reconfigurationWithSync)
6894       {
6895          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6896          return RFAILED;
6897       }
6898
6899       if((BuildRecfgWithSync(ueCb, spCellCfg->reconfigurationWithSync)) != ROK)
6900       {
6901          DU_LOG("\nERROR  -->  F1AP : Building of reconfiguration with sync failed at BuildSpCellCfg");
6902          return RFAILED;
6903       }
6904    }
6905
6906    spCellCfg->rlf_TimersAndConstants = NULLP;
6907    spCellCfg->rlmInSyncOutOfSyncThreshold = NULLP;
6908
6909    DU_ALLOC(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
6910    if(!spCellCfg->rlmInSyncOutOfSyncThreshold)
6911    {
6912       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6913       return RFAILED;
6914    }
6915    *(spCellCfg->rlmInSyncOutOfSyncThreshold) = RLM_SYNC_OUT_SYNC_THRESHOLD;
6916
6917    spCellCfg->spCellConfigDedicated = NULLP;
6918    DU_ALLOC(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
6919    if(!spCellCfg->spCellConfigDedicated)
6920    {
6921       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6922       return RFAILED;
6923    }
6924    if(BuildSpCellCfgDed(ueCb, spCellCfg->spCellConfigDedicated) != ROK)
6925    {
6926       DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfgDed failed");
6927       return RFAILED;
6928    }
6929
6930    return ROK;
6931 }
6932
6933 /*******************************************************************
6934  *
6935  * @brief Builds Phy cell group config 
6936  *
6937  * @details
6938  *
6939  *    Function : BuildPhyCellGrpCfg 
6940  *
6941  *    Functionality: Builds Phy cell group config in DuToCuRrcContainer
6942  *
6943  * @params[in] PhysicalCellGroupConfig_t *phyCellGrpCfg 
6944  *
6945  * @return ROK     - success
6946  *         RFAILED - failure
6947  *
6948  * ****************************************************************/
6949 uint8_t BuildPhyCellGrpCfg(DuUeCb *ueCb, PhysicalCellGroupConfig_t *phyCellGrpCfg)
6950 {
6951    phyCellGrpCfg->harq_ACK_SpatialBundlingPUCCH = NULLP;
6952    phyCellGrpCfg->harq_ACK_SpatialBundlingPUSCH = NULLP;
6953
6954    phyCellGrpCfg->p_NR_FR1 = NULLP;
6955    DU_ALLOC(phyCellGrpCfg->p_NR_FR1, sizeof(long));
6956    if(!phyCellGrpCfg->p_NR_FR1)
6957    {
6958       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhyCellGrpCfg");
6959       return RFAILED;
6960    }
6961
6962    if(ueCb == NULLP)
6963    {
6964       *(phyCellGrpCfg->p_NR_FR1)             = P_NR_FR1;
6965       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = PDSCH_HARQ_ACK_CODEBOOK;
6966    }
6967    else
6968    {
6969       *(phyCellGrpCfg->p_NR_FR1) = ueCb->macUeCfg.phyCellGrpCfg.pNrFr1;
6970       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = ueCb->macUeCfg.phyCellGrpCfg.pdschHarqAckCodebook;
6971    }
6972
6973    phyCellGrpCfg->tpc_SRS_RNTI = NULLP;
6974    phyCellGrpCfg->tpc_PUCCH_RNTI = NULLP;
6975    phyCellGrpCfg->tpc_PUSCH_RNTI = NULLP;
6976    phyCellGrpCfg->sp_CSI_RNTI = NULLP;
6977    phyCellGrpCfg->cs_RNTI = NULLP;
6978    phyCellGrpCfg->ext1 = NULLP;
6979    phyCellGrpCfg->ext2 = NULLP;
6980
6981    return ROK;
6982 }
6983
6984 /*******************************************************************
6985  *
6986  * @brief Builds Mac cell group config 
6987  *
6988  * @details
6989  *
6990  *    Function : BuildMacCellGrpCfg 
6991  *
6992  *    Functionality: Builds Mac cell group config in DuToCuRrcContainer
6993  *
6994  * @params[in] MAC_CellGroupConfig_t *macCellGrpCfg
6995  *
6996  * @return ROK     - success
6997  *         RFAILED - failure
6998  *
6999  * ****************************************************************/
7000 uint8_t BuildMacCellGrpCfg(DuUeCb *ueCb, MAC_CellGroupConfig_t *macCellGrpCfg)
7001 {
7002    macCellGrpCfg->drx_Config = NULLP;
7003    macCellGrpCfg->schedulingRequestConfig = NULLP;
7004    DU_ALLOC(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
7005    if(!macCellGrpCfg->schedulingRequestConfig)
7006    {
7007       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7008       return RFAILED;
7009    }
7010
7011    if(BuildSchedulingReqConfig(ueCb, macCellGrpCfg->schedulingRequestConfig) != ROK)
7012    {
7013       DU_LOG("\nERROR  -->  F1AP : BuildSchedulingReqConfig failed");
7014       return RFAILED;
7015    }
7016
7017    macCellGrpCfg->bsr_Config = NULLP;
7018    DU_ALLOC(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
7019    if(!macCellGrpCfg->bsr_Config)
7020    {
7021       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7022       return RFAILED;
7023    }
7024
7025    if(BuildBsrConfig(ueCb, macCellGrpCfg->bsr_Config) != ROK)
7026    {
7027       DU_LOG("\nERROR  -->  F1AP : BuildBsrConfig failed");
7028       return RFAILED;
7029    }
7030
7031    macCellGrpCfg->tag_Config = NULLP;
7032    DU_ALLOC(macCellGrpCfg->tag_Config, sizeof(struct TAG_Config));
7033    if(!macCellGrpCfg->tag_Config)
7034    {
7035       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7036       return RFAILED;
7037    }
7038
7039    if(BuildTagConfig(ueCb, macCellGrpCfg->tag_Config) != ROK)
7040    {
7041       DU_LOG("\nERROR  -->  F1AP : BuildTagConfig failed");
7042       return RFAILED;
7043    }
7044
7045    macCellGrpCfg->phr_Config = NULLP;
7046    DU_ALLOC(macCellGrpCfg->phr_Config, sizeof(struct MAC_CellGroupConfig__phr_Config));
7047    if(!macCellGrpCfg->phr_Config)
7048    {
7049       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7050       return RFAILED;
7051    }
7052
7053    if(BuildPhrConfig(ueCb, macCellGrpCfg->phr_Config) != ROK)
7054    {
7055       DU_LOG("\nERROR  -->  F1AP : BuildPhrConfig failed");
7056       return RFAILED;
7057    }
7058
7059    macCellGrpCfg->skipUplinkTxDynamic = false;
7060    macCellGrpCfg->ext1 = NULLP;
7061
7062    return ROK;
7063 }
7064 /*******************************************************************
7065  *
7066  * @brief Frees memeory allocated for SearchSpcToAddModList
7067  *
7068  * @details
7069  *
7070  *    Function : FreeSearchSpcToAddModList
7071  *
7072  *    Functionality: Deallocating memory of SearchSpcToAddModList
7073  *
7074  * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
7075  *
7076  * @return void
7077  *
7078  4221 * ****************************************************************/
7079 void FreeSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
7080 {
7081    uint8_t idx1=0;
7082    uint8_t idx2=0;
7083    struct  SearchSpace *searchSpc=NULLP;
7084
7085    if(searchSpcList->list.array)
7086    {
7087       if(searchSpcList->list.array[idx2])
7088       {
7089          searchSpc = searchSpcList->list.array[idx2];
7090          if(searchSpc->controlResourceSetId)
7091          {
7092             if(searchSpc->monitoringSlotPeriodicityAndOffset)
7093             {
7094                if(searchSpc->monitoringSymbolsWithinSlot)
7095                {
7096                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
7097                   {
7098                      if(searchSpc->nrofCandidates)
7099                      {
7100                         if(searchSpc->searchSpaceType)
7101                         {
7102                            DU_FREE(searchSpc->searchSpaceType->choice.ue_Specific,\
7103                                  sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
7104                            DU_FREE(searchSpc->searchSpaceType, sizeof(struct
7105                                     SearchSpace__searchSpaceType));
7106                         }
7107                         DU_FREE(searchSpc->nrofCandidates,
7108                               sizeof(struct SearchSpace__nrofCandidates));
7109                      }
7110                      DU_FREE(searchSpc->monitoringSymbolsWithinSlot->buf, \
7111                            searchSpc->monitoringSymbolsWithinSlot->size);
7112                   }
7113                   DU_FREE(searchSpc->monitoringSymbolsWithinSlot,
7114                         sizeof(BIT_STRING_t));
7115                }
7116                DU_FREE(searchSpc->monitoringSlotPeriodicityAndOffset, \
7117                      sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
7118             }
7119             DU_FREE(searchSpc->controlResourceSetId,
7120                   sizeof(ControlResourceSetId_t));
7121          }
7122       }
7123       for(idx1 = 0; idx1 < searchSpcList->list.count; idx1++)
7124       {
7125          DU_FREE(searchSpcList->list.array[idx1],
7126                sizeof(struct SearchSpace));
7127       }
7128       DU_FREE(searchSpcList->list.array,searchSpcList->list.size);
7129    }
7130 }
7131 /*******************************************************************
7132  *
7133  * @brief Frees memory allocated for PdschTimeDomAllocList
7134  *
7135  * @details
7136  *
7137  *    Function : FreePdschTimeDomAllocList
7138  *
7139  *    Functionality: Deallocating memory of PdschTimeDomAllocList
7140  *
7141  * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
7142  *
7143  * @return void
7144  *
7145  * ****************************************************************/
7146 void FreePdschTimeDomAllocList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
7147 {
7148    uint8_t idx1=0;
7149
7150    if(timeDomAllocList->choice.setup)
7151    {
7152       if(timeDomAllocList->choice.setup->list.array)
7153       {
7154          for(idx1 = 0; idx1 <timeDomAllocList->choice.setup->list.count ; idx1++)
7155          {
7156             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1]->k0, sizeof(long));
7157             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1],
7158                   sizeof(struct PDSCH_TimeDomainResourceAllocation));
7159          }
7160          DU_FREE(timeDomAllocList->choice.setup->list.array, \
7161                timeDomAllocList->choice.setup->list.size);
7162       }
7163       DU_FREE(timeDomAllocList->choice.setup,\
7164             sizeof(struct PDSCH_TimeDomainResourceAllocationList));
7165    }
7166 }
7167 /*******************************************************************
7168  *
7169  * @brief Frees memory allocated for PuschTimeDomAllocList
7170  *
7171  *@details
7172  *
7173  *    Function : FreePuschTimeDomAllocList
7174  *
7175  *    Functionality: Deallocating memory of PuschTimeDomAllocList
7176  *
7177  * @params[in] PUSCH_Config_t *puschCfg
7178  *
7179  * @return void
7180  *
7181  * ****************************************************************/
7182 void FreePuschTimeDomAllocList(PUSCH_Config_t *puschCfg)
7183 {
7184    uint8_t rsrcListIdx=0;
7185    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
7186
7187    if(puschCfg->pusch_TimeDomainAllocationList)
7188    {
7189       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
7190       if(timeDomAllocList_t->choice.setup)
7191       {
7192          if(timeDomAllocList_t->choice.setup->list.array)
7193          {
7194             for(rsrcListIdx = 0; rsrcListIdx<timeDomAllocList_t->choice.setup->list.count; rsrcListIdx++)
7195             {
7196                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx]->k2, sizeof(long));
7197                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx],\
7198                      sizeof(PUSCH_TimeDomainResourceAllocation_t));
7199             }
7200             DU_FREE(timeDomAllocList_t->choice.setup->list.array, \
7201                   timeDomAllocList_t->choice.setup->list.size);
7202          }
7203          DU_FREE(timeDomAllocList_t->choice.setup, \
7204                sizeof(struct PUSCH_TimeDomainResourceAllocationList));
7205       }
7206       DU_FREE(puschCfg->transformPrecoder, sizeof(long));
7207       DU_FREE(puschCfg->pusch_TimeDomainAllocationList, \
7208             sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
7209    }
7210
7211 }
7212
7213 /*******************************************************************
7214  *
7215  * @brief Frees memory allocated for Dedicated PUCCH config
7216  *
7217  * @details
7218  *
7219  *    Function : FreeBWPUlDedPucchCfg
7220  *
7221  *    Functionality: Deallocating memory of Dedicated PUCCH cfg
7222  *
7223  * @params[in] BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg
7224  *
7225  * @return void
7226  *
7227  * ****************************************************************/
7228 void FreeBWPUlDedPucchCfg(struct BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg)
7229 {
7230    uint8_t k1Idx, rsrcIdx, rsrcSetIdx;
7231    PUCCH_Config_t *pucchCfg = NULLP;
7232    PUCCH_ResourceSet_t *rsrcSet = NULLP;
7233    PUCCH_Resource_t *rsrc = NULLP;
7234
7235    if(ulBwpPucchCfg)
7236    {
7237       if(ulBwpPucchCfg->choice.setup)
7238       {
7239          pucchCfg = ulBwpPucchCfg->choice.setup;
7240
7241          //Free resource set list
7242          if(pucchCfg->resourceSetToAddModList)
7243          {
7244             if(pucchCfg->resourceSetToAddModList->list.array)
7245             {
7246                for(rsrcSetIdx=0; rsrcSetIdx < pucchCfg->resourceSetToAddModList->list.count; rsrcSetIdx++)
7247                {
7248                   rsrcSet = pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx];
7249                   if(rsrcSet->resourceList.list.array)
7250                   {
7251                      for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
7252                      {
7253                         DU_FREE(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
7254                      }
7255                      DU_FREE(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
7256                   }
7257                   DU_FREE(pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
7258                }
7259                DU_FREE(pucchCfg->resourceSetToAddModList->list.array, pucchCfg->resourceSetToAddModList->list.size);
7260             }
7261             DU_FREE(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
7262          }
7263
7264          //Free resource list
7265          if(pucchCfg->resourceToAddModList)
7266          {
7267             if(pucchCfg->resourceToAddModList->list.array)
7268             {
7269                for(rsrcIdx=0; rsrcIdx < pucchCfg->resourceToAddModList->list.count; rsrcIdx++)
7270                {
7271                   rsrc = pucchCfg->resourceToAddModList->list.array[rsrcIdx];
7272                   DU_FREE(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
7273                   DU_FREE(pucchCfg->resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
7274                }
7275                DU_FREE(pucchCfg->resourceToAddModList->list.array, pucchCfg->resourceToAddModList->list.size);
7276             }
7277             DU_FREE(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
7278          }
7279
7280          //PUCCH Format 1
7281          if(pucchCfg->format1)
7282          {
7283             if(pucchCfg->format1->choice.setup)
7284             {
7285                DU_FREE(pucchCfg->format1->choice.setup->nrofSlots, sizeof(long));
7286                DU_FREE(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
7287             }
7288             DU_FREE(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
7289          }
7290          
7291          //DL DATA TO UL ACK
7292          if(pucchCfg->dl_DataToUL_ACK)
7293          {
7294             if(pucchCfg->dl_DataToUL_ACK->list.array)
7295             {
7296                for(k1Idx = 0; k1Idx <  pucchCfg->dl_DataToUL_ACK->list.count; k1Idx++)
7297                {
7298                   DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array[k1Idx], sizeof(long));
7299                }
7300                DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array, pucchCfg->dl_DataToUL_ACK->list.size);
7301             }
7302             DU_FREE(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
7303          }
7304
7305          DU_FREE(ulBwpPucchCfg->choice.setup, sizeof(PUCCH_Config_t));
7306       }
7307       DU_FREE(ulBwpPucchCfg, sizeof(struct BWP_UplinkDedicated__pucch_Config));
7308    }
7309 }
7310
7311 /*******************************************************************
7312  *
7313  * @brief Frees memory allocated for InitialUlBWP
7314  *
7315  * @details
7316  *
7317  *    Function : FreeInitialUlBWP
7318  *
7319  *    Functionality: Deallocating memory of InitialUlBWP
7320  *
7321  * @params[in] BWP_UplinkDedicated_t *ulBwp
7322  *
7323  * @return void
7324  *
7325  * ****************************************************************/
7326 void FreeInitialUlBWP(BWP_UplinkDedicated_t *ulBwp)
7327 {
7328    uint8_t  rSetIdx, rsrcIdx;
7329    SRS_Config_t   *srsCfg = NULLP;
7330    PUSCH_Config_t *puschCfg = NULLP;
7331    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
7332    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
7333    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
7334    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
7335
7336    FreeBWPUlDedPucchCfg(ulBwp->pucch_Config);
7337
7338    if(ulBwp->pusch_Config)
7339    {
7340       if(ulBwp->pusch_Config->choice.setup)
7341       {
7342          puschCfg=ulBwp->pusch_Config->choice.setup;
7343          if(puschCfg->dataScramblingIdentityPUSCH)
7344          {
7345             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
7346             {
7347                FreePuschTimeDomAllocList(puschCfg);
7348                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
7349                if(dmrsUlCfg->choice.setup)
7350                {
7351                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
7352                   {
7353                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
7354                      {
7355                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
7356                               sizeof(long));
7357                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled,
7358                               sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
7359                      }
7360                      DU_FREE(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition,
7361                            sizeof(long));
7362                   }
7363                   DU_FREE(dmrsUlCfg->choice.setup,sizeof(DMRS_UplinkConfig_t));
7364                }
7365                DU_FREE(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, \
7366                      sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
7367             }
7368             DU_FREE(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
7369          }
7370          DU_FREE(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
7371       }
7372       DU_FREE(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
7373
7374       /* Free SRS-Config */
7375       if(ulBwp->srs_Config)
7376       {
7377          if(ulBwp->srs_Config->choice.setup)
7378          {
7379             srsCfg = ulBwp->srs_Config->choice.setup;
7380
7381             /* Free Resource Set to add/mod list */
7382             if(srsCfg->srs_ResourceSetToAddModList)
7383             {
7384                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
7385                if(rsrcSetList->list.array)
7386                {
7387                   rSetIdx = 0;
7388
7389                   /* Free SRS resource Id list in this SRS resource set */
7390                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
7391                   {
7392                      rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
7393
7394                      if(rsrcIdList->list.array)
7395                      {
7396                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
7397                         {
7398                            DU_FREE(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
7399                         }
7400                         DU_FREE(rsrcIdList->list.array, rsrcIdList->list.size);
7401                      }
7402                      DU_FREE(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
7403                            sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
7404                   }
7405
7406                   /* Free resource type info for this SRS resource set */
7407                   DU_FREE(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
7408                         sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
7409
7410                   /* Free memory for each resource set */
7411                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
7412                   {
7413                      DU_FREE(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
7414                   }
7415                   DU_FREE(rsrcSetList->list.array, rsrcSetList->list.size); 
7416                }
7417                DU_FREE(srsCfg->srs_ResourceSetToAddModList, \
7418                      sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
7419             }
7420
7421             /* Free resource to add/modd list */
7422             if(srsCfg->srs_ResourceToAddModList)
7423             {
7424                resourceList = srsCfg->srs_ResourceToAddModList;
7425                if(resourceList->list.array)
7426                {
7427                   rsrcIdx = 0;
7428                   DU_FREE(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2,\
7429                         sizeof(struct SRS_Resource__transmissionComb__n2));
7430                   DU_FREE(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,\
7431                         sizeof(struct SRS_Resource__resourceType__aperiodic));
7432
7433                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
7434                   {
7435                      DU_FREE(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
7436                   }
7437                   DU_FREE(resourceList->list.array, resourceList->list.size);
7438                }
7439                DU_FREE(srsCfg->srs_ResourceToAddModList, \
7440                      sizeof(struct SRS_Config__srs_ResourceToAddModList));
7441             }
7442
7443             DU_FREE(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
7444          }
7445          DU_FREE(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
7446       }
7447    }
7448 }       
7449 /*******************************************************************
7450  *
7451  * @brief Frees memory allocated for initialUplinkBWP
7452  *
7453  * @details
7454  *
7455  *    Function : FreeinitialUplinkBWP
7456  *
7457  *    Functionality: Deallocating memory of initialUplinkBWP
7458  *
7459  * @params[in] UplinkConfig_t *ulCfg
7460  *
7461  * @return void
7462  *         
7463  *
7464  * ****************************************************************/
7465 void FreeinitialUplinkBWP(UplinkConfig_t *ulCfg)
7466 {
7467    BWP_UplinkDedicated_t *ulBwp=NULLP; 
7468    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
7469
7470    if(ulCfg->initialUplinkBWP)
7471    {
7472       ulBwp=ulCfg->initialUplinkBWP;
7473       if(ulCfg->firstActiveUplinkBWP_Id)
7474       {
7475          if(ulCfg->pusch_ServingCellConfig)
7476          {
7477             puschCfg=ulCfg->pusch_ServingCellConfig;
7478             if(puschCfg->choice.setup)
7479             {
7480                if(puschCfg->choice.setup->ext1)
7481                {
7482                   DU_FREE(puschCfg->choice.setup->ext1->\
7483                         processingType2Enabled,sizeof(BOOLEAN_t));
7484                   DU_FREE(puschCfg->choice.setup->ext1->\
7485                         maxMIMO_Layers,sizeof(long));
7486                   DU_FREE(puschCfg->choice.setup->ext1, \
7487                         sizeof(struct PUSCH_ServingCellConfig__ext1));
7488                }
7489                DU_FREE(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
7490             }
7491             DU_FREE(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
7492          }
7493          DU_FREE(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
7494       }
7495       FreeInitialUlBWP(ulBwp);
7496       DU_FREE(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
7497    }
7498 }
7499 /*******************************************************************
7500  *
7501  * @brief Frees emmory allocated for BWPDlDedPdschCfg
7502  *
7503  * @details
7504  *
7505  *    Function : FreeBWPDlDedPdschCfg
7506  *
7507  *    Functionality: Deallocating memory of BWPDlDedPdschCfg
7508  *
7509  * @params[in] BWP_DownlinkDedicated_t *dlBwp
7510  *
7511  * @return void
7512  *
7513  *
7514  * ****************************************************************/
7515 void FreeBWPDlDedPdschCfg(BWP_DownlinkDedicated_t *dlBwp)
7516 {
7517    struct PDSCH_Config *pdschCfg=NULLP;
7518    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
7519    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
7520    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
7521
7522    if(dlBwp->pdsch_Config->choice.setup)
7523    {
7524       pdschCfg=dlBwp->pdsch_Config->choice.setup;
7525       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
7526       {
7527          if(pdschCfg->pdsch_TimeDomainAllocationList)
7528          {
7529             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
7530             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
7531             {
7532                prbBndlType=&pdschCfg->prb_BundlingType;
7533                DU_FREE(prbBndlType->choice.staticBundling,\
7534                      sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
7535                DU_FREE(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
7536             }
7537             FreePdschTimeDomAllocList(timeDomAllocList);
7538             DU_FREE(pdschCfg->pdsch_TimeDomainAllocationList, \
7539                   sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
7540          }
7541          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
7542          if(dmrsDlCfg->choice.setup)
7543          {
7544             DU_FREE(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition,
7545                   sizeof(long));
7546             DU_FREE(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
7547          }
7548          DU_FREE(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, \
7549                sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
7550       }
7551       DU_FREE(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
7552    }
7553 }
7554 /*******************************************************************
7555  *
7556  * @brief Frees emmory allocated for BWPDlDedPdcchCfg
7557  *
7558  * @details
7559  *
7560  *    Function : FreeBWPDlDedPdcchCfg
7561  *
7562  *    Functionality: Deallocating memory of BWPDlDedPdcchCfg
7563  *
7564  * @params[in] BWP_DownlinkDedicated_t *dlBwp
7565  *
7566  * @return void
7567  *         
7568  *
7569  * ****************************************************************/
7570 void FreeBWPDlDedPdcchCfg(BWP_DownlinkDedicated_t *dlBwp)
7571 {
7572    uint8_t idx1=0;
7573    uint8_t idx2=0;
7574    struct PDCCH_Config *pdcchCfg=NULLP;
7575    struct ControlResourceSet *controlRSet=NULLP;
7576    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
7577
7578    if(dlBwp->pdcch_Config->choice.setup)
7579    {
7580       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
7581       if(pdcchCfg->controlResourceSetToAddModList)
7582       {
7583          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
7584          if(controlRSetList->list.array)
7585          {
7586             controlRSet = controlRSetList->list.array[idx2];
7587             if(controlRSet)
7588             {
7589                if(controlRSet->frequencyDomainResources.buf)
7590                {
7591                   if(controlRSet->pdcch_DMRS_ScramblingID)
7592                   {
7593                      if(pdcchCfg->searchSpacesToAddModList)
7594                      {
7595                         FreeSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
7596                         DU_FREE(pdcchCfg->searchSpacesToAddModList, \
7597                               sizeof(struct PDCCH_Config__searchSpacesToAddModList));
7598                      }
7599                      DU_FREE(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
7600                   }
7601                   DU_FREE(controlRSet->frequencyDomainResources.buf, \
7602                         controlRSet->frequencyDomainResources.size);
7603                }
7604             }
7605             for(idx1 = 0; idx1 <controlRSetList->list.count; idx1++)
7606             {
7607                DU_FREE(controlRSetList->list.array[idx1], sizeof(struct ControlResourceSet));
7608             }
7609             DU_FREE(controlRSetList->list.array, controlRSetList->list.size);
7610          }
7611          DU_FREE(pdcchCfg->controlResourceSetToAddModList, \
7612                sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
7613       }
7614       DU_FREE(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
7615    }
7616 }       
7617
7618 /*******************************************************************
7619  *
7620  * @brief Free SCS specific carrier list in DL frequency info
7621  *
7622  * @details
7623  *
7624  *    Function : FreeScsSpecificCarrierListDl
7625  *
7626  *    Functionality: Free SCS specific carrier list in DL frequency info
7627  *
7628  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
7629  *
7630  * @return void
7631  *
7632  * ****************************************************************/
7633 void FreeScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
7634 {
7635    uint8_t listIdx = 0;
7636
7637    if(!scsCarrierList->list.array)
7638    {
7639       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
7640       {
7641          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
7642       }
7643       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
7644    }
7645 }
7646
7647 /*******************************************************************
7648  *
7649  * @brief Free DL frequency info in DL config common
7650  *
7651  * @details
7652  *
7653  *    Function : FreeFreqInfoDl
7654  *
7655  *    Functionality: Free DL frequency info in DL config common
7656  *
7657  * @params[in] Pointer to DownlinkConfigCommon_t
7658  *
7659  * @return void
7660  *
7661  * ****************************************************************/
7662 void FreeFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
7663 {
7664    uint8_t freqBandIdx = 0;
7665
7666    /* SSB Absolute Frequency */
7667    DU_FREE(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
7668
7669    /* NR Multi Frequency Band List */
7670    if(frequencyInfoDL->frequencyBandList.list.array)
7671    {
7672       for(freqBandIdx = 0; freqBandIdx < frequencyInfoDL->frequencyBandList.list.count; freqBandIdx++)
7673       {
7674          DU_FREE(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
7675       }
7676       DU_FREE(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
7677    }
7678
7679    /* Subcarrier Spacing specifc carrier List */
7680    FreeScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList);
7681 }
7682
7683 /*******************************************************************
7684  *
7685  * @brief Free DL config common in Serving cell config common
7686  *
7687  * @details
7688  *
7689  *    Function : FreeDlConfigCommon
7690  *
7691  *    Functionality: Free DL config common in Serving cell config common
7692  *
7693  * @params[in] Pointer to DownlinkConfigCommon_t
7694  *
7695  * @return void
7696  *
7697  * ****************************************************************/
7698 void FreeDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
7699 {
7700    /* DL Frequency Info */
7701    if(dlCfgCommon->frequencyInfoDL)
7702    {
7703       FreeFreqInfoDl(dlCfgCommon->frequencyInfoDL);
7704       DU_FREE(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
7705    }
7706
7707    /* DL BWP config common */
7708    if(dlCfgCommon->initialDownlinkBWP)
7709    {
7710       FreeBwpDlCommon(dlCfgCommon->initialDownlinkBWP);
7711       DU_FREE(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
7712    }
7713 }
7714
7715 /*******************************************************************
7716  *
7717  * @brief Free SCS specific carrier list in UL frequency Info
7718  *
7719  * @details
7720  *
7721  *    Function : FreeScsSpecificCarrierListUl
7722  *
7723  *    Functionality: Free SCS specific carrier list in UL frequency Info
7724  *
7725  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
7726  *
7727  * @return void
7728  *
7729  * ****************************************************************/
7730 void FreeScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
7731 {
7732    uint8_t listIdx = 0;
7733
7734    if(scsCarrierList->list.array)
7735    {
7736       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
7737       {
7738          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
7739       }
7740       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
7741    }
7742 }
7743
7744 /*******************************************************************
7745  *
7746  * @brief Free frequency info in UL config common
7747  *
7748  * @details
7749  *
7750  *    Function : FreeFreqInfoUl
7751  *
7752  *    Functionality: Free frequency info in UL config common
7753  *
7754  * @params[in] Pointer to FrequencyInfoUL_t
7755  *
7756  * @return void
7757  *
7758  * ****************************************************************/
7759 void FreeFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
7760 {
7761    uint8_t listIdx= 0;
7762
7763    /* NR Multi Frequency Band List */
7764    if(!frequencyInfoUL->frequencyBandList)
7765    {
7766       if(frequencyInfoUL->frequencyBandList->list.array)
7767       {
7768          for(listIdx = 0; listIdx < frequencyInfoUL->frequencyBandList->list.count; listIdx++)
7769          {
7770             DU_FREE(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
7771          }
7772          DU_FREE(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
7773       }
7774       DU_FREE(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
7775    }
7776
7777    /* Absolute frequency point A */
7778    DU_FREE(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
7779
7780    /* Subcarrier Spacing specifc carrier */
7781    FreeScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList);
7782
7783    /* P-MAX */
7784    DU_FREE(frequencyInfoUL->p_Max, sizeof(P_Max_t));
7785 }
7786
7787 /*******************************************************************
7788  *
7789  * @brief Free UL config common in Serving cell config common
7790  *
7791  * @details
7792  *
7793  *    Function : FreeUlConfigCommon
7794  *
7795  *    Functionality: Free UL config common in Serving cell config common
7796  *
7797  * @params[in] Pointer to UplinkConfigCommon_t
7798  *
7799  * @return void
7800  *
7801  * ****************************************************************/
7802 void FreeUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
7803 {
7804    /* UL Frequency Info */
7805    if(ulCfgCommon->frequencyInfoUL)
7806    {
7807       FreeFreqInfoUl(ulCfgCommon->frequencyInfoUL);
7808       DU_FREE(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
7809    }
7810
7811    /* UL BWP common */
7812    if(ulCfgCommon->initialUplinkBWP)
7813    {
7814       FreeBwpUlCommon(ulCfgCommon->initialUplinkBWP);
7815       DU_FREE(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
7816    }
7817 }
7818
7819 /*******************************************************************
7820  *
7821  * @brief Free SP cell config common in Reconfig with Sync
7822  *
7823  * @details
7824  *
7825  *    Function : FreeSpCellConfigCommon
7826  *
7827  *    Functionality: Free SP cell config common in Reconfig with Sync
7828  *
7829  * @params[in] Pointer to ServingCellConfigCommon_t
7830  *
7831  * @return void
7832  *
7833  * ****************************************************************/
7834 void FreeSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
7835 {
7836    /* Free Physical cell identity */
7837    DU_FREE(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
7838
7839    /* Free Downlink Config common */
7840    if(spCellConfigCommon->downlinkConfigCommon)
7841    {
7842       FreeDlConfigCommon(spCellConfigCommon->downlinkConfigCommon);
7843       DU_FREE(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
7844    }
7845
7846    /* Free Uplink Config common */
7847    if(spCellConfigCommon->uplinkConfigCommon)
7848    {
7849       FreeUlConfigCommon(spCellConfigCommon->uplinkConfigCommon);
7850       DU_FREE(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
7851    }
7852
7853    /* Free Timing Advance offset */
7854    DU_FREE(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
7855
7856    /* Free SSB Position in Burst */
7857    if(spCellConfigCommon->ssb_PositionsInBurst)
7858    {
7859       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.buf, \
7860          spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.size);
7861       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
7862    }
7863
7864    /* Free SSB Periodicity in Serving cell */
7865    DU_FREE(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
7866
7867    /* Free SSB subcarrier spacing */
7868    DU_FREE(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
7869
7870    /* TDD UL-DL configuration common */
7871    DU_FREE(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
7872 }
7873
7874 /*******************************************************************
7875  *
7876  * @brief Free dedicated RACH configuration in Reconfiguration with sync
7877  *
7878  * @details
7879  *
7880  *    Function : FreeRecfgWithSync
7881  *
7882  *    Functionality:
7883  *       Free dedicated RACH configuration in Reconfiguration with sync
7884  *
7885  * @params[in] Pinter to Rach config dedicated struct
7886  *
7887  * @return void
7888  *
7889  * ****************************************************************/
7890 void FreeRachConfigDedicated(struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
7891 {
7892    uint8_t listIdx = 0;
7893    CFRA_t *cfra = NULLP;
7894    struct CFRA__resources__ssb *ssbResource = NULLP;
7895
7896    /* Uplink */
7897    if(rachCfgDed->choice.uplink)
7898    {
7899       /* CFRA : Contention free Random Access */
7900       if(rachCfgDed->choice.uplink->cfra)
7901       {
7902          cfra = rachCfgDed->choice.uplink->cfra;
7903
7904          /* CFRA occassions */
7905          if(cfra->occasions)
7906          {
7907             /* CFRA occassions : SSB per RACH occasion */
7908             DU_FREE(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
7909             DU_FREE(cfra->occasions, sizeof(struct CFRA__occasions));
7910          }
7911
7912          /* CFRA resource */
7913          cfra->resources.present = CFRA__resources_PR_ssb;
7914
7915          /* CFRA resource : SSB */
7916          if(cfra->resources.choice.ssb)
7917          {
7918             ssbResource = cfra->resources.choice.ssb;
7919
7920             /* CFRA SSB resource list */
7921             if(ssbResource->ssb_ResourceList.list.array)
7922             {
7923                for(listIdx = 0; listIdx < ssbResource->ssb_ResourceList.list.count; listIdx++)
7924                {
7925                   DU_FREE(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
7926                }
7927                DU_FREE(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
7928             }
7929             DU_FREE(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
7930          }
7931          DU_FREE(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
7932       }
7933       DU_FREE(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
7934    }
7935 }
7936
7937 /*******************************************************************
7938  *
7939  * @brief Frees reconfiguration with sync in SP cell config
7940  *
7941  * @details
7942  *
7943  *    Function : FreeRecfgWithSync
7944  *
7945  *    Functionality: Fress reconfiguration with sync in SP cell config
7946  *
7947  * @params[in] Pointer to ReconfigurationWithSync_t
7948  *
7949  * @return void
7950  *
7951  * ****************************************************************/
7952 void FreeRecfgWithSync(ReconfigurationWithSync_t *recfgWithSync)
7953 {
7954    /* Free SP Cell config common */
7955    if(recfgWithSync->spCellConfigCommon)
7956    {
7957       FreeSpCellConfigCommon(recfgWithSync->spCellConfigCommon);
7958       DU_FREE(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
7959    }
7960
7961    /* Free Dedicated RACH configuration */
7962    if(recfgWithSync->rach_ConfigDedicated)
7963    {
7964       FreeRachConfigDedicated(recfgWithSync->rach_ConfigDedicated);
7965       DU_FREE(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
7966    }
7967 }
7968
7969 /*******************************************************************
7970  *
7971  * @brief Frees emmory allocated for DUToCURRCContainer 
7972  *
7973  * @details
7974  *
7975  *    Function : FreeMemDuToCuRrcCont
7976  *
7977  *    Functionality: Deallocating memory of DuToCuRrcContainer
7978  *
7979  * @params[in] DuToCuRRCContainer, DuToCuRRCContainer
7980  *
7981  * @return ROK     - success
7982  *         RFAILED - failure
7983  *
7984  * ****************************************************************/
7985 uint8_t FreeMemDuToCuRrcCont(CellGroupConfigRrc_t *cellGrpCfg)
7986 {
7987    uint8_t idx=0;
7988    SpCellConfig_t *spCellCfg=NULLP;
7989    ServingCellConfig_t *srvCellCfg=NULLP;
7990    BWP_DownlinkDedicated_t *dlBwp=NULLP;
7991    MAC_CellGroupConfig_t *macCellGrpCfg=NULLP;
7992    PhysicalCellGroupConfig_t *phyCellGrpCfg=NULLP;
7993    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList=NULLP;
7994    struct RLC_Config *rlcConfig=NULLP;
7995    struct LogicalChannelConfig *macLcConfig=NULLP;
7996    struct SchedulingRequestConfig *schedulingRequestConfig=NULLP;
7997    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList=NULLP;
7998    struct TAG_Config *tagConfig=NULLP;
7999    struct TAG_Config__tag_ToAddModList *tagList=NULLP;
8000    struct MAC_CellGroupConfig__phr_Config *phrConfig=NULLP;
8001    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg=NULLP;
8002
8003    rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
8004    if(rlcBearerList)
8005    {
8006       if(rlcBearerList->list.array)
8007       {
8008          for(idx=0; idx<rlcBearerList->list.count; idx++)
8009          {
8010             if(rlcBearerList->list.array[idx])
8011             {  
8012                rlcConfig   = rlcBearerList->list.array[idx]->rlc_Config;
8013                macLcConfig = rlcBearerList->list.array[idx]->mac_LogicalChannelConfig;
8014                if(rlcConfig)
8015                {
8016                   switch(rlcConfig->present)
8017                   {
8018                      case RLC_Config_PR_am:
8019                         {
8020                            if(rlcConfig->choice.am)
8021                            {
8022                               DU_FREE(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
8023                               DU_FREE(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
8024                               DU_FREE(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
8025                            }
8026                            break;
8027                         }
8028                      case RLC_Config_PR_um_Bi_Directional:
8029                         {
8030                            if(rlcConfig->choice.um_Bi_Directional)
8031                            {
8032                               DU_FREE(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t)); 
8033                               DU_FREE(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8034                               DU_FREE(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
8035                            }
8036                            break;
8037                         }
8038                      case RLC_Config_PR_um_Uni_Directional_UL:
8039                         {
8040                            if(rlcConfig->choice.um_Uni_Directional_UL)
8041                            {
8042                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8043                               DU_FREE(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
8044                            }
8045                            break;
8046                         }
8047                      case RLC_Config_PR_um_Uni_Directional_DL:
8048                         {
8049                            if(rlcConfig->choice.um_Uni_Directional_DL )
8050                            {
8051                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
8052                               DU_FREE(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
8053                            }
8054                            break;
8055                         }
8056                   }     
8057                   DU_FREE(rlcConfig, sizeof(struct RLC_Config));
8058                }
8059                DU_FREE(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
8060                if(macLcConfig)
8061                {
8062                   if(macLcConfig->ul_SpecificParameters)
8063                   {
8064                      DU_FREE(macLcConfig->ul_SpecificParameters->schedulingRequestID,   sizeof(SchedulingRequestId_t));
8065                      DU_FREE(macLcConfig->ul_SpecificParameters->logicalChannelGroup,   sizeof(long));
8066                      DU_FREE(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
8067                   }
8068                   DU_FREE(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
8069                }
8070                DU_FREE(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
8071             }   
8072          }
8073          DU_FREE(rlcBearerList->list.array, rlcBearerList->list.size);
8074       }
8075       DU_FREE(cellGrpCfg->rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8076    }
8077
8078    macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
8079    if(macCellGrpCfg)
8080    {
8081       schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig; 
8082       if(schedulingRequestConfig)
8083       {
8084          schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
8085          if(schReqList)
8086          {
8087             if(schReqList->list.array)
8088             {
8089                for(idx=0;idx<schReqList->list.count; idx++)
8090                {
8091                   if(schReqList->list.array[idx])
8092                   {
8093                      DU_FREE(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
8094                      DU_FREE(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
8095                   }
8096                }
8097                DU_FREE(schReqList->list.array, schReqList->list.size);
8098             }
8099             DU_FREE(schedulingRequestConfig->schedulingRequestToAddModList,\
8100                   sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));    }
8101             DU_FREE(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
8102       }
8103       if(macCellGrpCfg->bsr_Config)
8104       {
8105          DU_FREE(macCellGrpCfg->bsr_Config->logicalChannelSR_DelayTimer, sizeof(long));
8106          DU_FREE(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
8107       }
8108       tagConfig = macCellGrpCfg->tag_Config;
8109       if(tagConfig)
8110       {
8111          tagList = tagConfig->tag_ToAddModList;
8112          if(tagList)
8113          {
8114             if(tagList->list.array)
8115             {
8116                for(idx=0; idx<tagList->list.count; idx++)
8117                {
8118                   DU_FREE(tagList->list.array[idx], sizeof(struct TAG));
8119                }
8120                DU_FREE(tagList->list.array, tagList->list.size);
8121             }
8122             DU_FREE(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
8123          }
8124          DU_FREE(tagConfig, sizeof(struct TAG_Config));
8125       }
8126
8127       phrConfig = macCellGrpCfg->phr_Config;
8128       if(phrConfig)
8129       {
8130          DU_FREE(phrConfig->choice.setup, sizeof(struct PHR_Config));
8131          DU_FREE(phrConfig, sizeof(struct MAC_CellGroupConfig__phr_Config));
8132       }
8133
8134       DU_FREE(macCellGrpCfg, sizeof(MAC_CellGroupConfig_t));
8135    }
8136
8137    phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
8138    if(phyCellGrpCfg)
8139    {
8140       DU_FREE(phyCellGrpCfg->p_NR_FR1, sizeof(long));
8141       DU_FREE(phyCellGrpCfg, sizeof(PhysicalCellGroupConfig_t));
8142    }
8143
8144    spCellCfg = cellGrpCfg->spCellConfig;
8145    if(spCellCfg)
8146    {
8147       /* Free serving cell index */
8148       DU_FREE(spCellCfg->servCellIndex, sizeof(long));
8149
8150       /* Free Reconfiguration with sync */
8151       if(spCellCfg->reconfigurationWithSync)
8152       {
8153          FreeRecfgWithSync(spCellCfg->reconfigurationWithSync);
8154          DU_FREE(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
8155       }
8156
8157       /* Free rlmInSyncOutOfSyncThreshold */
8158       DU_FREE(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
8159
8160       /* Free SP Cell config dedicated */
8161       if(spCellCfg->spCellConfigDedicated)
8162       {
8163          srvCellCfg = spCellCfg->spCellConfigDedicated;
8164
8165          /* Free TDD UL-DL config dedicated */
8166          DU_FREE(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
8167
8168          /* Free Initial Downlink BWP */
8169          if(srvCellCfg->initialDownlinkBWP)
8170          {
8171             dlBwp = srvCellCfg->initialDownlinkBWP;
8172
8173             /* Free DL BWP PDCCH Config */
8174             if(dlBwp->pdcch_Config)
8175             {
8176                FreeBWPDlDedPdcchCfg(dlBwp);
8177                DU_FREE(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
8178             }
8179
8180             /* Free DL BWP PDSCH config */
8181             if(dlBwp->pdsch_Config)
8182             {
8183                FreeBWPDlDedPdschCfg(dlBwp);
8184                DU_FREE(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
8185             }
8186             DU_FREE(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
8187          }
8188
8189          /* Free First Active Downlink BWP */
8190          DU_FREE(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
8191
8192          /* Free Default downlink BWP */
8193          DU_FREE(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
8194
8195          /* Free Uplink config */
8196          if(srvCellCfg->uplinkConfig)
8197          {
8198             FreeinitialUplinkBWP(srvCellCfg->uplinkConfig);
8199             DU_FREE(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));  
8200          }
8201
8202          /* Free PDSCH serving cell config */
8203          if(srvCellCfg->pdsch_ServingCellConfig)
8204          {
8205             pdschCfg= srvCellCfg->pdsch_ServingCellConfig;
8206             if(pdschCfg->choice.setup)
8207             {
8208                DU_FREE(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH,sizeof(long));
8209                DU_FREE(pdschCfg->choice.setup, sizeof(struct PDSCH_ServingCellConfig));
8210             }
8211             DU_FREE(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct ServingCellConfig__pdsch_ServingCellConfig));
8212          }
8213
8214          DU_FREE(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
8215       }
8216       DU_FREE(spCellCfg,sizeof(SpCellConfig_t));
8217    }
8218    return ROK;
8219 }
8220
8221 /*******************************************************************
8222  *
8223  * @brief Builds CellGroupConfigRrc for DU To CU RRC Container 
8224  *
8225  * @details
8226  *
8227  *    Function : BuildCellGroupConfigRrc
8228  *
8229  *    Functionality: Builds and copied Cell group config buffer into 
8230  *       DuToCuRrcContainer
8231  *
8232  * @params[in] idx, index in F1AP msg
8233  *             DuToCuRRCContainer, DuToCuRRCContainer
8234  *
8235  * @return ROK     - success
8236  *         RFAILED - failure
8237  *
8238  * ****************************************************************/
8239 uint8_t BuildCellGroupConfigRrc(DuUeCb *ueCb, OCTET_STRING_t *duToCuRrcContainer)
8240 {
8241    uint8_t  ret = ROK;
8242    CellGroupConfigRrc_t  cellGrpCfg;
8243    asn_enc_rval_t        encRetVal;
8244    memset(&cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
8245    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8246
8247    while(true)
8248    {
8249       cellGrpCfg.cellGroupId = CELL_GRP_ID;
8250
8251       cellGrpCfg.rlc_BearerToAddModList = NULLP;
8252       DU_ALLOC(cellGrpCfg.rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8253       if(!cellGrpCfg.rlc_BearerToAddModList)
8254       {
8255          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8256          ret = RFAILED;
8257          break;
8258       }
8259       if(BuildRlcBearerToAddModList(ueCb, cellGrpCfg.rlc_BearerToAddModList) != ROK)
8260       {
8261          DU_LOG("\nERROR  -->  F1AP : BuildRlcBearerToAddModList failed");
8262          ret = RFAILED;
8263          break;
8264       }
8265
8266       cellGrpCfg.rlc_BearerToReleaseList = NULLP;
8267       cellGrpCfg.mac_CellGroupConfig = NULLP;
8268       DU_ALLOC(cellGrpCfg.mac_CellGroupConfig, sizeof(MAC_CellGroupConfig_t));
8269       if(!cellGrpCfg.mac_CellGroupConfig)
8270       {
8271          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8272          ret = RFAILED;
8273          break;
8274       }
8275       if(BuildMacCellGrpCfg(ueCb, cellGrpCfg.mac_CellGroupConfig) != ROK)
8276       {
8277          DU_LOG("\nERROR  -->  F1AP : BuildMacCellGrpCfg failed");
8278          ret = RFAILED;
8279          break;
8280       }
8281
8282       cellGrpCfg.physicalCellGroupConfig = NULLP;
8283       DU_ALLOC(cellGrpCfg.physicalCellGroupConfig, sizeof(PhysicalCellGroupConfig_t));
8284       if(!cellGrpCfg.physicalCellGroupConfig)
8285       {
8286          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8287          ret = RFAILED;
8288          break;
8289       }
8290       if(BuildPhyCellGrpCfg(ueCb, cellGrpCfg.physicalCellGroupConfig) != ROK)
8291       {
8292          DU_LOG("\nERROR  -->  F1AP : BuildPhyCellGrpCfg failed");
8293          ret = RFAILED;
8294          break;
8295       }
8296
8297       cellGrpCfg.spCellConfig = NULLP;
8298       DU_ALLOC(cellGrpCfg.spCellConfig, sizeof(SpCellConfig_t));
8299       if(!cellGrpCfg.spCellConfig)
8300       {
8301          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8302          ret = RFAILED;
8303          break;
8304       }
8305       if(BuildSpCellCfg(ueCb, cellGrpCfg.spCellConfig) != ROK)
8306       {
8307          DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfg failed");
8308          ret = RFAILED;
8309          break;
8310       }
8311
8312       cellGrpCfg.sCellToAddModList = NULLP;
8313       cellGrpCfg.sCellToReleaseList = NULLP;
8314       cellGrpCfg.ext1 = NULLP;
8315
8316       /* encode cellGrpCfg into duToCuRrcContainer */
8317       xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, &cellGrpCfg);
8318       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8319       encBufSize = 0;
8320       encRetVal = aper_encode(&asn_DEF_CellGroupConfigRrc, 0, &cellGrpCfg, PrepFinalEncBuf, encBuf);
8321       /* Encode results */
8322       if(encRetVal.encoded == ENCODE_FAIL)
8323       {
8324          DU_LOG( "\nERROR  --> F1AP : Could not encode DuToCuRrcContainer (at %s)\n",\
8325                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
8326          ret = RFAILED;
8327          break;
8328       }
8329       else
8330       {
8331          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DuToCuRrcContainer\n");
8332          for(int i=0; i< encBufSize; i++)
8333          {
8334             printf("%x",encBuf[i]);
8335          }
8336       }
8337
8338       duToCuRrcContainer->size = encBufSize;
8339       DU_ALLOC(duToCuRrcContainer->buf, duToCuRrcContainer->size);
8340       if(!duToCuRrcContainer->buf)
8341       {
8342          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDuToCuRrcContainer");
8343          ret = RFAILED;
8344          break;
8345       }
8346       if(ret == ROK)
8347       {
8348          memcpy(duToCuRrcContainer->buf, encBuf, duToCuRrcContainer->size);
8349       }
8350       break;
8351    }
8352    FreeMemDuToCuRrcCont(&cellGrpCfg);
8353    return ret;
8354 }
8355
8356 /*******************************************************************
8357  *
8358  * @brief Free memory allocated in InitialULRRCMessage
8359  *
8360  * @details
8361  *
8362  *    Function : freeInitUlRrcMsgTransfer
8363  *
8364  *    Functionality: Free memory allocated in InitialULRRCMessage
8365  *
8366  * @params[in]F1AP_PDU_t  *f1apMsg)
8367  *
8368  * @return ROK     - success
8369  *         RFAILED - failure
8370  *
8371  * ****************************************************************/
8372
8373 uint8_t freeInitUlRrcMsgTransfer(F1AP_PDU_t  *f1apMsg)
8374 {
8375    uint8_t ieIdx, arrIdx;
8376    InitialULRRCMessageTransfer_t *initULRRCMsg=NULLP;
8377
8378    if(f1apMsg)
8379    {
8380       if(f1apMsg->choice.initiatingMessage)
8381       {
8382          initULRRCMsg = &f1apMsg->choice.initiatingMessage->value.\
8383             choice.InitialULRRCMessageTransfer;
8384          if(initULRRCMsg->protocolIEs.list.array)
8385          {
8386             for(ieIdx = 0; ieIdx < initULRRCMsg->protocolIEs.list.count; ieIdx++)
8387             {
8388                switch(initULRRCMsg->protocolIEs.list.array[ieIdx]->id)
8389                {
8390                   case ProtocolIE_ID_id_NRCGI:
8391                   {
8392                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf)
8393                      {
8394                         if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf)
8395                         {
8396                            DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf,\
8397                            initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.size);
8398                         }
8399                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf,\
8400                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.size);
8401                      }
8402                      break;
8403                   }
8404                   case ProtocolIE_ID_id_RRCContainer:
8405                   {
8406                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
8407                      {
8408                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,\
8409                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
8410                      }
8411                      break;
8412                   }
8413                   case ProtocolIE_ID_id_DUtoCURRCContainer:
8414                   {
8415                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf)
8416                      {
8417                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf,
8418                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.size);
8419                      }
8420                      break;
8421                   }
8422                   default:
8423                      break;
8424                }
8425              }
8426              for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
8427              {
8428                 if(initULRRCMsg->protocolIEs.list.array[arrIdx])
8429                 {
8430                    DU_FREE(initULRRCMsg->protocolIEs.list.array[arrIdx],\
8431                       sizeof(InitialULRRCMessageTransferIEs_t));
8432                 }
8433              }
8434              DU_FREE(initULRRCMsg->protocolIEs.list.array, initULRRCMsg->protocolIEs.list.size);
8435           }
8436          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8437       }
8438       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
8439    }
8440    else
8441    {
8442       DU_LOG("\nERROR  -->  DU_APP : Recevied F1ap Pdu is null at freeInitUlRrcMsgTransfer()");
8443       return RFAILED;
8444    }
8445    return ROK;
8446 }
8447
8448 /*******************************************************************
8449  *
8450  * @brief Builds and sends the InitialULRRCMessage 
8451  *
8452  * @details
8453  *
8454  *    Function : BuildAndSendInitialRrcMsgTransfer 
8455  *
8456  *    Functionality: Constructs the Initial UL RRC Message Transfer and sends
8457  *                   it to the CU through SCTP.
8458  *
8459  * @params[in] 
8460  *
8461  * @return ROK     - success
8462  *         RFAILED - failure
8463  *
8464  * ****************************************************************/
8465 uint8_t BuildAndSendInitialRrcMsgTransfer(uint32_t gnbDuUeF1apId, uint16_t crnti,
8466       uint16_t rrcContSize, uint8_t *rrcContainer)
8467 {
8468    uint8_t   ret;
8469    uint8_t   elementCnt;
8470    uint8_t   ieIdx, cellIdx, ueIdx;
8471    DuUeCb    *duUeCb = NULLP;
8472    asn_enc_rval_t  encRetVal;
8473    F1AP_PDU_t  *f1apMsg = NULLP;
8474    InitialULRRCMessageTransfer_t *initULRRCMsg = NULLP;
8475    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8476
8477    while(true)
8478    {
8479       DU_LOG("\n INFO   -->  F1AP : Building RRC Setup Request\n");
8480       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
8481       if(f1apMsg == NULLP)
8482       {
8483          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
8484          break;
8485       }
8486       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
8487       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8488       if(f1apMsg->choice.initiatingMessage == NULLP)
8489       {
8490          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU failed");
8491          break;
8492       }
8493       f1apMsg->choice.initiatingMessage->procedureCode =\
8494                                                         ProcedureCode_id_InitialULRRCMessageTransfer;
8495       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
8496       f1apMsg->choice.initiatingMessage->value.present = \
8497                                                          InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
8498       initULRRCMsg =\
8499                     &f1apMsg->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
8500       elementCnt = 5;
8501       initULRRCMsg->protocolIEs.list.count = elementCnt;
8502       initULRRCMsg->protocolIEs.list.size = \
8503                                             elementCnt * sizeof(InitialULRRCMessageTransferIEs_t *);
8504       /* Initialize the F1Setup members */
8505       DU_ALLOC(initULRRCMsg->protocolIEs.list.array,initULRRCMsg->protocolIEs.list.size);
8506       if(initULRRCMsg->protocolIEs.list.array == NULLP)
8507       {
8508          DU_LOG(" ERROR  -->  F1AP : Memory allocation for\
8509                RRCSetupRequestMessageTransferIEs failed");
8510          break;
8511       }
8512       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
8513       {
8514          DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx],\
8515                sizeof(InitialULRRCMessageTransferIEs_t));
8516          if(initULRRCMsg->protocolIEs.list.array[ieIdx] == NULLP)
8517          {
8518             break;
8519          }
8520       }
8521       ieIdx = 0;
8522       /*GNB DU UE F1AP ID*/
8523       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8524                                                         ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
8525       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  = Criticality_reject;
8526       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
8527                                                                   InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
8528       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
8529
8530
8531       /*NRCGI*/
8532       ieIdx++;
8533       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8534                                                         ProtocolIE_ID_id_NRCGI;
8535       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  =Criticality_reject;
8536       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
8537                                                                   InitialULRRCMessageTransferIEs__value_PR_NRCGI;
8538
8539       ret =\
8540            BuildNrcgi(&initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
8541       if(ret!=ROK)
8542       {
8543          break;
8544       }
8545
8546       /*CRNTI*/
8547       ieIdx++;
8548       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8549                                                         ProtocolIE_ID_id_C_RNTI;
8550       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
8551       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
8552                                                                  InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
8553       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.C_RNTI = crnti;
8554
8555       /*RRCContainer*/
8556       ieIdx++;
8557       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8558                                                         ProtocolIE_ID_id_RRCContainer;
8559       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
8560       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
8561                                                                  InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
8562
8563       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size = rrcContSize;
8564       DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,
8565             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size)
8566       if(!initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
8567       {
8568          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRCSetupRequestMessageTransferIEs failed");
8569          break;
8570       
8571       }
8572       memcpy(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, rrcContainer,
8573             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
8574
8575
8576       /*DUtoCURRCContainer*/
8577       ieIdx++;
8578       initULRRCMsg->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCContainer;
8579       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
8580       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
8581                                                                  InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
8582
8583       for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
8584       {
8585          for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
8586          {
8587             if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
8588                   (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti == crnti))
8589             {
8590                duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
8591             }
8592          }
8593       }
8594
8595       ret = BuildCellGroupConfigRrc(duUeCb, &initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer);
8596       if(ret != ROK)
8597       {
8598          break;
8599       }
8600
8601       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
8602
8603       /* Encode the Intial UL RRC Message transfer as APER */
8604       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8605       encBufSize = 0;
8606       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
8607       /* Encode results */
8608       if(encRetVal.encoded == ENCODE_FAIL)
8609       {
8610          DU_LOG( "\nERROR  --> F1AP : Could not encode Initial UL RRC Message Transfer\
8611                structure (at %s)\n",encRetVal.failed_type ? \
8612                encRetVal.failed_type->name : "unknown");
8613          ret = RFAILED;
8614          break;
8615       }
8616       else
8617       {
8618
8619          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Initial UL RRC\
8620                Message transfer\n");
8621          for(int i=0; i< encBufSize; i++)
8622          {
8623             printf("%x",encBuf[i]);
8624          }
8625       }
8626       /* Sending  msg  */
8627       if(sendF1APMsg() != ROK)
8628       {
8629          DU_LOG("\nERROR  -->  F1AP : Sending Initial UL RRC Message Transfer Failed");
8630          ret = RFAILED;
8631          break;
8632       }
8633       break;
8634    }
8635    freeInitUlRrcMsgTransfer(f1apMsg);
8636    return ret;
8637 }/* End of BuildAndSendInitialRrcMsgTransfer*/
8638
8639 /*****  UE SETUP REQUEST *****/
8640
8641 /*******************************************************************
8642  *
8643  * @brief Free Qos And Snssai Drb Info
8644  *
8645  * @details
8646  *
8647  *    Function : freeDrbQosAndSnssaiInfo
8648  *
8649  *    Functionality: Free Qos And Snssai Drb Info
8650  *
8651  * @params[in] LcCfg *lcCfg,
8652  * @return void
8653  *
8654  * ****************************************************************/
8655 void freeDrbQosAndSnssaiInfo(LcCfg *lcCfg)
8656 {
8657    if(lcCfg->snssai)
8658    {
8659       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
8660    }
8661    if(lcCfg->drbQos)
8662    {
8663       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
8664    }
8665 }
8666
8667 /******************************************************************
8668 *
8669 * @brief Function to delete the RLC Lc cfg from UE APP DB
8670 *
8671 * @details
8672 *
8673 *  Function : freeRlcLcCfg
8674 *
8675 *  Functionality: Function to delete the RLC Lc cfg from UE APP DB
8676 *
8677 *
8678  *****************************************************************/
8679
8680 void freeRlcLcCfg(RlcBearerCfg *lcCfg)
8681 {
8682    switch(lcCfg->rlcMode)
8683    {
8684       case RLC_AM :
8685          {
8686             if(lcCfg->u.amCfg)
8687             {
8688                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
8689             }
8690             break;
8691          }
8692       case RLC_UM_BI_DIRECTIONAL :
8693          {
8694             if(lcCfg->u.umBiDirCfg)
8695             {
8696                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
8697             }
8698             break;
8699          }
8700       case RLC_UM_UNI_DIRECTIONAL_UL :
8701          {
8702             if(lcCfg->u.umUniDirUlCfg)
8703             {
8704                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
8705             }
8706             break;
8707
8708          }
8709       case RLC_UM_UNI_DIRECTIONAL_DL :
8710          {
8711             if(lcCfg->u.umUniDirDlCfg)
8712             {
8713                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
8714             }
8715             break;
8716          }
8717       default:
8718          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at freeRlcLcCfg()", lcCfg->rlcMode);
8719          break;
8720    }
8721    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
8722 }
8723
8724 /*******************************************************************
8725  *
8726  * @brief Function to free MacLcCfg
8727  *
8728  * @details
8729  *
8730  *    Function : freeMacLcCfg
8731  *
8732  *    Functionality: Function to free MacLcCfg
8733  *
8734  * @params[in] LcCfg *lcCfg,
8735  * @return void
8736  *
8737  * ****************************************************************/
8738
8739 void  freeMacLcCfg(LcCfg *lcCfg)
8740 {
8741     /* Deleting DRBQOS */
8742    if(lcCfg->drbQos)
8743    {
8744       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
8745    }
8746    /* Deleting SNSSAI */
8747    if(lcCfg->snssai)
8748    {
8749       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
8750    }
8751 }
8752 /*******************************************************************
8753  *
8754  * @brief Free UE NR Capability received in UE Context setup request
8755  *
8756  * @details
8757  *
8758  *    Function : freeAperDecodeUeNrCapability
8759  *
8760  *    Functionality:  
8761  *       Free UE NR Capability received in UE Context setup request
8762  *
8763  * @params[in] 
8764  * @return ROK     - success
8765  *         RFAILED - failure
8766  *
8767  * ****************************************************************/
8768 void freeAperDecodeUeNrCapability(void *ueNrCapability)
8769 {
8770    uint8_t arrIdx =0;
8771    FeatureSets_t *featureSets =NULLP;
8772    UE_NR_Capability_t *ueNrCap = (UE_NR_Capability_t *)ueNrCapability;
8773
8774    if(ueNrCap->rf_Parameters.supportedBandListNR.list.array)
8775    {
8776       for(arrIdx = 0; arrIdx < ueNrCap->rf_Parameters.supportedBandListNR.list.count; arrIdx++)
8777       {
8778          if(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx])
8779             free(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx]);
8780       }
8781       free(ueNrCap->rf_Parameters.supportedBandListNR.list.array);
8782    }
8783
8784    if(ueNrCap->featureSets)
8785    {
8786       featureSets = ueNrCap->featureSets;
8787       if(featureSets->featureSetsDownlinkPerCC)
8788       {
8789          if(featureSets->featureSetsDownlinkPerCC->list.array)
8790          {
8791             for(arrIdx = 0; arrIdx < featureSets->featureSetsDownlinkPerCC->list.count; arrIdx++)
8792             {
8793                if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx])
8794                {
8795                   if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL)
8796                      free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL);
8797                   free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]);
8798                }
8799             }
8800             free(featureSets->featureSetsDownlinkPerCC->list.array);
8801          }
8802          free(featureSets->featureSetsDownlinkPerCC);
8803       }
8804       if(featureSets->featureSetsUplinkPerCC)
8805       {
8806          if(featureSets->featureSetsUplinkPerCC->list.array)
8807          {
8808             for(arrIdx = 0; arrIdx < featureSets->featureSetsUplinkPerCC->list.count; arrIdx++)
8809             {
8810                if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx])
8811                {
8812                   if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL)
8813                      free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL);
8814                   free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]);
8815                }
8816             }
8817             free(featureSets->featureSetsUplinkPerCC->list.array);
8818          }
8819          free(featureSets->featureSetsUplinkPerCC);
8820       }
8821       free(ueNrCap->featureSets);
8822    }   
8823 }
8824
8825 /*******************************************************************
8826 *
8827 * @brief Function to free PdcchSearchSpcToAddModList
8828          where memory allocated by aper_decoder
8829 *
8830 * @details
8831 *
8832 *    Function : freeAperDecodePdcchSearchSpcToAddModList 
8833 *
8834 *    Functionality: Function to free PdcchSearchSpcToAddModList
8835 *
8836 * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
8837 * @return void
8838 *
8839 * ****************************************************************/
8840
8841 void freeAperDecodePdcchSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
8842 {
8843    uint8_t searchSpcArrIdx=0;
8844    uint8_t searchSpcArrIdx1=0;
8845    struct  SearchSpace *searchSpc=NULLP;
8846
8847
8848    if(searchSpcList->list.array)
8849    {
8850       if(searchSpcList->list.array[searchSpcArrIdx1])
8851       {
8852          searchSpc = searchSpcList->list.array[searchSpcArrIdx1];
8853          if(searchSpc->controlResourceSetId)
8854          {
8855             if(searchSpc->monitoringSlotPeriodicityAndOffset)
8856             {
8857                if(searchSpc->monitoringSymbolsWithinSlot)
8858                {
8859                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
8860                   {
8861                      if(searchSpc->nrofCandidates)
8862                      {
8863                         if(searchSpc->searchSpaceType)
8864                         {
8865                            free(searchSpc->searchSpaceType->choice.ue_Specific);
8866                            free(searchSpc->searchSpaceType);
8867                         }
8868                         free(searchSpc->nrofCandidates);
8869                      }
8870                      free(searchSpc->monitoringSymbolsWithinSlot->buf);
8871                   }
8872                   free(searchSpc->monitoringSymbolsWithinSlot);
8873                }
8874                free(searchSpc->monitoringSlotPeriodicityAndOffset);
8875             }
8876             free(searchSpc->controlResourceSetId);
8877          }
8878       }
8879       for(searchSpcArrIdx = 0; searchSpcArrIdx < searchSpcList->list.count; searchSpcArrIdx++)
8880       {
8881          free(searchSpcList->list.array[searchSpcArrIdx]);
8882       }
8883       free(searchSpcList->list.array);
8884    }
8885 }
8886 /*******************************************************************
8887 *
8888 * @brief Function for free part for the memory allocated by aper_decoder
8889
8890 * @details
8891 *
8892 *    Function : freeAperDecodeBWPDlDedPdcchConfig
8893 *
8894 *    Functionality: Function to free BWPDlDedPdcchConfig
8895 *
8896 * @params[in] 
8897 * @return void
8898 *
8899 * ****************************************************************/
8900
8901
8902 void freeAperDecodeBWPDlDedPdcchConfig(BWP_DownlinkDedicated_t *dlBwp)
8903 {
8904    uint8_t arrIdx1=0;
8905    uint8_t arrIdx2=0;
8906    struct PDCCH_Config *pdcchCfg=NULLP;
8907    struct ControlResourceSet *controlRSet=NULLP;
8908    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
8909    
8910    if(dlBwp->pdcch_Config->choice.setup)
8911    {
8912       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
8913       if(pdcchCfg->controlResourceSetToAddModList)
8914       {
8915          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
8916          if(controlRSetList->list.array)
8917          {
8918             controlRSet = controlRSetList->list.array[arrIdx2];
8919             if(controlRSet)
8920             {
8921                if(controlRSet->frequencyDomainResources.buf)
8922                {
8923                   if(controlRSet->pdcch_DMRS_ScramblingID)
8924                   {
8925                      if(pdcchCfg->searchSpacesToAddModList)
8926                      {
8927                         freeAperDecodePdcchSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
8928                         free(pdcchCfg->searchSpacesToAddModList);
8929                      }
8930                      free(controlRSet->pdcch_DMRS_ScramblingID);
8931                   }
8932                   free(controlRSet->frequencyDomainResources.buf);
8933                }
8934             }
8935             for(arrIdx1 = 0; arrIdx1 <controlRSetList->list.count; arrIdx1++)
8936             {
8937                free(controlRSetList->list.array[arrIdx1]);
8938             }
8939             free(controlRSetList->list.array);
8940          }
8941          free(pdcchCfg->controlResourceSetToAddModList);
8942       }
8943       free(dlBwp->pdcch_Config->choice.setup);
8944    }
8945 }
8946 /*******************************************************************
8947 *
8948 * @brief Function to free PdschTimeDomAllocationList 
8949 *     where the memory allocated by aper_decoder
8950
8951 * @details
8952 *
8953 *    Function : freeAperDecodePdschTimeDomAllocationList
8954 *
8955 *    Functionality: Function to free PdschTimeDomAllocationList
8956 *
8957 * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList 
8958 * @return void
8959 *
8960 * ****************************************************************/
8961
8962
8963 void freeAperDecodePdschTimeDomAllocationList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
8964 {
8965    uint8_t arrIdx=0;
8966
8967    if(timeDomAllocList->choice.setup)
8968    {
8969       if(timeDomAllocList->choice.setup->list.array)
8970       {
8971          for(arrIdx = 0; arrIdx <timeDomAllocList->choice.setup->list.count ; arrIdx++)
8972          {
8973             free(timeDomAllocList->choice.setup->list.array[arrIdx]);
8974          }
8975          free(timeDomAllocList->choice.setup->list.array);
8976       }
8977       free(timeDomAllocList->choice.setup);
8978    }
8979 }
8980
8981 /*******************************************************************
8982 *
8983 * @brief Function to free BWPDlDedPdschConfig 
8984 *        where the memory allocated by aper_decoder
8985 *  
8986 * @details
8987 *
8988 *    Function : freeAperDecodeBWPDlDedPdschConfig 
8989 *
8990 *    Functionality: Function to free BWPDlDedPdschConfig 
8991 *
8992 * @params[in] BWP_DownlinkDedicated_t *dlBwp 
8993 * @return void
8994 *
8995 * ****************************************************************/
8996
8997
8998 void freeAperDecodeBWPDlDedPdschConfig(BWP_DownlinkDedicated_t *dlBwp)
8999 {
9000    struct PDSCH_Config *pdschCfg=NULLP;
9001    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
9002    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
9003    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
9004
9005    if(dlBwp->pdsch_Config->choice.setup)
9006    {
9007       pdschCfg=dlBwp->pdsch_Config->choice.setup;
9008       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
9009       {
9010          if(pdschCfg->pdsch_TimeDomainAllocationList)
9011          {
9012             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
9013             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
9014             {
9015                prbBndlType=&pdschCfg->prb_BundlingType;
9016                free(prbBndlType->choice.staticBundling);
9017                free(pdschCfg->maxNrofCodeWordsScheduledByDCI);
9018             }
9019             freeAperDecodePdschTimeDomAllocationList(timeDomAllocList);
9020             free(pdschCfg->pdsch_TimeDomainAllocationList);
9021          }
9022          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
9023          if(dmrsDlCfg->choice.setup)
9024          {
9025             free(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition);
9026             free(dmrsDlCfg->choice.setup);
9027          }
9028          free(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA);
9029       }
9030       free(dlBwp->pdsch_Config->choice.setup);
9031    }
9032 }
9033 /*******************************************************************
9034 *
9035 * @brief Function to free PuschTimeDomAllocListCfg
9036                  where the memory allocated by aper_decoder
9037 *
9038 * @details
9039 *
9040 *    Function : freeAperDecodePuschTimeDomAllocListCfg
9041 *
9042 *    Functionality: Function to free PuschTimeDomAllocListCfg
9043 *
9044 * @params[in] PUSCH_Config_t *puschCfg 
9045 * @return void
9046 *
9047 * ****************************************************************/
9048
9049
9050 void freeAperDecodePuschTimeDomAllocListCfg(PUSCH_Config_t *puschCfg)
9051 {
9052    uint8_t arrIdx=0;
9053    uint8_t arrIdx1=0;
9054    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
9055
9056    if(puschCfg->pusch_TimeDomainAllocationList)
9057    {
9058       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
9059       if(timeDomAllocList_t->choice.setup)
9060       {
9061          if(timeDomAllocList_t->choice.setup->list.array)
9062          {
9063             free(timeDomAllocList_t->choice.setup->list.array[arrIdx1]->k2);
9064             for(arrIdx = 0; arrIdx<timeDomAllocList_t->choice.setup->list.count; arrIdx++)
9065             {
9066                free(timeDomAllocList_t->choice.setup->list.array[arrIdx]);
9067             }
9068             free(timeDomAllocList_t->choice.setup->list.array);
9069          }
9070          free(timeDomAllocList_t->choice.setup);
9071       }
9072       free(puschCfg->transformPrecoder);
9073       free(puschCfg->pusch_TimeDomainAllocationList);
9074    }
9075 }
9076 /*******************************************************************
9077 *
9078 * @brief Function to free InitialUlBWPConfig where memory allocated by aper_decoder
9079 *
9080 * @details
9081 *
9082 *    Function : freeAperDecodeInitialUlBWPConfig 
9083 *
9084 *    Functionality: Function to free InitialUlBWPConfig
9085 *
9086 * @params[in]  BWP_UplinkDedicated_t *ulBwp
9087 * @return void
9088 *
9089 * ****************************************************************/
9090
9091
9092 void freeAperDecodeInitialUlBWPConfig(BWP_UplinkDedicated_t *ulBwp)
9093 {
9094    uint8_t  rSetIdx =0;
9095    uint8_t  rsrcIdx =0;
9096    SRS_Config_t   *srsCfg = NULLP;
9097    PUSCH_Config_t *puschCfg = NULLP;
9098    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
9099    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
9100    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
9101    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
9102
9103    if(ulBwp->pusch_Config)
9104    {
9105       if(ulBwp->pusch_Config->choice.setup)
9106       {
9107          puschCfg=ulBwp->pusch_Config->choice.setup;
9108          if(puschCfg->dataScramblingIdentityPUSCH)
9109          {
9110             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
9111             {
9112                freeAperDecodePuschTimeDomAllocListCfg(puschCfg);
9113                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
9114                if(dmrsUlCfg->choice.setup)
9115                {
9116                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
9117                   {
9118                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
9119                      {
9120                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0);
9121                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled);
9122                      }
9123                      free(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition);
9124                   }
9125                   free(dmrsUlCfg->choice.setup);
9126                }
9127                free(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA);
9128             }
9129             free(puschCfg->dataScramblingIdentityPUSCH);
9130          }
9131          free(ulBwp->pusch_Config->choice.setup);
9132       }
9133       free(ulBwp->pusch_Config);
9134
9135       /* Free SRS-Config */
9136       if(ulBwp->srs_Config)
9137       {
9138          if(ulBwp->srs_Config->choice.setup)
9139          {
9140             srsCfg = ulBwp->srs_Config->choice.setup;
9141
9142             /* Free Resource Set to add/mod list */
9143             if(srsCfg->srs_ResourceSetToAddModList)
9144             {
9145                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
9146                if(rsrcSetList->list.array)
9147                {
9148                   rSetIdx = 0;
9149
9150                   /* Free SRS resource Id list in this SRS resource set */
9151                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
9152                   {
9153                      rsrcIdList =
9154                         rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
9155
9156                      if(rsrcIdList->list.array)
9157                      {
9158                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count;
9159                               rsrcIdx++)
9160                         {
9161                            free(rsrcIdList->list.array[rsrcIdx]);
9162                         }
9163                         free(rsrcIdList->list.array);
9164                      }
9165                      free(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList);
9166                   }
9167
9168                   /* Free resource type info for this SRS resource set */
9169
9170                   free(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic);
9171
9172                   /* Free memory for each resource set */
9173                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
9174                   {
9175                      free(rsrcSetList->list.array[rSetIdx]);
9176                   }
9177                   free(rsrcSetList->list.array);
9178                }
9179                free(srsCfg->srs_ResourceSetToAddModList);
9180             }
9181
9182             /* Free resource to add/modd list */
9183             if(srsCfg->srs_ResourceToAddModList)
9184             {
9185                resourceList = srsCfg->srs_ResourceToAddModList;
9186                if(resourceList->list.array)
9187                {
9188                   rsrcIdx = 0;
9189
9190                   free(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2);
9191                   free(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic);
9192
9193                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
9194                   {
9195                      free(resourceList->list.array[rsrcIdx]);
9196                   }
9197                   free(resourceList->list.array);
9198                }
9199                free(srsCfg->srs_ResourceToAddModList);
9200             }
9201
9202             free(ulBwp->srs_Config->choice.setup);
9203          }
9204          free(ulBwp->srs_Config);
9205       }
9206    }
9207 }
9208 /*******************************************************************
9209 *
9210 * @brief Function to free initialUplinkBWPConfig where memory allocated by aper_decoder
9211 *
9212 * @details
9213 *
9214 *    Function : freeAperDecodeinitialUplinkBWPConfig
9215 *
9216 *    Functionality: Function to free initialUplinkBWPConfig
9217 *
9218 * @params[in] UplinkConfig_t *ulCfg 
9219 * @return void
9220 *
9221 * ****************************************************************/
9222
9223
9224 void freeAperDecodeinitialUplinkBWPConfig(UplinkConfig_t *ulCfg)
9225 {
9226    BWP_UplinkDedicated_t *ulBwp=NULLP;
9227    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
9228    
9229    if(ulCfg->initialUplinkBWP)
9230    {
9231       ulBwp=ulCfg->initialUplinkBWP;
9232       if(ulCfg->firstActiveUplinkBWP_Id)
9233       {
9234          if(ulCfg->pusch_ServingCellConfig)
9235          {
9236             puschCfg=ulCfg->pusch_ServingCellConfig;
9237             if(puschCfg->choice.setup)
9238             {
9239                if(puschCfg->choice.setup->ext1)
9240                {
9241                   free(puschCfg->choice.setup->ext1->processingType2Enabled);
9242                   free(puschCfg->choice.setup->ext1->maxMIMO_Layers);
9243                   free(puschCfg->choice.setup->ext1);
9244                }
9245                free(puschCfg->choice.setup);
9246             }
9247             free(ulCfg->pusch_ServingCellConfig);
9248          }
9249          free(ulCfg->firstActiveUplinkBWP_Id);
9250       }
9251       freeAperDecodeInitialUlBWPConfig(ulBwp);
9252       free(ulCfg->initialUplinkBWP);
9253    }
9254 }
9255
9256 /*******************************************************************
9257  *
9258  * @brief Function to free DuUeCfg
9259  *
9260  * @details
9261  *
9262  *    Function : freeDuUeCfg
9263  *
9264  *    Functionality: Function to free DuUeCfg
9265  *
9266  * @params[in] DuUeCfg *ueCfg
9267  * @return void
9268  *
9269  * ****************************************************************/
9270 void freeDuUeCfg(DuUeCfg *ueCfg)
9271 {
9272    uint8_t lcIdx = 0;
9273    uint8_t arrIdx = 0;
9274    SpCellConfig_t *spCellCfg = NULLP;
9275    ServingCellConfig_t *srvCellCfg = NULLP;
9276    BWP_DownlinkDedicated_t *dlBwp = NULLP;
9277    MAC_CellGroupConfig_t *macCellGrpCfg = NULLP;
9278    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
9279    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList = NULLP;
9280    struct RLC_Config *rlcConfig = NULLP;
9281    struct LogicalChannelConfig *macLcConfig = NULLP;
9282    struct SchedulingRequestConfig *schedulingRequestConfig = NULLP;
9283    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList = NULLP;
9284    struct TAG_Config *tagConfig = NULLP;
9285    struct TAG_Config__tag_ToAddModList *tagList = NULLP;
9286    struct MAC_CellGroupConfig__phr_Config *phrConfig = NULLP;
9287    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg = NULLP;
9288    CellGroupConfigRrc_t *cellGrpCfg = ueCfg->cellGrpCfg;
9289   
9290    if(ueCfg->ueNrCapability)
9291    {
9292       freeAperDecodeUeNrCapability(ueCfg->ueNrCapability);
9293       DU_FREE(ueCfg->ueNrCapability, sizeof(UE_NR_Capability_t));
9294       ueCfg->ueNrCapability = NULLP;
9295    }
9296
9297    if(ueCfg->cellGrpCfg)
9298    {
9299       
9300       rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
9301       if(rlcBearerList)
9302       {
9303          if(rlcBearerList->list.array)
9304          {
9305             for(arrIdx=0; arrIdx<rlcBearerList->list.count; arrIdx++)
9306             {
9307                if(rlcBearerList->list.array[arrIdx])
9308                {
9309                   rlcConfig   = rlcBearerList->list.array[arrIdx]->rlc_Config;
9310                   macLcConfig = rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig;
9311                   
9312                   if(rlcBearerList->list.array[arrIdx]->servedRadioBearer)
9313                   {
9314                      free(rlcBearerList->list.array[arrIdx]->servedRadioBearer);
9315                   }
9316                   if(rlcConfig)
9317                   {
9318                      if(rlcConfig->choice.am)
9319                      {
9320                         free(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength);
9321                         free(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength);
9322                         free(rlcConfig->choice.am);
9323                      }
9324                      free(rlcBearerList->list.array[arrIdx]->rlc_Config);
9325                   }
9326                   if(macLcConfig)
9327                   {
9328                      if(macLcConfig->ul_SpecificParameters)
9329                      {
9330                         free(macLcConfig->ul_SpecificParameters->schedulingRequestID);
9331                         free(macLcConfig->ul_SpecificParameters->logicalChannelGroup);
9332                         free(macLcConfig->ul_SpecificParameters);
9333                      }
9334                      free(rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig);
9335                   }
9336                   free(rlcBearerList->list.array[arrIdx]); 
9337                }
9338             }
9339             free(rlcBearerList->list.array);
9340          }
9341          free(cellGrpCfg->rlc_BearerToAddModList);
9342       }
9343
9344       macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
9345       if(macCellGrpCfg)
9346       {
9347          schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig;
9348          if(schedulingRequestConfig)
9349          {
9350             schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
9351             if(schReqList)
9352             {
9353                if(schReqList->list.array)
9354                {
9355                   for(arrIdx=0;arrIdx<schReqList->list.count; arrIdx++)
9356                   {
9357                      if(schReqList->list.array[arrIdx])
9358                      {
9359                         free(schReqList->list.array[arrIdx]->sr_ProhibitTimer); 
9360                         free(schReqList->list.array[arrIdx]);
9361                      }
9362                   }
9363                   free(schReqList->list.array);
9364                }
9365                free(schedulingRequestConfig->schedulingRequestToAddModList);
9366             }
9367             free(macCellGrpCfg->schedulingRequestConfig);
9368          }
9369          if(macCellGrpCfg->bsr_Config)
9370          {
9371             free(macCellGrpCfg->bsr_Config);
9372          }
9373          tagConfig = macCellGrpCfg->tag_Config;
9374          if(tagConfig)
9375          {
9376             tagList = tagConfig->tag_ToAddModList;
9377             if(tagList)
9378             {
9379                if(tagList->list.array)
9380                {
9381                   for(arrIdx=0; arrIdx<tagList->list.count; arrIdx++)
9382                   {
9383                      free(tagList->list.array[arrIdx]);
9384                   }
9385                   free(tagList->list.array);
9386                }
9387                free(tagConfig->tag_ToAddModList);
9388             }
9389             free(tagConfig); 
9390          }
9391
9392          phrConfig = macCellGrpCfg->phr_Config;
9393          if(phrConfig)
9394          {
9395             free(phrConfig->choice.setup); 
9396             free(phrConfig); 
9397          }
9398
9399          free(macCellGrpCfg); 
9400       }
9401
9402       phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
9403       if(phyCellGrpCfg)
9404       {
9405          free(phyCellGrpCfg->p_NR_FR1);
9406          free(phyCellGrpCfg); 
9407       }
9408
9409       spCellCfg = cellGrpCfg->spCellConfig;
9410       if(spCellCfg)
9411       {
9412          if(spCellCfg->servCellIndex)
9413          {
9414             if(spCellCfg->rlmInSyncOutOfSyncThreshold)
9415             {
9416                if(spCellCfg->spCellConfigDedicated)
9417                {
9418                   srvCellCfg = spCellCfg->spCellConfigDedicated;
9419                   if(srvCellCfg->initialDownlinkBWP)
9420                   {
9421                      dlBwp = srvCellCfg->initialDownlinkBWP;
9422                      if(srvCellCfg->firstActiveDownlinkBWP_Id)
9423                      {
9424                         if(srvCellCfg->defaultDownlinkBWP_Id)
9425                         {
9426                            if(srvCellCfg->uplinkConfig)
9427                            {
9428
9429                               if(srvCellCfg->pdsch_ServingCellConfig)
9430                               {
9431                                  pdschCfg=
9432                                     srvCellCfg->pdsch_ServingCellConfig;
9433                                  if(pdschCfg->choice.setup)
9434                                  {
9435
9436                                     free(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH);
9437                                     free(pdschCfg->choice.setup);
9438                                  }
9439
9440                                  free(srvCellCfg->pdsch_ServingCellConfig);
9441                               }
9442
9443                               freeAperDecodeinitialUplinkBWPConfig(srvCellCfg->uplinkConfig);
9444                               free(srvCellCfg->uplinkConfig);
9445                            }
9446                            free(srvCellCfg->defaultDownlinkBWP_Id);
9447                         }
9448
9449                         free(srvCellCfg->firstActiveDownlinkBWP_Id);
9450                      }
9451                      if(dlBwp->pdcch_Config)
9452                      {
9453                         if(dlBwp->pdsch_Config)
9454                         {
9455                            freeAperDecodeBWPDlDedPdschConfig(dlBwp);
9456                            free(dlBwp->pdsch_Config);
9457                         }
9458                         freeAperDecodeBWPDlDedPdcchConfig(dlBwp);
9459                         free(dlBwp->pdcch_Config);
9460                      }
9461                      free(srvCellCfg->initialDownlinkBWP);
9462                   }
9463
9464                   free(spCellCfg->spCellConfigDedicated);
9465                }
9466                free(spCellCfg->rlmInSyncOutOfSyncThreshold);
9467             }
9468             free(spCellCfg->servCellIndex); 
9469          }
9470          free(spCellCfg);
9471       }
9472       DU_FREE(ueCfg->cellGrpCfg, sizeof(CellGroupConfigRrc_t));
9473       ueCfg->cellGrpCfg = NULLP;
9474    }
9475    if(ueCfg->ambrCfg)
9476    {
9477       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCfg->ambrCfg, sizeof(AmbrCfg));
9478    }
9479    for(lcIdx = 0; lcIdx < ueCfg->numRlcLcs; lcIdx++)
9480    {
9481       freeRlcLcCfg(&ueCfg->rlcLcCfg[lcIdx]);
9482    }
9483    for(lcIdx = 0; lcIdx < ueCfg->numMacLcs; lcIdx++)
9484    {
9485       freeMacLcCfg(&ueCfg->macLcCfg[lcIdx]);
9486    }
9487    for(lcIdx = 0; lcIdx < ueCfg->numDrb; lcIdx++)
9488    {
9489       DU_FREE(ueCfg->upTnlInfo[lcIdx].tnlCfg1, sizeof(GtpTnlCfg));
9490    }
9491 }
9492
9493 /*******************************************************************
9494  *
9495  * @brief Function to free UecontextSetupDb
9496  *
9497  * @details
9498  *
9499  *    Function : freeF1UeDb
9500  *
9501  *    Functionality: Function to free UecontextSetupDb
9502  *
9503  * @params[in] UecontextSetupDb *
9504  * @return void
9505  *
9506  * ****************************************************************/
9507
9508 void freeF1UeDb(F1UeContextSetupDb *f1UeDb)
9509 {
9510    
9511    if(f1UeDb->dlRrcMsg)
9512    {
9513       if(f1UeDb->dlRrcMsg->rrcMsgPdu)
9514       {
9515         //DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,\
9516                f1UeDb->dlRrcMsg->rrcMsgPdu, f1UeDb->dlRrcMsg->rrcMsgSize);
9517       }
9518       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
9519    }
9520    freeDuUeCfg(&f1UeDb->duUeCfg);
9521    memset(f1UeDb, 0, sizeof(F1UeContextSetupDb));
9522    DU_FREE(f1UeDb, sizeof(F1UeContextSetupDb));
9523 }
9524
9525 /*******************************************************************
9526  *
9527  * @brief Function to build Am cfg Info
9528  *
9529  * @details
9530  *
9531  *    Function : extractRlcAmCfg
9532  *
9533  *    Functionality: Function to build Am cfg Info
9534  *
9535  * @params[in] AmBearerCfg *
9536  *             void *
9537  *
9538  * @return ROK/RFAILED
9539  *
9540  * ****************************************************************/
9541
9542 void extractRlcAmCfg(AmBearerCfg *amCfgToSet, struct RLC_Config__am *rlcAmCfg)
9543 {
9544    if(rlcAmCfg)
9545    {
9546       /* UL AM */
9547       if(rlcAmCfg->dl_AM_RLC.sn_FieldLength)
9548       {
9549          amCfgToSet->ulAmCfg.snLenUl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->dl_AM_RLC.sn_FieldLength));
9550          /*TODO: Check the timer value when sent by real CU */
9551          amCfgToSet->ulAmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_Reassembly); 
9552          amCfgToSet->ulAmCfg.statProhTmr = convertProhibitTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_StatusProhibit);
9553       }
9554
9555       /* DL AM */
9556       if(rlcAmCfg->ul_AM_RLC.sn_FieldLength)
9557       {
9558          amCfgToSet->dlAmCfg.snLenDl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->ul_AM_RLC.sn_FieldLength));
9559          amCfgToSet->dlAmCfg.pollRetxTmr = covertPollRetxTmrEnumToValue(rlcAmCfg->ul_AM_RLC.t_PollRetransmit);
9560          amCfgToSet->dlAmCfg.pollPdu   = covertPollPduEnumToValue(rlcAmCfg->ul_AM_RLC.pollPDU);
9561          amCfgToSet->dlAmCfg.pollByte  = covertPollByteEnumToValue(rlcAmCfg->ul_AM_RLC.pollByte);
9562          amCfgToSet->dlAmCfg.maxRetxTh = covertMaxRetxEnumToValue(rlcAmCfg->ul_AM_RLC.maxRetxThreshold);
9563       }
9564    }
9565 }
9566
9567 /*******************************************************************
9568  *
9569  * @brief Function to build Um Bi Info
9570  *
9571  * @details
9572  *
9573  *    Function : extractRlcUmBiCfg
9574  *
9575  *    Functionality: Function to build Um Bi Info
9576  *
9577  * @params[in] UmBiDirBearerCfg *
9578  *             void *
9579  *
9580  * @return ROK/RFAILED
9581  *
9582  * ****************************************************************/
9583
9584 void extractRlcUmBiCfg(UmBiDirBearerCfg *umBiCfgToSet, struct RLC_Config__um_Bi_Directional *rlcBiCfg)
9585 {
9586    if(rlcBiCfg)
9587    {
9588       /* UL UM BI DIR Cfg */
9589       if(rlcBiCfg->dl_UM_RLC.sn_FieldLength)
9590       {
9591          umBiCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->dl_UM_RLC.sn_FieldLength));
9592          umBiCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcBiCfg->dl_UM_RLC.t_Reassembly);
9593       }
9594
9595       /* DL UM BI DIR Cfg */
9596       if(rlcBiCfg->ul_UM_RLC.sn_FieldLength)
9597          umBiCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->ul_UM_RLC.sn_FieldLength));
9598    }
9599 }
9600
9601 /*******************************************************************
9602  *
9603  * @brief Function to build Um Ul Info
9604  *
9605  * @details
9606  *
9607  *    Function : extractRlcUmUlCfg
9608  *
9609  *    Functionality: Function to build Um Ul Info
9610  *
9611  * @params[in] UmUniDirUlBearerCfg *
9612  *             void *
9613  *
9614  * @return ROK/RFAILED
9615  *
9616  * ****************************************************************/
9617
9618 void extractRlcUmUlCfg(UmUniDirUlBearerCfg *umUlCfgToSet, struct RLC_Config__um_Uni_Directional_DL *umUlCfg)
9619 {
9620    if(umUlCfg)
9621    {
9622       if(umUlCfg->dl_UM_RLC.sn_FieldLength)
9623       {
9624          umUlCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umUlCfg->dl_UM_RLC.sn_FieldLength));
9625          umUlCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(umUlCfg->dl_UM_RLC.t_Reassembly);
9626       }
9627    }
9628 }
9629
9630 /*******************************************************************
9631  *
9632  * @brief Function to build Um Uni Dl Info
9633  *
9634  * @details
9635  *
9636  *    Function : extractRlcUmDlCfg
9637  *
9638  *    Functionality: Function to build Um Uni Dl Info
9639  *
9640  * @params[in] UmUniDirDlBearerCfg *
9641  *             void *
9642  *
9643  * @return ROK/RFAILED
9644  *
9645  * ****************************************************************/
9646 void extractRlcUmDlCfg(UmUniDirDlBearerCfg *umDlCfgToSet, struct RLC_Config__um_Uni_Directional_UL *umDlCfg)
9647 {
9648    if(umDlCfg)
9649    {
9650       if(umDlCfg->ul_UM_RLC.sn_FieldLength)
9651          umDlCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umDlCfg->ul_UM_RLC.sn_FieldLength));
9652    }
9653 }
9654
9655 /*******************************************************************
9656  *
9657  * @brief Function to extractRlcModeCfg
9658  *
9659  * @details
9660  *
9661  *    Function : extractRlcModeCfg
9662  *
9663  *    Functionality: Function to extractRlcModeCfg
9664  *
9665  * @params[in] RLC_Config_t *
9666  *             RlcBearerCfg *
9667  *             void  *    
9668  * @return ROK/RFAILED
9669  *
9670  * ****************************************************************/
9671 void extractRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *rlcDbCfg, RLC_Config_t *lcCfg)
9672 {
9673    if(lcCfg)
9674    {
9675       switch(rlcMode)
9676       {
9677          case RLC_AM :
9678             {
9679                if(lcCfg->choice.am)
9680                {
9681                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.amCfg, sizeof(AmBearerCfg));
9682                   if(rlcDbCfg->u.amCfg)
9683                      extractRlcAmCfg(rlcDbCfg->u.amCfg, lcCfg->choice.am);
9684                }
9685                break;
9686             }
9687          case RLC_UM_BI_DIRECTIONAL :
9688             {
9689                if(lcCfg->choice.um_Bi_Directional)
9690                {
9691                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
9692                   if(rlcDbCfg->u.umBiDirCfg)
9693                      extractRlcUmBiCfg(rlcDbCfg->u.umBiDirCfg, lcCfg->choice.um_Bi_Directional);
9694                }
9695                break;
9696             }
9697          case RLC_UM_UNI_DIRECTIONAL_UL :
9698             {
9699                if(lcCfg->choice.um_Uni_Directional_DL)
9700                {
9701                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
9702                   if(rlcDbCfg->u.umUniDirUlCfg)
9703                      extractRlcUmUlCfg(rlcDbCfg->u.umUniDirUlCfg, lcCfg->choice.um_Uni_Directional_DL);
9704                }
9705                break;
9706             }
9707          case RLC_UM_UNI_DIRECTIONAL_DL :
9708             {
9709                if(lcCfg->choice.um_Uni_Directional_UL)
9710                {
9711                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
9712                   if(rlcDbCfg->u.umUniDirDlCfg)
9713                      extractRlcUmDlCfg(rlcDbCfg->u.umUniDirDlCfg, lcCfg->choice.um_Uni_Directional_UL);
9714                }
9715                break;
9716             }
9717          default:
9718             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
9719             break;
9720       }
9721    }
9722 }
9723
9724 /*******************************************************************
9725  *
9726  * @brief Function to extract extractUlLcCfg
9727  *
9728  * @details
9729  *
9730  *    Function : extractUlLcCfg
9731  *
9732  *    Functionality: Function to extract extractUlLcCfg
9733  *
9734  * @params[in] UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg
9735  * @return void
9736  *
9737  * ****************************************************************/
9738
9739 void extractUlLcCfg(UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg)
9740 {
9741    if(ulLcCfg)
9742    {
9743       if(ulLcCfg->ul_SpecificParameters)
9744       {
9745          f1UlLcCfg->priority = \
9746             ulLcCfg->ul_SpecificParameters->priority;
9747       if(ulLcCfg->ul_SpecificParameters->logicalChannelGroup)
9748       {
9749          f1UlLcCfg->lcGroup = \
9750            *(ulLcCfg->ul_SpecificParameters->logicalChannelGroup);
9751       }
9752       if(ulLcCfg->ul_SpecificParameters->schedulingRequestID)
9753       {
9754          f1UlLcCfg->schReqId = \
9755            *(ulLcCfg->ul_SpecificParameters->schedulingRequestID);
9756       }
9757       f1UlLcCfg->pbr = \
9758          ulLcCfg->ul_SpecificParameters->prioritisedBitRate;
9759       f1UlLcCfg->bsd = \
9760          ulLcCfg->ul_SpecificParameters->bucketSizeDuration;
9761       }
9762    }
9763 }
9764
9765 /*******************************************************************
9766 *
9767 * @brief Function to extract Snssai Cfg Info from CU
9768 *
9769 * @details
9770 *
9771 *    Function : extractDrbSnssaiCfg
9772 *
9773 *    Functionality: Function to extract Drb Snssai Cfg Info from CU
9774 *
9775 * @params[in] DRB_Information_t *drbInfo, Snssai  *snssai
9776 * @return ROK/RFAILED
9777 *
9778 * ****************************************************************/
9779
9780 uint8_t extractDrbSnssaiCfg(SNSSAI_t *RecvSnssai, Snssai **snssaiToBeShared)
9781 {
9782    if(!(*snssaiToBeShared))
9783    {
9784       DU_ALLOC_SHRABL_BUF((*snssaiToBeShared), sizeof(Snssai));
9785       if(snssaiToBeShared == NULLP)
9786       {
9787          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Memory failed at allocating for SNSSAI ");
9788          return RFAILED;
9789       }
9790    }
9791    if(RecvSnssai)
9792    {
9793       memcpy(&(*snssaiToBeShared)->sst, RecvSnssai->sST.buf, RecvSnssai->sST.size);
9794       if(RecvSnssai->sD)
9795       {
9796          memcpy((*snssaiToBeShared)->sd, RecvSnssai->sD->buf,  RecvSnssai->sD->size);
9797       }
9798       else
9799       {
9800          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Received Null pointer of Snssai->SD");
9801          return RFAILED;
9802       }
9803    }
9804    return ROK;
9805 }
9806
9807 /*******************************************************************
9808  *
9809  * @brief Function to procRlcLcCfg
9810  *
9811  * @details
9812  *
9813  *    Function : procRlcLcCfg
9814  *
9815  *    Functionality: Function to procRlcLcCfg
9816  *
9817  * @params[in] rbId, lcId, rbType, rlcMod
9818  *             RLC_Config_t *, RlcBearerCfg * , 
9819  * @return void
9820  *
9821  * ****************************************************************/
9822
9823 void procRlcLcCfg(uint8_t rbId, uint8_t lcId, uint8_t rbType, uint8_t rlcMode,\
9824    uint8_t configType, RLC_Config_t *f1RlcCfg, RlcBearerCfg *lcCfg, QoSInformation_t *qoSInformation)
9825 {
9826    DRB_Information_t *drbInfo;
9827
9828    lcCfg->rbId   = rbId;
9829    lcCfg->configType = configType;
9830
9831    if(rbType == RB_TYPE_SRB)
9832    {
9833       lcCfg->rbType = RB_TYPE_SRB;
9834       lcCfg->lcId   = rbId;
9835       lcCfg->lcType = LCH_DCCH;
9836       lcCfg->rlcMode = RLC_AM;
9837    }
9838    else if(rbType == RB_TYPE_DRB)
9839    {
9840       lcCfg->rbType = RB_TYPE_DRB;
9841       lcCfg->lcId   = lcId;
9842       lcCfg->lcType = LCH_DTCH;
9843       lcCfg->rlcMode = rlcMode;
9844    }
9845    if(f1RlcCfg) /* rlc mode config recived */
9846    {
9847       extractRlcModeCfg(lcCfg->rlcMode, lcCfg, f1RlcCfg);
9848    }
9849    if(qoSInformation != NULLP)
9850    {
9851       if(qoSInformation->present == QoSInformation_PR_choice_extension)
9852       {
9853          if(qoSInformation->choice.choice_extension->value.present ==\
9854                QoSInformation_ExtIEs__value_PR_DRB_Information)
9855          {
9856             drbInfo = &qoSInformation->choice.choice_extension->value.choice.DRB_Information; 
9857             if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &lcCfg->snssai) != ROK)
9858             {
9859                DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information at procRlcLcCfg()");
9860                return;
9861             }
9862          }
9863       }
9864    }
9865 }
9866
9867 /*******************************************************************
9868  *
9869  * @brief Fills DrbQos Info received by CU
9870  *
9871  * @details
9872  *
9873  *    Function : extractQosInfo
9874  *
9875  *    Functionality: Fills DrbQos Info received  by CU
9876  *
9877  * @params[in] DrbQosInfo *qosToAdd, 
9878  *             QoSFlowLevelQoSParameters_t *qosFlowCfg
9879  * @return void
9880  *
9881  * ****************************************************************/
9882
9883 void extractQosInfo(DrbQosInfo *qosToAdd, QoSFlowLevelQoSParameters_t *qosFlowCfg)
9884 {
9885    uint8_t qosCntIdx = 0;
9886    ProtocolExtensionContainer_4624P74_t *qosIeExt = NULLP;
9887
9888    qosToAdd->fiveQiType = qosFlowCfg->qoS_Characteristics.present;
9889    qosToAdd->u.nonDyn5Qi.fiveQi     =\
9890                                      qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->fiveQI;
9891    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow)
9892    {
9893       qosToAdd->u.nonDyn5Qi.avgWindow = \
9894                                         *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
9895    }
9896
9897    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume)
9898    {
9899       qosToAdd->u.nonDyn5Qi.maxDataBurstVol = \
9900                                               *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
9901    }
9902
9903    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel)
9904    {
9905       qosToAdd->u.nonDyn5Qi.priorLevel = \
9906                                          *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel);
9907    }
9908    qosToAdd->ngRanRetPri.priorityLevel = \
9909                                          qosFlowCfg->nGRANallocationRetentionPriority.priorityLevel; 
9910    qosToAdd->ngRanRetPri.preEmptionCap = \
9911                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionCapability;
9912    qosToAdd->ngRanRetPri.preEmptionVul = \
9913                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionVulnerability;
9914    if(qosFlowCfg->gBR_QoS_Flow_Information)
9915    {
9916       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateDl, \
9917             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.buf, \
9918             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.size);
9919       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateUl, \
9920             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.buf, \
9921             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.size);
9922       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateDl,\
9923             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.buf, \
9924             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.size);
9925       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateUl,\
9926             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.buf, \
9927             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.size);
9928    }
9929    /*Extracting PDU_SESSION_ID*/
9930    qosIeExt = (ProtocolExtensionContainer_4624P74_t *)qosFlowCfg->iE_Extensions;
9931    if(qosIeExt)
9932    {
9933       for(qosCntIdx = 0; qosCntIdx < qosIeExt->list.count; qosCntIdx++)
9934       {
9935          if(qosIeExt->list.array[qosCntIdx]->extensionValue.present == \
9936                QoSFlowLevelQoSParameters_ExtIEs__extensionValue_PR_PDUSessionID)
9937          {
9938             qosToAdd->pduSessionId = qosIeExt->list.array[qosCntIdx]->extensionValue.choice.PDUSessionID;
9939             DU_LOG("\nDEBUG -->  DU_F1AP : extractQosInfo: PDU SessionID:%d",qosToAdd->pduSessionId);
9940          }
9941       }  
9942    }
9943    qosToAdd->ulPduSessAggMaxBitRate = 0;
9944 }
9945
9946 /*******************************************************************
9947  *
9948  * @brief Function to extract GTP Tunnel Info from CU
9949  *
9950  * @details
9951  *
9952  *    Function : extractUpTnlInfo
9953  *
9954  *    Functionality: Function to extract GTP Tunnel Info from CU
9955  *
9956  * @params[in] F1AP message
9957  * @return ROK/RFAILED
9958  *
9959  * ****************************************************************/
9960
9961 uint8_t extractUpTnlInfo(uint8_t drbId, uint8_t configType,\
9962    ULUPTNLInformation_ToBeSetup_List_t *tnlInfo, UpTnlCfg *upTnlInfo)
9963 {
9964    uint8_t tnlIdx;
9965    uint32_t ipv4_du = 0;
9966    GTPTunnel_t *gtpTunnel = NULLP;
9967
9968    upTnlInfo->drbId = drbId; 
9969    upTnlInfo->configType = configType;
9970 #ifdef O1_ENABLE
9971    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
9972 #else
9973    cmInetAddr((char *)DU_IP_V4_ADDR, &ipv4_du);
9974 #endif
9975
9976    for(tnlIdx=0; tnlIdx < tnlInfo->list.count; tnlIdx++)
9977    {
9978       if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.present == UPTransportLayerInformation_PR_gTPTunnel)
9979       {
9980          if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel)
9981          {
9982             gtpTunnel = tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel;
9983             DU_ALLOC(upTnlInfo->tnlCfg1, sizeof(GtpTnlCfg));
9984             if(upTnlInfo->tnlCfg1 == NULLP)
9985             {
9986                DU_LOG("\nERROR  -->  F1AP : extractUpTnlInfo: Failed to allocate mmeory for tunnel cfg 1");
9987                return RFAILED;
9988             }
9989             bitStringToInt(&gtpTunnel->transportLayerAddress, &upTnlInfo->tnlCfg1->ulTnlAddress);
9990             upTnlInfo->tnlCfg1->dlTnlAddress = ipv4_du;
9991             if(gtpTunnel->gTP_TEID.size > 0)
9992             {
9993                teIdStringToInt(gtpTunnel->gTP_TEID.buf, &upTnlInfo->tnlCfg1->teId);
9994             }
9995          }
9996          break;
9997       }
9998    }
9999    return ROK;
10000 }
10001
10002 /*******************************************************************
10003 *
10004 * @brief Function to extract Drb Qos Cfg Info from CU
10005 *
10006 * @details
10007 *
10008 *    Function : extractDrbQosCfg 
10009 *
10010 *    Functionality: Function to extract Drb Qos Cfg Info from CU
10011 *
10012 * @params[in] DRB_Information_t *drbInfo, LcCfg *macLcToAdd
10013 * @return ROK/RFAILED
10014 *
10015 * ****************************************************************/
10016
10017 uint8_t extractDrbQosCfg(DRB_Information_t *drbInfo, LcCfg *macLcToAdd ) 
10018 {
10019    if(!macLcToAdd->drbQos)
10020    {
10021       DU_ALLOC_SHRABL_BUF(macLcToAdd->drbQos, sizeof(DrbQosInfo));
10022       if(macLcToAdd->drbQos == NULLP)
10023       {
10024          DU_LOG("\nERROR  -->  DUAPP:Memory failed at allocating DrbQos at extractDrbQosCfg()");
10025          return RFAILED;
10026       }
10027
10028    }
10029    if(drbInfo->dRB_QoS.qoS_Characteristics.present == QoS_Characteristics_PR_non_Dynamic_5QI)
10030    {
10031       extractQosInfo(macLcToAdd->drbQos, &drbInfo->dRB_QoS);
10032       macLcToAdd->dlLcCfg.lcp = macLcToAdd->drbQos->ngRanRetPri.priorityLevel;
10033    }
10034    if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &macLcToAdd->snssai) != ROK)
10035    {
10036       DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information  at extractDrbQosCfg()");
10037       return RFAILED;
10038    }
10039    return ROK;
10040 }
10041 /*******************************************************************
10042  *
10043  * @brief Function to extract DRB info received from CU
10044  *
10045  * @details
10046  *
10047  *    Function : extractDrbCfg
10048  *
10049  *    Functionality: Function to extract DRB info received from CU
10050  *
10051  * @params[in] F1AP message
10052  * @return void
10053  *
10054  * ****************************************************************/
10055 uint8_t extractDrbCfg(DRBs_ToBeSetup_Item_t *drbItem, DRBs_ToBeSetupMod_Item_t *drbSetupModItem,\
10056 DRBs_ToBeModified_Item_t *drbModItem,  LcCfg *macLcToAdd, UpTnlCfg *upTnlInfo)
10057 {
10058    DRB_Information_t *drbInfo = NULLP;
10059
10060    if(drbItem != NULLP)
10061    {
10062       if(extractUpTnlInfo(drbItem->dRBID, CONFIG_ADD, &drbItem->uLUPTNLInformation_ToBeSetup_List, upTnlInfo) != ROK)
10063       {
10064          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10065          return RFAILED;
10066       }
10067       if(drbItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10068       {
10069          if(drbItem->qoSInformation.choice.choice_extension->value.present == QoSInformation_ExtIEs__value_PR_DRB_Information)
10070          {
10071             drbInfo = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10072             if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
10073             {
10074                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");
10075                return RFAILED;
10076             }
10077          }
10078       }
10079    }
10080    else if(drbSetupModItem != NULLP)
10081    {
10082       if(extractUpTnlInfo(drbSetupModItem->dRBID, CONFIG_ADD, &drbSetupModItem->uLUPTNLInformation_ToBeSetup_List,\
10083       upTnlInfo) != ROK)
10084       {
10085          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10086          return RFAILED;
10087       }
10088       if(drbSetupModItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10089       {
10090          if(drbSetupModItem->qoSInformation.choice.choice_extension->value.present ==\
10091          QoSInformation_ExtIEs__value_PR_DRB_Information)
10092          {
10093             drbInfo = &drbSetupModItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10094             if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
10095             {
10096                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10097                return RFAILED;
10098             }
10099
10100          }
10101       }
10102    }
10103    else if(drbModItem != NULLP)
10104    {
10105       if(extractUpTnlInfo(drbModItem->dRBID, CONFIG_MOD, &drbModItem->uLUPTNLInformation_ToBeSetup_List,\
10106       upTnlInfo) != ROK)
10107       {
10108          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10109          return RFAILED;
10110       }
10111       if(drbModItem->qoSInformation != NULLP)
10112       {
10113          if(drbModItem->qoSInformation->present == QoSInformation_PR_choice_extension)
10114          {
10115             if(drbModItem->qoSInformation->choice.choice_extension->value.present ==\
10116                   QoSInformation_ExtIEs__value_PR_DRB_Information)
10117             {
10118                drbInfo = &drbModItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information;
10119                if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
10120                {
10121                   DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10122                   return RFAILED;
10123                }
10124
10125             }
10126          }
10127       }
10128    }
10129    return ROK;
10130 }
10131
10132 /*******************************************************************
10133  *
10134  * @brief Function to extract RB info received from CU
10135  *
10136  * @details
10137  *
10138  *    Function : extractMacRbCfg
10139  *
10140  *    Functionality: Function to extract RB info received from CU
10141  *
10142  * @params[in] F1AP message
10143  * @return ROK/RFAILED
10144  *
10145  * ****************************************************************/
10146
10147 uint8_t extractMacRbCfg(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbCfg,\
10148 DRBs_ToBeSetupMod_Item_t *drbSetupModCfg,  DRBs_ToBeModified_Item_t *drbModCfg, LogicalChannelConfig_t *ulLcCfg, LcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10149 {
10150    if(drbCfg != NULLP)
10151    {
10152       if(extractDrbCfg(drbCfg, NULL, NULL, lcCfg, upTnlInfo) != ROK)
10153       {
10154          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10155          return RFAILED;
10156       }
10157    }
10158    else if(drbSetupModCfg != NULLP)
10159    { 
10160       if(extractDrbCfg(NULL, drbSetupModCfg, NULL, lcCfg, upTnlInfo) != ROK)
10161       {
10162          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10163          return RFAILED;
10164       }
10165    }
10166    else if(drbModCfg != NULLP)
10167    { 
10168       if(extractDrbCfg(NULL, NULL, drbModCfg, lcCfg, upTnlInfo) != ROK)
10169       {
10170          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10171          return RFAILED;
10172       }
10173    }
10174    else
10175    {
10176       lcCfg->drbQos = NULLP;
10177       lcCfg->snssai = NULLP;
10178       if(lcCfg->lcId == SRB2_LCID)
10179          lcCfg->dlLcCfg.lcp = LC_PRIORITY_3;
10180       else
10181          lcCfg->dlLcCfg.lcp = LC_PRIORITY_1;
10182    }
10183    if(ulLcCfg)
10184    {
10185       lcCfg->ulLcCfgPres = true;
10186       extractUlLcCfg(&lcCfg->ulLcCfg, ulLcCfg);
10187    }
10188    else
10189       lcCfg->ulLcCfgPres = false;
10190    return ROK;
10191 }
10192
10193 /*******************************************************************
10194  *
10195  * @brief Function processing LC config info received from CU
10196  *
10197  * @details
10198  *
10199  *    Function : procMacLcCfg
10200  *
10201  *    Functionality: Function processing LC config info received from CU
10202  *
10203  * @params[in] F1AP message
10204  * @return ROK/RFAILED
10205  *
10206  * ****************************************************************/
10207
10208 uint8_t procMacLcCfg(uint8_t lcId, uint8_t rbType, uint8_t configType, DRBs_ToBeSetup_Item_t *drbItem,\
10209 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LogicalChannelConfig_t *ulLcCfg,\
10210 LcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10211 {
10212    uint8_t ret = ROK;
10213
10214    lcCfg->lcId = lcId;
10215    lcCfg->configType = configType;
10216    if(rbType == RB_TYPE_SRB)
10217    {
10218       ret = extractMacRbCfg(lcId, NULL, NULL, NULL, ulLcCfg, lcCfg, NULL);
10219    }
10220    else if(rbType == RB_TYPE_DRB)
10221    {
10222       if(drbItem != NULL)
10223         ret = extractMacRbCfg(lcId, drbItem, NULL, NULL, ulLcCfg, lcCfg, upTnlInfo);
10224       else if(drbSetupModItem != NULL)
10225         ret = extractMacRbCfg(lcId, NULL, drbSetupModItem, NULL, ulLcCfg, lcCfg, upTnlInfo);
10226       else if(drbModItem != NULL)
10227         ret = extractMacRbCfg(lcId, NULL, NULL, drbModItem, ulLcCfg, lcCfg, upTnlInfo);
10228    }
10229    return ret;
10230 }
10231
10232 /*******************************************************************
10233  *
10234  * @brief Function to extract Rlc cfg To Add/Mod in CellGrp Info
10235  *
10236  * @details
10237  *
10238  *    Function : extractRlcCfgToAddMod
10239  *
10240  *    Functionality: Function to extract Rlc cfg To Add/Mod in CellGrp Info
10241  *
10242  * @params[in] CellGroupConfigRrc__rlc_BearerTo pointer
10243  *             DuUeCfg Pointer
10244  * @return ROK/RFAILED
10245  *
10246  * ****************************************************************/
10247
10248 uint8_t extractRlcCfgToAddMod(struct CellGroupConfigRrc__rlc_BearerToAddModList *lcCfg, DuUeCfg *ueCfgDb)
10249 {
10250   uint8_t idx, rbId, lcId, rlcMode, rbType;
10251   RLC_Config_t *f1RlcCfg = NULLP;
10252   LogicalChannelConfig_t *macUlLcCfg = NULLP;
10253
10254   for(idx = 0; idx < lcCfg->list.count; idx++)
10255   {
10256      lcId = lcCfg->list.array[idx]->logicalChannelIdentity;
10257      if(lcCfg->list.array[idx]->servedRadioBearer)
10258      {
10259         /* RadioBearer for SRB/DRB */
10260         if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10261         RLC_BearerConfig__servedRadioBearer_PR_srb_Identity)
10262         {
10263            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.srb_Identity;
10264            rbType = RB_TYPE_SRB;
10265         }
10266         else if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10267         RLC_BearerConfig__servedRadioBearer_PR_drb_Identity)
10268         {
10269            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.drb_Identity;
10270            rbType = RB_TYPE_DRB;
10271         }
10272         else
10273         {
10274            DU_LOG("\nERROR  -->  No components present in Bearer config to ADD/MOD");
10275            return RFAILED;
10276         }
10277         /* MAC UL LC Config */
10278         if(lcCfg->list.array[idx]->mac_LogicalChannelConfig)
10279         {
10280            macUlLcCfg = lcCfg->list.array[idx]->mac_LogicalChannelConfig;
10281         }
10282      }
10283      else
10284      {
10285         DU_LOG("\nERROR  -->  DUAPP: Received RadioBearer config is NULL");
10286         return RFAILED;
10287      }
10288      /* RLC Mode Config */
10289      if(lcCfg->list.array[idx]->rlc_Config)
10290      {
10291         rlcMode  = lcCfg->list.array[idx]->rlc_Config->present;
10292         f1RlcCfg = lcCfg->list.array[idx]->rlc_Config;
10293      }
10294      
10295      /* Filling RLC/MAC Config*/
10296      memset(&ueCfgDb->macLcCfg[idx], 0, sizeof(LcCfg));
10297      memset(&ueCfgDb->rlcLcCfg[idx], 0, sizeof(RlcBearerCfg));
10298      procRlcLcCfg(rbId, lcId, rbType, rlcMode, CONFIG_UNKNOWN, f1RlcCfg, &(ueCfgDb->rlcLcCfg[idx]), NULLP);
10299      if(procMacLcCfg(lcId, rbType, CONFIG_UNKNOWN, NULL, NULL, NULL, macUlLcCfg, &ueCfgDb->macLcCfg[idx], NULL) != ROK)
10300      {
10301         DU_LOG("\nERROR  -->  DU APP : Failed while filling MAC LC config at extractRlcCfgToAddMod()");
10302         return RFAILED;
10303      }
10304      (ueCfgDb->numRlcLcs)++;
10305      (ueCfgDb->numMacLcs)++;
10306      DU_LOG("\nDEBUG  -> DUAPP: extractRlcCfgToAddMod:RBType:%d, DrbID: %d,lcId:%d, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
10307         rbType, rbId, lcId, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
10308   }
10309   //TODO: To send the failure cause in UeContextSetupRsp 
10310   return ROK;
10311 }
10312
10313 /*******************************************************************
10314  *
10315  * @brief DeAlloc pdsch serv cell config info
10316  *
10317  * @details
10318  *
10319  *    Function : freeMacPdschServCellInfo
10320  *
10321  *    Functionality: DeAlloc pdsch serv cell config info
10322  *
10323  * @params[in] PdschServCellCfg pointer
10324  * @return void
10325  *
10326  * ****************************************************************/
10327
10328 void freeMacPdschServCellInfo(PdschServCellCfg *pdsch)
10329 {
10330    if(pdsch->xOverhead)
10331    {
10332       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->xOverhead, sizeof(PdschXOverhead));
10333    }
10334    if(pdsch->codeBlkGrpFlushInd)
10335    {
10336       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->codeBlkGrpFlushInd, sizeof(bool));
10337    }
10338    if(pdsch->maxCodeBlkGrpPerTb)
10339    {
10340       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10341    }
10342    if(pdsch->maxMimoLayers)
10343    {
10344       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxMimoLayers, sizeof(uint8_t));
10345    }
10346 }
10347
10348 /*******************************************************************
10349  *
10350  * @brief Free Serving cell Info
10351  *
10352  * @details
10353  *
10354  *    Function : freeMacServingCellInfo
10355  *
10356  *    Functionality: Free Serving cell Info
10357  *
10358  * @params[in] ServCellCfgInfo *srvCellCfg
10359  * @return void
10360  *
10361  * ****************************************************************/
10362 void freeMacServingCellInfo(ServCellCfgInfo *srvCellCfg)
10363 {
10364    uint8_t timeDomRsrcIdx;
10365
10366    if(srvCellCfg->initDlBwp.pdschPresent)
10367    {
10368       for(timeDomRsrcIdx = 0; timeDomRsrcIdx < srvCellCfg->initDlBwp.pdschCfg.numTimeDomRsrcAlloc; timeDomRsrcIdx++)
10369       {
10370          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, \
10371             srvCellCfg->initDlBwp.pdschCfg.timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
10372       }
10373    }
10374
10375    freeMacPdschServCellInfo(&srvCellCfg->pdschServCellCfg);
10376    if(srvCellCfg->bwpInactivityTmr)
10377    {
10378       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
10379    }
10380
10381    if(srvCellCfg->initUlBwp.pucchPresent)
10382    {
10383       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->initUlBwp.pucchCfg.dlDataToUlAck, sizeof(PucchDlDataToUlAck));
10384    }
10385 }
10386
10387 /*******************************************************************
10388  *
10389  * @brief Free cell Grp Cfg Info
10390  *
10391  * @details
10392  *
10393  *    Function : freeUeReCfgCellGrpInfo
10394  *
10395  *    Functionality: Free cell Grp Cfg Info
10396  *
10397  * @params[in] MacUeCfg*  duUeCfg
10398  * @return void
10399  *
10400  * ****************************************************************/
10401
10402 void freeUeReCfgCellGrpInfo(MacUeCfg *macUeCfg)
10403 {
10404    freeMacServingCellInfo(&macUeCfg->spCellCfg.servCellCfg);
10405 }
10406
10407 /*******************************************************************
10408  *
10409  * @brief Fills Reconfig SchReqReConfig
10410  *
10411  * @details
10412  *
10413  *    Function : extractSchReqReConfig
10414  *
10415  *    Functionality: Fills Reconfig SchReqReConfig
10416  *
10417  * @params[in] SchedulingRequestConfig_t *cuSchedReq
10418  *             SchedReqCfg*  macSchedReq
10419  * @return void
10420  *
10421  * ****************************************************************/
10422 void extractSchReqReConfig(SchedulingRequestConfig_t *cuSchedReq, SchedReqCfg *macSchedReq)
10423 {
10424    uint8_t schReqIdx = 0;
10425    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqListToAdd = NULLP;
10426    struct SchedulingRequestConfig__schedulingRequestToReleaseList *schReqListToRel = NULLP;
10427
10428    if(cuSchedReq->schedulingRequestToAddModList)
10429    {
10430       schReqListToAdd = cuSchedReq->schedulingRequestToAddModList;
10431       if(schReqListToAdd->list.count)
10432       {
10433          macSchedReq->addModListCount = schReqListToAdd->list.count;
10434          for(schReqIdx = 0; schReqIdx < schReqListToAdd->list.count; schReqIdx++)
10435          {
10436             macSchedReq->addModList[schReqIdx].schedReqId = \
10437                schReqListToAdd->list.array[schReqIdx]->schedulingRequestId;
10438             macSchedReq->addModList[schReqIdx].srProhibitTmr = \
10439                *(schReqListToAdd->list.array[schReqIdx]->sr_ProhibitTimer);
10440             macSchedReq->addModList[schReqIdx].srTransMax    =\
10441                schReqListToAdd->list.array[schReqIdx]->sr_TransMax;
10442          }
10443       }
10444    }
10445    /* Scheduling Req To release */
10446    if(cuSchedReq->schedulingRequestToReleaseList)
10447    {
10448       schReqListToRel = cuSchedReq->schedulingRequestToReleaseList;
10449       if(schReqListToRel->list.count)
10450       {
10451          macSchedReq->relListCount = schReqListToRel->list.count;
10452          for(schReqIdx = 0; schReqIdx < schReqListToRel->list.count; schReqIdx++)
10453          {
10454             macSchedReq->relList[schReqIdx] = \
10455                *schReqListToRel->list.array[schReqIdx];
10456          }
10457       }
10458    }
10459 }
10460
10461 /*******************************************************************
10462  *
10463  * @brief Fills TagReconfig
10464  *
10465  * @details
10466  *
10467  *    Function : extractTagReconfig
10468  *
10469  *    Functionality: Fills extractTagReconfig
10470  *
10471  * @params[in] TAG_Config_t *cuTagCfg
10472  *             TagCfg *macTagCfg
10473  * @return void
10474  *
10475  * ****************************************************************/
10476
10477 void extractTagReconfig(TAG_Config_t *cuTagCfg, TagCfg *macTagCfg)
10478 {
10479   uint8_t tagIdx = 0;
10480   struct TAG_Config__tag_ToAddModList  *tagListToAddMod = NULLP;
10481   struct TAG_Config__tag_ToReleaseList *tagListToRel = NULLP;
10482
10483   /* Tag config to AddMod */
10484   if(cuTagCfg->tag_ToAddModList)
10485   {
10486      tagListToAddMod = cuTagCfg->tag_ToAddModList; 
10487      if(tagListToAddMod->list.count)
10488      {
10489         macTagCfg->addModListCount = tagListToAddMod->list.count;
10490         for(tagIdx = 0; tagIdx < tagListToAddMod->list.count; tagIdx++)
10491         {
10492            macTagCfg->addModList[tagIdx].tagId =\
10493               tagListToAddMod->list.array[tagIdx]->tag_Id;     
10494            macTagCfg->addModList[tagIdx].timeAlignTimer = \
10495
10496               tagListToAddMod->list.array[tagIdx]->timeAlignmentTimer;
10497         }
10498      }
10499   }
10500   /* Tag config to release */
10501   if(cuTagCfg->tag_ToReleaseList)
10502   {
10503      tagListToRel = cuTagCfg->tag_ToReleaseList;
10504      if(tagListToRel->list.count)
10505      {
10506         macTagCfg->relListCount = tagListToRel->list.count;
10507         for(tagIdx = 0; tagIdx < tagListToRel->list.count; tagIdx++)
10508         {
10509            macTagCfg->relList[tagIdx] = *tagListToRel->list.array[tagIdx];     
10510         }
10511      }
10512   }
10513 }
10514
10515 /*******************************************************************
10516  *
10517  * @brief Fills PdcchCfg received by CU
10518  *
10519  * @details
10520  *
10521  *    Function : extractPdcchCfg
10522  *
10523  *    Functionality: Fills PdcchCfg received  by CU
10524  *
10525  * @params[in] PDCCH_Config_t *cuPdcchCfg,
10526  *             PdcchConfig *duPdcchCfg
10527  * @return void
10528  *
10529  * ****************************************************************/
10530
10531 void extractPdcchCfg(PDCCH_Config_t *cuPdcchCfg, PdcchConfig *macPdcchCfg)
10532 {
10533    uint8_t cRsetIdx = 0;
10534    uint8_t srchSpcIdx = 0;
10535
10536    struct PDCCH_Config__controlResourceSetToAddModList *cRsetToAddModList = NULLP;
10537    struct PDCCH_Config__controlResourceSetToReleaseList *cRsetToRelList = NULLP;
10538    struct PDCCH_Config__searchSpacesToAddModList *srchSpcToAddModList = NULLP;
10539    struct PDCCH_Config__searchSpacesToReleaseList *srchSpcToRelList = NULLP;
10540
10541
10542    /* Control Resource Set To Add/Mod List */
10543    if(cuPdcchCfg->controlResourceSetToAddModList)
10544    {
10545       cRsetToAddModList = cuPdcchCfg->controlResourceSetToAddModList;
10546       if(cRsetToAddModList->list.count)
10547       {
10548          macPdcchCfg->numCRsetToAddMod = cRsetToAddModList->list.count;
10549          for(cRsetIdx = 0; cRsetIdx < cRsetToAddModList->list.count; cRsetIdx++)
10550          {
10551             macPdcchCfg->cRSetToAddModList[cRsetIdx].cRSetId = \
10552                cRsetToAddModList->list.array[cRsetIdx]->controlResourceSetId;
10553             //freqDomRsrcBitStringToInt(&cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources,\
10554                   macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc);
10555             memcpy(macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc, \
10556                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.buf,
10557                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.size);
10558
10559             macPdcchCfg->cRSetToAddModList[cRsetIdx].duration = \
10560                 cRsetToAddModList->list.array[cRsetIdx]->duration;
10561
10562             macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType = \
10563                cRsetToAddModList->list.array[cRsetIdx]->cce_REG_MappingType.present;   
10564             if(macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType == CCE_REG_MAPPINGTYPE_PR_INTERLEAVED)
10565             {
10566                //TODO: handle the case for Interleaved
10567             }
10568             macPdcchCfg->cRSetToAddModList[cRsetIdx].precoderGranularity = \
10569                 cRsetToAddModList->list.array[cRsetIdx]->precoderGranularity;
10570             if(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID)
10571             {
10572                macPdcchCfg->cRSetToAddModList[cRsetIdx].dmrsScramblingId= \
10573                   *(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID);
10574             }
10575          }
10576       }
10577    }
10578    /* Control Resource Set To Release List */
10579    if(cuPdcchCfg->controlResourceSetToReleaseList)
10580    {
10581       cRsetToRelList = cuPdcchCfg->controlResourceSetToReleaseList;
10582       if(cRsetToRelList->list.count)
10583       {
10584          macPdcchCfg->numCRsetToRel = cRsetToRelList->list.count;
10585          for(cRsetIdx = 0; cRsetIdx < cRsetToRelList->list.count; cRsetIdx++)
10586          {
10587             macPdcchCfg->cRSetToRelList[cRsetIdx] = *(cRsetToRelList->list.array[cRsetIdx]);
10588          }
10589       }
10590    }
10591
10592    /* Search space To Add/Mod List */
10593    if(cuPdcchCfg->searchSpacesToAddModList)
10594    {
10595       srchSpcToAddModList = cuPdcchCfg->searchSpacesToAddModList;
10596       if(srchSpcToAddModList->list.count)
10597       {
10598          macPdcchCfg->numSearchSpcToAddMod = srchSpcToAddModList->list.count;
10599          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToAddModList->list.count; srchSpcIdx++)
10600          {
10601             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceId =\
10602                                                                           srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceId;
10603             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].cRSetId =\
10604                                                                     *(srchSpcToAddModList->list.array[srchSpcIdx]->controlResourceSetId);
10605             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset)
10606             {
10607                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSlotPeriodicityAndOffset =\
10608                                                                                          srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset->present;
10609             }
10610             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot)
10611             {
10612                bitStringToInt(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot,\
10613                      macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSymbolsWithinSlot);
10614             }
10615             if(srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates)
10616             {
10617                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel1 = \
10618                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel1;
10619                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel2 = \
10620                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel2;
10621                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel4 = \
10622                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel4;
10623
10624                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel8 = \
10625                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel8;
10626
10627                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel16 = \
10628                                                                                         srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel16;
10629             }
10630             if(srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType)
10631             {
10632                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType =\
10633                                                                                srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->present;
10634                if(macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType == SEARCHSPACETYPE_PR_UE_SPECIFIC)
10635                {
10636                   macPdcchCfg->searchSpcToAddModList[srchSpcIdx].ueSpecificDciFormat =\
10637                                                                                       srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->choice.ue_Specific->dci_Formats;
10638                }
10639
10640             }
10641          }
10642       }
10643    }
10644    /* Search space To Rel List */
10645    if(cuPdcchCfg->searchSpacesToReleaseList)
10646    {
10647       srchSpcToRelList = cuPdcchCfg->searchSpacesToReleaseList;
10648       if(srchSpcToRelList->list.count)
10649       {
10650          macPdcchCfg->numSearchSpcToRel = srchSpcToRelList->list.count;
10651          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToRelList->list.count; srchSpcIdx++)
10652          {
10653             macPdcchCfg->searchSpcToRelList[srchSpcIdx] =\
10654                                                          *(srchSpcToRelList->list.array[srchSpcIdx]);
10655          }
10656       }
10657    }
10658 }
10659
10660 /*******************************************************************
10661  *
10662  * @brief Fills PdschCfg received by CU
10663  *
10664  * @details
10665  *
10666  *    Function : extractPdschCfg
10667  *
10668  *    Functionality: Fills PdschCfg received  by CU
10669  *
10670  * @params[in] PDSCH_Config_t *cuPdschCfg = Information which is send by CU,
10671  *                   which we have stored in F1UeContextSetupDb,
10672  *             PdschConfig *macPdschCfg = Used to Store the information which
10673  *                   needs to send in other layer, as well as this can be the variable
10674  *                   which stores the information in DuCb,
10675  *             PdschConfig *storedPdschCfg =  Null in case of sending the
10676  *                   information to other layer else it will have stored pdsch 
10677  *                   configuration in copyOfmacUeCfg.
10678  * @return void
10679  *
10680  * ****************************************************************/
10681
10682 void extractPdschCfg(PDSCH_Config_t *cuPdschCfg, PdschConfig *macPdschCfg, PdschConfig *storedPdschCfg)
10683 {
10684    uint8_t timeDomIdx;
10685    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAlloc = NULLP;
10686
10687    if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
10688    {
10689       if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->present == \
10690             PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup)
10691       {
10692          if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup)
10693          {
10694             macPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
10695                *(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_AdditionalPosition);
10696          }
10697       }
10698    }
10699    macPdschCfg->resourceAllocType = cuPdschCfg->resourceAllocation;
10700    if(cuPdschCfg->pdsch_TimeDomainAllocationList)
10701    {
10702       timeDomAlloc = cuPdschCfg->pdsch_TimeDomainAllocationList;
10703       if(timeDomAlloc->present ==\
10704             PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup)
10705       {
10706          if(timeDomAlloc->choice.setup)
10707          {
10708             macPdschCfg->numTimeDomRsrcAlloc  = timeDomAlloc->choice.setup->list.count;
10709             for(timeDomIdx = 0; timeDomIdx < timeDomAlloc->choice.setup->list.count; timeDomIdx++)
10710             {
10711                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 = NULLP;
10712                if(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0)
10713                {
10714                   if(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 == NULL)
10715                   {
10716                      if(storedPdschCfg)
10717                      {
10718                         if(storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
10719                         {
10720                            macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 =\
10721                            storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0;
10722                         }
10723                         else
10724                         {
10725                            DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
10726                         }
10727                      }
10728                      else
10729                      {
10730                         DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
10731                      }
10732                      if(!macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
10733                      {
10734                         DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for k0 at extractPdschCfg()");
10735                         return;
10736                      }
10737                   }
10738                   *(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0) = \
10739                   *(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0);
10740                }
10741                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].mappingType = \
10742                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->mappingType;
10743                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].startSymbolAndLength = \
10744                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
10745             }
10746          }
10747       }
10748    }
10749    macPdschCfg->rbgSize = cuPdschCfg->rbg_Size;
10750    if(cuPdschCfg->maxNrofCodeWordsScheduledByDCI)
10751       macPdschCfg->numCodeWordsSchByDci = *(cuPdschCfg->maxNrofCodeWordsScheduledByDCI);
10752    if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_staticBundling)
10753    {
10754       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
10755       if(cuPdschCfg->prb_BundlingType.choice.staticBundling)
10756       {
10757          if(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize)
10758          {
10759             macPdschCfg->bundlingInfo.StaticBundling.size = \
10760                *(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize);
10761          }
10762       }
10763    }
10764    else if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_dynamicBundling)
10765    {
10766       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
10767    }
10768
10769 }
10770
10771 /*******************************************************************
10772  *
10773  * @brief Fills PdschServingCellCfg received by CU
10774  *
10775  * @details
10776  *
10777  *    Function : extractPdschServingCellCfg
10778  *
10779  *    Functionality: Fills PdschCfg received  by CU
10780  *
10781  * @params[in] PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg,
10782  *             PdschServCellCfg *macUePdschSrvCellCfg
10783  * @return ROK/RFAILED
10784  *
10785  * ****************************************************************/
10786
10787 uint8_t extractPdschServingCellCfg(PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg, PdschServCellCfg *macUePdschSrvCellCfg)
10788 {
10789    if(cuPdschSrvCellCfg->codeBlockGroupTransmission)
10790    {
10791       if(cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup)
10792       {
10793          if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
10794          {
10795             *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
10796                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
10797          }
10798          else
10799          {
10800             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10801             if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
10802             {
10803                *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
10804                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
10805             }
10806             else
10807             {
10808                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxCodeBlkGrpPerTb at extractPdschServingCellCfg()");
10809                return RFAILED;
10810             }
10811          }
10812          if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
10813          {
10814             *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
10815                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
10816          }
10817          else
10818          {
10819             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->codeBlkGrpFlushInd , sizeof(bool));
10820             if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
10821             {
10822                *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
10823                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
10824             }
10825             else
10826             {
10827                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for codeBlkGrpFlushInd at extractPdschServingCellCfg()");
10828                return RFAILED;
10829             }
10830          }
10831       }
10832    }
10833    if(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH)
10834    {
10835       macUePdschSrvCellCfg->numHarqProcForPdsch = *(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH); 
10836    }
10837    if(cuPdschSrvCellCfg->ext1)
10838    {
10839       if(cuPdschSrvCellCfg->ext1->maxMIMO_Layers)
10840       {
10841         if(macUePdschSrvCellCfg->maxMimoLayers)
10842         {
10843            *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
10844         }
10845         else
10846         {
10847            DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxMimoLayers, sizeof(uint8_t));
10848            if(macUePdschSrvCellCfg->maxMimoLayers)
10849            {
10850               *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
10851            }
10852            else
10853            {
10854               DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxMimoLayers at extractPdschServingCellCfg()");
10855               return RFAILED;
10856            }
10857         }
10858       }
10859    }
10860    if(cuPdschSrvCellCfg->xOverhead)
10861    {
10862       if(macUePdschSrvCellCfg->xOverhead)
10863       {
10864          *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
10865       }
10866       else
10867       {
10868          DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->xOverhead, sizeof(PdschXOverhead));
10869          if(macUePdschSrvCellCfg->xOverhead)
10870          {
10871             *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
10872          }
10873          else
10874          {
10875             DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for xOverhead at extractPdschServingCellCfg()");
10876             return RFAILED;
10877          }
10878       }
10879    }
10880    return ROK;
10881 }
10882
10883 /*******************************************************************
10884  *
10885  * @brief Fills PuschCfg received by CU
10886  *
10887  * @details
10888  *
10889  *    Function : extractPuschCfg
10890  *
10891  *    Functionality: Fills PuschCfg received  by CU
10892  *
10893  * @params[in] BWP_UplinkDedicated__pusch_Config *cuPuschCfg,
10894  *             PuschCfg *macPuschCfg
10895  * @return void
10896  *
10897  * ****************************************************************/
10898
10899 void extractPuschCfg(struct BWP_UplinkDedicated__pusch_Config *cuPuschCfg, PuschCfg *macPuschCfg)
10900 {
10901    uint8_t timeDomIdx = 0;
10902    DMRS_UplinkConfig_t *dmrsUlCfg = NULLP;
10903    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList = NULLP;
10904
10905    if(cuPuschCfg->present == BWP_UplinkDedicated__pusch_Config_PR_setup)
10906    {
10907       if(cuPuschCfg->choice.setup)
10908       {
10909          if(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH)
10910          {
10911              macPuschCfg->dataScramblingId = \
10912                 *(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH);
10913          }
10914          if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA)
10915          {
10916             if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->present == PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup)
10917             {
10918                if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup)
10919                {
10920                   dmrsUlCfg = (cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup);
10921                   if(dmrsUlCfg->dmrs_AdditionalPosition)
10922                   {
10923                      macPuschCfg->dmrsUlCfgForPuschMapTypeA.addPos =\
10924                         *(dmrsUlCfg->dmrs_AdditionalPosition);
10925                   }
10926                   if(dmrsUlCfg->transformPrecodingDisabled)
10927                   {
10928                      if(dmrsUlCfg->transformPrecodingDisabled->scramblingID0)
10929                      {
10930                         macPuschCfg->dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0 = \
10931                            *(dmrsUlCfg->transformPrecodingDisabled->scramblingID0);
10932                      }
10933                   }
10934                }
10935             }
10936          }
10937          /*Res Alloc Type for UL */
10938          if(cuPuschCfg->choice.setup->resourceAllocation)
10939          {
10940             macPuschCfg->resourceAllocType = \
10941                cuPuschCfg->choice.setup->resourceAllocation;
10942          }
10943          if(cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList)
10944          {
10945             timeDomAllocList = cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList;
10946             if(timeDomAllocList->present == PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup)
10947             {
10948                if(timeDomAllocList->choice.setup)
10949                {
10950                   macPuschCfg->numTimeDomRsrcAlloc = timeDomAllocList->choice.setup->list.count;
10951                   for(timeDomIdx = 0; timeDomIdx <timeDomAllocList->choice.setup->list.count; timeDomIdx++)
10952                   {
10953                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].k2 = \
10954                         *(timeDomAllocList->choice.setup->list.array[timeDomIdx]->k2);
10955                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].mappingType = \
10956                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->mappingType;
10957                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].startSymbolAndLength = \
10958                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
10959                   }
10960                }
10961             }
10962          }
10963          if(cuPuschCfg->choice.setup->transformPrecoder)
10964             macPuschCfg->transformPrecoder = *(cuPuschCfg->choice.setup->transformPrecoder);
10965       }
10966    }
10967 }
10968
10969 /*******************************************************************
10970  *
10971  * @brief Function to fill pucch Power Control
10972  *
10973  * @details
10974  *
10975  *    Function : extractPucchPowerControl
10976  *
10977  *    Functionality: Function to fill pucch Power Control
10978  *
10979  * @params[in] PucchPowerControl *pwrCtrl,
10980  *             struct PUCCH_PowerControl *cuPwrCtrlCfg
10981  * @return void
10982  *
10983  * ****************************************************************/
10984
10985 void extractPucchPowerControl(PucchPowerControl *pwrCtrl, struct PUCCH_PowerControl *cuPwrCtrlCfg)
10986 {
10987    uint8_t arrIdx;
10988
10989    if(cuPwrCtrlCfg->deltaF_PUCCH_f0)
10990       pwrCtrl->deltaF_Format0 = *cuPwrCtrlCfg->deltaF_PUCCH_f0;
10991    if(cuPwrCtrlCfg->deltaF_PUCCH_f1)
10992       pwrCtrl->deltaF_Format1 = *cuPwrCtrlCfg->deltaF_PUCCH_f1;
10993    if(cuPwrCtrlCfg->deltaF_PUCCH_f2)
10994       pwrCtrl->deltaF_Format2 = *cuPwrCtrlCfg->deltaF_PUCCH_f2;
10995    if(cuPwrCtrlCfg->deltaF_PUCCH_f3)
10996       pwrCtrl->deltaF_Format3 = *cuPwrCtrlCfg->deltaF_PUCCH_f3;
10997    if(cuPwrCtrlCfg->deltaF_PUCCH_f4)
10998       pwrCtrl->deltaF_Format4 = *cuPwrCtrlCfg->deltaF_PUCCH_f4;
10999    if(cuPwrCtrlCfg->p0_Set)
11000    {
11001       pwrCtrl->p0SetCount = cuPwrCtrlCfg->p0_Set->list.count;
11002       for(arrIdx=0; arrIdx < pwrCtrl->p0SetCount; arrIdx++)
11003       {
11004          pwrCtrl->p0Set[arrIdx].p0PucchId =\
11005             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Id;
11006          pwrCtrl->p0Set[arrIdx].p0PucchVal =\
11007             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Value;
11008       }
11009    }
11010    if(cuPwrCtrlCfg->pathlossReferenceRSs)
11011    {
11012       pwrCtrl->pathLossRefRSListCount = cuPwrCtrlCfg->pathlossReferenceRSs->list.count;
11013       for(arrIdx = 0; arrIdx < pwrCtrl->pathLossRefRSListCount; arrIdx++)
11014       {
11015          pwrCtrl->pathLossRefRSList[arrIdx].pathLossRefRSId =\
11016             cuPwrCtrlCfg->pathlossReferenceRSs->list.array[arrIdx]->pucch_PathlossReferenceRS_Id;
11017       }
11018    }
11019 }
11020  
11021  /*******************************************************************
11022  *
11023  * @brief Function to extractResrcSetToAddModList sent by CU
11024  *
11025  * @details
11026  *
11027  *    Function : extractResrcSetToAddModList
11028  *
11029  *    Functionality: Fucntion to extractResrcSetToAddModList
11030  *
11031  * @params[in] PucchResrcSetCfg pointer,
11032  *             struct PUCCH_Config__resourceSetToAddModList pointer
11033  * @return void
11034  *
11035  * ****************************************************************/
11036
11037 void extractResrcSetToAddModList(PucchResrcSetCfg *macRsrcSetList, struct PUCCH_Config__resourceSetToAddModList *cuRsrcSetList)
11038 {
11039    uint8_t arrIdx, rsrcListIdx;
11040
11041    macRsrcSetList->resrcSetToAddModListCount = cuRsrcSetList->list.count; 
11042    for(arrIdx = 0; arrIdx < macRsrcSetList->resrcSetToAddModListCount; arrIdx++)
11043    {
11044       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcSetId     =\
11045          cuRsrcSetList->list.array[arrIdx]->pucch_ResourceSetId;
11046       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount =\
11047          cuRsrcSetList->list.array[arrIdx]->resourceList.list.count;
11048       for(rsrcListIdx = 0; rsrcListIdx < macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount; rsrcListIdx++)
11049       {
11050          macRsrcSetList->resrcSetToAddModList[arrIdx].resrcList[rsrcListIdx] =\
11051             *cuRsrcSetList->list.array[arrIdx]->resourceList.list.array[rsrcListIdx];
11052       }
11053
11054       if(cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1)
11055       {
11056          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize =\
11057             *cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1;
11058       }
11059       else
11060       {
11061          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize = 0;
11062       }
11063    }
11064 }/* End of extractResrcSetToAddModList */
11065
11066 /*******************************************************************
11067  *
11068  * @brief Fills extractResrcToAddModList sent by CU
11069  *
11070  * @details
11071  *
11072  *    Function : extractResrcToAddModList
11073  *
11074  *    Functionality: Fills extractResrcToAddModList
11075  *
11076  * @params[in] PucchResrcCfg pointer,
11077  *             struct PUCCH_Config__resourceToAddModList pointer
11078  * @return ROk/RFAILED
11079  *
11080  * ****************************************************************/
11081
11082 uint8_t extractResrcToAddModList(PucchResrcCfg *macResrcList, struct PUCCH_Config__resourceToAddModList *cuResrcList)
11083 {
11084    uint8_t arrIdx;
11085    
11086    macResrcList->resrcToAddModListCount = cuResrcList->list.count;
11087    for(arrIdx = 0; arrIdx < macResrcList->resrcToAddModListCount; arrIdx++)
11088    {
11089       macResrcList->resrcToAddModList[arrIdx].resrcId      =\
11090         cuResrcList->list.array[arrIdx]->pucch_ResourceId; 
11091       macResrcList->resrcToAddModList[arrIdx].startPrb     =\
11092         cuResrcList->list.array[arrIdx]->startingPRB;
11093       if(cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping)
11094       {
11095          macResrcList->resrcToAddModList[arrIdx].intraFreqHop =\
11096            *cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping;
11097       }
11098       if(cuResrcList->list.array[arrIdx]->secondHopPRB)
11099       {
11100          macResrcList->resrcToAddModList[arrIdx].secondPrbHop =\
11101            *cuResrcList->list.array[arrIdx]->secondHopPRB;
11102       }
11103       /* PUCCH RSRC FORMAT */
11104       if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format0)
11105       {
11106          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_0;
11107          if(cuResrcList->list.array[arrIdx]->format.choice.format0)
11108          {
11109             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0, sizeof(PucchFormat0));
11110             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0 == NULLP)
11111             {
11112                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format0 in extractResrcToAddModList()");
11113                return RFAILED;
11114             }
11115             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->initialCyclicShift =\
11116                cuResrcList->list.array[arrIdx]->format.choice.format0->initialCyclicShift;
11117             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->numSymbols =\
11118                cuResrcList->list.array[arrIdx]->format.choice.format0->nrofSymbols;
11119             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->startSymbolIdx =\
11120                cuResrcList->list.array[arrIdx]->format.choice.format0->startingSymbolIndex;
11121          }
11122       }
11123       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format1)
11124       {
11125          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_1;
11126          if(cuResrcList->list.array[arrIdx]->format.choice.format1)
11127          {
11128             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1, sizeof(PucchFormat1));
11129             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1 == NULLP)
11130             {
11131                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format1 in extractResrcToAddModList()");
11132                return RFAILED;
11133             }
11134             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->initialCyclicShift =\
11135                 cuResrcList->list.array[arrIdx]->format.choice.format1->initialCyclicShift;
11136             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->numSymbols =\
11137                 cuResrcList->list.array[arrIdx]->format.choice.format1->nrofSymbols;
11138             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->startSymbolIdx =\
11139                 cuResrcList->list.array[arrIdx]->format.choice.format1->startingSymbolIndex;
11140             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->timeDomOCC =\
11141                 cuResrcList->list.array[arrIdx]->format.choice.format1->timeDomainOCC;
11142          }
11143       }
11144       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format2)
11145       {
11146          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_2;
11147          if(cuResrcList->list.array[arrIdx]->format.choice.format2)
11148          {
11149             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
11150             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2 == NULLP)
11151             {
11152                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format2 in extractResrcToAddModList()");
11153                return RFAILED;
11154             }
11155             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numPrbs =\
11156                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofPRBs;
11157             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numSymbols =\
11158                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofSymbols;
11159             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->startSymbolIdx =\
11160                 cuResrcList->list.array[arrIdx]->format.choice.format2->startingSymbolIndex;
11161          }
11162       }
11163       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format3)
11164       {
11165          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_3;
11166          if(cuResrcList->list.array[arrIdx]->format.choice.format3)
11167          {
11168             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
11169             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3 == NULLP)
11170             {
11171                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format3 in extractResrcToAddModList()");
11172                return RFAILED;
11173             }
11174             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numPrbs =\
11175                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofPRBs;
11176             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numSymbols =\
11177                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofSymbols;
11178             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->startSymbolIdx =\
11179                 cuResrcList->list.array[arrIdx]->format.choice.format3->startingSymbolIndex;
11180          }
11181       }
11182       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format4)
11183       {
11184          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_4;
11185          if(cuResrcList->list.array[arrIdx]->format.choice.format4)
11186          {
11187             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4, sizeof(PucchFormat4));
11188             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4 == NULLP)
11189             {
11190                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format4 in extractResrcToAddModList()");
11191                return RFAILED;
11192             }
11193             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->numSymbols =\
11194                 cuResrcList->list.array[arrIdx]->format.choice.format4->nrofSymbols;
11195             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occLen =\
11196                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Length;
11197             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occIdx =\
11198                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Index;
11199             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->startSymbolIdx =\
11200                 cuResrcList->list.array[arrIdx]->format.choice.format4->startingSymbolIndex;
11201          }
11202       }
11203    }
11204    return ROK;
11205
11206 }/* End of extractResrcToAddModList */
11207
11208 /*******************************************************************
11209  *
11210  * @brief Fills fillPucchSchedReqPeriodAndOffset sent by CU
11211  *
11212  * @details
11213  *
11214  *    Function : fillPucchSchedReqPeriodAndOffset
11215  *
11216  *    Functionality: To fillPucchSchedReqPeriodAndOffset
11217  *
11218  * @params[in] macPeriodicty,
11219  *     SchedulingRequestResourceConfig__periodicityAndOffset pointer
11220  * @return void
11221  *
11222  * ****************************************************************/
11223
11224 void fillPucchSchedReqPeriodAndOffset(uint8_t macPeriodicty, uint16_t  macOffset,\
11225    struct SchedulingRequestResourceConfig__periodicityAndOffset *cuPeriodicty)
11226 {
11227    macPeriodicty = cuPeriodicty->present;
11228    switch(macPeriodicty)
11229    {
11230       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
11231          {
11232             macOffset     = cuPeriodicty->choice.sym2;
11233             break;
11234          }
11235       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
11236          {
11237             macOffset     = cuPeriodicty->choice.sym6or7;
11238             break;
11239          }
11240       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
11241          {
11242             macOffset     = cuPeriodicty->choice.sl1;
11243             break;
11244          }
11245       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
11246          {
11247             macOffset = cuPeriodicty->choice.sl2;
11248             break;
11249          }
11250       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
11251          {
11252             macOffset = cuPeriodicty->choice.sl4;
11253             break;
11254          }
11255       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
11256          {
11257             macOffset = cuPeriodicty->choice.sl5;
11258             break;
11259          }
11260       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
11261          {
11262             macOffset = cuPeriodicty->choice.sl8;
11263             break;
11264          }
11265       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
11266          {
11267             macOffset = cuPeriodicty->choice.sl10;
11268             break;
11269          }
11270       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
11271          {
11272             macOffset = cuPeriodicty->choice.sl16;
11273             break;
11274          }
11275       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
11276          {
11277             macOffset = cuPeriodicty->choice.sl20;
11278             break;
11279          }
11280       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
11281          {
11282             macOffset = cuPeriodicty->choice.sl40;
11283             break;
11284          }
11285       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
11286          {
11287             macOffset = cuPeriodicty->choice.sl80;
11288             break;
11289          }
11290       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
11291          {
11292             macOffset = cuPeriodicty->choice.sl160;
11293             break;
11294          }
11295       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
11296          {
11297             macOffset = cuPeriodicty->choice.sl320;
11298             break;
11299          }
11300       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
11301          {
11302             macOffset = cuPeriodicty->choice.sl640;
11303             break;
11304          }
11305       default :
11306          DU_LOG("\nERROR  -->  F1AP : Invalid periodicity %d", macPeriodicty);
11307    }
11308 }
11309
11310 /*******************************************************************
11311  *
11312  * @brief Function to extractPucchFormatCfg sent by CU
11313  *
11314  * @details
11315  *
11316  *    Function : extractPucchFormatCfg
11317  *
11318  *    Functionality: Function to extractPucchFormatCfg
11319  *
11320  * @params[in] PucchFormatCfg pointer,
11321  *             PUCCH_FormatConfig_t pointer
11322  * @return void
11323  *
11324  * ****************************************************************/
11325
11326 void extractPucchFormatCfg(PucchFormatCfg *macFormatCfg, PUCCH_FormatConfig_t *cuFormatCfg)
11327  {
11328     if(cuFormatCfg->interslotFrequencyHopping)
11329        macFormatCfg->interSlotFreqHop = *cuFormatCfg->interslotFrequencyHopping;
11330     if(cuFormatCfg->additionalDMRS)  
11331        macFormatCfg->addDmrs = *cuFormatCfg->additionalDMRS;
11332     if(cuFormatCfg->maxCodeRate)
11333        macFormatCfg->maxCodeRate = *cuFormatCfg->maxCodeRate;
11334     if(cuFormatCfg->nrofSlots)  
11335        macFormatCfg->numSlots = *cuFormatCfg->nrofSlots;
11336     if(cuFormatCfg->pi2BPSK)  
11337        macFormatCfg->pi2BPSK = *cuFormatCfg->pi2BPSK;
11338     if(cuFormatCfg->simultaneousHARQ_ACK_CSI)  
11339        macFormatCfg->harqAckCSI = *cuFormatCfg->simultaneousHARQ_ACK_CSI;
11340  }/* End of extractPucchFormatCfg */
11341
11342 /*******************************************************************
11343  *
11344  * @brief Function to extractSchedReqCfgToAddMod sent by CU
11345  *
11346  * @details
11347  *
11348  *    Function : extractSchedReqCfgToAddMod
11349  *
11350  *    Functionality: Function to extractSchedReqCfgToAddMod
11351  *
11352  * @params[in] PucchSchedReqCfg pointer,
11353  *      PUCCH_Config__schedulingRequestResourceToAddModList pointer
11354  * @return void
11355  *
11356  * ****************************************************************/
11357
11358 void extractSchedReqCfgToAddMod(PucchSchedReqCfg *macSchedReqCfg, struct PUCCH_Config__schedulingRequestResourceToAddModList *cuSchedReqList)
11359 {
11360    uint8_t arrIdx;
11361
11362    macSchedReqCfg->schedAddModListCount = cuSchedReqList->list.count;
11363    for(arrIdx = 0; arrIdx <  macSchedReqCfg->schedAddModListCount; arrIdx++)
11364    {
11365       macSchedReqCfg->schedAddModList[arrIdx].resrcId =\
11366          cuSchedReqList->list.array[arrIdx]->schedulingRequestResourceId;
11367       macSchedReqCfg->schedAddModList[arrIdx].requestId =\
11368          cuSchedReqList->list.array[arrIdx]->schedulingRequestID;
11369       if(cuSchedReqList->list.array[arrIdx]->periodicityAndOffset)
11370       {
11371          fillPucchSchedReqPeriodAndOffset(macSchedReqCfg->schedAddModList[arrIdx].periodicity,\
11372             macSchedReqCfg->schedAddModList[arrIdx].offset, cuSchedReqList->list.array[arrIdx]->periodicityAndOffset);
11373       }
11374       if(cuSchedReqList->list.array[arrIdx]->resource)
11375       {
11376          macSchedReqCfg->schedAddModList[arrIdx].resrc =\
11377             *cuSchedReqList->list.array[arrIdx]->resource;
11378       }
11379    }
11380
11381 }/* End of extractSchedReqCfgToAddMod */
11382
11383  /*******************************************************************
11384  *
11385  * @brief Fills PucchCfg received by CU
11386  *
11387  * @details
11388  *
11389  *    Function : extractPucchCfg
11390  *
11391  *    Functionality: Fills PucchCfg received  by CU
11392  *
11393  * @params[in] BWP_UplinkDedicated__pucch_Config *cuPucchCfg = Information which
11394  *                is send by CU, which we have stored in F1UeContextSetupDb,
11395  *             PucchCfg *macPucchCfg = Used to Store the information which
11396  *                needs to send in other layer, as well as this can be the variable
11397  *                which stores the information in DuCb,
11398  *             PucchCfg *storedPucchCfg = Null in case of sending the
11399  *                information to other layer else it will have Pucch Cfg which
11400  *                we have stored in copyOfmacUeCfg.
11401  * @return ROK/RFAILED
11402  *
11403  * ****************************************************************/
11404
11405 uint8_t extractPucchCfg(struct BWP_UplinkDedicated__pucch_Config *cuPucchCfg, PucchCfg *macPucchCfg,\
11406 PucchCfg *storedPucchCfg)        
11407 {
11408    uint8_t arrIdx;
11409
11410    if(cuPucchCfg->present == BWP_UplinkDedicated__pucch_Config_PR_setup)
11411    {
11412       if(cuPucchCfg->choice.setup)
11413       {
11414          /* Resource Set Cfg */ 
11415          if(cuPucchCfg->choice.setup->resourceSetToAddModList)
11416          {
11417             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrcSet, sizeof(PucchResrcSetCfg));
11418             if(macPucchCfg->resrcSet == NULLP)
11419             {
11420                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc set List in extractPucchCfg()");
11421                return RFAILED;
11422             }
11423             memset(macPucchCfg->resrcSet, 0, sizeof(PucchResrcSetCfg));
11424             extractResrcSetToAddModList(macPucchCfg->resrcSet, cuPucchCfg->choice.setup->resourceSetToAddModList);
11425          }
11426          
11427          /* Resource Cfg */ 
11428          if(cuPucchCfg->choice.setup->resourceToAddModList)
11429          {
11430             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrc, sizeof(PucchResrcCfg));
11431             if(macPucchCfg->resrc == NULLP)
11432             {
11433                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc List in extractPucchCfg()");
11434                return RFAILED;
11435             }
11436             memset(macPucchCfg->resrc, 0, sizeof(PucchResrcCfg));
11437             extractResrcToAddModList(macPucchCfg->resrc, cuPucchCfg->choice.setup->resourceToAddModList);
11438          }
11439          
11440          /* Format 1 Cfg */ 
11441          if(cuPucchCfg->choice.setup->format1)
11442          {
11443             DU_ALLOC_SHRABL_BUF(macPucchCfg->format1, sizeof(PucchFormatCfg));
11444             if(macPucchCfg->format1 == NULLP)
11445             {
11446                DU_LOG("\nERROR --> F1AP : Failed to extract format 1 Cfg in  extractPucchCfg()");
11447                return RFAILED;
11448             }
11449             memset(macPucchCfg->format1, 0, sizeof(PucchFormatCfg));
11450             extractPucchFormatCfg(macPucchCfg->format1,\
11451                cuPucchCfg->choice.setup->format1->choice.setup);
11452          }
11453          
11454          /* Format 2 Cfg */
11455          if(cuPucchCfg->choice.setup->format2)
11456          {
11457             DU_ALLOC_SHRABL_BUF(macPucchCfg->format2, sizeof(PucchFormatCfg));
11458             if(macPucchCfg->format2 == NULLP)
11459             {
11460                DU_LOG("\nERROR --> F1AP : Failed to extract format 2 Cfg in  extractPucchCfg()");
11461                return RFAILED;
11462             }
11463             memset(macPucchCfg->format2, 0, sizeof(PucchFormatCfg));
11464             extractPucchFormatCfg(macPucchCfg->format2,\
11465                cuPucchCfg->choice.setup->format2->choice.setup);
11466          }
11467          
11468          /* Format 3 Cfg */
11469          if(cuPucchCfg->choice.setup->format3)
11470          {
11471             DU_ALLOC_SHRABL_BUF(macPucchCfg->format3, sizeof(PucchFormatCfg));
11472             if(macPucchCfg->format3 == NULLP)
11473             {
11474                DU_LOG("\nERROR --> F1AP : Failed to extract format 3 Cfg in  extractPucchCfg()");
11475                return RFAILED;
11476             }
11477             memset(macPucchCfg->format3, 0, sizeof(PucchFormatCfg));
11478             extractPucchFormatCfg(macPucchCfg->format3,\
11479                cuPucchCfg->choice.setup->format3->choice.setup);
11480          }
11481
11482          /* Format 4 Cfg */
11483          if(cuPucchCfg->choice.setup->format4)
11484          {
11485             DU_ALLOC_SHRABL_BUF(macPucchCfg->format4, sizeof(PucchFormatCfg));
11486             if(macPucchCfg->format4 == NULLP)
11487             {
11488                DU_LOG("\nERROR --> F1AP : Failed to extract format 4 Cfg in  extractPucchCfg()");
11489                return RFAILED;
11490             }
11491             memset(macPucchCfg->format4, 0, sizeof(PucchFormatCfg));
11492             extractPucchFormatCfg(macPucchCfg->format4,\
11493                cuPucchCfg->choice.setup->format4->choice.setup);
11494          }
11495
11496          /* Sched Req List */
11497          if(cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList)
11498          {
11499             DU_ALLOC_SHRABL_BUF(macPucchCfg->schedReq, sizeof(PucchSchedReqCfg));
11500             if(macPucchCfg->schedReq == NULLP)
11501             {
11502                DU_LOG("\nERROR --> F1AP : Failed to extract schedReqCfg in  extractPucchCfg()");
11503                return RFAILED;
11504             }
11505             memset(macPucchCfg->schedReq, 0, sizeof(PucchSchedReqCfg));
11506             extractSchedReqCfgToAddMod(macPucchCfg->schedReq,\
11507             cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList);
11508          }
11509
11510          /*TODO: Add support for  Spatial Info */
11511
11512          /* MultiCsiCfg */
11513          if(cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList)
11514          {
11515             DU_ALLOC_SHRABL_BUF(macPucchCfg->multiCsiCfg, sizeof(PucchMultiCsiCfg));
11516             if(macPucchCfg->multiCsiCfg == NULLP)
11517             {
11518                DU_LOG("\nERROR --> F1AP : Failed to extract multiCsiCfg in  extractPucchCfg()");
11519                return RFAILED;
11520             }
11521             memset(macPucchCfg->multiCsiCfg, 0, sizeof(PucchMultiCsiCfg));
11522             macPucchCfg->multiCsiCfg->multiCsiResrcListCount = cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.count;
11523             for(arrIdx =0; arrIdx < macPucchCfg->multiCsiCfg->multiCsiResrcListCount; arrIdx++)
11524             {
11525                macPucchCfg->multiCsiCfg->multiCsiResrcList[arrIdx] =\
11526                  *cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.array[arrIdx];
11527             }
11528          }
11529
11530          /* Dl_DataToUL_ACK */ 
11531          if(cuPucchCfg->choice.setup->dl_DataToUL_ACK)
11532     {
11533        if(storedPucchCfg)
11534        {
11535           if(storedPucchCfg->dlDataToUlAck)
11536           {
11537              macPucchCfg->dlDataToUlAck = storedPucchCfg->dlDataToUlAck; 
11538           }
11539           else
11540           {
11541             DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
11542           }
11543        }
11544        else
11545        {
11546           DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
11547        }
11548        if(macPucchCfg->dlDataToUlAck == NULLP)
11549        {
11550           DU_LOG("\nERROR --> F1AP : Failed to extract Dl_DataToUL_ACK in extractPucchCfg()");
11551           return RFAILED;
11552        }
11553        memset(macPucchCfg->dlDataToUlAck, 0, sizeof(PucchDlDataToUlAck));
11554        macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount = cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.count;
11555        for(arrIdx = 0; arrIdx < macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; arrIdx++)
11556        {
11557           macPucchCfg->dlDataToUlAck->dlDataToUlAckList[arrIdx] =\
11558           *cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.array[arrIdx];
11559        }
11560          }
11561
11562          /* Power Control */
11563          if(cuPucchCfg->choice.setup->pucch_PowerControl)
11564          {
11565             DU_ALLOC_SHRABL_BUF(macPucchCfg->powerControl, sizeof(PucchPowerControl));
11566             if(macPucchCfg->powerControl == NULLP)
11567             {
11568                DU_LOG("\nERROR --> F1AP : Failed to extract power control in extractPucchCfg()");
11569                return RFAILED;
11570             }
11571             extractPucchPowerControl(macPucchCfg->powerControl,\
11572                cuPucchCfg->choice.setup->pucch_PowerControl);
11573          }
11574       }
11575    }
11576    return ROK;
11577 }
11578
11579 /*******************************************************************
11580  *
11581  * @brief Fills ServingCellReconfig received by CU
11582  *
11583  * @details
11584  *
11585  *    Function : extractSpCellDedicatedCfg
11586  *
11587  *    Functionality: Fills ServingCellReconfig received  by CU
11588  *
11589  * @params[in] ServingCellConfig_t *cuSrvCellCfg = Information which is send by
11590  *                  CU, which we have stored in F1UeContextSetupDb,
11591  *             ServCellCfgInfo *macSrvCellCfg = Used to Store the information
11592  *                  which  needs to send in other layer, as well as this can be the
11593  *                  variable which stores the information in DuCb, 
11594  *             ServCellCfgInfo *storedSrvCellCfg = Null in case of sending the
11595  *                  information to other layer else it will have ServCellCfgInfo which
11596  *                  we have stored in copyOfmacUeCfg.
11597  * @return ROK/RFAILD
11598  *
11599  * ****************************************************************/
11600 uint8_t extractSpCellDedicatedCfg(ServingCellConfig_t *cuSrvCellCfg, ServCellCfgInfo *macSrvCellCfg,\
11601 ServCellCfgInfo *storedSrvCellCfg)
11602 {
11603    uint8_t ret = ROK;
11604    BWP_DownlinkDedicated_t *dlBwp = NULLP;
11605    BWP_UplinkDedicated_t   *ulBwp = NULLP;
11606
11607    if(cuSrvCellCfg->initialDownlinkBWP)
11608    {
11609       dlBwp = ((BWP_DownlinkDedicated_t *)(cuSrvCellCfg->initialDownlinkBWP));
11610       if(dlBwp->pdcch_Config)
11611       {
11612          if(dlBwp->pdcch_Config->choice.setup)
11613          {
11614             macSrvCellCfg->initDlBwp.pdcchPresent = true;
11615             if(storedSrvCellCfg)
11616             {
11617                if(!storedSrvCellCfg->initDlBwp.pdcchPresent)
11618                {
11619                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11620                }
11621                else
11622                {
11623                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11624                }
11625             }
11626             else
11627             {
11628                extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11629             }
11630          }
11631       }
11632       if(dlBwp->pdsch_Config)
11633       {
11634          if(dlBwp->pdsch_Config->choice.setup)
11635          {
11636             macSrvCellCfg->initDlBwp.pdschPresent = true;
11637             
11638             if(storedSrvCellCfg)
11639             {
11640                if(!storedSrvCellCfg->initDlBwp.pdschPresent)
11641                {
11642                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
11643                }
11644                else
11645                {
11646                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg,\
11647                         &storedSrvCellCfg->initDlBwp.pdschCfg);
11648                }
11649             }
11650             else
11651             {
11652                extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
11653             }
11654          }
11655       }
11656    }
11657    if(cuSrvCellCfg->firstActiveDownlinkBWP_Id)
11658       macSrvCellCfg->firstActvDlBwpId = *(cuSrvCellCfg->firstActiveDownlinkBWP_Id);
11659    if(cuSrvCellCfg->defaultDownlinkBWP_Id)
11660       macSrvCellCfg->defaultDlBwpId = *(cuSrvCellCfg->defaultDownlinkBWP_Id);
11661    if(cuSrvCellCfg->bwp_InactivityTimer)
11662    {
11663       if(macSrvCellCfg->bwpInactivityTmr)
11664       {
11665          memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
11666       }
11667       else
11668       {
11669          macSrvCellCfg->bwpInactivityTmr = NULLP;
11670          DU_ALLOC_SHRABL_BUF(macSrvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
11671          if(macSrvCellCfg->bwpInactivityTmr)
11672          {
11673             memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
11674          }
11675          else
11676          {
11677             DU_LOG("\nERROR  --> F1AP : Memory Alloc failed for bwpInactivityTmr at extractSpCellDedicatedCfg()");
11678             return RFAILED;
11679          }
11680       }
11681    }
11682    if(cuSrvCellCfg->pdsch_ServingCellConfig)
11683    {
11684       if(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup)
11685       {
11686          ret = extractPdschServingCellCfg(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup, &macSrvCellCfg->pdschServCellCfg);
11687          if(ret == RFAILED)
11688          {
11689             DU_LOG("\nERROR --> F1AP : Failed at extractPdschServingCellCfg()");
11690             return RFAILED;
11691          }
11692       }
11693    }
11694    if(cuSrvCellCfg->uplinkConfig)
11695    {
11696       if(cuSrvCellCfg->uplinkConfig->initialUplinkBWP)
11697       {
11698          ulBwp = ((BWP_UplinkDedicated_t *)(cuSrvCellCfg->uplinkConfig->initialUplinkBWP));
11699          if(ulBwp->pusch_Config)
11700          {
11701             macSrvCellCfg->initUlBwp.puschPresent = true;
11702             extractPuschCfg(ulBwp->pusch_Config, &macSrvCellCfg->initUlBwp.puschCfg);
11703          }
11704          if(ulBwp->pucch_Config)
11705          {
11706             macSrvCellCfg->initUlBwp.pucchPresent = true;
11707             memset(&macSrvCellCfg->initUlBwp.pucchCfg, 0, sizeof(PucchCfg));
11708             if(storedSrvCellCfg)
11709             {
11710                if(!storedSrvCellCfg->initUlBwp.pucchPresent)
11711                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
11712                else
11713                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg,\
11714                   &storedSrvCellCfg->initUlBwp.pucchCfg);
11715             }
11716             else
11717             {
11718                extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
11719             }
11720          }
11721       }
11722       if(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id)
11723          macSrvCellCfg->firstActvUlBwpId = *(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id);
11724    }
11725    return ret;
11726 }
11727 /*******************************************************************
11728  *
11729  * @brief Fills Reconfig Cell group Info received by CU
11730  *
11731  * @details
11732  *
11733  *    Function : extractUeReCfgCellInfo
11734  *
11735  *    Functionality: Fills Reconfig Cell group Info received by CU
11736  *   
11737  * @params[in] CellGroupConfigRrc_t *cellGrp = CellGroupConfigRrc_t information which
11738  *                       is send by CU, which we have stored in F1UeContextSetupDb
11739  *             MacUeCfg *MacUeCfg = Used to Store the information,
11740  *                      which needs to send in other layer, as well as this can be
11741  *                      the variable which stores the information in DuCb,
11742  *             MacUeCfg *storedMacUeCfg = Null in case of sending the
11743  *                      information to other layer else it will have copyOfmacUeCfg
11744  *                      which we have stored in F1UeContextSetupDb.
11745  *
11746  * @return ROK/RFAILED
11747  *
11748  * ****************************************************************/
11749 uint8_t extractUeReCfgCellInfo(CellGroupConfigRrc_t *cellGrp, MacUeCfg *macUeCfg, MacUeCfg *storedMacUeCfg)
11750 {
11751    uint8_t ret = ROK;
11752    MAC_CellGroupConfig_t     *macCellGroup = NULLP;
11753    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
11754    SpCellConfig_t            *spcellCfg = NULLP;
11755    ServingCellConfig_t       *servCellCfg = NULLP;
11756
11757    if(cellGrp)
11758    {
11759       /* Fill MacCell Group Reconfig  */
11760       if(cellGrp->mac_CellGroupConfig)
11761       {
11762          macUeCfg->macCellGrpCfgPres = true;
11763          macCellGroup = ((MAC_CellGroupConfig_t *)(cellGrp->mac_CellGroupConfig));
11764          if(macCellGroup->schedulingRequestConfig)
11765          {
11766             extractSchReqReConfig(macCellGroup->schedulingRequestConfig, &macUeCfg->macCellGrpCfg.schReqCfg);
11767          }
11768          if(macCellGroup->tag_Config)
11769          {
11770             extractTagReconfig(macCellGroup->tag_Config, &macUeCfg->macCellGrpCfg.tagCfg);
11771          }
11772          if(macCellGroup->bsr_Config)
11773          {
11774             macUeCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer = macCellGroup->bsr_Config->periodicBSR_Timer;
11775             macUeCfg->macCellGrpCfg.bsrTmrCfg.retxTimer     = macCellGroup->bsr_Config->retxBSR_Timer;
11776             if(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer)
11777             {
11778                macUeCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer  =\
11779                *(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer);
11780             }
11781          }
11782          if(macCellGroup->phr_Config)
11783          {
11784             if(macCellGroup->phr_Config->present == MAC_CellGroupConfig__phr_Config_PR_setup)
11785             {
11786                macUeCfg->macCellGrpCfg.phrCfgSetupPres = true;
11787                if(macCellGroup->phr_Config->choice.setup)
11788                {
11789                   macUeCfg->macCellGrpCfg.phrCfg.periodicTimer     = \
11790                   macCellGroup->phr_Config->choice.setup->phr_PeriodicTimer;
11791                   macUeCfg->macCellGrpCfg.phrCfg.prohibitTimer     = \
11792                   macCellGroup->phr_Config->choice.setup->phr_ProhibitTimer;
11793                   macUeCfg->macCellGrpCfg.phrCfg.txPowerFactor     = \
11794                   macCellGroup->phr_Config->choice.setup->phr_Tx_PowerFactorChange;
11795                   macUeCfg->macCellGrpCfg.phrCfg.multiplePHR       = \
11796                   macCellGroup->phr_Config->choice.setup->multiplePHR;
11797                   macUeCfg->macCellGrpCfg.phrCfg.dummy             = \
11798                   macCellGroup->phr_Config->choice.setup->dummy;
11799                   macUeCfg->macCellGrpCfg.phrCfg.phrType2OtherCell = \
11800                   macCellGroup->phr_Config->choice.setup->phr_Type2OtherCell;
11801                   macUeCfg->macCellGrpCfg.phrCfg.phrOtherCG        = \
11802                   macCellGroup->phr_Config->choice.setup->phr_ModeOtherCG;
11803                }
11804             }
11805          }
11806       }
11807       /* Fill Physical Cell Group Reconfig */
11808       if(cellGrp->physicalCellGroupConfig)
11809       {
11810          macUeCfg->phyCellGrpCfgPres = true;
11811          phyCellGrpCfg = ((PhysicalCellGroupConfig_t *)(cellGrp->physicalCellGroupConfig));
11812          if(phyCellGrpCfg->p_NR_FR1)
11813          {
11814             if(*(phyCellGrpCfg->p_NR_FR1) != macUeCfg->phyCellGrpCfg.pNrFr1)
11815                macUeCfg->phyCellGrpCfg.pNrFr1 = *(phyCellGrpCfg->p_NR_FR1);
11816          }
11817          macUeCfg->phyCellGrpCfg.pdschHarqAckCodebook = phyCellGrpCfg->pdsch_HARQ_ACK_Codebook;
11818       }
11819       /* Fill SpCell Reconfig */
11820       if(cellGrp->spCellConfig)
11821       {
11822          macUeCfg->spCellCfgPres = true;
11823          spcellCfg = ((SpCellConfig_t *)(cellGrp->spCellConfig));  
11824          if(spcellCfg->servCellIndex)
11825          {
11826             macUeCfg->spCellCfg.servCellIdx = *(spcellCfg->servCellIndex);
11827          }
11828          /* Fill Serving cell Reconfig info */
11829          if(cellGrp->spCellConfig->spCellConfigDedicated)
11830          {
11831             servCellCfg = ((ServingCellConfig_t *)(cellGrp->spCellConfig->spCellConfigDedicated));
11832             if(storedMacUeCfg)
11833             {
11834                if(!storedMacUeCfg->spCellCfgPres)
11835                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
11836                else
11837                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg,\
11838                         &storedMacUeCfg->spCellCfg.servCellCfg);
11839             }
11840             else
11841             {
11842                ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
11843             }
11844             if(ret == RFAILED)
11845             {
11846                DU_LOG("\nERROR --> F1AP : Failed at extractSpCellDedicatedCfg()");
11847             }
11848          }
11849       }
11850    }
11851    return ret;
11852 }
11853 /*******************************************************************
11854 *
11855 * @brief free the memory allocated by decoder
11856 *
11857 * @details
11858 *
11859 *    Function : freeAperDecodeNrcgi 
11860 *
11861 *    Functionality: Free Nrcgi values
11862 *
11863 * @params[in] NRCGI_t *nrcgi
11864 * @return void
11865 *
11866 * ****************************************************************/
11867
11868
11869 void freeAperDecodeNrcgi(NRCGI_t *nrcgi)
11870 {
11871     if(nrcgi->pLMN_Identity.buf != NULLP)
11872     {
11873        free(nrcgi->pLMN_Identity.buf);
11874     }
11875     if(nrcgi->nRCellIdentity.buf != NULLP)
11876     {
11877        free(nrcgi->nRCellIdentity.buf);
11878     }
11879 }
11880 /*******************************************************************
11881 *
11882 * @brief free the memory allocated by decoder
11883 *
11884 * @details
11885 *
11886 *    Function : freeAperDecodeCuToDuInfo 
11887 *
11888 *    Functionality:  Free Cu To Du Information
11889 *
11890 * @params[in] CUtoDURRCInformation_t *rrcMsg
11891 * @return void
11892 *
11893 * ****************************************************************/
11894
11895
11896 void freeAperDecodeCuToDuInfo(CUtoDURRCInformation_t *rrcMsg)
11897 {
11898    uint8_t ieIdx =0;
11899    uint8_t arrIdx =0;
11900
11901    if(rrcMsg->uE_CapabilityRAT_ContainerList)
11902    {
11903       if(rrcMsg->uE_CapabilityRAT_ContainerList->buf)
11904          free(rrcMsg->uE_CapabilityRAT_ContainerList->buf);
11905       free(rrcMsg->uE_CapabilityRAT_ContainerList);
11906    }
11907
11908    if(rrcMsg->iE_Extensions)
11909    {
11910       if(rrcMsg->iE_Extensions->list.array)
11911       {
11912          for(ieIdx= 0; ieIdx < rrcMsg->iE_Extensions->list.count; ieIdx++)
11913          {
11914             if(rrcMsg->iE_Extensions->list.array[ieIdx])
11915             {
11916                switch(rrcMsg->iE_Extensions->list.array[ieIdx]->id)
11917                {
11918                   case ProtocolIE_ID_id_CellGroupConfig:
11919                      if(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf != NULLP)
11920                      {
11921                         free(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf);
11922                      }
11923                      break;
11924                   default:
11925                      DU_LOG("\nERROR  -->  F1AP : Invalid Event type %ld at FreeCuToDuInfo()", \
11926                            rrcMsg->iE_Extensions->list.array[ieIdx]->id);
11927                      break;
11928                }
11929             }
11930          }
11931          for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
11932          {
11933             free(rrcMsg->iE_Extensions->list.array[arrIdx]);
11934          }
11935          free(rrcMsg->iE_Extensions->list.array);
11936
11937       }
11938
11939       free(rrcMsg->iE_Extensions);
11940    }
11941 }
11942 /*******************************************************************
11943 *
11944 * @brief free the memory allocated by decoder
11945 *
11946 * @details 
11947 *
11948 *    Function : freeAperDecodeSplCellList
11949 *
11950 *    Functionality: Free Spl Cell List 
11951                     where memory allocated by aper_decoder
11952 *
11953 * @params[in]  SCell_ToBeSetup_List_t *spCellLst
11954 * @return void
11955 *
11956 * ****************************************************************/
11957
11958
11959 void freeAperDecodeSplCellList(SCell_ToBeSetup_List_t *spCellLst)
11960 {
11961     uint8_t  cellIdx =0;
11962
11963     if(spCellLst->list.array != NULLP)
11964     {
11965        for(cellIdx=0; cellIdx<spCellLst->list.count; cellIdx++)
11966        {
11967           if(cellIdx==0&&spCellLst->list.array[cellIdx]!=NULLP)
11968           {
11969              freeAperDecodeNrcgi(&spCellLst->list.array[cellIdx]->value.choice.SCell_ToBeSetup_Item.sCell_ID);
11970           }
11971           if(spCellLst->list.array[cellIdx]!=NULLP)
11972           {
11973              free(spCellLst->list.array[cellIdx]);
11974           }
11975        }
11976        free(spCellLst->list.array);
11977     }
11978 }
11979 /*******************************************************************
11980 *
11981 * @brief free the memory allocated by decoder
11982 *
11983 * @details
11984 *
11985 *    Function : freeAperDecodeSRBSetup 
11986 *
11987 *    Functionality: added free part for the memory allocated by aper_decoder
11988 *
11989 * @params[in] SRBs_ToBeSetup_List_t *srbSet
11990 * @return void
11991 *
11992 ****************************************************************/
11993
11994
11995 void freeAperDecodeSRBSetup(SRBs_ToBeSetup_List_t *srbSet)
11996 {
11997     uint8_t srbIdx =0;
11998     if(srbSet->list.array != NULLP)
11999     {
12000        for(srbIdx=0; srbIdx<srbSet->list.count; srbIdx++)
12001        {
12002           if(srbSet->list.array[srbIdx]!=NULLP)
12003           {
12004              free(srbSet->list.array[srbIdx]);
12005           }
12006        }
12007        free(srbSet->list.array);
12008     }
12009 }
12010
12011 /*******************************************************************
12012 *
12013 * @brief free the memory allocated by decoder
12014 *
12015 * @details
12016 *
12017 *    Function : freeAperDecodeULTnlInfo
12018 *
12019 *    Functionality: added free part for the memory allocated by aper_decoder
12020 *
12021 * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
12022 * @return void
12023 *
12024 * ****************************************************************/
12025
12026
12027 void freeAperDecodeULTnlInfo(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
12028 {
12029    uint8_t ulIdx=0;
12030    if(ulInfo->list.array != NULLP)
12031    {
12032       for(ulIdx=0; ulIdx<ulInfo->list.count; ulIdx++)
12033       {
12034          if(ulIdx==0&&ulInfo->list.array[ulIdx]!=NULLP)
12035          {
12036             if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel!=NULLP)
12037             {
12038                if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12039                      transportLayerAddress.buf != NULLP)
12040                {
12041                   if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf\
12042                         !=NULLP)
12043                   {
12044                      free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf);
12045                   }
12046                   free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12047                         transportLayerAddress.buf);
12048                }
12049                free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel);
12050             }
12051          }
12052          if(ulInfo->list.array[ulIdx]!=NULLP)
12053          {
12054             free(ulInfo->list.array[ulIdx]);
12055          }
12056       }
12057       free(ulInfo->list.array);
12058    }
12059 }
12060 /*******************************************************************
12061 *
12062 * @brief free the memory allocated by decoder
12063 *
12064 * @details
12065 *
12066 *    Function : freeAperDecodeDRBSetup  
12067 *
12068 *    Functionality: free DRBSetup which is allocated by decoder
12069 *
12070 * @params[in]  DRBs_ToBeSetup_List_t *drbSet
12071 * @return void
12072 *
12073 * ****************************************************************/
12074
12075 void freeAperDecodeDRBSetup(DRBs_ToBeSetup_List_t *drbSet)
12076 {
12077    DRBs_ToBeSetup_Item_t *drbSetItem = NULLP;
12078    uint8_t  flowIdx =0;
12079    uint8_t  drbIdx =0;
12080
12081    if(drbSet->list.array != NULLP)
12082    {
12083       for(drbIdx=0; drbIdx<drbSet->list.count; drbIdx++)
12084       {
12085          if(drbIdx==0&&drbSet->list.array[drbIdx] != NULLP)
12086          {
12087             drbSetItem =&drbSet->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12088             if(drbSetItem->qoSInformation.choice.choice_extension != NULLP)
12089             {
12090                if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12091                      qoS_Characteristics.choice.non_Dynamic_5QI !=NULLP)
12092                {
12093                   if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12094                         qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12095                   {
12096                      if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12097                            qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12098                      {
12099
12100                         if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf!=NULLP)
12101                         {
12102
12103                            if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD!=NULLP)
12104                            {
12105
12106                               if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD->\
12107                                     buf!=NULLP)
12108                               {
12109
12110                                  if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.\
12111                                        flows_Mapped_To_DRB_List.list.array != NULLP)
12112                                  {
12113
12114                                     for(flowIdx=0;flowIdx<drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12115                                           DRB_Information.flows_Mapped_To_DRB_List.list.count; flowIdx++)
12116                                     {
12117
12118                                        if(flowIdx==0&&drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12119                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12120                                        {
12121                                           if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12122                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12123                                                 qoSFlowLevelQoSParameters.\
12124                                                 qoS_Characteristics.choice.non_Dynamic_5QI!=NULLP)
12125                                           {
12126                                              if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12127                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12128                                                    qoSFlowLevelQoSParameters.\
12129                                                    qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12130                                              {
12131
12132                                                 if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12133                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12134                                                       qoSFlowLevelQoSParameters.\
12135                                                       qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12136                                                 {
12137
12138
12139                                                    free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12140                                                          DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12141                                                          qoSFlowLevelQoSParameters.\
12142                                                          qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12143                                                 }
12144
12145                                                 free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12146                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12147                                                       qoSFlowLevelQoSParameters.\
12148                                                       qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12149                                              }
12150
12151                                              free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12152
12153                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12154                                                    qoSFlowLevelQoSParameters.\
12155                                                    qoS_Characteristics.choice.non_Dynamic_5QI);
12156                                           }
12157                                        }
12158                                        if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12159                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12160                                        {
12161
12162                                           free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12163                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]);
12164                                        }
12165                                     }
12166
12167                                     free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12168                                           DRB_Information.flows_Mapped_To_DRB_List.list.array);
12169                                  }
12170
12171                                  free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12172                                        DRB_Information.sNSSAI.sD->buf);
12173                               }
12174
12175                               free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD);
12176                            }
12177
12178                            free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf);
12179
12180                         }
12181
12182                         free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12183
12184                               qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12185                      }
12186
12187                      free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12188                            qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12189                   }
12190
12191                   free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12192                         qoS_Characteristics.choice.non_Dynamic_5QI);
12193                }
12194                free(drbSetItem->qoSInformation.choice.choice_extension);
12195             }
12196             freeAperDecodeULTnlInfo(&drbSetItem->uLUPTNLInformation_ToBeSetup_List);
12197             if(drbSetItem->uLConfiguration)
12198             {
12199                free(drbSetItem->uLConfiguration);
12200             }
12201          }
12202          if(drbSet->list.array[drbIdx]!=NULLP)
12203          {
12204             free(drbSet->list.array[drbIdx]);
12205          }
12206       }
12207       free(drbSet->list.array);
12208    }
12209 }
12210
12211
12212 /*******************************************************************
12213  *
12214  * @brief builds Mac Cell Cfg
12215  *
12216  * @details
12217  *
12218  *    Function : procUeReCfgCellInfo
12219  *
12220  *    Functionality: builds Mac Cell Cfg
12221  *
12222  * @params[in] MacUeCfg *macUeCfgToSend = Used to Store the information which
12223  *                       needs to send in other layer, as well as this can be
12224  *                       the variable which stores the information in DuCb.
12225  *             MacUeCfg *storedMacUeCfg = Null in case of sending the
12226  *                       information to other layer else it will have copyOfmacUeCfg  
12227  *                       which we have stored in F1UeContextSetupDb
12228  *             void *cellInfo = CellGroupConfigRrc_t information which is send
12229  *                        by CU, which we have stored in F1UeContextSetupDb 
12230  *
12231  * @return void 
12232  *
12233  * ****************************************************************/
12234 uint8_t procUeReCfgCellInfo(MacUeCfg *macUeCfgToSend, MacUeCfg *storedMacUeCfg, void *cellInfo)
12235 {
12236    uint8_t ret = ROK;
12237    CellGroupConfigRrc_t *cellGrp = NULLP;
12238
12239    if(cellInfo)
12240    {
12241       cellGrp = (CellGroupConfigRrc_t *)cellInfo;
12242       ret = extractUeReCfgCellInfo(cellGrp, macUeCfgToSend, storedMacUeCfg);
12243       if(ret == RFAILED)
12244          DU_LOG("\nERROR  -->  F1AP : Failed at procUeReCfgCellInfo()");
12245    }
12246    if(ret == RFAILED)
12247    {
12248       freeUeReCfgCellGrpInfo(macUeCfgToSend);
12249    }
12250    return ret;
12251 }
12252
12253 /*******************************************************************
12254  *
12255  * @brief Filling modulation info in mac ue cfg
12256  *
12257  * @details
12258  *
12259  *    Function : duFillModulationDetails
12260  *
12261  *    Functionality: Filling modulation info in mac ue cfg
12262  *
12263  * @params[in] MAC UE Config to be updated
12264  *             Current UE configuration
12265  *             UE NR capability from CU
12266  * @return ROK     - success
12267  *         RFAILED - failure
12268  *
12269  * ****************************************************************/
12270 void duFillModulationDetails(MacUeCfg *ueCfg, MacUeCfg *oldUeCfg, void *ueCap)
12271 {
12272    UE_NR_Capability_t *ueNrCap=NULLP;
12273
12274    if(!ueCap && oldUeCfg)
12275    {
12276       memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));     
12277       memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12278    }
12279    else
12280    {
12281       ueNrCap = (UE_NR_Capability_t *)ueCap;
12282
12283       /* Filling DL modulation info */
12284       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsDownlinkPerCC && \
12285          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0] && \
12286          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL)
12287       {
12288          switch(*(ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL))
12289          {
12290             case ModulationOrder_qpsk:
12291                {
12292                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
12293                   break;
12294                }
12295             case ModulationOrder_qam16:
12296                {
12297                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM16;
12298                   break;
12299                }
12300             case ModulationOrder_qam64:
12301                {
12302                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM64;
12303                   ueCfg->dlModInfo.mcsIndex = PDSCH_MCS_INDEX;
12304                   ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64;
12305                   break;
12306                }
12307             case ModulationOrder_qam256:
12308                {
12309                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM256;
12310                   break;
12311                }
12312             default:
12313                {
12314                   DU_LOG("\nERROR  -->  DU APP: Incorrect downlink modulation order received. Reatining old modulation configuration");
12315                   if(oldUeCfg)
12316                      memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
12317                   break;
12318                }
12319          }
12320       }
12321       else
12322       {
12323          if(oldUeCfg)
12324             memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
12325       }
12326
12327       /* Filling UL modulation info */
12328       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsUplinkPerCC && \
12329          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0] && \
12330          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL)
12331       {
12332          switch(*(ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL))
12333          {
12334             case ModulationOrder_qpsk:
12335                {
12336                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
12337                   break;
12338                }
12339             case ModulationOrder_qam16:
12340                {
12341                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM16;
12342                   ueCfg->ulModInfo.mcsIndex = PUSCH_MCS_INDEX;
12343                   ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64;
12344                   break;
12345                }
12346             case ModulationOrder_qam64:
12347                {
12348                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM64;
12349                   break;
12350                }
12351             case ModulationOrder_qam256:
12352                {
12353                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM256;
12354                   break;
12355                }
12356             default:
12357                {
12358                   DU_LOG("\nERROR  -->  DU APP: Incorrect uplink modulation order received. Reatining old modulation configuration");
12359                   if(oldUeCfg)
12360                      memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12361                   break;
12362                }
12363          }
12364       }
12365       else
12366       {
12367          if(oldUeCfg)
12368             memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12369       }
12370    }
12371 }
12372
12373 /*******************************************************************
12374  *
12375  * @brief Function to extract info from CU to DU RRC container extension
12376  *
12377  * @details
12378  *
12379  *    Function : extractCuToDuRrcInfoExt
12380  *
12381  *    Functionality: Function to extract info from CU to DU RRC container
12382  *    extension
12383  *
12384  * @params[in] ProtocolExtensionContainer_4624P16_t pointer
12385  *
12386  * @return ROK
12387  *         RFAILED
12388  *
12389  * ****************************************************************/
12390 uint8_t extractCuToDuRrcInfoExt(ProtocolExtensionContainer_4624P16_t *protocolIeExtn, DuUeCfg *ueCfgDb)
12391 {
12392    uint8_t ieIdx =0;
12393    uint16_t recvBufLen =0;
12394    CellGroupConfigRrc_t *cellGrpCfg = NULLP;
12395    CUtoDURRCInformation_ExtIEs_t *extIeInfo = NULLP;
12396    asn_dec_rval_t rval; /* Decoder return value */
12397    memset(&rval, 0, sizeof(asn_dec_rval_t));
12398
12399    if(protocolIeExtn)
12400    {
12401       for(ieIdx = 0; ieIdx < protocolIeExtn->list.count; ieIdx++)
12402       {
12403          extIeInfo = ((CUtoDURRCInformation_ExtIEs_t *)(protocolIeExtn->list.array[ieIdx]));
12404          switch(extIeInfo->id)
12405          {
12406             case ProtocolIE_ID_id_CellGroupConfig:
12407                {
12408                   /* decoding the CellGroup Buf received */
12409                   recvBufLen = extIeInfo->extensionValue.choice.CellGroupConfig.size;
12410                   DU_ALLOC(cellGrpCfg, sizeof(CellGroupConfigRrc_t));
12411                   if(cellGrpCfg)
12412                   {
12413                      memset(cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
12414                      rval = aper_decode(0, &asn_DEF_CellGroupConfigRrc, (void **)&cellGrpCfg,
12415                            extIeInfo->extensionValue.choice.CellGroupConfig.buf, recvBufLen, 0, 0);
12416                      if(rval.code == RC_FAIL || rval.code == RC_WMORE)
12417                      {
12418                         DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
12419                         return RFAILED;
12420                      }
12421                      xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, cellGrpCfg);
12422
12423                      if(extractRlcCfgToAddMod(cellGrpCfg->rlc_BearerToAddModList, ueCfgDb))
12424                         return NULLP;
12425                      ueCfgDb->cellGrpCfg = cellGrpCfg;
12426                   }
12427                   break;
12428                }
12429
12430             case ProtocolIE_ID_id_HandoverPreparationInformation:
12431                {
12432                   DU_LOG("\nINFO -->  F1AP : Received HANDOVER PREPARATION INFO in UE CONTEXT SETUP REQUEST");
12433                   break;
12434                }
12435
12436             default:
12437                DU_LOG("\nERROR  -->  F1AP : Invalid IE received CUtoDURRCInformation: %ld at decodeCellGrpCfg()", extIeInfo->id);
12438                break;
12439          }
12440       }
12441    }
12442    return ROK;
12443 }
12444
12445 /*******************************************************************
12446  *
12447  * @brief Fills Srb List received by CU
12448  *
12449  * @details
12450  *
12451  *    Function : procSrbListToSetup
12452  *
12453  *    Functionality: Fills Srb List received  by CU
12454  *
12455  * @params[in] SRBs_ToBeSetup_Item_t *cuSrbItem
12456  *             LcCfg pointer
12457  *             RlcBearerCfg pointer
12458  * @return void
12459  *
12460  * ****************************************************************/
12461 uint8_t procSrbListToSetup(SRBs_ToBeSetup_Item_t * srbItem, LcCfg *macLcToAdd, RlcBearerCfg *rlcLcToAdd)
12462 {
12463
12464    /* Filling RLC INFO */
12465    procRlcLcCfg(srbItem->sRBID, srbItem->sRBID, RB_TYPE_SRB, RLC_AM, CONFIG_ADD, NULL, rlcLcToAdd, NULL);
12466
12467    /* Filling MAC INFO */
12468    if(procMacLcCfg(srbItem->sRBID, RB_TYPE_SRB, CONFIG_ADD, NULL,NULL, NULL, NULL, macLcToAdd, NULL)  != ROK)
12469    { 
12470       DU_LOG("\nERROR  -->  F1AP : Failed at MAC LC Cfg in procSrbListToSetup()");
12471       return RFAILED;
12472    }
12473
12474    return ROK;
12475 }
12476
12477
12478
12479 /*******************************************************************
12480  *
12481  * @brief extract Srb List received by CU
12482  *
12483  * @details
12484  *
12485  *    Function : extractSrbListToSetup
12486  *
12487  *    Functionality: extract Srb List received by CU
12488  *                   for both MAC and RLC
12489  *
12490  * @params[in] SRBs_ToBeSetup_Item_t pointer
12491  *             DuUeCfg pointer
12492  * @return ROK/RFAIED
12493  *
12494  * ****************************************************************/
12495
12496 uint8_t extractSrbListToSetup(SRBs_ToBeSetup_List_t *srbCfg, DuUeCfg *ueCfgDb)
12497 {
12498    uint8_t ret = ROK, srbIdx = 0, rlcLcIdx = 0;
12499    SRBs_ToBeSetup_Item_t *srbItem = NULLP;
12500    LcCfg *macLcCtxt = NULLP;
12501    RlcBearerCfg *rlcLcCtxt = NULLP;
12502
12503    if(srbCfg)
12504    {
12505       for(srbIdx = 0; srbIdx < srbCfg->list.count; srbIdx++)
12506       {
12507          macLcCtxt = NULL;
12508          rlcLcCtxt = NULL;
12509
12510          srbItem = &srbCfg->list.array[srbIdx]->value.choice.SRBs_ToBeSetup_Item;
12511          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
12512          { 
12513             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in MAC");
12514             ret = RFAILED;
12515             break;
12516          }
12517          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
12518          {
12519             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in RLC");
12520             ret = RFAILED;
12521             break;
12522          }
12523
12524          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numMacLcs; rlcLcIdx++)
12525          {
12526             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rbId == srbItem->sRBID && ueCfgDb->rlcLcCfg[rlcLcIdx].rbType == RB_TYPE_SRB)
12527             {
12528                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
12529                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
12530                break;
12531             }
12532          }
12533          if(!macLcCtxt)
12534          {
12535             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(LcCfg));
12536             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
12537             ueCfgDb->numMacLcs++;
12538          }
12539          if(!rlcLcCtxt)
12540          {
12541             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
12542             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
12543             ueCfgDb->numRlcLcs++;
12544          }
12545
12546          ret = procSrbListToSetup(srbItem, macLcCtxt, rlcLcCtxt);
12547
12548          DU_LOG("\nDEBUG --> DUAPP: extractSrbListToSetup: SRBID: %ld [RLC,MAC,NumDrb]:[%x,%x,%x]",\
12549                srbItem->sRBID, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
12550          if(ret == RFAILED)
12551          {
12552             DU_LOG("\nERROR  -->  F1AP:  Failed at extractSrbListToSetup()");
12553             break;
12554          }
12555       }
12556    }
12557    else
12558       ret = RFAILED;
12559
12560    return ret;
12561 }
12562
12563 /*******************************************************************
12564  *
12565  * @brief Fills Drb List received by CU
12566  *
12567  * @details
12568  *
12569  *    Function : procDrbListToSetupMod
12570  *
12571  *    Functionality: Fills Drb List received by CU
12572  *                   for both MAC and RLC
12573  *
12574  * @params[in] DRBs_ToBeSetup_Item_t , DRBs_ToBeSetupMod_Item_t,
12575  *             DRBs_ToBeModified_Item_t , lcId, LcCfg pointer,
12576  *             RlcBearerCfg , UpTnlCfg, RlcUeCfg
12577  * @return void
12578  *
12579  * ****************************************************************/
12580
12581 uint8_t procDrbListToSetupMod(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbItem,\
12582 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LcCfg *macLcToAdd, RlcBearerCfg *rlcLcToAdd, UpTnlCfg *upTnlInfo, RlcUeCfg *storedRlcUeCfg)
12583 {
12584    uint8_t cfgIdx = 0;
12585    RlcMode rlcModeInfo;
12586
12587    if(drbItem != NULLP)
12588    {
12589       /* Filling RLC INFO */
12590       procRlcLcCfg(drbItem->dRBID, lcId, RB_TYPE_DRB, drbItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, &drbItem->\
12591       qoSInformation);
12592
12593       /* Filling MAC INFO */
12594       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, drbItem, NULL, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
12595       { 
12596          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
12597          return RFAILED;
12598       }
12599    }
12600    else if(drbSetupModItem != NULLP)
12601    {
12602       procRlcLcCfg(drbSetupModItem->dRBID, lcId, RB_TYPE_DRB, drbSetupModItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, 
12603       &drbSetupModItem->qoSInformation);
12604
12605       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, NULL, drbSetupModItem, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
12606       {
12607          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
12608          return RFAILED;
12609       }
12610    }
12611    else if(drbModItem != NULLP)
12612    {
12613       /* Drb to Mod IEs doesnot have rlcMode to be modified
12614        * in ASN. Hence no change in RLC configurations */
12615       if(storedRlcUeCfg != NULLP)
12616       {
12617          for(cfgIdx = 0; cfgIdx < storedRlcUeCfg->numLcs; cfgIdx++)
12618          {
12619             if(storedRlcUeCfg->rlcLcCfg[cfgIdx].lcId == lcId)
12620             {
12621                rlcModeInfo = storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcMode;
12622                break;
12623             }
12624          }
12625       }
12626
12627       procRlcLcCfg(drbModItem->dRBID, lcId, RB_TYPE_DRB, rlcModeInfo, CONFIG_MOD, NULL, rlcLcToAdd, drbModItem->qoSInformation);
12628       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_MOD, NULL, NULL, drbModItem, NULL, macLcToAdd, upTnlInfo) != ROK)
12629       {
12630          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
12631          return RFAILED;
12632       }
12633    }
12634    return ROK;
12635 }
12636
12637 /*******************************************************************
12638  *
12639  * @brief extract Drb List received by CU
12640  *
12641  * @details
12642  *
12643  *    Function : extractDrbListToSetupMod
12644  *
12645  *    Functionality: extract Drb List received by CU
12646  *                   for both MAC and RLC
12647  *
12648  * @params[in] DRBs_ToBeSetup_Item_t pointer
12649  *             DuUeCfg pointer
12650  * @return ROK/RFAIED
12651  *
12652  * ****************************************************************/
12653
12654 uint8_t extractDrbListToSetupMod(DRBs_ToBeSetup_List_t *drbCfg, DRBs_ToBeSetupMod_List_t *drbSetupModCfg,\
12655  DRBs_ToBeModified_List_t *drbModCfg, uint8_t drbCount, DuUeCfg *ueCfgDb, uint32_t *drbBitMap, RlcUeCfg *rlcUeCfg)
12656 {
12657    uint8_t ret = ROK;
12658    uint8_t drbIdx = 0, rlcLcIdx = 0;
12659    uint8_t drbId = 0, lcId = 0;
12660    DRBs_ToBeSetup_Item_t *drbItem = NULLP;
12661    DRBs_ToBeSetupMod_ItemIEs_t *drbSetupModItem = NULLP;
12662    DRBs_ToBeModified_ItemIEs_t *drbModItem = NULLP;
12663    LcCfg *macLcCtxt = NULLP;
12664    RlcBearerCfg *rlcLcCtxt = NULLP;
12665
12666    ret = ROK;
12667    if(drbCount > 0)
12668    {
12669       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
12670       {
12671          macLcCtxt = NULL;
12672          rlcLcCtxt = NULL;
12673
12674          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
12675          { 
12676             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in MAC at extractDrbListToSetupMod()");
12677             ret = RFAILED;
12678             break;
12679          }
12680          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
12681          {
12682             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in RLC at extractDrbListToSetupMod()");
12683             ret = RFAILED;
12684             break;
12685          }
12686
12687          if(drbModCfg != NULLP)
12688          {
12689             drbModItem = (DRBs_ToBeModified_ItemIEs_t *) drbModCfg->list.array[drbIdx];
12690             drbId = drbModItem->value.choice.DRBs_ToBeModified_Item.dRBID;
12691          }
12692          else if(drbCfg != NULLP)
12693             drbId = drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item.dRBID;
12694          else if(drbSetupModCfg != NULL)
12695          {
12696             drbSetupModItem = (DRBs_ToBeSetupMod_ItemIEs_t *) drbSetupModCfg->list.array[drbIdx];
12697             drbId = drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item.dRBID;
12698          }
12699
12700          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
12701          {
12702             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rbId == drbId && ueCfgDb->rlcLcCfg[rlcLcIdx].rbType == RB_TYPE_DRB)
12703             {
12704                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
12705                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
12706                break;
12707             }
12708          }
12709          if(!macLcCtxt)
12710          {
12711             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(LcCfg));
12712             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
12713             ueCfgDb->numMacLcs++;
12714          }
12715          if(!rlcLcCtxt)
12716          {
12717             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
12718             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
12719             ueCfgDb->numRlcLcs++;
12720          }
12721
12722          if(drbModCfg != NULLP)
12723          {
12724             lcId = fetchLcId(drbId);
12725             if(lcId < MIN_DRB_LCID)
12726             {
12727                DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToSetupMod() for Modified List", lcId);
12728                break;
12729             } 
12730             ret = procDrbListToSetupMod(lcId, NULL, NULL, &(drbModItem->value.choice.DRBs_ToBeModified_Item),\
12731             macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
12732             if(ret == RFAILED)
12733             {
12734                DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for Modified List");
12735                break;
12736             }
12737          }
12738          else
12739          {
12740             lcId = getDrbLcId(drbBitMap);
12741             if(lcId == RFAILED)
12742             {
12743                DU_LOG("\nERROR  -->  F1AP :  InCorrect LCID extractDrbListToSetupMod()");
12744                ret = RFAILED;
12745                break;
12746             }
12747             if(drbCfg != NULL)
12748             {
12749                drbItem = &drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12750                ret = procDrbListToSetupMod(lcId, drbItem, NULL, NULL, macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
12751                if(ret == RFAILED)
12752                {
12753                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetup List");
12754                   break;
12755                }
12756             }
12757             else if(drbSetupModCfg != NULL)
12758             {
12759                ret = procDrbListToSetupMod(lcId, NULL, &(drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item), NULL,\
12760                      macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
12761                if(ret == RFAILED)
12762                {
12763                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetupMod List");
12764                   break;
12765                }
12766                ueCfgDb->numDrbSetupMod++;
12767             }
12768          }
12769          ueCfgDb->numDrb++;
12770  
12771          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToSetupMod:lcId:%x ,BitMap:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
12772                             lcId,*drbBitMap, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
12773          if(ret == RFAILED)
12774          {
12775             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod()");
12776             break;
12777          }
12778       }
12779    }
12780    else
12781       ret = RFAILED;
12782
12783    return ret;
12784 }
12785
12786 /*******************************************************************
12787  *
12788  * @brief Function to extract Dl RRC Msg received from CU
12789  *
12790  * @details
12791  *
12792  *    Function : extractDlRrcMsg
12793  *
12794  *    Functionality: Function to extract Dl RRC Msg received from CU
12795  *
12796  * @params[in] F1AP message
12797  * @return ROK     - success
12798  *         RFAILED - failure
12799  *
12800  * ****************************************************************/
12801
12802 uint8_t extractDlRrcMsg(uint32_t gnbDuUeF1apId, uint32_t gnbCuUeF1apId, \
12803    F1DlRrcMsg *dlRrcMsg, RRCContainer_t *rrcContainer)
12804 {
12805    uint8_t ret = ROK;
12806    dlRrcMsg->rrcMsgSize = rrcContainer->size;
12807    if(dlRrcMsg->rrcMsgSize > 0)
12808    {
12809       DU_ALLOC_SHRABL_BUF(dlRrcMsg->rrcMsgPdu, dlRrcMsg->rrcMsgSize);
12810       if(!dlRrcMsg->rrcMsgPdu)
12811       {
12812          DU_LOG("\nERROR  --> DU APP : Memory allocation failed for RRC Msg in extractDlRrcMsg()");
12813          ret = RFAILED;
12814       }
12815       else
12816       {
12817          dlRrcMsg->gnbDuUeF1apId = gnbDuUeF1apId;
12818          dlRrcMsg->gnbCuUeF1apId = gnbCuUeF1apId;
12819          dlRrcMsg->srbId = SRB1_LCID;
12820          memcpy(dlRrcMsg->rrcMsgPdu, rrcContainer->buf, dlRrcMsg->rrcMsgSize);
12821       }
12822    }
12823    return ret;
12824 }
12825
12826 /*******************************************************************
12827  *
12828  * @brief Extract UE capability info 
12829  *
12830  * @details
12831  *
12832  *    Function : extractUeCapability
12833  *
12834  *    Functionality: Extract UE capability info and stores in ue Cb
12835  *
12836  * @params[in] Octet string of UE capability RAT container list
12837  * @return ROK     - success
12838  *         RFAILED - failure
12839  *
12840  * ****************************************************************/
12841 UE_NR_Capability_t *extractUeCapability(UE_CapabilityRAT_ContainerList_t *ueCapablityListBuf, DuUeCb *ueCb)
12842 {
12843    uint8_t  idx;
12844    uint16_t recvBufLen;
12845    asn_dec_rval_t rval;
12846    UE_NR_Capability_t  *ueNrCap = NULLP;
12847    UE_CapabilityRAT_ContainerListRRC_t  *ueCapRatContList = NULLP;
12848
12849    /* Decoding UE Capability RAT Container List */
12850    recvBufLen = ueCapablityListBuf->size;
12851    DU_ALLOC(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
12852    if(!ueCapRatContList)
12853    {
12854       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
12855       return NULLP;
12856    }
12857    memset(ueCapRatContList, 0, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
12858    memset(&rval, 0, sizeof(asn_dec_rval_t));
12859    rval = aper_decode(0, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, (void **)&ueCapRatContList,
12860           ueCapablityListBuf->buf, recvBufLen, 0, 0);
12861    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
12862    {
12863       DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
12864       return NULLP;
12865    }
12866    xer_fprint(stdout, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, ueCapRatContList);
12867
12868    /* Free encoded buffer after decoding */
12869
12870    for(idx = 0; idx < ueCapRatContList->list.count; idx++)
12871    {
12872       if(ueCapRatContList->list.array[idx]->rat_Type == RAT_Type_nr)
12873       {
12874          /* Decoding UE NR Capability */
12875           recvBufLen = ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.size;
12876           DU_ALLOC(ueNrCap, sizeof(UE_NR_Capability_t));
12877           if(!ueNrCap)
12878           {
12879              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
12880              DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
12881              return NULLP;
12882           } 
12883           memset(ueNrCap, 0, sizeof(UE_NR_Capability_t));
12884           memset(&rval, 0, sizeof(asn_dec_rval_t));
12885           rval = aper_decode(0, &asn_DEF_UE_NR_Capability, (void **)&ueNrCap,
12886                  ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf, recvBufLen, 0, 0);
12887           if(rval.code == RC_FAIL || rval.code == RC_WMORE)
12888           {
12889              DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
12890              return NULLP;
12891           }
12892           xer_fprint(stdout, &asn_DEF_UE_NR_Capability, ueNrCap);
12893           
12894           /* Free encoded buffer after decoding */
12895           free(ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf);
12896       }
12897       free(ueCapRatContList->list.array[idx]);
12898    }
12899
12900    /* Free Memory*/
12901    free(ueCapRatContList->list.array);
12902    DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
12903    return ueNrCap;
12904 }
12905  
12906 /*******************************************************************
12907 *
12908 * @brief free UE context setup request from CU
12909 *
12910 * @details
12911 *
12912 *    Function : freeAperDecodeF1UeContextSetupReq
12913 *
12914 *    Functionality: freeing part for the memory allocated by aper_decoder
12915 *
12916 * @params[in] F1AP message
12917 * @return ROK     - success
12918 *         RFAILED - failure
12919 *
12920 * ****************************************************************/
12921 void freeAperDecodeF1UeContextSetupReq(UEContextSetupRequest_t   *ueSetReq)
12922 {
12923    uint8_t ieIdx = 0;
12924
12925    if(ueSetReq->protocolIEs.list.array != NULLP)
12926    {
12927       for(ieIdx = 0; ieIdx < ueSetReq->protocolIEs.list.count; ieIdx++)
12928       {
12929          if(ueSetReq->protocolIEs.list.array[ieIdx])
12930          {
12931             switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
12932             {
12933                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
12934                   break;
12935                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
12936                   break;
12937                case ProtocolIE_ID_id_SpCell_ID:
12938                   freeAperDecodeNrcgi(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
12939                   break;
12940                case ProtocolIE_ID_id_ServCellIndex:
12941                   break;
12942                case ProtocolIE_ID_id_SpCellULConfigured:
12943                   break;
12944                case ProtocolIE_ID_id_CUtoDURRCInformation:
12945
12946                   freeAperDecodeCuToDuInfo(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation);
12947                   break;
12948                case ProtocolIE_ID_id_SCell_ToBeSetup_List:
12949
12950                   freeAperDecodeSplCellList(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SCell_ToBeSetup_List);
12951                   break;
12952                case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
12953
12954                   freeAperDecodeSRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List);
12955                   break;
12956                case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
12957
12958                   freeAperDecodeDRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List);
12959                   break;
12960                case ProtocolIE_ID_id_RRCContainer:
12961                   {
12962
12963                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf != NULLP)
12964                      {
12965
12966                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
12967                      }
12968                      break;
12969                   }
12970                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
12971                   break;
12972                case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
12973                   {
12974                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf)
12975                      {
12976                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf);
12977                      }
12978                      break;
12979                   }
12980                default:
12981                   DU_LOG("\nERROR  -->  F1AP: Invalid event type %ld " ,ueSetReq->protocolIEs.list.array[ieIdx]->id);
12982             } 
12983             free(ueSetReq->protocolIEs.list.array[ieIdx]);
12984          }
12985       }
12986       free(ueSetReq->protocolIEs.list.array);
12987    }
12988 }
12989 /*******************************************************************
12990  *
12991  * @brief Process UE context setup request from CU
12992  *
12993  * @details
12994  *
12995  *    Function : procF1UeContextSetupReq
12996  *
12997  *    Functionality: Process UE context setup request from CU
12998  *
12999  * @params[in] F1AP message
13000  * @return ROK     - success
13001  *         RFAILED - failure
13002  *
13003  * ****************************************************************/
13004 uint8_t procF1UeContextSetupReq(F1AP_PDU_t *f1apMsg)
13005 {
13006    int8_t ueIdx = -1;
13007    uint8_t  ret=0, ieIdx=0, ieExtIdx = 0, servCellIdx = 0;
13008    bool ueCbFound = false, hoInProgress = false;
13009    uint16_t cellIdx=0;
13010    uint64_t nrCellId = 0;
13011    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0, bitRateSize=0;
13012    DuUeCb   *duUeCb = NULL;
13013    UEContextSetupRequest_t   *ueSetReq = NULL;
13014    DRBs_ToBeSetup_List_t *drbCfg = NULL;
13015    CUtoDURRCInformation_t *rrcInfo = NULL;
13016
13017    ret = ROK;
13018
13019    ueSetReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextSetupRequest;
13020    for(ieIdx=0; (ieIdx < ueSetReq->protocolIEs.list.count && ret == ROK); ieIdx++)
13021    {
13022       switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13023       {
13024          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13025             {
13026                gnbCuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
13027                break;
13028             }
13029
13030          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13031             {
13032                gnbDuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
13033                break;
13034             }
13035
13036          case ProtocolIE_ID_id_SpCell_ID:
13037             {
13038                bitStringToInt(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity, &nrCellId);
13039
13040                GET_CELL_IDX(nrCellId, cellIdx);
13041                if(!duCb.actvCellLst[cellIdx])
13042                {
13043                   DU_LOG("\nERROR  -->  F1AP : Cell Id [%d] not found", nrCellId);
13044                   ret = RFAILED;
13045                }
13046                break;
13047             }
13048
13049          case ProtocolIE_ID_id_ServCellIndex:
13050             {
13051                servCellIdx = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.ServCellIndex;
13052                break;
13053             }
13054
13055          case ProtocolIE_ID_id_SpCellULConfigured:
13056             {
13057                /* Indicates whether the gNB-CU requests the gNB-DU to configure the uplink as no UL, 
13058                   UL, SUL or UL+SUL for the indicated cell for the UE */
13059                break;
13060             }
13061
13062          case ProtocolIE_ID_id_CUtoDURRCInformation:
13063             {
13064                rrcInfo = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation;
13065
13066                /* Search if UE context is present */
13067                for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
13068                {
13069                   if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId)
13070                   {
13071                      ueCbFound = true;
13072                      duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13073                      break;
13074                   }
13075                }
13076
13077                /* Check if UE Handover scenario */
13078                if(rrcInfo->iE_Extensions)
13079                {
13080                   for(ieExtIdx = 0; ieExtIdx < rrcInfo->iE_Extensions->list.count; ieExtIdx++)
13081                   {
13082                      if(rrcInfo->iE_Extensions->list.array[ieExtIdx]->id == ProtocolIE_ID_id_HandoverPreparationInformation)
13083                      {
13084                         hoInProgress = true;
13085                         break;
13086                      }
13087                   }
13088                }
13089                
13090                /* If UE context is not present, but UE is in handover */
13091                if(!ueCbFound && hoInProgress)
13092                {
13093                   ueIdx = getFreeBitFromUeBitMap(nrCellId);
13094                   if(ueIdx != -1)
13095                      gnbDuUeF1apId = ueIdx +1;
13096                   else
13097                   {
13098                      DU_LOG("\nERROR  -->  F1AP : No free UE IDX found in UE bit map of cell Id [%d]", nrCellId);
13099                      ret = RFAILED;
13100                      break;
13101                   }
13102                   duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13103                   duUeCb->f1UeDb = NULL;
13104                   duUeCb->gnbCuUeF1apId = gnbCuUeF1apId;
13105                   duUeCb->gnbDuUeF1apId = gnbDuUeF1apId;
13106                   GET_CRNTI(duUeCb->crnti, duUeCb->gnbDuUeF1apId);
13107                   duUeCb->ueState = UE_HANDIN_IN_PROGRESS;
13108                }
13109
13110                if(duUeCb)
13111                {
13112                   DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
13113                   if(duUeCb->f1UeDb)
13114                   {
13115                      memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
13116                      duUeCb->f1UeDb->actionType = UE_CTXT_SETUP;
13117                      duUeCb->f1UeDb->cellIdx = cellIdx;
13118                   }
13119                   else
13120                   {
13121                      DU_LOG("\nERROR  -->  F1AP: Memory Alloc Failed at procF1UeContextSetupReq()");
13122                      ret = RFAILED;
13123                      break;
13124                   }
13125                }
13126                else
13127                {
13128                   DU_LOG("\nERROR  -->  F1AP: DuUeCb is not found at procF1UeContextSetupReq()");
13129                   ret = RFAILED;
13130                   break;
13131                }
13132                  
13133                /* Extract UE capability info */
13134                if(rrcInfo->uE_CapabilityRAT_ContainerList)
13135                {
13136                   duUeCb->f1UeDb->duUeCfg.ueNrCapability = extractUeCapability(rrcInfo->uE_CapabilityRAT_ContainerList, duUeCb);
13137                }
13138
13139                /* Extract IE extension */
13140                if(rrcInfo->iE_Extensions)
13141                {
13142                   if(extractCuToDuRrcInfoExt(rrcInfo->iE_Extensions, &duUeCb->f1UeDb->duUeCfg) != ROK)
13143                   {
13144                      DU_LOG("\nERROR  -->  F1AP: Failed to extract CU to DU RRC information extension IE");
13145                      //TODO: Update the failure cause in ue context Setup Response
13146                      ret = RFAILED;
13147                   }
13148                }
13149                break;
13150             } 
13151
13152          case ProtocolIE_ID_id_SCell_ToBeSetup_List:
13153             {
13154                DU_LOG("\nINFO   -->  DU_APP: Received SCell_ToBeSetup_List but  Not processing the list");
13155                break;
13156             }
13157
13158          case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
13159             {
13160                if(extractSrbListToSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List,\
13161                         &duUeCb->f1UeDb->duUeCfg))
13162                {
13163                   DU_LOG("\nERROR  -->  DU APP : Failed at extractSrbListToSetup()");
13164                   //TODO: Update the failure cause in ue context Setup Response
13165                   ret = RFAILED;
13166                }
13167                break;
13168             }
13169
13170          case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
13171             {
13172                drbCfg = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List;
13173
13174                if(extractDrbListToSetupMod(drbCfg, NULL, NULL, drbCfg->list.count, &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULLP))
13175                {
13176                   DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod()");
13177                   //TODO: Update the failure cause in ue context Setup Response
13178                   ret = RFAILED;
13179                }
13180                break;
13181             }
13182
13183          case ProtocolIE_ID_id_RRCContainer:
13184             {
13185                /* Filling Dl RRC Msg Info */
13186                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
13187                if(!duUeCb->f1UeDb->dlRrcMsg)
13188                {
13189                   DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for DL RRC Msg in procUeCtxtSetupReq()");
13190                   ret = RFAILED;
13191                }
13192                else
13193                {
13194                   duUeCb->f1UeDb->dlRrcMsgPres = true;
13195                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
13196                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
13197                         &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer);
13198                }          
13199                break;
13200             }
13201
13202          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13203             {
13204                if(duUeCb->f1UeDb->dlRrcMsg)
13205                {
13206                   if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
13207                   {
13208                      duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
13209                   }
13210                   else
13211                   {
13212                      DU_LOG("\nERROR  -->  Ignoring delivery report, since rrcContainer is not present");
13213                   }
13214                }
13215                break;
13216             }
13217
13218          case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
13219             {
13220                /* MaximumBitRate Uplink */
13221                bitRateSize = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.size;
13222                if(bitRateSize > 0)
13223                {
13224                   DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->duUeCfg.ambrCfg, bitRateSize);
13225                   if(!duUeCb->f1UeDb->duUeCfg.ambrCfg)
13226                   {
13227                      DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for bitRate in procUeCtxtSetupReq");
13228                      ret = RFAILED;
13229                   }
13230                   else
13231                   {
13232                      memset(duUeCb->f1UeDb->duUeCfg.ambrCfg, 0, sizeof(AmbrCfg)); 
13233                      memcpy(&duUeCb->f1UeDb->duUeCfg.ambrCfg->ulBr,
13234                            ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf, bitRateSize);
13235                   }
13236                }
13237                else
13238                   ret = RFAILED;
13239                break;
13240             }
13241
13242          default:
13243             {
13244                break;
13245             }
13246       } /* End of switch */
13247
13248       /* In case of any failure in any IE */
13249       if(ret == RFAILED)
13250       {
13251          // BuildAndSendUeContextSetupRsp(cellId,ueId);
13252          DU_LOG("\nERROR  -->  F1AP: Failed to process UE CNTXT SETUP REQ at procF1UeContextSetupReq()"); 
13253          break;
13254       }
13255    } /* End of for loop of IEs */
13256
13257    if(ret == ROK)
13258       ret = duProcUeContextSetupRequest(duUeCb);
13259
13260    freeAperDecodeF1UeContextSetupReq(ueSetReq); 
13261    return ret;
13262
13263 }
13264 /*******************************************************************
13265  * @brief Free the memory allocated for Dl Tunnel Info
13266  *
13267  * @details
13268  *
13269  *    Function : freeDlTnlInfo
13270  *
13271  *    Functionality:
13272  *       Free the memory allocated for Dl Tunnel Info
13273  *
13274  * @params[in] DLUPTNLInformation_ToBeSetup_List_t *
13275  * @return void
13276  *
13277  * ****************************************************************/
13278
13279 void freeDlTnlInfo(DLUPTNLInformation_ToBeSetup_List_t *tnlInfo)
13280 {
13281    uint8_t arrIdx = 0;
13282
13283    if(tnlInfo)
13284    {
13285       for(arrIdx=0; arrIdx < tnlInfo->list.count; arrIdx++)
13286       {
13287          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf,\
13288                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.size);
13289          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf,\
13290                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.size);
13291          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
13292          DU_FREE(tnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
13293       }
13294       DU_FREE(tnlInfo->list.array, tnlInfo->list.size);
13295    }
13296 }
13297
13298 /*******************************************************************
13299  * @brief Free the memory allocated for DRB setup List
13300  *
13301  * @details
13302  *
13303  *    Function : freeDrbSetupList
13304  *
13305  *    Functionality:
13306  *       Free the memory allocated for DRB setup list
13307  *
13308  * @params[in] DRBs_Setup_List_t *
13309  * @return void
13310  *
13311  * ****************************************************************/
13312 void freeDrbSetupList(DRBs_Setup_List_t *drbSetupList)
13313 {
13314    uint8_t arrIdx = 0;
13315    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
13316
13317    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
13318    {
13319       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
13320       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List);
13321       DU_FREE(drbSetupList->list.array[arrIdx],  sizeof(DRBs_Setup_Item_t));
13322    }
13323    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
13324 }
13325
13326 /*******************************************************************
13327  * @brief Free the memory allocated for UE Setup response
13328  *
13329  * @details
13330  *
13331  *    Function : FreeUeContextSetupRsp
13332  *
13333  *    Functionality:
13334  *       Free the memory allocated for UE Setup response
13335  *
13336  * @params[in] F1AP PDU for UE setup response
13337  * @return ROK     - success
13338  *         RFAILED - failure
13339  *
13340  * ****************************************************************/
13341 void FreeUeContextSetupRsp(F1AP_PDU_t *f1apMsg)
13342 {
13343    uint8_t idx;
13344    UEContextSetupResponse_t *ueSetRsp = NULLP;
13345
13346    if(f1apMsg)
13347    {
13348       if(f1apMsg->choice.successfulOutcome)
13349       {
13350          ueSetRsp = &f1apMsg->choice.successfulOutcome->value.choice.\
13351                     UEContextSetupResponse;
13352          if(ueSetRsp->protocolIEs.list.array)
13353          {
13354             for(idx = 0; idx < ueSetRsp->protocolIEs.list.count; idx++)
13355             {
13356                if(ueSetRsp->protocolIEs.list.array[idx])
13357                {
13358                   switch(ueSetRsp->protocolIEs.list.array[idx]->id)
13359                   {
13360                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13361                         break;
13362                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13363                         break;
13364                      case ProtocolIE_ID_id_DUtoCURRCInformation:
13365                         {
13366                            CellGroupConfig_t *cellGrpCfg = NULLP;
13367                            cellGrpCfg  = &ueSetRsp->protocolIEs.list.array[idx]->value.choice.\
13368                                          DUtoCURRCInformation.cellGroupConfig;
13369                            if(cellGrpCfg->buf != NULLP)
13370                            {
13371                               DU_FREE(cellGrpCfg->buf, cellGrpCfg->size);
13372                               cellGrpCfg = NULLP;
13373                            }
13374                            break;
13375                         }
13376                     case ProtocolIE_ID_id_DRBs_Setup_List:
13377                         {
13378                            freeDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List); 
13379                            break;
13380                         }
13381                      default:
13382                         DU_LOG("\nERROR  -->  DUAPP: Invalid Id %ld at FreeUeContextSetupRsp()",\
13383                         ueSetRsp->protocolIEs.list.array[idx]->id);
13384                         break;
13385                   }
13386                   DU_FREE(ueSetRsp->protocolIEs.list.array[idx],\
13387                         sizeof(UEContextSetupResponseIEs_t));
13388                }
13389             }
13390             DU_FREE(ueSetRsp->protocolIEs.list.array, \
13391                   ueSetRsp->protocolIEs.list.size);
13392          }
13393          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
13394       }
13395       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
13396    }
13397 }
13398
13399 /*******************************************************************
13400  *
13401  * @brief Builds Ue context Setup Rsp DU To CU Info
13402  *
13403  * @details
13404  *
13405  *    Function : EncodeUeCntxtDuToCuInfo
13406  *
13407  *    Functionality: Builds Ue context Setup Rsp DU To CU Info
13408  *
13409  * @params[in] CellGroupConfig_t *, CellGroupConfigRrc_t * 
13410  *
13411  * @return ROK     - success
13412  *         RFAILED - failure
13413  *
13414  ******************************************************************/
13415
13416 uint8_t EncodeUeCntxtDuToCuInfo(CellGroupConfig_t *duToCuCellGrp, CellGroupConfigRrc_t *duCellGrpCfg)
13417 {
13418    asn_enc_rval_t        encRetVal;
13419
13420    xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, duCellGrpCfg);
13421    memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
13422    encBufSize = 0;
13423    encRetVal = aper_encode(&asn_DEF_CellGroupConfigRrc, 0, duCellGrpCfg, PrepFinalEncBuf, encBuf);
13424    /* Encode results */
13425    if(encRetVal.encoded == ENCODE_FAIL)
13426    {
13427       DU_LOG( "\nERROR  -->  F1AP : Could not encode UeCntxtDuToCuInfo (at %s)\n",\
13428             encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
13429       return RFAILED;
13430    }
13431    else
13432    {
13433       DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UeCntxtDuToCuInfo\n");
13434       for(int i=0; i< encBufSize; i++)
13435       {
13436          printf("%x",encBuf[i]);
13437       }
13438    }
13439    duToCuCellGrp->size = encBufSize;
13440    DU_ALLOC(duToCuCellGrp->buf, duToCuCellGrp->size);
13441    if(!duToCuCellGrp->buf)
13442    {
13443       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in UeCntxtDuToCuInfo");
13444    }
13445    memcpy(duToCuCellGrp->buf, encBuf, duToCuCellGrp->size);
13446    return ROK;
13447 }
13448
13449 /*******************************************************************
13450  *
13451  * @brief Fills Dl Gtp tunnel Info
13452  *
13453  * @details
13454  *
13455  *    Function : fillGtpTunnelforDl
13456  *
13457  *    Functionality: Fills Dl Gtp tunnel Info
13458  *
13459  * @params[in] 
13460  *
13461  * @return ROK     - success
13462  *         RFAILED - failure
13463  *
13464  * ****************************************************************/
13465
13466 uint8_t fillGtpTunnelforDl(GTPTunnel_t *gtpDl, GtpTnlCfg *gtpUeCfg)
13467 {
13468    uint8_t bufSize = 0;
13469
13470    gtpDl->transportLayerAddress.size    = 4*sizeof(uint8_t);
13471    DU_ALLOC(gtpDl->transportLayerAddress.buf, gtpDl->transportLayerAddress.size);
13472    if(gtpDl->transportLayerAddress.buf == NULLP)
13473    {
13474       return RFAILED;
13475    }
13476    memcpy(gtpDl->transportLayerAddress.buf, &gtpUeCfg->dlTnlAddress, gtpDl->transportLayerAddress.size);
13477
13478    /*GTP TEID*/
13479    gtpDl->gTP_TEID.size = 4 * sizeof(uint8_t);
13480    DU_ALLOC(gtpDl->gTP_TEID.buf, gtpDl->gTP_TEID.size);
13481    if(gtpDl->gTP_TEID.buf == NULLP)
13482    {
13483       return RFAILED;
13484    }
13485    bufSize = 3; /*forming an Octect String*/
13486    fillTeIdString(bufSize, gtpUeCfg->teId, gtpDl->gTP_TEID.buf);
13487
13488    return ROK;
13489 }
13490
13491 /*******************************************************************
13492  *
13493  * @brief Fills DL Tunnel Setup List
13494  *
13495  * @details
13496  *
13497  *    Function : fillDlTnlSetupList
13498  *
13499  *    Functionality: Fills the DL Tunnel Setup List
13500  *
13501  * @params[in] 
13502  *
13503  * @return ROK     - success
13504  *         RFAILED - failure
13505  *
13506  * ****************************************************************/
13507
13508 uint8_t fillDlTnlSetupList(DLUPTNLInformation_ToBeSetup_List_t *dlTnlInfo, UpTnlCfg *tnlCfg)
13509 {
13510    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
13511
13512    eleCount = 1;
13513    dlTnlInfo->list.count = eleCount; 
13514    dlTnlInfo->list.size = (eleCount * sizeof(DLUPTNLInformation_ToBeSetup_Item_t *));
13515
13516    /* Initialize the DL Tnl Setup List Members */
13517    DU_ALLOC(dlTnlInfo->list.array, dlTnlInfo->list.size);
13518    if(dlTnlInfo->list.array == NULLP)
13519    {
13520       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL Tnl Setup List in fillDlTnlSetupList()");
13521       ret = RFAILED;
13522    }
13523    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
13524    {
13525       DU_ALLOC(dlTnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
13526       if(dlTnlInfo->list.array[arrIdx] == NULLP)
13527       {
13528          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDlTnlSetupList()", arrIdx);
13529          return RFAILED;
13530       }
13531       dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.present = UPTransportLayerInformation_PR_gTPTunnel;
13532       DU_ALLOC(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
13533       if(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel == NULLP)
13534       {
13535          DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL tunnel info in fillDlTnlSetupList()");
13536          return RFAILED;
13537       }
13538       ret = fillGtpTunnelforDl(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel,\
13539                tnlCfg->tnlCfg1);
13540       if(ret != ROK)
13541          break;
13542    }
13543    return ret;
13544 }
13545
13546 /*******************************************************************
13547  *
13548  * @brief Fills the Drb Setup List for Ue Context Setup Response
13549  *
13550  * @details
13551  *
13552  *    Function : fillDrbSetupList
13553  *
13554  *    Functionality: Fills the Drb Setup List for Ue Context Setup Response
13555  *
13556  * @params[in] 
13557  *
13558  * @return ROK     - success
13559  *         RFAILED - failure
13560  *
13561  * ****************************************************************/
13562 uint8_t fillDrbSetupList(DRBs_Setup_List_t *drbSetupList, DuUeCfg *ueCfg)
13563 {
13564    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
13565    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
13566
13567    eleCount = ueCfg->numDrb;
13568    drbSetupList->list.count = eleCount;
13569    drbSetupList->list.size = \
13570         (eleCount * sizeof(DRBs_Setup_Item_t *));
13571
13572    /* Initialize the Drb Setup List Members */
13573    DU_ALLOC(drbSetupList->list.array, drbSetupList->list.size);
13574    if(drbSetupList->list.array == NULLP)
13575    {
13576       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DRB Setup List in fillDrbSetupList()");
13577       ret = RFAILED;
13578    }
13579
13580    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
13581    {
13582       DU_ALLOC(drbSetupList->list.array[arrIdx], sizeof(DRBs_Setup_Item_t));
13583       if(drbSetupList->list.array[arrIdx] == NULLP)
13584       {
13585          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDrbSetupList()", arrIdx);
13586          return RFAILED;
13587       }
13588       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
13589       drbItemIe->id = ProtocolIE_ID_id_DRBs_Setup_Item;
13590       drbItemIe->criticality = Criticality_reject;
13591       drbItemIe->value.present = DRBs_Setup_ItemIEs__value_PR_DRBs_Setup_Item;
13592       drbItemIe->value.choice.DRBs_Setup_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
13593       ret = fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List,\
13594           &ueCfg->upTnlInfo[arrIdx]);
13595       if(ret != ROK)
13596          break;
13597    }
13598    return ret;
13599 }
13600
13601 /*******************************************************************
13602  *
13603  * @brief Builds and sends the UE Setup Response
13604  *
13605  * @details
13606  *
13607  *    Function : BuildAndSendUeContextSetupRsp
13608  *
13609  *    Functionality: Constructs the UE Setup Response and sends
13610  *                   it to the DU through SCTP.
13611  *
13612  * @params[in] uint8_t cellId,uint8_t ueId
13613  *
13614  * @return ROK     - success
13615  *         RFAILED - failure
13616  *
13617  * ****************************************************************/
13618 uint8_t BuildAndSendUeContextSetupRsp(uint8_t cellId,uint8_t ueId)
13619 {
13620    uint8_t   idx, ret, cellIdx, elementCnt;
13621    uint32_t  gnbCuUeF1apId;   /* gNB-CU UE F1AP Id */
13622    uint32_t  gnbDuUeF1apId;   /* gNB-DU UE F1AP Id */
13623    asn_enc_rval_t  encRetVal;        /* Encoder return value */
13624    F1AP_PDU_t               *f1apMsg = NULLP;
13625    UEContextSetupResponse_t *ueSetRsp = NULLP;
13626    DuUeCb                   *ueCb = NULLP;
13627
13628    DU_LOG("\n INFO   -->  F1AP : Building UE Context Setup Response for cellId %d, ueId %d\n", cellId, ueId);
13629
13630    while(true)
13631    {
13632       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
13633       if(f1apMsg == NULLP)
13634       {
13635          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
13636          ret = RFAILED;
13637          break;
13638       }
13639
13640       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
13641       DU_ALLOC(f1apMsg->choice.successfulOutcome,
13642             sizeof(SuccessfulOutcome_t));
13643       if(f1apMsg->choice.successfulOutcome == NULLP)
13644       {
13645          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
13646          ret = RFAILED;
13647          break;
13648       }
13649
13650       f1apMsg->choice.successfulOutcome->procedureCode = \
13651                                                          ProcedureCode_id_UEContextSetup;
13652       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
13653       f1apMsg->choice.successfulOutcome->value.present = \
13654                                                          SuccessfulOutcome__value_PR_UEContextSetupResponse;
13655
13656       ueSetRsp =
13657          &f1apMsg->choice.successfulOutcome->value.choice.UEContextSetupResponse;
13658       elementCnt = 5;
13659       ueSetRsp->protocolIEs.list.count = elementCnt;
13660       ueSetRsp->protocolIEs.list.size = \
13661                                         elementCnt * sizeof(UEContextSetupResponse_t *);
13662
13663       /* Initialize the UESetup members */
13664       DU_ALLOC(ueSetRsp->protocolIEs.list.array, \
13665             ueSetRsp->protocolIEs.list.size);
13666       if(ueSetRsp->protocolIEs.list.array == NULLP)
13667       {
13668          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
13669          ret = RFAILED;
13670          break;
13671       }
13672
13673       for(idx=0; idx<elementCnt; idx++)
13674       {
13675          DU_ALLOC(ueSetRsp->protocolIEs.list.array[idx],\
13676                sizeof(UEContextSetupResponseIEs_t));
13677          if(ueSetRsp->protocolIEs.list.array[idx] == NULLP)
13678          {
13679             DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
13680             ret = RFAILED;
13681             break;
13682          }
13683       }
13684       /* Fetching Ue Cb Info*/
13685       GET_CELL_IDX(cellId, cellIdx);
13686       gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
13687       gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
13688       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
13689
13690       idx = 0;
13691       /*GNB CU UE F1AP ID*/
13692       ueSetRsp->protocolIEs.list.array[idx]->id = \
13693                                                   ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
13694       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13695       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
13696                                                              UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
13697       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
13698
13699       /*GNB DU UE F1AP ID*/
13700       idx++;
13701       ueSetRsp->protocolIEs.list.array[idx]->id = \
13702                                                   ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
13703       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13704       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
13705                                                              UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
13706       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
13707
13708
13709       /*DUtoCURRC Information */
13710       idx++;
13711       ueSetRsp->protocolIEs.list.array[idx]->id  = \
13712                                                    ProtocolIE_ID_id_DUtoCURRCInformation;
13713       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13714       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
13715                                                             UEContextSetupResponseIEs__value_PR_DUtoCURRCInformation;
13716       BuildCellGroupConfigRrc(ueCb, &ueSetRsp->protocolIEs.list.array[idx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
13717
13718       /* CRNTI */
13719       idx++;
13720       ueSetRsp->protocolIEs.list.array[idx]->id  = ProtocolIE_ID_id_C_RNTI;
13721       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13722       ueSetRsp->protocolIEs.list.array[idx]->value.present = UEContextSetupResponseIEs__value_PR_C_RNTI;
13723       ueSetRsp->protocolIEs.list.array[idx]->value.choice.C_RNTI = ueCb->crnti; 
13724
13725
13726       /* Drb Setup List */
13727       idx++;
13728       ueSetRsp->protocolIEs.list.array[idx]->id  = \
13729                                                    ProtocolIE_ID_id_DRBs_Setup_List;
13730       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13731       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
13732                                                             UEContextSetupResponseIEs__value_PR_DRBs_Setup_List;
13733       ret = fillDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List,\
13734             &ueCb->f1UeDb->duUeCfg);
13735       if(ret == RFAILED)
13736       {
13737          DU_LOG("\nERROR  -->  F1AP : Failed to fillDrbSetupList in BuildAndSendUeContextSetupRsp()");
13738          freeF1UeDb(ueCb->f1UeDb);
13739          ueCb->f1UeDb = NULLP;
13740          break;
13741       }
13742
13743       /* Free UeContext Db created during Ue context Req */
13744       freeF1UeDb(ueCb->f1UeDb);
13745       ueCb->f1UeDb = NULLP;
13746
13747       /* TODO: To send Drb list */
13748       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
13749
13750       /* Encode the UE context setup response type as APER */
13751       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
13752       encBufSize = 0;
13753       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
13754             encBuf);
13755       /* Encode results */
13756       if(encRetVal.encoded == ENCODE_FAIL)
13757       {
13758          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Response structure (at %s)\n",\
13759                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
13760          ret = RFAILED;
13761          break;
13762       }
13763       else
13764       {
13765          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Setup Response\n");
13766          for(int i=0; i< encBufSize; i++)
13767          {
13768             printf("%x",encBuf[i]);
13769          }
13770       }
13771
13772       /* Sending  msg  */
13773       if(sendF1APMsg()  != ROK)
13774       {
13775          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Response failed");
13776          ret = RFAILED;
13777          break;
13778       }
13779       break;
13780    }
13781    FreeUeContextSetupRsp(f1apMsg);
13782    return ret;
13783 }/* End of BuildAndSendUeContextSetupRsp */
13784 /*******************************************************************
13785 *
13786 * @brief  Build And Send Ue Context Rsp 
13787 *
13788 * @details
13789 *
13790 *    Function : BuildAndSendUeCtxtRsp 
13791 *
13792 *    Functionality : Build And Send Ue Context Rsp
13793
13794 * @params[in]
13795 * @return sucess = ROK
13796 *         failure = RFAILED
13797 *
13798 * ****************************************************************/
13799 uint8_t BuildAndSendUeCtxtRsp(uint8_t cellId, uint8_t ueId)
13800 {
13801    uint8_t cellIdx = 0, actionType = 0; 
13802
13803    GET_CELL_IDX(cellId, cellIdx);
13804    actionType = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].f1UeDb->actionType;
13805
13806    switch(actionType)
13807    {
13808       case UE_CTXT_SETUP:
13809          {
13810             if((BuildAndSendUeContextSetupRsp(cellId,ueId)) != ROK)
13811             {
13812                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextSetupRsp()");
13813                return RFAILED;
13814             }
13815             break;
13816          }
13817       case UE_CTXT_MOD:
13818          {
13819             if((BuildAndSendUeContextModRsp(&duCb.actvCellLst[cellIdx]->ueCb[ueId-1])) != ROK)
13820             {
13821                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextModRsp");
13822                return RFAILED;
13823             }
13824             break;
13825          }
13826       default:
13827          DU_LOG("ERROR  -->  F1AP: Invalid Action Type %d at BuildAndSendUeCtxtRsp()", actionType);
13828          break;
13829
13830    }
13831    return ROK;
13832 }
13833
13834 /*******************************************************************
13835  *
13836  * @brief deallocating the memory of  F1reset msg
13837  *
13838  * @details
13839  *
13840  *    Function : FreeF1ResetReq
13841  *
13842  *    Functionality :
13843  *         - freeing memory of F1reset request msg
13844  *
13845  * @params[in]
13846  * @return void
13847  *
13848  *
13849  * ****************************************************************/
13850 void FreeF1ResetReq(F1AP_PDU_t *f1apMsg)
13851 {
13852    uint8_t idx =0 ;
13853    Reset_t *f1ResetMsg;
13854
13855    if(f1apMsg)
13856    {
13857       if(f1apMsg->choice.initiatingMessage)
13858       {
13859          f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
13860
13861          if(f1ResetMsg->protocolIEs.list.array)
13862          {
13863             for(idx=0 ;idx < f1ResetMsg->protocolIEs.list.count ; idx++)
13864             {
13865                if(f1ResetMsg->protocolIEs.list.array[idx])
13866                {
13867                   DU_FREE(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
13868                }
13869             }
13870             DU_FREE(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
13871          }
13872          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
13873       }
13874       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
13875    }
13876 }
13877 /*******************************************************************
13878  *
13879  * @brief Build and Send F1reset request 
13880  *
13881  * @details
13882  *
13883  *    Function : BuildAndSendF1ResetReq
13884  *
13885  *    Functionality:
13886  *         - Build and Send F1reset request msg
13887  *
13888  * @params[in]
13889  * @return ROK     - success
13890  *         RFAILED - failure
13891  *
13892  * ****************************************************************/
13893 uint8_t BuildAndSendF1ResetReq()
13894 {
13895    uint8_t          elementCnt=0;
13896    uint8_t          idx=0;
13897    uint8_t          ret= RFAILED;
13898    Reset_t          *f1ResetMsg = NULLP;
13899    F1AP_PDU_t       *f1apMsg = NULLP;
13900    asn_enc_rval_t   encRetVal;
13901    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset request \n");
13902    do
13903    {
13904       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
13905       if(f1apMsg == NULLP)
13906       {
13907          break;
13908       }
13909       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
13910       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
13911       if(f1apMsg->choice.initiatingMessage == NULLP)
13912       {
13913          break;
13914       }
13915       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_Reset;
13916       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
13917       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_Reset;
13918
13919       f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
13920
13921       elementCnt = 3;
13922       f1ResetMsg->protocolIEs.list.count = elementCnt;
13923       f1ResetMsg->protocolIEs.list.size = elementCnt * sizeof(ResetIEs_t *);
13924
13925       /* Initialize the F1Setup members */
13926       DU_ALLOC(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
13927       if(f1ResetMsg->protocolIEs.list.array == NULLP)
13928       {
13929          break;
13930       }
13931       for(idx=0; idx<elementCnt; idx++)
13932       {
13933          DU_ALLOC(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
13934          if(f1ResetMsg->protocolIEs.list.array[idx] == NULLP)
13935          {
13936             break;
13937          }
13938       }
13939
13940       /*TransactionID*/
13941       idx=0;
13942       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
13943       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13944       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_TransactionID;
13945       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.TransactionID = 1;
13946
13947       /*Cause*/
13948       idx++;
13949       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_Cause;
13950       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_ignore;
13951       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_Cause;
13952       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.present = Cause_PR_radioNetwork;
13953       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.choice.radioNetwork = CauseRadioNetwork_action_desirable_for_radio_reasons;
13954
13955       /*Reset Type*/
13956       idx++;
13957       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_ResetType;
13958       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13959       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_ResetType;
13960       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.present = ResetType_PR_f1_Interface;
13961       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.choice.f1_Interface = ResetAll_reset_all;
13962
13963       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
13964
13965       /* Encode the F1SetupRequest type as APER */
13966       memset(encBuf, 0, ENC_BUF_MAX_LEN);
13967       encBufSize = 0;
13968       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
13969             encBuf);
13970
13971       /* Encode results */
13972       if(encRetVal.encoded == ENCODE_FAIL)
13973       {
13974          DU_LOG("\nERROR  -->  F1AP : Could not encode F1Reset structure (at %s)\n",\
13975                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
13976          break;
13977       }
13978       else
13979       {
13980          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1Reset\n");
13981          for(idx=0; idx< encBufSize; idx++)
13982          {
13983             printf("%x",encBuf[idx]);
13984          }
13985       }
13986
13987       if(sendF1APMsg() != ROK)
13988       {
13989          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset request failed");
13990          break;
13991       }
13992
13993       ret = ROK;
13994       break;
13995    }while(true);
13996
13997    FreeF1ResetReq(f1apMsg);
13998    return ret;
13999 }
14000 /*******************************************************************
14001  *
14002  * @brief Build And Send F1ResetAck
14003  *
14004  * @details
14005  *
14006  *    Function : BuildAndSendF1ResetAck
14007  *
14008  *    Functionality:
14009  *         - Build And Send  F1ResetRSP
14010  *
14011  * @return ROK     - success
14012  *         RFAILED - failure
14013  *
14014  * ****************************************************************/
14015 void FreeF1ResetAck(F1AP_PDU_t *f1apMsg)
14016 {
14017    uint8_t idx;
14018    ResetAcknowledge_t *f1ResetAck;
14019
14020    if(f1apMsg)
14021    {
14022       if(f1apMsg->choice.successfulOutcome)
14023       {
14024          f1ResetAck= &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14025
14026          if(f1ResetAck->protocolIEs.list.array)
14027          {
14028             for(idx=0; idx<f1ResetAck->protocolIEs.list.count ; idx++)
14029             {
14030                if(f1ResetAck->protocolIEs.list.array[idx])
14031                {
14032                   DU_FREE(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14033                }
14034             }
14035             DU_FREE(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14036          }
14037          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14038       }
14039       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14040    }
14041 }
14042
14043 /*******************************************************************
14044  *
14045  * @brief Build And Send F1ResetAck
14046  *
14047  * @details
14048  *
14049  *    Function : BuildAndSendF1ResetAck
14050  *
14051  *    Functionality:
14052  *         - Build And Send  F1ResetRSP
14053  *
14054  *  @params[in]
14055  * @return ROK     - success
14056  *         RFAILED - failure
14057  *
14058  * ****************************************************************/
14059 uint8_t BuildAndSendF1ResetAck()
14060 {
14061    uint8_t                idx = 0;
14062    uint8_t                elementCnt = 0;
14063    uint8_t                ret = RFAILED;
14064    F1AP_PDU_t             *f1apMsg = NULL;
14065    ResetAcknowledge_t     *f1ResetAck = NULLP;
14066    asn_enc_rval_t         encRetVal;
14067    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset Acknowledgment \n");
14068
14069    do{
14070       /* Allocate the memory for F1ResetRequest_t */
14071       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14072       if(f1apMsg == NULLP)
14073       {
14074          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14075          break;
14076       }
14077
14078       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
14079
14080       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14081       if(f1apMsg->choice.successfulOutcome == NULLP)
14082       {
14083          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14084          break;
14085       }
14086       f1apMsg->choice.successfulOutcome->criticality   = Criticality_reject;
14087       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetAcknowledge;
14088       f1ResetAck = &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14089
14090       elementCnt = 1;
14091
14092       f1ResetAck->protocolIEs.list.count = elementCnt;
14093       f1ResetAck->protocolIEs.list.size = elementCnt*sizeof(ResetAcknowledgeIEs_t *);
14094
14095       DU_ALLOC(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14096       if(f1ResetAck->protocolIEs.list.array == NULLP)
14097       {
14098          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1ResetAckIEs failed");
14099          break;
14100       }
14101
14102       for(idx=0; idx<elementCnt; idx++)
14103       {
14104          DU_ALLOC(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14105          if(f1ResetAck->protocolIEs.list.array[idx] == NULLP)
14106          {
14107             break;
14108          }
14109       }
14110       /*TransactionID*/
14111       idx = 0;
14112       f1ResetAck->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
14113       f1ResetAck->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14114       f1ResetAck->protocolIEs.list.array[idx]->value.present = ResetAcknowledgeIEs__value_PR_TransactionID;
14115       f1ResetAck->protocolIEs.list.array[idx]->value.choice.TransactionID = TRANS_ID;
14116
14117       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14118
14119       /* Encode the F1SetupRequest type as UPER */
14120       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14121       encBufSize = 0;
14122       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
14123
14124       /* Check encode results */
14125       if(encRetVal.encoded == ENCODE_FAIL)
14126       {
14127          DU_LOG("\nERROR  -->  F1AP : Could not encode F1ResetAck structure (at %s)\n",\
14128                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14129          break;
14130       }
14131       else
14132       {
14133          DU_LOG("\nDUBUG   -->  F1AP : Created APER encoded buffer for F1ResetAck\n");
14134          for(int i=0; i< encBufSize; i++)
14135          {
14136             printf("%x",encBuf[i]);
14137          }
14138       }
14139       /* Sending msg */
14140       if(sendF1APMsg() != ROK)
14141       {
14142          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset Acknowledgement failed");
14143          break;
14144       }
14145
14146       ret = ROK;
14147       break;
14148    }while(true);
14149
14150    FreeF1ResetAck(f1apMsg);
14151    return ret;
14152 }
14153 /******************************************************************
14154 *
14155 * @brief free F1 reset msg allocated by aper_decoder 
14156 *
14157 * @details
14158 *
14159 *    Function : freeAperDecodeF1ResetMsg 
14160 *
14161 *    Functionality: free F1 reset msg allocated by aper_decoder 
14162 *
14163 * @params[in] Reset_t *f1ResetMsg 
14164 * @return void 
14165 *
14166 * ****************************************************************/
14167
14168 void freeAperDecodeF1ResetMsg(Reset_t *f1ResetMsg)
14169 {
14170    uint8_t ieIdx =0;
14171    if(f1ResetMsg->protocolIEs.list.array)
14172    {
14173       for(ieIdx=0 ;ieIdx < f1ResetMsg->protocolIEs.list.count ; ieIdx++)
14174       {
14175          if(f1ResetMsg->protocolIEs.list.array[ieIdx])
14176          {
14177             free(f1ResetMsg->protocolIEs.list.array[ieIdx]);
14178          }
14179       }
14180       free(f1ResetMsg->protocolIEs.list.array);
14181    }
14182 }
14183
14184 /******************************************************************
14185  *
14186  * @brief Processes DL RRC Message Transfer  sent by CU
14187  *
14188  * @details
14189  *
14190  *    Function : procF1ResetReq
14191  *
14192  *    Functionality: Processes DL RRC Message Transfer sent by CU
14193  *
14194  * @params[in] F1AP_PDU_t ASN decoded F1AP message
14195  * @return ROK     - success
14196  *         RFAILED - failure
14197  *
14198  * ****************************************************************/
14199 uint8_t procF1ResetReq(F1AP_PDU_t *f1apMsg)
14200 {
14201    /* we are currently not supporting Ue release. right now we are supporting only init case of fireset */
14202    uint8_t       ieIdx = 0;
14203    uint8_t        ret = ROK;
14204    Reset_t       *f1ResetMsg = NULLP;
14205
14206    DU_LOG("\nINFO   -->  Processing F1 reset request");
14207    f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14208
14209    for(ieIdx=0; ieIdx<f1ResetMsg->protocolIEs.list.count; ieIdx++)
14210    {
14211       switch(f1ResetMsg->protocolIEs.list.array[ieIdx]->id)
14212       {
14213          case ProtocolIE_ID_id_TransactionID:
14214             break;
14215
14216          case ProtocolIE_ID_id_Cause:
14217             break;
14218
14219          case ProtocolIE_ID_id_ResetType:
14220             {
14221                break;
14222             }
14223
14224          default:
14225             break;
14226       }
14227    }
14228    ret = BuildAndSendF1ResetAck();
14229    DU_LOG("\nINFO   -->  UE release is not supported for now");
14230
14231    freeAperDecodeF1ResetMsg(f1ResetMsg);
14232
14233    return ret;
14234 }
14235
14236 /*******************************************************************
14237  *
14238  * @brief free the RRC delivery report
14239  *
14240  * @details
14241  *
14242  *    Function : freeRrcDeliveryReport
14243  *
14244  *    Functionality: free the RRC delivery report
14245  *
14246  * @params[in]
14247  * @return ROK     - success
14248  *         RFAILED - failure
14249  *
14250  * ****************************************************************/
14251 void freeRrcDeliveryReport(F1AP_PDU_t  *f1apMsg )
14252 {
14253    uint8_t idx=0;
14254    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
14255
14256    if(f1apMsg)
14257    {
14258       if(f1apMsg->choice.initiatingMessage)
14259       {
14260          rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
14261          if(rrcDeliveryReport->protocolIEs.list.array)
14262          {
14263             for(idx =0 ;idx <rrcDeliveryReport->protocolIEs.list.count ;
14264                   idx++)
14265             {
14266                if(rrcDeliveryReport->protocolIEs.list.array[idx])
14267                {
14268                   DU_FREE(rrcDeliveryReport->protocolIEs.list.array[idx],
14269                         sizeof(RRCDeliveryReportIEs_t));
14270                }   
14271             }
14272             DU_FREE(rrcDeliveryReport->protocolIEs.list.array,
14273                   rrcDeliveryReport->protocolIEs.list.size);
14274          }
14275          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
14276       }
14277       DU_FREE(f1apMsg,
14278             sizeof(F1AP_PDU_t));
14279    }
14280 }
14281
14282 /*******************************************************************
14283 *
14284 * @brief Builds and sends the RRC delivery report
14285 *
14286 * @details
14287 *
14288 *    Function : BuildAndSendRrcDeliveryReport
14289 *
14290 *    Functionality: Builds and sends the RRC delivery report
14291 *
14292 * @params[in]
14293 *
14294 * @return ROK     - success
14295 *         RFAILED - failure
14296 *
14297 * ****************************************************************/
14298 uint8_t BuildAndSendRrcDeliveryReport(uint32_t gnbCuUeF1apId, \
14299    uint32_t gnbDuUeF1apId, RrcDeliveryReport *rrcDelivery)
14300 {
14301    uint8_t             ret = RFAILED;
14302    uint8_t             idx    = 0;
14303    uint8_t             idx1   = 0;
14304    uint8_t             elementCnt = 0;
14305    F1AP_PDU_t          *f1apMsg = NULLP;
14306    asn_enc_rval_t      encRetVal;  
14307    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
14308
14309    do{
14310
14311       DU_LOG("\nINFO   -->  F1AP : Building RRC delivery Message Transfer Message\n");
14312       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14313       if(f1apMsg == NULLP)
14314       {
14315          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14316          break;
14317       }
14318       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
14319       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
14320       if(f1apMsg->choice.initiatingMessage == NULLP)
14321       {
14322          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU  failed");
14323          break;
14324       }
14325       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_RRCDeliveryReport;
14326       f1apMsg->choice.initiatingMessage->criticality   = Criticality_ignore;
14327       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_RRCDeliveryReport;
14328
14329       rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
14330       elementCnt = 4;
14331       rrcDeliveryReport->protocolIEs.list.count = elementCnt;
14332       rrcDeliveryReport->protocolIEs.list.size = elementCnt * sizeof(RRCDeliveryReportIEs_t *);
14333
14334       /* Initialize the F1Setup members */
14335       DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array, rrcDeliveryReport->protocolIEs.list.size);
14336       if(rrcDeliveryReport->protocolIEs.list.array == NULLP)
14337       {
14338          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRC Delivery  failed");
14339          break;
14340       }
14341       for(idx =0 ;idx <elementCnt; idx++)
14342       {
14343          DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array[idx], sizeof(RRCDeliveryReportIEs_t));
14344          if(rrcDeliveryReport->protocolIEs.list.array[idx] == NULLP)
14345          {
14346             break;
14347          }
14348       }
14349
14350       idx1 = 0;
14351
14352       /*GNB CU UE F1AP ID*/
14353       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
14354       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
14355       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_CU_UE_F1AP_ID;
14356       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
14357
14358       /*GNB DU UE F1AP ID*/
14359       idx1++;
14360       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14361       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
14362       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_DU_UE_F1AP_ID;
14363       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
14364
14365       /*RRC delivery status*/
14366       idx1++;
14367       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_RRCDeliveryStatus;
14368       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
14369       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_RRCDeliveryStatus;
14370       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.delivery_status =\
14371       rrcDelivery->rrcDeliveryStatus.deliveryStatus;
14372       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.triggering_message =\
14373       rrcDelivery->rrcDeliveryStatus.triggeringMessage;
14374
14375       /* SRB ID */ 
14376       idx1++;
14377       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
14378       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
14379       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_SRBID;
14380       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.SRBID =  rrcDelivery->srbId;
14381
14382       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14383
14384       /* Encode the RRC DELIVERY REPORT type as APER */
14385       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14386       encBufSize = 0;
14387       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14388             encBuf);
14389
14390       /* Encode results */
14391       if(encRetVal.encoded == ENCODE_FAIL)
14392       {
14393          DU_LOG("\nERROR  -->  F1AP : Could not encode RRC Delivery Msg structure (at %s)\n",\
14394                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14395          break;
14396       }
14397       else
14398       {
14399          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for RRC Delivery Msg \n");
14400          for(idx=0; idx< encBufSize; idx++)
14401          {
14402             printf("%x",encBuf[idx]);
14403          }
14404       }
14405
14406       /* Sending msg */
14407       if(sendF1APMsg() != ROK)
14408       {
14409          DU_LOG("\nERROR  -->  F1AP : Sending RRC delivery  msg request failed");
14410          break;
14411       }
14412       ret = ROK;
14413       break;
14414
14415    }while(true);
14416
14417    freeRrcDeliveryReport(f1apMsg);
14418    return ret;
14419 }
14420
14421 /*******************************************************************
14422  *
14423  * @brief Processes cells to be activated
14424  *
14425  * @details
14426  *
14427  *    Function : extractCellsToBeActivated
14428  *
14429  *    Functionality:
14430  *      - Processes cells to be activated list received in F1SetupRsp
14431  *
14432  * @params[in] void
14433  * @return ROK     - success
14434  *         RFAILED - failure
14435  *
14436  * ****************************************************************/
14437
14438 uint8_t extractCellsToBeActivated(Cells_to_be_Activated_List_t cellsToActivate)
14439 {
14440    uint8_t  ret = ROK;
14441    uint16_t idx, pci = 0;
14442    uint64_t nci;
14443    Cells_to_be_Activated_List_Item_t cell;
14444
14445    for(idx=0; idx<cellsToActivate.list.count; idx++)
14446    {
14447       nci = 0;
14448       cell = cellsToActivate.list.array[idx]->value.choice.Cells_to_be_Activated_List_Item;
14449       bitStringToInt(&cell.nRCGI.nRCellIdentity, &nci);
14450
14451       if(cell.nRPCI)
14452       {
14453          pci = *cell.nRPCI;
14454       }
14455       ret = duProcCellsToBeActivated(cell.nRCGI.pLMN_Identity.buf, nci, pci);
14456    }
14457    return ret;
14458 }
14459 /******************************************************************
14460 *
14461 * @brief Processes F1 Setup Response allocated by aper_decoder 
14462 *
14463 * @details
14464 *
14465 *    Function : freeF1SetupRsp 
14466 *
14467 *    Functionality: free F1 Setup Response allocated by aper_decoder 
14468 *
14469 * @params[in] F1SetupResponse_t *f1SetRspMsg 
14470 * @return void 
14471 *
14472 * ****************************************************************/
14473
14474 void freeAperDecodeF1SetupRsp(F1SetupResponse_t *f1SetRspMsg)
14475 {
14476    uint8_t ieIdx =0;
14477    uint8_t arrIdx =0;
14478    Cells_to_be_Activated_List_t *cellToActivate =NULLP;
14479    RRC_Version_t      *rrcVer =NULLP;
14480
14481    if(f1SetRspMsg->protocolIEs.list.array)
14482    {
14483       for(ieIdx=0; ieIdx<f1SetRspMsg->protocolIEs.list.count; ieIdx++)
14484       {
14485          if(f1SetRspMsg->protocolIEs.list.array[ieIdx])
14486          {
14487             switch(f1SetRspMsg->protocolIEs.list.array[ieIdx]->id)
14488             {
14489                case ProtocolIE_ID_id_Cells_to_be_Activated_List:
14490                   {
14491                      cellToActivate =
14492                         &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.Cells_to_be_Activated_List;
14493                      if(cellToActivate->list.array)
14494                      {
14495                         for(arrIdx=0; arrIdx<cellToActivate->list.count ; arrIdx++)
14496                         {
14497                            if(cellToActivate->list.array[arrIdx])
14498                            {
14499
14500                               if(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.nRCGI.\
14501                               pLMN_Identity.buf)
14502                               {
14503                                  if(cellToActivate->list.array[0]->value.choice.\
14504                                        Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf)
14505                                  {
14506                                     free(cellToActivate->list.array[0]->value.choice.\
14507                                           Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf);
14508                                  }
14509
14510                                  free(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
14511                                        nRCGI.pLMN_Identity.buf);
14512                               }
14513                               free(cellToActivate->list.array[arrIdx]);
14514                            }
14515                         }
14516                         free(cellToActivate->list.array);
14517                      }
14518                      break;
14519                   }
14520                case ProtocolIE_ID_id_TransactionID:
14521                   {
14522                      break;
14523                   }
14524                case ProtocolIE_ID_id_gNB_CU_Name:
14525                   {
14526                      free(f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_Name.buf);
14527                      break;
14528                   }
14529                case ProtocolIE_ID_id_GNB_CU_RRC_Version:
14530                   {
14531                      rrcVer = &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
14532                      if(rrcVer->latest_RRC_Version.buf)
14533                      {
14534                         if(rrcVer->iE_Extensions)
14535                         {
14536                            if(rrcVer->iE_Extensions->list.array)
14537                            {
14538                               if(rrcVer->iE_Extensions->list.array[0])
14539                               {
14540                                  if(rrcVer->iE_Extensions->list.\
14541                                        array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf)
14542                                  {
14543                                     free(rrcVer->iE_Extensions->list.\
14544                                           array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf);
14545                                  }
14546                                  free(rrcVer->iE_Extensions->list.array[0]);
14547                               }
14548                               free(rrcVer->iE_Extensions->list.array);
14549                            }
14550                            free(rrcVer->iE_Extensions);
14551                         }
14552                         free(rrcVer->latest_RRC_Version.buf);
14553                      }
14554                      break;
14555
14556                   }
14557                default:
14558                   {
14559                      DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
14560                            f1SetRspMsg->protocolIEs.list.array[ieIdx]->id);
14561                   }
14562             }
14563             free(f1SetRspMsg->protocolIEs.list.array[ieIdx]);
14564          }
14565       }
14566       free(f1SetRspMsg->protocolIEs.list.array);
14567    }
14568 }
14569 /******************************************************************
14570  *
14571  * @brief Processes F1 Setup Response sent by CU
14572  *
14573  * @details
14574  *
14575  *    Function : procF1SetupRsp
14576  *
14577  *    Functionality: Processes F1 Setup Response sent by CU
14578  *
14579  * @params[in] F1AP_PDU_t ASN decoded F1AP message
14580  * @return ROK     - success
14581  *         RFAILED - failure
14582  *
14583  * ****************************************************************/
14584 uint8_t procF1SetupRsp(F1AP_PDU_t *f1apMsg, MsgLen recvBufLen, char *recvBuf)
14585 {
14586    uint8_t ret = ROK;
14587    uint16_t idx =0;
14588    F1SetupResponse_t *f1SetRspMsg = NULLP;
14589    GNB_CU_Name_t     *cuName = NULLP;
14590    F1SetupRsp  f1SetRspDb;
14591    RRC_Version_t      *rrcVer =NULLP;
14592    
14593    memset(&f1SetRspDb, 0, sizeof(F1SetupRsp));
14594
14595    DU_LOG("\nINFO   -->  F1AP : F1 Setup Response received");
14596    f1SetRspMsg = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
14597
14598    for(idx=0; idx<f1SetRspMsg->protocolIEs.list.count; idx++)
14599    {
14600       switch(f1SetRspMsg->protocolIEs.list.array[idx]->id)
14601       {
14602          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
14603             {
14604                extractCellsToBeActivated(f1SetRspMsg->protocolIEs.list.array[idx]->\
14605                      value.choice.Cells_to_be_Activated_List);
14606                break;
14607             }
14608          case ProtocolIE_ID_id_TransactionID:
14609             {
14610                f1SetRspDb.transId = f1SetRspMsg->protocolIEs.list.array[idx]->\
14611                                     value.choice.TransactionID;
14612                break;
14613             }
14614          case ProtocolIE_ID_id_gNB_CU_Name:
14615             {
14616                cuName = &f1SetRspMsg->protocolIEs.list.array[idx]->\
14617                         value.choice.GNB_CU_Name;
14618                strcpy(f1SetRspDb.cuName, (const char*)cuName->buf);
14619                break;
14620             }
14621          case ProtocolIE_ID_id_GNB_CU_RRC_Version:
14622             {
14623                rrcVer = &f1SetRspMsg->protocolIEs.list.array[idx]->value.choice.RRC_Version;
14624                strcpy(f1SetRspDb.rrcVersion.rrcVer,
14625                      (const char*)rrcVer->latest_RRC_Version.buf);
14626                break;
14627             }
14628          default:
14629             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
14630                   f1SetRspMsg->protocolIEs.list.array[idx]->id);
14631       }
14632       duProcF1SetupRsp();
14633    }
14634    
14635    freeAperDecodeF1SetupRsp(f1SetRspMsg);
14636
14637    duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize = recvBufLen;
14638    DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize);
14639    if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
14640    {
14641       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the buf of F1setup response");
14642       return RFAILED;
14643    }
14644    memcpy(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, recvBuf, recvBufLen);
14645    
14646    if(BuildAndSendE2SetupReq() != ROK)
14647    {
14648       DU_LOG("\nERROR  -->  F1AP : Failed to build and send E2 setup request ");
14649       return RFAILED;
14650    }
14651    return ret;
14652 }
14653 /*******************************************************************
14654 *
14655 * @brief free GNB DU config update ack
14656 *
14657 * @details
14658 *
14659 *    Function : freeAperDecodeGnbDuAck 
14660 *
14661 *    Functionality: Processes GNB DU config update ack And
14662 *                     added free part for the memory allocated by aper_decoder
14663 *
14664 * @params[in] F1AP_PDU_t ASN decoded F1AP message
14665 * @return ROK     - success
14666 *         RFAILED - failure
14667 *
14668 * ****************************************************************/
14669
14670 void freeAperDecodeGnbDuAck(GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck)
14671 {
14672    uint8_t ieIdx = 0;
14673
14674    if(gnbDuAck->protocolIEs.list.array)
14675    {
14676       for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
14677       {
14678          if(gnbDuAck->protocolIEs.list.array[ieIdx])
14679          {
14680             free(gnbDuAck->protocolIEs.list.array[ieIdx]);
14681          }
14682       }
14683       free(gnbDuAck->protocolIEs.list.array);
14684    }
14685 }
14686
14687 /*******************************************************************
14688 *
14689 * @brief Building  result of gnb-du config update ack output
14690 *
14691 * @details
14692 *
14693 *    Function : duProcGnbDuCfgUpdAckMsg 
14694 *
14695 *    Functionality: 
14696 *        Building output of gnb-du config update ack 
14697 *
14698 * @params[in] transId
14699 * @return void
14700 *
14701 * ****************************************************************/
14702
14703 uint8_t duProcGnbDuCfgUpdAckMsg(uint8_t transId)
14704 {
14705    uint8_t  ieIdx=0, arrIdx=0,ret=ROK;
14706    uint8_t  ueId =0 , ueIdx =0, totalActiveUe = 0;
14707    uint16_t cellIdx =0, crnti=0;
14708    uint64_t cellId =0;
14709    CmLList *f1apPduNode = NULLP;
14710    ReservedF1apPduInfo *f1apPduInfo =NULLP;
14711    F1AP_PDU_t *f1apMsgPdu = NULLP;
14712    GNBDUConfigurationUpdate_t *gnbDuConfigUpdate = NULLP;
14713    BIT_STRING_t *cellIdentity=NULLP;
14714    struct Served_Cells_To_Delete_ItemIEs *deleteItemIe=NULLP;
14715    Served_Cells_To_Delete_List_t *cellsToDelete=NULLP;
14716    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
14717
14718    DU_LOG("\nINFO   -->  DU APP: GNB-DU config update Ack received ");
14719    f1apPduNode = searchFromReservedF1apPduList(transId);
14720    f1apPduInfo = (ReservedF1apPduInfo *)f1apPduNode->node;
14721    f1apMsgPdu = (F1AP_PDU_t *)f1apPduInfo->f1apMsg;
14722
14723    if(f1apMsgPdu)
14724    {
14725       if(f1apMsgPdu->choice.initiatingMessage)
14726       {
14727          gnbDuConfigUpdate = &f1apMsgPdu->choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
14728          for(ieIdx=0; ieIdx < gnbDuConfigUpdate->protocolIEs.list.count; ieIdx++)
14729          {
14730             switch(gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->id)
14731             {
14732                case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
14733                   {
14734                      cellsToDelete = &gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
14735                                      Served_Cells_To_Delete_List;
14736                      if(cellsToDelete->list.array)
14737                      {
14738                         if(cellsToDelete->list.array[arrIdx])
14739                         {
14740                            deleteItemIe = (Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx];
14741                            deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
14742                            if(deleteItem->oldNRCGI.nRCellIdentity.buf)
14743                            {
14744                               cellIdentity = &deleteItem->oldNRCGI.nRCellIdentity;
14745                               bitStringToInt(cellIdentity, &cellId);
14746
14747                               GET_CELL_IDX(cellId, cellIdx);
14748                               if(duCb.actvCellLst[cellIdx] != NULLP)
14749                               {
14750                                  duCb.actvCellLst[cellId-1]->cellStatus = DELETION_IN_PROGRESS;
14751                               }
14752                            }
14753                         }
14754                      }
14755
14756                      if(duCb.actvCellLst[cellIdx] != NULLP)
14757                      {
14758                         if(duCb.actvCellLst[cellIdx]->numActvUes == 0)
14759                         {
14760                            ret = duSendCellDeletReq(cellId);
14761                            if(ret == RFAILED)
14762                            {
14763                               DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to send cell delete\
14764                               request for cellId[%d]", cellId);
14765                            }
14766                         }
14767                         else
14768                         {
14769                            totalActiveUe = duCb.actvCellLst[cellIdx]->numActvUes;
14770                            while(totalActiveUe)
14771                            {
14772                               if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState != UE_ACTIVE)
14773                               {
14774                                  ueIdx++;
14775                                  continue;
14776                               }
14777
14778                               crnti = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti;
14779                               GET_UE_ID(crnti,ueId);
14780                               /* Sending Ue Context release request only for maximum supporting UEs */
14781                               ret = BuildAndSendUeContextReleaseReq(cellId, ueId);
14782                               if(ret == RFAILED)
14783                               {
14784                                  DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to build and send UE delete\
14785                                  request for cellId[%d]", cellId);
14786                               }
14787                               ueIdx++;
14788                               totalActiveUe--;
14789                            }
14790                         }
14791                      }
14792                      else
14793                      {
14794                         DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): CellId [%d] not found", cellId);
14795                         ret = RFAILED;
14796                      }
14797                      break;
14798                   }
14799
14800                default:
14801                   break;
14802             }
14803          }
14804       }
14805    }
14806    
14807    FreeDUConfigUpdate(f1apMsgPdu);
14808    deleteFromReservedF1apPduList(f1apPduNode);
14809    return ret;
14810 }
14811
14812 /*******************************************************************
14813 *
14814 * @brief Processes GNB DU config update ack
14815 *
14816 * @details
14817 *
14818 *    Function : procF1GNBDUCfgUpdAck
14819 *
14820 *    Functionality: added free part for the memory allocated by aper_decoder
14821 *
14822 * @params[in] F1AP_PDU_t *f1apMsg 
14823 * @return void 
14824 *
14825 * ****************************************************************/
14826 uint8_t procF1GNBDUCfgUpdAck(F1AP_PDU_t *f1apMsg)
14827 {
14828    uint8_t ieIdx=0,transId=0;
14829    GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck = NULLP;
14830
14831    DU_LOG("\nINFO   -->  F1AP : GNB-DU config update acknowledgment");
14832    gnbDuAck = &f1apMsg->choice.successfulOutcome->value.choice.GNBDUConfigurationUpdateAcknowledge;
14833
14834    for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
14835    {
14836       switch(gnbDuAck->protocolIEs.list.array[ieIdx]->id)
14837       {
14838          case ProtocolIE_ID_id_TransactionID:
14839             {
14840                transId = gnbDuAck->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
14841                break;
14842             }
14843          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
14844             {
14845                break;
14846             }
14847          default :
14848             {
14849                DU_LOG("\nERROR  -->  F1AP: procF1GNBDUCfgUpdAck(): Invalid IE Received: %ld", \
14850                      gnbDuAck->protocolIEs.list.array[ieIdx]->id);
14851                break;
14852             }
14853       }
14854    }
14855    
14856    duProcGnbDuCfgUpdAckMsg(transId);
14857     
14858 #if 0
14859    /* presently we are not supporting F1 Reset from DU to CU , we are only
14860     * supporting F1 Reset from CU to DU */
14861
14862    if(BuildAndSendF1ResetReq() != ROK)
14863    {
14864       return RFAILED;
14865    }
14866 #endif
14867
14868    freeAperDecodeGnbDuAck(gnbDuAck);
14869    return ROK;
14870 }
14871 /******************************************************************
14872 *
14873 * @brief free DL RRC Message Transfer allocated by aper_decoder 
14874 *
14875 * @details
14876 *
14877 *    Function : freeAperDecodef1DlRrcMsg 
14878 *
14879 *    Functionality: free DL RRC Message Transfer allocated by aper_decoder 
14880 *
14881 * @params[in] DLRRCMessageTransfer_t *f1DlRrcMsg 
14882 * @return ROK     - success
14883 *         RFAILED - failure
14884 *
14885 * ****************************************************************/
14886
14887 void freeAperDecodef1DlRrcMsg(DLRRCMessageTransfer_t *f1DlRrcMsg)
14888 {
14889    uint8_t ieIdx =0;
14890    RRCContainer_t *rrcContainer = NULLP;
14891
14892    if(f1DlRrcMsg->protocolIEs.list.array)
14893    {
14894       for(ieIdx=0; ieIdx<f1DlRrcMsg->protocolIEs.list.count; ieIdx++)
14895       {
14896          if(f1DlRrcMsg->protocolIEs.list.array[ieIdx])
14897          {
14898             switch(f1DlRrcMsg->protocolIEs.list.array[ieIdx]->id)
14899             {
14900                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14901                   break;
14902                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14903                   break;
14904                case ProtocolIE_ID_id_SRBID:
14905                   break;
14906                case ProtocolIE_ID_id_RRCContainer:
14907                   {
14908                      rrcContainer =&f1DlRrcMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer;
14909                      free(rrcContainer->buf);
14910                   }
14911                case ProtocolIE_ID_id_ExecuteDuplication:
14912                   break;
14913                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
14914                   break;
14915                   break;
14916             }
14917             free(f1DlRrcMsg->protocolIEs.list.array[ieIdx]);
14918          }
14919       }
14920       free(f1DlRrcMsg->protocolIEs.list.array);
14921    }
14922 }
14923 /******************************************************************
14924  *
14925  * @brief Processes DL RRC Message Transfer  sent by CU
14926  *
14927  * @details
14928  *
14929  *    Function : procF1DlRrcMsgTrans
14930  *
14931  *    Functionality: Processes DL RRC Message Transfer sent by CU
14932  *
14933  * @params[in] F1AP_PDU_t ASN decoded F1AP message
14934  * @return ROK     - success
14935  *         RFAILED - failure
14936  *
14937  * ****************************************************************/
14938 uint8_t procF1DlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
14939 {
14940    uint8_t  idx, ret;
14941    DLRRCMessageTransfer_t *f1DlRrcMsg = NULLP;
14942    F1DlRrcMsg dlMsg;
14943    memset(&dlMsg, 0, sizeof(F1DlRrcMsg));
14944
14945    DU_LOG("\nINFO   -->  DU_APP : DL RRC message transfer Recevied");
14946    f1DlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
14947
14948    ret = ROK;
14949
14950    for(idx=0; idx<f1DlRrcMsg->protocolIEs.list.count; idx++)
14951    {
14952       switch(f1DlRrcMsg->protocolIEs.list.array[idx]->id)
14953       {
14954          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14955             {
14956                dlMsg.gnbCuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
14957                break;
14958             }
14959          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14960             {
14961                dlMsg.gnbDuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
14962                break;
14963             }
14964          case ProtocolIE_ID_id_SRBID:
14965             {
14966                dlMsg.srbId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
14967                break;
14968             }
14969          case ProtocolIE_ID_id_ExecuteDuplication:
14970             dlMsg.execDup = true;
14971             break;
14972
14973          case ProtocolIE_ID_id_RRCContainer:
14974             {
14975                if(f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
14976                {
14977                   dlMsg.rrcMsgSize = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
14978                   DU_ALLOC_SHRABL_BUF(dlMsg.rrcMsgPdu, dlMsg.rrcMsgSize);
14979                   if(dlMsg.rrcMsgPdu)
14980                   {
14981                      memcpy(dlMsg.rrcMsgPdu, f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf,\
14982                         dlMsg.rrcMsgSize);
14983                   }
14984                   else
14985                   {
14986                      DU_LOG("\nERROR  -->  DU APP : Memory alloc Failed at RRC Container at procF1DlRrcMsgTrans()");
14987                      return RFAILED;
14988                   }
14989                }
14990                else
14991                {
14992                   DU_LOG("\nERROR  -->  DU_APP : RRC Container Size is invalid:%ld",\
14993                   f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
14994                   return RFAILED;
14995                }
14996                break;
14997             }
14998          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
14999             {
15000                dlMsg.deliveryStatRpt = true;
15001                break;
15002             }
15003          default:
15004             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
15005                   f1DlRrcMsg->protocolIEs.list.array[idx]->id);
15006       }
15007    }
15008
15009    ret = duProcDlRrcMsg(&dlMsg);
15010
15011    freeAperDecodef1DlRrcMsg(f1DlRrcMsg);
15012    return ret;
15013 }
15014 /*******************************************************************
15015  *
15016 * @brief Builds the DRB to be Setup Mod list
15017 *
15018 * @details
15019 *
15020 *    Function : 
15021 *
15022 *    Functionality: Constructs the DRB to be Setup Mod list
15023 *
15024 * @params[in] DRBs_SetupMod_List_t *drbSet
15025 *
15026 * @return ROK     - success
15027 *         RFAILED - failure
15028 *
15029 * ****************************************************************/
15030 uint8_t BuildSrbSetupModList(SRBs_SetupMod_List_t *srbList, DuUeCfg *ueCfg)
15031 {
15032    uint8_t srbIdx = 0;
15033    struct SRBs_SetupMod_ItemIEs *srbItemIe;
15034
15035    srbList->list.count = ueCfg->numRlcLcs;
15036    srbList->list.size = srbList->list.count * sizeof(SRBs_SetupMod_ItemIEs_t *);
15037
15038    DU_ALLOC(srbList->list.array, srbList->list.size);
15039    if(srbList->list.array == NULLP)
15040    {
15041       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15042       return RFAILED;
15043    }
15044
15045    for(srbIdx = 0; srbIdx < srbList->list.count; srbIdx++)
15046    {
15047       DU_ALLOC(srbList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15048       if(srbList->list.array[srbIdx] == NULLP)
15049       {
15050          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15051          return RFAILED;
15052       }
15053    } 
15054
15055    for(srbIdx=0; srbIdx < srbList->list.count; srbIdx++)
15056    {
15057       srbItemIe = (struct SRBs_SetupMod_ItemIEs *)srbList->list.array[srbIdx];
15058       srbItemIe->id = ProtocolIE_ID_id_SRBs_SetupMod_Item;
15059       srbItemIe->criticality = Criticality_reject;
15060       srbItemIe->value.present = SRBs_SetupMod_ItemIEs__value_PR_SRBs_SetupMod_Item;
15061       srbItemIe->value.choice.SRBs_SetupMod_Item.sRBID = ueCfg->rlcLcCfg[srbIdx].rbId;
15062       srbItemIe->value.choice.SRBs_SetupMod_Item.lCID = ueCfg->rlcLcCfg[srbIdx].lcId;
15063    }
15064    return ROK;
15065 }
15066
15067 /*******************************************************************
15068  *
15069 * @brief Builds the DRB to be Setup Mod list
15070 *
15071 * @details
15072 *
15073 *    Function : 
15074 *
15075 *    Functionality: Constructs the DRB to be Setup Mod list
15076 *
15077 * @params[in] DRBs_SetupMod_List_t *drbSet
15078 *
15079 * @return ROK     - success
15080 *         RFAILED - failure
15081 *
15082 * ****************************************************************/
15083
15084 uint8_t BuildDrbSetupModList(DRBs_SetupMod_List_t *drbSet , DuUeCfg *ueCfg)
15085 {
15086    uint8_t arrIdx =0;
15087    uint8_t drbCnt =0;
15088    struct DRBs_SetupMod_ItemIEs *drbItemIe;
15089
15090    drbCnt = ueCfg->numDrbSetupMod;
15091
15092    if(!drbCnt)
15093    {
15094       DU_LOG("\nINFO  -->  F1AP : BuildDrbToBeSetupModList(): No DRB information to avaialble to add");
15095       return ROK;
15096    }
15097
15098    drbSet->list.count = drbCnt;
15099    drbSet->list.size = drbCnt * sizeof(DRBs_SetupMod_ItemIEs_t *);
15100    DU_ALLOC(drbSet->list.array, drbSet->list.size);
15101    if(drbSet->list.array == NULLP)
15102    {
15103       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
15104       return  RFAILED;
15105    }
15106    for(arrIdx=0; arrIdx<drbCnt; arrIdx++)
15107    {
15108       DU_ALLOC(drbSet->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
15109       if(drbSet->list.array[arrIdx] == NULLP)
15110       {
15111               DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
15112               return  RFAILED;
15113       }
15114
15115       drbItemIe = (struct DRBs_SetupMod_ItemIEs *)drbSet->list.array[arrIdx];
15116       drbItemIe->id = ProtocolIE_ID_id_DRBs_SetupMod_Item;
15117       drbItemIe->criticality = Criticality_reject;
15118       drbItemIe->value.present = DRBs_SetupMod_ItemIEs__value_PR_DRBs_SetupMod_Item;
15119       drbItemIe->value.choice.DRBs_SetupMod_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
15120       if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List,\
15121       &ueCfg->upTnlInfo[arrIdx])!= ROK)
15122       {
15123          DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbToBeSetupModList");
15124          return RFAILED;
15125       }
15126       
15127    }
15128
15129    return ROK;
15130 }
15131 /*******************************************************************
15132 * @brief Free the memory allocated for DRB setup List
15133 *
15134 * @details
15135 *
15136 *    Function : FreeDrbSetupModList 
15137 *
15138 *    Functionality:
15139 *       Free the memory allocated for DRB setup list
15140 *
15141 * @params[in] DRBs_Setup_List_t *
15142 * @return void
15143 *
15144 * ****************************************************************/
15145 void FreeDrbSetupModList(DRBs_SetupMod_List_t *drbSetupList)
15146 {
15147    uint8_t arrIdx = 0;
15148    DRBs_SetupMod_ItemIEs_t *drbItemIe = NULLP;
15149
15150    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
15151    {
15152       drbItemIe = ((DRBs_SetupMod_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
15153       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List);
15154       DU_FREE(drbSetupList->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
15155    }
15156    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
15157 }
15158
15159 /*******************************************************************
15160 * @brief Free the memory allocated for SRB setup List
15161 *
15162 * @details
15163 *
15164 *    Function : FreeSrbSetupModList 
15165 *
15166 *    Functionality:
15167 *       Free the memory allocated for SRB setup list
15168 *
15169 * @params[in] SRBs_Setup_List_t *
15170 * @return void
15171 *
15172 * ****************************************************************/
15173 void FreeSrbSetupModList(SRBs_SetupMod_List_t *srbSetupList)
15174 {
15175    uint8_t srbIdx = 0;
15176    
15177    for(srbIdx = 0; srbIdx < srbSetupList->list.count; srbIdx++)
15178       DU_FREE(srbSetupList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15179    DU_FREE(srbSetupList->list.array, srbSetupList->list.size);
15180 }
15181
15182 /*******************************************************************
15183 * @brief Free the memory allocated for UE Context Mod Response
15184 *
15185 * @details
15186 *
15187 *    Function : FreeUeContextModResp 
15188 *
15189 *    Functionality:
15190 *       Free the memory allocated for UE Context Mod Response
15191 *
15192 * @params[in] F1AP_PDU_t *f1apMsg
15193 * @return void
15194 *
15195 * ****************************************************************/
15196
15197 void FreeUeContextModResp(F1AP_PDU_t *f1apMsg)
15198 {
15199    uint8_t ieIdx;
15200    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
15201    if(f1apMsg)
15202    {
15203       if(f1apMsg->choice.successfulOutcome)
15204       {
15205          ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
15206          if(ueContextModifyRes->protocolIEs.list.array)
15207          {
15208             for(ieIdx=0 ; ieIdx<ueContextModifyRes->protocolIEs.list.count; ieIdx++)
15209             {
15210                if(ueContextModifyRes->protocolIEs.list.array[ieIdx])
15211                {
15212                   switch(ueContextModifyRes->protocolIEs.list.array[ieIdx]->id)
15213                   {
15214                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15215                         break;
15216                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15217                         break;
15218                      case ProtocolIE_ID_id_DRBs_SetupMod_List:
15219                         {
15220                             FreeDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
15221                             value.choice.DRBs_SetupMod_List));
15222                             break;
15223                         }
15224                      case ProtocolIE_ID_id_SRBs_SetupMod_List:
15225                         {
15226                            FreeSrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
15227                               SRBs_SetupMod_List));
15228                            break; 
15229                         }
15230                   }
15231                   DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
15232                }
15233
15234             }
15235             DU_FREE(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
15236          }
15237          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
15238       }
15239       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
15240    }
15241 }
15242
15243 /*****************************************************************i
15244 *
15245 * @brief Creating the ue context modifcation response and sending
15246 *
15247 * @details
15248 *
15249 *    Function : BuildAndSendUeContextModRsp 
15250 *
15251 *    Functionality:
15252 *         - Creating the ue context modifcation response 
15253 *
15254 * @params[in] uint8_t cellId,uint8_t ueId
15255 * @return ROK     - success
15256 *         RFAILED - failure
15257 *
15258 * ****************************************************************/
15259 uint8_t BuildAndSendUeContextModRsp(DuUeCb *ueCb)
15260 {
15261    uint8_t   ieIdx = 0, tnlIdx = 0, rbIdx = 0;
15262    uint8_t   elementCnt = 0;
15263    uint8_t   ret = RFAILED;
15264    F1AP_PDU_t *f1apMsg = NULLP;
15265    asn_enc_rval_t  encRetVal;
15266    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
15267
15268    DU_LOG("\nINFO  -->  F1AP : Building UE context modification response\n");
15269
15270    while(1)
15271    {
15272       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15273       if(f1apMsg == NULLP)
15274       {
15275          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
15276          break;
15277       }
15278
15279       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
15280
15281       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
15282       if(f1apMsg->choice.successfulOutcome == NULLP)
15283       {
15284          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
15285          break;
15286       }
15287       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextModification;
15288       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
15289       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_UEContextModificationResponse;
15290
15291       ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
15292   
15293       if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
15294       {
15295          if(ueCb->f1UeDb->duUeCfg.numDrbSetupMod)
15296             elementCnt =3;
15297          else
15298             elementCnt =2;
15299       }
15300       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15301          elementCnt = 5;
15302       if(ueCb->f1UeDb->actionType == UE_CTXT_RRC_RECFG_COMPLETE)
15303          elementCnt = 2;
15304       ueContextModifyRes->protocolIEs.list.count = elementCnt;
15305       ueContextModifyRes->protocolIEs.list.size = elementCnt*sizeof(UEContextModificationResponse_t*);
15306
15307       /* Initialize the UE context modification members */
15308       DU_ALLOC(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
15309       if(ueContextModifyRes->protocolIEs.list.array == NULLP)
15310       {
15311          DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
15312          break;
15313       }
15314
15315       for(ieIdx=0 ; ieIdx<elementCnt; ieIdx++)
15316       {
15317          DU_ALLOC(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
15318          if(ueContextModifyRes->protocolIEs.list.array[ieIdx] == NULLP)
15319          {
15320             DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
15321             break;
15322          }
15323       }
15324
15325       ieIdx=0;
15326       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
15327       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15328       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
15329       UEContextModificationResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
15330       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
15331
15332       ieIdx++;
15333       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
15334       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15335       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present=\
15336       UEContextModificationResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
15337       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
15338
15339       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15340       {
15341          ieIdx++;
15342          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCInformation;
15343          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15344          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
15345          UEContextModificationResponseIEs__value_PR_DUtoCURRCInformation;
15346          BuildCellGroupConfigRrc(ueCb, &ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
15347       }
15348
15349       if((ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY) || ((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbSetupMod)))
15350       { 
15351          ieIdx++;
15352          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_SetupMod_List;
15353          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15354          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
15355                                                                            UEContextModificationResponseIEs__value_PR_DRBs_SetupMod_List;
15356          if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15357          {
15358             for(tnlIdx = 0; tnlIdx < duCb.numTeId; tnlIdx++)
15359             {
15360                if(duCb.upTnlCfg[tnlIdx]->ueId == ueCb->gnbDuUeF1apId)
15361                {
15362                   memcpy(&ueCb->f1UeDb->duUeCfg.upTnlInfo[ueCb->f1UeDb->duUeCfg.numDrbSetupMod++], duCb.upTnlCfg[tnlIdx], sizeof(UpTnlCfg));
15363                }
15364             }
15365          }
15366          ret = BuildDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
15367                   value.choice.DRBs_SetupMod_List) , &ueCb->f1UeDb->duUeCfg);
15368          if(ret != ROK)
15369          {
15370             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB setupmod List ");
15371             break;
15372          }
15373       }
15374
15375       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15376       {
15377          ieIdx++;
15378          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_SRBs_SetupMod_List;
15379          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15380          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
15381                                                                             UEContextModificationResponseIEs__value_PR_SRBs_SetupMod_List;
15382          for(rbIdx = 0; rbIdx < ueCb->rlcUeCfg.numLcs; rbIdx++)
15383          {
15384             if(ueCb->rlcUeCfg.rlcLcCfg[rbIdx].rbType == RB_TYPE_SRB)
15385             {
15386                memcpy(&ueCb->f1UeDb->duUeCfg.rlcLcCfg[ueCb->f1UeDb->duUeCfg.numRlcLcs++], &ueCb->rlcUeCfg.rlcLcCfg[rbIdx],\
15387                      sizeof(RlcBearerCfg));
15388             }
15389          }
15390          ret = BuildSrbSetupModList(&ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.SRBs_SetupMod_List, \
15391                &ueCb->f1UeDb->duUeCfg);
15392          if(ret != ROK)
15393          {
15394             DU_LOG( "\nERROR  -->  F1AP : Failed to build SRB setupmod List ");
15395             break;
15396          }
15397       }
15398
15399       freeF1UeDb(ueCb->f1UeDb);
15400       ueCb->f1UeDb = NULLP;
15401
15402       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15403
15404       /* Encode the F1SetupRequest type as APER */
15405       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15406       encBufSize = 0;
15407       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,encBuf);
15408
15409       /* Encode results */
15410       if(encRetVal.encoded == ENCODE_FAIL)
15411       {
15412          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Request structure (at %s)\n",\
15413                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15414          ret = RFAILED;
15415          break;
15416       }
15417       else
15418       {
15419          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Modification Response\n");
15420          for(int i=0; i< encBufSize; i++)
15421          {
15422             printf("%x",encBuf[i]);
15423          }
15424       }
15425
15426       /* Sending  msg  */
15427       if(sendF1APMsg() != ROK)
15428       {
15429          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Res Failed");
15430          ret = RFAILED;
15431          break;
15432       }
15433
15434       ret = ROK;
15435       break;
15436    }
15437    FreeUeContextModResp(f1apMsg);
15438    return ret;
15439 }
15440 /*******************************************************************
15441  *
15442  * @brief Deallocating the memory allocated by the aper decoder
15443  *          for QOSInfo
15444  *
15445  * @details
15446  *
15447  *    Function : freeAperDecodeQosInfo
15448  *
15449  *    Functionality:  Deallocating the memory allocated for QOSInfo
15450  *
15451  * @params[in] QoSFlowLevelQoSParameters_t *drbQos
15452  *
15453  * @return void
15454  *
15455  * ****************************************************************/
15456
15457 void freeAperDecodeQosInfo(QoSFlowLevelQoSParameters_t *drbQos)
15458 {
15459    if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI != NULLP)
15460    {
15461       if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
15462       {
15463          if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
15464          {
15465             free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
15466          }
15467          free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
15468       }
15469       free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI);
15470    }
15471 }
15472 /*******************************************************************
15473  *
15474  * @brief Deallocating the memory allocated by the aper decoder
15475  *          for UlTnlInfoforDrb
15476  *
15477  * @details
15478  *
15479  *    Function : freeAperDecodeUlTnlInfoforDrbSetupMod 
15480  *
15481  *    Functionality:  Deallocating memory allocated for UlTnlInfoforDrb
15482  *
15483  * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
15484  *
15485  * @return void
15486  *
15487  * ****************************************************************/
15488 void freeAperDecodeUlTnlInfoforDrbSetupMod(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
15489 {
15490    uint8_t arrIdx =0;
15491
15492    if(ulInfo->list.array)
15493    {
15494       for(arrIdx=0; arrIdx<ulInfo->list.count ; arrIdx++)
15495       {
15496          if(ulInfo->list.array[arrIdx])
15497          {
15498             if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel )
15499             {
15500                if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf)
15501                {
15502                   if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf)
15503                   {
15504                      free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
15505                            gTP_TEID.buf);
15506                   }
15507                   free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
15508                         transportLayerAddress.buf);
15509                }
15510                free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel);
15511             }
15512             free(ulInfo->list.array[arrIdx]);
15513          }
15514       }
15515       free(ulInfo->list.array);
15516    }
15517 }
15518 /*******************************************************************
15519  *
15520  * @brief Deallocating the memory allocated by the aper decoder
15521  *          for DrbSetupModItem  
15522  *
15523  * @details
15524  *
15525  *    Function : freeAperDecodeDrbSetupModItem 
15526  *
15527  *    Functionality:  Deallocating memory allocated for DrbSetupModItem
15528  *
15529  * @params[in] DRBs_ToBeSetupMod_Item_t *drbItem
15530  *
15531  * @return void
15532  *
15533  * ****************************************************************/
15534
15535 void freeAperDecodeDrbSetupModItem(DRBs_ToBeSetupMod_Item_t *drbItem)
15536 {
15537    uint8_t arrIdx =0;
15538    SNSSAI_t *snssai =NULLP;
15539    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
15540
15541    drbItem->qoSInformation.present = QoSInformation_PR_choice_extension;
15542    switch(drbItem->qoSInformation.present)
15543    {
15544       case QoSInformation_PR_NOTHING:
15545          break;
15546       case QoSInformation_PR_eUTRANQoS:
15547          {
15548             if(drbItem->qoSInformation.choice.eUTRANQoS)
15549             {
15550                free(drbItem->qoSInformation.choice.eUTRANQoS);
15551             }
15552             break;
15553          }
15554       case QoSInformation_PR_choice_extension:
15555          {
15556             if(drbItem->qoSInformation.choice.choice_extension)
15557             {
15558                freeAperDecodeQosInfo(&drbItem->qoSInformation.choice.choice_extension->value.choice.\
15559                      DRB_Information.dRB_QoS);
15560                snssai = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI;
15561                if(snssai->sST.buf)
15562                {
15563                   free(snssai->sST.buf);
15564                }
15565                if(snssai->sD)
15566                {
15567                   if(snssai->sD->buf)
15568                   {
15569                      free(snssai->sD->buf);
15570                   }
15571                   free(snssai->sD);
15572                }
15573
15574                flowMap = &drbItem->qoSInformation.choice.choice_extension->value.choice.\
15575                          DRB_Information.flows_Mapped_To_DRB_List;
15576                if(flowMap->list.array)
15577                {
15578                   for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
15579                   {
15580                      if(flowMap->list.array[arrIdx] )
15581                      {
15582                         freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
15583                         free(flowMap->list.array[arrIdx]);
15584                      }
15585                   }
15586                   free(flowMap->list.array);
15587                }
15588
15589                free(drbItem->qoSInformation.choice.choice_extension);
15590             }
15591             break;
15592          }
15593
15594    }
15595    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
15596    if(drbItem->uLConfiguration)
15597    {
15598       free(drbItem->uLConfiguration);
15599    }
15600 }
15601
15602 /*******************************************************************
15603  *
15604  * @brief Deallocating the memory allocated by the aper decoder
15605  *          for DrbToBeSetupModList
15606  *
15607  * @details
15608  *
15609  *    Function : freeAperDecodeDrbToBeSetupModList
15610  *
15611  *    Functionality:  Deallocating memory allocated for DrbToBeSetupModList
15612  *
15613  * @params[in] DRBs_ToBeSetupMod_List_t *drbSet
15614  *
15615  * @return void
15616  *
15617  * ****************************************************************/
15618
15619 void freeAperDecodeDrbToBeSetupModList(DRBs_ToBeSetupMod_List_t *drbSet)
15620 {
15621    uint8_t arrIdx =0;
15622    struct DRBs_ToBeSetupMod_ItemIEs *drbItemIe;
15623
15624    if(drbSet->list.array)
15625    {
15626       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
15627       {
15628          if(drbSet->list.array[arrIdx] != NULLP)
15629          {
15630             if(arrIdx == 0)
15631             {
15632                drbItemIe = (DRBs_ToBeSetupMod_ItemIEs_t *)drbSet->list.array[arrIdx];
15633                freeAperDecodeDrbSetupModItem(&(drbItemIe->value.choice.DRBs_ToBeSetupMod_Item));
15634             }
15635             free(drbSet->list.array[arrIdx]);
15636          }
15637       }
15638       free(drbSet->list.array);
15639    }
15640
15641 }
15642 /*******************************************************************
15643  *
15644  * @brief Deallocating the memory allocated by the aper decoder
15645  *          for UeContextModificationReqMsg
15646  *
15647  * @details
15648  *
15649  *    Function : freeAperDecodeUeContextModificationReqMsg
15650  *
15651  *    Functionality:  Deallocating memory allocated for
15652  *                  UeContextModificationReqMsg
15653  *
15654  * @params[in] UEContextModificationRequest_t *UeContextModifyReq
15655  *
15656  * @return void
15657  *
15658  * ****************************************************************/
15659 void freeAperDecodeUeContextModificationReqMsg(UEContextModificationRequest_t *ueContextModifyReq )
15660 {
15661    uint8_t arrIdx, ieId;
15662
15663    if(ueContextModifyReq->protocolIEs.list.array)
15664    {
15665       for( arrIdx = 0 ; arrIdx<ueContextModifyReq->protocolIEs.list.count ; arrIdx++)
15666       {
15667          if(ueContextModifyReq->protocolIEs.list.array[arrIdx])
15668          {
15669             ieId = ueContextModifyReq->protocolIEs.list.array[arrIdx]->id;
15670             switch(ieId)
15671             {
15672                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15673                   break;
15674                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15675                   break;
15676                case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
15677                   {
15678                      freeAperDecodeDrbToBeSetupModList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
15679                            value.choice.DRBs_ToBeSetupMod_List);
15680                      break;
15681                   }
15682                case ProtocolIE_ID_id_TransmissionActionIndicator:
15683                   break;
15684                case ProtocolIE_ID_id_RRCContainer:
15685                   {
15686                      free(ueContextModifyReq->protocolIEs.list.array[arrIdx]->value.choice.RRCContainer.buf);
15687                   }
15688             }
15689             free(ueContextModifyReq->protocolIEs.list.array[arrIdx]);
15690          }
15691       }
15692       free(ueContextModifyReq->protocolIEs.list.array);
15693    }
15694 }
15695 /*******************************************************************
15696  *
15697  * @brief processing the F1 UeContextModificationReq
15698  *
15699  * @details
15700  *
15701  *    Function : procF1UeContextModificationReq
15702  *
15703  *    Functionality:  processing the F1 UeContextModificationReq
15704  *
15705  * @params[in] F1AP_PDU_t *f1apMsg
15706  *
15707  * @return
15708  * ****************************************************************/
15709 uint8_t procF1UeContextModificationReq(F1AP_PDU_t *f1apMsg)
15710 {
15711    UEContextModificationRequest_t *ueContextModifyReq = NULLP;
15712    uint8_t  ret = ROK, ieIdx = 0, cellIdx=0;
15713    DuUeCb   *duUeCb = NULLP;
15714    DRBs_ToBeSetupMod_List_t *drbSetupModCfg;
15715    DRBs_ToBeModified_List_t *drbModifiedCfg;
15716    uint32_t gnbCuUeF1apId, gnbDuUeF1apId;
15717
15718    ueContextModifyReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextModificationRequest;
15719    for(ieIdx=0; (ieIdx < ueContextModifyReq->protocolIEs.list.count && ret == ROK); ieIdx++)
15720    {
15721       switch(ueContextModifyReq->protocolIEs.list.array[ieIdx]->id)
15722       {
15723          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15724             {
15725                gnbCuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
15726                break;
15727             }
15728          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15729             {
15730                gnbDuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
15731                for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
15732                {
15733                   if(duCb.actvCellLst[cellIdx])
15734                   {
15735                      if((duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbDuUeF1apId == gnbDuUeF1apId)&&\
15736                            (duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbCuUeF1apId == gnbCuUeF1apId))
15737                      {
15738                         duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1];
15739                         if(duUeCb->f1UeDb == NULLP)
15740                         {
15741                            DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
15742                            duUeCb->f1UeDb->cellIdx = cellIdx;
15743                            duUeCb->f1UeDb->actionType = UE_CTXT_MOD;
15744                         }
15745                         break;
15746                      }
15747                   }
15748                }
15749                if(duUeCb == NULLP)
15750                {
15751                   DU_LOG("\nERROR  -->  DU APP : wrong values of gnbCuUeF1apId and gnbDuUeF1apId ");
15752                   ret = RFAILED;
15753                }
15754                break;
15755             }
15756
15757          case ProtocolIE_ID_id_RRCContainer:
15758             {
15759                /* Filling Dl RRC Msg Info */
15760                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
15761                if(!duUeCb->f1UeDb->dlRrcMsg)
15762                {
15763                   DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
15764                         Memory allocation failed ");
15765                   ret = RFAILED;
15766                }
15767                else
15768                {
15769                   duUeCb->f1UeDb->dlRrcMsgPres = true;
15770                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
15771                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
15772                         &ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
15773                         value.choice.RRCContainer);
15774                }
15775
15776                break;
15777             }
15778
15779          case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
15780          case ProtocolIE_ID_id_DRBs_ToBeModified_List:
15781             {
15782                if(duUeCb->f1UeDb)
15783                {
15784                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present ==\
15785                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List)
15786                   {
15787                      drbSetupModCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
15788                                       choice.DRBs_ToBeSetupMod_List;
15789
15790                      if(extractDrbListToSetupMod(NULL, drbSetupModCfg, NULL, drbSetupModCfg->list.count,\
15791                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULL))
15792                      {
15793                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbSetupModList");
15794                         ret = RFAILED;
15795                      }
15796                   }
15797
15798                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
15799                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List)
15800
15801                   {
15802                      drbModifiedCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
15803                                       choice.DRBs_ToBeModified_List;
15804                      if(extractDrbListToSetupMod(NULL, NULL, drbModifiedCfg, drbModifiedCfg->list.count,\
15805                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, &duUeCb->rlcUeCfg))
15806                      {
15807                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
15808                         ret = RFAILED;
15809                      }
15810                   }
15811                }
15812                break;
15813             }
15814
15815          case ProtocolIE_ID_id_GNB_DUConfigurationQuery:
15816             {
15817                DU_LOG("\nINFO  -->  DU APP : Received GNB DU Configuration Query in UE Context Modification Request from CU");
15818                if(duUeCb->f1UeDb)
15819                {
15820                   duUeCb->f1UeDb->actionType = UE_CTXT_CFG_QUERY;
15821                }
15822                break;
15823             }
15824
15825          case ProtocolIE_ID_id_RRCReconfigurationCompleteIndicator:
15826             {
15827                if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.RRCReconfigurationCompleteIndicator == \
15828                   RRCReconfigurationCompleteIndicator_true)
15829                {
15830                   duUeCb->f1UeDb->actionType = UE_CTXT_RRC_RECFG_COMPLETE;
15831                }
15832                break;
15833             }
15834          case ProtocolIE_ID_id_TransmissionActionIndicator:
15835             {
15836                if(duUeCb->f1UeDb)
15837                {
15838                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.TransmissionActionIndicator  == TransmissionActionIndicator_stop)
15839                   {
15840                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = STOP_TRANSMISSION; 
15841                   }
15842                   else 
15843                   {
15844                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = RESTART_TRANSMISSION; 
15845                   }
15846                }
15847                break;
15848             }
15849
15850          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15851             {
15852                if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
15853                {
15854                   duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
15855                }
15856                break;
15857             }
15858               
15859       }
15860    }
15861
15862    if(ret != RFAILED) 
15863    {
15864       ret = duProcUeContextModReq(duUeCb);
15865    }
15866    freeAperDecodeUeContextModificationReqMsg(ueContextModifyReq);
15867    return ret; 
15868 }
15869
15870 /*****************************************************************i
15871 *
15872 * @brief Free memory allocated for UE Context Release Request
15873 *
15874 * @details
15875 *
15876 *    Function : FreeUeContextReleaseReq
15877 *
15878 *    Functionality:
15879 *         - Free memory allocated for UE Context Release Request
15880 *
15881 * @params[in] F1AP_PDU_t *f1apMsg
15882 * @return void 
15883 *
15884 * *************************************************************/
15885 void FreeUeContextReleaseReq(F1AP_PDU_t *f1apMsg)
15886 {
15887    uint8_t ieIdx;
15888    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
15889    
15890    if(f1apMsg)
15891    {
15892       if(f1apMsg->choice.initiatingMessage)
15893       {
15894          ueReleaseReq =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
15895          if(ueReleaseReq->protocolIEs.list.array)
15896          {
15897             for(ieIdx=0 ; ieIdx<ueReleaseReq->protocolIEs.list.count; ieIdx++)
15898             {
15899                DU_FREE(ueReleaseReq->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseRequest_t));
15900             }
15901             DU_FREE(ueReleaseReq->protocolIEs.list.array, ueReleaseReq->protocolIEs.list.size);
15902          }
15903          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
15904       }
15905       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
15906    }
15907
15908 }
15909 /*****************************************************************i
15910 *
15911 * @brief Build and Send UE Context Release Request  
15912 *
15913 * @details
15914 *
15915 *    Function : BuildAndSendUeContextReleaseReq
15916 *
15917 *    Functionality:
15918 *         - Build and Send UE Context Release Request 
15919 *
15920 * @params[in]
15921 * @return ROK     - success
15922 *         RFAILED - failure
15923 *
15924 * *************************************************************/
15925 uint8_t BuildAndSendUeContextReleaseReq(uint16_t cellId, uint8_t ueId)
15926 {
15927    bool memAllocFail = false;
15928    uint8_t ieIdx =0;
15929    uint8_t ret = RFAILED;
15930    uint16_t cellIdx =0;
15931    uint16_t crnti = 0;
15932    uint8_t  elementCnt = 0;
15933    uint32_t  gnbCuUeF1apId =0;   /* gNB-CU UE F1AP Id */
15934    uint32_t  gnbDuUeF1apId =0;   /* gNB-DU UE F1AP Id */
15935    asn_enc_rval_t encRetVal; 
15936    F1AP_PDU_t *f1apMsg = NULLP;
15937    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
15938
15939    DU_LOG("\nINFO  --> Building the UE Context Release Request");
15940    do
15941    {
15942       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15943       if(f1apMsg == NULLP)
15944       {
15945          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for f1apMsg");
15946          break;
15947       }
15948
15949       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
15950       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
15951       if(f1apMsg->choice.initiatingMessage == NULLP)
15952       {
15953          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for\
15954          initiatingMessage");   
15955          break;
15956       }
15957       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_UEContextReleaseRequest;
15958       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
15959       f1apMsg->choice.initiatingMessage->value.present = \
15960       InitiatingMessage__value_PR_UEContextReleaseRequest;
15961
15962       ueReleaseReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
15963
15964       elementCnt = 2;
15965
15966       ueReleaseReq->protocolIEs.list.count = elementCnt;
15967       ueReleaseReq->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseRequest_t *);
15968
15969       /* Initialize the F1Setup members */
15970       DU_ALLOC(ueReleaseReq->protocolIEs.list.array,ueReleaseReq->protocolIEs.list.size);
15971       if(ueReleaseReq->protocolIEs.list.array == NULLP)
15972       {
15973          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE array");
15974          break;
15975       }
15976       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
15977       {
15978          DU_ALLOC(ueReleaseReq->protocolIEs.list.array[ieIdx],\
15979                sizeof(UEContextReleaseRequest_t));
15980          if(ueReleaseReq->protocolIEs.list.array[ieIdx] == NULLP)
15981          {
15982             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE elements");
15983             memAllocFail = true;  
15984             break;
15985          }
15986       }
15987       if(memAllocFail == true)
15988          break;
15989
15990       /* Fetching Ue Cb Info*/
15991       GET_CELL_IDX(cellId, cellIdx);
15992       if(duCb.actvCellLst[cellIdx] == NULLP)
15993       {
15994          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): CellId[%d] does not exist", cellId);
15995          break;
15996       }
15997       else
15998       {
15999          GET_CRNTI(crnti, ueId);
16000          if(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].crnti != crnti)
16001          {
16002             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): crnti[%d] does not exist", crnti);
16003             break;
16004          }
16005          gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
16006          gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
16007       }
16008
16009       ieIdx=0; 
16010       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID; 
16011       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16012       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present = \
16013       UEContextReleaseRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
16014       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
16015       
16016       ieIdx++;
16017       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16018       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16019       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present =\
16020       UEContextReleaseRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
16021       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
16022       
16023       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16024
16025       /* Encode the F1SetupRequest type as APER */
16026       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16027       encBufSize = 0;
16028       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
16029       /* Encode results */
16030       if(encRetVal.encoded == ENCODE_FAIL)
16031       {
16032          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseRequest structure (at %s)\n",\
16033                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16034          break;
16035       }
16036       else
16037       {
16038          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseRequest\n");
16039          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
16040          {
16041             printf("%x",encBuf[ieIdx]);
16042          }
16043       }
16044
16045       /* Sending msg */
16046       if(sendF1APMsg() != ROK)
16047       {
16048          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Request failed");
16049          break;
16050       }
16051       ret = ROK;
16052       break;
16053    }while(true);
16054
16055    FreeUeContextReleaseReq(f1apMsg);
16056    return ret;
16057 }
16058 /*****************************************************************i
16059  *
16060  * @brief Free memory allocated for UE Context Release Complete
16061  *
16062  * @details
16063  *
16064  *    Function : FreeUeContextReleaseComplete
16065  *
16066  *    Functionality:
16067  *         - Free memory allocated for UE Context Release Complete
16068  *
16069  * @params[in] F1AP_PDU_t *f1apMsg
16070  * @return void
16071  *
16072  * *************************************************************/
16073 void FreeUeContextReleaseComplete(F1AP_PDU_t *f1apMsg)
16074 {
16075    uint8_t ieIdx;
16076    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
16077
16078    if(f1apMsg)
16079    {
16080       if(f1apMsg->choice.successfulOutcome)
16081       {
16082          ueReleaseComplete =&f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
16083          if(ueReleaseComplete->protocolIEs.list.array)
16084          {
16085             for(ieIdx=0 ; ieIdx<ueReleaseComplete->protocolIEs.list.count; ieIdx++)
16086             {
16087                DU_FREE(ueReleaseComplete->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseComplete_t));
16088             }
16089             DU_FREE(ueReleaseComplete->protocolIEs.list.array, ueReleaseComplete->protocolIEs.list.size);
16090          }
16091          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16092       }
16093       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
16094    }
16095
16096 }
16097 /*****************************************************************i
16098  *
16099  * @brief Build and Send UE Context Release Complete
16100  *
16101  * @details
16102  *
16103  *    Function : BuildAndSendUeContextReleaseComplete
16104  *
16105  *    Functionality:
16106  *         - Build and Send UE Context Release Complete
16107  *
16108  * @params[in]  cellId,  gnbCuUeF1apId, gnbDuUeF1apId
16109  * @return ROK     - success
16110  *         RFAILED - failure
16111  *
16112  * *************************************************************/
16113 uint8_t BuildAndSendUeContextReleaseComplete(uint16_t cellId, uint32_t gnbCuUeF1apId, uint32_t gnbDuUeF1apId)
16114 {
16115    bool memAllocFail = false;
16116    uint8_t ieIdx =0, ret = RFAILED, elementCnt = 0;
16117    asn_enc_rval_t encRetVal;
16118    F1AP_PDU_t *f1apMsg = NULLP;
16119    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
16120
16121    DU_LOG("\nINFO  --> Building the UE Context Release Complete");
16122    do
16123    {
16124       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
16125       if(f1apMsg == NULLP)
16126       {
16127          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for f1apMsg");
16128          break;
16129       }
16130
16131       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
16132       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16133       if(f1apMsg->choice.successfulOutcome == NULLP)
16134       {
16135          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for\
16136                successfulOutcome");
16137          break;
16138       }
16139       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextRelease;
16140       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
16141       f1apMsg->choice.successfulOutcome->value.present = \
16142       SuccessfulOutcome__value_PR_UEContextReleaseComplete;
16143
16144       ueReleaseComplete = &f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
16145
16146       elementCnt = 2;
16147       ueReleaseComplete->protocolIEs.list.count = elementCnt;
16148       ueReleaseComplete->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseComplete_t *);
16149
16150       /* Initialize the UE Release Complete members */
16151       DU_ALLOC(ueReleaseComplete->protocolIEs.list.array,ueReleaseComplete->protocolIEs.list.size);
16152       if(ueReleaseComplete->protocolIEs.list.array == NULLP)
16153       {
16154          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE array");
16155          break;
16156       }
16157       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
16158       {
16159          DU_ALLOC(ueReleaseComplete->protocolIEs.list.array[ieIdx],\
16160                sizeof(UEContextReleaseComplete_t));
16161          if(ueReleaseComplete->protocolIEs.list.array[ieIdx] == NULLP)
16162          {
16163             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE\
16164             elements");
16165             memAllocFail = true;
16166             break;
16167          }
16168       }
16169       if(memAllocFail == true)
16170          break;
16171
16172
16173       ieIdx=0;
16174       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
16175       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16176       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present = \
16177       UEContextReleaseCompleteIEs__value_PR_GNB_CU_UE_F1AP_ID;
16178       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
16179
16180       ieIdx++;
16181       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16182       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16183       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present =\
16184       UEContextReleaseCompleteIEs__value_PR_GNB_DU_UE_F1AP_ID;
16185       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
16186
16187       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16188
16189       /* Encode the F1SetupComplete type as APER */
16190       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16191       encBufSize = 0;
16192       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
16193       /* Encode results */
16194       if(encRetVal.encoded == ENCODE_FAIL)
16195       {
16196          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseComplete structure (at %s)\n",\
16197                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16198          break;
16199       }
16200       else
16201       {
16202          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseComplete\n");
16203          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
16204          {
16205             printf("%x",encBuf[ieIdx]);
16206          }
16207       }
16208
16209       /* Sending msg */
16210       if(sendF1APMsg() != ROK)
16211       {
16212          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Complete failed");
16213          break;
16214       }
16215       ret = ROK;
16216       break;
16217    }while(true);
16218    
16219    if((ret == ROK) && (duCb.actvCellLst[cellId-1]) && (duCb.actvCellLst[cellId-1]->cellStatus == DELETION_IN_PROGRESS) 
16220          && (duCb.actvCellLst[cellId-1]->numActvUes == 0))
16221    {
16222       ret = duSendCellDeletReq(cellId);
16223       if(ret != ROK)
16224       {
16225          DU_LOG("\nERROR  -->  F1AP: BuildAndSendUeContextReleaseComplete(): Failed to process cell\
16226                Delete req for CellId");
16227       }
16228    }
16229    FreeUeContextReleaseComplete(f1apMsg);
16230    return ret;
16231
16232 }
16233
16234 /*******************************************************************
16235 *
16236 * @brief added free part for the memory allocated by aper_decoder 
16237 *
16238 * @details
16239 *
16240 *    Function : freeAperDecodeUeContextReleaseCommand 
16241 *
16242 *    Functionality: added free part for the memory allocated by aper_decoder
16243 *
16244 * @params[in] F1AP_PDU_t *f1apMsg
16245 * @return void
16246 *
16247 * ****************************************************************/
16248 void freeAperDecodeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
16249 {
16250    uint8_t ieIdx=0;
16251    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
16252
16253    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
16254    
16255    if(ueContextReleaseCommand->protocolIEs.list.array)
16256    {
16257       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
16258       {
16259          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
16260          {
16261             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
16262             {
16263                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16264                   break;
16265                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16266                   break;
16267                case ProtocolIE_ID_id_Cause:
16268                   break;
16269                case ProtocolIE_ID_id_RRCContainer:
16270                {
16271                   if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
16272                   {
16273                      free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
16274                   }
16275                   break;
16276                }
16277                default :
16278                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
16279                        ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
16280                   break;
16281             }
16282          }
16283          free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]);
16284       }
16285       free(ueContextReleaseCommand->protocolIEs.list.array);
16286    }
16287 }
16288 /*******************************************************************
16289 *
16290 * @brief processing of UE Context Release Command
16291 *
16292 * @details
16293 *
16294 *    Function : procF1UeContextReleaseCommand 
16295 *
16296 *    Functionality: processing of UE Context Release Command
16297 *
16298 * @params[in] F1AP_PDU_t *f1apMsg
16299 * @return void
16300 *
16301 * ****************************************************************/
16302 uint8_t procF1UeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
16303 {
16304    uint8_t  ieIdx=0, ret=ROK, ueIdx=0;
16305    uint16_t cellIdx =0, cellId = 0;
16306    bool ueIdxFound = false;
16307    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0;
16308    DuUeCb   *duUeCb = NULLP;
16309    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
16310
16311    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
16312
16313    if(ueContextReleaseCommand->protocolIEs.list.array)
16314    {
16315       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
16316       {
16317          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
16318          {
16319             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
16320             {
16321                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16322                   {
16323                      gnbCuUeF1apId= ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
16324                                     value.choice.GNB_CU_UE_F1AP_ID;
16325                      break;
16326                   }
16327
16328                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16329                   {
16330                      gnbDuUeF1apId = ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
16331                                      value.choice.GNB_DU_UE_F1AP_ID;
16332                      break;
16333                   }
16334
16335                case ProtocolIE_ID_id_Cause:
16336                   {
16337                      for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
16338                      {
16339                         for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
16340                         {
16341                            if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
16342                                  (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId))
16343                            {
16344                               cellId = duCb.actvCellLst[cellIdx]->cellId;
16345                               duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
16346                               ueIdxFound = true;
16347                               break;
16348                            }
16349                         }
16350                         if(ueIdxFound == true)
16351                         {
16352                            break;
16353                         }
16354                      }
16355                      
16356                      if(!ueIdxFound)
16357                      {
16358                         DU_LOG("\nERROR  -->  F1AP: procF1UeContextReleaseCommand(): Ue Information is not available");
16359                         ret = RFAILED;
16360                      }
16361                      break;
16362                   }
16363
16364                case ProtocolIE_ID_id_RRCContainer:
16365                   {
16366                      if(ueIdxFound == true)  
16367                      {
16368                         DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
16369                         if(duUeCb->f1UeDb)
16370                         {
16371                            memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
16372                            duUeCb->f1UeDb->actionType = UE_CTXT_RELEASE;
16373                            duUeCb->f1UeDb->cellIdx = cellIdx;
16374                            /* Filling Dl RRC Msg Info */
16375                            DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
16376                            if(!duUeCb->f1UeDb->dlRrcMsg)
16377                            {
16378                               DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16379                                     Memory allocation failed ");
16380                               ret = RFAILED;
16381                            }
16382                            else
16383                            {
16384                               duUeCb->f1UeDb->dlRrcMsgPres = true;
16385                               memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
16386                               ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
16387                                     &ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
16388                                     value.choice.RRCContainer);
16389                            }
16390
16391                         }
16392                         else
16393                         {
16394                            DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16395                                  Memory allocation failed ");
16396                            ret = RFAILED;
16397
16398                         }
16399                      }
16400                      break;
16401                   }
16402                default :
16403                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
16404                         ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
16405                   break;
16406             }
16407          }
16408       }
16409    }
16410    if(ret != RFAILED)
16411    {
16412       duProcUeContextReleaseCommand(cellId, duUeCb);
16413    }
16414    freeAperDecodeUeContextReleaseCommand(f1apMsg);
16415    return ret;
16416 }
16417
16418 /**************************************************************
16419  *
16420  * @brief free the memory allocated by aper decoder for paging
16421  *
16422  * @details
16423  *
16424  *    Function : freeAperDecodePagingMsg
16425  *
16426  *    Functionality:
16427  *         - free the memory allocated by aper decoder for
16428  *         the paging f1ap msg
16429  *
16430  * @params[in] Paging_t   *paging
16431  * @return ROK     - success
16432  *         RFAILED - failure
16433  *
16434  ****************************************************************/
16435 void freeAperDecodePagingMsg(Paging_t   *paging)
16436 {
16437    uint8_t ieIdx, cellIdx;
16438    PagingCell_ItemIEs_t *pagingCellItemIes;
16439    PagingCell_Item_t *pagingCellItem;
16440    PagingCell_list_t  *pagingCelllist;
16441
16442    if(paging)
16443    {
16444       if(paging->protocolIEs.list.array)
16445       {
16446          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
16447          {
16448             if(paging->protocolIEs.list.array[ieIdx])
16449             {
16450                switch(paging->protocolIEs.list.array[ieIdx]->id)
16451                {
16452                   case ProtocolIE_ID_id_UEIdentityIndexValue:
16453                      {
16454                         free(paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10.buf);
16455                         break;
16456                      }
16457                   case ProtocolIE_ID_id_PagingIdentity:
16458                      {
16459                         if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present == PagingIdentity_PR_cNUEPagingIdentity)
16460                         {
16461                            if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)
16462                            {
16463                               if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->present == \
16464                                     CNUEPagingIdentity_PR_fiveG_S_TMSI)
16465                               {
16466                                  free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->choice.fiveG_S_TMSI.buf);
16467                               }
16468                               free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity);
16469                            }
16470                         }
16471                         break;
16472                      }
16473                   case ProtocolIE_ID_id_PagingCell_List:
16474                      {
16475                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list;
16476                         if(pagingCelllist->list.array)
16477                         {
16478                            for(cellIdx = 0; cellIdx < pagingCelllist->list.count; cellIdx++)
16479                            {
16480                               if(pagingCelllist->list.array[cellIdx])
16481                               {
16482                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellIdx];
16483                                  if(pagingCellItemIes->id == ProtocolIE_ID_id_PagingCell_Item)
16484                                  {
16485                                     pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
16486                                     free(pagingCellItem->nRCGI.pLMN_Identity.buf);
16487                                     free(pagingCellItem->nRCGI.nRCellIdentity.buf);
16488                                  }
16489                                  free(pagingCelllist->list.array[cellIdx]);
16490                               }
16491                            }
16492                            free(pagingCelllist->list.array);
16493                         }
16494                         break;
16495                      }
16496                }
16497                free(paging->protocolIEs.list.array[ieIdx]);
16498             }
16499          }
16500          free(paging->protocolIEs.list.array);
16501
16502       }
16503    }
16504 }
16505
16506 /**************************************************************
16507  *
16508  * @brief processing the paging f1ap msg received from CU 
16509  *
16510  * @details
16511  *
16512  *    Function : procPagingMsg
16513  *
16514  *    Functionality:
16515  *         - processing the paging f1ap msg received from CU
16516  *
16517  * @params[in] F1AP_PDU_t *f1apMsg
16518  * @return ROK     - success
16519  *         RFAILED - failure
16520  *
16521  *
16522  ****************************************************************/
16523 uint8_t procPagingMsg(F1AP_PDU_t *f1apMsg) 
16524 {
16525    uint8_t ieIdx = 0, cellListIdx = 0;
16526    uint64_t cellId = 0;
16527    Paging_t   *paging = NULLP;
16528    PagingCell_list_t  *pagingCelllist = NULLP;
16529    PagingCell_ItemIEs_t *pagingCellItemIes = NULLP;
16530    PagingCell_Item_t *pagingCellItem = NULLP;
16531    DuPagingMsg *tmpPagingParam = NULLP;
16532
16533    DU_LOG("\nINFO  --> DU APP : Processing the Paging Message");
16534    paging = &f1apMsg->choice.initiatingMessage->value.choice.Paging;
16535    if(paging)
16536    {
16537       if(paging->protocolIEs.list.array)
16538       {
16539          DU_ALLOC(tmpPagingParam, sizeof(DuPagingMsg));
16540          if(tmpPagingParam == NULLP)
16541          {
16542             DU_LOG("\nERROR  --> DU APP : Memory Allocation Failure in procPagingMsg");
16543             freeAperDecodePagingMsg(paging);
16544             return RFAILED;
16545          }
16546          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
16547          {
16548             if(paging->protocolIEs.list.array[ieIdx])
16549             {
16550                switch(paging->protocolIEs.list.array[ieIdx]->id)
16551                {
16552                   case ProtocolIE_ID_id_UEIdentityIndexValue:
16553                      {
16554                         bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10,\
16555                                          &tmpPagingParam->pagUeId);
16556                         break;
16557                      }
16558
16559                   case ProtocolIE_ID_id_PagingIdentity:
16560                      {
16561                         switch(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present)
16562                         {
16563                            case PagingIdentity_PR_cNUEPagingIdentity: 
16564                               {
16565                                  if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)  
16566                                  {
16567                                     bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.\
16568                                           cNUEPagingIdentity->choice.fiveG_S_TMSI, &tmpPagingParam->sTmsi);
16569
16570                                  }
16571                                  break;
16572                               }
16573                             case PagingIdentity_PR_rANUEPagingIdentity:
16574                                {
16575                                   /*TODO: This Identifier is specific to RAN Initiated Paging â€“ Connected Mode Paging*/
16576                                   break;
16577                                }
16578                             default:
16579                                {
16580                                   DU_LOG("ERROR  -->  DU APP: Invalid UE Paging Identity, Skipping this Paging Message:");
16581                                   continue;
16582                                }
16583                         }
16584                      }
16585
16586                   case ProtocolIE_ID_id_PagingDRX:
16587                      {
16588                         tmpPagingParam->pagingDrxPres = TRUE;
16589                         tmpPagingParam->pagingDrx = convertPagingCycleEnumToValue(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingDRX);
16590                         break;
16591                      }
16592
16593                   case ProtocolIE_ID_id_PagingPriority:
16594                      {
16595                         tmpPagingParam->pagPriority = paging->protocolIEs.list.array[ieIdx]->value.choice.PagingPriority;
16596                         break;
16597                      }
16598
16599                   case ProtocolIE_ID_id_PagingCell_List:
16600                      {
16601                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list; 
16602                         if(pagingCelllist->list.array)
16603                         {
16604                            for(cellListIdx = 0; cellListIdx < pagingCelllist->list.count; cellListIdx++)
16605                            {
16606                               if(pagingCelllist->list.array[cellListIdx])
16607                               {
16608                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellListIdx];
16609                                  pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
16610                                  bitStringToInt(&pagingCellItem->nRCGI.nRCellIdentity, &cellId);
16611                                  if(processPagingMsg(cellId, tmpPagingParam) != ROK)
16612                                  {
16613                                     DU_LOG("\nERROR  --> DU APP : Paging Processing Failed at CellId:%d",cellId);
16614                                     continue;
16615                                  }
16616                               }
16617                            }
16618                         }
16619                         break;
16620                      }
16621                    default:
16622                      {
16623                          DU_LOG("\nERROR  --> F1AP : Incorrect Paging IE option");
16624                          break;
16625                      }
16626                }
16627             }
16628          }
16629       }
16630    }
16631    DU_FREE(tmpPagingParam, sizeof(DuPagingMsg));
16632    freeAperDecodePagingMsg(paging);
16633   
16634    return ROK;
16635 }
16636
16637 /**************************************************************
16638  *
16639  * @brief Handles received F1AP message and sends back response  
16640  *
16641  * @details
16642  *
16643  *    Function : F1APMsgHdlr
16644  *
16645  *    Functionality:
16646  *         - Decodes received F1AP control message
16647  *         - Prepares response message, encodes and sends to SCTP
16648  *
16649  * @params[in] 
16650  * @return ROK     - success
16651  *         RFAILED - failure
16652  *
16653  * ****************************************************************/
16654 void F1APMsgHdlr(Buffer *mBuf)
16655 {
16656    int i =0;
16657    char *recvBuf =NULLP;
16658    MsgLen copyCnt =0;
16659    MsgLen recvBufLen =0;
16660    F1AP_PDU_t *f1apMsg =NULLP;
16661    asn_dec_rval_t rval; /* Decoder return value */
16662    F1AP_PDU_t f1apasnmsg ;
16663    DU_LOG("\nINFO  -->  F1AP : Received F1AP message buffer");
16664    ODU_PRINT_MSG(mBuf, 0,0);
16665
16666    /* Copy mBuf into char array to decode it */
16667    ODU_GET_MSG_LEN(mBuf, &recvBufLen);
16668    DU_ALLOC(recvBuf, (Size)recvBufLen);
16669
16670    if(recvBuf == NULLP)
16671    {
16672       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed");
16673       return;
16674    }
16675    if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
16676    {
16677       DU_LOG("\nERROR   -->  F1AP : Failed while copying %d", copyCnt);
16678       return;
16679    }
16680
16681    printf("\nDEBUG   -->  F1AP : Received flat buffer to be decoded : ");
16682    for(i=0; i< recvBufLen; i++)
16683    {
16684       printf("%x",recvBuf[i]);
16685    }
16686
16687    /* Decoding flat buffer into F1AP messsage */
16688    f1apMsg = &f1apasnmsg;
16689    memset(f1apMsg, 0, sizeof(F1AP_PDU_t));
16690
16691    rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0);
16692
16693    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
16694    {
16695       DU_LOG("\nERROR  -->  F1AP : ASN decode failed");
16696       return;
16697    }
16698    printf("\n");
16699    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16700
16701    switch(f1apMsg->present)
16702    {
16703       case F1AP_PDU_PR_successfulOutcome:
16704          {
16705             switch(f1apMsg->choice.successfulOutcome->value.present)
16706             {
16707                case SuccessfulOutcome__value_PR_ResetAcknowledge:
16708                   {
16709                      DU_LOG("\nINFO   -->  F1AP : F1ResetAcknowledge is received successfully ");
16710                      break;
16711                   }
16712                case SuccessfulOutcome__value_PR_F1SetupResponse:
16713                   {                             
16714 #ifndef ODU_TEST_STUB
16715                      procF1SetupRsp(f1apMsg, recvBufLen, recvBuf);
16716 #endif
16717                      break;
16718                   }
16719
16720                case SuccessfulOutcome__value_PR_GNBDUConfigurationUpdateAcknowledge:
16721                   {
16722                      procF1GNBDUCfgUpdAck(f1apMsg);
16723                      break;
16724                   }
16725
16726                default:
16727                   {
16728                      DU_LOG("\nERROR  -->  F1AP : Invalid type of SuccessfulOutcome__value_PR_ResetAcknowledge [%d]",\
16729                            f1apMsg->choice.successfulOutcome->value.present);
16730                      return;
16731                   }
16732             }/* End of switch(successfulOutcome) */
16733             free(f1apMsg->choice.successfulOutcome);
16734             break;
16735          }
16736       case F1AP_PDU_PR_initiatingMessage:
16737          {
16738             switch(f1apMsg->choice.initiatingMessage->value.present)
16739             {
16740                case InitiatingMessage__value_PR_Reset:
16741                   {
16742                      procF1ResetReq(f1apMsg);
16743                      break;
16744                   }
16745                case InitiatingMessage__value_PR_DLRRCMessageTransfer:
16746                   {
16747                      procF1DlRrcMsgTrans(f1apMsg);
16748                      break;
16749                   }
16750                case InitiatingMessage__value_PR_UEContextSetupRequest:
16751                   {
16752                      procF1UeContextSetupReq(f1apMsg);
16753                      break;
16754                   }
16755                case InitiatingMessage__value_PR_UEContextModificationRequest:
16756                   {
16757                      procF1UeContextModificationReq(f1apMsg);
16758                      break;
16759                   }
16760                case InitiatingMessage__value_PR_UEContextReleaseCommand:
16761                   {
16762                       procF1UeContextReleaseCommand(f1apMsg);
16763                       break;
16764                   }
16765                case InitiatingMessage__value_PR_Paging:
16766                   {
16767                      procPagingMsg(f1apMsg);
16768                      break;
16769                   }
16770                default:
16771                   {
16772                      DU_LOG("\nERROR  -->  F1AP : Invalid type of F1AP_PDU_PR_initiatingMessage [%d]",
16773                            f1apMsg->choice.initiatingMessage->value.present);
16774                      return;
16775                   }
16776             }/* End of switch(initiatingMessage) */
16777             free(f1apMsg->choice.initiatingMessage);
16778             break;
16779          }
16780
16781       default:
16782          {
16783             DU_LOG("\nERROR  -->  F1AP : Invalid type of f1apMsg->present [%d]",f1apMsg->present);
16784             return;
16785          }
16786          free(f1apMsg);
16787
16788    }/* End of switch(f1apMsg->present) */
16789    
16790    DU_FREE(recvBuf, (Size)recvBufLen);
16791 } /* End of F1APMsgHdlr */
16792
16793 /**********************************************************************
16794   End of file
16795  **********************************************************************/