[Epic-ID: ODUHIGH-406][Task-ID: ODUHIGH-423] Fixes in DU APP to support cell ID other...
[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 "lrg.h"
22 #include "legtp.h"
23 #include "lkw.x"
24 #include "lrg.x"
25 #include "F1AP-PDU.h"
26 #include "du_app_mac_inf.h"
27 #include "du_cfg.h"
28 #include "du_app_rlc_inf.h"
29 #include "du_mgr_main.h"
30 #include "du_utils.h"
31 #include "RAT-Type.h"
32 #include "FeatureSetUplinkPerCC.h"
33 #include "FeatureSetDownlinkPerCC.h"
34 #include "FeatureSets.h"
35 #include "UE-NR-Capability.h"
36 #include "UE-CapabilityRAT-Container.h"
37 #include "UE-CapabilityRAT-ContainerListRRC.h"
38 #include "GNB-DU-System-Information.h"
39 #include "CellGroupConfigRrc.h"
40 #include "MAC-CellGroupConfig.h"
41 #include "SchedulingRequestConfig.h"
42 #include "SchedulingRequestToAddMod.h"
43 #include "BSR-Config.h"
44 #include "TAG-Config.h"
45 #include "TAG.h"
46 #include "PHR-Config.h"
47 #include "RLC-Config.h"
48 #include "UL-AM-RLC.h"
49 #include "DL-AM-RLC.h"
50 #include "LogicalChannelConfig.h"
51 #include "RLC-BearerConfig.h"
52 #include "PhysicalCellGroupConfig.h"
53 #include "SpCellConfig.h"
54 #include "TDD-UL-DL-ConfigDedicated.h"
55 #include "ServingCellConfig.h"
56 #include "ControlResourceSet.h"
57 #include "SearchSpace.h"
58 #include "PDCCH-Config.h"
59 #include "PDSCH-TimeDomainResourceAllocation.h"
60 #include "PDSCH-TimeDomainResourceAllocationList.h"
61 #include "PDSCH-CodeBlockGroupTransmission.h"
62 #include "PDSCH-ServingCellConfig.h"
63 #include "DMRS-DownlinkConfig.h"
64 #include "PDSCH-Config.h"
65 #include "BWP-DownlinkDedicated.h"
66 #include "BWP-Downlink.h"
67 #include "PUSCH-TimeDomainResourceAllocation.h"
68 #include "PUSCH-TimeDomainResourceAllocationList.h"
69 #include "DMRS-UplinkConfig.h"
70 #include "PUSCH-Config.h"
71 #include "SRS-ResourceId.h"
72 #include "SRS-Resource.h"
73 #include "SRS-ResourceSet.h"
74 #include "SRS-Config.h"
75 #include "BWP-UplinkDedicated.h"
76 #include "PUSCH-ServingCellConfig.h"
77 #include "UplinkConfig.h"
78 #include "DUtoCURRCContainer.h"
79 #include "GBR-QoSFlowInformation.h"
80 #include "QoSFlowLevelQoSParameters.h"
81 #include "PUCCH-Config.h"
82 #include "PUCCH-ResourceSet.h"
83 #include "PUCCH-Resource.h"
84 #include "PUCCH-PowerControl.h"
85 #include "P0-PUCCH.h"
86 #include "PUCCH-PathlossReferenceRS.h"
87 #include "PUCCH-format0.h"
88 #include "PUCCH-format1.h"
89 #include "PUCCH-format2.h"
90 #include "PUCCH-format3.h"
91 #include "PUCCH-format4.h"
92 #include "PUCCH-FormatConfig.h"
93 #include "SchedulingRequestResourceConfig.h"
94 #include<ProtocolIE-Field.h>
95 #include "ProtocolExtensionField.h"
96 #include "odu_common_codec.h"
97 #include "du_mgr.h"
98 #include "du_cell_mgr.h"
99 #include "du_f1ap_msg_hdl.h"
100 #include "DRBs-Setup-Item.h"
101 #include "DLUPTNLInformation-ToBeSetup-List.h"
102 #include "DLUPTNLInformation-ToBeSetup-Item.h"
103 #include "UPTransportLayerInformation.h"
104 #include "GTPTunnel.h"
105 #include "SupportedSULFreqBandItem.h"
106 #include "du_sys_info_hdl.h"
107 #include "du_e2ap_msg_hdl.h"
108 #include "du_f1ap_conversions.h"
109
110 #ifdef O1_ENABLE
111 #include "CmInterface.h"
112 extern StartupConfig g_cfg;
113 #endif
114
115 DuCfgParams duCfgParam;
116
117 /******************************************************************
118  *
119  * @brief Function to fetch lcId based on DRB Id
120  *
121  * @details
122  *
123  *    Function : fetchLcId
124  *
125  *    @params[in] drbId
126  *
127  *    Functionality: Function to fetch lcId based on DRB Id
128  *
129  * Returns: lcId - SUCCESS
130  *          RFAILED - FAILURE
131  *****************************************************************/
132
133 uint8_t fetchLcId(uint8_t drbId)
134 {
135    uint8_t cellIdx = 0, ueIdx = 0, lcIdx = 0, numLcs = 0, lcId = 0;
136
137    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
138    {
139       for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
140       {
141          if(duCb.actvCellLst[cellIdx] != NULLP)
142          {
143             numLcs = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg.numLcs;
144             for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
145             {
146                if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg.rlcLcCfg[lcIdx].rbId == drbId && \
147                   duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg.rlcLcCfg[lcIdx].rbType == RB_TYPE_DRB)
148                {
149                   lcId = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg.rlcLcCfg[lcIdx].lcId;
150                   return lcId;
151                }
152             }
153          }
154       }
155    }
156    DU_LOG("\nERROR   -->  DU_APP: fetchLcId() failed for drbId %d", drbId);
157    return RFAILED;
158 }
159
160 /*******************************************************************
161 *
162 * @brief Adding F1AP pdu to reserved pdu list
163 *
164 * @details
165 *
166 *    Function : addToReservedF1apPduList 
167 *
168 *    Functionality: Adding F1AP pdu to reserved pdu list.
169 *     These pdu are awaiting aknowledgment from CU
170 *
171 * @params[in] uint8_t transId, F1AP_PDU_t *f1apMsg
172 *
173 * @return ROK - success
174 *         RFAILED - failure
175 *
176 * ****************************************************************/
177 void addToReservedF1apPduList(uint8_t transId, F1AP_PDU_t *f1apPdu)
178 {
179    CmLList         *node = NULLP;
180    ReservedF1apPduInfo *pduInfo = NULLP;
181    DU_ALLOC(pduInfo, sizeof(ReservedF1apPduInfo));
182    if(pduInfo)
183    {
184       DU_ALLOC(node, sizeof(CmLList));
185       if(node)
186       {
187          pduInfo->transId = transId;
188          pduInfo->f1apMsg = (void*) f1apPdu;
189
190          node->node = (PTR)pduInfo;
191          cmLListAdd2Tail(&duCb.reservedF1apPduList, node);
192       }
193    }
194 }
195
196 /*******************************************************************
197 *
198 * @brief searching for F1AP pdu from ReservedF1apPduList 
199 *
200 * @details
201 *
202 *    Function : searchFromReservedF1apPduList 
203 *
204 *    Functionality: searching for F1AP pdu information
205 *
206 * @params[in] uint8_t transId
207 *
208 * @return pointer to F1AP_PDU_t
209 *
210 * ****************************************************************/
211
212 CmLList *searchFromReservedF1apPduList(uint8_t transId)
213 {
214    CmLList         *node;
215    ReservedF1apPduInfo *f1apPdu;
216    if(duCb.reservedF1apPduList.count)
217    {
218       CM_LLIST_FIRST_NODE(&duCb.reservedF1apPduList, node);
219       while(node)
220       {
221          f1apPdu = (ReservedF1apPduInfo*)node->node;
222          if(f1apPdu->transId == transId)
223          {
224             return node;
225          }
226          node = node->next;
227       }
228    }
229    return NULL;
230 }
231
232 /*******************************************************************
233 *
234 * @brief deleting F1AP pdu information from ReservedF1apPduList
235 *
236 * @details
237 *
238 *    Function : deleteFromReservedF1apPduList 
239 *
240 *    Functionality: deleting pdu information from ReservedF1apPduList
241 *
242 * @params[in] CmLList *node 
243 *
244 * @return void 
245 *
246 * ****************************************************************/
247
248 void deleteFromReservedF1apPduList(CmLList *node)
249 {
250    ReservedF1apPduInfo *f1apPdu;
251
252    if(node != NULL)
253    {
254       f1apPdu = (ReservedF1apPduInfo *)node->node;
255       cmLListDelFrm(&duCb.reservedF1apPduList, node);
256       DU_FREE(f1apPdu, sizeof(ReservedF1apPduInfo));
257       DU_FREE(node, sizeof(CmLList));
258       node = NULL;
259    }
260 }
261
262 /*******************************************************************
263  *
264  * @brief Builds Uplink Info for NR 
265  *
266  * @details
267  *
268  *    Function : BuildULNRInfo
269  *
270  *    Functionality: Building NR Uplink Info
271  *
272  * @params[in] NRFreqInfo_t *ulnrfreq
273  * @return ROK     - success
274  *         RFAILED - failure
275  *
276  * ****************************************************************/
277 uint8_t BuildULNRInfo(NRFreqInfo_t *ulnrfreq)
278 {
279    uint8_t idx=0;
280    ulnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
281                        fdd.ulNrFreqInfo.nrArfcn;
282    ulnrfreq->freqBandListNr.list.count = 1;
283    ulnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
284    DU_ALLOC(ulnrfreq->freqBandListNr.list.array,ulnrfreq->freqBandListNr.list.size);
285    if(ulnrfreq->freqBandListNr.list.array == NULLP)
286    {
287       return RFAILED;
288    }
289    for(idx=0;idx<ulnrfreq->freqBandListNr.list.count;idx++)
290    {
291       DU_ALLOC(ulnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
292       if(ulnrfreq->freqBandListNr.list.array[idx] == NULLP)
293       {
294          return RFAILED;
295       }
296    }
297    ulnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
298                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
299                                                                  freqBand[0].nrFreqBand;
300    ulnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
301    return ROK;
302 }
303 /*******************************************************************
304  *
305  * @brief Builds Downlink NR Info 
306  *
307  * @details
308  *
309  *    Function : BuildDLNRInfo
310  *
311  *    Functionality: Building Downlink NR Info
312  *    
313  * @params[in] NRFreqInfo_t *dlnrfreq
314  * @return ROK     - success
315  *         RFAILED - failure
316  *
317  * ****************************************************************/
318 uint8_t BuildDLNRInfo(NRFreqInfo_t *dlnrfreq)
319 {
320    uint8_t idx=0;
321    dlnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
322                        fdd.dlNrFreqInfo.nrArfcn;
323    dlnrfreq->freqBandListNr.list.count = 1;
324    dlnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
325    DU_ALLOC(dlnrfreq->freqBandListNr.list.array,dlnrfreq->freqBandListNr.list.size);
326    if(dlnrfreq->freqBandListNr.list.array == NULLP)
327    {
328       return RFAILED;   
329    }
330    for(idx=0;idx< dlnrfreq->freqBandListNr.list.count;idx++)
331    {
332       DU_ALLOC(dlnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
333       if(dlnrfreq->freqBandListNr.list.array[idx] == NULLP)
334       {
335          return RFAILED;
336       }
337    }   
338    dlnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
339                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
340                                                                  freqBand[0].nrFreqBand;
341    dlnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
342
343    return ROK;
344 }
345
346 /*******************************************************************
347  *
348  * @brief Builds NRCell ID 
349  *
350  * @details
351  *
352  *    Function : BuildNrCellId
353  *
354  *    Functionality: Building the NR Cell ID
355  *
356  * @params[in] BIT_STRING_t *nrcell
357  * @return ROK     - success
358  *         RFAILED - failure
359  *
360  * ****************************************************************/
361
362 S16 BuildNrCellId(BIT_STRING_t *nrcell)
363 {
364    memset(nrcell->buf, 0, nrcell->size);
365    nrcell->buf[4]   = duCfgParam.sib1Params.cellIdentity; 
366    nrcell->bits_unused = 4;
367    return ROK;
368 }
369
370 /*******************************************************************
371  *
372  * @brief Builds Nrcgi 
373  *
374  * @details
375  *
376  *    Function : BuildNrcgi
377  *
378  *    Functionality: Building the PLMN ID and NR Cell id
379  *
380  * @params[in] NRCGI_t *nrcgi
381  * @return ROK     - success
382  *         RFAILED - failure
383  *
384  * ****************************************************************/
385 uint8_t BuildNrcgi(NRCGI_t *nrcgi)
386 {
387    uint8_t ret;
388    uint8_t byteSize = 5;
389    /* Allocate Buffer Memory */
390    nrcgi->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
391    DU_ALLOC(nrcgi->pLMN_Identity.buf, nrcgi->pLMN_Identity.size);
392    if(nrcgi->pLMN_Identity.buf == NULLP)
393    {
394       return RFAILED;
395    }
396    ret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
397          nrcgi->pLMN_Identity.buf); // Building PLMN function
398    if(ret != ROK)
399    {
400       return RFAILED;
401    }
402    /*nrCellIdentity*/
403    nrcgi->nRCellIdentity.size = byteSize * sizeof(uint8_t);
404    DU_ALLOC(nrcgi->nRCellIdentity.buf, nrcgi->nRCellIdentity.size); 
405    if(nrcgi->nRCellIdentity.buf == NULLP)
406    {
407       return RFAILED;
408    }
409    BuildNrCellId(&nrcgi->nRCellIdentity);
410
411    return ROK;
412 }
413 /*******************************************************************
414  *
415  * @brief Builds FiveGStac 
416  *
417  * @details
418  *
419  *    Function : BuildFiveGSTac
420  *
421  *    Functionality: Building the FiveGSTac
422  *
423  * @params[in] OCTET_STRING_t *fivegsTac
424  * @return ROK     - success
425  *         RFAILED - failure
426  *
427  * ****************************************************************/
428 uint8_t BuildFiveGSTac(Served_Cell_Information_t *servcell)
429 {
430    DU_ALLOC(servcell->fiveGS_TAC,sizeof(FiveGS_TAC_t));
431    if(servcell->fiveGS_TAC == NULLP)
432    {
433       return RFAILED;
434    }
435    servcell->fiveGS_TAC->size = 3 * sizeof(uint8_t);
436    DU_ALLOC(servcell->fiveGS_TAC->buf,\
437          sizeof(servcell->fiveGS_TAC->size));
438    if(servcell->fiveGS_TAC->buf == NULLP)
439    {
440       return RFAILED;
441    }
442    servcell->fiveGS_TAC->buf[0] = 0;
443    servcell->fiveGS_TAC->buf[1] = 0;
444    servcell->fiveGS_TAC->buf[2] = duCfgParam.srvdCellLst[0].duCellInfo.tac;
445    return ROK;  
446 }
447
448 /*******************************************************************
449  *
450  * @brief fill nr frequency information
451  *
452  * @details
453  *
454  *    Function : fillNrTddInfo 
455  *
456  *    Functionality: fill nr frequency information
457  *
458  * @params[in] NRFreqInfo_t freqInfo
459  * @return ROK     - success
460  *         RFAILED - failure
461  *
462  * ****************************************************************/
463 uint8_t fillNrTddInfo(TDD_Info_t *tddInfo)
464 {
465    uint8_t elementCnt = 1, freqBandListIdx = 0, supportedBandIdx = 0;
466    NRFreqInfo_t *freqInfo = NULLP;
467
468    if(tddInfo == NULLP)
469    {
470       DU_LOG("\nERROR  --> DU APP : Null pointer received at fillNrTddInfo");
471       return RFAILED;
472    }
473    
474    freqInfo = &tddInfo->nRFreqInfo;
475    freqInfo->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.nrArfcn; 
476
477    freqInfo->freqBandListNr.list.count = elementCnt; 
478    freqInfo->freqBandListNr.list.size = freqInfo->freqBandListNr.list.count  * sizeof(FreqBandNrItem_t *);
479    DU_ALLOC(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
480    if(!freqInfo->freqBandListNr.list.array)
481    {
482       DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
483       return RFAILED;
484    }
485
486    for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
487    {
488       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
489       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx])
490       {
491          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
492          return RFAILED;
493       }
494
495       freqInfo->freqBandListNr.list.array[freqBandListIdx]->freqBandIndicatorNr = duCfgParam.srvdCellLst[0].duCellInfo.\
496       f1Mode.mode.tdd.nrFreqInfo.freqBand[0].nrFreqBand;
497       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count = elementCnt;
498       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size = freqInfo->freqBandListNr.list.array[freqBandListIdx]->\
499       supportedSULBandList.list.count * sizeof(SupportedSULFreqBandItem_t*);
500
501       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
502             freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
503       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
504       {
505          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
506          return RFAILED;
507       }
508
509       for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
510       {
511          DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
512                sizeof(SupportedSULFreqBandItem_t));
513          if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx])
514          {
515             DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
516             return RFAILED;
517          }
518
519          freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx]->freqBandIndicatorNr =\
520          duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[0].sulBand[0];
521       }
522    }
523
524    tddInfo->transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrScs;
525    tddInfo->transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrb;
526
527    return ROK;
528 }
529
530 /*******************************************************************
531  *
532  * @brief Builds NR Mode 
533  *
534  * @details
535  *
536  *    Function : BuildNrMode
537  *
538  *    Functionality: Building the NR Mode
539  *
540  * @params[in] NR_Mode_Info_t *fdd
541  * @return ROK     - success
542  *         RFAILED - failure
543  *
544  * ****************************************************************/
545 uint8_t BuildNrMode(NR_Mode_Info_t *mode)
546 {
547    uint8_t BuildDLNRInforet=0;
548    uint8_t BuildULNRInforet=0; 
549    
550 #ifdef NR_TDD
551    mode->present = NR_Mode_Info_PR_tDD;
552 #else
553    mode->present = NR_Mode_Info_PR_fDD;
554 #endif   
555    
556    if(mode->present == NR_Mode_Info_PR_fDD)
557    {
558       DU_ALLOC(mode->choice.fDD,sizeof(FDD_Info_t));
559       if(mode->choice.fDD == NULLP)
560       {
561          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
562          return RFAILED;
563       }
564       BuildULNRInforet = BuildULNRInfo(&mode->choice.fDD->uL_NRFreqInfo);
565       if(BuildULNRInforet != ROK)
566       {
567          DU_LOG("\nERROR  --> Failed to build UlNrFreqInfo");
568          return RFAILED;    
569       }
570       BuildDLNRInforet = BuildDLNRInfo(&mode->choice.fDD->dL_NRFreqInfo);
571       if(BuildDLNRInforet != ROK)
572       {
573          DU_LOG("\nERROR  --> Failed to build DlNrFreqInfo");
574          return RFAILED;
575       }
576       mode->choice.fDD->uL_Transmission_Bandwidth.nRSCS = \
577                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
578                                                           f1Mode.mode.fdd.ulTxBw.nrScs;
579       mode->choice.fDD->uL_Transmission_Bandwidth.nRNRB = \
580                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
581                                                           f1Mode.mode.fdd.ulTxBw.nrb;
582       mode->choice.fDD->dL_Transmission_Bandwidth.nRSCS = \
583                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
584                                                           f1Mode.mode.fdd.dlTxBw.nrScs;
585       mode->choice.fDD->dL_Transmission_Bandwidth.nRNRB = \
586                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
587                                                           f1Mode.mode.fdd.dlTxBw.nrb;
588    }
589    else if(mode->present == NR_Mode_Info_PR_tDD) 
590    {
591       DU_ALLOC(mode->choice.tDD,sizeof(TDD_Info_t));
592       if(mode->choice.tDD == NULLP)
593       {
594          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
595          return RFAILED;
596       }
597
598       if(fillNrTddInfo(mode->choice.tDD) != ROK)
599       {
600          DU_LOG("\nERROR  --> Failed to fill Nr TDD information");
601          return RFAILED;
602       }
603
604    }
605
606    return ROK;
607 }
608 /*******************************************************************
609  *
610  * @brief Builds IE Extensions for Served PLMNs 
611  *
612  * @details
613  *
614  *    Function : BuildExtensions
615  *
616  *    Functionality: Building the IE Extensions
617  *
618  * @params[in] struct ProtocolExtensionContainer_4624P3 *buildextend
619  * @return ROK     - success
620  *         RFAILED - failure
621  *
622  * ****************************************************************/
623 uint8_t BuildExtensions(ProtocolExtensionContainer_4624P3_t **ieExtend)
624 {
625    uint8_t idx=0, plmnidx=0, sliceLstIdx=0;
626    uint8_t elementCnt=0, extensionCnt=0;
627
628    extensionCnt=IE_EXTENSION_LIST_COUNT;
629    DU_ALLOC(*ieExtend,sizeof(ProtocolExtensionContainer_4624P3_t));
630    if((*ieExtend) == NULLP)
631    {
632       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
633       return RFAILED;
634    }
635    (*ieExtend)->list.count = extensionCnt;
636    (*ieExtend)->list.size = \
637                             extensionCnt * sizeof(ServedPLMNs_ItemExtIEs_t *);
638    DU_ALLOC((*ieExtend)->list.array,(*ieExtend)->list.size);
639    if((*ieExtend)->list.array == NULLP)
640    {
641       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
642       return RFAILED;
643    }
644    for(plmnidx=0;plmnidx<extensionCnt;plmnidx++)
645    {
646       DU_ALLOC((*ieExtend)->list.array[plmnidx],\
647             sizeof(ServedPLMNs_ItemExtIEs_t));
648       if((*ieExtend)->list.array[plmnidx] == NULLP)
649       {
650          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
651          return RFAILED;
652       }
653    }
654    
655    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices;
656    idx = 0;
657    (*ieExtend)->list.array[idx]->id = ProtocolIE_ID_id_TAISliceSupportList;
658    (*ieExtend)->list.array[idx]->criticality = Criticality_ignore;
659    (*ieExtend)->list.array[idx]->extensionValue.present = \
660    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
661    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
662       list.count = elementCnt;
663    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
664       list.size = (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
665       list.count * sizeof(SliceSupportItem_t *);
666
667    DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
668          list.array, elementCnt * sizeof(SliceSupportItem_t *));
669    if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
670          list.array == NULLP)
671    {
672       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
673       return RFAILED;
674    }
675
676    for(sliceLstIdx =0; sliceLstIdx<elementCnt; sliceLstIdx++)
677    {
678       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
679             list.array[sliceLstIdx],sizeof(SliceSupportItem_t));
680       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
681             list.array[sliceLstIdx] == NULLP) 
682       {
683          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
684          return RFAILED;
685       }
686       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
687          list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
688       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
689             .list.array[sliceLstIdx]->sNSSAI.sST.buf,(*ieExtend)->list.array[idx]->\
690             extensionValue.choice.SliceSupportList.\
691             list.array[sliceLstIdx]->sNSSAI.sST.size);
692       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
693             .list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
694       {
695          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
696          return RFAILED;
697       }
698       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
699          list.array[sliceLstIdx]->sNSSAI.sST.buf[0] = duCfgParam.srvdCellLst[0].duCellInfo.\
700          cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
701       
702       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
703             list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
704       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
705             list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
706       {
707          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
708          return RFAILED;
709       }
710       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
711          list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
712       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
713             list.array[sliceLstIdx]->sNSSAI.sD->buf, (*ieExtend)->list.array[idx]->extensionValue.choice.\
714             SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
715       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
716             list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
717       {
718          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
719          return RFAILED;
720       }
721       memcpy((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
722       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[0].duCellInfo.\
723       cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sd, (*ieExtend)->list.array[idx]->\
724       extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
725    }
726    return ROK;
727 }
728 /*******************************************************************
729  *
730  * @brief Builds Served PLMN 
731  *
732  * @details
733  *
734  *    Function : BuildServedPlmn
735  *
736  *    Functionality: Building the Served PLMN
737  *
738  * @params[in] GNB_DU_Served_Cells_Item_t *srvCellItem
739  * @return ROK     - success
740  *         RFAILED - failure
741  *
742  * ****************************************************************/
743 uint8_t  BuildServedPlmn(ServedPLMNs_List_t *srvplmn)
744 {  
745    uint8_t  plmnidx;
746    uint8_t  servPlmnCnt=1;
747    uint8_t buildPlmnIdret=0;
748    uint8_t BuildExtensionsret=0;
749    srvplmn->list.count = servPlmnCnt;
750    srvplmn->list.size = \
751                         servPlmnCnt*sizeof(ServedPLMNs_Item_t *);
752    DU_ALLOC(srvplmn->list.array,srvplmn->list.size);
753    if(srvplmn->list.array == NULLP)
754    {
755       return RFAILED;
756    }
757    for(plmnidx=0; plmnidx<servPlmnCnt; plmnidx++)
758    {   
759       DU_ALLOC(srvplmn->list.array[plmnidx],\
760             sizeof(ServedPLMNs_Item_t));
761       if(srvplmn->list.array[plmnidx] == NULLP)
762       {
763          return RFAILED;
764       }  
765    }
766    srvplmn->list.array[0]->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
767    DU_ALLOC(srvplmn->list.array[0]->pLMN_Identity.buf, srvplmn->list.array[0]->pLMN_Identity.size);
768    buildPlmnIdret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
769          srvplmn->list.array[0]->pLMN_Identity.buf);
770    if(buildPlmnIdret!= ROK)
771    {
772       return RFAILED;
773    }
774    BuildExtensionsret = BuildExtensions(&srvplmn->list.array[0]->iE_Extensions);
775    if(BuildExtensionsret!= ROK)
776    {
777       return RFAILED;
778    }
779    return ROK;
780 }
781 /*******************************************************************
782  *
783  * @brief Builds Served Cell List
784  *
785  * @details
786  *
787  *    Function : BuildServedCellList
788  *
789  *    Functionality: Building Served Cell List
790  *
791  * @params[in] PLMNID plmn
792  * @return ROK     - success
793  *         RFAILED - failure
794  *
795  * ****************************************************************/
796
797 uint8_t BuildServedCellList(GNB_DU_Served_Cells_List_t *duServedCell)
798 {
799    uint8_t  BuildNrcgiret=0;
800    uint8_t  BuildFiveGSTacret=0;
801    uint8_t  BuildServedPlmnret=0;
802    uint8_t  BuildNrModeret=0;
803    uint8_t  idx;
804    uint8_t  plmnidx;
805    uint8_t  plmnCnt=1;
806    GNB_DU_Served_Cells_Item_t *srvCellItem;
807    duServedCell->list.size = plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t *);
808    duServedCell->list.count = plmnCnt;
809
810    DU_ALLOC(duServedCell->list.array, duServedCell->list.size);
811    if(duServedCell->list.array == NULLP)
812    {
813       return RFAILED;
814    }
815    for(plmnidx=0; plmnidx<plmnCnt; plmnidx++)
816    {
817       DU_ALLOC(duServedCell->list.array[plmnidx],\
818             sizeof(GNB_DU_Served_Cells_ItemIEs_t));
819       if(duServedCell->list.array[plmnidx] == NULLP)
820       {
821          return RFAILED;
822       }
823    }
824    idx = 0;
825    duServedCell->list.array[idx]->id = ProtocolIE_ID_id_GNB_DU_Served_Cells_Item;
826    duServedCell->list.array[idx]->criticality = Criticality_reject;
827    duServedCell->list.array[idx]->value.present = \
828                                                   GNB_DU_Served_Cells_ItemIEs__value_PR_GNB_DU_Served_Cells_Item;
829    srvCellItem = \
830                  &duServedCell->list.array[idx]->value.choice.GNB_DU_Served_Cells_Item;
831    /*nRCGI*/
832    BuildNrcgiret = BuildNrcgi(&srvCellItem->served_Cell_Information.nRCGI);
833    if(BuildNrcgiret != ROK)
834    {
835       return RFAILED;
836    }
837    /*nRPCI*/
838    srvCellItem->served_Cell_Information.nRPCI = \
839                                                 duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
840
841    /*fiveGS_TAC*/
842    BuildFiveGSTacret = BuildFiveGSTac(&srvCellItem->served_Cell_Information);
843    if(BuildFiveGSTacret != ROK)
844    {
845       return RFAILED;
846    }
847    /*Served PLMNs*/
848    BuildServedPlmnret = BuildServedPlmn(&srvCellItem->served_Cell_Information.servedPLMNs);
849    if(BuildServedPlmnret !=ROK)
850    {
851       return RFAILED;
852    }
853    /*nR Mode Info with FDD*/
854    BuildNrModeret = BuildNrMode(&srvCellItem->served_Cell_Information.nR_Mode_Info);
855    if(BuildNrModeret != ROK)
856    {
857       return RFAILED;
858    }
859    /*Measurement timing Config*/
860    srvCellItem->served_Cell_Information.measurementTimingConfiguration.\
861       size = sizeof(uint8_t);
862    DU_ALLOC(srvCellItem->served_Cell_Information.\
863          measurementTimingConfiguration.buf,srvCellItem->served_Cell_Information.measurementTimingConfiguration.size);
864    if(srvCellItem->served_Cell_Information.\
865          measurementTimingConfiguration.buf == NULLP)
866    {
867       return RFAILED;
868    }
869    srvCellItem->served_Cell_Information.measurementTimingConfiguration.buf[0] = \
870                                                                                 duCfgParam.srvdCellLst[0].duCellInfo.measTimeCfg;
871
872    /* GNB DU System Information */
873    DU_ALLOC(srvCellItem->gNB_DU_System_Information,
874          sizeof(GNB_DU_System_Information_t));
875    if(!srvCellItem->gNB_DU_System_Information)
876    {
877       return RFAILED;
878    }
879    /* MIB */
880    srvCellItem->gNB_DU_System_Information->mIB_message.size = duCfgParam.srvdCellLst[0].duSysInfo.mibLen;
881    DU_ALLOC(srvCellItem->gNB_DU_System_Information->mIB_message.buf,
882          srvCellItem->gNB_DU_System_Information->mIB_message.size);
883    if(!srvCellItem->gNB_DU_System_Information->mIB_message.buf)
884    {
885       return RFAILED;
886    }
887    memcpy(srvCellItem->gNB_DU_System_Information->mIB_message.buf, duCfgParam.srvdCellLst[0].duSysInfo.mibMsg, \
888                    srvCellItem->gNB_DU_System_Information->mIB_message.size);
889
890    /* SIB1 */
891    srvCellItem->gNB_DU_System_Information->sIB1_message.size =\
892                                                               duCfgParam.srvdCellLst[0].duSysInfo.sib1Len;
893
894    DU_ALLOC(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,
895          srvCellItem->gNB_DU_System_Information->sIB1_message.size);
896    if(!srvCellItem->gNB_DU_System_Information->sIB1_message.buf)
897    {
898       return RFAILED;
899    }
900    for(int x=0; x<srvCellItem->gNB_DU_System_Information->sIB1_message.size; x++)
901    {
902       srvCellItem->gNB_DU_System_Information->sIB1_message.buf[x]=\
903                                                                   duCfgParam.srvdCellLst[0].duSysInfo.sib1Msg[x];
904    }
905    return ROK; 
906 }                                                                                                                  
907 /*******************************************************************
908  *
909  * @brief Builds RRC Version 
910  *
911  * @details
912  *
913  *    Function : BuildRrcVer
914  *
915  *    Functionality: Building RRC Version
916  *
917  * @params[in] int idx,int elementCnt,RRC_Version_t *rrcver
918  * @return ROK     - success
919  *         RFAILED - failure
920  *
921  * ****************************************************************/
922 uint8_t BuildRrcVer(RRC_Version_t *rrcVer)
923 {
924    uint8_t rrcExt;
925    uint8_t rrcLatest;
926    rrcVer->latest_RRC_Version.size = sizeof(uint8_t);
927    DU_ALLOC(rrcVer->latest_RRC_Version.buf,sizeof(uint8_t));
928    if(rrcVer->latest_RRC_Version.buf == NULLP)
929    {
930       return RFAILED;
931    }
932    rrcVer->latest_RRC_Version.buf[0] = 0;
933    rrcVer->latest_RRC_Version.bits_unused = 5;
934    DU_ALLOC(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
935    if(rrcVer->iE_Extensions == NULLP)
936    {  
937       return RFAILED;
938    }
939    rrcVer->iE_Extensions->list.count = 1;
940    rrcVer->iE_Extensions->list.size = sizeof(RRC_Version_ExtIEs_t *);
941    DU_ALLOC(rrcVer->iE_Extensions->list.array,rrcVer->iE_Extensions->list.size);
942    if(rrcVer->iE_Extensions->list.array == NULLP)
943    {
944       return RFAILED;
945    }
946    rrcExt = 0;
947    DU_ALLOC(rrcVer->iE_Extensions->list.array[0],\
948          sizeof(RRC_Version_ExtIEs_t));
949    if(rrcVer->iE_Extensions->list.array[0] == NULLP)
950    {
951       return RFAILED;
952    }
953    rrcVer->iE_Extensions->list.array[rrcExt]->id = \
954                                                    ProtocolIE_ID_id_latest_RRC_Version_Enhanced;
955    rrcVer->iE_Extensions->list.array[rrcExt]->criticality = Criticality_reject;
956    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.present =\
957                                                                       RRC_Version_ExtIEs__extensionValue_PR_Latest_RRC_Version_Enhanced;
958    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
959       .Latest_RRC_Version_Enhanced.size = 3*sizeof(uint8_t);
960    DU_ALLOC(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
961          .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
962          array[rrcExt]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
963    if(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
964          .Latest_RRC_Version_Enhanced.buf == NULLP)
965    {
966       return RFAILED;
967    }
968    rrcLatest = 0;
969    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
970       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 15;
971    rrcLatest++;
972    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
973       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 5;
974    rrcLatest++;
975    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
976       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 0;
977    return ROK;
978 }
979 /*******************************************************************
980  *
981  * @brief Sends F1 msg over SCTP
982  *
983  * @details
984  *
985  *    Function : sendF1APMsg
986  *
987  *    Functionality: Sends F1 msg over SCTP
988  *
989  * @params[in] Region region
990  *             Pool pool
991  * @return ROK     - success
992  *         RFAILED - failure
993  *
994  * ****************************************************************/
995 uint8_t sendF1APMsg()
996 {
997    Buffer *mBuf = NULLP;
998   
999    if(ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) == ROK)
1000    {
1001       if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
1002       {
1003             ODU_PRINT_MSG(mBuf, 0,0);
1004
1005             if(sctpSend(mBuf, F1_INTERFACE) != ROK)
1006             {
1007                DU_LOG("\nERROR  -->  F1AP : SCTP Send failed");
1008                ODU_PUT_MSG_BUF(mBuf);
1009                return RFAILED;
1010             }
1011       }
1012       else
1013       {
1014          DU_LOG("\nERROR  -->  F1AP : ODU_ADD_POST_MSG_MULT failed");
1015          ODU_PUT_MSG_BUF(mBuf);
1016          return RFAILED;
1017       }
1018       ODU_PUT_MSG_BUF(mBuf);
1019    }
1020    else
1021    {
1022       DU_LOG("\nERROR  -->  F1AP : Failed to allocate memory");
1023       return RFAILED;
1024    }
1025    return ROK; 
1026 } /* sendF1APMsg */
1027
1028 /*******************************************************************
1029  *
1030  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1031  *
1032  * @details
1033  *
1034  *    Function :  FreeRrcVer
1035  *
1036  *    Functionality: deallocating the memory of function BuildRrcVer
1037  *
1038  * @params[in] RRC_Version_t *rrcVer
1039  * 
1040  * @return void
1041  *
1042  *****************************************************************/
1043 void FreeRrcVer(RRC_Version_t *rrcVer)
1044 {
1045    if(rrcVer->latest_RRC_Version.buf != NULLP)
1046    {
1047       if(rrcVer->iE_Extensions != NULLP)
1048       {
1049          if(rrcVer->iE_Extensions->list.array != NULLP)
1050          {
1051             if(rrcVer->iE_Extensions->list.array[0] != NULLP)
1052             {
1053                if(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf
1054                      != NULLP)
1055                {
1056                   DU_FREE(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice\
1057                         .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1058                         array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1059                }
1060                DU_FREE(rrcVer->iE_Extensions->list.array[0],sizeof(RRC_Version_ExtIEs_t));
1061             }
1062             DU_FREE(rrcVer->iE_Extensions->list.array,sizeof(RRC_Version_ExtIEs_t*));
1063          }
1064          DU_FREE(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1065       }
1066       DU_FREE(rrcVer->latest_RRC_Version.buf,rrcVer->latest_RRC_Version.size);
1067    }
1068 }
1069
1070 /*******************************************************************
1071  *
1072  * @brief Deallocating memory of TDD NrFreqInfo 
1073  *
1074  * @details
1075  *
1076  *    Function : freeTddNrFreqInfo 
1077  *
1078  *    Functionality: freeTddNrFreqInfo 
1079  *
1080  * @params[in]  F1AP_PDU_t *f1apDuCfg
1081  *
1082  * @return ROK     - void
1083  *
1084  * ****************************************************************/
1085 void freeTddNrFreqInfo(NRFreqInfo_t *freqInfo)
1086 {
1087    uint8_t freqBandListIdx = 0, supportedBandIdx = 0;
1088
1089    if(freqInfo->freqBandListNr.list.array)
1090    {
1091       for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
1092       {
1093          if(freqInfo->freqBandListNr.list.array[freqBandListIdx])
1094          {
1095             if(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
1096             {
1097                for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
1098                {
1099                   DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
1100                         sizeof(SupportedSULFreqBandItem_t));
1101                }
1102                DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
1103                      freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
1104
1105             }
1106             DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
1107          }
1108       }
1109       DU_FREE(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
1110    }
1111 }
1112
1113 /*******************************************************************
1114  *
1115  * @brief Deallocating memory allocated for Nr fdd frequencey mode 
1116  *
1117  * @details
1118  *
1119  *    Function : freeFddNrFreqInfo 
1120  *
1121  *    Functionality:Free memory allocated for Nr fdd frequencey mode 
1122  *
1123  * @params[in]  
1124  *
1125  * @return ROK     - void
1126  *
1127  * ****************************************************************/
1128 void freeFddNrFreqInfo(FDD_Info_t *fDD)
1129 {
1130    uint8_t arrIdx =0;
1131
1132    if(fDD != NULLP)
1133    {
1134       if(fDD->uL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1135       {
1136          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.\
1137                array[arrIdx], sizeof(FreqBandNrItem_t));
1138          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.array, \
1139                fDD->uL_NRFreqInfo.freqBandListNr.list.size);
1140       }
1141
1142       if(fDD->dL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1143       {
1144          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.\
1145                array[arrIdx], sizeof(FreqBandNrItem_t));
1146          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.array,\
1147                fDD->dL_NRFreqInfo.freqBandListNr.list.size);
1148       }
1149       DU_FREE(fDD,sizeof(FDD_Info_t));
1150    }
1151 }
1152
1153 /*******************************************************************
1154  *
1155  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1156  *
1157  * @details
1158  *
1159  *    Function :  FreeServedCellList
1160  *
1161  *    Functionality:  deallocating the memory of function BuildServedCellList
1162
1163  *
1164  * @params[in] GNB_DU_Served_Cells_List_t *duServedCell
1165  *
1166  * @return void
1167  *
1168  * ****************************************************************/
1169 void FreeServedCellList( GNB_DU_Served_Cells_List_t *duServedCell)
1170 {
1171    uint8_t   plmnCnt=MAX_PLMN;
1172    uint8_t  extensionCnt=IE_EXTENSION_LIST_COUNT;
1173    uint8_t  plmnIdx=0, sliceIdx=0;
1174    GNB_DU_Served_Cells_Item_t *srvCellItem;
1175    ServedPLMNs_Item_t  *servedPlmnItem;
1176    SliceSupportItem_t  *sliceSupportItem;
1177
1178    if(duServedCell->list.array!=NULLP)
1179    {
1180       if(duServedCell->list.array[0]!=NULLP)
1181       {
1182          srvCellItem= &duServedCell->list.array[0]->value.choice.GNB_DU_Served_Cells_Item;
1183
1184          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1185                srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.size * sizeof(uint8_t));
1186          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1187                srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.size * sizeof(uint8_t));
1188
1189          if(srvCellItem->served_Cell_Information.fiveGS_TAC!=NULLP)
1190          {
1191             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC->buf,\
1192                   sizeof(srvCellItem->served_Cell_Information.fiveGS_TAC->size));
1193             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC,sizeof(FiveGS_TAC_t));
1194          }
1195
1196          if(srvCellItem->served_Cell_Information.servedPLMNs.list.array!=NULLP)
1197          {
1198             if(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx] != NULLP)
1199             {
1200                servedPlmnItem = srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx];
1201                DU_FREE(servedPlmnItem->pLMN_Identity.buf, servedPlmnItem->pLMN_Identity.size);
1202
1203                if(servedPlmnItem->iE_Extensions != NULLP)
1204                {
1205                   if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1206                   {
1207                      if(servedPlmnItem->iE_Extensions->list.array[0] != NULLP)
1208                      {
1209                         if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1210                               SliceSupportList.list.array != NULLP)
1211                         {
1212                            for(sliceIdx =0; sliceIdx<servedPlmnItem->iE_Extensions->list.array[0]->\
1213                                  extensionValue.choice.SliceSupportList.list.count; sliceIdx++)
1214                            {
1215                               if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1216                                     SliceSupportList.list.array[sliceIdx] != NULLP)
1217                               {
1218                                  sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[0]->\
1219                                                     extensionValue.choice.SliceSupportList.list.array[sliceIdx];
1220
1221                                  DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sizeof(uint8_t));
1222
1223                                  if(sliceSupportItem->sNSSAI.sD != NULLP)
1224                                  {
1225                                     DU_FREE(sliceSupportItem->sNSSAI.sD->buf,\
1226                                           sliceSupportItem->sNSSAI.sD->size);
1227                                     DU_FREE(sliceSupportItem->sNSSAI.sD, sizeof(OCTET_STRING_t));
1228                                  }
1229
1230                                  DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.\
1231                                        choice.SliceSupportList.list.array[sliceIdx], sizeof(SliceSupportItem_t));
1232                               }
1233                            }
1234                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1235                                  SliceSupportList.list.array, servedPlmnItem->iE_Extensions->list.array[0]->\
1236                                  extensionValue.choice.SliceSupportList.list.size);
1237                         }
1238                         DU_FREE(servedPlmnItem->iE_Extensions->list.array[0],\
1239                               sizeof(ServedPLMNs_ItemExtIEs_t));
1240                      }
1241                      DU_FREE(servedPlmnItem->iE_Extensions->list.array,\
1242                            extensionCnt*sizeof(ServedPLMNs_ItemExtIEs_t*));
1243                   }
1244                   DU_FREE(servedPlmnItem->iE_Extensions, sizeof(ProtocolExtensionContainer_4624P3_t));
1245                }
1246                DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx],\
1247                      sizeof(ServedPLMNs_Item_t));
1248             }
1249             DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array,\
1250                   sizeof(ServedPLMNs_Item_t *));
1251          }
1252
1253          if(srvCellItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1254          {
1255             freeFddNrFreqInfo(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1256          }
1257          else   
1258          {
1259             if(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD != NULLP)
1260             {
1261                freeTddNrFreqInfo(&srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1262                DU_FREE(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1263             }
1264          }
1265          
1266          DU_FREE(srvCellItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1267                srvCellItem->served_Cell_Information.measurementTimingConfiguration.size);
1268
1269          if(srvCellItem->gNB_DU_System_Information != NULLP)
1270          {
1271             if(srvCellItem->gNB_DU_System_Information->mIB_message.buf != NULLP)
1272             {
1273                DU_FREE(srvCellItem->gNB_DU_System_Information->mIB_message.buf,\
1274                      srvCellItem->gNB_DU_System_Information->mIB_message.size);
1275             }
1276
1277             if(srvCellItem->gNB_DU_System_Information->sIB1_message.buf != NULLP)
1278             { 
1279                DU_FREE(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,\
1280                      srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1281             }
1282
1283             DU_FREE(srvCellItem->gNB_DU_System_Information, sizeof(GNB_DU_System_Information_t));
1284          }
1285
1286          DU_FREE(duServedCell->list.array[0], sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1287       }
1288       DU_FREE(duServedCell->list.array, plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t*));
1289    }
1290 }
1291
1292 /*******************************************************************
1293  *
1294  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1295  *
1296  * @details
1297  *
1298  *    Function :  FreeF1SetupReq
1299  *
1300  *    Functionality:  deallocating the memory of function BuildAndSendF1SetupReq
1301  *
1302  * @params[in] F1AP_PDU_t *f1apMsg
1303  *
1304  * @return void
1305  *
1306  * ****************************************************************/
1307 void FreeF1SetupReq(F1AP_PDU_t *f1apMsg)
1308 {
1309    uint8_t ieIdx, ieIdx2;
1310    F1SetupRequest_t *f1SetupReq=NULLP;
1311
1312    if(f1apMsg != NULLP)
1313    {
1314       if(f1apMsg->choice.initiatingMessage != NULLP)
1315       {
1316          f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1317          if(f1SetupReq->protocolIEs.list.array != NULLP)
1318          {
1319             for(ieIdx = 0; ieIdx < f1SetupReq->protocolIEs.list.count; ieIdx++)
1320             {
1321                if(f1SetupReq->protocolIEs.list.array[ieIdx] != NULLP)
1322                {
1323                   switch(f1SetupReq->protocolIEs.list.array[ieIdx]->id)
1324                   {
1325                      case ProtocolIE_ID_id_TransactionID:
1326                         break;
1327                      case ProtocolIE_ID_id_gNB_DU_ID:
1328                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1329                               f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1330                         break;
1331                      case ProtocolIE_ID_id_gNB_DU_Name:
1332                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,\
1333                               strlen((char *)duCfgParam.duName));
1334                         break;
1335                      case ProtocolIE_ID_id_gNB_DU_Served_Cells_List:
1336                         FreeServedCellList(&f1SetupReq->protocolIEs.list.\
1337                               array[ieIdx]->value.choice.GNB_DU_Served_Cells_List);
1338                         break;
1339                      case ProtocolIE_ID_id_GNB_DU_RRC_Version:
1340                         FreeRrcVer(&f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version);
1341                         break;
1342                      default:
1343                         DU_LOG("\nERROR  -->  Invalid Event Type %ld", f1SetupReq->protocolIEs.list.array[ieIdx]->id);
1344                         break;
1345                   }
1346                }
1347             }
1348             for(ieIdx2=0; ieIdx2< ieIdx; ieIdx2++)
1349             {
1350                DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx2],sizeof(F1SetupRequestIEs_t));
1351             }
1352             DU_FREE(f1SetupReq->protocolIEs.list.array,\
1353                   f1SetupReq->protocolIEs.list.size);
1354          }
1355          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1356       }
1357       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
1358    }
1359 }
1360 /*******************************************************************
1361  *
1362  * @brief Builds and Send the F1SetupRequest
1363  *
1364  * @details
1365  *
1366  *    Function : BuildAndSendF1SetupReq
1367  *
1368  * Functionality:Fills the F1SetupRequest
1369  *
1370  * @return ROK     - success
1371  *         RFAILED - failure
1372  *
1373  ******************************************************************/
1374 uint8_t BuildAndSendF1SetupReq()
1375 {
1376    uint8_t   ret, ieIdx, elementCnt;
1377    F1AP_PDU_t                 *f1apMsg = NULLP;
1378    F1SetupRequest_t           *f1SetupReq=NULLP;
1379    GNB_DU_Served_Cells_List_t *duServedCell=NULLP;
1380    RRC_Version_t              *rrcVer=NULLP;
1381    asn_enc_rval_t             encRetVal;        /* Encoder return value */
1382    ret= RFAILED;
1383
1384    DU_LOG("\nINFO   -->  F1AP : Building F1 Setup Request\n");
1385    do
1386    {
1387       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
1388       if(f1apMsg == NULLP)
1389       {
1390          break;
1391       }
1392       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
1393       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1394       if(f1apMsg->choice.initiatingMessage == NULLP)
1395       {
1396          break;
1397       }
1398       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_F1Setup;
1399       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
1400       f1apMsg->choice.initiatingMessage->value.present = \
1401                                                          InitiatingMessage__value_PR_F1SetupRequest;
1402
1403       f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1404
1405       elementCnt = (duCfgParam.duName != NULL) ? 5 : 4;
1406
1407       f1SetupReq->protocolIEs.list.count = elementCnt;
1408       f1SetupReq->protocolIEs.list.size = elementCnt * sizeof(F1SetupRequestIEs_t );
1409
1410       /* Initialize the F1Setup members */
1411       DU_ALLOC(f1SetupReq->protocolIEs.list.array,f1SetupReq->protocolIEs.list.size);
1412       if(f1SetupReq->protocolIEs.list.array == NULLP)
1413       {
1414          break;
1415       }
1416       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
1417       {
1418          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx],\
1419                sizeof(F1SetupRequestIEs_t));
1420          if(f1SetupReq->protocolIEs.list.array[ieIdx] == NULLP)
1421          {
1422             break;
1423          }
1424       }
1425
1426       ieIdx = 0;
1427       /*TransactionID*/
1428       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_TransactionID;
1429       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1430       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present =\
1431                                                                F1SetupRequestIEs__value_PR_TransactionID;
1432       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = \
1433                                                                              TRANS_ID;
1434
1435       /*DU ID*/
1436       ieIdx++;
1437       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
1438       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1439       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1440                                                                 F1SetupRequestIEs__value_PR_GNB_DU_ID;
1441       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size =\
1442                                                                              sizeof(uint8_t);
1443
1444       DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1445             f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1446       if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == \
1447             NULLP)
1448       {
1449          break;
1450       }
1451
1452       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] =\
1453          duCfgParam.duId;
1454
1455       /*DU Name*/
1456       if(duCfgParam.duName != NULL)
1457       {
1458          ieIdx++;
1459          f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_Name;
1460          f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_ignore;
1461          f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = F1SetupRequestIEs__value_PR_GNB_DU_Name;
1462          f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size =\
1463             strlen((char *)duCfgParam.duName);
1464          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.\
1465                GNB_DU_Name.buf, strlen((char *)duCfgParam.duName));
1466          if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.\
1467                buf == NULLP)
1468          {
1469             break;
1470          }
1471          strcpy((char*)f1SetupReq->protocolIEs.list.array[ieIdx]->value.\
1472                choice.GNB_DU_Name.buf,
1473                (char*)&duCfgParam.duName);
1474
1475       }
1476
1477       /*Served Cell list */
1478       ieIdx++;
1479       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1480                                                      ProtocolIE_ID_id_gNB_DU_Served_Cells_List;
1481       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1482       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1483                                                                 F1SetupRequestIEs__value_PR_GNB_DU_Served_Cells_List;
1484       duServedCell = &f1SetupReq->protocolIEs.list.\
1485                      array[ieIdx]->value.choice.GNB_DU_Served_Cells_List;
1486       if(BuildServedCellList(duServedCell))
1487       {
1488          break;
1489       }
1490       /*RRC Version*/
1491       ieIdx++;
1492       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1493                                                      ProtocolIE_ID_id_GNB_DU_RRC_Version ;
1494       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1495       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1496                                                                 F1SetupRequestIEs__value_PR_RRC_Version;
1497       rrcVer = &f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
1498       if(BuildRrcVer(rrcVer))
1499       {
1500          break;
1501       }
1502       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
1503
1504       /* Encode the F1SetupRequest type as APER */
1505       memset(encBuf, 0, ENC_BUF_MAX_LEN);
1506       encBufSize = 0;
1507       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
1508             encBuf);
1509
1510       /* Encode results */
1511       if(encRetVal.encoded == ENCODE_FAIL)
1512       {
1513          DU_LOG("\nERROR  -->  F1AP : Could not encode F1SetupRequest structure (at %s)\n",\
1514                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1515          break;
1516       }
1517       else
1518       {
1519          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1SetupRequest\n");
1520          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
1521          {
1522             printf("%x",encBuf[ieIdx]);
1523          }
1524          
1525          duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize = encBufSize;
1526          DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, encBufSize);
1527          if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
1528          {
1529              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the encoding of f1setup req");
1530              return RFAILED;
1531          }
1532          memcpy(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, &encBuf, duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize);
1533       }
1534
1535       /* Sending msg */
1536       if(sendF1APMsg() != ROK)
1537       {
1538          DU_LOG("\nERROR  -->  F1AP : Sending F1 Setup request failed");
1539          break;
1540       }
1541
1542       ret=ROK;
1543       break;
1544    }while(true);
1545
1546    FreeF1SetupReq(f1apMsg);
1547
1548    return ret;
1549 }/* End of BuildAndSendF1SetupReq */
1550
1551 /*******************************************************************
1552  *
1553  * @brief Deallocating memory allocated for Served_Cells_To_Modify_Item_t
1554  *
1555  * @details
1556  *
1557  *    Function : freeCellsToModifyItem 
1558  *
1559  *    Functionality: Deallocating memory of variables allocated in
1560  *                    BuildAndSendDUConfigUpdate function
1561  *
1562  * @params[in]  Served_Cells_To_Modify_Item_t *modifyItem
1563  *
1564  * @return ROK     - void
1565  *
1566  * ****************************************************************/
1567
1568 void freeCellsToModifyItem(Served_Cells_To_Modify_Item_t *modifyItem)
1569 {
1570    uint8_t arrIdx=0, servedPlmnIdx=0, sliceLstIdx=0;
1571    ServedPLMNs_Item_t *servedPlmnItem = NULLP;
1572    SliceSupportItem_t *sliceSupportItem = NULLP;
1573
1574    DU_FREE(modifyItem->oldNRCGI.pLMN_Identity.buf, modifyItem->oldNRCGI.pLMN_Identity.size);
1575    DU_FREE(modifyItem->oldNRCGI.nRCellIdentity.buf, modifyItem->oldNRCGI.nRCellIdentity.size);
1576
1577    DU_FREE(modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1578            modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.size);
1579    DU_FREE(modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1580          modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.size);
1581
1582    if(modifyItem->served_Cell_Information.servedPLMNs.list.array != NULLP)
1583    {
1584       if(modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx] != NULLP)
1585       {
1586          servedPlmnItem = modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx];
1587
1588          DU_FREE(servedPlmnItem->pLMN_Identity.buf,servedPlmnItem->pLMN_Identity.size);
1589
1590          if(servedPlmnItem->iE_Extensions != NULLP)
1591          {
1592             if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1593             {
1594                if(servedPlmnItem->iE_Extensions->list.array[arrIdx] != NULLP)
1595                {
1596                   if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1597                         list.array != NULLP)
1598                   {
1599                      for(sliceLstIdx =0; sliceLstIdx<servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1600                            extensionValue.choice.SliceSupportList.list.count; sliceLstIdx++)
1601                      {
1602                         if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1603                               list.array[sliceLstIdx] != NULLP)
1604                         {
1605
1606                            sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1607                                               SliceSupportList.list.array[sliceLstIdx];
1608
1609                            DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sliceSupportItem->sNSSAI.sST.size);
1610                            if(sliceSupportItem->sNSSAI.sD != NULLP)
1611                            {
1612                               DU_FREE(sliceSupportItem->sNSSAI.sD->buf, sliceSupportItem->sNSSAI.sD->size);
1613                               DU_FREE(sliceSupportItem->sNSSAI.sD,sizeof(OCTET_STRING_t));
1614                            }
1615                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1616                                  SliceSupportList.list.array[sliceLstIdx], sizeof(SliceSupportItem_t));
1617                         }
1618                      }
1619                      DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.\
1620                            choice.SliceSupportList.list.array,\
1621                            servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1622                            extensionValue.choice.SliceSupportList.list.size);
1623                   }
1624                }
1625                for(servedPlmnIdx=0; servedPlmnIdx< servedPlmnItem->iE_Extensions->list.count ; servedPlmnIdx++)
1626                {
1627                   DU_FREE(servedPlmnItem->iE_Extensions->list.array[servedPlmnIdx], sizeof(ServedPLMNs_ItemExtIEs_t ));
1628                }
1629                DU_FREE(servedPlmnItem->iE_Extensions->list.array, servedPlmnItem->iE_Extensions->list.size);
1630             }
1631             DU_FREE(servedPlmnItem->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1632          }
1633       }
1634       for(servedPlmnIdx=0; servedPlmnIdx<modifyItem->served_Cell_Information.servedPLMNs.list.count; servedPlmnIdx++)
1635       {
1636          DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array[servedPlmnIdx], sizeof(ServedPLMNs_Item_t));
1637       }
1638       DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array,\
1639          modifyItem->served_Cell_Information.servedPLMNs.list.size);
1640    }
1641    
1642    if(modifyItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1643    {
1644       freeFddNrFreqInfo(modifyItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1645    }  
1646    else
1647    {
1648       if(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD)
1649       {
1650          freeTddNrFreqInfo(&modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1651          DU_FREE(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1652       }
1653    }
1654    DU_FREE(modifyItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1655       modifyItem->served_Cell_Information.measurementTimingConfiguration.size);
1656 }
1657
1658 /*******************************************************************
1659  *
1660  * @brief Deallocating memory of BuildAndSendDUConfigUpdate
1661  *
1662  * @details
1663  *
1664  *    Function : FreeDUConfigUpdate
1665  *
1666  *    Functionality: Deallocating memory of variables allocated in
1667  *                    BuildAndSendDUConfigUpdate function
1668  *
1669  * @params[in]  F1AP_PDU_t *f1apDuCfg
1670  *
1671  * @return ROK     - void
1672  *
1673  * ****************************************************************/
1674 void FreeDUConfigUpdate(F1AP_PDU_t *f1apDuCfg)
1675 {
1676    uint8_t  ieIdx=0, cellModifyIdx=0, cellDeleteIdx=0;
1677    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
1678    Served_Cells_To_Modify_List_t  *cellsToModify=NULLP;
1679    Served_Cells_To_Delete_List_t  *cellsToDelete=NULLP;
1680    Served_Cells_To_Delete_Item_t  *deleteItem = NULLP;
1681    Served_Cells_To_Delete_ItemIEs_t *deleteItemIe = NULLP;
1682
1683    if(f1apDuCfg != NULLP)
1684    {
1685       if(f1apDuCfg->choice.initiatingMessage != NULLP)
1686       {
1687          duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->\
1688                        value.choice.GNBDUConfigurationUpdate;
1689          if(duCfgUpdate->protocolIEs.list.array != NULLP)
1690          {
1691             for(ieIdx=0; ieIdx<duCfgUpdate->protocolIEs.list.count; ieIdx++)
1692             {
1693                if(duCfgUpdate->protocolIEs.list.array[ieIdx] != NULLP)
1694                {
1695                   switch(duCfgUpdate->protocolIEs.list.array[ieIdx]->id)
1696                   {
1697                      case ProtocolIE_ID_id_Served_Cells_To_Modify_List:
1698                         {
1699                            cellsToModify = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1700                                            value.choice.Served_Cells_To_Modify_List;
1701                            if(cellsToModify->list.array != NULLP)
1702                            {
1703                               for(cellModifyIdx=0; cellModifyIdx<cellsToModify->list.count ;cellModifyIdx++)
1704                               {
1705                                  if(cellsToModify->list.array[cellModifyIdx] != NULLP)
1706                                  {
1707                                     freeCellsToModifyItem(&cellsToModify->list.array[cellModifyIdx]->value.choice.\
1708                                           Served_Cells_To_Modify_Item);
1709                                     DU_FREE(cellsToModify->list.array[cellModifyIdx],\
1710                                           sizeof(Served_Cells_To_Modify_ItemIEs_t));
1711                                  }
1712                               }
1713                               DU_FREE(cellsToModify->list.array,cellsToModify->list.size);
1714                            }
1715                            break;
1716                         }
1717                      case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
1718                         {
1719                            cellsToDelete = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1720                                            value.choice.Served_Cells_To_Delete_List;
1721                            if(cellsToDelete->list.array != NULLP)
1722                            {
1723                               for(cellDeleteIdx=0; cellDeleteIdx<cellsToDelete->list.count ;cellDeleteIdx++)
1724                               {
1725                                  if(cellsToDelete->list.array[cellDeleteIdx] != NULLP)
1726                                  {
1727                                     deleteItemIe = ((Served_Cells_To_Delete_ItemIEs_t*)\
1728                                           cellsToDelete->list.array[cellDeleteIdx]);
1729                                     deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
1730                                     DU_FREE(deleteItem->oldNRCGI.pLMN_Identity.buf,\
1731                                           deleteItem->oldNRCGI.pLMN_Identity.size); 
1732                                     DU_FREE(deleteItem->oldNRCGI.nRCellIdentity.buf,\
1733                                           deleteItem->oldNRCGI.nRCellIdentity.size);
1734                                     DU_FREE(cellsToDelete->list.array[cellDeleteIdx],\
1735                                           sizeof(Served_Cells_To_Delete_ItemIEs_t));
1736                                  }
1737                               }
1738                               DU_FREE(cellsToDelete->list.array,cellsToDelete->list.size);
1739                            }
1740
1741                            break;
1742                         }
1743                      case ProtocolIE_ID_id_gNB_DU_ID:
1744                         {
1745                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1746                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1747                            break;
1748                         }
1749                   }
1750                   DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx],\
1751                         sizeof(GNBDUConfigurationUpdateIEs_t));
1752                }
1753             }
1754             DU_FREE(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
1755          }
1756          DU_FREE(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
1757       }
1758       DU_FREE(f1apDuCfg, (Size)sizeof(F1AP_PDU_t));
1759    }
1760 }
1761
1762 /*******************************************************************
1763  *
1764  * @brief Fills Served Plmns required in ServCellInfo IE
1765  *
1766  * @details
1767  *
1768  *    Function : fillServedPlmns
1769  *
1770  *    Functionality: Fills Served Plmns required in ServCellInfo IE
1771  *
1772  * @params[in] Pointer to ServedPLMNs_List_t *
1773  *
1774  * @return ROK     - success
1775  *         RFAILED - failure
1776  *
1777  *****************************************************************/
1778
1779 uint8_t fillServedPlmns(ServedPLMNs_List_t *servedPlmn)
1780 {
1781    uint8_t ieIdx=0, arrayIdx=0, ieListCnt=0, elementCnt=0, sliceLstIdx=0;
1782
1783    servedPlmn->list.array[arrayIdx]->pLMN_Identity.size = 3*sizeof(uint8_t);
1784    DU_ALLOC(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf, servedPlmn->list.\
1785          array[arrayIdx]->pLMN_Identity.size);
1786    if(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf == NULLP)
1787    {
1788       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1789       return RFAILED;
1790    }
1791    buildPlmnId(duCfgParam.srvdCellLst[arrayIdx].duCellInfo.cellInfo.srvdPlmn[arrayIdx].plmn,\
1792          servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf);
1793    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1794    if(servedPlmn->list.array[arrayIdx]->iE_Extensions == NULLP)
1795    {
1796       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1797       return RFAILED;
1798    }
1799
1800    ieListCnt=1;
1801    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.count = ieListCnt;
1802    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.size = ieListCnt *sizeof(ServedPLMNs_ItemExtIEs_t *);
1803    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array,servedPlmn->list.array[arrayIdx]->\
1804          iE_Extensions->list.size);
1805    if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array == NULLP)
1806    {
1807       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1808       return RFAILED;
1809    }
1810    for(ieIdx=arrayIdx;ieIdx<ieListCnt;ieIdx++)
1811    {
1812       DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx],\
1813             sizeof(ServedPLMNs_ItemExtIEs_t));
1814       if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx] == NULLP)
1815       {
1816          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1817          return RFAILED;
1818       }
1819    }
1820    
1821    ieIdx = 0;
1822    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices; 
1823    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->id =ProtocolIE_ID_id_TAISliceSupportList;
1824    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->criticality = Criticality_ignore;
1825    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.present = \
1826    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
1827    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1828       list.count = elementCnt;
1829    servedPlmn->list.array[arrayIdx]->\
1830       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1831       list.size = elementCnt * sizeof(SliceSupportItem_t *);
1832    DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1833          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1834          list.array,servedPlmn->list.array[arrayIdx]->\
1835          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.size);
1836    if(servedPlmn->list.array[arrayIdx]->\
1837          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1838          list.array == NULLP)
1839    {
1840       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1841       return RFAILED;
1842    }
1843
1844    for(sliceLstIdx =0; sliceLstIdx< elementCnt; sliceLstIdx++)
1845    {
1846       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1847       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1848       list.array[sliceLstIdx],sizeof( SliceSupportItem_t));
1849       if(servedPlmn->list.array[arrayIdx]->\
1850       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1851       list.array[sliceLstIdx] == NULLP)
1852       {   
1853          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1854          return RFAILED;
1855       }
1856       
1857       servedPlmn->list.array[arrayIdx]->\
1858       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1859       list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
1860       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1861       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1862       list.array[sliceLstIdx]->sNSSAI.sST.buf,servedPlmn->list.array[arrayIdx]->\
1863       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->\
1864       sNSSAI.sST.size);
1865       
1866       if(servedPlmn->list.array[arrayIdx]->\
1867       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1868       list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
1869       {
1870          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1871          return RFAILED;
1872       }
1873       servedPlmn->list.array[arrayIdx]->\
1874       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1875       list.array[sliceLstIdx]->sNSSAI.sST.buf[arrayIdx] =  duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
1876       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
1877
1878       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1879       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1880       list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
1881       if(servedPlmn->list.array[arrayIdx]->\
1882       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1883       list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
1884       {
1885          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1886          return RFAILED;
1887       }
1888       servedPlmn->list.array[arrayIdx]->\
1889       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1890       list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
1891       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1892       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1893       list.array[sliceLstIdx]->sNSSAI.sD->buf,servedPlmn->list.array[arrayIdx]->\
1894       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1895       list.array[sliceLstIdx]->sNSSAI.sD->size);
1896       if(servedPlmn->list.array[arrayIdx]->\
1897       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1898       list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
1899       {
1900          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1901          return RFAILED;
1902       }
1903       memcpy(servedPlmn->list.array[arrayIdx]->\
1904       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1905       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
1906       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sd,\
1907       servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1908       list.array[sliceLstIdx]->sNSSAI.sD->size);
1909    }
1910    return ROK;
1911 }
1912
1913 /*******************************************************************
1914  *
1915  * @brief Fills Nr Fdd Info required in ServCellInfo IE
1916  *
1917  * @details
1918  *
1919  *    Function : fillNrFddInfo
1920  *
1921  *    Functionality: Fills Nr Fdd Info required in ServCellInfo IE
1922  *
1923  * @params[in] FDD_Info_t *fDD
1924  *
1925  * @return ROK     - success
1926  *         RFAILED - failure
1927  *
1928  *****************************************************************/
1929
1930 uint8_t fillNrFddInfo(FDD_Info_t *fDD)
1931 {
1932    fDD->uL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.\
1933       f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn;
1934    fDD->uL_NRFreqInfo.freqBandListNr.list.count = 1;
1935    fDD->uL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t*);
1936    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.\
1937          array, fDD->uL_NRFreqInfo.freqBandListNr.list.size);
1938    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array == NULLP)
1939    {
1940       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
1941       return RFAILED;
1942    }
1943
1944    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0], \
1945       sizeof(FreqBandNrItem_t));
1946    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
1947    {
1948       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
1949       return RFAILED;
1950    }
1951    
1952    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
1953       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
1954       freqBand[0].nrFreqBand;
1955    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
1956    fDD->dL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.\
1957       dlNrFreqInfo.nrArfcn;
1958    fDD->dL_NRFreqInfo.freqBandListNr.list.count = 1;
1959    fDD->dL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
1960    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array, fDD->dL_NRFreqInfo.freqBandListNr.list.size);
1961    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array == NULLP)
1962    {
1963       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
1964       return RFAILED;
1965    }
1966    
1967    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0],  sizeof(FreqBandNrItem_t));
1968    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
1969    {
1970       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
1971       return RFAILED;
1972    }
1973
1974    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
1975       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
1976       freqBand[0].nrFreqBand;
1977    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
1978    
1979    /*Transmission Bandwidth*/
1980    fDD->uL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
1981       f1Mode.mode.fdd.ulTxBw.nrScs;
1982    fDD->uL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
1983       f1Mode.mode.fdd.ulTxBw.nrb;
1984    fDD->dL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
1985       f1Mode.mode.fdd.dlTxBw.nrScs;
1986    fDD->dL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
1987       f1Mode.mode.fdd.dlTxBw.nrb;
1988
1989    return ROK;
1990 }
1991
1992 /*******************************************************************
1993  *
1994  * @brief Fills ServCellInfo IE
1995  *
1996  * @details
1997  *
1998  *    Function : fillServedCellInfo
1999  *
2000  *    Functionality: Fills ServCellInfo
2001  *
2002  * @params[in] Pointer to Served_Cell_Information_t *
2003  *
2004  * @return ROK     - success
2005  *         RFAILED - failure
2006  *
2007  *****************************************************************/
2008
2009 uint8_t fillServedCellInfo(Served_Cell_Information_t *srvCellInfo)
2010 {
2011    uint8_t ieIdx, ieListCnt;
2012
2013    /*nRCGI*/
2014    srvCellInfo->nRCGI.pLMN_Identity.size =3*sizeof(uint8_t);
2015    DU_ALLOC(srvCellInfo->nRCGI.pLMN_Identity.buf,\
2016          srvCellInfo->nRCGI.pLMN_Identity.size);
2017    if(srvCellInfo->nRCGI.pLMN_Identity.buf == NULLP)
2018    {
2019       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2020       return RFAILED;
2021    }
2022    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2023          srvCellInfo->nRCGI.pLMN_Identity.buf);
2024    srvCellInfo->nRCGI.nRCellIdentity.size =5*sizeof(uint8_t);
2025    DU_ALLOC(srvCellInfo->nRCGI.nRCellIdentity.buf,\
2026          srvCellInfo->nRCGI.nRCellIdentity.size);
2027    if(srvCellInfo->nRCGI.nRCellIdentity.buf == NULLP)
2028    {   
2029       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2030       return RFAILED;
2031    }
2032    
2033    fillBitString(&srvCellInfo->nRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2034    /*nRPCI*/
2035    srvCellInfo->nRPCI = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
2036
2037    /*servedPLMNs*/
2038    ieListCnt = 1;
2039    srvCellInfo->servedPLMNs.list.count = ieListCnt;
2040    srvCellInfo->servedPLMNs.list.size = ieListCnt*sizeof(ServedPLMNs_Item_t *);
2041    DU_ALLOC(srvCellInfo->servedPLMNs.list.array, srvCellInfo->servedPLMNs.list.size);
2042    if(srvCellInfo->servedPLMNs.list.array == NULLP)
2043    {
2044       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2045       return RFAILED;
2046    }
2047    for(ieIdx=0; ieIdx < ieListCnt; ieIdx++)
2048    {
2049       DU_ALLOC(srvCellInfo->servedPLMNs.list.array[ieIdx], sizeof(ServedPLMNs_Item_t));
2050       if(srvCellInfo->servedPLMNs.list.array[ieIdx]== NULLP)
2051       {
2052          DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2053          return RFAILED;
2054       }
2055    }
2056    if(fillServedPlmns(&srvCellInfo->servedPLMNs))
2057    {
2058       DU_LOG("\nERROR  --> Failed to fill Served Plmn info");
2059       return RFAILED;
2060    }
2061
2062 #ifndef NR_TDD
2063    /*nR Mode Info with FDD*/
2064    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_fDD;
2065    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.fDD, sizeof(FDD_Info_t));
2066    if(srvCellInfo->nR_Mode_Info.choice.fDD == NULLP)
2067    {
2068       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2069       return RFAILED;
2070    }
2071    if(fillNrFddInfo(srvCellInfo->nR_Mode_Info.choice.fDD))
2072    {
2073        DU_LOG("\nERROR  --> Failed to fill the Nr FDD information");
2074       return RFAILED;
2075    }
2076 #else
2077    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_tDD;   
2078    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
2079    if(srvCellInfo->nR_Mode_Info.choice.tDD == NULLP)
2080    {
2081       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2082       return RFAILED;
2083    }
2084    if(fillNrTddInfo(srvCellInfo->nR_Mode_Info.choice.tDD) != ROK)
2085    {
2086       DU_LOG("\nERROR  --> Failed to fill the Nr TDD information");
2087       return RFAILED;
2088    }
2089 #endif
2090
2091    /*Measurement timing Config*/
2092    srvCellInfo->measurementTimingConfiguration.size = sizeof(uint8_t);
2093    DU_ALLOC(srvCellInfo->measurementTimingConfiguration.\
2094          buf,srvCellInfo->measurementTimingConfiguration.size);
2095    if(srvCellInfo->measurementTimingConfiguration.buf == NULLP)
2096    {
2097       return RFAILED;
2098    }
2099    srvCellInfo->measurementTimingConfiguration.\
2100          buf[0] = duCfgParam.srvdCellLst[0].duCellInfo.measTimeCfg;
2101
2102    return ROK;
2103 }
2104
2105 /*******************************************************************
2106  *
2107  * @brief Fills ServCellToModItem IE
2108  *
2109  * @details
2110  *
2111  *    Function : fillServCellToModItem
2112  *
2113  *    Functionality: Fills ServCellToModItem IE
2114  *
2115  * @params[in] Pointer to Served_Cells_To_Modify_Item_t *
2116  *
2117  * @return ROK     - success
2118  *         RFAILED - failure
2119  *
2120  *****************************************************************/
2121
2122 uint8_t fillServCellToModItem(Served_Cells_To_Modify_Item_t *modifyItem)
2123 {
2124    /*pLMN_Identity*/
2125    modifyItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2126    DU_ALLOC(modifyItem->oldNRCGI.pLMN_Identity.buf,modifyItem->oldNRCGI.pLMN_Identity.size);
2127    if(modifyItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2128    {
2129       return RFAILED;
2130    }
2131    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2132          modifyItem->oldNRCGI.pLMN_Identity.buf);
2133
2134    /*nRCellIdentity*/
2135    modifyItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2136    DU_ALLOC(modifyItem->oldNRCGI.nRCellIdentity.buf,\
2137          modifyItem->oldNRCGI.nRCellIdentity.size);
2138    if(modifyItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2139    {
2140       return RFAILED;
2141    }
2142    fillBitString(&modifyItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2143
2144    if(fillServedCellInfo(&modifyItem->served_Cell_Information))
2145       return RFAILED;
2146    else
2147       return ROK;
2148 }
2149
2150 /*******************************************************************
2151  *
2152  * @brief Builds ServCellToModList
2153  *
2154  * @details
2155  *
2156  *    Function : buildServCellToModList
2157  *
2158  *    Functionality: Builds the serv cell to Mod List
2159  *
2160  * @params[in] Pointer to Served_Cells_To_Modify_List_t *
2161  *
2162  * @return ROK     - success
2163  *         RFAILED - failure
2164  *
2165  *****************************************************************/
2166
2167 uint8_t buildServCellToModList(Served_Cells_To_Modify_List_t *cellsToModify)
2168 {
2169    uint8_t ieListCnt, ieIdx;
2170    Served_Cells_To_Modify_Item_t *modifyItem = NULLP;
2171
2172    ieListCnt = 1;
2173    cellsToModify->list.count = ieListCnt;
2174    cellsToModify->list.size = ieListCnt*sizeof(Served_Cells_To_Modify_ItemIEs_t *);
2175    DU_ALLOC(cellsToModify->list.array,cellsToModify->list.size);
2176    if(cellsToModify->list.array == NULLP)
2177    {
2178       return RFAILED;
2179    }
2180    for(ieIdx=0; ieIdx< ieListCnt; ieIdx++)
2181    {
2182       DU_ALLOC(cellsToModify->list.array[ieIdx],sizeof(Served_Cells_To_Modify_ItemIEs_t));
2183       if(cellsToModify->list.array[ieIdx] == NULLP)
2184       {
2185          return RFAILED;
2186       }
2187    }
2188    cellsToModify->list.array[0]->id = ProtocolIE_ID_id_Served_Cells_To_Modify_Item;
2189    cellsToModify->list.array[0]->criticality = Criticality_reject;
2190    cellsToModify->list.array[0]->value.present =\
2191       Served_Cells_To_Modify_ItemIEs__value_PR_Served_Cells_To_Modify_Item;
2192    modifyItem=&cellsToModify->list.array[0]->value.choice.Served_Cells_To_Modify_Item;
2193
2194    if(fillServCellToModItem(modifyItem))
2195       return RFAILED;
2196    else
2197       return ROK;
2198 }
2199 /*******************************************************************
2200  *
2201  * @brief filling the DeleteItemList
2202  *
2203  * @details
2204  *
2205  *    Function : fillCellToDeleteItem 
2206  *
2207  *    Functionality: Filling the DeleteItemIe 
2208  *
2209  * @params[in] Pointer to Served_Cells_To_Delete_ItemIEs_t 
2210  *
2211  * @return ROK     - success
2212  *         RFAILED - failure
2213  *
2214  *****************************************************************/
2215 uint8_t fillCellToDeleteItem(struct Served_Cells_To_Delete_ItemIEs *deleteItemIe)
2216 {
2217    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
2218    
2219    deleteItemIe->id = ProtocolIE_ID_id_Served_Cells_To_Delete_Item;
2220    deleteItemIe->criticality = Criticality_reject;
2221    deleteItemIe->value.present =\
2222    Served_Cells_To_Delete_ItemIEs__value_PR_Served_Cells_To_Delete_Item;
2223    deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
2224
2225    /*pLMN_Identity*/
2226    deleteItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2227    DU_ALLOC(deleteItem->oldNRCGI.pLMN_Identity.buf,deleteItem->oldNRCGI.pLMN_Identity.size);
2228    if(deleteItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2229    {
2230       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2231       return RFAILED;
2232    }
2233    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2234          deleteItem->oldNRCGI.pLMN_Identity.buf);
2235
2236    /*nRCellIdentity*/
2237    deleteItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2238    DU_ALLOC(deleteItem->oldNRCGI.nRCellIdentity.buf,\
2239          deleteItem->oldNRCGI.nRCellIdentity.size);
2240    if(deleteItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2241    {
2242       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2243       return RFAILED;
2244    }
2245    fillBitString(&deleteItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2246    return ROK;
2247
2248 /*******************************************************************
2249  *
2250  * @brief Builds ServCellToDeleteList
2251  *
2252  * @details
2253  *
2254  *    Function : buildServCellToDeleteList
2255  *
2256  *    Functionality: Builds the serv cell to delete List
2257  *
2258  * @params[in] Pointer to Served_Cells_To_Delete_List_t *
2259  *
2260  * @return ROK     - success
2261  *         RFAILED - failure
2262  *
2263  *****************************************************************/
2264  
2265 uint8_t buildServCellToDeleteList(Served_Cells_To_Delete_List_t *cellsToDelete)
2266 {
2267    uint8_t ieListCnt, arrIdx;
2268    
2269    ieListCnt = 1;
2270    cellsToDelete->list.count = ieListCnt;
2271    cellsToDelete->list.size = ieListCnt*sizeof(Served_Cells_To_Delete_ItemIEs_t *);
2272    
2273    DU_ALLOC(cellsToDelete->list.array,cellsToDelete->list.size);
2274    if(cellsToDelete->list.array == NULLP)
2275    {
2276       DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2277       return RFAILED;
2278    }
2279    
2280    for(arrIdx=0; arrIdx< ieListCnt; arrIdx++)
2281    {
2282       DU_ALLOC(cellsToDelete->list.array[arrIdx],sizeof(Served_Cells_To_Delete_ItemIEs_t));
2283       if(cellsToDelete->list.array[arrIdx] == NULLP)
2284       {
2285          DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2286          return RFAILED;
2287       }
2288    }
2289    
2290    arrIdx=0;
2291    if(fillCellToDeleteItem((Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx]) !=ROK)
2292    {
2293       DU_LOG("\nERROR  -->  F1AP: buildServCellToDeleteList(): failed to fill Served_Cells_To_Delete_ItemIEs");
2294       return RFAILED;
2295    }
2296    return ROK;
2297 }
2298
2299 /*******************************************************************
2300  *
2301  * @brief Builds and sends the DUConfigUpdate
2302  *
2303  * @details
2304  *
2305  *    Function : BuildAndSendDUConfigUpdate
2306  *
2307  *    Functionality: Constructs the DU Update message and sends
2308  *                   it to the CU through SCTP.
2309  *
2310  * @params[in] void **buf,Buffer to which encoded pattern is written into
2311  * @params[in] int *size,size of buffer
2312  *
2313  * @return ROK     - success
2314  *         RFAILED - failure
2315  *
2316  * ****************************************************************/
2317 uint8_t BuildAndSendDUConfigUpdate(ServCellAction servCellAction)
2318 {
2319    uint8_t ret =0, ieIdx=0, elementCnt=0;
2320    bool memAlloctionFailure = false;
2321    F1AP_PDU_t                 *f1apDuCfg = NULLP;
2322    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
2323    asn_enc_rval_t encRetVal;     /* Encoder return value */
2324    
2325    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2326    ret= RFAILED;
2327
2328    while(true)
2329    {
2330       DU_LOG("\nINFO   -->  F1AP : Building DU config update\n");
2331       /* Allocate the memory for F1DuCfg */
2332       DU_ALLOC(f1apDuCfg, sizeof(F1AP_PDU_t));
2333       if(f1apDuCfg == NULLP)
2334       {
2335          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2336          break;
2337       }
2338
2339       f1apDuCfg->present = F1AP_PDU_PR_initiatingMessage;
2340       DU_ALLOC(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2341       if(f1apDuCfg->choice.initiatingMessage == NULLP)
2342       {
2343          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2344          break;
2345       }
2346
2347       f1apDuCfg->choice.initiatingMessage->procedureCode = \
2348                                                            ProcedureCode_id_gNBDUConfigurationUpdate;
2349       f1apDuCfg->choice.initiatingMessage->criticality = Criticality_reject;
2350       f1apDuCfg->choice.initiatingMessage->value.present = \
2351                                                            InitiatingMessage__value_PR_GNBDUConfigurationUpdate;
2352       duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->value.\
2353                     choice.GNBDUConfigurationUpdate;
2354       elementCnt = 3;
2355       duCfgUpdate->protocolIEs.list.count = elementCnt;
2356       duCfgUpdate->protocolIEs.list.size = \
2357                                            elementCnt * sizeof(GNBDUConfigurationUpdateIEs_t*);
2358
2359       /* Initialize the F1Setup members */
2360       DU_ALLOC(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2361       if(duCfgUpdate->protocolIEs.list.array == NULLP)
2362       {
2363          DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2364          break;
2365       }
2366       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
2367       {
2368          DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx],sizeof(GNBDUConfigurationUpdateIEs_t));
2369          if(duCfgUpdate->protocolIEs.list.array[ieIdx] == NULLP)
2370          {
2371             DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2372             memAlloctionFailure = true;
2373             break;
2374          }
2375       }
2376       
2377       if(memAlloctionFailure == true)
2378       {
2379          break;
2380       }
2381       /*TransactionID*/
2382       ieIdx = 0;
2383       duCfgUpdate->protocolIEs.list.array[ieIdx]->id=ProtocolIE_ID_id_TransactionID;
2384       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
2385       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2386       GNBDUConfigurationUpdateIEs__value_PR_TransactionID;
2387       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = TRANS_ID;
2388       
2389       ieIdx++;
2390       if(servCellAction == SERV_CELL_TO_MODIFY)
2391       {
2392          /*Served Cell to Modify */
2393          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2394          ProtocolIE_ID_id_Served_Cells_To_Modify_List;
2395          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2396          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2397          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Modify_List;
2398          if(buildServCellToModList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2399                   Served_Cells_To_Modify_List))
2400          {
2401             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToModList");
2402             break;
2403          }
2404       }
2405       else
2406       {
2407          /*Served Cell to Delete */ 
2408          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2409          ProtocolIE_ID_id_Served_Cells_To_Delete_List;
2410          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2411          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2412          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Delete_List;
2413          if(buildServCellToDeleteList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2414          Served_Cells_To_Delete_List)!=ROK)
2415          {
2416             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToDeleteList");
2417             break;
2418          }
2419          
2420       }
2421       // NOTE :GNB DU SYS INFO:MIB AND SIB1 INFORMATION TO BE BUILT AND FILLED HERE
2422       /*GNB DU ID */
2423       ieIdx++;
2424       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
2425       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2426       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2427       GNBDUConfigurationUpdateIEs__value_PR_GNB_DU_ID;
2428       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size = sizeof(uint8_t);
2429       DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
2430             duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
2431       if(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == NULLP)
2432       {
2433          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Memory allocation failed for GNB_DU_ID");
2434          break;
2435       }
2436       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] = duCfgParam.duId;
2437
2438       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apDuCfg);
2439
2440       /* Encode the DU Config Update type as APER */
2441       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
2442       encBufSize = 0;
2443       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apDuCfg, PrepFinalEncBuf, encBuf);
2444
2445       /* Checking encode results */
2446       if(encRetVal.encoded == ENCODE_FAIL)
2447       {
2448          DU_LOG("ERROR  -->  F1AP : Could not encode DUConfigUpdate structure (at %s)\n",\
2449                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2450          break;
2451       }
2452       else
2453       {
2454          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DUConfigUpdate\n");
2455          for(ieIdx =0; ieIdx < encBufSize; ieIdx++)
2456          {
2457             printf("%x",encBuf[ieIdx]);
2458          }
2459       }
2460       /* Sending msg */
2461       if(sendF1APMsg() != ROK)
2462       {
2463          DU_LOG("\nERROR  -->  F1AP : Sending GNB-DU Config Update failed");
2464          break;
2465       }
2466
2467       ret = ROK;
2468       break;
2469    }
2470   
2471    addToReservedF1apPduList(TRANS_ID,f1apDuCfg);
2472    return ret;
2473 }
2474
2475
2476 /*******************************************************************
2477  *
2478  * @brief free the ULRRCMessageTransfer
2479  *
2480  * @details
2481  *
2482  *    Function : FreeULRRCMessageTransfer
2483  *
2484  *    Functionality: Deallocating the memory of variable allocated in
2485  *                      FreeULRRCMessageTransfer
2486  *
2487  * @params[in]
2488  *
2489  * @return ROK     - void
2490  *
2491  ******************************************************************/
2492 void FreeULRRCMessageTransfer( F1AP_PDU_t *f1apMsg)
2493 {
2494    uint8_t idx1;
2495    ULRRCMessageTransfer_t  *ulRRCMsg;
2496
2497    if(f1apMsg != NULLP)
2498    { 
2499       if(f1apMsg->choice.initiatingMessage != NULLP)
2500       {
2501          ulRRCMsg = &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2502          if(ulRRCMsg->protocolIEs.list.array != NULLP)
2503          {
2504             for(idx1=0;idx1<ulRRCMsg->protocolIEs.list.count;idx1++)
2505             {
2506                if(ulRRCMsg->protocolIEs.list.array[idx1] != NULLP)
2507                {
2508                   if(ulRRCMsg->protocolIEs.list.array[idx1]->value.present ==
2509                         ULRRCMessageTransferIEs__value_PR_RRCContainer)
2510                   {
2511                      DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2512                            ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2513                   }
2514                   DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1],sizeof(ULRRCMessageTransferIEs_t));
2515                }
2516             }
2517             DU_FREE(ulRRCMsg->protocolIEs.list.array,ulRRCMsg->protocolIEs.list.size );
2518          }
2519          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2520       }
2521       DU_FREE(f1apMsg,sizeof(F1AP_PDU_t));
2522    }
2523 }
2524 /*******************************************************************
2525  *
2526  * @brief Builds and sends the ULRRCMessageTransfer 
2527  *
2528  * @details
2529  *
2530  *    Function : BuildAndSendULRRCMessageTransfer
2531  *
2532  *    Functionality: Constructs the UL RRC Message Transfer and sends
2533  *                   it to the CU through SCTP.
2534  *
2535  * @params[in] 
2536  *
2537  * @return ROK     - success
2538  *         RFAILED - failure
2539  *
2540  * ****************************************************************/
2541 uint8_t BuildAndSendULRRCMessageTransfer(DuUeCb  ueCb, uint8_t lcId, \
2542       uint16_t msgLen, uint8_t *rrcMsg)
2543 {
2544    uint8_t   elementCnt =0;
2545    uint8_t   idx1 =0;
2546    uint8_t   idx =0;
2547    F1AP_PDU_t                   *f1apMsg = NULLP;
2548    ULRRCMessageTransfer_t       *ulRRCMsg = NULLP;
2549    asn_enc_rval_t               encRetVal;        /* Encoder return value */
2550    uint8_t ret =RFAILED;
2551    
2552    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2553
2554    while(true)
2555    {
2556       DU_LOG("\n INFO   -->  F1AP : Building UL RRC Message Transfer Message\n");
2557
2558       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
2559       if(f1apMsg == NULLP)
2560       {
2561          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
2562          break;
2563       }
2564       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
2565       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2566       if(f1apMsg->choice.initiatingMessage == NULLP)
2567       {
2568          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
2569          break;
2570       }
2571       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_ULRRCMessageTransfer;
2572       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
2573       f1apMsg->choice.initiatingMessage->value.present = \
2574                                                          InitiatingMessage__value_PR_ULRRCMessageTransfer;
2575       ulRRCMsg =
2576          &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2577       elementCnt = 4;
2578       ulRRCMsg->protocolIEs.list.count = elementCnt;
2579       ulRRCMsg->protocolIEs.list.size = \
2580                                         elementCnt * sizeof(ULRRCMessageTransferIEs_t *);
2581
2582       /* Initialize the F1Setup members */
2583       DU_ALLOC(ulRRCMsg->protocolIEs.list.array, ulRRCMsg->protocolIEs.list.size);
2584       if(ulRRCMsg->protocolIEs.list.array == NULLP)
2585       {
2586          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UL RRC MessageTransferIEs failed");
2587          break;
2588       }
2589       for(idx=0; idx<elementCnt; idx++)
2590       {
2591          DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx],sizeof(ULRRCMessageTransferIEs_t));
2592          if(ulRRCMsg->protocolIEs.list.array[idx] == NULLP)
2593          {
2594             break;
2595          }
2596       }
2597
2598       idx1 = 0;
2599
2600       /*GNB CU UE F1AP ID*/
2601       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
2602       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2603       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2604                                                               ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
2605       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = ueCb.gnbCuUeF1apId;
2606
2607       /*GNB DU UE F1AP ID*/
2608       idx1++;
2609       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
2610       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2611       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2612                                                               ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
2613       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = ueCb.gnbDuUeF1apId;
2614
2615       /*SRBID*/
2616       idx1++;
2617       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
2618       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2619       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2620                                                               ULRRCMessageTransferIEs__value_PR_SRBID;
2621       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.SRBID = lcId;
2622
2623       /*RRCContainer*/
2624       idx1++;
2625       ulRRCMsg->protocolIEs.list.array[idx1]->id  = ProtocolIE_ID_id_RRCContainer;
2626       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2627       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2628                                                               ULRRCMessageTransferIEs__value_PR_RRCContainer;
2629       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size = msgLen;
2630       DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2631             ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size)
2632       if(!ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf)
2633       {
2634          DU_LOG(" ERROR  -->  F1AP : Memory allocation for BuildAndSendULRRCMessageTransfer failed");
2635          break;
2636       }
2637       memset(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, 0, msgLen);
2638       memcpy(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, \
2639             rrcMsg, ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2640
2641       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
2642
2643       /* Encode the F1SetupRequest type as APER */
2644       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2645       encBufSize = 0;
2646       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
2647             encBuf);
2648       /* Encode results */
2649       if(encRetVal.encoded == ENCODE_FAIL)
2650       {
2651          DU_LOG( "\nERROR  -->  F1AP : Could not encode ULRRCMessageTransfer structure (at %s)\n",\
2652                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2653          break;
2654       }
2655       else
2656       {
2657          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for ULRRCMessageTransfer\n");
2658          for(int i=0; i< encBufSize; i++)
2659          {
2660             printf("%x",encBuf[i]);
2661          }
2662       }
2663
2664       /* Sending  msg  */
2665       if(sendF1APMsg()  !=      ROK)
2666       {
2667          DU_LOG("\nERROR  -->   F1AP : Sending  UL RRC Message Transfer Failed");
2668          break;
2669       }
2670       ret = ROK;
2671       break;
2672    }
2673    FreeULRRCMessageTransfer(f1apMsg);
2674
2675    return ret;
2676 }/* End of BuildAndSendULRRCMessageTransfer*/
2677
2678 /*******************************************************************
2679  *
2680  * @brief Builds tag config 
2681  *
2682  * @details
2683  *
2684  *    Function : BuildTagConfig 
2685  *
2686  *    Functionality: Builds tag config in MacCellGroupConfig
2687  *
2688  * @params[in] TAG_Config *tag_Config
2689  *
2690  * @return ROK     - success
2691  *         RFAILED - failure
2692  *
2693  * ****************************************************************/
2694 uint8_t BuildTagConfig(DuUeCb *ueCb, struct TAG_Config *tagConfig)
2695 {
2696    struct TAG_Config__tag_ToAddModList *tagList;
2697    uint8_t                     idx, elementCnt;
2698
2699    tagConfig->tag_ToReleaseList = NULLP;
2700    tagConfig->tag_ToAddModList = NULLP;
2701    DU_ALLOC(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
2702    if(!tagConfig->tag_ToAddModList)
2703    {
2704       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2705       return RFAILED;
2706    }
2707
2708    if(ueCb == NULLP)
2709       elementCnt = ODU_VALUE_ONE;
2710    else
2711       elementCnt = ueCb->macUeCfg.macCellGrpCfg.tagCfg.addModListCount;
2712
2713    tagList = tagConfig->tag_ToAddModList;
2714    tagList->list.count = elementCnt;
2715    tagList->list.size  =  elementCnt * sizeof(struct TAG *);
2716
2717    tagList->list.array = NULLP;
2718    DU_ALLOC(tagList->list.array, tagList->list.size);
2719    if(!tagList->list.array)
2720    {
2721       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2722       return RFAILED;
2723    }
2724
2725    for(idx=0; idx<tagList->list.count; idx++)
2726    {
2727       tagList->list.array[idx] = NULLP;
2728       DU_ALLOC(tagList->list.array[idx], sizeof(struct TAG));
2729       if(!tagList->list.array[idx])
2730       {
2731          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2732          return RFAILED;
2733       }
2734    }
2735
2736    if(ueCb == NULLP)
2737    {
2738       idx = 0;
2739       tagList->list.array[idx]->tag_Id = TAG_ID;
2740       tagList->list.array[idx]->timeAlignmentTimer = TIME_ALIGNMENT_TMR;
2741    }
2742    else
2743    {
2744       for(idx=0; idx<tagList->list.count; idx++)
2745       {
2746          tagList->list.array[idx]->tag_Id = ueCb->macUeCfg.macCellGrpCfg.tagCfg.addModList[idx].tagId;
2747          tagList->list.array[idx]->timeAlignmentTimer = ueCb->macUeCfg.macCellGrpCfg.tagCfg.addModList[idx].timeAlignTimer;
2748       }
2749    }
2750
2751    return ROK;
2752 }
2753
2754 /*******************************************************************
2755  *
2756  * @brief Builds PHR Config 
2757  *
2758  * @details
2759  *
2760  *    Function : BuildPhrConfig
2761  *
2762  *    Functionality: Builds phrConfig in MacCellGroupConfig
2763  *
2764  * @params[in] PHR Config *
2765  *
2766  * @return ROK     - success
2767  *         RFAILED - failure
2768  *
2769  * ****************************************************************/
2770 uint8_t BuildPhrConfig(DuUeCb *ueCb, struct MAC_CellGroupConfig__phr_Config *phrConfig)
2771 {
2772
2773    phrConfig->present = MAC_CellGroupConfig__phr_Config_PR_setup;
2774    phrConfig->choice.setup = NULLP;
2775    DU_ALLOC(phrConfig->choice.setup, sizeof(struct PHR_Config));
2776    if(!phrConfig->choice.setup)
2777    {
2778       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhrConfig");
2779       return RFAILED;
2780    }
2781
2782    if(ueCb == NULLP)
2783    {
2784       phrConfig->choice.setup->phr_PeriodicTimer        = PHR_PERIODIC_TMR;
2785       phrConfig->choice.setup->phr_ProhibitTimer        = PHR_PROHIBHIT_TMR;
2786       phrConfig->choice.setup->phr_Tx_PowerFactorChange = PHR_PWR_FACTOR_CHANGE;
2787       phrConfig->choice.setup->multiplePHR              = false;
2788       phrConfig->choice.setup->dummy                    = false;
2789       phrConfig->choice.setup->phr_Type2OtherCell       = false;
2790       phrConfig->choice.setup->phr_ModeOtherCG          = PHR_MODE_OTHER_CG;
2791    }
2792    else
2793    {
2794       phrConfig->choice.setup->phr_PeriodicTimer        = ueCb->macUeCfg.macCellGrpCfg.phrCfg.periodicTimer;
2795       phrConfig->choice.setup->phr_ProhibitTimer        = ueCb->macUeCfg.macCellGrpCfg.phrCfg.prohibitTimer;
2796       phrConfig->choice.setup->phr_Tx_PowerFactorChange = ueCb->macUeCfg.macCellGrpCfg.phrCfg.txPowerFactor;
2797       phrConfig->choice.setup->multiplePHR              = ueCb->macUeCfg.macCellGrpCfg.phrCfg.multiplePHR;
2798       phrConfig->choice.setup->dummy                    = ueCb->macUeCfg.macCellGrpCfg.phrCfg.dummy;
2799       phrConfig->choice.setup->phr_Type2OtherCell       = ueCb->macUeCfg.macCellGrpCfg.phrCfg.phrType2OtherCell;
2800       phrConfig->choice.setup->phr_ModeOtherCG          = ueCb->macUeCfg.macCellGrpCfg.phrCfg.phrOtherCG;
2801    }
2802
2803    return ROK;
2804 }
2805
2806 /*******************************************************************
2807  *
2808  * @brief Builds BSR Config 
2809  *
2810  * @details
2811  *
2812  *    Function : BuildBsrConfig
2813  *
2814  *    Functionality: Builds BuildBsrConfig in MacCellGroupConfig
2815  *
2816  * @params[in] BSR_Config *bsrConfig
2817  *
2818  * @return ROK     - success
2819  *         RFAILED - failure
2820  *
2821  * ****************************************************************/
2822 uint8_t BuildBsrConfig(DuUeCb *ueCb, struct BSR_Config *bsrConfig)
2823 {
2824    if(ueCb == NULLP)
2825    {
2826       bsrConfig->periodicBSR_Timer = PERIODIC_BSR_TMR;
2827       bsrConfig->retxBSR_Timer     = RETX_BSR_TMR;
2828       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
2829    }
2830    else
2831    {
2832       bsrConfig->periodicBSR_Timer = ueCb->macUeCfg.macCellGrpCfg.bsrTmrCfg.periodicTimer;
2833       bsrConfig->retxBSR_Timer     = ueCb->macUeCfg.macCellGrpCfg.bsrTmrCfg.retxTimer;
2834
2835       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
2836       DU_ALLOC(bsrConfig->logicalChannelSR_DelayTimer, sizeof(long));
2837       if(bsrConfig->logicalChannelSR_DelayTimer == NULLP)
2838       {
2839          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildBsrConfig");
2840          return RFAILED;
2841       }
2842       *(bsrConfig->logicalChannelSR_DelayTimer) = convertLcSrDelayTmrValueToEnum(ueCb->macUeCfg.macCellGrpCfg.bsrTmrCfg.srDelayTimer);
2843    }
2844
2845    return ROK;
2846 }
2847
2848 /*******************************************************************
2849  *
2850  * @brief Builds scheduling request config 
2851  *
2852  * @details
2853  *
2854  *    Function : BuildSchedulingReqConfig 
2855  *
2856  *    Functionality: Builds BuildSchedulingReqConfig in MacCellGroupConfig
2857  *
2858  * @params[in] SchedulingRequestConfig *schedulingRequestConfig
2859  *
2860  * @return ROK     - success
2861  *         RFAILED - failure
2862  *
2863  * ****************************************************************/
2864 uint8_t BuildSchedulingReqConfig(DuUeCb *ueCb, struct SchedulingRequestConfig *schedulingRequestConfig)
2865 {
2866    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList;
2867    uint8_t                     idx, elementCnt;
2868
2869    schedulingRequestConfig->schedulingRequestToAddModList = NULLP;
2870    DU_ALLOC(schedulingRequestConfig->schedulingRequestToAddModList,
2871          sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));
2872    if(!schedulingRequestConfig->schedulingRequestToAddModList)
2873    {
2874       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2875       return RFAILED;
2876    }
2877
2878    if(ueCb == NULLP)
2879       elementCnt = ODU_VALUE_ONE;
2880    else
2881       elementCnt = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModListCount;
2882
2883    schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
2884    schReqList->list.count = elementCnt;
2885    schReqList->list.size  = elementCnt * sizeof(struct SchedulingRequestToAddMod *);
2886
2887    schReqList->list.array = NULLP;
2888    DU_ALLOC(schReqList->list.array, schReqList->list.size);
2889    if(!schReqList->list.array)
2890    {
2891       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2892       return RFAILED;
2893    }
2894
2895    for(idx=0; idx<schReqList->list.count; idx++)
2896    {
2897       schReqList->list.array[idx] = NULLP;
2898       DU_ALLOC(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
2899       if(!schReqList->list.array[idx])
2900       {
2901          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2902          return RFAILED;
2903       }
2904    }
2905
2906    if(ueCb == NULLP)
2907    {
2908       idx = 0;
2909       schReqList->list.array[idx]->schedulingRequestId = SCH_REQ_ID;
2910
2911       schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
2912       DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
2913       if(!schReqList->list.array[idx]->sr_ProhibitTimer)
2914       {
2915          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2916          return RFAILED;
2917       }
2918       *(schReqList->list.array[idx]->sr_ProhibitTimer) = SR_PROHIBIT_TMR;
2919       schReqList->list.array[idx]->sr_TransMax = SR_TRANS_MAX;
2920    }
2921    else
2922    {
2923       for(idx=0; idx<schReqList->list.count; idx++)
2924       {
2925          schReqList->list.array[idx]->schedulingRequestId = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].schedReqId;
2926
2927          schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
2928          DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
2929          if(!schReqList->list.array[idx]->sr_ProhibitTimer)
2930          {
2931             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2932             return RFAILED;
2933          }
2934          *(schReqList->list.array[idx]->sr_ProhibitTimer) = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srProhibitTmr;
2935          schReqList->list.array[idx]->sr_TransMax = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srTransMax;
2936       }
2937    }
2938
2939    schedulingRequestConfig->schedulingRequestToReleaseList = NULLP;
2940
2941    return ROK;
2942 }
2943
2944 /*******************************************************************
2945  *
2946  * @brief Builds RLC Configuration for AM mode
2947  *
2948  * @details
2949  *
2950  *    Function : BuildRlcConfigAm
2951  *
2952  *    Functionality: 
2953  *       Builds AM mode RLC Config in BuildRlcBearerToAddModList
2954  *
2955  * @params[in] AmBearerCfg *amCfg
2956  *             RLC_Config_t  *rlcConfig
2957  *
2958  * @return ROK     - success
2959  *         RFAILED - failure
2960  *
2961  * ****************************************************************/
2962 uint8_t BuildRlcConfigAm(AmBearerCfg *amCfg, struct RLC_Config *rlcConfig)
2963 {
2964    rlcConfig->choice.am = NULLP;
2965    DU_ALLOC(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
2966    if(!rlcConfig->choice.am)
2967    {
2968       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
2969       return RFAILED;
2970    }
2971
2972    /* Fill AM UL configuration */
2973    rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength = NULLP;
2974    DU_ALLOC(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
2975    if(!rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength)
2976    {
2977       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
2978       return RFAILED;
2979    }
2980
2981    /* Fill default AM UL configuration if input pointer to DU database is NULL */
2982    if(amCfg == NULLP)
2983    {
2984       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = SN_FIELD_LEN;
2985       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = T_POLL_RETRANSMIT;
2986       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = POLL_PDU;
2987       rlcConfig->choice.am->ul_AM_RLC.pollByte          = POLL_BYTE;
2988       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = MAX_RETX_THRESHOLD;
2989    }
2990    else
2991    {
2992       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->dlAmCfg.snLenDl);
2993       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = covertPollRetxTmrValueToEnum(amCfg->dlAmCfg.pollRetxTmr);
2994       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = covertPollPduValueToEnum(amCfg->dlAmCfg.pollPdu);
2995       rlcConfig->choice.am->ul_AM_RLC.pollByte          = covertPollByteValueToEnum(amCfg->dlAmCfg.pollByte);
2996       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = covertMaxRetxValueToEnum(amCfg->dlAmCfg.maxRetxTh);
2997    }
2998
2999    /* Fill AM DL configuraion */
3000    rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength = NULLP;
3001    DU_ALLOC(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
3002    if(!rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength)
3003    {
3004       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3005       return RFAILED;
3006    }
3007
3008    /* Fill default AM DL configuration if input pointer to DU database is NULL */
3009    if(amCfg == NULLP)
3010    {
3011       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = SN_FIELD_LEN;
3012       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = T_REASSEMBLY;
3013       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = T_STATUS_PROHIBHIT;
3014    }
3015    else /* Fill AM configuration from DU database */
3016    {
3017       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->ulAmCfg.snLenUl);
3018       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = convertReasmblTmrValueToEnum(amCfg->ulAmCfg.reAssemTmr);
3019       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = convertProhibitTmrValueToEnum(amCfg->ulAmCfg.statProhTmr);
3020    }
3021    return ROK;
3022 }
3023
3024 /*******************************************************************
3025  *
3026  * @brief Builds RLC Config for UM Bidirection
3027  *
3028  * @details
3029  *
3030  *    Function : BuildRlcConfig UmBiDir
3031  *
3032  *    Functionality: 
3033  *       Builds RLC Config for UM Bidirection in BuildRlcBearerToAddModList 
3034  *
3035  * @params[in] UmBiDirBearerCfg *umBiDirCfg
3036  *             RLC_Config_t *rlcConfig
3037  *
3038  * @return ROK     - success
3039  *         RFAILED - failure
3040  *
3041  * ****************************************************************/
3042 uint8_t BuildRlcConfigUmBiDir(UmBiDirBearerCfg *umBiDirCfg, struct RLC_Config *rlcConfig)
3043 {
3044    rlcConfig->choice.um_Bi_Directional = NULLP;
3045    DU_ALLOC(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
3046    if(rlcConfig->choice.um_Bi_Directional == NULLP)
3047    {
3048       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3049       return RFAILED;
3050    }
3051
3052    /* Fill UM Bidirectional UL configuration */
3053    rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength = NULLP;
3054    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3055    if(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength == NULLP)
3056    {
3057       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3058       return RFAILED;
3059    }
3060
3061    if(umBiDirCfg != NULLP)
3062    {
3063       *(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->dlUmCfg.snLenDlUm);     
3064    }
3065
3066    /* Fill UM Bidirectional DL configuration */
3067    rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength = NULLP;
3068    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3069    if(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength == NULLP)
3070    {
3071       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3072       return RFAILED;
3073    }
3074
3075    if(umBiDirCfg != NULLP)
3076    {
3077       *(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->ulUmCfg.snLenUlUm);     
3078       rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umBiDirCfg->ulUmCfg.reAssemTmr);
3079    }
3080
3081    return ROK;
3082 }
3083
3084 /*******************************************************************
3085  *
3086  * @brief Builds RLC Config for UM Uni directional UL
3087  *
3088  * @details
3089  *
3090  *    Function : BuildRlcConfigUmUniDirUl
3091  *
3092  *    Functionality: 
3093  *       Builds RLC Config for UM Unidirection UL in BuildRlcBearerToAddModList 
3094  *
3095  * @params[in] UmUniDirDlBearerCfg *umUniDirDlCfg
3096  *             RLC_Config_t *rlcConfig
3097  *
3098  * @return ROK     - success
3099  *         RFAILED - failure
3100  *
3101  * ****************************************************************/
3102 uint8_t BuildRlcConfigUmUniDirUl(UmUniDirDlBearerCfg *umUniDirDlCfg, RLC_Config_t *rlcConfig)
3103 {
3104    rlcConfig->choice.um_Uni_Directional_UL = NULLP;
3105    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
3106    if(rlcConfig->choice.um_Uni_Directional_UL == NULLP)
3107    {
3108       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3109       return RFAILED;
3110    }
3111
3112    rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength = NULLP;
3113    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3114    if(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength == NULLP)
3115    {
3116       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3117       return RFAILED;
3118    }
3119
3120    if(umUniDirDlCfg != NULLP)
3121    {
3122       *(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirDlCfg->dlUmCfg.snLenDlUm);
3123    }
3124
3125    return ROK;
3126 }
3127
3128 /*******************************************************************
3129  *
3130  * @brief Builds RLC Config for UM Uni directional DL
3131  *
3132  * @details
3133  *
3134  *    Function : BuildRlcConfigUmUniDirDl
3135  *
3136  *    Functionality: 
3137  *       Builds RLC Config for UM Unidirection DL in BuildRlcBearerToAddModList 
3138  *
3139  * @params[in] UmUniDirUlBearerCfg *umUniDirUlCfg
3140  *             RLC_Config_t *rlcConfig
3141  *
3142  * @return ROK     - success
3143  *         RFAILED - failure
3144  *
3145  * ****************************************************************/
3146 uint8_t BuildRlcConfigUmUniDirDl(UmUniDirUlBearerCfg *umUniDirUlCfg, RLC_Config_t *rlcConfig)
3147 {
3148    rlcConfig->choice.um_Uni_Directional_DL = NULLP;
3149    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
3150    if(rlcConfig->choice.um_Uni_Directional_DL == NULLP)
3151    {
3152       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3153       return RFAILED;
3154    }
3155
3156    rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength = NULLP;
3157    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3158    if(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength == NULLP)
3159    {
3160       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3161       return RFAILED;
3162    }
3163
3164    if(umUniDirUlCfg != NULLP)
3165    {
3166       *(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirUlCfg->ulUmCfg.snLenUlUm);
3167       rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umUniDirUlCfg->ulUmCfg.reAssemTmr);
3168    }
3169
3170    return ROK;
3171 }
3172
3173 /*******************************************************************
3174  *
3175  * @brief Builds RLC Config
3176  *
3177  * @details
3178  *
3179  *    Function : BuildRlcConfig
3180  *
3181  *    Functionality: Builds RLC Config in BuildRlcBearerToAddModList 
3182  *
3183  * @params[in] RLC_Config_t *rlcConfig
3184  *
3185  * @return ROK     - success
3186  *         RFAILED - failure
3187  *
3188  * ****************************************************************/
3189 uint8_t BuildRlcConfig(RlcBearerCfg *rbCfg, struct RLC_Config *rlcConfig)
3190 {
3191    
3192    /* Fill default values if rbCfg is NULL */
3193    if(rbCfg == NULLP)
3194    {
3195       rlcConfig->present = RLC_Config_PR_am;
3196       BuildRlcConfigAm(NULLP, rlcConfig);
3197    }
3198    /* If RbCfg is present, fill RLC configurations from DU Database */
3199    else
3200    {
3201       rlcConfig->present = covertRlcModeFromIntEnumToRrcEnum(rbCfg->rlcMode);
3202       switch(rlcConfig->present)
3203       {
3204          case RLC_Config_PR_am:
3205             BuildRlcConfigAm(rbCfg->u.amCfg, rlcConfig);
3206             break;
3207          case RLC_Config_PR_um_Bi_Directional:
3208             BuildRlcConfigUmBiDir(rbCfg->u.umBiDirCfg, rlcConfig);
3209             break;
3210          case RLC_Config_PR_um_Uni_Directional_UL:
3211             BuildRlcConfigUmUniDirUl(rbCfg->u.umUniDirDlCfg, rlcConfig);
3212             break;
3213          case RLC_Config_PR_um_Uni_Directional_DL:
3214             BuildRlcConfigUmUniDirDl(rbCfg->u.umUniDirUlCfg, rlcConfig);
3215             break;
3216          case RLC_Config_PR_NOTHING:
3217          default:
3218             break;
3219       }
3220    }
3221
3222    return ROK;
3223 }
3224
3225 /*******************************************************************
3226  *
3227  * @brief Builds MAC LC Config
3228  *
3229  * @details
3230  *
3231  *    Function : BuildMacLCConfig 
3232  *
3233  *    Functionality: Builds MAC LC Config in BuildRlcBearerToAddModList 
3234  *
3235  * @params[in] struct LogicalChannelConfig macLcConfig
3236  *
3237  * @return ROK     - success
3238  *         RFAILED - failure
3239  *
3240  * ****************************************************************/
3241 uint8_t BuildMacLCConfig(LcCfg *lcCfgDb, struct LogicalChannelConfig *macLcConfig)
3242 {
3243    macLcConfig->ul_SpecificParameters = NULLP;
3244    DU_ALLOC(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
3245    if(!macLcConfig->ul_SpecificParameters)
3246    {
3247       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3248       return RFAILED;
3249    }
3250
3251    if(lcCfgDb == NULLP)
3252    {
3253       macLcConfig->ul_SpecificParameters->priority = MAC_LC_PRIORITY;
3254       macLcConfig->ul_SpecificParameters->prioritisedBitRate =  PRIORTISIED_BIT_RATE;
3255       macLcConfig->ul_SpecificParameters->bucketSizeDuration =  BUCKET_SIZE_DURATION;
3256    }
3257    else
3258    {
3259       macLcConfig->ul_SpecificParameters->priority = lcCfgDb->ulLcCfg.priority;
3260       macLcConfig->ul_SpecificParameters->prioritisedBitRate = lcCfgDb->ulLcCfg.pbr;
3261       macLcConfig->ul_SpecificParameters->bucketSizeDuration = lcCfgDb->ulLcCfg.bsd;
3262    }
3263
3264    macLcConfig->ul_SpecificParameters->allowedServingCells = NULLP;
3265    macLcConfig->ul_SpecificParameters->allowedSCS_List = NULLP;
3266    macLcConfig->ul_SpecificParameters->maxPUSCH_Duration = NULLP;
3267    macLcConfig->ul_SpecificParameters->configuredGrantType1Allowed = NULLP;
3268
3269    macLcConfig->ul_SpecificParameters->logicalChannelGroup = NULLP;
3270    DU_ALLOC(macLcConfig->ul_SpecificParameters->logicalChannelGroup,    sizeof(long));
3271    if(!macLcConfig->ul_SpecificParameters->logicalChannelGroup)
3272    {
3273       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3274       return RFAILED;
3275    }
3276
3277    if(lcCfgDb == NULLP)
3278       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = LC_GRP;
3279    else
3280       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = lcCfgDb->ulLcCfg.lcGroup;
3281
3282    macLcConfig->ul_SpecificParameters->schedulingRequestID = NULLP;
3283    DU_ALLOC(macLcConfig->ul_SpecificParameters->schedulingRequestID,    sizeof(SchedulingRequestId_t));
3284    if(!macLcConfig->ul_SpecificParameters->schedulingRequestID)
3285    {
3286       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3287       return RFAILED;
3288    }
3289
3290    if(lcCfgDb == NULLP)
3291       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = SCH_REQ_ID;
3292    else
3293       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = lcCfgDb->ulLcCfg.schReqId;
3294
3295    macLcConfig->ul_SpecificParameters->logicalChannelSR_Mask = false;
3296    macLcConfig->ul_SpecificParameters->logicalChannelSR_DelayTimerApplied = false;
3297    macLcConfig->ul_SpecificParameters->bitRateQueryProhibitTimer = NULLP;
3298
3299    return ROK;
3300 }
3301
3302 /*******************************************************************
3303  *
3304  * @brief Builds RLC Bearer to Add/Mod list
3305  *
3306  * @details
3307  *
3308  *    Function :BuildRlcBearerToAddModList 
3309  *
3310  *    Functionality: Builds RLC Bearer to Add/Mod list in DuToCuRrcContainer
3311  *
3312  * @params[in] rlc_BearerToAddModList
3313  *
3314  * @return ROK     - success
3315  *         RFAILED - failure
3316  *
3317  * ****************************************************************/
3318 uint8_t BuildRlcBearerToAddModList(DuUeCb *ueCb, struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList)
3319 {
3320    uint8_t  idx = 0, macLcIdx = 0, elementCnt = 0;
3321
3322    if(ueCb == NULLP)
3323       elementCnt = 1;
3324    else
3325       elementCnt = ueCb->rlcUeCfg.numLcs;
3326    rlcBearerList->list.count = elementCnt;
3327    rlcBearerList->list.size  = elementCnt * sizeof(struct RLC_BearerConfig *);
3328
3329    rlcBearerList->list.array = NULLP;
3330    DU_ALLOC(rlcBearerList->list.array, rlcBearerList->list.size);
3331    if(!rlcBearerList->list.array)
3332    {
3333       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3334       return RFAILED;
3335    }
3336
3337    for(idx=0; idx<rlcBearerList->list.count; idx++)
3338    {
3339       rlcBearerList->list.array[idx] = NULLP;
3340       DU_ALLOC(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
3341       if(!rlcBearerList->list.array[idx])
3342       {
3343          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3344          return RFAILED;
3345       }
3346    }
3347
3348    for(idx=0; idx<rlcBearerList->list.count; idx++)
3349    {
3350       /* Fill Logical channel identity */
3351       if(ueCb == NULLP)
3352          rlcBearerList->list.array[idx]->logicalChannelIdentity = SRB1_LCID;
3353       else
3354          rlcBearerList->list.array[idx]->logicalChannelIdentity = ueCb->rlcUeCfg.rlcLcCfg[idx].lcId;
3355
3356       /* Fill Radio Bearer Id and type (DRB/SRB) for this logical channel */
3357       DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3358       if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3359       {
3360          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3361          return RFAILED;
3362       }
3363       if(ueCb == NULLP)
3364       {
3365          rlcBearerList->list.array[idx]->servedRadioBearer->present = RLC_BearerConfig__servedRadioBearer_PR_srb_Identity;
3366          rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = SRB1_LCID;
3367       }
3368       else
3369       {
3370          rlcBearerList->list.array[idx]->servedRadioBearer->present = \
3371             covertRbTypeFromIntEnumToRrcEnum(ueCb->rlcUeCfg.rlcLcCfg[idx].rbType);
3372          switch(rlcBearerList->list.array[idx]->servedRadioBearer->present)
3373          {
3374             case RLC_BearerConfig__servedRadioBearer_PR_srb_Identity: 
3375                rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = ueCb->rlcUeCfg.rlcLcCfg[idx].rbId;
3376                break;
3377             case RLC_BearerConfig__servedRadioBearer_PR_drb_Identity:
3378                rlcBearerList->list.array[idx]->servedRadioBearer->choice.drb_Identity = ueCb->rlcUeCfg.rlcLcCfg[idx].rbId;
3379                break;
3380             case RLC_BearerConfig__servedRadioBearer_PR_NOTHING:
3381             default:
3382                break;
3383          }
3384       }
3385
3386       rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3387
3388       /* Fill RLC related Configurations for this Radio Bearer */
3389       rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3390       DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3391       if(!rlcBearerList->list.array[idx]->rlc_Config)
3392       {
3393          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3394          return RFAILED;
3395       }
3396       if(ueCb == NULLP)
3397       {
3398          if(BuildRlcConfig(NULLP, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3399          {
3400             DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3401             return RFAILED;
3402          }
3403       }
3404       else
3405       {
3406          if(BuildRlcConfig(&ueCb->rlcUeCfg.rlcLcCfg[idx], rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3407          {
3408             DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3409             return RFAILED;
3410          }
3411       }
3412
3413       /* Fill MAC related configurations for this Radio Bearer */
3414       rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3415       DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3416       if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3417       {
3418          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3419          return RFAILED;
3420       }
3421
3422       if(ueCb == NULLP)
3423       {
3424          if(BuildMacLCConfig(NULLP, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3425          {
3426             DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3427             return RFAILED;
3428          }
3429       }
3430       else
3431       {
3432          for(macLcIdx = 0; macLcIdx < ueCb->macUeCfg.numLcs; macLcIdx++)
3433          {
3434             if(ueCb->macUeCfg.lcCfgList[macLcIdx].lcId == ueCb->rlcUeCfg.rlcLcCfg[idx].lcId)
3435             {
3436                if(BuildMacLCConfig(&ueCb->macUeCfg.lcCfgList[macLcIdx], rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3437                {
3438                   DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3439                   return RFAILED;
3440                }
3441                break;
3442             }
3443          }
3444       }
3445    }
3446    return ROK;
3447 }
3448
3449 /*******************************************************************
3450  *
3451  * @brief Build Control resource set to add/modify list 
3452  *
3453  * @details
3454  *
3455  *    Function : BuildControlRSetToAddModList
3456  *
3457  *    Functionality: Build Control resource set to add/modify list
3458  *
3459  * @params[in] 
3460  * struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList
3461  *
3462  * @return ROK     - success
3463  *         RFAILED - failure
3464  *
3465  * ****************************************************************/
3466 uint8_t BuildControlRSetToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList)
3467 {
3468    uint8_t idx;
3469    uint8_t elementCnt;
3470    uint8_t numBytes, bitsUnused;
3471    struct ControlResourceSet *controlRSet;
3472    uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
3473    uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
3474
3475    if(pdcchCfg == NULLP)
3476       elementCnt = 1;
3477    else
3478       elementCnt = pdcchCfg->numCRsetToAddMod;
3479
3480    controlRSetList->list.count = elementCnt;
3481    controlRSetList->list.size = elementCnt * sizeof(struct ControlResourceSet *);
3482
3483    controlRSetList->list.array = NULLP;
3484    DU_ALLOC(controlRSetList->list.array, controlRSetList->list.size);
3485    if(!controlRSetList->list.array)
3486    {
3487       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3488       return RFAILED;
3489    }
3490
3491    for(idx = 0; idx < elementCnt; idx++)
3492    {
3493       controlRSetList->list.array[idx] = NULLP;
3494       DU_ALLOC(controlRSetList->list.array[idx], sizeof(struct ControlResourceSet));
3495       if(!controlRSetList->list.array[idx])
3496       {
3497          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3498          return RFAILED;
3499       }
3500    }
3501
3502    for(idx = 0; idx < elementCnt; idx++)
3503    {
3504       controlRSet = controlRSetList->list.array[idx];
3505
3506       if(pdcchCfg == NULLP)
3507          controlRSet->controlResourceSetId = PDCCH_CTRL_RSRC_SET_ONE_ID;
3508       else
3509          controlRSet->controlResourceSetId = pdcchCfg->cRSetToAddModList[idx].cRSetId;
3510
3511       /* size 6 bytes
3512        * 3 LSBs unsued
3513        * Bit string stored ff0000000000
3514        */
3515       numBytes = 6;
3516       bitsUnused = 3;
3517       controlRSet->frequencyDomainResources.size = numBytes * sizeof(uint8_t);
3518
3519       controlRSet->frequencyDomainResources.buf = NULLP;
3520       DU_ALLOC(controlRSet->frequencyDomainResources.buf, controlRSet->frequencyDomainResources.size);
3521       if(!controlRSet->frequencyDomainResources.buf)
3522       {
3523          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3524          return RFAILED;
3525       }
3526
3527       memset(controlRSet->frequencyDomainResources.buf, 0, FREQ_DOM_RSRC_SIZE);
3528
3529       if(pdcchCfg == NULLP)
3530       {
3531          coreset0EndPrb = CORESET0_END_PRB;
3532          coreset1StartPrb = coreset0EndPrb + 6;
3533          coreset1NumPrb = CORESET1_NUM_PRB;
3534          /* calculate the PRBs */
3535          fillCoresetFeqDomAllocMap(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
3536          memcpy(controlRSet->frequencyDomainResources.buf, freqDomainResource, FREQ_DOM_RSRC_SIZE);
3537          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3538
3539          controlRSet->duration = PDCCH_CTRL_RSRC_SET_ONE_DURATION;
3540          controlRSet->cce_REG_MappingType.present = ControlResourceSet__cce_REG_MappingType_PR_nonInterleaved;
3541          controlRSet->precoderGranularity = PDCCH_CTRL_RSRC_SET_ONE_PRECOD_GRANULARITY;
3542       }
3543       else
3544       {
3545          memcpy(controlRSet->frequencyDomainResources.buf, pdcchCfg->cRSetToAddModList[idx].freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
3546          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3547          controlRSet->duration = pdcchCfg->cRSetToAddModList[idx].duration;
3548          controlRSet->cce_REG_MappingType.present = pdcchCfg->cRSetToAddModList[idx].cceRegMappingType;
3549          controlRSet->precoderGranularity = pdcchCfg->cRSetToAddModList[idx].precoderGranularity;
3550       }
3551       controlRSet->tci_StatesPDCCH_ToAddList = NULLP;
3552       controlRSet->tci_StatesPDCCH_ToReleaseList = NULLP;
3553       controlRSet->tci_PresentInDCI = NULLP;
3554
3555 #if 0
3556       uint8_t tciStateIdx;
3557
3558       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList, \
3559             sizeof(struct ControlResourceSet__tci_StatesPDCCH_ToAddList));
3560       if(!controlRset->tci_StatesPDCCH_ToAddList)
3561       {
3562          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3563          return RFAILED;
3564       }
3565
3566       elementCnt = 1;
3567       controlRset->tci_StatesPDCCH_ToAddList->list.count = elementCnt;
3568       controlRset->tci_StatesPDCCH_ToAddList->list.size = elementCnt * sizeof(TCI_StateId_t *);
3569       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array, \
3570             controlRset->tci_StatesPDCCH_ToAddList->list.size)
3571          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array)
3572          {
3573             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3574             return RFAILED;
3575          }
3576
3577       for(tciStateIdx = 0; tciStateIdx <elementCntl; tciStateIdx++)
3578       {
3579          DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx], sizeof(TCI_StateId_t));
3580          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx])
3581          {
3582             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3583             return RFAILED;
3584          }
3585       }
3586
3587       tciStateIdx = 0;
3588       /* TODO */
3589       *(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx]);
3590
3591       DU_ALLOC(controlRset->tci_PresentInDCI, sizeof(long));
3592       if(!controlRset->tci_PresentInDCI)
3593       {
3594          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3595          return RFAILED;
3596       }
3597       /* TODO */
3598       *(controlRset->tci_PresentInDCI);
3599 #endif
3600
3601       controlRSet->pdcch_DMRS_ScramblingID = NULLP;
3602       DU_ALLOC(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
3603       if(!controlRSet->pdcch_DMRS_ScramblingID)
3604       {
3605          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3606          return RFAILED;
3607       }
3608       if(pdcchCfg == NULLP)
3609          *(controlRSet->pdcch_DMRS_ScramblingID) = SCRAMBLING_ID;
3610       else
3611          *(controlRSet->pdcch_DMRS_ScramblingID) = pdcchCfg->cRSetToAddModList[idx].dmrsScramblingId;
3612    }
3613    return ROK;
3614 } /* End BuildControlRSetToAddModList */
3615
3616 /*******************************************************************
3617  *
3618  * @brief Build search space to add/modify list
3619  *
3620  * @details
3621  *
3622  *    Function : BuildSearchSpcToAddModList
3623  *
3624  *    Functionality: Build search space to add/modify list
3625  *
3626  * @params[in] 
3627  * @return ROK     - success
3628  *         RFAILED - failure
3629  *
3630  * ****************************************************************/
3631 uint8_t BuildSearchSpcToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
3632 {
3633    uint8_t idx;
3634    uint8_t numBytes;
3635    uint8_t byteIdx;
3636    uint8_t bitsUnused;
3637    uint8_t elementCnt;
3638    struct SearchSpace *searchSpc;
3639
3640    if(pdcchCfg == NULLP)
3641       elementCnt = 1;
3642    else
3643       elementCnt = pdcchCfg->numSearchSpcToAddMod;
3644
3645    searchSpcList->list.count = elementCnt;
3646    searchSpcList->list.size = elementCnt * sizeof(struct SearchSpace *);
3647
3648    searchSpcList->list.array = NULLP;
3649    DU_ALLOC(searchSpcList->list.array, searchSpcList->list.size);
3650    if(!searchSpcList->list.array)
3651    {
3652       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3653       return RFAILED;
3654    }
3655
3656    for(idx = 0; idx < elementCnt; idx++)
3657    {
3658       searchSpcList->list.array[idx] = NULLP;
3659       DU_ALLOC(searchSpcList->list.array[idx], sizeof(struct SearchSpace));
3660       if(!searchSpcList->list.array[idx])
3661       {
3662          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3663          return RFAILED;
3664       }
3665    }
3666
3667    for(idx = 0; idx < elementCnt; idx++)
3668    {
3669       searchSpc = searchSpcList->list.array[idx];
3670
3671       if(pdcchCfg == NULLP)
3672          searchSpc->searchSpaceId = PDCCH_SRCH_SPC_TWO_ID;
3673       else
3674          searchSpc->searchSpaceId = pdcchCfg->searchSpcToAddModList[idx].searchSpaceId;
3675
3676       searchSpc->controlResourceSetId = NULLP;
3677       DU_ALLOC(searchSpc->controlResourceSetId, sizeof(ControlResourceSetId_t));
3678       if(!searchSpc->controlResourceSetId)
3679       {
3680          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3681          return RFAILED;
3682       }
3683       if(pdcchCfg == NULLP)
3684          *(searchSpc->controlResourceSetId) = PDCCH_CTRL_RSRC_SET_ONE_ID;
3685       else
3686          *(searchSpc->controlResourceSetId) = pdcchCfg->searchSpcToAddModList[idx].cRSetId;
3687
3688       searchSpc->monitoringSlotPeriodicityAndOffset = NULLP;
3689       DU_ALLOC(searchSpc->monitoringSlotPeriodicityAndOffset, sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
3690       if(!searchSpc->monitoringSlotPeriodicityAndOffset)
3691       {
3692          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3693          return RFAILED;
3694       }
3695       if(pdcchCfg == NULLP)
3696          searchSpc->monitoringSlotPeriodicityAndOffset->present = SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
3697       else
3698          searchSpc->monitoringSlotPeriodicityAndOffset->present = pdcchCfg->searchSpcToAddModList[idx].mSlotPeriodicityAndOffset;
3699
3700       searchSpc->duration = NULLP;
3701       searchSpc->monitoringSymbolsWithinSlot = NULLP;
3702       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot, sizeof(BIT_STRING_t));
3703       if(!searchSpc->monitoringSymbolsWithinSlot)
3704       {
3705          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3706          return RFAILED;
3707       }
3708
3709       /* Values taken from reference logs :
3710        * size 2 bytes
3711        * 2 LSBs unsued
3712        * Bit string stores 8000
3713        */
3714       numBytes = 2;
3715       bitsUnused = 2;
3716       searchSpc->monitoringSymbolsWithinSlot->size = numBytes * sizeof(uint8_t);
3717       searchSpc->monitoringSymbolsWithinSlot->buf = NULLP;
3718       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot->buf, searchSpc->monitoringSymbolsWithinSlot->size);
3719       if(!searchSpc->monitoringSymbolsWithinSlot->buf)
3720       {
3721          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3722          return RFAILED;
3723       }
3724       if(pdcchCfg == NULLP)
3725       {
3726          byteIdx = 0;
3727          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = PDCCH_SYMBOL_WITHIN_SLOT /* setting MSB to 128 i.e. 0x80 */;
3728          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = 0;
3729       }
3730       else
3731          memcpy(searchSpc->monitoringSymbolsWithinSlot->buf, pdcchCfg->searchSpcToAddModList[idx].mSymbolsWithinSlot, numBytes);
3732       searchSpc->monitoringSymbolsWithinSlot->bits_unused = bitsUnused;
3733
3734       searchSpc->nrofCandidates = NULLP;
3735       DU_ALLOC(searchSpc->nrofCandidates, sizeof(struct SearchSpace__nrofCandidates));
3736       if(!searchSpc->nrofCandidates)
3737       {
3738          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3739          return RFAILED;
3740       }
3741
3742       if(pdcchCfg == NULLP)
3743       {
3744          searchSpc->nrofCandidates->aggregationLevel1 = PDCCH_SRCH_SPC_TWO_AGG_LVL1_CANDIDATE;
3745          searchSpc->nrofCandidates->aggregationLevel2 = PDCCH_SRCH_SPC_TWO_AGG_LVL2_CANDIDATE;
3746          searchSpc->nrofCandidates->aggregationLevel4 = PDCCH_SRCH_SPC_TWO_AGG_LVL4_CANDIDATE;
3747          searchSpc->nrofCandidates->aggregationLevel8 = PDCCH_SRCH_SPC_TWO_AGG_LVL8_CANDIDATE;
3748          searchSpc->nrofCandidates->aggregationLevel16 = PDCCH_SRCH_SPC_TWO_AGG_LVL16_CANDIDATE;
3749       }
3750       else
3751       {
3752          searchSpc->nrofCandidates->aggregationLevel1 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel1;
3753          searchSpc->nrofCandidates->aggregationLevel2 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel2;
3754          searchSpc->nrofCandidates->aggregationLevel4 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel4;
3755          searchSpc->nrofCandidates->aggregationLevel8 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel8;
3756          searchSpc->nrofCandidates->aggregationLevel16 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel16;
3757       }
3758
3759       searchSpc->searchSpaceType = NULLP;
3760       DU_ALLOC(searchSpc->searchSpaceType, sizeof(struct SearchSpace__searchSpaceType));
3761       if(!searchSpc->searchSpaceType)
3762       {
3763          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3764          return RFAILED;
3765       }
3766       if(pdcchCfg == NULLP)
3767          searchSpc->searchSpaceType->present = SearchSpace__searchSpaceType_PR_ue_Specific;
3768       else
3769          searchSpc->searchSpaceType->present = pdcchCfg->searchSpcToAddModList[idx].searchSpaceType;
3770
3771       searchSpc->searchSpaceType->choice.ue_Specific = NULLP;
3772       DU_ALLOC(searchSpc->searchSpaceType->choice.ue_Specific, sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
3773       if(!searchSpc->searchSpaceType->choice.ue_Specific)
3774       {
3775          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3776          return RFAILED;
3777       }  
3778       if(pdcchCfg == NULLP)
3779          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
3780       else
3781          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = pdcchCfg->searchSpcToAddModList[idx].ueSpecificDciFormat;
3782    }
3783    return ROK;
3784 }/* End BuildSearchSpcToAddModList */
3785
3786 /*******************************************************************
3787  *
3788  * @brief Builds BWP DL dedicated PDCCH config
3789  *
3790  * @details
3791  *
3792  *    Function : BuildBWPDlDedPdcchCfg
3793  *
3794  *    Functionality: Builds BWP DL dedicated PDCCH config
3795  *
3796  * @params[in] struct PDCCH_Config *pdcchCfg
3797  *
3798  * @return ROK     - success
3799  *         RFAILED - failure
3800  *
3801  * ****************************************************************/
3802 uint8_t BuildBWPDlDedPdcchCfg(PdcchConfig *pdcchCfgDb, struct PDCCH_Config *pdcchCfg)
3803 {
3804    pdcchCfg->controlResourceSetToAddModList = NULLP;
3805    DU_ALLOC(pdcchCfg->controlResourceSetToAddModList, sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
3806    if(!pdcchCfg->controlResourceSetToAddModList)
3807    {
3808       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
3809       return RFAILED;
3810    }
3811
3812    if(BuildControlRSetToAddModList(pdcchCfgDb, pdcchCfg->controlResourceSetToAddModList) != ROK)
3813    {
3814       DU_LOG("\nERROR  --> F1AP : Failed in BuildControlRSetToAddModList()");
3815       return RFAILED;
3816    }
3817
3818    pdcchCfg->controlResourceSetToReleaseList = NULLP;
3819
3820    pdcchCfg->searchSpacesToAddModList = NULLP;
3821    DU_ALLOC(pdcchCfg->searchSpacesToAddModList, sizeof(struct PDCCH_Config__searchSpacesToAddModList));
3822    if(!pdcchCfg->searchSpacesToAddModList)
3823    {
3824       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
3825       return RFAILED;
3826    }
3827
3828    if(BuildSearchSpcToAddModList(pdcchCfgDb, pdcchCfg->searchSpacesToAddModList) != ROK)
3829    {
3830       DU_LOG("\nERROR  --> F1AP : Failed in BuildSearchSpcToAddModList()");
3831       return RFAILED;
3832    }
3833
3834    pdcchCfg->searchSpacesToReleaseList = NULLP;
3835    pdcchCfg->downlinkPreemption = NULLP;
3836    pdcchCfg->tpc_PUSCH = NULLP;
3837    pdcchCfg->tpc_PUCCH = NULLP;
3838    pdcchCfg->tpc_SRS = NULLP;
3839
3840    return ROK;
3841 }
3842
3843 /*******************************************************************
3844  *
3845  * @brief Builds DMRS DL PDSCH Mapping type A
3846  *
3847  * @details
3848  *
3849  *    Function : BuildDMRSDLPdschMapTypeA
3850  *
3851  *    Functionality: Builds DMRS DL PDSCH Mapping type A
3852  *
3853  * @params[in]
3854  * struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg
3855  * @return ROK     - success
3856  *         RFAILED - failure
3857  *
3858  * ****************************************************************/
3859 uint8_t BuildDMRSDLPdschMapTypeA(PdschConfig *pdschCfg, struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg)
3860 {
3861    dmrsDlCfg->present = PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup;
3862    dmrsDlCfg->choice.setup = NULLP;
3863    DU_ALLOC(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
3864    if(!dmrsDlCfg->choice.setup)
3865    {
3866       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
3867       return RFAILED;
3868    }
3869
3870    dmrsDlCfg->choice.setup->dmrs_Type = NULLP;
3871    dmrsDlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
3872    DU_ALLOC(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
3873    if(!dmrsDlCfg->choice.setup->dmrs_AdditionalPosition)
3874    {
3875       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
3876       return RFAILED;
3877    }
3878    if(pdschCfg == NULLP)
3879       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS;
3880    else
3881       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = pdschCfg->dmrsDlCfgForPdschMapTypeA.addPos;
3882
3883    dmrsDlCfg->choice.setup->maxLength = NULLP;
3884    dmrsDlCfg->choice.setup->scramblingID0 = NULLP;
3885    dmrsDlCfg->choice.setup->scramblingID1 = NULLP;
3886    dmrsDlCfg->choice.setup->phaseTrackingRS = NULLP;
3887
3888    return ROK;
3889 }
3890
3891 /*******************************************************************
3892  *
3893  * @brief Builds TCI states to add/modify list
3894  *
3895  * @details
3896  *
3897  *    Function : BuildTCIStatesToAddModList
3898  *
3899  *    Functionality:Builds TCI states to add/modify list
3900  *
3901  * @params[in] 
3902  * struct PDSCH_Config__tci_StatesToAddModList *tciStatesList
3903  *
3904  * @return ROK     - success
3905  *         RFAILED - failure
3906  *
3907  * ****************************************************************/
3908 uint8_t BuildTCIStatesToAddModList(struct PDSCH_Config__tci_StatesToAddModList *tciStatesList)
3909 {
3910    return ROK;
3911 }
3912
3913 /*******************************************************************
3914  *
3915  * @brief Builds PDSCH time domain allocation list
3916  *
3917  * @details
3918  *
3919  *    Function : BuildPdschTimeDomAllocList
3920  *
3921  *    Functionality: Builds PDSCH time domain allocation list
3922  *
3923  * @params[in] 
3924  * struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
3925  *
3926  * @return ROK     - success
3927  *         RFAILED - failure
3928  *
3929  * ****************************************************************/
3930 uint8_t BuildPdschTimeDomAllocList(PdschConfig *pdschCfg, struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
3931 {
3932    uint8_t idx;
3933    uint8_t elementCnt;
3934    struct PDSCH_TimeDomainResourceAllocation *timeDomAlloc;
3935
3936    timeDomAllocList->present = PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup;
3937
3938    timeDomAllocList->choice.setup = NULLP;
3939    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PDSCH_TimeDomainResourceAllocationList));
3940    if(!timeDomAllocList->choice.setup)
3941    {
3942       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
3943       return RFAILED;
3944    }
3945
3946 if(pdschCfg == NULLP)
3947    elementCnt = 2;
3948 else
3949 elementCnt = pdschCfg->numTimeDomRsrcAlloc;
3950    timeDomAllocList->choice.setup->list.count = elementCnt;
3951    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(struct PDSCH_TimeDomainResourceAllocation *);
3952
3953    timeDomAllocList->choice.setup->list.array = NULLP;
3954    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
3955    if(!timeDomAllocList->choice.setup->list.array)
3956    {
3957       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
3958       return RFAILED;
3959    }
3960
3961    for(idx = 0; idx < elementCnt; idx++)
3962    {
3963       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
3964       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], \
3965             sizeof(struct PDSCH_TimeDomainResourceAllocation));
3966       if(!timeDomAllocList->choice.setup->list.array[idx])
3967       {
3968          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
3969          return RFAILED;
3970       }
3971    }
3972
3973    if(pdschCfg == NULLP)
3974    {
3975       idx = 0;
3976       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
3977       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
3978       if(!timeDomAlloc->k0)
3979       {
3980          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
3981          return RFAILED;
3982       }
3983       *(timeDomAlloc->k0) = 0;
3984       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
3985       timeDomAlloc->startSymbolAndLength = \
3986                                            calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
3987
3988       idx++;
3989       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
3990       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
3991       if(!timeDomAlloc->k0)
3992       {
3993          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
3994          return RFAILED;
3995       }
3996       *(timeDomAlloc->k0) = 1;
3997       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
3998       timeDomAlloc->startSymbolAndLength = calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
3999    }
4000    else
4001    {
4002       for(idx = 0; idx < elementCnt; idx++)
4003       {
4004          timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4005          DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4006          if(!timeDomAlloc->k0)
4007          {
4008             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4009             return RFAILED;
4010          }
4011          *(timeDomAlloc->k0) = *(pdschCfg->timeDomRsrcAllociList[idx].k0);
4012          timeDomAlloc->mappingType = pdschCfg->timeDomRsrcAllociList[idx].mappingType;
4013          timeDomAlloc->startSymbolAndLength = pdschCfg->timeDomRsrcAllociList[idx].startSymbolAndLength;
4014       }
4015    }
4016
4017    return ROK;
4018 }
4019
4020 /*******************************************************************
4021  *
4022  * @brief Builds PDSCH PRB Bundling type
4023  *
4024  * @details
4025  *
4026  *    Function : BuildPdschPrbBundlingType
4027  *
4028  *    Functionality: Builds PDSCH PRB Bundling type
4029  *
4030  * @params[in] 
4031  * struct PDSCH_Config__prb_BundlingType *prbBndlType
4032  *
4033  * @return ROK     - success
4034  *         RFAILED - failure
4035  *
4036  * ****************************************************************/
4037 uint8_t BuildPdschPrbBundlingType(PdschConfig *pdschCfg, struct PDSCH_Config__prb_BundlingType *prbBndlType)
4038 {
4039    if(pdschCfg == NULLP)
4040       prbBndlType->present = PDSCH_Config__prb_BundlingType_PR_staticBundling;
4041    else
4042       prbBndlType->present = pdschCfg->bundlingType;
4043
4044    prbBndlType->choice.staticBundling = NULLP;
4045    DU_ALLOC(prbBndlType->choice.staticBundling, \
4046          sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
4047    if(!prbBndlType->choice.staticBundling)
4048    {
4049       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschPrbBundlingType");
4050       return RFAILED;
4051    }
4052    prbBndlType->choice.staticBundling->bundleSize = NULLP;
4053
4054    return ROK;
4055 }
4056
4057 /*******************************************************************
4058  *
4059  * @brief Builds BWP DL dedicated PDSCH config 
4060  *
4061  * @details
4062  *
4063  *    Function : BuildBWPDlDedPdschCfg
4064  *
4065  *    Functionality: Builds BWP DL dedicated PDSCH config
4066  *
4067  * @params[in] struct PDSCH_Config *pdschCfg
4068  *
4069  * @return ROK     - success
4070  *         RFAILED - failure
4071  *
4072  * ****************************************************************/
4073 uint8_t BuildBWPDlDedPdschCfg(PdschConfig *pdschCfgDb, struct PDSCH_Config *pdschCfg)
4074 {
4075    pdschCfg->dataScramblingIdentityPDSCH = NULLP;
4076
4077    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA = NULLP;
4078    DU_ALLOC(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
4079    if(!pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
4080    {
4081       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4082       return RFAILED;
4083    }
4084
4085    if(BuildDMRSDLPdschMapTypeA(pdschCfgDb, pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA) != ROK)
4086    {
4087       return RFAILED;
4088    }
4089
4090    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeB = NULLP;
4091    pdschCfg->tci_StatesToAddModList = NULLP;
4092    pdschCfg->tci_StatesToReleaseList = NULLP;
4093    pdschCfg->vrb_ToPRB_Interleaver = NULLP;
4094 #if 0
4095    DU_ALLOC(pdschCfg->tci_StatesToAddModList, sizeof(struct PDSCH_Config__tci_StatesToAddModList));
4096    if(!pdschCfg->tci_StatesToAddModList)
4097    {
4098       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4099       return RFAILED;
4100    }
4101    if(BuildTCIStatesToAddModList(pdschCfg->tci_StatesToAddModList) != ROK)
4102    {
4103       return RFAILED;
4104    }
4105 #endif
4106
4107 if(pdschCfgDb == NULLP)
4108    pdschCfg->resourceAllocation = RES_ALLOC_TYPE;
4109 else
4110 pdschCfg->resourceAllocation = pdschCfgDb->resourceAllocType;
4111
4112    pdschCfg->pdsch_TimeDomainAllocationList = NULLP;
4113    DU_ALLOC(pdschCfg->pdsch_TimeDomainAllocationList, sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
4114    if(!pdschCfg->pdsch_TimeDomainAllocationList)
4115    {
4116       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4117       return RFAILED;
4118    }
4119    if(BuildPdschTimeDomAllocList(pdschCfgDb, pdschCfg->pdsch_TimeDomainAllocationList) != ROK)
4120    {
4121       return RFAILED;
4122    }
4123
4124    pdschCfg->pdsch_AggregationFactor = NULLP;
4125    pdschCfg->rateMatchPatternToAddModList = NULLP;
4126    pdschCfg->rateMatchPatternToReleaseList = NULLP;
4127    pdschCfg->rateMatchPatternGroup1 = NULLP;
4128    pdschCfg->rateMatchPatternGroup2 = NULLP;
4129    if(pdschCfgDb == NULLP)
4130       pdschCfg->rbg_Size = PDSCH_RBG_SIZE;
4131    else
4132       pdschCfg->rbg_Size = pdschCfgDb->rbgSize;
4133    pdschCfg->mcs_Table = NULLP;
4134
4135    pdschCfg->maxNrofCodeWordsScheduledByDCI = NULLP;
4136    DU_ALLOC(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
4137    if(!pdschCfg->maxNrofCodeWordsScheduledByDCI)
4138    {
4139       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4140       return RFAILED;
4141    }
4142    if(pdschCfgDb == NULLP)
4143       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = PDSCH_MAX_CODEWORD_SCH_BY_DCI;
4144    else
4145       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = pdschCfgDb->numCodeWordsSchByDci;
4146
4147    if(BuildPdschPrbBundlingType(pdschCfgDb, &pdschCfg->prb_BundlingType) != ROK)
4148    {
4149       return RFAILED;
4150    }
4151
4152    pdschCfg->zp_CSI_RS_ResourceToAddModList = NULLP;
4153    pdschCfg->zp_CSI_RS_ResourceToReleaseList = NULLP;
4154    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4155    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4156    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4157    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4158    pdschCfg->p_ZP_CSI_RS_ResourceSet = NULLP;
4159
4160    return ROK;
4161 }
4162
4163 /*******************************************************************
4164  *
4165  * @brief Builds intitial DL BWP
4166  * @details
4167  *
4168  *    Function : BuildInitialDlBWP 
4169  *
4170  *    Functionality: Builds intitial DL BWP in spCellCfgDed
4171  *
4172  * @params[in] BWP_DownlinkDedicated_t *dlBwp
4173  *
4174  * @return ROK     - success
4175  *         RFAILED - failure
4176  *
4177  * ****************************************************************/
4178 uint8_t BuildInitialDlBWP(InitialDlBwp *initiDlBwp, BWP_DownlinkDedicated_t *dlBwp)
4179 {
4180    PdcchConfig *pdcchCfg = NULLP;
4181    PdschConfig *pdschCfg = NULLP;
4182
4183    if(initiDlBwp)
4184    {
4185       if(initiDlBwp->pdcchPresent)
4186          pdcchCfg = &initiDlBwp->pdcchCfg;
4187       if(initiDlBwp->pdschPresent)
4188          pdschCfg = &initiDlBwp->pdschCfg;
4189    }
4190
4191    dlBwp->pdcch_Config = NULLP;
4192    DU_ALLOC(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
4193    if(!dlBwp->pdcch_Config)
4194    {
4195       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4196       return RFAILED;
4197    }
4198    dlBwp->pdcch_Config->present = BWP_DownlinkDedicated__pdcch_Config_PR_setup; 
4199
4200    dlBwp->pdcch_Config->choice.setup = NULLP;
4201    DU_ALLOC(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
4202    if(!dlBwp->pdcch_Config->choice.setup)
4203    {
4204       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4205       return RFAILED;
4206    }
4207    if(BuildBWPDlDedPdcchCfg(pdcchCfg, dlBwp->pdcch_Config->choice.setup) != ROK)
4208    {
4209       return RFAILED;
4210    }
4211
4212    dlBwp->pdsch_Config = NULLP;
4213    DU_ALLOC(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
4214    if(!dlBwp->pdsch_Config)
4215    {
4216       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4217       return RFAILED;
4218    }
4219    dlBwp->pdsch_Config->present = BWP_DownlinkDedicated__pdsch_Config_PR_setup;
4220
4221    dlBwp->pdsch_Config->choice.setup = NULLP;
4222    DU_ALLOC(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
4223    if(!dlBwp->pdsch_Config->choice.setup)
4224    {
4225       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4226       return RFAILED;
4227    }
4228
4229    if(BuildBWPDlDedPdschCfg(pdschCfg, dlBwp->pdsch_Config->choice.setup) != ROK)
4230    {
4231       return RFAILED;
4232    }
4233
4234    dlBwp->sps_Config = NULLP;
4235    dlBwp->radioLinkMonitoringConfig = NULLP; 
4236    return ROK;
4237 }
4238
4239 /*******************************************************************
4240  *
4241  * @brief Builds DMRS UL Pusch Mapping type A
4242  *
4243  * @details
4244  *
4245  *    Function : BuildDMRSULPuschMapTypeA
4246  *
4247  *    Functionality: Builds DMRS UL Pusch Mapping type A
4248  *
4249  * @params[in] 
4250  *    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg
4251  * @return ROK     - success
4252  *         RFAILED - failure
4253  *
4254  * ****************************************************************/
4255 uint8_t BuildDMRSULPuschMapTypeA(DmrsUlCfg *ulDmrsCfgDb, struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg)
4256 {
4257    dmrsUlCfg->present = PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup;
4258    dmrsUlCfg->choice.setup= NULLP;
4259    DU_ALLOC(dmrsUlCfg->choice.setup, sizeof(DMRS_UplinkConfig_t));
4260    if(!dmrsUlCfg->choice.setup)
4261    {
4262       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4263       return RFAILED;
4264    }
4265
4266    dmrsUlCfg->choice.setup->dmrs_Type = NULLP;
4267    dmrsUlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4268    DU_ALLOC(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4269    if(!dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
4270    {
4271       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4272       return RFAILED;
4273    }
4274    if(ulDmrsCfgDb == NULLP)
4275       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS; 
4276    else
4277       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = ulDmrsCfgDb->addPos;
4278
4279    dmrsUlCfg->choice.setup->phaseTrackingRS = NULLP;
4280    dmrsUlCfg->choice.setup->maxLength = NULLP;
4281    dmrsUlCfg->choice.setup->transformPrecodingDisabled = NULLP;
4282    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled, sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
4283    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled)
4284    {
4285       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4286       return RFAILED;
4287    }
4288
4289    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0 = NULLP;
4290    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
4291          sizeof(long));
4292    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0)
4293    {
4294       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4295       return RFAILED;
4296    }
4297    if(ulDmrsCfgDb == NULLP)
4298       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = SCRAMBLING_ID;
4299    else
4300       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = ulDmrsCfgDb->transPrecodDisabled.scramblingId0;
4301
4302    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID1 = NULLP;
4303    dmrsUlCfg->choice.setup->transformPrecodingEnabled = NULLP;
4304    return ROK;
4305 }
4306
4307 /*******************************************************************
4308  *
4309  * @brief Build PUSCH time domain allocation list
4310  *
4311  * @details
4312  *
4313  *    Function : BuildPuschTimeDomAllocList
4314  *
4315  *    Functionality: Build PUSCH time domain allocation list
4316  *
4317  * @params[in] 
4318  * struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList
4319  *
4320  * @return ROK     - success
4321  *         RFAILED - failure
4322  *
4323  * ****************************************************************/
4324 uint8_t BuildPuschTimeDomAllocList(PuschCfg *puschCfgDb, struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList)
4325 {
4326    uint8_t idx;
4327    uint8_t elementCnt;
4328    PUSCH_TimeDomainResourceAllocation_t  *timeDomAlloc;
4329
4330    timeDomAllocList->present = PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup;
4331    timeDomAllocList->choice.setup = NULLP;
4332    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PUSCH_TimeDomainResourceAllocationList));
4333    if(!timeDomAllocList->choice.setup)
4334    {
4335       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4336       return RFAILED;
4337    }
4338
4339    if(puschCfgDb == NULLP)
4340       elementCnt = 2;
4341    else
4342       elementCnt = puschCfgDb->numTimeDomRsrcAlloc;
4343
4344    timeDomAllocList->choice.setup->list.count = elementCnt;
4345    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(PUSCH_TimeDomainResourceAllocation_t *);
4346    timeDomAllocList->choice.setup->list.array = NULLP;
4347    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4348    if(!timeDomAllocList->choice.setup->list.array)
4349    {
4350       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4351       return RFAILED;
4352    }
4353
4354    for(idx = 0; idx < elementCnt; idx++)
4355    {
4356       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4357       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], sizeof(PUSCH_TimeDomainResourceAllocation_t));
4358       if(!timeDomAllocList->choice.setup->list.array[idx])
4359       {
4360          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4361          return RFAILED;
4362       }
4363    }
4364
4365    for(idx = 0; idx < elementCnt; idx++)
4366    {
4367       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4368       DU_ALLOC(timeDomAlloc->k2, sizeof(long));
4369       if(!timeDomAlloc->k2)
4370       {
4371          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4372          return RFAILED;
4373       }
4374       if(puschCfgDb == NULLP)
4375       {
4376          if(idx == 0)
4377             *(timeDomAlloc->k2) = PUSCH_K2_CFG1;
4378          else if(idx == 1)
4379             *(timeDomAlloc->k2) = PUSCH_K2_CFG2;
4380
4381          timeDomAlloc->mappingType = PUSCH_MAPPING_TYPE_A;
4382          timeDomAlloc->startSymbolAndLength = calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
4383       }
4384       else
4385       {
4386          *(timeDomAlloc->k2) = puschCfgDb->timeDomRsrcAllocList[idx].k2;
4387          timeDomAlloc->mappingType = puschCfgDb->timeDomRsrcAllocList[idx].mappingType;
4388          timeDomAlloc->startSymbolAndLength = puschCfgDb->timeDomRsrcAllocList[idx].startSymbolAndLength;
4389       }
4390    }
4391
4392    return ROK;
4393 }
4394
4395 /*******************************************************************
4396  *
4397  * @brief Builds BWP UL dedicated PUSCH Config
4398  *
4399  * @details
4400  *
4401  *    Function : BuildBWPUlDedPuschCfg
4402  *
4403  *    Functionality:
4404  *      Builds BWP UL dedicated PUSCH Config
4405  *
4406  * @params[in] : PUSCH_Config_t *puschCfg
4407  *    
4408  * @return ROK     - success
4409  *         RFAILED - failure
4410  *
4411  * ****************************************************************/
4412 uint8_t BuildBWPUlDedPuschCfg(PuschCfg *puschCfgDb, PUSCH_Config_t *puschCfg)
4413 {
4414    DmrsUlCfg *ulDmrsCfg = NULLP;
4415    
4416    if(puschCfgDb)
4417       ulDmrsCfg = &puschCfgDb->dmrsUlCfgForPuschMapTypeA;
4418
4419    puschCfg->dataScramblingIdentityPUSCH = NULLP;
4420    DU_ALLOC(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
4421    if(!puschCfg->dataScramblingIdentityPUSCH)
4422    {
4423       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4424       return RFAILED;
4425    }
4426    if(puschCfgDb == NULLP)
4427       *(puschCfg->dataScramblingIdentityPUSCH) = SCRAMBLING_ID;
4428    else
4429       *(puschCfg->dataScramblingIdentityPUSCH) = puschCfgDb->dataScramblingId;
4430
4431    puschCfg->txConfig = NULLP;
4432    puschCfg->dmrs_UplinkForPUSCH_MappingTypeA = NULLP;
4433    DU_ALLOC(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
4434    if(!puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
4435    {
4436       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4437       return RFAILED;
4438    }
4439
4440    if(BuildDMRSULPuschMapTypeA(ulDmrsCfg, puschCfg->dmrs_UplinkForPUSCH_MappingTypeA) != ROK)
4441    {
4442       return RFAILED;
4443    }
4444
4445    puschCfg->dmrs_UplinkForPUSCH_MappingTypeB = NULLP;
4446    puschCfg->pusch_PowerControl = NULLP;
4447    puschCfg->frequencyHopping = NULLP;
4448    puschCfg->frequencyHoppingOffsetLists = NULLP;
4449
4450    if(puschCfgDb == NULLP)
4451       puschCfg->resourceAllocation = RES_ALLOC_TYPE;
4452    else
4453       puschCfg->resourceAllocation = puschCfgDb->resourceAllocType;
4454
4455    puschCfg->pusch_TimeDomainAllocationList = NULLP;
4456    DU_ALLOC(puschCfg->pusch_TimeDomainAllocationList, sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
4457    if(!puschCfg->pusch_TimeDomainAllocationList)
4458    {
4459       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4460       return RFAILED;
4461    }
4462
4463    if(BuildPuschTimeDomAllocList(puschCfgDb, puschCfg->pusch_TimeDomainAllocationList) != ROK)
4464    {
4465       return RFAILED;
4466    }
4467
4468    puschCfg->pusch_AggregationFactor = NULLP;
4469    puschCfg->mcs_Table = NULLP;
4470    puschCfg->mcs_TableTransformPrecoder = NULLP;
4471    puschCfg->transformPrecoder = NULLP;
4472    DU_ALLOC(puschCfg->transformPrecoder, sizeof(long));
4473    if(!puschCfg->transformPrecoder)
4474    {
4475       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4476       return RFAILED;
4477    }
4478    if(puschCfgDb == NULLP)
4479       *(puschCfg->transformPrecoder) = PUSCH_TRANSFORM_PRECODER;
4480    else
4481       *(puschCfg->transformPrecoder) = puschCfgDb->transformPrecoder;
4482
4483    puschCfg->codebookSubset = NULLP;
4484    puschCfg->maxRank = NULLP;
4485    puschCfg->rbg_Size = NULLP;
4486    puschCfg->uci_OnPUSCH = NULLP;
4487    puschCfg->tp_pi2BPSK = NULLP;
4488
4489    return ROK;
4490 }
4491
4492 /*******************************************************************
4493  *
4494  * @brief Builds PUCCH resource set add/modify list
4495  *
4496  * @details
4497  *
4498  *    Function : BuildPucchRsrcSetAddModList
4499  *
4500  *    Functionality:
4501  *      Builds PUCCH resource set add/modify list
4502  *
4503  * @params[in] : PucchResrcSetCfg *rsrcSetCfgDb
4504  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4505  *
4506  * @return ROK     - success
4507  *         RFAILED - failure
4508  *
4509  * ****************************************************************/
4510 uint8_t BuildPucchRsrcSetAddModList(PucchResrcSetCfg *rsrcSetCfgDb, \
4511    struct PUCCH_Config__resourceSetToAddModList *resourceSetToAddModList)
4512 {
4513    uint8_t elementCnt = 0, rsrcSetIdx = 0, rsrcIdx = 0;
4514    PUCCH_ResourceSet_t *rsrcSet = NULLP;
4515
4516    if(rsrcSetCfgDb == NULLP)
4517       elementCnt = 1;
4518    else
4519       elementCnt = rsrcSetCfgDb->resrcSetToAddModListCount;
4520
4521    resourceSetToAddModList->list.count = elementCnt;
4522    resourceSetToAddModList->list.size = elementCnt * sizeof(PUCCH_ResourceSet_t *);
4523    DU_ALLOC(resourceSetToAddModList->list.array, resourceSetToAddModList->list.size);
4524    if(resourceSetToAddModList->list.array == NULLP)
4525    {
4526       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4527       return RFAILED;
4528    }
4529    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4530    {
4531       DU_ALLOC(resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
4532       if(resourceSetToAddModList->list.array[rsrcSetIdx] == NULLP)
4533       {
4534          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4535          return RFAILED;
4536       }
4537    }
4538
4539    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4540    {
4541       rsrcSet = resourceSetToAddModList->list.array[rsrcSetIdx];
4542
4543       /* Resource set Id */
4544       if(rsrcSetCfgDb == NULLP)
4545          rsrcSet->pucch_ResourceSetId = 1;
4546       else
4547          rsrcSet->pucch_ResourceSetId = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcSetId;
4548  
4549       /* Resource list of a resource set */
4550       if(rsrcSetCfgDb == NULLP)
4551          elementCnt = 1;
4552       else
4553          elementCnt = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcListCount;
4554       rsrcSet->resourceList.list.count = elementCnt;
4555       rsrcSet->resourceList.list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
4556       DU_ALLOC(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
4557       if(rsrcSet->resourceList.list.array == NULLP)
4558       {
4559          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4560          return RFAILED;
4561       }
4562
4563       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4564       {
4565          DU_ALLOC(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
4566          if(rsrcSet->resourceList.list.array[rsrcIdx] == NULLP)
4567          {
4568             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4569             return RFAILED;
4570          }
4571       }
4572       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4573       {
4574          if(rsrcSetCfgDb == NULLP)
4575             *(rsrcSet->resourceList.list.array[rsrcIdx]) = 1;
4576          else
4577             *(rsrcSet->resourceList.list.array[rsrcIdx]) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcList[rsrcIdx];
4578       }
4579
4580       /* Max payload size (minus 1) in a Resource set */
4581       rsrcSet->maxPayloadMinus1 = NULLP;
4582       if(rsrcSetCfgDb && rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize)
4583       {
4584          DU_ALLOC(rsrcSet->maxPayloadMinus1, sizeof(long));
4585          if(rsrcSet->maxPayloadMinus1 == NULLP)
4586          {
4587             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4588             return RFAILED;
4589          }
4590          *(rsrcSet->maxPayloadMinus1) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize;
4591       }
4592    }
4593    return ROK;
4594 }
4595
4596 /*******************************************************************
4597  *
4598  * @brief Builds PUCCH resource add/modify list
4599  *
4600  * @details
4601  *
4602  *    Function : BuildPucchRsrcAdddModList
4603  *
4604  *    Functionality:
4605  *      Builds PUCCH resource add/modify list
4606  *
4607  * @params[in] : PucchResrcCfg *rsrcSetCfgDb
4608  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4609  *
4610  * @return ROK     - success
4611  *         RFAILED - failure
4612  *
4613  * ****************************************************************/
4614 uint8_t BuildPucchRsrcAddModList(PucchResrcCfg *rsrcCfgDb, struct PUCCH_Config__resourceToAddModList  *resourceToAddModList)
4615 {
4616    uint8_t elementCnt = 0, rsrcIdx = 0;
4617    PUCCH_Resource_t *rsrc = NULLP;
4618
4619    if(rsrcCfgDb == NULLP)
4620       elementCnt = 1;
4621    else
4622       elementCnt = rsrcCfgDb->resrcToAddModListCount;
4623    resourceToAddModList->list.count = elementCnt;
4624    resourceToAddModList->list.size = elementCnt * sizeof(PUCCH_Resource_t *);
4625    DU_ALLOC(resourceToAddModList->list.array, resourceToAddModList->list.size);
4626    if(resourceToAddModList->list.array == NULLP)
4627    {
4628       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4629       return RFAILED;
4630    }
4631    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4632    {
4633       DU_ALLOC(resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
4634       if(resourceToAddModList->list.array[rsrcIdx] == NULLP)
4635       {
4636          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4637          return RFAILED;
4638       }
4639    }
4640
4641    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4642    {
4643       rsrc = resourceToAddModList->list.array[rsrcIdx];
4644
4645       if(rsrcCfgDb == NULLP)
4646       {
4647          rsrc->pucch_ResourceId = 1;
4648          rsrc->startingPRB = 0;
4649          rsrc->format.present = PUCCH_Resource__format_PR_format1; 
4650          DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4651          if(rsrc->format.choice.format1 == NULLP)
4652          {
4653             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4654             return RFAILED;
4655          }  
4656          rsrc->format.choice.format1->initialCyclicShift = 0;
4657          rsrc->format.choice.format1->nrofSymbols = 4;
4658          rsrc->format.choice.format1->startingSymbolIndex = 0;
4659          rsrc->format.choice.format1->timeDomainOCC = 0;
4660       }
4661       else
4662       {
4663          rsrc->pucch_ResourceId = rsrcCfgDb->resrcToAddModList[rsrcIdx].resrcId;
4664          rsrc->startingPRB = rsrcCfgDb->resrcToAddModList[rsrcIdx].startPrb;
4665          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop)
4666          {
4667             DU_ALLOC(rsrc->intraSlotFrequencyHopping, sizeof(long));
4668             if(rsrc->intraSlotFrequencyHopping == NULLP)
4669             {
4670                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4671                return RFAILED;
4672             }
4673             *(rsrc->intraSlotFrequencyHopping) = rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop;
4674          }
4675          else
4676             rsrc->intraSlotFrequencyHopping = NULLP;
4677
4678          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop)
4679          {
4680             DU_ALLOC(rsrc->secondHopPRB, sizeof(PRB_Id_t));
4681             if(rsrc->secondHopPRB == NULLP)
4682             {
4683                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4684                return RFAILED;
4685             }
4686             *(rsrc->secondHopPRB) = rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop;
4687          }
4688          else
4689             rsrc->secondHopPRB = NULLP;
4690          rsrc->format.present = covertPucchFormatIntEnumToRrcEnum(rsrcCfgDb->resrcToAddModList[rsrcIdx].pucchFormat); 
4691
4692          switch(rsrc->format.present)
4693          {
4694             case PUCCH_Resource__format_PR_NOTHING:
4695                break;
4696             case PUCCH_Resource__format_PR_format0:
4697                {
4698                   DU_ALLOC(rsrc->format.choice.format0, sizeof(PUCCH_format0_t));
4699                   if(rsrc->format.choice.format0 == NULLP)
4700                   {
4701                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4702                      return RFAILED;
4703                   }
4704                   rsrc->format.choice.format0->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->initialCyclicShift;
4705                   rsrc->format.choice.format0->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->numSymbols;
4706                   rsrc->format.choice.format0->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->startSymbolIdx;
4707                   break;
4708                }
4709
4710             case PUCCH_Resource__format_PR_format1:
4711                {
4712                   DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4713                   if(rsrc->format.choice.format1 == NULLP)
4714                   {
4715                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4716                      return RFAILED;
4717                   }  
4718                   rsrc->format.choice.format1->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->initialCyclicShift;
4719                   rsrc->format.choice.format1->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->numSymbols;
4720                   rsrc->format.choice.format1->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->startSymbolIdx;
4721                   rsrc->format.choice.format1->timeDomainOCC = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->timeDomOCC;
4722                   break;
4723                }
4724
4725             case PUCCH_Resource__format_PR_format2:
4726                {
4727                   DU_ALLOC(rsrc->format.choice.format2, sizeof(PUCCH_format2_t));
4728                   if(rsrc->format.choice.format2 == NULLP)
4729                   {
4730                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4731                      return RFAILED;
4732                   } 
4733                   rsrc->format.choice.format2->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numPrbs;
4734                   rsrc->format.choice.format2->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numSymbols;
4735                   rsrc->format.choice.format2->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->startSymbolIdx;
4736                   break;
4737                }
4738
4739             case PUCCH_Resource__format_PR_format3:
4740                {
4741                   DU_ALLOC(rsrc->format.choice.format3, sizeof(PUCCH_format3_t));
4742                   if(rsrc->format.choice.format3 == NULLP)
4743                   {
4744                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4745                      return RFAILED;
4746                   }
4747                   rsrc->format.choice.format3->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numPrbs;
4748                   rsrc->format.choice.format3->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numSymbols;
4749                   rsrc->format.choice.format3->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->startSymbolIdx;
4750                   break;
4751                }
4752
4753             case PUCCH_Resource__format_PR_format4:
4754                {
4755                   DU_ALLOC(rsrc->format.choice.format4, sizeof(PUCCH_format4_t));
4756                   if(rsrc->format.choice.format4 == NULLP)
4757                   {
4758                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4759                      return RFAILED;
4760                   }
4761                   rsrc->format.choice.format4->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->numSymbols;
4762                   rsrc->format.choice.format4->occ_Length = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occLen;
4763                   rsrc->format.choice.format4->occ_Index = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occIdx;
4764                   rsrc->format.choice.format4->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->startSymbolIdx;
4765                   break;
4766                }
4767          }
4768       }
4769    }
4770    return ROK;
4771 }
4772
4773 /*******************************************************************
4774  *
4775  * @brief Builds PUCCH format  config
4776  *
4777  * @details
4778  *
4779  *    Function : BuildPucchFormat
4780  *
4781  *    Functionality: Builds PUCCH format  config
4782  *
4783  * @params[in] : PucchFormatCfg *formatDb
4784  *               PUCCH_FormatConfig_t *format
4785  *
4786  * @return ROK     - success
4787  *         RFAILED - failure
4788  *
4789  * ****************************************************************/
4790 uint8_t BuildPucchFormat(PucchFormatCfg *formatDb, PUCCH_FormatConfig_t *format)
4791 {
4792    /* Inter Slot Fequency hopping */
4793    format->interslotFrequencyHopping = NULLP;
4794    if((formatDb != NULLP) && (formatDb->interSlotFreqHop == true))
4795    {
4796       DU_ALLOC(format->interslotFrequencyHopping, sizeof(long));
4797       if(format->interslotFrequencyHopping)
4798       {
4799          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4800          return RFAILED;
4801       }
4802       *(format->interslotFrequencyHopping) = PUCCH_FormatConfig__interslotFrequencyHopping_enabled;
4803    }
4804
4805    /* Additional DMRS */
4806    format->additionalDMRS = NULLP;
4807    if((formatDb != NULLP) && (formatDb->addDmrs == true))
4808    {
4809       DU_ALLOC(format->additionalDMRS, sizeof(long));
4810       if(format->additionalDMRS)
4811       {
4812          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4813          return RFAILED;
4814       }
4815       *(format->additionalDMRS) = PUCCH_FormatConfig__additionalDMRS_true;
4816    }
4817
4818     /* Maximum code rate */
4819    format->maxCodeRate = NULLP;
4820    if((formatDb != NULLP) && (formatDb->maxCodeRate != 0))
4821    {
4822       DU_ALLOC(format->maxCodeRate, sizeof(long));
4823       if(format->maxCodeRate)
4824       {
4825          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4826          return RFAILED;
4827       }  
4828       *(format->maxCodeRate) = formatDb->maxCodeRate;
4829    }
4830  
4831    /* Number of slots */
4832    format->nrofSlots = NULLP;
4833    if((formatDb == NULLP) || ((formatDb != NULLP) && (formatDb->numSlots != 0)))
4834    {
4835       DU_ALLOC(format->nrofSlots, sizeof(long));
4836       if(format->nrofSlots == NULLP)
4837       {
4838          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4839          return RFAILED;
4840       }
4841       if(formatDb == NULLP)
4842          *(format->nrofSlots) = PUCCH_FormatConfig__nrofSlots_n4;
4843       else
4844          *(format->nrofSlots) = formatDb->numSlots;
4845    }
4846
4847    /* Pi2BPSK*/
4848    format->pi2BPSK = NULLP;
4849    if((formatDb != NULLP) && (formatDb->pi2BPSK == true))
4850    {
4851       DU_ALLOC(format->pi2BPSK, sizeof(long));
4852       if(format->pi2BPSK)
4853       {     
4854          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4855          return RFAILED;
4856       }     
4857       *(format->pi2BPSK) = PUCCH_FormatConfig__pi2BPSK_enabled;
4858    }
4859
4860    /* Simultaneous HARQ ACK and CSI */
4861    format->simultaneousHARQ_ACK_CSI = NULLP;
4862    if((formatDb != NULLP) && (formatDb->harqAckCSI == true))
4863    {
4864       DU_ALLOC(format->simultaneousHARQ_ACK_CSI, sizeof(long));
4865       if(format->simultaneousHARQ_ACK_CSI)
4866       {     
4867          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4868          return RFAILED;
4869       }     
4870       *(format->simultaneousHARQ_ACK_CSI) = PUCCH_FormatConfig__simultaneousHARQ_ACK_CSI_true;
4871    }
4872
4873    return ROK;
4874 }
4875
4876
4877 /*******************************************************************
4878  *
4879  * @brief Builds PUCCH scheduling request list
4880  *
4881  * @details
4882  *
4883  *    Function : BuildPucchSchReqAddModList
4884  *
4885  *    Functionality:
4886  *      Builds PUCCH scheduling request list
4887  *
4888  * @params[in] : PucchSchedReqCfg *schReqDb
4889  *               struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList
4890  *
4891  * @return ROK     - success
4892  *         RFAILED - failure
4893  *
4894  * ****************************************************************/
4895 uint8_t BuildPucchSchReqAddModList(PucchSchedReqCfg *schReqDb, \
4896    struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList)
4897 {
4898    uint8_t elementCnt = 0, schReqIdx = 0;
4899    SchedulingRequestResourceConfig_t *schReqRsrc;
4900
4901    elementCnt = schReqDb->schedAddModListCount;
4902    schReqRsrcToAddModList->list.count = elementCnt;
4903    schReqRsrcToAddModList->list.size = elementCnt *sizeof(struct SchedulingRequestResourceConfig *);
4904
4905    schReqRsrcToAddModList->list.array = NULLP;
4906    DU_ALLOC(schReqRsrcToAddModList->list.array, schReqRsrcToAddModList->list.size);
4907    if(schReqRsrcToAddModList->list.array == NULLP)
4908    {
4909       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
4910       return RFAILED;
4911    }
4912
4913    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
4914    {
4915       DU_ALLOC(schReqRsrcToAddModList->list.array[schReqIdx], schReqRsrcToAddModList->list.size);
4916       if(schReqRsrcToAddModList->list.array[schReqIdx] == NULLP)
4917       {
4918          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
4919          return RFAILED;
4920       }
4921    }
4922
4923    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
4924    {
4925       schReqRsrc = schReqRsrcToAddModList->list.array[schReqIdx];
4926       schReqRsrc->schedulingRequestResourceId = schReqDb->schedAddModList[schReqIdx].resrcId;
4927       schReqRsrc->schedulingRequestID = schReqDb->schedAddModList[schReqIdx].requestId;
4928
4929       if(schReqDb->schedAddModList[schReqIdx].periodicity)
4930       {
4931          schReqRsrc->periodicityAndOffset = NULLP;
4932          DU_ALLOC(schReqRsrc->periodicityAndOffset, sizeof(struct SchedulingRequestResourceConfig__periodicityAndOffset));
4933          if(schReqRsrc->periodicityAndOffset == NULLP)
4934          {
4935             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
4936             return RFAILED;
4937          }
4938
4939          schReqRsrc->periodicityAndOffset->present = schReqDb->schedAddModList[schReqIdx].periodicity;
4940          switch(schReqRsrc->periodicityAndOffset->present)
4941          {
4942             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_NOTHING:
4943                break;
4944             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
4945                schReqRsrc->periodicityAndOffset->choice.sym2 = schReqDb->schedAddModList[schReqIdx].offset;
4946                break;
4947             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
4948                schReqRsrc->periodicityAndOffset->choice.sym6or7 = schReqDb->schedAddModList[schReqIdx].offset;
4949                break;
4950             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
4951                schReqRsrc->periodicityAndOffset->choice.sl1 = schReqDb->schedAddModList[schReqIdx].offset;
4952                break;
4953             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
4954                schReqRsrc->periodicityAndOffset->choice.sl2 = schReqDb->schedAddModList[schReqIdx].offset;
4955                break;
4956             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
4957                schReqRsrc->periodicityAndOffset->choice.sl4 = schReqDb->schedAddModList[schReqIdx].offset;
4958                break;
4959             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
4960                schReqRsrc->periodicityAndOffset->choice.sl5 = schReqDb->schedAddModList[schReqIdx].offset;
4961                break;
4962             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
4963                schReqRsrc->periodicityAndOffset->choice.sl8 = schReqDb->schedAddModList[schReqIdx].offset;
4964                break;
4965             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
4966                schReqRsrc->periodicityAndOffset->choice.sl10 = schReqDb->schedAddModList[schReqIdx].offset;
4967                break;
4968             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
4969                schReqRsrc->periodicityAndOffset->choice.sl16 = schReqDb->schedAddModList[schReqIdx].offset;
4970                break;
4971             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
4972                schReqRsrc->periodicityAndOffset->choice.sl20 = schReqDb->schedAddModList[schReqIdx].offset;
4973                break;
4974             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
4975                schReqRsrc->periodicityAndOffset->choice.sl40 = schReqDb->schedAddModList[schReqIdx].offset;
4976                break;
4977             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
4978                schReqRsrc->periodicityAndOffset->choice.sl80 = schReqDb->schedAddModList[schReqIdx].offset;
4979                break;
4980             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
4981                schReqRsrc->periodicityAndOffset->choice.sl160 = schReqDb->schedAddModList[schReqIdx].offset;
4982                break;
4983             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
4984                schReqRsrc->periodicityAndOffset->choice.sl320 = schReqDb->schedAddModList[schReqIdx].offset;
4985                break;
4986             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
4987                schReqRsrc->periodicityAndOffset->choice.sl640 = schReqDb->schedAddModList[schReqIdx].offset;
4988                break;
4989          }
4990       }
4991
4992       if(schReqDb->schedAddModList[schReqIdx].resrc)
4993       {
4994          schReqRsrc->resource = NULLP;
4995          DU_ALLOC(schReqRsrc->resource, sizeof(PUCCH_ResourceId_t));
4996          if(schReqRsrc->resource == NULLP)
4997          {
4998             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
4999             return RFAILED;
5000          }
5001          *(schReqRsrc->resource) = schReqDb->schedAddModList[schReqIdx].resrc;
5002
5003       }
5004    }
5005    return ROK;
5006 }
5007
5008 /*******************************************************************
5009  *
5010  * @brief Builds PUCCH multi csi resource list
5011  *
5012  * @details
5013  *
5014  *    Function : BuildPucchMultiCsiRsrcList
5015  *
5016  *    Functionality:
5017  *      Builds PUCCH multi csi resource list
5018  *
5019  * @params[in] : PucchMultiCsiCfg *multiCsiDb
5020  *               struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList
5021  *
5022  * @return ROK     - success
5023  *         RFAILED - failure
5024  *
5025  * ****************************************************************/
5026 uint8_t BuildPucchMultiCsiRsrcList(PucchMultiCsiCfg *multiCsiDb, struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList)
5027 {
5028    uint8_t elementCnt = 0, rsrcIdx = 0;
5029
5030    elementCnt = multiCsiDb->multiCsiResrcListCount;
5031    multiCsiRsrcList->list.count = elementCnt;
5032    multiCsiRsrcList->list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
5033    multiCsiRsrcList->list.array = NULLP;
5034    DU_ALLOC(multiCsiRsrcList->list.array, multiCsiRsrcList->list.size);
5035    if(multiCsiRsrcList->list.array == NULLP)
5036    {
5037       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5038       return RFAILED;
5039    }
5040
5041    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5042    {
5043       DU_ALLOC(multiCsiRsrcList->list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
5044       if(multiCsiRsrcList->list.array[rsrcIdx] == NULLP)
5045       {
5046          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5047          return RFAILED;
5048       }
5049    }
5050
5051    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5052    {
5053       *(multiCsiRsrcList->list.array[rsrcIdx]) = multiCsiDb->multiCsiResrcList[rsrcIdx];
5054    }
5055    return ROK;
5056 }
5057
5058 /*******************************************************************
5059  *
5060  * @brief Builds DL data -to- Ul Ack list
5061  *
5062  * @details
5063  *
5064  *    Function : BuildDlDataToUlAckList
5065  *
5066  *    Functionality: Builds DL data -to- Ul Ack list
5067  *
5068  * @params[in] : PucchDlDataToUlAck *dlDataToUlAckDb
5069  *               struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList
5070  *
5071  * @return ROK     - success
5072  *         RFAILED - failure
5073  *
5074  * ****************************************************************/
5075 uint8_t BuildDlDataToUlAckList(PucchDlDataToUlAck *dlDataToUlAckDb, struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList)
5076 {
5077    uint8_t elementCnt = 0, arrIdx = 0;
5078
5079    if(dlDataToUlAckDb == NULLP)
5080       elementCnt = 2;
5081    else
5082       elementCnt = dlDataToUlAckDb->dlDataToUlAckListCount;
5083
5084    dlDataToUlACKList->list.count = elementCnt;
5085    dlDataToUlACKList->list.size = elementCnt * sizeof(long *);
5086    DU_ALLOC(dlDataToUlACKList->list.array, dlDataToUlACKList->list.size);
5087    if(dlDataToUlACKList->list.array == NULLP)
5088    {
5089       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5090       return RFAILED;
5091    }   
5092
5093    for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5094    {
5095       DU_ALLOC(dlDataToUlACKList->list.array[arrIdx], sizeof(long));
5096       if(dlDataToUlACKList->list.array[arrIdx] == NULLP)
5097       {
5098          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5099          return RFAILED;
5100       }   
5101    }
5102
5103    if(dlDataToUlAckDb == NULLP)
5104    {
5105       arrIdx = 0;
5106       *(dlDataToUlACKList->list.array[arrIdx++]) = 1;
5107       *(dlDataToUlACKList->list.array[arrIdx]) = 2;
5108    }
5109    else
5110    {
5111       for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5112       {
5113          *(dlDataToUlACKList->list.array[arrIdx]) = dlDataToUlAckDb->dlDataToUlAckList[arrIdx];
5114       }
5115    }
5116    return ROK;
5117 }
5118
5119 /*******************************************************************
5120  *
5121  * @brief Builds BWP UL dedicated PUCCH Config
5122  *
5123  * @details
5124  *
5125  *    Function : BuildBWPUlDedPucchCfg
5126  *
5127  *    Functionality:
5128  *      Builds BWP UL dedicated PUCCH Config
5129  *
5130  * @params[in] : PUCCH_Config_t *pucchCfg
5131  *
5132  * @return ROK     - success
5133  *         RFAILED - failure
5134  *
5135  * ****************************************************************/
5136 uint8_t BuildBWPUlDedPucchCfg(PucchCfg *pucchCfgDb, PUCCH_Config_t *pucchCfg)
5137 {
5138    PucchResrcSetCfg *rsrcSetCfgDb = NULLP;
5139    PucchResrcCfg *rsrcCfgDb = NULLP;
5140    PucchFormatCfg *format1Db = NULLP;
5141    PucchFormatCfg *format2Db = NULLP;
5142    PucchFormatCfg *format3Db = NULLP;
5143    PucchFormatCfg *format4Db = NULLP;
5144    PucchSchedReqCfg *schReqDb = NULLP;   
5145    PucchMultiCsiCfg  *multiCsiDb = NULLP;
5146    PucchDlDataToUlAck *dlDataToUlAckDb = NULLP;
5147
5148    if(pucchCfgDb)
5149    {
5150       rsrcSetCfgDb = pucchCfgDb->resrcSet;
5151       rsrcCfgDb = pucchCfgDb->resrc;
5152       format1Db = pucchCfgDb->format1;
5153       format2Db = pucchCfgDb->format2;
5154       format3Db = pucchCfgDb->format3;
5155       format4Db = pucchCfgDb->format4;
5156       schReqDb = pucchCfgDb->schedReq;
5157       multiCsiDb = pucchCfgDb->multiCsiCfg;
5158       dlDataToUlAckDb = pucchCfgDb->dlDataToUlAck;
5159    }
5160
5161    /* RESOURCE SET */
5162    DU_ALLOC(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
5163    if(pucchCfg->resourceSetToAddModList == NULL)
5164    {
5165       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5166       return RFAILED;
5167    }
5168
5169    if(BuildPucchRsrcSetAddModList(rsrcSetCfgDb, pucchCfg->resourceSetToAddModList) != ROK)
5170    {
5171       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5172       return RFAILED;
5173    }
5174
5175    /* PUCCH RESOURCE */
5176    DU_ALLOC(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
5177    if(pucchCfg->resourceToAddModList == NULLP)
5178    {
5179       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5180       return RFAILED;
5181    }
5182
5183    if(BuildPucchRsrcAddModList(rsrcCfgDb, pucchCfg->resourceToAddModList) != ROK)
5184    {
5185       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5186       return RFAILED;
5187    }
5188
5189    /* PUCCH Format 1 */
5190    DU_ALLOC(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
5191    if(pucchCfg->format1 == NULLP)
5192    {
5193       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5194       return RFAILED;
5195    }
5196    
5197    pucchCfg->format1->present = PUCCH_Config__format1_PR_setup;
5198    DU_ALLOC(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
5199    if(pucchCfg->format1->choice.setup == NULLP)
5200    {
5201       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5202       return RFAILED;
5203    }
5204
5205    if(BuildPucchFormat(format1Db, pucchCfg->format1->choice.setup) != ROK)
5206    {
5207       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5208       return RFAILED;
5209    }
5210
5211    /* PUCCH Format 2 */
5212    if(format2Db)
5213    {
5214       DU_ALLOC(pucchCfg->format2, sizeof(struct PUCCH_Config__format2));
5215       if(pucchCfg->format2 == NULLP)
5216       {
5217          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5218          return RFAILED;
5219       }
5220
5221       pucchCfg->format2->present = PUCCH_Config__format2_PR_setup;
5222       DU_ALLOC(pucchCfg->format2->choice.setup, sizeof(PUCCH_FormatConfig_t));
5223       if(pucchCfg->format2->choice.setup == NULLP)
5224       {
5225          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5226          return RFAILED;
5227       }
5228
5229       if(BuildPucchFormat(format2Db, pucchCfg->format2->choice.setup) != ROK)
5230       {
5231          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5232          return RFAILED;
5233       }
5234    }
5235
5236    /* PUCCH Format 3 */
5237    if(format3Db)
5238    {
5239       DU_ALLOC(pucchCfg->format3, sizeof(struct PUCCH_Config__format3));
5240       if(pucchCfg->format3 == NULLP)
5241       {
5242          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5243          return RFAILED;
5244       }
5245
5246       pucchCfg->format3->present = PUCCH_Config__format3_PR_setup;
5247       DU_ALLOC(pucchCfg->format3->choice.setup, sizeof(PUCCH_FormatConfig_t));
5248       if(pucchCfg->format3->choice.setup == NULLP)
5249       {
5250          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5251          return RFAILED;
5252       }
5253
5254       if(BuildPucchFormat(format3Db, pucchCfg->format3->choice.setup) != ROK)
5255       {
5256          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5257          return RFAILED;
5258       }
5259    }
5260
5261    /* PUCCH Format 4 */
5262    if(format4Db)
5263    {
5264       DU_ALLOC(pucchCfg->format4, sizeof(struct PUCCH_Config__format4));
5265       if(pucchCfg->format4 == NULLP)
5266       {
5267          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5268          return RFAILED;
5269       }
5270
5271       pucchCfg->format4->present = PUCCH_Config__format4_PR_setup;
5272       DU_ALLOC(pucchCfg->format4->choice.setup, sizeof(PUCCH_FormatConfig_t));
5273       if(pucchCfg->format4->choice.setup == NULLP)
5274       {
5275          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5276          return RFAILED;
5277       }
5278
5279       if(BuildPucchFormat(format4Db, pucchCfg->format4->choice.setup) != ROK)
5280       {
5281          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5282          return RFAILED;
5283       }
5284    }
5285
5286    /* Scheduling Request */
5287    if(schReqDb && (schReqDb->schedAddModListCount != 0))
5288    {
5289       pucchCfg->schedulingRequestResourceToAddModList = NULLP;
5290       DU_ALLOC(pucchCfg->schedulingRequestResourceToAddModList, sizeof(struct PUCCH_Config__schedulingRequestResourceToAddModList));
5291       if(pucchCfg->schedulingRequestResourceToAddModList == NULLP)
5292       {
5293          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5294          return RFAILED;
5295       }
5296
5297       if(BuildPucchSchReqAddModList(schReqDb, pucchCfg->schedulingRequestResourceToAddModList) != ROK)
5298       {
5299          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5300          return RFAILED;
5301       }
5302    }
5303
5304    /* Multi CSI */
5305    if(multiCsiDb && (multiCsiDb->multiCsiResrcListCount != 0))
5306    {
5307       pucchCfg->multi_CSI_PUCCH_ResourceList == NULLP;
5308       DU_ALLOC(pucchCfg->multi_CSI_PUCCH_ResourceList, sizeof(struct PUCCH_Config__multi_CSI_PUCCH_ResourceList));
5309       if(pucchCfg->multi_CSI_PUCCH_ResourceList == NULLP)
5310       {
5311          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5312          return RFAILED;
5313       }
5314
5315       if(BuildPucchMultiCsiRsrcList(multiCsiDb, pucchCfg->multi_CSI_PUCCH_ResourceList) != ROK)
5316       {
5317          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5318          return RFAILED;
5319       }
5320    }
5321
5322    /* DL DATA TO UL ACK */
5323    DU_ALLOC(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
5324    if(pucchCfg->dl_DataToUL_ACK == NULLP)
5325    {
5326       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5327       return RFAILED;
5328    }
5329
5330    if(BuildDlDataToUlAckList(dlDataToUlAckDb, pucchCfg->dl_DataToUL_ACK) != ROK)
5331    {
5332       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5333       return RFAILED;
5334    }
5335    
5336    /* TODO : spatial relation info add/mod list and power control*/
5337
5338    return ROK;
5339 }
5340
5341 /*******************************************************************
5342  *
5343  * @brief Fills SRS resource to add/modify list 
5344  *
5345  * @details
5346  *
5347  *    Function : BuildSrsRsrcAddModList
5348  *
5349  *    Functionality: Fills SRS resource to add/modify list
5350  *
5351  * @params[in] 
5352  * @return ROK     - success
5353  *         RFAILED - failure
5354  *
5355  * ****************************************************************/
5356 uint8_t BuildSrsRsrcAddModList(struct SRS_Config__srs_ResourceToAddModList *resourceList)
5357 {
5358    uint8_t   elementCnt;
5359    uint8_t   rsrcIdx;
5360
5361    elementCnt = 1;
5362    resourceList->list.count = elementCnt;
5363    resourceList->list.size = elementCnt * sizeof(SRS_Resource_t *);
5364    resourceList->list.array = NULLP;
5365    DU_ALLOC(resourceList->list.array, resourceList->list.size);
5366    if(!resourceList->list.array)
5367    {
5368       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5369       return RFAILED;
5370    }
5371
5372    for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
5373    {
5374       DU_ALLOC(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
5375       if(!resourceList->list.array[rsrcIdx])
5376       {
5377          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5378          return RFAILED;
5379       }
5380    }
5381
5382    rsrcIdx = 0;
5383    resourceList->list.array[rsrcIdx]->srs_ResourceId = SRS_RSRC_ID;
5384    resourceList->list.array[rsrcIdx]->nrofSRS_Ports = SRS_Resource__nrofSRS_Ports_port1;
5385    resourceList->list.array[rsrcIdx]->transmissionComb.present = SRS_Resource__transmissionComb_PR_n2;
5386
5387    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2 = NULLP;
5388    DU_ALLOC(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2, \
5389          sizeof(struct SRS_Resource__transmissionComb__n2));
5390    if(!resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2)
5391    {
5392       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5393       return RFAILED;
5394    }
5395    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->combOffset_n2\
5396       = SRS_COMB_OFFSET_N2;
5397    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->cyclicShift_n2\
5398       = SRS_CYCLIC_SHIFT_N2;
5399
5400    resourceList->list.array[rsrcIdx]->resourceMapping.startPosition = \
5401                                                                       PUSCH_START_SYMBOL;
5402    resourceList->list.array[rsrcIdx]->resourceMapping.nrofSymbols =  \
5403                                                                      SRS_Resource__resourceMapping__nrofSymbols_n1;
5404    resourceList->list.array[rsrcIdx]->resourceMapping.repetitionFactor = \
5405                                                                          SRS_Resource__resourceMapping__repetitionFactor_n1;
5406
5407    resourceList->list.array[rsrcIdx]->freqDomainPosition = SRS_FREQ_DOM_POS;
5408    resourceList->list.array[rsrcIdx]->freqDomainShift = SRS_FREQ_DOM_SHIFT;
5409    resourceList->list.array[rsrcIdx]->freqHopping.c_SRS = C_SRS;
5410    resourceList->list.array[rsrcIdx]->freqHopping.b_SRS = B_SRS;
5411    resourceList->list.array[rsrcIdx]->freqHopping.b_hop = B_HOP;
5412    resourceList->list.array[rsrcIdx]->groupOrSequenceHopping = \
5413                                                                SRS_Resource__groupOrSequenceHopping_neither;
5414
5415    /* Setting resource type to aperiodic for intergration purposes */
5416    resourceList->list.array[rsrcIdx]->resourceType.present = \
5417                                                              SRS_Resource__resourceType_PR_aperiodic;
5418    resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic = NULLP;
5419    DU_ALLOC(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,
5420          sizeof(struct SRS_Resource__resourceType__aperiodic));
5421    if(!resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic)
5422    {
5423       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5424       return RFAILED;
5425    }
5426    resourceList->list.array[rsrcIdx]->sequenceId = SRS_SEQ_ID;
5427
5428    return ROK;
5429 }
5430
5431 /*******************************************************************
5432  *
5433  * @brief Build SRS resource set Add/mod list
5434  *
5435  * @details
5436  *
5437  *    Function : BuildSrsRsrcSetAddModList
5438  *
5439  *    Functionality: Build SRS resource set Add/mod list
5440  *
5441  * @params[in] 
5442  * @return ROK     - success
5443  *         RFAILED - failure
5444  *
5445  * ****************************************************************/
5446    uint8_t BuildSrsRsrcSetAddModList
5447 (
5448  struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList
5449  )
5450 {
5451    uint8_t  elementCnt;
5452    uint8_t  rSetIdx;
5453    uint8_t  rsrcIdx;
5454    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList;
5455
5456    elementCnt = 1;
5457    rsrcSetList->list.count = elementCnt;
5458    rsrcSetList->list.size = elementCnt * sizeof(SRS_ResourceSet_t *);
5459    rsrcSetList->list.array = NULLP;
5460    DU_ALLOC(rsrcSetList->list.array, rsrcSetList->list.size);
5461    if(!rsrcSetList->list.array)
5462    {
5463       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5464       return RFAILED;
5465    }
5466
5467    for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
5468    {
5469       DU_ALLOC(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
5470       if(!rsrcSetList->list.array[rSetIdx])
5471       {
5472          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5473          return RFAILED;
5474       }
5475    }
5476
5477    rSetIdx = 0;
5478    rsrcSetList->list.array[rSetIdx]->srs_ResourceSetId = SRS_RSET_ID;
5479
5480    /* Fill Resource Id list in resource set */
5481    rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList = NULLP;
5482    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
5483          sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
5484    if(!rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
5485    {
5486       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5487       return RFAILED;
5488    }
5489
5490    elementCnt = 1;
5491    rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
5492    rsrcIdList->list.count = elementCnt;
5493    rsrcIdList->list.size = elementCnt * sizeof(SRS_ResourceId_t *);
5494    rsrcIdList->list.array = NULLP;
5495    DU_ALLOC(rsrcIdList->list.array, rsrcIdList->list.size);
5496    if(!rsrcIdList->list.array)
5497    {
5498       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5499       return RFAILED;
5500    }
5501
5502    for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
5503    {
5504       DU_ALLOC(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
5505       if(!rsrcIdList->list.array[rsrcIdx])
5506       {
5507          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5508          return RFAILED;
5509       }
5510    }
5511
5512    rsrcIdx = 0;
5513    *rsrcIdList->list.array[rsrcIdx] = SRS_RSRC_ID;
5514
5515    /* Fill resource type */
5516    rsrcSetList->list.array[rSetIdx]->resourceType.present = \
5517                                                             SRS_ResourceSet__resourceType_PR_aperiodic;
5518
5519    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic = NULLP;
5520    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
5521          sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
5522    if(!rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic)
5523    {
5524       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5525       return RFAILED;
5526    }
5527    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->aperiodicSRS_ResourceTrigger \
5528       = APERIODIC_SRS_RESRC_TRIGGER;
5529
5530    /* TODO : Fill values for below IEs as expected by Viavi */
5531    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->csi_RS = NULLP;
5532    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->slotOffset = NULLP;
5533
5534
5535    rsrcSetList->list.array[rSetIdx]->usage = SRS_ResourceSet__usage_codebook;
5536    rsrcSetList->list.array[rSetIdx]->alpha = NULLP;
5537    rsrcSetList->list.array[rSetIdx]->p0 = NULLP;
5538    rsrcSetList->list.array[rSetIdx]->pathlossReferenceRS = NULLP;
5539    rsrcSetList->list.array[rSetIdx]->srs_PowerControlAdjustmentStates = NULLP;
5540
5541    return ROK;
5542 }
5543
5544 /*******************************************************************
5545  *
5546  * @brief Builds BWP UL dedicated SRS Config
5547  *
5548  * @details
5549  *
5550  *    Function : BuildBWPUlDedSrsCfg
5551  *
5552  *    Functionality: Builds BWP UL dedicated SRS Config
5553  *
5554  * @params[in] SRS Config 
5555  * @return ROK     - success
5556  *         RFAILED - failure
5557  *
5558  * ****************************************************************/
5559 uint8_t BuildBWPUlDedSrsCfg(SRS_Config_t *srsCfg)
5560 {
5561    srsCfg->srs_ResourceSetToReleaseList = NULLP;
5562    srsCfg->srs_ResourceSetToAddModList = NULLP;
5563    DU_ALLOC(srsCfg->srs_ResourceSetToAddModList, \
5564          sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
5565    if(!srsCfg->srs_ResourceSetToAddModList)
5566    {
5567       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5568       return RFAILED;
5569    }
5570    if(BuildSrsRsrcSetAddModList(srsCfg->srs_ResourceSetToAddModList) != ROK)
5571    {
5572       return RFAILED;
5573    }
5574
5575    srsCfg->srs_ResourceToReleaseList = NULLP;
5576
5577    /* Resource to Add/Modify list */
5578    srsCfg->srs_ResourceToAddModList = NULLP;
5579    DU_ALLOC(srsCfg->srs_ResourceToAddModList, \
5580          sizeof(struct SRS_Config__srs_ResourceToAddModList));
5581    if(!srsCfg->srs_ResourceToAddModList)
5582    {
5583       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5584       return RFAILED;
5585    }
5586
5587    if(BuildSrsRsrcAddModList(srsCfg->srs_ResourceToAddModList) != ROK)
5588    {
5589       return RFAILED;
5590    }
5591
5592    srsCfg->tpc_Accumulation = NULLP;
5593
5594    return ROK;
5595 }
5596
5597
5598
5599 /*******************************************************************
5600  *
5601  * @brief Builds Pusch Serving cell Config
5602  *
5603  * @details
5604  *
5605  *    Function : BuildPuschSrvCellCfg
5606  *
5607  *    Functionality: Builds Pusch Serving cell Config
5608  *
5609  * @params[in] struct UplinkConfig__pusch_ServingCellConfig *puschCfg
5610  *
5611  * @return ROK     - success
5612  *         RFAILED - failure
5613  *
5614  * ****************************************************************/
5615 uint8_t BuildPuschSrvCellCfg(struct UplinkConfig__pusch_ServingCellConfig *puschCfg)
5616 {
5617    puschCfg->present = UplinkConfig__pusch_ServingCellConfig_PR_setup;
5618    puschCfg->choice.setup = NULLP;
5619    DU_ALLOC(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
5620    if(!puschCfg->choice.setup)
5621    {
5622       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5623       return RFAILED;
5624    }
5625
5626    puschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5627    puschCfg->choice.setup->rateMatching = NULLP;
5628    puschCfg->choice.setup->xOverhead = NULLP;
5629    puschCfg->choice.setup->ext1 = NULLP;
5630    DU_ALLOC(puschCfg->choice.setup->ext1, sizeof(struct PUSCH_ServingCellConfig__ext1));
5631    if(!puschCfg->choice.setup->ext1)
5632    {
5633       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5634       return RFAILED;
5635    }
5636
5637    puschCfg->choice.setup->ext1->maxMIMO_Layers = NULLP;
5638    DU_ALLOC(puschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5639    if(!puschCfg->choice.setup->ext1->maxMIMO_Layers)
5640    {
5641       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5642       return RFAILED;
5643    }
5644    *(puschCfg->choice.setup->ext1->maxMIMO_Layers) = PUSCH_MAX_MIMO_LAYERS;
5645
5646    puschCfg->choice.setup->ext1->processingType2Enabled= NULLP;
5647    DU_ALLOC(puschCfg->choice.setup->ext1->processingType2Enabled,sizeof(BOOLEAN_t));
5648    if(!puschCfg->choice.setup->ext1->processingType2Enabled)
5649    {
5650       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5651       return RFAILED;
5652    }
5653    *(puschCfg->choice.setup->ext1->processingType2Enabled) = PUSCH_PROCESS_TYPE2_ENABLED;
5654    return ROK;
5655 }
5656
5657 /*******************************************************************
5658  *
5659  * @brief Builds inital UL BWP
5660  *
5661  * @details
5662  *
5663  *    Function : BuildInitialUlBWP
5664  *
5665  *    Functionality: Builds initial UL BWP
5666  *
5667  * @params[in] BWP_UplinkDedicated_t *ulBwp
5668  * @return ROK     - success
5669  *         RFAILED - failure
5670  *
5671  * ****************************************************************/
5672 uint8_t BuildInitialUlBWP(InitialUlBwp *initUlBwp, BWP_UplinkDedicated_t *ulBwp)
5673 {
5674    PucchCfg *pucchCfg = NULLP;
5675    PuschCfg *puschCfg = NULLP;
5676
5677    if(initUlBwp)
5678    {
5679       if(initUlBwp->pucchPresent)
5680          pucchCfg = &initUlBwp->pucchCfg;
5681       if(initUlBwp->puschPresent)
5682          puschCfg = &initUlBwp->puschCfg;
5683    }
5684
5685    ulBwp->pucch_Config = NULLP;
5686    DU_ALLOC(ulBwp->pucch_Config, sizeof(struct BWP_UplinkDedicated__pucch_Config));
5687    if(!ulBwp->pucch_Config)
5688    {
5689       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5690       return RFAILED;
5691    }
5692
5693    ulBwp->pucch_Config->present = BWP_UplinkDedicated__pucch_Config_PR_setup;
5694    ulBwp->pucch_Config->choice.setup = NULLP;
5695    DU_ALLOC(ulBwp->pucch_Config->choice.setup, sizeof(PUCCH_Config_t));
5696    if(!ulBwp->pucch_Config->choice.setup)
5697    {
5698       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5699       return RFAILED;
5700    }
5701
5702    if(BuildBWPUlDedPucchCfg(pucchCfg, ulBwp->pucch_Config->choice.setup) != ROK)
5703    {
5704       return RFAILED;
5705    }
5706
5707    /* Fill BWP UL dedicated PUSCH config */
5708    ulBwp->pusch_Config = NULLP;
5709    DU_ALLOC(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
5710    if(!ulBwp->pusch_Config)
5711    {
5712       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5713       return RFAILED;
5714    }
5715
5716    ulBwp->pusch_Config->present = BWP_UplinkDedicated__pusch_Config_PR_setup;
5717    ulBwp->pusch_Config->choice.setup = NULLP;
5718    DU_ALLOC(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
5719    if(!ulBwp->pusch_Config->choice.setup)
5720    {
5721       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5722       return RFAILED;
5723    }
5724
5725    if(BuildBWPUlDedPuschCfg(puschCfg, ulBwp->pusch_Config->choice.setup) != ROK)
5726    {
5727       return RFAILED;
5728    }
5729
5730    ulBwp->configuredGrantConfig = NULLP;
5731
5732    /* Fill BPW UL dedicated SRS config */
5733    ulBwp->srs_Config = NULLP;
5734    DU_ALLOC(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
5735    if(!ulBwp->srs_Config)
5736    {
5737       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5738       return RFAILED;
5739    }
5740
5741    ulBwp->srs_Config->present = BWP_UplinkDedicated__srs_Config_PR_setup;
5742    ulBwp->srs_Config->choice.setup = NULLP;
5743    DU_ALLOC(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
5744    if(!ulBwp->srs_Config->choice.setup)
5745    {
5746       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5747       return RFAILED;
5748    }
5749
5750    if(BuildBWPUlDedSrsCfg(ulBwp->srs_Config->choice.setup) != ROK)
5751    {
5752       return RFAILED;   
5753    }
5754
5755    ulBwp->beamFailureRecoveryConfig = NULLP;
5756
5757    return ROK;
5758 }
5759
5760 /*******************************************************************
5761  *
5762  * @brief Builds UL config
5763  * @details
5764  *
5765  *    Function : BuildUlCfg 
5766  *
5767  *    Functionality: Builds UL config in spCellCfgDed
5768  *
5769  * @params[in] UplinkConfig_t *ulCfg
5770  *
5771  * @return ROK     - success
5772  *         RFAILED - failure
5773  *
5774  * ****************************************************************/
5775 uint8_t BuildUlCfg(ServCellCfgInfo *servCellCfg, UplinkConfig_t *ulCfg)
5776 {
5777    InitialUlBwp *initUlBwp = NULLP;
5778
5779    if(servCellCfg)
5780    {
5781       initUlBwp = &servCellCfg->initUlBwp;
5782    }
5783
5784    ulCfg->initialUplinkBWP = NULLP;
5785    DU_ALLOC(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
5786    if(!ulCfg->initialUplinkBWP)
5787    {
5788       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5789       return RFAILED;
5790    }
5791
5792    if(BuildInitialUlBWP(initUlBwp, ulCfg->initialUplinkBWP) != ROK)
5793    {
5794       return RFAILED;
5795    }
5796
5797    ulCfg->uplinkBWP_ToReleaseList = NULLP;
5798    ulCfg->uplinkBWP_ToAddModList = NULLP;
5799    ulCfg->firstActiveUplinkBWP_Id = NULLP;
5800    DU_ALLOC(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
5801    if(!ulCfg->firstActiveUplinkBWP_Id)
5802    {
5803       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5804       return RFAILED;
5805    }
5806    if(servCellCfg == NULLP)
5807       *(ulCfg->firstActiveUplinkBWP_Id) = ACTIVE_UL_BWP_ID;
5808    else
5809       *(ulCfg->firstActiveUplinkBWP_Id) = servCellCfg->firstActvUlBwpId;
5810
5811    ulCfg->pusch_ServingCellConfig = NULLP;
5812    DU_ALLOC(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
5813    if(!ulCfg->pusch_ServingCellConfig)
5814    {
5815       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5816       return RFAILED;
5817    }
5818
5819    if(BuildPuschSrvCellCfg(ulCfg->pusch_ServingCellConfig) != ROK)
5820    {
5821       return RFAILED;
5822    }
5823
5824    ulCfg->carrierSwitching = NULLP;
5825    ulCfg->ext1 = NULLP;
5826    return ROK;
5827 }
5828
5829 /*******************************************************************
5830  *
5831  * @brief Builds PDSCH serving cell config
5832  * @details
5833  *
5834  *    Function : BuildPdschSrvCellCfg
5835  *
5836  *    Functionality: Builds PDSCH serving cell config in spCellCfgDed
5837  *
5838  * @params[in] struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg 
5839  *
5840  * @return ROK     - success
5841  *         RFAILED - failure
5842  *
5843  * ****************************************************************/
5844 uint8_t BuildPdschSrvCellCfg(PdschServCellCfg *pdschServCellDb, struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg)
5845 {
5846    pdschCfg->present =  ServingCellConfig__pdsch_ServingCellConfig_PR_setup;
5847    pdschCfg->choice.setup = NULLP;
5848    DU_ALLOC(pdschCfg->choice.setup, sizeof( struct PDSCH_ServingCellConfig));
5849    if(!pdschCfg->choice.setup)
5850    {
5851       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5852       return RFAILED;
5853    }
5854
5855    /* Code Block Group Transmission */
5856    pdschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5857    if(pdschServCellDb && (pdschServCellDb->maxCodeBlkGrpPerTb || pdschServCellDb->codeBlkGrpFlushInd))
5858    {
5859       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission, sizeof(struct PDSCH_ServingCellConfig__codeBlockGroupTransmission));
5860       if(pdschCfg->choice.setup->codeBlockGroupTransmission == NULLP)
5861       {
5862          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5863          return RFAILED;
5864       }
5865
5866       pdschCfg->choice.setup->codeBlockGroupTransmission->present = PDSCH_ServingCellConfig__codeBlockGroupTransmission_PR_setup;
5867       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup = NULLP;
5868       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup, sizeof(struct PDSCH_CodeBlockGroupTransmission ));
5869       if(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup == NULLP)
5870       {
5871          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5872          return RFAILED;
5873       }
5874
5875       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock = \
5876          *(pdschServCellDb->maxCodeBlkGrpPerTb);
5877       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator = \
5878          *(pdschServCellDb->codeBlkGrpFlushInd);
5879    }
5880
5881    /* xOverhead */
5882    pdschCfg->choice.setup->xOverhead = NULLP;
5883    if(pdschServCellDb && pdschServCellDb->xOverhead)
5884    {
5885       DU_ALLOC(pdschCfg->choice.setup->xOverhead, sizeof(long));
5886       if(pdschCfg->choice.setup->xOverhead == NULLP)
5887       {
5888          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5889          return RFAILED;
5890       }
5891       *(pdschCfg->choice.setup->xOverhead) = *(pdschServCellDb->xOverhead);
5892    }
5893
5894    /* Number of HARQ processes */
5895    pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH = NULLP;
5896    DU_ALLOC(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH, sizeof(long));
5897    if(!pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH)
5898    {
5899       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5900       return RFAILED;
5901    }
5902
5903    if(pdschServCellDb == NULLP)
5904    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = PDSCH_NUM_HARQ_PROC;
5905    else
5906    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = pdschServCellDb->numHarqProcForPdsch;
5907
5908    pdschCfg->choice.setup->pucch_Cell = NULLP;
5909
5910    /* Extension */
5911    pdschCfg->choice.setup->ext1 = NULLP;
5912    if(pdschServCellDb && pdschServCellDb->maxMimoLayers)
5913    {
5914       DU_ALLOC(pdschCfg->choice.setup->ext1, sizeof(struct PDSCH_ServingCellConfig__ext1));
5915       if(pdschCfg->choice.setup->ext1 == NULLP)
5916       {
5917          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5918          return RFAILED;
5919       }
5920
5921       DU_ALLOC(pdschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5922       if(pdschCfg->choice.setup->ext1->maxMIMO_Layers == NULLP)
5923       {
5924          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5925          return RFAILED;
5926       }
5927       *(pdschCfg->choice.setup->ext1->maxMIMO_Layers) = *(pdschServCellDb->maxMimoLayers);
5928    }
5929
5930    return ROK;
5931 }
5932
5933 /*******************************************************************
5934  *
5935  * @brief Builds CSI Meas config
5936  * @details
5937  *
5938  *    Function : BuildCsiMeasCfg 
5939  *
5940  *    Functionality: Builds CSI Meas config in spCellCfgDed
5941  *
5942  * @params[in] struct ServingCellConfig__csi_MeasConfig *csiMeasCfg
5943  *
5944  * @return ROK     - success
5945  *         RFAILED - failure
5946  *
5947  * ****************************************************************/
5948 uint8_t BuildCsiMeasCfg(struct ServingCellConfig__csi_MeasConfig *csiMeasCfg)
5949 {
5950
5951    return ROK;
5952 }
5953
5954 /*******************************************************************
5955  *
5956  * @brief Builds DL BWP to add/modify list
5957  * @details
5958  *
5959  *    Function : BuildDlBwpToAddModList
5960  *
5961  *    Functionality: Builds DL BWP to add/modify list
5962  *
5963  * @params[in] ServCellCfgInfo *servCellCfg, 
5964  *             struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList
5965  *
5966  * @return ROK     - success
5967  *         RFAILED - failure
5968  *
5969  * ****************************************************************/ 
5970 uint8_t BuildDlBwpToAddModList(ServCellCfgInfo *servCellCfg, struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList)
5971 {
5972    uint8_t elementCnt, idx;
5973
5974    elementCnt = servCellCfg->numDlBwpToAdd;
5975    dlBwpAddModList->list.count = elementCnt;
5976    dlBwpAddModList->list.size = elementCnt * sizeof(struct BWP_Downlink *);
5977    dlBwpAddModList->list.array = NULLP;
5978    DU_ALLOC(dlBwpAddModList->list.array, dlBwpAddModList->list.size);
5979    if(dlBwpAddModList->list.array == NULLP)
5980    {
5981       DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
5982       return RFAILED;
5983    }
5984
5985    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
5986    {
5987       DU_ALLOC(dlBwpAddModList->list.array[idx], sizeof(BWP_Downlink_t));
5988       if(dlBwpAddModList->list.array[idx] == NULLP)
5989       {
5990          DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
5991          return RFAILED;
5992       }
5993    }
5994
5995    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
5996    {
5997       dlBwpAddModList->list.array[idx]->bwp_Id = servCellCfg->DlBwpToAddList[idx].bwpId;
5998       dlBwpAddModList->list.array[idx]->bwp_Common = NULLP;
5999       dlBwpAddModList->list.array[idx]->bwp_Dedicated = NULLP;
6000    }
6001    return ROK;
6002 }
6003
6004 /*******************************************************************
6005  *
6006  * @brief Builds Spcell config dedicated
6007  * @details
6008  *
6009  *    Function : BuildSpCellCfgDed
6010  *
6011  *    Functionality: Builds sp cell config dedicated in spCellCfg
6012  *
6013  * @params[in] ServingCellConfig_t srvCellCfg
6014  *
6015  * @return ROK     - success
6016  *         RFAILED - failure
6017  *
6018  * ****************************************************************/
6019 uint8_t BuildSpCellCfgDed(DuUeCb *ueCb, ServingCellConfig_t *srvCellCfg)
6020 {
6021    ServCellCfgInfo *servCellCfg = NULLP;
6022    InitialDlBwp *initDlBwp = NULLP;
6023    PdschServCellCfg *pdschServCellDb = NULLP;
6024
6025    if(ueCb)
6026    {
6027       servCellCfg = &ueCb->macUeCfg.spCellCfg.servCellCfg;
6028       initDlBwp = &servCellCfg->initDlBwp;
6029       pdschServCellDb = &servCellCfg->pdschServCellCfg;
6030    }
6031
6032    srvCellCfg->tdd_UL_DL_ConfigurationDedicated = NULLP;
6033    DU_ALLOC(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
6034    if(!srvCellCfg->tdd_UL_DL_ConfigurationDedicated)
6035    {
6036       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6037       return RFAILED;
6038    }
6039
6040    srvCellCfg->initialDownlinkBWP = NULLP;
6041    DU_ALLOC(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
6042    if(!srvCellCfg->initialDownlinkBWP)
6043    {
6044       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6045       return RFAILED;
6046    }
6047
6048    if(BuildInitialDlBWP(initDlBwp, srvCellCfg->initialDownlinkBWP) != ROK)
6049    {
6050       DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6051       return RFAILED;
6052    }
6053
6054    srvCellCfg->downlinkBWP_ToReleaseList = NULLP;
6055
6056    srvCellCfg->downlinkBWP_ToAddModList = NULLP;
6057    if(ueCb && ueCb->macUeCfg.spCellCfg.servCellCfg.numDlBwpToAdd)
6058    {
6059       DU_ALLOC(srvCellCfg->downlinkBWP_ToAddModList, sizeof(struct ServingCellConfig__downlinkBWP_ToAddModList));
6060       if(srvCellCfg->downlinkBWP_ToAddModList == NULLP)
6061       {
6062          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6063          return RFAILED;
6064       }
6065
6066       if(BuildDlBwpToAddModList(&ueCb->macUeCfg.spCellCfg.servCellCfg, srvCellCfg->downlinkBWP_ToAddModList) != ROK)
6067       {
6068          DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6069          return RFAILED;
6070       }
6071    }
6072
6073    srvCellCfg->firstActiveDownlinkBWP_Id = NULLP;
6074    DU_ALLOC(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
6075    if(!srvCellCfg->firstActiveDownlinkBWP_Id)
6076    {
6077       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6078       return RFAILED;
6079    }
6080    if(ueCb == NULLP)
6081       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6082    else
6083       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ueCb->macUeCfg.spCellCfg.servCellCfg.firstActvDlBwpId;
6084
6085    srvCellCfg->bwp_InactivityTimer = NULLP;
6086
6087    srvCellCfg->defaultDownlinkBWP_Id = NULLP;
6088    DU_ALLOC(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
6089    if(!srvCellCfg->defaultDownlinkBWP_Id)
6090    {
6091       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6092       return RFAILED;
6093    }
6094    if(ueCb == NULLP)
6095       *(srvCellCfg->defaultDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6096    else
6097       *(srvCellCfg->defaultDownlinkBWP_Id) = ueCb->macUeCfg.spCellCfg.servCellCfg.defaultDlBwpId;
6098
6099    srvCellCfg->uplinkConfig = NULLP;
6100    DU_ALLOC(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));
6101    if(!srvCellCfg->uplinkConfig)
6102    {
6103       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6104       return RFAILED;
6105    }
6106
6107    if(BuildUlCfg(servCellCfg, srvCellCfg->uplinkConfig) != ROK)
6108    {
6109       DU_LOG("\nERROR  -->  F1AP : BuildUlCfg failed");
6110       return RFAILED;
6111    }
6112    srvCellCfg->supplementaryUplink = NULLP;
6113    srvCellCfg->pdcch_ServingCellConfig = NULLP;
6114
6115    srvCellCfg->pdsch_ServingCellConfig = NULLP;
6116    DU_ALLOC(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct  ServingCellConfig__pdsch_ServingCellConfig));
6117    if(!srvCellCfg->pdsch_ServingCellConfig)
6118    {
6119       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6120       return RFAILED;
6121    }
6122
6123    if(BuildPdschSrvCellCfg(pdschServCellDb, srvCellCfg->pdsch_ServingCellConfig) != ROK)
6124    {
6125       DU_LOG("\nERROR  -->  F1AP : BuildPdschSrvCellCfg failed");
6126       return RFAILED;
6127    }
6128
6129    srvCellCfg->csi_MeasConfig = NULLP;
6130 #if 0
6131    DU_ALLOC(srvCellCfg->csi_MeasConfig, sizeof(struct   ServingCellConfig__csi_MeasConfig))
6132       if(!srvCellCfg->csi_MeasConfig)
6133       {
6134          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6135          return RFAILED;
6136       }
6137
6138    if(BuildCsiMeasCfg(srvCellCfg->csi_MeasConfig) != ROK)
6139    {
6140       DU_LOG("\nF1AP : BuildCsiMeasCfg failed");
6141       return RFAILED;
6142    }
6143 #endif
6144    srvCellCfg->sCellDeactivationTimer = NULLP;
6145    srvCellCfg->crossCarrierSchedulingConfig = NULLP;
6146    srvCellCfg->tag_Id = TAG_ID;
6147    srvCellCfg->dummy = NULLP;
6148    srvCellCfg->pathlossReferenceLinking = NULLP;
6149    srvCellCfg->servingCellMO = NULLP;
6150    srvCellCfg->ext1 = NULLP;
6151
6152    return ROK;
6153 }
6154 /*******************************************************************
6155  *
6156  * @brief Builds Spcell config 
6157  *
6158  * @details
6159  *
6160  *    Function : BuildSpCellCfg 
6161  *
6162  *    Functionality: Builds sp cell config in DuToCuRrcContainer
6163  *
6164  * @params[in] SpCellConfig_t spCellCfg
6165  *
6166  * @return ROK     - success
6167  *         RFAILED - failure
6168  *
6169  * ****************************************************************/
6170 uint8_t BuildSpCellCfg(DuUeCb *ueCb, SpCellConfig_t *spCellCfg)
6171 {
6172    spCellCfg->servCellIndex = NULLP;
6173    DU_ALLOC(spCellCfg->servCellIndex, sizeof(long));
6174    if(!spCellCfg->servCellIndex)
6175    {
6176       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6177       return RFAILED;
6178    }
6179
6180    if(ueCb == NULLP)
6181       *(spCellCfg->servCellIndex) = SERV_CELL_IDX;
6182    else
6183       *(spCellCfg->servCellIndex) = ueCb->macUeCfg.spCellCfg.servCellIdx;
6184
6185    spCellCfg->reconfigurationWithSync = NULLP;
6186    spCellCfg->rlf_TimersAndConstants = NULLP;
6187    spCellCfg->rlmInSyncOutOfSyncThreshold = NULLP;
6188
6189    DU_ALLOC(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
6190    if(!spCellCfg->rlmInSyncOutOfSyncThreshold)
6191    {
6192       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6193       return RFAILED;
6194    }
6195    *(spCellCfg->rlmInSyncOutOfSyncThreshold) = RLM_SYNC_OUT_SYNC_THRESHOLD;
6196
6197    spCellCfg->spCellConfigDedicated = NULLP;
6198    DU_ALLOC(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
6199    if(!spCellCfg->spCellConfigDedicated)
6200    {
6201       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6202       return RFAILED;
6203    }
6204    if(BuildSpCellCfgDed(ueCb, spCellCfg->spCellConfigDedicated) != ROK)
6205    {
6206       DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfgDed failed");
6207       return RFAILED;
6208    }
6209
6210    return ROK;
6211 }
6212
6213 /*******************************************************************
6214  *
6215  * @brief Builds Phy cell group config 
6216  *
6217  * @details
6218  *
6219  *    Function : BuildPhyCellGrpCfg 
6220  *
6221  *    Functionality: Builds Phy cell group config in DuToCuRrcContainer
6222  *
6223  * @params[in] PhysicalCellGroupConfig_t *phyCellGrpCfg 
6224  *
6225  * @return ROK     - success
6226  *         RFAILED - failure
6227  *
6228  * ****************************************************************/
6229 uint8_t BuildPhyCellGrpCfg(DuUeCb *ueCb, PhysicalCellGroupConfig_t *phyCellGrpCfg)
6230 {
6231    phyCellGrpCfg->harq_ACK_SpatialBundlingPUCCH = NULLP;
6232    phyCellGrpCfg->harq_ACK_SpatialBundlingPUSCH = NULLP;
6233
6234    phyCellGrpCfg->p_NR_FR1 = NULLP;
6235    DU_ALLOC(phyCellGrpCfg->p_NR_FR1, sizeof(long));
6236    if(!phyCellGrpCfg->p_NR_FR1)
6237    {
6238       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhyCellGrpCfg");
6239       return RFAILED;
6240    }
6241
6242    if(ueCb == NULLP)
6243    {
6244       *(phyCellGrpCfg->p_NR_FR1)             = P_NR_FR1;
6245       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = PDSCH_HARQ_ACK_CODEBOOK;
6246    }
6247    else
6248    {
6249       *(phyCellGrpCfg->p_NR_FR1) = ueCb->macUeCfg.phyCellGrpCfg.pNrFr1;
6250       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = ueCb->macUeCfg.phyCellGrpCfg.pdschHarqAckCodebook;
6251    }
6252
6253    phyCellGrpCfg->tpc_SRS_RNTI = NULLP;
6254    phyCellGrpCfg->tpc_PUCCH_RNTI = NULLP;
6255    phyCellGrpCfg->tpc_PUSCH_RNTI = NULLP;
6256    phyCellGrpCfg->sp_CSI_RNTI = NULLP;
6257    phyCellGrpCfg->cs_RNTI = NULLP;
6258    phyCellGrpCfg->ext1 = NULLP;
6259    phyCellGrpCfg->ext2 = NULLP;
6260
6261    return ROK;
6262 }
6263
6264 /*******************************************************************
6265  *
6266  * @brief Builds Mac cell group config 
6267  *
6268  * @details
6269  *
6270  *    Function : BuildMacCellGrpCfg 
6271  *
6272  *    Functionality: Builds Mac cell group config in DuToCuRrcContainer
6273  *
6274  * @params[in] MAC_CellGroupConfig_t *macCellGrpCfg
6275  *
6276  * @return ROK     - success
6277  *         RFAILED - failure
6278  *
6279  * ****************************************************************/
6280 uint8_t BuildMacCellGrpCfg(DuUeCb *ueCb, MAC_CellGroupConfig_t *macCellGrpCfg)
6281 {
6282    macCellGrpCfg->drx_Config = NULLP;
6283    macCellGrpCfg->schedulingRequestConfig = NULLP;
6284    DU_ALLOC(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
6285    if(!macCellGrpCfg->schedulingRequestConfig)
6286    {
6287       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
6288       return RFAILED;
6289    }
6290
6291    if(BuildSchedulingReqConfig(ueCb, macCellGrpCfg->schedulingRequestConfig) != ROK)
6292    {
6293       DU_LOG("\nERROR  -->  F1AP : BuildSchedulingReqConfig failed");
6294       return RFAILED;
6295    }
6296
6297    macCellGrpCfg->bsr_Config = NULLP;
6298    DU_ALLOC(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
6299    if(!macCellGrpCfg->bsr_Config)
6300    {
6301       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
6302       return RFAILED;
6303    }
6304
6305    if(BuildBsrConfig(ueCb, macCellGrpCfg->bsr_Config) != ROK)
6306    {
6307       DU_LOG("\nERROR  -->  F1AP : BuildBsrConfig failed");
6308       return RFAILED;
6309    }
6310
6311    macCellGrpCfg->tag_Config = NULLP;
6312    DU_ALLOC(macCellGrpCfg->tag_Config, sizeof(struct TAG_Config));
6313    if(!macCellGrpCfg->tag_Config)
6314    {
6315       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
6316       return RFAILED;
6317    }
6318
6319    if(BuildTagConfig(ueCb, macCellGrpCfg->tag_Config) != ROK)
6320    {
6321       DU_LOG("\nERROR  -->  F1AP : BuildTagConfig failed");
6322       return RFAILED;
6323    }
6324
6325    macCellGrpCfg->phr_Config = NULLP;
6326    DU_ALLOC(macCellGrpCfg->phr_Config, sizeof(struct MAC_CellGroupConfig__phr_Config));
6327    if(!macCellGrpCfg->phr_Config)
6328    {
6329       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
6330       return RFAILED;
6331    }
6332
6333    if(BuildPhrConfig(ueCb, macCellGrpCfg->phr_Config) != ROK)
6334    {
6335       DU_LOG("\nERROR  -->  F1AP : BuildPhrConfig failed");
6336       return RFAILED;
6337    }
6338
6339    macCellGrpCfg->skipUplinkTxDynamic = false;
6340    macCellGrpCfg->ext1 = NULLP;
6341
6342    return ROK;
6343 }
6344 /*******************************************************************
6345  *
6346  * @brief Frees memeory allocated for SearchSpcToAddModList
6347  *
6348  * @details
6349  *
6350  *    Function : FreeSearchSpcToAddModList
6351  *
6352  *    Functionality: Deallocating memory of SearchSpcToAddModList
6353  *
6354  * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
6355  *
6356  * @return void
6357  *
6358  4221 * ****************************************************************/
6359 void FreeSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
6360 {
6361    uint8_t idx1=0;
6362    uint8_t idx2=0;
6363    struct  SearchSpace *searchSpc=NULLP;
6364
6365    if(searchSpcList->list.array)
6366    {
6367       if(searchSpcList->list.array[idx2])
6368       {
6369          searchSpc = searchSpcList->list.array[idx2];
6370          if(searchSpc->controlResourceSetId)
6371          {
6372             if(searchSpc->monitoringSlotPeriodicityAndOffset)
6373             {
6374                if(searchSpc->monitoringSymbolsWithinSlot)
6375                {
6376                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
6377                   {
6378                      if(searchSpc->nrofCandidates)
6379                      {
6380                         if(searchSpc->searchSpaceType)
6381                         {
6382                            DU_FREE(searchSpc->searchSpaceType->choice.ue_Specific,\
6383                                  sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
6384                            DU_FREE(searchSpc->searchSpaceType, sizeof(struct
6385                                     SearchSpace__searchSpaceType));
6386                         }
6387                         DU_FREE(searchSpc->nrofCandidates,
6388                               sizeof(struct SearchSpace__nrofCandidates));
6389                      }
6390                      DU_FREE(searchSpc->monitoringSymbolsWithinSlot->buf, \
6391                            searchSpc->monitoringSymbolsWithinSlot->size);
6392                   }
6393                   DU_FREE(searchSpc->monitoringSymbolsWithinSlot,
6394                         sizeof(BIT_STRING_t));
6395                }
6396                DU_FREE(searchSpc->monitoringSlotPeriodicityAndOffset, \
6397                      sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
6398             }
6399             DU_FREE(searchSpc->controlResourceSetId,
6400                   sizeof(ControlResourceSetId_t));
6401          }
6402       }
6403       for(idx1 = 0; idx1 < searchSpcList->list.count; idx1++)
6404       {
6405          DU_FREE(searchSpcList->list.array[idx1],
6406                sizeof(struct SearchSpace));
6407       }
6408       DU_FREE(searchSpcList->list.array,searchSpcList->list.size);
6409    }
6410 }
6411 /*******************************************************************
6412  *
6413  * @brief Frees memory allocated for PdschTimeDomAllocList
6414  *
6415  * @details
6416  *
6417  *    Function : FreePdschTimeDomAllocList
6418  *
6419  *    Functionality: Deallocating memory of PdschTimeDomAllocList
6420  *
6421  * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
6422  *
6423  * @return void
6424  *
6425  * ****************************************************************/
6426 void FreePdschTimeDomAllocList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
6427 {
6428    uint8_t idx1=0;
6429
6430    if(timeDomAllocList->choice.setup)
6431    {
6432       if(timeDomAllocList->choice.setup->list.array)
6433       {
6434          for(idx1 = 0; idx1 <timeDomAllocList->choice.setup->list.count ; idx1++)
6435          {
6436             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1]->k0, sizeof(long));
6437             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1],
6438                   sizeof(struct PDSCH_TimeDomainResourceAllocation));
6439          }
6440          DU_FREE(timeDomAllocList->choice.setup->list.array, \
6441                timeDomAllocList->choice.setup->list.size);
6442       }
6443       DU_FREE(timeDomAllocList->choice.setup,\
6444             sizeof(struct PDSCH_TimeDomainResourceAllocationList));
6445    }
6446 }
6447 /*******************************************************************
6448  *
6449  * @brief Frees memory allocated for PuschTimeDomAllocList
6450  *
6451  *@details
6452  *
6453  *    Function : FreePuschTimeDomAllocList
6454  *
6455  *    Functionality: Deallocating memory of PuschTimeDomAllocList
6456  *
6457  * @params[in] PUSCH_Config_t *puschCfg
6458  *
6459  * @return void
6460  *
6461  * ****************************************************************/
6462 void FreePuschTimeDomAllocList(PUSCH_Config_t *puschCfg)
6463 {
6464    uint8_t rsrcListIdx=0;
6465    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
6466
6467    if(puschCfg->pusch_TimeDomainAllocationList)
6468    {
6469       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
6470       if(timeDomAllocList_t->choice.setup)
6471       {
6472          if(timeDomAllocList_t->choice.setup->list.array)
6473          {
6474             for(rsrcListIdx = 0; rsrcListIdx<timeDomAllocList_t->choice.setup->list.count; rsrcListIdx++)
6475             {
6476                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx]->k2, sizeof(long));
6477                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx],\
6478                      sizeof(PUSCH_TimeDomainResourceAllocation_t));
6479             }
6480             DU_FREE(timeDomAllocList_t->choice.setup->list.array, \
6481                   timeDomAllocList_t->choice.setup->list.size);
6482          }
6483          DU_FREE(timeDomAllocList_t->choice.setup, \
6484                sizeof(struct PUSCH_TimeDomainResourceAllocationList));
6485       }
6486       DU_FREE(puschCfg->transformPrecoder, sizeof(long));
6487       DU_FREE(puschCfg->pusch_TimeDomainAllocationList, \
6488             sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
6489    }
6490
6491 }
6492
6493 /*******************************************************************
6494  *
6495  * @brief Frees memory allocated for Dedicated PUCCH config
6496  *
6497  * @details
6498  *
6499  *    Function : FreeBWPUlDedPucchCfg
6500  *
6501  *    Functionality: Deallocating memory of Dedicated PUCCH cfg
6502  *
6503  * @params[in] BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg
6504  *
6505  * @return void
6506  *
6507  * ****************************************************************/
6508 void FreeBWPUlDedPucchCfg(struct BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg)
6509 {
6510    uint8_t k1Idx, rsrcIdx, rsrcSetIdx;
6511    PUCCH_Config_t *pucchCfg = NULLP;
6512    PUCCH_ResourceSet_t *rsrcSet = NULLP;
6513    PUCCH_Resource_t *rsrc = NULLP;
6514
6515    if(ulBwpPucchCfg)
6516    {
6517       if(ulBwpPucchCfg->choice.setup)
6518       {
6519          pucchCfg = ulBwpPucchCfg->choice.setup;
6520
6521          //Free resource set list
6522          if(pucchCfg->resourceSetToAddModList)
6523          {
6524             if(pucchCfg->resourceSetToAddModList->list.array)
6525             {
6526                for(rsrcSetIdx=0; rsrcSetIdx < pucchCfg->resourceSetToAddModList->list.count; rsrcSetIdx++)
6527                {
6528                   rsrcSet = pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx];
6529                   if(rsrcSet->resourceList.list.array)
6530                   {
6531                      for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
6532                      {
6533                         DU_FREE(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
6534                      }
6535                      DU_FREE(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
6536                   }
6537                   DU_FREE(pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
6538                }
6539                DU_FREE(pucchCfg->resourceSetToAddModList->list.array, pucchCfg->resourceSetToAddModList->list.size);
6540             }
6541             DU_FREE(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
6542          }
6543
6544          //Free resource list
6545          if(pucchCfg->resourceToAddModList)
6546          {
6547             if(pucchCfg->resourceToAddModList->list.array)
6548             {
6549                for(rsrcIdx=0; rsrcIdx < pucchCfg->resourceToAddModList->list.count; rsrcIdx++)
6550                {
6551                   rsrc = pucchCfg->resourceToAddModList->list.array[rsrcIdx];
6552                   DU_FREE(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
6553                   DU_FREE(pucchCfg->resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
6554                }
6555                DU_FREE(pucchCfg->resourceToAddModList->list.array, pucchCfg->resourceToAddModList->list.size);
6556             }
6557             DU_FREE(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
6558          }
6559
6560          //PUCCH Format 1
6561          if(pucchCfg->format1)
6562          {
6563             if(pucchCfg->format1->choice.setup)
6564             {
6565                DU_FREE(pucchCfg->format1->choice.setup->nrofSlots, sizeof(long));
6566                DU_FREE(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
6567             }
6568             DU_FREE(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
6569          }
6570          
6571          //DL DATA TO UL ACK
6572          if(pucchCfg->dl_DataToUL_ACK)
6573          {
6574             if(pucchCfg->dl_DataToUL_ACK->list.array)
6575             {
6576                for(k1Idx = 0; k1Idx <  pucchCfg->dl_DataToUL_ACK->list.count; k1Idx++)
6577                {
6578                   DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array[k1Idx], sizeof(long));
6579                }
6580                DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array, pucchCfg->dl_DataToUL_ACK->list.size);
6581             }
6582             DU_FREE(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
6583          }
6584
6585          DU_FREE(ulBwpPucchCfg->choice.setup, sizeof(PUCCH_Config_t));
6586       }
6587       DU_FREE(ulBwpPucchCfg, sizeof(struct BWP_UplinkDedicated__pucch_Config));
6588    }
6589 }
6590
6591 /*******************************************************************
6592  *
6593  * @brief Frees memory allocated for InitialUlBWP
6594  *
6595  * @details
6596  *
6597  *    Function : FreeInitialUlBWP
6598  *
6599  *    Functionality: Deallocating memory of InitialUlBWP
6600  *
6601  * @params[in] BWP_UplinkDedicated_t *ulBwp
6602  *
6603  * @return void
6604  *
6605  * ****************************************************************/
6606 void FreeInitialUlBWP(BWP_UplinkDedicated_t *ulBwp)
6607 {
6608    uint8_t  rSetIdx, rsrcIdx;
6609    SRS_Config_t   *srsCfg = NULLP;
6610    PUSCH_Config_t *puschCfg = NULLP;
6611    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
6612    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
6613    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
6614    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
6615
6616    FreeBWPUlDedPucchCfg(ulBwp->pucch_Config);
6617
6618    if(ulBwp->pusch_Config)
6619    {
6620       if(ulBwp->pusch_Config->choice.setup)
6621       {
6622          puschCfg=ulBwp->pusch_Config->choice.setup;
6623          if(puschCfg->dataScramblingIdentityPUSCH)
6624          {
6625             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
6626             {
6627                FreePuschTimeDomAllocList(puschCfg);
6628                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
6629                if(dmrsUlCfg->choice.setup)
6630                {
6631                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
6632                   {
6633                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
6634                      {
6635                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
6636                               sizeof(long));
6637                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled,
6638                               sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
6639                      }
6640                      DU_FREE(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition,
6641                            sizeof(long));
6642                   }
6643                   DU_FREE(dmrsUlCfg->choice.setup,sizeof(DMRS_UplinkConfig_t));
6644                }
6645                DU_FREE(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, \
6646                      sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
6647             }
6648             DU_FREE(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
6649          }
6650          DU_FREE(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
6651       }
6652       DU_FREE(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
6653
6654       /* Free SRS-Config */
6655       if(ulBwp->srs_Config)
6656       {
6657          if(ulBwp->srs_Config->choice.setup)
6658          {
6659             srsCfg = ulBwp->srs_Config->choice.setup;
6660
6661             /* Free Resource Set to add/mod list */
6662             if(srsCfg->srs_ResourceSetToAddModList)
6663             {
6664                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
6665                if(rsrcSetList->list.array)
6666                {
6667                   rSetIdx = 0;
6668
6669                   /* Free SRS resource Id list in this SRS resource set */
6670                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
6671                   {
6672                      rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
6673
6674                      if(rsrcIdList->list.array)
6675                      {
6676                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
6677                         {
6678                            DU_FREE(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
6679                         }
6680                         DU_FREE(rsrcIdList->list.array, rsrcIdList->list.size);
6681                      }
6682                      DU_FREE(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
6683                            sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
6684                   }
6685
6686                   /* Free resource type info for this SRS resource set */
6687                   DU_FREE(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
6688                         sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
6689
6690                   /* Free memory for each resource set */
6691                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
6692                   {
6693                      DU_FREE(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
6694                   }
6695                   DU_FREE(rsrcSetList->list.array, rsrcSetList->list.size); 
6696                }
6697                DU_FREE(srsCfg->srs_ResourceSetToAddModList, \
6698                      sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
6699             }
6700
6701             /* Free resource to add/modd list */
6702             if(srsCfg->srs_ResourceToAddModList)
6703             {
6704                resourceList = srsCfg->srs_ResourceToAddModList;
6705                if(resourceList->list.array)
6706                {
6707                   rsrcIdx = 0;
6708                   DU_FREE(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2,\
6709                         sizeof(struct SRS_Resource__transmissionComb__n2));
6710                   DU_FREE(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,\
6711                         sizeof(struct SRS_Resource__resourceType__aperiodic));
6712
6713                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
6714                   {
6715                      DU_FREE(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
6716                   }
6717                   DU_FREE(resourceList->list.array, resourceList->list.size);
6718                }
6719                DU_FREE(srsCfg->srs_ResourceToAddModList, \
6720                      sizeof(struct SRS_Config__srs_ResourceToAddModList));
6721             }
6722
6723             DU_FREE(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
6724          }
6725          DU_FREE(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
6726       }
6727    }
6728 }       
6729 /*******************************************************************
6730  *
6731  * @brief Frees memory allocated for initialUplinkBWP
6732  *
6733  * @details
6734  *
6735  *    Function : FreeinitialUplinkBWP
6736  *
6737  *    Functionality: Deallocating memory of initialUplinkBWP
6738  *
6739  * @params[in] UplinkConfig_t *ulCfg
6740  *
6741  * @return void
6742  *         
6743  *
6744  * ****************************************************************/
6745 void FreeinitialUplinkBWP(UplinkConfig_t *ulCfg)
6746 {
6747    BWP_UplinkDedicated_t *ulBwp=NULLP; 
6748    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
6749
6750    if(ulCfg->initialUplinkBWP)
6751    {
6752       ulBwp=ulCfg->initialUplinkBWP;
6753       if(ulCfg->firstActiveUplinkBWP_Id)
6754       {
6755          if(ulCfg->pusch_ServingCellConfig)
6756          {
6757             puschCfg=ulCfg->pusch_ServingCellConfig;
6758             if(puschCfg->choice.setup)
6759             {
6760                if(puschCfg->choice.setup->ext1)
6761                {
6762                   DU_FREE(puschCfg->choice.setup->ext1->\
6763                         processingType2Enabled,sizeof(BOOLEAN_t));
6764                   DU_FREE(puschCfg->choice.setup->ext1->\
6765                         maxMIMO_Layers,sizeof(long));
6766                   DU_FREE(puschCfg->choice.setup->ext1, \
6767                         sizeof(struct PUSCH_ServingCellConfig__ext1));
6768                }
6769                DU_FREE(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
6770             }
6771             DU_FREE(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
6772          }
6773          DU_FREE(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
6774       }
6775       FreeInitialUlBWP(ulBwp);
6776       DU_FREE(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
6777    }
6778 }
6779 /*******************************************************************
6780  *
6781  * @brief Frees emmory allocated for BWPDlDedPdschCfg
6782  *
6783  * @details
6784  *
6785  *    Function : FreeBWPDlDedPdschCfg
6786  *
6787  *    Functionality: Deallocating memory of BWPDlDedPdschCfg
6788  *
6789  * @params[in] BWP_DownlinkDedicated_t *dlBwp
6790  *
6791  * @return void
6792  *
6793  *
6794  * ****************************************************************/
6795 void FreeBWPDlDedPdschCfg(BWP_DownlinkDedicated_t *dlBwp)
6796 {
6797    struct PDSCH_Config *pdschCfg=NULLP;
6798    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
6799    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
6800    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
6801
6802    if(dlBwp->pdsch_Config->choice.setup)
6803    {
6804       pdschCfg=dlBwp->pdsch_Config->choice.setup;
6805       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
6806       {
6807          if(pdschCfg->pdsch_TimeDomainAllocationList)
6808          {
6809             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
6810             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
6811             {
6812                prbBndlType=&pdschCfg->prb_BundlingType;
6813                DU_FREE(prbBndlType->choice.staticBundling,\
6814                      sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
6815                DU_FREE(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
6816             }
6817             FreePdschTimeDomAllocList(timeDomAllocList);
6818             DU_FREE(pdschCfg->pdsch_TimeDomainAllocationList, \
6819                   sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
6820          }
6821          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
6822          if(dmrsDlCfg->choice.setup)
6823          {
6824             DU_FREE(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition,
6825                   sizeof(long));
6826             DU_FREE(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
6827          }
6828          DU_FREE(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, \
6829                sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
6830       }
6831       DU_FREE(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
6832    }
6833 }
6834 /*******************************************************************
6835  *
6836  * @brief Frees emmory allocated for BWPDlDedPdcchCfg
6837  *
6838  * @details
6839  *
6840  *    Function : FreeBWPDlDedPdcchCfg
6841  *
6842  *    Functionality: Deallocating memory of BWPDlDedPdcchCfg
6843  *
6844  * @params[in] BWP_DownlinkDedicated_t *dlBwp
6845  *
6846  * @return void
6847  *         
6848  *
6849  * ****************************************************************/
6850 void FreeBWPDlDedPdcchCfg(BWP_DownlinkDedicated_t *dlBwp)
6851 {
6852    uint8_t idx1=0;
6853    uint8_t idx2=0;
6854    struct PDCCH_Config *pdcchCfg=NULLP;
6855    struct ControlResourceSet *controlRSet=NULLP;
6856    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
6857
6858    if(dlBwp->pdcch_Config->choice.setup)
6859    {
6860       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
6861       if(pdcchCfg->controlResourceSetToAddModList)
6862       {
6863          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
6864          if(controlRSetList->list.array)
6865          {
6866             controlRSet = controlRSetList->list.array[idx2];
6867             if(controlRSet)
6868             {
6869                if(controlRSet->frequencyDomainResources.buf)
6870                {
6871                   if(controlRSet->pdcch_DMRS_ScramblingID)
6872                   {
6873                      if(pdcchCfg->searchSpacesToAddModList)
6874                      {
6875                         FreeSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
6876                         DU_FREE(pdcchCfg->searchSpacesToAddModList, \
6877                               sizeof(struct PDCCH_Config__searchSpacesToAddModList));
6878                      }
6879                      DU_FREE(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
6880                   }
6881                   DU_FREE(controlRSet->frequencyDomainResources.buf, \
6882                         controlRSet->frequencyDomainResources.size);
6883                }
6884             }
6885             for(idx1 = 0; idx1 <controlRSetList->list.count; idx1++)
6886             {
6887                DU_FREE(controlRSetList->list.array[idx1], sizeof(struct ControlResourceSet));
6888             }
6889             DU_FREE(controlRSetList->list.array, controlRSetList->list.size);
6890          }
6891          DU_FREE(pdcchCfg->controlResourceSetToAddModList, \
6892                sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
6893       }
6894       DU_FREE(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
6895    }
6896 }       
6897
6898 /*******************************************************************
6899  *
6900  * @brief Frees emmory allocated for DUToCURRCContainer 
6901  *
6902  * @details
6903  *
6904  *    Function : FreeMemDuToCuRrcCont
6905  *
6906  *    Functionality: Deallocating memory of DuToCuRrcContainer
6907  *
6908  * @params[in] DuToCuRRCContainer, DuToCuRRCContainer
6909  *
6910  * @return ROK     - success
6911  *         RFAILED - failure
6912  *
6913  * ****************************************************************/
6914 uint8_t FreeMemDuToCuRrcCont(CellGroupConfigRrc_t *cellGrpCfg)
6915 {
6916    uint8_t idx=0;
6917    SpCellConfig_t *spCellCfg=NULLP;
6918    ServingCellConfig_t *srvCellCfg=NULLP;
6919    BWP_DownlinkDedicated_t *dlBwp=NULLP;
6920    MAC_CellGroupConfig_t *macCellGrpCfg=NULLP;
6921    PhysicalCellGroupConfig_t *phyCellGrpCfg=NULLP;
6922    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList=NULLP;
6923    struct RLC_Config *rlcConfig=NULLP;
6924    struct LogicalChannelConfig *macLcConfig=NULLP;
6925    struct SchedulingRequestConfig *schedulingRequestConfig=NULLP;
6926    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList=NULLP;
6927    struct TAG_Config *tagConfig=NULLP;
6928    struct TAG_Config__tag_ToAddModList *tagList=NULLP;
6929    struct MAC_CellGroupConfig__phr_Config *phrConfig=NULLP;
6930    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg=NULLP;
6931
6932    rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
6933    if(rlcBearerList)
6934    {
6935       if(rlcBearerList->list.array)
6936       {
6937          for(idx=0; idx<rlcBearerList->list.count; idx++)
6938          {
6939             if(rlcBearerList->list.array[idx])
6940             {  
6941                rlcConfig   = rlcBearerList->list.array[idx]->rlc_Config;
6942                macLcConfig = rlcBearerList->list.array[idx]->mac_LogicalChannelConfig;
6943                if(rlcConfig)
6944                {
6945                   if(rlcConfig->choice.am)
6946                   {
6947                      DU_FREE(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
6948                      DU_FREE(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
6949                      DU_FREE(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
6950                   }     
6951                   DU_FREE(rlcConfig, sizeof(struct RLC_Config));
6952                }
6953                DU_FREE(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
6954                if(macLcConfig)
6955                {
6956                   if(macLcConfig->ul_SpecificParameters)
6957                   {
6958                      DU_FREE(macLcConfig->ul_SpecificParameters->schedulingRequestID,   sizeof(SchedulingRequestId_t));
6959                      DU_FREE(macLcConfig->ul_SpecificParameters->logicalChannelGroup,   sizeof(long));
6960                      DU_FREE(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
6961                   }
6962                   DU_FREE(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
6963                }
6964                DU_FREE(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
6965             }   
6966          }
6967          DU_FREE(rlcBearerList->list.array, rlcBearerList->list.size);
6968       }
6969       DU_FREE(cellGrpCfg->rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
6970    }
6971
6972    macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
6973    if(macCellGrpCfg)
6974    {
6975       schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig; 
6976       if(schedulingRequestConfig)
6977       {
6978          schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
6979          if(schReqList)
6980          {
6981             if(schReqList->list.array)
6982             {
6983                for(idx=0;idx<schReqList->list.count; idx++)
6984                {
6985                   if(schReqList->list.array[idx])
6986                   {
6987                      DU_FREE(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
6988                      DU_FREE(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
6989                   }
6990                }
6991                DU_FREE(schReqList->list.array, schReqList->list.size);
6992             }
6993             DU_FREE(schedulingRequestConfig->schedulingRequestToAddModList,\
6994                   sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));    }
6995             DU_FREE(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
6996       }
6997       if(macCellGrpCfg->bsr_Config)
6998       {
6999          DU_FREE(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
7000       }
7001       tagConfig = macCellGrpCfg->tag_Config;
7002       if(tagConfig)
7003       {
7004          tagList = tagConfig->tag_ToAddModList;
7005          if(tagList)
7006          {
7007             if(tagList->list.array)
7008             {
7009                for(idx=0; idx<tagList->list.count; idx++)
7010                {
7011                   DU_FREE(tagList->list.array[idx], sizeof(struct TAG));
7012                }
7013                DU_FREE(tagList->list.array, tagList->list.size);
7014             }
7015             DU_FREE(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
7016          }
7017          DU_FREE(tagConfig, sizeof(struct TAG_Config));
7018       }
7019
7020       phrConfig = macCellGrpCfg->phr_Config;
7021       if(phrConfig)
7022       {
7023          DU_FREE(phrConfig->choice.setup, sizeof(struct PHR_Config));
7024          DU_FREE(phrConfig, sizeof(struct MAC_CellGroupConfig__phr_Config));
7025       }
7026
7027       DU_FREE(macCellGrpCfg, sizeof(MAC_CellGroupConfig_t));
7028    }
7029
7030    phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
7031    if(phyCellGrpCfg)
7032    {
7033       DU_FREE(phyCellGrpCfg->p_NR_FR1, sizeof(long));
7034       DU_FREE(phyCellGrpCfg, sizeof(PhysicalCellGroupConfig_t));
7035    }
7036
7037    spCellCfg = cellGrpCfg->spCellConfig;
7038    if(spCellCfg)
7039    {
7040       if(spCellCfg->servCellIndex)
7041       {
7042          if(spCellCfg->rlmInSyncOutOfSyncThreshold)
7043          {
7044             if(spCellCfg->spCellConfigDedicated)
7045             {
7046                srvCellCfg = spCellCfg->spCellConfigDedicated;
7047                if(srvCellCfg->tdd_UL_DL_ConfigurationDedicated)
7048                {
7049                   if(srvCellCfg->initialDownlinkBWP)
7050                   {
7051                      dlBwp = srvCellCfg->initialDownlinkBWP;
7052                      if(srvCellCfg->firstActiveDownlinkBWP_Id)
7053                      {
7054                         if(srvCellCfg->defaultDownlinkBWP_Id)
7055                         {
7056                            if(srvCellCfg->uplinkConfig)
7057                            {
7058                               if(srvCellCfg->pdsch_ServingCellConfig)
7059                               {
7060                                  pdschCfg= srvCellCfg->pdsch_ServingCellConfig;
7061                                  if(pdschCfg->choice.setup)
7062                                  {
7063                                     DU_FREE(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH,sizeof(long));
7064                                     DU_FREE(pdschCfg->choice.setup, sizeof( struct PDSCH_ServingCellConfig));
7065                                  }
7066                                  DU_FREE(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct
7067                                           ServingCellConfig__pdsch_ServingCellConfig));
7068                               }  
7069                               FreeinitialUplinkBWP(srvCellCfg->uplinkConfig);
7070                               DU_FREE(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));        
7071                            }
7072                            DU_FREE(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
7073                         }
7074                         DU_FREE(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
7075                      }
7076                      if(dlBwp->pdcch_Config)
7077                      {
7078                         if(dlBwp->pdsch_Config)
7079                         {
7080                            FreeBWPDlDedPdschCfg(dlBwp);
7081                            DU_FREE(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
7082                         }
7083                         FreeBWPDlDedPdcchCfg(dlBwp);
7084                         DU_FREE(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
7085                      }
7086                      DU_FREE(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
7087                   }
7088                   DU_FREE(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
7089                }
7090                DU_FREE(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
7091             }
7092             DU_FREE(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
7093          }
7094          DU_FREE(spCellCfg->servCellIndex, sizeof(long));
7095       }
7096       DU_FREE(spCellCfg,sizeof(SpCellConfig_t));
7097    }
7098    return ROK;
7099 }
7100
7101 /*******************************************************************
7102  *
7103  * @brief Builds CellGroupConfigRrc for DU To CU RRC Container 
7104  *
7105  * @details
7106  *
7107  *    Function : BuildCellGroupConfigRrc
7108  *
7109  *    Functionality: Builds and copied Cell group config buffer into 
7110  *       DuToCuRrcContainer
7111  *
7112  * @params[in] idx, index in F1AP msg
7113  *             DuToCuRRCContainer, DuToCuRRCContainer
7114  *
7115  * @return ROK     - success
7116  *         RFAILED - failure
7117  *
7118  * ****************************************************************/
7119 uint8_t BuildCellGroupConfigRrc(DuUeCb *ueCb, OCTET_STRING_t *duToCuRrcContainer)
7120 {
7121    uint8_t  ret = ROK;
7122    CellGroupConfigRrc_t  cellGrpCfg;
7123    asn_enc_rval_t        encRetVal;
7124    memset(&cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
7125    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
7126
7127    while(true)
7128    {
7129       cellGrpCfg.cellGroupId = CELL_GRP_ID;
7130
7131       cellGrpCfg.rlc_BearerToAddModList = NULLP;
7132       DU_ALLOC(cellGrpCfg.rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
7133       if(!cellGrpCfg.rlc_BearerToAddModList)
7134       {
7135          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
7136          ret = RFAILED;
7137          break;
7138       }
7139       if(BuildRlcBearerToAddModList(ueCb, cellGrpCfg.rlc_BearerToAddModList) != ROK)
7140       {
7141          DU_LOG("\nERROR  -->  F1AP : BuildRlcBearerToAddModList failed");
7142          ret = RFAILED;
7143          break;
7144       }
7145
7146       cellGrpCfg.rlc_BearerToReleaseList = NULLP;
7147       cellGrpCfg.mac_CellGroupConfig = NULLP;
7148       DU_ALLOC(cellGrpCfg.mac_CellGroupConfig, sizeof(MAC_CellGroupConfig_t));
7149       if(!cellGrpCfg.mac_CellGroupConfig)
7150       {
7151          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
7152          ret = RFAILED;
7153          break;
7154       }
7155       if(BuildMacCellGrpCfg(ueCb, cellGrpCfg.mac_CellGroupConfig) != ROK)
7156       {
7157          DU_LOG("\nERROR  -->  F1AP : BuildMacCellGrpCfg failed");
7158          ret = RFAILED;
7159          break;
7160       }
7161
7162       cellGrpCfg.physicalCellGroupConfig = NULLP;
7163       DU_ALLOC(cellGrpCfg.physicalCellGroupConfig, sizeof(PhysicalCellGroupConfig_t));
7164       if(!cellGrpCfg.physicalCellGroupConfig)
7165       {
7166          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
7167          ret = RFAILED;
7168          break;
7169       }
7170       if(BuildPhyCellGrpCfg(ueCb, cellGrpCfg.physicalCellGroupConfig) != ROK)
7171       {
7172          DU_LOG("\nERROR  -->  F1AP : BuildPhyCellGrpCfg failed");
7173          ret = RFAILED;
7174          break;
7175       }
7176
7177       cellGrpCfg.spCellConfig = NULLP;
7178       DU_ALLOC(cellGrpCfg.spCellConfig, sizeof(SpCellConfig_t));
7179       if(!cellGrpCfg.spCellConfig)
7180       {
7181          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
7182          ret = RFAILED;
7183          break;
7184       }
7185       if(BuildSpCellCfg(ueCb, cellGrpCfg.spCellConfig) != ROK)
7186       {
7187          DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfg failed");
7188          ret = RFAILED;
7189          break;
7190       }
7191
7192       cellGrpCfg.sCellToAddModList = NULLP;
7193       cellGrpCfg.sCellToReleaseList = NULLP;
7194       cellGrpCfg.ext1 = NULLP;
7195
7196       /* encode cellGrpCfg into duToCuRrcContainer */
7197       xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, &cellGrpCfg);
7198       memset(encBuf, 0, ENC_BUF_MAX_LEN);
7199       encBufSize = 0;
7200       encRetVal = aper_encode(&asn_DEF_CellGroupConfigRrc, 0, &cellGrpCfg, PrepFinalEncBuf, encBuf);
7201       /* Encode results */
7202       if(encRetVal.encoded == ENCODE_FAIL)
7203       {
7204          DU_LOG( "\nERROR  --> F1AP : Could not encode DuToCuRrcContainer (at %s)\n",\
7205                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
7206          ret = RFAILED;
7207          break;
7208       }
7209       else
7210       {
7211          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DuToCuRrcContainer\n");
7212          for(int i=0; i< encBufSize; i++)
7213          {
7214             printf("%x",encBuf[i]);
7215          }
7216       }
7217
7218       duToCuRrcContainer->size = encBufSize;
7219       DU_ALLOC(duToCuRrcContainer->buf, duToCuRrcContainer->size);
7220       if(!duToCuRrcContainer->buf)
7221       {
7222          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDuToCuRrcContainer");
7223          ret = RFAILED;
7224          break;
7225       }
7226       if(ret == ROK)
7227       {
7228          memcpy(duToCuRrcContainer->buf, encBuf, duToCuRrcContainer->size);
7229       }
7230       break;
7231    }
7232    FreeMemDuToCuRrcCont(&cellGrpCfg);
7233    return ret;
7234 }
7235
7236 /*******************************************************************
7237  *
7238  * @brief Free memory allocated in InitialULRRCMessage
7239  *
7240  * @details
7241  *
7242  *    Function : freeInitUlRrcMsgTransfer
7243  *
7244  *    Functionality: Free memory allocated in InitialULRRCMessage
7245  *
7246  * @params[in]F1AP_PDU_t  *f1apMsg)
7247  *
7248  * @return ROK     - success
7249  *         RFAILED - failure
7250  *
7251  * ****************************************************************/
7252
7253 uint8_t freeInitUlRrcMsgTransfer(F1AP_PDU_t  *f1apMsg)
7254 {
7255    uint8_t ieIdx, arrIdx;
7256    InitialULRRCMessageTransfer_t *initULRRCMsg=NULLP;
7257
7258    if(f1apMsg)
7259    {
7260       if(f1apMsg->choice.initiatingMessage)
7261       {
7262          initULRRCMsg = &f1apMsg->choice.initiatingMessage->value.\
7263             choice.InitialULRRCMessageTransfer;
7264          if(initULRRCMsg->protocolIEs.list.array)
7265          {
7266             for(ieIdx = 0; ieIdx < initULRRCMsg->protocolIEs.list.count; ieIdx++)
7267             {
7268                switch(initULRRCMsg->protocolIEs.list.array[ieIdx]->id)
7269                {
7270                   case ProtocolIE_ID_id_NRCGI:
7271                   {
7272                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf)
7273                      {
7274                         if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf)
7275                         {
7276                            DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf,\
7277                            initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.size);
7278                         }
7279                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf,\
7280                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.size);
7281                      }
7282                      break;
7283                   }
7284                   case ProtocolIE_ID_id_RRCContainer:
7285                   {
7286                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
7287                      {
7288                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,\
7289                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
7290                      }
7291                      break;
7292                   }
7293                   case ProtocolIE_ID_id_DUtoCURRCContainer:
7294                   {
7295                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf)
7296                      {
7297                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf,
7298                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.size);
7299                      }
7300                      break;
7301                   }
7302                   default:
7303                      break;
7304                }
7305              }
7306              for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
7307              {
7308                 if(initULRRCMsg->protocolIEs.list.array[arrIdx])
7309                 {
7310                    DU_FREE(initULRRCMsg->protocolIEs.list.array[arrIdx],\
7311                       sizeof(InitialULRRCMessageTransferIEs_t));
7312                 }
7313              }
7314              DU_FREE(initULRRCMsg->protocolIEs.list.array, initULRRCMsg->protocolIEs.list.size);
7315           }
7316          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
7317       }
7318       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
7319    }
7320    else
7321    {
7322       DU_LOG("\nERROR  -->  DU_APP : Recevied F1ap Pdu is null at freeInitUlRrcMsgTransfer()");
7323       return RFAILED;
7324    }
7325    return ROK;
7326 }
7327
7328 /*******************************************************************
7329  *
7330  * @brief Builds and sends the InitialULRRCMessage 
7331  *
7332  * @details
7333  *
7334  *    Function : BuildAndSendInitialRrcMsgTransfer 
7335  *
7336  *    Functionality: Constructs the Initial UL RRC Message Transfer and sends
7337  *                   it to the CU through SCTP.
7338  *
7339  * @params[in] 
7340  *
7341  * @return ROK     - success
7342  *         RFAILED - failure
7343  *
7344  * ****************************************************************/
7345 uint8_t BuildAndSendInitialRrcMsgTransfer(uint32_t gnbDuUeF1apId, uint16_t crnti,
7346       uint16_t rrcContSize, uint8_t *rrcContainer)
7347 {
7348    uint8_t   ret;
7349    uint8_t   elementCnt;
7350    uint8_t   ieIdx;
7351    asn_enc_rval_t  encRetVal;
7352    F1AP_PDU_t  *f1apMsg = NULLP;
7353    InitialULRRCMessageTransfer_t *initULRRCMsg = NULLP;
7354    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
7355
7356    while(true)
7357    {
7358       DU_LOG("\n INFO   -->  F1AP : Building RRC Setup Request\n");
7359       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
7360       if(f1apMsg == NULLP)
7361       {
7362          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
7363          break;
7364       }
7365       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
7366       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
7367       if(f1apMsg->choice.initiatingMessage == NULLP)
7368       {
7369          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU failed");
7370          break;
7371       }
7372       f1apMsg->choice.initiatingMessage->procedureCode =\
7373                                                         ProcedureCode_id_InitialULRRCMessageTransfer;
7374       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
7375       f1apMsg->choice.initiatingMessage->value.present = \
7376                                                          InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
7377       initULRRCMsg =\
7378                     &f1apMsg->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
7379       elementCnt = 5;
7380       initULRRCMsg->protocolIEs.list.count = elementCnt;
7381       initULRRCMsg->protocolIEs.list.size = \
7382                                             elementCnt * sizeof(InitialULRRCMessageTransferIEs_t *);
7383       /* Initialize the F1Setup members */
7384       DU_ALLOC(initULRRCMsg->protocolIEs.list.array,initULRRCMsg->protocolIEs.list.size);
7385       if(initULRRCMsg->protocolIEs.list.array == NULLP)
7386       {
7387          DU_LOG(" ERROR  -->  F1AP : Memory allocation for\
7388                RRCSetupRequestMessageTransferIEs failed");
7389          break;
7390       }
7391       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
7392       {
7393          DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx],\
7394                sizeof(InitialULRRCMessageTransferIEs_t));
7395          if(initULRRCMsg->protocolIEs.list.array[ieIdx] == NULLP)
7396          {
7397             break;
7398          }
7399       }
7400       ieIdx = 0;
7401       /*GNB DU UE F1AP ID*/
7402       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
7403                                                         ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
7404       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  = Criticality_reject;
7405       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
7406                                                                   InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
7407       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
7408
7409
7410       /*NRCGI*/
7411       ieIdx++;
7412       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
7413                                                         ProtocolIE_ID_id_NRCGI;
7414       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  =Criticality_reject;
7415       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
7416                                                                   InitialULRRCMessageTransferIEs__value_PR_NRCGI;
7417
7418       ret =\
7419            BuildNrcgi(&initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
7420       if(ret!=ROK)
7421       {
7422          break;
7423       }
7424
7425       /*CRNTI*/
7426       ieIdx++;
7427       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
7428                                                         ProtocolIE_ID_id_C_RNTI;
7429       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
7430       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
7431                                                                  InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
7432       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.C_RNTI = crnti;
7433
7434       /*RRCContainer*/
7435       ieIdx++;
7436       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
7437                                                         ProtocolIE_ID_id_RRCContainer;
7438       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
7439       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
7440                                                                  InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
7441
7442       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size = rrcContSize;
7443       DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,
7444             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size)
7445       if(!initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
7446       {
7447          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRCSetupRequestMessageTransferIEs failed");
7448          break;
7449       
7450       }
7451       memcpy(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, rrcContainer,
7452             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
7453
7454
7455       /*DUtoCURRCContainer*/
7456       ieIdx++;
7457       initULRRCMsg->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCContainer;
7458       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
7459       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
7460                                                                  InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
7461
7462       ret = BuildCellGroupConfigRrc(NULLP, &initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer);
7463       if(ret != ROK)
7464       {
7465          break;
7466       }
7467
7468       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
7469
7470       /* Encode the Intial UL RRC Message transfer as APER */
7471       memset(encBuf, 0, ENC_BUF_MAX_LEN);
7472       encBufSize = 0;
7473       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
7474       /* Encode results */
7475       if(encRetVal.encoded == ENCODE_FAIL)
7476       {
7477          DU_LOG( "\nERROR  --> F1AP : Could not encode Initial UL RRC Message Transfer\
7478                structure (at %s)\n",encRetVal.failed_type ? \
7479                encRetVal.failed_type->name : "unknown");
7480          ret = RFAILED;
7481          break;
7482       }
7483       else
7484       {
7485
7486          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Initial UL RRC\
7487                Message transfer\n");
7488          for(int i=0; i< encBufSize; i++)
7489          {
7490             printf("%x",encBuf[i]);
7491          }
7492       }
7493       /* Sending  msg  */
7494       if(sendF1APMsg() != ROK)
7495       {
7496          DU_LOG("\nERROR  -->  F1AP : Sending Initial UL RRC Message Transfer Failed");
7497          ret = RFAILED;
7498          break;
7499       }
7500       break;
7501    }
7502    freeInitUlRrcMsgTransfer(f1apMsg);
7503    return ret;
7504 }/* End of BuildAndSendInitialRrcMsgTransfer*/
7505
7506 /*****  UE SETUP REQUEST *****/
7507
7508 /*******************************************************************
7509  *
7510  * @brief Free Qos And Snssai Drb Info
7511  *
7512  * @details
7513  *
7514  *    Function : freeDrbQosAndSnssaiInfo
7515  *
7516  *    Functionality: Free Qos And Snssai Drb Info
7517  *
7518  * @params[in] LcCfg *lcCfg,
7519  * @return void
7520  *
7521  * ****************************************************************/
7522 void freeDrbQosAndSnssaiInfo(LcCfg *lcCfg)
7523 {
7524    if(lcCfg->snssai)
7525    {
7526       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
7527    }
7528    if(lcCfg->drbQos)
7529    {
7530       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
7531    }
7532 }
7533
7534 /******************************************************************
7535 *
7536 * @brief Function to delete the RLC Lc cfg from UE APP DB
7537 *
7538 * @details
7539 *
7540 *  Function : freeRlcLcCfg
7541 *
7542 *  Functionality: Function to delete the RLC Lc cfg from UE APP DB
7543 *
7544 *
7545  *****************************************************************/
7546
7547 void freeRlcLcCfg(RlcBearerCfg *lcCfg)
7548 {
7549    switch(lcCfg->rlcMode)
7550    {
7551       case RLC_AM :
7552          {
7553             if(lcCfg->u.amCfg)
7554             {
7555                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
7556             }
7557             break;
7558          }
7559       case RLC_UM_BI_DIRECTIONAL :
7560          {
7561             if(lcCfg->u.umBiDirCfg)
7562             {
7563                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
7564             }
7565             break;
7566          }
7567       case RLC_UM_UNI_DIRECTIONAL_UL :
7568          {
7569             if(lcCfg->u.umUniDirUlCfg)
7570             {
7571                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
7572             }
7573             break;
7574
7575          }
7576       case RLC_UM_UNI_DIRECTIONAL_DL :
7577          {
7578             if(lcCfg->u.umUniDirDlCfg)
7579             {
7580                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
7581             }
7582             break;
7583          }
7584       default:
7585          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at freeRlcLcCfg()", lcCfg->rlcMode);
7586          break;
7587    }
7588    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
7589 }
7590
7591 /*******************************************************************
7592  *
7593  * @brief Function to free MacLcCfg
7594  *
7595  * @details
7596  *
7597  *    Function : freeMacLcCfg
7598  *
7599  *    Functionality: Function to free MacLcCfg
7600  *
7601  * @params[in] LcCfg *lcCfg,
7602  * @return void
7603  *
7604  * ****************************************************************/
7605
7606 void  freeMacLcCfg(LcCfg *lcCfg)
7607 {
7608     /* Deleting DRBQOS */
7609    if(lcCfg->drbQos)
7610    {
7611       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
7612    }
7613    /* Deleting SNSSAI */
7614    if(lcCfg->snssai)
7615    {
7616       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
7617    }
7618 }
7619 /*******************************************************************
7620  *
7621  * @brief Free UE NR Capability received in UE Context setup request
7622  *
7623  * @details
7624  *
7625  *    Function : freeAperDecodeUeNrCapability
7626  *
7627  *    Functionality:  
7628  *       Free UE NR Capability received in UE Context setup request
7629  *
7630  * @params[in] 
7631  * @return ROK     - success
7632  *         RFAILED - failure
7633  *
7634  * ****************************************************************/
7635 void freeAperDecodeUeNrCapability(void *ueNrCapability)
7636 {
7637    uint8_t arrIdx =0;
7638    FeatureSets_t *featureSets =NULLP;
7639    UE_NR_Capability_t *ueNrCap = (UE_NR_Capability_t *)ueNrCapability;
7640
7641    if(ueNrCap->rf_Parameters.supportedBandListNR.list.array)
7642    {
7643       for(arrIdx = 0; arrIdx < ueNrCap->rf_Parameters.supportedBandListNR.list.count; arrIdx++)
7644       {
7645          if(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx])
7646             free(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx]);
7647       }
7648       free(ueNrCap->rf_Parameters.supportedBandListNR.list.array);
7649    }
7650
7651    if(ueNrCap->featureSets)
7652    {
7653       featureSets = ueNrCap->featureSets;
7654       if(featureSets->featureSetsDownlinkPerCC)
7655       {
7656          if(featureSets->featureSetsDownlinkPerCC->list.array)
7657          {
7658             for(arrIdx = 0; arrIdx < featureSets->featureSetsDownlinkPerCC->list.count; arrIdx++)
7659             {
7660                if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx])
7661                {
7662                   if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL)
7663                      free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL);
7664                   free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]);
7665                }
7666             }
7667             free(featureSets->featureSetsDownlinkPerCC->list.array);
7668          }
7669          free(featureSets->featureSetsDownlinkPerCC);
7670       }
7671       if(featureSets->featureSetsUplinkPerCC)
7672       {
7673          if(featureSets->featureSetsUplinkPerCC->list.array)
7674          {
7675             for(arrIdx = 0; arrIdx < featureSets->featureSetsUplinkPerCC->list.count; arrIdx++)
7676             {
7677                if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx])
7678                {
7679                   if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL)
7680                      free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL);
7681                   free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]);
7682                }
7683             }
7684             free(featureSets->featureSetsUplinkPerCC->list.array);
7685          }
7686          free(featureSets->featureSetsUplinkPerCC);
7687       }
7688       free(ueNrCap->featureSets);
7689    }   
7690 }
7691
7692 /*******************************************************************
7693 *
7694 * @brief Function to free PdcchSearchSpcToAddModList
7695          where memory allocated by aper_decoder
7696 *
7697 * @details
7698 *
7699 *    Function : freeAperDecodePdcchSearchSpcToAddModList 
7700 *
7701 *    Functionality: Function to free PdcchSearchSpcToAddModList
7702 *
7703 * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
7704 * @return void
7705 *
7706 * ****************************************************************/
7707
7708 void freeAperDecodePdcchSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
7709 {
7710    uint8_t searchSpcArrIdx=0;
7711    uint8_t searchSpcArrIdx1=0;
7712    struct  SearchSpace *searchSpc=NULLP;
7713
7714
7715    if(searchSpcList->list.array)
7716    {
7717       if(searchSpcList->list.array[searchSpcArrIdx1])
7718       {
7719          searchSpc = searchSpcList->list.array[searchSpcArrIdx1];
7720          if(searchSpc->controlResourceSetId)
7721          {
7722             if(searchSpc->monitoringSlotPeriodicityAndOffset)
7723             {
7724                if(searchSpc->monitoringSymbolsWithinSlot)
7725                {
7726                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
7727                   {
7728                      if(searchSpc->nrofCandidates)
7729                      {
7730                         if(searchSpc->searchSpaceType)
7731                         {
7732                            free(searchSpc->searchSpaceType->choice.ue_Specific);
7733                            free(searchSpc->searchSpaceType);
7734                         }
7735                         free(searchSpc->nrofCandidates);
7736                      }
7737                      free(searchSpc->monitoringSymbolsWithinSlot->buf);
7738                   }
7739                   free(searchSpc->monitoringSymbolsWithinSlot);
7740                }
7741                free(searchSpc->monitoringSlotPeriodicityAndOffset);
7742             }
7743             free(searchSpc->controlResourceSetId);
7744          }
7745       }
7746       for(searchSpcArrIdx = 0; searchSpcArrIdx < searchSpcList->list.count; searchSpcArrIdx++)
7747       {
7748          free(searchSpcList->list.array[searchSpcArrIdx]);
7749       }
7750       free(searchSpcList->list.array);
7751    }
7752 }
7753 /*******************************************************************
7754 *
7755 * @brief Function for free part for the memory allocated by aper_decoder
7756
7757 * @details
7758 *
7759 *    Function : freeAperDecodeBWPDlDedPdcchConfig
7760 *
7761 *    Functionality: Function to free BWPDlDedPdcchConfig
7762 *
7763 * @params[in] 
7764 * @return void
7765 *
7766 * ****************************************************************/
7767
7768
7769 void freeAperDecodeBWPDlDedPdcchConfig(BWP_DownlinkDedicated_t *dlBwp)
7770 {
7771    uint8_t arrIdx1=0;
7772    uint8_t arrIdx2=0;
7773    struct PDCCH_Config *pdcchCfg=NULLP;
7774    struct ControlResourceSet *controlRSet=NULLP;
7775    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
7776    
7777    if(dlBwp->pdcch_Config->choice.setup)
7778    {
7779       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
7780       if(pdcchCfg->controlResourceSetToAddModList)
7781       {
7782          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
7783          if(controlRSetList->list.array)
7784          {
7785             controlRSet = controlRSetList->list.array[arrIdx2];
7786             if(controlRSet)
7787             {
7788                if(controlRSet->frequencyDomainResources.buf)
7789                {
7790                   if(controlRSet->pdcch_DMRS_ScramblingID)
7791                   {
7792                      if(pdcchCfg->searchSpacesToAddModList)
7793                      {
7794                         freeAperDecodePdcchSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
7795                         free(pdcchCfg->searchSpacesToAddModList);
7796                      }
7797                      free(controlRSet->pdcch_DMRS_ScramblingID);
7798                   }
7799                   free(controlRSet->frequencyDomainResources.buf);
7800                }
7801             }
7802             for(arrIdx1 = 0; arrIdx1 <controlRSetList->list.count; arrIdx1++)
7803             {
7804                free(controlRSetList->list.array[arrIdx1]);
7805             }
7806             free(controlRSetList->list.array);
7807          }
7808          free(pdcchCfg->controlResourceSetToAddModList);
7809       }
7810       free(dlBwp->pdcch_Config->choice.setup);
7811    }
7812 }
7813 /*******************************************************************
7814 *
7815 * @brief Function to free PdschTimeDomAllocationList 
7816 *     where the memory allocated by aper_decoder
7817
7818 * @details
7819 *
7820 *    Function : freeAperDecodePdschTimeDomAllocationList
7821 *
7822 *    Functionality: Function to free PdschTimeDomAllocationList
7823 *
7824 * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList 
7825 * @return void
7826 *
7827 * ****************************************************************/
7828
7829
7830 void freeAperDecodePdschTimeDomAllocationList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
7831 {
7832    uint8_t arrIdx=0;
7833
7834    if(timeDomAllocList->choice.setup)
7835    {
7836       if(timeDomAllocList->choice.setup->list.array)
7837       {
7838          for(arrIdx = 0; arrIdx <timeDomAllocList->choice.setup->list.count ; arrIdx++)
7839          {
7840             free(timeDomAllocList->choice.setup->list.array[arrIdx]);
7841          }
7842          free(timeDomAllocList->choice.setup->list.array);
7843       }
7844       free(timeDomAllocList->choice.setup);
7845    }
7846 }
7847
7848 /*******************************************************************
7849 *
7850 * @brief Function to free BWPDlDedPdschConfig 
7851 *        where the memory allocated by aper_decoder
7852 *  
7853 * @details
7854 *
7855 *    Function : freeAperDecodeBWPDlDedPdschConfig 
7856 *
7857 *    Functionality: Function to free BWPDlDedPdschConfig 
7858 *
7859 * @params[in] BWP_DownlinkDedicated_t *dlBwp 
7860 * @return void
7861 *
7862 * ****************************************************************/
7863
7864
7865 void freeAperDecodeBWPDlDedPdschConfig(BWP_DownlinkDedicated_t *dlBwp)
7866 {
7867    struct PDSCH_Config *pdschCfg=NULLP;
7868    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
7869    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
7870    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
7871
7872    if(dlBwp->pdsch_Config->choice.setup)
7873    {
7874       pdschCfg=dlBwp->pdsch_Config->choice.setup;
7875       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
7876       {
7877          if(pdschCfg->pdsch_TimeDomainAllocationList)
7878          {
7879             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
7880             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
7881             {
7882                prbBndlType=&pdschCfg->prb_BundlingType;
7883                free(prbBndlType->choice.staticBundling);
7884                free(pdschCfg->maxNrofCodeWordsScheduledByDCI);
7885             }
7886             freeAperDecodePdschTimeDomAllocationList(timeDomAllocList);
7887             free(pdschCfg->pdsch_TimeDomainAllocationList);
7888          }
7889          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
7890          if(dmrsDlCfg->choice.setup)
7891          {
7892             free(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition);
7893             free(dmrsDlCfg->choice.setup);
7894          }
7895          free(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA);
7896       }
7897       free(dlBwp->pdsch_Config->choice.setup);
7898    }
7899 }
7900 /*******************************************************************
7901 *
7902 * @brief Function to free PuschTimeDomAllocListCfg
7903                  where the memory allocated by aper_decoder
7904 *
7905 * @details
7906 *
7907 *    Function : freeAperDecodePuschTimeDomAllocListCfg
7908 *
7909 *    Functionality: Function to free PuschTimeDomAllocListCfg
7910 *
7911 * @params[in] PUSCH_Config_t *puschCfg 
7912 * @return void
7913 *
7914 * ****************************************************************/
7915
7916
7917 void freeAperDecodePuschTimeDomAllocListCfg(PUSCH_Config_t *puschCfg)
7918 {
7919    uint8_t arrIdx=0;
7920    uint8_t arrIdx1=0;
7921    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
7922
7923    if(puschCfg->pusch_TimeDomainAllocationList)
7924    {
7925       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
7926       if(timeDomAllocList_t->choice.setup)
7927       {
7928          if(timeDomAllocList_t->choice.setup->list.array)
7929          {
7930             free(timeDomAllocList_t->choice.setup->list.array[arrIdx1]->k2);
7931             for(arrIdx = 0; arrIdx<timeDomAllocList_t->choice.setup->list.count; arrIdx++)
7932             {
7933                free(timeDomAllocList_t->choice.setup->list.array[arrIdx]);
7934             }
7935             free(timeDomAllocList_t->choice.setup->list.array);
7936          }
7937          free(timeDomAllocList_t->choice.setup);
7938       }
7939       free(puschCfg->transformPrecoder);
7940       free(puschCfg->pusch_TimeDomainAllocationList);
7941    }
7942 }
7943 /*******************************************************************
7944 *
7945 * @brief Function to free InitialUlBWPConfig where memory allocated by aper_decoder
7946 *
7947 * @details
7948 *
7949 *    Function : freeAperDecodeInitialUlBWPConfig 
7950 *
7951 *    Functionality: Function to free InitialUlBWPConfig
7952 *
7953 * @params[in]  BWP_UplinkDedicated_t *ulBwp
7954 * @return void
7955 *
7956 * ****************************************************************/
7957
7958
7959 void freeAperDecodeInitialUlBWPConfig(BWP_UplinkDedicated_t *ulBwp)
7960 {
7961    uint8_t  rSetIdx =0;
7962    uint8_t  rsrcIdx =0;
7963    SRS_Config_t   *srsCfg = NULLP;
7964    PUSCH_Config_t *puschCfg = NULLP;
7965    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
7966    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
7967    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
7968    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
7969
7970    if(ulBwp->pusch_Config)
7971    {
7972       if(ulBwp->pusch_Config->choice.setup)
7973       {
7974          puschCfg=ulBwp->pusch_Config->choice.setup;
7975          if(puschCfg->dataScramblingIdentityPUSCH)
7976          {
7977             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
7978             {
7979                freeAperDecodePuschTimeDomAllocListCfg(puschCfg);
7980                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
7981                if(dmrsUlCfg->choice.setup)
7982                {
7983                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
7984                   {
7985                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
7986                      {
7987                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0);
7988                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled);
7989                      }
7990                      free(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition);
7991                   }
7992                   free(dmrsUlCfg->choice.setup);
7993                }
7994                free(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA);
7995             }
7996             free(puschCfg->dataScramblingIdentityPUSCH);
7997          }
7998          free(ulBwp->pusch_Config->choice.setup);
7999       }
8000       free(ulBwp->pusch_Config);
8001
8002       /* Free SRS-Config */
8003       if(ulBwp->srs_Config)
8004       {
8005          if(ulBwp->srs_Config->choice.setup)
8006          {
8007             srsCfg = ulBwp->srs_Config->choice.setup;
8008
8009             /* Free Resource Set to add/mod list */
8010             if(srsCfg->srs_ResourceSetToAddModList)
8011             {
8012                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
8013                if(rsrcSetList->list.array)
8014                {
8015                   rSetIdx = 0;
8016
8017                   /* Free SRS resource Id list in this SRS resource set */
8018                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
8019                   {
8020                      rsrcIdList =
8021                         rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
8022
8023                      if(rsrcIdList->list.array)
8024                      {
8025                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count;
8026                               rsrcIdx++)
8027                         {
8028                            free(rsrcIdList->list.array[rsrcIdx]);
8029                         }
8030                         free(rsrcIdList->list.array);
8031                      }
8032                      free(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList);
8033                   }
8034
8035                   /* Free resource type info for this SRS resource set */
8036
8037                   free(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic);
8038
8039                   /* Free memory for each resource set */
8040                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
8041                   {
8042                      free(rsrcSetList->list.array[rSetIdx]);
8043                   }
8044                   free(rsrcSetList->list.array);
8045                }
8046                free(srsCfg->srs_ResourceSetToAddModList);
8047             }
8048
8049             /* Free resource to add/modd list */
8050             if(srsCfg->srs_ResourceToAddModList)
8051             {
8052                resourceList = srsCfg->srs_ResourceToAddModList;
8053                if(resourceList->list.array)
8054                {
8055                   rsrcIdx = 0;
8056
8057                   free(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2);
8058                   free(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic);
8059
8060                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
8061                   {
8062                      free(resourceList->list.array[rsrcIdx]);
8063                   }
8064                   free(resourceList->list.array);
8065                }
8066                free(srsCfg->srs_ResourceToAddModList);
8067             }
8068
8069             free(ulBwp->srs_Config->choice.setup);
8070          }
8071          free(ulBwp->srs_Config);
8072       }
8073    }
8074 }
8075 /*******************************************************************
8076 *
8077 * @brief Function to free initialUplinkBWPConfig where memory allocated by aper_decoder
8078 *
8079 * @details
8080 *
8081 *    Function : freeAperDecodeinitialUplinkBWPConfig
8082 *
8083 *    Functionality: Function to free initialUplinkBWPConfig
8084 *
8085 * @params[in] UplinkConfig_t *ulCfg 
8086 * @return void
8087 *
8088 * ****************************************************************/
8089
8090
8091 void freeAperDecodeinitialUplinkBWPConfig(UplinkConfig_t *ulCfg)
8092 {
8093    BWP_UplinkDedicated_t *ulBwp=NULLP;
8094    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
8095    
8096    if(ulCfg->initialUplinkBWP)
8097    {
8098       ulBwp=ulCfg->initialUplinkBWP;
8099       if(ulCfg->firstActiveUplinkBWP_Id)
8100       {
8101          if(ulCfg->pusch_ServingCellConfig)
8102          {
8103             puschCfg=ulCfg->pusch_ServingCellConfig;
8104             if(puschCfg->choice.setup)
8105             {
8106                if(puschCfg->choice.setup->ext1)
8107                {
8108                   free(puschCfg->choice.setup->ext1->processingType2Enabled);
8109                   free(puschCfg->choice.setup->ext1->maxMIMO_Layers);
8110                   free(puschCfg->choice.setup->ext1);
8111                }
8112                free(puschCfg->choice.setup);
8113             }
8114             free(ulCfg->pusch_ServingCellConfig);
8115          }
8116          free(ulCfg->firstActiveUplinkBWP_Id);
8117       }
8118       freeAperDecodeInitialUlBWPConfig(ulBwp);
8119       free(ulCfg->initialUplinkBWP);
8120    }
8121 }
8122
8123 /*******************************************************************
8124  *
8125  * @brief Function to free DuUeCfg
8126  *
8127  * @details
8128  *
8129  *    Function : freeDuUeCfg
8130  *
8131  *    Functionality: Function to free DuUeCfg
8132  *
8133  * @params[in] DuUeCfg *ueCfg
8134  * @return void
8135  *
8136  * ****************************************************************/
8137 void freeDuUeCfg(DuUeCfg *ueCfg)
8138 {
8139    uint8_t lcIdx = 0;
8140    uint8_t arrIdx = 0;
8141    SpCellConfig_t *spCellCfg = NULLP;
8142    ServingCellConfig_t *srvCellCfg = NULLP;
8143    BWP_DownlinkDedicated_t *dlBwp = NULLP;
8144    MAC_CellGroupConfig_t *macCellGrpCfg = NULLP;
8145    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
8146    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList = NULLP;
8147    struct RLC_Config *rlcConfig = NULLP;
8148    struct LogicalChannelConfig *macLcConfig = NULLP;
8149    struct SchedulingRequestConfig *schedulingRequestConfig = NULLP;
8150    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList = NULLP;
8151    struct TAG_Config *tagConfig = NULLP;
8152    struct TAG_Config__tag_ToAddModList *tagList = NULLP;
8153    struct MAC_CellGroupConfig__phr_Config *phrConfig = NULLP;
8154    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg = NULLP;
8155    CellGroupConfigRrc_t *cellGrpCfg = ueCfg->cellGrpCfg;
8156   
8157    if(ueCfg->ueNrCapability)
8158    {
8159       freeAperDecodeUeNrCapability(ueCfg->ueNrCapability);
8160       DU_FREE(ueCfg->ueNrCapability, sizeof(UE_NR_Capability_t));
8161       ueCfg->ueNrCapability = NULLP;
8162    }
8163
8164    if(ueCfg->cellGrpCfg)
8165    {
8166       
8167       rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
8168       if(rlcBearerList)
8169       {
8170          if(rlcBearerList->list.array)
8171          {
8172             for(arrIdx=0; arrIdx<rlcBearerList->list.count; arrIdx++)
8173             {
8174                if(rlcBearerList->list.array[arrIdx])
8175                {
8176                   rlcConfig   = rlcBearerList->list.array[arrIdx]->rlc_Config;
8177                   macLcConfig = rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig;
8178                   
8179                   if(rlcBearerList->list.array[arrIdx]->servedRadioBearer)
8180                   {
8181                      free(rlcBearerList->list.array[arrIdx]->servedRadioBearer);
8182                   }
8183                   if(rlcConfig)
8184                   {
8185                      if(rlcConfig->choice.am)
8186                      {
8187                         free(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength);
8188                         free(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength);
8189                         free(rlcConfig->choice.am);
8190                      }
8191                      free(rlcBearerList->list.array[arrIdx]->rlc_Config);
8192                   }
8193                   if(macLcConfig)
8194                   {
8195                      if(macLcConfig->ul_SpecificParameters)
8196                      {
8197                         free(macLcConfig->ul_SpecificParameters->schedulingRequestID);
8198                         free(macLcConfig->ul_SpecificParameters->logicalChannelGroup);
8199                         free(macLcConfig->ul_SpecificParameters);
8200                      }
8201                      free(rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig);
8202                   }
8203                   free(rlcBearerList->list.array[arrIdx]); 
8204                }
8205             }
8206             free(rlcBearerList->list.array);
8207          }
8208          free(cellGrpCfg->rlc_BearerToAddModList);
8209       }
8210
8211       macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
8212       if(macCellGrpCfg)
8213       {
8214          schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig;
8215          if(schedulingRequestConfig)
8216          {
8217             schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
8218             if(schReqList)
8219             {
8220                if(schReqList->list.array)
8221                {
8222                   for(arrIdx=0;arrIdx<schReqList->list.count; arrIdx++)
8223                   {
8224                      if(schReqList->list.array[arrIdx])
8225                      {
8226                         free(schReqList->list.array[arrIdx]->sr_ProhibitTimer); 
8227                         free(schReqList->list.array[arrIdx]);
8228                      }
8229                   }
8230                   free(schReqList->list.array);
8231                }
8232                free(schedulingRequestConfig->schedulingRequestToAddModList);
8233             }
8234             free(macCellGrpCfg->schedulingRequestConfig);
8235          }
8236          if(macCellGrpCfg->bsr_Config)
8237          {
8238             free(macCellGrpCfg->bsr_Config);
8239          }
8240          tagConfig = macCellGrpCfg->tag_Config;
8241          if(tagConfig)
8242          {
8243             tagList = tagConfig->tag_ToAddModList;
8244             if(tagList)
8245             {
8246                if(tagList->list.array)
8247                {
8248                   for(arrIdx=0; arrIdx<tagList->list.count; arrIdx++)
8249                   {
8250                      free(tagList->list.array[arrIdx]);
8251                   }
8252                   free(tagList->list.array);
8253                }
8254                free(tagConfig->tag_ToAddModList);
8255             }
8256             free(tagConfig); 
8257          }
8258
8259          phrConfig = macCellGrpCfg->phr_Config;
8260          if(phrConfig)
8261          {
8262             free(phrConfig->choice.setup); 
8263             free(phrConfig); 
8264          }
8265
8266          free(macCellGrpCfg); 
8267       }
8268
8269       phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
8270       if(phyCellGrpCfg)
8271       {
8272          free(phyCellGrpCfg->p_NR_FR1);
8273          free(phyCellGrpCfg); 
8274       }
8275
8276       spCellCfg = cellGrpCfg->spCellConfig;
8277       if(spCellCfg)
8278       {
8279          if(spCellCfg->servCellIndex)
8280          {
8281             if(spCellCfg->rlmInSyncOutOfSyncThreshold)
8282             {
8283                if(spCellCfg->spCellConfigDedicated)
8284                {
8285                   srvCellCfg = spCellCfg->spCellConfigDedicated;
8286                   if(srvCellCfg->initialDownlinkBWP)
8287                   {
8288                      dlBwp = srvCellCfg->initialDownlinkBWP;
8289                      if(srvCellCfg->firstActiveDownlinkBWP_Id)
8290                      {
8291                         if(srvCellCfg->defaultDownlinkBWP_Id)
8292                         {
8293                            if(srvCellCfg->uplinkConfig)
8294                            {
8295
8296                               if(srvCellCfg->pdsch_ServingCellConfig)
8297                               {
8298                                  pdschCfg=
8299                                     srvCellCfg->pdsch_ServingCellConfig;
8300                                  if(pdschCfg->choice.setup)
8301                                  {
8302
8303                                     free(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH);
8304                                     free(pdschCfg->choice.setup);
8305                                  }
8306
8307                                  free(srvCellCfg->pdsch_ServingCellConfig);
8308                               }
8309
8310                               freeAperDecodeinitialUplinkBWPConfig(srvCellCfg->uplinkConfig);
8311                               free(srvCellCfg->uplinkConfig);
8312                            }
8313                            free(srvCellCfg->defaultDownlinkBWP_Id);
8314                         }
8315
8316                         free(srvCellCfg->firstActiveDownlinkBWP_Id);
8317                      }
8318                      if(dlBwp->pdcch_Config)
8319                      {
8320                         if(dlBwp->pdsch_Config)
8321                         {
8322                            freeAperDecodeBWPDlDedPdschConfig(dlBwp);
8323                            free(dlBwp->pdsch_Config);
8324                         }
8325                         freeAperDecodeBWPDlDedPdcchConfig(dlBwp);
8326                         free(dlBwp->pdcch_Config);
8327                      }
8328                      free(srvCellCfg->initialDownlinkBWP);
8329                   }
8330
8331                   free(spCellCfg->spCellConfigDedicated);
8332                }
8333                free(spCellCfg->rlmInSyncOutOfSyncThreshold);
8334             }
8335             free(spCellCfg->servCellIndex); 
8336          }
8337          free(spCellCfg);
8338       }
8339       DU_FREE(ueCfg->cellGrpCfg, sizeof(CellGroupConfigRrc_t));
8340       ueCfg->cellGrpCfg = NULLP;
8341    }
8342    if(ueCfg->ambrCfg)
8343    {
8344       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCfg->ambrCfg, sizeof(AmbrCfg));
8345    }
8346    for(lcIdx = 0; lcIdx < ueCfg->numRlcLcs; lcIdx++)
8347    {
8348       freeRlcLcCfg(&ueCfg->rlcLcCfg[lcIdx]);
8349    }
8350    for(lcIdx = 0; lcIdx < ueCfg->numMacLcs; lcIdx++)
8351    {
8352       freeMacLcCfg(&ueCfg->macLcCfg[lcIdx]);
8353    }
8354    for(lcIdx = 0; lcIdx < ueCfg->numDrb; lcIdx++)
8355    {
8356       DU_FREE(ueCfg->upTnlInfo[lcIdx].tnlCfg1, sizeof(GtpTnlCfg));
8357    }
8358 }
8359
8360 /*******************************************************************
8361  *
8362  * @brief Function to free UecontextSetupDb
8363  *
8364  * @details
8365  *
8366  *    Function : freeF1UeDb
8367  *
8368  *    Functionality: Function to free UecontextSetupDb
8369  *
8370  * @params[in] UecontextSetupDb *
8371  * @return void
8372  *
8373  * ****************************************************************/
8374
8375 void freeF1UeDb(F1UeContextSetupDb *f1UeDb)
8376 {
8377    
8378    if(f1UeDb->dlRrcMsg)
8379    {
8380       if(f1UeDb->dlRrcMsg->rrcMsgPdu)
8381       {
8382         //DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,\
8383                f1UeDb->dlRrcMsg->rrcMsgPdu, f1UeDb->dlRrcMsg->rrcMsgSize);
8384       }
8385       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
8386    }
8387    freeDuUeCfg(&f1UeDb->duUeCfg);
8388    memset(f1UeDb, 0, sizeof(F1UeContextSetupDb));
8389    DU_FREE(f1UeDb, sizeof(F1UeContextSetupDb));
8390 }
8391
8392 /*******************************************************************
8393  *
8394  * @brief Function to build Am cfg Info
8395  *
8396  * @details
8397  *
8398  *    Function : extractRlcAmCfg
8399  *
8400  *    Functionality: Function to build Am cfg Info
8401  *
8402  * @params[in] AmBearerCfg *
8403  *             void *
8404  *
8405  * @return ROK/RFAILED
8406  *
8407  * ****************************************************************/
8408
8409 void extractRlcAmCfg(AmBearerCfg *amCfgToSet, struct RLC_Config__am *rlcAmCfg)
8410 {
8411    if(rlcAmCfg)
8412    {
8413       /* UL AM */
8414       if(rlcAmCfg->dl_AM_RLC.sn_FieldLength)
8415       {
8416          amCfgToSet->ulAmCfg.snLenUl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->dl_AM_RLC.sn_FieldLength));
8417          /*TODO: Check the timer value when sent by real CU */
8418          amCfgToSet->ulAmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_Reassembly); 
8419          amCfgToSet->ulAmCfg.statProhTmr = convertProhibitTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_StatusProhibit);
8420       }
8421
8422       /* DL AM */
8423       if(rlcAmCfg->ul_AM_RLC.sn_FieldLength)
8424       {
8425          amCfgToSet->dlAmCfg.snLenDl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->ul_AM_RLC.sn_FieldLength));
8426          amCfgToSet->dlAmCfg.pollRetxTmr = covertPollRetxTmrEnumToValue(rlcAmCfg->ul_AM_RLC.t_PollRetransmit);
8427          amCfgToSet->dlAmCfg.pollPdu   = covertPollPduEnumToValue(rlcAmCfg->ul_AM_RLC.pollPDU);
8428          amCfgToSet->dlAmCfg.pollByte  = covertPollByteEnumToValue(rlcAmCfg->ul_AM_RLC.pollByte);
8429          amCfgToSet->dlAmCfg.maxRetxTh = covertMaxRetxEnumToValue(rlcAmCfg->ul_AM_RLC.maxRetxThreshold);
8430       }
8431    }
8432 }
8433
8434 /*******************************************************************
8435  *
8436  * @brief Function to build Um Bi Info
8437  *
8438  * @details
8439  *
8440  *    Function : extractRlcUmBiCfg
8441  *
8442  *    Functionality: Function to build Um Bi Info
8443  *
8444  * @params[in] UmBiDirBearerCfg *
8445  *             void *
8446  *
8447  * @return ROK/RFAILED
8448  *
8449  * ****************************************************************/
8450
8451 void extractRlcUmBiCfg(UmBiDirBearerCfg *umBiCfgToSet, struct RLC_Config__um_Bi_Directional *rlcBiCfg)
8452 {
8453    if(rlcBiCfg)
8454    {
8455       /* UL UM BI DIR Cfg */
8456       if(rlcBiCfg->dl_UM_RLC.sn_FieldLength)
8457       {
8458          umBiCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->dl_UM_RLC.sn_FieldLength));
8459          umBiCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcBiCfg->dl_UM_RLC.t_Reassembly);
8460       }
8461
8462       /* DL UM BI DIR Cfg */
8463       if(rlcBiCfg->ul_UM_RLC.sn_FieldLength)
8464          umBiCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->ul_UM_RLC.sn_FieldLength));
8465    }
8466 }
8467
8468 /*******************************************************************
8469  *
8470  * @brief Function to build Um Ul Info
8471  *
8472  * @details
8473  *
8474  *    Function : extractRlcUmUlCfg
8475  *
8476  *    Functionality: Function to build Um Ul Info
8477  *
8478  * @params[in] UmUniDirUlBearerCfg *
8479  *             void *
8480  *
8481  * @return ROK/RFAILED
8482  *
8483  * ****************************************************************/
8484
8485 void extractRlcUmUlCfg(UmUniDirUlBearerCfg *umUlCfgToSet, struct RLC_Config__um_Uni_Directional_DL *umUlCfg)
8486 {
8487    if(umUlCfg)
8488    {
8489       if(umUlCfg->dl_UM_RLC.sn_FieldLength)
8490       {
8491          umUlCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umUlCfg->dl_UM_RLC.sn_FieldLength));
8492          umUlCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(umUlCfg->dl_UM_RLC.t_Reassembly);
8493       }
8494    }
8495 }
8496
8497 /*******************************************************************
8498  *
8499  * @brief Function to build Um Uni Dl Info
8500  *
8501  * @details
8502  *
8503  *    Function : extractRlcUmDlCfg
8504  *
8505  *    Functionality: Function to build Um Uni Dl Info
8506  *
8507  * @params[in] UmUniDirDlBearerCfg *
8508  *             void *
8509  *
8510  * @return ROK/RFAILED
8511  *
8512  * ****************************************************************/
8513 void extractRlcUmDlCfg(UmUniDirDlBearerCfg *umDlCfgToSet, struct RLC_Config__um_Uni_Directional_UL *umDlCfg)
8514 {
8515    if(umDlCfg)
8516    {
8517       if(umDlCfg->ul_UM_RLC.sn_FieldLength)
8518          umDlCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umDlCfg->ul_UM_RLC.sn_FieldLength));
8519    }
8520 }
8521
8522 /*******************************************************************
8523  *
8524  * @brief Function to extractRlcModeCfg
8525  *
8526  * @details
8527  *
8528  *    Function : extractRlcModeCfg
8529  *
8530  *    Functionality: Function to extractRlcModeCfg
8531  *
8532  * @params[in] RLC_Config_t *
8533  *             RlcBearerCfg *
8534  *             void  *    
8535  * @return ROK/RFAILED
8536  *
8537  * ****************************************************************/
8538 void extractRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *rlcDbCfg, RLC_Config_t *lcCfg)
8539 {
8540    if(lcCfg)
8541    {
8542       switch(rlcMode)
8543       {
8544          case RLC_AM :
8545             {
8546                if(lcCfg->choice.am)
8547                {
8548                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.amCfg, sizeof(AmBearerCfg));
8549                   if(rlcDbCfg->u.amCfg)
8550                      extractRlcAmCfg(rlcDbCfg->u.amCfg, lcCfg->choice.am);
8551                }
8552                break;
8553             }
8554          case RLC_UM_BI_DIRECTIONAL :
8555             {
8556                if(lcCfg->choice.um_Bi_Directional)
8557                {
8558                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
8559                   if(rlcDbCfg->u.umBiDirCfg)
8560                      extractRlcUmBiCfg(rlcDbCfg->u.umBiDirCfg, lcCfg->choice.um_Bi_Directional);
8561                }
8562                break;
8563             }
8564          case RLC_UM_UNI_DIRECTIONAL_UL :
8565             {
8566                if(lcCfg->choice.um_Uni_Directional_DL)
8567                {
8568                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
8569                   if(rlcDbCfg->u.umUniDirUlCfg)
8570                      extractRlcUmUlCfg(rlcDbCfg->u.umUniDirUlCfg, lcCfg->choice.um_Uni_Directional_DL);
8571                }
8572                break;
8573             }
8574          case RLC_UM_UNI_DIRECTIONAL_DL :
8575             {
8576                if(lcCfg->choice.um_Uni_Directional_UL)
8577                {
8578                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
8579                   if(rlcDbCfg->u.umUniDirDlCfg)
8580                      extractRlcUmDlCfg(rlcDbCfg->u.umUniDirDlCfg, lcCfg->choice.um_Uni_Directional_UL);
8581                }
8582                break;
8583             }
8584          default:
8585             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
8586             break;
8587       }
8588    }
8589 }
8590
8591 /*******************************************************************
8592  *
8593  * @brief Function to extract extractUlLcCfg
8594  *
8595  * @details
8596  *
8597  *    Function : extractUlLcCfg
8598  *
8599  *    Functionality: Function to extract extractUlLcCfg
8600  *
8601  * @params[in] UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg
8602  * @return void
8603  *
8604  * ****************************************************************/
8605
8606 void extractUlLcCfg(UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg)
8607 {
8608    if(ulLcCfg)
8609    {
8610       if(ulLcCfg->ul_SpecificParameters)
8611       {
8612          f1UlLcCfg->priority = \
8613             ulLcCfg->ul_SpecificParameters->priority;
8614       if(ulLcCfg->ul_SpecificParameters->logicalChannelGroup)
8615       {
8616          f1UlLcCfg->lcGroup = \
8617            *(ulLcCfg->ul_SpecificParameters->logicalChannelGroup);
8618       }
8619       if(ulLcCfg->ul_SpecificParameters->schedulingRequestID)
8620       {
8621          f1UlLcCfg->schReqId = \
8622            *(ulLcCfg->ul_SpecificParameters->schedulingRequestID);
8623       }
8624       f1UlLcCfg->pbr = \
8625          ulLcCfg->ul_SpecificParameters->prioritisedBitRate;
8626       f1UlLcCfg->bsd = \
8627          ulLcCfg->ul_SpecificParameters->bucketSizeDuration;
8628       }
8629    }
8630 }
8631
8632 /*******************************************************************
8633 *
8634 * @brief Function to extract Snssai Cfg Info from CU
8635 *
8636 * @details
8637 *
8638 *    Function : extractDrbSnssaiCfg
8639 *
8640 *    Functionality: Function to extract Drb Snssai Cfg Info from CU
8641 *
8642 * @params[in] DRB_Information_t *drbInfo, Snssai  *snssai
8643 * @return ROK/RFAILED
8644 *
8645 * ****************************************************************/
8646
8647 uint8_t extractDrbSnssaiCfg(SNSSAI_t *RecvSnssai, Snssai **snssaiToBeShared)
8648 {
8649    if(!(*snssaiToBeShared))
8650    {
8651       DU_ALLOC_SHRABL_BUF((*snssaiToBeShared), sizeof(Snssai));
8652       if(snssaiToBeShared == NULLP)
8653       {
8654          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Memory failed at allocating for SNSSAI ");
8655          return RFAILED;
8656       }
8657    }
8658    if(RecvSnssai)
8659    {
8660       memcpy(&(*snssaiToBeShared)->sst, RecvSnssai->sST.buf, RecvSnssai->sST.size);
8661       if(RecvSnssai->sD)
8662       {
8663          memcpy((*snssaiToBeShared)->sd, RecvSnssai->sD->buf,  RecvSnssai->sD->size);
8664       }
8665       else
8666       {
8667          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Received Null pointer of Snssai->SD");
8668          return RFAILED;
8669       }
8670    }
8671    return ROK;
8672 }
8673
8674 /*******************************************************************
8675  *
8676  * @brief Function to procRlcLcCfg
8677  *
8678  * @details
8679  *
8680  *    Function : procRlcLcCfg
8681  *
8682  *    Functionality: Function to procRlcLcCfg
8683  *
8684  * @params[in] rbId, lcId, rbType, rlcMod
8685  *             RLC_Config_t *, RlcBearerCfg * , 
8686  * @return void
8687  *
8688  * ****************************************************************/
8689
8690 void procRlcLcCfg(uint8_t rbId, uint8_t lcId, uint8_t rbType, uint8_t rlcMode,\
8691    uint8_t configType, RLC_Config_t *f1RlcCfg, RlcBearerCfg *lcCfg, QoSInformation_t *qoSInformation)
8692 {
8693    DRB_Information_t *drbInfo;
8694
8695    lcCfg->rbId   = rbId;
8696    lcCfg->configType = configType;
8697
8698    if(rbType == RB_TYPE_SRB)
8699    {
8700       lcCfg->rbType = RB_TYPE_SRB;
8701       lcCfg->lcId   = rbId;
8702       lcCfg->lcType = LCH_DCCH;
8703       lcCfg->rlcMode = RLC_AM;
8704    }
8705    else if(rbType == RB_TYPE_DRB)
8706    {
8707       lcCfg->rbType = RB_TYPE_DRB;
8708       lcCfg->lcId   = lcId;
8709       lcCfg->lcType = LCH_DTCH;
8710       lcCfg->rlcMode = rlcMode;
8711    }
8712    if(f1RlcCfg) /* rlc mode config recived */
8713    {
8714       extractRlcModeCfg(lcCfg->rlcMode, lcCfg, f1RlcCfg);
8715    }
8716    if(qoSInformation != NULLP)
8717    {
8718       if(qoSInformation->present == QoSInformation_PR_choice_extension)
8719       {
8720          if(qoSInformation->choice.choice_extension->value.present ==\
8721                QoSInformation_ExtIEs__value_PR_DRB_Information)
8722          {
8723             drbInfo = &qoSInformation->choice.choice_extension->value.choice.DRB_Information; 
8724             if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &lcCfg->snssai) != ROK)
8725             {
8726                DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information at procRlcLcCfg()");
8727                return;
8728             }
8729          }
8730       }
8731    }
8732 }
8733
8734 /*******************************************************************
8735  *
8736  * @brief Fills DrbQos Info received by CU
8737  *
8738  * @details
8739  *
8740  *    Function : extractQosInfo
8741  *
8742  *    Functionality: Fills DrbQos Info received  by CU
8743  *
8744  * @params[in] DrbQosInfo *qosToAdd, 
8745  *             QoSFlowLevelQoSParameters_t *qosFlowCfg
8746  * @return void
8747  *
8748  * ****************************************************************/
8749
8750 void extractQosInfo(DrbQosInfo *qosToAdd, QoSFlowLevelQoSParameters_t *qosFlowCfg)
8751 {
8752    uint8_t qosCntIdx = 0;
8753    ProtocolExtensionContainer_4624P74_t *qosIeExt = NULLP;
8754
8755    qosToAdd->fiveQiType = qosFlowCfg->qoS_Characteristics.present;
8756    qosToAdd->u.nonDyn5Qi.fiveQi     =\
8757                                      qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->fiveQI;
8758    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow)
8759    {
8760       qosToAdd->u.nonDyn5Qi.avgWindow = \
8761                                         *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
8762    }
8763    qosToAdd->u.nonDyn5Qi.maxDataBurstVol = \
8764                                            *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
8765    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel)
8766    {
8767       qosToAdd->u.nonDyn5Qi.priorLevel = \
8768                                          *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel);
8769    }
8770    qosToAdd->ngRanRetPri.priorityLevel = \
8771                                          qosFlowCfg->nGRANallocationRetentionPriority.priorityLevel; 
8772    qosToAdd->ngRanRetPri.preEmptionCap = \
8773                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionCapability;
8774    qosToAdd->ngRanRetPri.preEmptionVul = \
8775                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionVulnerability;
8776    if(qosFlowCfg->gBR_QoS_Flow_Information)
8777    {
8778       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateDl, \
8779             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.buf, \
8780             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.size);
8781       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateUl, \
8782             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.buf, \
8783             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.size);
8784       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateDl,\
8785             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.buf, \
8786             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.size);
8787       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateUl,\
8788             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.buf, \
8789             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.size);
8790    }
8791    /*Extracting PDU_SESSION_ID*/
8792    qosIeExt = (ProtocolExtensionContainer_4624P74_t *)qosFlowCfg->iE_Extensions;
8793    if(qosIeExt)
8794    {
8795       for(qosCntIdx = 0; qosCntIdx < qosIeExt->list.count; qosCntIdx++)
8796       {
8797          if(qosIeExt->list.array[qosCntIdx]->extensionValue.present == \
8798                QoSFlowLevelQoSParameters_ExtIEs__extensionValue_PR_PDUSessionID)
8799          {
8800             qosToAdd->pduSessionId = qosIeExt->list.array[qosCntIdx]->extensionValue.choice.PDUSessionID;
8801             DU_LOG("\nDEBUG -->  DU_F1AP : extractQosInfo: PDU SessionID:%d",qosToAdd->pduSessionId);
8802          }
8803       }  
8804    }
8805    qosToAdd->ulPduSessAggMaxBitRate = 0;
8806 }
8807
8808 /*******************************************************************
8809  *
8810  * @brief Function to extract GTP Tunnel Info from CU
8811  *
8812  * @details
8813  *
8814  *    Function : extractUpTnlInfo
8815  *
8816  *    Functionality: Function to extract GTP Tunnel Info from CU
8817  *
8818  * @params[in] F1AP message
8819  * @return ROK/RFAILED
8820  *
8821  * ****************************************************************/
8822
8823 uint8_t extractUpTnlInfo(uint8_t drbId, uint8_t configType,\
8824    ULUPTNLInformation_ToBeSetup_List_t *tnlInfo, UpTnlCfg *upTnlInfo)
8825 {
8826    uint8_t tnlIdx;
8827    uint32_t ipv4_du = 0;
8828    GTPTunnel_t *gtpTunnel = NULLP;
8829
8830    upTnlInfo->drbId = drbId; 
8831    upTnlInfo->configType = configType;
8832 #ifdef O1_ENABLE
8833    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
8834 #else
8835    cmInetAddr((char *)DU_IP_V4_ADDR, &ipv4_du);
8836 #endif
8837
8838    for(tnlIdx=0; tnlIdx < tnlInfo->list.count; tnlIdx++)
8839    {
8840       if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.present == UPTransportLayerInformation_PR_gTPTunnel)
8841       {
8842          if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel)
8843          {
8844             gtpTunnel = tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel;
8845             DU_ALLOC(upTnlInfo->tnlCfg1, sizeof(GtpTnlCfg));
8846             if(upTnlInfo->tnlCfg1 == NULLP)
8847             {
8848                DU_LOG("\nERROR  -->  F1AP : extractUpTnlInfo: Failed to allocate mmeory for tunnel cfg 1");
8849                return RFAILED;
8850             }
8851             bitStringToInt(&gtpTunnel->transportLayerAddress, &upTnlInfo->tnlCfg1->ulTnlAddress);
8852             upTnlInfo->tnlCfg1->dlTnlAddress = ipv4_du;
8853             if(gtpTunnel->gTP_TEID.size > 0)
8854             {
8855                teIdStringToInt(gtpTunnel->gTP_TEID.buf, &upTnlInfo->tnlCfg1->teId);
8856             }
8857          }
8858          break;
8859       }
8860    }
8861    return ROK;
8862 }
8863
8864 /*******************************************************************
8865 *
8866 * @brief Function to extract Drb Qos Cfg Info from CU
8867 *
8868 * @details
8869 *
8870 *    Function : extractDrbQosCfg 
8871 *
8872 *    Functionality: Function to extract Drb Qos Cfg Info from CU
8873 *
8874 * @params[in] DRB_Information_t *drbInfo, LcCfg *macLcToAdd
8875 * @return ROK/RFAILED
8876 *
8877 * ****************************************************************/
8878
8879 uint8_t extractDrbQosCfg(DRB_Information_t *drbInfo, LcCfg *macLcToAdd ) 
8880 {
8881    if(!macLcToAdd->drbQos)
8882    {
8883       DU_ALLOC_SHRABL_BUF(macLcToAdd->drbQos, sizeof(DrbQosInfo));
8884       if(macLcToAdd->drbQos == NULLP)
8885       {
8886          DU_LOG("\nERROR  -->  DUAPP:Memory failed at allocating DrbQos at extractDrbQosCfg()");
8887          return RFAILED;
8888       }
8889
8890    }
8891    if(drbInfo->dRB_QoS.qoS_Characteristics.present == QoS_Characteristics_PR_non_Dynamic_5QI)
8892    {
8893       extractQosInfo(macLcToAdd->drbQos, &drbInfo->dRB_QoS);
8894       macLcToAdd->dlLcCfg.lcp = macLcToAdd->drbQos->ngRanRetPri.priorityLevel;
8895    }
8896    if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &macLcToAdd->snssai) != ROK)
8897    {
8898       DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information  at extractDrbQosCfg()");
8899       return RFAILED;
8900    }
8901    return ROK;
8902 }
8903 /*******************************************************************
8904  *
8905  * @brief Function to extract DRB info received from CU
8906  *
8907  * @details
8908  *
8909  *    Function : extractDrbCfg
8910  *
8911  *    Functionality: Function to extract DRB info received from CU
8912  *
8913  * @params[in] F1AP message
8914  * @return void
8915  *
8916  * ****************************************************************/
8917 uint8_t extractDrbCfg(DRBs_ToBeSetup_Item_t *drbItem, DRBs_ToBeSetupMod_Item_t *drbSetupModItem,\
8918 DRBs_ToBeModified_Item_t *drbModItem,  LcCfg *macLcToAdd, UpTnlCfg *upTnlInfo)
8919 {
8920    DRB_Information_t *drbInfo = NULLP;
8921
8922    if(drbItem != NULLP)
8923    {
8924       if(extractUpTnlInfo(drbItem->dRBID, CONFIG_ADD, &drbItem->uLUPTNLInformation_ToBeSetup_List, upTnlInfo) != ROK)
8925       {
8926          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
8927          return RFAILED;
8928       }
8929       if(drbItem->qoSInformation.present == QoSInformation_PR_choice_extension)
8930       {
8931          if(drbItem->qoSInformation.choice.choice_extension->value.present == QoSInformation_ExtIEs__value_PR_DRB_Information)
8932          {
8933             drbInfo = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
8934             if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
8935             {
8936                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");
8937                return RFAILED;
8938             }
8939          }
8940       }
8941    }
8942    else if(drbSetupModItem != NULLP)
8943    {
8944       if(extractUpTnlInfo(drbSetupModItem->dRBID, CONFIG_ADD, &drbSetupModItem->uLUPTNLInformation_ToBeSetup_List,\
8945       upTnlInfo) != ROK)
8946       {
8947          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
8948          return RFAILED;
8949       }
8950       if(drbSetupModItem->qoSInformation.present == QoSInformation_PR_choice_extension)
8951       {
8952          if(drbSetupModItem->qoSInformation.choice.choice_extension->value.present ==\
8953          QoSInformation_ExtIEs__value_PR_DRB_Information)
8954          {
8955             drbInfo = &drbSetupModItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
8956             if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
8957             {
8958                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
8959                return RFAILED;
8960             }
8961
8962          }
8963       }
8964    }
8965    else if(drbModItem != NULLP)
8966    {
8967       if(extractUpTnlInfo(drbModItem->dRBID, CONFIG_MOD, &drbModItem->uLUPTNLInformation_ToBeSetup_List,\
8968       upTnlInfo) != ROK)
8969       {
8970          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
8971          return RFAILED;
8972       }
8973       if(drbModItem->qoSInformation != NULLP)
8974       {
8975          if(drbModItem->qoSInformation->present == QoSInformation_PR_choice_extension)
8976          {
8977             if(drbModItem->qoSInformation->choice.choice_extension->value.present ==\
8978                   QoSInformation_ExtIEs__value_PR_DRB_Information)
8979             {
8980                drbInfo = &drbModItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information;
8981                if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
8982                {
8983                   DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
8984                   return RFAILED;
8985                }
8986
8987             }
8988          }
8989       }
8990    }
8991    return ROK;
8992 }
8993
8994 /*******************************************************************
8995  *
8996  * @brief Function to extract RB info received from CU
8997  *
8998  * @details
8999  *
9000  *    Function : extractMacRbCfg
9001  *
9002  *    Functionality: Function to extract RB info received from CU
9003  *
9004  * @params[in] F1AP message
9005  * @return ROK/RFAILED
9006  *
9007  * ****************************************************************/
9008
9009 uint8_t extractMacRbCfg(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbCfg,\
9010 DRBs_ToBeSetupMod_Item_t *drbSetupModCfg,  DRBs_ToBeModified_Item_t *drbModCfg, LogicalChannelConfig_t *ulLcCfg, LcCfg *lcCfg, UpTnlCfg *upTnlInfo)
9011 {
9012    if(drbCfg != NULLP)
9013    {
9014       if(extractDrbCfg(drbCfg, NULL, NULL, lcCfg, upTnlInfo) != ROK)
9015       {
9016          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
9017          return RFAILED;
9018       }
9019    }
9020    else if(drbSetupModCfg != NULLP)
9021    { 
9022       if(extractDrbCfg(NULL, drbSetupModCfg, NULL, lcCfg, upTnlInfo) != ROK)
9023       {
9024          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
9025          return RFAILED;
9026       }
9027    }
9028    else if(drbModCfg != NULLP)
9029    { 
9030       if(extractDrbCfg(NULL, NULL, drbModCfg, lcCfg, upTnlInfo) != ROK)
9031       {
9032          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
9033          return RFAILED;
9034       }
9035    }
9036    else
9037    {
9038       lcCfg->drbQos = NULLP;
9039       lcCfg->snssai = NULLP;
9040       if(lcCfg->lcId == SRB2_LCID)
9041          lcCfg->dlLcCfg.lcp = LC_PRIORITY_3;
9042       else
9043          lcCfg->dlLcCfg.lcp = LC_PRIORITY_1;
9044    }
9045    if(ulLcCfg)
9046    {
9047       lcCfg->ulLcCfgPres = true;
9048       extractUlLcCfg(&lcCfg->ulLcCfg, ulLcCfg);
9049    }
9050    else
9051       lcCfg->ulLcCfgPres = false;
9052    return ROK;
9053 }
9054
9055 /*******************************************************************
9056  *
9057  * @brief Function processing LC config info received from CU
9058  *
9059  * @details
9060  *
9061  *    Function : procMacLcCfg
9062  *
9063  *    Functionality: Function processing LC config info received from CU
9064  *
9065  * @params[in] F1AP message
9066  * @return ROK/RFAILED
9067  *
9068  * ****************************************************************/
9069
9070 uint8_t procMacLcCfg(uint8_t lcId, uint8_t rbType, uint8_t configType, DRBs_ToBeSetup_Item_t *drbItem,\
9071 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LogicalChannelConfig_t *ulLcCfg,\
9072 LcCfg *lcCfg, UpTnlCfg *upTnlInfo)
9073 {
9074    uint8_t ret = ROK;
9075
9076    lcCfg->lcId = lcId;
9077    lcCfg->configType = configType;
9078    if(rbType == RB_TYPE_SRB)
9079    {
9080       ret = extractMacRbCfg(lcId, NULL, NULL, NULL, ulLcCfg, lcCfg, NULL);
9081    }
9082    else if(rbType == RB_TYPE_DRB)
9083    {
9084       if(drbItem != NULL)
9085         ret = extractMacRbCfg(lcId, drbItem, NULL, NULL, ulLcCfg, lcCfg, upTnlInfo);
9086       else if(drbSetupModItem != NULL)
9087         ret = extractMacRbCfg(lcId, NULL, drbSetupModItem, NULL, ulLcCfg, lcCfg, upTnlInfo);
9088       else if(drbModItem != NULL)
9089         ret = extractMacRbCfg(lcId, NULL, NULL, drbModItem, ulLcCfg, lcCfg, upTnlInfo);
9090    }
9091    return ret;
9092 }
9093
9094 /*******************************************************************
9095  *
9096  * @brief Function to extract Rlc cfg To Add/Mod in CellGrp Info
9097  *
9098  * @details
9099  *
9100  *    Function : extractRlcCfgToAddMod
9101  *
9102  *    Functionality: Function to extract Rlc cfg To Add/Mod in CellGrp Info
9103  *
9104  * @params[in] CellGroupConfigRrc__rlc_BearerTo pointer
9105  *             DuUeCfg Pointer
9106  * @return ROK/RFAILED
9107  *
9108  * ****************************************************************/
9109
9110 uint8_t extractRlcCfgToAddMod(struct CellGroupConfigRrc__rlc_BearerToAddModList *lcCfg, DuUeCfg *ueCfgDb)
9111 {
9112   uint8_t idx, rbId, lcId, rlcMode, rbType;
9113   RLC_Config_t *f1RlcCfg = NULLP;
9114   LogicalChannelConfig_t *macUlLcCfg = NULLP;
9115
9116   for(idx = 0; idx < lcCfg->list.count; idx++)
9117   {
9118      lcId = lcCfg->list.array[idx]->logicalChannelIdentity;
9119      if(lcCfg->list.array[idx]->servedRadioBearer)
9120      {
9121         /* RadioBearer for SRB/DRB */
9122         if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
9123         RLC_BearerConfig__servedRadioBearer_PR_srb_Identity)
9124         {
9125            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.srb_Identity;
9126            rbType = RB_TYPE_SRB;
9127         }
9128         else if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
9129         RLC_BearerConfig__servedRadioBearer_PR_drb_Identity)
9130         {
9131            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.drb_Identity;
9132            rbType = RB_TYPE_DRB;
9133         }
9134         else
9135         {
9136            DU_LOG("\nERROR  -->  No components present in Bearer config to ADD/MOD");
9137            return RFAILED;
9138         }
9139         /* MAC UL LC Config */
9140         if(lcCfg->list.array[idx]->mac_LogicalChannelConfig)
9141         {
9142            macUlLcCfg = lcCfg->list.array[idx]->mac_LogicalChannelConfig;
9143         }
9144      }
9145      else
9146      {
9147         DU_LOG("\nERROR  -->  DUAPP: Received RadioBearer config is NULL");
9148         return RFAILED;
9149      }
9150      /* RLC Mode Config */
9151      if(lcCfg->list.array[idx]->rlc_Config)
9152      {
9153         rlcMode  = lcCfg->list.array[idx]->rlc_Config->present;
9154         f1RlcCfg = lcCfg->list.array[idx]->rlc_Config;
9155      }
9156      
9157      /* Filling RLC/MAC Config*/
9158      memset(&ueCfgDb->macLcCfg[idx], 0, sizeof(LcCfg));
9159      memset(&ueCfgDb->rlcLcCfg[idx], 0, sizeof(RlcBearerCfg));
9160      procRlcLcCfg(rbId, lcId, rbType, rlcMode, CONFIG_UNKNOWN, f1RlcCfg, &(ueCfgDb->rlcLcCfg[idx]), NULLP);
9161      if(procMacLcCfg(lcId, rbType, CONFIG_UNKNOWN, NULL, NULL, NULL, macUlLcCfg, &ueCfgDb->macLcCfg[idx], NULL) != ROK)
9162      {
9163         DU_LOG("\nERROR  -->  DU APP : Failed while filling MAC LC config at extractRlcCfgToAddMod()");
9164         return RFAILED;
9165      }
9166      (ueCfgDb->numRlcLcs)++;
9167      (ueCfgDb->numMacLcs)++;
9168          DU_LOG("\nDEBUG  -> DUAPP: extractRlcCfgToAddMod:RBType:%d, DrbID: %d,lcId:%d, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
9169                             rbType, rbId, lcId, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
9170   }
9171   //TODO: To send the failure cause in UeContextSetupRsp 
9172   return ROK;
9173 }
9174
9175 /*******************************************************************
9176  *
9177  * @brief DeAlloc pdsch serv cell config info
9178  *
9179  * @details
9180  *
9181  *    Function : freeMacPdschServCellInfo
9182  *
9183  *    Functionality: DeAlloc pdsch serv cell config info
9184  *
9185  * @params[in] PdschServCellCfg pointer
9186  * @return void
9187  *
9188  * ****************************************************************/
9189
9190 void freeMacPdschServCellInfo(PdschServCellCfg *pdsch)
9191 {
9192    if(pdsch->xOverhead)
9193    {
9194       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->xOverhead, sizeof(PdschXOverhead));
9195    }
9196    if(pdsch->codeBlkGrpFlushInd)
9197    {
9198       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->codeBlkGrpFlushInd, sizeof(bool));
9199    }
9200    if(pdsch->maxCodeBlkGrpPerTb)
9201    {
9202       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
9203    }
9204    if(pdsch->maxMimoLayers)
9205    {
9206       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxMimoLayers, sizeof(uint8_t));
9207    }
9208 }
9209
9210 /*******************************************************************
9211  *
9212  * @brief Free Serving cell Info
9213  *
9214  * @details
9215  *
9216  *    Function : freeMacServingCellInfo
9217  *
9218  *    Functionality: Free Serving cell Info
9219  *
9220  * @params[in] ServCellCfgInfo *srvCellCfg
9221  * @return void
9222  *
9223  * ****************************************************************/
9224 void freeMacServingCellInfo(ServCellCfgInfo *srvCellCfg)
9225 {
9226    uint8_t timeDomRsrcIdx;
9227
9228    if(srvCellCfg->initDlBwp.pdschPresent)
9229    {
9230       for(timeDomRsrcIdx = 0; timeDomRsrcIdx < srvCellCfg->initDlBwp.pdschCfg.numTimeDomRsrcAlloc; timeDomRsrcIdx++)
9231       {
9232          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, \
9233             srvCellCfg->initDlBwp.pdschCfg.timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
9234       }
9235    }
9236
9237    freeMacPdschServCellInfo(&srvCellCfg->pdschServCellCfg);
9238    if(srvCellCfg->bwpInactivityTmr)
9239    {
9240       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
9241    }
9242
9243    if(srvCellCfg->initUlBwp.pucchPresent)
9244    {
9245       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->initUlBwp.pucchCfg.dlDataToUlAck, sizeof(PucchDlDataToUlAck));
9246    }
9247 }
9248
9249 /*******************************************************************
9250  *
9251  * @brief Free cell Grp Cfg Info
9252  *
9253  * @details
9254  *
9255  *    Function : freeUeReCfgCellGrpInfo
9256  *
9257  *    Functionality: Free cell Grp Cfg Info
9258  *
9259  * @params[in] MacUeCfg*  duUeCfg
9260  * @return void
9261  *
9262  * ****************************************************************/
9263
9264 void freeUeReCfgCellGrpInfo(MacUeCfg *macUeCfg)
9265 {
9266    freeMacServingCellInfo(&macUeCfg->spCellCfg.servCellCfg);
9267 }
9268
9269 /*******************************************************************
9270  *
9271  * @brief Fills Reconfig SchReqReConfig
9272  *
9273  * @details
9274  *
9275  *    Function : extractSchReqReConfig
9276  *
9277  *    Functionality: Fills Reconfig SchReqReConfig
9278  *
9279  * @params[in] SchedulingRequestConfig_t *cuSchedReq
9280  *             SchedReqCfg*  macSchedReq
9281  * @return void
9282  *
9283  * ****************************************************************/
9284 void extractSchReqReConfig(SchedulingRequestConfig_t *cuSchedReq, SchedReqCfg *macSchedReq)
9285 {
9286    uint8_t schReqIdx = 0;
9287    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqListToAdd = NULLP;
9288    struct SchedulingRequestConfig__schedulingRequestToReleaseList *schReqListToRel = NULLP;
9289
9290    if(cuSchedReq->schedulingRequestToAddModList)
9291    {
9292       schReqListToAdd = cuSchedReq->schedulingRequestToAddModList;
9293       if(schReqListToAdd->list.count)
9294       {
9295          macSchedReq->addModListCount = schReqListToAdd->list.count;
9296          for(schReqIdx = 0; schReqIdx < schReqListToAdd->list.count; schReqIdx++)
9297          {
9298             macSchedReq->addModList[schReqIdx].schedReqId = \
9299                schReqListToAdd->list.array[schReqIdx]->schedulingRequestId;
9300             macSchedReq->addModList[schReqIdx].srProhibitTmr = \
9301                *(schReqListToAdd->list.array[schReqIdx]->sr_ProhibitTimer);
9302             macSchedReq->addModList[schReqIdx].srTransMax    =\
9303                schReqListToAdd->list.array[schReqIdx]->sr_TransMax;
9304          }
9305       }
9306    }
9307    /* Scheduling Req To release */
9308    if(cuSchedReq->schedulingRequestToReleaseList)
9309    {
9310       schReqListToRel = cuSchedReq->schedulingRequestToReleaseList;
9311       if(schReqListToRel->list.count)
9312       {
9313          macSchedReq->relListCount = schReqListToRel->list.count;
9314          for(schReqIdx = 0; schReqIdx < schReqListToRel->list.count; schReqIdx++)
9315          {
9316             macSchedReq->relList[schReqIdx] = \
9317                *schReqListToRel->list.array[schReqIdx];
9318          }
9319       }
9320    }
9321 }
9322
9323 /*******************************************************************
9324  *
9325  * @brief Fills TagReconfig
9326  *
9327  * @details
9328  *
9329  *    Function : extractTagReconfig
9330  *
9331  *    Functionality: Fills extractTagReconfig
9332  *
9333  * @params[in] TAG_Config_t *cuTagCfg
9334  *             TagCfg *macTagCfg
9335  * @return void
9336  *
9337  * ****************************************************************/
9338
9339 void extractTagReconfig(TAG_Config_t *cuTagCfg, TagCfg *macTagCfg)
9340 {
9341   uint8_t tagIdx = 0;
9342   struct TAG_Config__tag_ToAddModList  *tagListToAddMod = NULLP;
9343   struct TAG_Config__tag_ToReleaseList *tagListToRel = NULLP;
9344
9345   /* Tag config to AddMod */
9346   if(cuTagCfg->tag_ToAddModList)
9347   {
9348      tagListToAddMod = cuTagCfg->tag_ToAddModList; 
9349      if(tagListToAddMod->list.count)
9350      {
9351         macTagCfg->addModListCount = tagListToAddMod->list.count;
9352         for(tagIdx = 0; tagIdx < tagListToAddMod->list.count; tagIdx++)
9353         {
9354            macTagCfg->addModList[tagIdx].tagId =\
9355               tagListToAddMod->list.array[tagIdx]->tag_Id;     
9356            macTagCfg->addModList[tagIdx].timeAlignTimer = \
9357
9358               tagListToAddMod->list.array[tagIdx]->timeAlignmentTimer;
9359         }
9360      }
9361   }
9362   /* Tag config to release */
9363   if(cuTagCfg->tag_ToReleaseList)
9364   {
9365      tagListToRel = cuTagCfg->tag_ToReleaseList;
9366      if(tagListToRel->list.count)
9367      {
9368         macTagCfg->relListCount = tagListToRel->list.count;
9369         for(tagIdx = 0; tagIdx < tagListToRel->list.count; tagIdx++)
9370         {
9371            macTagCfg->relList[tagIdx] = *tagListToRel->list.array[tagIdx];     
9372         }
9373      }
9374   }
9375 }
9376
9377 /*******************************************************************
9378  *
9379  * @brief Fills PdcchCfg received by CU
9380  *
9381  * @details
9382  *
9383  *    Function : extractPdcchCfg
9384  *
9385  *    Functionality: Fills PdcchCfg received  by CU
9386  *
9387  * @params[in] PDCCH_Config_t *cuPdcchCfg,
9388  *             PdcchConfig *duPdcchCfg
9389  * @return void
9390  *
9391  * ****************************************************************/
9392
9393 void extractPdcchCfg(PDCCH_Config_t *cuPdcchCfg, PdcchConfig *macPdcchCfg)
9394 {
9395    uint8_t cRsetIdx = 0;
9396    uint8_t srchSpcIdx = 0;
9397
9398    struct PDCCH_Config__controlResourceSetToAddModList *cRsetToAddModList = NULLP;
9399    struct PDCCH_Config__controlResourceSetToReleaseList *cRsetToRelList = NULLP;
9400    struct PDCCH_Config__searchSpacesToAddModList *srchSpcToAddModList = NULLP;
9401    struct PDCCH_Config__searchSpacesToReleaseList *srchSpcToRelList = NULLP;
9402
9403
9404    /* Control Resource Set To Add/Mod List */
9405    if(cuPdcchCfg->controlResourceSetToAddModList)
9406    {
9407       cRsetToAddModList = cuPdcchCfg->controlResourceSetToAddModList;
9408       if(cRsetToAddModList->list.count)
9409       {
9410          macPdcchCfg->numCRsetToAddMod = cRsetToAddModList->list.count;
9411          for(cRsetIdx = 0; cRsetIdx < cRsetToAddModList->list.count; cRsetIdx++)
9412          {
9413             macPdcchCfg->cRSetToAddModList[cRsetIdx].cRSetId = \
9414                cRsetToAddModList->list.array[cRsetIdx]->controlResourceSetId;
9415             //freqDomRsrcBitStringToInt(&cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources,\
9416                   macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc);
9417             memcpy(macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc, \
9418                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.buf,
9419                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.size);
9420
9421             macPdcchCfg->cRSetToAddModList[cRsetIdx].duration = \
9422                 cRsetToAddModList->list.array[cRsetIdx]->duration;
9423
9424             macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType = \
9425                cRsetToAddModList->list.array[cRsetIdx]->cce_REG_MappingType.present;   
9426             if(macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType == CCE_REG_MAPPINGTYPE_PR_INTERLEAVED)
9427             {
9428                //TODO: handle the case for Interleaved
9429             }
9430             macPdcchCfg->cRSetToAddModList[cRsetIdx].precoderGranularity = \
9431                 cRsetToAddModList->list.array[cRsetIdx]->precoderGranularity;
9432             if(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID)
9433             {
9434                macPdcchCfg->cRSetToAddModList[cRsetIdx].dmrsScramblingId= \
9435                   *(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID);
9436             }
9437          }
9438       }
9439    }
9440    /* Control Resource Set To Release List */
9441    if(cuPdcchCfg->controlResourceSetToReleaseList)
9442    {
9443       cRsetToRelList = cuPdcchCfg->controlResourceSetToReleaseList;
9444       if(cRsetToRelList->list.count)
9445       {
9446          macPdcchCfg->numCRsetToRel = cRsetToRelList->list.count;
9447          for(cRsetIdx = 0; cRsetIdx < cRsetToRelList->list.count; cRsetIdx++)
9448          {
9449             macPdcchCfg->cRSetToRelList[cRsetIdx] = *(cRsetToRelList->list.array[cRsetIdx]);
9450          }
9451       }
9452    }
9453
9454    /* Search space To Add/Mod List */
9455    if(cuPdcchCfg->searchSpacesToAddModList)
9456    {
9457       srchSpcToAddModList = cuPdcchCfg->searchSpacesToAddModList;
9458       if(srchSpcToAddModList->list.count)
9459       {
9460          macPdcchCfg->numSearchSpcToAddMod = srchSpcToAddModList->list.count;
9461          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToAddModList->list.count; srchSpcIdx++)
9462          {
9463             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceId =\
9464                                                                           srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceId;
9465             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].cRSetId =\
9466                                                                     *(srchSpcToAddModList->list.array[srchSpcIdx]->controlResourceSetId);
9467             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset)
9468             {
9469                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSlotPeriodicityAndOffset =\
9470                                                                                          srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset->present;
9471             }
9472             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot)
9473             {
9474                bitStringToInt(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot,\
9475                      macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSymbolsWithinSlot);
9476             }
9477             if(srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates)
9478             {
9479                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel1 = \
9480                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel1;
9481                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel2 = \
9482                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel2;
9483                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel4 = \
9484                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel4;
9485
9486                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel8 = \
9487                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel8;
9488
9489                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel16 = \
9490                                                                                         srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel16;
9491             }
9492             if(srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType)
9493             {
9494                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType =\
9495                                                                                srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->present;
9496                if(macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType == SEARCHSPACETYPE_PR_UE_SPECIFIC)
9497                {
9498                   macPdcchCfg->searchSpcToAddModList[srchSpcIdx].ueSpecificDciFormat =\
9499                                                                                       srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->choice.ue_Specific->dci_Formats;
9500                }
9501
9502             }
9503          }
9504       }
9505    }
9506    /* Search space To Rel List */
9507    if(cuPdcchCfg->searchSpacesToReleaseList)
9508    {
9509       srchSpcToRelList = cuPdcchCfg->searchSpacesToReleaseList;
9510       if(srchSpcToRelList->list.count)
9511       {
9512          macPdcchCfg->numSearchSpcToRel = srchSpcToRelList->list.count;
9513          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToRelList->list.count; srchSpcIdx++)
9514          {
9515             macPdcchCfg->searchSpcToRelList[srchSpcIdx] =\
9516                                                          *(srchSpcToRelList->list.array[srchSpcIdx]);
9517          }
9518       }
9519    }
9520 }
9521
9522 /*******************************************************************
9523  *
9524  * @brief Fills PdschCfg received by CU
9525  *
9526  * @details
9527  *
9528  *    Function : extractPdschCfg
9529  *
9530  *    Functionality: Fills PdschCfg received  by CU
9531  *
9532  * @params[in] PDSCH_Config_t *cuPdschCfg = Information which is send by CU,
9533  *                   which we have stored in F1UeContextSetupDb,
9534  *             PdschConfig *macPdschCfg = Used to Store the information which
9535  *                   needs to send in other layer, as well as this can be the variable
9536  *                   which stores the information in DuCb,
9537  *             PdschConfig *storedPdschCfg =  Null in case of sending the
9538  *                   information to other layer else it will have stored pdsch 
9539  *                   configuration in copyOfmacUeCfg.
9540  * @return void
9541  *
9542  * ****************************************************************/
9543
9544 void extractPdschCfg(PDSCH_Config_t *cuPdschCfg, PdschConfig *macPdschCfg, PdschConfig *storedPdschCfg)
9545 {
9546    uint8_t timeDomIdx;
9547    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAlloc = NULLP;
9548
9549    if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
9550    {
9551       if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->present == \
9552             PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup)
9553       {
9554          if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup)
9555          {
9556             macPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
9557                *(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_AdditionalPosition);
9558          }
9559       }
9560    }
9561    macPdschCfg->resourceAllocType = cuPdschCfg->resourceAllocation;
9562    if(cuPdschCfg->pdsch_TimeDomainAllocationList)
9563    {
9564       timeDomAlloc = cuPdschCfg->pdsch_TimeDomainAllocationList;
9565       if(timeDomAlloc->present ==\
9566             PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup)
9567       {
9568          if(timeDomAlloc->choice.setup)
9569          {
9570             macPdschCfg->numTimeDomRsrcAlloc  = timeDomAlloc->choice.setup->list.count;
9571             for(timeDomIdx = 0; timeDomIdx < timeDomAlloc->choice.setup->list.count; timeDomIdx++)
9572             {
9573                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 = NULLP;
9574                if(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0)
9575                {
9576                   if(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 == NULL)
9577                   {
9578                      if(storedPdschCfg)
9579                      {
9580                         if(storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
9581                         {
9582                            macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 =\
9583                            storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0;
9584                         }
9585                         else
9586                         {
9587                            DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
9588                         }
9589                      }
9590                      else
9591                      {
9592                         DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
9593                      }
9594                      if(!macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
9595                      {
9596                         DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for k0 at extractPdschCfg()");
9597                         return;
9598                      }
9599                   }
9600                   *(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0) = \
9601                   *(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0);
9602                }
9603                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].mappingType = \
9604                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->mappingType;
9605                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].startSymbolAndLength = \
9606                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
9607             }
9608          }
9609       }
9610    }
9611    macPdschCfg->rbgSize = cuPdschCfg->rbg_Size;
9612    if(cuPdschCfg->maxNrofCodeWordsScheduledByDCI)
9613       macPdschCfg->numCodeWordsSchByDci = *(cuPdschCfg->maxNrofCodeWordsScheduledByDCI);
9614    if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_staticBundling)
9615    {
9616       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
9617       if(cuPdschCfg->prb_BundlingType.choice.staticBundling)
9618       {
9619          if(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize)
9620          {
9621             macPdschCfg->bundlingInfo.StaticBundling.size = \
9622                *(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize);
9623          }
9624       }
9625    }
9626    else if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_dynamicBundling)
9627    {
9628       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
9629    }
9630
9631 }
9632
9633 /*******************************************************************
9634  *
9635  * @brief Fills PdschServingCellCfg received by CU
9636  *
9637  * @details
9638  *
9639  *    Function : extractPdschServingCellCfg
9640  *
9641  *    Functionality: Fills PdschCfg received  by CU
9642  *
9643  * @params[in] PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg,
9644  *             PdschServCellCfg *macUePdschSrvCellCfg
9645  * @return ROK/RFAILED
9646  *
9647  * ****************************************************************/
9648
9649 uint8_t extractPdschServingCellCfg(PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg, PdschServCellCfg *macUePdschSrvCellCfg)
9650 {
9651    if(cuPdschSrvCellCfg->codeBlockGroupTransmission)
9652    {
9653       if(cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup)
9654       {
9655          if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
9656          {
9657             *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
9658                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
9659          }
9660          else
9661          {
9662             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
9663             if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
9664             {
9665                *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
9666                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
9667             }
9668             else
9669             {
9670                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxCodeBlkGrpPerTb at extractPdschServingCellCfg()");
9671                return RFAILED;
9672             }
9673          }
9674          if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
9675          {
9676             *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
9677                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
9678          }
9679          else
9680          {
9681             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->codeBlkGrpFlushInd , sizeof(bool));
9682             if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
9683             {
9684                *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
9685                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
9686             }
9687             else
9688             {
9689                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for codeBlkGrpFlushInd at extractPdschServingCellCfg()");
9690                return RFAILED;
9691             }
9692          }
9693       }
9694    }
9695    if(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH)
9696    {
9697       macUePdschSrvCellCfg->numHarqProcForPdsch = *(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH); 
9698    }
9699    if(cuPdschSrvCellCfg->ext1)
9700    {
9701       if(cuPdschSrvCellCfg->ext1->maxMIMO_Layers)
9702       {
9703         if(macUePdschSrvCellCfg->maxMimoLayers)
9704         {
9705            *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
9706         }
9707         else
9708         {
9709            DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxMimoLayers, sizeof(uint8_t));
9710            if(macUePdschSrvCellCfg->maxMimoLayers)
9711            {
9712               *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
9713            }
9714            else
9715            {
9716               DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxMimoLayers at extractPdschServingCellCfg()");
9717               return RFAILED;
9718            }
9719         }
9720       }
9721    }
9722    if(cuPdschSrvCellCfg->xOverhead)
9723    {
9724       if(macUePdschSrvCellCfg->xOverhead)
9725       {
9726          *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
9727       }
9728       else
9729       {
9730          DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->xOverhead, sizeof(PdschXOverhead));
9731          if(macUePdschSrvCellCfg->xOverhead)
9732          {
9733             *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
9734          }
9735          else
9736          {
9737             DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for xOverhead at extractPdschServingCellCfg()");
9738             return RFAILED;
9739          }
9740       }
9741    }
9742    return ROK;
9743 }
9744
9745 /*******************************************************************
9746  *
9747  * @brief Fills PuschCfg received by CU
9748  *
9749  * @details
9750  *
9751  *    Function : extractPuschCfg
9752  *
9753  *    Functionality: Fills PuschCfg received  by CU
9754  *
9755  * @params[in] BWP_UplinkDedicated__pusch_Config *cuPuschCfg,
9756  *             PuschCfg *macPuschCfg
9757  * @return void
9758  *
9759  * ****************************************************************/
9760
9761 void extractPuschCfg(struct BWP_UplinkDedicated__pusch_Config *cuPuschCfg, PuschCfg *macPuschCfg)
9762 {
9763    uint8_t timeDomIdx = 0;
9764    DMRS_UplinkConfig_t *dmrsUlCfg = NULLP;
9765    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList = NULLP;
9766
9767    if(cuPuschCfg->present == BWP_UplinkDedicated__pusch_Config_PR_setup)
9768    {
9769       if(cuPuschCfg->choice.setup)
9770       {
9771          if(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH)
9772          {
9773              macPuschCfg->dataScramblingId = \
9774                 *(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH);
9775          }
9776          if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA)
9777          {
9778             if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->present == PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup)
9779             {
9780                if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup)
9781                {
9782                   dmrsUlCfg = (cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup);
9783                   if(dmrsUlCfg->dmrs_AdditionalPosition)
9784                   {
9785                      macPuschCfg->dmrsUlCfgForPuschMapTypeA.addPos =\
9786                         *(dmrsUlCfg->dmrs_AdditionalPosition);
9787                   }
9788                   if(dmrsUlCfg->transformPrecodingDisabled)
9789                   {
9790                      if(dmrsUlCfg->transformPrecodingDisabled->scramblingID0)
9791                      {
9792                         macPuschCfg->dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0 = \
9793                            *(dmrsUlCfg->transformPrecodingDisabled->scramblingID0);
9794                      }
9795                   }
9796                }
9797             }
9798          }
9799          /*Res Alloc Type for UL */
9800          if(cuPuschCfg->choice.setup->resourceAllocation)
9801          {
9802             macPuschCfg->resourceAllocType = \
9803                cuPuschCfg->choice.setup->resourceAllocation;
9804          }
9805          if(cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList)
9806          {
9807             timeDomAllocList = cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList;
9808             if(timeDomAllocList->present == PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup)
9809             {
9810                if(timeDomAllocList->choice.setup)
9811                {
9812                   macPuschCfg->numTimeDomRsrcAlloc = timeDomAllocList->choice.setup->list.count;
9813                   for(timeDomIdx = 0; timeDomIdx <timeDomAllocList->choice.setup->list.count; timeDomIdx++)
9814                   {
9815                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].k2 = \
9816                         *(timeDomAllocList->choice.setup->list.array[timeDomIdx]->k2);
9817                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].mappingType = \
9818                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->mappingType;
9819                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].startSymbolAndLength = \
9820                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
9821                   }
9822                }
9823             }
9824          }
9825          if(cuPuschCfg->choice.setup->transformPrecoder)
9826             macPuschCfg->transformPrecoder = *(cuPuschCfg->choice.setup->transformPrecoder);
9827       }
9828    }
9829 }
9830
9831 /*******************************************************************
9832  *
9833  * @brief Function to fill pucch Power Control
9834  *
9835  * @details
9836  *
9837  *    Function : extractPucchPowerControl
9838  *
9839  *    Functionality: Function to fill pucch Power Control
9840  *
9841  * @params[in] PucchPowerControl *pwrCtrl,
9842  *             struct PUCCH_PowerControl *cuPwrCtrlCfg
9843  * @return void
9844  *
9845  * ****************************************************************/
9846
9847 void extractPucchPowerControl(PucchPowerControl *pwrCtrl, struct PUCCH_PowerControl *cuPwrCtrlCfg)
9848 {
9849    uint8_t arrIdx;
9850
9851    if(cuPwrCtrlCfg->deltaF_PUCCH_f0)
9852       pwrCtrl->deltaF_Format0 = *cuPwrCtrlCfg->deltaF_PUCCH_f0;
9853    if(cuPwrCtrlCfg->deltaF_PUCCH_f1)
9854       pwrCtrl->deltaF_Format1 = *cuPwrCtrlCfg->deltaF_PUCCH_f1;
9855    if(cuPwrCtrlCfg->deltaF_PUCCH_f2)
9856       pwrCtrl->deltaF_Format2 = *cuPwrCtrlCfg->deltaF_PUCCH_f2;
9857    if(cuPwrCtrlCfg->deltaF_PUCCH_f3)
9858       pwrCtrl->deltaF_Format3 = *cuPwrCtrlCfg->deltaF_PUCCH_f3;
9859    if(cuPwrCtrlCfg->deltaF_PUCCH_f4)
9860       pwrCtrl->deltaF_Format4 = *cuPwrCtrlCfg->deltaF_PUCCH_f4;
9861    if(cuPwrCtrlCfg->p0_Set)
9862    {
9863       pwrCtrl->p0SetCount = cuPwrCtrlCfg->p0_Set->list.count;
9864       for(arrIdx=0; arrIdx < pwrCtrl->p0SetCount; arrIdx++)
9865       {
9866          pwrCtrl->p0Set[arrIdx].p0PucchId =\
9867             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Id;
9868          pwrCtrl->p0Set[arrIdx].p0PucchVal =\
9869             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Value;
9870       }
9871    }
9872    if(cuPwrCtrlCfg->pathlossReferenceRSs)
9873    {
9874       pwrCtrl->pathLossRefRSListCount = cuPwrCtrlCfg->pathlossReferenceRSs->list.count;
9875       for(arrIdx = 0; arrIdx < pwrCtrl->pathLossRefRSListCount; arrIdx++)
9876       {
9877          pwrCtrl->pathLossRefRSList[arrIdx].pathLossRefRSId =\
9878             cuPwrCtrlCfg->pathlossReferenceRSs->list.array[arrIdx]->pucch_PathlossReferenceRS_Id;
9879       }
9880    }
9881 }
9882  
9883  /*******************************************************************
9884  *
9885  * @brief Function to extractResrcSetToAddModList sent by CU
9886  *
9887  * @details
9888  *
9889  *    Function : extractResrcSetToAddModList
9890  *
9891  *    Functionality: Fucntion to extractResrcSetToAddModList
9892  *
9893  * @params[in] PucchResrcSetCfg pointer,
9894  *             struct PUCCH_Config__resourceSetToAddModList pointer
9895  * @return void
9896  *
9897  * ****************************************************************/
9898
9899 void extractResrcSetToAddModList(PucchResrcSetCfg *macRsrcSetList, struct PUCCH_Config__resourceSetToAddModList *cuRsrcSetList)
9900 {
9901    uint8_t arrIdx, rsrcListIdx;
9902
9903    macRsrcSetList->resrcSetToAddModListCount = cuRsrcSetList->list.count; 
9904    for(arrIdx = 0; arrIdx < macRsrcSetList->resrcSetToAddModListCount; arrIdx++)
9905    {
9906       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcSetId     =\
9907          cuRsrcSetList->list.array[arrIdx]->pucch_ResourceSetId;
9908       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount =\
9909          cuRsrcSetList->list.array[arrIdx]->resourceList.list.count;
9910       for(rsrcListIdx = 0; rsrcListIdx < macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount; rsrcListIdx++)
9911       {
9912          macRsrcSetList->resrcSetToAddModList[arrIdx].resrcList[rsrcListIdx] =\
9913             *cuRsrcSetList->list.array[arrIdx]->resourceList.list.array[rsrcListIdx];
9914       }
9915
9916       if(cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1)
9917       {
9918          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize =\
9919             *cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1;
9920       }
9921       else
9922       {
9923          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize = 0;
9924       }
9925    }
9926 }/* End of extractResrcSetToAddModList */
9927
9928 /*******************************************************************
9929  *
9930  * @brief Fills extractResrcToAddModList sent by CU
9931  *
9932  * @details
9933  *
9934  *    Function : extractResrcToAddModList
9935  *
9936  *    Functionality: Fills extractResrcToAddModList
9937  *
9938  * @params[in] PucchResrcCfg pointer,
9939  *             struct PUCCH_Config__resourceToAddModList pointer
9940  * @return ROk/RFAILED
9941  *
9942  * ****************************************************************/
9943
9944 uint8_t extractResrcToAddModList(PucchResrcCfg *macResrcList, struct PUCCH_Config__resourceToAddModList *cuResrcList)
9945 {
9946    uint8_t arrIdx;
9947    
9948    macResrcList->resrcToAddModListCount = cuResrcList->list.count;
9949    for(arrIdx = 0; arrIdx < macResrcList->resrcToAddModListCount; arrIdx++)
9950    {
9951       macResrcList->resrcToAddModList[arrIdx].resrcId      =\
9952         cuResrcList->list.array[arrIdx]->pucch_ResourceId; 
9953       macResrcList->resrcToAddModList[arrIdx].startPrb     =\
9954         cuResrcList->list.array[arrIdx]->startingPRB;
9955       if(cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping)
9956       {
9957          macResrcList->resrcToAddModList[arrIdx].intraFreqHop =\
9958            *cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping;
9959       }
9960       if(cuResrcList->list.array[arrIdx]->secondHopPRB)
9961       {
9962          macResrcList->resrcToAddModList[arrIdx].secondPrbHop =\
9963            *cuResrcList->list.array[arrIdx]->secondHopPRB;
9964       }
9965       /* PUCCH RSRC FORMAT */
9966       if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format0)
9967       {
9968          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_0;
9969          if(cuResrcList->list.array[arrIdx]->format.choice.format0)
9970          {
9971             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0, sizeof(PucchFormat0));
9972             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0 == NULLP)
9973             {
9974                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format0 in extractResrcToAddModList()");
9975                return RFAILED;
9976             }
9977             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->initialCyclicShift =\
9978                cuResrcList->list.array[arrIdx]->format.choice.format0->initialCyclicShift;
9979             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->numSymbols =\
9980                cuResrcList->list.array[arrIdx]->format.choice.format0->nrofSymbols;
9981             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->startSymbolIdx =\
9982                cuResrcList->list.array[arrIdx]->format.choice.format0->startingSymbolIndex;
9983          }
9984       }
9985       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format1)
9986       {
9987          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_1;
9988          if(cuResrcList->list.array[arrIdx]->format.choice.format1)
9989          {
9990             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1, sizeof(PucchFormat1));
9991             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1 == NULLP)
9992             {
9993                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format1 in extractResrcToAddModList()");
9994                return RFAILED;
9995             }
9996             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->initialCyclicShift =\
9997                 cuResrcList->list.array[arrIdx]->format.choice.format1->initialCyclicShift;
9998             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->numSymbols =\
9999                 cuResrcList->list.array[arrIdx]->format.choice.format1->nrofSymbols;
10000             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->startSymbolIdx =\
10001                 cuResrcList->list.array[arrIdx]->format.choice.format1->startingSymbolIndex;
10002             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->timeDomOCC =\
10003                 cuResrcList->list.array[arrIdx]->format.choice.format1->timeDomainOCC;
10004          }
10005       }
10006       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format2)
10007       {
10008          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_2;
10009          if(cuResrcList->list.array[arrIdx]->format.choice.format2)
10010          {
10011             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
10012             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2 == NULLP)
10013             {
10014                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format2 in extractResrcToAddModList()");
10015                return RFAILED;
10016             }
10017             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numPrbs =\
10018                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofPRBs;
10019             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numSymbols =\
10020                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofSymbols;
10021             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->startSymbolIdx =\
10022                 cuResrcList->list.array[arrIdx]->format.choice.format2->startingSymbolIndex;
10023          }
10024       }
10025       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format3)
10026       {
10027          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_3;
10028          if(cuResrcList->list.array[arrIdx]->format.choice.format3)
10029          {
10030             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
10031             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3 == NULLP)
10032             {
10033                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format3 in extractResrcToAddModList()");
10034                return RFAILED;
10035             }
10036             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numPrbs =\
10037                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofPRBs;
10038             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numSymbols =\
10039                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofSymbols;
10040             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->startSymbolIdx =\
10041                 cuResrcList->list.array[arrIdx]->format.choice.format3->startingSymbolIndex;
10042          }
10043       }
10044       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format4)
10045       {
10046          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_4;
10047          if(cuResrcList->list.array[arrIdx]->format.choice.format4)
10048          {
10049             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4, sizeof(PucchFormat4));
10050             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4 == NULLP)
10051             {
10052                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format4 in extractResrcToAddModList()");
10053                return RFAILED;
10054             }
10055             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->numSymbols =\
10056                 cuResrcList->list.array[arrIdx]->format.choice.format4->nrofSymbols;
10057             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occLen =\
10058                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Length;
10059             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occIdx =\
10060                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Index;
10061             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->startSymbolIdx =\
10062                 cuResrcList->list.array[arrIdx]->format.choice.format4->startingSymbolIndex;
10063          }
10064       }
10065    }
10066    return ROK;
10067
10068 }/* End of extractResrcToAddModList */
10069
10070 /*******************************************************************
10071  *
10072  * @brief Fills fillPucchSchedReqPeriodAndOffset sent by CU
10073  *
10074  * @details
10075  *
10076  *    Function : fillPucchSchedReqPeriodAndOffset
10077  *
10078  *    Functionality: To fillPucchSchedReqPeriodAndOffset
10079  *
10080  * @params[in] macPeriodicty,
10081  *     SchedulingRequestResourceConfig__periodicityAndOffset pointer
10082  * @return void
10083  *
10084  * ****************************************************************/
10085
10086 void fillPucchSchedReqPeriodAndOffset(uint8_t macPeriodicty, uint16_t  macOffset,\
10087    struct SchedulingRequestResourceConfig__periodicityAndOffset *cuPeriodicty)
10088 {
10089    macPeriodicty = cuPeriodicty->present;
10090    switch(macPeriodicty)
10091    {
10092       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
10093          {
10094             macOffset     = cuPeriodicty->choice.sym2;
10095             break;
10096          }
10097       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
10098          {
10099             macOffset     = cuPeriodicty->choice.sym6or7;
10100             break;
10101          }
10102       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
10103          {
10104             macOffset     = cuPeriodicty->choice.sl1;
10105             break;
10106          }
10107       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
10108          {
10109             macOffset = cuPeriodicty->choice.sl2;
10110             break;
10111          }
10112       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
10113          {
10114             macOffset = cuPeriodicty->choice.sl4;
10115             break;
10116          }
10117       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
10118          {
10119             macOffset = cuPeriodicty->choice.sl5;
10120             break;
10121          }
10122       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
10123          {
10124             macOffset = cuPeriodicty->choice.sl8;
10125             break;
10126          }
10127       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
10128          {
10129             macOffset = cuPeriodicty->choice.sl10;
10130             break;
10131          }
10132       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
10133          {
10134             macOffset = cuPeriodicty->choice.sl16;
10135             break;
10136          }
10137       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
10138          {
10139             macOffset = cuPeriodicty->choice.sl20;
10140             break;
10141          }
10142       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
10143          {
10144             macOffset = cuPeriodicty->choice.sl40;
10145             break;
10146          }
10147       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
10148          {
10149             macOffset = cuPeriodicty->choice.sl80;
10150             break;
10151          }
10152       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
10153          {
10154             macOffset = cuPeriodicty->choice.sl160;
10155             break;
10156          }
10157       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
10158          {
10159             macOffset = cuPeriodicty->choice.sl320;
10160             break;
10161          }
10162       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
10163          {
10164             macOffset = cuPeriodicty->choice.sl640;
10165             break;
10166          }
10167       default :
10168          DU_LOG("\nERROR  -->  F1AP : Invalid periodicity %d", macPeriodicty);
10169    }
10170 }
10171
10172 /*******************************************************************
10173  *
10174  * @brief Function to extractPucchFormatCfg sent by CU
10175  *
10176  * @details
10177  *
10178  *    Function : extractPucchFormatCfg
10179  *
10180  *    Functionality: Function to extractPucchFormatCfg
10181  *
10182  * @params[in] PucchFormatCfg pointer,
10183  *             PUCCH_FormatConfig_t pointer
10184  * @return void
10185  *
10186  * ****************************************************************/
10187
10188 void extractPucchFormatCfg(PucchFormatCfg *macFormatCfg, PUCCH_FormatConfig_t *cuFormatCfg)
10189  {
10190     if(cuFormatCfg->interslotFrequencyHopping)
10191        macFormatCfg->interSlotFreqHop = *cuFormatCfg->interslotFrequencyHopping;
10192     if(cuFormatCfg->additionalDMRS)  
10193        macFormatCfg->addDmrs = *cuFormatCfg->additionalDMRS;
10194     if(cuFormatCfg->maxCodeRate)
10195        macFormatCfg->maxCodeRate = *cuFormatCfg->maxCodeRate;
10196     if(cuFormatCfg->nrofSlots)  
10197        macFormatCfg->numSlots = *cuFormatCfg->nrofSlots;
10198     if(cuFormatCfg->pi2BPSK)  
10199        macFormatCfg->pi2BPSK = *cuFormatCfg->pi2BPSK;
10200     if(cuFormatCfg->simultaneousHARQ_ACK_CSI)  
10201        macFormatCfg->harqAckCSI = *cuFormatCfg->simultaneousHARQ_ACK_CSI;
10202  }/* End of extractPucchFormatCfg */
10203
10204 /*******************************************************************
10205  *
10206  * @brief Function to extractSchedReqCfgToAddMod sent by CU
10207  *
10208  * @details
10209  *
10210  *    Function : extractSchedReqCfgToAddMod
10211  *
10212  *    Functionality: Function to extractSchedReqCfgToAddMod
10213  *
10214  * @params[in] PucchSchedReqCfg pointer,
10215  *      PUCCH_Config__schedulingRequestResourceToAddModList pointer
10216  * @return void
10217  *
10218  * ****************************************************************/
10219
10220 void extractSchedReqCfgToAddMod(PucchSchedReqCfg *macSchedReqCfg, struct PUCCH_Config__schedulingRequestResourceToAddModList *cuSchedReqList)
10221 {
10222    uint8_t arrIdx;
10223
10224    macSchedReqCfg->schedAddModListCount = cuSchedReqList->list.count;
10225    for(arrIdx = 0; arrIdx <  macSchedReqCfg->schedAddModListCount; arrIdx++)
10226    {
10227       macSchedReqCfg->schedAddModList[arrIdx].resrcId =\
10228          cuSchedReqList->list.array[arrIdx]->schedulingRequestResourceId;
10229       macSchedReqCfg->schedAddModList[arrIdx].requestId =\
10230          cuSchedReqList->list.array[arrIdx]->schedulingRequestID;
10231       if(cuSchedReqList->list.array[arrIdx]->periodicityAndOffset)
10232       {
10233          fillPucchSchedReqPeriodAndOffset(macSchedReqCfg->schedAddModList[arrIdx].periodicity,\
10234             macSchedReqCfg->schedAddModList[arrIdx].offset, cuSchedReqList->list.array[arrIdx]->periodicityAndOffset);
10235       }
10236       if(cuSchedReqList->list.array[arrIdx]->resource)
10237       {
10238          macSchedReqCfg->schedAddModList[arrIdx].resrc =\
10239             *cuSchedReqList->list.array[arrIdx]->resource;
10240       }
10241    }
10242
10243 }/* End of extractSchedReqCfgToAddMod */
10244
10245  /*******************************************************************
10246  *
10247  * @brief Fills PucchCfg received by CU
10248  *
10249  * @details
10250  *
10251  *    Function : extractPucchCfg
10252  *
10253  *    Functionality: Fills PucchCfg received  by CU
10254  *
10255  * @params[in] BWP_UplinkDedicated__pucch_Config *cuPucchCfg = Information which
10256  *                is send by CU, which we have stored in F1UeContextSetupDb,
10257  *             PucchCfg *macPucchCfg = Used to Store the information which
10258  *                needs to send in other layer, as well as this can be the variable
10259  *                which stores the information in DuCb,
10260  *             PucchCfg *storedPucchCfg = Null in case of sending the
10261  *                information to other layer else it will have Pucch Cfg which
10262  *                we have stored in copyOfmacUeCfg.
10263  * @return ROK/RFAILED
10264  *
10265  * ****************************************************************/
10266
10267 uint8_t extractPucchCfg(struct BWP_UplinkDedicated__pucch_Config *cuPucchCfg, PucchCfg *macPucchCfg,\
10268 PucchCfg *storedPucchCfg)        
10269 {
10270    uint8_t arrIdx;
10271
10272    if(cuPucchCfg->present == BWP_UplinkDedicated__pucch_Config_PR_setup)
10273    {
10274       if(cuPucchCfg->choice.setup)
10275       {
10276          /* Resource Set Cfg */ 
10277          if(cuPucchCfg->choice.setup->resourceSetToAddModList)
10278          {
10279             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrcSet, sizeof(PucchResrcSetCfg));
10280             if(macPucchCfg->resrcSet == NULLP)
10281             {
10282                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc set List in extractPucchCfg()");
10283                return RFAILED;
10284             }
10285             memset(macPucchCfg->resrcSet, 0, sizeof(PucchResrcSetCfg));
10286             extractResrcSetToAddModList(macPucchCfg->resrcSet, cuPucchCfg->choice.setup->resourceSetToAddModList);
10287          }
10288          
10289          /* Resource Cfg */ 
10290          if(cuPucchCfg->choice.setup->resourceToAddModList)
10291          {
10292             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrc, sizeof(PucchResrcCfg));
10293             if(macPucchCfg->resrc == NULLP)
10294             {
10295                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc List in extractPucchCfg()");
10296                return RFAILED;
10297             }
10298             memset(macPucchCfg->resrc, 0, sizeof(PucchResrcCfg));
10299             extractResrcToAddModList(macPucchCfg->resrc, cuPucchCfg->choice.setup->resourceToAddModList);
10300          }
10301          
10302          /* Format 1 Cfg */ 
10303          if(cuPucchCfg->choice.setup->format1)
10304          {
10305             DU_ALLOC_SHRABL_BUF(macPucchCfg->format1, sizeof(PucchFormatCfg));
10306             if(macPucchCfg->format1 == NULLP)
10307             {
10308                DU_LOG("\nERROR --> F1AP : Failed to extract format 1 Cfg in  extractPucchCfg()");
10309                return RFAILED;
10310             }
10311             memset(macPucchCfg->format1, 0, sizeof(PucchFormatCfg));
10312             extractPucchFormatCfg(macPucchCfg->format1,\
10313                cuPucchCfg->choice.setup->format1->choice.setup);
10314          }
10315          
10316          /* Format 2 Cfg */
10317          if(cuPucchCfg->choice.setup->format2)
10318          {
10319             DU_ALLOC_SHRABL_BUF(macPucchCfg->format2, sizeof(PucchFormatCfg));
10320             if(macPucchCfg->format2 == NULLP)
10321             {
10322                DU_LOG("\nERROR --> F1AP : Failed to extract format 2 Cfg in  extractPucchCfg()");
10323                return RFAILED;
10324             }
10325             memset(macPucchCfg->format2, 0, sizeof(PucchFormatCfg));
10326             extractPucchFormatCfg(macPucchCfg->format2,\
10327                cuPucchCfg->choice.setup->format2->choice.setup);
10328          }
10329          
10330          /* Format 3 Cfg */
10331          if(cuPucchCfg->choice.setup->format3)
10332          {
10333             DU_ALLOC_SHRABL_BUF(macPucchCfg->format3, sizeof(PucchFormatCfg));
10334             if(macPucchCfg->format3 == NULLP)
10335             {
10336                DU_LOG("\nERROR --> F1AP : Failed to extract format 3 Cfg in  extractPucchCfg()");
10337                return RFAILED;
10338             }
10339             memset(macPucchCfg->format3, 0, sizeof(PucchFormatCfg));
10340             extractPucchFormatCfg(macPucchCfg->format3,\
10341                cuPucchCfg->choice.setup->format3->choice.setup);
10342          }
10343
10344          /* Format 4 Cfg */
10345          if(cuPucchCfg->choice.setup->format4)
10346          {
10347             DU_ALLOC_SHRABL_BUF(macPucchCfg->format4, sizeof(PucchFormatCfg));
10348             if(macPucchCfg->format4 == NULLP)
10349             {
10350                DU_LOG("\nERROR --> F1AP : Failed to extract format 4 Cfg in  extractPucchCfg()");
10351                return RFAILED;
10352             }
10353             memset(macPucchCfg->format4, 0, sizeof(PucchFormatCfg));
10354             extractPucchFormatCfg(macPucchCfg->format4,\
10355                cuPucchCfg->choice.setup->format4->choice.setup);
10356          }
10357
10358          /* Sched Req List */
10359          if(cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList)
10360          {
10361             DU_ALLOC_SHRABL_BUF(macPucchCfg->schedReq, sizeof(PucchSchedReqCfg));
10362             if(macPucchCfg->schedReq == NULLP)
10363             {
10364                DU_LOG("\nERROR --> F1AP : Failed to extract schedReqCfg in  extractPucchCfg()");
10365                return RFAILED;
10366             }
10367             memset(macPucchCfg->schedReq, 0, sizeof(PucchSchedReqCfg));
10368             extractSchedReqCfgToAddMod(macPucchCfg->schedReq,\
10369             cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList);
10370          }
10371
10372          /*TODO: Add support for  Spatial Info */
10373
10374          /* MultiCsiCfg */
10375          if(cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList)
10376          {
10377             DU_ALLOC_SHRABL_BUF(macPucchCfg->multiCsiCfg, sizeof(PucchMultiCsiCfg));
10378             if(macPucchCfg->multiCsiCfg == NULLP)
10379             {
10380                DU_LOG("\nERROR --> F1AP : Failed to extract multiCsiCfg in  extractPucchCfg()");
10381                return RFAILED;
10382             }
10383             memset(macPucchCfg->multiCsiCfg, 0, sizeof(PucchMultiCsiCfg));
10384             macPucchCfg->multiCsiCfg->multiCsiResrcListCount = cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.count;
10385             for(arrIdx =0; arrIdx < macPucchCfg->multiCsiCfg->multiCsiResrcListCount; arrIdx++)
10386             {
10387                macPucchCfg->multiCsiCfg->multiCsiResrcList[arrIdx] =\
10388                  *cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.array[arrIdx];
10389             }
10390          }
10391
10392          /* Dl_DataToUL_ACK */ 
10393          if(cuPucchCfg->choice.setup->dl_DataToUL_ACK)
10394     {
10395        if(storedPucchCfg)
10396        {
10397           if(storedPucchCfg->dlDataToUlAck)
10398           {
10399              macPucchCfg->dlDataToUlAck = storedPucchCfg->dlDataToUlAck; 
10400           }
10401           else
10402           {
10403             DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
10404           }
10405        }
10406        else
10407        {
10408           DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
10409        }
10410        if(macPucchCfg->dlDataToUlAck == NULLP)
10411        {
10412           DU_LOG("\nERROR --> F1AP : Failed to extract Dl_DataToUL_ACK in extractPucchCfg()");
10413           return RFAILED;
10414        }
10415        memset(macPucchCfg->dlDataToUlAck, 0, sizeof(PucchDlDataToUlAck));
10416        macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount = cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.count;
10417        for(arrIdx = 0; arrIdx < macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; arrIdx++)
10418        {
10419           macPucchCfg->dlDataToUlAck->dlDataToUlAckList[arrIdx] =\
10420           *cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.array[arrIdx];
10421        }
10422          }
10423
10424          /* Power Control */
10425          if(cuPucchCfg->choice.setup->pucch_PowerControl)
10426          {
10427             DU_ALLOC_SHRABL_BUF(macPucchCfg->powerControl, sizeof(PucchPowerControl));
10428             if(macPucchCfg->powerControl == NULLP)
10429             {
10430                DU_LOG("\nERROR --> F1AP : Failed to extract power control in extractPucchCfg()");
10431                return RFAILED;
10432             }
10433             extractPucchPowerControl(macPucchCfg->powerControl,\
10434                cuPucchCfg->choice.setup->pucch_PowerControl);
10435          }
10436       }
10437    }
10438    return ROK;
10439 }
10440
10441 /*******************************************************************
10442  *
10443  * @brief Fills ServingCellReconfig received by CU
10444  *
10445  * @details
10446  *
10447  *    Function : extractSpCellDedicatedCfg
10448  *
10449  *    Functionality: Fills ServingCellReconfig received  by CU
10450  *
10451  * @params[in] ServingCellConfig_t *cuSrvCellCfg = Information which is send by
10452  *                  CU, which we have stored in F1UeContextSetupDb,
10453  *             ServCellCfgInfo *macSrvCellCfg = Used to Store the information
10454  *                  which  needs to send in other layer, as well as this can be the
10455  *                  variable which stores the information in DuCb, 
10456  *             ServCellCfgInfo *storedSrvCellCfg = Null in case of sending the
10457  *                  information to other layer else it will have ServCellCfgInfo which
10458  *                  we have stored in copyOfmacUeCfg.
10459  * @return ROK/RFAILD
10460  *
10461  * ****************************************************************/
10462 uint8_t extractSpCellDedicatedCfg(ServingCellConfig_t *cuSrvCellCfg, ServCellCfgInfo *macSrvCellCfg,\
10463 ServCellCfgInfo *storedSrvCellCfg)
10464 {
10465    uint8_t ret = ROK;
10466    BWP_DownlinkDedicated_t *dlBwp = NULLP;
10467    BWP_UplinkDedicated_t   *ulBwp = NULLP;
10468
10469    if(cuSrvCellCfg->initialDownlinkBWP)
10470    {
10471       dlBwp = ((BWP_DownlinkDedicated_t *)(cuSrvCellCfg->initialDownlinkBWP));
10472       if(dlBwp->pdcch_Config)
10473       {
10474          if(dlBwp->pdcch_Config->choice.setup)
10475          {
10476             macSrvCellCfg->initDlBwp.pdcchPresent = true;
10477             if(storedSrvCellCfg)
10478             {
10479                if(!storedSrvCellCfg->initDlBwp.pdcchPresent)
10480                {
10481                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
10482                }
10483                else
10484                {
10485                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
10486                }
10487             }
10488             else
10489             {
10490                extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
10491             }
10492          }
10493       }
10494       if(dlBwp->pdsch_Config)
10495       {
10496          if(dlBwp->pdsch_Config->choice.setup)
10497          {
10498             macSrvCellCfg->initDlBwp.pdschPresent = true;
10499             
10500             if(storedSrvCellCfg)
10501             {
10502                if(!storedSrvCellCfg->initDlBwp.pdschPresent)
10503                {
10504                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
10505                }
10506                else
10507                {
10508                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg,\
10509                         &storedSrvCellCfg->initDlBwp.pdschCfg);
10510                }
10511             }
10512             else
10513             {
10514                extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
10515             }
10516          }
10517       }
10518    }
10519    if(cuSrvCellCfg->firstActiveDownlinkBWP_Id)
10520       macSrvCellCfg->firstActvDlBwpId = *(cuSrvCellCfg->firstActiveDownlinkBWP_Id);
10521    if(cuSrvCellCfg->defaultDownlinkBWP_Id)
10522       macSrvCellCfg->defaultDlBwpId = *(cuSrvCellCfg->defaultDownlinkBWP_Id);
10523    if(cuSrvCellCfg->bwp_InactivityTimer)
10524    {
10525       if(macSrvCellCfg->bwpInactivityTmr)
10526       {
10527          memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
10528       }
10529       else
10530       {
10531          macSrvCellCfg->bwpInactivityTmr = NULLP;
10532          DU_ALLOC_SHRABL_BUF(macSrvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
10533          if(macSrvCellCfg->bwpInactivityTmr)
10534          {
10535             memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
10536          }
10537          else
10538          {
10539             DU_LOG("\nERROR  --> F1AP : Memory Alloc failed for bwpInactivityTmr at extractSpCellDedicatedCfg()");
10540             return RFAILED;
10541          }
10542       }
10543    }
10544    if(cuSrvCellCfg->pdsch_ServingCellConfig)
10545    {
10546       if(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup)
10547       {
10548          ret = extractPdschServingCellCfg(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup, &macSrvCellCfg->pdschServCellCfg);
10549          if(ret == RFAILED)
10550          {
10551             DU_LOG("\nERROR --> F1AP : Failed at extractPdschServingCellCfg()");
10552             return RFAILED;
10553          }
10554       }
10555    }
10556    if(cuSrvCellCfg->uplinkConfig)
10557    {
10558       if(cuSrvCellCfg->uplinkConfig->initialUplinkBWP)
10559       {
10560          ulBwp = ((BWP_UplinkDedicated_t *)(cuSrvCellCfg->uplinkConfig->initialUplinkBWP));
10561          if(ulBwp->pusch_Config)
10562          {
10563             macSrvCellCfg->initUlBwp.puschPresent = true;
10564             extractPuschCfg(ulBwp->pusch_Config, &macSrvCellCfg->initUlBwp.puschCfg);
10565          }
10566          if(ulBwp->pucch_Config)
10567          {
10568             macSrvCellCfg->initUlBwp.pucchPresent = true;
10569             memset(&macSrvCellCfg->initUlBwp.pucchCfg, 0, sizeof(PucchCfg));
10570             if(storedSrvCellCfg)
10571             {
10572                if(!storedSrvCellCfg->initUlBwp.pucchPresent)
10573                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
10574                else
10575                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg,\
10576                   &storedSrvCellCfg->initUlBwp.pucchCfg);
10577             }
10578             else
10579             {
10580                extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
10581             }
10582          }
10583       }
10584       if(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id)
10585          macSrvCellCfg->firstActvUlBwpId = *(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id);
10586    }
10587    return ret;
10588 }
10589 /*******************************************************************
10590  *
10591  * @brief Fills Reconfig Cell group Info received by CU
10592  *
10593  * @details
10594  *
10595  *    Function : extractUeReCfgCellInfo
10596  *
10597  *    Functionality: Fills Reconfig Cell group Info received by CU
10598  *   
10599  * @params[in] CellGroupConfigRrc_t *cellGrp = CellGroupConfigRrc_t information which
10600  *                       is send by CU, which we have stored in F1UeContextSetupDb
10601  *             MacUeCfg *MacUeCfg = Used to Store the information,
10602  *                      which needs to send in other layer, as well as this can be
10603  *                      the variable which stores the information in DuCb,
10604  *             MacUeCfg *storedMacUeCfg = Null in case of sending the
10605  *                      information to other layer else it will have copyOfmacUeCfg
10606  *                      which we have stored in F1UeContextSetupDb.
10607  *
10608  * @return ROK/RFAILED
10609  *
10610  * ****************************************************************/
10611 uint8_t extractUeReCfgCellInfo(CellGroupConfigRrc_t *cellGrp, MacUeCfg *macUeCfg, MacUeCfg *storedMacUeCfg)
10612 {
10613    uint8_t ret = ROK;
10614    MAC_CellGroupConfig_t     *macCellGroup = NULLP;
10615    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
10616    SpCellConfig_t            *spcellCfg = NULLP;
10617    ServingCellConfig_t       *servCellCfg = NULLP;
10618
10619    if(cellGrp)
10620    {
10621       /* Fill MacCell Group Reconfig  */
10622       if(cellGrp->mac_CellGroupConfig)
10623       {
10624          macUeCfg->macCellGrpCfgPres = true;
10625          macCellGroup = ((MAC_CellGroupConfig_t *)(cellGrp->mac_CellGroupConfig));
10626          if(macCellGroup->schedulingRequestConfig)
10627          {
10628             extractSchReqReConfig(macCellGroup->schedulingRequestConfig, &macUeCfg->macCellGrpCfg.schReqCfg);
10629          }
10630          if(macCellGroup->tag_Config)
10631          {
10632             extractTagReconfig(macCellGroup->tag_Config, &macUeCfg->macCellGrpCfg.tagCfg);
10633          }
10634          if(macCellGroup->bsr_Config)
10635          {
10636             macUeCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer = macCellGroup->bsr_Config->periodicBSR_Timer;
10637             macUeCfg->macCellGrpCfg.bsrTmrCfg.retxTimer     = macCellGroup->bsr_Config->retxBSR_Timer;
10638             if(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer)
10639             {
10640                macUeCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer  =\
10641                *(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer);
10642             }
10643          }
10644          if(macCellGroup->phr_Config)
10645          {
10646             if(macCellGroup->phr_Config->present == MAC_CellGroupConfig__phr_Config_PR_setup)
10647             {
10648                macUeCfg->macCellGrpCfg.phrCfgSetupPres = true;
10649                if(macCellGroup->phr_Config->choice.setup)
10650                {
10651                   macUeCfg->macCellGrpCfg.phrCfg.periodicTimer     = \
10652                   macCellGroup->phr_Config->choice.setup->phr_PeriodicTimer;
10653                   macUeCfg->macCellGrpCfg.phrCfg.prohibitTimer     = \
10654                   macCellGroup->phr_Config->choice.setup->phr_ProhibitTimer;
10655                   macUeCfg->macCellGrpCfg.phrCfg.txPowerFactor     = \
10656                   macCellGroup->phr_Config->choice.setup->phr_Tx_PowerFactorChange;
10657                   macUeCfg->macCellGrpCfg.phrCfg.multiplePHR       = \
10658                   macCellGroup->phr_Config->choice.setup->multiplePHR;
10659                   macUeCfg->macCellGrpCfg.phrCfg.dummy             = \
10660                   macCellGroup->phr_Config->choice.setup->dummy;
10661                   macUeCfg->macCellGrpCfg.phrCfg.phrType2OtherCell = \
10662                   macCellGroup->phr_Config->choice.setup->phr_Type2OtherCell;
10663                   macUeCfg->macCellGrpCfg.phrCfg.phrOtherCG        = \
10664                   macCellGroup->phr_Config->choice.setup->phr_ModeOtherCG;
10665                }
10666             }
10667          }
10668       }
10669       /* Fill Physical Cell Group Reconfig */
10670       if(cellGrp->physicalCellGroupConfig)
10671       {
10672          macUeCfg->phyCellGrpCfgPres = true;
10673          phyCellGrpCfg = ((PhysicalCellGroupConfig_t *)(cellGrp->physicalCellGroupConfig));
10674          if(phyCellGrpCfg->p_NR_FR1)
10675          {
10676             if(*(phyCellGrpCfg->p_NR_FR1) != macUeCfg->phyCellGrpCfg.pNrFr1)
10677                macUeCfg->phyCellGrpCfg.pNrFr1 = *(phyCellGrpCfg->p_NR_FR1);
10678          }
10679          macUeCfg->phyCellGrpCfg.pdschHarqAckCodebook = phyCellGrpCfg->pdsch_HARQ_ACK_Codebook;
10680       }
10681       /* Fill SpCell Reconfig */
10682       if(cellGrp->spCellConfig)
10683       {
10684          macUeCfg->spCellCfgPres = true;
10685          spcellCfg = ((SpCellConfig_t *)(cellGrp->spCellConfig));  
10686          if(spcellCfg->servCellIndex)
10687          {
10688             macUeCfg->spCellCfg.servCellIdx = *(spcellCfg->servCellIndex);
10689          }
10690          /* Fill Serving cell Reconfig info */
10691          if(cellGrp->spCellConfig->spCellConfigDedicated)
10692          {
10693             servCellCfg = ((ServingCellConfig_t *)(cellGrp->spCellConfig->spCellConfigDedicated));
10694             if(storedMacUeCfg)
10695             {
10696                if(!storedMacUeCfg->spCellCfgPres)
10697                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
10698                else
10699                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg,\
10700                         &storedMacUeCfg->spCellCfg.servCellCfg);
10701             }
10702             else
10703             {
10704                ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
10705             }
10706             if(ret == RFAILED)
10707             {
10708                DU_LOG("\nERROR --> F1AP : Failed at extractSpCellDedicatedCfg()");
10709             }
10710          }
10711       }
10712    }
10713    return ret;
10714 }
10715 /*******************************************************************
10716 *
10717 * @brief free the memory allocated by decoder
10718 *
10719 * @details
10720 *
10721 *    Function : freeAperDecodeNrcgi 
10722 *
10723 *    Functionality: Free Nrcgi values
10724 *
10725 * @params[in] NRCGI_t *nrcgi
10726 * @return void
10727 *
10728 * ****************************************************************/
10729
10730
10731 void freeAperDecodeNrcgi(NRCGI_t *nrcgi)
10732 {
10733     if(nrcgi->pLMN_Identity.buf != NULLP)
10734     {
10735        free(nrcgi->pLMN_Identity.buf);
10736     }
10737     if(nrcgi->nRCellIdentity.buf != NULLP)
10738     {
10739        free(nrcgi->nRCellIdentity.buf);
10740     }
10741 }
10742 /*******************************************************************
10743 *
10744 * @brief free the memory allocated by decoder
10745 *
10746 * @details
10747 *
10748 *    Function : freeAperDecodeCuToDuInfo 
10749 *
10750 *    Functionality:  Free Cu To Du Information
10751 *
10752 * @params[in] CUtoDURRCInformation_t *rrcMsg
10753 * @return void
10754 *
10755 * ****************************************************************/
10756
10757
10758 void freeAperDecodeCuToDuInfo(CUtoDURRCInformation_t *rrcMsg)
10759 {
10760    uint8_t ieIdx =0;
10761    uint8_t arrIdx =0;
10762
10763    if(rrcMsg->uE_CapabilityRAT_ContainerList)
10764    {
10765       if(rrcMsg->uE_CapabilityRAT_ContainerList->buf)
10766          free(rrcMsg->uE_CapabilityRAT_ContainerList->buf);
10767       free(rrcMsg->uE_CapabilityRAT_ContainerList);
10768    }
10769
10770    if(rrcMsg->iE_Extensions)
10771    {
10772       if(rrcMsg->iE_Extensions->list.array)
10773       {
10774          for(ieIdx= 0; ieIdx < rrcMsg->iE_Extensions->list.count; ieIdx++)
10775          {
10776             if(rrcMsg->iE_Extensions->list.array[ieIdx])
10777             {
10778                switch(rrcMsg->iE_Extensions->list.array[ieIdx]->id)
10779                {
10780                   case ProtocolIE_ID_id_CellGroupConfig:
10781                      if(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf != NULLP)
10782                      {
10783                         free(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf);
10784                      }
10785                      break;
10786                   default:
10787                      DU_LOG("\nERROR  -->  F1AP : Invalid Event type %ld at FreeCuToDuInfo()", \
10788                            rrcMsg->iE_Extensions->list.array[ieIdx]->id);
10789                      break;
10790                }
10791             }
10792          }
10793          for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
10794          {
10795             free(rrcMsg->iE_Extensions->list.array[arrIdx]);
10796          }
10797          free(rrcMsg->iE_Extensions->list.array);
10798
10799       }
10800
10801       free(rrcMsg->iE_Extensions);
10802    }
10803 }
10804 /*******************************************************************
10805 *
10806 * @brief free the memory allocated by decoder
10807 *
10808 * @details 
10809 *
10810 *    Function : freeAperDecodeSplCellList
10811 *
10812 *    Functionality: Free Spl Cell List 
10813                     where memory allocated by aper_decoder
10814 *
10815 * @params[in]  SCell_ToBeSetup_List_t *spCellLst
10816 * @return void
10817 *
10818 * ****************************************************************/
10819
10820
10821 void freeAperDecodeSplCellList(SCell_ToBeSetup_List_t *spCellLst)
10822 {
10823     uint8_t  cellIdx =0;
10824
10825     if(spCellLst->list.array != NULLP)
10826     {
10827        for(cellIdx=0; cellIdx<spCellLst->list.count; cellIdx++)
10828        {
10829           if(cellIdx==0&&spCellLst->list.array[cellIdx]!=NULLP)
10830           {
10831              freeAperDecodeNrcgi(&spCellLst->list.array[cellIdx]->value.choice.SCell_ToBeSetup_Item.sCell_ID);
10832           }
10833           if(spCellLst->list.array[cellIdx]!=NULLP)
10834           {
10835              free(spCellLst->list.array[cellIdx]);
10836           }
10837        }
10838        free(spCellLst->list.array);
10839     }
10840 }
10841 /*******************************************************************
10842 *
10843 * @brief free the memory allocated by decoder
10844 *
10845 * @details
10846 *
10847 *    Function : freeAperDecodeSRBSetup 
10848 *
10849 *    Functionality: added free part for the memory allocated by aper_decoder
10850 *
10851 * @params[in] SRBs_ToBeSetup_List_t *srbSet
10852 * @return void
10853 *
10854 ****************************************************************/
10855
10856
10857 void freeAperDecodeSRBSetup(SRBs_ToBeSetup_List_t *srbSet)
10858 {
10859     uint8_t srbIdx =0;
10860     if(srbSet->list.array != NULLP)
10861     {
10862        for(srbIdx=0; srbIdx<srbSet->list.count; srbIdx++)
10863        {
10864           if(srbSet->list.array[srbIdx]!=NULLP)
10865           {
10866              free(srbSet->list.array[srbIdx]);
10867           }
10868        }
10869        free(srbSet->list.array);
10870     }
10871 }
10872
10873 /*******************************************************************
10874 *
10875 * @brief free the memory allocated by decoder
10876 *
10877 * @details
10878 *
10879 *    Function : freeAperDecodeULTnlInfo
10880 *
10881 *    Functionality: added free part for the memory allocated by aper_decoder
10882 *
10883 * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
10884 * @return void
10885 *
10886 * ****************************************************************/
10887
10888
10889 void freeAperDecodeULTnlInfo(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
10890 {
10891    uint8_t ulIdx=0;
10892    if(ulInfo->list.array != NULLP)
10893    {
10894       for(ulIdx=0; ulIdx<ulInfo->list.count; ulIdx++)
10895       {
10896          if(ulIdx==0&&ulInfo->list.array[ulIdx]!=NULLP)
10897          {
10898             if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel!=NULLP)
10899             {
10900                if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
10901                      transportLayerAddress.buf != NULLP)
10902                {
10903                   if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf\
10904                         !=NULLP)
10905                   {
10906                      free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf);
10907                   }
10908                   free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
10909                         transportLayerAddress.buf);
10910                }
10911                free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel);
10912             }
10913          }
10914          if(ulInfo->list.array[ulIdx]!=NULLP)
10915          {
10916             free(ulInfo->list.array[ulIdx]);
10917          }
10918       }
10919       free(ulInfo->list.array);
10920    }
10921 }
10922 /*******************************************************************
10923 *
10924 * @brief free the memory allocated by decoder
10925 *
10926 * @details
10927 *
10928 *    Function : freeAperDecodeDRBSetup  
10929 *
10930 *    Functionality: free DRBSetup which is allocated by decoder
10931 *
10932 * @params[in]  DRBs_ToBeSetup_List_t *drbSet
10933 * @return void
10934 *
10935 * ****************************************************************/
10936
10937 void freeAperDecodeDRBSetup(DRBs_ToBeSetup_List_t *drbSet)
10938 {
10939    DRBs_ToBeSetup_Item_t *drbSetItem = NULLP;
10940    uint8_t  flowIdx =0;
10941    uint8_t  drbIdx =0;
10942
10943    if(drbSet->list.array != NULLP)
10944    {
10945       for(drbIdx=0; drbIdx<drbSet->list.count; drbIdx++)
10946       {
10947          if(drbIdx==0&&drbSet->list.array[drbIdx] != NULLP)
10948          {
10949             drbSetItem =&drbSet->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
10950             if(drbSetItem->qoSInformation.choice.choice_extension != NULLP)
10951             {
10952                if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
10953                      qoS_Characteristics.choice.non_Dynamic_5QI !=NULLP)
10954                {
10955                   if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
10956                         qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
10957                   {
10958                      if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
10959                            qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
10960                      {
10961
10962                         if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf!=NULLP)
10963                         {
10964
10965                            if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD!=NULLP)
10966                            {
10967
10968                               if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD->\
10969                                     buf!=NULLP)
10970                               {
10971
10972                                  if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.\
10973                                        flows_Mapped_To_DRB_List.list.array != NULLP)
10974                                  {
10975
10976                                     for(flowIdx=0;flowIdx<drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
10977                                           DRB_Information.flows_Mapped_To_DRB_List.list.count; flowIdx++)
10978                                     {
10979
10980                                        if(flowIdx==0&&drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
10981                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
10982                                        {
10983                                           if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
10984                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
10985                                                 qoSFlowLevelQoSParameters.\
10986                                                 qoS_Characteristics.choice.non_Dynamic_5QI!=NULLP)
10987                                           {
10988                                              if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
10989                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
10990                                                    qoSFlowLevelQoSParameters.\
10991                                                    qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
10992                                              {
10993
10994                                                 if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
10995                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
10996                                                       qoSFlowLevelQoSParameters.\
10997                                                       qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
10998                                                 {
10999
11000
11001                                                    free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
11002                                                          DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
11003                                                          qoSFlowLevelQoSParameters.\
11004                                                          qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
11005                                                 }
11006
11007                                                 free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
11008                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
11009                                                       qoSFlowLevelQoSParameters.\
11010                                                       qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
11011                                              }
11012
11013                                              free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
11014
11015                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
11016                                                    qoSFlowLevelQoSParameters.\
11017                                                    qoS_Characteristics.choice.non_Dynamic_5QI);
11018                                           }
11019                                        }
11020                                        if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
11021                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
11022                                        {
11023
11024                                           free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
11025                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]);
11026                                        }
11027                                     }
11028
11029                                     free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
11030                                           DRB_Information.flows_Mapped_To_DRB_List.list.array);
11031                                  }
11032
11033                                  free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
11034                                        DRB_Information.sNSSAI.sD->buf);
11035                               }
11036
11037                               free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD);
11038                            }
11039
11040                            free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf);
11041
11042                         }
11043
11044                         free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
11045
11046                               qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
11047                      }
11048
11049                      free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
11050                            qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
11051                   }
11052
11053                   free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
11054                         qoS_Characteristics.choice.non_Dynamic_5QI);
11055                }
11056                free(drbSetItem->qoSInformation.choice.choice_extension);
11057             }
11058             freeAperDecodeULTnlInfo(&drbSetItem->uLUPTNLInformation_ToBeSetup_List);
11059             if(drbSetItem->uLConfiguration)
11060             {
11061                free(drbSetItem->uLConfiguration);
11062             }
11063          }
11064          if(drbSet->list.array[drbIdx]!=NULLP)
11065          {
11066             free(drbSet->list.array[drbIdx]);
11067          }
11068       }
11069       free(drbSet->list.array);
11070    }
11071 }
11072
11073
11074 /*******************************************************************
11075  *
11076  * @brief builds Mac Cell Cfg
11077  *
11078  * @details
11079  *
11080  *    Function : procUeReCfgCellInfo
11081  *
11082  *    Functionality: builds Mac Cell Cfg
11083  *
11084  * @params[in] MacUeCfg *macUeCfgToSend = Used to Store the information which
11085  *                       needs to send in other layer, as well as this can be
11086  *                       the variable which stores the information in DuCb.
11087  *             MacUeCfg *storedMacUeCfg = Null in case of sending the
11088  *                       information to other layer else it will have copyOfmacUeCfg  
11089  *                       which we have stored in F1UeContextSetupDb
11090  *             void *cellInfo = CellGroupConfigRrc_t information which is send
11091  *                        by CU, which we have stored in F1UeContextSetupDb 
11092  *
11093  * @return void 
11094  *
11095  * ****************************************************************/
11096 uint8_t procUeReCfgCellInfo(MacUeCfg *macUeCfgToSend,MacUeCfg *storedMacUeCfg, void *cellInfo)
11097 {
11098    uint8_t ret = ROK;
11099    CellGroupConfigRrc_t *cellGrp = NULLP;
11100
11101    if(cellInfo)
11102    {
11103       cellGrp = (CellGroupConfigRrc_t *)cellInfo;
11104       ret = extractUeReCfgCellInfo(cellGrp, macUeCfgToSend, storedMacUeCfg);
11105       if(ret == RFAILED)
11106          DU_LOG("\nERROR  -->  F1AP : Failed at procUeReCfgCellInfo()");
11107    }
11108    if(ret == RFAILED)
11109    {
11110       freeUeReCfgCellGrpInfo(macUeCfgToSend);
11111    }
11112    return ret;
11113 }
11114
11115 /*******************************************************************
11116  *
11117  * @brief Filling modulation info in mac ue cfg
11118  *
11119  * @details
11120  *
11121  *    Function : duFillModulationDetails
11122  *
11123  *    Functionality: Filling modulation info in mac ue cfg
11124  *
11125  * @params[in] MAC UE Config to be updated
11126  *             Current UE configuration
11127  *             UE NR capability from CU
11128  * @return ROK     - success
11129  *         RFAILED - failure
11130  *
11131  * ****************************************************************/
11132 void duFillModulationDetails(MacUeCfg *ueCfg, MacUeCfg *oldUeCfg, void *ueCap)
11133 {
11134    UE_NR_Capability_t *ueNrCap=NULLP;
11135
11136    if(!ueCap)
11137    {
11138       memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));     
11139       memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
11140    }
11141    else
11142    {
11143       ueNrCap = (UE_NR_Capability_t *)ueCap;
11144
11145       /* Filling DL modulation info */
11146       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsDownlinkPerCC && \
11147          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0] && \
11148          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL)
11149       {
11150          switch(*(ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL))
11151          {
11152             case ModulationOrder_qpsk:
11153                {
11154                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
11155                   break;
11156                }
11157             case ModulationOrder_qam16:
11158                {
11159                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM16;
11160                   break;
11161                }
11162             case ModulationOrder_qam64:
11163                {
11164                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM64;
11165                   ueCfg->dlModInfo.mcsIndex = PDSCH_MCS_INDEX;
11166                   ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64;
11167                   break;
11168                }
11169             case ModulationOrder_qam256:
11170                {
11171                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM256;
11172                   break;
11173                }
11174             default:
11175                {
11176                   DU_LOG("\nERROR  -->  DU APP: Incorrect downlink modulation order received. Reatining old modulation configuration");
11177                   memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
11178                   break;
11179                }
11180          }
11181       }
11182       else
11183       {
11184          memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
11185       }
11186
11187       /* Filling UL modulation info */
11188       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsUplinkPerCC && \
11189          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0] && \
11190          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL)
11191       {
11192          switch(*(ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL))
11193          {
11194             case ModulationOrder_qpsk:
11195                {
11196                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
11197                   break;
11198                }
11199             case ModulationOrder_qam16:
11200                {
11201                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM16;
11202                   ueCfg->ulModInfo.mcsIndex = PUSCH_MCS_INDEX;
11203                   ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64;
11204                   break;
11205                }
11206             case ModulationOrder_qam64:
11207                {
11208                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM64;
11209                   break;
11210                }
11211             case ModulationOrder_qam256:
11212                {
11213                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM256;
11214                   break;
11215                }
11216             default:
11217                {
11218                   DU_LOG("\nERROR  -->  DU APP: Incorrect uplink modulation order received. Reatining old modulation configuration");
11219                   memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
11220                   break;
11221                }
11222          }
11223       }
11224       else
11225       {
11226          memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
11227       }
11228    }
11229 }
11230
11231 /*******************************************************************
11232  *
11233  * @brief Function to extract cellGrp Info present in cutoDu cont
11234  *
11235  * @details
11236  *
11237  *    Function : extractCellGrpInfo
11238  *
11239  *    Functionality: Function to extract cellGrp Info present
11240  *                   in cutoDu cont
11241  *
11242  * @params[in] ProtocolExtensionContainer_4624P16_t pointer
11243  *
11244  * @return CellGroupConfigRrc_t *
11245  *
11246  * ****************************************************************/
11247
11248 CellGroupConfigRrc_t *extractCellGrpInfo(ProtocolExtensionContainer_4624P16_t *protocolIeExtn,\
11249       DuUeCfg *ueCfgDb)
11250 {
11251    uint8_t idx2 =0;
11252    uint16_t id =0;
11253    uint16_t recvBufLen =0;
11254    CellGroupConfigRrc_t *cellGrpCfg = NULLP;
11255    CUtoDURRCInformation_ExtIEs_t *extIeInfo = NULLP;
11256    asn_dec_rval_t rval; /* Decoder return value */
11257    memset(&rval, 0, sizeof(asn_dec_rval_t));
11258
11259    if(protocolIeExtn)
11260    {
11261       for(idx2 = 0; idx2 < protocolIeExtn->list.count; idx2++)
11262       {
11263          extIeInfo = ((CUtoDURRCInformation_ExtIEs_t *)(protocolIeExtn->list.array[idx2]));
11264          id = extIeInfo->id;
11265          switch(id)
11266          {
11267             case ProtocolIE_ID_id_CellGroupConfig:
11268             {
11269                recvBufLen = extIeInfo->extensionValue.choice.CellGroupConfig.size;
11270                /* decoding the CellGroup Buf received */
11271                DU_ALLOC(cellGrpCfg, sizeof(CellGroupConfigRrc_t));
11272                if(cellGrpCfg)
11273                {
11274                   memset(cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
11275                   rval = aper_decode(0, &asn_DEF_CellGroupConfigRrc, (void **)&cellGrpCfg,
11276                      extIeInfo->extensionValue.choice.CellGroupConfig.buf, recvBufLen, 0, 0);
11277                   if(rval.code == RC_FAIL || rval.code == RC_WMORE)
11278                   {
11279                      DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
11280                      return NULLP;
11281                   }
11282                   xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, cellGrpCfg);
11283                   if(extractRlcCfgToAddMod(cellGrpCfg->rlc_BearerToAddModList, ueCfgDb))
11284                      return NULLP;
11285                }
11286                break;
11287             }
11288             default:
11289                DU_LOG("\nERROR  -->  F1AP : Invalid IE received CUtoDURRCInformation:%d at decodeCellGrpCfg()", id);
11290                break;
11291          }
11292       }
11293    }
11294    return cellGrpCfg;
11295 }
11296
11297 /*******************************************************************
11298  *
11299  * @brief Fills Srb List received by CU
11300  *
11301  * @details
11302  *
11303  *    Function : procSrbListToSetup
11304  *
11305  *    Functionality: Fills Srb List received  by CU
11306  *
11307  * @params[in] SRBs_ToBeSetup_Item_t *cuSrbItem
11308  *             LcCfg pointer
11309  *             RlcBearerCfg pointer
11310  * @return void
11311  *
11312  * ****************************************************************/
11313 uint8_t procSrbListToSetup(SRBs_ToBeSetup_Item_t * srbItem, LcCfg *macLcToAdd, RlcBearerCfg *rlcLcToAdd)
11314 {
11315
11316    /* Filling RLC INFO */
11317    procRlcLcCfg(srbItem->sRBID, srbItem->sRBID, RB_TYPE_SRB, RLC_AM, CONFIG_ADD, NULL, rlcLcToAdd, NULL);
11318
11319    /* Filling MAC INFO */
11320    if(procMacLcCfg(srbItem->sRBID, RB_TYPE_SRB, CONFIG_ADD, NULL,NULL, NULL, NULL, macLcToAdd, NULL)  != ROK)
11321    { 
11322       DU_LOG("\nERROR  -->  F1AP : Failed at MAC LC Cfg in procSrbListToSetup()");
11323       return RFAILED;
11324    }
11325
11326    return ROK;
11327 }
11328
11329
11330
11331 /*******************************************************************
11332  *
11333  * @brief extract Srb List received by CU
11334  *
11335  * @details
11336  *
11337  *    Function : extractSrbListToSetup
11338  *
11339  *    Functionality: extract Srb List received by CU
11340  *                   for both MAC and RLC
11341  *
11342  * @params[in] SRBs_ToBeSetup_Item_t pointer
11343  *             DuUeCfg pointer
11344  * @return ROK/RFAIED
11345  *
11346  * ****************************************************************/
11347
11348 uint8_t extractSrbListToSetup(SRBs_ToBeSetup_List_t *srbCfg, DuUeCfg *ueCfgDb)
11349 {
11350    uint8_t ret, srbIdx;
11351    SRBs_ToBeSetup_Item_t *srbItem = NULLP;
11352
11353    if(srbCfg)
11354    {
11355       for(srbIdx = 0; srbIdx < srbCfg->list.count; srbIdx++)
11356       {
11357          srbItem = &srbCfg->list.array[srbIdx]->value.choice.SRBs_ToBeSetup_Item;
11358          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
11359          { 
11360             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in MAC");
11361             ret = RFAILED;
11362             break;
11363          }
11364          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
11365          {
11366             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in RLC");
11367             ret = RFAILED;
11368             break;
11369          }
11370          memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(LcCfg));
11371          memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
11372          ret = procSrbListToSetup(srbItem, &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs],\
11373             &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs]);
11374          ueCfgDb->numRlcLcs++;
11375          ueCfgDb->numMacLcs++;
11376          DU_LOG("\nDEBUG --> DUAPP: extractSrbListToSetup: SRBID: %d [RLC,MAC,NumDrb]:[%x,%x,%x]",\
11377                             srbItem->sRBID, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
11378          if(ret == RFAILED)
11379          {
11380             DU_LOG("\nERROR  -->  F1AP:  Failed at extractSrbListToSetup()");
11381             break;
11382          }
11383       }
11384    }
11385    else
11386       ret = RFAILED;
11387
11388    return ret;
11389 }
11390
11391 /*******************************************************************
11392  *
11393  * @brief Fills Drb List received by CU
11394  *
11395  * @details
11396  *
11397  *    Function : procDrbListToSetupMod
11398  *
11399  *    Functionality: Fills Drb List received by CU
11400  *                   for both MAC and RLC
11401  *
11402  * @params[in] DRBs_ToBeSetup_Item_t , DRBs_ToBeSetupMod_Item_t,
11403  *             DRBs_ToBeModified_Item_t , lcId, LcCfg pointer,
11404  *             RlcBearerCfg , UpTnlCfg, RlcUeCfg
11405  * @return void
11406  *
11407  * ****************************************************************/
11408
11409 uint8_t procDrbListToSetupMod(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbItem,\
11410 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LcCfg *macLcToAdd, RlcBearerCfg *rlcLcToAdd, UpTnlCfg *upTnlInfo, RlcUeCfg *storedRlcUeCfg)
11411 {
11412    uint8_t cfgIdx = 0;
11413    RlcMode rlcModeInfo;
11414
11415    if(drbItem != NULLP)
11416    {
11417       /* Filling RLC INFO */
11418       procRlcLcCfg(drbItem->dRBID, lcId, RB_TYPE_DRB, drbItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, &drbItem->\
11419       qoSInformation);
11420
11421       /* Filling MAC INFO */
11422       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, drbItem, NULL, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
11423       { 
11424          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
11425          return RFAILED;
11426       }
11427    }
11428    else if(drbSetupModItem != NULLP)
11429    {
11430       procRlcLcCfg(drbSetupModItem->dRBID, lcId, RB_TYPE_DRB, drbSetupModItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, 
11431       &drbSetupModItem->qoSInformation);
11432
11433       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, NULL, drbSetupModItem, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
11434       {
11435          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
11436          return RFAILED;
11437       }
11438    }
11439    else if(drbModItem != NULLP)
11440    {
11441       /* Drb to Mod IEs doesnot have rlcMode to be modified
11442        * in ASN. Hence no change in RLC configurations */
11443       if(storedRlcUeCfg != NULLP)
11444       {
11445          for(cfgIdx = 0; cfgIdx < storedRlcUeCfg->numLcs; cfgIdx++)
11446          {
11447             if(storedRlcUeCfg->rlcLcCfg[cfgIdx].lcId == lcId)
11448             {
11449                rlcModeInfo = storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcMode;
11450                break;
11451             }
11452          }
11453       }
11454
11455       procRlcLcCfg(drbModItem->dRBID, lcId, RB_TYPE_DRB, rlcModeInfo, CONFIG_MOD, NULL, rlcLcToAdd, drbModItem->qoSInformation);
11456       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_MOD, NULL, NULL, drbModItem, NULL, macLcToAdd, upTnlInfo) != ROK)
11457       {
11458          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
11459          return RFAILED;
11460       }
11461    }
11462    return ROK;
11463 }
11464
11465 /*******************************************************************
11466  *
11467  * @brief extract Drb List received by CU
11468  *
11469  * @details
11470  *
11471  *    Function : extractDrbListToSetupMod
11472  *
11473  *    Functionality: extract Drb List received by CU
11474  *                   for both MAC and RLC
11475  *
11476  * @params[in] DRBs_ToBeSetup_Item_t pointer
11477  *             DuUeCfg pointer
11478  * @return ROK/RFAIED
11479  *
11480  * ****************************************************************/
11481
11482 uint8_t extractDrbListToSetupMod(DRBs_ToBeSetup_List_t *drbCfg, DRBs_ToBeSetupMod_List_t *drbSetupModCfg,\
11483  DRBs_ToBeModified_List_t *drbModCfg, uint8_t drbCount, DuUeCfg *ueCfgDb, uint32_t *drbBitMap, RlcUeCfg *rlcUeCfg)
11484 {
11485    uint8_t ret, drbIdx = 0, lcId = 0;
11486    DRBs_ToBeSetup_Item_t *drbItem = NULLP;
11487    DRBs_ToBeSetupMod_ItemIEs_t *drbSetupModItem = NULLP;
11488    DRBs_ToBeModified_ItemIEs_t *drbModItem = NULLP;
11489
11490    ret = ROK;
11491    if(drbCount > 0)
11492    {
11493       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
11494       {
11495          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
11496          { 
11497             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in MAC at extractDrbListToSetupMod()");
11498             ret = RFAILED;
11499             break;
11500          }
11501          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
11502          {
11503             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in RLC at extractDrbListToSetupMod()");
11504             ret = RFAILED;
11505             break;
11506          }
11507          memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(LcCfg));
11508          memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
11509
11510          if(drbModCfg != NULLP)
11511          {
11512             drbModItem = (DRBs_ToBeModified_ItemIEs_t *) drbModCfg->list.array[drbIdx];
11513             lcId = fetchLcId(drbModItem->value.choice.DRBs_ToBeModified_Item.dRBID);
11514             if(lcId < MIN_DRB_LCID)
11515             {
11516                DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToSetupMod() for Modified List", lcId);
11517                break;
11518             } 
11519             ret = procDrbListToSetupMod(lcId, NULL, NULL, &(drbModItem->value.choice.DRBs_ToBeModified_Item),\
11520             &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs],\
11521             &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
11522             if(ret == RFAILED)
11523             {
11524                DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for Modified List");
11525                break;
11526             }
11527
11528          }
11529          else
11530          {
11531             lcId = getDrbLcId(drbBitMap);
11532             if(lcId == RFAILED)
11533             {
11534                DU_LOG("\nERROR  -->  F1AP :  InCorrect LCID extractDrbListToSetupMod()");
11535                ret = RFAILED;
11536                break;
11537             }
11538             if(drbCfg != NULL)
11539             {
11540                drbItem = &drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
11541                ret = procDrbListToSetupMod(lcId, drbItem, NULL, NULL, &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs],\
11542                      &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
11543                if(ret == RFAILED)
11544                {
11545                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetup List");
11546                   break;
11547                }
11548             }
11549             else if(drbSetupModCfg != NULL)
11550             {
11551                drbSetupModItem = (DRBs_ToBeSetupMod_ItemIEs_t *) drbSetupModCfg->list.array[drbIdx];
11552                ret = procDrbListToSetupMod(lcId, NULL, &(drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item), NULL,\
11553                      &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs],\
11554                      &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
11555                if(ret == RFAILED)
11556                {
11557                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetupMod List");
11558                   break;
11559                }
11560                ueCfgDb->numDrbSetupMod++;
11561             }
11562          }
11563          ueCfgDb->numRlcLcs++;
11564          ueCfgDb->numMacLcs++;
11565          ueCfgDb->numDrb++;
11566  
11567          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToSetupMod:lcId:%x ,BitMap:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
11568                             lcId,*drbBitMap, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
11569          if(ret == RFAILED)
11570          {
11571             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod()");
11572             break;
11573          }
11574       }
11575    }
11576    else
11577       ret = RFAILED;
11578
11579    return ret;
11580 }
11581
11582 /*******************************************************************
11583  *
11584  * @brief Function to extract Dl RRC Msg received from CU
11585  *
11586  * @details
11587  *
11588  *    Function : extractDlRrcMsg
11589  *
11590  *    Functionality: Function to extract Dl RRC Msg received from CU
11591  *
11592  * @params[in] F1AP message
11593  * @return ROK     - success
11594  *         RFAILED - failure
11595  *
11596  * ****************************************************************/
11597
11598 uint8_t extractDlRrcMsg(uint32_t gnbDuUeF1apId, uint32_t gnbCuUeF1apId, \
11599    F1DlRrcMsg *dlRrcMsg, RRCContainer_t *rrcContainer)
11600 {
11601    uint8_t ret = ROK;
11602    dlRrcMsg->rrcMsgSize = rrcContainer->size;
11603    if(dlRrcMsg->rrcMsgSize > 0)
11604    {
11605       DU_ALLOC_SHRABL_BUF(dlRrcMsg->rrcMsgPdu, dlRrcMsg->rrcMsgSize);
11606       if(!dlRrcMsg->rrcMsgPdu)
11607       {
11608          DU_LOG("\nERROR  --> DU APP : Memory allocation failed for RRC Msg in extractDlRrcMsg()");
11609          ret = RFAILED;
11610       }
11611       else
11612       {
11613          dlRrcMsg->gnbDuUeF1apId = gnbDuUeF1apId;
11614          dlRrcMsg->gnbCuUeF1apId = gnbCuUeF1apId;
11615          dlRrcMsg->srbId = SRB1_LCID;
11616          memcpy(dlRrcMsg->rrcMsgPdu, rrcContainer->buf, dlRrcMsg->rrcMsgSize);
11617       }
11618    }
11619    return ret;
11620 }
11621
11622 /*******************************************************************
11623  *
11624  * @brief Extract UE capability info 
11625  *
11626  * @details
11627  *
11628  *    Function : extractUeCapability
11629  *
11630  *    Functionality: Extract UE capability info and stores in ue Cb
11631  *
11632  * @params[in] Octet string of UE capability RAT container list
11633  * @return ROK     - success
11634  *         RFAILED - failure
11635  *
11636  * ****************************************************************/
11637 UE_NR_Capability_t *extractUeCapability(UE_CapabilityRAT_ContainerList_t *ueCapablityListBuf, DuUeCb *ueCb)
11638 {
11639    uint8_t  idx;
11640    uint16_t recvBufLen;
11641    asn_dec_rval_t rval;
11642    UE_NR_Capability_t  *ueNrCap = NULLP;
11643    UE_CapabilityRAT_ContainerListRRC_t  *ueCapRatContList = NULLP;
11644
11645    /* Decoding UE Capability RAT Container List */
11646    recvBufLen = ueCapablityListBuf->size;
11647    DU_ALLOC(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
11648    if(!ueCapRatContList)
11649    {
11650       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
11651       return NULLP;
11652    }
11653    memset(ueCapRatContList, 0, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
11654    memset(&rval, 0, sizeof(asn_dec_rval_t));
11655    rval = aper_decode(0, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, (void **)&ueCapRatContList,
11656           ueCapablityListBuf->buf, recvBufLen, 0, 0);
11657    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
11658    {
11659       DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
11660       return NULLP;
11661    }
11662    xer_fprint(stdout, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, ueCapRatContList);
11663
11664    /* Free encoded buffer after decoding */
11665
11666    for(idx = 0; idx < ueCapRatContList->list.count; idx++)
11667    {
11668       if(ueCapRatContList->list.array[idx]->rat_Type == RAT_Type_nr)
11669       {
11670          /* Decoding UE NR Capability */
11671           recvBufLen = ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.size;
11672           DU_ALLOC(ueNrCap, sizeof(UE_NR_Capability_t));
11673           if(!ueNrCap)
11674           {
11675              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
11676              DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
11677              return NULLP;
11678           } 
11679           memset(ueNrCap, 0, sizeof(UE_NR_Capability_t));
11680           memset(&rval, 0, sizeof(asn_dec_rval_t));
11681           rval = aper_decode(0, &asn_DEF_UE_NR_Capability, (void **)&ueNrCap,
11682                  ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf, recvBufLen, 0, 0);
11683           if(rval.code == RC_FAIL || rval.code == RC_WMORE)
11684           {
11685              DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
11686              return NULLP;
11687           }
11688           xer_fprint(stdout, &asn_DEF_UE_NR_Capability, ueNrCap);
11689           
11690           /* Free encoded buffer after decoding */
11691           free(ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf);
11692       }
11693       free(ueCapRatContList->list.array[idx]);
11694    }
11695
11696    /* Free Memory*/
11697    free(ueCapRatContList->list.array);
11698    DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
11699    return ueNrCap;
11700 }
11701  
11702 /*******************************************************************
11703 *
11704 * @brief free UE context setup request from CU
11705 *
11706 * @details
11707 *
11708 *    Function : freeAperDecodeF1UeContextSetupReq
11709 *
11710 *    Functionality: freeing part for the memory allocated by aper_decoder
11711 *
11712 * @params[in] F1AP message
11713 * @return ROK     - success
11714 *         RFAILED - failure
11715 *
11716 * ****************************************************************/
11717 void freeAperDecodeF1UeContextSetupReq(UEContextSetupRequest_t   *ueSetReq)
11718 {
11719    uint8_t ieIdx = 0;
11720
11721    if(ueSetReq->protocolIEs.list.array != NULLP)
11722    {
11723       for(ieIdx = 0; ieIdx < ueSetReq->protocolIEs.list.count; ieIdx++)
11724       {
11725          if(ueSetReq->protocolIEs.list.array[ieIdx])
11726          {
11727             switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
11728             {
11729                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
11730                   break;
11731                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
11732                   break;
11733                case ProtocolIE_ID_id_SpCell_ID:
11734                   freeAperDecodeNrcgi(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
11735                   break;
11736                case ProtocolIE_ID_id_ServCellIndex:
11737                   break;
11738                case ProtocolIE_ID_id_SpCellULConfigured:
11739                   break;
11740                case ProtocolIE_ID_id_CUtoDURRCInformation:
11741
11742                   freeAperDecodeCuToDuInfo(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation);
11743                   break;
11744                case ProtocolIE_ID_id_SCell_ToBeSetup_List:
11745
11746                   freeAperDecodeSplCellList(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SCell_ToBeSetup_List);
11747                   break;
11748                case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
11749
11750                   freeAperDecodeSRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List);
11751                   break;
11752                case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
11753
11754                   freeAperDecodeDRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List);
11755                   break;
11756                case ProtocolIE_ID_id_RRCContainer:
11757                   {
11758
11759                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf != NULLP)
11760                      {
11761
11762                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
11763                      }
11764                      break;
11765                   }
11766                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
11767                   break;
11768                case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
11769                   {
11770                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf)
11771                      {
11772                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf);
11773                      }
11774                      break;
11775                   }
11776                default:
11777                   DU_LOG("\nERROR  -->  F1AP: Invalid event type %ld " ,ueSetReq->protocolIEs.list.array[ieIdx]->id);
11778             } 
11779             free(ueSetReq->protocolIEs.list.array[ieIdx]);
11780          }
11781       }
11782       free(ueSetReq->protocolIEs.list.array);
11783    }
11784 }
11785 /*******************************************************************
11786  *
11787  * @brief Process UE context setup request from CU
11788  *
11789  * @details
11790  *
11791  *    Function : procF1UeContextSetupReq
11792  *
11793  *    Functionality: Process UE context setup request from CU
11794  *
11795  * @params[in] F1AP message
11796  * @return ROK     - success
11797  *         RFAILED - failure
11798  *
11799  * ****************************************************************/
11800 uint8_t procF1UeContextSetupReq(F1AP_PDU_t *f1apMsg)
11801 {
11802    uint8_t  ret=0, ieIdx=0, ueIdx=0, cellIdx=0, servCellIdx = 0;
11803    bool ueCbFound = false;
11804    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0, bitRateSize=0;
11805    DuUeCb   *duUeCb = NULL;
11806    UEContextSetupRequest_t   *ueSetReq = NULL;
11807    DRBs_ToBeSetup_List_t *drbCfg = NULL;
11808
11809    ret = ROK;
11810
11811    ueSetReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextSetupRequest;
11812    for(ieIdx=0; (ieIdx < ueSetReq->protocolIEs.list.count && ret == ROK); ieIdx++)
11813    {
11814       switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
11815       {
11816          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
11817             {
11818                gnbCuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
11819                break;
11820             }
11821          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
11822             {
11823                gnbDuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
11824                break;
11825             }
11826          case ProtocolIE_ID_id_ServCellIndex:
11827             {
11828                servCellIdx = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.ServCellIndex;
11829                for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
11830                {
11831                   for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
11832                   {
11833                      if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
11834                            (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId))
11835                      {
11836                         ueCbFound = true;
11837                         duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
11838                         DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
11839                         if(duUeCb->f1UeDb)
11840                         {
11841                            memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
11842                            duUeCb->f1UeDb->actionType = UE_CTXT_SETUP;
11843                            duUeCb->f1UeDb->cellIdx = cellIdx;
11844                         }
11845                         else
11846                         {
11847                            DU_LOG("\nERROR  -->  F1AP: Memory Alloc Failed at procF1UeContextSetupReq()");
11848                            ret = RFAILED;
11849                         }
11850                         break;
11851                      }
11852                      else
11853                         ueCbFound = false;
11854
11855                   }
11856                   if(ueCbFound)
11857                      break;
11858                }
11859                if(!ueCbFound)
11860                {
11861                   DU_LOG("\nERROR  -->  F1AP: DuUeCb is not found at procF1UeContextSetupReq()");
11862                   ret = RFAILED;
11863                }
11864                break;
11865             }
11866          case ProtocolIE_ID_id_SpCellULConfigured:
11867             /* Indicates whether the gNB-CU requests the gNB-DU to configure the uplink as no UL, 
11868                UL, SUL or UL+SUL for the indicated cell for the UE */
11869             break;
11870          case ProtocolIE_ID_id_CUtoDURRCInformation:
11871             {
11872                if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation.uE_CapabilityRAT_ContainerList)
11873                {
11874                   duUeCb->f1UeDb->duUeCfg.ueNrCapability = \
11875                   extractUeCapability(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation.\
11876                   uE_CapabilityRAT_ContainerList, duUeCb);
11877                }
11878                if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation.iE_Extensions)
11879                {
11880                   duUeCb->f1UeDb->duUeCfg.cellGrpCfg = extractCellGrpInfo(ueSetReq->protocolIEs.list.array[ieIdx]->\
11881                         value.choice.CUtoDURRCInformation.iE_Extensions, &duUeCb->f1UeDb->duUeCfg);
11882                   if(!duUeCb->f1UeDb->duUeCfg.cellGrpCfg)
11883                   {
11884                      DU_LOG("\nERROR  -->  F1AP: Failed to extract cell Grp Info");
11885                      //TODO: Update the failure cause in ue context Setup Response
11886                      ret = RFAILED;
11887                   }
11888                }
11889                break;
11890             } 
11891          case ProtocolIE_ID_id_SCell_ToBeSetup_List:
11892             {
11893                DU_LOG("\nINFO   -->  DU_APP: Received SCell_ToBeSetup_List but  Not processing the list");
11894                break;
11895             }
11896          case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
11897             {
11898                if(extractSrbListToSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List,\
11899                &duUeCb->f1UeDb->duUeCfg))
11900                {
11901                   DU_LOG("\nERROR  -->  DU APP : Failed at extractSrbListToSetup()");
11902                   //TODO: Update the failure cause in ue context Setup Response
11903                   ret = RFAILED;
11904                }
11905                break;
11906             }
11907          case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
11908             {
11909                   drbCfg = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List;
11910
11911                   if(extractDrbListToSetupMod(drbCfg, NULL, NULL, drbCfg->list.count, &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULLP))
11912                   {
11913                      DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod()");
11914                      //TODO: Update the failure cause in ue context Setup Response
11915                      ret = RFAILED;
11916                   }
11917                break;
11918             }
11919          case ProtocolIE_ID_id_RRCContainer:
11920             {
11921                /* Filling Dl RRC Msg Info */
11922                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
11923                if(!duUeCb->f1UeDb->dlRrcMsg)
11924                {
11925                   DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for DL RRC Msg in procUeCtxtSetupReq()");
11926                   ret = RFAILED;
11927                }
11928                else
11929                {
11930                   duUeCb->f1UeDb->dlRrcMsgPres = true;
11931                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
11932                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
11933                         &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer);
11934                }          
11935                break;
11936             }
11937          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
11938             {
11939                if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
11940                {
11941                   duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
11942                }
11943                else
11944                {
11945                   DU_LOG("\nERROR  -->  Ignoring delivery report, since rrcContainer is not present");
11946                }
11947                break;
11948             }
11949          case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
11950             {
11951                /* MaximumBitRate Uplink */
11952                bitRateSize = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.size;
11953                if(bitRateSize > 0)
11954                {
11955                   DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->duUeCfg.ambrCfg, bitRateSize);
11956                   if(!duUeCb->f1UeDb->duUeCfg.ambrCfg)
11957                   {
11958                      DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for bitRate in procUeCtxtSetupReq");
11959                      ret = RFAILED;
11960                   }
11961                   else
11962                   {
11963                      memset(duUeCb->f1UeDb->duUeCfg.ambrCfg, 0, sizeof(AmbrCfg)); 
11964                      memcpy(&duUeCb->f1UeDb->duUeCfg.ambrCfg->ulBr,
11965                            ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf, bitRateSize);
11966                   }
11967                }
11968                else
11969                   ret = RFAILED;
11970                break;
11971             }
11972          default:
11973             {
11974                break;
11975             }
11976       }
11977    }
11978    if(ret == RFAILED)
11979    {
11980       /*TODO : Negative case*/
11981       // BuildAndSendUeContextSetupRsp(cellId,ueId);
11982       DU_LOG("\nERROR  -->  F1AP: Failed to process UE CNTXT SETUP REQ at procF1UeContextSetupReq()"); 
11983    }
11984    else
11985       ret = duProcUeContextSetupRequest(duUeCb);
11986
11987    freeAperDecodeF1UeContextSetupReq(ueSetReq); 
11988    return ret;
11989
11990 }
11991 /*******************************************************************
11992  * @brief Free the memory allocated for Dl Tunnel Info
11993  *
11994  * @details
11995  *
11996  *    Function : freeDlTnlInfo
11997  *
11998  *    Functionality:
11999  *       Free the memory allocated for Dl Tunnel Info
12000  *
12001  * @params[in] DLUPTNLInformation_ToBeSetup_List_t *
12002  * @return void
12003  *
12004  * ****************************************************************/
12005
12006 void freeDlTnlInfo(DLUPTNLInformation_ToBeSetup_List_t *tnlInfo)
12007 {
12008    uint8_t arrIdx = 0;
12009
12010    if(tnlInfo)
12011    {
12012       for(arrIdx=0; arrIdx < tnlInfo->list.count; arrIdx++)
12013       {
12014          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf,\
12015                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.size);
12016          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf,\
12017                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.size);
12018          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
12019          DU_FREE(tnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
12020       }
12021       DU_FREE(tnlInfo->list.array, tnlInfo->list.size);
12022    }
12023 }
12024
12025 /*******************************************************************
12026  * @brief Free the memory allocated for DRB setup List
12027  *
12028  * @details
12029  *
12030  *    Function : freeDrbSetupList
12031  *
12032  *    Functionality:
12033  *       Free the memory allocated for DRB setup list
12034  *
12035  * @params[in] DRBs_Setup_List_t *
12036  * @return void
12037  *
12038  * ****************************************************************/
12039 void freeDrbSetupList(DRBs_Setup_List_t *drbSetupList)
12040 {
12041    uint8_t arrIdx = 0;
12042    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
12043
12044    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
12045    {
12046       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
12047       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List);
12048       DU_FREE(drbSetupList->list.array[arrIdx],  sizeof(DRBs_Setup_Item_t));
12049    }
12050    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
12051 }
12052
12053 /*******************************************************************
12054  * @brief Free the memory allocated for UE Setup response
12055  *
12056  * @details
12057  *
12058  *    Function : FreeUeContextSetupRsp
12059  *
12060  *    Functionality:
12061  *       Free the memory allocated for UE Setup response
12062  *
12063  * @params[in] F1AP PDU for UE setup response
12064  * @return ROK     - success
12065  *         RFAILED - failure
12066  *
12067  * ****************************************************************/
12068 void FreeUeContextSetupRsp(F1AP_PDU_t *f1apMsg)
12069 {
12070    uint8_t idx;
12071    UEContextSetupResponse_t *ueSetRsp = NULLP;
12072
12073    if(f1apMsg)
12074    {
12075       if(f1apMsg->choice.successfulOutcome)
12076       {
12077          ueSetRsp = &f1apMsg->choice.successfulOutcome->value.choice.\
12078                     UEContextSetupResponse;
12079          if(ueSetRsp->protocolIEs.list.array)
12080          {
12081             for(idx = 0; idx < ueSetRsp->protocolIEs.list.count; idx++)
12082             {
12083                if(ueSetRsp->protocolIEs.list.array[idx])
12084                {
12085                   switch(ueSetRsp->protocolIEs.list.array[idx]->id)
12086                   {
12087                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
12088                         break;
12089                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
12090                         break;
12091                      case ProtocolIE_ID_id_DUtoCURRCInformation:
12092                         {
12093                            CellGroupConfig_t *cellGrpCfg = NULLP;
12094                            cellGrpCfg  = &ueSetRsp->protocolIEs.list.array[idx]->value.choice.\
12095                                          DUtoCURRCInformation.cellGroupConfig;
12096                            if(cellGrpCfg->buf != NULLP)
12097                            {
12098                               DU_FREE(cellGrpCfg->buf, cellGrpCfg->size);
12099                               cellGrpCfg = NULLP;
12100                            }
12101                            break;
12102                         }
12103                     case ProtocolIE_ID_id_DRBs_Setup_List:
12104                         {
12105                            freeDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List); 
12106                            break;
12107                         }
12108                      default:
12109                         DU_LOG("\nERROR  -->  DUAPP: Invalid Id %ld at FreeUeContextSetupRsp()",\
12110                         ueSetRsp->protocolIEs.list.array[idx]->id);
12111                         break;
12112                   }
12113                   DU_FREE(ueSetRsp->protocolIEs.list.array[idx],\
12114                         sizeof(UEContextSetupResponseIEs_t));
12115                }
12116             }
12117             DU_FREE(ueSetRsp->protocolIEs.list.array, \
12118                   ueSetRsp->protocolIEs.list.size);
12119          }
12120          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
12121       }
12122       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
12123    }
12124 }
12125
12126 /*******************************************************************
12127  *
12128  * @brief Builds Ue context Setup Rsp DU To CU Info
12129  *
12130  * @details
12131  *
12132  *    Function : EncodeUeCntxtDuToCuInfo
12133  *
12134  *    Functionality: Builds Ue context Setup Rsp DU To CU Info
12135  *
12136  * @params[in] CellGroupConfig_t *, CellGroupConfigRrc_t * 
12137  *
12138  * @return ROK     - success
12139  *         RFAILED - failure
12140  *
12141  ******************************************************************/
12142
12143 uint8_t EncodeUeCntxtDuToCuInfo(CellGroupConfig_t *duToCuCellGrp, CellGroupConfigRrc_t *duCellGrpCfg)
12144 {
12145    asn_enc_rval_t        encRetVal;
12146
12147    xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, duCellGrpCfg);
12148    memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
12149    encBufSize = 0;
12150    encRetVal = aper_encode(&asn_DEF_CellGroupConfigRrc, 0, duCellGrpCfg, PrepFinalEncBuf, encBuf);
12151    /* Encode results */
12152    if(encRetVal.encoded == ENCODE_FAIL)
12153    {
12154       DU_LOG( "\nERROR  -->  F1AP : Could not encode UeCntxtDuToCuInfo (at %s)\n",\
12155             encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
12156       return RFAILED;
12157    }
12158    else
12159    {
12160       DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UeCntxtDuToCuInfo\n");
12161       for(int i=0; i< encBufSize; i++)
12162       {
12163          printf("%x",encBuf[i]);
12164       }
12165    }
12166    duToCuCellGrp->size = encBufSize;
12167    DU_ALLOC(duToCuCellGrp->buf, duToCuCellGrp->size);
12168    if(!duToCuCellGrp->buf)
12169    {
12170       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in UeCntxtDuToCuInfo");
12171    }
12172    memcpy(duToCuCellGrp->buf, encBuf, duToCuCellGrp->size);
12173    return ROK;
12174 }
12175
12176 /*******************************************************************
12177  *
12178  * @brief Fills Dl Gtp tunnel Info
12179  *
12180  * @details
12181  *
12182  *    Function : fillGtpTunnelforDl
12183  *
12184  *    Functionality: Fills Dl Gtp tunnel Info
12185  *
12186  * @params[in] 
12187  *
12188  * @return ROK     - success
12189  *         RFAILED - failure
12190  *
12191  * ****************************************************************/
12192
12193 uint8_t fillGtpTunnelforDl(GTPTunnel_t *gtpDl, GtpTnlCfg *gtpUeCfg)
12194 {
12195    uint8_t bufSize = 0;
12196
12197    gtpDl->transportLayerAddress.size    = 4*sizeof(uint8_t);
12198    DU_ALLOC(gtpDl->transportLayerAddress.buf, gtpDl->transportLayerAddress.size);
12199    if(gtpDl->transportLayerAddress.buf == NULLP)
12200    {
12201       return RFAILED;
12202    }
12203    memcpy(gtpDl->transportLayerAddress.buf, &gtpUeCfg->dlTnlAddress, gtpDl->transportLayerAddress.size);
12204
12205    /*GTP TEID*/
12206    gtpDl->gTP_TEID.size = 4 * sizeof(uint8_t);
12207    DU_ALLOC(gtpDl->gTP_TEID.buf, gtpDl->gTP_TEID.size);
12208    if(gtpDl->gTP_TEID.buf == NULLP)
12209    {
12210       return RFAILED;
12211    }
12212    bufSize = 3; /*forming an Octect String*/
12213    fillTeIdString(bufSize, gtpUeCfg->teId, gtpDl->gTP_TEID.buf);
12214
12215    return ROK;
12216 }
12217
12218 /*******************************************************************
12219  *
12220  * @brief Fills DL Tunnel Setup List
12221  *
12222  * @details
12223  *
12224  *    Function : fillDlTnlSetupList
12225  *
12226  *    Functionality: Fills the DL Tunnel Setup List
12227  *
12228  * @params[in] 
12229  *
12230  * @return ROK     - success
12231  *         RFAILED - failure
12232  *
12233  * ****************************************************************/
12234
12235 uint8_t fillDlTnlSetupList(DLUPTNLInformation_ToBeSetup_List_t *dlTnlInfo, UpTnlCfg *tnlCfg)
12236 {
12237    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
12238
12239    eleCount = 1;
12240    dlTnlInfo->list.count = eleCount; 
12241    dlTnlInfo->list.size = (eleCount * sizeof(DLUPTNLInformation_ToBeSetup_Item_t *));
12242
12243    /* Initialize the DL Tnl Setup List Members */
12244    DU_ALLOC(dlTnlInfo->list.array, dlTnlInfo->list.size);
12245    if(dlTnlInfo->list.array == NULLP)
12246    {
12247       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL Tnl Setup List in fillDlTnlSetupList()");
12248       ret = RFAILED;
12249    }
12250    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
12251    {
12252       DU_ALLOC(dlTnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
12253       if(dlTnlInfo->list.array[arrIdx] == NULLP)
12254       {
12255          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDlTnlSetupList()", arrIdx);
12256          return RFAILED;
12257       }
12258       dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.present = UPTransportLayerInformation_PR_gTPTunnel;
12259       DU_ALLOC(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
12260       if(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel == NULLP)
12261       {
12262          DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL tunnel info in fillDlTnlSetupList()");
12263          return RFAILED;
12264       }
12265       ret = fillGtpTunnelforDl(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel,\
12266                tnlCfg->tnlCfg1);
12267       if(ret != ROK)
12268          break;
12269    }
12270    return ret;
12271 }
12272
12273 /*******************************************************************
12274  *
12275  * @brief Fills the Drb Setup List for Ue Context Setup Response
12276  *
12277  * @details
12278  *
12279  *    Function : fillDrbSetupList
12280  *
12281  *    Functionality: Fills the Drb Setup List for Ue Context Setup Response
12282  *
12283  * @params[in] 
12284  *
12285  * @return ROK     - success
12286  *         RFAILED - failure
12287  *
12288  * ****************************************************************/
12289 uint8_t fillDrbSetupList(DRBs_Setup_List_t *drbSetupList, DuUeCfg *ueCfg)
12290 {
12291    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
12292    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
12293
12294    eleCount = ueCfg->numDrb;
12295    drbSetupList->list.count = eleCount;
12296    drbSetupList->list.size = \
12297         (eleCount * sizeof(DRBs_Setup_Item_t *));
12298
12299    /* Initialize the Drb Setup List Members */
12300    DU_ALLOC(drbSetupList->list.array, drbSetupList->list.size);
12301    if(drbSetupList->list.array == NULLP)
12302    {
12303       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DRB Setup List in fillDrbSetupList()");
12304       ret = RFAILED;
12305    }
12306
12307    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
12308    {
12309       DU_ALLOC(drbSetupList->list.array[arrIdx], sizeof(DRBs_Setup_Item_t));
12310       if(drbSetupList->list.array[arrIdx] == NULLP)
12311       {
12312          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDrbSetupList()", arrIdx);
12313          return RFAILED;
12314       }
12315       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
12316       drbItemIe->id = ProtocolIE_ID_id_DRBs_Setup_Item;
12317       drbItemIe->criticality = Criticality_reject;
12318       drbItemIe->value.present = DRBs_Setup_ItemIEs__value_PR_DRBs_Setup_Item;
12319       drbItemIe->value.choice.DRBs_Setup_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
12320       ret = fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List,\
12321           &ueCfg->upTnlInfo[arrIdx]);
12322       if(ret != ROK)
12323          break;
12324    }
12325    return ret;
12326 }
12327
12328 /*******************************************************************
12329  *
12330  * @brief Builds and sends the UE Setup Response
12331  *
12332  * @details
12333  *
12334  *    Function : BuildAndSendUeContextSetupRsp
12335  *
12336  *    Functionality: Constructs the UE Setup Response and sends
12337  *                   it to the DU through SCTP.
12338  *
12339  * @params[in] uint8_t cellId,uint8_t ueId
12340  *
12341  * @return ROK     - success
12342  *         RFAILED - failure
12343  *
12344  * ****************************************************************/
12345 uint8_t BuildAndSendUeContextSetupRsp(uint8_t cellId,uint8_t ueId)
12346 {
12347    uint8_t   idx, ret, cellIdx, elementCnt;
12348    uint32_t  gnbCuUeF1apId;   /* gNB-CU UE F1AP Id */
12349    uint32_t  gnbDuUeF1apId;   /* gNB-DU UE F1AP Id */
12350    asn_enc_rval_t  encRetVal;        /* Encoder return value */
12351    F1AP_PDU_t               *f1apMsg = NULLP;
12352    UEContextSetupResponse_t *ueSetRsp = NULLP;
12353    CellGroupConfigRrc_t     *cellGrpCfg = NULLP;
12354    DuUeCb                   *ueCb = NULLP;
12355
12356    DU_LOG("\n INFO   -->  F1AP : Building UE Context Setup Response for cellId %d, ueId %d\n", cellId, ueId);
12357
12358    while(true)
12359    {
12360       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
12361       if(f1apMsg == NULLP)
12362       {
12363          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
12364          ret = RFAILED;
12365          break;
12366       }
12367
12368       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
12369       DU_ALLOC(f1apMsg->choice.successfulOutcome,
12370             sizeof(SuccessfulOutcome_t));
12371       if(f1apMsg->choice.successfulOutcome == NULLP)
12372       {
12373          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
12374          ret = RFAILED;
12375          break;
12376       }
12377
12378       f1apMsg->choice.successfulOutcome->procedureCode = \
12379                                                          ProcedureCode_id_UEContextSetup;
12380       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
12381       f1apMsg->choice.successfulOutcome->value.present = \
12382                                                          SuccessfulOutcome__value_PR_UEContextSetupResponse;
12383
12384       ueSetRsp =
12385          &f1apMsg->choice.successfulOutcome->value.choice.UEContextSetupResponse;
12386       elementCnt = 4;
12387       ueSetRsp->protocolIEs.list.count = elementCnt;
12388       ueSetRsp->protocolIEs.list.size = \
12389                                         elementCnt * sizeof(UEContextSetupResponse_t *);
12390
12391       /* Initialize the UESetup members */
12392       DU_ALLOC(ueSetRsp->protocolIEs.list.array, \
12393             ueSetRsp->protocolIEs.list.size);
12394       if(ueSetRsp->protocolIEs.list.array == NULLP)
12395       {
12396          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
12397          ret = RFAILED;
12398          break;
12399       }
12400
12401       for(idx=0; idx<elementCnt; idx++)
12402       {
12403          DU_ALLOC(ueSetRsp->protocolIEs.list.array[idx],\
12404                sizeof(UEContextSetupResponseIEs_t));
12405          if(ueSetRsp->protocolIEs.list.array[idx] == NULLP)
12406          {
12407             DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
12408             ret = RFAILED;
12409             break;
12410          }
12411       }
12412       /* Fetching Ue Cb Info*/
12413       GET_CELL_IDX(cellId, cellIdx);
12414       gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
12415       gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
12416       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
12417
12418       idx = 0;
12419       /*GNB CU UE F1AP ID*/
12420       ueSetRsp->protocolIEs.list.array[idx]->id = \
12421                                                   ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
12422       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
12423       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
12424                                                              UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
12425       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
12426
12427       /*GNB DU UE F1AP ID*/
12428       idx++;
12429       ueSetRsp->protocolIEs.list.array[idx]->id = \
12430                                                   ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
12431       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
12432       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
12433                                                              UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
12434       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
12435
12436
12437       /*DUtoCURRC Information */
12438       idx++;
12439       ueSetRsp->protocolIEs.list.array[idx]->id  = \
12440                                                    ProtocolIE_ID_id_DUtoCURRCInformation;
12441       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
12442       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
12443                                                             UEContextSetupResponseIEs__value_PR_DUtoCURRCInformation;
12444       if(ueCb->f1UeDb)
12445       {
12446          if(ueCb->f1UeDb->duUeCfg.cellGrpCfg)
12447          {
12448             cellGrpCfg = (CellGroupConfigRrc_t*)ueCb->f1UeDb->duUeCfg.cellGrpCfg;
12449             ret = EncodeUeCntxtDuToCuInfo(&ueSetRsp->protocolIEs.list.array[idx]->value.\
12450                      choice.DUtoCURRCInformation.cellGroupConfig, cellGrpCfg);
12451             if(ret == RFAILED)
12452             {
12453                DU_LOG("\nERROR  -->  F1AP : Failed to EncodeUeCntxtDuToCuInfo in BuildAndSendUeContextSetupRsp()");
12454                freeF1UeDb(ueCb->f1UeDb);
12455                ueCb->f1UeDb = NULLP;
12456                break;
12457             }
12458          }
12459       }
12460       else
12461       {
12462          DU_LOG("\nERROR  -->  F1AP : Failed to form DUtoCU RRCInfo at BuildAndSendUeContextSetupRsp()");
12463          ret = RFAILED;
12464          break;
12465       }
12466
12467       /* Drb Setup List */
12468       idx++;
12469       ueSetRsp->protocolIEs.list.array[idx]->id  = \
12470                                  ProtocolIE_ID_id_DRBs_Setup_List;
12471       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
12472       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
12473                                  UEContextSetupResponseIEs__value_PR_DRBs_Setup_List;
12474       ret = fillDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List,\
12475                &ueCb->f1UeDb->duUeCfg);
12476       if(ret == RFAILED)
12477       {
12478          DU_LOG("\nERROR  -->  F1AP : Failed to fillDrbSetupList in BuildAndSendUeContextSetupRsp()");
12479          freeF1UeDb(ueCb->f1UeDb);
12480          ueCb->f1UeDb = NULLP;
12481          break;
12482       }
12483
12484        /* Free UeContext Db created during Ue context Req */
12485        freeF1UeDb(ueCb->f1UeDb);
12486        ueCb->f1UeDb = NULLP;
12487
12488       /* TODO: To send Drb list */
12489       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
12490
12491       /* Encode the UE context setup response type as APER */
12492       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
12493       encBufSize = 0;
12494       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
12495             encBuf);
12496       /* Encode results */
12497       if(encRetVal.encoded == ENCODE_FAIL)
12498       {
12499          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Response structure (at %s)\n",\
12500                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
12501          ret = RFAILED;
12502          break;
12503       }
12504       else
12505       {
12506          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Setup Response\n");
12507          for(int i=0; i< encBufSize; i++)
12508          {
12509             printf("%x",encBuf[i]);
12510          }
12511       }
12512
12513       /* Sending  msg  */
12514       if(sendF1APMsg()  != ROK)
12515       {
12516          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Response failed");
12517          ret = RFAILED;
12518          break;
12519       }
12520       break;
12521    }
12522    FreeUeContextSetupRsp(f1apMsg);
12523    return ret;
12524 }/* End of BuildAndSendUeContextSetupRsp */
12525 /*******************************************************************
12526 *
12527 * @brief  Build And Send Ue Context Rsp 
12528 *
12529 * @details
12530 *
12531 *    Function : BuildAndSendUeCtxtRsp 
12532 *
12533 *    Functionality : Build And Send Ue Context Rsp
12534
12535 * @params[in]
12536 * @return sucess = ROK
12537 *         failure = RFAILED
12538 *
12539 * ****************************************************************/
12540 uint8_t BuildAndSendUeCtxtRsp(uint8_t cellId, uint8_t ueId)
12541 {
12542    uint8_t cellIdx = 0, actionType = 0; 
12543
12544    GET_CELL_IDX(cellId, cellIdx);
12545    actionType = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].f1UeDb->actionType;
12546
12547    switch(actionType)
12548    {
12549       case UE_CTXT_SETUP:
12550          {
12551             BuildAndSendUeContextSetupRsp(cellId,ueId);
12552             break;
12553          }
12554       case UE_CTXT_MOD:
12555          {
12556             BuildAndSendUeContextModRsp(&duCb.actvCellLst[cellIdx]->ueCb[ueId-1]);
12557             break;
12558          }
12559       default:
12560          DU_LOG("ERROR  -->  F1AP: Invalid Action Type %d at BuildAndSendUeCtxtRsp()", actionType);
12561          break;
12562
12563    }
12564    return ROK;
12565 }
12566
12567 /*******************************************************************
12568  *
12569  * @brief deallocating the memory of  F1reset msg
12570  *
12571  * @details
12572  *
12573  *    Function : FreeF1ResetReq
12574  *
12575  *    Functionality :
12576  *         - freeing memory of F1reset request msg
12577  *
12578  * @params[in]
12579  * @return void
12580  *
12581  *
12582  * ****************************************************************/
12583 void FreeF1ResetReq(F1AP_PDU_t *f1apMsg)
12584 {
12585    uint8_t idx =0 ;
12586    Reset_t *f1ResetMsg;
12587
12588    if(f1apMsg)
12589    {
12590       if(f1apMsg->choice.initiatingMessage)
12591       {
12592          f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
12593
12594          if(f1ResetMsg->protocolIEs.list.array)
12595          {
12596             for(idx=0 ;idx < f1ResetMsg->protocolIEs.list.count ; idx++)
12597             {
12598                if(f1ResetMsg->protocolIEs.list.array[idx])
12599                {
12600                   DU_FREE(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
12601                }
12602             }
12603             DU_FREE(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
12604          }
12605          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
12606       }
12607       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
12608    }
12609 }
12610 /*******************************************************************
12611  *
12612  * @brief Build and Send F1reset request 
12613  *
12614  * @details
12615  *
12616  *    Function : BuildAndSendF1ResetReq
12617  *
12618  *    Functionality:
12619  *         - Build and Send F1reset request msg
12620  *
12621  * @params[in]
12622  * @return ROK     - success
12623  *         RFAILED - failure
12624  *
12625  * ****************************************************************/
12626 uint8_t BuildAndSendF1ResetReq()
12627 {
12628    uint8_t          elementCnt=0;
12629    uint8_t          idx=0;
12630    uint8_t          ret= RFAILED;
12631    Reset_t          *f1ResetMsg = NULLP;
12632    F1AP_PDU_t       *f1apMsg = NULLP;
12633    asn_enc_rval_t   encRetVal;
12634    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset request \n");
12635    do
12636    {
12637       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
12638       if(f1apMsg == NULLP)
12639       {
12640          break;
12641       }
12642       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
12643       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
12644       if(f1apMsg->choice.initiatingMessage == NULLP)
12645       {
12646          break;
12647       }
12648       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_Reset;
12649       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
12650       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_Reset;
12651
12652       f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
12653
12654       elementCnt = 3;
12655       f1ResetMsg->protocolIEs.list.count = elementCnt;
12656       f1ResetMsg->protocolIEs.list.size = elementCnt * sizeof(ResetIEs_t *);
12657
12658       /* Initialize the F1Setup members */
12659       DU_ALLOC(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
12660       if(f1ResetMsg->protocolIEs.list.array == NULLP)
12661       {
12662          break;
12663       }
12664       for(idx=0; idx<elementCnt; idx++)
12665       {
12666          DU_ALLOC(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
12667          if(f1ResetMsg->protocolIEs.list.array[idx] == NULLP)
12668          {
12669             break;
12670          }
12671       }
12672
12673       /*TransactionID*/
12674       idx=0;
12675       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
12676       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
12677       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_TransactionID;
12678       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.TransactionID = 1;
12679
12680       /*Cause*/
12681       idx++;
12682       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_Cause;
12683       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_ignore;
12684       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_Cause;
12685       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.present = Cause_PR_radioNetwork;
12686       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.choice.radioNetwork = CauseRadioNetwork_action_desirable_for_radio_reasons;
12687
12688       /*Reset Type*/
12689       idx++;
12690       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_ResetType;
12691       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
12692       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_ResetType;
12693       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.present = ResetType_PR_f1_Interface;
12694       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.choice.f1_Interface = ResetAll_reset_all;
12695
12696       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
12697
12698       /* Encode the F1SetupRequest type as APER */
12699       memset(encBuf, 0, ENC_BUF_MAX_LEN);
12700       encBufSize = 0;
12701       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
12702             encBuf);
12703
12704       /* Encode results */
12705       if(encRetVal.encoded == ENCODE_FAIL)
12706       {
12707          DU_LOG("\nERROR  -->  F1AP : Could not encode F1Reset structure (at %s)\n",\
12708                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
12709          break;
12710       }
12711       else
12712       {
12713          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1Reset\n");
12714          for(idx=0; idx< encBufSize; idx++)
12715          {
12716             printf("%x",encBuf[idx]);
12717          }
12718       }
12719
12720       if(sendF1APMsg() != ROK)
12721       {
12722          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset request failed");
12723          break;
12724       }
12725
12726       ret = ROK;
12727       break;
12728    }while(true);
12729
12730    FreeF1ResetReq(f1apMsg);
12731    return ret;
12732 }
12733 /*******************************************************************
12734  *
12735  * @brief Build And Send F1ResetAck
12736  *
12737  * @details
12738  *
12739  *    Function : BuildAndSendF1ResetAck
12740  *
12741  *    Functionality:
12742  *         - Build And Send  F1ResetRSP
12743  *
12744  * @return ROK     - success
12745  *         RFAILED - failure
12746  *
12747  * ****************************************************************/
12748 void FreeF1ResetAck(F1AP_PDU_t *f1apMsg)
12749 {
12750    uint8_t idx;
12751    ResetAcknowledge_t *f1ResetAck;
12752
12753    if(f1apMsg)
12754    {
12755       if(f1apMsg->choice.successfulOutcome)
12756       {
12757          f1ResetAck= &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
12758
12759          if(f1ResetAck->protocolIEs.list.array)
12760          {
12761             for(idx=0; idx<f1ResetAck->protocolIEs.list.count ; idx++)
12762             {
12763                if(f1ResetAck->protocolIEs.list.array[idx])
12764                {
12765                   DU_FREE(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
12766                }
12767             }
12768             DU_FREE(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
12769          }
12770          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
12771       }
12772       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
12773    }
12774 }
12775
12776 /*******************************************************************
12777  *
12778  * @brief Build And Send F1ResetAck
12779  *
12780  * @details
12781  *
12782  *    Function : BuildAndSendF1ResetAck
12783  *
12784  *    Functionality:
12785  *         - Build And Send  F1ResetRSP
12786  *
12787  *  @params[in]
12788  * @return ROK     - success
12789  *         RFAILED - failure
12790  *
12791  * ****************************************************************/
12792 uint8_t BuildAndSendF1ResetAck()
12793 {
12794    uint8_t                idx = 0;
12795    uint8_t                elementCnt = 0;
12796    uint8_t                ret = RFAILED;
12797    F1AP_PDU_t             *f1apMsg = NULL;
12798    ResetAcknowledge_t     *f1ResetAck = NULLP;
12799    asn_enc_rval_t         encRetVal;
12800    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset Acknowledgment \n");
12801
12802    do{
12803       /* Allocate the memory for F1ResetRequest_t */
12804       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
12805       if(f1apMsg == NULLP)
12806       {
12807          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
12808          break;
12809       }
12810
12811       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
12812
12813       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
12814       if(f1apMsg->choice.successfulOutcome == NULLP)
12815       {
12816          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
12817          break;
12818       }
12819       f1apMsg->choice.successfulOutcome->criticality   = Criticality_reject;
12820       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetAcknowledge;
12821       f1ResetAck = &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
12822
12823       elementCnt = 1;
12824
12825       f1ResetAck->protocolIEs.list.count = elementCnt;
12826       f1ResetAck->protocolIEs.list.size = elementCnt*sizeof(ResetAcknowledgeIEs_t *);
12827
12828       DU_ALLOC(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
12829       if(f1ResetAck->protocolIEs.list.array == NULLP)
12830       {
12831          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1ResetAckIEs failed");
12832          break;
12833       }
12834
12835       for(idx=0; idx<elementCnt; idx++)
12836       {
12837          DU_ALLOC(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
12838          if(f1ResetAck->protocolIEs.list.array[idx] == NULLP)
12839          {
12840             break;
12841          }
12842       }
12843       /*TransactionID*/
12844       idx = 0;
12845       f1ResetAck->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
12846       f1ResetAck->protocolIEs.list.array[idx]->criticality = Criticality_reject;
12847       f1ResetAck->protocolIEs.list.array[idx]->value.present = ResetAcknowledgeIEs__value_PR_TransactionID;
12848       f1ResetAck->protocolIEs.list.array[idx]->value.choice.TransactionID = TRANS_ID;
12849
12850       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
12851
12852       /* Encode the F1SetupRequest type as UPER */
12853       memset(encBuf, 0, ENC_BUF_MAX_LEN);
12854       encBufSize = 0;
12855       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
12856
12857       /* Check encode results */
12858       if(encRetVal.encoded == ENCODE_FAIL)
12859       {
12860          DU_LOG("\nERROR  -->  F1AP : Could not encode F1ResetAck structure (at %s)\n",\
12861                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
12862          break;
12863       }
12864       else
12865       {
12866          DU_LOG("\nDUBUG   -->  F1AP : Created APER encoded buffer for F1ResetAck\n");
12867          for(int i=0; i< encBufSize; i++)
12868          {
12869             printf("%x",encBuf[i]);
12870          }
12871       }
12872       /* Sending msg */
12873       if(sendF1APMsg() != ROK)
12874       {
12875          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset Acknowledgement failed");
12876          break;
12877       }
12878
12879       ret = ROK;
12880       break;
12881    }while(true);
12882
12883    FreeF1ResetAck(f1apMsg);
12884    return ret;
12885 }
12886 /******************************************************************
12887 *
12888 * @brief free F1 reset msg allocated by aper_decoder 
12889 *
12890 * @details
12891 *
12892 *    Function : freeAperDecodeF1ResetMsg 
12893 *
12894 *    Functionality: free F1 reset msg allocated by aper_decoder 
12895 *
12896 * @params[in] Reset_t *f1ResetMsg 
12897 * @return void 
12898 *
12899 * ****************************************************************/
12900
12901 void freeAperDecodeF1ResetMsg(Reset_t *f1ResetMsg)
12902 {
12903    uint8_t ieIdx =0;
12904    if(f1ResetMsg->protocolIEs.list.array)
12905    {
12906       for(ieIdx=0 ;ieIdx < f1ResetMsg->protocolIEs.list.count ; ieIdx++)
12907       {
12908          if(f1ResetMsg->protocolIEs.list.array[ieIdx])
12909          {
12910             free(f1ResetMsg->protocolIEs.list.array[ieIdx]);
12911          }
12912       }
12913       free(f1ResetMsg->protocolIEs.list.array);
12914    }
12915 }
12916
12917 /******************************************************************
12918  *
12919  * @brief Processes DL RRC Message Transfer  sent by CU
12920  *
12921  * @details
12922  *
12923  *    Function : procF1ResetReq
12924  *
12925  *    Functionality: Processes DL RRC Message Transfer sent by CU
12926  *
12927  * @params[in] F1AP_PDU_t ASN decoded F1AP message
12928  * @return ROK     - success
12929  *         RFAILED - failure
12930  *
12931  * ****************************************************************/
12932 uint8_t procF1ResetReq(F1AP_PDU_t *f1apMsg)
12933 {
12934    /* we are currently not supporting Ue release. right now we are supporting only init case of fireset */
12935    uint8_t       ieIdx = 0;
12936    uint8_t        ret = ROK;
12937    Reset_t       *f1ResetMsg = NULLP;
12938
12939    DU_LOG("\nINFO   -->  Processing F1 reset request");
12940    f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
12941
12942    for(ieIdx=0; ieIdx<f1ResetMsg->protocolIEs.list.count; ieIdx++)
12943    {
12944       switch(f1ResetMsg->protocolIEs.list.array[ieIdx]->id)
12945       {
12946          case ProtocolIE_ID_id_TransactionID:
12947             break;
12948
12949          case ProtocolIE_ID_id_Cause:
12950             break;
12951
12952          case ProtocolIE_ID_id_ResetType:
12953             {
12954                break;
12955             }
12956
12957          default:
12958             break;
12959       }
12960    }
12961    ret = BuildAndSendF1ResetAck();
12962    DU_LOG("\nINFO   -->  UE release is not supported for now");
12963
12964    freeAperDecodeF1ResetMsg(f1ResetMsg);
12965
12966    return ret;
12967 }
12968
12969 /*******************************************************************
12970  *
12971  * @brief free the RRC delivery report
12972  *
12973  * @details
12974  *
12975  *    Function : freeRrcDeliveryReport
12976  *
12977  *    Functionality: free the RRC delivery report
12978  *
12979  * @params[in]
12980  * @return ROK     - success
12981  *         RFAILED - failure
12982  *
12983  * ****************************************************************/
12984 void freeRrcDeliveryReport(F1AP_PDU_t  *f1apMsg )
12985 {
12986    uint8_t idx=0;
12987    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
12988
12989    if(f1apMsg)
12990    {
12991       if(f1apMsg->choice.initiatingMessage)
12992       {
12993          rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
12994          if(rrcDeliveryReport->protocolIEs.list.array)
12995          {
12996             for(idx =0 ;idx <rrcDeliveryReport->protocolIEs.list.count ;
12997                   idx++)
12998             {
12999                if(rrcDeliveryReport->protocolIEs.list.array[idx])
13000                {
13001                   DU_FREE(rrcDeliveryReport->protocolIEs.list.array[idx],
13002                         sizeof(RRCDeliveryReportIEs_t));
13003                }   
13004             }
13005             DU_FREE(rrcDeliveryReport->protocolIEs.list.array,
13006                   rrcDeliveryReport->protocolIEs.list.size);
13007          }
13008          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
13009       }
13010       DU_FREE(f1apMsg,
13011             sizeof(F1AP_PDU_t));
13012    }
13013 }
13014
13015 /*******************************************************************
13016 *
13017 * @brief Builds and sends the RRC delivery report
13018 *
13019 * @details
13020 *
13021 *    Function : BuildAndSendRrcDeliveryReport
13022 *
13023 *    Functionality: Builds and sends the RRC delivery report
13024 *
13025 * @params[in]
13026 *
13027 * @return ROK     - success
13028 *         RFAILED - failure
13029 *
13030 * ****************************************************************/
13031 uint8_t BuildAndSendRrcDeliveryReport(uint32_t gnbCuUeF1apId, \
13032    uint32_t gnbDuUeF1apId, RrcDeliveryReport *rrcDelivery)
13033 {
13034    uint8_t             ret = RFAILED;
13035    uint8_t             idx    = 0;
13036    uint8_t             idx1   = 0;
13037    uint8_t             elementCnt = 0;
13038    F1AP_PDU_t          *f1apMsg = NULLP;
13039    asn_enc_rval_t      encRetVal;  
13040    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
13041
13042    do{
13043
13044       DU_LOG("\nINFO   -->  F1AP : Building RRC delivery Message Transfer Message\n");
13045       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
13046       if(f1apMsg == NULLP)
13047       {
13048          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
13049          break;
13050       }
13051       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
13052       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
13053       if(f1apMsg->choice.initiatingMessage == NULLP)
13054       {
13055          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU  failed");
13056          break;
13057       }
13058       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_RRCDeliveryReport;
13059       f1apMsg->choice.initiatingMessage->criticality   = Criticality_ignore;
13060       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_RRCDeliveryReport;
13061
13062       rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
13063       elementCnt = 4;
13064       rrcDeliveryReport->protocolIEs.list.count = elementCnt;
13065       rrcDeliveryReport->protocolIEs.list.size = elementCnt * sizeof(RRCDeliveryReportIEs_t *);
13066
13067       /* Initialize the F1Setup members */
13068       DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array, rrcDeliveryReport->protocolIEs.list.size);
13069       if(rrcDeliveryReport->protocolIEs.list.array == NULLP)
13070       {
13071          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRC Delivery  failed");
13072          break;
13073       }
13074       for(idx =0 ;idx <elementCnt; idx++)
13075       {
13076          DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array[idx], sizeof(RRCDeliveryReportIEs_t));
13077          if(rrcDeliveryReport->protocolIEs.list.array[idx] == NULLP)
13078          {
13079             break;
13080          }
13081       }
13082
13083       idx1 = 0;
13084
13085       /*GNB CU UE F1AP ID*/
13086       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
13087       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
13088       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_CU_UE_F1AP_ID;
13089       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
13090
13091       /*GNB DU UE F1AP ID*/
13092       idx1++;
13093       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
13094       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
13095       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_DU_UE_F1AP_ID;
13096       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
13097
13098       /*RRC delivery status*/
13099       idx1++;
13100       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_RRCDeliveryStatus;
13101       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
13102       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_RRCDeliveryStatus;
13103       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.delivery_status =\
13104       rrcDelivery->rrcDeliveryStatus.deliveryStatus;
13105       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.triggering_message =\
13106       rrcDelivery->rrcDeliveryStatus.triggeringMessage;
13107
13108       /* SRB ID */ 
13109       idx1++;
13110       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
13111       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
13112       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_SRBID;
13113       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.SRBID =  rrcDelivery->srbId;
13114
13115       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
13116
13117       /* Encode the RRC DELIVERY REPORT type as APER */
13118       memset(encBuf, 0, ENC_BUF_MAX_LEN);
13119       encBufSize = 0;
13120       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
13121             encBuf);
13122
13123       /* Encode results */
13124       if(encRetVal.encoded == ENCODE_FAIL)
13125       {
13126          DU_LOG("\nERROR  -->  F1AP : Could not encode RRC Delivery Msg structure (at %s)\n",\
13127                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
13128          break;
13129       }
13130       else
13131       {
13132          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for RRC Delivery Msg \n");
13133          for(idx=0; idx< encBufSize; idx++)
13134          {
13135             printf("%x",encBuf[idx]);
13136          }
13137       }
13138
13139       /* Sending msg */
13140       if(sendF1APMsg() != ROK)
13141       {
13142          DU_LOG("\nERROR  -->  F1AP : Sending RRC delivery  msg request failed");
13143          break;
13144       }
13145       ret = ROK;
13146       break;
13147
13148    }while(true);
13149
13150    freeRrcDeliveryReport(f1apMsg);
13151    return ret;
13152 }
13153
13154 /*******************************************************************
13155  *
13156  * @brief Processes cells to be activated
13157  *
13158  * @details
13159  *
13160  *    Function : extractCellsToBeActivated
13161  *
13162  *    Functionality:
13163  *      - Processes cells to be activated list received in F1SetupRsp
13164  *
13165  * @params[in] void
13166  * @return ROK     - success
13167  *         RFAILED - failure
13168  *
13169  * ****************************************************************/
13170
13171 uint8_t extractCellsToBeActivated(Cells_to_be_Activated_List_t cellsToActivate)
13172 {
13173    uint8_t  ret = ROK;
13174    uint16_t idx, nci, pci = 0;
13175    Cells_to_be_Activated_List_Item_t cell;
13176
13177    for(idx=0; idx<cellsToActivate.list.count; idx++)
13178    {
13179       nci = 0;
13180       cell = cellsToActivate.list.array[idx]->value.choice.Cells_to_be_Activated_List_Item;
13181       bitStringToInt(&cell.nRCGI.nRCellIdentity, &nci);
13182
13183       if(cell.nRPCI)
13184       {
13185          pci = *cell.nRPCI;
13186       }
13187       ret = duProcCellsToBeActivated(cell.nRCGI.pLMN_Identity.buf, nci, pci);
13188    }
13189    return ret;
13190 }
13191 /******************************************************************
13192 *
13193 * @brief Processes F1 Setup Response allocated by aper_decoder 
13194 *
13195 * @details
13196 *
13197 *    Function : freeF1SetupRsp 
13198 *
13199 *    Functionality: free F1 Setup Response allocated by aper_decoder 
13200 *
13201 * @params[in] F1SetupResponse_t *f1SetRspMsg 
13202 * @return void 
13203 *
13204 * ****************************************************************/
13205
13206 void freeAperDecodeF1SetupRsp(F1SetupResponse_t *f1SetRspMsg)
13207 {
13208    uint8_t ieIdx =0;
13209    uint8_t arrIdx =0;
13210    Cells_to_be_Activated_List_t *cellToActivate =NULLP;
13211    RRC_Version_t      *rrcVer =NULLP;
13212
13213    if(f1SetRspMsg->protocolIEs.list.array)
13214    {
13215       for(ieIdx=0; ieIdx<f1SetRspMsg->protocolIEs.list.count; ieIdx++)
13216       {
13217          if(f1SetRspMsg->protocolIEs.list.array[ieIdx])
13218          {
13219             switch(f1SetRspMsg->protocolIEs.list.array[ieIdx]->id)
13220             {
13221                case ProtocolIE_ID_id_Cells_to_be_Activated_List:
13222                   {
13223                      cellToActivate =
13224                         &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.Cells_to_be_Activated_List;
13225                      if(cellToActivate->list.array)
13226                      {
13227                         for(arrIdx=0; arrIdx<cellToActivate->list.count ; arrIdx++)
13228                         {
13229                            if(cellToActivate->list.array[arrIdx])
13230                            {
13231
13232                               if(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.nRCGI.\
13233                               pLMN_Identity.buf)
13234                               {
13235                                  if(cellToActivate->list.array[0]->value.choice.\
13236                                        Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf)
13237                                  {
13238                                     free(cellToActivate->list.array[0]->value.choice.\
13239                                           Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf);
13240                                  }
13241
13242                                  free(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
13243                                        nRCGI.pLMN_Identity.buf);
13244                               }
13245                               free(cellToActivate->list.array[arrIdx]);
13246                            }
13247                         }
13248                         free(cellToActivate->list.array);
13249                      }
13250                      break;
13251                   }
13252                case ProtocolIE_ID_id_TransactionID:
13253                   {
13254                      break;
13255                   }
13256                case ProtocolIE_ID_id_gNB_CU_Name:
13257                   {
13258                      free(f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_Name.buf);
13259                      break;
13260                   }
13261                case ProtocolIE_ID_id_GNB_CU_RRC_Version:
13262                   {
13263                      rrcVer = &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
13264                      if(rrcVer->latest_RRC_Version.buf)
13265                      {
13266                         if(rrcVer->iE_Extensions)
13267                         {
13268                            if(rrcVer->iE_Extensions->list.array)
13269                            {
13270                               if(rrcVer->iE_Extensions->list.array[0])
13271                               {
13272                                  if(rrcVer->iE_Extensions->list.\
13273                                        array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf)
13274                                  {
13275                                     free(rrcVer->iE_Extensions->list.\
13276                                           array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf);
13277                                  }
13278                                  free(rrcVer->iE_Extensions->list.array[0]);
13279                               }
13280                               free(rrcVer->iE_Extensions->list.array);
13281                            }
13282                            free(rrcVer->iE_Extensions);
13283                         }
13284                         free(rrcVer->latest_RRC_Version.buf);
13285                      }
13286                      break;
13287
13288                   }
13289                default:
13290                   {
13291                      DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
13292                            f1SetRspMsg->protocolIEs.list.array[ieIdx]->id);
13293                   }
13294             }
13295             free(f1SetRspMsg->protocolIEs.list.array[ieIdx]);
13296          }
13297       }
13298       free(f1SetRspMsg->protocolIEs.list.array);
13299    }
13300 }
13301 /******************************************************************
13302  *
13303  * @brief Processes F1 Setup Response sent by CU
13304  *
13305  * @details
13306  *
13307  *    Function : procF1SetupRsp
13308  *
13309  *    Functionality: Processes F1 Setup Response sent by CU
13310  *
13311  * @params[in] F1AP_PDU_t ASN decoded F1AP message
13312  * @return ROK     - success
13313  *         RFAILED - failure
13314  *
13315  * ****************************************************************/
13316 uint8_t procF1SetupRsp(F1AP_PDU_t *f1apMsg, MsgLen recvBufLen, char *recvBuf)
13317 {
13318    uint8_t ret = ROK;
13319    uint16_t idx =0;
13320    F1SetupResponse_t *f1SetRspMsg = NULLP;
13321    GNB_CU_Name_t     *cuName = NULLP;
13322    F1SetupRsp  f1SetRspDb;
13323    RRC_Version_t      *rrcVer =NULLP;
13324    
13325    memset(&f1SetRspDb, 0, sizeof(F1SetupRsp));
13326
13327    DU_LOG("\nINFO   -->  F1AP : F1 Setup Response received");
13328    f1SetRspMsg = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
13329
13330    for(idx=0; idx<f1SetRspMsg->protocolIEs.list.count; idx++)
13331    {
13332       switch(f1SetRspMsg->protocolIEs.list.array[idx]->id)
13333       {
13334          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
13335             {
13336                extractCellsToBeActivated(f1SetRspMsg->protocolIEs.list.array[idx]->\
13337                      value.choice.Cells_to_be_Activated_List);
13338                break;
13339             }
13340          case ProtocolIE_ID_id_TransactionID:
13341             {
13342                f1SetRspDb.transId = f1SetRspMsg->protocolIEs.list.array[idx]->\
13343                                     value.choice.TransactionID;
13344                break;
13345             }
13346          case ProtocolIE_ID_id_gNB_CU_Name:
13347             {
13348                cuName = &f1SetRspMsg->protocolIEs.list.array[idx]->\
13349                         value.choice.GNB_CU_Name;
13350                strcpy(f1SetRspDb.cuName, (const char*)cuName->buf);
13351                break;
13352             }
13353          case ProtocolIE_ID_id_GNB_CU_RRC_Version:
13354             {
13355                rrcVer = &f1SetRspMsg->protocolIEs.list.array[idx]->value.choice.RRC_Version;
13356                strcpy(f1SetRspDb.rrcVersion.rrcVer,
13357                      (const char*)rrcVer->latest_RRC_Version.buf);
13358                break;
13359             }
13360          default:
13361             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
13362                   f1SetRspMsg->protocolIEs.list.array[idx]->id);
13363       }
13364       duProcF1SetupRsp();
13365    }
13366    
13367    freeAperDecodeF1SetupRsp(f1SetRspMsg);
13368
13369    duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize = recvBufLen;
13370    DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize);
13371    if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
13372    {
13373       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the buf of F1setup response");
13374       return RFAILED;
13375    }
13376    memcpy(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, recvBuf, recvBufLen);
13377    
13378    if(BuildAndSendE2SetupReq() != ROK)
13379    {
13380       DU_LOG("\nERROR  -->  F1AP : Failed to build and send E2 setup request ");
13381       return RFAILED;
13382    }
13383    return ret;
13384 }
13385 /*******************************************************************
13386 *
13387 * @brief free GNB DU config update ack
13388 *
13389 * @details
13390 *
13391 *    Function : freeAperDecodeGnbDuAck 
13392 *
13393 *    Functionality: Processes GNB DU config update ack And
13394 *                     added free part for the memory allocated by aper_decoder
13395 *
13396 * @params[in] F1AP_PDU_t ASN decoded F1AP message
13397 * @return ROK     - success
13398 *         RFAILED - failure
13399 *
13400 * ****************************************************************/
13401
13402 void freeAperDecodeGnbDuAck(GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck)
13403 {
13404    uint8_t ieIdx = 0;
13405
13406    if(gnbDuAck->protocolIEs.list.array)
13407    {
13408       for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
13409       {
13410          if(gnbDuAck->protocolIEs.list.array[ieIdx])
13411          {
13412             free(gnbDuAck->protocolIEs.list.array[ieIdx]);
13413          }
13414       }
13415       free(gnbDuAck->protocolIEs.list.array);
13416    }
13417 }
13418
13419 /*******************************************************************
13420 *
13421 * @brief Building  result of gnb-du config update ack output
13422 *
13423 * @details
13424 *
13425 *    Function : duProcGnbDuCfgUpdAckMsg 
13426 *
13427 *    Functionality: 
13428 *        Building output of gnb-du config update ack 
13429 *
13430 * @params[in] transId
13431 * @return void
13432 *
13433 * ****************************************************************/
13434
13435 uint8_t duProcGnbDuCfgUpdAckMsg(uint8_t transId)
13436 {
13437    uint8_t  ieIdx=0, arrIdx=0,ret=ROK;
13438    uint8_t  ueId =0 , ueIdx =0, totalActiveUe = 0;
13439    uint16_t cellId =0, cellIdx =0, crnti=0;
13440    CmLList *f1apPduNode = NULLP;
13441    ReservedF1apPduInfo *f1apPduInfo =NULLP;
13442    F1AP_PDU_t *f1apMsgPdu = NULLP;
13443    GNBDUConfigurationUpdate_t *gnbDuConfigUpdate = NULLP;
13444    BIT_STRING_t *cellIdentity=NULLP;
13445    struct Served_Cells_To_Delete_ItemIEs *deleteItemIe=NULLP;
13446    Served_Cells_To_Delete_List_t *cellsToDelete=NULLP;
13447    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
13448
13449    DU_LOG("\nINFO   -->  DU APP: GNB-DU config update Ack received ");
13450    f1apPduNode = searchFromReservedF1apPduList(transId);
13451    f1apPduInfo = (ReservedF1apPduInfo *)f1apPduNode->node;
13452    f1apMsgPdu = (F1AP_PDU_t *)f1apPduInfo->f1apMsg;
13453
13454    if(f1apMsgPdu)
13455    {
13456       if(f1apMsgPdu->choice.initiatingMessage)
13457       {
13458          gnbDuConfigUpdate = &f1apMsgPdu->choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
13459          for(ieIdx=0; ieIdx < gnbDuConfigUpdate->protocolIEs.list.count; ieIdx++)
13460          {
13461             switch(gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->id)
13462             {
13463                case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
13464                   {
13465                      cellsToDelete = &gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
13466                                      Served_Cells_To_Delete_List;
13467                      if(cellsToDelete->list.array)
13468                      {
13469                         if(cellsToDelete->list.array[arrIdx])
13470                         {
13471                            deleteItemIe = (Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx];
13472                            deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
13473                            if(deleteItem->oldNRCGI.nRCellIdentity.buf)
13474                            {
13475                               cellIdentity = &deleteItem->oldNRCGI.nRCellIdentity;
13476                               bitStringToInt(cellIdentity, &cellId);
13477                            }
13478                         }
13479                      }
13480
13481                      GET_CELL_IDX(cellId, cellIdx);
13482                      if(duCb.actvCellLst[cellIdx] != NULLP)
13483                      {
13484                         if(duCb.actvCellLst[cellIdx]->numActvUes == 0)
13485                         {
13486                            duCb.actvCellLst[cellId-1]->cellStatus = DELETION_IN_PROGRESS;
13487                            ret = duSendCellDeletReq(cellId);
13488                            if(ret == RFAILED)
13489                            {
13490                               DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to send cell delete\
13491                               request for cellId[%d]", cellId);
13492                            }
13493                         }
13494                         else
13495                         {
13496                            totalActiveUe = duCb.actvCellLst[cellIdx]->numActvUes;
13497                            while(totalActiveUe)
13498                            {
13499                               if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState != UE_ACTIVE)
13500                               {
13501                                  ueIdx++;
13502                                  continue;
13503                               }
13504
13505                               crnti = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti;
13506                               GET_UE_ID(crnti,ueId);
13507                               /* Sending Ue Context release request only for maximum supporting UEs */
13508                               ret = BuildAndSendUeContextReleaseReq(cellId, ueId);
13509                               if(ret == RFAILED)
13510                               {
13511                                  DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to build and send UE delete\
13512                                  request for cellId[%d]", cellId);
13513                               }
13514                               ueIdx++;
13515                               totalActiveUe--;
13516                            }
13517                         }
13518                      }
13519                      else
13520                      {
13521                         DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): CellId [%d] not found", cellId);
13522                         ret = RFAILED;
13523                      }
13524                      break;
13525                   }
13526
13527                default:
13528                   break;
13529             }
13530          }
13531       }
13532    }
13533    
13534    FreeDUConfigUpdate(f1apMsgPdu);
13535    deleteFromReservedF1apPduList(f1apPduNode);
13536    return ret;
13537 }
13538
13539 /*******************************************************************
13540 *
13541 * @brief Processes GNB DU config update ack
13542 *
13543 * @details
13544 *
13545 *    Function : procF1GNBDUCfgUpdAck
13546 *
13547 *    Functionality: added free part for the memory allocated by aper_decoder
13548 *
13549 * @params[in] F1AP_PDU_t *f1apMsg 
13550 * @return void 
13551 *
13552 * ****************************************************************/
13553 uint8_t procF1GNBDUCfgUpdAck(F1AP_PDU_t *f1apMsg)
13554 {
13555    uint8_t ieIdx=0,transId=0;
13556    GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck = NULLP;
13557
13558    DU_LOG("\nINFO   -->  F1AP : GNB-DU config update acknowledgment");
13559    gnbDuAck = &f1apMsg->choice.successfulOutcome->value.choice.GNBDUConfigurationUpdateAcknowledge;
13560
13561    for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
13562    {
13563       switch(gnbDuAck->protocolIEs.list.array[ieIdx]->id)
13564       {
13565          case ProtocolIE_ID_id_TransactionID:
13566             {
13567                transId = gnbDuAck->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
13568                break;
13569             }
13570          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
13571             {
13572                break;
13573             }
13574          default :
13575             {
13576                DU_LOG("\nERROR  -->  F1AP: procF1GNBDUCfgUpdAck(): Invalid IE Received: %ld", \
13577                      gnbDuAck->protocolIEs.list.array[ieIdx]->id);
13578                break;
13579             }
13580       }
13581    }
13582    
13583    duProcGnbDuCfgUpdAckMsg(transId);
13584     
13585 #if 0
13586    /* presently we are not supporting F1 Reset from DU to CU , we are only
13587     * supporting F1 Reset from CU to DU */
13588
13589    if(BuildAndSendF1ResetReq() != ROK)
13590    {
13591       return RFAILED;
13592    }
13593 #endif
13594
13595    freeAperDecodeGnbDuAck(gnbDuAck);
13596    return ROK;
13597 }
13598 /******************************************************************
13599 *
13600 * @brief free DL RRC Message Transfer allocated by aper_decoder 
13601 *
13602 * @details
13603 *
13604 *    Function : freeAperDecodef1DlRrcMsg 
13605 *
13606 *    Functionality: free DL RRC Message Transfer allocated by aper_decoder 
13607 *
13608 * @params[in] DLRRCMessageTransfer_t *f1DlRrcMsg 
13609 * @return ROK     - success
13610 *         RFAILED - failure
13611 *
13612 * ****************************************************************/
13613
13614 void freeAperDecodef1DlRrcMsg(DLRRCMessageTransfer_t *f1DlRrcMsg)
13615 {
13616    uint8_t ieIdx =0;
13617    RRCContainer_t *rrcContainer = NULLP;
13618
13619    if(f1DlRrcMsg->protocolIEs.list.array)
13620    {
13621       for(ieIdx=0; ieIdx<f1DlRrcMsg->protocolIEs.list.count; ieIdx++)
13622       {
13623          if(f1DlRrcMsg->protocolIEs.list.array[ieIdx])
13624          {
13625             switch(f1DlRrcMsg->protocolIEs.list.array[ieIdx]->id)
13626             {
13627                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13628                   break;
13629                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13630                   break;
13631                case ProtocolIE_ID_id_SRBID:
13632                   break;
13633                case ProtocolIE_ID_id_RRCContainer:
13634                   {
13635                      rrcContainer =&f1DlRrcMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer;
13636                      free(rrcContainer->buf);
13637                   }
13638                case ProtocolIE_ID_id_ExecuteDuplication:
13639                   break;
13640                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13641                   break;
13642                   break;
13643             }
13644             free(f1DlRrcMsg->protocolIEs.list.array[ieIdx]);
13645          }
13646       }
13647       free(f1DlRrcMsg->protocolIEs.list.array);
13648    }
13649 }
13650 /******************************************************************
13651  *
13652  * @brief Processes DL RRC Message Transfer  sent by CU
13653  *
13654  * @details
13655  *
13656  *    Function : procF1DlRrcMsgTrans
13657  *
13658  *    Functionality: Processes DL RRC Message Transfer sent by CU
13659  *
13660  * @params[in] F1AP_PDU_t ASN decoded F1AP message
13661  * @return ROK     - success
13662  *         RFAILED - failure
13663  *
13664  * ****************************************************************/
13665 uint8_t procF1DlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
13666 {
13667    uint8_t  idx, ret;
13668    DLRRCMessageTransfer_t *f1DlRrcMsg = NULLP;
13669    F1DlRrcMsg dlMsg;
13670    memset(&dlMsg, 0, sizeof(F1DlRrcMsg));
13671
13672    DU_LOG("\nINFO   -->  DU_APP : DL RRC message transfer Recevied");
13673    f1DlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
13674
13675    ret = ROK;
13676
13677    for(idx=0; idx<f1DlRrcMsg->protocolIEs.list.count; idx++)
13678    {
13679       switch(f1DlRrcMsg->protocolIEs.list.array[idx]->id)
13680       {
13681          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13682             {
13683                dlMsg.gnbCuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
13684                break;
13685             }
13686          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13687             {
13688                dlMsg.gnbDuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
13689                break;
13690             }
13691          case ProtocolIE_ID_id_SRBID:
13692             {
13693                dlMsg.srbId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
13694                break;
13695             }
13696          case ProtocolIE_ID_id_ExecuteDuplication:
13697             dlMsg.execDup = true;
13698             break;
13699
13700          case ProtocolIE_ID_id_RRCContainer:
13701             {
13702                if(f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
13703                {
13704                   dlMsg.rrcMsgSize = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
13705                   DU_ALLOC_SHRABL_BUF(dlMsg.rrcMsgPdu, dlMsg.rrcMsgSize);
13706                   if(dlMsg.rrcMsgPdu)
13707                   {
13708                      memcpy(dlMsg.rrcMsgPdu, f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf,\
13709                         dlMsg.rrcMsgSize);
13710                   }
13711                   else
13712                   {
13713                      DU_LOG("\nERROR  -->  DU APP : Memory alloc Failed at RRC Container at procF1DlRrcMsgTrans()");
13714                      return RFAILED;
13715                   }
13716                }
13717                else
13718                {
13719                   DU_LOG("\nERROR  -->  DU_APP : RRC Container Size is invalid:%ld",\
13720                   f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
13721                   return RFAILED;
13722                }
13723                break;
13724             }
13725          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13726             {
13727                dlMsg.deliveryStatRpt = true;
13728                break;
13729             }
13730          default:
13731             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
13732                   f1DlRrcMsg->protocolIEs.list.array[idx]->id);
13733       }
13734    }
13735
13736    ret = duProcDlRrcMsg(&dlMsg);
13737
13738    freeAperDecodef1DlRrcMsg(f1DlRrcMsg);
13739    return ret;
13740 }
13741 /*******************************************************************
13742  *
13743 * @brief Builds the DRB to be Setup Mod list
13744 *
13745 * @details
13746 *
13747 *    Function : 
13748 *
13749 *    Functionality: Constructs the DRB to be Setup Mod list
13750 *
13751 * @params[in] DRBs_SetupMod_List_t *drbSet
13752 *
13753 * @return ROK     - success
13754 *         RFAILED - failure
13755 *
13756 * ****************************************************************/
13757 uint8_t BuildSrbSetupModList(SRBs_SetupMod_List_t *srbList, DuUeCfg *ueCfg)
13758 {
13759    uint8_t srbIdx = 0;
13760    struct SRBs_SetupMod_ItemIEs *srbItemIe;
13761
13762    srbList->list.count = ueCfg->numRlcLcs;
13763    srbList->list.size = srbList->list.count * sizeof(SRBs_SetupMod_ItemIEs_t *);
13764
13765    DU_ALLOC(srbList->list.array, srbList->list.size);
13766    if(srbList->list.array == NULLP)
13767    {
13768       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
13769       return RFAILED;
13770    }
13771
13772    for(srbIdx = 0; srbIdx < srbList->list.count; srbIdx++)
13773    {
13774       DU_ALLOC(srbList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
13775       if(srbList->list.array[srbIdx] == NULLP)
13776       {
13777          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
13778          return RFAILED;
13779       }
13780    } 
13781
13782    for(srbIdx=0; srbIdx < srbList->list.count; srbIdx++)
13783    {
13784       srbItemIe = (struct SRBs_SetupMod_ItemIEs *)srbList->list.array[srbIdx];
13785       srbItemIe->id = ProtocolIE_ID_id_SRBs_SetupMod_Item;
13786       srbItemIe->criticality = Criticality_reject;
13787       srbItemIe->value.present = SRBs_SetupMod_ItemIEs__value_PR_SRBs_SetupMod_Item;
13788       srbItemIe->value.choice.SRBs_SetupMod_Item.sRBID = ueCfg->rlcLcCfg[srbIdx].rbId;
13789       srbItemIe->value.choice.SRBs_SetupMod_Item.lCID = ueCfg->rlcLcCfg[srbIdx].lcId;
13790    }
13791    return ROK;
13792 }
13793
13794 /*******************************************************************
13795  *
13796 * @brief Builds the DRB to be Setup Mod list
13797 *
13798 * @details
13799 *
13800 *    Function : 
13801 *
13802 *    Functionality: Constructs the DRB to be Setup Mod list
13803 *
13804 * @params[in] DRBs_SetupMod_List_t *drbSet
13805 *
13806 * @return ROK     - success
13807 *         RFAILED - failure
13808 *
13809 * ****************************************************************/
13810
13811 uint8_t BuildDrbSetupModList(DRBs_SetupMod_List_t *drbSet , DuUeCfg *ueCfg)
13812 {
13813    uint8_t arrIdx =0;
13814    uint8_t drbCnt =0;
13815    struct DRBs_SetupMod_ItemIEs *drbItemIe;
13816
13817    drbCnt = ueCfg->numDrbSetupMod;
13818    drbSet->list.count = drbCnt;
13819    drbSet->list.size = drbCnt * sizeof(DRBs_SetupMod_ItemIEs_t *);
13820    DU_ALLOC(drbSet->list.array, drbSet->list.size);
13821    if(drbSet->list.array == NULLP)
13822    {
13823       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
13824       return  RFAILED;
13825    }
13826    for(arrIdx=0; arrIdx<drbCnt; arrIdx++)
13827    {
13828       DU_ALLOC(drbSet->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
13829       if(drbSet->list.array[arrIdx] == NULLP)
13830       {
13831               DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
13832               return  RFAILED;
13833       }
13834
13835       drbItemIe = (struct DRBs_SetupMod_ItemIEs *)drbSet->list.array[arrIdx];
13836       drbItemIe->id = ProtocolIE_ID_id_DRBs_SetupMod_Item;
13837       drbItemIe->criticality = Criticality_reject;
13838       drbItemIe->value.present = DRBs_SetupMod_ItemIEs__value_PR_DRBs_SetupMod_Item;
13839       drbItemIe->value.choice.DRBs_SetupMod_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
13840       if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List,\
13841       &ueCfg->upTnlInfo[arrIdx])!= ROK)
13842       {
13843          DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbToBeSetupModList");
13844          return RFAILED;
13845       }
13846       
13847    }
13848
13849    return ROK;
13850 }
13851 /*******************************************************************
13852 * @brief Free the memory allocated for DRB setup List
13853 *
13854 * @details
13855 *
13856 *    Function : FreeDrbSetupModList 
13857 *
13858 *    Functionality:
13859 *       Free the memory allocated for DRB setup list
13860 *
13861 * @params[in] DRBs_Setup_List_t *
13862 * @return void
13863 *
13864 * ****************************************************************/
13865 void FreeDrbSetupModList(DRBs_SetupMod_List_t *drbSetupList)
13866 {
13867    uint8_t arrIdx = 0;
13868    DRBs_SetupMod_ItemIEs_t *drbItemIe = NULLP;
13869
13870    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
13871    {
13872       drbItemIe = ((DRBs_SetupMod_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
13873       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List);
13874       DU_FREE(drbSetupList->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
13875    }
13876    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
13877 }
13878
13879 /*******************************************************************
13880 * @brief Free the memory allocated for SRB setup List
13881 *
13882 * @details
13883 *
13884 *    Function : FreeSrbSetupModList 
13885 *
13886 *    Functionality:
13887 *       Free the memory allocated for SRB setup list
13888 *
13889 * @params[in] SRBs_Setup_List_t *
13890 * @return void
13891 *
13892 * ****************************************************************/
13893 void FreeSrbSetupModList(SRBs_SetupMod_List_t *srbSetupList)
13894 {
13895    uint8_t srbIdx = 0;
13896    
13897    for(srbIdx = 0; srbIdx < srbSetupList->list.count; srbIdx++)
13898       DU_FREE(srbSetupList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
13899    DU_FREE(srbSetupList->list.array, srbSetupList->list.size);
13900 }
13901
13902 /*******************************************************************
13903 * @brief Free the memory allocated for UE Context Mod Response
13904 *
13905 * @details
13906 *
13907 *    Function : FreeUeContextModResp 
13908 *
13909 *    Functionality:
13910 *       Free the memory allocated for UE Context Mod Response
13911 *
13912 * @params[in] F1AP_PDU_t *f1apMsg
13913 * @return void
13914 *
13915 * ****************************************************************/
13916
13917 void FreeUeContextModResp(F1AP_PDU_t *f1apMsg)
13918 {
13919    uint8_t ieIdx;
13920    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
13921    if(f1apMsg)
13922    {
13923       if(f1apMsg->choice.successfulOutcome)
13924       {
13925          ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
13926          if(ueContextModifyRes->protocolIEs.list.array)
13927          {
13928             for(ieIdx=0 ; ieIdx<ueContextModifyRes->protocolIEs.list.count; ieIdx++)
13929             {
13930                if(ueContextModifyRes->protocolIEs.list.array[ieIdx])
13931                {
13932                   switch(ueContextModifyRes->protocolIEs.list.array[ieIdx]->id)
13933                   {
13934                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13935                         break;
13936                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13937                         break;
13938                      case ProtocolIE_ID_id_DRBs_SetupMod_List:
13939                         {
13940                             FreeDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
13941                             value.choice.DRBs_SetupMod_List));
13942                             break;
13943                         }
13944                      case ProtocolIE_ID_id_SRBs_SetupMod_List:
13945                         {
13946                            FreeSrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
13947                               SRBs_SetupMod_List));
13948                            break; 
13949                         }
13950                   }
13951                   DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
13952                }
13953
13954             }
13955             DU_FREE(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
13956          }
13957          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
13958       }
13959       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
13960    }
13961 }
13962
13963 /*****************************************************************i
13964 *
13965 * @brief Creating the ue context modifcation response and sending
13966 *
13967 * @details
13968 *
13969 *    Function : BuildAndSendUeContextModRsp 
13970 *
13971 *    Functionality:
13972 *         - Creating the ue context modifcation response 
13973 *
13974 * @params[in] uint8_t cellId,uint8_t ueId
13975 * @return ROK     - success
13976 *         RFAILED - failure
13977 *
13978 * ****************************************************************/
13979 uint8_t BuildAndSendUeContextModRsp(DuUeCb *ueCb)
13980 {
13981    uint8_t   ieIdx = 0, tnlIdx = 0, rbIdx = 0;
13982    uint8_t   elementCnt = 0;
13983    uint8_t   ret = RFAILED;
13984    F1AP_PDU_t *f1apMsg = NULLP;
13985    asn_enc_rval_t  encRetVal;
13986    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
13987
13988    DU_LOG("\nINFO  -->  F1AP : Building UE context modification response\n");
13989
13990    while(1)
13991    {
13992       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
13993       if(f1apMsg == NULLP)
13994       {
13995          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
13996          break;
13997       }
13998
13999       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
14000
14001       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14002       if(f1apMsg->choice.successfulOutcome == NULLP)
14003       {
14004          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
14005          break;
14006       }
14007       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextModification;
14008       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
14009       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_UEContextModificationResponse;
14010
14011       ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
14012   
14013       if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
14014          elementCnt = 3;
14015       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
14016          elementCnt = 5;
14017       ueContextModifyRes->protocolIEs.list.count = elementCnt;
14018       ueContextModifyRes->protocolIEs.list.size = elementCnt*sizeof(UEContextModificationResponse_t*);
14019
14020       /* Initialize the UE context modification members */
14021       DU_ALLOC(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
14022       if(ueContextModifyRes->protocolIEs.list.array == NULLP)
14023       {
14024          DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
14025          break;
14026       }
14027
14028       for(ieIdx=0 ; ieIdx<elementCnt; ieIdx++)
14029       {
14030          DU_ALLOC(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
14031          if(ueContextModifyRes->protocolIEs.list.array[ieIdx] == NULLP)
14032          {
14033             DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
14034             break;
14035          }
14036       }
14037
14038       ieIdx=0;
14039       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
14040       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
14041       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
14042       UEContextModificationResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
14043       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
14044
14045       ieIdx++;
14046       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14047       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
14048       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present=\
14049       UEContextModificationResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
14050       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
14051
14052       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
14053       {
14054          ieIdx++;
14055          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCInformation;
14056          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
14057          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
14058          UEContextModificationResponseIEs__value_PR_DUtoCURRCInformation;
14059          BuildCellGroupConfigRrc(ueCb, &ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
14060       }
14061
14062       ieIdx++;
14063       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_SetupMod_List;
14064       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
14065       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
14066                                                                         UEContextModificationResponseIEs__value_PR_DRBs_SetupMod_List;
14067       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
14068       {
14069          for(tnlIdx = 0; tnlIdx < duCb.numTeId; tnlIdx++)
14070          {
14071             if(duCb.upTnlCfg[tnlIdx]->ueId == ueCb->gnbDuUeF1apId)
14072             {
14073                memcpy(&ueCb->f1UeDb->duUeCfg.upTnlInfo[ueCb->f1UeDb->duUeCfg.numDrbSetupMod++], duCb.upTnlCfg[tnlIdx], sizeof(UpTnlCfg));
14074             }
14075          }
14076       }
14077       ret = BuildDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
14078                value.choice.DRBs_SetupMod_List) , &ueCb->f1UeDb->duUeCfg);
14079       if(ret != ROK)
14080       {
14081          DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB setupmod List ");
14082          break;
14083       }
14084
14085       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
14086       {
14087          ieIdx++;
14088          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_SRBs_SetupMod_List;
14089          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
14090          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
14091                                                                             UEContextModificationResponseIEs__value_PR_SRBs_SetupMod_List;
14092          for(rbIdx = 0; rbIdx < ueCb->rlcUeCfg.numLcs; rbIdx++)
14093          {
14094             if(ueCb->rlcUeCfg.rlcLcCfg[rbIdx].rbType == RB_TYPE_SRB)
14095             {
14096                memcpy(&ueCb->f1UeDb->duUeCfg.rlcLcCfg[ueCb->f1UeDb->duUeCfg.numRlcLcs++], &ueCb->rlcUeCfg.rlcLcCfg[rbIdx],\
14097                      sizeof(RlcBearerCfg));
14098             }
14099          }
14100          ret = BuildSrbSetupModList(&ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.SRBs_SetupMod_List, \
14101                &ueCb->f1UeDb->duUeCfg);
14102          if(ret != ROK)
14103          {
14104             DU_LOG( "\nERROR  -->  F1AP : Failed to build SRB setupmod List ");
14105             break;
14106          }
14107       }
14108
14109       freeF1UeDb(ueCb->f1UeDb);
14110       ueCb->f1UeDb = NULLP;
14111
14112       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14113
14114       /* Encode the F1SetupRequest type as APER */
14115       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14116       encBufSize = 0;
14117       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,encBuf);
14118
14119       /* Encode results */
14120       if(encRetVal.encoded == ENCODE_FAIL)
14121       {
14122          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Request structure (at %s)\n",\
14123                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14124          ret = RFAILED;
14125          break;
14126       }
14127       else
14128       {
14129          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Modification Response\n");
14130          for(int i=0; i< encBufSize; i++)
14131          {
14132             printf("%x",encBuf[i]);
14133          }
14134       }
14135
14136       /* Sending  msg  */
14137       if(sendF1APMsg() != ROK)
14138       {
14139          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Res Failed");
14140          ret = RFAILED;
14141          break;
14142       }
14143       break;
14144    }
14145    FreeUeContextModResp(f1apMsg);
14146    return ret;
14147 }
14148 /*******************************************************************
14149  *
14150  * @brief Deallocating the memory allocated by the aper decoder
14151  *          for QOSInfo
14152  *
14153  * @details
14154  *
14155  *    Function : freeAperDecodeQosInfo
14156  *
14157  *    Functionality:  Deallocating the memory allocated for QOSInfo
14158  *
14159  * @params[in] QoSFlowLevelQoSParameters_t *drbQos
14160  *
14161  * @return void
14162  *
14163  * ****************************************************************/
14164
14165 void freeAperDecodeQosInfo(QoSFlowLevelQoSParameters_t *drbQos)
14166 {
14167    if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI != NULLP)
14168    {
14169       if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
14170       {
14171          if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
14172          {
14173             free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
14174          }
14175          free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
14176       }
14177       free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI);
14178    }
14179 }
14180 /*******************************************************************
14181  *
14182  * @brief Deallocating the memory allocated by the aper decoder
14183  *          for UlTnlInfoforDrb
14184  *
14185  * @details
14186  *
14187  *    Function : freeAperDecodeUlTnlInfoforDrbSetupMod 
14188  *
14189  *    Functionality:  Deallocating memory allocated for UlTnlInfoforDrb
14190  *
14191  * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
14192  *
14193  * @return void
14194  *
14195  * ****************************************************************/
14196 void freeAperDecodeUlTnlInfoforDrbSetupMod(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
14197 {
14198    uint8_t arrIdx =0;
14199
14200    if(ulInfo->list.array)
14201    {
14202       for(arrIdx=0; arrIdx<ulInfo->list.count ; arrIdx++)
14203       {
14204          if(ulInfo->list.array[arrIdx])
14205          {
14206             if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel )
14207             {
14208                if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf)
14209                {
14210                   if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf)
14211                   {
14212                      free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
14213                            gTP_TEID.buf);
14214                   }
14215                   free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
14216                         transportLayerAddress.buf);
14217                }
14218                free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel);
14219             }
14220             free(ulInfo->list.array[arrIdx]);
14221          }
14222       }
14223       free(ulInfo->list.array);
14224    }
14225 }
14226 /*******************************************************************
14227  *
14228  * @brief Deallocating the memory allocated by the aper decoder
14229  *          for DrbSetupModItem  
14230  *
14231  * @details
14232  *
14233  *    Function : freeAperDecodeDrbSetupModItem 
14234  *
14235  *    Functionality:  Deallocating memory allocated for DrbSetupModItem
14236  *
14237  * @params[in] DRBs_ToBeSetupMod_Item_t *drbItem
14238  *
14239  * @return void
14240  *
14241  * ****************************************************************/
14242
14243 void freeAperDecodeDrbSetupModItem(DRBs_ToBeSetupMod_Item_t *drbItem)
14244 {
14245    uint8_t arrIdx =0;
14246    SNSSAI_t *snssai =NULLP;
14247    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
14248
14249    drbItem->qoSInformation.present = QoSInformation_PR_choice_extension;
14250    switch(drbItem->qoSInformation.present)
14251    {
14252       case QoSInformation_PR_NOTHING:
14253          break;
14254       case QoSInformation_PR_eUTRANQoS:
14255          {
14256             if(drbItem->qoSInformation.choice.eUTRANQoS)
14257             {
14258                free(drbItem->qoSInformation.choice.eUTRANQoS);
14259             }
14260             break;
14261          }
14262       case QoSInformation_PR_choice_extension:
14263          {
14264             if(drbItem->qoSInformation.choice.choice_extension)
14265             {
14266                freeAperDecodeQosInfo(&drbItem->qoSInformation.choice.choice_extension->value.choice.\
14267                      DRB_Information.dRB_QoS);
14268                snssai = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI;
14269                if(snssai->sST.buf)
14270                {
14271                   free(snssai->sST.buf);
14272                }
14273                if(snssai->sD)
14274                {
14275                   if(snssai->sD->buf)
14276                   {
14277                      free(snssai->sD->buf);
14278                   }
14279                   free(snssai->sD);
14280                }
14281
14282                flowMap = &drbItem->qoSInformation.choice.choice_extension->value.choice.\
14283                          DRB_Information.flows_Mapped_To_DRB_List;
14284                if(flowMap->list.array)
14285                {
14286                   for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
14287                   {
14288                      if(flowMap->list.array[arrIdx] )
14289                      {
14290                         freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
14291                         free(flowMap->list.array[arrIdx]);
14292                      }
14293                   }
14294                   free(flowMap->list.array);
14295                }
14296
14297                free(drbItem->qoSInformation.choice.choice_extension);
14298             }
14299             break;
14300          }
14301
14302    }
14303    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
14304    if(drbItem->uLConfiguration)
14305    {
14306       free(drbItem->uLConfiguration);
14307    }
14308 }
14309
14310 /*******************************************************************
14311  *
14312  * @brief Deallocating the memory allocated by the aper decoder
14313  *          for DrbToBeSetupModList
14314  *
14315  * @details
14316  *
14317  *    Function : freeAperDecodeDrbToBeSetupModList
14318  *
14319  *    Functionality:  Deallocating memory allocated for DrbToBeSetupModList
14320  *
14321  * @params[in] DRBs_ToBeSetupMod_List_t *drbSet
14322  *
14323  * @return void
14324  *
14325  * ****************************************************************/
14326
14327 void freeAperDecodeDrbToBeSetupModList(DRBs_ToBeSetupMod_List_t *drbSet)
14328 {
14329    uint8_t arrIdx =0;
14330    struct DRBs_ToBeSetupMod_ItemIEs *drbItemIe;
14331
14332    if(drbSet->list.array)
14333    {
14334       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
14335       {
14336          if(drbSet->list.array[arrIdx] != NULLP)
14337          {
14338             if(arrIdx == 0)
14339             {
14340                drbItemIe = (DRBs_ToBeSetupMod_ItemIEs_t *)drbSet->list.array[arrIdx];
14341                freeAperDecodeDrbSetupModItem(&(drbItemIe->value.choice.DRBs_ToBeSetupMod_Item));
14342             }
14343             free(drbSet->list.array[arrIdx]);
14344          }
14345       }
14346       free(drbSet->list.array);
14347    }
14348
14349 }
14350 /*******************************************************************
14351  *
14352  * @brief Deallocating the memory allocated by the aper decoder
14353  *          for UeContextModificationReqMsg
14354  *
14355  * @details
14356  *
14357  *    Function : freeAperDecodeUeContextModificationReqMsg
14358  *
14359  *    Functionality:  Deallocating memory allocated for
14360  *                  UeContextModificationReqMsg
14361  *
14362  * @params[in] UEContextModificationRequest_t *UeContextModifyReq
14363  *
14364  * @return void
14365  *
14366  * ****************************************************************/
14367 void freeAperDecodeUeContextModificationReqMsg(UEContextModificationRequest_t *UeContextModifyReq )
14368 {
14369    uint8_t arrIdx, ieId;
14370
14371    if(UeContextModifyReq->protocolIEs.list.array)
14372    {
14373       for( arrIdx = 0 ; arrIdx<UeContextModifyReq->protocolIEs.list.count ; arrIdx++)
14374       {
14375          if(UeContextModifyReq->protocolIEs.list.array[arrIdx])
14376          {
14377             ieId = UeContextModifyReq->protocolIEs.list.array[arrIdx]->id;
14378             switch(ieId)
14379             {
14380                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14381                   break;
14382                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14383                   break;
14384                case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
14385                   {
14386                      freeAperDecodeDrbToBeSetupModList(&UeContextModifyReq->protocolIEs.list.array[arrIdx]->\
14387                            value.choice.DRBs_ToBeSetupMod_List);
14388                      break;
14389                   }
14390             }
14391             free(UeContextModifyReq->protocolIEs.list.array[arrIdx]);
14392          }
14393       }
14394       free(UeContextModifyReq->protocolIEs.list.array);
14395    }
14396 }
14397 /*******************************************************************
14398  *
14399  * @brief processing the F1 UeContextModificationReq
14400  *
14401  * @details
14402  *
14403  *    Function : procF1UeContextModificationReq
14404  *
14405  *    Functionality:  processing the F1 UeContextModificationReq
14406  *
14407  * @params[in] F1AP_PDU_t *f1apMsg
14408  *
14409  * @return
14410  * ****************************************************************/
14411 uint8_t procF1UeContextModificationReq(F1AP_PDU_t *f1apMsg)
14412 {
14413    UEContextModificationRequest_t *ueContextModifyReq = NULLP;
14414    uint8_t  ret = ROK, ieIdx = 0, cellIdx=0, ueIdx=0;
14415    DuUeCb   *duUeCb = NULLP;
14416    DRBs_ToBeSetupMod_List_t *drbSetupModCfg;
14417    DRBs_ToBeModified_List_t *drbModifiedCfg;
14418    uint32_t gnbCuUeF1apId, gnbDuUeF1apId;
14419
14420    ueContextModifyReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextModificationRequest;
14421    for(ieIdx=0; (ieIdx < ueContextModifyReq->protocolIEs.list.count && ret == ROK); ieIdx++)
14422    {
14423       switch(ueContextModifyReq->protocolIEs.list.array[ieIdx]->id)
14424       {
14425          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14426             {
14427                gnbCuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
14428                break;
14429             }
14430          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14431             {
14432                gnbDuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
14433                for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
14434                {
14435                   if(duCb.actvCellLst[cellIdx])
14436                   {
14437                      for(ueIdx = 0; ueIdx < duCb.actvCellLst[cellIdx]->numActvUes; ueIdx++)
14438                      {
14439                         if((duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
14440                               (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId))
14441                         {
14442                            duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
14443                            if(duUeCb->f1UeDb == NULLP)
14444                            {
14445                               DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
14446                               duUeCb->f1UeDb->cellIdx = cellIdx;
14447                            }
14448                            break;
14449                         }
14450                      }
14451                   }
14452                }
14453                if(duUeCb == NULLP)
14454                {
14455                   DU_LOG("\nERROR  -->  DU APP : wrong values of gnbCuUeF1apId and gnbDuUeF1apId ");
14456                   ret = RFAILED;
14457                }
14458                break;
14459             }
14460          case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
14461          case ProtocolIE_ID_id_DRBs_ToBeModified_List:
14462             {
14463                if(duUeCb->f1UeDb)
14464                {
14465                   duUeCb->f1UeDb->actionType = UE_CTXT_MOD;
14466                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present ==\
14467                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List)
14468                   {
14469                      drbSetupModCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
14470                                       choice.DRBs_ToBeSetupMod_List;
14471
14472                      if(extractDrbListToSetupMod(NULL, drbSetupModCfg, NULL, drbSetupModCfg->list.count,\
14473                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULL))
14474                      {
14475                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbSetupModList");
14476                         ret = RFAILED;
14477                      }
14478                   }
14479
14480                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
14481                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List)
14482
14483                   {
14484                      drbModifiedCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
14485                                       choice.DRBs_ToBeModified_List;
14486                      if(extractDrbListToSetupMod(NULL, NULL, drbModifiedCfg, drbModifiedCfg->list.count,\
14487                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, &duUeCb->rlcUeCfg))
14488                      {
14489                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
14490                         ret = RFAILED;
14491                      }
14492                   }
14493                }
14494                break;
14495             }
14496          case ProtocolIE_ID_id_GNB_DUConfigurationQuery:
14497             {
14498                DU_LOG("\nINFO  -->  DU APP : Received GNB DU Configuration Query in UE Context Modification Request from CU");
14499                if(duUeCb->f1UeDb)
14500                {
14501                   duUeCb->f1UeDb->actionType = UE_CTXT_CFG_QUERY;
14502                }
14503                break;
14504             }
14505       }
14506    }
14507
14508    if(ret != RFAILED)
14509    {
14510       ret = duProcUeContextModReq(duUeCb);
14511    }
14512    freeAperDecodeUeContextModificationReqMsg(ueContextModifyReq);
14513    return ret; 
14514 }
14515
14516 /*****************************************************************i
14517 *
14518 * @brief Free memory allocated for UE Context Release Request
14519 *
14520 * @details
14521 *
14522 *    Function : FreeUeContextReleaseReq
14523 *
14524 *    Functionality:
14525 *         - Free memory allocated for UE Context Release Request
14526 *
14527 * @params[in] F1AP_PDU_t *f1apMsg
14528 * @return void 
14529 *
14530 * *************************************************************/
14531 void FreeUeContextReleaseReq(F1AP_PDU_t *f1apMsg)
14532 {
14533    uint8_t ieIdx;
14534    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
14535    
14536    if(f1apMsg)
14537    {
14538       if(f1apMsg->choice.initiatingMessage)
14539       {
14540          ueReleaseReq =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
14541          if(ueReleaseReq->protocolIEs.list.array)
14542          {
14543             for(ieIdx=0 ; ieIdx<ueReleaseReq->protocolIEs.list.count; ieIdx++)
14544             {
14545                DU_FREE(ueReleaseReq->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseRequest_t));
14546             }
14547             DU_FREE(ueReleaseReq->protocolIEs.list.array, ueReleaseReq->protocolIEs.list.size);
14548          }
14549          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14550       }
14551       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14552    }
14553
14554 }
14555 /*****************************************************************i
14556 *
14557 * @brief Build and Send UE Context Release Request  
14558 *
14559 * @details
14560 *
14561 *    Function : BuildAndSendUeContextReleaseReq
14562 *
14563 *    Functionality:
14564 *         - Build and Send UE Context Release Request 
14565 *
14566 * @params[in]
14567 * @return ROK     - success
14568 *         RFAILED - failure
14569 *
14570 * *************************************************************/
14571 uint8_t BuildAndSendUeContextReleaseReq(uint16_t cellId, uint8_t ueId)
14572 {
14573    bool memAllocFail = false;
14574    uint8_t ieIdx =0;
14575    uint8_t ret = RFAILED;
14576    uint16_t cellIdx =0;
14577    uint16_t crnti = 0;
14578    uint8_t  elementCnt = 0;
14579    uint32_t  gnbCuUeF1apId =0;   /* gNB-CU UE F1AP Id */
14580    uint32_t  gnbDuUeF1apId =0;   /* gNB-DU UE F1AP Id */
14581    asn_enc_rval_t encRetVal; 
14582    F1AP_PDU_t *f1apMsg = NULLP;
14583    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
14584
14585    DU_LOG("\nINFO  --> Building the UE Context Release Request");
14586    do
14587    {
14588       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14589       if(f1apMsg == NULLP)
14590       {
14591          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for f1apMsg");
14592          break;
14593       }
14594
14595       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
14596       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
14597       if(f1apMsg->choice.initiatingMessage == NULLP)
14598       {
14599          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for\
14600          initiatingMessage");   
14601          break;
14602       }
14603       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_UEContextReleaseRequest;
14604       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
14605       f1apMsg->choice.initiatingMessage->value.present = \
14606       InitiatingMessage__value_PR_UEContextReleaseRequest;
14607
14608       ueReleaseReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
14609
14610       elementCnt = 2;
14611
14612       ueReleaseReq->protocolIEs.list.count = elementCnt;
14613       ueReleaseReq->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseRequest_t *);
14614
14615       /* Initialize the F1Setup members */
14616       DU_ALLOC(ueReleaseReq->protocolIEs.list.array,ueReleaseReq->protocolIEs.list.size);
14617       if(ueReleaseReq->protocolIEs.list.array == NULLP)
14618       {
14619          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE array");
14620          break;
14621       }
14622       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
14623       {
14624          DU_ALLOC(ueReleaseReq->protocolIEs.list.array[ieIdx],\
14625                sizeof(UEContextReleaseRequest_t));
14626          if(ueReleaseReq->protocolIEs.list.array[ieIdx] == NULLP)
14627          {
14628             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE elements");
14629             memAllocFail = true;  
14630             break;
14631          }
14632       }
14633       if(memAllocFail == true)
14634          break;
14635
14636       /* Fetching Ue Cb Info*/
14637       GET_CELL_IDX(cellId, cellIdx);
14638       if(duCb.actvCellLst[cellIdx] == NULLP)
14639       {
14640          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): CellId[%d] does not exist", cellId);
14641          break;
14642       }
14643       else
14644       {
14645          GET_CRNTI(crnti, ueId);
14646          if(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].crnti != crnti)
14647          {
14648             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): crnti[%d] does not exist", crnti);
14649             break;
14650          }
14651          gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
14652          gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
14653       }
14654
14655       ieIdx=0; 
14656       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID; 
14657       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
14658       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present = \
14659       UEContextReleaseRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
14660       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
14661       
14662       ieIdx++;
14663       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14664       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
14665       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present =\
14666       UEContextReleaseRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
14667       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
14668       
14669       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14670
14671       /* Encode the F1SetupRequest type as APER */
14672       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14673       encBufSize = 0;
14674       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
14675       /* Encode results */
14676       if(encRetVal.encoded == ENCODE_FAIL)
14677       {
14678          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseRequest structure (at %s)\n",\
14679                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14680          break;
14681       }
14682       else
14683       {
14684          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseRequest\n");
14685          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
14686          {
14687             printf("%x",encBuf[ieIdx]);
14688          }
14689       }
14690
14691       /* Sending msg */
14692       if(sendF1APMsg() != ROK)
14693       {
14694          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Request failed");
14695          break;
14696       }
14697       ret = ROK;
14698       break;
14699    }while(true);
14700
14701    FreeUeContextReleaseReq(f1apMsg);
14702    return ret;
14703 }
14704 /*****************************************************************i
14705  *
14706  * @brief Free memory allocated for UE Context Release Complete
14707  *
14708  * @details
14709  *
14710  *    Function : FreeUeContextReleaseComplete
14711  *
14712  *    Functionality:
14713  *         - Free memory allocated for UE Context Release Complete
14714  *
14715  * @params[in] F1AP_PDU_t *f1apMsg
14716  * @return void
14717  *
14718  * *************************************************************/
14719 void FreeUeContextReleaseComplete(F1AP_PDU_t *f1apMsg)
14720 {
14721    uint8_t ieIdx;
14722    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
14723
14724    if(f1apMsg)
14725    {
14726       if(f1apMsg->choice.successfulOutcome)
14727       {
14728          ueReleaseComplete =&f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
14729          if(ueReleaseComplete->protocolIEs.list.array)
14730          {
14731             for(ieIdx=0 ; ieIdx<ueReleaseComplete->protocolIEs.list.count; ieIdx++)
14732             {
14733                DU_FREE(ueReleaseComplete->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseComplete_t));
14734             }
14735             DU_FREE(ueReleaseComplete->protocolIEs.list.array, ueReleaseComplete->protocolIEs.list.size);
14736          }
14737          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14738       }
14739       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14740    }
14741
14742 }
14743 /*****************************************************************i
14744  *
14745  * @brief Build and Send UE Context Release Complete
14746  *
14747  * @details
14748  *
14749  *    Function : BuildAndSendUeContextReleaseComplete
14750  *
14751  *    Functionality:
14752  *         - Build and Send UE Context Release Complete
14753  *
14754  * @params[in]  cellId,  gnbCuUeF1apId, gnbDuUeF1apId
14755  * @return ROK     - success
14756  *         RFAILED - failure
14757  *
14758  * *************************************************************/
14759 uint8_t BuildAndSendUeContextReleaseComplete(uint16_t cellId, uint32_t gnbCuUeF1apId, uint32_t gnbDuUeF1apId)
14760 {
14761    bool memAllocFail = false;
14762    uint8_t ieIdx =0, ret = RFAILED, elementCnt = 0;
14763    asn_enc_rval_t encRetVal;
14764    F1AP_PDU_t *f1apMsg = NULLP;
14765    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
14766
14767    DU_LOG("\nINFO  --> Building the UE Context Release Complete");
14768    do
14769    {
14770       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14771       if(f1apMsg == NULLP)
14772       {
14773          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for f1apMsg");
14774          break;
14775       }
14776
14777       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
14778       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14779       if(f1apMsg->choice.successfulOutcome == NULLP)
14780       {
14781          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for\
14782                successfulOutcome");
14783          break;
14784       }
14785       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextRelease;
14786       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
14787       f1apMsg->choice.successfulOutcome->value.present = \
14788       SuccessfulOutcome__value_PR_UEContextReleaseComplete;
14789
14790       ueReleaseComplete = &f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
14791
14792       elementCnt = 2;
14793       ueReleaseComplete->protocolIEs.list.count = elementCnt;
14794       ueReleaseComplete->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseComplete_t *);
14795
14796       /* Initialize the UE Release Complete members */
14797       DU_ALLOC(ueReleaseComplete->protocolIEs.list.array,ueReleaseComplete->protocolIEs.list.size);
14798       if(ueReleaseComplete->protocolIEs.list.array == NULLP)
14799       {
14800          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE array");
14801          break;
14802       }
14803       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
14804       {
14805          DU_ALLOC(ueReleaseComplete->protocolIEs.list.array[ieIdx],\
14806                sizeof(UEContextReleaseComplete_t));
14807          if(ueReleaseComplete->protocolIEs.list.array[ieIdx] == NULLP)
14808          {
14809             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE\
14810             elements");
14811             memAllocFail = true;
14812             break;
14813          }
14814       }
14815       if(memAllocFail == true)
14816          break;
14817
14818
14819       ieIdx=0;
14820       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
14821       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
14822       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present = \
14823       UEContextReleaseCompleteIEs__value_PR_GNB_CU_UE_F1AP_ID;
14824       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
14825
14826       ieIdx++;
14827       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14828       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
14829       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present =\
14830       UEContextReleaseCompleteIEs__value_PR_GNB_DU_UE_F1AP_ID;
14831       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
14832
14833       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14834
14835       /* Encode the F1SetupComplete type as APER */
14836       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14837       encBufSize = 0;
14838       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
14839       /* Encode results */
14840       if(encRetVal.encoded == ENCODE_FAIL)
14841       {
14842          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseComplete structure (at %s)\n",\
14843                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14844          break;
14845       }
14846       else
14847       {
14848          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseComplete\n");
14849          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
14850          {
14851             printf("%x",encBuf[ieIdx]);
14852          }
14853       }
14854
14855       /* Sending msg */
14856       if(sendF1APMsg() != ROK)
14857       {
14858          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Complete failed");
14859          break;
14860       }
14861       ret = ROK;
14862       break;
14863    }while(true);
14864    
14865    if(ret == ROK && duCb.actvCellLst[cellId-1] && (duCb.actvCellLst[cellId-1]->numActvUes == 0))
14866    {
14867       duCb.actvCellLst[cellId-1]->cellStatus = DELETION_IN_PROGRESS;
14868       ret = duSendCellDeletReq(cellId);
14869       if(ret != ROK)
14870       {
14871          DU_LOG("\nERROR  -->  F1AP: BuildAndSendUeContextReleaseComplete(): Failed to process cell\
14872                Delete req for CellId");
14873       }
14874    }
14875    FreeUeContextReleaseComplete(f1apMsg);
14876    return ret;
14877
14878 }
14879
14880 /*******************************************************************
14881 *
14882 * @brief added free part for the memory allocated by aper_decoder 
14883 *
14884 * @details
14885 *
14886 *    Function : freeAperDecodeUeContextReleaseCommand 
14887 *
14888 *    Functionality: added free part for the memory allocated by aper_decoder
14889 *
14890 * @params[in] F1AP_PDU_t *f1apMsg
14891 * @return void
14892 *
14893 * ****************************************************************/
14894 void freeAperDecodeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
14895 {
14896    uint8_t ieIdx=0;
14897    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
14898
14899    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
14900    
14901    if(ueContextReleaseCommand->protocolIEs.list.array)
14902    {
14903       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
14904       {
14905          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
14906          {
14907             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
14908             {
14909                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14910                   break;
14911                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14912                   break;
14913                case ProtocolIE_ID_id_Cause:
14914                   break;
14915                case ProtocolIE_ID_id_RRCContainer:
14916                {
14917                   if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
14918                   {
14919                      free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
14920                   }
14921                   break;
14922                }
14923                default :
14924                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
14925                        ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
14926                   break;
14927             }
14928          }
14929          free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]);
14930       }
14931       free(ueContextReleaseCommand->protocolIEs.list.array);
14932    }
14933 }
14934 /*******************************************************************
14935 *
14936 * @brief processing of UE Context Release Command
14937 *
14938 * @details
14939 *
14940 *    Function : procF1UeContextReleaseCommand 
14941 *
14942 *    Functionality: processing of UE Context Release Command
14943 *
14944 * @params[in] F1AP_PDU_t *f1apMsg
14945 * @return void
14946 *
14947 * ****************************************************************/
14948 uint8_t procF1UeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
14949 {
14950    uint8_t  ieIdx=0, ret=ROK, ueIdx=0;
14951    uint16_t cellIdx =0;
14952    bool ueIdxFound;
14953    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0;
14954    DuUeCb   *duUeCb = NULLP;
14955    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
14956
14957    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
14958
14959    if(ueContextReleaseCommand->protocolIEs.list.array)
14960    {
14961       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
14962       {
14963          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
14964          {
14965             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
14966             {
14967                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14968                   {
14969                      gnbCuUeF1apId= ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
14970                                     value.choice.GNB_CU_UE_F1AP_ID;
14971                      break;
14972                   }
14973
14974                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14975                   {
14976                      gnbDuUeF1apId = ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
14977                                      value.choice.GNB_DU_UE_F1AP_ID;
14978                      break;
14979                   }
14980
14981                case ProtocolIE_ID_id_Cause:
14982                   {
14983                      break;
14984                   }
14985
14986                case ProtocolIE_ID_id_RRCContainer:
14987                   {
14988                      for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
14989                      {
14990                         for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
14991                         {
14992                            if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
14993                                  (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId))
14994                            {
14995                               duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
14996                               DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
14997                               if(duUeCb->f1UeDb)
14998                               {
14999                                  memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
15000                                  duUeCb->f1UeDb->actionType = UE_CTXT_RELEASE;
15001                                  duUeCb->f1UeDb->cellIdx = cellIdx;
15002                                  /* Filling Dl RRC Msg Info */
15003                                  DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
15004                                  if(!duUeCb->f1UeDb->dlRrcMsg)
15005                                  {
15006                                     DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
15007                                     Memory allocation failed ");
15008                                     ret = RFAILED;
15009                                  }
15010                                  else
15011                                  {
15012                                     duUeCb->f1UeDb->dlRrcMsgPres = true;
15013                                     memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
15014                                     ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
15015                                           &ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
15016                                           value.choice.RRCContainer);
15017                                  }
15018
15019                               }
15020                               else
15021                               {
15022                                  DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
15023                                  Memory allocation failed ");
15024                                  ret = RFAILED;
15025
15026                               }
15027
15028                               ueIdxFound = true;
15029                               break;
15030                            }
15031                         }
15032                         if(ueIdxFound == true)
15033                         {
15034                            break;
15035                         }
15036                      }
15037                      if(!ueIdxFound)
15038                      {
15039                         DU_LOG("\nERROR  -->  F1AP: DuUeCb is not found at procF1UeContextReleaseCommand()");
15040                         ret = RFAILED;
15041                      }
15042
15043
15044                      break;
15045                   }
15046                default :
15047                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
15048                         ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
15049                   break;
15050             }
15051          }
15052       }
15053    }
15054    if(ret != RFAILED)
15055    {
15056       duProcUeContextReleaseCommand(duUeCb);
15057    }
15058    freeAperDecodeUeContextReleaseCommand(f1apMsg);
15059    return ret;
15060 }
15061 /**************************************************************
15062  *
15063  * @brief Handles received F1AP message and sends back response  
15064  *
15065  * @details
15066  *
15067  *    Function : F1APMsgHdlr
15068  *
15069  *    Functionality:
15070  *         - Decodes received F1AP control message
15071  *         - Prepares response message, encodes and sends to SCTP
15072  *
15073  * @params[in] 
15074  * @return ROK     - success
15075  *         RFAILED - failure
15076  *
15077  * ****************************************************************/
15078 void F1APMsgHdlr(Buffer *mBuf)
15079 {
15080    int i =0;
15081    char *recvBuf =NULLP;
15082    MsgLen copyCnt =0;
15083    MsgLen recvBufLen =0;
15084    F1AP_PDU_t *f1apMsg =NULLP;
15085    asn_dec_rval_t rval; /* Decoder return value */
15086    F1AP_PDU_t f1apasnmsg ;
15087    DU_LOG("\nINFO  -->  F1AP : Received F1AP message buffer");
15088    ODU_PRINT_MSG(mBuf, 0,0);
15089
15090    /* Copy mBuf into char array to decode it */
15091    ODU_GET_MSG_LEN(mBuf, &recvBufLen);
15092    DU_ALLOC(recvBuf, (Size)recvBufLen);
15093
15094    if(recvBuf == NULLP)
15095    {
15096       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed");
15097       return;
15098    }
15099    if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
15100    {
15101       DU_LOG("\nERROR   -->  F1AP : Failed while copying %d", copyCnt);
15102       return;
15103    }
15104
15105    printf("\nDEBUG   -->  F1AP : Received flat buffer to be decoded : ");
15106    for(i=0; i< recvBufLen; i++)
15107    {
15108       printf("%x",recvBuf[i]);
15109    }
15110
15111    /* Decoding flat buffer into F1AP messsage */
15112    f1apMsg = &f1apasnmsg;
15113    memset(f1apMsg, 0, sizeof(F1AP_PDU_t));
15114
15115    rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0);
15116
15117    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
15118    {
15119       DU_LOG("\nERROR  -->  F1AP : ASN decode failed");
15120       return;
15121    }
15122    printf("\n");
15123    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15124
15125    switch(f1apMsg->present)
15126    {
15127       case F1AP_PDU_PR_successfulOutcome:
15128          {
15129             switch(f1apMsg->choice.successfulOutcome->value.present)
15130             {
15131                case SuccessfulOutcome__value_PR_ResetAcknowledge:
15132                   {
15133                      DU_LOG("\nINFO   -->  F1AP : F1ResetAcknowledge is received successfully ");
15134                      break;
15135                   }
15136                case SuccessfulOutcome__value_PR_F1SetupResponse:
15137                   {                             
15138 #ifndef ODU_TEST_STUB
15139                      procF1SetupRsp(f1apMsg, recvBufLen, recvBuf);
15140 #endif
15141                      break;
15142                   }
15143
15144                case SuccessfulOutcome__value_PR_GNBDUConfigurationUpdateAcknowledge:
15145                   {
15146                      procF1GNBDUCfgUpdAck(f1apMsg);
15147                      break;
15148                   }
15149
15150                default:
15151                   {
15152                      DU_LOG("\nERROR  -->  F1AP : Invalid type of SuccessfulOutcome__value_PR_ResetAcknowledge [%d]",\
15153                            f1apMsg->choice.successfulOutcome->value.present);
15154                      return;
15155                   }
15156             }/* End of switch(successfulOutcome) */
15157             free(f1apMsg->choice.successfulOutcome);
15158             break;
15159          }
15160       case F1AP_PDU_PR_initiatingMessage:
15161          {
15162             switch(f1apMsg->choice.initiatingMessage->value.present)
15163             {
15164                case InitiatingMessage__value_PR_Reset:
15165                   {
15166                      procF1ResetReq(f1apMsg);
15167                      break;
15168                   }
15169                case InitiatingMessage__value_PR_DLRRCMessageTransfer:
15170                   {
15171                      procF1DlRrcMsgTrans(f1apMsg);
15172                      break;
15173                   }
15174                case InitiatingMessage__value_PR_UEContextSetupRequest:
15175                   {
15176                      procF1UeContextSetupReq(f1apMsg);
15177                      break;
15178                   }
15179                case InitiatingMessage__value_PR_UEContextModificationRequest:
15180                   {
15181                      procF1UeContextModificationReq(f1apMsg);
15182                      break;
15183                   }
15184                case InitiatingMessage__value_PR_UEContextReleaseCommand:
15185                   {
15186                       procF1UeContextReleaseCommand(f1apMsg);
15187                       break;
15188                   }
15189                default:
15190                   {
15191                      DU_LOG("\nERROR  -->  F1AP : Invalid type of F1AP_PDU_PR_initiatingMessage [%d]",
15192                            f1apMsg->choice.initiatingMessage->value.present);
15193                      return;
15194                   }
15195             }/* End of switch(initiatingMessage) */
15196             free(f1apMsg->choice.initiatingMessage);
15197             break;
15198          }
15199
15200       default:
15201          {
15202             DU_LOG("\nERROR  -->  F1AP : Invalid type of f1apMsg->present [%d]",f1apMsg->present);
15203             return;
15204          }
15205          free(f1apMsg);
15206
15207    }/* End of switch(f1apMsg->present) */
15208    
15209    DU_FREE(recvBuf, (Size)recvBufLen);
15210 } /* End of F1APMsgHdlr */
15211
15212 /**********************************************************************
15213   End of file
15214  **********************************************************************/