[Epic-ID: ODUHIGH-405][Task-ID: ODUHIGH-423]Filled ReconfigurationWithSync IE,
[o-du/l2.git] / src / du_app / du_f1ap_msg_hdl.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /* This file contains F1AP message handler functions */
20 #include "common_def.h"
21 #include "ckw.h"
22 #include "ckw.x"
23 #include "kwu.h"
24 #include "kwu.x"
25 #include "lkw.h"
26 #include "lrg.h"
27 #include "legtp.h"
28 #include "lkw.x"
29 #include "lrg.x"
30 #include "F1AP-PDU.h"
31 #include "du_app_mac_inf.h"
32 #include "du_cfg.h"
33 #include "du_app_rlc_inf.h"
34 #include "du_mgr_main.h"
35 #include "du_mgr.h"
36 #include "du_utils.h"
37 #include "du_ue_mgr.h"
38 #include "RAT-Type.h"
39 #include "FeatureSetUplinkPerCC.h"
40 #include "FeatureSetDownlinkPerCC.h"
41 #include "FeatureSets.h"
42 #include "UE-NR-Capability.h"
43 #include "UE-CapabilityRAT-Container.h"
44 #include "UE-CapabilityRAT-ContainerListRRC.h"
45 #include "GNB-DU-System-Information.h"
46 #include "CellGroupConfigRrc.h"
47 #include "MAC-CellGroupConfig.h"
48 #include "SchedulingRequestConfig.h"
49 #include "SchedulingRequestToAddMod.h"
50 #include "BSR-Config.h"
51 #include "TAG-Config.h"
52 #include "TAG.h"
53 #include "PHR-Config.h"
54 #include "RLC-Config.h"
55 #include "UL-AM-RLC.h"
56 #include "DL-AM-RLC.h"
57 #include "LogicalChannelConfig.h"
58 #include "RLC-BearerConfig.h"
59 #include "PhysicalCellGroupConfig.h"
60 #include "SpCellConfig.h"
61 #include "TDD-UL-DL-ConfigDedicated.h"
62 #include "ServingCellConfig.h"
63 #include "ControlResourceSet.h"
64 #include "SearchSpace.h"
65 #include "PDCCH-Config.h"
66 #include "PDSCH-TimeDomainResourceAllocation.h"
67 #include "PDSCH-TimeDomainResourceAllocationList.h"
68 #include "PDSCH-CodeBlockGroupTransmission.h"
69 #include "PDSCH-ServingCellConfig.h"
70 #include "DMRS-DownlinkConfig.h"
71 #include "PDSCH-Config.h"
72 #include "BWP-DownlinkDedicated.h"
73 #include "BWP-Downlink.h"
74 #include "PUSCH-TimeDomainResourceAllocation.h"
75 #include "PUSCH-TimeDomainResourceAllocationList.h"
76 #include "DMRS-UplinkConfig.h"
77 #include "PUSCH-Config.h"
78 #include "SRS-ResourceId.h"
79 #include "SRS-Resource.h"
80 #include "SRS-ResourceSet.h"
81 #include "SRS-Config.h"
82 #include "BWP-UplinkDedicated.h"
83 #include "PUSCH-ServingCellConfig.h"
84 #include "UplinkConfig.h"
85 #include "DUtoCURRCContainer.h"
86 #include "GBR-QoSFlowInformation.h"
87 #include "QoSFlowLevelQoSParameters.h"
88 #include "PUCCH-Config.h"
89 #include "PUCCH-ResourceSet.h"
90 #include "PUCCH-Resource.h"
91 #include "PUCCH-PowerControl.h"
92 #include "P0-PUCCH.h"
93 #include "PUCCH-PathlossReferenceRS.h"
94 #include "PUCCH-format0.h"
95 #include "PUCCH-format1.h"
96 #include "PUCCH-format2.h"
97 #include "PUCCH-format3.h"
98 #include "PUCCH-format4.h"
99 #include "PUCCH-FormatConfig.h"
100 #include "SchedulingRequestResourceConfig.h"
101 #include<ProtocolIE-Field.h>
102 #include "ProtocolExtensionField.h"
103 #include "odu_common_codec.h"
104 #include "du_mgr.h"
105 #include "du_cell_mgr.h"
106 #include "du_f1ap_msg_hdl.h"
107 #include "DRBs-Setup-Item.h"
108 #include "DLUPTNLInformation-ToBeSetup-List.h"
109 #include "DLUPTNLInformation-ToBeSetup-Item.h"
110 #include "UPTransportLayerInformation.h"
111 #include "GTPTunnel.h"
112 #include "SupportedSULFreqBandItem.h"
113 #include "du_e2ap_msg_hdl.h"
114 #include "du_f1ap_conversions.h"
115 #include "CNUEPagingIdentity.h"
116 #include "PCCH-Config.h"
117 #include "SCS-SpecificCarrier.h"
118 #include "FrequencyInfoDL.h"
119 #include "DownlinkConfigCommon.h"
120 #include "FrequencyInfoUL.h"
121 #include "UplinkConfigCommon.h"
122 #include "TDD-UL-DL-ConfigCommon.h"
123 #include "RACH-ConfigDedicated.h"
124 #include "CFRA-SSB-Resource.h"
125 #include "BWP-UplinkCommon.h"
126 #include "ReconfigurationWithSync.h"
127 #include "du_sys_info_hdl.h"
128
129 #ifdef O1_ENABLE
130 #include "CmInterface.h"
131 extern StartupConfig g_cfg;
132 #endif
133
134 DuCfgParams duCfgParam;
135
136 /******************************************************************
137  *
138  * @brief Function to fetch lcId based on DRB Id
139  *
140  * @details
141  *
142  *    Function : fetchLcId
143  *
144  *    @params[in] drbId
145  *
146  *    Functionality: Function to fetch lcId based on DRB Id
147  *
148  * Returns: lcId - SUCCESS
149  *          RFAILED - FAILURE
150  *****************************************************************/
151
152 uint8_t fetchLcId(uint8_t drbId)
153 {
154    uint8_t cellIdx = 0, ueIdx = 0, lcIdx = 0, numLcs = 0, lcId = 0;
155
156    for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
157    {
158       for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
159       {
160          if(duCb.actvCellLst[cellIdx] != NULLP)
161          {
162             numLcs = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg.numLcs;
163             for(lcIdx = 0; lcIdx < numLcs; lcIdx++)
164             {
165                if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg.rlcLcCfg[lcIdx].rbId == drbId && \
166                   duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg.rlcLcCfg[lcIdx].rbType == RB_TYPE_DRB)
167                {
168                   lcId = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].rlcUeCfg.rlcLcCfg[lcIdx].lcId;
169                   return lcId;
170                }
171             }
172          }
173       }
174    }
175    DU_LOG("\nERROR   -->  DU_APP: fetchLcId() failed for drbId %d", drbId);
176    return RFAILED;
177 }
178
179 /*******************************************************************
180 *
181 * @brief Adding F1AP pdu to reserved pdu list
182 *
183 * @details
184 *
185 *    Function : addToReservedF1apPduList 
186 *
187 *    Functionality: Adding F1AP pdu to reserved pdu list.
188 *     These pdu are awaiting aknowledgment from CU
189 *
190 * @params[in] uint8_t transId, F1AP_PDU_t *f1apMsg
191 *
192 * @return ROK - success
193 *         RFAILED - failure
194 *
195 * ****************************************************************/
196 void addToReservedF1apPduList(uint8_t transId, F1AP_PDU_t *f1apPdu)
197 {
198    CmLList         *node = NULLP;
199    ReservedF1apPduInfo *pduInfo = NULLP;
200    DU_ALLOC(pduInfo, sizeof(ReservedF1apPduInfo));
201    if(pduInfo)
202    {
203       DU_ALLOC(node, sizeof(CmLList));
204       if(node)
205       {
206          pduInfo->transId = transId;
207          pduInfo->f1apMsg = (void*) f1apPdu;
208
209          node->node = (PTR)pduInfo;
210          cmLListAdd2Tail(&duCb.reservedF1apPduList, node);
211       }
212    }
213 }
214
215 /*******************************************************************
216 *
217 * @brief searching for F1AP pdu from ReservedF1apPduList 
218 *
219 * @details
220 *
221 *    Function : searchFromReservedF1apPduList 
222 *
223 *    Functionality: searching for F1AP pdu information
224 *
225 * @params[in] uint8_t transId
226 *
227 * @return pointer to F1AP_PDU_t
228 *
229 * ****************************************************************/
230
231 CmLList *searchFromReservedF1apPduList(uint8_t transId)
232 {
233    CmLList         *node;
234    ReservedF1apPduInfo *f1apPdu;
235    if(duCb.reservedF1apPduList.count)
236    {
237       CM_LLIST_FIRST_NODE(&duCb.reservedF1apPduList, node);
238       while(node)
239       {
240          f1apPdu = (ReservedF1apPduInfo*)node->node;
241          if(f1apPdu->transId == transId)
242          {
243             return node;
244          }
245          node = node->next;
246       }
247    }
248    return NULL;
249 }
250
251 /*******************************************************************
252 *
253 * @brief deleting F1AP pdu information from ReservedF1apPduList
254 *
255 * @details
256 *
257 *    Function : deleteFromReservedF1apPduList 
258 *
259 *    Functionality: deleting pdu information from ReservedF1apPduList
260 *
261 * @params[in] CmLList *node 
262 *
263 * @return void 
264 *
265 * ****************************************************************/
266
267 void deleteFromReservedF1apPduList(CmLList *node)
268 {
269    ReservedF1apPduInfo *f1apPdu;
270
271    if(node != NULL)
272    {
273       f1apPdu = (ReservedF1apPduInfo *)node->node;
274       cmLListDelFrm(&duCb.reservedF1apPduList, node);
275       DU_FREE(f1apPdu, sizeof(ReservedF1apPduInfo));
276       DU_FREE(node, sizeof(CmLList));
277       node = NULL;
278    }
279 }
280
281 /*******************************************************************
282  *
283  * @brief Builds Uplink Info for NR 
284  *
285  * @details
286  *
287  *    Function : BuildULNRInfo
288  *
289  *    Functionality: Building NR Uplink Info
290  *
291  * @params[in] NRFreqInfo_t *ulnrfreq
292  * @return ROK     - success
293  *         RFAILED - failure
294  *
295  * ****************************************************************/
296 uint8_t BuildULNRInfo(NRFreqInfo_t *ulnrfreq)
297 {
298    uint8_t idx=0;
299    ulnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
300                        fdd.ulNrFreqInfo.nrArfcn;
301    ulnrfreq->freqBandListNr.list.count = 1;
302    ulnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
303    DU_ALLOC(ulnrfreq->freqBandListNr.list.array,ulnrfreq->freqBandListNr.list.size);
304    if(ulnrfreq->freqBandListNr.list.array == NULLP)
305    {
306       return RFAILED;
307    }
308    for(idx=0;idx<ulnrfreq->freqBandListNr.list.count;idx++)
309    {
310       DU_ALLOC(ulnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
311       if(ulnrfreq->freqBandListNr.list.array[idx] == NULLP)
312       {
313          return RFAILED;
314       }
315    }
316    ulnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
317                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
318                                                                  freqBand[0].nrFreqBand;
319    ulnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
320    return ROK;
321 }
322 /*******************************************************************
323  *
324  * @brief Builds Downlink NR Info 
325  *
326  * @details
327  *
328  *    Function : BuildDLNRInfo
329  *
330  *    Functionality: Building Downlink NR Info
331  *    
332  * @params[in] NRFreqInfo_t *dlnrfreq
333  * @return ROK     - success
334  *         RFAILED - failure
335  *
336  * ****************************************************************/
337 uint8_t BuildDLNRInfo(NRFreqInfo_t *dlnrfreq)
338 {
339    uint8_t idx=0;
340    dlnrfreq->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.\
341                        fdd.dlNrFreqInfo.nrArfcn;
342    dlnrfreq->freqBandListNr.list.count = 1;
343    dlnrfreq->freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
344    DU_ALLOC(dlnrfreq->freqBandListNr.list.array,dlnrfreq->freqBandListNr.list.size);
345    if(dlnrfreq->freqBandListNr.list.array == NULLP)
346    {
347       return RFAILED;   
348    }
349    for(idx=0;idx< dlnrfreq->freqBandListNr.list.count;idx++)
350    {
351       DU_ALLOC(dlnrfreq->freqBandListNr.list.array[idx],sizeof(FreqBandNrItem_t));
352       if(dlnrfreq->freqBandListNr.list.array[idx] == NULLP)
353       {
354          return RFAILED;
355       }
356    }   
357    dlnrfreq->freqBandListNr.list.array[0]->freqBandIndicatorNr = \
358                                                                  duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
359                                                                  freqBand[0].nrFreqBand;
360    dlnrfreq->freqBandListNr.list.array[0]->supportedSULBandList.list.count = SUL_BAND_COUNT;
361
362    return ROK;
363 }
364
365 /*******************************************************************
366  *
367  * @brief Builds NRCell ID 
368  *
369  * @details
370  *
371  *    Function : BuildNrCellId
372  *
373  *    Functionality: Building the NR Cell ID
374  *
375  * @params[in] BIT_STRING_t *nrcell
376  * @return ROK     - success
377  *         RFAILED - failure
378  *
379  * ****************************************************************/
380
381 S16 BuildNrCellId(BIT_STRING_t *nrcell)
382 {
383    memset(nrcell->buf, 0, nrcell->size);
384    nrcell->buf[4]   = duCfgParam.sib1Params.cellIdentity; 
385    nrcell->bits_unused = 4;
386    return ROK;
387 }
388
389 /*******************************************************************
390  *
391  * @brief Builds Nrcgi 
392  *
393  * @details
394  *
395  *    Function : BuildNrcgi
396  *
397  *    Functionality: Building the PLMN ID and NR Cell id
398  *
399  * @params[in] NRCGI_t *nrcgi
400  * @return ROK     - success
401  *         RFAILED - failure
402  *
403  * ****************************************************************/
404 uint8_t BuildNrcgi(NRCGI_t *nrcgi)
405 {
406    uint8_t ret;
407    uint8_t byteSize = 5;
408    /* Allocate Buffer Memory */
409    nrcgi->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
410    DU_ALLOC(nrcgi->pLMN_Identity.buf, nrcgi->pLMN_Identity.size);
411    if(nrcgi->pLMN_Identity.buf == NULLP)
412    {
413       return RFAILED;
414    }
415    ret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
416          nrcgi->pLMN_Identity.buf); // Building PLMN function
417    if(ret != ROK)
418    {
419       return RFAILED;
420    }
421    /*nrCellIdentity*/
422    nrcgi->nRCellIdentity.size = byteSize * sizeof(uint8_t);
423    DU_ALLOC(nrcgi->nRCellIdentity.buf, nrcgi->nRCellIdentity.size); 
424    if(nrcgi->nRCellIdentity.buf == NULLP)
425    {
426       return RFAILED;
427    }
428    BuildNrCellId(&nrcgi->nRCellIdentity);
429
430    return ROK;
431 }
432 /*******************************************************************
433  *
434  * @brief Builds FiveGStac 
435  *
436  * @details
437  *
438  *    Function : BuildFiveGSTac
439  *
440  *    Functionality: Building the FiveGSTac
441  *
442  * @params[in] OCTET_STRING_t *fivegsTac
443  * @return ROK     - success
444  *         RFAILED - failure
445  *
446  * ****************************************************************/
447 uint8_t BuildFiveGSTac(Served_Cell_Information_t *servcell)
448 {
449    DU_ALLOC(servcell->fiveGS_TAC,sizeof(FiveGS_TAC_t));
450    if(servcell->fiveGS_TAC == NULLP)
451    {
452       return RFAILED;
453    }
454    servcell->fiveGS_TAC->size = 3 * sizeof(uint8_t);
455    DU_ALLOC(servcell->fiveGS_TAC->buf,\
456          sizeof(servcell->fiveGS_TAC->size));
457    if(servcell->fiveGS_TAC->buf == NULLP)
458    {
459       return RFAILED;
460    }
461    servcell->fiveGS_TAC->buf[0] = 0;
462    servcell->fiveGS_TAC->buf[1] = 0;
463    servcell->fiveGS_TAC->buf[2] = duCfgParam.srvdCellLst[0].duCellInfo.tac;
464    return ROK;  
465 }
466
467 /*******************************************************************
468  *
469  * @brief fill nr frequency information
470  *
471  * @details
472  *
473  *    Function : fillNrTddInfo 
474  *
475  *    Functionality: fill nr frequency information
476  *
477  * @params[in] NRFreqInfo_t freqInfo
478  * @return ROK     - success
479  *         RFAILED - failure
480  *
481  * ****************************************************************/
482 uint8_t fillNrTddInfo(TDD_Info_t *tddInfo)
483 {
484    uint8_t elementCnt = 1, freqBandListIdx = 0, supportedBandIdx = 0;
485    NRFreqInfo_t *freqInfo = NULLP;
486
487    if(tddInfo == NULLP)
488    {
489       DU_LOG("\nERROR  --> DU APP : Null pointer received at fillNrTddInfo");
490       return RFAILED;
491    }
492    
493    freqInfo = &tddInfo->nRFreqInfo;
494    freqInfo->nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.nrArfcn; 
495
496    freqInfo->freqBandListNr.list.count = elementCnt; 
497    freqInfo->freqBandListNr.list.size = freqInfo->freqBandListNr.list.count  * sizeof(FreqBandNrItem_t *);
498    DU_ALLOC(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
499    if(!freqInfo->freqBandListNr.list.array)
500    {
501       DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
502       return RFAILED;
503    }
504
505    for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
506    {
507       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
508       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx])
509       {
510          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
511          return RFAILED;
512       }
513
514       freqInfo->freqBandListNr.list.array[freqBandListIdx]->freqBandIndicatorNr = duCfgParam.srvdCellLst[0].duCellInfo.\
515       f1Mode.mode.tdd.nrFreqInfo.freqBand[0].nrFreqBand;
516       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count = elementCnt;
517       freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size = freqInfo->freqBandListNr.list.array[freqBandListIdx]->\
518       supportedSULBandList.list.count * sizeof(SupportedSULFreqBandItem_t*);
519
520       DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
521             freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
522       if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
523       {
524          DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
525          return RFAILED;
526       }
527
528       for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
529       {
530          DU_ALLOC(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
531                sizeof(SupportedSULFreqBandItem_t));
532          if(!freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx])
533          {
534             DU_LOG("\nERROR  --> DU APP : Memory allocation failed at fillNrTddInfo");
535             return RFAILED;
536          }
537
538          freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx]->freqBandIndicatorNr =\
539          duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[0].sulBand[0];
540       }
541    }
542
543    tddInfo->transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrScs;
544    tddInfo->transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrb;
545
546    return ROK;
547 }
548
549 /*******************************************************************
550  *
551  * @brief Builds NR Mode 
552  *
553  * @details
554  *
555  *    Function : BuildNrMode
556  *
557  *    Functionality: Building the NR Mode
558  *
559  * @params[in] NR_Mode_Info_t *fdd
560  * @return ROK     - success
561  *         RFAILED - failure
562  *
563  * ****************************************************************/
564 uint8_t BuildNrMode(NR_Mode_Info_t *mode)
565 {
566    uint8_t BuildDLNRInforet=0;
567    uint8_t BuildULNRInforet=0; 
568    
569 #ifdef NR_TDD
570    mode->present = NR_Mode_Info_PR_tDD;
571 #else
572    mode->present = NR_Mode_Info_PR_fDD;
573 #endif   
574    
575    if(mode->present == NR_Mode_Info_PR_fDD)
576    {
577       DU_ALLOC(mode->choice.fDD,sizeof(FDD_Info_t));
578       if(mode->choice.fDD == NULLP)
579       {
580          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
581          return RFAILED;
582       }
583       BuildULNRInforet = BuildULNRInfo(&mode->choice.fDD->uL_NRFreqInfo);
584       if(BuildULNRInforet != ROK)
585       {
586          DU_LOG("\nERROR  --> Failed to build UlNrFreqInfo");
587          return RFAILED;    
588       }
589       BuildDLNRInforet = BuildDLNRInfo(&mode->choice.fDD->dL_NRFreqInfo);
590       if(BuildDLNRInforet != ROK)
591       {
592          DU_LOG("\nERROR  --> Failed to build DlNrFreqInfo");
593          return RFAILED;
594       }
595       mode->choice.fDD->uL_Transmission_Bandwidth.nRSCS = \
596                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
597                                                           f1Mode.mode.fdd.ulTxBw.nrScs;
598       mode->choice.fDD->uL_Transmission_Bandwidth.nRNRB = \
599                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
600                                                           f1Mode.mode.fdd.ulTxBw.nrb;
601       mode->choice.fDD->dL_Transmission_Bandwidth.nRSCS = \
602                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
603                                                           f1Mode.mode.fdd.dlTxBw.nrScs;
604       mode->choice.fDD->dL_Transmission_Bandwidth.nRNRB = \
605                                                           duCfgParam.srvdCellLst[0].duCellInfo.\
606                                                           f1Mode.mode.fdd.dlTxBw.nrb;
607    }
608    else if(mode->present == NR_Mode_Info_PR_tDD) 
609    {
610       DU_ALLOC(mode->choice.tDD,sizeof(TDD_Info_t));
611       if(mode->choice.tDD == NULLP)
612       {
613          DU_LOG("\nERROR  --> Memory allocation failed in BuildNrMode");
614          return RFAILED;
615       }
616
617       if(fillNrTddInfo(mode->choice.tDD) != ROK)
618       {
619          DU_LOG("\nERROR  --> Failed to fill Nr TDD information");
620          return RFAILED;
621       }
622
623    }
624
625    return ROK;
626 }
627 /*******************************************************************
628  *
629  * @brief Builds IE Extensions for Served PLMNs 
630  *
631  * @details
632  *
633  *    Function : BuildExtensions
634  *
635  *    Functionality: Building the IE Extensions
636  *
637  * @params[in] struct ProtocolExtensionContainer_4624P3 *buildextend
638  * @return ROK     - success
639  *         RFAILED - failure
640  *
641  * ****************************************************************/
642 uint8_t BuildExtensions(ProtocolExtensionContainer_4624P3_t **ieExtend)
643 {
644    uint8_t idx=0, plmnidx=0, sliceLstIdx=0;
645    uint8_t elementCnt=0, extensionCnt=0;
646
647    extensionCnt=IE_EXTENSION_LIST_COUNT;
648    DU_ALLOC(*ieExtend,sizeof(ProtocolExtensionContainer_4624P3_t));
649    if((*ieExtend) == NULLP)
650    {
651       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
652       return RFAILED;
653    }
654    (*ieExtend)->list.count = extensionCnt;
655    (*ieExtend)->list.size = \
656                             extensionCnt * sizeof(ServedPLMNs_ItemExtIEs_t *);
657    DU_ALLOC((*ieExtend)->list.array,(*ieExtend)->list.size);
658    if((*ieExtend)->list.array == NULLP)
659    {
660       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
661       return RFAILED;
662    }
663    for(plmnidx=0;plmnidx<extensionCnt;plmnidx++)
664    {
665       DU_ALLOC((*ieExtend)->list.array[plmnidx],\
666             sizeof(ServedPLMNs_ItemExtIEs_t));
667       if((*ieExtend)->list.array[plmnidx] == NULLP)
668       {
669          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
670          return RFAILED;
671       }
672    }
673    
674    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices;
675    idx = 0;
676    (*ieExtend)->list.array[idx]->id = ProtocolIE_ID_id_TAISliceSupportList;
677    (*ieExtend)->list.array[idx]->criticality = Criticality_ignore;
678    (*ieExtend)->list.array[idx]->extensionValue.present = \
679    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
680    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
681       list.count = elementCnt;
682    (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
683       list.size = (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
684       list.count * sizeof(SliceSupportItem_t *);
685
686    DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
687          list.array, elementCnt * sizeof(SliceSupportItem_t *));
688    if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
689          list.array == NULLP)
690    {
691       DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
692       return RFAILED;
693    }
694
695    for(sliceLstIdx =0; sliceLstIdx<elementCnt; sliceLstIdx++)
696    {
697       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
698             list.array[sliceLstIdx],sizeof(SliceSupportItem_t));
699       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
700             list.array[sliceLstIdx] == NULLP) 
701       {
702          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
703          return RFAILED;
704       }
705       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
706          list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
707       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
708             .list.array[sliceLstIdx]->sNSSAI.sST.buf,(*ieExtend)->list.array[idx]->\
709             extensionValue.choice.SliceSupportList.\
710             list.array[sliceLstIdx]->sNSSAI.sST.size);
711       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList\
712             .list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
713       {
714          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
715          return RFAILED;
716       }
717       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
718          list.array[sliceLstIdx]->sNSSAI.sST.buf[0] = duCfgParam.srvdCellLst[0].duCellInfo.\
719          cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
720       
721       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
722             list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
723       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
724             list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
725       {
726          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
727          return RFAILED;
728       }
729       (*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
730          list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
731       DU_ALLOC((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
732             list.array[sliceLstIdx]->sNSSAI.sD->buf, (*ieExtend)->list.array[idx]->extensionValue.choice.\
733             SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
734       if((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
735             list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
736       {
737          DU_LOG("ERROR  --> DU_APP : BuildExtensions(): Memory allocation failed");
738          return RFAILED;
739       }
740       memcpy((*ieExtend)->list.array[idx]->extensionValue.choice.SliceSupportList.\
741       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[0].duCellInfo.\
742       cellInfo.srvdPlmn[0].taiSliceSuppLst.snssai[sliceLstIdx]->sd, (*ieExtend)->list.array[idx]->\
743       extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->sNSSAI.sD->size);
744    }
745    return ROK;
746 }
747 /*******************************************************************
748  *
749  * @brief Builds Served PLMN 
750  *
751  * @details
752  *
753  *    Function : BuildServedPlmn
754  *
755  *    Functionality: Building the Served PLMN
756  *
757  * @params[in] GNB_DU_Served_Cells_Item_t *srvCellItem
758  * @return ROK     - success
759  *         RFAILED - failure
760  *
761  * ****************************************************************/
762 uint8_t  BuildServedPlmn(ServedPLMNs_List_t *srvplmn)
763 {  
764    uint8_t  plmnidx;
765    uint8_t  servPlmnCnt=1;
766    uint8_t buildPlmnIdret=0;
767    uint8_t BuildExtensionsret=0;
768    srvplmn->list.count = servPlmnCnt;
769    srvplmn->list.size = \
770                         servPlmnCnt*sizeof(ServedPLMNs_Item_t *);
771    DU_ALLOC(srvplmn->list.array,srvplmn->list.size);
772    if(srvplmn->list.array == NULLP)
773    {
774       return RFAILED;
775    }
776    for(plmnidx=0; plmnidx<servPlmnCnt; plmnidx++)
777    {   
778       DU_ALLOC(srvplmn->list.array[plmnidx],\
779             sizeof(ServedPLMNs_Item_t));
780       if(srvplmn->list.array[plmnidx] == NULLP)
781       {
782          return RFAILED;
783       }  
784    }
785    srvplmn->list.array[0]->pLMN_Identity.size = PLMN_SIZE * sizeof(uint8_t);
786    DU_ALLOC(srvplmn->list.array[0]->pLMN_Identity.buf, srvplmn->list.array[0]->pLMN_Identity.size);
787    buildPlmnIdret = buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
788          srvplmn->list.array[0]->pLMN_Identity.buf);
789    if(buildPlmnIdret!= ROK)
790    {
791       return RFAILED;
792    }
793    BuildExtensionsret = BuildExtensions(&srvplmn->list.array[0]->iE_Extensions);
794    if(BuildExtensionsret!= ROK)
795    {
796       return RFAILED;
797    }
798    return ROK;
799 }
800 /*******************************************************************
801  *
802  * @brief Builds Served Cell List
803  *
804  * @details
805  *
806  *    Function : BuildServedCellList
807  *
808  *    Functionality: Building Served Cell List
809  *
810  * @params[in] PLMNID plmn
811  * @return ROK     - success
812  *         RFAILED - failure
813  *
814  * ****************************************************************/
815
816 uint8_t BuildServedCellList(GNB_DU_Served_Cells_List_t *duServedCell)
817 {
818    uint8_t  BuildNrcgiret=0;
819    uint8_t  BuildFiveGSTacret=0;
820    uint8_t  BuildServedPlmnret=0;
821    uint8_t  BuildNrModeret=0;
822    uint8_t  idx;
823    uint8_t  plmnidx;
824    uint8_t  plmnCnt=1;
825    GNB_DU_Served_Cells_Item_t *srvCellItem;
826    duServedCell->list.size = plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t *);
827    duServedCell->list.count = plmnCnt;
828
829    DU_ALLOC(duServedCell->list.array, duServedCell->list.size);
830    if(duServedCell->list.array == NULLP)
831    {
832       return RFAILED;
833    }
834    for(plmnidx=0; plmnidx<plmnCnt; plmnidx++)
835    {
836       DU_ALLOC(duServedCell->list.array[plmnidx],\
837             sizeof(GNB_DU_Served_Cells_ItemIEs_t));
838       if(duServedCell->list.array[plmnidx] == NULLP)
839       {
840          return RFAILED;
841       }
842    }
843    idx = 0;
844    duServedCell->list.array[idx]->id = ProtocolIE_ID_id_GNB_DU_Served_Cells_Item;
845    duServedCell->list.array[idx]->criticality = Criticality_reject;
846    duServedCell->list.array[idx]->value.present = \
847                                                   GNB_DU_Served_Cells_ItemIEs__value_PR_GNB_DU_Served_Cells_Item;
848    srvCellItem = \
849                  &duServedCell->list.array[idx]->value.choice.GNB_DU_Served_Cells_Item;
850    /*nRCGI*/
851    BuildNrcgiret = BuildNrcgi(&srvCellItem->served_Cell_Information.nRCGI);
852    if(BuildNrcgiret != ROK)
853    {
854       return RFAILED;
855    }
856    /*nRPCI*/
857    srvCellItem->served_Cell_Information.nRPCI = \
858                                                 duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
859
860    /*fiveGS_TAC*/
861    BuildFiveGSTacret = BuildFiveGSTac(&srvCellItem->served_Cell_Information);
862    if(BuildFiveGSTacret != ROK)
863    {
864       return RFAILED;
865    }
866    /*Served PLMNs*/
867    BuildServedPlmnret = BuildServedPlmn(&srvCellItem->served_Cell_Information.servedPLMNs);
868    if(BuildServedPlmnret !=ROK)
869    {
870       return RFAILED;
871    }
872    /*nR Mode Info with FDD*/
873    BuildNrModeret = BuildNrMode(&srvCellItem->served_Cell_Information.nR_Mode_Info);
874    if(BuildNrModeret != ROK)
875    {
876       return RFAILED;
877    }
878    /*Measurement timing Config*/
879    srvCellItem->served_Cell_Information.measurementTimingConfiguration.\
880       size = sizeof(uint8_t);
881    DU_ALLOC(srvCellItem->served_Cell_Information.\
882          measurementTimingConfiguration.buf,srvCellItem->served_Cell_Information.measurementTimingConfiguration.size);
883    if(srvCellItem->served_Cell_Information.\
884          measurementTimingConfiguration.buf == NULLP)
885    {
886       return RFAILED;
887    }
888    srvCellItem->served_Cell_Information.measurementTimingConfiguration.buf[0] = \
889                                                                                 duCfgParam.srvdCellLst[0].duCellInfo.measTimeCfg;
890
891    /* GNB DU System Information */
892    DU_ALLOC(srvCellItem->gNB_DU_System_Information,
893          sizeof(GNB_DU_System_Information_t));
894    if(!srvCellItem->gNB_DU_System_Information)
895    {
896       return RFAILED;
897    }
898    /* MIB */
899    srvCellItem->gNB_DU_System_Information->mIB_message.size = duCfgParam.srvdCellLst[0].duSysInfo.mibLen;
900    DU_ALLOC(srvCellItem->gNB_DU_System_Information->mIB_message.buf,
901          srvCellItem->gNB_DU_System_Information->mIB_message.size);
902    if(!srvCellItem->gNB_DU_System_Information->mIB_message.buf)
903    {
904       return RFAILED;
905    }
906    memcpy(srvCellItem->gNB_DU_System_Information->mIB_message.buf, duCfgParam.srvdCellLst[0].duSysInfo.mibMsg, \
907                    srvCellItem->gNB_DU_System_Information->mIB_message.size);
908
909    /* SIB1 */
910    srvCellItem->gNB_DU_System_Information->sIB1_message.size =\
911                                                               duCfgParam.srvdCellLst[0].duSysInfo.sib1Len;
912
913    DU_ALLOC(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,
914          srvCellItem->gNB_DU_System_Information->sIB1_message.size);
915    if(!srvCellItem->gNB_DU_System_Information->sIB1_message.buf)
916    {
917       return RFAILED;
918    }
919    for(int x=0; x<srvCellItem->gNB_DU_System_Information->sIB1_message.size; x++)
920    {
921       srvCellItem->gNB_DU_System_Information->sIB1_message.buf[x]=\
922                                                                   duCfgParam.srvdCellLst[0].duSysInfo.sib1Msg[x];
923    }
924    return ROK; 
925 }                                                                                                                  
926 /*******************************************************************
927  *
928  * @brief Builds RRC Version 
929  *
930  * @details
931  *
932  *    Function : BuildRrcVer
933  *
934  *    Functionality: Building RRC Version
935  *
936  * @params[in] int idx,int elementCnt,RRC_Version_t *rrcver
937  * @return ROK     - success
938  *         RFAILED - failure
939  *
940  * ****************************************************************/
941 uint8_t BuildRrcVer(RRC_Version_t *rrcVer)
942 {
943    uint8_t rrcExt;
944    uint8_t rrcLatest;
945    rrcVer->latest_RRC_Version.size = sizeof(uint8_t);
946    DU_ALLOC(rrcVer->latest_RRC_Version.buf,sizeof(uint8_t));
947    if(rrcVer->latest_RRC_Version.buf == NULLP)
948    {
949       return RFAILED;
950    }
951    rrcVer->latest_RRC_Version.buf[0] = 0;
952    rrcVer->latest_RRC_Version.bits_unused = 5;
953    DU_ALLOC(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
954    if(rrcVer->iE_Extensions == NULLP)
955    {  
956       return RFAILED;
957    }
958    rrcVer->iE_Extensions->list.count = 1;
959    rrcVer->iE_Extensions->list.size = sizeof(RRC_Version_ExtIEs_t *);
960    DU_ALLOC(rrcVer->iE_Extensions->list.array,rrcVer->iE_Extensions->list.size);
961    if(rrcVer->iE_Extensions->list.array == NULLP)
962    {
963       return RFAILED;
964    }
965    rrcExt = 0;
966    DU_ALLOC(rrcVer->iE_Extensions->list.array[0],\
967          sizeof(RRC_Version_ExtIEs_t));
968    if(rrcVer->iE_Extensions->list.array[0] == NULLP)
969    {
970       return RFAILED;
971    }
972    rrcVer->iE_Extensions->list.array[rrcExt]->id = \
973                                                    ProtocolIE_ID_id_latest_RRC_Version_Enhanced;
974    rrcVer->iE_Extensions->list.array[rrcExt]->criticality = Criticality_reject;
975    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.present =\
976                                                                       RRC_Version_ExtIEs__extensionValue_PR_Latest_RRC_Version_Enhanced;
977    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
978       .Latest_RRC_Version_Enhanced.size = 3*sizeof(uint8_t);
979    DU_ALLOC(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
980          .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
981          array[rrcExt]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
982    if(rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice\
983          .Latest_RRC_Version_Enhanced.buf == NULLP)
984    {
985       return RFAILED;
986    }
987    rrcLatest = 0;
988    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
989       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 15;
990    rrcLatest++;
991    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
992       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 5;
993    rrcLatest++;
994    rrcVer->iE_Extensions->list.array[rrcExt]->extensionValue.choice.\
995       Latest_RRC_Version_Enhanced.buf[rrcLatest] = 0;
996    return ROK;
997 }
998 /*******************************************************************
999  *
1000  * @brief Sends F1 msg over SCTP
1001  *
1002  * @details
1003  *
1004  *    Function : sendF1APMsg
1005  *
1006  *    Functionality: Sends F1 msg over SCTP
1007  *
1008  * @params[in] Region region
1009  *             Pool pool
1010  * @return ROK     - success
1011  *         RFAILED - failure
1012  *
1013  * ****************************************************************/
1014 uint8_t sendF1APMsg()
1015 {
1016    Buffer *mBuf = NULLP;
1017   
1018    if(ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) == ROK)
1019    {
1020       if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
1021       {
1022             ODU_PRINT_MSG(mBuf, 0,0);
1023
1024             if(sctpSend(mBuf, F1_INTERFACE) != ROK)
1025             {
1026                DU_LOG("\nERROR  -->  F1AP : SCTP Send failed");
1027                ODU_PUT_MSG_BUF(mBuf);
1028                return RFAILED;
1029             }
1030       }
1031       else
1032       {
1033          DU_LOG("\nERROR  -->  F1AP : ODU_ADD_POST_MSG_MULT failed");
1034          ODU_PUT_MSG_BUF(mBuf);
1035          return RFAILED;
1036       }
1037       ODU_PUT_MSG_BUF(mBuf);
1038    }
1039    else
1040    {
1041       DU_LOG("\nERROR  -->  F1AP : Failed to allocate memory");
1042       return RFAILED;
1043    }
1044    return ROK; 
1045 } /* sendF1APMsg */
1046
1047 /*******************************************************************
1048  *
1049  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1050  *
1051  * @details
1052  *
1053  *    Function :  FreeRrcVer
1054  *
1055  *    Functionality: deallocating the memory of function BuildRrcVer
1056  *
1057  * @params[in] RRC_Version_t *rrcVer
1058  * 
1059  * @return void
1060  *
1061  *****************************************************************/
1062 void FreeRrcVer(RRC_Version_t *rrcVer)
1063 {
1064    if(rrcVer->latest_RRC_Version.buf != NULLP)
1065    {
1066       if(rrcVer->iE_Extensions != NULLP)
1067       {
1068          if(rrcVer->iE_Extensions->list.array != NULLP)
1069          {
1070             if(rrcVer->iE_Extensions->list.array[0] != NULLP)
1071             {
1072                if(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf
1073                      != NULLP)
1074                {
1075                   DU_FREE(rrcVer->iE_Extensions->list.array[0]->extensionValue.choice\
1076                         .Latest_RRC_Version_Enhanced.buf,rrcVer->iE_Extensions->list.\
1077                         array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.size);
1078                }
1079                DU_FREE(rrcVer->iE_Extensions->list.array[0],sizeof(RRC_Version_ExtIEs_t));
1080             }
1081             DU_FREE(rrcVer->iE_Extensions->list.array,sizeof(RRC_Version_ExtIEs_t*));
1082          }
1083          DU_FREE(rrcVer->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P81_t));
1084       }
1085       DU_FREE(rrcVer->latest_RRC_Version.buf,rrcVer->latest_RRC_Version.size);
1086    }
1087 }
1088
1089 /*******************************************************************
1090  *
1091  * @brief Deallocating memory of TDD NrFreqInfo 
1092  *
1093  * @details
1094  *
1095  *    Function : freeTddNrFreqInfo 
1096  *
1097  *    Functionality: freeTddNrFreqInfo 
1098  *
1099  * @params[in]  F1AP_PDU_t *f1apDuCfg
1100  *
1101  * @return ROK     - void
1102  *
1103  * ****************************************************************/
1104 void freeTddNrFreqInfo(NRFreqInfo_t *freqInfo)
1105 {
1106    uint8_t freqBandListIdx = 0, supportedBandIdx = 0;
1107
1108    if(freqInfo->freqBandListNr.list.array)
1109    {
1110       for(freqBandListIdx = 0; freqBandListIdx<freqInfo->freqBandListNr.list.count; freqBandListIdx++)
1111       {
1112          if(freqInfo->freqBandListNr.list.array[freqBandListIdx])
1113          {
1114             if(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array)
1115             {
1116                for(supportedBandIdx = 0; supportedBandIdx<freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.count; supportedBandIdx++)
1117                {
1118                   DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array[supportedBandIdx],\
1119                         sizeof(SupportedSULFreqBandItem_t));
1120                }
1121                DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.array,\
1122                      freqInfo->freqBandListNr.list.array[freqBandListIdx]->supportedSULBandList.list.size);
1123
1124             }
1125             DU_FREE(freqInfo->freqBandListNr.list.array[freqBandListIdx],  sizeof(FreqBandNrItem_t ));
1126          }
1127       }
1128       DU_FREE(freqInfo->freqBandListNr.list.array, freqInfo->freqBandListNr.list.size );
1129    }
1130 }
1131
1132 /*******************************************************************
1133  *
1134  * @brief Deallocating memory allocated for Nr fdd frequencey mode 
1135  *
1136  * @details
1137  *
1138  *    Function : freeFddNrFreqInfo 
1139  *
1140  *    Functionality:Free memory allocated for Nr fdd frequencey mode 
1141  *
1142  * @params[in]  
1143  *
1144  * @return ROK     - void
1145  *
1146  * ****************************************************************/
1147 void freeFddNrFreqInfo(FDD_Info_t *fDD)
1148 {
1149    uint8_t arrIdx =0;
1150
1151    if(fDD != NULLP)
1152    {
1153       if(fDD->uL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1154       {
1155          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.\
1156                array[arrIdx], sizeof(FreqBandNrItem_t));
1157          DU_FREE(fDD->uL_NRFreqInfo.freqBandListNr.list.array, \
1158                fDD->uL_NRFreqInfo.freqBandListNr.list.size);
1159       }
1160
1161       if(fDD->dL_NRFreqInfo.freqBandListNr.list.array != NULLP)
1162       {
1163          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.\
1164                array[arrIdx], sizeof(FreqBandNrItem_t));
1165          DU_FREE(fDD->dL_NRFreqInfo.freqBandListNr.list.array,\
1166                fDD->dL_NRFreqInfo.freqBandListNr.list.size);
1167       }
1168       DU_FREE(fDD,sizeof(FDD_Info_t));
1169    }
1170 }
1171
1172 /*******************************************************************
1173  *
1174  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1175  *
1176  * @details
1177  *
1178  *    Function :  FreeServedCellList
1179  *
1180  *    Functionality:  deallocating the memory of function BuildServedCellList
1181
1182  *
1183  * @params[in] GNB_DU_Served_Cells_List_t *duServedCell
1184  *
1185  * @return void
1186  *
1187  * ****************************************************************/
1188 void FreeServedCellList( GNB_DU_Served_Cells_List_t *duServedCell)
1189 {
1190    uint8_t   plmnCnt=MAX_PLMN;
1191    uint8_t  extensionCnt=IE_EXTENSION_LIST_COUNT;
1192    uint8_t  plmnIdx=0, sliceIdx=0;
1193    GNB_DU_Served_Cells_Item_t *srvCellItem;
1194    ServedPLMNs_Item_t  *servedPlmnItem;
1195    SliceSupportItem_t  *sliceSupportItem;
1196
1197    if(duServedCell->list.array!=NULLP)
1198    {
1199       if(duServedCell->list.array[0]!=NULLP)
1200       {
1201          srvCellItem= &duServedCell->list.array[0]->value.choice.GNB_DU_Served_Cells_Item;
1202
1203          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1204                srvCellItem->served_Cell_Information.nRCGI.pLMN_Identity.size * sizeof(uint8_t));
1205          DU_FREE(srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1206                srvCellItem->served_Cell_Information.nRCGI.nRCellIdentity.size * sizeof(uint8_t));
1207
1208          if(srvCellItem->served_Cell_Information.fiveGS_TAC!=NULLP)
1209          {
1210             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC->buf,\
1211                   sizeof(srvCellItem->served_Cell_Information.fiveGS_TAC->size));
1212             DU_FREE(srvCellItem->served_Cell_Information.fiveGS_TAC,sizeof(FiveGS_TAC_t));
1213          }
1214
1215          if(srvCellItem->served_Cell_Information.servedPLMNs.list.array!=NULLP)
1216          {
1217             if(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx] != NULLP)
1218             {
1219                servedPlmnItem = srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx];
1220                DU_FREE(servedPlmnItem->pLMN_Identity.buf, servedPlmnItem->pLMN_Identity.size);
1221
1222                if(servedPlmnItem->iE_Extensions != NULLP)
1223                {
1224                   if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1225                   {
1226                      if(servedPlmnItem->iE_Extensions->list.array[0] != NULLP)
1227                      {
1228                         if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1229                               SliceSupportList.list.array != NULLP)
1230                         {
1231                            for(sliceIdx =0; sliceIdx<servedPlmnItem->iE_Extensions->list.array[0]->\
1232                                  extensionValue.choice.SliceSupportList.list.count; sliceIdx++)
1233                            {
1234                               if(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1235                                     SliceSupportList.list.array[sliceIdx] != NULLP)
1236                               {
1237                                  sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[0]->\
1238                                                     extensionValue.choice.SliceSupportList.list.array[sliceIdx];
1239
1240                                  DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sizeof(uint8_t));
1241
1242                                  if(sliceSupportItem->sNSSAI.sD != NULLP)
1243                                  {
1244                                     DU_FREE(sliceSupportItem->sNSSAI.sD->buf,\
1245                                           sliceSupportItem->sNSSAI.sD->size);
1246                                     DU_FREE(sliceSupportItem->sNSSAI.sD, sizeof(OCTET_STRING_t));
1247                                  }
1248
1249                                  DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.\
1250                                        choice.SliceSupportList.list.array[sliceIdx], sizeof(SliceSupportItem_t));
1251                               }
1252                            }
1253                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[0]->extensionValue.choice.\
1254                                  SliceSupportList.list.array, servedPlmnItem->iE_Extensions->list.array[0]->\
1255                                  extensionValue.choice.SliceSupportList.list.size);
1256                         }
1257                         DU_FREE(servedPlmnItem->iE_Extensions->list.array[0],\
1258                               sizeof(ServedPLMNs_ItemExtIEs_t));
1259                      }
1260                      DU_FREE(servedPlmnItem->iE_Extensions->list.array,\
1261                            extensionCnt*sizeof(ServedPLMNs_ItemExtIEs_t*));
1262                   }
1263                   DU_FREE(servedPlmnItem->iE_Extensions, sizeof(ProtocolExtensionContainer_4624P3_t));
1264                }
1265                DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array[plmnIdx],\
1266                      sizeof(ServedPLMNs_Item_t));
1267             }
1268             DU_FREE(srvCellItem->served_Cell_Information.servedPLMNs.list.array,\
1269                   sizeof(ServedPLMNs_Item_t *));
1270          }
1271
1272          if(srvCellItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1273          {
1274             freeFddNrFreqInfo(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1275          }
1276          else   
1277          {
1278             if(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD != NULLP)
1279             {
1280                freeTddNrFreqInfo(&srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1281                DU_FREE(srvCellItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1282             }
1283          }
1284          
1285          DU_FREE(srvCellItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1286                srvCellItem->served_Cell_Information.measurementTimingConfiguration.size);
1287
1288          if(srvCellItem->gNB_DU_System_Information != NULLP)
1289          {
1290             if(srvCellItem->gNB_DU_System_Information->mIB_message.buf != NULLP)
1291             {
1292                DU_FREE(srvCellItem->gNB_DU_System_Information->mIB_message.buf,\
1293                      srvCellItem->gNB_DU_System_Information->mIB_message.size);
1294             }
1295
1296             if(srvCellItem->gNB_DU_System_Information->sIB1_message.buf != NULLP)
1297             { 
1298                DU_FREE(srvCellItem->gNB_DU_System_Information->sIB1_message.buf,\
1299                      srvCellItem->gNB_DU_System_Information->sIB1_message.size);
1300             }
1301
1302             DU_FREE(srvCellItem->gNB_DU_System_Information, sizeof(GNB_DU_System_Information_t));
1303          }
1304
1305          DU_FREE(duServedCell->list.array[0], sizeof(GNB_DU_Served_Cells_ItemIEs_t));
1306       }
1307       DU_FREE(duServedCell->list.array, plmnCnt * sizeof(GNB_DU_Served_Cells_ItemIEs_t*));
1308    }
1309 }
1310
1311 /*******************************************************************
1312  *
1313  * @brief  deallocating the memory of function BuildAndSendF1SetupReq()
1314  *
1315  * @details
1316  *
1317  *    Function :  FreeF1SetupReq
1318  *
1319  *    Functionality:  deallocating the memory of function BuildAndSendF1SetupReq
1320  *
1321  * @params[in] F1AP_PDU_t *f1apMsg
1322  *
1323  * @return void
1324  *
1325  * ****************************************************************/
1326 void FreeF1SetupReq(F1AP_PDU_t *f1apMsg)
1327 {
1328    uint8_t ieIdx, ieIdx2;
1329    F1SetupRequest_t *f1SetupReq=NULLP;
1330
1331    if(f1apMsg != NULLP)
1332    {
1333       if(f1apMsg->choice.initiatingMessage != NULLP)
1334       {
1335          f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1336          if(f1SetupReq->protocolIEs.list.array != NULLP)
1337          {
1338             for(ieIdx = 0; ieIdx < f1SetupReq->protocolIEs.list.count; ieIdx++)
1339             {
1340                if(f1SetupReq->protocolIEs.list.array[ieIdx] != NULLP)
1341                {
1342                   switch(f1SetupReq->protocolIEs.list.array[ieIdx]->id)
1343                   {
1344                      case ProtocolIE_ID_id_TransactionID:
1345                         break;
1346                      case ProtocolIE_ID_id_gNB_DU_ID:
1347                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1348                               f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1349                         break;
1350                      case ProtocolIE_ID_id_gNB_DU_Name:
1351                         DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.buf,\
1352                               strlen((char *)duCfgParam.duName));
1353                         break;
1354                      case ProtocolIE_ID_id_gNB_DU_Served_Cells_List:
1355                         FreeServedCellList(&f1SetupReq->protocolIEs.list.\
1356                               array[ieIdx]->value.choice.GNB_DU_Served_Cells_List);
1357                         break;
1358                      case ProtocolIE_ID_id_GNB_DU_RRC_Version:
1359                         FreeRrcVer(&f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version);
1360                         break;
1361                      default:
1362                         DU_LOG("\nERROR  -->  Invalid Event Type %ld", f1SetupReq->protocolIEs.list.array[ieIdx]->id);
1363                         break;
1364                   }
1365                }
1366             }
1367             for(ieIdx2=0; ieIdx2< ieIdx; ieIdx2++)
1368             {
1369                DU_FREE(f1SetupReq->protocolIEs.list.array[ieIdx2],sizeof(F1SetupRequestIEs_t));
1370             }
1371             DU_FREE(f1SetupReq->protocolIEs.list.array,\
1372                   f1SetupReq->protocolIEs.list.size);
1373          }
1374          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1375       }
1376       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
1377    }
1378 }
1379 /*******************************************************************
1380  *
1381  * @brief Builds and Send the F1SetupRequest
1382  *
1383  * @details
1384  *
1385  *    Function : BuildAndSendF1SetupReq
1386  *
1387  * Functionality:Fills the F1SetupRequest
1388  *
1389  * @return ROK     - success
1390  *         RFAILED - failure
1391  *
1392  ******************************************************************/
1393 uint8_t BuildAndSendF1SetupReq()
1394 {
1395    uint8_t   ret, ieIdx, elementCnt;
1396    F1AP_PDU_t                 *f1apMsg = NULLP;
1397    F1SetupRequest_t           *f1SetupReq=NULLP;
1398    GNB_DU_Served_Cells_List_t *duServedCell=NULLP;
1399    RRC_Version_t              *rrcVer=NULLP;
1400    asn_enc_rval_t             encRetVal;        /* Encoder return value */
1401    ret= RFAILED;
1402
1403    DU_LOG("\nINFO   -->  F1AP : Building F1 Setup Request\n");
1404    do
1405    {
1406       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
1407       if(f1apMsg == NULLP)
1408       {
1409          break;
1410       }
1411       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
1412       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
1413       if(f1apMsg->choice.initiatingMessage == NULLP)
1414       {
1415          break;
1416       }
1417       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_F1Setup;
1418       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
1419       f1apMsg->choice.initiatingMessage->value.present = \
1420                                                          InitiatingMessage__value_PR_F1SetupRequest;
1421
1422       f1SetupReq = &f1apMsg->choice.initiatingMessage->value.choice.F1SetupRequest;
1423
1424       elementCnt = (duCfgParam.duName != NULL) ? 5 : 4;
1425
1426       f1SetupReq->protocolIEs.list.count = elementCnt;
1427       f1SetupReq->protocolIEs.list.size = elementCnt * sizeof(F1SetupRequestIEs_t );
1428
1429       /* Initialize the F1Setup members */
1430       DU_ALLOC(f1SetupReq->protocolIEs.list.array,f1SetupReq->protocolIEs.list.size);
1431       if(f1SetupReq->protocolIEs.list.array == NULLP)
1432       {
1433          break;
1434       }
1435       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
1436       {
1437          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx],\
1438                sizeof(F1SetupRequestIEs_t));
1439          if(f1SetupReq->protocolIEs.list.array[ieIdx] == NULLP)
1440          {
1441             break;
1442          }
1443       }
1444
1445       ieIdx = 0;
1446       /*TransactionID*/
1447       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_TransactionID;
1448       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1449       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present =\
1450                                                                F1SetupRequestIEs__value_PR_TransactionID;
1451       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = \
1452                                                                              TRANS_ID;
1453
1454       /*DU ID*/
1455       ieIdx++;
1456       f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
1457       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1458       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1459                                                                 F1SetupRequestIEs__value_PR_GNB_DU_ID;
1460       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size =\
1461                                                                              sizeof(uint8_t);
1462
1463       DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1464             f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1465       if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == \
1466             NULLP)
1467       {
1468          break;
1469       }
1470
1471       f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] =\
1472          duCfgParam.duId;
1473
1474       /*DU Name*/
1475       if(duCfgParam.duName != NULL)
1476       {
1477          ieIdx++;
1478          f1SetupReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_Name;
1479          f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_ignore;
1480          f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = F1SetupRequestIEs__value_PR_GNB_DU_Name;
1481          f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.size =\
1482             strlen((char *)duCfgParam.duName);
1483          DU_ALLOC(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.\
1484                GNB_DU_Name.buf, strlen((char *)duCfgParam.duName));
1485          if(f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_Name.\
1486                buf == NULLP)
1487          {
1488             break;
1489          }
1490          strcpy((char*)f1SetupReq->protocolIEs.list.array[ieIdx]->value.\
1491                choice.GNB_DU_Name.buf,
1492                (char*)&duCfgParam.duName);
1493
1494       }
1495
1496       /*Served Cell list */
1497       ieIdx++;
1498       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1499                                                      ProtocolIE_ID_id_gNB_DU_Served_Cells_List;
1500       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1501       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1502                                                                 F1SetupRequestIEs__value_PR_GNB_DU_Served_Cells_List;
1503       duServedCell = &f1SetupReq->protocolIEs.list.\
1504                      array[ieIdx]->value.choice.GNB_DU_Served_Cells_List;
1505       if(BuildServedCellList(duServedCell))
1506       {
1507          break;
1508       }
1509       /*RRC Version*/
1510       ieIdx++;
1511       f1SetupReq->protocolIEs.list.array[ieIdx]->id = \
1512                                                      ProtocolIE_ID_id_GNB_DU_RRC_Version ;
1513       f1SetupReq->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
1514       f1SetupReq->protocolIEs.list.array[ieIdx]->value.present = \
1515                                                                 F1SetupRequestIEs__value_PR_RRC_Version;
1516       rrcVer = &f1SetupReq->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
1517       if(BuildRrcVer(rrcVer))
1518       {
1519          break;
1520       }
1521       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
1522
1523       /* Encode the F1SetupRequest type as APER */
1524       memset(encBuf, 0, ENC_BUF_MAX_LEN);
1525       encBufSize = 0;
1526       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
1527             encBuf);
1528
1529       /* Encode results */
1530       if(encRetVal.encoded == ENCODE_FAIL)
1531       {
1532          DU_LOG("\nERROR  -->  F1AP : Could not encode F1SetupRequest structure (at %s)\n",\
1533                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1534          break;
1535       }
1536       else
1537       {
1538          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1SetupRequest\n");
1539          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
1540          {
1541             printf("%x",encBuf[ieIdx]);
1542          }
1543          
1544          duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize = encBufSize;
1545          DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, encBufSize);
1546          if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
1547          {
1548              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the encoding of f1setup req");
1549              return RFAILED;
1550          }
1551          memcpy(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, &encBuf, duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize);
1552       }
1553
1554       /* Sending msg */
1555       if(sendF1APMsg() != ROK)
1556       {
1557          DU_LOG("\nERROR  -->  F1AP : Sending F1 Setup request failed");
1558          break;
1559       }
1560
1561       ret=ROK;
1562       break;
1563    }while(true);
1564
1565    FreeF1SetupReq(f1apMsg);
1566
1567    return ret;
1568 }/* End of BuildAndSendF1SetupReq */
1569
1570 /*******************************************************************
1571  *
1572  * @brief Deallocating memory allocated for Served_Cells_To_Modify_Item_t
1573  *
1574  * @details
1575  *
1576  *    Function : freeCellsToModifyItem 
1577  *
1578  *    Functionality: Deallocating memory of variables allocated in
1579  *                    BuildAndSendDUConfigUpdate function
1580  *
1581  * @params[in]  Served_Cells_To_Modify_Item_t *modifyItem
1582  *
1583  * @return ROK     - void
1584  *
1585  * ****************************************************************/
1586
1587 void freeCellsToModifyItem(Served_Cells_To_Modify_Item_t *modifyItem)
1588 {
1589    uint8_t arrIdx=0, servedPlmnIdx=0, sliceLstIdx=0;
1590    ServedPLMNs_Item_t *servedPlmnItem = NULLP;
1591    SliceSupportItem_t *sliceSupportItem = NULLP;
1592
1593    DU_FREE(modifyItem->oldNRCGI.pLMN_Identity.buf, modifyItem->oldNRCGI.pLMN_Identity.size);
1594    DU_FREE(modifyItem->oldNRCGI.nRCellIdentity.buf, modifyItem->oldNRCGI.nRCellIdentity.size);
1595
1596    DU_FREE(modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.buf,\
1597            modifyItem->served_Cell_Information.nRCGI.pLMN_Identity.size);
1598    DU_FREE(modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.buf,\
1599          modifyItem->served_Cell_Information.nRCGI.nRCellIdentity.size);
1600
1601    if(modifyItem->served_Cell_Information.servedPLMNs.list.array != NULLP)
1602    {
1603       if(modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx] != NULLP)
1604       {
1605          servedPlmnItem = modifyItem->served_Cell_Information.servedPLMNs.list.array[arrIdx];
1606
1607          DU_FREE(servedPlmnItem->pLMN_Identity.buf,servedPlmnItem->pLMN_Identity.size);
1608
1609          if(servedPlmnItem->iE_Extensions != NULLP)
1610          {
1611             if(servedPlmnItem->iE_Extensions->list.array != NULLP)
1612             {
1613                if(servedPlmnItem->iE_Extensions->list.array[arrIdx] != NULLP)
1614                {
1615                   if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1616                         list.array != NULLP)
1617                   {
1618                      for(sliceLstIdx =0; sliceLstIdx<servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1619                            extensionValue.choice.SliceSupportList.list.count; sliceLstIdx++)
1620                      {
1621                         if(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.SliceSupportList.\
1622                               list.array[sliceLstIdx] != NULLP)
1623                         {
1624
1625                            sliceSupportItem = servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1626                                               SliceSupportList.list.array[sliceLstIdx];
1627
1628                            DU_FREE(sliceSupportItem->sNSSAI.sST.buf, sliceSupportItem->sNSSAI.sST.size);
1629                            if(sliceSupportItem->sNSSAI.sD != NULLP)
1630                            {
1631                               DU_FREE(sliceSupportItem->sNSSAI.sD->buf, sliceSupportItem->sNSSAI.sD->size);
1632                               DU_FREE(sliceSupportItem->sNSSAI.sD,sizeof(OCTET_STRING_t));
1633                            }
1634                            DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.choice.\
1635                                  SliceSupportList.list.array[sliceLstIdx], sizeof(SliceSupportItem_t));
1636                         }
1637                      }
1638                      DU_FREE(servedPlmnItem->iE_Extensions->list.array[arrIdx]->extensionValue.\
1639                            choice.SliceSupportList.list.array,\
1640                            servedPlmnItem->iE_Extensions->list.array[arrIdx]->\
1641                            extensionValue.choice.SliceSupportList.list.size);
1642                   }
1643                }
1644                for(servedPlmnIdx=0; servedPlmnIdx< servedPlmnItem->iE_Extensions->list.count ; servedPlmnIdx++)
1645                {
1646                   DU_FREE(servedPlmnItem->iE_Extensions->list.array[servedPlmnIdx], sizeof(ServedPLMNs_ItemExtIEs_t ));
1647                }
1648                DU_FREE(servedPlmnItem->iE_Extensions->list.array, servedPlmnItem->iE_Extensions->list.size);
1649             }
1650             DU_FREE(servedPlmnItem->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1651          }
1652       }
1653       for(servedPlmnIdx=0; servedPlmnIdx<modifyItem->served_Cell_Information.servedPLMNs.list.count; servedPlmnIdx++)
1654       {
1655          DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array[servedPlmnIdx], sizeof(ServedPLMNs_Item_t));
1656       }
1657       DU_FREE(modifyItem->served_Cell_Information.servedPLMNs.list.array,\
1658          modifyItem->served_Cell_Information.servedPLMNs.list.size);
1659    }
1660    
1661    if(modifyItem->served_Cell_Information.nR_Mode_Info.present == NR_Mode_Info_PR_fDD)
1662    {
1663       freeFddNrFreqInfo(modifyItem->served_Cell_Information.nR_Mode_Info.choice.fDD);
1664    }  
1665    else
1666    {
1667       if(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD)
1668       {
1669          freeTddNrFreqInfo(&modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD->nRFreqInfo);
1670          DU_FREE(modifyItem->served_Cell_Information.nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
1671       }
1672    }
1673    DU_FREE(modifyItem->served_Cell_Information.measurementTimingConfiguration.buf,\
1674       modifyItem->served_Cell_Information.measurementTimingConfiguration.size);
1675 }
1676
1677 /*******************************************************************
1678  *
1679  * @brief Deallocating memory of BuildAndSendDUConfigUpdate
1680  *
1681  * @details
1682  *
1683  *    Function : FreeDUConfigUpdate
1684  *
1685  *    Functionality: Deallocating memory of variables allocated in
1686  *                    BuildAndSendDUConfigUpdate function
1687  *
1688  * @params[in]  F1AP_PDU_t *f1apDuCfg
1689  *
1690  * @return ROK     - void
1691  *
1692  * ****************************************************************/
1693 void FreeDUConfigUpdate(F1AP_PDU_t *f1apDuCfg)
1694 {
1695    uint8_t  ieIdx=0, cellModifyIdx=0, cellDeleteIdx=0;
1696    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
1697    Served_Cells_To_Modify_List_t  *cellsToModify=NULLP;
1698    Served_Cells_To_Delete_List_t  *cellsToDelete=NULLP;
1699    Served_Cells_To_Delete_Item_t  *deleteItem = NULLP;
1700    Served_Cells_To_Delete_ItemIEs_t *deleteItemIe = NULLP;
1701
1702    if(f1apDuCfg != NULLP)
1703    {
1704       if(f1apDuCfg->choice.initiatingMessage != NULLP)
1705       {
1706          duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->\
1707                        value.choice.GNBDUConfigurationUpdate;
1708          if(duCfgUpdate->protocolIEs.list.array != NULLP)
1709          {
1710             for(ieIdx=0; ieIdx<duCfgUpdate->protocolIEs.list.count; ieIdx++)
1711             {
1712                if(duCfgUpdate->protocolIEs.list.array[ieIdx] != NULLP)
1713                {
1714                   switch(duCfgUpdate->protocolIEs.list.array[ieIdx]->id)
1715                   {
1716                      case ProtocolIE_ID_id_Served_Cells_To_Modify_List:
1717                         {
1718                            cellsToModify = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1719                                            value.choice.Served_Cells_To_Modify_List;
1720                            if(cellsToModify->list.array != NULLP)
1721                            {
1722                               for(cellModifyIdx=0; cellModifyIdx<cellsToModify->list.count ;cellModifyIdx++)
1723                               {
1724                                  if(cellsToModify->list.array[cellModifyIdx] != NULLP)
1725                                  {
1726                                     freeCellsToModifyItem(&cellsToModify->list.array[cellModifyIdx]->value.choice.\
1727                                           Served_Cells_To_Modify_Item);
1728                                     DU_FREE(cellsToModify->list.array[cellModifyIdx],\
1729                                           sizeof(Served_Cells_To_Modify_ItemIEs_t));
1730                                  }
1731                               }
1732                               DU_FREE(cellsToModify->list.array,cellsToModify->list.size);
1733                            }
1734                            break;
1735                         }
1736                      case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
1737                         {
1738                            cellsToDelete = &duCfgUpdate->protocolIEs.list.array[ieIdx]->\
1739                                            value.choice.Served_Cells_To_Delete_List;
1740                            if(cellsToDelete->list.array != NULLP)
1741                            {
1742                               for(cellDeleteIdx=0; cellDeleteIdx<cellsToDelete->list.count ;cellDeleteIdx++)
1743                               {
1744                                  if(cellsToDelete->list.array[cellDeleteIdx] != NULLP)
1745                                  {
1746                                     deleteItemIe = ((Served_Cells_To_Delete_ItemIEs_t*)\
1747                                           cellsToDelete->list.array[cellDeleteIdx]);
1748                                     deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
1749                                     DU_FREE(deleteItem->oldNRCGI.pLMN_Identity.buf,\
1750                                           deleteItem->oldNRCGI.pLMN_Identity.size); 
1751                                     DU_FREE(deleteItem->oldNRCGI.nRCellIdentity.buf,\
1752                                           deleteItem->oldNRCGI.nRCellIdentity.size);
1753                                     DU_FREE(cellsToDelete->list.array[cellDeleteIdx],\
1754                                           sizeof(Served_Cells_To_Delete_ItemIEs_t));
1755                                  }
1756                               }
1757                               DU_FREE(cellsToDelete->list.array,cellsToDelete->list.size);
1758                            }
1759
1760                            break;
1761                         }
1762                      case ProtocolIE_ID_id_gNB_DU_ID:
1763                         {
1764                            DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
1765                                  duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
1766                            break;
1767                         }
1768                   }
1769                   DU_FREE(duCfgUpdate->protocolIEs.list.array[ieIdx],\
1770                         sizeof(GNBDUConfigurationUpdateIEs_t));
1771                }
1772             }
1773             DU_FREE(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
1774          }
1775          DU_FREE(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
1776       }
1777       DU_FREE(f1apDuCfg, (Size)sizeof(F1AP_PDU_t));
1778    }
1779 }
1780
1781 /*******************************************************************
1782  *
1783  * @brief Fills Served Plmns required in ServCellInfo IE
1784  *
1785  * @details
1786  *
1787  *    Function : fillServedPlmns
1788  *
1789  *    Functionality: Fills Served Plmns required in ServCellInfo IE
1790  *
1791  * @params[in] Pointer to ServedPLMNs_List_t *
1792  *
1793  * @return ROK     - success
1794  *         RFAILED - failure
1795  *
1796  *****************************************************************/
1797
1798 uint8_t fillServedPlmns(ServedPLMNs_List_t *servedPlmn)
1799 {
1800    uint8_t ieIdx=0, arrayIdx=0, ieListCnt=0, elementCnt=0, sliceLstIdx=0;
1801
1802    servedPlmn->list.array[arrayIdx]->pLMN_Identity.size = 3*sizeof(uint8_t);
1803    DU_ALLOC(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf, servedPlmn->list.\
1804          array[arrayIdx]->pLMN_Identity.size);
1805    if(servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf == NULLP)
1806    {
1807       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1808       return RFAILED;
1809    }
1810    buildPlmnId(duCfgParam.srvdCellLst[arrayIdx].duCellInfo.cellInfo.srvdPlmn[arrayIdx].plmn,\
1811          servedPlmn->list.array[arrayIdx]->pLMN_Identity.buf);
1812    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions,sizeof(ProtocolExtensionContainer_4624P3_t));
1813    if(servedPlmn->list.array[arrayIdx]->iE_Extensions == NULLP)
1814    {
1815       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1816       return RFAILED;
1817    }
1818
1819    ieListCnt=1;
1820    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.count = ieListCnt;
1821    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.size = ieListCnt *sizeof(ServedPLMNs_ItemExtIEs_t *);
1822    DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array,servedPlmn->list.array[arrayIdx]->\
1823          iE_Extensions->list.size);
1824    if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array == NULLP)
1825    {
1826       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1827       return RFAILED;
1828    }
1829    for(ieIdx=arrayIdx;ieIdx<ieListCnt;ieIdx++)
1830    {
1831       DU_ALLOC(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx],\
1832             sizeof(ServedPLMNs_ItemExtIEs_t));
1833       if(servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx] == NULLP)
1834       {
1835          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1836          return RFAILED;
1837       }
1838    }
1839    
1840    ieIdx = 0;
1841    elementCnt = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst.numSupportedSlices; 
1842    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->id =ProtocolIE_ID_id_TAISliceSupportList;
1843    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->criticality = Criticality_ignore;
1844    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.present = \
1845    ServedPLMNs_ItemExtIEs__extensionValue_PR_SliceSupportList;
1846    servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1847       list.count = elementCnt;
1848    servedPlmn->list.array[arrayIdx]->\
1849       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1850       list.size = elementCnt * sizeof(SliceSupportItem_t *);
1851    DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1852          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1853          list.array,servedPlmn->list.array[arrayIdx]->\
1854          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.size);
1855    if(servedPlmn->list.array[arrayIdx]->\
1856          iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1857          list.array == NULLP)
1858    {
1859       DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1860       return RFAILED;
1861    }
1862
1863    for(sliceLstIdx =0; sliceLstIdx< elementCnt; sliceLstIdx++)
1864    {
1865       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1866       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1867       list.array[sliceLstIdx],sizeof( SliceSupportItem_t));
1868       if(servedPlmn->list.array[arrayIdx]->\
1869       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1870       list.array[sliceLstIdx] == NULLP)
1871       {   
1872          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1873          return RFAILED;
1874       }
1875       
1876       servedPlmn->list.array[arrayIdx]->\
1877       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1878       list.array[sliceLstIdx]->sNSSAI.sST.size = sizeof(uint8_t);
1879       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1880       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1881       list.array[sliceLstIdx]->sNSSAI.sST.buf,servedPlmn->list.array[arrayIdx]->\
1882       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.list.array[sliceLstIdx]->\
1883       sNSSAI.sST.size);
1884       
1885       if(servedPlmn->list.array[arrayIdx]->\
1886       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1887       list.array[sliceLstIdx]->sNSSAI.sST.buf == NULLP)
1888       {
1889          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1890          return RFAILED;
1891       }
1892       servedPlmn->list.array[arrayIdx]->\
1893       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1894       list.array[sliceLstIdx]->sNSSAI.sST.buf[arrayIdx] =  duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
1895       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sst;
1896
1897       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1898       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1899       list.array[sliceLstIdx]->sNSSAI.sD,sizeof(OCTET_STRING_t));
1900       if(servedPlmn->list.array[arrayIdx]->\
1901       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1902       list.array[sliceLstIdx]->sNSSAI.sD == NULLP)
1903       {
1904          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1905          return RFAILED;
1906       }
1907       servedPlmn->list.array[arrayIdx]->\
1908       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1909       list.array[sliceLstIdx]->sNSSAI.sD->size = 3 * sizeof(uint8_t);
1910       DU_ALLOC(servedPlmn->list.array[arrayIdx]->\
1911       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1912       list.array[sliceLstIdx]->sNSSAI.sD->buf,servedPlmn->list.array[arrayIdx]->\
1913       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1914       list.array[sliceLstIdx]->sNSSAI.sD->size);
1915       if(servedPlmn->list.array[arrayIdx]->\
1916       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1917       list.array[sliceLstIdx]->sNSSAI.sD->buf == NULLP)
1918       {
1919          DU_LOG("ERROR  --> DU_APP : fillServedPlmns(): Memory allocation failed");
1920          return RFAILED;
1921       }
1922       memcpy(servedPlmn->list.array[arrayIdx]->\
1923       iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1924       list.array[sliceLstIdx]->sNSSAI.sD->buf, duCfgParam.srvdCellLst[arrayIdx].duCellInfo.\
1925       cellInfo.srvdPlmn[arrayIdx].taiSliceSuppLst.snssai[sliceLstIdx]->sd,\
1926       servedPlmn->list.array[arrayIdx]->iE_Extensions->list.array[ieIdx]->extensionValue.choice.SliceSupportList.\
1927       list.array[sliceLstIdx]->sNSSAI.sD->size);
1928    }
1929    return ROK;
1930 }
1931
1932 /*******************************************************************
1933  *
1934  * @brief Fills Nr Fdd Info required in ServCellInfo IE
1935  *
1936  * @details
1937  *
1938  *    Function : fillNrFddInfo
1939  *
1940  *    Functionality: Fills Nr Fdd Info required in ServCellInfo IE
1941  *
1942  * @params[in] FDD_Info_t *fDD
1943  *
1944  * @return ROK     - success
1945  *         RFAILED - failure
1946  *
1947  *****************************************************************/
1948
1949 uint8_t fillNrFddInfo(FDD_Info_t *fDD)
1950 {
1951    fDD->uL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.\
1952       f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn;
1953    fDD->uL_NRFreqInfo.freqBandListNr.list.count = 1;
1954    fDD->uL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t*);
1955    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.\
1956          array, fDD->uL_NRFreqInfo.freqBandListNr.list.size);
1957    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array == NULLP)
1958    {
1959       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
1960       return RFAILED;
1961    }
1962
1963    DU_ALLOC(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0], \
1964       sizeof(FreqBandNrItem_t));
1965    if(fDD->uL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
1966    {
1967       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
1968       return RFAILED;
1969    }
1970    
1971    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
1972       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.\
1973       freqBand[0].nrFreqBand;
1974    fDD->uL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
1975    fDD->dL_NRFreqInfo.nRARFCN = duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.\
1976       dlNrFreqInfo.nrArfcn;
1977    fDD->dL_NRFreqInfo.freqBandListNr.list.count = 1;
1978    fDD->dL_NRFreqInfo.freqBandListNr.list.size = sizeof(FreqBandNrItem_t *);
1979    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array, fDD->dL_NRFreqInfo.freqBandListNr.list.size);
1980    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array == NULLP)
1981    {
1982       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
1983       return RFAILED;
1984    }
1985    
1986    DU_ALLOC(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0],  sizeof(FreqBandNrItem_t));
1987    if(fDD->dL_NRFreqInfo.freqBandListNr.list.array[0] == NULLP)
1988    {
1989       DU_LOG("\nERROR  --> Memory allocation failed in fillNrFddInfo");
1990       return RFAILED;
1991    }
1992
1993    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->freqBandIndicatorNr = \
1994       duCfgParam.srvdCellLst[0].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.\
1995       freqBand[0].nrFreqBand;
1996    fDD->dL_NRFreqInfo.freqBandListNr.list.array[0]->supportedSULBandList.list.count=0;
1997    
1998    /*Transmission Bandwidth*/
1999    fDD->uL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2000       f1Mode.mode.fdd.ulTxBw.nrScs;
2001    fDD->uL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2002       f1Mode.mode.fdd.ulTxBw.nrb;
2003    fDD->dL_Transmission_Bandwidth.nRSCS = duCfgParam.srvdCellLst[0].duCellInfo.\
2004       f1Mode.mode.fdd.dlTxBw.nrScs;
2005    fDD->dL_Transmission_Bandwidth.nRNRB = duCfgParam.srvdCellLst[0].duCellInfo.\
2006       f1Mode.mode.fdd.dlTxBw.nrb;
2007
2008    return ROK;
2009 }
2010
2011 /*******************************************************************
2012  *
2013  * @brief Fills ServCellInfo IE
2014  *
2015  * @details
2016  *
2017  *    Function : fillServedCellInfo
2018  *
2019  *    Functionality: Fills ServCellInfo
2020  *
2021  * @params[in] Pointer to Served_Cell_Information_t *
2022  *
2023  * @return ROK     - success
2024  *         RFAILED - failure
2025  *
2026  *****************************************************************/
2027
2028 uint8_t fillServedCellInfo(Served_Cell_Information_t *srvCellInfo)
2029 {
2030    uint8_t ieIdx, ieListCnt;
2031
2032    /*nRCGI*/
2033    srvCellInfo->nRCGI.pLMN_Identity.size =3*sizeof(uint8_t);
2034    DU_ALLOC(srvCellInfo->nRCGI.pLMN_Identity.buf,\
2035          srvCellInfo->nRCGI.pLMN_Identity.size);
2036    if(srvCellInfo->nRCGI.pLMN_Identity.buf == NULLP)
2037    {
2038       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2039       return RFAILED;
2040    }
2041    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2042          srvCellInfo->nRCGI.pLMN_Identity.buf);
2043    srvCellInfo->nRCGI.nRCellIdentity.size =5*sizeof(uint8_t);
2044    DU_ALLOC(srvCellInfo->nRCGI.nRCellIdentity.buf,\
2045          srvCellInfo->nRCGI.nRCellIdentity.size);
2046    if(srvCellInfo->nRCGI.nRCellIdentity.buf == NULLP)
2047    {   
2048       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2049       return RFAILED;
2050    }
2051    
2052    fillBitString(&srvCellInfo->nRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2053    /*nRPCI*/
2054    srvCellInfo->nRPCI = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci;
2055
2056    /*servedPLMNs*/
2057    ieListCnt = 1;
2058    srvCellInfo->servedPLMNs.list.count = ieListCnt;
2059    srvCellInfo->servedPLMNs.list.size = ieListCnt*sizeof(ServedPLMNs_Item_t *);
2060    DU_ALLOC(srvCellInfo->servedPLMNs.list.array, srvCellInfo->servedPLMNs.list.size);
2061    if(srvCellInfo->servedPLMNs.list.array == NULLP)
2062    {
2063       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2064       return RFAILED;
2065    }
2066    for(ieIdx=0; ieIdx < ieListCnt; ieIdx++)
2067    {
2068       DU_ALLOC(srvCellInfo->servedPLMNs.list.array[ieIdx], sizeof(ServedPLMNs_Item_t));
2069       if(srvCellInfo->servedPLMNs.list.array[ieIdx]== NULLP)
2070       {
2071          DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2072          return RFAILED;
2073       }
2074    }
2075    if(fillServedPlmns(&srvCellInfo->servedPLMNs))
2076    {
2077       DU_LOG("\nERROR  --> Failed to fill Served Plmn info");
2078       return RFAILED;
2079    }
2080
2081 #ifndef NR_TDD
2082    /*nR Mode Info with FDD*/
2083    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_fDD;
2084    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.fDD, sizeof(FDD_Info_t));
2085    if(srvCellInfo->nR_Mode_Info.choice.fDD == NULLP)
2086    {
2087       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2088       return RFAILED;
2089    }
2090    if(fillNrFddInfo(srvCellInfo->nR_Mode_Info.choice.fDD))
2091    {
2092        DU_LOG("\nERROR  --> Failed to fill the Nr FDD information");
2093       return RFAILED;
2094    }
2095 #else
2096    srvCellInfo->nR_Mode_Info.present = NR_Mode_Info_PR_tDD;   
2097    DU_ALLOC(srvCellInfo->nR_Mode_Info.choice.tDD, sizeof(TDD_Info_t));
2098    if(srvCellInfo->nR_Mode_Info.choice.tDD == NULLP)
2099    {
2100       DU_LOG("\nERROR  --> Memory allocation failed in fillServedCellInfo");
2101       return RFAILED;
2102    }
2103    if(fillNrTddInfo(srvCellInfo->nR_Mode_Info.choice.tDD) != ROK)
2104    {
2105       DU_LOG("\nERROR  --> Failed to fill the Nr TDD information");
2106       return RFAILED;
2107    }
2108 #endif
2109
2110    /*Measurement timing Config*/
2111    srvCellInfo->measurementTimingConfiguration.size = sizeof(uint8_t);
2112    DU_ALLOC(srvCellInfo->measurementTimingConfiguration.\
2113          buf,srvCellInfo->measurementTimingConfiguration.size);
2114    if(srvCellInfo->measurementTimingConfiguration.buf == NULLP)
2115    {
2116       return RFAILED;
2117    }
2118    srvCellInfo->measurementTimingConfiguration.\
2119          buf[0] = duCfgParam.srvdCellLst[0].duCellInfo.measTimeCfg;
2120
2121    return ROK;
2122 }
2123
2124 /*******************************************************************
2125  *
2126  * @brief Fills ServCellToModItem IE
2127  *
2128  * @details
2129  *
2130  *    Function : fillServCellToModItem
2131  *
2132  *    Functionality: Fills ServCellToModItem IE
2133  *
2134  * @params[in] Pointer to Served_Cells_To_Modify_Item_t *
2135  *
2136  * @return ROK     - success
2137  *         RFAILED - failure
2138  *
2139  *****************************************************************/
2140
2141 uint8_t fillServCellToModItem(Served_Cells_To_Modify_Item_t *modifyItem)
2142 {
2143    /*pLMN_Identity*/
2144    modifyItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2145    DU_ALLOC(modifyItem->oldNRCGI.pLMN_Identity.buf,modifyItem->oldNRCGI.pLMN_Identity.size);
2146    if(modifyItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2147    {
2148       return RFAILED;
2149    }
2150    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2151          modifyItem->oldNRCGI.pLMN_Identity.buf);
2152
2153    /*nRCellIdentity*/
2154    modifyItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2155    DU_ALLOC(modifyItem->oldNRCGI.nRCellIdentity.buf,\
2156          modifyItem->oldNRCGI.nRCellIdentity.size);
2157    if(modifyItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2158    {
2159       return RFAILED;
2160    }
2161    fillBitString(&modifyItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2162
2163    if(fillServedCellInfo(&modifyItem->served_Cell_Information))
2164       return RFAILED;
2165    else
2166       return ROK;
2167 }
2168
2169 /*******************************************************************
2170  *
2171  * @brief Builds ServCellToModList
2172  *
2173  * @details
2174  *
2175  *    Function : buildServCellToModList
2176  *
2177  *    Functionality: Builds the serv cell to Mod List
2178  *
2179  * @params[in] Pointer to Served_Cells_To_Modify_List_t *
2180  *
2181  * @return ROK     - success
2182  *         RFAILED - failure
2183  *
2184  *****************************************************************/
2185
2186 uint8_t buildServCellToModList(Served_Cells_To_Modify_List_t *cellsToModify)
2187 {
2188    uint8_t ieListCnt, ieIdx;
2189    Served_Cells_To_Modify_Item_t *modifyItem = NULLP;
2190
2191    ieListCnt = 1;
2192    cellsToModify->list.count = ieListCnt;
2193    cellsToModify->list.size = ieListCnt*sizeof(Served_Cells_To_Modify_ItemIEs_t *);
2194    DU_ALLOC(cellsToModify->list.array,cellsToModify->list.size);
2195    if(cellsToModify->list.array == NULLP)
2196    {
2197       return RFAILED;
2198    }
2199    for(ieIdx=0; ieIdx< ieListCnt; ieIdx++)
2200    {
2201       DU_ALLOC(cellsToModify->list.array[ieIdx],sizeof(Served_Cells_To_Modify_ItemIEs_t));
2202       if(cellsToModify->list.array[ieIdx] == NULLP)
2203       {
2204          return RFAILED;
2205       }
2206    }
2207    cellsToModify->list.array[0]->id = ProtocolIE_ID_id_Served_Cells_To_Modify_Item;
2208    cellsToModify->list.array[0]->criticality = Criticality_reject;
2209    cellsToModify->list.array[0]->value.present =\
2210       Served_Cells_To_Modify_ItemIEs__value_PR_Served_Cells_To_Modify_Item;
2211    modifyItem=&cellsToModify->list.array[0]->value.choice.Served_Cells_To_Modify_Item;
2212
2213    if(fillServCellToModItem(modifyItem))
2214       return RFAILED;
2215    else
2216       return ROK;
2217 }
2218 /*******************************************************************
2219  *
2220  * @brief filling the DeleteItemList
2221  *
2222  * @details
2223  *
2224  *    Function : fillCellToDeleteItem 
2225  *
2226  *    Functionality: Filling the DeleteItemIe 
2227  *
2228  * @params[in] Pointer to Served_Cells_To_Delete_ItemIEs_t 
2229  *
2230  * @return ROK     - success
2231  *         RFAILED - failure
2232  *
2233  *****************************************************************/
2234 uint8_t fillCellToDeleteItem(struct Served_Cells_To_Delete_ItemIEs *deleteItemIe)
2235 {
2236    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
2237    
2238    deleteItemIe->id = ProtocolIE_ID_id_Served_Cells_To_Delete_Item;
2239    deleteItemIe->criticality = Criticality_reject;
2240    deleteItemIe->value.present =\
2241    Served_Cells_To_Delete_ItemIEs__value_PR_Served_Cells_To_Delete_Item;
2242    deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
2243
2244    /*pLMN_Identity*/
2245    deleteItem->oldNRCGI.pLMN_Identity.size = 3*sizeof(uint8_t);
2246    DU_ALLOC(deleteItem->oldNRCGI.pLMN_Identity.buf,deleteItem->oldNRCGI.pLMN_Identity.size);
2247    if(deleteItem->oldNRCGI.pLMN_Identity.buf == NULLP)
2248    {
2249       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2250       return RFAILED;
2251    }
2252    buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn,\
2253          deleteItem->oldNRCGI.pLMN_Identity.buf);
2254
2255    /*nRCellIdentity*/
2256    deleteItem->oldNRCGI.nRCellIdentity.size = 5*sizeof(uint8_t);
2257    DU_ALLOC(deleteItem->oldNRCGI.nRCellIdentity.buf,\
2258          deleteItem->oldNRCGI.nRCellIdentity.size);
2259    if(deleteItem->oldNRCGI.nRCellIdentity.buf == NULLP)
2260    {
2261       DU_LOG("ERROR  --> F1AP: fillCellToDeleteItem(): Failed to allocate the memory");
2262       return RFAILED;
2263    }
2264    fillBitString(&deleteItem->oldNRCGI.nRCellIdentity, ODU_VALUE_FOUR, ODU_VALUE_FIVE, duCfgParam.sib1Params.cellIdentity);
2265    return ROK;
2266
2267 /*******************************************************************
2268  *
2269  * @brief Builds ServCellToDeleteList
2270  *
2271  * @details
2272  *
2273  *    Function : buildServCellToDeleteList
2274  *
2275  *    Functionality: Builds the serv cell to delete List
2276  *
2277  * @params[in] Pointer to Served_Cells_To_Delete_List_t *
2278  *
2279  * @return ROK     - success
2280  *         RFAILED - failure
2281  *
2282  *****************************************************************/
2283  
2284 uint8_t buildServCellToDeleteList(Served_Cells_To_Delete_List_t *cellsToDelete)
2285 {
2286    uint8_t ieListCnt, arrIdx;
2287    
2288    ieListCnt = 1;
2289    cellsToDelete->list.count = ieListCnt;
2290    cellsToDelete->list.size = ieListCnt*sizeof(Served_Cells_To_Delete_ItemIEs_t *);
2291    
2292    DU_ALLOC(cellsToDelete->list.array,cellsToDelete->list.size);
2293    if(cellsToDelete->list.array == NULLP)
2294    {
2295       DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2296       return RFAILED;
2297    }
2298    
2299    for(arrIdx=0; arrIdx< ieListCnt; arrIdx++)
2300    {
2301       DU_ALLOC(cellsToDelete->list.array[arrIdx],sizeof(Served_Cells_To_Delete_ItemIEs_t));
2302       if(cellsToDelete->list.array[arrIdx] == NULLP)
2303       {
2304          DU_LOG("\nERROR  --> F1AP : buildServCellToDeleteList(): Memory allocation failed");
2305          return RFAILED;
2306       }
2307    }
2308    
2309    arrIdx=0;
2310    if(fillCellToDeleteItem((Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx]) !=ROK)
2311    {
2312       DU_LOG("\nERROR  -->  F1AP: buildServCellToDeleteList(): failed to fill Served_Cells_To_Delete_ItemIEs");
2313       return RFAILED;
2314    }
2315    return ROK;
2316 }
2317
2318 /*******************************************************************
2319  *
2320  * @brief Builds and sends the DUConfigUpdate
2321  *
2322  * @details
2323  *
2324  *    Function : BuildAndSendDUConfigUpdate
2325  *
2326  *    Functionality: Constructs the DU Update message and sends
2327  *                   it to the CU through SCTP.
2328  *
2329  * @params[in] void **buf,Buffer to which encoded pattern is written into
2330  * @params[in] int *size,size of buffer
2331  *
2332  * @return ROK     - success
2333  *         RFAILED - failure
2334  *
2335  * ****************************************************************/
2336 uint8_t BuildAndSendDUConfigUpdate(ServCellAction servCellAction)
2337 {
2338    uint8_t ret =0, ieIdx=0, elementCnt=0;
2339    bool memAlloctionFailure = false;
2340    F1AP_PDU_t                 *f1apDuCfg = NULLP;
2341    GNBDUConfigurationUpdate_t *duCfgUpdate = NULLP;
2342    asn_enc_rval_t encRetVal;     /* Encoder return value */
2343    
2344    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2345    ret= RFAILED;
2346
2347    while(true)
2348    {
2349       DU_LOG("\nINFO   -->  F1AP : Building DU config update\n");
2350       /* Allocate the memory for F1DuCfg */
2351       DU_ALLOC(f1apDuCfg, sizeof(F1AP_PDU_t));
2352       if(f1apDuCfg == NULLP)
2353       {
2354          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2355          break;
2356       }
2357
2358       f1apDuCfg->present = F1AP_PDU_PR_initiatingMessage;
2359       DU_ALLOC(f1apDuCfg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2360       if(f1apDuCfg->choice.initiatingMessage == NULLP)
2361       {
2362          DU_LOG("\nERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation for F1AP-PDU failed");
2363          break;
2364       }
2365
2366       f1apDuCfg->choice.initiatingMessage->procedureCode = \
2367                                                            ProcedureCode_id_gNBDUConfigurationUpdate;
2368       f1apDuCfg->choice.initiatingMessage->criticality = Criticality_reject;
2369       f1apDuCfg->choice.initiatingMessage->value.present = \
2370                                                            InitiatingMessage__value_PR_GNBDUConfigurationUpdate;
2371       duCfgUpdate = &f1apDuCfg->choice.initiatingMessage->value.\
2372                     choice.GNBDUConfigurationUpdate;
2373       elementCnt = 3;
2374       duCfgUpdate->protocolIEs.list.count = elementCnt;
2375       duCfgUpdate->protocolIEs.list.size = \
2376                                            elementCnt * sizeof(GNBDUConfigurationUpdateIEs_t*);
2377
2378       /* Initialize the F1Setup members */
2379       DU_ALLOC(duCfgUpdate->protocolIEs.list.array,duCfgUpdate->protocolIEs.list.size);
2380       if(duCfgUpdate->protocolIEs.list.array == NULLP)
2381       {
2382          DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2383          break;
2384       }
2385       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
2386       {
2387          DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx],sizeof(GNBDUConfigurationUpdateIEs_t));
2388          if(duCfgUpdate->protocolIEs.list.array[ieIdx] == NULLP)
2389          {
2390             DU_LOG("ERROR  -->  F1AP : BuildAndSendDUConfigUpdate(): Memory allocation failed");
2391             memAlloctionFailure = true;
2392             break;
2393          }
2394       }
2395       
2396       if(memAlloctionFailure == true)
2397       {
2398          break;
2399       }
2400       /*TransactionID*/
2401       ieIdx = 0;
2402       duCfgUpdate->protocolIEs.list.array[ieIdx]->id=ProtocolIE_ID_id_TransactionID;
2403       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
2404       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2405       GNBDUConfigurationUpdateIEs__value_PR_TransactionID;
2406       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = TRANS_ID;
2407       
2408       ieIdx++;
2409       if(servCellAction == SERV_CELL_TO_MODIFY)
2410       {
2411          /*Served Cell to Modify */
2412          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2413          ProtocolIE_ID_id_Served_Cells_To_Modify_List;
2414          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2415          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2416          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Modify_List;
2417          if(buildServCellToModList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2418                   Served_Cells_To_Modify_List))
2419          {
2420             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToModList");
2421             break;
2422          }
2423       }
2424       else
2425       {
2426          /*Served Cell to Delete */ 
2427          duCfgUpdate->protocolIEs.list.array[ieIdx]->id = \
2428          ProtocolIE_ID_id_Served_Cells_To_Delete_List;
2429          duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality =Criticality_reject;
2430          duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2431          GNBDUConfigurationUpdateIEs__value_PR_Served_Cells_To_Delete_List;
2432          if(buildServCellToDeleteList(&duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
2433          Served_Cells_To_Delete_List)!=ROK)
2434          {
2435             DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): failed to build ServCellToDeleteList");
2436             break;
2437          }
2438          
2439       }
2440       // NOTE :GNB DU SYS INFO:MIB AND SIB1 INFORMATION TO BE BUILT AND FILLED HERE
2441       /*GNB DU ID */
2442       ieIdx++;
2443       duCfgUpdate->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_ID;
2444       duCfgUpdate->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
2445       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.present = \
2446       GNBDUConfigurationUpdateIEs__value_PR_GNB_DU_ID;
2447       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size = sizeof(uint8_t);
2448       DU_ALLOC(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf,\
2449             duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.size);
2450       if(duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf == NULLP)
2451       {
2452          DU_LOG("ERROR  --> DU APP : BuildAndSendDUConfigUpdate(): Memory allocation failed for GNB_DU_ID");
2453          break;
2454       }
2455       duCfgUpdate->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_ID.buf[0] = duCfgParam.duId;
2456
2457       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apDuCfg);
2458
2459       /* Encode the DU Config Update type as APER */
2460       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
2461       encBufSize = 0;
2462       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apDuCfg, PrepFinalEncBuf, encBuf);
2463
2464       /* Checking encode results */
2465       if(encRetVal.encoded == ENCODE_FAIL)
2466       {
2467          DU_LOG("ERROR  -->  F1AP : Could not encode DUConfigUpdate structure (at %s)\n",\
2468                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2469          break;
2470       }
2471       else
2472       {
2473          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DUConfigUpdate\n");
2474          for(ieIdx =0; ieIdx < encBufSize; ieIdx++)
2475          {
2476             printf("%x",encBuf[ieIdx]);
2477          }
2478       }
2479       /* Sending msg */
2480       if(sendF1APMsg() != ROK)
2481       {
2482          DU_LOG("\nERROR  -->  F1AP : Sending GNB-DU Config Update failed");
2483          break;
2484       }
2485
2486       ret = ROK;
2487       break;
2488    }
2489   
2490    addToReservedF1apPduList(TRANS_ID,f1apDuCfg);
2491    return ret;
2492 }
2493
2494
2495 /*******************************************************************
2496  *
2497  * @brief free the ULRRCMessageTransfer
2498  *
2499  * @details
2500  *
2501  *    Function : FreeULRRCMessageTransfer
2502  *
2503  *    Functionality: Deallocating the memory of variable allocated in
2504  *                      FreeULRRCMessageTransfer
2505  *
2506  * @params[in]
2507  *
2508  * @return ROK     - void
2509  *
2510  ******************************************************************/
2511 void FreeULRRCMessageTransfer( F1AP_PDU_t *f1apMsg)
2512 {
2513    uint8_t idx1;
2514    ULRRCMessageTransfer_t  *ulRRCMsg;
2515
2516    if(f1apMsg != NULLP)
2517    { 
2518       if(f1apMsg->choice.initiatingMessage != NULLP)
2519       {
2520          ulRRCMsg = &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2521          if(ulRRCMsg->protocolIEs.list.array != NULLP)
2522          {
2523             for(idx1=0;idx1<ulRRCMsg->protocolIEs.list.count;idx1++)
2524             {
2525                if(ulRRCMsg->protocolIEs.list.array[idx1] != NULLP)
2526                {
2527                   if(ulRRCMsg->protocolIEs.list.array[idx1]->value.present ==
2528                         ULRRCMessageTransferIEs__value_PR_RRCContainer)
2529                   {
2530                      DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2531                            ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2532                   }
2533                   DU_FREE(ulRRCMsg->protocolIEs.list.array[idx1],sizeof(ULRRCMessageTransferIEs_t));
2534                }
2535             }
2536             DU_FREE(ulRRCMsg->protocolIEs.list.array,ulRRCMsg->protocolIEs.list.size );
2537          }
2538          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2539       }
2540       DU_FREE(f1apMsg,sizeof(F1AP_PDU_t));
2541    }
2542 }
2543 /*******************************************************************
2544  *
2545  * @brief Builds and sends the ULRRCMessageTransfer 
2546  *
2547  * @details
2548  *
2549  *    Function : BuildAndSendULRRCMessageTransfer
2550  *
2551  *    Functionality: Constructs the UL RRC Message Transfer and sends
2552  *                   it to the CU through SCTP.
2553  *
2554  * @params[in] 
2555  *
2556  * @return ROK     - success
2557  *         RFAILED - failure
2558  *
2559  * ****************************************************************/
2560 uint8_t BuildAndSendULRRCMessageTransfer(DuUeCb  ueCb, uint8_t lcId, \
2561       uint16_t msgLen, uint8_t *rrcMsg)
2562 {
2563    uint8_t   elementCnt =0;
2564    uint8_t   idx1 =0;
2565    uint8_t   idx =0;
2566    F1AP_PDU_t                   *f1apMsg = NULLP;
2567    ULRRCMessageTransfer_t       *ulRRCMsg = NULLP;
2568    asn_enc_rval_t               encRetVal;        /* Encoder return value */
2569    uint8_t ret =RFAILED;
2570    
2571    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
2572
2573    while(true)
2574    {
2575       DU_LOG("\n INFO   -->  F1AP : Building UL RRC Message Transfer Message\n");
2576
2577       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
2578       if(f1apMsg == NULLP)
2579       {
2580          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
2581          break;
2582       }
2583       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
2584       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
2585       if(f1apMsg->choice.initiatingMessage == NULLP)
2586       {
2587          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
2588          break;
2589       }
2590       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_ULRRCMessageTransfer;
2591       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
2592       f1apMsg->choice.initiatingMessage->value.present = \
2593                                                          InitiatingMessage__value_PR_ULRRCMessageTransfer;
2594       ulRRCMsg =
2595          &f1apMsg->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
2596       elementCnt = 4;
2597       ulRRCMsg->protocolIEs.list.count = elementCnt;
2598       ulRRCMsg->protocolIEs.list.size = \
2599                                         elementCnt * sizeof(ULRRCMessageTransferIEs_t *);
2600
2601       /* Initialize the F1Setup members */
2602       DU_ALLOC(ulRRCMsg->protocolIEs.list.array, ulRRCMsg->protocolIEs.list.size);
2603       if(ulRRCMsg->protocolIEs.list.array == NULLP)
2604       {
2605          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UL RRC MessageTransferIEs failed");
2606          break;
2607       }
2608       for(idx=0; idx<elementCnt; idx++)
2609       {
2610          DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx],sizeof(ULRRCMessageTransferIEs_t));
2611          if(ulRRCMsg->protocolIEs.list.array[idx] == NULLP)
2612          {
2613             break;
2614          }
2615       }
2616
2617       idx1 = 0;
2618
2619       /*GNB CU UE F1AP ID*/
2620       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
2621       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2622       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2623                                                               ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
2624       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = ueCb.gnbCuUeF1apId;
2625
2626       /*GNB DU UE F1AP ID*/
2627       idx1++;
2628       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
2629       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2630       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2631                                                               ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
2632       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = ueCb.gnbDuUeF1apId;
2633
2634       /*SRBID*/
2635       idx1++;
2636       ulRRCMsg->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
2637       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2638       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2639                                                               ULRRCMessageTransferIEs__value_PR_SRBID;
2640       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.SRBID = lcId;
2641
2642       /*RRCContainer*/
2643       idx1++;
2644       ulRRCMsg->protocolIEs.list.array[idx1]->id  = ProtocolIE_ID_id_RRCContainer;
2645       ulRRCMsg->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
2646       ulRRCMsg->protocolIEs.list.array[idx1]->value.present = \
2647                                                               ULRRCMessageTransferIEs__value_PR_RRCContainer;
2648       ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size = msgLen;
2649       DU_ALLOC(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf,
2650             ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size)
2651       if(!ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf)
2652       {
2653          DU_LOG(" ERROR  -->  F1AP : Memory allocation for BuildAndSendULRRCMessageTransfer failed");
2654          break;
2655       }
2656       memset(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, 0, msgLen);
2657       memcpy(ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.buf, \
2658             rrcMsg, ulRRCMsg->protocolIEs.list.array[idx1]->value.choice.RRCContainer.size);
2659
2660       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
2661
2662       /* Encode the F1SetupRequest type as APER */
2663       memset(encBuf, 0, ENC_BUF_MAX_LEN);
2664       encBufSize = 0;
2665       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
2666             encBuf);
2667       /* Encode results */
2668       if(encRetVal.encoded == ENCODE_FAIL)
2669       {
2670          DU_LOG( "\nERROR  -->  F1AP : Could not encode ULRRCMessageTransfer structure (at %s)\n",\
2671                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2672          break;
2673       }
2674       else
2675       {
2676          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for ULRRCMessageTransfer\n");
2677          for(int i=0; i< encBufSize; i++)
2678          {
2679             printf("%x",encBuf[i]);
2680          }
2681       }
2682
2683       /* Sending  msg  */
2684       if(sendF1APMsg()  !=      ROK)
2685       {
2686          DU_LOG("\nERROR  -->   F1AP : Sending  UL RRC Message Transfer Failed");
2687          break;
2688       }
2689       ret = ROK;
2690       break;
2691    }
2692    FreeULRRCMessageTransfer(f1apMsg);
2693
2694    return ret;
2695 }/* End of BuildAndSendULRRCMessageTransfer*/
2696
2697 /*******************************************************************
2698  *
2699  * @brief Builds tag config 
2700  *
2701  * @details
2702  *
2703  *    Function : BuildTagConfig 
2704  *
2705  *    Functionality: Builds tag config in MacCellGroupConfig
2706  *
2707  * @params[in] TAG_Config *tag_Config
2708  *
2709  * @return ROK     - success
2710  *         RFAILED - failure
2711  *
2712  * ****************************************************************/
2713 uint8_t BuildTagConfig(DuUeCb *ueCb, struct TAG_Config *tagConfig)
2714 {
2715    struct TAG_Config__tag_ToAddModList *tagList;
2716    uint8_t                     idx, elementCnt;
2717
2718    tagConfig->tag_ToReleaseList = NULLP;
2719    tagConfig->tag_ToAddModList = NULLP;
2720    DU_ALLOC(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
2721    if(!tagConfig->tag_ToAddModList)
2722    {
2723       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2724       return RFAILED;
2725    }
2726
2727    if(ueCb == NULLP)
2728       elementCnt = ODU_VALUE_ONE;
2729    else
2730       elementCnt = ueCb->macUeCfg.macCellGrpCfg.tagCfg.addModListCount;
2731
2732    tagList = tagConfig->tag_ToAddModList;
2733    tagList->list.count = elementCnt;
2734    tagList->list.size  =  elementCnt * sizeof(struct TAG *);
2735
2736    tagList->list.array = NULLP;
2737    DU_ALLOC(tagList->list.array, tagList->list.size);
2738    if(!tagList->list.array)
2739    {
2740       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2741       return RFAILED;
2742    }
2743
2744    for(idx=0; idx<tagList->list.count; idx++)
2745    {
2746       tagList->list.array[idx] = NULLP;
2747       DU_ALLOC(tagList->list.array[idx], sizeof(struct TAG));
2748       if(!tagList->list.array[idx])
2749       {
2750          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildTagConfig");
2751          return RFAILED;
2752       }
2753    }
2754
2755    if(ueCb == NULLP)
2756    {
2757       idx = 0;
2758       tagList->list.array[idx]->tag_Id = TAG_ID;
2759       tagList->list.array[idx]->timeAlignmentTimer = TIME_ALIGNMENT_TMR;
2760    }
2761    else
2762    {
2763       for(idx=0; idx<tagList->list.count; idx++)
2764       {
2765          tagList->list.array[idx]->tag_Id = ueCb->macUeCfg.macCellGrpCfg.tagCfg.addModList[idx].tagId;
2766          tagList->list.array[idx]->timeAlignmentTimer = ueCb->macUeCfg.macCellGrpCfg.tagCfg.addModList[idx].timeAlignTimer;
2767       }
2768    }
2769
2770    return ROK;
2771 }
2772
2773 /*******************************************************************
2774  *
2775  * @brief Builds PHR Config 
2776  *
2777  * @details
2778  *
2779  *    Function : BuildPhrConfig
2780  *
2781  *    Functionality: Builds phrConfig in MacCellGroupConfig
2782  *
2783  * @params[in] PHR Config *
2784  *
2785  * @return ROK     - success
2786  *         RFAILED - failure
2787  *
2788  * ****************************************************************/
2789 uint8_t BuildPhrConfig(DuUeCb *ueCb, struct MAC_CellGroupConfig__phr_Config *phrConfig)
2790 {
2791
2792    phrConfig->present = MAC_CellGroupConfig__phr_Config_PR_setup;
2793    phrConfig->choice.setup = NULLP;
2794    DU_ALLOC(phrConfig->choice.setup, sizeof(struct PHR_Config));
2795    if(!phrConfig->choice.setup)
2796    {
2797       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhrConfig");
2798       return RFAILED;
2799    }
2800
2801    if(ueCb == NULLP)
2802    {
2803       phrConfig->choice.setup->phr_PeriodicTimer        = PHR_PERIODIC_TMR;
2804       phrConfig->choice.setup->phr_ProhibitTimer        = PHR_PROHIBHIT_TMR;
2805       phrConfig->choice.setup->phr_Tx_PowerFactorChange = PHR_PWR_FACTOR_CHANGE;
2806       phrConfig->choice.setup->multiplePHR              = false;
2807       phrConfig->choice.setup->dummy                    = false;
2808       phrConfig->choice.setup->phr_Type2OtherCell       = false;
2809       phrConfig->choice.setup->phr_ModeOtherCG          = PHR_MODE_OTHER_CG;
2810    }
2811    else
2812    {
2813       phrConfig->choice.setup->phr_PeriodicTimer        = ueCb->macUeCfg.macCellGrpCfg.phrCfg.periodicTimer;
2814       phrConfig->choice.setup->phr_ProhibitTimer        = ueCb->macUeCfg.macCellGrpCfg.phrCfg.prohibitTimer;
2815       phrConfig->choice.setup->phr_Tx_PowerFactorChange = ueCb->macUeCfg.macCellGrpCfg.phrCfg.txPowerFactor;
2816       phrConfig->choice.setup->multiplePHR              = ueCb->macUeCfg.macCellGrpCfg.phrCfg.multiplePHR;
2817       phrConfig->choice.setup->dummy                    = ueCb->macUeCfg.macCellGrpCfg.phrCfg.dummy;
2818       phrConfig->choice.setup->phr_Type2OtherCell       = ueCb->macUeCfg.macCellGrpCfg.phrCfg.phrType2OtherCell;
2819       phrConfig->choice.setup->phr_ModeOtherCG          = ueCb->macUeCfg.macCellGrpCfg.phrCfg.phrOtherCG;
2820    }
2821
2822    return ROK;
2823 }
2824
2825 /*******************************************************************
2826  *
2827  * @brief Builds BSR Config 
2828  *
2829  * @details
2830  *
2831  *    Function : BuildBsrConfig
2832  *
2833  *    Functionality: Builds BuildBsrConfig in MacCellGroupConfig
2834  *
2835  * @params[in] BSR_Config *bsrConfig
2836  *
2837  * @return ROK     - success
2838  *         RFAILED - failure
2839  *
2840  * ****************************************************************/
2841 uint8_t BuildBsrConfig(DuUeCb *ueCb, struct BSR_Config *bsrConfig)
2842 {
2843    if(ueCb == NULLP)
2844    {
2845       bsrConfig->periodicBSR_Timer = PERIODIC_BSR_TMR;
2846       bsrConfig->retxBSR_Timer     = RETX_BSR_TMR;
2847       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
2848    }
2849    else
2850    {
2851       bsrConfig->periodicBSR_Timer = convertBsrPeriodicTmrValueToEnum(ueCb->macUeCfg.macCellGrpCfg.bsrTmrCfg.periodicTimer);
2852       bsrConfig->retxBSR_Timer     = convertBsrRetxTmrValueToEnum(ueCb->macUeCfg.macCellGrpCfg.bsrTmrCfg.retxTimer);
2853
2854       bsrConfig->logicalChannelSR_DelayTimer = NULLP;
2855       DU_ALLOC(bsrConfig->logicalChannelSR_DelayTimer, sizeof(long));
2856       if(bsrConfig->logicalChannelSR_DelayTimer == NULLP)
2857       {
2858          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildBsrConfig");
2859          return RFAILED;
2860       }
2861       *(bsrConfig->logicalChannelSR_DelayTimer) = convertLcSrDelayTmrValueToEnum(ueCb->macUeCfg.macCellGrpCfg.bsrTmrCfg.srDelayTimer);
2862    }
2863
2864    return ROK;
2865 }
2866
2867 /*******************************************************************
2868  *
2869  * @brief Builds scheduling request config 
2870  *
2871  * @details
2872  *
2873  *    Function : BuildSchedulingReqConfig 
2874  *
2875  *    Functionality: Builds BuildSchedulingReqConfig in MacCellGroupConfig
2876  *
2877  * @params[in] SchedulingRequestConfig *schedulingRequestConfig
2878  *
2879  * @return ROK     - success
2880  *         RFAILED - failure
2881  *
2882  * ****************************************************************/
2883 uint8_t BuildSchedulingReqConfig(DuUeCb *ueCb, struct SchedulingRequestConfig *schedulingRequestConfig)
2884 {
2885    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList;
2886    uint8_t                     idx, elementCnt;
2887
2888    schedulingRequestConfig->schedulingRequestToAddModList = NULLP;
2889    DU_ALLOC(schedulingRequestConfig->schedulingRequestToAddModList,
2890          sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));
2891    if(!schedulingRequestConfig->schedulingRequestToAddModList)
2892    {
2893       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2894       return RFAILED;
2895    }
2896
2897    if(ueCb == NULLP)
2898       elementCnt = ODU_VALUE_ONE;
2899    else
2900       elementCnt = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModListCount;
2901
2902    schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
2903    schReqList->list.count = elementCnt;
2904    schReqList->list.size  = elementCnt * sizeof(struct SchedulingRequestToAddMod *);
2905
2906    schReqList->list.array = NULLP;
2907    DU_ALLOC(schReqList->list.array, schReqList->list.size);
2908    if(!schReqList->list.array)
2909    {
2910       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2911       return RFAILED;
2912    }
2913
2914    for(idx=0; idx<schReqList->list.count; idx++)
2915    {
2916       schReqList->list.array[idx] = NULLP;
2917       DU_ALLOC(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
2918       if(!schReqList->list.array[idx])
2919       {
2920          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2921          return RFAILED;
2922       }
2923    }
2924
2925    if(ueCb == NULLP)
2926    {
2927       idx = 0;
2928       schReqList->list.array[idx]->schedulingRequestId = SCH_REQ_ID;
2929
2930       schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
2931       DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
2932       if(!schReqList->list.array[idx]->sr_ProhibitTimer)
2933       {
2934          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2935          return RFAILED;
2936       }
2937       *(schReqList->list.array[idx]->sr_ProhibitTimer) = SR_PROHIBIT_TMR;
2938       schReqList->list.array[idx]->sr_TransMax = SR_TRANS_MAX;
2939    }
2940    else
2941    {
2942       for(idx=0; idx<schReqList->list.count; idx++)
2943       {
2944          schReqList->list.array[idx]->schedulingRequestId = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].schedReqId;
2945
2946          schReqList->list.array[idx]->sr_ProhibitTimer = NULLP;
2947          DU_ALLOC(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
2948          if(!schReqList->list.array[idx]->sr_ProhibitTimer)
2949          {
2950             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSchedulingReqConfig");
2951             return RFAILED;
2952          }
2953          *(schReqList->list.array[idx]->sr_ProhibitTimer) = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srProhibitTmr;
2954          schReqList->list.array[idx]->sr_TransMax = ueCb->macUeCfg.macCellGrpCfg.schReqCfg.addModList[idx].srTransMax;
2955       }
2956    }
2957
2958    schedulingRequestConfig->schedulingRequestToReleaseList = NULLP;
2959
2960    return ROK;
2961 }
2962
2963 /*******************************************************************
2964  *
2965  * @brief Builds RLC Configuration for AM mode
2966  *
2967  * @details
2968  *
2969  *    Function : BuildRlcConfigAm
2970  *
2971  *    Functionality: 
2972  *       Builds AM mode RLC Config in BuildRlcBearerToAddModList
2973  *
2974  * @params[in] AmBearerCfg *amCfg
2975  *             RLC_Config_t  *rlcConfig
2976  *
2977  * @return ROK     - success
2978  *         RFAILED - failure
2979  *
2980  * ****************************************************************/
2981 uint8_t BuildRlcConfigAm(AmBearerCfg *amCfg, struct RLC_Config *rlcConfig)
2982 {
2983    rlcConfig->choice.am = NULLP;
2984    DU_ALLOC(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
2985    if(!rlcConfig->choice.am)
2986    {
2987       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
2988       return RFAILED;
2989    }
2990
2991    /* Fill AM UL configuration */
2992    rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength = NULLP;
2993    DU_ALLOC(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
2994    if(!rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength)
2995    {
2996       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
2997       return RFAILED;
2998    }
2999
3000    /* Fill default AM UL configuration if input pointer to DU database is NULL */
3001    if(amCfg == NULLP)
3002    {
3003       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = SN_FIELD_LEN;
3004       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = T_POLL_RETRANSMIT;
3005       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = POLL_PDU;
3006       rlcConfig->choice.am->ul_AM_RLC.pollByte          = POLL_BYTE;
3007       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = MAX_RETX_THRESHOLD;
3008    }
3009    else
3010    {
3011       *(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->dlAmCfg.snLenDl);
3012       rlcConfig->choice.am->ul_AM_RLC.t_PollRetransmit  = covertPollRetxTmrValueToEnum(amCfg->dlAmCfg.pollRetxTmr);
3013       rlcConfig->choice.am->ul_AM_RLC.pollPDU           = covertPollPduValueToEnum(amCfg->dlAmCfg.pollPdu);
3014       rlcConfig->choice.am->ul_AM_RLC.pollByte          = covertPollByteValueToEnum(amCfg->dlAmCfg.pollByte);
3015       rlcConfig->choice.am->ul_AM_RLC.maxRetxThreshold  = covertMaxRetxValueToEnum(amCfg->dlAmCfg.maxRetxTh);
3016    }
3017
3018    /* Fill AM DL configuraion */
3019    rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength = NULLP;
3020    DU_ALLOC(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
3021    if(!rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength)
3022    {
3023       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigAm");
3024       return RFAILED;
3025    }
3026
3027    /* Fill default AM DL configuration if input pointer to DU database is NULL */
3028    if(amCfg == NULLP)
3029    {
3030       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = SN_FIELD_LEN;
3031       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = T_REASSEMBLY;
3032       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = T_STATUS_PROHIBHIT;
3033    }
3034    else /* Fill AM configuration from DU database */
3035    {
3036       *(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength) = covertAmSnLenFromIntEnumToRrcEnum(amCfg->ulAmCfg.snLenUl);
3037       rlcConfig->choice.am->dl_AM_RLC.t_Reassembly      = convertReasmblTmrValueToEnum(amCfg->ulAmCfg.reAssemTmr);
3038       rlcConfig->choice.am->dl_AM_RLC.t_StatusProhibit  = convertProhibitTmrValueToEnum(amCfg->ulAmCfg.statProhTmr);
3039    }
3040    return ROK;
3041 }
3042
3043 /*******************************************************************
3044  *
3045  * @brief Builds RLC Config for UM Bidirection
3046  *
3047  * @details
3048  *
3049  *    Function : BuildRlcConfig UmBiDir
3050  *
3051  *    Functionality: 
3052  *       Builds RLC Config for UM Bidirection in BuildRlcBearerToAddModList 
3053  *
3054  * @params[in] UmBiDirBearerCfg *umBiDirCfg
3055  *             RLC_Config_t *rlcConfig
3056  *
3057  * @return ROK     - success
3058  *         RFAILED - failure
3059  *
3060  * ****************************************************************/
3061 uint8_t BuildRlcConfigUmBiDir(UmBiDirBearerCfg *umBiDirCfg, struct RLC_Config *rlcConfig)
3062 {
3063    rlcConfig->choice.um_Bi_Directional = NULLP;
3064    DU_ALLOC(rlcConfig->choice.um_Bi_Directional, sizeof(struct RLC_Config__um_Bi_Directional));
3065    if(rlcConfig->choice.um_Bi_Directional == NULLP)
3066    {
3067       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3068       return RFAILED;
3069    }
3070
3071    /* Fill UM Bidirectional UL configuration */
3072    rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength = NULLP;
3073    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3074    if(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength == NULLP)
3075    {
3076       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3077       return RFAILED;
3078    }
3079
3080    if(umBiDirCfg != NULLP)
3081    {
3082       *(rlcConfig->choice.um_Bi_Directional->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->dlUmCfg.snLenDlUm);     
3083    }
3084
3085    /* Fill UM Bidirectional DL configuration */
3086    rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength = NULLP;
3087    DU_ALLOC(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3088    if(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength == NULLP)
3089    {
3090       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmBiDir");
3091       return RFAILED;
3092    }
3093
3094    if(umBiDirCfg != NULLP)
3095    {
3096       *(rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umBiDirCfg->ulUmCfg.snLenUlUm);     
3097       rlcConfig->choice.um_Bi_Directional->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umBiDirCfg->ulUmCfg.reAssemTmr);
3098    }
3099
3100    return ROK;
3101 }
3102
3103 /*******************************************************************
3104  *
3105  * @brief Builds RLC Config for UM Uni directional UL
3106  *
3107  * @details
3108  *
3109  *    Function : BuildRlcConfigUmUniDirUl
3110  *
3111  *    Functionality: 
3112  *       Builds RLC Config for UM Unidirection UL in BuildRlcBearerToAddModList 
3113  *
3114  * @params[in] UmUniDirDlBearerCfg *umUniDirDlCfg
3115  *             RLC_Config_t *rlcConfig
3116  *
3117  * @return ROK     - success
3118  *         RFAILED - failure
3119  *
3120  * ****************************************************************/
3121 uint8_t BuildRlcConfigUmUniDirUl(UmUniDirDlBearerCfg *umUniDirDlCfg, RLC_Config_t *rlcConfig)
3122 {
3123    rlcConfig->choice.um_Uni_Directional_UL = NULLP;
3124    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL , sizeof(struct RLC_Config__um_Uni_Directional_UL));
3125    if(rlcConfig->choice.um_Uni_Directional_UL == NULLP)
3126    {
3127       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3128       return RFAILED;
3129    }
3130
3131    rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength = NULLP;
3132    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3133    if(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength == NULLP)
3134    {
3135       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirUl");
3136       return RFAILED;
3137    }
3138
3139    if(umUniDirDlCfg != NULLP)
3140    {
3141       *(rlcConfig->choice.um_Uni_Directional_UL->ul_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirDlCfg->dlUmCfg.snLenDlUm);
3142    }
3143
3144    return ROK;
3145 }
3146
3147 /*******************************************************************
3148  *
3149  * @brief Builds RLC Config for UM Uni directional DL
3150  *
3151  * @details
3152  *
3153  *    Function : BuildRlcConfigUmUniDirDl
3154  *
3155  *    Functionality: 
3156  *       Builds RLC Config for UM Unidirection DL in BuildRlcBearerToAddModList 
3157  *
3158  * @params[in] UmUniDirUlBearerCfg *umUniDirUlCfg
3159  *             RLC_Config_t *rlcConfig
3160  *
3161  * @return ROK     - success
3162  *         RFAILED - failure
3163  *
3164  * ****************************************************************/
3165 uint8_t BuildRlcConfigUmUniDirDl(UmUniDirUlBearerCfg *umUniDirUlCfg, RLC_Config_t *rlcConfig)
3166 {
3167    rlcConfig->choice.um_Uni_Directional_DL = NULLP;
3168    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL , sizeof(struct RLC_Config__um_Uni_Directional_DL));
3169    if(rlcConfig->choice.um_Uni_Directional_DL == NULLP)
3170    {
3171       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3172       return RFAILED;
3173    }
3174
3175    rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength = NULLP;
3176    DU_ALLOC(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength, sizeof(SN_FieldLengthUM_t));
3177    if(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength == NULLP)
3178    {
3179       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcConfigUmUniDirDl");
3180       return RFAILED;
3181    }
3182
3183    if(umUniDirUlCfg != NULLP)
3184    {
3185       *(rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.sn_FieldLength) = covertUmSnLenFromIntEnumToRrcEnum(umUniDirUlCfg->ulUmCfg.snLenUlUm);
3186       rlcConfig->choice.um_Uni_Directional_DL->dl_UM_RLC.t_Reassembly = convertReasmblTmrValueToEnum(umUniDirUlCfg->ulUmCfg.reAssemTmr);
3187    }
3188
3189    return ROK;
3190 }
3191
3192 /*******************************************************************
3193  *
3194  * @brief Builds RLC Config
3195  *
3196  * @details
3197  *
3198  *    Function : BuildRlcConfig
3199  *
3200  *    Functionality: Builds RLC Config in BuildRlcBearerToAddModList 
3201  *
3202  * @params[in] RLC_Config_t *rlcConfig
3203  *
3204  * @return ROK     - success
3205  *         RFAILED - failure
3206  *
3207  * ****************************************************************/
3208 uint8_t BuildRlcConfig(RlcBearerCfg *rbCfg, struct RLC_Config *rlcConfig)
3209 {
3210    
3211    /* Fill default values if rbCfg is NULL */
3212    if(rbCfg == NULLP)
3213    {
3214       rlcConfig->present = RLC_Config_PR_am;
3215       BuildRlcConfigAm(NULLP, rlcConfig);
3216    }
3217    /* If RbCfg is present, fill RLC configurations from DU Database */
3218    else
3219    {
3220       rlcConfig->present = covertRlcModeFromIntEnumToRrcEnum(rbCfg->rlcMode);
3221       switch(rlcConfig->present)
3222       {
3223          case RLC_Config_PR_am:
3224             BuildRlcConfigAm(rbCfg->u.amCfg, rlcConfig);
3225             break;
3226          case RLC_Config_PR_um_Bi_Directional:
3227             BuildRlcConfigUmBiDir(rbCfg->u.umBiDirCfg, rlcConfig);
3228             break;
3229          case RLC_Config_PR_um_Uni_Directional_UL:
3230             BuildRlcConfigUmUniDirUl(rbCfg->u.umUniDirDlCfg, rlcConfig);
3231             break;
3232          case RLC_Config_PR_um_Uni_Directional_DL:
3233             BuildRlcConfigUmUniDirDl(rbCfg->u.umUniDirUlCfg, rlcConfig);
3234             break;
3235          case RLC_Config_PR_NOTHING:
3236          default:
3237             break;
3238       }
3239    }
3240
3241    return ROK;
3242 }
3243
3244 /*******************************************************************
3245  *
3246  * @brief Builds MAC LC Config
3247  *
3248  * @details
3249  *
3250  *    Function : BuildMacLCConfig 
3251  *
3252  *    Functionality: Builds MAC LC Config in BuildRlcBearerToAddModList 
3253  *
3254  * @params[in] struct LogicalChannelConfig macLcConfig
3255  *
3256  * @return ROK     - success
3257  *         RFAILED - failure
3258  *
3259  * ****************************************************************/
3260 uint8_t BuildMacLCConfig(LcCfg *lcCfgDb, struct LogicalChannelConfig *macLcConfig)
3261 {
3262    macLcConfig->ul_SpecificParameters = NULLP;
3263    DU_ALLOC(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
3264    if(!macLcConfig->ul_SpecificParameters)
3265    {
3266       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3267       return RFAILED;
3268    }
3269
3270    if(lcCfgDb == NULLP)
3271    {
3272       macLcConfig->ul_SpecificParameters->priority = MAC_LC_PRIORITY;
3273       macLcConfig->ul_SpecificParameters->prioritisedBitRate =  PRIORTISIED_BIT_RATE;
3274       macLcConfig->ul_SpecificParameters->bucketSizeDuration =  BUCKET_SIZE_DURATION;
3275    }
3276    else
3277    {
3278       macLcConfig->ul_SpecificParameters->priority = lcCfgDb->ulLcCfg.priority;
3279       macLcConfig->ul_SpecificParameters->prioritisedBitRate = lcCfgDb->ulLcCfg.pbr;
3280       macLcConfig->ul_SpecificParameters->bucketSizeDuration = lcCfgDb->ulLcCfg.bsd;
3281    }
3282
3283    macLcConfig->ul_SpecificParameters->allowedServingCells = NULLP;
3284    macLcConfig->ul_SpecificParameters->allowedSCS_List = NULLP;
3285    macLcConfig->ul_SpecificParameters->maxPUSCH_Duration = NULLP;
3286    macLcConfig->ul_SpecificParameters->configuredGrantType1Allowed = NULLP;
3287
3288    macLcConfig->ul_SpecificParameters->logicalChannelGroup = NULLP;
3289    DU_ALLOC(macLcConfig->ul_SpecificParameters->logicalChannelGroup,    sizeof(long));
3290    if(!macLcConfig->ul_SpecificParameters->logicalChannelGroup)
3291    {
3292       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3293       return RFAILED;
3294    }
3295
3296    if(lcCfgDb == NULLP)
3297       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = LC_GRP;
3298    else
3299       *(macLcConfig->ul_SpecificParameters->logicalChannelGroup) = lcCfgDb->ulLcCfg.lcGroup;
3300
3301    macLcConfig->ul_SpecificParameters->schedulingRequestID = NULLP;
3302    DU_ALLOC(macLcConfig->ul_SpecificParameters->schedulingRequestID,    sizeof(SchedulingRequestId_t));
3303    if(!macLcConfig->ul_SpecificParameters->schedulingRequestID)
3304    {
3305       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacLCConfig");
3306       return RFAILED;
3307    }
3308
3309    if(lcCfgDb == NULLP)
3310       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = SCH_REQ_ID;
3311    else
3312       *(macLcConfig->ul_SpecificParameters->schedulingRequestID) = lcCfgDb->ulLcCfg.schReqId;
3313
3314    macLcConfig->ul_SpecificParameters->logicalChannelSR_Mask = false;
3315    macLcConfig->ul_SpecificParameters->logicalChannelSR_DelayTimerApplied = false;
3316    macLcConfig->ul_SpecificParameters->bitRateQueryProhibitTimer = NULLP;
3317
3318    return ROK;
3319 }
3320
3321 /*******************************************************************
3322  *
3323  * @brief Builds RLC Bearer to Add/Mod list
3324  *
3325  * @details
3326  *
3327  *    Function :BuildRlcBearerToAddModList 
3328  *
3329  *    Functionality: Builds RLC Bearer to Add/Mod list in DuToCuRrcContainer
3330  *
3331  * @params[in] rlc_BearerToAddModList
3332  *
3333  * @return ROK     - success
3334  *         RFAILED - failure
3335  *
3336  * ****************************************************************/
3337 uint8_t BuildRlcBearerToAddModList(DuUeCb *ueCb, struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList)
3338 {
3339    uint8_t  idx = 0, lcIdx=0, macLcIdx = 0, elementCnt = 0;
3340
3341    if(ueCb == NULLP)
3342       elementCnt = 1;
3343    else if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
3344       elementCnt = ueCb->rlcUeCfg.numLcs;
3345    else
3346    {
3347       for(lcIdx = 0; lcIdx<ueCb->rlcUeCfg.numLcs; lcIdx++)
3348       {
3349          if(ueCb->rlcUeCfg.rlcLcCfg[lcIdx].isLcAddModRspSent == false)
3350             elementCnt++;
3351       }
3352    }
3353    rlcBearerList->list.count = elementCnt;
3354    rlcBearerList->list.size  = elementCnt * sizeof(struct RLC_BearerConfig *);
3355
3356    rlcBearerList->list.array = NULLP;
3357    DU_ALLOC(rlcBearerList->list.array, rlcBearerList->list.size);
3358    if(!rlcBearerList->list.array)
3359    {
3360       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3361       return RFAILED;
3362    }
3363
3364    for(idx=0; idx<rlcBearerList->list.count; idx++)
3365    {
3366       rlcBearerList->list.array[idx] = NULLP;
3367       DU_ALLOC(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
3368       if(!rlcBearerList->list.array[idx])
3369       {
3370          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3371          return RFAILED;
3372       }
3373    }
3374
3375    if(ueCb == NULLP)
3376    {
3377       idx=0;
3378       rlcBearerList->list.array[idx]->logicalChannelIdentity = SRB1_LCID;
3379       DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3380       if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3381       {     
3382          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3383          return RFAILED;
3384       }     
3385       rlcBearerList->list.array[idx]->servedRadioBearer->present = RLC_BearerConfig__servedRadioBearer_PR_srb_Identity;
3386       rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = SRB1_LCID;
3387       rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3388
3389       /* Fill RLC related Configurations for this Radio Bearer */
3390       rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3391       DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3392       if(!rlcBearerList->list.array[idx]->rlc_Config)
3393       {
3394          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3395          return RFAILED;
3396       }
3397       if(BuildRlcConfig(NULLP, rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3398       {
3399          DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3400          return RFAILED;
3401       }
3402
3403       /* Fill MAC related configurations for this Radio Bearer */
3404       rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3405       DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3406       if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3407       {
3408          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3409          return RFAILED;
3410       }
3411       if(BuildMacLCConfig(NULLP, rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3412       {
3413          DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3414          return RFAILED;
3415       }
3416    }
3417    else
3418    {
3419       idx=0;
3420       for(lcIdx=0; lcIdx<ueCb->rlcUeCfg.numLcs; lcIdx++)
3421       {
3422          if((ueCb->f1UeDb->actionType != UE_CTXT_CFG_QUERY) && (ueCb->rlcUeCfg.rlcLcCfg[lcIdx].isLcAddModRspSent == true))
3423             continue;
3424
3425          /* Fill Logical channel identity */
3426          rlcBearerList->list.array[idx]->logicalChannelIdentity = ueCb->rlcUeCfg.rlcLcCfg[lcIdx].lcId;
3427
3428          /* Fill Radio Bearer Id and type (DRB/SRB) for this logical channel */
3429          DU_ALLOC(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
3430          if(!rlcBearerList->list.array[idx]->servedRadioBearer)
3431          {
3432             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3433             return RFAILED;
3434          }
3435          rlcBearerList->list.array[idx]->servedRadioBearer->present = \
3436                                                                       covertRbTypeFromIntEnumToRrcEnum(ueCb->rlcUeCfg.rlcLcCfg[lcIdx].rbType);
3437          switch(rlcBearerList->list.array[idx]->servedRadioBearer->present)
3438          {
3439             case RLC_BearerConfig__servedRadioBearer_PR_srb_Identity: 
3440                rlcBearerList->list.array[idx]->servedRadioBearer->choice.srb_Identity = ueCb->rlcUeCfg.rlcLcCfg[lcIdx].rbId;
3441                break;
3442             case RLC_BearerConfig__servedRadioBearer_PR_drb_Identity:
3443                rlcBearerList->list.array[idx]->servedRadioBearer->choice.drb_Identity = ueCb->rlcUeCfg.rlcLcCfg[lcIdx].rbId;
3444                break;
3445             case RLC_BearerConfig__servedRadioBearer_PR_NOTHING:
3446             default:
3447                break;
3448          }
3449          ueCb->rlcUeCfg.rlcLcCfg[lcIdx].isLcAddModRspSent = true;
3450
3451          rlcBearerList->list.array[idx]->reestablishRLC = NULLP;
3452
3453          /* Fill RLC related Configurations for this Radio Bearer */
3454          rlcBearerList->list.array[idx]->rlc_Config = NULLP;
3455          DU_ALLOC(rlcBearerList->list.array[idx]->rlc_Config, sizeof(struct RLC_Config));
3456          if(!rlcBearerList->list.array[idx]->rlc_Config)
3457          {
3458             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3459             return RFAILED;
3460          }
3461          if(BuildRlcConfig(&ueCb->rlcUeCfg.rlcLcCfg[lcIdx], rlcBearerList->list.array[idx]->rlc_Config) != ROK)
3462          {
3463             DU_LOG("\nERROR  -->  F1AP : BuildRlcConfig failed");
3464             return RFAILED;
3465          }
3466
3467          /* Fill MAC related configurations for this Radio Bearer */
3468          rlcBearerList->list.array[idx]->mac_LogicalChannelConfig = NULLP;
3469          DU_ALLOC(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
3470          if(!rlcBearerList->list.array[idx]->mac_LogicalChannelConfig)
3471          {
3472             DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildRlcBearerToAddModList");
3473             return RFAILED;
3474          }
3475          for(macLcIdx = 0; macLcIdx < ueCb->macUeCfg.numLcs; macLcIdx++)
3476          {
3477             if(ueCb->macUeCfg.lcCfgList[macLcIdx].lcId == ueCb->rlcUeCfg.rlcLcCfg[lcIdx].lcId)
3478             {
3479                if(BuildMacLCConfig(&ueCb->macUeCfg.lcCfgList[macLcIdx], rlcBearerList->list.array[idx]->mac_LogicalChannelConfig) != ROK)
3480                {
3481                   DU_LOG("\nERROR  -->  F1AP : BuildMacLCConfig failed");
3482                   return RFAILED;
3483                }
3484                break;
3485             }
3486          }
3487
3488          idx++;
3489       }
3490    }
3491    return ROK;
3492 }
3493
3494 /*******************************************************************
3495  *
3496  * @brief Build Control resource set to add/modify list 
3497  *
3498  * @details
3499  *
3500  *    Function : BuildControlRSetToAddModList
3501  *
3502  *    Functionality: Build Control resource set to add/modify list
3503  *
3504  * @params[in] 
3505  * struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList
3506  *
3507  * @return ROK     - success
3508  *         RFAILED - failure
3509  *
3510  * ****************************************************************/
3511 uint8_t BuildControlRSetToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList)
3512 {
3513    uint8_t idx;
3514    uint8_t elementCnt;
3515    uint8_t numBytes, bitsUnused;
3516    struct ControlResourceSet *controlRSet;
3517    uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
3518    uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
3519
3520    if(pdcchCfg == NULLP)
3521       elementCnt = 1;
3522    else
3523       elementCnt = pdcchCfg->numCRsetToAddMod;
3524
3525    controlRSetList->list.count = elementCnt;
3526    controlRSetList->list.size = elementCnt * sizeof(struct ControlResourceSet *);
3527
3528    controlRSetList->list.array = NULLP;
3529    DU_ALLOC(controlRSetList->list.array, controlRSetList->list.size);
3530    if(!controlRSetList->list.array)
3531    {
3532       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3533       return RFAILED;
3534    }
3535
3536    for(idx = 0; idx < elementCnt; idx++)
3537    {
3538       controlRSetList->list.array[idx] = NULLP;
3539       DU_ALLOC(controlRSetList->list.array[idx], sizeof(struct ControlResourceSet));
3540       if(!controlRSetList->list.array[idx])
3541       {
3542          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3543          return RFAILED;
3544       }
3545    }
3546
3547    for(idx = 0; idx < elementCnt; idx++)
3548    {
3549       controlRSet = controlRSetList->list.array[idx];
3550
3551       if(pdcchCfg == NULLP)
3552          controlRSet->controlResourceSetId = PDCCH_CTRL_RSRC_SET_ONE_ID;
3553       else
3554          controlRSet->controlResourceSetId = pdcchCfg->cRSetToAddModList[idx].cRSetId;
3555
3556       /* size 6 bytes
3557        * 3 LSBs unsued
3558        * Bit string stored ff0000000000
3559        */
3560       numBytes = 6;
3561       bitsUnused = 3;
3562       controlRSet->frequencyDomainResources.size = numBytes * sizeof(uint8_t);
3563
3564       controlRSet->frequencyDomainResources.buf = NULLP;
3565       DU_ALLOC(controlRSet->frequencyDomainResources.buf, controlRSet->frequencyDomainResources.size);
3566       if(!controlRSet->frequencyDomainResources.buf)
3567       {
3568          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3569          return RFAILED;
3570       }
3571
3572       memset(controlRSet->frequencyDomainResources.buf, 0, FREQ_DOM_RSRC_SIZE);
3573
3574       if(pdcchCfg == NULLP)
3575       {
3576          coreset0EndPrb = CORESET0_END_PRB;
3577          coreset1StartPrb = coreset0EndPrb + 6;
3578          coreset1NumPrb = CORESET1_NUM_PRB;
3579          /* calculate the PRBs */
3580          fillCoresetFeqDomAllocMap(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
3581          memcpy(controlRSet->frequencyDomainResources.buf, freqDomainResource, FREQ_DOM_RSRC_SIZE);
3582          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3583
3584          controlRSet->duration = PDCCH_CTRL_RSRC_SET_ONE_DURATION;
3585          controlRSet->cce_REG_MappingType.present = ControlResourceSet__cce_REG_MappingType_PR_nonInterleaved;
3586          controlRSet->precoderGranularity = PDCCH_CTRL_RSRC_SET_ONE_PRECOD_GRANULARITY;
3587       }
3588       else
3589       {
3590          memcpy(controlRSet->frequencyDomainResources.buf, pdcchCfg->cRSetToAddModList[idx].freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
3591          controlRSet->frequencyDomainResources.bits_unused = bitsUnused;
3592          controlRSet->duration = pdcchCfg->cRSetToAddModList[idx].duration;
3593          controlRSet->cce_REG_MappingType.present = pdcchCfg->cRSetToAddModList[idx].cceRegMappingType;
3594          controlRSet->precoderGranularity = pdcchCfg->cRSetToAddModList[idx].precoderGranularity;
3595       }
3596       controlRSet->tci_StatesPDCCH_ToAddList = NULLP;
3597       controlRSet->tci_StatesPDCCH_ToReleaseList = NULLP;
3598       controlRSet->tci_PresentInDCI = NULLP;
3599
3600 #if 0
3601       uint8_t tciStateIdx;
3602
3603       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList, \
3604             sizeof(struct ControlResourceSet__tci_StatesPDCCH_ToAddList));
3605       if(!controlRset->tci_StatesPDCCH_ToAddList)
3606       {
3607          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3608          return RFAILED;
3609       }
3610
3611       elementCnt = 1;
3612       controlRset->tci_StatesPDCCH_ToAddList->list.count = elementCnt;
3613       controlRset->tci_StatesPDCCH_ToAddList->list.size = elementCnt * sizeof(TCI_StateId_t *);
3614       DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array, \
3615             controlRset->tci_StatesPDCCH_ToAddList->list.size)
3616          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array)
3617          {
3618             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3619             return RFAILED;
3620          }
3621
3622       for(tciStateIdx = 0; tciStateIdx <elementCntl; tciStateIdx++)
3623       {
3624          DU_ALLOC(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx], sizeof(TCI_StateId_t));
3625          if(!controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx])
3626          {
3627             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3628             return RFAILED;
3629          }
3630       }
3631
3632       tciStateIdx = 0;
3633       /* TODO */
3634       *(controlRset->tci_StatesPDCCH_ToAddList->list.array[tciStateIdx]);
3635
3636       DU_ALLOC(controlRset->tci_PresentInDCI, sizeof(long));
3637       if(!controlRset->tci_PresentInDCI)
3638       {
3639          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3640          return RFAILED;
3641       }
3642       /* TODO */
3643       *(controlRset->tci_PresentInDCI);
3644 #endif
3645
3646       controlRSet->pdcch_DMRS_ScramblingID = NULLP;
3647       DU_ALLOC(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
3648       if(!controlRSet->pdcch_DMRS_ScramblingID)
3649       {
3650          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildControlRSetToAddModList");
3651          return RFAILED;
3652       }
3653       if(pdcchCfg == NULLP)
3654          *(controlRSet->pdcch_DMRS_ScramblingID) = SCRAMBLING_ID;
3655       else
3656          *(controlRSet->pdcch_DMRS_ScramblingID) = pdcchCfg->cRSetToAddModList[idx].dmrsScramblingId;
3657    }
3658    return ROK;
3659 } /* End BuildControlRSetToAddModList */
3660
3661 /*******************************************************************
3662  *
3663  * @brief Build search space to add/modify list
3664  *
3665  * @details
3666  *
3667  *    Function : BuildSearchSpcToAddModList
3668  *
3669  *    Functionality: Build search space to add/modify list
3670  *
3671  * @params[in] 
3672  * @return ROK     - success
3673  *         RFAILED - failure
3674  *
3675  * ****************************************************************/
3676 uint8_t BuildSearchSpcToAddModList(PdcchConfig *pdcchCfg, struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
3677 {
3678    uint8_t idx;
3679    uint8_t numBytes;
3680    uint8_t byteIdx;
3681    uint8_t bitsUnused;
3682    uint8_t elementCnt;
3683    struct SearchSpace *searchSpc;
3684
3685    if(pdcchCfg == NULLP)
3686       elementCnt = 1;
3687    else
3688       elementCnt = pdcchCfg->numSearchSpcToAddMod;
3689
3690    searchSpcList->list.count = elementCnt;
3691    searchSpcList->list.size = elementCnt * sizeof(struct SearchSpace *);
3692
3693    searchSpcList->list.array = NULLP;
3694    DU_ALLOC(searchSpcList->list.array, searchSpcList->list.size);
3695    if(!searchSpcList->list.array)
3696    {
3697       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3698       return RFAILED;
3699    }
3700
3701    for(idx = 0; idx < elementCnt; idx++)
3702    {
3703       searchSpcList->list.array[idx] = NULLP;
3704       DU_ALLOC(searchSpcList->list.array[idx], sizeof(struct SearchSpace));
3705       if(!searchSpcList->list.array[idx])
3706       {
3707          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3708          return RFAILED;
3709       }
3710    }
3711
3712    for(idx = 0; idx < elementCnt; idx++)
3713    {
3714       searchSpc = searchSpcList->list.array[idx];
3715
3716       if(pdcchCfg == NULLP)
3717          searchSpc->searchSpaceId = PDCCH_SRCH_SPC_TWO_ID;
3718       else
3719          searchSpc->searchSpaceId = pdcchCfg->searchSpcToAddModList[idx].searchSpaceId;
3720
3721       searchSpc->controlResourceSetId = NULLP;
3722       DU_ALLOC(searchSpc->controlResourceSetId, sizeof(ControlResourceSetId_t));
3723       if(!searchSpc->controlResourceSetId)
3724       {
3725          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3726          return RFAILED;
3727       }
3728       if(pdcchCfg == NULLP)
3729          *(searchSpc->controlResourceSetId) = PDCCH_CTRL_RSRC_SET_ONE_ID;
3730       else
3731          *(searchSpc->controlResourceSetId) = pdcchCfg->searchSpcToAddModList[idx].cRSetId;
3732
3733       searchSpc->monitoringSlotPeriodicityAndOffset = NULLP;
3734       DU_ALLOC(searchSpc->monitoringSlotPeriodicityAndOffset, sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
3735       if(!searchSpc->monitoringSlotPeriodicityAndOffset)
3736       {
3737          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3738          return RFAILED;
3739       }
3740       if(pdcchCfg == NULLP)
3741          searchSpc->monitoringSlotPeriodicityAndOffset->present = SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
3742       else
3743          searchSpc->monitoringSlotPeriodicityAndOffset->present = pdcchCfg->searchSpcToAddModList[idx].mSlotPeriodicityAndOffset;
3744
3745       searchSpc->duration = NULLP;
3746       searchSpc->monitoringSymbolsWithinSlot = NULLP;
3747       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot, sizeof(BIT_STRING_t));
3748       if(!searchSpc->monitoringSymbolsWithinSlot)
3749       {
3750          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3751          return RFAILED;
3752       }
3753
3754       /* Values taken from reference logs :
3755        * size 2 bytes
3756        * 2 LSBs unsued
3757        * Bit string stores 8000
3758        */
3759       numBytes = 2;
3760       bitsUnused = 2;
3761       searchSpc->monitoringSymbolsWithinSlot->size = numBytes * sizeof(uint8_t);
3762       searchSpc->monitoringSymbolsWithinSlot->buf = NULLP;
3763       DU_ALLOC(searchSpc->monitoringSymbolsWithinSlot->buf, searchSpc->monitoringSymbolsWithinSlot->size);
3764       if(!searchSpc->monitoringSymbolsWithinSlot->buf)
3765       {
3766          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3767          return RFAILED;
3768       }
3769       if(pdcchCfg == NULLP)
3770       {
3771          byteIdx = 0;
3772          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = PDCCH_SYMBOL_WITHIN_SLOT /* setting MSB to 128 i.e. 0x80 */;
3773          searchSpc->monitoringSymbolsWithinSlot->buf[byteIdx++] = 0;
3774       }
3775       else
3776          memcpy(searchSpc->monitoringSymbolsWithinSlot->buf, pdcchCfg->searchSpcToAddModList[idx].mSymbolsWithinSlot, numBytes);
3777       searchSpc->monitoringSymbolsWithinSlot->bits_unused = bitsUnused;
3778
3779       searchSpc->nrofCandidates = NULLP;
3780       DU_ALLOC(searchSpc->nrofCandidates, sizeof(struct SearchSpace__nrofCandidates));
3781       if(!searchSpc->nrofCandidates)
3782       {
3783          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3784          return RFAILED;
3785       }
3786
3787       if(pdcchCfg == NULLP)
3788       {
3789          searchSpc->nrofCandidates->aggregationLevel1 = PDCCH_SRCH_SPC_TWO_AGG_LVL1_CANDIDATE;
3790          searchSpc->nrofCandidates->aggregationLevel2 = PDCCH_SRCH_SPC_TWO_AGG_LVL2_CANDIDATE;
3791          searchSpc->nrofCandidates->aggregationLevel4 = PDCCH_SRCH_SPC_TWO_AGG_LVL4_CANDIDATE;
3792          searchSpc->nrofCandidates->aggregationLevel8 = PDCCH_SRCH_SPC_TWO_AGG_LVL8_CANDIDATE;
3793          searchSpc->nrofCandidates->aggregationLevel16 = PDCCH_SRCH_SPC_TWO_AGG_LVL16_CANDIDATE;
3794       }
3795       else
3796       {
3797          searchSpc->nrofCandidates->aggregationLevel1 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel1;
3798          searchSpc->nrofCandidates->aggregationLevel2 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel2;
3799          searchSpc->nrofCandidates->aggregationLevel4 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel4;
3800          searchSpc->nrofCandidates->aggregationLevel8 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel8;
3801          searchSpc->nrofCandidates->aggregationLevel16 = pdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel16;
3802       }
3803
3804       searchSpc->searchSpaceType = NULLP;
3805       DU_ALLOC(searchSpc->searchSpaceType, sizeof(struct SearchSpace__searchSpaceType));
3806       if(!searchSpc->searchSpaceType)
3807       {
3808          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3809          return RFAILED;
3810       }
3811       if(pdcchCfg == NULLP)
3812          searchSpc->searchSpaceType->present = SearchSpace__searchSpaceType_PR_ue_Specific;
3813       else
3814          searchSpc->searchSpaceType->present = pdcchCfg->searchSpcToAddModList[idx].searchSpaceType;
3815
3816       searchSpc->searchSpaceType->choice.ue_Specific = NULLP;
3817       DU_ALLOC(searchSpc->searchSpaceType->choice.ue_Specific, sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
3818       if(!searchSpc->searchSpaceType->choice.ue_Specific)
3819       {
3820          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSearchSpcToAddModList");
3821          return RFAILED;
3822       }  
3823       if(pdcchCfg == NULLP)
3824          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
3825       else
3826          searchSpc->searchSpaceType->choice.ue_Specific->dci_Formats = pdcchCfg->searchSpcToAddModList[idx].ueSpecificDciFormat;
3827    }
3828    return ROK;
3829 }/* End BuildSearchSpcToAddModList */
3830
3831 /*******************************************************************
3832  *
3833  * @brief Builds BWP DL dedicated PDCCH config
3834  *
3835  * @details
3836  *
3837  *    Function : BuildBWPDlDedPdcchCfg
3838  *
3839  *    Functionality: Builds BWP DL dedicated PDCCH config
3840  *
3841  * @params[in] struct PDCCH_Config *pdcchCfg
3842  *
3843  * @return ROK     - success
3844  *         RFAILED - failure
3845  *
3846  * ****************************************************************/
3847 uint8_t BuildBWPDlDedPdcchCfg(PdcchConfig *pdcchCfgDb, struct PDCCH_Config *pdcchCfg)
3848 {
3849    pdcchCfg->controlResourceSetToAddModList = NULLP;
3850    DU_ALLOC(pdcchCfg->controlResourceSetToAddModList, sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
3851    if(!pdcchCfg->controlResourceSetToAddModList)
3852    {
3853       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
3854       return RFAILED;
3855    }
3856
3857    if(BuildControlRSetToAddModList(pdcchCfgDb, pdcchCfg->controlResourceSetToAddModList) != ROK)
3858    {
3859       DU_LOG("\nERROR  --> F1AP : Failed in BuildControlRSetToAddModList()");
3860       return RFAILED;
3861    }
3862
3863    pdcchCfg->controlResourceSetToReleaseList = NULLP;
3864
3865    pdcchCfg->searchSpacesToAddModList = NULLP;
3866    DU_ALLOC(pdcchCfg->searchSpacesToAddModList, sizeof(struct PDCCH_Config__searchSpacesToAddModList));
3867    if(!pdcchCfg->searchSpacesToAddModList)
3868    {
3869       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdcchCfg");
3870       return RFAILED;
3871    }
3872
3873    if(BuildSearchSpcToAddModList(pdcchCfgDb, pdcchCfg->searchSpacesToAddModList) != ROK)
3874    {
3875       DU_LOG("\nERROR  --> F1AP : Failed in BuildSearchSpcToAddModList()");
3876       return RFAILED;
3877    }
3878
3879    pdcchCfg->searchSpacesToReleaseList = NULLP;
3880    pdcchCfg->downlinkPreemption = NULLP;
3881    pdcchCfg->tpc_PUSCH = NULLP;
3882    pdcchCfg->tpc_PUCCH = NULLP;
3883    pdcchCfg->tpc_SRS = NULLP;
3884
3885    return ROK;
3886 }
3887
3888 /*******************************************************************
3889  *
3890  * @brief Builds DMRS DL PDSCH Mapping type A
3891  *
3892  * @details
3893  *
3894  *    Function : BuildDMRSDLPdschMapTypeA
3895  *
3896  *    Functionality: Builds DMRS DL PDSCH Mapping type A
3897  *
3898  * @params[in]
3899  * struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg
3900  * @return ROK     - success
3901  *         RFAILED - failure
3902  *
3903  * ****************************************************************/
3904 uint8_t BuildDMRSDLPdschMapTypeA(PdschConfig *pdschCfg, struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg)
3905 {
3906    dmrsDlCfg->present = PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup;
3907    dmrsDlCfg->choice.setup = NULLP;
3908    DU_ALLOC(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
3909    if(!dmrsDlCfg->choice.setup)
3910    {
3911       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
3912       return RFAILED;
3913    }
3914
3915    dmrsDlCfg->choice.setup->dmrs_Type = NULLP;
3916    dmrsDlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
3917    DU_ALLOC(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
3918    if(!dmrsDlCfg->choice.setup->dmrs_AdditionalPosition)
3919    {
3920       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSDLPdschMapTypeA");
3921       return RFAILED;
3922    }
3923    if(pdschCfg == NULLP)
3924       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS;
3925    else
3926       *(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition) = pdschCfg->dmrsDlCfgForPdschMapTypeA.addPos;
3927
3928    dmrsDlCfg->choice.setup->maxLength = NULLP;
3929    dmrsDlCfg->choice.setup->scramblingID0 = NULLP;
3930    dmrsDlCfg->choice.setup->scramblingID1 = NULLP;
3931    dmrsDlCfg->choice.setup->phaseTrackingRS = NULLP;
3932
3933    return ROK;
3934 }
3935
3936 /*******************************************************************
3937  *
3938  * @brief Builds TCI states to add/modify list
3939  *
3940  * @details
3941  *
3942  *    Function : BuildTCIStatesToAddModList
3943  *
3944  *    Functionality:Builds TCI states to add/modify list
3945  *
3946  * @params[in] 
3947  * struct PDSCH_Config__tci_StatesToAddModList *tciStatesList
3948  *
3949  * @return ROK     - success
3950  *         RFAILED - failure
3951  *
3952  * ****************************************************************/
3953 uint8_t BuildTCIStatesToAddModList(struct PDSCH_Config__tci_StatesToAddModList *tciStatesList)
3954 {
3955    return ROK;
3956 }
3957
3958 /*******************************************************************
3959  *
3960  * @brief Builds PDSCH time domain allocation list
3961  *
3962  * @details
3963  *
3964  *    Function : BuildPdschTimeDomAllocList
3965  *
3966  *    Functionality: Builds PDSCH time domain allocation list
3967  *
3968  * @params[in] 
3969  * struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
3970  *
3971  * @return ROK     - success
3972  *         RFAILED - failure
3973  *
3974  * ****************************************************************/
3975 uint8_t BuildPdschTimeDomAllocList(PdschConfig *pdschCfg, struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
3976 {
3977    uint8_t idx;
3978    uint8_t elementCnt;
3979    struct PDSCH_TimeDomainResourceAllocation *timeDomAlloc;
3980
3981    timeDomAllocList->present = PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup;
3982
3983    timeDomAllocList->choice.setup = NULLP;
3984    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PDSCH_TimeDomainResourceAllocationList));
3985    if(!timeDomAllocList->choice.setup)
3986    {
3987       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
3988       return RFAILED;
3989    }
3990
3991 if(pdschCfg == NULLP)
3992    elementCnt = 2;
3993 else
3994 elementCnt = pdschCfg->numTimeDomRsrcAlloc;
3995    timeDomAllocList->choice.setup->list.count = elementCnt;
3996    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(struct PDSCH_TimeDomainResourceAllocation *);
3997
3998    timeDomAllocList->choice.setup->list.array = NULLP;
3999    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4000    if(!timeDomAllocList->choice.setup->list.array)
4001    {
4002       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4003       return RFAILED;
4004    }
4005
4006    for(idx = 0; idx < elementCnt; idx++)
4007    {
4008       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4009       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], \
4010             sizeof(struct PDSCH_TimeDomainResourceAllocation));
4011       if(!timeDomAllocList->choice.setup->list.array[idx])
4012       {
4013          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4014          return RFAILED;
4015       }
4016    }
4017
4018    if(pdschCfg == NULLP)
4019    {
4020       idx = 0;
4021       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4022       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4023       if(!timeDomAlloc->k0)
4024       {
4025          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4026          return RFAILED;
4027       }
4028       *(timeDomAlloc->k0) = 0;
4029       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4030       timeDomAlloc->startSymbolAndLength = \
4031                                            calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4032
4033       idx++;
4034       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4035       DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4036       if(!timeDomAlloc->k0)
4037       {
4038          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4039          return RFAILED;
4040       }
4041       *(timeDomAlloc->k0) = 1;
4042       timeDomAlloc->mappingType = PDSCH_MAPPING_TYPE_A;
4043       timeDomAlloc->startSymbolAndLength = calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
4044    }
4045    else
4046    {
4047       for(idx = 0; idx < elementCnt; idx++)
4048       {
4049          timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4050          DU_ALLOC(timeDomAlloc->k0, sizeof(long));
4051          if(!timeDomAlloc->k0)
4052          {
4053             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschTimeDomAllocList");
4054             return RFAILED;
4055          }
4056          if(pdschCfg->timeDomRsrcAllociList[idx].k0)
4057             *(timeDomAlloc->k0) = *(pdschCfg->timeDomRsrcAllociList[idx].k0);
4058          timeDomAlloc->mappingType = pdschCfg->timeDomRsrcAllociList[idx].mappingType;
4059          timeDomAlloc->startSymbolAndLength = pdschCfg->timeDomRsrcAllociList[idx].startSymbolAndLength;
4060       }
4061    }
4062
4063    return ROK;
4064 }
4065
4066 /*******************************************************************
4067  *
4068  * @brief Builds PDSCH PRB Bundling type
4069  *
4070  * @details
4071  *
4072  *    Function : BuildPdschPrbBundlingType
4073  *
4074  *    Functionality: Builds PDSCH PRB Bundling type
4075  *
4076  * @params[in] 
4077  * struct PDSCH_Config__prb_BundlingType *prbBndlType
4078  *
4079  * @return ROK     - success
4080  *         RFAILED - failure
4081  *
4082  * ****************************************************************/
4083 uint8_t BuildPdschPrbBundlingType(PdschConfig *pdschCfg, struct PDSCH_Config__prb_BundlingType *prbBndlType)
4084 {
4085    if(pdschCfg == NULLP)
4086       prbBndlType->present = PDSCH_Config__prb_BundlingType_PR_staticBundling;
4087    else
4088       prbBndlType->present = pdschCfg->bundlingType;
4089
4090    prbBndlType->choice.staticBundling = NULLP;
4091    DU_ALLOC(prbBndlType->choice.staticBundling, \
4092          sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
4093    if(!prbBndlType->choice.staticBundling)
4094    {
4095       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschPrbBundlingType");
4096       return RFAILED;
4097    }
4098    prbBndlType->choice.staticBundling->bundleSize = NULLP;
4099
4100    return ROK;
4101 }
4102
4103 /*******************************************************************
4104  *
4105  * @brief Builds BWP DL dedicated PDSCH config 
4106  *
4107  * @details
4108  *
4109  *    Function : BuildBWPDlDedPdschCfg
4110  *
4111  *    Functionality: Builds BWP DL dedicated PDSCH config
4112  *
4113  * @params[in] struct PDSCH_Config *pdschCfg
4114  *
4115  * @return ROK     - success
4116  *         RFAILED - failure
4117  *
4118  * ****************************************************************/
4119 uint8_t BuildBWPDlDedPdschCfg(PdschConfig *pdschCfgDb, struct PDSCH_Config *pdschCfg)
4120 {
4121    pdschCfg->dataScramblingIdentityPDSCH = NULLP;
4122
4123    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA = NULLP;
4124    DU_ALLOC(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
4125    if(!pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
4126    {
4127       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4128       return RFAILED;
4129    }
4130
4131    if(BuildDMRSDLPdschMapTypeA(pdschCfgDb, pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA) != ROK)
4132    {
4133       return RFAILED;
4134    }
4135
4136    pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeB = NULLP;
4137    pdschCfg->tci_StatesToAddModList = NULLP;
4138    pdschCfg->tci_StatesToReleaseList = NULLP;
4139    pdschCfg->vrb_ToPRB_Interleaver = NULLP;
4140 #if 0
4141    DU_ALLOC(pdschCfg->tci_StatesToAddModList, sizeof(struct PDSCH_Config__tci_StatesToAddModList));
4142    if(!pdschCfg->tci_StatesToAddModList)
4143    {
4144       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4145       return RFAILED;
4146    }
4147    if(BuildTCIStatesToAddModList(pdschCfg->tci_StatesToAddModList) != ROK)
4148    {
4149       return RFAILED;
4150    }
4151 #endif
4152
4153 if(pdschCfgDb == NULLP)
4154    pdschCfg->resourceAllocation = RES_ALLOC_TYPE;
4155 else
4156 pdschCfg->resourceAllocation = pdschCfgDb->resourceAllocType;
4157
4158    pdschCfg->pdsch_TimeDomainAllocationList = NULLP;
4159    DU_ALLOC(pdschCfg->pdsch_TimeDomainAllocationList, sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
4160    if(!pdschCfg->pdsch_TimeDomainAllocationList)
4161    {
4162       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4163       return RFAILED;
4164    }
4165    if(BuildPdschTimeDomAllocList(pdschCfgDb, pdschCfg->pdsch_TimeDomainAllocationList) != ROK)
4166    {
4167       return RFAILED;
4168    }
4169
4170    pdschCfg->pdsch_AggregationFactor = NULLP;
4171    pdschCfg->rateMatchPatternToAddModList = NULLP;
4172    pdschCfg->rateMatchPatternToReleaseList = NULLP;
4173    pdschCfg->rateMatchPatternGroup1 = NULLP;
4174    pdschCfg->rateMatchPatternGroup2 = NULLP;
4175    if(pdschCfgDb == NULLP)
4176       pdschCfg->rbg_Size = PDSCH_RBG_SIZE;
4177    else
4178       pdschCfg->rbg_Size = pdschCfgDb->rbgSize;
4179    pdschCfg->mcs_Table = NULLP;
4180
4181    pdschCfg->maxNrofCodeWordsScheduledByDCI = NULLP;
4182    DU_ALLOC(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
4183    if(!pdschCfg->maxNrofCodeWordsScheduledByDCI)
4184    {
4185       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPDlDedPdschCfg");
4186       return RFAILED;
4187    }
4188    if(pdschCfgDb == NULLP)
4189       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = PDSCH_MAX_CODEWORD_SCH_BY_DCI;
4190    else
4191       *(pdschCfg->maxNrofCodeWordsScheduledByDCI) = pdschCfgDb->numCodeWordsSchByDci;
4192
4193    if(BuildPdschPrbBundlingType(pdschCfgDb, &pdschCfg->prb_BundlingType) != ROK)
4194    {
4195       return RFAILED;
4196    }
4197
4198    pdschCfg->zp_CSI_RS_ResourceToAddModList = NULLP;
4199    pdschCfg->zp_CSI_RS_ResourceToReleaseList = NULLP;
4200    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4201    pdschCfg->aperiodic_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4202    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToAddModList = NULLP;
4203    pdschCfg->sp_ZP_CSI_RS_ResourceSetsToReleaseList = NULLP;
4204    pdschCfg->p_ZP_CSI_RS_ResourceSet = NULLP;
4205
4206    return ROK;
4207 }
4208
4209 /*******************************************************************
4210  *
4211  * @brief Builds intitial DL BWP
4212  * @details
4213  *
4214  *    Function : BuildInitialDlBWP 
4215  *
4216  *    Functionality: Builds intitial DL BWP in spCellCfgDed
4217  *
4218  * @params[in] BWP_DownlinkDedicated_t *dlBwp
4219  *
4220  * @return ROK     - success
4221  *         RFAILED - failure
4222  *
4223  * ****************************************************************/
4224 uint8_t BuildInitialDlBWP(InitialDlBwp *initiDlBwp, BWP_DownlinkDedicated_t *dlBwp)
4225 {
4226    PdcchConfig *pdcchCfg = NULLP;
4227    PdschConfig *pdschCfg = NULLP;
4228
4229    if(initiDlBwp)
4230    {
4231       if(initiDlBwp->pdcchPresent)
4232          pdcchCfg = &initiDlBwp->pdcchCfg;
4233       if(initiDlBwp->pdschPresent)
4234          pdschCfg = &initiDlBwp->pdschCfg;
4235    }
4236
4237    dlBwp->pdcch_Config = NULLP;
4238    DU_ALLOC(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
4239    if(!dlBwp->pdcch_Config)
4240    {
4241       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4242       return RFAILED;
4243    }
4244    dlBwp->pdcch_Config->present = BWP_DownlinkDedicated__pdcch_Config_PR_setup; 
4245
4246    dlBwp->pdcch_Config->choice.setup = NULLP;
4247    DU_ALLOC(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
4248    if(!dlBwp->pdcch_Config->choice.setup)
4249    {
4250       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4251       return RFAILED;
4252    }
4253    if(BuildBWPDlDedPdcchCfg(pdcchCfg, dlBwp->pdcch_Config->choice.setup) != ROK)
4254    {
4255       return RFAILED;
4256    }
4257
4258    dlBwp->pdsch_Config = NULLP;
4259    DU_ALLOC(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
4260    if(!dlBwp->pdsch_Config)
4261    {
4262       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4263       return RFAILED;
4264    }
4265    dlBwp->pdsch_Config->present = BWP_DownlinkDedicated__pdsch_Config_PR_setup;
4266
4267    dlBwp->pdsch_Config->choice.setup = NULLP;
4268    DU_ALLOC(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
4269    if(!dlBwp->pdsch_Config->choice.setup)
4270    {
4271       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failure in BuildInitialDlBWP");
4272       return RFAILED;
4273    }
4274
4275    if(BuildBWPDlDedPdschCfg(pdschCfg, dlBwp->pdsch_Config->choice.setup) != ROK)
4276    {
4277       return RFAILED;
4278    }
4279
4280    dlBwp->sps_Config = NULLP;
4281    dlBwp->radioLinkMonitoringConfig = NULLP; 
4282    return ROK;
4283 }
4284
4285 /*******************************************************************
4286  *
4287  * @brief Builds DMRS UL Pusch Mapping type A
4288  *
4289  * @details
4290  *
4291  *    Function : BuildDMRSULPuschMapTypeA
4292  *
4293  *    Functionality: Builds DMRS UL Pusch Mapping type A
4294  *
4295  * @params[in] 
4296  *    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg
4297  * @return ROK     - success
4298  *         RFAILED - failure
4299  *
4300  * ****************************************************************/
4301 uint8_t BuildDMRSULPuschMapTypeA(DmrsUlCfg *ulDmrsCfgDb, struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg)
4302 {
4303    dmrsUlCfg->present = PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup;
4304    dmrsUlCfg->choice.setup= NULLP;
4305    DU_ALLOC(dmrsUlCfg->choice.setup, sizeof(DMRS_UplinkConfig_t));
4306    if(!dmrsUlCfg->choice.setup)
4307    {
4308       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4309       return RFAILED;
4310    }
4311
4312    dmrsUlCfg->choice.setup->dmrs_Type = NULLP;
4313    dmrsUlCfg->choice.setup->dmrs_AdditionalPosition = NULLP;
4314    DU_ALLOC(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition, sizeof(long));
4315    if(!dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
4316    {
4317       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4318       return RFAILED;
4319    }
4320    if(ulDmrsCfgDb == NULLP)
4321       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = DMRS_ADDITIONAL_POS; 
4322    else
4323       *(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition) = ulDmrsCfgDb->addPos;
4324
4325    dmrsUlCfg->choice.setup->phaseTrackingRS = NULLP;
4326    dmrsUlCfg->choice.setup->maxLength = NULLP;
4327    dmrsUlCfg->choice.setup->transformPrecodingDisabled = NULLP;
4328    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled, sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
4329    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled)
4330    {
4331       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4332       return RFAILED;
4333    }
4334
4335    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0 = NULLP;
4336    DU_ALLOC(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
4337          sizeof(long));
4338    if(!dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0)
4339    {
4340       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDMRSULPuschMapTypeA");
4341       return RFAILED;
4342    }
4343    if(ulDmrsCfgDb == NULLP)
4344       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = SCRAMBLING_ID;
4345    else
4346       *(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0) = ulDmrsCfgDb->transPrecodDisabled.scramblingId0;
4347
4348    dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID1 = NULLP;
4349    dmrsUlCfg->choice.setup->transformPrecodingEnabled = NULLP;
4350    return ROK;
4351 }
4352
4353 /*******************************************************************
4354  *
4355  * @brief Build PUSCH time domain allocation list
4356  *
4357  * @details
4358  *
4359  *    Function : BuildPuschTimeDomAllocList
4360  *
4361  *    Functionality: Build PUSCH time domain allocation list
4362  *
4363  * @params[in] 
4364  * struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList
4365  *
4366  * @return ROK     - success
4367  *         RFAILED - failure
4368  *
4369  * ****************************************************************/
4370 uint8_t BuildPuschTimeDomAllocList(PuschCfg *puschCfgDb, struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList)
4371 {
4372    uint8_t idx;
4373    uint8_t elementCnt;
4374    PUSCH_TimeDomainResourceAllocation_t  *timeDomAlloc;
4375
4376    timeDomAllocList->present = PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup;
4377    timeDomAllocList->choice.setup = NULLP;
4378    DU_ALLOC(timeDomAllocList->choice.setup, sizeof(struct PUSCH_TimeDomainResourceAllocationList));
4379    if(!timeDomAllocList->choice.setup)
4380    {
4381       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4382       return RFAILED;
4383    }
4384
4385    if(puschCfgDb == NULLP)
4386       elementCnt = 2;
4387    else
4388       elementCnt = puschCfgDb->numTimeDomRsrcAlloc;
4389
4390    timeDomAllocList->choice.setup->list.count = elementCnt;
4391    timeDomAllocList->choice.setup->list.size = elementCnt * sizeof(PUSCH_TimeDomainResourceAllocation_t *);
4392    timeDomAllocList->choice.setup->list.array = NULLP;
4393    DU_ALLOC(timeDomAllocList->choice.setup->list.array, timeDomAllocList->choice.setup->list.size);
4394    if(!timeDomAllocList->choice.setup->list.array)
4395    {
4396       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4397       return RFAILED;
4398    }
4399
4400    for(idx = 0; idx < elementCnt; idx++)
4401    {
4402       timeDomAllocList->choice.setup->list.array[idx] = NULLP;
4403       DU_ALLOC(timeDomAllocList->choice.setup->list.array[idx], sizeof(PUSCH_TimeDomainResourceAllocation_t));
4404       if(!timeDomAllocList->choice.setup->list.array[idx])
4405       {
4406          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4407          return RFAILED;
4408       }
4409    }
4410
4411    for(idx = 0; idx < elementCnt; idx++)
4412    {
4413       timeDomAlloc = timeDomAllocList->choice.setup->list.array[idx];
4414       DU_ALLOC(timeDomAlloc->k2, sizeof(long));
4415       if(!timeDomAlloc->k2)
4416       {
4417          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschTimeDomAllocList");
4418          return RFAILED;
4419       }
4420       if(puschCfgDb == NULLP)
4421       {
4422          if(idx == 0)
4423             *(timeDomAlloc->k2) = PUSCH_K2_CFG1;
4424          else if(idx == 1)
4425             *(timeDomAlloc->k2) = PUSCH_K2_CFG2;
4426
4427          timeDomAlloc->mappingType = PUSCH_MAPPING_TYPE_A;
4428          timeDomAlloc->startSymbolAndLength = calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
4429       }
4430       else
4431       {
4432          *(timeDomAlloc->k2) = puschCfgDb->timeDomRsrcAllocList[idx].k2;
4433          timeDomAlloc->mappingType = puschCfgDb->timeDomRsrcAllocList[idx].mappingType;
4434          timeDomAlloc->startSymbolAndLength = puschCfgDb->timeDomRsrcAllocList[idx].startSymbolAndLength;
4435       }
4436    }
4437
4438    return ROK;
4439 }
4440
4441 /*******************************************************************
4442  *
4443  * @brief Builds BWP UL dedicated PUSCH Config
4444  *
4445  * @details
4446  *
4447  *    Function : BuildBWPUlDedPuschCfg
4448  *
4449  *    Functionality:
4450  *      Builds BWP UL dedicated PUSCH Config
4451  *
4452  * @params[in] : PUSCH_Config_t *puschCfg
4453  *    
4454  * @return ROK     - success
4455  *         RFAILED - failure
4456  *
4457  * ****************************************************************/
4458 uint8_t BuildBWPUlDedPuschCfg(PuschCfg *puschCfgDb, PUSCH_Config_t *puschCfg)
4459 {
4460    DmrsUlCfg *ulDmrsCfg = NULLP;
4461    
4462    if(puschCfgDb)
4463       ulDmrsCfg = &puschCfgDb->dmrsUlCfgForPuschMapTypeA;
4464
4465    puschCfg->dataScramblingIdentityPUSCH = NULLP;
4466    DU_ALLOC(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
4467    if(!puschCfg->dataScramblingIdentityPUSCH)
4468    {
4469       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4470       return RFAILED;
4471    }
4472    if(puschCfgDb == NULLP)
4473       *(puschCfg->dataScramblingIdentityPUSCH) = SCRAMBLING_ID;
4474    else
4475       *(puschCfg->dataScramblingIdentityPUSCH) = puschCfgDb->dataScramblingId;
4476
4477    puschCfg->txConfig = NULLP;
4478    puschCfg->dmrs_UplinkForPUSCH_MappingTypeA = NULLP;
4479    DU_ALLOC(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
4480    if(!puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
4481    {
4482       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4483       return RFAILED;
4484    }
4485
4486    if(BuildDMRSULPuschMapTypeA(ulDmrsCfg, puschCfg->dmrs_UplinkForPUSCH_MappingTypeA) != ROK)
4487    {
4488       return RFAILED;
4489    }
4490
4491    puschCfg->dmrs_UplinkForPUSCH_MappingTypeB = NULLP;
4492    puschCfg->pusch_PowerControl = NULLP;
4493    puschCfg->frequencyHopping = NULLP;
4494    puschCfg->frequencyHoppingOffsetLists = NULLP;
4495
4496    if(puschCfgDb == NULLP)
4497       puschCfg->resourceAllocation = RES_ALLOC_TYPE;
4498    else
4499       puschCfg->resourceAllocation = puschCfgDb->resourceAllocType;
4500
4501    puschCfg->pusch_TimeDomainAllocationList = NULLP;
4502    DU_ALLOC(puschCfg->pusch_TimeDomainAllocationList, sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
4503    if(!puschCfg->pusch_TimeDomainAllocationList)
4504    {
4505       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4506       return RFAILED;
4507    }
4508
4509    if(BuildPuschTimeDomAllocList(puschCfgDb, puschCfg->pusch_TimeDomainAllocationList) != ROK)
4510    {
4511       return RFAILED;
4512    }
4513
4514    puschCfg->pusch_AggregationFactor = NULLP;
4515    puschCfg->mcs_Table = NULLP;
4516    puschCfg->mcs_TableTransformPrecoder = NULLP;
4517    puschCfg->transformPrecoder = NULLP;
4518    DU_ALLOC(puschCfg->transformPrecoder, sizeof(long));
4519    if(!puschCfg->transformPrecoder)
4520    {
4521       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPuschCfg");
4522       return RFAILED;
4523    }
4524    if(puschCfgDb == NULLP)
4525       *(puschCfg->transformPrecoder) = PUSCH_TRANSFORM_PRECODER;
4526    else
4527       *(puschCfg->transformPrecoder) = puschCfgDb->transformPrecoder;
4528
4529    puschCfg->codebookSubset = NULLP;
4530    puschCfg->maxRank = NULLP;
4531    puschCfg->rbg_Size = NULLP;
4532    puschCfg->uci_OnPUSCH = NULLP;
4533    puschCfg->tp_pi2BPSK = NULLP;
4534
4535    return ROK;
4536 }
4537
4538 /*******************************************************************
4539  *
4540  * @brief Builds PUCCH resource set add/modify list
4541  *
4542  * @details
4543  *
4544  *    Function : BuildPucchRsrcSetAddModList
4545  *
4546  *    Functionality:
4547  *      Builds PUCCH resource set add/modify list
4548  *
4549  * @params[in] : PucchResrcSetCfg *rsrcSetCfgDb
4550  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4551  *
4552  * @return ROK     - success
4553  *         RFAILED - failure
4554  *
4555  * ****************************************************************/
4556 uint8_t BuildPucchRsrcSetAddModList(PucchResrcSetCfg *rsrcSetCfgDb, \
4557    struct PUCCH_Config__resourceSetToAddModList *resourceSetToAddModList)
4558 {
4559    uint8_t elementCnt = 0, rsrcSetIdx = 0, rsrcIdx = 0;
4560    PUCCH_ResourceSet_t *rsrcSet = NULLP;
4561
4562    if(rsrcSetCfgDb == NULLP)
4563       elementCnt = 1;
4564    else
4565       elementCnt = rsrcSetCfgDb->resrcSetToAddModListCount;
4566
4567    resourceSetToAddModList->list.count = elementCnt;
4568    resourceSetToAddModList->list.size = elementCnt * sizeof(PUCCH_ResourceSet_t *);
4569    DU_ALLOC(resourceSetToAddModList->list.array, resourceSetToAddModList->list.size);
4570    if(resourceSetToAddModList->list.array == NULLP)
4571    {
4572       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4573       return RFAILED;
4574    }
4575    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4576    {
4577       DU_ALLOC(resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
4578       if(resourceSetToAddModList->list.array[rsrcSetIdx] == NULLP)
4579       {
4580          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4581          return RFAILED;
4582       }
4583    }
4584
4585    for(rsrcSetIdx=0; rsrcSetIdx < resourceSetToAddModList->list.count; rsrcSetIdx++)
4586    {
4587       rsrcSet = resourceSetToAddModList->list.array[rsrcSetIdx];
4588
4589       /* Resource set Id */
4590       if(rsrcSetCfgDb == NULLP)
4591          rsrcSet->pucch_ResourceSetId = 1;
4592       else
4593          rsrcSet->pucch_ResourceSetId = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcSetId;
4594  
4595       /* Resource list of a resource set */
4596       if(rsrcSetCfgDb == NULLP)
4597          elementCnt = 1;
4598       else
4599          elementCnt = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcListCount;
4600       rsrcSet->resourceList.list.count = elementCnt;
4601       rsrcSet->resourceList.list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
4602       DU_ALLOC(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
4603       if(rsrcSet->resourceList.list.array == NULLP)
4604       {
4605          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4606          return RFAILED;
4607       }
4608
4609       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4610       {
4611          DU_ALLOC(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
4612          if(rsrcSet->resourceList.list.array[rsrcIdx] == NULLP)
4613          {
4614             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4615             return RFAILED;
4616          }
4617       }
4618       for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
4619       {
4620          if(rsrcSetCfgDb == NULLP)
4621             *(rsrcSet->resourceList.list.array[rsrcIdx]) = 1;
4622          else
4623             *(rsrcSet->resourceList.list.array[rsrcIdx]) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].resrcList[rsrcIdx];
4624       }
4625
4626       /* Max payload size (minus 1) in a Resource set */
4627       rsrcSet->maxPayloadMinus1 = NULLP;
4628       if(rsrcSetCfgDb && rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize)
4629       {
4630          DU_ALLOC(rsrcSet->maxPayloadMinus1, sizeof(long));
4631          if(rsrcSet->maxPayloadMinus1 == NULLP)
4632          {
4633             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcSetAddModList");
4634             return RFAILED;
4635          }
4636          *(rsrcSet->maxPayloadMinus1) = rsrcSetCfgDb->resrcSetToAddModList[rsrcSetIdx].maxPayLoadSize;
4637       }
4638    }
4639    return ROK;
4640 }
4641
4642 /*******************************************************************
4643  *
4644  * @brief Builds PUCCH resource add/modify list
4645  *
4646  * @details
4647  *
4648  *    Function : BuildPucchRsrcAdddModList
4649  *
4650  *    Functionality:
4651  *      Builds PUCCH resource add/modify list
4652  *
4653  * @params[in] : PucchResrcCfg *rsrcSetCfgDb
4654  *               struct PUCCH_Config__resourceSetToAddModList *rsrcSetAddModList
4655  *
4656  * @return ROK     - success
4657  *         RFAILED - failure
4658  *
4659  * ****************************************************************/
4660 uint8_t BuildPucchRsrcAddModList(PucchResrcCfg *rsrcCfgDb, struct PUCCH_Config__resourceToAddModList  *resourceToAddModList)
4661 {
4662    uint8_t elementCnt = 0, rsrcIdx = 0;
4663    PUCCH_Resource_t *rsrc = NULLP;
4664
4665    if(rsrcCfgDb == NULLP)
4666       elementCnt = 1;
4667    else
4668       elementCnt = rsrcCfgDb->resrcToAddModListCount;
4669    resourceToAddModList->list.count = elementCnt;
4670    resourceToAddModList->list.size = elementCnt * sizeof(PUCCH_Resource_t *);
4671    DU_ALLOC(resourceToAddModList->list.array, resourceToAddModList->list.size);
4672    if(resourceToAddModList->list.array == NULLP)
4673    {
4674       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4675       return RFAILED;
4676    }
4677    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4678    {
4679       DU_ALLOC(resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
4680       if(resourceToAddModList->list.array[rsrcIdx] == NULLP)
4681       {
4682          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4683          return RFAILED;
4684       }
4685    }
4686
4687    for(rsrcIdx=0; rsrcIdx < resourceToAddModList->list.count; rsrcIdx++)
4688    {
4689       rsrc = resourceToAddModList->list.array[rsrcIdx];
4690
4691       if(rsrcCfgDb == NULLP)
4692       {
4693          rsrc->pucch_ResourceId = 1;
4694          rsrc->startingPRB = 0;
4695          rsrc->format.present = PUCCH_Resource__format_PR_format1; 
4696          DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4697          if(rsrc->format.choice.format1 == NULLP)
4698          {
4699             DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4700             return RFAILED;
4701          }  
4702          rsrc->format.choice.format1->initialCyclicShift = 0;
4703          rsrc->format.choice.format1->nrofSymbols = 4;
4704          rsrc->format.choice.format1->startingSymbolIndex = 0;
4705          rsrc->format.choice.format1->timeDomainOCC = 0;
4706       }
4707       else
4708       {
4709          rsrc->pucch_ResourceId = rsrcCfgDb->resrcToAddModList[rsrcIdx].resrcId;
4710          rsrc->startingPRB = rsrcCfgDb->resrcToAddModList[rsrcIdx].startPrb;
4711          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop)
4712          {
4713             DU_ALLOC(rsrc->intraSlotFrequencyHopping, sizeof(long));
4714             if(rsrc->intraSlotFrequencyHopping == NULLP)
4715             {
4716                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4717                return RFAILED;
4718             }
4719             *(rsrc->intraSlotFrequencyHopping) = rsrcCfgDb->resrcToAddModList[rsrcIdx].intraFreqHop;
4720          }
4721          else
4722             rsrc->intraSlotFrequencyHopping = NULLP;
4723
4724          if(rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop)
4725          {
4726             DU_ALLOC(rsrc->secondHopPRB, sizeof(PRB_Id_t));
4727             if(rsrc->secondHopPRB == NULLP)
4728             {
4729                DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4730                return RFAILED;
4731             }
4732             *(rsrc->secondHopPRB) = rsrcCfgDb->resrcToAddModList[rsrcIdx].secondPrbHop;
4733          }
4734          else
4735             rsrc->secondHopPRB = NULLP;
4736          rsrc->format.present = covertPucchFormatIntEnumToRrcEnum(rsrcCfgDb->resrcToAddModList[rsrcIdx].pucchFormat); 
4737
4738          switch(rsrc->format.present)
4739          {
4740             case PUCCH_Resource__format_PR_NOTHING:
4741                break;
4742             case PUCCH_Resource__format_PR_format0:
4743                {
4744                   DU_ALLOC(rsrc->format.choice.format0, sizeof(PUCCH_format0_t));
4745                   if(rsrc->format.choice.format0 == NULLP)
4746                   {
4747                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4748                      return RFAILED;
4749                   }
4750                   rsrc->format.choice.format0->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->initialCyclicShift;
4751                   rsrc->format.choice.format0->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->numSymbols;
4752                   rsrc->format.choice.format0->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format0->startSymbolIdx;
4753                   break;
4754                }
4755
4756             case PUCCH_Resource__format_PR_format1:
4757                {
4758                   DU_ALLOC(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
4759                   if(rsrc->format.choice.format1 == NULLP)
4760                   {
4761                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4762                      return RFAILED;
4763                   }  
4764                   rsrc->format.choice.format1->initialCyclicShift = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->initialCyclicShift;
4765                   rsrc->format.choice.format1->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->numSymbols;
4766                   rsrc->format.choice.format1->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->startSymbolIdx;
4767                   rsrc->format.choice.format1->timeDomainOCC = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format1->timeDomOCC;
4768                   break;
4769                }
4770
4771             case PUCCH_Resource__format_PR_format2:
4772                {
4773                   DU_ALLOC(rsrc->format.choice.format2, sizeof(PUCCH_format2_t));
4774                   if(rsrc->format.choice.format2 == NULLP)
4775                   {
4776                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4777                      return RFAILED;
4778                   } 
4779                   rsrc->format.choice.format2->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numPrbs;
4780                   rsrc->format.choice.format2->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->numSymbols;
4781                   rsrc->format.choice.format2->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format2->startSymbolIdx;
4782                   break;
4783                }
4784
4785             case PUCCH_Resource__format_PR_format3:
4786                {
4787                   DU_ALLOC(rsrc->format.choice.format3, sizeof(PUCCH_format3_t));
4788                   if(rsrc->format.choice.format3 == NULLP)
4789                   {
4790                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4791                      return RFAILED;
4792                   }
4793                   rsrc->format.choice.format3->nrofPRBs = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numPrbs;
4794                   rsrc->format.choice.format3->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->numSymbols;
4795                   rsrc->format.choice.format3->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format3->startSymbolIdx;
4796                   break;
4797                }
4798
4799             case PUCCH_Resource__format_PR_format4:
4800                {
4801                   DU_ALLOC(rsrc->format.choice.format4, sizeof(PUCCH_format4_t));
4802                   if(rsrc->format.choice.format4 == NULLP)
4803                   {
4804                      DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchRsrcAddModList");
4805                      return RFAILED;
4806                   }
4807                   rsrc->format.choice.format4->nrofSymbols = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->numSymbols;
4808                   rsrc->format.choice.format4->occ_Length = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occLen;
4809                   rsrc->format.choice.format4->occ_Index = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->occIdx;
4810                   rsrc->format.choice.format4->startingSymbolIndex = rsrcCfgDb->resrcToAddModList[rsrcIdx].PucchFormat.format4->startSymbolIdx;
4811                   break;
4812                }
4813          }
4814       }
4815    }
4816    return ROK;
4817 }
4818
4819 /*******************************************************************
4820  *
4821  * @brief Builds PUCCH format  config
4822  *
4823  * @details
4824  *
4825  *    Function : BuildPucchFormat
4826  *
4827  *    Functionality: Builds PUCCH format  config
4828  *
4829  * @params[in] : PucchFormatCfg *formatDb
4830  *               PUCCH_FormatConfig_t *format
4831  *
4832  * @return ROK     - success
4833  *         RFAILED - failure
4834  *
4835  * ****************************************************************/
4836 uint8_t BuildPucchFormat(PucchFormatCfg *formatDb, PUCCH_FormatConfig_t *format)
4837 {
4838    /* Inter Slot Fequency hopping */
4839    format->interslotFrequencyHopping = NULLP;
4840    if((formatDb != NULLP) && (formatDb->interSlotFreqHop == true))
4841    {
4842       DU_ALLOC(format->interslotFrequencyHopping, sizeof(long));
4843       if(format->interslotFrequencyHopping)
4844       {
4845          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4846          return RFAILED;
4847       }
4848       *(format->interslotFrequencyHopping) = PUCCH_FormatConfig__interslotFrequencyHopping_enabled;
4849    }
4850
4851    /* Additional DMRS */
4852    format->additionalDMRS = NULLP;
4853    if((formatDb != NULLP) && (formatDb->addDmrs == true))
4854    {
4855       DU_ALLOC(format->additionalDMRS, sizeof(long));
4856       if(format->additionalDMRS)
4857       {
4858          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4859          return RFAILED;
4860       }
4861       *(format->additionalDMRS) = PUCCH_FormatConfig__additionalDMRS_true;
4862    }
4863
4864     /* Maximum code rate */
4865    format->maxCodeRate = NULLP;
4866    if((formatDb != NULLP) && (formatDb->maxCodeRate != 0))
4867    {
4868       DU_ALLOC(format->maxCodeRate, sizeof(long));
4869       if(format->maxCodeRate)
4870       {
4871          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4872          return RFAILED;
4873       }  
4874       *(format->maxCodeRate) = formatDb->maxCodeRate;
4875    }
4876  
4877    /* Number of slots */
4878    format->nrofSlots = NULLP;
4879    if((formatDb == NULLP) || ((formatDb != NULLP) && (formatDb->numSlots != 0)))
4880    {
4881       DU_ALLOC(format->nrofSlots, sizeof(long));
4882       if(format->nrofSlots == NULLP)
4883       {
4884          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4885          return RFAILED;
4886       }
4887       if(formatDb == NULLP)
4888          *(format->nrofSlots) = PUCCH_FormatConfig__nrofSlots_n4;
4889       else
4890          *(format->nrofSlots) = formatDb->numSlots;
4891    }
4892
4893    /* Pi2BPSK*/
4894    format->pi2BPSK = NULLP;
4895    if((formatDb != NULLP) && (formatDb->pi2BPSK == true))
4896    {
4897       DU_ALLOC(format->pi2BPSK, sizeof(long));
4898       if(format->pi2BPSK)
4899       {     
4900          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4901          return RFAILED;
4902       }     
4903       *(format->pi2BPSK) = PUCCH_FormatConfig__pi2BPSK_enabled;
4904    }
4905
4906    /* Simultaneous HARQ ACK and CSI */
4907    format->simultaneousHARQ_ACK_CSI = NULLP;
4908    if((formatDb != NULLP) && (formatDb->harqAckCSI == true))
4909    {
4910       DU_ALLOC(format->simultaneousHARQ_ACK_CSI, sizeof(long));
4911       if(format->simultaneousHARQ_ACK_CSI)
4912       {     
4913          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPucchFormat");
4914          return RFAILED;
4915       }     
4916       *(format->simultaneousHARQ_ACK_CSI) = PUCCH_FormatConfig__simultaneousHARQ_ACK_CSI_true;
4917    }
4918
4919    return ROK;
4920 }
4921
4922
4923 /*******************************************************************
4924  *
4925  * @brief Builds PUCCH scheduling request list
4926  *
4927  * @details
4928  *
4929  *    Function : BuildPucchSchReqAddModList
4930  *
4931  *    Functionality:
4932  *      Builds PUCCH scheduling request list
4933  *
4934  * @params[in] : PucchSchedReqCfg *schReqDb
4935  *               struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList
4936  *
4937  * @return ROK     - success
4938  *         RFAILED - failure
4939  *
4940  * ****************************************************************/
4941 uint8_t BuildPucchSchReqAddModList(PucchSchedReqCfg *schReqDb, \
4942    struct PUCCH_Config__schedulingRequestResourceToAddModList *schReqRsrcToAddModList)
4943 {
4944    uint8_t elementCnt = 0, schReqIdx = 0;
4945    SchedulingRequestResourceConfig_t *schReqRsrc;
4946
4947    elementCnt = schReqDb->schedAddModListCount;
4948    schReqRsrcToAddModList->list.count = elementCnt;
4949    schReqRsrcToAddModList->list.size = elementCnt *sizeof(struct SchedulingRequestResourceConfig *);
4950
4951    schReqRsrcToAddModList->list.array = NULLP;
4952    DU_ALLOC(schReqRsrcToAddModList->list.array, schReqRsrcToAddModList->list.size);
4953    if(schReqRsrcToAddModList->list.array == NULLP)
4954    {
4955       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
4956       return RFAILED;
4957    }
4958
4959    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
4960    {
4961       DU_ALLOC(schReqRsrcToAddModList->list.array[schReqIdx], schReqRsrcToAddModList->list.size);
4962       if(schReqRsrcToAddModList->list.array[schReqIdx] == NULLP)
4963       {
4964          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
4965          return RFAILED;
4966       }
4967    }
4968
4969    for(schReqIdx = 0; schReqIdx < schReqRsrcToAddModList->list.count; schReqIdx++)
4970    {
4971       schReqRsrc = schReqRsrcToAddModList->list.array[schReqIdx];
4972       schReqRsrc->schedulingRequestResourceId = schReqDb->schedAddModList[schReqIdx].resrcId;
4973       schReqRsrc->schedulingRequestID = schReqDb->schedAddModList[schReqIdx].requestId;
4974
4975       if(schReqDb->schedAddModList[schReqIdx].periodicity)
4976       {
4977          schReqRsrc->periodicityAndOffset = NULLP;
4978          DU_ALLOC(schReqRsrc->periodicityAndOffset, sizeof(struct SchedulingRequestResourceConfig__periodicityAndOffset));
4979          if(schReqRsrc->periodicityAndOffset == NULLP)
4980          {
4981             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
4982             return RFAILED;
4983          }
4984
4985          schReqRsrc->periodicityAndOffset->present = schReqDb->schedAddModList[schReqIdx].periodicity;
4986          switch(schReqRsrc->periodicityAndOffset->present)
4987          {
4988             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_NOTHING:
4989                break;
4990             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
4991                schReqRsrc->periodicityAndOffset->choice.sym2 = schReqDb->schedAddModList[schReqIdx].offset;
4992                break;
4993             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
4994                schReqRsrc->periodicityAndOffset->choice.sym6or7 = schReqDb->schedAddModList[schReqIdx].offset;
4995                break;
4996             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
4997                schReqRsrc->periodicityAndOffset->choice.sl1 = schReqDb->schedAddModList[schReqIdx].offset;
4998                break;
4999             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
5000                schReqRsrc->periodicityAndOffset->choice.sl2 = schReqDb->schedAddModList[schReqIdx].offset;
5001                break;
5002             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
5003                schReqRsrc->periodicityAndOffset->choice.sl4 = schReqDb->schedAddModList[schReqIdx].offset;
5004                break;
5005             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
5006                schReqRsrc->periodicityAndOffset->choice.sl5 = schReqDb->schedAddModList[schReqIdx].offset;
5007                break;
5008             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
5009                schReqRsrc->periodicityAndOffset->choice.sl8 = schReqDb->schedAddModList[schReqIdx].offset;
5010                break;
5011             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
5012                schReqRsrc->periodicityAndOffset->choice.sl10 = schReqDb->schedAddModList[schReqIdx].offset;
5013                break;
5014             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
5015                schReqRsrc->periodicityAndOffset->choice.sl16 = schReqDb->schedAddModList[schReqIdx].offset;
5016                break;
5017             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
5018                schReqRsrc->periodicityAndOffset->choice.sl20 = schReqDb->schedAddModList[schReqIdx].offset;
5019                break;
5020             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
5021                schReqRsrc->periodicityAndOffset->choice.sl40 = schReqDb->schedAddModList[schReqIdx].offset;
5022                break;
5023             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
5024                schReqRsrc->periodicityAndOffset->choice.sl80 = schReqDb->schedAddModList[schReqIdx].offset;
5025                break;
5026             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
5027                schReqRsrc->periodicityAndOffset->choice.sl160 = schReqDb->schedAddModList[schReqIdx].offset;
5028                break;
5029             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
5030                schReqRsrc->periodicityAndOffset->choice.sl320 = schReqDb->schedAddModList[schReqIdx].offset;
5031                break;
5032             case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
5033                schReqRsrc->periodicityAndOffset->choice.sl640 = schReqDb->schedAddModList[schReqIdx].offset;
5034                break;
5035          }
5036       }
5037
5038       if(schReqDb->schedAddModList[schReqIdx].resrc)
5039       {
5040          schReqRsrc->resource = NULLP;
5041          DU_ALLOC(schReqRsrc->resource, sizeof(PUCCH_ResourceId_t));
5042          if(schReqRsrc->resource == NULLP)
5043          {
5044             DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchSchReqAddModList");
5045             return RFAILED;
5046          }
5047          *(schReqRsrc->resource) = schReqDb->schedAddModList[schReqIdx].resrc;
5048
5049       }
5050    }
5051    return ROK;
5052 }
5053
5054 /*******************************************************************
5055  *
5056  * @brief Builds PUCCH multi csi resource list
5057  *
5058  * @details
5059  *
5060  *    Function : BuildPucchMultiCsiRsrcList
5061  *
5062  *    Functionality:
5063  *      Builds PUCCH multi csi resource list
5064  *
5065  * @params[in] : PucchMultiCsiCfg *multiCsiDb
5066  *               struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList
5067  *
5068  * @return ROK     - success
5069  *         RFAILED - failure
5070  *
5071  * ****************************************************************/
5072 uint8_t BuildPucchMultiCsiRsrcList(PucchMultiCsiCfg *multiCsiDb, struct PUCCH_Config__multi_CSI_PUCCH_ResourceList  *multiCsiRsrcList)
5073 {
5074    uint8_t elementCnt = 0, rsrcIdx = 0;
5075
5076    elementCnt = multiCsiDb->multiCsiResrcListCount;
5077    multiCsiRsrcList->list.count = elementCnt;
5078    multiCsiRsrcList->list.size = elementCnt * sizeof(PUCCH_ResourceId_t *);
5079    multiCsiRsrcList->list.array = NULLP;
5080    DU_ALLOC(multiCsiRsrcList->list.array, multiCsiRsrcList->list.size);
5081    if(multiCsiRsrcList->list.array == NULLP)
5082    {
5083       DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5084       return RFAILED;
5085    }
5086
5087    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5088    {
5089       DU_ALLOC(multiCsiRsrcList->list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
5090       if(multiCsiRsrcList->list.array[rsrcIdx] == NULLP)
5091       {
5092          DU_LOG("\nERROR  --> DU APP: Memory allocation failed in BuildPucchMultiCsiRsrcList");
5093          return RFAILED;
5094       }
5095    }
5096
5097    for(rsrcIdx = 0; rsrcIdx<multiCsiRsrcList->list.count; rsrcIdx++)
5098    {
5099       *(multiCsiRsrcList->list.array[rsrcIdx]) = multiCsiDb->multiCsiResrcList[rsrcIdx];
5100    }
5101    return ROK;
5102 }
5103
5104 /*******************************************************************
5105  *
5106  * @brief Builds DL data -to- Ul Ack list
5107  *
5108  * @details
5109  *
5110  *    Function : BuildDlDataToUlAckList
5111  *
5112  *    Functionality: Builds DL data -to- Ul Ack list
5113  *
5114  * @params[in] : PucchDlDataToUlAck *dlDataToUlAckDb
5115  *               struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList
5116  *
5117  * @return ROK     - success
5118  *         RFAILED - failure
5119  *
5120  * ****************************************************************/
5121 uint8_t BuildDlDataToUlAckList(PucchDlDataToUlAck *dlDataToUlAckDb, struct PUCCH_Config__dl_DataToUL_ACK * dlDataToUlACKList)
5122 {
5123    uint8_t elementCnt = 0, arrIdx = 0;
5124
5125    if(dlDataToUlAckDb == NULLP)
5126       elementCnt = 2;
5127    else
5128       elementCnt = dlDataToUlAckDb->dlDataToUlAckListCount;
5129
5130    dlDataToUlACKList->list.count = elementCnt;
5131    dlDataToUlACKList->list.size = elementCnt * sizeof(long *);
5132    DU_ALLOC(dlDataToUlACKList->list.array, dlDataToUlACKList->list.size);
5133    if(dlDataToUlACKList->list.array == NULLP)
5134    {
5135       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5136       return RFAILED;
5137    }   
5138
5139    for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5140    {
5141       DU_ALLOC(dlDataToUlACKList->list.array[arrIdx], sizeof(long));
5142       if(dlDataToUlACKList->list.array[arrIdx] == NULLP)
5143       {
5144          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDlDataToUlAckList");
5145          return RFAILED;
5146       }   
5147    }
5148
5149    if(dlDataToUlAckDb == NULLP)
5150    {
5151       arrIdx = 0;
5152       *(dlDataToUlACKList->list.array[arrIdx++]) = 1;
5153       *(dlDataToUlACKList->list.array[arrIdx]) = 2;
5154    }
5155    else
5156    {
5157       for(arrIdx = 0; arrIdx <  dlDataToUlACKList->list.count; arrIdx++)
5158       {
5159          *(dlDataToUlACKList->list.array[arrIdx]) = dlDataToUlAckDb->dlDataToUlAckList[arrIdx];
5160       }
5161    }
5162    return ROK;
5163 }
5164
5165 /*******************************************************************
5166  *
5167  * @brief Builds BWP UL dedicated PUCCH Config
5168  *
5169  * @details
5170  *
5171  *    Function : BuildBWPUlDedPucchCfg
5172  *
5173  *    Functionality:
5174  *      Builds BWP UL dedicated PUCCH Config
5175  *
5176  * @params[in] : PUCCH_Config_t *pucchCfg
5177  *
5178  * @return ROK     - success
5179  *         RFAILED - failure
5180  *
5181  * ****************************************************************/
5182 uint8_t BuildBWPUlDedPucchCfg(PucchCfg *pucchCfgDb, PUCCH_Config_t *pucchCfg)
5183 {
5184    PucchResrcSetCfg *rsrcSetCfgDb = NULLP;
5185    PucchResrcCfg *rsrcCfgDb = NULLP;
5186    PucchFormatCfg *format1Db = NULLP;
5187    PucchFormatCfg *format2Db = NULLP;
5188    PucchFormatCfg *format3Db = NULLP;
5189    PucchFormatCfg *format4Db = NULLP;
5190    PucchSchedReqCfg *schReqDb = NULLP;   
5191    PucchMultiCsiCfg  *multiCsiDb = NULLP;
5192    PucchDlDataToUlAck *dlDataToUlAckDb = NULLP;
5193
5194    if(pucchCfgDb)
5195    {
5196       rsrcSetCfgDb = pucchCfgDb->resrcSet;
5197       rsrcCfgDb = pucchCfgDb->resrc;
5198       format1Db = pucchCfgDb->format1;
5199       format2Db = pucchCfgDb->format2;
5200       format3Db = pucchCfgDb->format3;
5201       format4Db = pucchCfgDb->format4;
5202       schReqDb = pucchCfgDb->schedReq;
5203       multiCsiDb = pucchCfgDb->multiCsiCfg;
5204       dlDataToUlAckDb = pucchCfgDb->dlDataToUlAck;
5205    }
5206
5207    /* RESOURCE SET */
5208    DU_ALLOC(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
5209    if(pucchCfg->resourceSetToAddModList == NULL)
5210    {
5211       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5212       return RFAILED;
5213    }
5214
5215    if(BuildPucchRsrcSetAddModList(rsrcSetCfgDb, pucchCfg->resourceSetToAddModList) != ROK)
5216    {
5217       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5218       return RFAILED;
5219    }
5220
5221    /* PUCCH RESOURCE */
5222    DU_ALLOC(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
5223    if(pucchCfg->resourceToAddModList == NULLP)
5224    {
5225       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5226       return RFAILED;
5227    }
5228
5229    if(BuildPucchRsrcAddModList(rsrcCfgDb, pucchCfg->resourceToAddModList) != ROK)
5230    {
5231       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5232       return RFAILED;
5233    }
5234
5235    /* PUCCH Format 1 */
5236    DU_ALLOC(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
5237    if(pucchCfg->format1 == NULLP)
5238    {
5239       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5240       return RFAILED;
5241    }
5242    
5243    pucchCfg->format1->present = PUCCH_Config__format1_PR_setup;
5244    DU_ALLOC(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
5245    if(pucchCfg->format1->choice.setup == NULLP)
5246    {
5247       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5248       return RFAILED;
5249    }
5250
5251    if(BuildPucchFormat(format1Db, pucchCfg->format1->choice.setup) != ROK)
5252    {
5253       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5254       return RFAILED;
5255    }
5256
5257    /* PUCCH Format 2 */
5258    if(format2Db)
5259    {
5260       DU_ALLOC(pucchCfg->format2, sizeof(struct PUCCH_Config__format2));
5261       if(pucchCfg->format2 == NULLP)
5262       {
5263          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5264          return RFAILED;
5265       }
5266
5267       pucchCfg->format2->present = PUCCH_Config__format2_PR_setup;
5268       DU_ALLOC(pucchCfg->format2->choice.setup, sizeof(PUCCH_FormatConfig_t));
5269       if(pucchCfg->format2->choice.setup == NULLP)
5270       {
5271          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5272          return RFAILED;
5273       }
5274
5275       if(BuildPucchFormat(format2Db, pucchCfg->format2->choice.setup) != ROK)
5276       {
5277          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5278          return RFAILED;
5279       }
5280    }
5281
5282    /* PUCCH Format 3 */
5283    if(format3Db)
5284    {
5285       DU_ALLOC(pucchCfg->format3, sizeof(struct PUCCH_Config__format3));
5286       if(pucchCfg->format3 == NULLP)
5287       {
5288          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5289          return RFAILED;
5290       }
5291
5292       pucchCfg->format3->present = PUCCH_Config__format3_PR_setup;
5293       DU_ALLOC(pucchCfg->format3->choice.setup, sizeof(PUCCH_FormatConfig_t));
5294       if(pucchCfg->format3->choice.setup == NULLP)
5295       {
5296          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5297          return RFAILED;
5298       }
5299
5300       if(BuildPucchFormat(format3Db, pucchCfg->format3->choice.setup) != ROK)
5301       {
5302          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5303          return RFAILED;
5304       }
5305    }
5306
5307    /* PUCCH Format 4 */
5308    if(format4Db)
5309    {
5310       DU_ALLOC(pucchCfg->format4, sizeof(struct PUCCH_Config__format4));
5311       if(pucchCfg->format4 == NULLP)
5312       {
5313          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5314          return RFAILED;
5315       }
5316
5317       pucchCfg->format4->present = PUCCH_Config__format4_PR_setup;
5318       DU_ALLOC(pucchCfg->format4->choice.setup, sizeof(PUCCH_FormatConfig_t));
5319       if(pucchCfg->format4->choice.setup == NULLP)
5320       {
5321          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5322          return RFAILED;
5323       }
5324
5325       if(BuildPucchFormat(format4Db, pucchCfg->format4->choice.setup) != ROK)
5326       {
5327          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5328          return RFAILED;
5329       }
5330    }
5331
5332    /* Scheduling Request */
5333    if(schReqDb && (schReqDb->schedAddModListCount != 0))
5334    {
5335       pucchCfg->schedulingRequestResourceToAddModList = NULLP;
5336       DU_ALLOC(pucchCfg->schedulingRequestResourceToAddModList, sizeof(struct PUCCH_Config__schedulingRequestResourceToAddModList));
5337       if(pucchCfg->schedulingRequestResourceToAddModList == NULLP)
5338       {
5339          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5340          return RFAILED;
5341       }
5342
5343       if(BuildPucchSchReqAddModList(schReqDb, pucchCfg->schedulingRequestResourceToAddModList) != ROK)
5344       {
5345          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5346          return RFAILED;
5347       }
5348    }
5349
5350    /* Multi CSI */
5351    if(multiCsiDb && (multiCsiDb->multiCsiResrcListCount != 0))
5352    {
5353       pucchCfg->multi_CSI_PUCCH_ResourceList = NULLP;
5354       DU_ALLOC(pucchCfg->multi_CSI_PUCCH_ResourceList, sizeof(struct PUCCH_Config__multi_CSI_PUCCH_ResourceList));
5355       if(pucchCfg->multi_CSI_PUCCH_ResourceList == NULLP)
5356       {
5357          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5358          return RFAILED;
5359       }
5360
5361       if(BuildPucchMultiCsiRsrcList(multiCsiDb, pucchCfg->multi_CSI_PUCCH_ResourceList) != ROK)
5362       {
5363          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5364          return RFAILED;
5365       }
5366    }
5367
5368    /* DL DATA TO UL ACK */
5369    DU_ALLOC(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
5370    if(pucchCfg->dl_DataToUL_ACK == NULLP)
5371    {
5372       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5373       return RFAILED;
5374    }
5375
5376    if(BuildDlDataToUlAckList(dlDataToUlAckDb, pucchCfg->dl_DataToUL_ACK) != ROK)
5377    {
5378       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedPucchCfg");
5379       return RFAILED;
5380    }
5381    
5382    /* TODO : spatial relation info add/mod list and power control*/
5383
5384    return ROK;
5385 }
5386
5387 /*******************************************************************
5388  *
5389  * @brief Fills SRS resource to add/modify list 
5390  *
5391  * @details
5392  *
5393  *    Function : BuildSrsRsrcAddModList
5394  *
5395  *    Functionality: Fills SRS resource to add/modify list
5396  *
5397  * @params[in] 
5398  * @return ROK     - success
5399  *         RFAILED - failure
5400  *
5401  * ****************************************************************/
5402 uint8_t BuildSrsRsrcAddModList(struct SRS_Config__srs_ResourceToAddModList *resourceList)
5403 {
5404    uint8_t   elementCnt;
5405    uint8_t   rsrcIdx;
5406
5407    elementCnt = 1;
5408    resourceList->list.count = elementCnt;
5409    resourceList->list.size = elementCnt * sizeof(SRS_Resource_t *);
5410    resourceList->list.array = NULLP;
5411    DU_ALLOC(resourceList->list.array, resourceList->list.size);
5412    if(!resourceList->list.array)
5413    {
5414       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5415       return RFAILED;
5416    }
5417
5418    for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
5419    {
5420       DU_ALLOC(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
5421       if(!resourceList->list.array[rsrcIdx])
5422       {
5423          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5424          return RFAILED;
5425       }
5426    }
5427
5428    rsrcIdx = 0;
5429    resourceList->list.array[rsrcIdx]->srs_ResourceId = SRS_RSRC_ID;
5430    resourceList->list.array[rsrcIdx]->nrofSRS_Ports = SRS_Resource__nrofSRS_Ports_port1;
5431    resourceList->list.array[rsrcIdx]->transmissionComb.present = SRS_Resource__transmissionComb_PR_n2;
5432
5433    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2 = NULLP;
5434    DU_ALLOC(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2, \
5435          sizeof(struct SRS_Resource__transmissionComb__n2));
5436    if(!resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2)
5437    {
5438       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5439       return RFAILED;
5440    }
5441    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->combOffset_n2\
5442       = SRS_COMB_OFFSET_N2;
5443    resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2->cyclicShift_n2\
5444       = SRS_CYCLIC_SHIFT_N2;
5445
5446    resourceList->list.array[rsrcIdx]->resourceMapping.startPosition = \
5447                                                                       PUSCH_START_SYMBOL;
5448    resourceList->list.array[rsrcIdx]->resourceMapping.nrofSymbols =  \
5449                                                                      SRS_Resource__resourceMapping__nrofSymbols_n1;
5450    resourceList->list.array[rsrcIdx]->resourceMapping.repetitionFactor = \
5451                                                                          SRS_Resource__resourceMapping__repetitionFactor_n1;
5452
5453    resourceList->list.array[rsrcIdx]->freqDomainPosition = SRS_FREQ_DOM_POS;
5454    resourceList->list.array[rsrcIdx]->freqDomainShift = SRS_FREQ_DOM_SHIFT;
5455    resourceList->list.array[rsrcIdx]->freqHopping.c_SRS = C_SRS;
5456    resourceList->list.array[rsrcIdx]->freqHopping.b_SRS = B_SRS;
5457    resourceList->list.array[rsrcIdx]->freqHopping.b_hop = B_HOP;
5458    resourceList->list.array[rsrcIdx]->groupOrSequenceHopping = \
5459                                                                SRS_Resource__groupOrSequenceHopping_neither;
5460
5461    /* Setting resource type to aperiodic for intergration purposes */
5462    resourceList->list.array[rsrcIdx]->resourceType.present = \
5463                                                              SRS_Resource__resourceType_PR_aperiodic;
5464    resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic = NULLP;
5465    DU_ALLOC(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,
5466          sizeof(struct SRS_Resource__resourceType__aperiodic));
5467    if(!resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic)
5468    {
5469       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcAddModList");
5470       return RFAILED;
5471    }
5472    resourceList->list.array[rsrcIdx]->sequenceId = SRS_SEQ_ID;
5473
5474    return ROK;
5475 }
5476
5477 /*******************************************************************
5478  *
5479  * @brief Build SRS resource set Add/mod list
5480  *
5481  * @details
5482  *
5483  *    Function : BuildSrsRsrcSetAddModList
5484  *
5485  *    Functionality: Build SRS resource set Add/mod list
5486  *
5487  * @params[in] 
5488  * @return ROK     - success
5489  *         RFAILED - failure
5490  *
5491  * ****************************************************************/
5492    uint8_t BuildSrsRsrcSetAddModList
5493 (
5494  struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList
5495  )
5496 {
5497    uint8_t  elementCnt;
5498    uint8_t  rSetIdx;
5499    uint8_t  rsrcIdx;
5500    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList;
5501
5502    elementCnt = 1;
5503    rsrcSetList->list.count = elementCnt;
5504    rsrcSetList->list.size = elementCnt * sizeof(SRS_ResourceSet_t *);
5505    rsrcSetList->list.array = NULLP;
5506    DU_ALLOC(rsrcSetList->list.array, rsrcSetList->list.size);
5507    if(!rsrcSetList->list.array)
5508    {
5509       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5510       return RFAILED;
5511    }
5512
5513    for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
5514    {
5515       DU_ALLOC(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
5516       if(!rsrcSetList->list.array[rSetIdx])
5517       {
5518          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5519          return RFAILED;
5520       }
5521    }
5522
5523    rSetIdx = 0;
5524    rsrcSetList->list.array[rSetIdx]->srs_ResourceSetId = SRS_RSET_ID;
5525
5526    /* Fill Resource Id list in resource set */
5527    rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList = NULLP;
5528    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
5529          sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
5530    if(!rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
5531    {
5532       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5533       return RFAILED;
5534    }
5535
5536    elementCnt = 1;
5537    rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
5538    rsrcIdList->list.count = elementCnt;
5539    rsrcIdList->list.size = elementCnt * sizeof(SRS_ResourceId_t *);
5540    rsrcIdList->list.array = NULLP;
5541    DU_ALLOC(rsrcIdList->list.array, rsrcIdList->list.size);
5542    if(!rsrcIdList->list.array)
5543    {
5544       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5545       return RFAILED;
5546    }
5547
5548    for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
5549    {
5550       DU_ALLOC(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
5551       if(!rsrcIdList->list.array[rsrcIdx])
5552       {
5553          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5554          return RFAILED;
5555       }
5556    }
5557
5558    rsrcIdx = 0;
5559    *rsrcIdList->list.array[rsrcIdx] = SRS_RSRC_ID;
5560
5561    /* Fill resource type */
5562    rsrcSetList->list.array[rSetIdx]->resourceType.present = \
5563                                                             SRS_ResourceSet__resourceType_PR_aperiodic;
5564
5565    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic = NULLP;
5566    DU_ALLOC(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
5567          sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
5568    if(!rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic)
5569    {
5570       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildSrsRsrcSetAddModList");
5571       return RFAILED;
5572    }
5573    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->aperiodicSRS_ResourceTrigger \
5574       = APERIODIC_SRS_RESRC_TRIGGER;
5575
5576    /* TODO : Fill values for below IEs as expected by Viavi */
5577    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->csi_RS = NULLP;
5578    rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic->slotOffset = NULLP;
5579
5580
5581    rsrcSetList->list.array[rSetIdx]->usage = SRS_ResourceSet__usage_codebook;
5582    rsrcSetList->list.array[rSetIdx]->alpha = NULLP;
5583    rsrcSetList->list.array[rSetIdx]->p0 = NULLP;
5584    rsrcSetList->list.array[rSetIdx]->pathlossReferenceRS = NULLP;
5585    rsrcSetList->list.array[rSetIdx]->srs_PowerControlAdjustmentStates = NULLP;
5586
5587    return ROK;
5588 }
5589
5590 /*******************************************************************
5591  *
5592  * @brief Builds BWP UL dedicated SRS Config
5593  *
5594  * @details
5595  *
5596  *    Function : BuildBWPUlDedSrsCfg
5597  *
5598  *    Functionality: Builds BWP UL dedicated SRS Config
5599  *
5600  * @params[in] SRS Config 
5601  * @return ROK     - success
5602  *         RFAILED - failure
5603  *
5604  * ****************************************************************/
5605 uint8_t BuildBWPUlDedSrsCfg(SRS_Config_t *srsCfg)
5606 {
5607    srsCfg->srs_ResourceSetToReleaseList = NULLP;
5608    srsCfg->srs_ResourceSetToAddModList = NULLP;
5609    DU_ALLOC(srsCfg->srs_ResourceSetToAddModList, \
5610          sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
5611    if(!srsCfg->srs_ResourceSetToAddModList)
5612    {
5613       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5614       return RFAILED;
5615    }
5616    if(BuildSrsRsrcSetAddModList(srsCfg->srs_ResourceSetToAddModList) != ROK)
5617    {
5618       return RFAILED;
5619    }
5620
5621    srsCfg->srs_ResourceToReleaseList = NULLP;
5622
5623    /* Resource to Add/Modify list */
5624    srsCfg->srs_ResourceToAddModList = NULLP;
5625    DU_ALLOC(srsCfg->srs_ResourceToAddModList, \
5626          sizeof(struct SRS_Config__srs_ResourceToAddModList));
5627    if(!srsCfg->srs_ResourceToAddModList)
5628    {
5629       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildBWPUlDedSrsCfg");
5630       return RFAILED;
5631    }
5632
5633    if(BuildSrsRsrcAddModList(srsCfg->srs_ResourceToAddModList) != ROK)
5634    {
5635       return RFAILED;
5636    }
5637
5638    srsCfg->tpc_Accumulation = NULLP;
5639
5640    return ROK;
5641 }
5642
5643
5644
5645 /*******************************************************************
5646  *
5647  * @brief Builds Pusch Serving cell Config
5648  *
5649  * @details
5650  *
5651  *    Function : BuildPuschSrvCellCfg
5652  *
5653  *    Functionality: Builds Pusch Serving cell Config
5654  *
5655  * @params[in] struct UplinkConfig__pusch_ServingCellConfig *puschCfg
5656  *
5657  * @return ROK     - success
5658  *         RFAILED - failure
5659  *
5660  * ****************************************************************/
5661 uint8_t BuildPuschSrvCellCfg(struct UplinkConfig__pusch_ServingCellConfig *puschCfg)
5662 {
5663    puschCfg->present = UplinkConfig__pusch_ServingCellConfig_PR_setup;
5664    puschCfg->choice.setup = NULLP;
5665    DU_ALLOC(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
5666    if(!puschCfg->choice.setup)
5667    {
5668       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5669       return RFAILED;
5670    }
5671
5672    puschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5673    puschCfg->choice.setup->rateMatching = NULLP;
5674    puschCfg->choice.setup->xOverhead = NULLP;
5675    puschCfg->choice.setup->ext1 = NULLP;
5676    DU_ALLOC(puschCfg->choice.setup->ext1, sizeof(struct PUSCH_ServingCellConfig__ext1));
5677    if(!puschCfg->choice.setup->ext1)
5678    {
5679       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5680       return RFAILED;
5681    }
5682
5683    puschCfg->choice.setup->ext1->maxMIMO_Layers = NULLP;
5684    DU_ALLOC(puschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5685    if(!puschCfg->choice.setup->ext1->maxMIMO_Layers)
5686    {
5687       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5688       return RFAILED;
5689    }
5690    *(puschCfg->choice.setup->ext1->maxMIMO_Layers) = PUSCH_MAX_MIMO_LAYERS;
5691
5692    puschCfg->choice.setup->ext1->processingType2Enabled= NULLP;
5693    DU_ALLOC(puschCfg->choice.setup->ext1->processingType2Enabled,sizeof(BOOLEAN_t));
5694    if(!puschCfg->choice.setup->ext1->processingType2Enabled)
5695    {
5696       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPuschSrvCellCfg");
5697       return RFAILED;
5698    }
5699    *(puschCfg->choice.setup->ext1->processingType2Enabled) = PUSCH_PROCESS_TYPE2_ENABLED;
5700    return ROK;
5701 }
5702
5703 /*******************************************************************
5704  *
5705  * @brief Builds inital UL BWP
5706  *
5707  * @details
5708  *
5709  *    Function : BuildInitialUlBWP
5710  *
5711  *    Functionality: Builds initial UL BWP
5712  *
5713  * @params[in] BWP_UplinkDedicated_t *ulBwp
5714  * @return ROK     - success
5715  *         RFAILED - failure
5716  *
5717  * ****************************************************************/
5718 uint8_t BuildInitialUlBWP(InitialUlBwp *initUlBwp, BWP_UplinkDedicated_t *ulBwp)
5719 {
5720    PucchCfg *pucchCfg = NULLP;
5721    PuschCfg *puschCfg = NULLP;
5722
5723    if(initUlBwp)
5724    {
5725       if(initUlBwp->pucchPresent)
5726          pucchCfg = &initUlBwp->pucchCfg;
5727       if(initUlBwp->puschPresent)
5728          puschCfg = &initUlBwp->puschCfg;
5729    }
5730
5731    ulBwp->pucch_Config = NULLP;
5732    DU_ALLOC(ulBwp->pucch_Config, sizeof(struct BWP_UplinkDedicated__pucch_Config));
5733    if(!ulBwp->pucch_Config)
5734    {
5735       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5736       return RFAILED;
5737    }
5738
5739    ulBwp->pucch_Config->present = BWP_UplinkDedicated__pucch_Config_PR_setup;
5740    ulBwp->pucch_Config->choice.setup = NULLP;
5741    DU_ALLOC(ulBwp->pucch_Config->choice.setup, sizeof(PUCCH_Config_t));
5742    if(!ulBwp->pucch_Config->choice.setup)
5743    {
5744       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5745       return RFAILED;
5746    }
5747
5748    if(BuildBWPUlDedPucchCfg(pucchCfg, ulBwp->pucch_Config->choice.setup) != ROK)
5749    {
5750       return RFAILED;
5751    }
5752
5753    /* Fill BWP UL dedicated PUSCH config */
5754    ulBwp->pusch_Config = NULLP;
5755    DU_ALLOC(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
5756    if(!ulBwp->pusch_Config)
5757    {
5758       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5759       return RFAILED;
5760    }
5761
5762    ulBwp->pusch_Config->present = BWP_UplinkDedicated__pusch_Config_PR_setup;
5763    ulBwp->pusch_Config->choice.setup = NULLP;
5764    DU_ALLOC(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
5765    if(!ulBwp->pusch_Config->choice.setup)
5766    {
5767       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5768       return RFAILED;
5769    }
5770
5771    if(BuildBWPUlDedPuschCfg(puschCfg, ulBwp->pusch_Config->choice.setup) != ROK)
5772    {
5773       return RFAILED;
5774    }
5775
5776    ulBwp->configuredGrantConfig = NULLP;
5777
5778    /* Fill BPW UL dedicated SRS config */
5779    ulBwp->srs_Config = NULLP;
5780    DU_ALLOC(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
5781    if(!ulBwp->srs_Config)
5782    {
5783       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5784       return RFAILED;
5785    }
5786
5787    ulBwp->srs_Config->present = BWP_UplinkDedicated__srs_Config_PR_setup;
5788    ulBwp->srs_Config->choice.setup = NULLP;
5789    DU_ALLOC(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
5790    if(!ulBwp->srs_Config->choice.setup)
5791    {
5792       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildInitialUlBWP");
5793       return RFAILED;
5794    }
5795
5796    if(BuildBWPUlDedSrsCfg(ulBwp->srs_Config->choice.setup) != ROK)
5797    {
5798       return RFAILED;   
5799    }
5800
5801    ulBwp->beamFailureRecoveryConfig = NULLP;
5802
5803    return ROK;
5804 }
5805
5806 /*******************************************************************
5807  *
5808  * @brief Builds UL config
5809  * @details
5810  *
5811  *    Function : BuildUlCfg 
5812  *
5813  *    Functionality: Builds UL config in spCellCfgDed
5814  *
5815  * @params[in] UplinkConfig_t *ulCfg
5816  *
5817  * @return ROK     - success
5818  *         RFAILED - failure
5819  *
5820  * ****************************************************************/
5821 uint8_t BuildUlCfg(ServCellCfgInfo *servCellCfg, UplinkConfig_t *ulCfg)
5822 {
5823    InitialUlBwp *initUlBwp = NULLP;
5824
5825    if(servCellCfg)
5826    {
5827       initUlBwp = &servCellCfg->initUlBwp;
5828    }
5829
5830    ulCfg->initialUplinkBWP = NULLP;
5831    DU_ALLOC(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
5832    if(!ulCfg->initialUplinkBWP)
5833    {
5834       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5835       return RFAILED;
5836    }
5837
5838    if(BuildInitialUlBWP(initUlBwp, ulCfg->initialUplinkBWP) != ROK)
5839    {
5840       return RFAILED;
5841    }
5842
5843    ulCfg->uplinkBWP_ToReleaseList = NULLP;
5844    ulCfg->uplinkBWP_ToAddModList = NULLP;
5845    ulCfg->firstActiveUplinkBWP_Id = NULLP;
5846    DU_ALLOC(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
5847    if(!ulCfg->firstActiveUplinkBWP_Id)
5848    {
5849       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5850       return RFAILED;
5851    }
5852    if(servCellCfg == NULLP)
5853       *(ulCfg->firstActiveUplinkBWP_Id) = ACTIVE_UL_BWP_ID;
5854    else
5855       *(ulCfg->firstActiveUplinkBWP_Id) = servCellCfg->firstActvUlBwpId;
5856
5857    ulCfg->pusch_ServingCellConfig = NULLP;
5858    DU_ALLOC(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
5859    if(!ulCfg->pusch_ServingCellConfig)
5860    {
5861       DU_LOG("\nERROR  -->  F1AP : Memory Allocation failed in BuildUlCfg");
5862       return RFAILED;
5863    }
5864
5865    if(BuildPuschSrvCellCfg(ulCfg->pusch_ServingCellConfig) != ROK)
5866    {
5867       return RFAILED;
5868    }
5869
5870    ulCfg->carrierSwitching = NULLP;
5871    ulCfg->ext1 = NULLP;
5872    return ROK;
5873 }
5874
5875 /*******************************************************************
5876  *
5877  * @brief Builds PDSCH serving cell config
5878  * @details
5879  *
5880  *    Function : BuildPdschSrvCellCfg
5881  *
5882  *    Functionality: Builds PDSCH serving cell config in spCellCfgDed
5883  *
5884  * @params[in] struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg 
5885  *
5886  * @return ROK     - success
5887  *         RFAILED - failure
5888  *
5889  * ****************************************************************/
5890 uint8_t BuildPdschSrvCellCfg(PdschServCellCfg *pdschServCellDb, struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg)
5891 {
5892    pdschCfg->present =  ServingCellConfig__pdsch_ServingCellConfig_PR_setup;
5893    pdschCfg->choice.setup = NULLP;
5894    DU_ALLOC(pdschCfg->choice.setup, sizeof( struct PDSCH_ServingCellConfig));
5895    if(!pdschCfg->choice.setup)
5896    {
5897       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5898       return RFAILED;
5899    }
5900
5901    /* Code Block Group Transmission */
5902    pdschCfg->choice.setup->codeBlockGroupTransmission = NULLP;
5903    if(pdschServCellDb && (pdschServCellDb->maxCodeBlkGrpPerTb || pdschServCellDb->codeBlkGrpFlushInd))
5904    {
5905       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission, sizeof(struct PDSCH_ServingCellConfig__codeBlockGroupTransmission));
5906       if(pdschCfg->choice.setup->codeBlockGroupTransmission == NULLP)
5907       {
5908          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5909          return RFAILED;
5910       }
5911
5912       pdschCfg->choice.setup->codeBlockGroupTransmission->present = PDSCH_ServingCellConfig__codeBlockGroupTransmission_PR_setup;
5913       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup = NULLP;
5914       DU_ALLOC(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup, sizeof(struct PDSCH_CodeBlockGroupTransmission ));
5915       if(pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup == NULLP)
5916       {
5917          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5918          return RFAILED;
5919       }
5920
5921       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock = \
5922          *(pdschServCellDb->maxCodeBlkGrpPerTb);
5923       pdschCfg->choice.setup->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator = \
5924          *(pdschServCellDb->codeBlkGrpFlushInd);
5925    }
5926
5927    /* xOverhead */
5928    pdschCfg->choice.setup->xOverhead = NULLP;
5929    if(pdschServCellDb && pdschServCellDb->xOverhead)
5930    {
5931       DU_ALLOC(pdschCfg->choice.setup->xOverhead, sizeof(long));
5932       if(pdschCfg->choice.setup->xOverhead == NULLP)
5933       {
5934          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5935          return RFAILED;
5936       }
5937       *(pdschCfg->choice.setup->xOverhead) = *(pdschServCellDb->xOverhead);
5938    }
5939
5940    /* Number of HARQ processes */
5941    pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH = NULLP;
5942    DU_ALLOC(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH, sizeof(long));
5943    if(!pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH)
5944    {
5945       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5946       return RFAILED;
5947    }
5948
5949    if(pdschServCellDb == NULLP)
5950    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = PDSCH_NUM_HARQ_PROC;
5951    else
5952    *(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH) = pdschServCellDb->numHarqProcForPdsch;
5953
5954    pdschCfg->choice.setup->pucch_Cell = NULLP;
5955
5956    /* Extension */
5957    pdschCfg->choice.setup->ext1 = NULLP;
5958    if(pdschServCellDb && pdschServCellDb->maxMimoLayers)
5959    {
5960       DU_ALLOC(pdschCfg->choice.setup->ext1, sizeof(struct PDSCH_ServingCellConfig__ext1));
5961       if(pdschCfg->choice.setup->ext1 == NULLP)
5962       {
5963          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5964          return RFAILED;
5965       }
5966
5967       DU_ALLOC(pdschCfg->choice.setup->ext1->maxMIMO_Layers, sizeof(long));
5968       if(pdschCfg->choice.setup->ext1->maxMIMO_Layers == NULLP)
5969       {
5970          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildPdschSrvCellCfg");
5971          return RFAILED;
5972       }
5973       *(pdschCfg->choice.setup->ext1->maxMIMO_Layers) = *(pdschServCellDb->maxMimoLayers);
5974    }
5975
5976    return ROK;
5977 }
5978
5979 /*******************************************************************
5980  *
5981  * @brief Builds CSI Meas config
5982  * @details
5983  *
5984  *    Function : BuildCsiMeasCfg 
5985  *
5986  *    Functionality: Builds CSI Meas config in spCellCfgDed
5987  *
5988  * @params[in] struct ServingCellConfig__csi_MeasConfig *csiMeasCfg
5989  *
5990  * @return ROK     - success
5991  *         RFAILED - failure
5992  *
5993  * ****************************************************************/
5994 uint8_t BuildCsiMeasCfg(struct ServingCellConfig__csi_MeasConfig *csiMeasCfg)
5995 {
5996
5997    return ROK;
5998 }
5999
6000 /*******************************************************************
6001  *
6002  * @brief Builds DL BWP to add/modify list
6003  * @details
6004  *
6005  *    Function : BuildDlBwpToAddModList
6006  *
6007  *    Functionality: Builds DL BWP to add/modify list
6008  *
6009  * @params[in] ServCellCfgInfo *servCellCfg, 
6010  *             struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList
6011  *
6012  * @return ROK     - success
6013  *         RFAILED - failure
6014  *
6015  * ****************************************************************/ 
6016 uint8_t BuildDlBwpToAddModList(ServCellCfgInfo *servCellCfg, struct ServingCellConfig__downlinkBWP_ToAddModList *dlBwpAddModList)
6017 {
6018    uint8_t elementCnt, idx;
6019
6020    elementCnt = servCellCfg->numDlBwpToAdd;
6021    dlBwpAddModList->list.count = elementCnt;
6022    dlBwpAddModList->list.size = elementCnt * sizeof(struct BWP_Downlink *);
6023    dlBwpAddModList->list.array = NULLP;
6024    DU_ALLOC(dlBwpAddModList->list.array, dlBwpAddModList->list.size);
6025    if(dlBwpAddModList->list.array == NULLP)
6026    {
6027       DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6028       return RFAILED;
6029    }
6030
6031    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6032    {
6033       DU_ALLOC(dlBwpAddModList->list.array[idx], sizeof(BWP_Downlink_t));
6034       if(dlBwpAddModList->list.array[idx] == NULLP)
6035       {
6036          DU_LOG("\nERROR  --> DU APP: Memory allocation failure in BuildDlBwpToAddModList");
6037          return RFAILED;
6038       }
6039    }
6040
6041    for(idx=0; idx<dlBwpAddModList->list.count; idx++)
6042    {
6043       dlBwpAddModList->list.array[idx]->bwp_Id = servCellCfg->DlBwpToAddList[idx].bwpId;
6044       dlBwpAddModList->list.array[idx]->bwp_Common = NULLP;
6045       dlBwpAddModList->list.array[idx]->bwp_Dedicated = NULLP;
6046    }
6047    return ROK;
6048 }
6049
6050 /*******************************************************************
6051  *
6052  * @brief Builds Spcell config dedicated
6053  * @details
6054  *
6055  *    Function : BuildSpCellCfgDed
6056  *
6057  *    Functionality: Builds sp cell config dedicated in spCellCfg
6058  *
6059  * @params[in] ServingCellConfig_t srvCellCfg
6060  *
6061  * @return ROK     - success
6062  *         RFAILED - failure
6063  *
6064  * ****************************************************************/
6065 uint8_t BuildSpCellCfgDed(DuUeCb *ueCb, ServingCellConfig_t *srvCellCfg)
6066 {
6067    ServCellCfgInfo *servCellCfg = NULLP;
6068    InitialDlBwp *initDlBwp = NULLP;
6069    PdschServCellCfg *pdschServCellDb = NULLP;
6070
6071    if(ueCb)
6072    {
6073       servCellCfg = &ueCb->macUeCfg.spCellCfg.servCellCfg;
6074       initDlBwp = &servCellCfg->initDlBwp;
6075       pdschServCellDb = &servCellCfg->pdschServCellCfg;
6076    }
6077
6078    srvCellCfg->tdd_UL_DL_ConfigurationDedicated = NULLP;
6079    DU_ALLOC(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
6080    if(!srvCellCfg->tdd_UL_DL_ConfigurationDedicated)
6081    {
6082       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6083       return RFAILED;
6084    }
6085
6086    srvCellCfg->initialDownlinkBWP = NULLP;
6087    DU_ALLOC(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
6088    if(!srvCellCfg->initialDownlinkBWP)
6089    {
6090       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6091       return RFAILED;
6092    }
6093
6094    if(BuildInitialDlBWP(initDlBwp, srvCellCfg->initialDownlinkBWP) != ROK)
6095    {
6096       DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6097       return RFAILED;
6098    }
6099
6100    srvCellCfg->downlinkBWP_ToReleaseList = NULLP;
6101
6102    srvCellCfg->downlinkBWP_ToAddModList = NULLP;
6103    if(ueCb && ueCb->macUeCfg.spCellCfg.servCellCfg.numDlBwpToAdd)
6104    {
6105       DU_ALLOC(srvCellCfg->downlinkBWP_ToAddModList, sizeof(struct ServingCellConfig__downlinkBWP_ToAddModList));
6106       if(srvCellCfg->downlinkBWP_ToAddModList == NULLP)
6107       {
6108          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6109          return RFAILED;
6110       }
6111
6112       if(BuildDlBwpToAddModList(&ueCb->macUeCfg.spCellCfg.servCellCfg, srvCellCfg->downlinkBWP_ToAddModList) != ROK)
6113       {
6114          DU_LOG("\nERROR  -->  F1AP : BuildInitialDlBWP failed");
6115          return RFAILED;
6116       }
6117    }
6118
6119    srvCellCfg->firstActiveDownlinkBWP_Id = NULLP;
6120    DU_ALLOC(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
6121    if(!srvCellCfg->firstActiveDownlinkBWP_Id)
6122    {
6123       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6124       return RFAILED;
6125    }
6126    if(ueCb == NULLP)
6127       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6128    else
6129       *(srvCellCfg->firstActiveDownlinkBWP_Id) = ueCb->macUeCfg.spCellCfg.servCellCfg.firstActvDlBwpId;
6130
6131    srvCellCfg->bwp_InactivityTimer = NULLP;
6132
6133    srvCellCfg->defaultDownlinkBWP_Id = NULLP;
6134    DU_ALLOC(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
6135    if(!srvCellCfg->defaultDownlinkBWP_Id)
6136    {
6137       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6138       return RFAILED;
6139    }
6140    if(ueCb == NULLP)
6141       *(srvCellCfg->defaultDownlinkBWP_Id) = ACTIVE_DL_BWP_ID;
6142    else
6143       *(srvCellCfg->defaultDownlinkBWP_Id) = ueCb->macUeCfg.spCellCfg.servCellCfg.defaultDlBwpId;
6144
6145    srvCellCfg->uplinkConfig = NULLP;
6146    DU_ALLOC(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));
6147    if(!srvCellCfg->uplinkConfig)
6148    {
6149       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6150       return RFAILED;
6151    }
6152
6153    if(BuildUlCfg(servCellCfg, srvCellCfg->uplinkConfig) != ROK)
6154    {
6155       DU_LOG("\nERROR  -->  F1AP : BuildUlCfg failed");
6156       return RFAILED;
6157    }
6158    srvCellCfg->supplementaryUplink = NULLP;
6159    srvCellCfg->pdcch_ServingCellConfig = NULLP;
6160
6161    srvCellCfg->pdsch_ServingCellConfig = NULLP;
6162    DU_ALLOC(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct  ServingCellConfig__pdsch_ServingCellConfig));
6163    if(!srvCellCfg->pdsch_ServingCellConfig)
6164    {
6165       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6166       return RFAILED;
6167    }
6168
6169    if(BuildPdschSrvCellCfg(pdschServCellDb, srvCellCfg->pdsch_ServingCellConfig) != ROK)
6170    {
6171       DU_LOG("\nERROR  -->  F1AP : BuildPdschSrvCellCfg failed");
6172       return RFAILED;
6173    }
6174
6175    srvCellCfg->csi_MeasConfig = NULLP;
6176 #if 0
6177    DU_ALLOC(srvCellCfg->csi_MeasConfig, sizeof(struct   ServingCellConfig__csi_MeasConfig))
6178       if(!srvCellCfg->csi_MeasConfig)
6179       {
6180          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfgDed");
6181          return RFAILED;
6182       }
6183
6184    if(BuildCsiMeasCfg(srvCellCfg->csi_MeasConfig) != ROK)
6185    {
6186       DU_LOG("\nF1AP : BuildCsiMeasCfg failed");
6187       return RFAILED;
6188    }
6189 #endif
6190    srvCellCfg->sCellDeactivationTimer = NULLP;
6191    srvCellCfg->crossCarrierSchedulingConfig = NULLP;
6192    srvCellCfg->tag_Id = TAG_ID;
6193    srvCellCfg->dummy = NULLP;
6194    srvCellCfg->pathlossReferenceLinking = NULLP;
6195    srvCellCfg->servingCellMO = NULLP;
6196    srvCellCfg->ext1 = NULLP;
6197
6198    return ROK;
6199 }
6200
6201 /*******************************************************************
6202  *
6203  * @brief Fills SCS specific carrier list in DL frequency info
6204  *
6205  * @details
6206  *
6207  *    Function : BuildScsSpecificCarrierListDl
6208  *
6209  *    Functionality: Fills SCS specific carrier list in DL frequency info
6210  *
6211  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
6212  *
6213  * @return ROK     - success
6214  *         RFAILED - failure
6215  *
6216  * ****************************************************************/
6217 uint8_t BuildScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
6218 {
6219    uint8_t elementCnt = 0, listIdx = 0;
6220    ScsSpecCarrier duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg.dlScsCarrier;
6221
6222    elementCnt = ODU_VALUE_ONE;
6223    scsCarrierList->list.count = elementCnt;
6224    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6225
6226    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6227    if(!scsCarrierList->list.array)
6228    {
6229       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for scs carrier list array \
6230          in BuildScsSpecificCarrierListDl()");
6231       return RFAILED;
6232    }
6233
6234    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6235    {
6236       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6237       if(!scsCarrierList->list.array[listIdx])
6238       {    
6239          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SCS Specific Carrier list array \
6240             element in BuildScsSpecificCarrierListDl()");
6241          return RFAILED;
6242       }    
6243    }
6244
6245    listIdx = 0;
6246    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6247    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6248    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6249
6250    return ROK;
6251 }
6252
6253 /*******************************************************************
6254  *
6255  * @brief Fills DL frequency info in DL config common
6256  *
6257  * @details
6258  *
6259  *    Function : BuildFreqInfoDl
6260  *
6261  *    Functionality: Fills DL frequency info in DL config common
6262  *
6263  * @params[in] Pointer to DownlinkConfigCommon_t
6264  *
6265  * @return ROK     - success
6266  *         RFAILED - failure
6267  *
6268  * ****************************************************************/
6269 uint8_t BuildFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
6270 {
6271    uint8_t freqBandIdx = 0, elementCnt = 0;
6272    DlCfgCommon  dlCfg = duCfgParam.sib1Params.srvCellCfgCommSib.dlCfg;
6273
6274    /* TODO : Fill SSB Absolute Frequency */
6275    /*
6276       DU_ALLOC(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
6277       if(!frequencyInfoDL->absoluteFrequencySSB)
6278       {
6279       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB Absolute Frequency in BuildFreqInfoDl()");
6280       return RFAILED;
6281       }
6282       frequencyInfoDL->absoluteFrequencySSB = ?;
6283       */
6284
6285    /* NR Multi Frequency Band List */
6286    elementCnt = ODU_VALUE_ONE;
6287    frequencyInfoDL->frequencyBandList.list.count = elementCnt;
6288    frequencyInfoDL->frequencyBandList.list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6289
6290    DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
6291    if(!frequencyInfoDL->frequencyBandList.list.array)
6292    {
6293       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for Frequency Band List array in BuildFreqInfoDl()");
6294       return RFAILED;
6295    }
6296
6297    for(freqBandIdx = 0; freqBandIdx < elementCnt; freqBandIdx++)
6298    {
6299       DU_ALLOC(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
6300       if(!frequencyInfoDL->frequencyBandList.list.array[freqBandIdx])
6301       {
6302          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoDl()");
6303          return RFAILED;
6304       }
6305    }
6306
6307    freqBandIdx = 0;
6308    *(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx]) = dlCfg.freqBandInd;
6309
6310    /* TODO : Absolute Frequency to Point A */
6311    //frequencyInfoDL->absoluteFrequencyPointA
6312
6313    /* Subcarrier Spacing specifc carrier List */
6314    if((BuildScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList)) != ROK)
6315    {
6316       DU_LOG("\nERROR  -->  DU APP : Failed to fill SCS specific carrier list DL in BuildFreqInfoDl()");
6317       return RFAILED;
6318    }
6319
6320    return ROK;
6321
6322 }
6323
6324 /*******************************************************************
6325  *
6326  * @brief Fills DL config common in Serving cell config common
6327  *
6328  * @details
6329  *
6330  *    Function : BuildDlConfigCommon
6331  *
6332  *    Functionality: Fills DL config common in Serving cell config common
6333  *
6334  * @params[in] Pointer to DownlinkConfigCommon_t
6335  *
6336  * @return ROK     - success
6337  *         RFAILED - failure
6338  *
6339  * ****************************************************************/
6340 uint8_t BuildDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
6341 {
6342    /* DL Frequency Info */
6343    DU_ALLOC(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
6344    if(!dlCfgCommon->frequencyInfoDL)
6345    {
6346       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL frequency info in BuildDlConfigCommon()");
6347       return RFAILED;
6348    }
6349    if((BuildFreqInfoDl(dlCfgCommon->frequencyInfoDL))!= ROK)
6350    {
6351       DU_LOG("\nERROR  --> DU APP : Failed to fill DL frequency info in BuildDlConfigCommon()");
6352       return RFAILED;
6353    }
6354
6355    /* DL BWP config common */
6356    DU_ALLOC(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
6357    if(!dlCfgCommon->initialDownlinkBWP)
6358    {
6359       DU_LOG("\nERROR  --> DU APP : Memory allocation failed for DL BWP config common in BuildDlConfigCommon()");
6360       return RFAILED;
6361    }
6362    if((BuildBwpDlCommon(dlCfgCommon->initialDownlinkBWP)) != ROK)
6363    {
6364       DU_LOG("\nERROR  --> DU APP : Failed to fill DL DWP config common in BuildDlConfigCommon()");
6365       return RFAILED;
6366    }
6367
6368    return ROK;
6369 }
6370
6371 /*******************************************************************
6372  *
6373  * @brief Fills SCS specific carrier list in UL frequency Info
6374  *
6375  * @details
6376  *
6377  *    Function : BuildScsSpecificCarrierListUl
6378  *
6379  *    Functionality: Fills SCS specific carrier list in UL frequency Info
6380  *
6381  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
6382  *
6383  * @return ROK     - success
6384  *         RFAILED - failure
6385  *
6386  * ****************************************************************/
6387 uint8_t BuildScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
6388 {
6389    uint8_t elementCnt = 0, listIdx = 0; 
6390    ScsSpecCarrier   duScsSpecCarrier = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.ulScsCarrier;
6391
6392    elementCnt = ODU_VALUE_ONE;
6393    scsCarrierList->list.count = elementCnt;
6394    scsCarrierList->list.size = elementCnt * sizeof(SCS_SpecificCarrier_t *);
6395
6396    DU_ALLOC(scsCarrierList->list.array, scsCarrierList->list.size);
6397    if(!scsCarrierList->list.array)
6398    {
6399       DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6400       return RFAILED;
6401    }
6402
6403    for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
6404    {
6405       DU_ALLOC(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
6406       if(!scsCarrierList->list.array[listIdx])
6407       {    
6408          DU_LOG("\nERROR  -->  DU APP : SCS Specific Carrier list memory allocation failed");
6409          return RFAILED;
6410       }    
6411    }
6412    listIdx = 0; 
6413    scsCarrierList->list.array[listIdx]->offsetToCarrier = duScsSpecCarrier.scsOffset;
6414    scsCarrierList->list.array[listIdx]->subcarrierSpacing = duScsSpecCarrier.scs;
6415    scsCarrierList->list.array[listIdx]->carrierBandwidth = duScsSpecCarrier.scsBw;
6416
6417    return ROK;
6418 }
6419
6420 /*******************************************************************
6421  *
6422  * @brief Fills frequency info in UL config common
6423  *
6424  * @details
6425  *
6426  *    Function : BuildFreqInfoUl
6427  *
6428  *    Functionality: Fills frequency info in UL config common
6429  *
6430  * @params[in] Pointer to FrequencyInfoUL_t
6431  *
6432  * @return ROK     - success
6433  *         RFAILED - failure
6434  *
6435  * ****************************************************************/
6436 uint8_t BuildFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
6437 {
6438    uint8_t elementCnt = 0, listIdx= 0;
6439    UlCfgCommon  ulCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg;
6440
6441    /* NR Multi Frequency Band List */
6442    DU_ALLOC(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
6443    if(!frequencyInfoUL->frequencyBandList)
6444    {
6445       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band list in BuildFreqInfoUl()");
6446       return RFAILED;
6447    }
6448
6449    elementCnt = ODU_VALUE_ONE;
6450    frequencyInfoUL->frequencyBandList->list.count = elementCnt;
6451    frequencyInfoUL->frequencyBandList->list.size = elementCnt * sizeof(FreqBandIndicatorNR_t *);
6452
6453    DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
6454    if(!frequencyInfoUL->frequencyBandList->list.array)
6455    {
6456       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array in BuildFreqInfoUl()");
6457       return RFAILED;
6458    }
6459
6460    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6461    {
6462       DU_ALLOC(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
6463       if(!frequencyInfoUL->frequencyBandList->list.array[listIdx])
6464       {
6465          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for frequency band array element in BuildFreqInfoUl()");
6466          return RFAILED;
6467       }
6468    }
6469
6470    listIdx = 0;
6471    *(frequencyInfoUL->frequencyBandList->list.array[listIdx]) = ulCfg.freqBandInd;
6472
6473    /* TODO : Fill Absolute frequency point A */
6474    /*
6475       DU_ALLOC(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
6476       if(!frequencyInfoUL->absoluteFrequencyPointA)
6477       {
6478       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for absolute frequency point A in BuildFreqInfoUl()");
6479       return RFAILED;
6480       }
6481     *(frequencyInfoUL->absoluteFrequencyPointA) = ?;
6482     */
6483
6484    /* Subcarrier Spacing specifc carrier */
6485    if((BuildScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList)) != ROK) 
6486    {
6487       DU_LOG("\nERROR  --> DU APP : Failed to fill SCS Specific Carrier list UL in BuildFreqInfoUl()");
6488       return RFAILED;
6489    }
6490
6491    /* P-MAX */
6492    DU_ALLOC(frequencyInfoUL->p_Max, sizeof(P_Max_t));
6493    if(!frequencyInfoUL->p_Max)
6494    {
6495       DU_LOG("\nERROR  -->  DU APP : UL Frequency Infoo  memory allocation failure");
6496       return RFAILED;
6497    }
6498    *frequencyInfoUL->p_Max = ulCfg.pMax;
6499
6500    return ROK;
6501 }
6502
6503 /*******************************************************************
6504  *
6505  * @brief Fills UL config common in Serving cell config common
6506  *
6507  * @details
6508  *
6509  *    Function : BuildUlConfigCommon
6510  *
6511  *    Functionality: Fills UL config common in Serving cell config common
6512  *
6513  * @params[in] Pointer to UplinkConfigCommon_t
6514  *
6515  * @return ROK     - success
6516  *         RFAILED - failure
6517  *
6518  * ****************************************************************/
6519 uint8_t BuildUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
6520 {
6521    /* UL Frequency Info */
6522    DU_ALLOC(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
6523    if(!ulCfgCommon->frequencyInfoUL)
6524    {
6525       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for UL frequency info in BuildUlConfigCommon()");
6526       return RFAILED;
6527    }
6528
6529    if((BuildFreqInfoUl(ulCfgCommon->frequencyInfoUL)) != ROK)
6530    {
6531       DU_LOG("\nERROR  -->  DU APP : Failed to fill frequency info UL in BuildUlConfigCommon()");
6532       return RFAILED;
6533    }
6534
6535    /* UL BWP common */
6536    DU_ALLOC(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
6537    if(!ulCfgCommon->initialUplinkBWP)
6538    {
6539       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for initial UL BWP in BuildUlConfigCommon()");
6540       return RFAILED;
6541    }
6542
6543    if((BuildBwpUlCommon(ulCfgCommon->initialUplinkBWP)) != ROK)
6544    {
6545       DU_LOG("\nERROR  -->  DU APP : Failed to fill BWP UL common in BuildUlConfigCommon()");
6546       return RFAILED;
6547    }
6548
6549    /* Time Alignment timer */
6550    ulCfgCommon->dummy = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.timeAlignTimerComm;
6551
6552    return ROK;
6553 }
6554
6555 /*******************************************************************
6556  *
6557  * @brief Fills SSB position in burst in SP cell config common
6558  *
6559  * @details
6560  *
6561  *    Function : BuildSsbPosInBurst
6562  *
6563  *    Functionality: 
6564  *       Fills SSB position in burst in SP cell config common
6565  *
6566  * @params[in] Pointer to struct ServingCellConfigCommon__ssb_PositionsInBurst
6567  *
6568  * @return ROK     - success
6569  *         RFAILED - failure
6570  *
6571  * ****************************************************************/
6572 uint8_t BuildSsbPosInBurst(struct ServingCellConfigCommon__ssb_PositionsInBurst *ssbPosInBurst)
6573 {
6574    uint8_t bitStringSizeInBytes = 0;
6575
6576    ssbPosInBurst->present = ServingCellConfigCommon__ssb_PositionsInBurst_PR_mediumBitmap;
6577
6578    /* As per spec 38.331,in the definition of ServingCellConfigCommon */
6579    bitStringSizeInBytes = 1;
6580    ssbPosInBurst->choice.mediumBitmap.size = bitStringSizeInBytes * sizeof(uint8_t);
6581
6582    DU_ALLOC(ssbPosInBurst->choice.mediumBitmap.buf, ssbPosInBurst->choice.mediumBitmap.size);
6583    if(!ssbPosInBurst->choice.mediumBitmap.buf)
6584    {
6585       DU_LOG("\nERROR  -->  DU APP : Memory Allocation failed for medium bit map buffer in BuildSsbPosInBurst()");
6586       return RFAILED;
6587    }
6588
6589    if((fillBitString(&ssbPosInBurst->choice.mediumBitmap, 0, bitStringSizeInBytes, \
6590                duCfgParam.sib1Params.srvCellCfgCommSib.ssbPosInBurst)) != ROK)
6591    {
6592       DU_LOG("\nERROR  -->  DU APP : Failed to fill medium bit map in BuildSsbPosInBurst()");
6593       return RFAILED;
6594    }
6595
6596    return ROK;
6597 }
6598
6599 /*******************************************************************
6600  *
6601  * @brief Fills SP cell config common in Reconfig with Sync
6602  *
6603  * @details
6604  *
6605  *    Function : BuildSpCellConfigCommon
6606  *
6607  *    Functionality: Fills SP cell config common in Reconfig with Sync
6608  *
6609  * @params[in] Pointer to ServingCellConfigCommon_t
6610  *
6611  * @return ROK     - success
6612  *         RFAILED - failure
6613  *
6614  * ****************************************************************/
6615 uint8_t BuildSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
6616 {
6617    /* Physical Cell Identity */
6618    DU_ALLOC(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
6619    if(!spCellConfigCommon->physCellId)
6620    {
6621       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for physical cell id in BuildSpCellConfigCommon()");
6622       return RFAILED;
6623    } 
6624    *(spCellConfigCommon->physCellId) = NR_PCI;
6625
6626    /* Downlink Config Common */
6627    DU_ALLOC(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
6628    if(!spCellConfigCommon->downlinkConfigCommon)
6629    {
6630       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for DL Config Common in BuildSpCellConfigCommon()");
6631       return RFAILED;
6632    }
6633    if((BuildDlConfigCommon(spCellConfigCommon->downlinkConfigCommon)) != ROK)
6634    {
6635       DU_LOG("\nERROR  -->  DU APP : Failed to fill DL config commin in BuildSpCellConfigCommon()");
6636       return RFAILED;
6637    }
6638
6639    /* Uplinlink Config Common */
6640    DU_ALLOC(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
6641    if(!spCellConfigCommon->uplinkConfigCommon)
6642    {
6643       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for UL Config Common in BuildSpCellConfigCommon()");
6644       return RFAILED;
6645    }
6646    if((BuildUlConfigCommon(spCellConfigCommon->uplinkConfigCommon)) != ROK)
6647    {
6648       DU_LOG("\nERROR  -->  DU APP : Failed to fill UL config commin in BuildSpCellConfigCommon()");
6649       return RFAILED;
6650    }
6651
6652    /* Timing Advance offset */
6653    DU_ALLOC(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
6654    if(!spCellConfigCommon->n_TimingAdvanceOffset)
6655    {
6656       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for Timing Advance Offset in BuildSpCellConfigCommon()");
6657       return RFAILED;
6658    }
6659    *(spCellConfigCommon->n_TimingAdvanceOffset) = ServingCellConfigCommon__n_TimingAdvanceOffset_n0;
6660
6661    /* SSB Position In Burst */
6662    DU_ALLOC(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
6663    if(!spCellConfigCommon->ssb_PositionsInBurst)
6664    {
6665       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Position In Burst in BuildSpCellConfigCommon()");
6666       return RFAILED;
6667    }
6668    if((BuildSsbPosInBurst(spCellConfigCommon->ssb_PositionsInBurst)) != ROK)
6669    {
6670       DU_LOG("\nERROR  -->  DU APP : Failed to fill SSB Position In Burst in BuildSpCellConfigCommon()");
6671       return RFAILED;
6672    }
6673
6674    /* SSB Periodicity in Serving cell */
6675    DU_ALLOC(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
6676    if(!spCellConfigCommon->ssb_periodicityServingCell)
6677    {
6678       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for SSB Periodicity serving cell in \
6679          BuildSpCellConfigCommon()");
6680       return RFAILED;
6681    }
6682    *(spCellConfigCommon->ssb_periodicityServingCell) = \
6683       convertSsbPeriodicityValueToEnum(duCfgParam.sib1Params.srvCellCfgCommSib.ssbPrdServingCell);
6684
6685    /* DMRS Type A position */
6686    spCellConfigCommon->dmrs_TypeA_Position = convertDmrsTypeAPosValueToEnum(duCfgParam.macCellCfg.dmrsTypeAPos);
6687
6688    /* SSB subcarrier spacing */
6689    DU_ALLOC(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
6690    if(!spCellConfigCommon->ssbSubcarrierSpacing)
6691    {
6692       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for sub-carrier spacing in BuildSpCellConfigCommon()");
6693       return RFAILED;
6694    }
6695    *(spCellConfigCommon->ssbSubcarrierSpacing) = duCfgParam.sib1Params.srvCellCfgCommSib.scs;
6696
6697    /* TDD UL-DL configuration common */
6698    DU_ALLOC(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
6699    if(!spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)
6700    {
6701       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for TDD UL-DL config common in BuildSpCellConfigCommon()");
6702       return RFAILED;
6703    }
6704    if((BuildTddUlDlCfgComm(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon)) != ROK)
6705    {
6706       DU_LOG("\nERROR  -->  DU APP : Failed to fill TDD UL-DL config common in BuildSpCellConfigCommon()");
6707       return RFAILED;
6708    }
6709
6710    /* SS PBCH Block Power */
6711    spCellConfigCommon->ss_PBCH_BlockPower = duCfgParam.sib1Params.srvCellCfgCommSib.ssPbchBlockPwr;
6712
6713    return ROK;
6714 }
6715
6716 /*******************************************************************
6717  *
6718  * @brief Fills dedicated RACH configuration in Reconfiguration with sync
6719  *
6720  * @details
6721  *
6722  *    Function : BuildRecfgWithSync
6723  *
6724  *    Functionality: 
6725  *       Fills dedicated RACH configuration in Reconfiguration with sync
6726  *
6727  * @params[in] DU UE CB
6728  *             Pointer to Rach config dedicated struct
6729  *
6730  * @return ROK     - success
6731  *         RFAILED - failure
6732  *
6733  * ****************************************************************/
6734 uint8_t BuildRachConfigDedicated(DuUeCb *ueCb, struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
6735 {
6736    uint8_t elementCnt = 0, listIdx = 0;
6737    CFRA_t *cfra = NULLP;
6738    struct CFRA__resources__ssb *ssbResource = NULLP;
6739    RachCfgCommon duRachCfg = duCfgParam.sib1Params.srvCellCfgCommSib.ulCfg.rachCfg;
6740
6741    rachCfgDed->present = ReconfigurationWithSync__rach_ConfigDedicated_PR_uplink;
6742
6743    /* Uplink */
6744    DU_ALLOC(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
6745    if(!rachCfgDed->choice.uplink)
6746    {
6747       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for RACH uplink configuration in BuildRachConfigDedicated()");
6748       return RFAILED;
6749    }
6750
6751    /* CFRA : Contention free Random Access */
6752    DU_ALLOC(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
6753    if(!rachCfgDed->choice.uplink->cfra)
6754    {
6755       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA in BuildRachConfigDedicated()");
6756       return RFAILED;
6757    }
6758    cfra = rachCfgDed->choice.uplink->cfra;
6759
6760    /* CFRA occassions */
6761    DU_ALLOC(cfra->occasions, sizeof(struct CFRA__occasions));
6762    if(!cfra->occasions)
6763    {
6764       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA occassion in BuildRachConfigDedicated()");
6765       return RFAILED;
6766    }
6767
6768    /* CFRA occassions : RACH generic configuration */
6769    cfra->occasions->rach_ConfigGeneric.prach_ConfigurationIndex = duRachCfg.prachCfgIdx;
6770    cfra->occasions->rach_ConfigGeneric.msg1_FDM = duRachCfg.msg1Fdm;
6771    cfra->occasions->rach_ConfigGeneric.msg1_FrequencyStart = duRachCfg.msg1FreqStart;
6772    cfra->occasions->rach_ConfigGeneric.zeroCorrelationZoneConfig = duRachCfg.zeroCorrZoneCfg;
6773    cfra->occasions->rach_ConfigGeneric.preambleReceivedTargetPower = duRachCfg.preambleRcvdTgtPwr;
6774    cfra->occasions->rach_ConfigGeneric.preambleTransMax = duRachCfg.preambleTransMax;
6775    cfra->occasions->rach_ConfigGeneric.powerRampingStep = duRachCfg.pwrRampingStep;
6776    cfra->occasions->rach_ConfigGeneric.ra_ResponseWindow = duRachCfg.raRspWindow;
6777
6778    /* CFRA occassions : SSB per RACH occasion */
6779    DU_ALLOC(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
6780    if(!cfra->occasions->ssb_perRACH_Occasion)
6781    {
6782       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB per RACH occassion in BuildRachConfigDedicated()");
6783       return RFAILED;
6784    }
6785    *(cfra->occasions->ssb_perRACH_Occasion) = convertCFRASsbPerRachOccasionValueToEnum(duCfgParam.macCellCfg.prachCfg.ssbPerRach);
6786
6787    /* CFRA resource */
6788    cfra->resources.present = CFRA__resources_PR_ssb;
6789
6790    /* CFRA resource : SSB */
6791    DU_ALLOC(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
6792    if(!cfra->resources.choice.ssb)
6793    {
6794       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for CFRA resource - SSB in BuildRachConfigDedicated()");
6795       return RFAILED;
6796    }
6797    ssbResource = cfra->resources.choice.ssb;
6798
6799    /* CFRA SSB resource list */
6800    elementCnt = ueCb->cfraResource.numSsb;
6801    ssbResource->ssb_ResourceList.list.count = elementCnt;
6802    ssbResource->ssb_ResourceList.list.size = elementCnt * sizeof(CFRA_SSB_Resource_t *);
6803
6804    DU_ALLOC(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
6805    if(!ssbResource->ssb_ResourceList.list.array)
6806    {
6807       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list in BuildRachConfigDedicated()");
6808       return RFAILED;
6809    }
6810
6811    for(listIdx = 0; listIdx < elementCnt; listIdx++)
6812    {
6813       DU_ALLOC(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
6814       if(!ssbResource->ssb_ResourceList.list.array[listIdx])
6815       {
6816          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for SSB resource list element in BuildRachConfigDedicated()");  
6817          return RFAILED;
6818       }
6819       ssbResource->ssb_ResourceList.list.array[listIdx]->ssb = ueCb->cfraResource.ssbResource[listIdx].ssbIdx;
6820       ssbResource->ssb_ResourceList.list.array[listIdx]->ra_PreambleIndex = ueCb->cfraResource.ssbResource[listIdx].raPreambleIdx;
6821    }
6822
6823    return ROK;
6824 }
6825
6826 /*******************************************************************
6827  *
6828  * @brief Fills reconfiguration with sync in SP cell config
6829  *
6830  * @details
6831  *
6832  *    Function : BuildRecfgWithSync
6833  *
6834  *    Functionality: Fills reconfiguration with sync in SP cell config
6835  *
6836  * @params[in] DU UE CB
6837  *             Pointer to ReconfigurationWithSync_t
6838  *
6839  * @return ROK     - success
6840  *         RFAILED - failure
6841  *
6842  * ****************************************************************/
6843 uint8_t BuildRecfgWithSync(DuUeCb *ueCb, ReconfigurationWithSync_t *recfgWithSync)
6844 {
6845    /* SP Cell Config Common */  
6846    DU_ALLOC(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
6847    if(!recfgWithSync->spCellConfigCommon)
6848    {
6849       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for spCellConfigCommon in BuildRecfgWithSync()");
6850       return RFAILED;
6851    }
6852
6853    if((BuildSpCellConfigCommon(recfgWithSync->spCellConfigCommon)) != ROK)
6854    {
6855       DU_LOG("\nERROR  -->  DU APP : Failed to build SpCellConfigCommon in BuildRecfgWithSync()");
6856       return RFAILED;
6857    }
6858
6859    /* New UE Identity */
6860    recfgWithSync->newUE_Identity = ueCb->crnti;
6861
6862    /* T304 timer */
6863    recfgWithSync->t304 = ReconfigurationWithSync__t304_ms1000;
6864
6865    /* RACH configuration dedicated */
6866    DU_ALLOC(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
6867    if(!recfgWithSync->rach_ConfigDedicated)
6868    {
6869       DU_LOG("\nERROR  -->  DU APP : Failed to allocate memory for RACH config dedicated in BuildRecfgWithSync()");
6870       return RFAILED;
6871    }
6872
6873    if((BuildRachConfigDedicated(ueCb, recfgWithSync->rach_ConfigDedicated)) != ROK)
6874    {
6875       DU_LOG("\nERROR  -->  DU APP : Failed to build RACH config dedicated in BuildRecfgWithSync()");
6876       return RFAILED;
6877    }
6878
6879    return ROK;
6880 }
6881
6882 /*******************************************************************
6883  *
6884  * @brief Builds Spcell config 
6885  *
6886  * @details
6887  *
6888  *    Function : BuildSpCellCfg 
6889  *
6890  *    Functionality: Builds sp cell config in DuToCuRrcContainer
6891  *
6892  * @params[in] SpCellConfig_t spCellCfg
6893  *
6894  * @return ROK     - success
6895  *         RFAILED - failure
6896  *
6897  * ****************************************************************/
6898 uint8_t BuildSpCellCfg(DuUeCb *ueCb, SpCellConfig_t *spCellCfg)
6899 {
6900    spCellCfg->servCellIndex = NULLP;
6901    DU_ALLOC(spCellCfg->servCellIndex, sizeof(long));
6902    if(!spCellCfg->servCellIndex)
6903    {
6904       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6905       return RFAILED;
6906    }
6907
6908    if(ueCb == NULLP)
6909       *(spCellCfg->servCellIndex) = SERV_CELL_IDX;
6910    else
6911       *(spCellCfg->servCellIndex) = ueCb->macUeCfg.spCellCfg.servCellIdx;
6912
6913    spCellCfg->reconfigurationWithSync = NULLP;
6914    if(ueCb && (ueCb->ueState == UE_HANDIN_IN_PROGRESS))
6915    {
6916       DU_ALLOC(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
6917       if(!spCellCfg->reconfigurationWithSync)
6918       {
6919          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6920          return RFAILED;
6921       }
6922
6923       if((BuildRecfgWithSync(ueCb, spCellCfg->reconfigurationWithSync)) != ROK)
6924       {
6925          DU_LOG("\nERROR  -->  F1AP : Building of reconfiguration with sync failed at BuildSpCellCfg");
6926          return RFAILED;
6927       }
6928    }
6929
6930    spCellCfg->rlf_TimersAndConstants = NULLP;
6931    spCellCfg->rlmInSyncOutOfSyncThreshold = NULLP;
6932
6933    DU_ALLOC(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
6934    if(!spCellCfg->rlmInSyncOutOfSyncThreshold)
6935    {
6936       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6937       return RFAILED;
6938    }
6939    *(spCellCfg->rlmInSyncOutOfSyncThreshold) = RLM_SYNC_OUT_SYNC_THRESHOLD;
6940
6941    spCellCfg->spCellConfigDedicated = NULLP;
6942    DU_ALLOC(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
6943    if(!spCellCfg->spCellConfigDedicated)
6944    {
6945       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildSpCellCfg");
6946       return RFAILED;
6947    }
6948    if(BuildSpCellCfgDed(ueCb, spCellCfg->spCellConfigDedicated) != ROK)
6949    {
6950       DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfgDed failed");
6951       return RFAILED;
6952    }
6953
6954    return ROK;
6955 }
6956
6957 /*******************************************************************
6958  *
6959  * @brief Builds Phy cell group config 
6960  *
6961  * @details
6962  *
6963  *    Function : BuildPhyCellGrpCfg 
6964  *
6965  *    Functionality: Builds Phy cell group config in DuToCuRrcContainer
6966  *
6967  * @params[in] PhysicalCellGroupConfig_t *phyCellGrpCfg 
6968  *
6969  * @return ROK     - success
6970  *         RFAILED - failure
6971  *
6972  * ****************************************************************/
6973 uint8_t BuildPhyCellGrpCfg(DuUeCb *ueCb, PhysicalCellGroupConfig_t *phyCellGrpCfg)
6974 {
6975    phyCellGrpCfg->harq_ACK_SpatialBundlingPUCCH = NULLP;
6976    phyCellGrpCfg->harq_ACK_SpatialBundlingPUSCH = NULLP;
6977
6978    phyCellGrpCfg->p_NR_FR1 = NULLP;
6979    DU_ALLOC(phyCellGrpCfg->p_NR_FR1, sizeof(long));
6980    if(!phyCellGrpCfg->p_NR_FR1)
6981    {
6982       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildPhyCellGrpCfg");
6983       return RFAILED;
6984    }
6985
6986    if(ueCb == NULLP)
6987    {
6988       *(phyCellGrpCfg->p_NR_FR1)             = P_NR_FR1;
6989       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = PDSCH_HARQ_ACK_CODEBOOK;
6990    }
6991    else
6992    {
6993       *(phyCellGrpCfg->p_NR_FR1) = ueCb->macUeCfg.phyCellGrpCfg.pNrFr1;
6994       phyCellGrpCfg->pdsch_HARQ_ACK_Codebook = ueCb->macUeCfg.phyCellGrpCfg.pdschHarqAckCodebook;
6995    }
6996
6997    phyCellGrpCfg->tpc_SRS_RNTI = NULLP;
6998    phyCellGrpCfg->tpc_PUCCH_RNTI = NULLP;
6999    phyCellGrpCfg->tpc_PUSCH_RNTI = NULLP;
7000    phyCellGrpCfg->sp_CSI_RNTI = NULLP;
7001    phyCellGrpCfg->cs_RNTI = NULLP;
7002    phyCellGrpCfg->ext1 = NULLP;
7003    phyCellGrpCfg->ext2 = NULLP;
7004
7005    return ROK;
7006 }
7007
7008 /*******************************************************************
7009  *
7010  * @brief Builds Mac cell group config 
7011  *
7012  * @details
7013  *
7014  *    Function : BuildMacCellGrpCfg 
7015  *
7016  *    Functionality: Builds Mac cell group config in DuToCuRrcContainer
7017  *
7018  * @params[in] MAC_CellGroupConfig_t *macCellGrpCfg
7019  *
7020  * @return ROK     - success
7021  *         RFAILED - failure
7022  *
7023  * ****************************************************************/
7024 uint8_t BuildMacCellGrpCfg(DuUeCb *ueCb, MAC_CellGroupConfig_t *macCellGrpCfg)
7025 {
7026    macCellGrpCfg->drx_Config = NULLP;
7027    macCellGrpCfg->schedulingRequestConfig = NULLP;
7028    DU_ALLOC(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
7029    if(!macCellGrpCfg->schedulingRequestConfig)
7030    {
7031       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7032       return RFAILED;
7033    }
7034
7035    if(BuildSchedulingReqConfig(ueCb, macCellGrpCfg->schedulingRequestConfig) != ROK)
7036    {
7037       DU_LOG("\nERROR  -->  F1AP : BuildSchedulingReqConfig failed");
7038       return RFAILED;
7039    }
7040
7041    macCellGrpCfg->bsr_Config = NULLP;
7042    DU_ALLOC(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
7043    if(!macCellGrpCfg->bsr_Config)
7044    {
7045       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7046       return RFAILED;
7047    }
7048
7049    if(BuildBsrConfig(ueCb, macCellGrpCfg->bsr_Config) != ROK)
7050    {
7051       DU_LOG("\nERROR  -->  F1AP : BuildBsrConfig failed");
7052       return RFAILED;
7053    }
7054
7055    macCellGrpCfg->tag_Config = NULLP;
7056    DU_ALLOC(macCellGrpCfg->tag_Config, sizeof(struct TAG_Config));
7057    if(!macCellGrpCfg->tag_Config)
7058    {
7059       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7060       return RFAILED;
7061    }
7062
7063    if(BuildTagConfig(ueCb, macCellGrpCfg->tag_Config) != ROK)
7064    {
7065       DU_LOG("\nERROR  -->  F1AP : BuildTagConfig failed");
7066       return RFAILED;
7067    }
7068
7069    macCellGrpCfg->phr_Config = NULLP;
7070    DU_ALLOC(macCellGrpCfg->phr_Config, sizeof(struct MAC_CellGroupConfig__phr_Config));
7071    if(!macCellGrpCfg->phr_Config)
7072    {
7073       DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildMacCellGrpCfg");
7074       return RFAILED;
7075    }
7076
7077    if(BuildPhrConfig(ueCb, macCellGrpCfg->phr_Config) != ROK)
7078    {
7079       DU_LOG("\nERROR  -->  F1AP : BuildPhrConfig failed");
7080       return RFAILED;
7081    }
7082
7083    macCellGrpCfg->skipUplinkTxDynamic = false;
7084    macCellGrpCfg->ext1 = NULLP;
7085
7086    return ROK;
7087 }
7088 /*******************************************************************
7089  *
7090  * @brief Frees memeory allocated for SearchSpcToAddModList
7091  *
7092  * @details
7093  *
7094  *    Function : FreeSearchSpcToAddModList
7095  *
7096  *    Functionality: Deallocating memory of SearchSpcToAddModList
7097  *
7098  * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
7099  *
7100  * @return void
7101  *
7102  4221 * ****************************************************************/
7103 void FreeSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
7104 {
7105    uint8_t idx1=0;
7106    uint8_t idx2=0;
7107    struct  SearchSpace *searchSpc=NULLP;
7108
7109    if(searchSpcList->list.array)
7110    {
7111       if(searchSpcList->list.array[idx2])
7112       {
7113          searchSpc = searchSpcList->list.array[idx2];
7114          if(searchSpc->controlResourceSetId)
7115          {
7116             if(searchSpc->monitoringSlotPeriodicityAndOffset)
7117             {
7118                if(searchSpc->monitoringSymbolsWithinSlot)
7119                {
7120                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
7121                   {
7122                      if(searchSpc->nrofCandidates)
7123                      {
7124                         if(searchSpc->searchSpaceType)
7125                         {
7126                            DU_FREE(searchSpc->searchSpaceType->choice.ue_Specific,\
7127                                  sizeof(struct SearchSpace__searchSpaceType__ue_Specific));
7128                            DU_FREE(searchSpc->searchSpaceType, sizeof(struct
7129                                     SearchSpace__searchSpaceType));
7130                         }
7131                         DU_FREE(searchSpc->nrofCandidates,
7132                               sizeof(struct SearchSpace__nrofCandidates));
7133                      }
7134                      DU_FREE(searchSpc->monitoringSymbolsWithinSlot->buf, \
7135                            searchSpc->monitoringSymbolsWithinSlot->size);
7136                   }
7137                   DU_FREE(searchSpc->monitoringSymbolsWithinSlot,
7138                         sizeof(BIT_STRING_t));
7139                }
7140                DU_FREE(searchSpc->monitoringSlotPeriodicityAndOffset, \
7141                      sizeof(struct SearchSpace__monitoringSlotPeriodicityAndOffset));
7142             }
7143             DU_FREE(searchSpc->controlResourceSetId,
7144                   sizeof(ControlResourceSetId_t));
7145          }
7146       }
7147       for(idx1 = 0; idx1 < searchSpcList->list.count; idx1++)
7148       {
7149          DU_FREE(searchSpcList->list.array[idx1],
7150                sizeof(struct SearchSpace));
7151       }
7152       DU_FREE(searchSpcList->list.array,searchSpcList->list.size);
7153    }
7154 }
7155 /*******************************************************************
7156  *
7157  * @brief Frees memory allocated for PdschTimeDomAllocList
7158  *
7159  * @details
7160  *
7161  *    Function : FreePdschTimeDomAllocList
7162  *
7163  *    Functionality: Deallocating memory of PdschTimeDomAllocList
7164  *
7165  * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList
7166  *
7167  * @return void
7168  *
7169  * ****************************************************************/
7170 void FreePdschTimeDomAllocList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
7171 {
7172    uint8_t idx1=0;
7173
7174    if(timeDomAllocList->choice.setup)
7175    {
7176       if(timeDomAllocList->choice.setup->list.array)
7177       {
7178          for(idx1 = 0; idx1 <timeDomAllocList->choice.setup->list.count ; idx1++)
7179          {
7180             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1]->k0, sizeof(long));
7181             DU_FREE(timeDomAllocList->choice.setup->list.array[idx1],
7182                   sizeof(struct PDSCH_TimeDomainResourceAllocation));
7183          }
7184          DU_FREE(timeDomAllocList->choice.setup->list.array, \
7185                timeDomAllocList->choice.setup->list.size);
7186       }
7187       DU_FREE(timeDomAllocList->choice.setup,\
7188             sizeof(struct PDSCH_TimeDomainResourceAllocationList));
7189    }
7190 }
7191 /*******************************************************************
7192  *
7193  * @brief Frees memory allocated for PuschTimeDomAllocList
7194  *
7195  *@details
7196  *
7197  *    Function : FreePuschTimeDomAllocList
7198  *
7199  *    Functionality: Deallocating memory of PuschTimeDomAllocList
7200  *
7201  * @params[in] PUSCH_Config_t *puschCfg
7202  *
7203  * @return void
7204  *
7205  * ****************************************************************/
7206 void FreePuschTimeDomAllocList(PUSCH_Config_t *puschCfg)
7207 {
7208    uint8_t rsrcListIdx=0;
7209    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
7210
7211    if(puschCfg->pusch_TimeDomainAllocationList)
7212    {
7213       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
7214       if(timeDomAllocList_t->choice.setup)
7215       {
7216          if(timeDomAllocList_t->choice.setup->list.array)
7217          {
7218             for(rsrcListIdx = 0; rsrcListIdx<timeDomAllocList_t->choice.setup->list.count; rsrcListIdx++)
7219             {
7220                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx]->k2, sizeof(long));
7221                DU_FREE(timeDomAllocList_t->choice.setup->list.array[rsrcListIdx],\
7222                      sizeof(PUSCH_TimeDomainResourceAllocation_t));
7223             }
7224             DU_FREE(timeDomAllocList_t->choice.setup->list.array, \
7225                   timeDomAllocList_t->choice.setup->list.size);
7226          }
7227          DU_FREE(timeDomAllocList_t->choice.setup, \
7228                sizeof(struct PUSCH_TimeDomainResourceAllocationList));
7229       }
7230       DU_FREE(puschCfg->transformPrecoder, sizeof(long));
7231       DU_FREE(puschCfg->pusch_TimeDomainAllocationList, \
7232             sizeof(struct PUSCH_Config__pusch_TimeDomainAllocationList));
7233    }
7234
7235 }
7236
7237 /*******************************************************************
7238  *
7239  * @brief Frees memory allocated for Dedicated PUCCH config
7240  *
7241  * @details
7242  *
7243  *    Function : FreeBWPUlDedPucchCfg
7244  *
7245  *    Functionality: Deallocating memory of Dedicated PUCCH cfg
7246  *
7247  * @params[in] BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg
7248  *
7249  * @return void
7250  *
7251  * ****************************************************************/
7252 void FreeBWPUlDedPucchCfg(struct BWP_UplinkDedicated__pucch_Config *ulBwpPucchCfg)
7253 {
7254    uint8_t k1Idx, rsrcIdx, rsrcSetIdx;
7255    PUCCH_Config_t *pucchCfg = NULLP;
7256    PUCCH_ResourceSet_t *rsrcSet = NULLP;
7257    PUCCH_Resource_t *rsrc = NULLP;
7258
7259    if(ulBwpPucchCfg)
7260    {
7261       if(ulBwpPucchCfg->choice.setup)
7262       {
7263          pucchCfg = ulBwpPucchCfg->choice.setup;
7264
7265          //Free resource set list
7266          if(pucchCfg->resourceSetToAddModList)
7267          {
7268             if(pucchCfg->resourceSetToAddModList->list.array)
7269             {
7270                for(rsrcSetIdx=0; rsrcSetIdx < pucchCfg->resourceSetToAddModList->list.count; rsrcSetIdx++)
7271                {
7272                   rsrcSet = pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx];
7273                   if(rsrcSet->resourceList.list.array)
7274                   {
7275                      for(rsrcIdx=0; rsrcIdx < rsrcSet->resourceList.list.count; rsrcIdx++)
7276                      {
7277                         DU_FREE(rsrcSet->resourceList.list.array[rsrcIdx], sizeof(PUCCH_ResourceId_t));
7278                      }
7279                      DU_FREE(rsrcSet->resourceList.list.array, rsrcSet->resourceList.list.size);
7280                   }
7281                   DU_FREE(pucchCfg->resourceSetToAddModList->list.array[rsrcSetIdx], sizeof(PUCCH_ResourceSet_t));
7282                }
7283                DU_FREE(pucchCfg->resourceSetToAddModList->list.array, pucchCfg->resourceSetToAddModList->list.size);
7284             }
7285             DU_FREE(pucchCfg->resourceSetToAddModList, sizeof(struct PUCCH_Config__resourceSetToAddModList));
7286          }
7287
7288          //Free resource list
7289          if(pucchCfg->resourceToAddModList)
7290          {
7291             if(pucchCfg->resourceToAddModList->list.array)
7292             {
7293                for(rsrcIdx=0; rsrcIdx < pucchCfg->resourceToAddModList->list.count; rsrcIdx++)
7294                {
7295                   rsrc = pucchCfg->resourceToAddModList->list.array[rsrcIdx];
7296                   DU_FREE(rsrc->format.choice.format1, sizeof(PUCCH_format1_t));
7297                   DU_FREE(pucchCfg->resourceToAddModList->list.array[rsrcIdx], sizeof(PUCCH_Resource_t));
7298                }
7299                DU_FREE(pucchCfg->resourceToAddModList->list.array, pucchCfg->resourceToAddModList->list.size);
7300             }
7301             DU_FREE(pucchCfg->resourceToAddModList, sizeof(struct PUCCH_Config__resourceToAddModList));
7302          }
7303
7304          //PUCCH Format 1
7305          if(pucchCfg->format1)
7306          {
7307             if(pucchCfg->format1->choice.setup)
7308             {
7309                DU_FREE(pucchCfg->format1->choice.setup->nrofSlots, sizeof(long));
7310                DU_FREE(pucchCfg->format1->choice.setup, sizeof(PUCCH_FormatConfig_t));
7311             }
7312             DU_FREE(pucchCfg->format1, sizeof(struct PUCCH_Config__format1));
7313          }
7314          
7315          //DL DATA TO UL ACK
7316          if(pucchCfg->dl_DataToUL_ACK)
7317          {
7318             if(pucchCfg->dl_DataToUL_ACK->list.array)
7319             {
7320                for(k1Idx = 0; k1Idx <  pucchCfg->dl_DataToUL_ACK->list.count; k1Idx++)
7321                {
7322                   DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array[k1Idx], sizeof(long));
7323                }
7324                DU_FREE(pucchCfg->dl_DataToUL_ACK->list.array, pucchCfg->dl_DataToUL_ACK->list.size);
7325             }
7326             DU_FREE(pucchCfg->dl_DataToUL_ACK, sizeof(struct PUCCH_Config__dl_DataToUL_ACK));
7327          }
7328
7329          DU_FREE(ulBwpPucchCfg->choice.setup, sizeof(PUCCH_Config_t));
7330       }
7331       DU_FREE(ulBwpPucchCfg, sizeof(struct BWP_UplinkDedicated__pucch_Config));
7332    }
7333 }
7334
7335 /*******************************************************************
7336  *
7337  * @brief Frees memory allocated for InitialUlBWP
7338  *
7339  * @details
7340  *
7341  *    Function : FreeInitialUlBWP
7342  *
7343  *    Functionality: Deallocating memory of InitialUlBWP
7344  *
7345  * @params[in] BWP_UplinkDedicated_t *ulBwp
7346  *
7347  * @return void
7348  *
7349  * ****************************************************************/
7350 void FreeInitialUlBWP(BWP_UplinkDedicated_t *ulBwp)
7351 {
7352    uint8_t  rSetIdx, rsrcIdx;
7353    SRS_Config_t   *srsCfg = NULLP;
7354    PUSCH_Config_t *puschCfg = NULLP;
7355    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
7356    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
7357    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
7358    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
7359
7360    FreeBWPUlDedPucchCfg(ulBwp->pucch_Config);
7361
7362    if(ulBwp->pusch_Config)
7363    {
7364       if(ulBwp->pusch_Config->choice.setup)
7365       {
7366          puschCfg=ulBwp->pusch_Config->choice.setup;
7367          if(puschCfg->dataScramblingIdentityPUSCH)
7368          {
7369             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
7370             {
7371                FreePuschTimeDomAllocList(puschCfg);
7372                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
7373                if(dmrsUlCfg->choice.setup)
7374                {
7375                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
7376                   {
7377                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
7378                      {
7379                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0,\
7380                               sizeof(long));
7381                         DU_FREE(dmrsUlCfg->choice.setup->transformPrecodingDisabled,
7382                               sizeof(struct DMRS_UplinkConfig__transformPrecodingDisabled));
7383                      }
7384                      DU_FREE(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition,
7385                            sizeof(long));
7386                   }
7387                   DU_FREE(dmrsUlCfg->choice.setup,sizeof(DMRS_UplinkConfig_t));
7388                }
7389                DU_FREE(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA, \
7390                      sizeof(struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA));
7391             }
7392             DU_FREE(puschCfg->dataScramblingIdentityPUSCH, sizeof(long));
7393          }
7394          DU_FREE(ulBwp->pusch_Config->choice.setup, sizeof(PUSCH_Config_t));
7395       }
7396       DU_FREE(ulBwp->pusch_Config, sizeof(struct BWP_UplinkDedicated__pusch_Config));
7397
7398       /* Free SRS-Config */
7399       if(ulBwp->srs_Config)
7400       {
7401          if(ulBwp->srs_Config->choice.setup)
7402          {
7403             srsCfg = ulBwp->srs_Config->choice.setup;
7404
7405             /* Free Resource Set to add/mod list */
7406             if(srsCfg->srs_ResourceSetToAddModList)
7407             {
7408                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
7409                if(rsrcSetList->list.array)
7410                {
7411                   rSetIdx = 0;
7412
7413                   /* Free SRS resource Id list in this SRS resource set */
7414                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
7415                   {
7416                      rsrcIdList = rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
7417
7418                      if(rsrcIdList->list.array)
7419                      {
7420                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count; rsrcIdx++)
7421                         {
7422                            DU_FREE(rsrcIdList->list.array[rsrcIdx], sizeof(SRS_ResourceId_t));
7423                         }
7424                         DU_FREE(rsrcIdList->list.array, rsrcIdList->list.size);
7425                      }
7426                      DU_FREE(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList,\
7427                            sizeof(struct SRS_ResourceSet__srs_ResourceIdList));
7428                   }
7429
7430                   /* Free resource type info for this SRS resource set */
7431                   DU_FREE(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic, \
7432                         sizeof(struct SRS_ResourceSet__resourceType__aperiodic));
7433
7434                   /* Free memory for each resource set */
7435                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
7436                   {
7437                      DU_FREE(rsrcSetList->list.array[rSetIdx], sizeof(SRS_ResourceSet_t));
7438                   }
7439                   DU_FREE(rsrcSetList->list.array, rsrcSetList->list.size); 
7440                }
7441                DU_FREE(srsCfg->srs_ResourceSetToAddModList, \
7442                      sizeof(struct SRS_Config__srs_ResourceSetToAddModList));
7443             }
7444
7445             /* Free resource to add/modd list */
7446             if(srsCfg->srs_ResourceToAddModList)
7447             {
7448                resourceList = srsCfg->srs_ResourceToAddModList;
7449                if(resourceList->list.array)
7450                {
7451                   rsrcIdx = 0;
7452                   DU_FREE(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2,\
7453                         sizeof(struct SRS_Resource__transmissionComb__n2));
7454                   DU_FREE(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic,\
7455                         sizeof(struct SRS_Resource__resourceType__aperiodic));
7456
7457                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
7458                   {
7459                      DU_FREE(resourceList->list.array[rsrcIdx], sizeof(SRS_Resource_t));
7460                   }
7461                   DU_FREE(resourceList->list.array, resourceList->list.size);
7462                }
7463                DU_FREE(srsCfg->srs_ResourceToAddModList, \
7464                      sizeof(struct SRS_Config__srs_ResourceToAddModList));
7465             }
7466
7467             DU_FREE(ulBwp->srs_Config->choice.setup, sizeof(SRS_Config_t));
7468          }
7469          DU_FREE(ulBwp->srs_Config, sizeof(struct BWP_UplinkDedicated__srs_Config));
7470       }
7471    }
7472 }       
7473 /*******************************************************************
7474  *
7475  * @brief Frees memory allocated for initialUplinkBWP
7476  *
7477  * @details
7478  *
7479  *    Function : FreeinitialUplinkBWP
7480  *
7481  *    Functionality: Deallocating memory of initialUplinkBWP
7482  *
7483  * @params[in] UplinkConfig_t *ulCfg
7484  *
7485  * @return void
7486  *         
7487  *
7488  * ****************************************************************/
7489 void FreeinitialUplinkBWP(UplinkConfig_t *ulCfg)
7490 {
7491    BWP_UplinkDedicated_t *ulBwp=NULLP; 
7492    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
7493
7494    if(ulCfg->initialUplinkBWP)
7495    {
7496       ulBwp=ulCfg->initialUplinkBWP;
7497       if(ulCfg->firstActiveUplinkBWP_Id)
7498       {
7499          if(ulCfg->pusch_ServingCellConfig)
7500          {
7501             puschCfg=ulCfg->pusch_ServingCellConfig;
7502             if(puschCfg->choice.setup)
7503             {
7504                if(puschCfg->choice.setup->ext1)
7505                {
7506                   DU_FREE(puschCfg->choice.setup->ext1->\
7507                         processingType2Enabled,sizeof(BOOLEAN_t));
7508                   DU_FREE(puschCfg->choice.setup->ext1->\
7509                         maxMIMO_Layers,sizeof(long));
7510                   DU_FREE(puschCfg->choice.setup->ext1, \
7511                         sizeof(struct PUSCH_ServingCellConfig__ext1));
7512                }
7513                DU_FREE(puschCfg->choice.setup, sizeof(struct PUSCH_ServingCellConfig));
7514             }
7515             DU_FREE(ulCfg->pusch_ServingCellConfig, sizeof(struct UplinkConfig__pusch_ServingCellConfig));
7516          }
7517          DU_FREE(ulCfg->firstActiveUplinkBWP_Id, sizeof(BWP_Id_t));
7518       }
7519       FreeInitialUlBWP(ulBwp);
7520       DU_FREE(ulCfg->initialUplinkBWP, sizeof(BWP_UplinkDedicated_t));
7521    }
7522 }
7523 /*******************************************************************
7524  *
7525  * @brief Frees emmory allocated for BWPDlDedPdschCfg
7526  *
7527  * @details
7528  *
7529  *    Function : FreeBWPDlDedPdschCfg
7530  *
7531  *    Functionality: Deallocating memory of BWPDlDedPdschCfg
7532  *
7533  * @params[in] BWP_DownlinkDedicated_t *dlBwp
7534  *
7535  * @return void
7536  *
7537  *
7538  * ****************************************************************/
7539 void FreeBWPDlDedPdschCfg(BWP_DownlinkDedicated_t *dlBwp)
7540 {
7541    struct PDSCH_Config *pdschCfg=NULLP;
7542    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
7543    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
7544    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
7545
7546    if(dlBwp->pdsch_Config->choice.setup)
7547    {
7548       pdschCfg=dlBwp->pdsch_Config->choice.setup;
7549       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
7550       {
7551          if(pdschCfg->pdsch_TimeDomainAllocationList)
7552          {
7553             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
7554             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
7555             {
7556                prbBndlType=&pdschCfg->prb_BundlingType;
7557                DU_FREE(prbBndlType->choice.staticBundling,\
7558                      sizeof(struct PDSCH_Config__prb_BundlingType__staticBundling));
7559                DU_FREE(pdschCfg->maxNrofCodeWordsScheduledByDCI, sizeof(long));
7560             }
7561             FreePdschTimeDomAllocList(timeDomAllocList);
7562             DU_FREE(pdschCfg->pdsch_TimeDomainAllocationList, \
7563                   sizeof(struct PDSCH_Config__pdsch_TimeDomainAllocationList));
7564          }
7565          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
7566          if(dmrsDlCfg->choice.setup)
7567          {
7568             DU_FREE(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition,
7569                   sizeof(long));
7570             DU_FREE(dmrsDlCfg->choice.setup, sizeof(struct DMRS_DownlinkConfig));
7571          }
7572          DU_FREE(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA, \
7573                sizeof(struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA));
7574       }
7575       DU_FREE(dlBwp->pdsch_Config->choice.setup, sizeof(struct PDSCH_Config));
7576    }
7577 }
7578 /*******************************************************************
7579  *
7580  * @brief Frees emmory allocated for BWPDlDedPdcchCfg
7581  *
7582  * @details
7583  *
7584  *    Function : FreeBWPDlDedPdcchCfg
7585  *
7586  *    Functionality: Deallocating memory of BWPDlDedPdcchCfg
7587  *
7588  * @params[in] BWP_DownlinkDedicated_t *dlBwp
7589  *
7590  * @return void
7591  *         
7592  *
7593  * ****************************************************************/
7594 void FreeBWPDlDedPdcchCfg(BWP_DownlinkDedicated_t *dlBwp)
7595 {
7596    uint8_t idx1=0;
7597    uint8_t idx2=0;
7598    struct PDCCH_Config *pdcchCfg=NULLP;
7599    struct ControlResourceSet *controlRSet=NULLP;
7600    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
7601
7602    if(dlBwp->pdcch_Config->choice.setup)
7603    {
7604       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
7605       if(pdcchCfg->controlResourceSetToAddModList)
7606       {
7607          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
7608          if(controlRSetList->list.array)
7609          {
7610             controlRSet = controlRSetList->list.array[idx2];
7611             if(controlRSet)
7612             {
7613                if(controlRSet->frequencyDomainResources.buf)
7614                {
7615                   if(controlRSet->pdcch_DMRS_ScramblingID)
7616                   {
7617                      if(pdcchCfg->searchSpacesToAddModList)
7618                      {
7619                         FreeSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
7620                         DU_FREE(pdcchCfg->searchSpacesToAddModList, \
7621                               sizeof(struct PDCCH_Config__searchSpacesToAddModList));
7622                      }
7623                      DU_FREE(controlRSet->pdcch_DMRS_ScramblingID, sizeof(long));
7624                   }
7625                   DU_FREE(controlRSet->frequencyDomainResources.buf, \
7626                         controlRSet->frequencyDomainResources.size);
7627                }
7628             }
7629             for(idx1 = 0; idx1 <controlRSetList->list.count; idx1++)
7630             {
7631                DU_FREE(controlRSetList->list.array[idx1], sizeof(struct ControlResourceSet));
7632             }
7633             DU_FREE(controlRSetList->list.array, controlRSetList->list.size);
7634          }
7635          DU_FREE(pdcchCfg->controlResourceSetToAddModList, \
7636                sizeof(struct PDCCH_Config__controlResourceSetToAddModList));
7637       }
7638       DU_FREE(dlBwp->pdcch_Config->choice.setup, sizeof(struct PDCCH_Config));
7639    }
7640 }       
7641
7642 /*******************************************************************
7643  *
7644  * @brief Free SCS specific carrier list in DL frequency info
7645  *
7646  * @details
7647  *
7648  *    Function : FreeScsSpecificCarrierListDl
7649  *
7650  *    Functionality: Free SCS specific carrier list in DL frequency info
7651  *
7652  * @params[in] Pointer to struct FrequencyInfoDL__scs_SpecificCarrierList
7653  *
7654  * @return void
7655  *
7656  * ****************************************************************/
7657 void FreeScsSpecificCarrierListDl(struct FrequencyInfoDL__scs_SpecificCarrierList *scsCarrierList)
7658 {
7659    uint8_t listIdx = 0;
7660
7661    if(!scsCarrierList->list.array)
7662    {
7663       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
7664       {
7665          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
7666       }
7667       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
7668    }
7669 }
7670
7671 /*******************************************************************
7672  *
7673  * @brief Free DL frequency info in DL config common
7674  *
7675  * @details
7676  *
7677  *    Function : FreeFreqInfoDl
7678  *
7679  *    Functionality: Free DL frequency info in DL config common
7680  *
7681  * @params[in] Pointer to DownlinkConfigCommon_t
7682  *
7683  * @return void
7684  *
7685  * ****************************************************************/
7686 void FreeFreqInfoDl(FrequencyInfoDL_t *frequencyInfoDL)
7687 {
7688    uint8_t freqBandIdx = 0;
7689
7690    /* SSB Absolute Frequency */
7691    DU_FREE(frequencyInfoDL->absoluteFrequencySSB, sizeof(ARFCN_ValueNR_t));
7692
7693    /* NR Multi Frequency Band List */
7694    if(frequencyInfoDL->frequencyBandList.list.array)
7695    {
7696       for(freqBandIdx = 0; freqBandIdx < frequencyInfoDL->frequencyBandList.list.count; freqBandIdx++)
7697       {
7698          DU_FREE(frequencyInfoDL->frequencyBandList.list.array[freqBandIdx], sizeof(FreqBandIndicatorNR_t));
7699       }
7700       DU_FREE(frequencyInfoDL->frequencyBandList.list.array, frequencyInfoDL->frequencyBandList.list.size);
7701    }
7702
7703    /* Subcarrier Spacing specifc carrier List */
7704    FreeScsSpecificCarrierListDl(&frequencyInfoDL->scs_SpecificCarrierList);
7705 }
7706
7707 /*******************************************************************
7708  *
7709  * @brief Free DL config common in Serving cell config common
7710  *
7711  * @details
7712  *
7713  *    Function : FreeDlConfigCommon
7714  *
7715  *    Functionality: Free DL config common in Serving cell config common
7716  *
7717  * @params[in] Pointer to DownlinkConfigCommon_t
7718  *
7719  * @return void
7720  *
7721  * ****************************************************************/
7722 void FreeDlConfigCommon(DownlinkConfigCommon_t *dlCfgCommon)
7723 {
7724    /* DL Frequency Info */
7725    if(dlCfgCommon->frequencyInfoDL)
7726    {
7727       FreeFreqInfoDl(dlCfgCommon->frequencyInfoDL);
7728       DU_FREE(dlCfgCommon->frequencyInfoDL, sizeof(FrequencyInfoDL_t));
7729    }
7730
7731    /* DL BWP config common */
7732    if(dlCfgCommon->initialDownlinkBWP)
7733    {
7734       FreeBwpDlCommon(dlCfgCommon->initialDownlinkBWP);
7735       DU_FREE(dlCfgCommon->initialDownlinkBWP, sizeof(BWP_DownlinkCommon_t));
7736    }
7737 }
7738
7739 /*******************************************************************
7740  *
7741  * @brief Free SCS specific carrier list in UL frequency Info
7742  *
7743  * @details
7744  *
7745  *    Function : FreeScsSpecificCarrierListUl
7746  *
7747  *    Functionality: Free SCS specific carrier list in UL frequency Info
7748  *
7749  * @params[in] Pointer to struct FrequencyInfoUL__scs_SpecificCarrierList
7750  *
7751  * @return void
7752  *
7753  * ****************************************************************/
7754 void FreeScsSpecificCarrierListUl(struct FrequencyInfoUL__scs_SpecificCarrierList *scsCarrierList)
7755 {
7756    uint8_t listIdx = 0;
7757
7758    if(scsCarrierList->list.array)
7759    {
7760       for(listIdx = 0; listIdx < scsCarrierList->list.count; listIdx++)
7761       {
7762          DU_FREE(scsCarrierList->list.array[listIdx], sizeof(SCS_SpecificCarrier_t));
7763       }
7764       DU_FREE(scsCarrierList->list.array, scsCarrierList->list.size);
7765    }
7766 }
7767
7768 /*******************************************************************
7769  *
7770  * @brief Free frequency info in UL config common
7771  *
7772  * @details
7773  *
7774  *    Function : FreeFreqInfoUl
7775  *
7776  *    Functionality: Free frequency info in UL config common
7777  *
7778  * @params[in] Pointer to FrequencyInfoUL_t
7779  *
7780  * @return void
7781  *
7782  * ****************************************************************/
7783 void FreeFreqInfoUl(FrequencyInfoUL_t *frequencyInfoUL)
7784 {
7785    uint8_t listIdx= 0;
7786
7787    /* NR Multi Frequency Band List */
7788    if(!frequencyInfoUL->frequencyBandList)
7789    {
7790       if(frequencyInfoUL->frequencyBandList->list.array)
7791       {
7792          for(listIdx = 0; listIdx < frequencyInfoUL->frequencyBandList->list.count; listIdx++)
7793          {
7794             DU_FREE(frequencyInfoUL->frequencyBandList->list.array[listIdx], sizeof(FreqBandIndicatorNR_t));
7795          }
7796          DU_FREE(frequencyInfoUL->frequencyBandList->list.array, frequencyInfoUL->frequencyBandList->list.size);
7797       }
7798       DU_FREE(frequencyInfoUL->frequencyBandList, sizeof(MultiFrequencyBandListNR_t));
7799    }
7800
7801    /* Absolute frequency point A */
7802    DU_FREE(frequencyInfoUL->absoluteFrequencyPointA, sizeof(ARFCN_ValueNR_t));
7803
7804    /* Subcarrier Spacing specifc carrier */
7805    FreeScsSpecificCarrierListUl(&frequencyInfoUL->scs_SpecificCarrierList);
7806
7807    /* P-MAX */
7808    DU_FREE(frequencyInfoUL->p_Max, sizeof(P_Max_t));
7809 }
7810
7811 /*******************************************************************
7812  *
7813  * @brief Free UL config common in Serving cell config common
7814  *
7815  * @details
7816  *
7817  *    Function : FreeUlConfigCommon
7818  *
7819  *    Functionality: Free UL config common in Serving cell config common
7820  *
7821  * @params[in] Pointer to UplinkConfigCommon_t
7822  *
7823  * @return void
7824  *
7825  * ****************************************************************/
7826 void FreeUlConfigCommon(UplinkConfigCommon_t *ulCfgCommon)
7827 {
7828    /* UL Frequency Info */
7829    if(ulCfgCommon->frequencyInfoUL)
7830    {
7831       FreeFreqInfoUl(ulCfgCommon->frequencyInfoUL);
7832       DU_FREE(ulCfgCommon->frequencyInfoUL, sizeof(FrequencyInfoUL_t));
7833    }
7834
7835    /* UL BWP common */
7836    if(ulCfgCommon->initialUplinkBWP)
7837    {
7838       FreeBwpUlCommon(ulCfgCommon->initialUplinkBWP);
7839       DU_FREE(ulCfgCommon->initialUplinkBWP, sizeof(BWP_UplinkCommon_t));
7840    }
7841 }
7842
7843 /*******************************************************************
7844  *
7845  * @brief Free SP cell config common in Reconfig with Sync
7846  *
7847  * @details
7848  *
7849  *    Function : FreeSpCellConfigCommon
7850  *
7851  *    Functionality: Free SP cell config common in Reconfig with Sync
7852  *
7853  * @params[in] Pointer to ServingCellConfigCommon_t
7854  *
7855  * @return void
7856  *
7857  * ****************************************************************/
7858 void FreeSpCellConfigCommon(ServingCellConfigCommon_t *spCellConfigCommon)
7859 {
7860    /* Free Physical cell identity */
7861    DU_FREE(spCellConfigCommon->physCellId, sizeof(PhysCellId_t));
7862
7863    /* Free Downlink Config common */
7864    if(spCellConfigCommon->downlinkConfigCommon)
7865    {
7866       FreeDlConfigCommon(spCellConfigCommon->downlinkConfigCommon);
7867       DU_FREE(spCellConfigCommon->downlinkConfigCommon, sizeof(DownlinkConfigCommon_t));
7868    }
7869
7870    /* Free Uplink Config common */
7871    if(spCellConfigCommon->uplinkConfigCommon)
7872    {
7873       FreeUlConfigCommon(spCellConfigCommon->uplinkConfigCommon);
7874       DU_FREE(spCellConfigCommon->uplinkConfigCommon, sizeof(UplinkConfigCommon_t));
7875    }
7876
7877    /* Free Timing Advance offset */
7878    DU_FREE(spCellConfigCommon->n_TimingAdvanceOffset, sizeof(long));
7879
7880    /* Free SSB Position in Burst */
7881    if(spCellConfigCommon->ssb_PositionsInBurst)
7882    {
7883       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.buf, \
7884          spCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap.size);
7885       DU_FREE(spCellConfigCommon->ssb_PositionsInBurst, sizeof(struct ServingCellConfigCommon__ssb_PositionsInBurst));
7886    }
7887
7888    /* Free SSB Periodicity in Serving cell */
7889    DU_FREE(spCellConfigCommon->ssb_periodicityServingCell, sizeof(long));
7890
7891    /* Free SSB subcarrier spacing */
7892    DU_FREE(spCellConfigCommon->ssbSubcarrierSpacing, sizeof(SubcarrierSpacing_t));
7893
7894    /* TDD UL-DL configuration common */
7895    DU_FREE(spCellConfigCommon->tdd_UL_DL_ConfigurationCommon, sizeof(TDD_UL_DL_ConfigCommon_t));
7896 }
7897
7898 /*******************************************************************
7899  *
7900  * @brief Free dedicated RACH configuration in Reconfiguration with sync
7901  *
7902  * @details
7903  *
7904  *    Function : FreeRecfgWithSync
7905  *
7906  *    Functionality:
7907  *       Free dedicated RACH configuration in Reconfiguration with sync
7908  *
7909  * @params[in] Pinter to Rach config dedicated struct
7910  *
7911  * @return void
7912  *
7913  * ****************************************************************/
7914 void FreeRachConfigDedicated(struct ReconfigurationWithSync__rach_ConfigDedicated *rachCfgDed)
7915 {
7916    uint8_t listIdx = 0;
7917    CFRA_t *cfra = NULLP;
7918    struct CFRA__resources__ssb *ssbResource = NULLP;
7919
7920    /* Uplink */
7921    if(rachCfgDed->choice.uplink)
7922    {
7923       /* CFRA : Contention free Random Access */
7924       if(rachCfgDed->choice.uplink->cfra)
7925       {
7926          cfra = rachCfgDed->choice.uplink->cfra;
7927
7928          /* CFRA occassions */
7929          if(cfra->occasions)
7930          {
7931             /* CFRA occassions : SSB per RACH occasion */
7932             DU_FREE(cfra->occasions->ssb_perRACH_Occasion, sizeof(long));
7933             DU_FREE(cfra->occasions, sizeof(struct CFRA__occasions));
7934          }
7935
7936          /* CFRA resource */
7937          cfra->resources.present = CFRA__resources_PR_ssb;
7938
7939          /* CFRA resource : SSB */
7940          if(cfra->resources.choice.ssb)
7941          {
7942             ssbResource = cfra->resources.choice.ssb;
7943
7944             /* CFRA SSB resource list */
7945             if(ssbResource->ssb_ResourceList.list.array)
7946             {
7947                for(listIdx = 0; listIdx < ssbResource->ssb_ResourceList.list.count; listIdx++)
7948                {
7949                   DU_FREE(ssbResource->ssb_ResourceList.list.array[listIdx], sizeof(CFRA_SSB_Resource_t));
7950                }
7951                DU_FREE(ssbResource->ssb_ResourceList.list.array, ssbResource->ssb_ResourceList.list.size);
7952             }
7953             DU_FREE(cfra->resources.choice.ssb, sizeof(struct CFRA__resources__ssb));
7954          }
7955          DU_FREE(rachCfgDed->choice.uplink->cfra, sizeof(CFRA_t));
7956       }
7957       DU_FREE(rachCfgDed->choice.uplink, sizeof(RACH_ConfigDedicated_t));
7958    }
7959 }
7960
7961 /*******************************************************************
7962  *
7963  * @brief Frees reconfiguration with sync in SP cell config
7964  *
7965  * @details
7966  *
7967  *    Function : FreeRecfgWithSync
7968  *
7969  *    Functionality: Fress reconfiguration with sync in SP cell config
7970  *
7971  * @params[in] Pointer to ReconfigurationWithSync_t
7972  *
7973  * @return void
7974  *
7975  * ****************************************************************/
7976 void FreeRecfgWithSync(ReconfigurationWithSync_t *recfgWithSync)
7977 {
7978    /* Free SP Cell config common */
7979    if(recfgWithSync->spCellConfigCommon)
7980    {
7981       FreeSpCellConfigCommon(recfgWithSync->spCellConfigCommon);
7982       DU_FREE(recfgWithSync->spCellConfigCommon, sizeof(ServingCellConfigCommon_t));
7983    }
7984
7985    /* Free Dedicated RACH configuration */
7986    if(recfgWithSync->rach_ConfigDedicated)
7987    {
7988       FreeRachConfigDedicated(recfgWithSync->rach_ConfigDedicated);
7989       DU_FREE(recfgWithSync->rach_ConfigDedicated, sizeof(struct ReconfigurationWithSync__rach_ConfigDedicated));
7990    }
7991 }
7992
7993 /*******************************************************************
7994  *
7995  * @brief Frees emmory allocated for DUToCURRCContainer 
7996  *
7997  * @details
7998  *
7999  *    Function : FreeMemDuToCuRrcCont
8000  *
8001  *    Functionality: Deallocating memory of DuToCuRrcContainer
8002  *
8003  * @params[in] DuToCuRRCContainer, DuToCuRRCContainer
8004  *
8005  * @return ROK     - success
8006  *         RFAILED - failure
8007  *
8008  * ****************************************************************/
8009 uint8_t FreeMemDuToCuRrcCont(CellGroupConfigRrc_t *cellGrpCfg)
8010 {
8011    uint8_t idx=0;
8012    SpCellConfig_t *spCellCfg=NULLP;
8013    ServingCellConfig_t *srvCellCfg=NULLP;
8014    BWP_DownlinkDedicated_t *dlBwp=NULLP;
8015    MAC_CellGroupConfig_t *macCellGrpCfg=NULLP;
8016    PhysicalCellGroupConfig_t *phyCellGrpCfg=NULLP;
8017    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList=NULLP;
8018    struct RLC_Config *rlcConfig=NULLP;
8019    struct LogicalChannelConfig *macLcConfig=NULLP;
8020    struct SchedulingRequestConfig *schedulingRequestConfig=NULLP;
8021    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList=NULLP;
8022    struct TAG_Config *tagConfig=NULLP;
8023    struct TAG_Config__tag_ToAddModList *tagList=NULLP;
8024    struct MAC_CellGroupConfig__phr_Config *phrConfig=NULLP;
8025    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg=NULLP;
8026
8027    rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
8028    if(rlcBearerList)
8029    {
8030       if(rlcBearerList->list.array)
8031       {
8032          for(idx=0; idx<rlcBearerList->list.count; idx++)
8033          {
8034             if(rlcBearerList->list.array[idx])
8035             {  
8036                rlcConfig   = rlcBearerList->list.array[idx]->rlc_Config;
8037                macLcConfig = rlcBearerList->list.array[idx]->mac_LogicalChannelConfig;
8038                if(rlcConfig)
8039                {
8040                   if(rlcConfig->choice.am)
8041                   {
8042                      DU_FREE(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t));
8043                      DU_FREE(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength, sizeof(SN_FieldLengthAM_t)); 
8044                      DU_FREE(rlcConfig->choice.am, sizeof(struct RLC_Config__am));
8045                   }     
8046                   DU_FREE(rlcConfig, sizeof(struct RLC_Config));
8047                }
8048                DU_FREE(rlcBearerList->list.array[idx]->servedRadioBearer, sizeof(struct RLC_BearerConfig__servedRadioBearer));
8049                if(macLcConfig)
8050                {
8051                   if(macLcConfig->ul_SpecificParameters)
8052                   {
8053                      DU_FREE(macLcConfig->ul_SpecificParameters->schedulingRequestID,   sizeof(SchedulingRequestId_t));
8054                      DU_FREE(macLcConfig->ul_SpecificParameters->logicalChannelGroup,   sizeof(long));
8055                      DU_FREE(macLcConfig->ul_SpecificParameters, sizeof(struct LogicalChannelConfig__ul_SpecificParameters));
8056                   }
8057                   DU_FREE(rlcBearerList->list.array[idx]->mac_LogicalChannelConfig, sizeof(struct LogicalChannelConfig));
8058                }
8059                DU_FREE(rlcBearerList->list.array[idx], sizeof(struct RLC_BearerConfig));
8060             }   
8061          }
8062          DU_FREE(rlcBearerList->list.array, rlcBearerList->list.size);
8063       }
8064       DU_FREE(cellGrpCfg->rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8065    }
8066
8067    macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
8068    if(macCellGrpCfg)
8069    {
8070       schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig; 
8071       if(schedulingRequestConfig)
8072       {
8073          schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
8074          if(schReqList)
8075          {
8076             if(schReqList->list.array)
8077             {
8078                for(idx=0;idx<schReqList->list.count; idx++)
8079                {
8080                   if(schReqList->list.array[idx])
8081                   {
8082                      DU_FREE(schReqList->list.array[idx]->sr_ProhibitTimer, sizeof(long));
8083                      DU_FREE(schReqList->list.array[idx], sizeof(struct SchedulingRequestToAddMod));
8084                   }
8085                }
8086                DU_FREE(schReqList->list.array, schReqList->list.size);
8087             }
8088             DU_FREE(schedulingRequestConfig->schedulingRequestToAddModList,\
8089                   sizeof(struct SchedulingRequestConfig__schedulingRequestToAddModList));    }
8090             DU_FREE(macCellGrpCfg->schedulingRequestConfig, sizeof(struct SchedulingRequestConfig));
8091       }
8092       if(macCellGrpCfg->bsr_Config)
8093       {
8094          DU_FREE(macCellGrpCfg->bsr_Config, sizeof(struct BSR_Config));
8095       }
8096       tagConfig = macCellGrpCfg->tag_Config;
8097       if(tagConfig)
8098       {
8099          tagList = tagConfig->tag_ToAddModList;
8100          if(tagList)
8101          {
8102             if(tagList->list.array)
8103             {
8104                for(idx=0; idx<tagList->list.count; idx++)
8105                {
8106                   DU_FREE(tagList->list.array[idx], sizeof(struct TAG));
8107                }
8108                DU_FREE(tagList->list.array, tagList->list.size);
8109             }
8110             DU_FREE(tagConfig->tag_ToAddModList, sizeof(struct TAG_Config__tag_ToAddModList));
8111          }
8112          DU_FREE(tagConfig, sizeof(struct TAG_Config));
8113       }
8114
8115       phrConfig = macCellGrpCfg->phr_Config;
8116       if(phrConfig)
8117       {
8118          DU_FREE(phrConfig->choice.setup, sizeof(struct PHR_Config));
8119          DU_FREE(phrConfig, sizeof(struct MAC_CellGroupConfig__phr_Config));
8120       }
8121
8122       DU_FREE(macCellGrpCfg, sizeof(MAC_CellGroupConfig_t));
8123    }
8124
8125    phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
8126    if(phyCellGrpCfg)
8127    {
8128       DU_FREE(phyCellGrpCfg->p_NR_FR1, sizeof(long));
8129       DU_FREE(phyCellGrpCfg, sizeof(PhysicalCellGroupConfig_t));
8130    }
8131
8132    spCellCfg = cellGrpCfg->spCellConfig;
8133    if(spCellCfg)
8134    {
8135       /* Free serving cell index */
8136       DU_FREE(spCellCfg->servCellIndex, sizeof(long));
8137
8138       /* Free Reconfiguration with sync */
8139       if(spCellCfg->reconfigurationWithSync)
8140       {
8141          FreeRecfgWithSync(spCellCfg->reconfigurationWithSync);
8142          DU_FREE(spCellCfg->reconfigurationWithSync, sizeof(ReconfigurationWithSync_t));
8143       }
8144
8145       /* Free rlmInSyncOutOfSyncThreshold */
8146       DU_FREE(spCellCfg->rlmInSyncOutOfSyncThreshold, sizeof(long));
8147
8148       /* Free SP Cell config dedicated */
8149       if(spCellCfg->spCellConfigDedicated)
8150       {
8151          srvCellCfg = spCellCfg->spCellConfigDedicated;
8152
8153          /* Free TDD UL-DL config dedicated */
8154          DU_FREE(srvCellCfg->tdd_UL_DL_ConfigurationDedicated, sizeof(TDD_UL_DL_ConfigDedicated_t));
8155
8156          /* Free Initial Downlink BWP */
8157          if(srvCellCfg->initialDownlinkBWP)
8158          {
8159             dlBwp = srvCellCfg->initialDownlinkBWP;
8160
8161             /* Free DL BWP PDCCH Config */
8162             if(dlBwp->pdcch_Config)
8163             {
8164                FreeBWPDlDedPdcchCfg(dlBwp);
8165                DU_FREE(dlBwp->pdcch_Config, sizeof(struct BWP_DownlinkDedicated__pdcch_Config));
8166             }
8167
8168             /* Free DL BWP PDSCH config */
8169             if(dlBwp->pdsch_Config)
8170             {
8171                FreeBWPDlDedPdschCfg(dlBwp);
8172                DU_FREE(dlBwp->pdsch_Config, sizeof(struct BWP_DownlinkDedicated__pdsch_Config));
8173             }
8174             DU_FREE(srvCellCfg->initialDownlinkBWP, sizeof(BWP_DownlinkDedicated_t));
8175          }
8176
8177          /* Free First Active Downlink BWP */
8178          DU_FREE(srvCellCfg->firstActiveDownlinkBWP_Id, sizeof(long));
8179
8180          /* Free Default downlink BWP */
8181          DU_FREE(srvCellCfg->defaultDownlinkBWP_Id, sizeof(long));
8182
8183          /* Free Uplink config */
8184          if(srvCellCfg->uplinkConfig)
8185          {
8186             FreeinitialUplinkBWP(srvCellCfg->uplinkConfig);
8187             DU_FREE(srvCellCfg->uplinkConfig, sizeof(UplinkConfig_t));  
8188          }
8189
8190          /* Free PDSCH serving cell config */
8191          if(srvCellCfg->pdsch_ServingCellConfig)
8192          {
8193             pdschCfg= srvCellCfg->pdsch_ServingCellConfig;
8194             if(pdschCfg->choice.setup)
8195             {
8196                DU_FREE(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH,sizeof(long));
8197                DU_FREE(pdschCfg->choice.setup, sizeof(struct PDSCH_ServingCellConfig));
8198             }
8199             DU_FREE(srvCellCfg->pdsch_ServingCellConfig, sizeof(struct ServingCellConfig__pdsch_ServingCellConfig));
8200          }
8201
8202          DU_FREE(spCellCfg->spCellConfigDedicated, sizeof(ServingCellConfig_t));
8203       }
8204       DU_FREE(spCellCfg,sizeof(SpCellConfig_t));
8205    }
8206    return ROK;
8207 }
8208
8209 /*******************************************************************
8210  *
8211  * @brief Builds CellGroupConfigRrc for DU To CU RRC Container 
8212  *
8213  * @details
8214  *
8215  *    Function : BuildCellGroupConfigRrc
8216  *
8217  *    Functionality: Builds and copied Cell group config buffer into 
8218  *       DuToCuRrcContainer
8219  *
8220  * @params[in] idx, index in F1AP msg
8221  *             DuToCuRRCContainer, DuToCuRRCContainer
8222  *
8223  * @return ROK     - success
8224  *         RFAILED - failure
8225  *
8226  * ****************************************************************/
8227 uint8_t BuildCellGroupConfigRrc(DuUeCb *ueCb, OCTET_STRING_t *duToCuRrcContainer)
8228 {
8229    uint8_t  ret = ROK;
8230    CellGroupConfigRrc_t  cellGrpCfg;
8231    asn_enc_rval_t        encRetVal;
8232    memset(&cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
8233    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8234
8235    while(true)
8236    {
8237       cellGrpCfg.cellGroupId = CELL_GRP_ID;
8238
8239       cellGrpCfg.rlc_BearerToAddModList = NULLP;
8240       DU_ALLOC(cellGrpCfg.rlc_BearerToAddModList, sizeof(struct CellGroupConfigRrc__rlc_BearerToAddModList));
8241       if(!cellGrpCfg.rlc_BearerToAddModList)
8242       {
8243          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8244          ret = RFAILED;
8245          break;
8246       }
8247       if(BuildRlcBearerToAddModList(ueCb, cellGrpCfg.rlc_BearerToAddModList) != ROK)
8248       {
8249          DU_LOG("\nERROR  -->  F1AP : BuildRlcBearerToAddModList failed");
8250          ret = RFAILED;
8251          break;
8252       }
8253
8254       cellGrpCfg.rlc_BearerToReleaseList = NULLP;
8255       cellGrpCfg.mac_CellGroupConfig = NULLP;
8256       DU_ALLOC(cellGrpCfg.mac_CellGroupConfig, sizeof(MAC_CellGroupConfig_t));
8257       if(!cellGrpCfg.mac_CellGroupConfig)
8258       {
8259          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8260          ret = RFAILED;
8261          break;
8262       }
8263       if(BuildMacCellGrpCfg(ueCb, cellGrpCfg.mac_CellGroupConfig) != ROK)
8264       {
8265          DU_LOG("\nERROR  -->  F1AP : BuildMacCellGrpCfg failed");
8266          ret = RFAILED;
8267          break;
8268       }
8269
8270       cellGrpCfg.physicalCellGroupConfig = NULLP;
8271       DU_ALLOC(cellGrpCfg.physicalCellGroupConfig, sizeof(PhysicalCellGroupConfig_t));
8272       if(!cellGrpCfg.physicalCellGroupConfig)
8273       {
8274          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8275          ret = RFAILED;
8276          break;
8277       }
8278       if(BuildPhyCellGrpCfg(ueCb, cellGrpCfg.physicalCellGroupConfig) != ROK)
8279       {
8280          DU_LOG("\nERROR  -->  F1AP : BuildPhyCellGrpCfg failed");
8281          ret = RFAILED;
8282          break;
8283       }
8284
8285       cellGrpCfg.spCellConfig = NULLP;
8286       DU_ALLOC(cellGrpCfg.spCellConfig, sizeof(SpCellConfig_t));
8287       if(!cellGrpCfg.spCellConfig)
8288       {
8289          DU_LOG("\nERROR  -->  F1AP : Memory allocation failure in BuildDuToCuRrcContainer");
8290          ret = RFAILED;
8291          break;
8292       }
8293       if(BuildSpCellCfg(ueCb, cellGrpCfg.spCellConfig) != ROK)
8294       {
8295          DU_LOG("\nERROR  -->  F1AP : BuildSpCellCfg failed");
8296          ret = RFAILED;
8297          break;
8298       }
8299
8300       cellGrpCfg.sCellToAddModList = NULLP;
8301       cellGrpCfg.sCellToReleaseList = NULLP;
8302       cellGrpCfg.ext1 = NULLP;
8303
8304       /* encode cellGrpCfg into duToCuRrcContainer */
8305       xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, &cellGrpCfg);
8306       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8307       encBufSize = 0;
8308       encRetVal = aper_encode(&asn_DEF_CellGroupConfigRrc, 0, &cellGrpCfg, PrepFinalEncBuf, encBuf);
8309       /* Encode results */
8310       if(encRetVal.encoded == ENCODE_FAIL)
8311       {
8312          DU_LOG( "\nERROR  --> F1AP : Could not encode DuToCuRrcContainer (at %s)\n",\
8313                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
8314          ret = RFAILED;
8315          break;
8316       }
8317       else
8318       {
8319          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for DuToCuRrcContainer\n");
8320          for(int i=0; i< encBufSize; i++)
8321          {
8322             printf("%x",encBuf[i]);
8323          }
8324       }
8325
8326       duToCuRrcContainer->size = encBufSize;
8327       DU_ALLOC(duToCuRrcContainer->buf, duToCuRrcContainer->size);
8328       if(!duToCuRrcContainer->buf)
8329       {
8330          DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDuToCuRrcContainer");
8331          ret = RFAILED;
8332          break;
8333       }
8334       if(ret == ROK)
8335       {
8336          memcpy(duToCuRrcContainer->buf, encBuf, duToCuRrcContainer->size);
8337       }
8338       break;
8339    }
8340    FreeMemDuToCuRrcCont(&cellGrpCfg);
8341    return ret;
8342 }
8343
8344 /*******************************************************************
8345  *
8346  * @brief Free memory allocated in InitialULRRCMessage
8347  *
8348  * @details
8349  *
8350  *    Function : freeInitUlRrcMsgTransfer
8351  *
8352  *    Functionality: Free memory allocated in InitialULRRCMessage
8353  *
8354  * @params[in]F1AP_PDU_t  *f1apMsg)
8355  *
8356  * @return ROK     - success
8357  *         RFAILED - failure
8358  *
8359  * ****************************************************************/
8360
8361 uint8_t freeInitUlRrcMsgTransfer(F1AP_PDU_t  *f1apMsg)
8362 {
8363    uint8_t ieIdx, arrIdx;
8364    InitialULRRCMessageTransfer_t *initULRRCMsg=NULLP;
8365
8366    if(f1apMsg)
8367    {
8368       if(f1apMsg->choice.initiatingMessage)
8369       {
8370          initULRRCMsg = &f1apMsg->choice.initiatingMessage->value.\
8371             choice.InitialULRRCMessageTransfer;
8372          if(initULRRCMsg->protocolIEs.list.array)
8373          {
8374             for(ieIdx = 0; ieIdx < initULRRCMsg->protocolIEs.list.count; ieIdx++)
8375             {
8376                switch(initULRRCMsg->protocolIEs.list.array[ieIdx]->id)
8377                {
8378                   case ProtocolIE_ID_id_NRCGI:
8379                   {
8380                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf)
8381                      {
8382                         if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf)
8383                         {
8384                            DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.buf,\
8385                            initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity.size);
8386                         }
8387                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.buf,\
8388                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.pLMN_Identity.size);
8389                      }
8390                      break;
8391                   }
8392                   case ProtocolIE_ID_id_RRCContainer:
8393                   {
8394                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
8395                      {
8396                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,\
8397                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
8398                      }
8399                      break;
8400                   }
8401                   case ProtocolIE_ID_id_DUtoCURRCContainer:
8402                   {
8403                      if(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf)
8404                      {
8405                         DU_FREE(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.buf,
8406                         initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer.size);
8407                      }
8408                      break;
8409                   }
8410                   default:
8411                      break;
8412                }
8413              }
8414              for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
8415              {
8416                 if(initULRRCMsg->protocolIEs.list.array[arrIdx])
8417                 {
8418                    DU_FREE(initULRRCMsg->protocolIEs.list.array[arrIdx],\
8419                       sizeof(InitialULRRCMessageTransferIEs_t));
8420                 }
8421              }
8422              DU_FREE(initULRRCMsg->protocolIEs.list.array, initULRRCMsg->protocolIEs.list.size);
8423           }
8424          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8425       }
8426       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
8427    }
8428    else
8429    {
8430       DU_LOG("\nERROR  -->  DU_APP : Recevied F1ap Pdu is null at freeInitUlRrcMsgTransfer()");
8431       return RFAILED;
8432    }
8433    return ROK;
8434 }
8435
8436 /*******************************************************************
8437  *
8438  * @brief Builds and sends the InitialULRRCMessage 
8439  *
8440  * @details
8441  *
8442  *    Function : BuildAndSendInitialRrcMsgTransfer 
8443  *
8444  *    Functionality: Constructs the Initial UL RRC Message Transfer and sends
8445  *                   it to the CU through SCTP.
8446  *
8447  * @params[in] 
8448  *
8449  * @return ROK     - success
8450  *         RFAILED - failure
8451  *
8452  * ****************************************************************/
8453 uint8_t BuildAndSendInitialRrcMsgTransfer(uint32_t gnbDuUeF1apId, uint16_t crnti,
8454       uint16_t rrcContSize, uint8_t *rrcContainer)
8455 {
8456    uint8_t   ret;
8457    uint8_t   elementCnt;
8458    uint8_t   ieIdx, cellIdx, ueIdx;
8459    DuUeCb    *duUeCb = NULLP;
8460    asn_enc_rval_t  encRetVal;
8461    F1AP_PDU_t  *f1apMsg = NULLP;
8462    InitialULRRCMessageTransfer_t *initULRRCMsg = NULLP;
8463    memset(&encRetVal, 0, sizeof(asn_enc_rval_t));
8464
8465    while(true)
8466    {
8467       DU_LOG("\n INFO   -->  F1AP : Building RRC Setup Request\n");
8468       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
8469       if(f1apMsg == NULLP)
8470       {
8471          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
8472          break;
8473       }
8474       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
8475       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
8476       if(f1apMsg->choice.initiatingMessage == NULLP)
8477       {
8478          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU failed");
8479          break;
8480       }
8481       f1apMsg->choice.initiatingMessage->procedureCode =\
8482                                                         ProcedureCode_id_InitialULRRCMessageTransfer;
8483       f1apMsg->choice.initiatingMessage->criticality = Criticality_ignore;
8484       f1apMsg->choice.initiatingMessage->value.present = \
8485                                                          InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
8486       initULRRCMsg =\
8487                     &f1apMsg->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
8488       elementCnt = 5;
8489       initULRRCMsg->protocolIEs.list.count = elementCnt;
8490       initULRRCMsg->protocolIEs.list.size = \
8491                                             elementCnt * sizeof(InitialULRRCMessageTransferIEs_t *);
8492       /* Initialize the F1Setup members */
8493       DU_ALLOC(initULRRCMsg->protocolIEs.list.array,initULRRCMsg->protocolIEs.list.size);
8494       if(initULRRCMsg->protocolIEs.list.array == NULLP)
8495       {
8496          DU_LOG(" ERROR  -->  F1AP : Memory allocation for\
8497                RRCSetupRequestMessageTransferIEs failed");
8498          break;
8499       }
8500       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
8501       {
8502          DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx],\
8503                sizeof(InitialULRRCMessageTransferIEs_t));
8504          if(initULRRCMsg->protocolIEs.list.array[ieIdx] == NULLP)
8505          {
8506             break;
8507          }
8508       }
8509       ieIdx = 0;
8510       /*GNB DU UE F1AP ID*/
8511       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8512                                                         ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
8513       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  = Criticality_reject;
8514       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
8515                                                                   InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
8516       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
8517
8518
8519       /*NRCGI*/
8520       ieIdx++;
8521       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8522                                                         ProtocolIE_ID_id_NRCGI;
8523       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality  =Criticality_reject;
8524       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present = \
8525                                                                   InitialULRRCMessageTransferIEs__value_PR_NRCGI;
8526
8527       ret =\
8528            BuildNrcgi(&initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
8529       if(ret!=ROK)
8530       {
8531          break;
8532       }
8533
8534       /*CRNTI*/
8535       ieIdx++;
8536       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8537                                                         ProtocolIE_ID_id_C_RNTI;
8538       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
8539       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
8540                                                                  InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
8541       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.C_RNTI = crnti;
8542
8543       /*RRCContainer*/
8544       ieIdx++;
8545       initULRRCMsg->protocolIEs.list.array[ieIdx]->id  = \
8546                                                         ProtocolIE_ID_id_RRCContainer;
8547       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
8548       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
8549                                                                  InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
8550
8551       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size = rrcContSize;
8552       DU_ALLOC(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,
8553             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size)
8554       if(!initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
8555       {
8556          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRCSetupRequestMessageTransferIEs failed");
8557          break;
8558       
8559       }
8560       memcpy(initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf, rrcContainer,
8561             initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size);
8562
8563
8564       /*DUtoCURRCContainer*/
8565       ieIdx++;
8566       initULRRCMsg->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCContainer;
8567       initULRRCMsg->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
8568       initULRRCMsg->protocolIEs.list.array[ieIdx]->value.present =\
8569                                                                  InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
8570
8571       for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
8572       {
8573          for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
8574          {
8575             if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
8576                   (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti == crnti))
8577             {
8578                duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
8579             }
8580          }
8581       }
8582
8583       ret = BuildCellGroupConfigRrc(duUeCb, &initULRRCMsg->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCContainer);
8584       if(ret != ROK)
8585       {
8586          break;
8587       }
8588
8589       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
8590
8591       /* Encode the Intial UL RRC Message transfer as APER */
8592       memset(encBuf, 0, ENC_BUF_MAX_LEN);
8593       encBufSize = 0;
8594       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
8595       /* Encode results */
8596       if(encRetVal.encoded == ENCODE_FAIL)
8597       {
8598          DU_LOG( "\nERROR  --> F1AP : Could not encode Initial UL RRC Message Transfer\
8599                structure (at %s)\n",encRetVal.failed_type ? \
8600                encRetVal.failed_type->name : "unknown");
8601          ret = RFAILED;
8602          break;
8603       }
8604       else
8605       {
8606
8607          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for Initial UL RRC\
8608                Message transfer\n");
8609          for(int i=0; i< encBufSize; i++)
8610          {
8611             printf("%x",encBuf[i]);
8612          }
8613       }
8614       /* Sending  msg  */
8615       if(sendF1APMsg() != ROK)
8616       {
8617          DU_LOG("\nERROR  -->  F1AP : Sending Initial UL RRC Message Transfer Failed");
8618          ret = RFAILED;
8619          break;
8620       }
8621       break;
8622    }
8623    freeInitUlRrcMsgTransfer(f1apMsg);
8624    return ret;
8625 }/* End of BuildAndSendInitialRrcMsgTransfer*/
8626
8627 /*****  UE SETUP REQUEST *****/
8628
8629 /*******************************************************************
8630  *
8631  * @brief Free Qos And Snssai Drb Info
8632  *
8633  * @details
8634  *
8635  *    Function : freeDrbQosAndSnssaiInfo
8636  *
8637  *    Functionality: Free Qos And Snssai Drb Info
8638  *
8639  * @params[in] LcCfg *lcCfg,
8640  * @return void
8641  *
8642  * ****************************************************************/
8643 void freeDrbQosAndSnssaiInfo(LcCfg *lcCfg)
8644 {
8645    if(lcCfg->snssai)
8646    {
8647       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
8648    }
8649    if(lcCfg->drbQos)
8650    {
8651       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
8652    }
8653 }
8654
8655 /******************************************************************
8656 *
8657 * @brief Function to delete the RLC Lc cfg from UE APP DB
8658 *
8659 * @details
8660 *
8661 *  Function : freeRlcLcCfg
8662 *
8663 *  Functionality: Function to delete the RLC Lc cfg from UE APP DB
8664 *
8665 *
8666  *****************************************************************/
8667
8668 void freeRlcLcCfg(RlcBearerCfg *lcCfg)
8669 {
8670    switch(lcCfg->rlcMode)
8671    {
8672       case RLC_AM :
8673          {
8674             if(lcCfg->u.amCfg)
8675             {
8676                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
8677             }
8678             break;
8679          }
8680       case RLC_UM_BI_DIRECTIONAL :
8681          {
8682             if(lcCfg->u.umBiDirCfg)
8683             {
8684                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
8685             }
8686             break;
8687          }
8688       case RLC_UM_UNI_DIRECTIONAL_UL :
8689          {
8690             if(lcCfg->u.umUniDirUlCfg)
8691             {
8692                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
8693             }
8694             break;
8695
8696          }
8697       case RLC_UM_UNI_DIRECTIONAL_DL :
8698          {
8699             if(lcCfg->u.umUniDirDlCfg)
8700             {
8701                DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
8702             }
8703             break;
8704          }
8705       default:
8706          DU_LOG("\nERROR  -->  DU_APP: Invalid Rlc Mode %d at freeRlcLcCfg()", lcCfg->rlcMode);
8707          break;
8708    }
8709    DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
8710 }
8711
8712 /*******************************************************************
8713  *
8714  * @brief Function to free MacLcCfg
8715  *
8716  * @details
8717  *
8718  *    Function : freeMacLcCfg
8719  *
8720  *    Functionality: Function to free MacLcCfg
8721  *
8722  * @params[in] LcCfg *lcCfg,
8723  * @return void
8724  *
8725  * ****************************************************************/
8726
8727 void  freeMacLcCfg(LcCfg *lcCfg)
8728 {
8729     /* Deleting DRBQOS */
8730    if(lcCfg->drbQos)
8731    {
8732       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->drbQos, sizeof(DrbQosInfo));
8733    }
8734    /* Deleting SNSSAI */
8735    if(lcCfg->snssai)
8736    {
8737       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
8738    }
8739 }
8740 /*******************************************************************
8741  *
8742  * @brief Free UE NR Capability received in UE Context setup request
8743  *
8744  * @details
8745  *
8746  *    Function : freeAperDecodeUeNrCapability
8747  *
8748  *    Functionality:  
8749  *       Free UE NR Capability received in UE Context setup request
8750  *
8751  * @params[in] 
8752  * @return ROK     - success
8753  *         RFAILED - failure
8754  *
8755  * ****************************************************************/
8756 void freeAperDecodeUeNrCapability(void *ueNrCapability)
8757 {
8758    uint8_t arrIdx =0;
8759    FeatureSets_t *featureSets =NULLP;
8760    UE_NR_Capability_t *ueNrCap = (UE_NR_Capability_t *)ueNrCapability;
8761
8762    if(ueNrCap->rf_Parameters.supportedBandListNR.list.array)
8763    {
8764       for(arrIdx = 0; arrIdx < ueNrCap->rf_Parameters.supportedBandListNR.list.count; arrIdx++)
8765       {
8766          if(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx])
8767             free(ueNrCap->rf_Parameters.supportedBandListNR.list.array[arrIdx]);
8768       }
8769       free(ueNrCap->rf_Parameters.supportedBandListNR.list.array);
8770    }
8771
8772    if(ueNrCap->featureSets)
8773    {
8774       featureSets = ueNrCap->featureSets;
8775       if(featureSets->featureSetsDownlinkPerCC)
8776       {
8777          if(featureSets->featureSetsDownlinkPerCC->list.array)
8778          {
8779             for(arrIdx = 0; arrIdx < featureSets->featureSetsDownlinkPerCC->list.count; arrIdx++)
8780             {
8781                if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx])
8782                {
8783                   if(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL)
8784                      free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]->supportedModulationOrderDL);
8785                   free(featureSets->featureSetsDownlinkPerCC->list.array[arrIdx]);
8786                }
8787             }
8788             free(featureSets->featureSetsDownlinkPerCC->list.array);
8789          }
8790          free(featureSets->featureSetsDownlinkPerCC);
8791       }
8792       if(featureSets->featureSetsUplinkPerCC)
8793       {
8794          if(featureSets->featureSetsUplinkPerCC->list.array)
8795          {
8796             for(arrIdx = 0; arrIdx < featureSets->featureSetsUplinkPerCC->list.count; arrIdx++)
8797             {
8798                if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx])
8799                {
8800                   if(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL)
8801                      free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]->supportedModulationOrderUL);
8802                   free(featureSets->featureSetsUplinkPerCC->list.array[arrIdx]);
8803                }
8804             }
8805             free(featureSets->featureSetsUplinkPerCC->list.array);
8806          }
8807          free(featureSets->featureSetsUplinkPerCC);
8808       }
8809       free(ueNrCap->featureSets);
8810    }   
8811 }
8812
8813 /*******************************************************************
8814 *
8815 * @brief Function to free PdcchSearchSpcToAddModList
8816          where memory allocated by aper_decoder
8817 *
8818 * @details
8819 *
8820 *    Function : freeAperDecodePdcchSearchSpcToAddModList 
8821 *
8822 *    Functionality: Function to free PdcchSearchSpcToAddModList
8823 *
8824 * @params[in] struct PDCCH_Config__searchSpacesToAddModList *searchSpcList
8825 * @return void
8826 *
8827 * ****************************************************************/
8828
8829 void freeAperDecodePdcchSearchSpcToAddModList(struct PDCCH_Config__searchSpacesToAddModList *searchSpcList)
8830 {
8831    uint8_t searchSpcArrIdx=0;
8832    uint8_t searchSpcArrIdx1=0;
8833    struct  SearchSpace *searchSpc=NULLP;
8834
8835
8836    if(searchSpcList->list.array)
8837    {
8838       if(searchSpcList->list.array[searchSpcArrIdx1])
8839       {
8840          searchSpc = searchSpcList->list.array[searchSpcArrIdx1];
8841          if(searchSpc->controlResourceSetId)
8842          {
8843             if(searchSpc->monitoringSlotPeriodicityAndOffset)
8844             {
8845                if(searchSpc->monitoringSymbolsWithinSlot)
8846                {
8847                   if(searchSpc->monitoringSymbolsWithinSlot->buf)
8848                   {
8849                      if(searchSpc->nrofCandidates)
8850                      {
8851                         if(searchSpc->searchSpaceType)
8852                         {
8853                            free(searchSpc->searchSpaceType->choice.ue_Specific);
8854                            free(searchSpc->searchSpaceType);
8855                         }
8856                         free(searchSpc->nrofCandidates);
8857                      }
8858                      free(searchSpc->monitoringSymbolsWithinSlot->buf);
8859                   }
8860                   free(searchSpc->monitoringSymbolsWithinSlot);
8861                }
8862                free(searchSpc->monitoringSlotPeriodicityAndOffset);
8863             }
8864             free(searchSpc->controlResourceSetId);
8865          }
8866       }
8867       for(searchSpcArrIdx = 0; searchSpcArrIdx < searchSpcList->list.count; searchSpcArrIdx++)
8868       {
8869          free(searchSpcList->list.array[searchSpcArrIdx]);
8870       }
8871       free(searchSpcList->list.array);
8872    }
8873 }
8874 /*******************************************************************
8875 *
8876 * @brief Function for free part for the memory allocated by aper_decoder
8877
8878 * @details
8879 *
8880 *    Function : freeAperDecodeBWPDlDedPdcchConfig
8881 *
8882 *    Functionality: Function to free BWPDlDedPdcchConfig
8883 *
8884 * @params[in] 
8885 * @return void
8886 *
8887 * ****************************************************************/
8888
8889
8890 void freeAperDecodeBWPDlDedPdcchConfig(BWP_DownlinkDedicated_t *dlBwp)
8891 {
8892    uint8_t arrIdx1=0;
8893    uint8_t arrIdx2=0;
8894    struct PDCCH_Config *pdcchCfg=NULLP;
8895    struct ControlResourceSet *controlRSet=NULLP;
8896    struct PDCCH_Config__controlResourceSetToAddModList *controlRSetList=NULLP;
8897    
8898    if(dlBwp->pdcch_Config->choice.setup)
8899    {
8900       pdcchCfg=dlBwp->pdcch_Config->choice.setup;
8901       if(pdcchCfg->controlResourceSetToAddModList)
8902       {
8903          controlRSetList = pdcchCfg->controlResourceSetToAddModList;
8904          if(controlRSetList->list.array)
8905          {
8906             controlRSet = controlRSetList->list.array[arrIdx2];
8907             if(controlRSet)
8908             {
8909                if(controlRSet->frequencyDomainResources.buf)
8910                {
8911                   if(controlRSet->pdcch_DMRS_ScramblingID)
8912                   {
8913                      if(pdcchCfg->searchSpacesToAddModList)
8914                      {
8915                         freeAperDecodePdcchSearchSpcToAddModList(pdcchCfg->searchSpacesToAddModList);
8916                         free(pdcchCfg->searchSpacesToAddModList);
8917                      }
8918                      free(controlRSet->pdcch_DMRS_ScramblingID);
8919                   }
8920                   free(controlRSet->frequencyDomainResources.buf);
8921                }
8922             }
8923             for(arrIdx1 = 0; arrIdx1 <controlRSetList->list.count; arrIdx1++)
8924             {
8925                free(controlRSetList->list.array[arrIdx1]);
8926             }
8927             free(controlRSetList->list.array);
8928          }
8929          free(pdcchCfg->controlResourceSetToAddModList);
8930       }
8931       free(dlBwp->pdcch_Config->choice.setup);
8932    }
8933 }
8934 /*******************************************************************
8935 *
8936 * @brief Function to free PdschTimeDomAllocationList 
8937 *     where the memory allocated by aper_decoder
8938
8939 * @details
8940 *
8941 *    Function : freeAperDecodePdschTimeDomAllocationList
8942 *
8943 *    Functionality: Function to free PdschTimeDomAllocationList
8944 *
8945 * @params[in] struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList 
8946 * @return void
8947 *
8948 * ****************************************************************/
8949
8950
8951 void freeAperDecodePdschTimeDomAllocationList( struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList)
8952 {
8953    uint8_t arrIdx=0;
8954
8955    if(timeDomAllocList->choice.setup)
8956    {
8957       if(timeDomAllocList->choice.setup->list.array)
8958       {
8959          for(arrIdx = 0; arrIdx <timeDomAllocList->choice.setup->list.count ; arrIdx++)
8960          {
8961             free(timeDomAllocList->choice.setup->list.array[arrIdx]);
8962          }
8963          free(timeDomAllocList->choice.setup->list.array);
8964       }
8965       free(timeDomAllocList->choice.setup);
8966    }
8967 }
8968
8969 /*******************************************************************
8970 *
8971 * @brief Function to free BWPDlDedPdschConfig 
8972 *        where the memory allocated by aper_decoder
8973 *  
8974 * @details
8975 *
8976 *    Function : freeAperDecodeBWPDlDedPdschConfig 
8977 *
8978 *    Functionality: Function to free BWPDlDedPdschConfig 
8979 *
8980 * @params[in] BWP_DownlinkDedicated_t *dlBwp 
8981 * @return void
8982 *
8983 * ****************************************************************/
8984
8985
8986 void freeAperDecodeBWPDlDedPdschConfig(BWP_DownlinkDedicated_t *dlBwp)
8987 {
8988    struct PDSCH_Config *pdschCfg=NULLP;
8989    struct PDSCH_Config__prb_BundlingType *prbBndlType=NULLP;
8990    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAllocList=NULLP;
8991    struct PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA *dmrsDlCfg=NULLP;
8992
8993    if(dlBwp->pdsch_Config->choice.setup)
8994    {
8995       pdschCfg=dlBwp->pdsch_Config->choice.setup;
8996       if(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
8997       {
8998          if(pdschCfg->pdsch_TimeDomainAllocationList)
8999          {
9000             timeDomAllocList=pdschCfg->pdsch_TimeDomainAllocationList;
9001             if(pdschCfg->maxNrofCodeWordsScheduledByDCI)
9002             {
9003                prbBndlType=&pdschCfg->prb_BundlingType;
9004                free(prbBndlType->choice.staticBundling);
9005                free(pdschCfg->maxNrofCodeWordsScheduledByDCI);
9006             }
9007             freeAperDecodePdschTimeDomAllocationList(timeDomAllocList);
9008             free(pdschCfg->pdsch_TimeDomainAllocationList);
9009          }
9010          dmrsDlCfg=pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA;
9011          if(dmrsDlCfg->choice.setup)
9012          {
9013             free(dmrsDlCfg->choice.setup->dmrs_AdditionalPosition);
9014             free(dmrsDlCfg->choice.setup);
9015          }
9016          free(pdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA);
9017       }
9018       free(dlBwp->pdsch_Config->choice.setup);
9019    }
9020 }
9021 /*******************************************************************
9022 *
9023 * @brief Function to free PuschTimeDomAllocListCfg
9024                  where the memory allocated by aper_decoder
9025 *
9026 * @details
9027 *
9028 *    Function : freeAperDecodePuschTimeDomAllocListCfg
9029 *
9030 *    Functionality: Function to free PuschTimeDomAllocListCfg
9031 *
9032 * @params[in] PUSCH_Config_t *puschCfg 
9033 * @return void
9034 *
9035 * ****************************************************************/
9036
9037
9038 void freeAperDecodePuschTimeDomAllocListCfg(PUSCH_Config_t *puschCfg)
9039 {
9040    uint8_t arrIdx=0;
9041    uint8_t arrIdx1=0;
9042    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList_t=NULLP;
9043
9044    if(puschCfg->pusch_TimeDomainAllocationList)
9045    {
9046       timeDomAllocList_t=puschCfg->pusch_TimeDomainAllocationList;
9047       if(timeDomAllocList_t->choice.setup)
9048       {
9049          if(timeDomAllocList_t->choice.setup->list.array)
9050          {
9051             free(timeDomAllocList_t->choice.setup->list.array[arrIdx1]->k2);
9052             for(arrIdx = 0; arrIdx<timeDomAllocList_t->choice.setup->list.count; arrIdx++)
9053             {
9054                free(timeDomAllocList_t->choice.setup->list.array[arrIdx]);
9055             }
9056             free(timeDomAllocList_t->choice.setup->list.array);
9057          }
9058          free(timeDomAllocList_t->choice.setup);
9059       }
9060       free(puschCfg->transformPrecoder);
9061       free(puschCfg->pusch_TimeDomainAllocationList);
9062    }
9063 }
9064 /*******************************************************************
9065 *
9066 * @brief Function to free InitialUlBWPConfig where memory allocated by aper_decoder
9067 *
9068 * @details
9069 *
9070 *    Function : freeAperDecodeInitialUlBWPConfig 
9071 *
9072 *    Functionality: Function to free InitialUlBWPConfig
9073 *
9074 * @params[in]  BWP_UplinkDedicated_t *ulBwp
9075 * @return void
9076 *
9077 * ****************************************************************/
9078
9079
9080 void freeAperDecodeInitialUlBWPConfig(BWP_UplinkDedicated_t *ulBwp)
9081 {
9082    uint8_t  rSetIdx =0;
9083    uint8_t  rsrcIdx =0;
9084    SRS_Config_t   *srsCfg = NULLP;
9085    PUSCH_Config_t *puschCfg = NULLP;
9086    struct PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA *dmrsUlCfg = NULLP;
9087    struct SRS_Config__srs_ResourceSetToAddModList *rsrcSetList = NULLP;
9088    struct SRS_ResourceSet__srs_ResourceIdList *rsrcIdList = NULLP;
9089    struct SRS_Config__srs_ResourceToAddModList *resourceList = NULLP;
9090
9091    if(ulBwp->pusch_Config)
9092    {
9093       if(ulBwp->pusch_Config->choice.setup)
9094       {
9095          puschCfg=ulBwp->pusch_Config->choice.setup;
9096          if(puschCfg->dataScramblingIdentityPUSCH)
9097          {
9098             if(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA)
9099             {
9100                freeAperDecodePuschTimeDomAllocListCfg(puschCfg);
9101                dmrsUlCfg=puschCfg->dmrs_UplinkForPUSCH_MappingTypeA;
9102                if(dmrsUlCfg->choice.setup)
9103                {
9104                   if(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition)
9105                   {
9106                      if(dmrsUlCfg->choice.setup->transformPrecodingDisabled)
9107                      {
9108                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled->scramblingID0);
9109                         free(dmrsUlCfg->choice.setup->transformPrecodingDisabled);
9110                      }
9111                      free(dmrsUlCfg->choice.setup->dmrs_AdditionalPosition);
9112                   }
9113                   free(dmrsUlCfg->choice.setup);
9114                }
9115                free(puschCfg->dmrs_UplinkForPUSCH_MappingTypeA);
9116             }
9117             free(puschCfg->dataScramblingIdentityPUSCH);
9118          }
9119          free(ulBwp->pusch_Config->choice.setup);
9120       }
9121       free(ulBwp->pusch_Config);
9122
9123       /* Free SRS-Config */
9124       if(ulBwp->srs_Config)
9125       {
9126          if(ulBwp->srs_Config->choice.setup)
9127          {
9128             srsCfg = ulBwp->srs_Config->choice.setup;
9129
9130             /* Free Resource Set to add/mod list */
9131             if(srsCfg->srs_ResourceSetToAddModList)
9132             {
9133                rsrcSetList = srsCfg->srs_ResourceSetToAddModList;
9134                if(rsrcSetList->list.array)
9135                {
9136                   rSetIdx = 0;
9137
9138                   /* Free SRS resource Id list in this SRS resource set */
9139                   if(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList)
9140                   {
9141                      rsrcIdList =
9142                         rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList;
9143
9144                      if(rsrcIdList->list.array)
9145                      {
9146                         for(rsrcIdx = 0; rsrcIdx < rsrcIdList->list.count;
9147                               rsrcIdx++)
9148                         {
9149                            free(rsrcIdList->list.array[rsrcIdx]);
9150                         }
9151                         free(rsrcIdList->list.array);
9152                      }
9153                      free(rsrcSetList->list.array[rSetIdx]->srs_ResourceIdList);
9154                   }
9155
9156                   /* Free resource type info for this SRS resource set */
9157
9158                   free(rsrcSetList->list.array[rSetIdx]->resourceType.choice.aperiodic);
9159
9160                   /* Free memory for each resource set */
9161                   for(rSetIdx = 0; rSetIdx < rsrcSetList->list.count; rSetIdx++)
9162                   {
9163                      free(rsrcSetList->list.array[rSetIdx]);
9164                   }
9165                   free(rsrcSetList->list.array);
9166                }
9167                free(srsCfg->srs_ResourceSetToAddModList);
9168             }
9169
9170             /* Free resource to add/modd list */
9171             if(srsCfg->srs_ResourceToAddModList)
9172             {
9173                resourceList = srsCfg->srs_ResourceToAddModList;
9174                if(resourceList->list.array)
9175                {
9176                   rsrcIdx = 0;
9177
9178                   free(resourceList->list.array[rsrcIdx]->transmissionComb.choice.n2);
9179                   free(resourceList->list.array[rsrcIdx]->resourceType.choice.aperiodic);
9180
9181                   for(rsrcIdx = 0; rsrcIdx < resourceList->list.count; rsrcIdx++)
9182                   {
9183                      free(resourceList->list.array[rsrcIdx]);
9184                   }
9185                   free(resourceList->list.array);
9186                }
9187                free(srsCfg->srs_ResourceToAddModList);
9188             }
9189
9190             free(ulBwp->srs_Config->choice.setup);
9191          }
9192          free(ulBwp->srs_Config);
9193       }
9194    }
9195 }
9196 /*******************************************************************
9197 *
9198 * @brief Function to free initialUplinkBWPConfig where memory allocated by aper_decoder
9199 *
9200 * @details
9201 *
9202 *    Function : freeAperDecodeinitialUplinkBWPConfig
9203 *
9204 *    Functionality: Function to free initialUplinkBWPConfig
9205 *
9206 * @params[in] UplinkConfig_t *ulCfg 
9207 * @return void
9208 *
9209 * ****************************************************************/
9210
9211
9212 void freeAperDecodeinitialUplinkBWPConfig(UplinkConfig_t *ulCfg)
9213 {
9214    BWP_UplinkDedicated_t *ulBwp=NULLP;
9215    struct UplinkConfig__pusch_ServingCellConfig *puschCfg=NULLP;
9216    
9217    if(ulCfg->initialUplinkBWP)
9218    {
9219       ulBwp=ulCfg->initialUplinkBWP;
9220       if(ulCfg->firstActiveUplinkBWP_Id)
9221       {
9222          if(ulCfg->pusch_ServingCellConfig)
9223          {
9224             puschCfg=ulCfg->pusch_ServingCellConfig;
9225             if(puschCfg->choice.setup)
9226             {
9227                if(puschCfg->choice.setup->ext1)
9228                {
9229                   free(puschCfg->choice.setup->ext1->processingType2Enabled);
9230                   free(puschCfg->choice.setup->ext1->maxMIMO_Layers);
9231                   free(puschCfg->choice.setup->ext1);
9232                }
9233                free(puschCfg->choice.setup);
9234             }
9235             free(ulCfg->pusch_ServingCellConfig);
9236          }
9237          free(ulCfg->firstActiveUplinkBWP_Id);
9238       }
9239       freeAperDecodeInitialUlBWPConfig(ulBwp);
9240       free(ulCfg->initialUplinkBWP);
9241    }
9242 }
9243
9244 /*******************************************************************
9245  *
9246  * @brief Function to free DuUeCfg
9247  *
9248  * @details
9249  *
9250  *    Function : freeDuUeCfg
9251  *
9252  *    Functionality: Function to free DuUeCfg
9253  *
9254  * @params[in] DuUeCfg *ueCfg
9255  * @return void
9256  *
9257  * ****************************************************************/
9258 void freeDuUeCfg(DuUeCfg *ueCfg)
9259 {
9260    uint8_t lcIdx = 0;
9261    uint8_t arrIdx = 0;
9262    SpCellConfig_t *spCellCfg = NULLP;
9263    ServingCellConfig_t *srvCellCfg = NULLP;
9264    BWP_DownlinkDedicated_t *dlBwp = NULLP;
9265    MAC_CellGroupConfig_t *macCellGrpCfg = NULLP;
9266    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
9267    struct CellGroupConfigRrc__rlc_BearerToAddModList *rlcBearerList = NULLP;
9268    struct RLC_Config *rlcConfig = NULLP;
9269    struct LogicalChannelConfig *macLcConfig = NULLP;
9270    struct SchedulingRequestConfig *schedulingRequestConfig = NULLP;
9271    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqList = NULLP;
9272    struct TAG_Config *tagConfig = NULLP;
9273    struct TAG_Config__tag_ToAddModList *tagList = NULLP;
9274    struct MAC_CellGroupConfig__phr_Config *phrConfig = NULLP;
9275    struct ServingCellConfig__pdsch_ServingCellConfig *pdschCfg = NULLP;
9276    CellGroupConfigRrc_t *cellGrpCfg = ueCfg->cellGrpCfg;
9277   
9278    if(ueCfg->ueNrCapability)
9279    {
9280       freeAperDecodeUeNrCapability(ueCfg->ueNrCapability);
9281       DU_FREE(ueCfg->ueNrCapability, sizeof(UE_NR_Capability_t));
9282       ueCfg->ueNrCapability = NULLP;
9283    }
9284
9285    if(ueCfg->cellGrpCfg)
9286    {
9287       
9288       rlcBearerList = cellGrpCfg->rlc_BearerToAddModList;
9289       if(rlcBearerList)
9290       {
9291          if(rlcBearerList->list.array)
9292          {
9293             for(arrIdx=0; arrIdx<rlcBearerList->list.count; arrIdx++)
9294             {
9295                if(rlcBearerList->list.array[arrIdx])
9296                {
9297                   rlcConfig   = rlcBearerList->list.array[arrIdx]->rlc_Config;
9298                   macLcConfig = rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig;
9299                   
9300                   if(rlcBearerList->list.array[arrIdx]->servedRadioBearer)
9301                   {
9302                      free(rlcBearerList->list.array[arrIdx]->servedRadioBearer);
9303                   }
9304                   if(rlcConfig)
9305                   {
9306                      if(rlcConfig->choice.am)
9307                      {
9308                         free(rlcConfig->choice.am->ul_AM_RLC.sn_FieldLength);
9309                         free(rlcConfig->choice.am->dl_AM_RLC.sn_FieldLength);
9310                         free(rlcConfig->choice.am);
9311                      }
9312                      free(rlcBearerList->list.array[arrIdx]->rlc_Config);
9313                   }
9314                   if(macLcConfig)
9315                   {
9316                      if(macLcConfig->ul_SpecificParameters)
9317                      {
9318                         free(macLcConfig->ul_SpecificParameters->schedulingRequestID);
9319                         free(macLcConfig->ul_SpecificParameters->logicalChannelGroup);
9320                         free(macLcConfig->ul_SpecificParameters);
9321                      }
9322                      free(rlcBearerList->list.array[arrIdx]->mac_LogicalChannelConfig);
9323                   }
9324                   free(rlcBearerList->list.array[arrIdx]); 
9325                }
9326             }
9327             free(rlcBearerList->list.array);
9328          }
9329          free(cellGrpCfg->rlc_BearerToAddModList);
9330       }
9331
9332       macCellGrpCfg = cellGrpCfg->mac_CellGroupConfig;
9333       if(macCellGrpCfg)
9334       {
9335          schedulingRequestConfig = macCellGrpCfg->schedulingRequestConfig;
9336          if(schedulingRequestConfig)
9337          {
9338             schReqList = schedulingRequestConfig->schedulingRequestToAddModList;
9339             if(schReqList)
9340             {
9341                if(schReqList->list.array)
9342                {
9343                   for(arrIdx=0;arrIdx<schReqList->list.count; arrIdx++)
9344                   {
9345                      if(schReqList->list.array[arrIdx])
9346                      {
9347                         free(schReqList->list.array[arrIdx]->sr_ProhibitTimer); 
9348                         free(schReqList->list.array[arrIdx]);
9349                      }
9350                   }
9351                   free(schReqList->list.array);
9352                }
9353                free(schedulingRequestConfig->schedulingRequestToAddModList);
9354             }
9355             free(macCellGrpCfg->schedulingRequestConfig);
9356          }
9357          if(macCellGrpCfg->bsr_Config)
9358          {
9359             free(macCellGrpCfg->bsr_Config);
9360          }
9361          tagConfig = macCellGrpCfg->tag_Config;
9362          if(tagConfig)
9363          {
9364             tagList = tagConfig->tag_ToAddModList;
9365             if(tagList)
9366             {
9367                if(tagList->list.array)
9368                {
9369                   for(arrIdx=0; arrIdx<tagList->list.count; arrIdx++)
9370                   {
9371                      free(tagList->list.array[arrIdx]);
9372                   }
9373                   free(tagList->list.array);
9374                }
9375                free(tagConfig->tag_ToAddModList);
9376             }
9377             free(tagConfig); 
9378          }
9379
9380          phrConfig = macCellGrpCfg->phr_Config;
9381          if(phrConfig)
9382          {
9383             free(phrConfig->choice.setup); 
9384             free(phrConfig); 
9385          }
9386
9387          free(macCellGrpCfg); 
9388       }
9389
9390       phyCellGrpCfg = cellGrpCfg->physicalCellGroupConfig;
9391       if(phyCellGrpCfg)
9392       {
9393          free(phyCellGrpCfg->p_NR_FR1);
9394          free(phyCellGrpCfg); 
9395       }
9396
9397       spCellCfg = cellGrpCfg->spCellConfig;
9398       if(spCellCfg)
9399       {
9400          if(spCellCfg->servCellIndex)
9401          {
9402             if(spCellCfg->rlmInSyncOutOfSyncThreshold)
9403             {
9404                if(spCellCfg->spCellConfigDedicated)
9405                {
9406                   srvCellCfg = spCellCfg->spCellConfigDedicated;
9407                   if(srvCellCfg->initialDownlinkBWP)
9408                   {
9409                      dlBwp = srvCellCfg->initialDownlinkBWP;
9410                      if(srvCellCfg->firstActiveDownlinkBWP_Id)
9411                      {
9412                         if(srvCellCfg->defaultDownlinkBWP_Id)
9413                         {
9414                            if(srvCellCfg->uplinkConfig)
9415                            {
9416
9417                               if(srvCellCfg->pdsch_ServingCellConfig)
9418                               {
9419                                  pdschCfg=
9420                                     srvCellCfg->pdsch_ServingCellConfig;
9421                                  if(pdschCfg->choice.setup)
9422                                  {
9423
9424                                     free(pdschCfg->choice.setup->nrofHARQ_ProcessesForPDSCH);
9425                                     free(pdschCfg->choice.setup);
9426                                  }
9427
9428                                  free(srvCellCfg->pdsch_ServingCellConfig);
9429                               }
9430
9431                               freeAperDecodeinitialUplinkBWPConfig(srvCellCfg->uplinkConfig);
9432                               free(srvCellCfg->uplinkConfig);
9433                            }
9434                            free(srvCellCfg->defaultDownlinkBWP_Id);
9435                         }
9436
9437                         free(srvCellCfg->firstActiveDownlinkBWP_Id);
9438                      }
9439                      if(dlBwp->pdcch_Config)
9440                      {
9441                         if(dlBwp->pdsch_Config)
9442                         {
9443                            freeAperDecodeBWPDlDedPdschConfig(dlBwp);
9444                            free(dlBwp->pdsch_Config);
9445                         }
9446                         freeAperDecodeBWPDlDedPdcchConfig(dlBwp);
9447                         free(dlBwp->pdcch_Config);
9448                      }
9449                      free(srvCellCfg->initialDownlinkBWP);
9450                   }
9451
9452                   free(spCellCfg->spCellConfigDedicated);
9453                }
9454                free(spCellCfg->rlmInSyncOutOfSyncThreshold);
9455             }
9456             free(spCellCfg->servCellIndex); 
9457          }
9458          free(spCellCfg);
9459       }
9460       DU_FREE(ueCfg->cellGrpCfg, sizeof(CellGroupConfigRrc_t));
9461       ueCfg->cellGrpCfg = NULLP;
9462    }
9463    if(ueCfg->ambrCfg)
9464    {
9465       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCfg->ambrCfg, sizeof(AmbrCfg));
9466    }
9467    for(lcIdx = 0; lcIdx < ueCfg->numRlcLcs; lcIdx++)
9468    {
9469       freeRlcLcCfg(&ueCfg->rlcLcCfg[lcIdx]);
9470    }
9471    for(lcIdx = 0; lcIdx < ueCfg->numMacLcs; lcIdx++)
9472    {
9473       freeMacLcCfg(&ueCfg->macLcCfg[lcIdx]);
9474    }
9475    for(lcIdx = 0; lcIdx < ueCfg->numDrb; lcIdx++)
9476    {
9477       DU_FREE(ueCfg->upTnlInfo[lcIdx].tnlCfg1, sizeof(GtpTnlCfg));
9478    }
9479 }
9480
9481 /*******************************************************************
9482  *
9483  * @brief Function to free UecontextSetupDb
9484  *
9485  * @details
9486  *
9487  *    Function : freeF1UeDb
9488  *
9489  *    Functionality: Function to free UecontextSetupDb
9490  *
9491  * @params[in] UecontextSetupDb *
9492  * @return void
9493  *
9494  * ****************************************************************/
9495
9496 void freeF1UeDb(F1UeContextSetupDb *f1UeDb)
9497 {
9498    
9499    if(f1UeDb->dlRrcMsg)
9500    {
9501       if(f1UeDb->dlRrcMsg->rrcMsgPdu)
9502       {
9503         //DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,\
9504                f1UeDb->dlRrcMsg->rrcMsgPdu, f1UeDb->dlRrcMsg->rrcMsgSize);
9505       }
9506       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
9507    }
9508    freeDuUeCfg(&f1UeDb->duUeCfg);
9509    memset(f1UeDb, 0, sizeof(F1UeContextSetupDb));
9510    DU_FREE(f1UeDb, sizeof(F1UeContextSetupDb));
9511 }
9512
9513 /*******************************************************************
9514  *
9515  * @brief Function to build Am cfg Info
9516  *
9517  * @details
9518  *
9519  *    Function : extractRlcAmCfg
9520  *
9521  *    Functionality: Function to build Am cfg Info
9522  *
9523  * @params[in] AmBearerCfg *
9524  *             void *
9525  *
9526  * @return ROK/RFAILED
9527  *
9528  * ****************************************************************/
9529
9530 void extractRlcAmCfg(AmBearerCfg *amCfgToSet, struct RLC_Config__am *rlcAmCfg)
9531 {
9532    if(rlcAmCfg)
9533    {
9534       /* UL AM */
9535       if(rlcAmCfg->dl_AM_RLC.sn_FieldLength)
9536       {
9537          amCfgToSet->ulAmCfg.snLenUl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->dl_AM_RLC.sn_FieldLength));
9538          /*TODO: Check the timer value when sent by real CU */
9539          amCfgToSet->ulAmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_Reassembly); 
9540          amCfgToSet->ulAmCfg.statProhTmr = convertProhibitTmrEnumToValue(rlcAmCfg->dl_AM_RLC.t_StatusProhibit);
9541       }
9542
9543       /* DL AM */
9544       if(rlcAmCfg->ul_AM_RLC.sn_FieldLength)
9545       {
9546          amCfgToSet->dlAmCfg.snLenDl = covertAmSnLenFromRrcEnumToIntEnum(*(rlcAmCfg->ul_AM_RLC.sn_FieldLength));
9547          amCfgToSet->dlAmCfg.pollRetxTmr = covertPollRetxTmrEnumToValue(rlcAmCfg->ul_AM_RLC.t_PollRetransmit);
9548          amCfgToSet->dlAmCfg.pollPdu   = covertPollPduEnumToValue(rlcAmCfg->ul_AM_RLC.pollPDU);
9549          amCfgToSet->dlAmCfg.pollByte  = covertPollByteEnumToValue(rlcAmCfg->ul_AM_RLC.pollByte);
9550          amCfgToSet->dlAmCfg.maxRetxTh = covertMaxRetxEnumToValue(rlcAmCfg->ul_AM_RLC.maxRetxThreshold);
9551       }
9552    }
9553 }
9554
9555 /*******************************************************************
9556  *
9557  * @brief Function to build Um Bi Info
9558  *
9559  * @details
9560  *
9561  *    Function : extractRlcUmBiCfg
9562  *
9563  *    Functionality: Function to build Um Bi Info
9564  *
9565  * @params[in] UmBiDirBearerCfg *
9566  *             void *
9567  *
9568  * @return ROK/RFAILED
9569  *
9570  * ****************************************************************/
9571
9572 void extractRlcUmBiCfg(UmBiDirBearerCfg *umBiCfgToSet, struct RLC_Config__um_Bi_Directional *rlcBiCfg)
9573 {
9574    if(rlcBiCfg)
9575    {
9576       /* UL UM BI DIR Cfg */
9577       if(rlcBiCfg->dl_UM_RLC.sn_FieldLength)
9578       {
9579          umBiCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->dl_UM_RLC.sn_FieldLength));
9580          umBiCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(rlcBiCfg->dl_UM_RLC.t_Reassembly);
9581       }
9582
9583       /* DL UM BI DIR Cfg */
9584       if(rlcBiCfg->ul_UM_RLC.sn_FieldLength)
9585          umBiCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(rlcBiCfg->ul_UM_RLC.sn_FieldLength));
9586    }
9587 }
9588
9589 /*******************************************************************
9590  *
9591  * @brief Function to build Um Ul Info
9592  *
9593  * @details
9594  *
9595  *    Function : extractRlcUmUlCfg
9596  *
9597  *    Functionality: Function to build Um Ul Info
9598  *
9599  * @params[in] UmUniDirUlBearerCfg *
9600  *             void *
9601  *
9602  * @return ROK/RFAILED
9603  *
9604  * ****************************************************************/
9605
9606 void extractRlcUmUlCfg(UmUniDirUlBearerCfg *umUlCfgToSet, struct RLC_Config__um_Uni_Directional_DL *umUlCfg)
9607 {
9608    if(umUlCfg)
9609    {
9610       if(umUlCfg->dl_UM_RLC.sn_FieldLength)
9611       {
9612          umUlCfgToSet->ulUmCfg.snLenUlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umUlCfg->dl_UM_RLC.sn_FieldLength));
9613          umUlCfgToSet->ulUmCfg.reAssemTmr = convertReasmblTmrEnumToValue(umUlCfg->dl_UM_RLC.t_Reassembly);
9614       }
9615    }
9616 }
9617
9618 /*******************************************************************
9619  *
9620  * @brief Function to build Um Uni Dl Info
9621  *
9622  * @details
9623  *
9624  *    Function : extractRlcUmDlCfg
9625  *
9626  *    Functionality: Function to build Um Uni Dl Info
9627  *
9628  * @params[in] UmUniDirDlBearerCfg *
9629  *             void *
9630  *
9631  * @return ROK/RFAILED
9632  *
9633  * ****************************************************************/
9634 void extractRlcUmDlCfg(UmUniDirDlBearerCfg *umDlCfgToSet, struct RLC_Config__um_Uni_Directional_UL *umDlCfg)
9635 {
9636    if(umDlCfg)
9637    {
9638       if(umDlCfg->ul_UM_RLC.sn_FieldLength)
9639          umDlCfgToSet->dlUmCfg.snLenDlUm  = covertUmSnLenFromRrcEnumToIntEnum(*(umDlCfg->ul_UM_RLC.sn_FieldLength));
9640    }
9641 }
9642
9643 /*******************************************************************
9644  *
9645  * @brief Function to extractRlcModeCfg
9646  *
9647  * @details
9648  *
9649  *    Function : extractRlcModeCfg
9650  *
9651  *    Functionality: Function to extractRlcModeCfg
9652  *
9653  * @params[in] RLC_Config_t *
9654  *             RlcBearerCfg *
9655  *             void  *    
9656  * @return ROK/RFAILED
9657  *
9658  * ****************************************************************/
9659 void extractRlcModeCfg(uint8_t rlcMode, RlcBearerCfg *rlcDbCfg, RLC_Config_t *lcCfg)
9660 {
9661    if(lcCfg)
9662    {
9663       switch(rlcMode)
9664       {
9665          case RLC_AM :
9666             {
9667                if(lcCfg->choice.am)
9668                {
9669                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.amCfg, sizeof(AmBearerCfg));
9670                   if(rlcDbCfg->u.amCfg)
9671                      extractRlcAmCfg(rlcDbCfg->u.amCfg, lcCfg->choice.am);
9672                }
9673                break;
9674             }
9675          case RLC_UM_BI_DIRECTIONAL :
9676             {
9677                if(lcCfg->choice.um_Bi_Directional)
9678                {
9679                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
9680                   if(rlcDbCfg->u.umBiDirCfg)
9681                      extractRlcUmBiCfg(rlcDbCfg->u.umBiDirCfg, lcCfg->choice.um_Bi_Directional);
9682                }
9683                break;
9684             }
9685          case RLC_UM_UNI_DIRECTIONAL_UL :
9686             {
9687                if(lcCfg->choice.um_Uni_Directional_DL)
9688                {
9689                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
9690                   if(rlcDbCfg->u.umUniDirUlCfg)
9691                      extractRlcUmUlCfg(rlcDbCfg->u.umUniDirUlCfg, lcCfg->choice.um_Uni_Directional_DL);
9692                }
9693                break;
9694             }
9695          case RLC_UM_UNI_DIRECTIONAL_DL :
9696             {
9697                if(lcCfg->choice.um_Uni_Directional_UL)
9698                {
9699                   DU_ALLOC_SHRABL_BUF(rlcDbCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
9700                   if(rlcDbCfg->u.umUniDirDlCfg)
9701                      extractRlcUmDlCfg(rlcDbCfg->u.umUniDirDlCfg, lcCfg->choice.um_Uni_Directional_UL);
9702                }
9703                break;
9704             }
9705          default:
9706             DU_LOG("\nERROR  -->  DUAPP: Invalid rlcMode %d at extractRlcCfgToAddMod()", rlcMode);
9707             break;
9708       }
9709    }
9710 }
9711
9712 /*******************************************************************
9713  *
9714  * @brief Function to extract extractUlLcCfg
9715  *
9716  * @details
9717  *
9718  *    Function : extractUlLcCfg
9719  *
9720  *    Functionality: Function to extract extractUlLcCfg
9721  *
9722  * @params[in] UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg
9723  * @return void
9724  *
9725  * ****************************************************************/
9726
9727 void extractUlLcCfg(UlLcCfg *f1UlLcCfg, LogicalChannelConfig_t *ulLcCfg)
9728 {
9729    if(ulLcCfg)
9730    {
9731       if(ulLcCfg->ul_SpecificParameters)
9732       {
9733          f1UlLcCfg->priority = \
9734             ulLcCfg->ul_SpecificParameters->priority;
9735       if(ulLcCfg->ul_SpecificParameters->logicalChannelGroup)
9736       {
9737          f1UlLcCfg->lcGroup = \
9738            *(ulLcCfg->ul_SpecificParameters->logicalChannelGroup);
9739       }
9740       if(ulLcCfg->ul_SpecificParameters->schedulingRequestID)
9741       {
9742          f1UlLcCfg->schReqId = \
9743            *(ulLcCfg->ul_SpecificParameters->schedulingRequestID);
9744       }
9745       f1UlLcCfg->pbr = \
9746          ulLcCfg->ul_SpecificParameters->prioritisedBitRate;
9747       f1UlLcCfg->bsd = \
9748          ulLcCfg->ul_SpecificParameters->bucketSizeDuration;
9749       }
9750    }
9751 }
9752
9753 /*******************************************************************
9754 *
9755 * @brief Function to extract Snssai Cfg Info from CU
9756 *
9757 * @details
9758 *
9759 *    Function : extractDrbSnssaiCfg
9760 *
9761 *    Functionality: Function to extract Drb Snssai Cfg Info from CU
9762 *
9763 * @params[in] DRB_Information_t *drbInfo, Snssai  *snssai
9764 * @return ROK/RFAILED
9765 *
9766 * ****************************************************************/
9767
9768 uint8_t extractDrbSnssaiCfg(SNSSAI_t *RecvSnssai, Snssai **snssaiToBeShared)
9769 {
9770    if(!(*snssaiToBeShared))
9771    {
9772       DU_ALLOC_SHRABL_BUF((*snssaiToBeShared), sizeof(Snssai));
9773       if(snssaiToBeShared == NULLP)
9774       {
9775          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Memory failed at allocating for SNSSAI ");
9776          return RFAILED;
9777       }
9778    }
9779    if(RecvSnssai)
9780    {
9781       memcpy(&(*snssaiToBeShared)->sst, RecvSnssai->sST.buf, RecvSnssai->sST.size);
9782       if(RecvSnssai->sD)
9783       {
9784          memcpy((*snssaiToBeShared)->sd, RecvSnssai->sD->buf,  RecvSnssai->sD->size);
9785       }
9786       else
9787       {
9788          DU_LOG("\nERROR  -->  DUAPP : extractDrbSnssaiCfg(): Received Null pointer of Snssai->SD");
9789          return RFAILED;
9790       }
9791    }
9792    return ROK;
9793 }
9794
9795 /*******************************************************************
9796  *
9797  * @brief Function to procRlcLcCfg
9798  *
9799  * @details
9800  *
9801  *    Function : procRlcLcCfg
9802  *
9803  *    Functionality: Function to procRlcLcCfg
9804  *
9805  * @params[in] rbId, lcId, rbType, rlcMod
9806  *             RLC_Config_t *, RlcBearerCfg * , 
9807  * @return void
9808  *
9809  * ****************************************************************/
9810
9811 void procRlcLcCfg(uint8_t rbId, uint8_t lcId, uint8_t rbType, uint8_t rlcMode,\
9812    uint8_t configType, RLC_Config_t *f1RlcCfg, RlcBearerCfg *lcCfg, QoSInformation_t *qoSInformation)
9813 {
9814    DRB_Information_t *drbInfo;
9815
9816    lcCfg->rbId   = rbId;
9817    lcCfg->configType = configType;
9818
9819    if(rbType == RB_TYPE_SRB)
9820    {
9821       lcCfg->rbType = RB_TYPE_SRB;
9822       lcCfg->lcId   = rbId;
9823       lcCfg->lcType = LCH_DCCH;
9824       lcCfg->rlcMode = RLC_AM;
9825    }
9826    else if(rbType == RB_TYPE_DRB)
9827    {
9828       lcCfg->rbType = RB_TYPE_DRB;
9829       lcCfg->lcId   = lcId;
9830       lcCfg->lcType = LCH_DTCH;
9831       lcCfg->rlcMode = rlcMode;
9832    }
9833    if(f1RlcCfg) /* rlc mode config recived */
9834    {
9835       extractRlcModeCfg(lcCfg->rlcMode, lcCfg, f1RlcCfg);
9836    }
9837    if(qoSInformation != NULLP)
9838    {
9839       if(qoSInformation->present == QoSInformation_PR_choice_extension)
9840       {
9841          if(qoSInformation->choice.choice_extension->value.present ==\
9842                QoSInformation_ExtIEs__value_PR_DRB_Information)
9843          {
9844             drbInfo = &qoSInformation->choice.choice_extension->value.choice.DRB_Information; 
9845             if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &lcCfg->snssai) != ROK)
9846             {
9847                DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information at procRlcLcCfg()");
9848                return;
9849             }
9850          }
9851       }
9852    }
9853 }
9854
9855 /*******************************************************************
9856  *
9857  * @brief Fills DrbQos Info received by CU
9858  *
9859  * @details
9860  *
9861  *    Function : extractQosInfo
9862  *
9863  *    Functionality: Fills DrbQos Info received  by CU
9864  *
9865  * @params[in] DrbQosInfo *qosToAdd, 
9866  *             QoSFlowLevelQoSParameters_t *qosFlowCfg
9867  * @return void
9868  *
9869  * ****************************************************************/
9870
9871 void extractQosInfo(DrbQosInfo *qosToAdd, QoSFlowLevelQoSParameters_t *qosFlowCfg)
9872 {
9873    uint8_t qosCntIdx = 0;
9874    ProtocolExtensionContainer_4624P74_t *qosIeExt = NULLP;
9875
9876    qosToAdd->fiveQiType = qosFlowCfg->qoS_Characteristics.present;
9877    qosToAdd->u.nonDyn5Qi.fiveQi     =\
9878                                      qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->fiveQI;
9879    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow)
9880    {
9881       qosToAdd->u.nonDyn5Qi.avgWindow = \
9882                                         *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
9883    }
9884
9885    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume)
9886    {
9887       qosToAdd->u.nonDyn5Qi.maxDataBurstVol = \
9888                                               *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
9889    }
9890
9891    if(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel)
9892    {
9893       qosToAdd->u.nonDyn5Qi.priorLevel = \
9894                                          *(qosFlowCfg->qoS_Characteristics.choice.non_Dynamic_5QI->qoSPriorityLevel);
9895    }
9896    qosToAdd->ngRanRetPri.priorityLevel = \
9897                                          qosFlowCfg->nGRANallocationRetentionPriority.priorityLevel; 
9898    qosToAdd->ngRanRetPri.preEmptionCap = \
9899                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionCapability;
9900    qosToAdd->ngRanRetPri.preEmptionVul = \
9901                                          qosFlowCfg->nGRANallocationRetentionPriority.pre_emptionVulnerability;
9902    if(qosFlowCfg->gBR_QoS_Flow_Information)
9903    {
9904       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateDl, \
9905             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.buf, \
9906             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateDownlink.size);
9907       memcpy(&qosToAdd->grbQosInfo.maxFlowBitRateUl, \
9908             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.buf, \
9909             qosFlowCfg->gBR_QoS_Flow_Information->maxFlowBitRateUplink.size);
9910       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateDl,\
9911             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.buf, \
9912             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateDownlink.size);
9913       memcpy(&qosToAdd->grbQosInfo.guarFlowBitRateUl,\
9914             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.buf, \
9915             qosFlowCfg->gBR_QoS_Flow_Information->guaranteedFlowBitRateUplink.size);
9916    }
9917    /*Extracting PDU_SESSION_ID*/
9918    qosIeExt = (ProtocolExtensionContainer_4624P74_t *)qosFlowCfg->iE_Extensions;
9919    if(qosIeExt)
9920    {
9921       for(qosCntIdx = 0; qosCntIdx < qosIeExt->list.count; qosCntIdx++)
9922       {
9923          if(qosIeExt->list.array[qosCntIdx]->extensionValue.present == \
9924                QoSFlowLevelQoSParameters_ExtIEs__extensionValue_PR_PDUSessionID)
9925          {
9926             qosToAdd->pduSessionId = qosIeExt->list.array[qosCntIdx]->extensionValue.choice.PDUSessionID;
9927             DU_LOG("\nDEBUG -->  DU_F1AP : extractQosInfo: PDU SessionID:%d",qosToAdd->pduSessionId);
9928          }
9929       }  
9930    }
9931    qosToAdd->ulPduSessAggMaxBitRate = 0;
9932 }
9933
9934 /*******************************************************************
9935  *
9936  * @brief Function to extract GTP Tunnel Info from CU
9937  *
9938  * @details
9939  *
9940  *    Function : extractUpTnlInfo
9941  *
9942  *    Functionality: Function to extract GTP Tunnel Info from CU
9943  *
9944  * @params[in] F1AP message
9945  * @return ROK/RFAILED
9946  *
9947  * ****************************************************************/
9948
9949 uint8_t extractUpTnlInfo(uint8_t drbId, uint8_t configType,\
9950    ULUPTNLInformation_ToBeSetup_List_t *tnlInfo, UpTnlCfg *upTnlInfo)
9951 {
9952    uint8_t tnlIdx;
9953    uint32_t ipv4_du = 0;
9954    GTPTunnel_t *gtpTunnel = NULLP;
9955
9956    upTnlInfo->drbId = drbId; 
9957    upTnlInfo->configType = configType;
9958 #ifdef O1_ENABLE
9959    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
9960 #else
9961    cmInetAddr((char *)DU_IP_V4_ADDR, &ipv4_du);
9962 #endif
9963
9964    for(tnlIdx=0; tnlIdx < tnlInfo->list.count; tnlIdx++)
9965    {
9966       if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.present == UPTransportLayerInformation_PR_gTPTunnel)
9967       {
9968          if(tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel)
9969          {
9970             gtpTunnel = tnlInfo->list.array[tnlIdx]->uLUPTNLInformation.choice.gTPTunnel;
9971             DU_ALLOC(upTnlInfo->tnlCfg1, sizeof(GtpTnlCfg));
9972             if(upTnlInfo->tnlCfg1 == NULLP)
9973             {
9974                DU_LOG("\nERROR  -->  F1AP : extractUpTnlInfo: Failed to allocate mmeory for tunnel cfg 1");
9975                return RFAILED;
9976             }
9977             bitStringToInt(&gtpTunnel->transportLayerAddress, &upTnlInfo->tnlCfg1->ulTnlAddress);
9978             upTnlInfo->tnlCfg1->dlTnlAddress = ipv4_du;
9979             if(gtpTunnel->gTP_TEID.size > 0)
9980             {
9981                teIdStringToInt(gtpTunnel->gTP_TEID.buf, &upTnlInfo->tnlCfg1->teId);
9982             }
9983          }
9984          break;
9985       }
9986    }
9987    return ROK;
9988 }
9989
9990 /*******************************************************************
9991 *
9992 * @brief Function to extract Drb Qos Cfg Info from CU
9993 *
9994 * @details
9995 *
9996 *    Function : extractDrbQosCfg 
9997 *
9998 *    Functionality: Function to extract Drb Qos Cfg Info from CU
9999 *
10000 * @params[in] DRB_Information_t *drbInfo, LcCfg *macLcToAdd
10001 * @return ROK/RFAILED
10002 *
10003 * ****************************************************************/
10004
10005 uint8_t extractDrbQosCfg(DRB_Information_t *drbInfo, LcCfg *macLcToAdd ) 
10006 {
10007    if(!macLcToAdd->drbQos)
10008    {
10009       DU_ALLOC_SHRABL_BUF(macLcToAdd->drbQos, sizeof(DrbQosInfo));
10010       if(macLcToAdd->drbQos == NULLP)
10011       {
10012          DU_LOG("\nERROR  -->  DUAPP:Memory failed at allocating DrbQos at extractDrbQosCfg()");
10013          return RFAILED;
10014       }
10015
10016    }
10017    if(drbInfo->dRB_QoS.qoS_Characteristics.present == QoS_Characteristics_PR_non_Dynamic_5QI)
10018    {
10019       extractQosInfo(macLcToAdd->drbQos, &drbInfo->dRB_QoS);
10020       macLcToAdd->dlLcCfg.lcp = macLcToAdd->drbQos->ngRanRetPri.priorityLevel;
10021    }
10022    if(extractDrbSnssaiCfg(&drbInfo->sNSSAI, &macLcToAdd->snssai) != ROK)
10023    {
10024       DU_LOG("\nERROR  -->  DUAPP: Unable to extract Snssai information  at extractDrbQosCfg()");
10025       return RFAILED;
10026    }
10027    return ROK;
10028 }
10029 /*******************************************************************
10030  *
10031  * @brief Function to extract DRB info received from CU
10032  *
10033  * @details
10034  *
10035  *    Function : extractDrbCfg
10036  *
10037  *    Functionality: Function to extract DRB info received from CU
10038  *
10039  * @params[in] F1AP message
10040  * @return void
10041  *
10042  * ****************************************************************/
10043 uint8_t extractDrbCfg(DRBs_ToBeSetup_Item_t *drbItem, DRBs_ToBeSetupMod_Item_t *drbSetupModItem,\
10044 DRBs_ToBeModified_Item_t *drbModItem,  LcCfg *macLcToAdd, UpTnlCfg *upTnlInfo)
10045 {
10046    DRB_Information_t *drbInfo = NULLP;
10047
10048    if(drbItem != NULLP)
10049    {
10050       if(extractUpTnlInfo(drbItem->dRBID, CONFIG_ADD, &drbItem->uLUPTNLInformation_ToBeSetup_List, upTnlInfo) != ROK)
10051       {
10052          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10053          return RFAILED;
10054       }
10055       if(drbItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10056       {
10057          if(drbItem->qoSInformation.choice.choice_extension->value.present == QoSInformation_ExtIEs__value_PR_DRB_Information)
10058          {
10059             drbInfo = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10060             if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
10061             {
10062                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");
10063                return RFAILED;
10064             }
10065          }
10066       }
10067    }
10068    else if(drbSetupModItem != NULLP)
10069    {
10070       if(extractUpTnlInfo(drbSetupModItem->dRBID, CONFIG_ADD, &drbSetupModItem->uLUPTNLInformation_ToBeSetup_List,\
10071       upTnlInfo) != ROK)
10072       {
10073          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10074          return RFAILED;
10075       }
10076       if(drbSetupModItem->qoSInformation.present == QoSInformation_PR_choice_extension)
10077       {
10078          if(drbSetupModItem->qoSInformation.choice.choice_extension->value.present ==\
10079          QoSInformation_ExtIEs__value_PR_DRB_Information)
10080          {
10081             drbInfo = &drbSetupModItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information;
10082             if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
10083             {
10084                DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10085                return RFAILED;
10086             }
10087
10088          }
10089       }
10090    }
10091    else if(drbModItem != NULLP)
10092    {
10093       if(extractUpTnlInfo(drbModItem->dRBID, CONFIG_MOD, &drbModItem->uLUPTNLInformation_ToBeSetup_List,\
10094       upTnlInfo) != ROK)
10095       {
10096          DU_LOG("\nERROR  -->  DUAPP : Failed to extract tunnel Cfg at extractDrbCfg()");
10097          return RFAILED;
10098       }
10099       if(drbModItem->qoSInformation != NULLP)
10100       {
10101          if(drbModItem->qoSInformation->present == QoSInformation_PR_choice_extension)
10102          {
10103             if(drbModItem->qoSInformation->choice.choice_extension->value.present ==\
10104                   QoSInformation_ExtIEs__value_PR_DRB_Information)
10105             {
10106                drbInfo = &drbModItem->qoSInformation->choice.choice_extension->value.choice.DRB_Information;
10107                if(extractDrbQosCfg(drbInfo , macLcToAdd) != ROK)
10108                {
10109                   DU_LOG("\nERROR  -->  DUAPP : Failed to extract qos Cfg at extractDrbCfg()");  
10110                   return RFAILED;
10111                }
10112
10113             }
10114          }
10115       }
10116    }
10117    return ROK;
10118 }
10119
10120 /*******************************************************************
10121  *
10122  * @brief Function to extract RB info received from CU
10123  *
10124  * @details
10125  *
10126  *    Function : extractMacRbCfg
10127  *
10128  *    Functionality: Function to extract RB info received from CU
10129  *
10130  * @params[in] F1AP message
10131  * @return ROK/RFAILED
10132  *
10133  * ****************************************************************/
10134
10135 uint8_t extractMacRbCfg(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbCfg,\
10136 DRBs_ToBeSetupMod_Item_t *drbSetupModCfg,  DRBs_ToBeModified_Item_t *drbModCfg, LogicalChannelConfig_t *ulLcCfg, LcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10137 {
10138    if(drbCfg != NULLP)
10139    {
10140       if(extractDrbCfg(drbCfg, NULL, NULL, lcCfg, upTnlInfo) != ROK)
10141       {
10142          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10143          return RFAILED;
10144       }
10145    }
10146    else if(drbSetupModCfg != NULLP)
10147    { 
10148       if(extractDrbCfg(NULL, drbSetupModCfg, NULL, lcCfg, upTnlInfo) != ROK)
10149       {
10150          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10151          return RFAILED;
10152       }
10153    }
10154    else if(drbModCfg != NULLP)
10155    { 
10156       if(extractDrbCfg(NULL, NULL, drbModCfg, lcCfg, upTnlInfo) != ROK)
10157       {
10158          DU_LOG("ERROR  -->  F1AP : Failed to build Drb Qos at extractMacRbCfg()");
10159          return RFAILED;
10160       }
10161    }
10162    else
10163    {
10164       lcCfg->drbQos = NULLP;
10165       lcCfg->snssai = NULLP;
10166       if(lcCfg->lcId == SRB2_LCID)
10167          lcCfg->dlLcCfg.lcp = LC_PRIORITY_3;
10168       else
10169          lcCfg->dlLcCfg.lcp = LC_PRIORITY_1;
10170    }
10171    if(ulLcCfg)
10172    {
10173       lcCfg->ulLcCfgPres = true;
10174       extractUlLcCfg(&lcCfg->ulLcCfg, ulLcCfg);
10175    }
10176    else
10177       lcCfg->ulLcCfgPres = false;
10178    return ROK;
10179 }
10180
10181 /*******************************************************************
10182  *
10183  * @brief Function processing LC config info received from CU
10184  *
10185  * @details
10186  *
10187  *    Function : procMacLcCfg
10188  *
10189  *    Functionality: Function processing LC config info received from CU
10190  *
10191  * @params[in] F1AP message
10192  * @return ROK/RFAILED
10193  *
10194  * ****************************************************************/
10195
10196 uint8_t procMacLcCfg(uint8_t lcId, uint8_t rbType, uint8_t configType, DRBs_ToBeSetup_Item_t *drbItem,\
10197 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LogicalChannelConfig_t *ulLcCfg,\
10198 LcCfg *lcCfg, UpTnlCfg *upTnlInfo)
10199 {
10200    uint8_t ret = ROK;
10201
10202    lcCfg->lcId = lcId;
10203    lcCfg->configType = configType;
10204    if(rbType == RB_TYPE_SRB)
10205    {
10206       ret = extractMacRbCfg(lcId, NULL, NULL, NULL, ulLcCfg, lcCfg, NULL);
10207    }
10208    else if(rbType == RB_TYPE_DRB)
10209    {
10210       if(drbItem != NULL)
10211         ret = extractMacRbCfg(lcId, drbItem, NULL, NULL, ulLcCfg, lcCfg, upTnlInfo);
10212       else if(drbSetupModItem != NULL)
10213         ret = extractMacRbCfg(lcId, NULL, drbSetupModItem, NULL, ulLcCfg, lcCfg, upTnlInfo);
10214       else if(drbModItem != NULL)
10215         ret = extractMacRbCfg(lcId, NULL, NULL, drbModItem, ulLcCfg, lcCfg, upTnlInfo);
10216    }
10217    return ret;
10218 }
10219
10220 /*******************************************************************
10221  *
10222  * @brief Function to extract Rlc cfg To Add/Mod in CellGrp Info
10223  *
10224  * @details
10225  *
10226  *    Function : extractRlcCfgToAddMod
10227  *
10228  *    Functionality: Function to extract Rlc cfg To Add/Mod in CellGrp Info
10229  *
10230  * @params[in] CellGroupConfigRrc__rlc_BearerTo pointer
10231  *             DuUeCfg Pointer
10232  * @return ROK/RFAILED
10233  *
10234  * ****************************************************************/
10235
10236 uint8_t extractRlcCfgToAddMod(struct CellGroupConfigRrc__rlc_BearerToAddModList *lcCfg, DuUeCfg *ueCfgDb)
10237 {
10238   uint8_t idx, rbId, lcId, rlcMode, rbType;
10239   RLC_Config_t *f1RlcCfg = NULLP;
10240   LogicalChannelConfig_t *macUlLcCfg = NULLP;
10241
10242   for(idx = 0; idx < lcCfg->list.count; idx++)
10243   {
10244      lcId = lcCfg->list.array[idx]->logicalChannelIdentity;
10245      if(lcCfg->list.array[idx]->servedRadioBearer)
10246      {
10247         /* RadioBearer for SRB/DRB */
10248         if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10249         RLC_BearerConfig__servedRadioBearer_PR_srb_Identity)
10250         {
10251            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.srb_Identity;
10252            rbType = RB_TYPE_SRB;
10253         }
10254         else if(lcCfg->list.array[idx]->servedRadioBearer->present ==\
10255         RLC_BearerConfig__servedRadioBearer_PR_drb_Identity)
10256         {
10257            rbId = lcCfg->list.array[idx]->servedRadioBearer->choice.drb_Identity;
10258            rbType = RB_TYPE_DRB;
10259         }
10260         else
10261         {
10262            DU_LOG("\nERROR  -->  No components present in Bearer config to ADD/MOD");
10263            return RFAILED;
10264         }
10265         /* MAC UL LC Config */
10266         if(lcCfg->list.array[idx]->mac_LogicalChannelConfig)
10267         {
10268            macUlLcCfg = lcCfg->list.array[idx]->mac_LogicalChannelConfig;
10269         }
10270      }
10271      else
10272      {
10273         DU_LOG("\nERROR  -->  DUAPP: Received RadioBearer config is NULL");
10274         return RFAILED;
10275      }
10276      /* RLC Mode Config */
10277      if(lcCfg->list.array[idx]->rlc_Config)
10278      {
10279         rlcMode  = lcCfg->list.array[idx]->rlc_Config->present;
10280         f1RlcCfg = lcCfg->list.array[idx]->rlc_Config;
10281      }
10282      
10283      /* Filling RLC/MAC Config*/
10284      memset(&ueCfgDb->macLcCfg[idx], 0, sizeof(LcCfg));
10285      memset(&ueCfgDb->rlcLcCfg[idx], 0, sizeof(RlcBearerCfg));
10286      procRlcLcCfg(rbId, lcId, rbType, rlcMode, CONFIG_UNKNOWN, f1RlcCfg, &(ueCfgDb->rlcLcCfg[idx]), NULLP);
10287      if(procMacLcCfg(lcId, rbType, CONFIG_UNKNOWN, NULL, NULL, NULL, macUlLcCfg, &ueCfgDb->macLcCfg[idx], NULL) != ROK)
10288      {
10289         DU_LOG("\nERROR  -->  DU APP : Failed while filling MAC LC config at extractRlcCfgToAddMod()");
10290         return RFAILED;
10291      }
10292      (ueCfgDb->numRlcLcs)++;
10293      (ueCfgDb->numMacLcs)++;
10294      DU_LOG("\nDEBUG  -> DUAPP: extractRlcCfgToAddMod:RBType:%d, DrbID: %d,lcId:%d, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
10295         rbType, rbId, lcId, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
10296   }
10297   //TODO: To send the failure cause in UeContextSetupRsp 
10298   return ROK;
10299 }
10300
10301 /*******************************************************************
10302  *
10303  * @brief DeAlloc pdsch serv cell config info
10304  *
10305  * @details
10306  *
10307  *    Function : freeMacPdschServCellInfo
10308  *
10309  *    Functionality: DeAlloc pdsch serv cell config info
10310  *
10311  * @params[in] PdschServCellCfg pointer
10312  * @return void
10313  *
10314  * ****************************************************************/
10315
10316 void freeMacPdschServCellInfo(PdschServCellCfg *pdsch)
10317 {
10318    if(pdsch->xOverhead)
10319    {
10320       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->xOverhead, sizeof(PdschXOverhead));
10321    }
10322    if(pdsch->codeBlkGrpFlushInd)
10323    {
10324       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->codeBlkGrpFlushInd, sizeof(bool));
10325    }
10326    if(pdsch->maxCodeBlkGrpPerTb)
10327    {
10328       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10329    }
10330    if(pdsch->maxMimoLayers)
10331    {
10332       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, pdsch->maxMimoLayers, sizeof(uint8_t));
10333    }
10334 }
10335
10336 /*******************************************************************
10337  *
10338  * @brief Free Serving cell Info
10339  *
10340  * @details
10341  *
10342  *    Function : freeMacServingCellInfo
10343  *
10344  *    Functionality: Free Serving cell Info
10345  *
10346  * @params[in] ServCellCfgInfo *srvCellCfg
10347  * @return void
10348  *
10349  * ****************************************************************/
10350 void freeMacServingCellInfo(ServCellCfgInfo *srvCellCfg)
10351 {
10352    uint8_t timeDomRsrcIdx;
10353
10354    if(srvCellCfg->initDlBwp.pdschPresent)
10355    {
10356       for(timeDomRsrcIdx = 0; timeDomRsrcIdx < srvCellCfg->initDlBwp.pdschCfg.numTimeDomRsrcAlloc; timeDomRsrcIdx++)
10357       {
10358          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, \
10359             srvCellCfg->initDlBwp.pdschCfg.timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
10360       }
10361    }
10362
10363    freeMacPdschServCellInfo(&srvCellCfg->pdschServCellCfg);
10364    if(srvCellCfg->bwpInactivityTmr)
10365    {
10366       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
10367    }
10368
10369    if(srvCellCfg->initUlBwp.pucchPresent)
10370    {
10371       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, srvCellCfg->initUlBwp.pucchCfg.dlDataToUlAck, sizeof(PucchDlDataToUlAck));
10372    }
10373 }
10374
10375 /*******************************************************************
10376  *
10377  * @brief Free cell Grp Cfg Info
10378  *
10379  * @details
10380  *
10381  *    Function : freeUeReCfgCellGrpInfo
10382  *
10383  *    Functionality: Free cell Grp Cfg Info
10384  *
10385  * @params[in] MacUeCfg*  duUeCfg
10386  * @return void
10387  *
10388  * ****************************************************************/
10389
10390 void freeUeReCfgCellGrpInfo(MacUeCfg *macUeCfg)
10391 {
10392    freeMacServingCellInfo(&macUeCfg->spCellCfg.servCellCfg);
10393 }
10394
10395 /*******************************************************************
10396  *
10397  * @brief Fills Reconfig SchReqReConfig
10398  *
10399  * @details
10400  *
10401  *    Function : extractSchReqReConfig
10402  *
10403  *    Functionality: Fills Reconfig SchReqReConfig
10404  *
10405  * @params[in] SchedulingRequestConfig_t *cuSchedReq
10406  *             SchedReqCfg*  macSchedReq
10407  * @return void
10408  *
10409  * ****************************************************************/
10410 void extractSchReqReConfig(SchedulingRequestConfig_t *cuSchedReq, SchedReqCfg *macSchedReq)
10411 {
10412    uint8_t schReqIdx = 0;
10413    struct SchedulingRequestConfig__schedulingRequestToAddModList *schReqListToAdd = NULLP;
10414    struct SchedulingRequestConfig__schedulingRequestToReleaseList *schReqListToRel = NULLP;
10415
10416    if(cuSchedReq->schedulingRequestToAddModList)
10417    {
10418       schReqListToAdd = cuSchedReq->schedulingRequestToAddModList;
10419       if(schReqListToAdd->list.count)
10420       {
10421          macSchedReq->addModListCount = schReqListToAdd->list.count;
10422          for(schReqIdx = 0; schReqIdx < schReqListToAdd->list.count; schReqIdx++)
10423          {
10424             macSchedReq->addModList[schReqIdx].schedReqId = \
10425                schReqListToAdd->list.array[schReqIdx]->schedulingRequestId;
10426             macSchedReq->addModList[schReqIdx].srProhibitTmr = \
10427                *(schReqListToAdd->list.array[schReqIdx]->sr_ProhibitTimer);
10428             macSchedReq->addModList[schReqIdx].srTransMax    =\
10429                schReqListToAdd->list.array[schReqIdx]->sr_TransMax;
10430          }
10431       }
10432    }
10433    /* Scheduling Req To release */
10434    if(cuSchedReq->schedulingRequestToReleaseList)
10435    {
10436       schReqListToRel = cuSchedReq->schedulingRequestToReleaseList;
10437       if(schReqListToRel->list.count)
10438       {
10439          macSchedReq->relListCount = schReqListToRel->list.count;
10440          for(schReqIdx = 0; schReqIdx < schReqListToRel->list.count; schReqIdx++)
10441          {
10442             macSchedReq->relList[schReqIdx] = \
10443                *schReqListToRel->list.array[schReqIdx];
10444          }
10445       }
10446    }
10447 }
10448
10449 /*******************************************************************
10450  *
10451  * @brief Fills TagReconfig
10452  *
10453  * @details
10454  *
10455  *    Function : extractTagReconfig
10456  *
10457  *    Functionality: Fills extractTagReconfig
10458  *
10459  * @params[in] TAG_Config_t *cuTagCfg
10460  *             TagCfg *macTagCfg
10461  * @return void
10462  *
10463  * ****************************************************************/
10464
10465 void extractTagReconfig(TAG_Config_t *cuTagCfg, TagCfg *macTagCfg)
10466 {
10467   uint8_t tagIdx = 0;
10468   struct TAG_Config__tag_ToAddModList  *tagListToAddMod = NULLP;
10469   struct TAG_Config__tag_ToReleaseList *tagListToRel = NULLP;
10470
10471   /* Tag config to AddMod */
10472   if(cuTagCfg->tag_ToAddModList)
10473   {
10474      tagListToAddMod = cuTagCfg->tag_ToAddModList; 
10475      if(tagListToAddMod->list.count)
10476      {
10477         macTagCfg->addModListCount = tagListToAddMod->list.count;
10478         for(tagIdx = 0; tagIdx < tagListToAddMod->list.count; tagIdx++)
10479         {
10480            macTagCfg->addModList[tagIdx].tagId =\
10481               tagListToAddMod->list.array[tagIdx]->tag_Id;     
10482            macTagCfg->addModList[tagIdx].timeAlignTimer = \
10483
10484               tagListToAddMod->list.array[tagIdx]->timeAlignmentTimer;
10485         }
10486      }
10487   }
10488   /* Tag config to release */
10489   if(cuTagCfg->tag_ToReleaseList)
10490   {
10491      tagListToRel = cuTagCfg->tag_ToReleaseList;
10492      if(tagListToRel->list.count)
10493      {
10494         macTagCfg->relListCount = tagListToRel->list.count;
10495         for(tagIdx = 0; tagIdx < tagListToRel->list.count; tagIdx++)
10496         {
10497            macTagCfg->relList[tagIdx] = *tagListToRel->list.array[tagIdx];     
10498         }
10499      }
10500   }
10501 }
10502
10503 /*******************************************************************
10504  *
10505  * @brief Fills PdcchCfg received by CU
10506  *
10507  * @details
10508  *
10509  *    Function : extractPdcchCfg
10510  *
10511  *    Functionality: Fills PdcchCfg received  by CU
10512  *
10513  * @params[in] PDCCH_Config_t *cuPdcchCfg,
10514  *             PdcchConfig *duPdcchCfg
10515  * @return void
10516  *
10517  * ****************************************************************/
10518
10519 void extractPdcchCfg(PDCCH_Config_t *cuPdcchCfg, PdcchConfig *macPdcchCfg)
10520 {
10521    uint8_t cRsetIdx = 0;
10522    uint8_t srchSpcIdx = 0;
10523
10524    struct PDCCH_Config__controlResourceSetToAddModList *cRsetToAddModList = NULLP;
10525    struct PDCCH_Config__controlResourceSetToReleaseList *cRsetToRelList = NULLP;
10526    struct PDCCH_Config__searchSpacesToAddModList *srchSpcToAddModList = NULLP;
10527    struct PDCCH_Config__searchSpacesToReleaseList *srchSpcToRelList = NULLP;
10528
10529
10530    /* Control Resource Set To Add/Mod List */
10531    if(cuPdcchCfg->controlResourceSetToAddModList)
10532    {
10533       cRsetToAddModList = cuPdcchCfg->controlResourceSetToAddModList;
10534       if(cRsetToAddModList->list.count)
10535       {
10536          macPdcchCfg->numCRsetToAddMod = cRsetToAddModList->list.count;
10537          for(cRsetIdx = 0; cRsetIdx < cRsetToAddModList->list.count; cRsetIdx++)
10538          {
10539             macPdcchCfg->cRSetToAddModList[cRsetIdx].cRSetId = \
10540                cRsetToAddModList->list.array[cRsetIdx]->controlResourceSetId;
10541             //freqDomRsrcBitStringToInt(&cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources,\
10542                   macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc);
10543             memcpy(macPdcchCfg->cRSetToAddModList[cRsetIdx].freqDomainRsrc, \
10544                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.buf,
10545                cRsetToAddModList->list.array[cRsetIdx]->frequencyDomainResources.size);
10546
10547             macPdcchCfg->cRSetToAddModList[cRsetIdx].duration = \
10548                 cRsetToAddModList->list.array[cRsetIdx]->duration;
10549
10550             macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType = \
10551                cRsetToAddModList->list.array[cRsetIdx]->cce_REG_MappingType.present;   
10552             if(macPdcchCfg->cRSetToAddModList[cRsetIdx].cceRegMappingType == CCE_REG_MAPPINGTYPE_PR_INTERLEAVED)
10553             {
10554                //TODO: handle the case for Interleaved
10555             }
10556             macPdcchCfg->cRSetToAddModList[cRsetIdx].precoderGranularity = \
10557                 cRsetToAddModList->list.array[cRsetIdx]->precoderGranularity;
10558             if(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID)
10559             {
10560                macPdcchCfg->cRSetToAddModList[cRsetIdx].dmrsScramblingId= \
10561                   *(cRsetToAddModList->list.array[cRsetIdx]->pdcch_DMRS_ScramblingID);
10562             }
10563          }
10564       }
10565    }
10566    /* Control Resource Set To Release List */
10567    if(cuPdcchCfg->controlResourceSetToReleaseList)
10568    {
10569       cRsetToRelList = cuPdcchCfg->controlResourceSetToReleaseList;
10570       if(cRsetToRelList->list.count)
10571       {
10572          macPdcchCfg->numCRsetToRel = cRsetToRelList->list.count;
10573          for(cRsetIdx = 0; cRsetIdx < cRsetToRelList->list.count; cRsetIdx++)
10574          {
10575             macPdcchCfg->cRSetToRelList[cRsetIdx] = *(cRsetToRelList->list.array[cRsetIdx]);
10576          }
10577       }
10578    }
10579
10580    /* Search space To Add/Mod List */
10581    if(cuPdcchCfg->searchSpacesToAddModList)
10582    {
10583       srchSpcToAddModList = cuPdcchCfg->searchSpacesToAddModList;
10584       if(srchSpcToAddModList->list.count)
10585       {
10586          macPdcchCfg->numSearchSpcToAddMod = srchSpcToAddModList->list.count;
10587          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToAddModList->list.count; srchSpcIdx++)
10588          {
10589             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceId =\
10590                                                                           srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceId;
10591             macPdcchCfg->searchSpcToAddModList[srchSpcIdx].cRSetId =\
10592                                                                     *(srchSpcToAddModList->list.array[srchSpcIdx]->controlResourceSetId);
10593             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset)
10594             {
10595                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSlotPeriodicityAndOffset =\
10596                                                                                          srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSlotPeriodicityAndOffset->present;
10597             }
10598             if(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot)
10599             {
10600                bitStringToInt(srchSpcToAddModList->list.array[srchSpcIdx]->monitoringSymbolsWithinSlot,\
10601                      macPdcchCfg->searchSpcToAddModList[srchSpcIdx].mSymbolsWithinSlot);
10602             }
10603             if(srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates)
10604             {
10605                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel1 = \
10606                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel1;
10607                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel2 = \
10608                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel2;
10609                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel4 = \
10610                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel4;
10611
10612                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel8 = \
10613                                                                                        srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel8;
10614
10615                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].numCandidatesAggLevel16 = \
10616                                                                                         srchSpcToAddModList->list.array[srchSpcIdx]->nrofCandidates->aggregationLevel16;
10617             }
10618             if(srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType)
10619             {
10620                macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType =\
10621                                                                                srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->present;
10622                if(macPdcchCfg->searchSpcToAddModList[srchSpcIdx].searchSpaceType == SEARCHSPACETYPE_PR_UE_SPECIFIC)
10623                {
10624                   macPdcchCfg->searchSpcToAddModList[srchSpcIdx].ueSpecificDciFormat =\
10625                                                                                       srchSpcToAddModList->list.array[srchSpcIdx]->searchSpaceType->choice.ue_Specific->dci_Formats;
10626                }
10627
10628             }
10629          }
10630       }
10631    }
10632    /* Search space To Rel List */
10633    if(cuPdcchCfg->searchSpacesToReleaseList)
10634    {
10635       srchSpcToRelList = cuPdcchCfg->searchSpacesToReleaseList;
10636       if(srchSpcToRelList->list.count)
10637       {
10638          macPdcchCfg->numSearchSpcToRel = srchSpcToRelList->list.count;
10639          for(srchSpcIdx = 0; srchSpcIdx < srchSpcToRelList->list.count; srchSpcIdx++)
10640          {
10641             macPdcchCfg->searchSpcToRelList[srchSpcIdx] =\
10642                                                          *(srchSpcToRelList->list.array[srchSpcIdx]);
10643          }
10644       }
10645    }
10646 }
10647
10648 /*******************************************************************
10649  *
10650  * @brief Fills PdschCfg received by CU
10651  *
10652  * @details
10653  *
10654  *    Function : extractPdschCfg
10655  *
10656  *    Functionality: Fills PdschCfg received  by CU
10657  *
10658  * @params[in] PDSCH_Config_t *cuPdschCfg = Information which is send by CU,
10659  *                   which we have stored in F1UeContextSetupDb,
10660  *             PdschConfig *macPdschCfg = Used to Store the information which
10661  *                   needs to send in other layer, as well as this can be the variable
10662  *                   which stores the information in DuCb,
10663  *             PdschConfig *storedPdschCfg =  Null in case of sending the
10664  *                   information to other layer else it will have stored pdsch 
10665  *                   configuration in copyOfmacUeCfg.
10666  * @return void
10667  *
10668  * ****************************************************************/
10669
10670 void extractPdschCfg(PDSCH_Config_t *cuPdschCfg, PdschConfig *macPdschCfg, PdschConfig *storedPdschCfg)
10671 {
10672    uint8_t timeDomIdx;
10673    struct PDSCH_Config__pdsch_TimeDomainAllocationList *timeDomAlloc = NULLP;
10674
10675    if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA)
10676    {
10677       if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->present == \
10678             PDSCH_Config__dmrs_DownlinkForPDSCH_MappingTypeA_PR_setup)
10679       {
10680          if(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup)
10681          {
10682             macPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
10683                *(cuPdschCfg->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_AdditionalPosition);
10684          }
10685       }
10686    }
10687    macPdschCfg->resourceAllocType = cuPdschCfg->resourceAllocation;
10688    if(cuPdschCfg->pdsch_TimeDomainAllocationList)
10689    {
10690       timeDomAlloc = cuPdschCfg->pdsch_TimeDomainAllocationList;
10691       if(timeDomAlloc->present ==\
10692             PDSCH_Config__pdsch_TimeDomainAllocationList_PR_setup)
10693       {
10694          if(timeDomAlloc->choice.setup)
10695          {
10696             macPdschCfg->numTimeDomRsrcAlloc  = timeDomAlloc->choice.setup->list.count;
10697             for(timeDomIdx = 0; timeDomIdx < timeDomAlloc->choice.setup->list.count; timeDomIdx++)
10698             {
10699                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 = NULLP;
10700                if(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0)
10701                {
10702                   if(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 == NULL)
10703                   {
10704                      if(storedPdschCfg)
10705                      {
10706                         if(storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
10707                         {
10708                            macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0 =\
10709                            storedPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0;
10710                         }
10711                         else
10712                         {
10713                            DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
10714                         }
10715                      }
10716                      else
10717                      {
10718                         DU_ALLOC_SHRABL_BUF(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0, sizeof(uint8_t));
10719                      }
10720                      if(!macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0)
10721                      {
10722                         DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for k0 at extractPdschCfg()");
10723                         return;
10724                      }
10725                   }
10726                   *(macPdschCfg->timeDomRsrcAllociList[timeDomIdx].k0) = \
10727                   *(timeDomAlloc->choice.setup->list.array[timeDomIdx]->k0);
10728                }
10729                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].mappingType = \
10730                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->mappingType;
10731                macPdschCfg->timeDomRsrcAllociList[timeDomIdx].startSymbolAndLength = \
10732                   timeDomAlloc->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
10733             }
10734          }
10735       }
10736    }
10737    macPdschCfg->rbgSize = cuPdschCfg->rbg_Size;
10738    if(cuPdschCfg->maxNrofCodeWordsScheduledByDCI)
10739       macPdschCfg->numCodeWordsSchByDci = *(cuPdschCfg->maxNrofCodeWordsScheduledByDCI);
10740    if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_staticBundling)
10741    {
10742       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
10743       if(cuPdschCfg->prb_BundlingType.choice.staticBundling)
10744       {
10745          if(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize)
10746          {
10747             macPdschCfg->bundlingInfo.StaticBundling.size = \
10748                *(cuPdschCfg->prb_BundlingType.choice.staticBundling->bundleSize);
10749          }
10750       }
10751    }
10752    else if(cuPdschCfg->prb_BundlingType.present == PDSCH_Config__prb_BundlingType_PR_dynamicBundling)
10753    {
10754       macPdschCfg->bundlingType = cuPdschCfg->prb_BundlingType.present;
10755    }
10756
10757 }
10758
10759 /*******************************************************************
10760  *
10761  * @brief Fills PdschServingCellCfg received by CU
10762  *
10763  * @details
10764  *
10765  *    Function : extractPdschServingCellCfg
10766  *
10767  *    Functionality: Fills PdschCfg received  by CU
10768  *
10769  * @params[in] PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg,
10770  *             PdschServCellCfg *macUePdschSrvCellCfg
10771  * @return ROK/RFAILED
10772  *
10773  * ****************************************************************/
10774
10775 uint8_t extractPdschServingCellCfg(PDSCH_ServingCellConfig_t *cuPdschSrvCellCfg, PdschServCellCfg *macUePdschSrvCellCfg)
10776 {
10777    if(cuPdschSrvCellCfg->codeBlockGroupTransmission)
10778    {
10779       if(cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup)
10780       {
10781          if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
10782          {
10783             *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
10784                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
10785          }
10786          else
10787          {
10788             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb, sizeof(MaxCodeBlkGrpPerTB));
10789             if(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)
10790             {
10791                *(macUePdschSrvCellCfg->maxCodeBlkGrpPerTb)  = \
10792                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->maxCodeBlockGroupsPerTransportBlock;
10793             }
10794             else
10795             {
10796                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxCodeBlkGrpPerTb at extractPdschServingCellCfg()");
10797                return RFAILED;
10798             }
10799          }
10800          if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
10801          {
10802             *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
10803                cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
10804          }
10805          else
10806          {
10807             DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->codeBlkGrpFlushInd , sizeof(bool));
10808             if(macUePdschSrvCellCfg->codeBlkGrpFlushInd)
10809             {
10810                *(macUePdschSrvCellCfg->codeBlkGrpFlushInd)  = \
10811                   cuPdschSrvCellCfg->codeBlockGroupTransmission->choice.setup->codeBlockGroupFlushIndicator;
10812             }
10813             else
10814             {
10815                DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for codeBlkGrpFlushInd at extractPdschServingCellCfg()");
10816                return RFAILED;
10817             }
10818          }
10819       }
10820    }
10821    if(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH)
10822    {
10823       macUePdschSrvCellCfg->numHarqProcForPdsch = *(cuPdschSrvCellCfg->nrofHARQ_ProcessesForPDSCH); 
10824    }
10825    if(cuPdschSrvCellCfg->ext1)
10826    {
10827       if(cuPdschSrvCellCfg->ext1->maxMIMO_Layers)
10828       {
10829         if(macUePdschSrvCellCfg->maxMimoLayers)
10830         {
10831            *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
10832         }
10833         else
10834         {
10835            DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->maxMimoLayers, sizeof(uint8_t));
10836            if(macUePdschSrvCellCfg->maxMimoLayers)
10837            {
10838               *(macUePdschSrvCellCfg->maxMimoLayers)  = *(cuPdschSrvCellCfg->ext1->maxMIMO_Layers);
10839            }
10840            else
10841            {
10842               DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for maxMimoLayers at extractPdschServingCellCfg()");
10843               return RFAILED;
10844            }
10845         }
10846       }
10847    }
10848    if(cuPdschSrvCellCfg->xOverhead)
10849    {
10850       if(macUePdschSrvCellCfg->xOverhead)
10851       {
10852          *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
10853       }
10854       else
10855       {
10856          DU_ALLOC_SHRABL_BUF(macUePdschSrvCellCfg->xOverhead, sizeof(PdschXOverhead));
10857          if(macUePdschSrvCellCfg->xOverhead)
10858          {
10859             *(macUePdschSrvCellCfg->xOverhead)  = *(cuPdschSrvCellCfg->xOverhead);
10860          }
10861          else
10862          {
10863             DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for xOverhead at extractPdschServingCellCfg()");
10864             return RFAILED;
10865          }
10866       }
10867    }
10868    return ROK;
10869 }
10870
10871 /*******************************************************************
10872  *
10873  * @brief Fills PuschCfg received by CU
10874  *
10875  * @details
10876  *
10877  *    Function : extractPuschCfg
10878  *
10879  *    Functionality: Fills PuschCfg received  by CU
10880  *
10881  * @params[in] BWP_UplinkDedicated__pusch_Config *cuPuschCfg,
10882  *             PuschCfg *macPuschCfg
10883  * @return void
10884  *
10885  * ****************************************************************/
10886
10887 void extractPuschCfg(struct BWP_UplinkDedicated__pusch_Config *cuPuschCfg, PuschCfg *macPuschCfg)
10888 {
10889    uint8_t timeDomIdx = 0;
10890    DMRS_UplinkConfig_t *dmrsUlCfg = NULLP;
10891    struct PUSCH_Config__pusch_TimeDomainAllocationList *timeDomAllocList = NULLP;
10892
10893    if(cuPuschCfg->present == BWP_UplinkDedicated__pusch_Config_PR_setup)
10894    {
10895       if(cuPuschCfg->choice.setup)
10896       {
10897          if(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH)
10898          {
10899              macPuschCfg->dataScramblingId = \
10900                 *(cuPuschCfg->choice.setup->dataScramblingIdentityPUSCH);
10901          }
10902          if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA)
10903          {
10904             if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->present == PUSCH_Config__dmrs_UplinkForPUSCH_MappingTypeA_PR_setup)
10905             {
10906                if(cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup)
10907                {
10908                   dmrsUlCfg = (cuPuschCfg->choice.setup->dmrs_UplinkForPUSCH_MappingTypeA->choice.setup);
10909                   if(dmrsUlCfg->dmrs_AdditionalPosition)
10910                   {
10911                      macPuschCfg->dmrsUlCfgForPuschMapTypeA.addPos =\
10912                         *(dmrsUlCfg->dmrs_AdditionalPosition);
10913                   }
10914                   if(dmrsUlCfg->transformPrecodingDisabled)
10915                   {
10916                      if(dmrsUlCfg->transformPrecodingDisabled->scramblingID0)
10917                      {
10918                         macPuschCfg->dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0 = \
10919                            *(dmrsUlCfg->transformPrecodingDisabled->scramblingID0);
10920                      }
10921                   }
10922                }
10923             }
10924          }
10925          /*Res Alloc Type for UL */
10926          if(cuPuschCfg->choice.setup->resourceAllocation)
10927          {
10928             macPuschCfg->resourceAllocType = \
10929                cuPuschCfg->choice.setup->resourceAllocation;
10930          }
10931          if(cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList)
10932          {
10933             timeDomAllocList = cuPuschCfg->choice.setup->pusch_TimeDomainAllocationList;
10934             if(timeDomAllocList->present == PUSCH_Config__pusch_TimeDomainAllocationList_PR_setup)
10935             {
10936                if(timeDomAllocList->choice.setup)
10937                {
10938                   macPuschCfg->numTimeDomRsrcAlloc = timeDomAllocList->choice.setup->list.count;
10939                   for(timeDomIdx = 0; timeDomIdx <timeDomAllocList->choice.setup->list.count; timeDomIdx++)
10940                   {
10941                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].k2 = \
10942                         *(timeDomAllocList->choice.setup->list.array[timeDomIdx]->k2);
10943                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].mappingType = \
10944                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->mappingType;
10945                      macPuschCfg->timeDomRsrcAllocList[timeDomIdx].startSymbolAndLength = \
10946                         timeDomAllocList->choice.setup->list.array[timeDomIdx]->startSymbolAndLength;
10947                   }
10948                }
10949             }
10950          }
10951          if(cuPuschCfg->choice.setup->transformPrecoder)
10952             macPuschCfg->transformPrecoder = *(cuPuschCfg->choice.setup->transformPrecoder);
10953       }
10954    }
10955 }
10956
10957 /*******************************************************************
10958  *
10959  * @brief Function to fill pucch Power Control
10960  *
10961  * @details
10962  *
10963  *    Function : extractPucchPowerControl
10964  *
10965  *    Functionality: Function to fill pucch Power Control
10966  *
10967  * @params[in] PucchPowerControl *pwrCtrl,
10968  *             struct PUCCH_PowerControl *cuPwrCtrlCfg
10969  * @return void
10970  *
10971  * ****************************************************************/
10972
10973 void extractPucchPowerControl(PucchPowerControl *pwrCtrl, struct PUCCH_PowerControl *cuPwrCtrlCfg)
10974 {
10975    uint8_t arrIdx;
10976
10977    if(cuPwrCtrlCfg->deltaF_PUCCH_f0)
10978       pwrCtrl->deltaF_Format0 = *cuPwrCtrlCfg->deltaF_PUCCH_f0;
10979    if(cuPwrCtrlCfg->deltaF_PUCCH_f1)
10980       pwrCtrl->deltaF_Format1 = *cuPwrCtrlCfg->deltaF_PUCCH_f1;
10981    if(cuPwrCtrlCfg->deltaF_PUCCH_f2)
10982       pwrCtrl->deltaF_Format2 = *cuPwrCtrlCfg->deltaF_PUCCH_f2;
10983    if(cuPwrCtrlCfg->deltaF_PUCCH_f3)
10984       pwrCtrl->deltaF_Format3 = *cuPwrCtrlCfg->deltaF_PUCCH_f3;
10985    if(cuPwrCtrlCfg->deltaF_PUCCH_f4)
10986       pwrCtrl->deltaF_Format4 = *cuPwrCtrlCfg->deltaF_PUCCH_f4;
10987    if(cuPwrCtrlCfg->p0_Set)
10988    {
10989       pwrCtrl->p0SetCount = cuPwrCtrlCfg->p0_Set->list.count;
10990       for(arrIdx=0; arrIdx < pwrCtrl->p0SetCount; arrIdx++)
10991       {
10992          pwrCtrl->p0Set[arrIdx].p0PucchId =\
10993             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Id;
10994          pwrCtrl->p0Set[arrIdx].p0PucchVal =\
10995             cuPwrCtrlCfg->p0_Set->list.array[arrIdx]->p0_PUCCH_Value;
10996       }
10997    }
10998    if(cuPwrCtrlCfg->pathlossReferenceRSs)
10999    {
11000       pwrCtrl->pathLossRefRSListCount = cuPwrCtrlCfg->pathlossReferenceRSs->list.count;
11001       for(arrIdx = 0; arrIdx < pwrCtrl->pathLossRefRSListCount; arrIdx++)
11002       {
11003          pwrCtrl->pathLossRefRSList[arrIdx].pathLossRefRSId =\
11004             cuPwrCtrlCfg->pathlossReferenceRSs->list.array[arrIdx]->pucch_PathlossReferenceRS_Id;
11005       }
11006    }
11007 }
11008  
11009  /*******************************************************************
11010  *
11011  * @brief Function to extractResrcSetToAddModList sent by CU
11012  *
11013  * @details
11014  *
11015  *    Function : extractResrcSetToAddModList
11016  *
11017  *    Functionality: Fucntion to extractResrcSetToAddModList
11018  *
11019  * @params[in] PucchResrcSetCfg pointer,
11020  *             struct PUCCH_Config__resourceSetToAddModList pointer
11021  * @return void
11022  *
11023  * ****************************************************************/
11024
11025 void extractResrcSetToAddModList(PucchResrcSetCfg *macRsrcSetList, struct PUCCH_Config__resourceSetToAddModList *cuRsrcSetList)
11026 {
11027    uint8_t arrIdx, rsrcListIdx;
11028
11029    macRsrcSetList->resrcSetToAddModListCount = cuRsrcSetList->list.count; 
11030    for(arrIdx = 0; arrIdx < macRsrcSetList->resrcSetToAddModListCount; arrIdx++)
11031    {
11032       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcSetId     =\
11033          cuRsrcSetList->list.array[arrIdx]->pucch_ResourceSetId;
11034       macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount =\
11035          cuRsrcSetList->list.array[arrIdx]->resourceList.list.count;
11036       for(rsrcListIdx = 0; rsrcListIdx < macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount; rsrcListIdx++)
11037       {
11038          macRsrcSetList->resrcSetToAddModList[arrIdx].resrcList[rsrcListIdx] =\
11039             *cuRsrcSetList->list.array[arrIdx]->resourceList.list.array[rsrcListIdx];
11040       }
11041
11042       if(cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1)
11043       {
11044          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize =\
11045             *cuRsrcSetList->list.array[arrIdx]->maxPayloadMinus1;
11046       }
11047       else
11048       {
11049          macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize = 0;
11050       }
11051    }
11052 }/* End of extractResrcSetToAddModList */
11053
11054 /*******************************************************************
11055  *
11056  * @brief Fills extractResrcToAddModList sent by CU
11057  *
11058  * @details
11059  *
11060  *    Function : extractResrcToAddModList
11061  *
11062  *    Functionality: Fills extractResrcToAddModList
11063  *
11064  * @params[in] PucchResrcCfg pointer,
11065  *             struct PUCCH_Config__resourceToAddModList pointer
11066  * @return ROk/RFAILED
11067  *
11068  * ****************************************************************/
11069
11070 uint8_t extractResrcToAddModList(PucchResrcCfg *macResrcList, struct PUCCH_Config__resourceToAddModList *cuResrcList)
11071 {
11072    uint8_t arrIdx;
11073    
11074    macResrcList->resrcToAddModListCount = cuResrcList->list.count;
11075    for(arrIdx = 0; arrIdx < macResrcList->resrcToAddModListCount; arrIdx++)
11076    {
11077       macResrcList->resrcToAddModList[arrIdx].resrcId      =\
11078         cuResrcList->list.array[arrIdx]->pucch_ResourceId; 
11079       macResrcList->resrcToAddModList[arrIdx].startPrb     =\
11080         cuResrcList->list.array[arrIdx]->startingPRB;
11081       if(cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping)
11082       {
11083          macResrcList->resrcToAddModList[arrIdx].intraFreqHop =\
11084            *cuResrcList->list.array[arrIdx]->intraSlotFrequencyHopping;
11085       }
11086       if(cuResrcList->list.array[arrIdx]->secondHopPRB)
11087       {
11088          macResrcList->resrcToAddModList[arrIdx].secondPrbHop =\
11089            *cuResrcList->list.array[arrIdx]->secondHopPRB;
11090       }
11091       /* PUCCH RSRC FORMAT */
11092       if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format0)
11093       {
11094          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_0;
11095          if(cuResrcList->list.array[arrIdx]->format.choice.format0)
11096          {
11097             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0, sizeof(PucchFormat0));
11098             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0 == NULLP)
11099             {
11100                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format0 in extractResrcToAddModList()");
11101                return RFAILED;
11102             }
11103             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->initialCyclicShift =\
11104                cuResrcList->list.array[arrIdx]->format.choice.format0->initialCyclicShift;
11105             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->numSymbols =\
11106                cuResrcList->list.array[arrIdx]->format.choice.format0->nrofSymbols;
11107             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format0->startSymbolIdx =\
11108                cuResrcList->list.array[arrIdx]->format.choice.format0->startingSymbolIndex;
11109          }
11110       }
11111       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format1)
11112       {
11113          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_1;
11114          if(cuResrcList->list.array[arrIdx]->format.choice.format1)
11115          {
11116             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1, sizeof(PucchFormat1));
11117             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1 == NULLP)
11118             {
11119                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format1 in extractResrcToAddModList()");
11120                return RFAILED;
11121             }
11122             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->initialCyclicShift =\
11123                 cuResrcList->list.array[arrIdx]->format.choice.format1->initialCyclicShift;
11124             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->numSymbols =\
11125                 cuResrcList->list.array[arrIdx]->format.choice.format1->nrofSymbols;
11126             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->startSymbolIdx =\
11127                 cuResrcList->list.array[arrIdx]->format.choice.format1->startingSymbolIndex;
11128             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format1->timeDomOCC =\
11129                 cuResrcList->list.array[arrIdx]->format.choice.format1->timeDomainOCC;
11130          }
11131       }
11132       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format2)
11133       {
11134          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_2;
11135          if(cuResrcList->list.array[arrIdx]->format.choice.format2)
11136          {
11137             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
11138             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2 == NULLP)
11139             {
11140                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format2 in extractResrcToAddModList()");
11141                return RFAILED;
11142             }
11143             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numPrbs =\
11144                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofPRBs;
11145             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->numSymbols =\
11146                 cuResrcList->list.array[arrIdx]->format.choice.format2->nrofSymbols;
11147             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format2->startSymbolIdx =\
11148                 cuResrcList->list.array[arrIdx]->format.choice.format2->startingSymbolIndex;
11149          }
11150       }
11151       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format3)
11152       {
11153          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_3;
11154          if(cuResrcList->list.array[arrIdx]->format.choice.format3)
11155          {
11156             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
11157             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3 == NULLP)
11158             {
11159                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format3 in extractResrcToAddModList()");
11160                return RFAILED;
11161             }
11162             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numPrbs =\
11163                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofPRBs;
11164             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->numSymbols =\
11165                 cuResrcList->list.array[arrIdx]->format.choice.format3->nrofSymbols;
11166             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format3->startSymbolIdx =\
11167                 cuResrcList->list.array[arrIdx]->format.choice.format3->startingSymbolIndex;
11168          }
11169       }
11170       else if(cuResrcList->list.array[arrIdx]->format.present == PUCCH_Resource__format_PR_format4)
11171       {
11172          macResrcList->resrcToAddModList[arrIdx].pucchFormat = PUCCH_FORMAT_4;
11173          if(cuResrcList->list.array[arrIdx]->format.choice.format4)
11174          {
11175             DU_ALLOC_SHRABL_BUF(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4, sizeof(PucchFormat4));
11176             if(macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4 == NULLP)
11177             {
11178                DU_LOG("\nERROR  --> F1AP : Failed to allocate memory for Format4 in extractResrcToAddModList()");
11179                return RFAILED;
11180             }
11181             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->numSymbols =\
11182                 cuResrcList->list.array[arrIdx]->format.choice.format4->nrofSymbols;
11183             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occLen =\
11184                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Length;
11185             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->occIdx =\
11186                 cuResrcList->list.array[arrIdx]->format.choice.format4->occ_Index;
11187             macResrcList->resrcToAddModList[arrIdx].PucchFormat.format4->startSymbolIdx =\
11188                 cuResrcList->list.array[arrIdx]->format.choice.format4->startingSymbolIndex;
11189          }
11190       }
11191    }
11192    return ROK;
11193
11194 }/* End of extractResrcToAddModList */
11195
11196 /*******************************************************************
11197  *
11198  * @brief Fills fillPucchSchedReqPeriodAndOffset sent by CU
11199  *
11200  * @details
11201  *
11202  *    Function : fillPucchSchedReqPeriodAndOffset
11203  *
11204  *    Functionality: To fillPucchSchedReqPeriodAndOffset
11205  *
11206  * @params[in] macPeriodicty,
11207  *     SchedulingRequestResourceConfig__periodicityAndOffset pointer
11208  * @return void
11209  *
11210  * ****************************************************************/
11211
11212 void fillPucchSchedReqPeriodAndOffset(uint8_t macPeriodicty, uint16_t  macOffset,\
11213    struct SchedulingRequestResourceConfig__periodicityAndOffset *cuPeriodicty)
11214 {
11215    macPeriodicty = cuPeriodicty->present;
11216    switch(macPeriodicty)
11217    {
11218       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym2:
11219          {
11220             macOffset     = cuPeriodicty->choice.sym2;
11221             break;
11222          }
11223       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sym6or7:
11224          {
11225             macOffset     = cuPeriodicty->choice.sym6or7;
11226             break;
11227          }
11228       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl1:
11229          {
11230             macOffset     = cuPeriodicty->choice.sl1;
11231             break;
11232          }
11233       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl2:
11234          {
11235             macOffset = cuPeriodicty->choice.sl2;
11236             break;
11237          }
11238       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl4:
11239          {
11240             macOffset = cuPeriodicty->choice.sl4;
11241             break;
11242          }
11243       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl5:
11244          {
11245             macOffset = cuPeriodicty->choice.sl5;
11246             break;
11247          }
11248       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl8:
11249          {
11250             macOffset = cuPeriodicty->choice.sl8;
11251             break;
11252          }
11253       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl10:
11254          {
11255             macOffset = cuPeriodicty->choice.sl10;
11256             break;
11257          }
11258       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl16:
11259          {
11260             macOffset = cuPeriodicty->choice.sl16;
11261             break;
11262          }
11263       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl20:
11264          {
11265             macOffset = cuPeriodicty->choice.sl20;
11266             break;
11267          }
11268       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl40:
11269          {
11270             macOffset = cuPeriodicty->choice.sl40;
11271             break;
11272          }
11273       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl80:
11274          {
11275             macOffset = cuPeriodicty->choice.sl80;
11276             break;
11277          }
11278       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl160:
11279          {
11280             macOffset = cuPeriodicty->choice.sl160;
11281             break;
11282          }
11283       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl320:
11284          {
11285             macOffset = cuPeriodicty->choice.sl320;
11286             break;
11287          }
11288       case SchedulingRequestResourceConfig__periodicityAndOffset_PR_sl640:
11289          {
11290             macOffset = cuPeriodicty->choice.sl640;
11291             break;
11292          }
11293       default :
11294          DU_LOG("\nERROR  -->  F1AP : Invalid periodicity %d", macPeriodicty);
11295    }
11296 }
11297
11298 /*******************************************************************
11299  *
11300  * @brief Function to extractPucchFormatCfg sent by CU
11301  *
11302  * @details
11303  *
11304  *    Function : extractPucchFormatCfg
11305  *
11306  *    Functionality: Function to extractPucchFormatCfg
11307  *
11308  * @params[in] PucchFormatCfg pointer,
11309  *             PUCCH_FormatConfig_t pointer
11310  * @return void
11311  *
11312  * ****************************************************************/
11313
11314 void extractPucchFormatCfg(PucchFormatCfg *macFormatCfg, PUCCH_FormatConfig_t *cuFormatCfg)
11315  {
11316     if(cuFormatCfg->interslotFrequencyHopping)
11317        macFormatCfg->interSlotFreqHop = *cuFormatCfg->interslotFrequencyHopping;
11318     if(cuFormatCfg->additionalDMRS)  
11319        macFormatCfg->addDmrs = *cuFormatCfg->additionalDMRS;
11320     if(cuFormatCfg->maxCodeRate)
11321        macFormatCfg->maxCodeRate = *cuFormatCfg->maxCodeRate;
11322     if(cuFormatCfg->nrofSlots)  
11323        macFormatCfg->numSlots = *cuFormatCfg->nrofSlots;
11324     if(cuFormatCfg->pi2BPSK)  
11325        macFormatCfg->pi2BPSK = *cuFormatCfg->pi2BPSK;
11326     if(cuFormatCfg->simultaneousHARQ_ACK_CSI)  
11327        macFormatCfg->harqAckCSI = *cuFormatCfg->simultaneousHARQ_ACK_CSI;
11328  }/* End of extractPucchFormatCfg */
11329
11330 /*******************************************************************
11331  *
11332  * @brief Function to extractSchedReqCfgToAddMod sent by CU
11333  *
11334  * @details
11335  *
11336  *    Function : extractSchedReqCfgToAddMod
11337  *
11338  *    Functionality: Function to extractSchedReqCfgToAddMod
11339  *
11340  * @params[in] PucchSchedReqCfg pointer,
11341  *      PUCCH_Config__schedulingRequestResourceToAddModList pointer
11342  * @return void
11343  *
11344  * ****************************************************************/
11345
11346 void extractSchedReqCfgToAddMod(PucchSchedReqCfg *macSchedReqCfg, struct PUCCH_Config__schedulingRequestResourceToAddModList *cuSchedReqList)
11347 {
11348    uint8_t arrIdx;
11349
11350    macSchedReqCfg->schedAddModListCount = cuSchedReqList->list.count;
11351    for(arrIdx = 0; arrIdx <  macSchedReqCfg->schedAddModListCount; arrIdx++)
11352    {
11353       macSchedReqCfg->schedAddModList[arrIdx].resrcId =\
11354          cuSchedReqList->list.array[arrIdx]->schedulingRequestResourceId;
11355       macSchedReqCfg->schedAddModList[arrIdx].requestId =\
11356          cuSchedReqList->list.array[arrIdx]->schedulingRequestID;
11357       if(cuSchedReqList->list.array[arrIdx]->periodicityAndOffset)
11358       {
11359          fillPucchSchedReqPeriodAndOffset(macSchedReqCfg->schedAddModList[arrIdx].periodicity,\
11360             macSchedReqCfg->schedAddModList[arrIdx].offset, cuSchedReqList->list.array[arrIdx]->periodicityAndOffset);
11361       }
11362       if(cuSchedReqList->list.array[arrIdx]->resource)
11363       {
11364          macSchedReqCfg->schedAddModList[arrIdx].resrc =\
11365             *cuSchedReqList->list.array[arrIdx]->resource;
11366       }
11367    }
11368
11369 }/* End of extractSchedReqCfgToAddMod */
11370
11371  /*******************************************************************
11372  *
11373  * @brief Fills PucchCfg received by CU
11374  *
11375  * @details
11376  *
11377  *    Function : extractPucchCfg
11378  *
11379  *    Functionality: Fills PucchCfg received  by CU
11380  *
11381  * @params[in] BWP_UplinkDedicated__pucch_Config *cuPucchCfg = Information which
11382  *                is send by CU, which we have stored in F1UeContextSetupDb,
11383  *             PucchCfg *macPucchCfg = Used to Store the information which
11384  *                needs to send in other layer, as well as this can be the variable
11385  *                which stores the information in DuCb,
11386  *             PucchCfg *storedPucchCfg = Null in case of sending the
11387  *                information to other layer else it will have Pucch Cfg which
11388  *                we have stored in copyOfmacUeCfg.
11389  * @return ROK/RFAILED
11390  *
11391  * ****************************************************************/
11392
11393 uint8_t extractPucchCfg(struct BWP_UplinkDedicated__pucch_Config *cuPucchCfg, PucchCfg *macPucchCfg,\
11394 PucchCfg *storedPucchCfg)        
11395 {
11396    uint8_t arrIdx;
11397
11398    if(cuPucchCfg->present == BWP_UplinkDedicated__pucch_Config_PR_setup)
11399    {
11400       if(cuPucchCfg->choice.setup)
11401       {
11402          /* Resource Set Cfg */ 
11403          if(cuPucchCfg->choice.setup->resourceSetToAddModList)
11404          {
11405             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrcSet, sizeof(PucchResrcSetCfg));
11406             if(macPucchCfg->resrcSet == NULLP)
11407             {
11408                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc set List in extractPucchCfg()");
11409                return RFAILED;
11410             }
11411             memset(macPucchCfg->resrcSet, 0, sizeof(PucchResrcSetCfg));
11412             extractResrcSetToAddModList(macPucchCfg->resrcSet, cuPucchCfg->choice.setup->resourceSetToAddModList);
11413          }
11414          
11415          /* Resource Cfg */ 
11416          if(cuPucchCfg->choice.setup->resourceToAddModList)
11417          {
11418             DU_ALLOC_SHRABL_BUF(macPucchCfg->resrc, sizeof(PucchResrcCfg));
11419             if(macPucchCfg->resrc == NULLP)
11420             {
11421                DU_LOG("\nERROR --> F1AP : Failed to extract Resrc List in extractPucchCfg()");
11422                return RFAILED;
11423             }
11424             memset(macPucchCfg->resrc, 0, sizeof(PucchResrcCfg));
11425             extractResrcToAddModList(macPucchCfg->resrc, cuPucchCfg->choice.setup->resourceToAddModList);
11426          }
11427          
11428          /* Format 1 Cfg */ 
11429          if(cuPucchCfg->choice.setup->format1)
11430          {
11431             DU_ALLOC_SHRABL_BUF(macPucchCfg->format1, sizeof(PucchFormatCfg));
11432             if(macPucchCfg->format1 == NULLP)
11433             {
11434                DU_LOG("\nERROR --> F1AP : Failed to extract format 1 Cfg in  extractPucchCfg()");
11435                return RFAILED;
11436             }
11437             memset(macPucchCfg->format1, 0, sizeof(PucchFormatCfg));
11438             extractPucchFormatCfg(macPucchCfg->format1,\
11439                cuPucchCfg->choice.setup->format1->choice.setup);
11440          }
11441          
11442          /* Format 2 Cfg */
11443          if(cuPucchCfg->choice.setup->format2)
11444          {
11445             DU_ALLOC_SHRABL_BUF(macPucchCfg->format2, sizeof(PucchFormatCfg));
11446             if(macPucchCfg->format2 == NULLP)
11447             {
11448                DU_LOG("\nERROR --> F1AP : Failed to extract format 2 Cfg in  extractPucchCfg()");
11449                return RFAILED;
11450             }
11451             memset(macPucchCfg->format2, 0, sizeof(PucchFormatCfg));
11452             extractPucchFormatCfg(macPucchCfg->format2,\
11453                cuPucchCfg->choice.setup->format2->choice.setup);
11454          }
11455          
11456          /* Format 3 Cfg */
11457          if(cuPucchCfg->choice.setup->format3)
11458          {
11459             DU_ALLOC_SHRABL_BUF(macPucchCfg->format3, sizeof(PucchFormatCfg));
11460             if(macPucchCfg->format3 == NULLP)
11461             {
11462                DU_LOG("\nERROR --> F1AP : Failed to extract format 3 Cfg in  extractPucchCfg()");
11463                return RFAILED;
11464             }
11465             memset(macPucchCfg->format3, 0, sizeof(PucchFormatCfg));
11466             extractPucchFormatCfg(macPucchCfg->format3,\
11467                cuPucchCfg->choice.setup->format3->choice.setup);
11468          }
11469
11470          /* Format 4 Cfg */
11471          if(cuPucchCfg->choice.setup->format4)
11472          {
11473             DU_ALLOC_SHRABL_BUF(macPucchCfg->format4, sizeof(PucchFormatCfg));
11474             if(macPucchCfg->format4 == NULLP)
11475             {
11476                DU_LOG("\nERROR --> F1AP : Failed to extract format 4 Cfg in  extractPucchCfg()");
11477                return RFAILED;
11478             }
11479             memset(macPucchCfg->format4, 0, sizeof(PucchFormatCfg));
11480             extractPucchFormatCfg(macPucchCfg->format4,\
11481                cuPucchCfg->choice.setup->format4->choice.setup);
11482          }
11483
11484          /* Sched Req List */
11485          if(cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList)
11486          {
11487             DU_ALLOC_SHRABL_BUF(macPucchCfg->schedReq, sizeof(PucchSchedReqCfg));
11488             if(macPucchCfg->schedReq == NULLP)
11489             {
11490                DU_LOG("\nERROR --> F1AP : Failed to extract schedReqCfg in  extractPucchCfg()");
11491                return RFAILED;
11492             }
11493             memset(macPucchCfg->schedReq, 0, sizeof(PucchSchedReqCfg));
11494             extractSchedReqCfgToAddMod(macPucchCfg->schedReq,\
11495             cuPucchCfg->choice.setup->schedulingRequestResourceToAddModList);
11496          }
11497
11498          /*TODO: Add support for  Spatial Info */
11499
11500          /* MultiCsiCfg */
11501          if(cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList)
11502          {
11503             DU_ALLOC_SHRABL_BUF(macPucchCfg->multiCsiCfg, sizeof(PucchMultiCsiCfg));
11504             if(macPucchCfg->multiCsiCfg == NULLP)
11505             {
11506                DU_LOG("\nERROR --> F1AP : Failed to extract multiCsiCfg in  extractPucchCfg()");
11507                return RFAILED;
11508             }
11509             memset(macPucchCfg->multiCsiCfg, 0, sizeof(PucchMultiCsiCfg));
11510             macPucchCfg->multiCsiCfg->multiCsiResrcListCount = cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.count;
11511             for(arrIdx =0; arrIdx < macPucchCfg->multiCsiCfg->multiCsiResrcListCount; arrIdx++)
11512             {
11513                macPucchCfg->multiCsiCfg->multiCsiResrcList[arrIdx] =\
11514                  *cuPucchCfg->choice.setup->multi_CSI_PUCCH_ResourceList->list.array[arrIdx];
11515             }
11516          }
11517
11518          /* Dl_DataToUL_ACK */ 
11519          if(cuPucchCfg->choice.setup->dl_DataToUL_ACK)
11520     {
11521        if(storedPucchCfg)
11522        {
11523           if(storedPucchCfg->dlDataToUlAck)
11524           {
11525              macPucchCfg->dlDataToUlAck = storedPucchCfg->dlDataToUlAck; 
11526           }
11527           else
11528           {
11529             DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
11530           }
11531        }
11532        else
11533        {
11534           DU_ALLOC_SHRABL_BUF(macPucchCfg->dlDataToUlAck, sizeof(PucchDlDataToUlAck));
11535        }
11536        if(macPucchCfg->dlDataToUlAck == NULLP)
11537        {
11538           DU_LOG("\nERROR --> F1AP : Failed to extract Dl_DataToUL_ACK in extractPucchCfg()");
11539           return RFAILED;
11540        }
11541        memset(macPucchCfg->dlDataToUlAck, 0, sizeof(PucchDlDataToUlAck));
11542        macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount = cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.count;
11543        for(arrIdx = 0; arrIdx < macPucchCfg->dlDataToUlAck->dlDataToUlAckListCount; arrIdx++)
11544        {
11545           macPucchCfg->dlDataToUlAck->dlDataToUlAckList[arrIdx] =\
11546           *cuPucchCfg->choice.setup->dl_DataToUL_ACK->list.array[arrIdx];
11547        }
11548          }
11549
11550          /* Power Control */
11551          if(cuPucchCfg->choice.setup->pucch_PowerControl)
11552          {
11553             DU_ALLOC_SHRABL_BUF(macPucchCfg->powerControl, sizeof(PucchPowerControl));
11554             if(macPucchCfg->powerControl == NULLP)
11555             {
11556                DU_LOG("\nERROR --> F1AP : Failed to extract power control in extractPucchCfg()");
11557                return RFAILED;
11558             }
11559             extractPucchPowerControl(macPucchCfg->powerControl,\
11560                cuPucchCfg->choice.setup->pucch_PowerControl);
11561          }
11562       }
11563    }
11564    return ROK;
11565 }
11566
11567 /*******************************************************************
11568  *
11569  * @brief Fills ServingCellReconfig received by CU
11570  *
11571  * @details
11572  *
11573  *    Function : extractSpCellDedicatedCfg
11574  *
11575  *    Functionality: Fills ServingCellReconfig received  by CU
11576  *
11577  * @params[in] ServingCellConfig_t *cuSrvCellCfg = Information which is send by
11578  *                  CU, which we have stored in F1UeContextSetupDb,
11579  *             ServCellCfgInfo *macSrvCellCfg = Used to Store the information
11580  *                  which  needs to send in other layer, as well as this can be the
11581  *                  variable which stores the information in DuCb, 
11582  *             ServCellCfgInfo *storedSrvCellCfg = Null in case of sending the
11583  *                  information to other layer else it will have ServCellCfgInfo which
11584  *                  we have stored in copyOfmacUeCfg.
11585  * @return ROK/RFAILD
11586  *
11587  * ****************************************************************/
11588 uint8_t extractSpCellDedicatedCfg(ServingCellConfig_t *cuSrvCellCfg, ServCellCfgInfo *macSrvCellCfg,\
11589 ServCellCfgInfo *storedSrvCellCfg)
11590 {
11591    uint8_t ret = ROK;
11592    BWP_DownlinkDedicated_t *dlBwp = NULLP;
11593    BWP_UplinkDedicated_t   *ulBwp = NULLP;
11594
11595    if(cuSrvCellCfg->initialDownlinkBWP)
11596    {
11597       dlBwp = ((BWP_DownlinkDedicated_t *)(cuSrvCellCfg->initialDownlinkBWP));
11598       if(dlBwp->pdcch_Config)
11599       {
11600          if(dlBwp->pdcch_Config->choice.setup)
11601          {
11602             macSrvCellCfg->initDlBwp.pdcchPresent = true;
11603             if(storedSrvCellCfg)
11604             {
11605                if(!storedSrvCellCfg->initDlBwp.pdcchPresent)
11606                {
11607                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11608                }
11609                else
11610                {
11611                   extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11612                }
11613             }
11614             else
11615             {
11616                extractPdcchCfg(dlBwp->pdcch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdcchCfg);
11617             }
11618          }
11619       }
11620       if(dlBwp->pdsch_Config)
11621       {
11622          if(dlBwp->pdsch_Config->choice.setup)
11623          {
11624             macSrvCellCfg->initDlBwp.pdschPresent = true;
11625             
11626             if(storedSrvCellCfg)
11627             {
11628                if(!storedSrvCellCfg->initDlBwp.pdschPresent)
11629                {
11630                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
11631                }
11632                else
11633                {
11634                   extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg,\
11635                         &storedSrvCellCfg->initDlBwp.pdschCfg);
11636                }
11637             }
11638             else
11639             {
11640                extractPdschCfg(dlBwp->pdsch_Config->choice.setup, &macSrvCellCfg->initDlBwp.pdschCfg, NULL);
11641             }
11642          }
11643       }
11644    }
11645    if(cuSrvCellCfg->firstActiveDownlinkBWP_Id)
11646       macSrvCellCfg->firstActvDlBwpId = *(cuSrvCellCfg->firstActiveDownlinkBWP_Id);
11647    if(cuSrvCellCfg->defaultDownlinkBWP_Id)
11648       macSrvCellCfg->defaultDlBwpId = *(cuSrvCellCfg->defaultDownlinkBWP_Id);
11649    if(cuSrvCellCfg->bwp_InactivityTimer)
11650    {
11651       if(macSrvCellCfg->bwpInactivityTmr)
11652       {
11653          memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
11654       }
11655       else
11656       {
11657          macSrvCellCfg->bwpInactivityTmr = NULLP;
11658          DU_ALLOC_SHRABL_BUF(macSrvCellCfg->bwpInactivityTmr, sizeof(uint8_t));
11659          if(macSrvCellCfg->bwpInactivityTmr)
11660          {
11661             memcpy(macSrvCellCfg->bwpInactivityTmr, cuSrvCellCfg->bwp_InactivityTimer, sizeof(uint8_t));
11662          }
11663          else
11664          {
11665             DU_LOG("\nERROR  --> F1AP : Memory Alloc failed for bwpInactivityTmr at extractSpCellDedicatedCfg()");
11666             return RFAILED;
11667          }
11668       }
11669    }
11670    if(cuSrvCellCfg->pdsch_ServingCellConfig)
11671    {
11672       if(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup)
11673       {
11674          ret = extractPdschServingCellCfg(cuSrvCellCfg->pdsch_ServingCellConfig->choice.setup, &macSrvCellCfg->pdschServCellCfg);
11675          if(ret == RFAILED)
11676          {
11677             DU_LOG("\nERROR --> F1AP : Failed at extractPdschServingCellCfg()");
11678             return RFAILED;
11679          }
11680       }
11681    }
11682    if(cuSrvCellCfg->uplinkConfig)
11683    {
11684       if(cuSrvCellCfg->uplinkConfig->initialUplinkBWP)
11685       {
11686          ulBwp = ((BWP_UplinkDedicated_t *)(cuSrvCellCfg->uplinkConfig->initialUplinkBWP));
11687          if(ulBwp->pusch_Config)
11688          {
11689             macSrvCellCfg->initUlBwp.puschPresent = true;
11690             extractPuschCfg(ulBwp->pusch_Config, &macSrvCellCfg->initUlBwp.puschCfg);
11691          }
11692          if(ulBwp->pucch_Config)
11693          {
11694             macSrvCellCfg->initUlBwp.pucchPresent = true;
11695             memset(&macSrvCellCfg->initUlBwp.pucchCfg, 0, sizeof(PucchCfg));
11696             if(storedSrvCellCfg)
11697             {
11698                if(!storedSrvCellCfg->initUlBwp.pucchPresent)
11699                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
11700                else
11701                   extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg,\
11702                   &storedSrvCellCfg->initUlBwp.pucchCfg);
11703             }
11704             else
11705             {
11706                extractPucchCfg(ulBwp->pucch_Config, &macSrvCellCfg->initUlBwp.pucchCfg, NULL);
11707             }
11708          }
11709       }
11710       if(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id)
11711          macSrvCellCfg->firstActvUlBwpId = *(cuSrvCellCfg->uplinkConfig->firstActiveUplinkBWP_Id);
11712    }
11713    return ret;
11714 }
11715 /*******************************************************************
11716  *
11717  * @brief Fills Reconfig Cell group Info received by CU
11718  *
11719  * @details
11720  *
11721  *    Function : extractUeReCfgCellInfo
11722  *
11723  *    Functionality: Fills Reconfig Cell group Info received by CU
11724  *   
11725  * @params[in] CellGroupConfigRrc_t *cellGrp = CellGroupConfigRrc_t information which
11726  *                       is send by CU, which we have stored in F1UeContextSetupDb
11727  *             MacUeCfg *MacUeCfg = Used to Store the information,
11728  *                      which needs to send in other layer, as well as this can be
11729  *                      the variable which stores the information in DuCb,
11730  *             MacUeCfg *storedMacUeCfg = Null in case of sending the
11731  *                      information to other layer else it will have copyOfmacUeCfg
11732  *                      which we have stored in F1UeContextSetupDb.
11733  *
11734  * @return ROK/RFAILED
11735  *
11736  * ****************************************************************/
11737 uint8_t extractUeReCfgCellInfo(CellGroupConfigRrc_t *cellGrp, MacUeCfg *macUeCfg, MacUeCfg *storedMacUeCfg)
11738 {
11739    uint8_t ret = ROK;
11740    MAC_CellGroupConfig_t     *macCellGroup = NULLP;
11741    PhysicalCellGroupConfig_t *phyCellGrpCfg = NULLP;
11742    SpCellConfig_t            *spcellCfg = NULLP;
11743    ServingCellConfig_t       *servCellCfg = NULLP;
11744
11745    if(cellGrp)
11746    {
11747       /* Fill MacCell Group Reconfig  */
11748       if(cellGrp->mac_CellGroupConfig)
11749       {
11750          macUeCfg->macCellGrpCfgPres = true;
11751          macCellGroup = ((MAC_CellGroupConfig_t *)(cellGrp->mac_CellGroupConfig));
11752          if(macCellGroup->schedulingRequestConfig)
11753          {
11754             extractSchReqReConfig(macCellGroup->schedulingRequestConfig, &macUeCfg->macCellGrpCfg.schReqCfg);
11755          }
11756          if(macCellGroup->tag_Config)
11757          {
11758             extractTagReconfig(macCellGroup->tag_Config, &macUeCfg->macCellGrpCfg.tagCfg);
11759          }
11760          if(macCellGroup->bsr_Config)
11761          {
11762             macUeCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer = macCellGroup->bsr_Config->periodicBSR_Timer;
11763             macUeCfg->macCellGrpCfg.bsrTmrCfg.retxTimer     = macCellGroup->bsr_Config->retxBSR_Timer;
11764             if(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer)
11765             {
11766                macUeCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer  =\
11767                *(macCellGroup->bsr_Config->logicalChannelSR_DelayTimer);
11768             }
11769          }
11770          if(macCellGroup->phr_Config)
11771          {
11772             if(macCellGroup->phr_Config->present == MAC_CellGroupConfig__phr_Config_PR_setup)
11773             {
11774                macUeCfg->macCellGrpCfg.phrCfgSetupPres = true;
11775                if(macCellGroup->phr_Config->choice.setup)
11776                {
11777                   macUeCfg->macCellGrpCfg.phrCfg.periodicTimer     = \
11778                   macCellGroup->phr_Config->choice.setup->phr_PeriodicTimer;
11779                   macUeCfg->macCellGrpCfg.phrCfg.prohibitTimer     = \
11780                   macCellGroup->phr_Config->choice.setup->phr_ProhibitTimer;
11781                   macUeCfg->macCellGrpCfg.phrCfg.txPowerFactor     = \
11782                   macCellGroup->phr_Config->choice.setup->phr_Tx_PowerFactorChange;
11783                   macUeCfg->macCellGrpCfg.phrCfg.multiplePHR       = \
11784                   macCellGroup->phr_Config->choice.setup->multiplePHR;
11785                   macUeCfg->macCellGrpCfg.phrCfg.dummy             = \
11786                   macCellGroup->phr_Config->choice.setup->dummy;
11787                   macUeCfg->macCellGrpCfg.phrCfg.phrType2OtherCell = \
11788                   macCellGroup->phr_Config->choice.setup->phr_Type2OtherCell;
11789                   macUeCfg->macCellGrpCfg.phrCfg.phrOtherCG        = \
11790                   macCellGroup->phr_Config->choice.setup->phr_ModeOtherCG;
11791                }
11792             }
11793          }
11794       }
11795       /* Fill Physical Cell Group Reconfig */
11796       if(cellGrp->physicalCellGroupConfig)
11797       {
11798          macUeCfg->phyCellGrpCfgPres = true;
11799          phyCellGrpCfg = ((PhysicalCellGroupConfig_t *)(cellGrp->physicalCellGroupConfig));
11800          if(phyCellGrpCfg->p_NR_FR1)
11801          {
11802             if(*(phyCellGrpCfg->p_NR_FR1) != macUeCfg->phyCellGrpCfg.pNrFr1)
11803                macUeCfg->phyCellGrpCfg.pNrFr1 = *(phyCellGrpCfg->p_NR_FR1);
11804          }
11805          macUeCfg->phyCellGrpCfg.pdschHarqAckCodebook = phyCellGrpCfg->pdsch_HARQ_ACK_Codebook;
11806       }
11807       /* Fill SpCell Reconfig */
11808       if(cellGrp->spCellConfig)
11809       {
11810          macUeCfg->spCellCfgPres = true;
11811          spcellCfg = ((SpCellConfig_t *)(cellGrp->spCellConfig));  
11812          if(spcellCfg->servCellIndex)
11813          {
11814             macUeCfg->spCellCfg.servCellIdx = *(spcellCfg->servCellIndex);
11815          }
11816          /* Fill Serving cell Reconfig info */
11817          if(cellGrp->spCellConfig->spCellConfigDedicated)
11818          {
11819             servCellCfg = ((ServingCellConfig_t *)(cellGrp->spCellConfig->spCellConfigDedicated));
11820             if(storedMacUeCfg)
11821             {
11822                if(!storedMacUeCfg->spCellCfgPres)
11823                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
11824                else
11825                   ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg,\
11826                         &storedMacUeCfg->spCellCfg.servCellCfg);
11827             }
11828             else
11829             {
11830                ret = extractSpCellDedicatedCfg(servCellCfg, &macUeCfg->spCellCfg.servCellCfg, NULL);
11831             }
11832             if(ret == RFAILED)
11833             {
11834                DU_LOG("\nERROR --> F1AP : Failed at extractSpCellDedicatedCfg()");
11835             }
11836          }
11837       }
11838    }
11839    return ret;
11840 }
11841 /*******************************************************************
11842 *
11843 * @brief free the memory allocated by decoder
11844 *
11845 * @details
11846 *
11847 *    Function : freeAperDecodeNrcgi 
11848 *
11849 *    Functionality: Free Nrcgi values
11850 *
11851 * @params[in] NRCGI_t *nrcgi
11852 * @return void
11853 *
11854 * ****************************************************************/
11855
11856
11857 void freeAperDecodeNrcgi(NRCGI_t *nrcgi)
11858 {
11859     if(nrcgi->pLMN_Identity.buf != NULLP)
11860     {
11861        free(nrcgi->pLMN_Identity.buf);
11862     }
11863     if(nrcgi->nRCellIdentity.buf != NULLP)
11864     {
11865        free(nrcgi->nRCellIdentity.buf);
11866     }
11867 }
11868 /*******************************************************************
11869 *
11870 * @brief free the memory allocated by decoder
11871 *
11872 * @details
11873 *
11874 *    Function : freeAperDecodeCuToDuInfo 
11875 *
11876 *    Functionality:  Free Cu To Du Information
11877 *
11878 * @params[in] CUtoDURRCInformation_t *rrcMsg
11879 * @return void
11880 *
11881 * ****************************************************************/
11882
11883
11884 void freeAperDecodeCuToDuInfo(CUtoDURRCInformation_t *rrcMsg)
11885 {
11886    uint8_t ieIdx =0;
11887    uint8_t arrIdx =0;
11888
11889    if(rrcMsg->uE_CapabilityRAT_ContainerList)
11890    {
11891       if(rrcMsg->uE_CapabilityRAT_ContainerList->buf)
11892          free(rrcMsg->uE_CapabilityRAT_ContainerList->buf);
11893       free(rrcMsg->uE_CapabilityRAT_ContainerList);
11894    }
11895
11896    if(rrcMsg->iE_Extensions)
11897    {
11898       if(rrcMsg->iE_Extensions->list.array)
11899       {
11900          for(ieIdx= 0; ieIdx < rrcMsg->iE_Extensions->list.count; ieIdx++)
11901          {
11902             if(rrcMsg->iE_Extensions->list.array[ieIdx])
11903             {
11904                switch(rrcMsg->iE_Extensions->list.array[ieIdx]->id)
11905                {
11906                   case ProtocolIE_ID_id_CellGroupConfig:
11907                      if(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf != NULLP)
11908                      {
11909                         free(rrcMsg->iE_Extensions->list.array[ieIdx]->extensionValue.choice.CellGroupConfig.buf);
11910                      }
11911                      break;
11912                   default:
11913                      DU_LOG("\nERROR  -->  F1AP : Invalid Event type %ld at FreeCuToDuInfo()", \
11914                            rrcMsg->iE_Extensions->list.array[ieIdx]->id);
11915                      break;
11916                }
11917             }
11918          }
11919          for(arrIdx = 0; arrIdx < ieIdx; arrIdx++)
11920          {
11921             free(rrcMsg->iE_Extensions->list.array[arrIdx]);
11922          }
11923          free(rrcMsg->iE_Extensions->list.array);
11924
11925       }
11926
11927       free(rrcMsg->iE_Extensions);
11928    }
11929 }
11930 /*******************************************************************
11931 *
11932 * @brief free the memory allocated by decoder
11933 *
11934 * @details 
11935 *
11936 *    Function : freeAperDecodeSplCellList
11937 *
11938 *    Functionality: Free Spl Cell List 
11939                     where memory allocated by aper_decoder
11940 *
11941 * @params[in]  SCell_ToBeSetup_List_t *spCellLst
11942 * @return void
11943 *
11944 * ****************************************************************/
11945
11946
11947 void freeAperDecodeSplCellList(SCell_ToBeSetup_List_t *spCellLst)
11948 {
11949     uint8_t  cellIdx =0;
11950
11951     if(spCellLst->list.array != NULLP)
11952     {
11953        for(cellIdx=0; cellIdx<spCellLst->list.count; cellIdx++)
11954        {
11955           if(cellIdx==0&&spCellLst->list.array[cellIdx]!=NULLP)
11956           {
11957              freeAperDecodeNrcgi(&spCellLst->list.array[cellIdx]->value.choice.SCell_ToBeSetup_Item.sCell_ID);
11958           }
11959           if(spCellLst->list.array[cellIdx]!=NULLP)
11960           {
11961              free(spCellLst->list.array[cellIdx]);
11962           }
11963        }
11964        free(spCellLst->list.array);
11965     }
11966 }
11967 /*******************************************************************
11968 *
11969 * @brief free the memory allocated by decoder
11970 *
11971 * @details
11972 *
11973 *    Function : freeAperDecodeSRBSetup 
11974 *
11975 *    Functionality: added free part for the memory allocated by aper_decoder
11976 *
11977 * @params[in] SRBs_ToBeSetup_List_t *srbSet
11978 * @return void
11979 *
11980 ****************************************************************/
11981
11982
11983 void freeAperDecodeSRBSetup(SRBs_ToBeSetup_List_t *srbSet)
11984 {
11985     uint8_t srbIdx =0;
11986     if(srbSet->list.array != NULLP)
11987     {
11988        for(srbIdx=0; srbIdx<srbSet->list.count; srbIdx++)
11989        {
11990           if(srbSet->list.array[srbIdx]!=NULLP)
11991           {
11992              free(srbSet->list.array[srbIdx]);
11993           }
11994        }
11995        free(srbSet->list.array);
11996     }
11997 }
11998
11999 /*******************************************************************
12000 *
12001 * @brief free the memory allocated by decoder
12002 *
12003 * @details
12004 *
12005 *    Function : freeAperDecodeULTnlInfo
12006 *
12007 *    Functionality: added free part for the memory allocated by aper_decoder
12008 *
12009 * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
12010 * @return void
12011 *
12012 * ****************************************************************/
12013
12014
12015 void freeAperDecodeULTnlInfo(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
12016 {
12017    uint8_t ulIdx=0;
12018    if(ulInfo->list.array != NULLP)
12019    {
12020       for(ulIdx=0; ulIdx<ulInfo->list.count; ulIdx++)
12021       {
12022          if(ulIdx==0&&ulInfo->list.array[ulIdx]!=NULLP)
12023          {
12024             if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel!=NULLP)
12025             {
12026                if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12027                      transportLayerAddress.buf != NULLP)
12028                {
12029                   if(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf\
12030                         !=NULLP)
12031                   {
12032                      free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf);
12033                   }
12034                   free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel->\
12035                         transportLayerAddress.buf);
12036                }
12037                free(ulInfo->list.array[ulIdx]->uLUPTNLInformation.choice.gTPTunnel);
12038             }
12039          }
12040          if(ulInfo->list.array[ulIdx]!=NULLP)
12041          {
12042             free(ulInfo->list.array[ulIdx]);
12043          }
12044       }
12045       free(ulInfo->list.array);
12046    }
12047 }
12048 /*******************************************************************
12049 *
12050 * @brief free the memory allocated by decoder
12051 *
12052 * @details
12053 *
12054 *    Function : freeAperDecodeDRBSetup  
12055 *
12056 *    Functionality: free DRBSetup which is allocated by decoder
12057 *
12058 * @params[in]  DRBs_ToBeSetup_List_t *drbSet
12059 * @return void
12060 *
12061 * ****************************************************************/
12062
12063 void freeAperDecodeDRBSetup(DRBs_ToBeSetup_List_t *drbSet)
12064 {
12065    DRBs_ToBeSetup_Item_t *drbSetItem = NULLP;
12066    uint8_t  flowIdx =0;
12067    uint8_t  drbIdx =0;
12068
12069    if(drbSet->list.array != NULLP)
12070    {
12071       for(drbIdx=0; drbIdx<drbSet->list.count; drbIdx++)
12072       {
12073          if(drbIdx==0&&drbSet->list.array[drbIdx] != NULLP)
12074          {
12075             drbSetItem =&drbSet->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12076             if(drbSetItem->qoSInformation.choice.choice_extension != NULLP)
12077             {
12078                if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12079                      qoS_Characteristics.choice.non_Dynamic_5QI !=NULLP)
12080                {
12081                   if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12082                         qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12083                   {
12084                      if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12085                            qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12086                      {
12087
12088                         if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf!=NULLP)
12089                         {
12090
12091                            if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD!=NULLP)
12092                            {
12093
12094                               if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD->\
12095                                     buf!=NULLP)
12096                               {
12097
12098                                  if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.\
12099                                        flows_Mapped_To_DRB_List.list.array != NULLP)
12100                                  {
12101
12102                                     for(flowIdx=0;flowIdx<drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12103                                           DRB_Information.flows_Mapped_To_DRB_List.list.count; flowIdx++)
12104                                     {
12105
12106                                        if(flowIdx==0&&drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12107                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12108                                        {
12109                                           if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12110                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12111                                                 qoSFlowLevelQoSParameters.\
12112                                                 qoS_Characteristics.choice.non_Dynamic_5QI!=NULLP)
12113                                           {
12114                                              if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12115                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12116                                                    qoSFlowLevelQoSParameters.\
12117                                                    qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
12118                                              {
12119
12120                                                 if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12121                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12122                                                       qoSFlowLevelQoSParameters.\
12123                                                       qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
12124                                                 {
12125
12126
12127                                                    free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12128                                                          DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12129                                                          qoSFlowLevelQoSParameters.\
12130                                                          qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12131                                                 }
12132
12133                                                 free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12134                                                       DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12135                                                       qoSFlowLevelQoSParameters.\
12136                                                       qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12137                                              }
12138
12139                                              free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12140
12141                                                    DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]->\
12142                                                    qoSFlowLevelQoSParameters.\
12143                                                    qoS_Characteristics.choice.non_Dynamic_5QI);
12144                                           }
12145                                        }
12146                                        if(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12147                                              DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]!=NULLP)
12148                                        {
12149
12150                                           free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12151                                                 DRB_Information.flows_Mapped_To_DRB_List.list.array[flowIdx]);
12152                                        }
12153                                     }
12154
12155                                     free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12156                                           DRB_Information.flows_Mapped_To_DRB_List.list.array);
12157                                  }
12158
12159                                  free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.\
12160                                        DRB_Information.sNSSAI.sD->buf);
12161                               }
12162
12163                               free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sD);
12164                            }
12165
12166                            free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI.sST.buf);
12167
12168                         }
12169
12170                         free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12171
12172                               qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
12173                      }
12174
12175                      free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12176                            qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
12177                   }
12178
12179                   free(drbSetItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.dRB_QoS.\
12180                         qoS_Characteristics.choice.non_Dynamic_5QI);
12181                }
12182                free(drbSetItem->qoSInformation.choice.choice_extension);
12183             }
12184             freeAperDecodeULTnlInfo(&drbSetItem->uLUPTNLInformation_ToBeSetup_List);
12185             if(drbSetItem->uLConfiguration)
12186             {
12187                free(drbSetItem->uLConfiguration);
12188             }
12189          }
12190          if(drbSet->list.array[drbIdx]!=NULLP)
12191          {
12192             free(drbSet->list.array[drbIdx]);
12193          }
12194       }
12195       free(drbSet->list.array);
12196    }
12197 }
12198
12199
12200 /*******************************************************************
12201  *
12202  * @brief builds Mac Cell Cfg
12203  *
12204  * @details
12205  *
12206  *    Function : procUeReCfgCellInfo
12207  *
12208  *    Functionality: builds Mac Cell Cfg
12209  *
12210  * @params[in] MacUeCfg *macUeCfgToSend = Used to Store the information which
12211  *                       needs to send in other layer, as well as this can be
12212  *                       the variable which stores the information in DuCb.
12213  *             MacUeCfg *storedMacUeCfg = Null in case of sending the
12214  *                       information to other layer else it will have copyOfmacUeCfg  
12215  *                       which we have stored in F1UeContextSetupDb
12216  *             void *cellInfo = CellGroupConfigRrc_t information which is send
12217  *                        by CU, which we have stored in F1UeContextSetupDb 
12218  *
12219  * @return void 
12220  *
12221  * ****************************************************************/
12222 uint8_t procUeReCfgCellInfo(MacUeCfg *macUeCfgToSend, MacUeCfg *storedMacUeCfg, void *cellInfo)
12223 {
12224    uint8_t ret = ROK;
12225    CellGroupConfigRrc_t *cellGrp = NULLP;
12226
12227    if(cellInfo)
12228    {
12229       cellGrp = (CellGroupConfigRrc_t *)cellInfo;
12230       ret = extractUeReCfgCellInfo(cellGrp, macUeCfgToSend, storedMacUeCfg);
12231       if(ret == RFAILED)
12232          DU_LOG("\nERROR  -->  F1AP : Failed at procUeReCfgCellInfo()");
12233    }
12234    if(ret == RFAILED)
12235    {
12236       freeUeReCfgCellGrpInfo(macUeCfgToSend);
12237    }
12238    return ret;
12239 }
12240
12241 /*******************************************************************
12242  *
12243  * @brief Filling modulation info in mac ue cfg
12244  *
12245  * @details
12246  *
12247  *    Function : duFillModulationDetails
12248  *
12249  *    Functionality: Filling modulation info in mac ue cfg
12250  *
12251  * @params[in] MAC UE Config to be updated
12252  *             Current UE configuration
12253  *             UE NR capability from CU
12254  * @return ROK     - success
12255  *         RFAILED - failure
12256  *
12257  * ****************************************************************/
12258 void duFillModulationDetails(MacUeCfg *ueCfg, MacUeCfg *oldUeCfg, void *ueCap)
12259 {
12260    UE_NR_Capability_t *ueNrCap=NULLP;
12261
12262    if(!ueCap && oldUeCfg)
12263    {
12264       memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));     
12265       memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12266    }
12267    else
12268    {
12269       ueNrCap = (UE_NR_Capability_t *)ueCap;
12270
12271       /* Filling DL modulation info */
12272       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsDownlinkPerCC && \
12273          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0] && \
12274          ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL)
12275       {
12276          switch(*(ueNrCap->featureSets->featureSetsDownlinkPerCC->list.array[0]->supportedModulationOrderDL))
12277          {
12278             case ModulationOrder_qpsk:
12279                {
12280                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QPSK;
12281                   break;
12282                }
12283             case ModulationOrder_qam16:
12284                {
12285                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM16;
12286                   break;
12287                }
12288             case ModulationOrder_qam64:
12289                {
12290                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM64;
12291                   ueCfg->dlModInfo.mcsIndex = PDSCH_MCS_INDEX;
12292                   ueCfg->dlModInfo.mcsTable = MCS_TABLE_QAM64;
12293                   break;
12294                }
12295             case ModulationOrder_qam256:
12296                {
12297                   ueCfg->dlModInfo.modOrder = MOD_ORDER_QAM256;
12298                   break;
12299                }
12300             default:
12301                {
12302                   DU_LOG("\nERROR  -->  DU APP: Incorrect downlink modulation order received. Reatining old modulation configuration");
12303                   if(oldUeCfg)
12304                      memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
12305                   break;
12306                }
12307          }
12308       }
12309       else
12310       {
12311          if(oldUeCfg)
12312             memcpy(&ueCfg->dlModInfo, &oldUeCfg->dlModInfo, sizeof(ModulationInfo));
12313       }
12314
12315       /* Filling UL modulation info */
12316       if(ueNrCap->featureSets && ueNrCap->featureSets->featureSetsUplinkPerCC && \
12317          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0] && \
12318          ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL)
12319       {
12320          switch(*(ueNrCap->featureSets->featureSetsUplinkPerCC->list.array[0]->supportedModulationOrderUL))
12321          {
12322             case ModulationOrder_qpsk:
12323                {
12324                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QPSK;
12325                   break;
12326                }
12327             case ModulationOrder_qam16:
12328                {
12329                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM16;
12330                   ueCfg->ulModInfo.mcsIndex = PUSCH_MCS_INDEX;
12331                   ueCfg->ulModInfo.mcsTable = MCS_TABLE_QAM64;
12332                   break;
12333                }
12334             case ModulationOrder_qam64:
12335                {
12336                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM64;
12337                   break;
12338                }
12339             case ModulationOrder_qam256:
12340                {
12341                   ueCfg->ulModInfo.modOrder = MOD_ORDER_QAM256;
12342                   break;
12343                }
12344             default:
12345                {
12346                   DU_LOG("\nERROR  -->  DU APP: Incorrect uplink modulation order received. Reatining old modulation configuration");
12347                   if(oldUeCfg)
12348                      memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12349                   break;
12350                }
12351          }
12352       }
12353       else
12354       {
12355          if(oldUeCfg)
12356             memcpy(&ueCfg->ulModInfo, &oldUeCfg->ulModInfo, sizeof(ModulationInfo));
12357       }
12358    }
12359 }
12360
12361 /*******************************************************************
12362  *
12363  * @brief Function to extract info from CU to DU RRC container extension
12364  *
12365  * @details
12366  *
12367  *    Function : extractCuToDuRrcInfoExt
12368  *
12369  *    Functionality: Function to extract info from CU to DU RRC container
12370  *    extension
12371  *
12372  * @params[in] ProtocolExtensionContainer_4624P16_t pointer
12373  *
12374  * @return ROK
12375  *         RFAILED
12376  *
12377  * ****************************************************************/
12378 uint8_t extractCuToDuRrcInfoExt(ProtocolExtensionContainer_4624P16_t *protocolIeExtn, DuUeCfg *ueCfgDb)
12379 {
12380    uint8_t ieIdx =0;
12381    uint16_t recvBufLen =0;
12382    CellGroupConfigRrc_t *cellGrpCfg = NULLP;
12383    CUtoDURRCInformation_ExtIEs_t *extIeInfo = NULLP;
12384    asn_dec_rval_t rval; /* Decoder return value */
12385    memset(&rval, 0, sizeof(asn_dec_rval_t));
12386
12387    if(protocolIeExtn)
12388    {
12389       for(ieIdx = 0; ieIdx < protocolIeExtn->list.count; ieIdx++)
12390       {
12391          extIeInfo = ((CUtoDURRCInformation_ExtIEs_t *)(protocolIeExtn->list.array[ieIdx]));
12392          switch(extIeInfo->id)
12393          {
12394             case ProtocolIE_ID_id_CellGroupConfig:
12395                {
12396                   /* decoding the CellGroup Buf received */
12397                   recvBufLen = extIeInfo->extensionValue.choice.CellGroupConfig.size;
12398                   DU_ALLOC(cellGrpCfg, sizeof(CellGroupConfigRrc_t));
12399                   if(cellGrpCfg)
12400                   {
12401                      memset(cellGrpCfg, 0, sizeof(CellGroupConfigRrc_t));
12402                      rval = aper_decode(0, &asn_DEF_CellGroupConfigRrc, (void **)&cellGrpCfg,
12403                            extIeInfo->extensionValue.choice.CellGroupConfig.buf, recvBufLen, 0, 0);
12404                      if(rval.code == RC_FAIL || rval.code == RC_WMORE)
12405                      {
12406                         DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
12407                         return RFAILED;
12408                      }
12409                      xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, cellGrpCfg);
12410
12411                      if(extractRlcCfgToAddMod(cellGrpCfg->rlc_BearerToAddModList, ueCfgDb))
12412                         return NULLP;
12413                      ueCfgDb->cellGrpCfg = cellGrpCfg;
12414                   }
12415                   break;
12416                }
12417
12418             case ProtocolIE_ID_id_HandoverPreparationInformation:
12419                {
12420                   DU_LOG("\nINFO -->  F1AP : Received HANDOVER PREPARATION INFO in UE CONTEXT SETUP REQUEST");
12421                   break;
12422                }
12423
12424             default:
12425                DU_LOG("\nERROR  -->  F1AP : Invalid IE received CUtoDURRCInformation: %ld at decodeCellGrpCfg()", extIeInfo->id);
12426                break;
12427          }
12428       }
12429    }
12430    return ROK;
12431 }
12432
12433 /*******************************************************************
12434  *
12435  * @brief Fills Srb List received by CU
12436  *
12437  * @details
12438  *
12439  *    Function : procSrbListToSetup
12440  *
12441  *    Functionality: Fills Srb List received  by CU
12442  *
12443  * @params[in] SRBs_ToBeSetup_Item_t *cuSrbItem
12444  *             LcCfg pointer
12445  *             RlcBearerCfg pointer
12446  * @return void
12447  *
12448  * ****************************************************************/
12449 uint8_t procSrbListToSetup(SRBs_ToBeSetup_Item_t * srbItem, LcCfg *macLcToAdd, RlcBearerCfg *rlcLcToAdd)
12450 {
12451
12452    /* Filling RLC INFO */
12453    procRlcLcCfg(srbItem->sRBID, srbItem->sRBID, RB_TYPE_SRB, RLC_AM, CONFIG_ADD, NULL, rlcLcToAdd, NULL);
12454
12455    /* Filling MAC INFO */
12456    if(procMacLcCfg(srbItem->sRBID, RB_TYPE_SRB, CONFIG_ADD, NULL,NULL, NULL, NULL, macLcToAdd, NULL)  != ROK)
12457    { 
12458       DU_LOG("\nERROR  -->  F1AP : Failed at MAC LC Cfg in procSrbListToSetup()");
12459       return RFAILED;
12460    }
12461
12462    return ROK;
12463 }
12464
12465
12466
12467 /*******************************************************************
12468  *
12469  * @brief extract Srb List received by CU
12470  *
12471  * @details
12472  *
12473  *    Function : extractSrbListToSetup
12474  *
12475  *    Functionality: extract Srb List received by CU
12476  *                   for both MAC and RLC
12477  *
12478  * @params[in] SRBs_ToBeSetup_Item_t pointer
12479  *             DuUeCfg pointer
12480  * @return ROK/RFAIED
12481  *
12482  * ****************************************************************/
12483
12484 uint8_t extractSrbListToSetup(SRBs_ToBeSetup_List_t *srbCfg, DuUeCfg *ueCfgDb)
12485 {
12486    uint8_t ret = ROK, srbIdx = 0, rlcLcIdx = 0;
12487    SRBs_ToBeSetup_Item_t *srbItem = NULLP;
12488    LcCfg *macLcCtxt = NULLP;
12489    RlcBearerCfg *rlcLcCtxt = NULLP;
12490
12491    if(srbCfg)
12492    {
12493       for(srbIdx = 0; srbIdx < srbCfg->list.count; srbIdx++)
12494       {
12495          macLcCtxt = NULL;
12496          rlcLcCtxt = NULL;
12497
12498          srbItem = &srbCfg->list.array[srbIdx]->value.choice.SRBs_ToBeSetup_Item;
12499          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
12500          { 
12501             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in MAC");
12502             ret = RFAILED;
12503             break;
12504          }
12505          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
12506          {
12507             DU_LOG("\nERROR   -->  F1AP:  MAX LC Reached in RLC");
12508             ret = RFAILED;
12509             break;
12510          }
12511
12512          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numMacLcs; rlcLcIdx++)
12513          {
12514             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rbId == srbItem->sRBID && ueCfgDb->rlcLcCfg[rlcLcIdx].rbType == RB_TYPE_SRB)
12515             {
12516                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
12517                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
12518                break;
12519             }
12520          }
12521          if(!macLcCtxt)
12522          {
12523             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(LcCfg));
12524             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
12525             ueCfgDb->numMacLcs++;
12526          }
12527          if(!rlcLcCtxt)
12528          {
12529             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
12530             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
12531             ueCfgDb->numRlcLcs++;
12532          }
12533
12534          ret = procSrbListToSetup(srbItem, macLcCtxt, rlcLcCtxt);
12535
12536          DU_LOG("\nDEBUG --> DUAPP: extractSrbListToSetup: SRBID: %ld [RLC,MAC,NumDrb]:[%x,%x,%x]",\
12537                srbItem->sRBID, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
12538          if(ret == RFAILED)
12539          {
12540             DU_LOG("\nERROR  -->  F1AP:  Failed at extractSrbListToSetup()");
12541             break;
12542          }
12543       }
12544    }
12545    else
12546       ret = RFAILED;
12547
12548    return ret;
12549 }
12550
12551 /*******************************************************************
12552  *
12553  * @brief Fills Drb List received by CU
12554  *
12555  * @details
12556  *
12557  *    Function : procDrbListToSetupMod
12558  *
12559  *    Functionality: Fills Drb List received by CU
12560  *                   for both MAC and RLC
12561  *
12562  * @params[in] DRBs_ToBeSetup_Item_t , DRBs_ToBeSetupMod_Item_t,
12563  *             DRBs_ToBeModified_Item_t , lcId, LcCfg pointer,
12564  *             RlcBearerCfg , UpTnlCfg, RlcUeCfg
12565  * @return void
12566  *
12567  * ****************************************************************/
12568
12569 uint8_t procDrbListToSetupMod(uint8_t lcId, DRBs_ToBeSetup_Item_t *drbItem,\
12570 DRBs_ToBeSetupMod_Item_t *drbSetupModItem, DRBs_ToBeModified_Item_t *drbModItem, LcCfg *macLcToAdd, RlcBearerCfg *rlcLcToAdd, UpTnlCfg *upTnlInfo, RlcUeCfg *storedRlcUeCfg)
12571 {
12572    uint8_t cfgIdx = 0;
12573    RlcMode rlcModeInfo;
12574
12575    if(drbItem != NULLP)
12576    {
12577       /* Filling RLC INFO */
12578       procRlcLcCfg(drbItem->dRBID, lcId, RB_TYPE_DRB, drbItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, &drbItem->\
12579       qoSInformation);
12580
12581       /* Filling MAC INFO */
12582       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, drbItem, NULL, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
12583       { 
12584          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
12585          return RFAILED;
12586       }
12587    }
12588    else if(drbSetupModItem != NULLP)
12589    {
12590       procRlcLcCfg(drbSetupModItem->dRBID, lcId, RB_TYPE_DRB, drbSetupModItem->rLCMode, CONFIG_ADD, NULL, rlcLcToAdd, 
12591       &drbSetupModItem->qoSInformation);
12592
12593       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_ADD, NULL, drbSetupModItem, NULL, NULL, macLcToAdd, upTnlInfo) != ROK)
12594       {
12595          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
12596          return RFAILED;
12597       }
12598    }
12599    else if(drbModItem != NULLP)
12600    {
12601       /* Drb to Mod IEs doesnot have rlcMode to be modified
12602        * in ASN. Hence no change in RLC configurations */
12603       if(storedRlcUeCfg != NULLP)
12604       {
12605          for(cfgIdx = 0; cfgIdx < storedRlcUeCfg->numLcs; cfgIdx++)
12606          {
12607             if(storedRlcUeCfg->rlcLcCfg[cfgIdx].lcId == lcId)
12608             {
12609                rlcModeInfo = storedRlcUeCfg->rlcLcCfg[cfgIdx].rlcMode;
12610                break;
12611             }
12612          }
12613       }
12614
12615       procRlcLcCfg(drbModItem->dRBID, lcId, RB_TYPE_DRB, rlcModeInfo, CONFIG_MOD, NULL, rlcLcToAdd, drbModItem->qoSInformation);
12616       if(procMacLcCfg(lcId, RB_TYPE_DRB, CONFIG_MOD, NULL, NULL, drbModItem, NULL, macLcToAdd, upTnlInfo) != ROK)
12617       {
12618          DU_LOG("\nERROR  --> F1AP : Failed at RLC LC Cfg in procDrbListToSetupMod()");
12619          return RFAILED;
12620       }
12621    }
12622    return ROK;
12623 }
12624
12625 /*******************************************************************
12626  *
12627  * @brief extract Drb List received by CU
12628  *
12629  * @details
12630  *
12631  *    Function : extractDrbListToSetupMod
12632  *
12633  *    Functionality: extract Drb List received by CU
12634  *                   for both MAC and RLC
12635  *
12636  * @params[in] DRBs_ToBeSetup_Item_t pointer
12637  *             DuUeCfg pointer
12638  * @return ROK/RFAIED
12639  *
12640  * ****************************************************************/
12641
12642 uint8_t extractDrbListToSetupMod(DRBs_ToBeSetup_List_t *drbCfg, DRBs_ToBeSetupMod_List_t *drbSetupModCfg,\
12643  DRBs_ToBeModified_List_t *drbModCfg, uint8_t drbCount, DuUeCfg *ueCfgDb, uint32_t *drbBitMap, RlcUeCfg *rlcUeCfg)
12644 {
12645    uint8_t ret = ROK;
12646    uint8_t drbIdx = 0, rlcLcIdx = 0;
12647    uint8_t drbId = 0, lcId = 0;
12648    DRBs_ToBeSetup_Item_t *drbItem = NULLP;
12649    DRBs_ToBeSetupMod_ItemIEs_t *drbSetupModItem = NULLP;
12650    DRBs_ToBeModified_ItemIEs_t *drbModItem = NULLP;
12651    LcCfg *macLcCtxt = NULLP;
12652    RlcBearerCfg *rlcLcCtxt = NULLP;
12653
12654    ret = ROK;
12655    if(drbCount > 0)
12656    {
12657       for(drbIdx = 0; drbIdx < drbCount; drbIdx++)
12658       {
12659          macLcCtxt = NULL;
12660          rlcLcCtxt = NULL;
12661
12662          if(ueCfgDb->numMacLcs > MAX_NUM_LC)
12663          { 
12664             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in MAC at extractDrbListToSetupMod()");
12665             ret = RFAILED;
12666             break;
12667          }
12668          if(ueCfgDb->numRlcLcs > MAX_NUM_LC)
12669          {
12670             DU_LOG("\nERROR  -->  F1AP :  MAX LC Reached in RLC at extractDrbListToSetupMod()");
12671             ret = RFAILED;
12672             break;
12673          }
12674
12675          if(drbModCfg != NULLP)
12676          {
12677             drbModItem = (DRBs_ToBeModified_ItemIEs_t *) drbModCfg->list.array[drbIdx];
12678             drbId = drbModItem->value.choice.DRBs_ToBeModified_Item.dRBID;
12679          }
12680          else if(drbCfg != NULLP)
12681             drbId = drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item.dRBID;
12682          else if(drbSetupModCfg != NULL)
12683          {
12684             drbSetupModItem = (DRBs_ToBeSetupMod_ItemIEs_t *) drbSetupModCfg->list.array[drbIdx];
12685             drbId = drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item.dRBID;
12686          }
12687
12688          for(rlcLcIdx = 0; rlcLcIdx < ueCfgDb->numRlcLcs; rlcLcIdx++)
12689          {
12690             if(ueCfgDb->rlcLcCfg[rlcLcIdx].rbId == drbId && ueCfgDb->rlcLcCfg[rlcLcIdx].rbType == RB_TYPE_DRB)
12691             {
12692                macLcCtxt = &ueCfgDb->macLcCfg[rlcLcIdx];
12693                rlcLcCtxt = &ueCfgDb->rlcLcCfg[rlcLcIdx];
12694                break;
12695             }
12696          }
12697          if(!macLcCtxt)
12698          {
12699             memset(&ueCfgDb->macLcCfg[ueCfgDb->numMacLcs], 0, sizeof(LcCfg));
12700             macLcCtxt = &ueCfgDb->macLcCfg[ueCfgDb->numMacLcs];
12701             ueCfgDb->numMacLcs++;
12702          }
12703          if(!rlcLcCtxt)
12704          {
12705             memset(&ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs], 0, sizeof(RlcBearerCfg));
12706             rlcLcCtxt = &ueCfgDb->rlcLcCfg[ueCfgDb->numRlcLcs];
12707             ueCfgDb->numRlcLcs++;
12708          }
12709
12710          if(drbModCfg != NULLP)
12711          {
12712             lcId = fetchLcId(drbId);
12713             if(lcId < MIN_DRB_LCID)
12714             {
12715                DU_LOG("\nERROR  --> F1AP : Failed fetching LCID %d in extractDrbListToSetupMod() for Modified List", lcId);
12716                break;
12717             } 
12718             ret = procDrbListToSetupMod(lcId, NULL, NULL, &(drbModItem->value.choice.DRBs_ToBeModified_Item),\
12719             macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
12720             if(ret == RFAILED)
12721             {
12722                DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for Modified List");
12723                break;
12724             }
12725          }
12726          else
12727          {
12728             lcId = getDrbLcId(drbBitMap);
12729             if(lcId == RFAILED)
12730             {
12731                DU_LOG("\nERROR  -->  F1AP :  InCorrect LCID extractDrbListToSetupMod()");
12732                ret = RFAILED;
12733                break;
12734             }
12735             if(drbCfg != NULL)
12736             {
12737                drbItem = &drbCfg->list.array[drbIdx]->value.choice.DRBs_ToBeSetup_Item;
12738                ret = procDrbListToSetupMod(lcId, drbItem, NULL, NULL, macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
12739                if(ret == RFAILED)
12740                {
12741                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetup List");
12742                   break;
12743                }
12744             }
12745             else if(drbSetupModCfg != NULL)
12746             {
12747                ret = procDrbListToSetupMod(lcId, NULL, &(drbSetupModItem->value.choice.DRBs_ToBeSetupMod_Item), NULL,\
12748                      macLcCtxt, rlcLcCtxt, &ueCfgDb->upTnlInfo[ueCfgDb->numDrb], rlcUeCfg);
12749                if(ret == RFAILED)
12750                {
12751                   DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod() for DrbSetupMod List");
12752                   break;
12753                }
12754                ueCfgDb->numDrbSetupMod++;
12755             }
12756          }
12757          ueCfgDb->numDrb++;
12758  
12759          DU_LOG("\nDEBUG --> DUAPP: extractDrbListToSetupMod:lcId:%x ,BitMap:%x, [RLC,MAC,NumDrb]:[%x,%x,%x]",\
12760                             lcId,*drbBitMap, ueCfgDb->numRlcLcs, ueCfgDb->numMacLcs,  ueCfgDb->numDrb);
12761          if(ret == RFAILED)
12762          {
12763             DU_LOG("\nERROR  --> F1AP : Failed at extractDrbListToSetupMod()");
12764             break;
12765          }
12766       }
12767    }
12768    else
12769       ret = RFAILED;
12770
12771    return ret;
12772 }
12773
12774 /*******************************************************************
12775  *
12776  * @brief Function to extract Dl RRC Msg received from CU
12777  *
12778  * @details
12779  *
12780  *    Function : extractDlRrcMsg
12781  *
12782  *    Functionality: Function to extract Dl RRC Msg received from CU
12783  *
12784  * @params[in] F1AP message
12785  * @return ROK     - success
12786  *         RFAILED - failure
12787  *
12788  * ****************************************************************/
12789
12790 uint8_t extractDlRrcMsg(uint32_t gnbDuUeF1apId, uint32_t gnbCuUeF1apId, \
12791    F1DlRrcMsg *dlRrcMsg, RRCContainer_t *rrcContainer)
12792 {
12793    uint8_t ret = ROK;
12794    dlRrcMsg->rrcMsgSize = rrcContainer->size;
12795    if(dlRrcMsg->rrcMsgSize > 0)
12796    {
12797       DU_ALLOC_SHRABL_BUF(dlRrcMsg->rrcMsgPdu, dlRrcMsg->rrcMsgSize);
12798       if(!dlRrcMsg->rrcMsgPdu)
12799       {
12800          DU_LOG("\nERROR  --> DU APP : Memory allocation failed for RRC Msg in extractDlRrcMsg()");
12801          ret = RFAILED;
12802       }
12803       else
12804       {
12805          dlRrcMsg->gnbDuUeF1apId = gnbDuUeF1apId;
12806          dlRrcMsg->gnbCuUeF1apId = gnbCuUeF1apId;
12807          dlRrcMsg->srbId = SRB1_LCID;
12808          memcpy(dlRrcMsg->rrcMsgPdu, rrcContainer->buf, dlRrcMsg->rrcMsgSize);
12809       }
12810    }
12811    return ret;
12812 }
12813
12814 /*******************************************************************
12815  *
12816  * @brief Extract UE capability info 
12817  *
12818  * @details
12819  *
12820  *    Function : extractUeCapability
12821  *
12822  *    Functionality: Extract UE capability info and stores in ue Cb
12823  *
12824  * @params[in] Octet string of UE capability RAT container list
12825  * @return ROK     - success
12826  *         RFAILED - failure
12827  *
12828  * ****************************************************************/
12829 UE_NR_Capability_t *extractUeCapability(UE_CapabilityRAT_ContainerList_t *ueCapablityListBuf, DuUeCb *ueCb)
12830 {
12831    uint8_t  idx;
12832    uint16_t recvBufLen;
12833    asn_dec_rval_t rval;
12834    UE_NR_Capability_t  *ueNrCap = NULLP;
12835    UE_CapabilityRAT_ContainerListRRC_t  *ueCapRatContList = NULLP;
12836
12837    /* Decoding UE Capability RAT Container List */
12838    recvBufLen = ueCapablityListBuf->size;
12839    DU_ALLOC(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
12840    if(!ueCapRatContList)
12841    {
12842       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
12843       return NULLP;
12844    }
12845    memset(ueCapRatContList, 0, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
12846    memset(&rval, 0, sizeof(asn_dec_rval_t));
12847    rval = aper_decode(0, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, (void **)&ueCapRatContList,
12848           ueCapablityListBuf->buf, recvBufLen, 0, 0);
12849    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
12850    {
12851       DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
12852       return NULLP;
12853    }
12854    xer_fprint(stdout, &asn_DEF_UE_CapabilityRAT_ContainerListRRC, ueCapRatContList);
12855
12856    /* Free encoded buffer after decoding */
12857
12858    for(idx = 0; idx < ueCapRatContList->list.count; idx++)
12859    {
12860       if(ueCapRatContList->list.array[idx]->rat_Type == RAT_Type_nr)
12861       {
12862          /* Decoding UE NR Capability */
12863           recvBufLen = ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.size;
12864           DU_ALLOC(ueNrCap, sizeof(UE_NR_Capability_t));
12865           if(!ueNrCap)
12866           {
12867              DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in extractUeCapability");
12868              DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
12869              return NULLP;
12870           } 
12871           memset(ueNrCap, 0, sizeof(UE_NR_Capability_t));
12872           memset(&rval, 0, sizeof(asn_dec_rval_t));
12873           rval = aper_decode(0, &asn_DEF_UE_NR_Capability, (void **)&ueNrCap,
12874                  ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf, recvBufLen, 0, 0);
12875           if(rval.code == RC_FAIL || rval.code == RC_WMORE)
12876           {
12877              DU_LOG("\nERROR  -->  F1AP : ASN decode failed at decodeCellGrpCfg()");
12878              return NULLP;
12879           }
12880           xer_fprint(stdout, &asn_DEF_UE_NR_Capability, ueNrCap);
12881           
12882           /* Free encoded buffer after decoding */
12883           free(ueCapRatContList->list.array[idx]->ue_CapabilityRAT_Container.buf);
12884       }
12885       free(ueCapRatContList->list.array[idx]);
12886    }
12887
12888    /* Free Memory*/
12889    free(ueCapRatContList->list.array);
12890    DU_FREE(ueCapRatContList, sizeof(UE_CapabilityRAT_ContainerListRRC_t));
12891    return ueNrCap;
12892 }
12893  
12894 /*******************************************************************
12895 *
12896 * @brief free UE context setup request from CU
12897 *
12898 * @details
12899 *
12900 *    Function : freeAperDecodeF1UeContextSetupReq
12901 *
12902 *    Functionality: freeing part for the memory allocated by aper_decoder
12903 *
12904 * @params[in] F1AP message
12905 * @return ROK     - success
12906 *         RFAILED - failure
12907 *
12908 * ****************************************************************/
12909 void freeAperDecodeF1UeContextSetupReq(UEContextSetupRequest_t   *ueSetReq)
12910 {
12911    uint8_t ieIdx = 0;
12912
12913    if(ueSetReq->protocolIEs.list.array != NULLP)
12914    {
12915       for(ieIdx = 0; ieIdx < ueSetReq->protocolIEs.list.count; ieIdx++)
12916       {
12917          if(ueSetReq->protocolIEs.list.array[ieIdx])
12918          {
12919             switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
12920             {
12921                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
12922                   break;
12923                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
12924                   break;
12925                case ProtocolIE_ID_id_SpCell_ID:
12926                   freeAperDecodeNrcgi(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI);
12927                   break;
12928                case ProtocolIE_ID_id_ServCellIndex:
12929                   break;
12930                case ProtocolIE_ID_id_SpCellULConfigured:
12931                   break;
12932                case ProtocolIE_ID_id_CUtoDURRCInformation:
12933
12934                   freeAperDecodeCuToDuInfo(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation);
12935                   break;
12936                case ProtocolIE_ID_id_SCell_ToBeSetup_List:
12937
12938                   freeAperDecodeSplCellList(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SCell_ToBeSetup_List);
12939                   break;
12940                case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
12941
12942                   freeAperDecodeSRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List);
12943                   break;
12944                case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
12945
12946                   freeAperDecodeDRBSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List);
12947                   break;
12948                case ProtocolIE_ID_id_RRCContainer:
12949                   {
12950
12951                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf != NULLP)
12952                      {
12953
12954                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
12955                      }
12956                      break;
12957                   }
12958                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
12959                   break;
12960                case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
12961                   {
12962                      if(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf)
12963                      {
12964                         free(ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf);
12965                      }
12966                      break;
12967                   }
12968                default:
12969                   DU_LOG("\nERROR  -->  F1AP: Invalid event type %ld " ,ueSetReq->protocolIEs.list.array[ieIdx]->id);
12970             } 
12971             free(ueSetReq->protocolIEs.list.array[ieIdx]);
12972          }
12973       }
12974       free(ueSetReq->protocolIEs.list.array);
12975    }
12976 }
12977 /*******************************************************************
12978  *
12979  * @brief Process UE context setup request from CU
12980  *
12981  * @details
12982  *
12983  *    Function : procF1UeContextSetupReq
12984  *
12985  *    Functionality: Process UE context setup request from CU
12986  *
12987  * @params[in] F1AP message
12988  * @return ROK     - success
12989  *         RFAILED - failure
12990  *
12991  * ****************************************************************/
12992 uint8_t procF1UeContextSetupReq(F1AP_PDU_t *f1apMsg)
12993 {
12994    int8_t ueIdx = -1;
12995    uint8_t  ret=0, ieIdx=0, ieExtIdx = 0, servCellIdx = 0;
12996    bool ueCbFound = false, hoInProgress = false;
12997    uint16_t nrCellId = 0,  cellIdx=0;
12998    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0, bitRateSize=0;
12999    DuUeCb   *duUeCb = NULL;
13000    UEContextSetupRequest_t   *ueSetReq = NULL;
13001    DRBs_ToBeSetup_List_t *drbCfg = NULL;
13002    CUtoDURRCInformation_t *rrcInfo = NULL;
13003
13004    ret = ROK;
13005
13006    ueSetReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextSetupRequest;
13007    for(ieIdx=0; (ieIdx < ueSetReq->protocolIEs.list.count && ret == ROK); ieIdx++)
13008    {
13009       switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
13010       {
13011          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13012             {
13013                gnbCuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
13014                break;
13015             }
13016
13017          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13018             {
13019                gnbDuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
13020                break;
13021             }
13022
13023          case ProtocolIE_ID_id_SpCell_ID:
13024             {
13025                bitStringToInt(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.NRCGI.nRCellIdentity, &nrCellId);
13026
13027                GET_CELL_IDX(nrCellId, cellIdx);
13028                if(!duCb.actvCellLst[cellIdx])
13029                {
13030                   DU_LOG("\nERROR  -->  F1AP : Cell Id [%d] not found", nrCellId);
13031                   ret = RFAILED;
13032                }
13033                break;
13034             }
13035
13036          case ProtocolIE_ID_id_ServCellIndex:
13037             {
13038                servCellIdx = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.ServCellIndex;
13039                break;
13040             }
13041
13042          case ProtocolIE_ID_id_SpCellULConfigured:
13043             {
13044                /* Indicates whether the gNB-CU requests the gNB-DU to configure the uplink as no UL, 
13045                   UL, SUL or UL+SUL for the indicated cell for the UE */
13046                break;
13047             }
13048
13049          case ProtocolIE_ID_id_CUtoDURRCInformation:
13050             {
13051                rrcInfo = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.CUtoDURRCInformation;
13052
13053                /* Search if UE context is present */
13054                for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
13055                {
13056                   if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId)
13057                   {
13058                      ueCbFound = true;
13059                      duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13060                      break;
13061                   }
13062                }
13063
13064                /* Check if UE Handover scenario */
13065                if(rrcInfo->iE_Extensions)
13066                {
13067                   for(ieExtIdx = 0; ieExtIdx < rrcInfo->iE_Extensions->list.count; ieExtIdx++)
13068                   {
13069                      if(rrcInfo->iE_Extensions->list.array[ieExtIdx]->id == ProtocolIE_ID_id_HandoverPreparationInformation)
13070                      {
13071                         hoInProgress = true;
13072                         break;
13073                      }
13074                   }
13075                }
13076                
13077                /* If UE context is not present, but UE is in handover */
13078                if(!ueCbFound && hoInProgress)
13079                {
13080                   ueIdx = getFreeBitFromUeBitMap(nrCellId);
13081                   if(ueIdx != -1)
13082                      gnbDuUeF1apId = ueIdx +1;
13083                   else
13084                   {
13085                      DU_LOG("\nERROR  -->  F1AP : No free UE IDX found in UE bit map of cell Id [%d]", nrCellId);
13086                      ret = RFAILED;
13087                      break;
13088                   }
13089                   duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
13090                   duUeCb->f1UeDb = NULL;
13091                   duUeCb->gnbCuUeF1apId = gnbCuUeF1apId;
13092                   duUeCb->gnbDuUeF1apId = gnbDuUeF1apId;
13093                   GET_CRNTI(duUeCb->crnti, duUeCb->gnbDuUeF1apId);
13094                   duUeCb->ueState = UE_HANDIN_IN_PROGRESS;
13095                }
13096
13097                if(duUeCb)
13098                {
13099                   DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
13100                   if(duUeCb->f1UeDb)
13101                   {
13102                      memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
13103                      duUeCb->f1UeDb->actionType = UE_CTXT_SETUP;
13104                      duUeCb->f1UeDb->cellIdx = cellIdx;
13105                   }
13106                   else
13107                   {
13108                      DU_LOG("\nERROR  -->  F1AP: Memory Alloc Failed at procF1UeContextSetupReq()");
13109                      ret = RFAILED;
13110                      break;
13111                   }
13112                }
13113                else
13114                {
13115                   DU_LOG("\nERROR  -->  F1AP: DuUeCb is not found at procF1UeContextSetupReq()");
13116                   ret = RFAILED;
13117                   break;
13118                }
13119                  
13120                /* Extract UE capability info */
13121                if(rrcInfo->uE_CapabilityRAT_ContainerList)
13122                {
13123                   duUeCb->f1UeDb->duUeCfg.ueNrCapability = extractUeCapability(rrcInfo->uE_CapabilityRAT_ContainerList, duUeCb);
13124                }
13125
13126                /* Extract IE extension */
13127                if(rrcInfo->iE_Extensions)
13128                {
13129                   if(extractCuToDuRrcInfoExt(rrcInfo->iE_Extensions, &duUeCb->f1UeDb->duUeCfg) != ROK)
13130                   {
13131                      DU_LOG("\nERROR  -->  F1AP: Failed to extract CU to DU RRC information extension IE");
13132                      //TODO: Update the failure cause in ue context Setup Response
13133                      ret = RFAILED;
13134                   }
13135                }
13136                break;
13137             } 
13138
13139          case ProtocolIE_ID_id_SCell_ToBeSetup_List:
13140             {
13141                DU_LOG("\nINFO   -->  DU_APP: Received SCell_ToBeSetup_List but  Not processing the list");
13142                break;
13143             }
13144
13145          case ProtocolIE_ID_id_SRBs_ToBeSetup_List:
13146             {
13147                if(extractSrbListToSetup(&ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.SRBs_ToBeSetup_List,\
13148                         &duUeCb->f1UeDb->duUeCfg))
13149                {
13150                   DU_LOG("\nERROR  -->  DU APP : Failed at extractSrbListToSetup()");
13151                   //TODO: Update the failure cause in ue context Setup Response
13152                   ret = RFAILED;
13153                }
13154                break;
13155             }
13156
13157          case ProtocolIE_ID_id_DRBs_ToBeSetup_List:
13158             {
13159                drbCfg = &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.DRBs_ToBeSetup_List;
13160
13161                if(extractDrbListToSetupMod(drbCfg, NULL, NULL, drbCfg->list.count, &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULLP))
13162                {
13163                   DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod()");
13164                   //TODO: Update the failure cause in ue context Setup Response
13165                   ret = RFAILED;
13166                }
13167                break;
13168             }
13169
13170          case ProtocolIE_ID_id_RRCContainer:
13171             {
13172                /* Filling Dl RRC Msg Info */
13173                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
13174                if(!duUeCb->f1UeDb->dlRrcMsg)
13175                {
13176                   DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for DL RRC Msg in procUeCtxtSetupReq()");
13177                   ret = RFAILED;
13178                }
13179                else
13180                {
13181                   duUeCb->f1UeDb->dlRrcMsgPres = true;
13182                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
13183                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
13184                         &ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer);
13185                }          
13186                break;
13187             }
13188
13189          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
13190             {
13191                if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
13192                {
13193                   duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
13194                }
13195                else
13196                {
13197                   DU_LOG("\nERROR  -->  Ignoring delivery report, since rrcContainer is not present");
13198                }
13199                break;
13200             }
13201
13202          case ProtocolIE_ID_id_GNB_DU_UE_AMBR_UL:
13203             {
13204                /* MaximumBitRate Uplink */
13205                bitRateSize = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.size;
13206                if(bitRateSize > 0)
13207                {
13208                   DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->duUeCfg.ambrCfg, bitRateSize);
13209                   if(!duUeCb->f1UeDb->duUeCfg.ambrCfg)
13210                   {
13211                      DU_LOG("\nERROR  -->  DU APP : Memory allocation failed for bitRate in procUeCtxtSetupReq");
13212                      ret = RFAILED;
13213                   }
13214                   else
13215                   {
13216                      memset(duUeCb->f1UeDb->duUeCfg.ambrCfg, 0, sizeof(AmbrCfg)); 
13217                      memcpy(&duUeCb->f1UeDb->duUeCfg.ambrCfg->ulBr,
13218                            ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.BitRate.buf, bitRateSize);
13219                   }
13220                }
13221                else
13222                   ret = RFAILED;
13223                break;
13224             }
13225
13226          default:
13227             {
13228                break;
13229             }
13230       } /* End of switch */
13231
13232       /* In case of any failure in any IE */
13233       if(ret == RFAILED)
13234       {
13235          // BuildAndSendUeContextSetupRsp(cellId,ueId);
13236          DU_LOG("\nERROR  -->  F1AP: Failed to process UE CNTXT SETUP REQ at procF1UeContextSetupReq()"); 
13237          break;
13238       }
13239    } /* End of for loop of IEs */
13240
13241    if(ret == ROK)
13242       ret = duProcUeContextSetupRequest(duUeCb);
13243
13244    freeAperDecodeF1UeContextSetupReq(ueSetReq); 
13245    return ret;
13246
13247 }
13248 /*******************************************************************
13249  * @brief Free the memory allocated for Dl Tunnel Info
13250  *
13251  * @details
13252  *
13253  *    Function : freeDlTnlInfo
13254  *
13255  *    Functionality:
13256  *       Free the memory allocated for Dl Tunnel Info
13257  *
13258  * @params[in] DLUPTNLInformation_ToBeSetup_List_t *
13259  * @return void
13260  *
13261  * ****************************************************************/
13262
13263 void freeDlTnlInfo(DLUPTNLInformation_ToBeSetup_List_t *tnlInfo)
13264 {
13265    uint8_t arrIdx = 0;
13266
13267    if(tnlInfo)
13268    {
13269       for(arrIdx=0; arrIdx < tnlInfo->list.count; arrIdx++)
13270       {
13271          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf,\
13272                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.size);
13273          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf,\
13274                tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel->gTP_TEID.size);
13275          DU_FREE(tnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
13276          DU_FREE(tnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
13277       }
13278       DU_FREE(tnlInfo->list.array, tnlInfo->list.size);
13279    }
13280 }
13281
13282 /*******************************************************************
13283  * @brief Free the memory allocated for DRB setup List
13284  *
13285  * @details
13286  *
13287  *    Function : freeDrbSetupList
13288  *
13289  *    Functionality:
13290  *       Free the memory allocated for DRB setup list
13291  *
13292  * @params[in] DRBs_Setup_List_t *
13293  * @return void
13294  *
13295  * ****************************************************************/
13296 void freeDrbSetupList(DRBs_Setup_List_t *drbSetupList)
13297 {
13298    uint8_t arrIdx = 0;
13299    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
13300
13301    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
13302    {
13303       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
13304       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List);
13305       DU_FREE(drbSetupList->list.array[arrIdx],  sizeof(DRBs_Setup_Item_t));
13306    }
13307    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
13308 }
13309
13310 /*******************************************************************
13311  * @brief Free the memory allocated for UE Setup response
13312  *
13313  * @details
13314  *
13315  *    Function : FreeUeContextSetupRsp
13316  *
13317  *    Functionality:
13318  *       Free the memory allocated for UE Setup response
13319  *
13320  * @params[in] F1AP PDU for UE setup response
13321  * @return ROK     - success
13322  *         RFAILED - failure
13323  *
13324  * ****************************************************************/
13325 void FreeUeContextSetupRsp(F1AP_PDU_t *f1apMsg)
13326 {
13327    uint8_t idx;
13328    UEContextSetupResponse_t *ueSetRsp = NULLP;
13329
13330    if(f1apMsg)
13331    {
13332       if(f1apMsg->choice.successfulOutcome)
13333       {
13334          ueSetRsp = &f1apMsg->choice.successfulOutcome->value.choice.\
13335                     UEContextSetupResponse;
13336          if(ueSetRsp->protocolIEs.list.array)
13337          {
13338             for(idx = 0; idx < ueSetRsp->protocolIEs.list.count; idx++)
13339             {
13340                if(ueSetRsp->protocolIEs.list.array[idx])
13341                {
13342                   switch(ueSetRsp->protocolIEs.list.array[idx]->id)
13343                   {
13344                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
13345                         break;
13346                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
13347                         break;
13348                      case ProtocolIE_ID_id_DUtoCURRCInformation:
13349                         {
13350                            CellGroupConfig_t *cellGrpCfg = NULLP;
13351                            cellGrpCfg  = &ueSetRsp->protocolIEs.list.array[idx]->value.choice.\
13352                                          DUtoCURRCInformation.cellGroupConfig;
13353                            if(cellGrpCfg->buf != NULLP)
13354                            {
13355                               DU_FREE(cellGrpCfg->buf, cellGrpCfg->size);
13356                               cellGrpCfg = NULLP;
13357                            }
13358                            break;
13359                         }
13360                     case ProtocolIE_ID_id_DRBs_Setup_List:
13361                         {
13362                            freeDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List); 
13363                            break;
13364                         }
13365                      default:
13366                         DU_LOG("\nERROR  -->  DUAPP: Invalid Id %ld at FreeUeContextSetupRsp()",\
13367                         ueSetRsp->protocolIEs.list.array[idx]->id);
13368                         break;
13369                   }
13370                   DU_FREE(ueSetRsp->protocolIEs.list.array[idx],\
13371                         sizeof(UEContextSetupResponseIEs_t));
13372                }
13373             }
13374             DU_FREE(ueSetRsp->protocolIEs.list.array, \
13375                   ueSetRsp->protocolIEs.list.size);
13376          }
13377          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
13378       }
13379       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
13380    }
13381 }
13382
13383 /*******************************************************************
13384  *
13385  * @brief Builds Ue context Setup Rsp DU To CU Info
13386  *
13387  * @details
13388  *
13389  *    Function : EncodeUeCntxtDuToCuInfo
13390  *
13391  *    Functionality: Builds Ue context Setup Rsp DU To CU Info
13392  *
13393  * @params[in] CellGroupConfig_t *, CellGroupConfigRrc_t * 
13394  *
13395  * @return ROK     - success
13396  *         RFAILED - failure
13397  *
13398  ******************************************************************/
13399
13400 uint8_t EncodeUeCntxtDuToCuInfo(CellGroupConfig_t *duToCuCellGrp, CellGroupConfigRrc_t *duCellGrpCfg)
13401 {
13402    asn_enc_rval_t        encRetVal;
13403
13404    xer_fprint(stdout, &asn_DEF_CellGroupConfigRrc, duCellGrpCfg);
13405    memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
13406    encBufSize = 0;
13407    encRetVal = aper_encode(&asn_DEF_CellGroupConfigRrc, 0, duCellGrpCfg, PrepFinalEncBuf, encBuf);
13408    /* Encode results */
13409    if(encRetVal.encoded == ENCODE_FAIL)
13410    {
13411       DU_LOG( "\nERROR  -->  F1AP : Could not encode UeCntxtDuToCuInfo (at %s)\n",\
13412             encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
13413       return RFAILED;
13414    }
13415    else
13416    {
13417       DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UeCntxtDuToCuInfo\n");
13418       for(int i=0; i< encBufSize; i++)
13419       {
13420          printf("%x",encBuf[i]);
13421       }
13422    }
13423    duToCuCellGrp->size = encBufSize;
13424    DU_ALLOC(duToCuCellGrp->buf, duToCuCellGrp->size);
13425    if(!duToCuCellGrp->buf)
13426    {
13427       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in UeCntxtDuToCuInfo");
13428    }
13429    memcpy(duToCuCellGrp->buf, encBuf, duToCuCellGrp->size);
13430    return ROK;
13431 }
13432
13433 /*******************************************************************
13434  *
13435  * @brief Fills Dl Gtp tunnel Info
13436  *
13437  * @details
13438  *
13439  *    Function : fillGtpTunnelforDl
13440  *
13441  *    Functionality: Fills Dl Gtp tunnel Info
13442  *
13443  * @params[in] 
13444  *
13445  * @return ROK     - success
13446  *         RFAILED - failure
13447  *
13448  * ****************************************************************/
13449
13450 uint8_t fillGtpTunnelforDl(GTPTunnel_t *gtpDl, GtpTnlCfg *gtpUeCfg)
13451 {
13452    uint8_t bufSize = 0;
13453
13454    gtpDl->transportLayerAddress.size    = 4*sizeof(uint8_t);
13455    DU_ALLOC(gtpDl->transportLayerAddress.buf, gtpDl->transportLayerAddress.size);
13456    if(gtpDl->transportLayerAddress.buf == NULLP)
13457    {
13458       return RFAILED;
13459    }
13460    memcpy(gtpDl->transportLayerAddress.buf, &gtpUeCfg->dlTnlAddress, gtpDl->transportLayerAddress.size);
13461
13462    /*GTP TEID*/
13463    gtpDl->gTP_TEID.size = 4 * sizeof(uint8_t);
13464    DU_ALLOC(gtpDl->gTP_TEID.buf, gtpDl->gTP_TEID.size);
13465    if(gtpDl->gTP_TEID.buf == NULLP)
13466    {
13467       return RFAILED;
13468    }
13469    bufSize = 3; /*forming an Octect String*/
13470    fillTeIdString(bufSize, gtpUeCfg->teId, gtpDl->gTP_TEID.buf);
13471
13472    return ROK;
13473 }
13474
13475 /*******************************************************************
13476  *
13477  * @brief Fills DL Tunnel Setup List
13478  *
13479  * @details
13480  *
13481  *    Function : fillDlTnlSetupList
13482  *
13483  *    Functionality: Fills the DL Tunnel Setup List
13484  *
13485  * @params[in] 
13486  *
13487  * @return ROK     - success
13488  *         RFAILED - failure
13489  *
13490  * ****************************************************************/
13491
13492 uint8_t fillDlTnlSetupList(DLUPTNLInformation_ToBeSetup_List_t *dlTnlInfo, UpTnlCfg *tnlCfg)
13493 {
13494    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
13495
13496    eleCount = 1;
13497    dlTnlInfo->list.count = eleCount; 
13498    dlTnlInfo->list.size = (eleCount * sizeof(DLUPTNLInformation_ToBeSetup_Item_t *));
13499
13500    /* Initialize the DL Tnl Setup List Members */
13501    DU_ALLOC(dlTnlInfo->list.array, dlTnlInfo->list.size);
13502    if(dlTnlInfo->list.array == NULLP)
13503    {
13504       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL Tnl Setup List in fillDlTnlSetupList()");
13505       ret = RFAILED;
13506    }
13507    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
13508    {
13509       DU_ALLOC(dlTnlInfo->list.array[arrIdx], sizeof(DLUPTNLInformation_ToBeSetup_Item_t));
13510       if(dlTnlInfo->list.array[arrIdx] == NULLP)
13511       {
13512          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDlTnlSetupList()", arrIdx);
13513          return RFAILED;
13514       }
13515       dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.present = UPTransportLayerInformation_PR_gTPTunnel;
13516       DU_ALLOC(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel, sizeof(GTPTunnel_t));
13517       if(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel == NULLP)
13518       {
13519          DU_LOG(" ERROR  -->  F1AP : Memory allocation for DL tunnel info in fillDlTnlSetupList()");
13520          return RFAILED;
13521       }
13522       ret = fillGtpTunnelforDl(dlTnlInfo->list.array[arrIdx]->dLUPTNLInformation.choice.gTPTunnel,\
13523                tnlCfg->tnlCfg1);
13524       if(ret != ROK)
13525          break;
13526    }
13527    return ret;
13528 }
13529
13530 /*******************************************************************
13531  *
13532  * @brief Fills the Drb Setup List for Ue Context Setup Response
13533  *
13534  * @details
13535  *
13536  *    Function : fillDrbSetupList
13537  *
13538  *    Functionality: Fills the Drb Setup List for Ue Context Setup Response
13539  *
13540  * @params[in] 
13541  *
13542  * @return ROK     - success
13543  *         RFAILED - failure
13544  *
13545  * ****************************************************************/
13546 uint8_t fillDrbSetupList(DRBs_Setup_List_t *drbSetupList, DuUeCfg *ueCfg)
13547 {
13548    uint8_t ret = ROK, arrIdx = 0, eleCount = 0;
13549    DRBs_Setup_ItemIEs_t *drbItemIe = NULLP;
13550
13551    eleCount = ueCfg->numDrb;
13552    drbSetupList->list.count = eleCount;
13553    drbSetupList->list.size = \
13554         (eleCount * sizeof(DRBs_Setup_Item_t *));
13555
13556    /* Initialize the Drb Setup List Members */
13557    DU_ALLOC(drbSetupList->list.array, drbSetupList->list.size);
13558    if(drbSetupList->list.array == NULLP)
13559    {
13560       DU_LOG(" ERROR  -->  F1AP : Memory allocation for DRB Setup List in fillDrbSetupList()");
13561       ret = RFAILED;
13562    }
13563
13564    for(arrIdx=0; arrIdx < eleCount; arrIdx++)
13565    {
13566       DU_ALLOC(drbSetupList->list.array[arrIdx], sizeof(DRBs_Setup_Item_t));
13567       if(drbSetupList->list.array[arrIdx] == NULLP)
13568       {
13569          DU_LOG(" ERROR  -->  F1AP : Memory allocation for arrIdx [%d] failed in fillDrbSetupList()", arrIdx);
13570          return RFAILED;
13571       }
13572       drbItemIe = ((DRBs_Setup_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
13573       drbItemIe->id = ProtocolIE_ID_id_DRBs_Setup_Item;
13574       drbItemIe->criticality = Criticality_reject;
13575       drbItemIe->value.present = DRBs_Setup_ItemIEs__value_PR_DRBs_Setup_Item;
13576       drbItemIe->value.choice.DRBs_Setup_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
13577       ret = fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_Setup_Item.dLUPTNLInformation_ToBeSetup_List,\
13578           &ueCfg->upTnlInfo[arrIdx]);
13579       if(ret != ROK)
13580          break;
13581    }
13582    return ret;
13583 }
13584
13585 /*******************************************************************
13586  *
13587  * @brief Builds and sends the UE Setup Response
13588  *
13589  * @details
13590  *
13591  *    Function : BuildAndSendUeContextSetupRsp
13592  *
13593  *    Functionality: Constructs the UE Setup Response and sends
13594  *                   it to the DU through SCTP.
13595  *
13596  * @params[in] uint8_t cellId,uint8_t ueId
13597  *
13598  * @return ROK     - success
13599  *         RFAILED - failure
13600  *
13601  * ****************************************************************/
13602 uint8_t BuildAndSendUeContextSetupRsp(uint8_t cellId,uint8_t ueId)
13603 {
13604    uint8_t   idx, ret, cellIdx, elementCnt;
13605    uint32_t  gnbCuUeF1apId;   /* gNB-CU UE F1AP Id */
13606    uint32_t  gnbDuUeF1apId;   /* gNB-DU UE F1AP Id */
13607    asn_enc_rval_t  encRetVal;        /* Encoder return value */
13608    F1AP_PDU_t               *f1apMsg = NULLP;
13609    UEContextSetupResponse_t *ueSetRsp = NULLP;
13610    DuUeCb                   *ueCb = NULLP;
13611
13612    DU_LOG("\n INFO   -->  F1AP : Building UE Context Setup Response for cellId %d, ueId %d\n", cellId, ueId);
13613
13614    while(true)
13615    {
13616       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
13617       if(f1apMsg == NULLP)
13618       {
13619          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
13620          ret = RFAILED;
13621          break;
13622       }
13623
13624       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
13625       DU_ALLOC(f1apMsg->choice.successfulOutcome,
13626             sizeof(SuccessfulOutcome_t));
13627       if(f1apMsg->choice.successfulOutcome == NULLP)
13628       {
13629          DU_LOG(" ERROR  -->  F1AP : Memory allocation for      F1AP-PDU failed");
13630          ret = RFAILED;
13631          break;
13632       }
13633
13634       f1apMsg->choice.successfulOutcome->procedureCode = \
13635                                                          ProcedureCode_id_UEContextSetup;
13636       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
13637       f1apMsg->choice.successfulOutcome->value.present = \
13638                                                          SuccessfulOutcome__value_PR_UEContextSetupResponse;
13639
13640       ueSetRsp =
13641          &f1apMsg->choice.successfulOutcome->value.choice.UEContextSetupResponse;
13642       elementCnt = 5;
13643       ueSetRsp->protocolIEs.list.count = elementCnt;
13644       ueSetRsp->protocolIEs.list.size = \
13645                                         elementCnt * sizeof(UEContextSetupResponse_t *);
13646
13647       /* Initialize the UESetup members */
13648       DU_ALLOC(ueSetRsp->protocolIEs.list.array, \
13649             ueSetRsp->protocolIEs.list.size);
13650       if(ueSetRsp->protocolIEs.list.array == NULLP)
13651       {
13652          DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
13653          ret = RFAILED;
13654          break;
13655       }
13656
13657       for(idx=0; idx<elementCnt; idx++)
13658       {
13659          DU_ALLOC(ueSetRsp->protocolIEs.list.array[idx],\
13660                sizeof(UEContextSetupResponseIEs_t));
13661          if(ueSetRsp->protocolIEs.list.array[idx] == NULLP)
13662          {
13663             DU_LOG(" ERROR  -->  F1AP : Memory allocation for UE Setup Response failed");
13664             ret = RFAILED;
13665             break;
13666          }
13667       }
13668       /* Fetching Ue Cb Info*/
13669       GET_CELL_IDX(cellId, cellIdx);
13670       gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
13671       gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
13672       ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
13673
13674       idx = 0;
13675       /*GNB CU UE F1AP ID*/
13676       ueSetRsp->protocolIEs.list.array[idx]->id = \
13677                                                   ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
13678       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13679       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
13680                                                              UEContextSetupResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
13681       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
13682
13683       /*GNB DU UE F1AP ID*/
13684       idx++;
13685       ueSetRsp->protocolIEs.list.array[idx]->id = \
13686                                                   ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
13687       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13688       ueSetRsp->protocolIEs.list.array[idx]->value.present = \
13689                                                              UEContextSetupResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
13690       ueSetRsp->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
13691
13692
13693       /*DUtoCURRC Information */
13694       idx++;
13695       ueSetRsp->protocolIEs.list.array[idx]->id  = \
13696                                                    ProtocolIE_ID_id_DUtoCURRCInformation;
13697       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13698       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
13699                                                             UEContextSetupResponseIEs__value_PR_DUtoCURRCInformation;
13700       BuildCellGroupConfigRrc(ueCb, &ueSetRsp->protocolIEs.list.array[idx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
13701
13702       /* CRNTI */
13703       idx++;
13704       ueSetRsp->protocolIEs.list.array[idx]->id  = ProtocolIE_ID_id_C_RNTI;
13705       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13706       ueSetRsp->protocolIEs.list.array[idx]->value.present = UEContextSetupResponseIEs__value_PR_C_RNTI;
13707       ueSetRsp->protocolIEs.list.array[idx]->value.choice.C_RNTI = ueCb->crnti; 
13708
13709
13710       /* Drb Setup List */
13711       idx++;
13712       ueSetRsp->protocolIEs.list.array[idx]->id  = \
13713                                                    ProtocolIE_ID_id_DRBs_Setup_List;
13714       ueSetRsp->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13715       ueSetRsp->protocolIEs.list.array[idx]->value.present =\
13716                                                             UEContextSetupResponseIEs__value_PR_DRBs_Setup_List;
13717       ret = fillDrbSetupList(&ueSetRsp->protocolIEs.list.array[idx]->value.choice.DRBs_Setup_List,\
13718             &ueCb->f1UeDb->duUeCfg);
13719       if(ret == RFAILED)
13720       {
13721          DU_LOG("\nERROR  -->  F1AP : Failed to fillDrbSetupList in BuildAndSendUeContextSetupRsp()");
13722          freeF1UeDb(ueCb->f1UeDb);
13723          ueCb->f1UeDb = NULLP;
13724          break;
13725       }
13726
13727       /* Free UeContext Db created during Ue context Req */
13728       freeF1UeDb(ueCb->f1UeDb);
13729       ueCb->f1UeDb = NULLP;
13730
13731       /* TODO: To send Drb list */
13732       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
13733
13734       /* Encode the UE context setup response type as APER */
13735       memset((uint8_t *)encBuf, 0, ENC_BUF_MAX_LEN);
13736       encBufSize = 0;
13737       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
13738             encBuf);
13739       /* Encode results */
13740       if(encRetVal.encoded == ENCODE_FAIL)
13741       {
13742          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Response structure (at %s)\n",\
13743                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
13744          ret = RFAILED;
13745          break;
13746       }
13747       else
13748       {
13749          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Setup Response\n");
13750          for(int i=0; i< encBufSize; i++)
13751          {
13752             printf("%x",encBuf[i]);
13753          }
13754       }
13755
13756       /* Sending  msg  */
13757       if(sendF1APMsg()  != ROK)
13758       {
13759          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Response failed");
13760          ret = RFAILED;
13761          break;
13762       }
13763       break;
13764    }
13765    FreeUeContextSetupRsp(f1apMsg);
13766    return ret;
13767 }/* End of BuildAndSendUeContextSetupRsp */
13768 /*******************************************************************
13769 *
13770 * @brief  Build And Send Ue Context Rsp 
13771 *
13772 * @details
13773 *
13774 *    Function : BuildAndSendUeCtxtRsp 
13775 *
13776 *    Functionality : Build And Send Ue Context Rsp
13777
13778 * @params[in]
13779 * @return sucess = ROK
13780 *         failure = RFAILED
13781 *
13782 * ****************************************************************/
13783 uint8_t BuildAndSendUeCtxtRsp(uint8_t cellId, uint8_t ueId)
13784 {
13785    uint8_t cellIdx = 0, actionType = 0; 
13786
13787    GET_CELL_IDX(cellId, cellIdx);
13788    actionType = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].f1UeDb->actionType;
13789
13790    switch(actionType)
13791    {
13792       case UE_CTXT_SETUP:
13793          {
13794             if((BuildAndSendUeContextSetupRsp(cellId,ueId)) != ROK)
13795             {
13796                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextSetupRsp()");
13797                return RFAILED;
13798             }
13799             break;
13800          }
13801       case UE_CTXT_MOD:
13802          {
13803             if((BuildAndSendUeContextModRsp(&duCb.actvCellLst[cellIdx]->ueCb[ueId-1])) != ROK)
13804             {
13805                DU_LOG("\nERROR  -->  F1AP : Failed at BuildAndSendUeContextModRsp");
13806                return RFAILED;
13807             }
13808             break;
13809          }
13810       default:
13811          DU_LOG("ERROR  -->  F1AP: Invalid Action Type %d at BuildAndSendUeCtxtRsp()", actionType);
13812          break;
13813
13814    }
13815    return ROK;
13816 }
13817
13818 /*******************************************************************
13819  *
13820  * @brief deallocating the memory of  F1reset msg
13821  *
13822  * @details
13823  *
13824  *    Function : FreeF1ResetReq
13825  *
13826  *    Functionality :
13827  *         - freeing memory of F1reset request msg
13828  *
13829  * @params[in]
13830  * @return void
13831  *
13832  *
13833  * ****************************************************************/
13834 void FreeF1ResetReq(F1AP_PDU_t *f1apMsg)
13835 {
13836    uint8_t idx =0 ;
13837    Reset_t *f1ResetMsg;
13838
13839    if(f1apMsg)
13840    {
13841       if(f1apMsg->choice.initiatingMessage)
13842       {
13843          f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
13844
13845          if(f1ResetMsg->protocolIEs.list.array)
13846          {
13847             for(idx=0 ;idx < f1ResetMsg->protocolIEs.list.count ; idx++)
13848             {
13849                if(f1ResetMsg->protocolIEs.list.array[idx])
13850                {
13851                   DU_FREE(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
13852                }
13853             }
13854             DU_FREE(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
13855          }
13856          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
13857       }
13858       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
13859    }
13860 }
13861 /*******************************************************************
13862  *
13863  * @brief Build and Send F1reset request 
13864  *
13865  * @details
13866  *
13867  *    Function : BuildAndSendF1ResetReq
13868  *
13869  *    Functionality:
13870  *         - Build and Send F1reset request msg
13871  *
13872  * @params[in]
13873  * @return ROK     - success
13874  *         RFAILED - failure
13875  *
13876  * ****************************************************************/
13877 uint8_t BuildAndSendF1ResetReq()
13878 {
13879    uint8_t          elementCnt=0;
13880    uint8_t          idx=0;
13881    uint8_t          ret= RFAILED;
13882    Reset_t          *f1ResetMsg = NULLP;
13883    F1AP_PDU_t       *f1apMsg = NULLP;
13884    asn_enc_rval_t   encRetVal;
13885    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset request \n");
13886    do
13887    {
13888       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
13889       if(f1apMsg == NULLP)
13890       {
13891          break;
13892       }
13893       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
13894       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
13895       if(f1apMsg->choice.initiatingMessage == NULLP)
13896       {
13897          break;
13898       }
13899       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_Reset;
13900       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
13901       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_Reset;
13902
13903       f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
13904
13905       elementCnt = 3;
13906       f1ResetMsg->protocolIEs.list.count = elementCnt;
13907       f1ResetMsg->protocolIEs.list.size = elementCnt * sizeof(ResetIEs_t *);
13908
13909       /* Initialize the F1Setup members */
13910       DU_ALLOC(f1ResetMsg->protocolIEs.list.array,f1ResetMsg->protocolIEs.list.size);
13911       if(f1ResetMsg->protocolIEs.list.array == NULLP)
13912       {
13913          break;
13914       }
13915       for(idx=0; idx<elementCnt; idx++)
13916       {
13917          DU_ALLOC(f1ResetMsg->protocolIEs.list.array[idx],sizeof(ResetIEs_t));
13918          if(f1ResetMsg->protocolIEs.list.array[idx] == NULLP)
13919          {
13920             break;
13921          }
13922       }
13923
13924       /*TransactionID*/
13925       idx=0;
13926       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
13927       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13928       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_TransactionID;
13929       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.TransactionID = 1;
13930
13931       /*Cause*/
13932       idx++;
13933       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_Cause;
13934       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_ignore;
13935       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_Cause;
13936       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.present = Cause_PR_radioNetwork;
13937       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.Cause.choice.radioNetwork = CauseRadioNetwork_action_desirable_for_radio_reasons;
13938
13939       /*Reset Type*/
13940       idx++;
13941       f1ResetMsg->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_ResetType;
13942       f1ResetMsg->protocolIEs.list.array[idx]->criticality = Criticality_reject;
13943       f1ResetMsg->protocolIEs.list.array[idx]->value.present = ResetIEs__value_PR_ResetType;
13944       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.present = ResetType_PR_f1_Interface;
13945       f1ResetMsg->protocolIEs.list.array[idx]->value.choice.ResetType.choice.f1_Interface = ResetAll_reset_all;
13946
13947       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
13948
13949       /* Encode the F1SetupRequest type as APER */
13950       memset(encBuf, 0, ENC_BUF_MAX_LEN);
13951       encBufSize = 0;
13952       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
13953             encBuf);
13954
13955       /* Encode results */
13956       if(encRetVal.encoded == ENCODE_FAIL)
13957       {
13958          DU_LOG("\nERROR  -->  F1AP : Could not encode F1Reset structure (at %s)\n",\
13959                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
13960          break;
13961       }
13962       else
13963       {
13964          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for F1Reset\n");
13965          for(idx=0; idx< encBufSize; idx++)
13966          {
13967             printf("%x",encBuf[idx]);
13968          }
13969       }
13970
13971       if(sendF1APMsg() != ROK)
13972       {
13973          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset request failed");
13974          break;
13975       }
13976
13977       ret = ROK;
13978       break;
13979    }while(true);
13980
13981    FreeF1ResetReq(f1apMsg);
13982    return ret;
13983 }
13984 /*******************************************************************
13985  *
13986  * @brief Build And Send F1ResetAck
13987  *
13988  * @details
13989  *
13990  *    Function : BuildAndSendF1ResetAck
13991  *
13992  *    Functionality:
13993  *         - Build And Send  F1ResetRSP
13994  *
13995  * @return ROK     - success
13996  *         RFAILED - failure
13997  *
13998  * ****************************************************************/
13999 void FreeF1ResetAck(F1AP_PDU_t *f1apMsg)
14000 {
14001    uint8_t idx;
14002    ResetAcknowledge_t *f1ResetAck;
14003
14004    if(f1apMsg)
14005    {
14006       if(f1apMsg->choice.successfulOutcome)
14007       {
14008          f1ResetAck= &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14009
14010          if(f1ResetAck->protocolIEs.list.array)
14011          {
14012             for(idx=0; idx<f1ResetAck->protocolIEs.list.count ; idx++)
14013             {
14014                if(f1ResetAck->protocolIEs.list.array[idx])
14015                {
14016                   DU_FREE(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14017                }
14018             }
14019             DU_FREE(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14020          }
14021          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14022       }
14023       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
14024    }
14025 }
14026
14027 /*******************************************************************
14028  *
14029  * @brief Build And Send F1ResetAck
14030  *
14031  * @details
14032  *
14033  *    Function : BuildAndSendF1ResetAck
14034  *
14035  *    Functionality:
14036  *         - Build And Send  F1ResetRSP
14037  *
14038  *  @params[in]
14039  * @return ROK     - success
14040  *         RFAILED - failure
14041  *
14042  * ****************************************************************/
14043 uint8_t BuildAndSendF1ResetAck()
14044 {
14045    uint8_t                idx = 0;
14046    uint8_t                elementCnt = 0;
14047    uint8_t                ret = RFAILED;
14048    F1AP_PDU_t             *f1apMsg = NULL;
14049    ResetAcknowledge_t     *f1ResetAck = NULLP;
14050    asn_enc_rval_t         encRetVal;
14051    DU_LOG("\nINFO   -->  F1AP : Building F1 Reset Acknowledgment \n");
14052
14053    do{
14054       /* Allocate the memory for F1ResetRequest_t */
14055       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14056       if(f1apMsg == NULLP)
14057       {
14058          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14059          break;
14060       }
14061
14062       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
14063
14064       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
14065       if(f1apMsg->choice.successfulOutcome == NULLP)
14066       {
14067          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14068          break;
14069       }
14070       f1apMsg->choice.successfulOutcome->criticality   = Criticality_reject;
14071       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetAcknowledge;
14072       f1ResetAck = &f1apMsg->choice.successfulOutcome->value.choice.ResetAcknowledge;
14073
14074       elementCnt = 1;
14075
14076       f1ResetAck->protocolIEs.list.count = elementCnt;
14077       f1ResetAck->protocolIEs.list.size = elementCnt*sizeof(ResetAcknowledgeIEs_t *);
14078
14079       DU_ALLOC(f1ResetAck->protocolIEs.list.array, f1ResetAck->protocolIEs.list.size );
14080       if(f1ResetAck->protocolIEs.list.array == NULLP)
14081       {
14082          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1ResetAckIEs failed");
14083          break;
14084       }
14085
14086       for(idx=0; idx<elementCnt; idx++)
14087       {
14088          DU_ALLOC(f1ResetAck->protocolIEs.list.array[idx], sizeof(ResetAcknowledgeIEs_t));
14089          if(f1ResetAck->protocolIEs.list.array[idx] == NULLP)
14090          {
14091             break;
14092          }
14093       }
14094       /*TransactionID*/
14095       idx = 0;
14096       f1ResetAck->protocolIEs.list.array[idx]->id = ProtocolIE_ID_id_TransactionID;
14097       f1ResetAck->protocolIEs.list.array[idx]->criticality = Criticality_reject;
14098       f1ResetAck->protocolIEs.list.array[idx]->value.present = ResetAcknowledgeIEs__value_PR_TransactionID;
14099       f1ResetAck->protocolIEs.list.array[idx]->value.choice.TransactionID = TRANS_ID;
14100
14101       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14102
14103       /* Encode the F1SetupRequest type as UPER */
14104       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14105       encBufSize = 0;
14106       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
14107
14108       /* Check encode results */
14109       if(encRetVal.encoded == ENCODE_FAIL)
14110       {
14111          DU_LOG("\nERROR  -->  F1AP : Could not encode F1ResetAck structure (at %s)\n",\
14112                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14113          break;
14114       }
14115       else
14116       {
14117          DU_LOG("\nDUBUG   -->  F1AP : Created APER encoded buffer for F1ResetAck\n");
14118          for(int i=0; i< encBufSize; i++)
14119          {
14120             printf("%x",encBuf[i]);
14121          }
14122       }
14123       /* Sending msg */
14124       if(sendF1APMsg() != ROK)
14125       {
14126          DU_LOG("\nERROR  -->  F1AP : Sending F1 Reset Acknowledgement failed");
14127          break;
14128       }
14129
14130       ret = ROK;
14131       break;
14132    }while(true);
14133
14134    FreeF1ResetAck(f1apMsg);
14135    return ret;
14136 }
14137 /******************************************************************
14138 *
14139 * @brief free F1 reset msg allocated by aper_decoder 
14140 *
14141 * @details
14142 *
14143 *    Function : freeAperDecodeF1ResetMsg 
14144 *
14145 *    Functionality: free F1 reset msg allocated by aper_decoder 
14146 *
14147 * @params[in] Reset_t *f1ResetMsg 
14148 * @return void 
14149 *
14150 * ****************************************************************/
14151
14152 void freeAperDecodeF1ResetMsg(Reset_t *f1ResetMsg)
14153 {
14154    uint8_t ieIdx =0;
14155    if(f1ResetMsg->protocolIEs.list.array)
14156    {
14157       for(ieIdx=0 ;ieIdx < f1ResetMsg->protocolIEs.list.count ; ieIdx++)
14158       {
14159          if(f1ResetMsg->protocolIEs.list.array[ieIdx])
14160          {
14161             free(f1ResetMsg->protocolIEs.list.array[ieIdx]);
14162          }
14163       }
14164       free(f1ResetMsg->protocolIEs.list.array);
14165    }
14166 }
14167
14168 /******************************************************************
14169  *
14170  * @brief Processes DL RRC Message Transfer  sent by CU
14171  *
14172  * @details
14173  *
14174  *    Function : procF1ResetReq
14175  *
14176  *    Functionality: Processes DL RRC Message Transfer sent by CU
14177  *
14178  * @params[in] F1AP_PDU_t ASN decoded F1AP message
14179  * @return ROK     - success
14180  *         RFAILED - failure
14181  *
14182  * ****************************************************************/
14183 uint8_t procF1ResetReq(F1AP_PDU_t *f1apMsg)
14184 {
14185    /* we are currently not supporting Ue release. right now we are supporting only init case of fireset */
14186    uint8_t       ieIdx = 0;
14187    uint8_t        ret = ROK;
14188    Reset_t       *f1ResetMsg = NULLP;
14189
14190    DU_LOG("\nINFO   -->  Processing F1 reset request");
14191    f1ResetMsg = &f1apMsg->choice.initiatingMessage->value.choice.Reset;
14192
14193    for(ieIdx=0; ieIdx<f1ResetMsg->protocolIEs.list.count; ieIdx++)
14194    {
14195       switch(f1ResetMsg->protocolIEs.list.array[ieIdx]->id)
14196       {
14197          case ProtocolIE_ID_id_TransactionID:
14198             break;
14199
14200          case ProtocolIE_ID_id_Cause:
14201             break;
14202
14203          case ProtocolIE_ID_id_ResetType:
14204             {
14205                break;
14206             }
14207
14208          default:
14209             break;
14210       }
14211    }
14212    ret = BuildAndSendF1ResetAck();
14213    DU_LOG("\nINFO   -->  UE release is not supported for now");
14214
14215    freeAperDecodeF1ResetMsg(f1ResetMsg);
14216
14217    return ret;
14218 }
14219
14220 /*******************************************************************
14221  *
14222  * @brief free the RRC delivery report
14223  *
14224  * @details
14225  *
14226  *    Function : freeRrcDeliveryReport
14227  *
14228  *    Functionality: free the RRC delivery report
14229  *
14230  * @params[in]
14231  * @return ROK     - success
14232  *         RFAILED - failure
14233  *
14234  * ****************************************************************/
14235 void freeRrcDeliveryReport(F1AP_PDU_t  *f1apMsg )
14236 {
14237    uint8_t idx=0;
14238    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
14239
14240    if(f1apMsg)
14241    {
14242       if(f1apMsg->choice.initiatingMessage)
14243       {
14244          rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
14245          if(rrcDeliveryReport->protocolIEs.list.array)
14246          {
14247             for(idx =0 ;idx <rrcDeliveryReport->protocolIEs.list.count ;
14248                   idx++)
14249             {
14250                if(rrcDeliveryReport->protocolIEs.list.array[idx])
14251                {
14252                   DU_FREE(rrcDeliveryReport->protocolIEs.list.array[idx],
14253                         sizeof(RRCDeliveryReportIEs_t));
14254                }   
14255             }
14256             DU_FREE(rrcDeliveryReport->protocolIEs.list.array,
14257                   rrcDeliveryReport->protocolIEs.list.size);
14258          }
14259          DU_FREE(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
14260       }
14261       DU_FREE(f1apMsg,
14262             sizeof(F1AP_PDU_t));
14263    }
14264 }
14265
14266 /*******************************************************************
14267 *
14268 * @brief Builds and sends the RRC delivery report
14269 *
14270 * @details
14271 *
14272 *    Function : BuildAndSendRrcDeliveryReport
14273 *
14274 *    Functionality: Builds and sends the RRC delivery report
14275 *
14276 * @params[in]
14277 *
14278 * @return ROK     - success
14279 *         RFAILED - failure
14280 *
14281 * ****************************************************************/
14282 uint8_t BuildAndSendRrcDeliveryReport(uint32_t gnbCuUeF1apId, \
14283    uint32_t gnbDuUeF1apId, RrcDeliveryReport *rrcDelivery)
14284 {
14285    uint8_t             ret = RFAILED;
14286    uint8_t             idx    = 0;
14287    uint8_t             idx1   = 0;
14288    uint8_t             elementCnt = 0;
14289    F1AP_PDU_t          *f1apMsg = NULLP;
14290    asn_enc_rval_t      encRetVal;  
14291    RRCDeliveryReport_t *rrcDeliveryReport= NULLP;
14292
14293    do{
14294
14295       DU_LOG("\nINFO   -->  F1AP : Building RRC delivery Message Transfer Message\n");
14296       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
14297       if(f1apMsg == NULLP)
14298       {
14299          DU_LOG(" ERROR  -->  F1AP : Memory allocation for F1AP-PDU failed");
14300          break;
14301       }
14302       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
14303       DU_ALLOC(f1apMsg->choice.initiatingMessage,sizeof(InitiatingMessage_t));
14304       if(f1apMsg->choice.initiatingMessage == NULLP)
14305       {
14306          DU_LOG(" ERROR  -->  F1AP : Memory allocation for  F1AP-PDU  failed");
14307          break;
14308       }
14309       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_RRCDeliveryReport;
14310       f1apMsg->choice.initiatingMessage->criticality   = Criticality_ignore;
14311       f1apMsg->choice.initiatingMessage->value.present = InitiatingMessage__value_PR_RRCDeliveryReport;
14312
14313       rrcDeliveryReport = &f1apMsg->choice.initiatingMessage->value.choice.RRCDeliveryReport;
14314       elementCnt = 4;
14315       rrcDeliveryReport->protocolIEs.list.count = elementCnt;
14316       rrcDeliveryReport->protocolIEs.list.size = elementCnt * sizeof(RRCDeliveryReportIEs_t *);
14317
14318       /* Initialize the F1Setup members */
14319       DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array, rrcDeliveryReport->protocolIEs.list.size);
14320       if(rrcDeliveryReport->protocolIEs.list.array == NULLP)
14321       {
14322          DU_LOG(" ERROR  -->  F1AP : Memory allocation for RRC Delivery  failed");
14323          break;
14324       }
14325       for(idx =0 ;idx <elementCnt; idx++)
14326       {
14327          DU_ALLOC(rrcDeliveryReport->protocolIEs.list.array[idx], sizeof(RRCDeliveryReportIEs_t));
14328          if(rrcDeliveryReport->protocolIEs.list.array[idx] == NULLP)
14329          {
14330             break;
14331          }
14332       }
14333
14334       idx1 = 0;
14335
14336       /*GNB CU UE F1AP ID*/
14337       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
14338       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
14339       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_CU_UE_F1AP_ID;
14340       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_CU_UE_F1AP_ID = gnbCuUeF1apId;
14341
14342       /*GNB DU UE F1AP ID*/
14343       idx1++;
14344       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
14345       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_reject;
14346       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_GNB_DU_UE_F1AP_ID;
14347       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.GNB_DU_UE_F1AP_ID = gnbDuUeF1apId;
14348
14349       /*RRC delivery status*/
14350       idx1++;
14351       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_RRCDeliveryStatus;
14352       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
14353       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_RRCDeliveryStatus;
14354       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.delivery_status =\
14355       rrcDelivery->rrcDeliveryStatus.deliveryStatus;
14356       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.RRCDeliveryStatus.triggering_message =\
14357       rrcDelivery->rrcDeliveryStatus.triggeringMessage;
14358
14359       /* SRB ID */ 
14360       idx1++;
14361       rrcDeliveryReport->protocolIEs.list.array[idx1]->id = ProtocolIE_ID_id_SRBID;
14362       rrcDeliveryReport->protocolIEs.list.array[idx1]->criticality = Criticality_ignore;
14363       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.present = RRCDeliveryReportIEs__value_PR_SRBID;
14364       rrcDeliveryReport->protocolIEs.list.array[idx1]->value.choice.SRBID =  rrcDelivery->srbId;
14365
14366       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
14367
14368       /* Encode the RRC DELIVERY REPORT type as APER */
14369       memset(encBuf, 0, ENC_BUF_MAX_LEN);
14370       encBufSize = 0;
14371       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,\
14372             encBuf);
14373
14374       /* Encode results */
14375       if(encRetVal.encoded == ENCODE_FAIL)
14376       {
14377          DU_LOG("\nERROR  -->  F1AP : Could not encode RRC Delivery Msg structure (at %s)\n",\
14378                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
14379          break;
14380       }
14381       else
14382       {
14383          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for RRC Delivery Msg \n");
14384          for(idx=0; idx< encBufSize; idx++)
14385          {
14386             printf("%x",encBuf[idx]);
14387          }
14388       }
14389
14390       /* Sending msg */
14391       if(sendF1APMsg() != ROK)
14392       {
14393          DU_LOG("\nERROR  -->  F1AP : Sending RRC delivery  msg request failed");
14394          break;
14395       }
14396       ret = ROK;
14397       break;
14398
14399    }while(true);
14400
14401    freeRrcDeliveryReport(f1apMsg);
14402    return ret;
14403 }
14404
14405 /*******************************************************************
14406  *
14407  * @brief Processes cells to be activated
14408  *
14409  * @details
14410  *
14411  *    Function : extractCellsToBeActivated
14412  *
14413  *    Functionality:
14414  *      - Processes cells to be activated list received in F1SetupRsp
14415  *
14416  * @params[in] void
14417  * @return ROK     - success
14418  *         RFAILED - failure
14419  *
14420  * ****************************************************************/
14421
14422 uint8_t extractCellsToBeActivated(Cells_to_be_Activated_List_t cellsToActivate)
14423 {
14424    uint8_t  ret = ROK;
14425    uint16_t idx, nci, pci = 0;
14426    Cells_to_be_Activated_List_Item_t cell;
14427
14428    for(idx=0; idx<cellsToActivate.list.count; idx++)
14429    {
14430       nci = 0;
14431       cell = cellsToActivate.list.array[idx]->value.choice.Cells_to_be_Activated_List_Item;
14432       bitStringToInt(&cell.nRCGI.nRCellIdentity, &nci);
14433
14434       if(cell.nRPCI)
14435       {
14436          pci = *cell.nRPCI;
14437       }
14438       ret = duProcCellsToBeActivated(cell.nRCGI.pLMN_Identity.buf, nci, pci);
14439    }
14440    return ret;
14441 }
14442 /******************************************************************
14443 *
14444 * @brief Processes F1 Setup Response allocated by aper_decoder 
14445 *
14446 * @details
14447 *
14448 *    Function : freeF1SetupRsp 
14449 *
14450 *    Functionality: free F1 Setup Response allocated by aper_decoder 
14451 *
14452 * @params[in] F1SetupResponse_t *f1SetRspMsg 
14453 * @return void 
14454 *
14455 * ****************************************************************/
14456
14457 void freeAperDecodeF1SetupRsp(F1SetupResponse_t *f1SetRspMsg)
14458 {
14459    uint8_t ieIdx =0;
14460    uint8_t arrIdx =0;
14461    Cells_to_be_Activated_List_t *cellToActivate =NULLP;
14462    RRC_Version_t      *rrcVer =NULLP;
14463
14464    if(f1SetRspMsg->protocolIEs.list.array)
14465    {
14466       for(ieIdx=0; ieIdx<f1SetRspMsg->protocolIEs.list.count; ieIdx++)
14467       {
14468          if(f1SetRspMsg->protocolIEs.list.array[ieIdx])
14469          {
14470             switch(f1SetRspMsg->protocolIEs.list.array[ieIdx]->id)
14471             {
14472                case ProtocolIE_ID_id_Cells_to_be_Activated_List:
14473                   {
14474                      cellToActivate =
14475                         &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.Cells_to_be_Activated_List;
14476                      if(cellToActivate->list.array)
14477                      {
14478                         for(arrIdx=0; arrIdx<cellToActivate->list.count ; arrIdx++)
14479                         {
14480                            if(cellToActivate->list.array[arrIdx])
14481                            {
14482
14483                               if(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.nRCGI.\
14484                               pLMN_Identity.buf)
14485                               {
14486                                  if(cellToActivate->list.array[0]->value.choice.\
14487                                        Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf)
14488                                  {
14489                                     free(cellToActivate->list.array[0]->value.choice.\
14490                                           Cells_to_be_Activated_List_Item.nRCGI.nRCellIdentity.buf);
14491                                  }
14492
14493                                  free(cellToActivate->list.array[0]->value.choice.Cells_to_be_Activated_List_Item.\
14494                                        nRCGI.pLMN_Identity.buf);
14495                               }
14496                               free(cellToActivate->list.array[arrIdx]);
14497                            }
14498                         }
14499                         free(cellToActivate->list.array);
14500                      }
14501                      break;
14502                   }
14503                case ProtocolIE_ID_id_TransactionID:
14504                   {
14505                      break;
14506                   }
14507                case ProtocolIE_ID_id_gNB_CU_Name:
14508                   {
14509                      free(f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_Name.buf);
14510                      break;
14511                   }
14512                case ProtocolIE_ID_id_GNB_CU_RRC_Version:
14513                   {
14514                      rrcVer = &f1SetRspMsg->protocolIEs.list.array[ieIdx]->value.choice.RRC_Version;
14515                      if(rrcVer->latest_RRC_Version.buf)
14516                      {
14517                         if(rrcVer->iE_Extensions)
14518                         {
14519                            if(rrcVer->iE_Extensions->list.array)
14520                            {
14521                               if(rrcVer->iE_Extensions->list.array[0])
14522                               {
14523                                  if(rrcVer->iE_Extensions->list.\
14524                                        array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf)
14525                                  {
14526                                     free(rrcVer->iE_Extensions->list.\
14527                                           array[0]->extensionValue.choice.Latest_RRC_Version_Enhanced.buf);
14528                                  }
14529                                  free(rrcVer->iE_Extensions->list.array[0]);
14530                               }
14531                               free(rrcVer->iE_Extensions->list.array);
14532                            }
14533                            free(rrcVer->iE_Extensions);
14534                         }
14535                         free(rrcVer->latest_RRC_Version.buf);
14536                      }
14537                      break;
14538
14539                   }
14540                default:
14541                   {
14542                      DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
14543                            f1SetRspMsg->protocolIEs.list.array[ieIdx]->id);
14544                   }
14545             }
14546             free(f1SetRspMsg->protocolIEs.list.array[ieIdx]);
14547          }
14548       }
14549       free(f1SetRspMsg->protocolIEs.list.array);
14550    }
14551 }
14552 /******************************************************************
14553  *
14554  * @brief Processes F1 Setup Response sent by CU
14555  *
14556  * @details
14557  *
14558  *    Function : procF1SetupRsp
14559  *
14560  *    Functionality: Processes F1 Setup Response sent by CU
14561  *
14562  * @params[in] F1AP_PDU_t ASN decoded F1AP message
14563  * @return ROK     - success
14564  *         RFAILED - failure
14565  *
14566  * ****************************************************************/
14567 uint8_t procF1SetupRsp(F1AP_PDU_t *f1apMsg, MsgLen recvBufLen, char *recvBuf)
14568 {
14569    uint8_t ret = ROK;
14570    uint16_t idx =0;
14571    F1SetupResponse_t *f1SetRspMsg = NULLP;
14572    GNB_CU_Name_t     *cuName = NULLP;
14573    F1SetupRsp  f1SetRspDb;
14574    RRC_Version_t      *rrcVer =NULLP;
14575    
14576    memset(&f1SetRspDb, 0, sizeof(F1SetupRsp));
14577
14578    DU_LOG("\nINFO   -->  F1AP : F1 Setup Response received");
14579    f1SetRspMsg = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
14580
14581    for(idx=0; idx<f1SetRspMsg->protocolIEs.list.count; idx++)
14582    {
14583       switch(f1SetRspMsg->protocolIEs.list.array[idx]->id)
14584       {
14585          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
14586             {
14587                extractCellsToBeActivated(f1SetRspMsg->protocolIEs.list.array[idx]->\
14588                      value.choice.Cells_to_be_Activated_List);
14589                break;
14590             }
14591          case ProtocolIE_ID_id_TransactionID:
14592             {
14593                f1SetRspDb.transId = f1SetRspMsg->protocolIEs.list.array[idx]->\
14594                                     value.choice.TransactionID;
14595                break;
14596             }
14597          case ProtocolIE_ID_id_gNB_CU_Name:
14598             {
14599                cuName = &f1SetRspMsg->protocolIEs.list.array[idx]->\
14600                         value.choice.GNB_CU_Name;
14601                strcpy(f1SetRspDb.cuName, (const char*)cuName->buf);
14602                break;
14603             }
14604          case ProtocolIE_ID_id_GNB_CU_RRC_Version:
14605             {
14606                rrcVer = &f1SetRspMsg->protocolIEs.list.array[idx]->value.choice.RRC_Version;
14607                strcpy(f1SetRspDb.rrcVersion.rrcVer,
14608                      (const char*)rrcVer->latest_RRC_Version.buf);
14609                break;
14610             }
14611          default:
14612             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in F1SetupRsp:%ld",
14613                   f1SetRspMsg->protocolIEs.list.array[idx]->id);
14614       }
14615       duProcF1SetupRsp();
14616    }
14617    
14618    freeAperDecodeF1SetupRsp(f1SetRspMsg);
14619
14620    duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize = recvBufLen;
14621    DU_ALLOC(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize);
14622    if(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf == NULLP)
14623    {
14624       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed to store the buf of F1setup response");
14625       return RFAILED;
14626    }
14627    memcpy(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, recvBuf, recvBufLen);
14628    
14629    if(BuildAndSendE2SetupReq() != ROK)
14630    {
14631       DU_LOG("\nERROR  -->  F1AP : Failed to build and send E2 setup request ");
14632       return RFAILED;
14633    }
14634    return ret;
14635 }
14636 /*******************************************************************
14637 *
14638 * @brief free GNB DU config update ack
14639 *
14640 * @details
14641 *
14642 *    Function : freeAperDecodeGnbDuAck 
14643 *
14644 *    Functionality: Processes GNB DU config update ack And
14645 *                     added free part for the memory allocated by aper_decoder
14646 *
14647 * @params[in] F1AP_PDU_t ASN decoded F1AP message
14648 * @return ROK     - success
14649 *         RFAILED - failure
14650 *
14651 * ****************************************************************/
14652
14653 void freeAperDecodeGnbDuAck(GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck)
14654 {
14655    uint8_t ieIdx = 0;
14656
14657    if(gnbDuAck->protocolIEs.list.array)
14658    {
14659       for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
14660       {
14661          if(gnbDuAck->protocolIEs.list.array[ieIdx])
14662          {
14663             free(gnbDuAck->protocolIEs.list.array[ieIdx]);
14664          }
14665       }
14666       free(gnbDuAck->protocolIEs.list.array);
14667    }
14668 }
14669
14670 /*******************************************************************
14671 *
14672 * @brief Building  result of gnb-du config update ack output
14673 *
14674 * @details
14675 *
14676 *    Function : duProcGnbDuCfgUpdAckMsg 
14677 *
14678 *    Functionality: 
14679 *        Building output of gnb-du config update ack 
14680 *
14681 * @params[in] transId
14682 * @return void
14683 *
14684 * ****************************************************************/
14685
14686 uint8_t duProcGnbDuCfgUpdAckMsg(uint8_t transId)
14687 {
14688    uint8_t  ieIdx=0, arrIdx=0,ret=ROK;
14689    uint8_t  ueId =0 , ueIdx =0, totalActiveUe = 0;
14690    uint16_t cellId =0, cellIdx =0, crnti=0;
14691    CmLList *f1apPduNode = NULLP;
14692    ReservedF1apPduInfo *f1apPduInfo =NULLP;
14693    F1AP_PDU_t *f1apMsgPdu = NULLP;
14694    GNBDUConfigurationUpdate_t *gnbDuConfigUpdate = NULLP;
14695    BIT_STRING_t *cellIdentity=NULLP;
14696    struct Served_Cells_To_Delete_ItemIEs *deleteItemIe=NULLP;
14697    Served_Cells_To_Delete_List_t *cellsToDelete=NULLP;
14698    Served_Cells_To_Delete_Item_t *deleteItem=NULLP;
14699
14700    DU_LOG("\nINFO   -->  DU APP: GNB-DU config update Ack received ");
14701    f1apPduNode = searchFromReservedF1apPduList(transId);
14702    f1apPduInfo = (ReservedF1apPduInfo *)f1apPduNode->node;
14703    f1apMsgPdu = (F1AP_PDU_t *)f1apPduInfo->f1apMsg;
14704
14705    if(f1apMsgPdu)
14706    {
14707       if(f1apMsgPdu->choice.initiatingMessage)
14708       {
14709          gnbDuConfigUpdate = &f1apMsgPdu->choice.initiatingMessage->value.choice.GNBDUConfigurationUpdate;
14710          for(ieIdx=0; ieIdx < gnbDuConfigUpdate->protocolIEs.list.count; ieIdx++)
14711          {
14712             switch(gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->id)
14713             {
14714                case ProtocolIE_ID_id_Served_Cells_To_Delete_List:
14715                   {
14716                      cellsToDelete = &gnbDuConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.\
14717                                      Served_Cells_To_Delete_List;
14718                      if(cellsToDelete->list.array)
14719                      {
14720                         if(cellsToDelete->list.array[arrIdx])
14721                         {
14722                            deleteItemIe = (Served_Cells_To_Delete_ItemIEs_t*)cellsToDelete->list.array[arrIdx];
14723                            deleteItem=&deleteItemIe->value.choice.Served_Cells_To_Delete_Item;
14724                            if(deleteItem->oldNRCGI.nRCellIdentity.buf)
14725                            {
14726                               cellIdentity = &deleteItem->oldNRCGI.nRCellIdentity;
14727                               bitStringToInt(cellIdentity, &cellId);
14728
14729                               GET_CELL_IDX(cellId, cellIdx);
14730                               if(duCb.actvCellLst[cellIdx] != NULLP)
14731                               {
14732                                  duCb.actvCellLst[cellId-1]->cellStatus = DELETION_IN_PROGRESS;
14733                               }
14734                            }
14735                         }
14736                      }
14737
14738                      if(duCb.actvCellLst[cellIdx] != NULLP)
14739                      {
14740                         if(duCb.actvCellLst[cellIdx]->numActvUes == 0)
14741                         {
14742                            ret = duSendCellDeletReq(cellId);
14743                            if(ret == RFAILED)
14744                            {
14745                               DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to send cell delete\
14746                               request for cellId[%d]", cellId);
14747                            }
14748                         }
14749                         else
14750                         {
14751                            totalActiveUe = duCb.actvCellLst[cellIdx]->numActvUes;
14752                            while(totalActiveUe)
14753                            {
14754                               if(duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState != UE_ACTIVE)
14755                               {
14756                                  ueIdx++;
14757                                  continue;
14758                               }
14759
14760                               crnti = duCb.actvCellLst[cellIdx]->ueCb[ueIdx].crnti;
14761                               GET_UE_ID(crnti,ueId);
14762                               /* Sending Ue Context release request only for maximum supporting UEs */
14763                               ret = BuildAndSendUeContextReleaseReq(cellId, ueId);
14764                               if(ret == RFAILED)
14765                               {
14766                                  DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): Failed to build and send UE delete\
14767                                  request for cellId[%d]", cellId);
14768                               }
14769                               ueIdx++;
14770                               totalActiveUe--;
14771                            }
14772                         }
14773                      }
14774                      else
14775                      {
14776                         DU_LOG("\nERROR  --> DU_APP : duProcGnbDuCfgUpdAckMsg(): CellId [%d] not found", cellId);
14777                         ret = RFAILED;
14778                      }
14779                      break;
14780                   }
14781
14782                default:
14783                   break;
14784             }
14785          }
14786       }
14787    }
14788    
14789    FreeDUConfigUpdate(f1apMsgPdu);
14790    deleteFromReservedF1apPduList(f1apPduNode);
14791    return ret;
14792 }
14793
14794 /*******************************************************************
14795 *
14796 * @brief Processes GNB DU config update ack
14797 *
14798 * @details
14799 *
14800 *    Function : procF1GNBDUCfgUpdAck
14801 *
14802 *    Functionality: added free part for the memory allocated by aper_decoder
14803 *
14804 * @params[in] F1AP_PDU_t *f1apMsg 
14805 * @return void 
14806 *
14807 * ****************************************************************/
14808 uint8_t procF1GNBDUCfgUpdAck(F1AP_PDU_t *f1apMsg)
14809 {
14810    uint8_t ieIdx=0,transId=0;
14811    GNBDUConfigurationUpdateAcknowledge_t *gnbDuAck = NULLP;
14812
14813    DU_LOG("\nINFO   -->  F1AP : GNB-DU config update acknowledgment");
14814    gnbDuAck = &f1apMsg->choice.successfulOutcome->value.choice.GNBDUConfigurationUpdateAcknowledge;
14815
14816    for(ieIdx=0; ieIdx < gnbDuAck->protocolIEs.list.count; ieIdx++)
14817    {
14818       switch(gnbDuAck->protocolIEs.list.array[ieIdx]->id)
14819       {
14820          case ProtocolIE_ID_id_TransactionID:
14821             {
14822                transId = gnbDuAck->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
14823                break;
14824             }
14825          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
14826             {
14827                break;
14828             }
14829          default :
14830             {
14831                DU_LOG("\nERROR  -->  F1AP: procF1GNBDUCfgUpdAck(): Invalid IE Received: %ld", \
14832                      gnbDuAck->protocolIEs.list.array[ieIdx]->id);
14833                break;
14834             }
14835       }
14836    }
14837    
14838    duProcGnbDuCfgUpdAckMsg(transId);
14839     
14840 #if 0
14841    /* presently we are not supporting F1 Reset from DU to CU , we are only
14842     * supporting F1 Reset from CU to DU */
14843
14844    if(BuildAndSendF1ResetReq() != ROK)
14845    {
14846       return RFAILED;
14847    }
14848 #endif
14849
14850    freeAperDecodeGnbDuAck(gnbDuAck);
14851    return ROK;
14852 }
14853 /******************************************************************
14854 *
14855 * @brief free DL RRC Message Transfer allocated by aper_decoder 
14856 *
14857 * @details
14858 *
14859 *    Function : freeAperDecodef1DlRrcMsg 
14860 *
14861 *    Functionality: free DL RRC Message Transfer allocated by aper_decoder 
14862 *
14863 * @params[in] DLRRCMessageTransfer_t *f1DlRrcMsg 
14864 * @return ROK     - success
14865 *         RFAILED - failure
14866 *
14867 * ****************************************************************/
14868
14869 void freeAperDecodef1DlRrcMsg(DLRRCMessageTransfer_t *f1DlRrcMsg)
14870 {
14871    uint8_t ieIdx =0;
14872    RRCContainer_t *rrcContainer = NULLP;
14873
14874    if(f1DlRrcMsg->protocolIEs.list.array)
14875    {
14876       for(ieIdx=0; ieIdx<f1DlRrcMsg->protocolIEs.list.count; ieIdx++)
14877       {
14878          if(f1DlRrcMsg->protocolIEs.list.array[ieIdx])
14879          {
14880             switch(f1DlRrcMsg->protocolIEs.list.array[ieIdx]->id)
14881             {
14882                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14883                   break;
14884                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14885                   break;
14886                case ProtocolIE_ID_id_SRBID:
14887                   break;
14888                case ProtocolIE_ID_id_RRCContainer:
14889                   {
14890                      rrcContainer =&f1DlRrcMsg->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer;
14891                      free(rrcContainer->buf);
14892                   }
14893                case ProtocolIE_ID_id_ExecuteDuplication:
14894                   break;
14895                case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
14896                   break;
14897                   break;
14898             }
14899             free(f1DlRrcMsg->protocolIEs.list.array[ieIdx]);
14900          }
14901       }
14902       free(f1DlRrcMsg->protocolIEs.list.array);
14903    }
14904 }
14905 /******************************************************************
14906  *
14907  * @brief Processes DL RRC Message Transfer  sent by CU
14908  *
14909  * @details
14910  *
14911  *    Function : procF1DlRrcMsgTrans
14912  *
14913  *    Functionality: Processes DL RRC Message Transfer sent by CU
14914  *
14915  * @params[in] F1AP_PDU_t ASN decoded F1AP message
14916  * @return ROK     - success
14917  *         RFAILED - failure
14918  *
14919  * ****************************************************************/
14920 uint8_t procF1DlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
14921 {
14922    uint8_t  idx, ret;
14923    DLRRCMessageTransfer_t *f1DlRrcMsg = NULLP;
14924    F1DlRrcMsg dlMsg;
14925    memset(&dlMsg, 0, sizeof(F1DlRrcMsg));
14926
14927    DU_LOG("\nINFO   -->  DU_APP : DL RRC message transfer Recevied");
14928    f1DlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
14929
14930    ret = ROK;
14931
14932    for(idx=0; idx<f1DlRrcMsg->protocolIEs.list.count; idx++)
14933    {
14934       switch(f1DlRrcMsg->protocolIEs.list.array[idx]->id)
14935       {
14936          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
14937             {
14938                dlMsg.gnbCuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
14939                break;
14940             }
14941          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
14942             {
14943                dlMsg.gnbDuUeF1apId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
14944                break;
14945             }
14946          case ProtocolIE_ID_id_SRBID:
14947             {
14948                dlMsg.srbId = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
14949                break;
14950             }
14951          case ProtocolIE_ID_id_ExecuteDuplication:
14952             dlMsg.execDup = true;
14953             break;
14954
14955          case ProtocolIE_ID_id_RRCContainer:
14956             {
14957                if(f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
14958                {
14959                   dlMsg.rrcMsgSize = f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
14960                   DU_ALLOC_SHRABL_BUF(dlMsg.rrcMsgPdu, dlMsg.rrcMsgSize);
14961                   if(dlMsg.rrcMsgPdu)
14962                   {
14963                      memcpy(dlMsg.rrcMsgPdu, f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf,\
14964                         dlMsg.rrcMsgSize);
14965                   }
14966                   else
14967                   {
14968                      DU_LOG("\nERROR  -->  DU APP : Memory alloc Failed at RRC Container at procF1DlRrcMsgTrans()");
14969                      return RFAILED;
14970                   }
14971                }
14972                else
14973                {
14974                   DU_LOG("\nERROR  -->  DU_APP : RRC Container Size is invalid:%ld",\
14975                   f1DlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
14976                   return RFAILED;
14977                }
14978                break;
14979             }
14980          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
14981             {
14982                dlMsg.deliveryStatRpt = true;
14983                break;
14984             }
14985          default:
14986             DU_LOG("\nERROR  -->  DU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
14987                   f1DlRrcMsg->protocolIEs.list.array[idx]->id);
14988       }
14989    }
14990
14991    ret = duProcDlRrcMsg(&dlMsg);
14992
14993    freeAperDecodef1DlRrcMsg(f1DlRrcMsg);
14994    return ret;
14995 }
14996 /*******************************************************************
14997  *
14998 * @brief Builds the DRB to be Setup Mod list
14999 *
15000 * @details
15001 *
15002 *    Function : 
15003 *
15004 *    Functionality: Constructs the DRB to be Setup Mod list
15005 *
15006 * @params[in] DRBs_SetupMod_List_t *drbSet
15007 *
15008 * @return ROK     - success
15009 *         RFAILED - failure
15010 *
15011 * ****************************************************************/
15012 uint8_t BuildSrbSetupModList(SRBs_SetupMod_List_t *srbList, DuUeCfg *ueCfg)
15013 {
15014    uint8_t srbIdx = 0;
15015    struct SRBs_SetupMod_ItemIEs *srbItemIe;
15016
15017    srbList->list.count = ueCfg->numRlcLcs;
15018    srbList->list.size = srbList->list.count * sizeof(SRBs_SetupMod_ItemIEs_t *);
15019
15020    DU_ALLOC(srbList->list.array, srbList->list.size);
15021    if(srbList->list.array == NULLP)
15022    {
15023       DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15024       return RFAILED;
15025    }
15026
15027    for(srbIdx = 0; srbIdx < srbList->list.count; srbIdx++)
15028    {
15029       DU_ALLOC(srbList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15030       if(srbList->list.array[srbIdx] == NULLP)
15031       {
15032          DU_LOG("\nERROR  -->  DU APP : Memory allocation failed in BuildSrbSetupModList");
15033          return RFAILED;
15034       }
15035    } 
15036
15037    for(srbIdx=0; srbIdx < srbList->list.count; srbIdx++)
15038    {
15039       srbItemIe = (struct SRBs_SetupMod_ItemIEs *)srbList->list.array[srbIdx];
15040       srbItemIe->id = ProtocolIE_ID_id_SRBs_SetupMod_Item;
15041       srbItemIe->criticality = Criticality_reject;
15042       srbItemIe->value.present = SRBs_SetupMod_ItemIEs__value_PR_SRBs_SetupMod_Item;
15043       srbItemIe->value.choice.SRBs_SetupMod_Item.sRBID = ueCfg->rlcLcCfg[srbIdx].rbId;
15044       srbItemIe->value.choice.SRBs_SetupMod_Item.lCID = ueCfg->rlcLcCfg[srbIdx].lcId;
15045    }
15046    return ROK;
15047 }
15048
15049 /*******************************************************************
15050  *
15051 * @brief Builds the DRB to be Setup Mod list
15052 *
15053 * @details
15054 *
15055 *    Function : 
15056 *
15057 *    Functionality: Constructs the DRB to be Setup Mod list
15058 *
15059 * @params[in] DRBs_SetupMod_List_t *drbSet
15060 *
15061 * @return ROK     - success
15062 *         RFAILED - failure
15063 *
15064 * ****************************************************************/
15065
15066 uint8_t BuildDrbSetupModList(DRBs_SetupMod_List_t *drbSet , DuUeCfg *ueCfg)
15067 {
15068    uint8_t arrIdx =0;
15069    uint8_t drbCnt =0;
15070    struct DRBs_SetupMod_ItemIEs *drbItemIe;
15071
15072    drbCnt = ueCfg->numDrbSetupMod;
15073
15074    if(!drbCnt)
15075    {
15076       DU_LOG("\nINFO  -->  F1AP : BuildDrbToBeSetupModList(): No DRB information to avaialble to add");
15077       return ROK;
15078    }
15079
15080    drbSet->list.count = drbCnt;
15081    drbSet->list.size = drbCnt * sizeof(DRBs_SetupMod_ItemIEs_t *);
15082    DU_ALLOC(drbSet->list.array, drbSet->list.size);
15083    if(drbSet->list.array == NULLP)
15084    {
15085       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
15086       return  RFAILED;
15087    }
15088    for(arrIdx=0; arrIdx<drbCnt; arrIdx++)
15089    {
15090       DU_ALLOC(drbSet->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
15091       if(drbSet->list.array[arrIdx] == NULLP)
15092       {
15093               DU_LOG("\nERROR  -->  F1AP : Memory allocation failed in BuildDrbToBeSetupModList");
15094               return  RFAILED;
15095       }
15096
15097       drbItemIe = (struct DRBs_SetupMod_ItemIEs *)drbSet->list.array[arrIdx];
15098       drbItemIe->id = ProtocolIE_ID_id_DRBs_SetupMod_Item;
15099       drbItemIe->criticality = Criticality_reject;
15100       drbItemIe->value.present = DRBs_SetupMod_ItemIEs__value_PR_DRBs_SetupMod_Item;
15101       drbItemIe->value.choice.DRBs_SetupMod_Item.dRBID = ueCfg->upTnlInfo[arrIdx].drbId;
15102       if(fillDlTnlSetupList(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List,\
15103       &ueCfg->upTnlInfo[arrIdx])!= ROK)
15104       {
15105          DU_LOG("\nERROR  -->  F1AP : Failed to fill DlTnl SetupList in BuildDrbToBeSetupModList");
15106          return RFAILED;
15107       }
15108       
15109    }
15110
15111    return ROK;
15112 }
15113 /*******************************************************************
15114 * @brief Free the memory allocated for DRB setup List
15115 *
15116 * @details
15117 *
15118 *    Function : FreeDrbSetupModList 
15119 *
15120 *    Functionality:
15121 *       Free the memory allocated for DRB setup list
15122 *
15123 * @params[in] DRBs_Setup_List_t *
15124 * @return void
15125 *
15126 * ****************************************************************/
15127 void FreeDrbSetupModList(DRBs_SetupMod_List_t *drbSetupList)
15128 {
15129    uint8_t arrIdx = 0;
15130    DRBs_SetupMod_ItemIEs_t *drbItemIe = NULLP;
15131
15132    for(arrIdx = 0; arrIdx < drbSetupList->list.count; arrIdx++)
15133    {
15134       drbItemIe = ((DRBs_SetupMod_ItemIEs_t *)drbSetupList->list.array[arrIdx]);
15135       freeDlTnlInfo(&drbItemIe->value.choice.DRBs_SetupMod_Item.dLUPTNLInformation_ToBeSetup_List);
15136       DU_FREE(drbSetupList->list.array[arrIdx], sizeof(DRBs_SetupMod_ItemIEs_t));
15137    }
15138    DU_FREE(drbSetupList->list.array, drbSetupList->list.size);
15139 }
15140
15141 /*******************************************************************
15142 * @brief Free the memory allocated for SRB setup List
15143 *
15144 * @details
15145 *
15146 *    Function : FreeSrbSetupModList 
15147 *
15148 *    Functionality:
15149 *       Free the memory allocated for SRB setup list
15150 *
15151 * @params[in] SRBs_Setup_List_t *
15152 * @return void
15153 *
15154 * ****************************************************************/
15155 void FreeSrbSetupModList(SRBs_SetupMod_List_t *srbSetupList)
15156 {
15157    uint8_t srbIdx = 0;
15158    
15159    for(srbIdx = 0; srbIdx < srbSetupList->list.count; srbIdx++)
15160       DU_FREE(srbSetupList->list.array[srbIdx], sizeof(SRBs_SetupMod_ItemIEs_t));
15161    DU_FREE(srbSetupList->list.array, srbSetupList->list.size);
15162 }
15163
15164 /*******************************************************************
15165 * @brief Free the memory allocated for UE Context Mod Response
15166 *
15167 * @details
15168 *
15169 *    Function : FreeUeContextModResp 
15170 *
15171 *    Functionality:
15172 *       Free the memory allocated for UE Context Mod Response
15173 *
15174 * @params[in] F1AP_PDU_t *f1apMsg
15175 * @return void
15176 *
15177 * ****************************************************************/
15178
15179 void FreeUeContextModResp(F1AP_PDU_t *f1apMsg)
15180 {
15181    uint8_t ieIdx;
15182    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
15183    if(f1apMsg)
15184    {
15185       if(f1apMsg->choice.successfulOutcome)
15186       {
15187          ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
15188          if(ueContextModifyRes->protocolIEs.list.array)
15189          {
15190             for(ieIdx=0 ; ieIdx<ueContextModifyRes->protocolIEs.list.count; ieIdx++)
15191             {
15192                if(ueContextModifyRes->protocolIEs.list.array[ieIdx])
15193                {
15194                   switch(ueContextModifyRes->protocolIEs.list.array[ieIdx]->id)
15195                   {
15196                      case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15197                         break;
15198                      case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15199                         break;
15200                      case ProtocolIE_ID_id_DRBs_SetupMod_List:
15201                         {
15202                             FreeDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
15203                             value.choice.DRBs_SetupMod_List));
15204                             break;
15205                         }
15206                      case ProtocolIE_ID_id_SRBs_SetupMod_List:
15207                         {
15208                            FreeSrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.\
15209                               SRBs_SetupMod_List));
15210                            break; 
15211                         }
15212                   }
15213                   DU_FREE(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
15214                }
15215
15216             }
15217             DU_FREE(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
15218          }
15219          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
15220       }
15221       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
15222    }
15223 }
15224
15225 /*****************************************************************i
15226 *
15227 * @brief Creating the ue context modifcation response and sending
15228 *
15229 * @details
15230 *
15231 *    Function : BuildAndSendUeContextModRsp 
15232 *
15233 *    Functionality:
15234 *         - Creating the ue context modifcation response 
15235 *
15236 * @params[in] uint8_t cellId,uint8_t ueId
15237 * @return ROK     - success
15238 *         RFAILED - failure
15239 *
15240 * ****************************************************************/
15241 uint8_t BuildAndSendUeContextModRsp(DuUeCb *ueCb)
15242 {
15243    uint8_t   ieIdx = 0, tnlIdx = 0, rbIdx = 0;
15244    uint8_t   elementCnt = 0;
15245    uint8_t   ret = RFAILED;
15246    F1AP_PDU_t *f1apMsg = NULLP;
15247    asn_enc_rval_t  encRetVal;
15248    UEContextModificationResponse_t *ueContextModifyRes = NULLP;
15249
15250    DU_LOG("\nINFO  -->  F1AP : Building UE context modification response\n");
15251
15252    while(1)
15253    {
15254       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15255       if(f1apMsg == NULLP)
15256       {
15257          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
15258          break;
15259       }
15260
15261       f1apMsg->present =  F1AP_PDU_PR_successfulOutcome;
15262
15263       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
15264       if(f1apMsg->choice.successfulOutcome == NULLP)
15265       {
15266          DU_LOG("\nERROR  -->  F1AP : Memory allocation for F1AP-PDU failed Ue context modification");
15267          break;
15268       }
15269       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextModification;
15270       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
15271       f1apMsg->choice.successfulOutcome->value.present = SuccessfulOutcome__value_PR_UEContextModificationResponse;
15272
15273       ueContextModifyRes =&f1apMsg->choice.successfulOutcome->value.choice.UEContextModificationResponse;
15274   
15275       if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
15276       {
15277          if(ueCb->f1UeDb->duUeCfg.numDrbSetupMod)
15278             elementCnt =3;
15279          else
15280             elementCnt =2;
15281       }
15282       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15283          elementCnt = 5;
15284       if(ueCb->f1UeDb->actionType == UE_CTXT_RRC_RECFG_COMPLETE)
15285          elementCnt = 2;
15286       ueContextModifyRes->protocolIEs.list.count = elementCnt;
15287       ueContextModifyRes->protocolIEs.list.size = elementCnt*sizeof(UEContextModificationResponse_t*);
15288
15289       /* Initialize the UE context modification members */
15290       DU_ALLOC(ueContextModifyRes->protocolIEs.list.array, ueContextModifyRes->protocolIEs.list.size);
15291       if(ueContextModifyRes->protocolIEs.list.array == NULLP)
15292       {
15293          DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
15294          break;
15295       }
15296
15297       for(ieIdx=0 ; ieIdx<elementCnt; ieIdx++)
15298       {
15299          DU_ALLOC(ueContextModifyRes->protocolIEs.list.array[ieIdx], sizeof(UEContextModificationResponse_t));
15300          if(ueContextModifyRes->protocolIEs.list.array[ieIdx] == NULLP)
15301          {
15302             DU_LOG("\nERROR  -->  F1AP : Memory allocation for UE context modifcation Request failed");
15303             break;
15304          }
15305       }
15306
15307       ieIdx=0;
15308       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
15309       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15310       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
15311       UEContextModificationResponseIEs__value_PR_GNB_CU_UE_F1AP_ID;
15312       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID = ueCb->gnbCuUeF1apId;
15313
15314       ieIdx++;
15315       ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
15316       ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15317       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present=\
15318       UEContextModificationResponseIEs__value_PR_GNB_DU_UE_F1AP_ID;
15319       ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID = ueCb->gnbDuUeF1apId;
15320
15321       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15322       {
15323          ieIdx++;
15324          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DUtoCURRCInformation;
15325          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15326          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
15327          UEContextModificationResponseIEs__value_PR_DUtoCURRCInformation;
15328          BuildCellGroupConfigRrc(ueCb, &ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.DUtoCURRCInformation.cellGroupConfig);
15329       }
15330
15331       if((ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY) || ((ueCb->f1UeDb->actionType == UE_CTXT_MOD) && (ueCb->f1UeDb->duUeCfg.numDrbSetupMod)))
15332       { 
15333          ieIdx++;
15334          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_DRBs_SetupMod_List;
15335          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15336          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present =\
15337                                                                            UEContextModificationResponseIEs__value_PR_DRBs_SetupMod_List;
15338          if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15339          {
15340             for(tnlIdx = 0; tnlIdx < duCb.numTeId; tnlIdx++)
15341             {
15342                if(duCb.upTnlCfg[tnlIdx]->ueId == ueCb->gnbDuUeF1apId)
15343                {
15344                   memcpy(&ueCb->f1UeDb->duUeCfg.upTnlInfo[ueCb->f1UeDb->duUeCfg.numDrbSetupMod++], duCb.upTnlCfg[tnlIdx], sizeof(UpTnlCfg));
15345                }
15346             }
15347          }
15348          ret = BuildDrbSetupModList(&(ueContextModifyRes->protocolIEs.list.array[ieIdx]->\
15349                   value.choice.DRBs_SetupMod_List) , &ueCb->f1UeDb->duUeCfg);
15350          if(ret != ROK)
15351          {
15352             DU_LOG( "\nERROR  -->  F1AP : Failed to build DRB setupmod List ");
15353             break;
15354          }
15355       }
15356
15357       if(ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY)
15358       {
15359          ieIdx++;
15360          ueContextModifyRes->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_SRBs_SetupMod_List;
15361          ueContextModifyRes->protocolIEs.list.array[ieIdx]->criticality = Criticality_reject;
15362          ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.present = \
15363                                                                             UEContextModificationResponseIEs__value_PR_SRBs_SetupMod_List;
15364          for(rbIdx = 0; rbIdx < ueCb->rlcUeCfg.numLcs; rbIdx++)
15365          {
15366             if(ueCb->rlcUeCfg.rlcLcCfg[rbIdx].rbType == RB_TYPE_SRB)
15367             {
15368                memcpy(&ueCb->f1UeDb->duUeCfg.rlcLcCfg[ueCb->f1UeDb->duUeCfg.numRlcLcs++], &ueCb->rlcUeCfg.rlcLcCfg[rbIdx],\
15369                      sizeof(RlcBearerCfg));
15370             }
15371          }
15372          ret = BuildSrbSetupModList(&ueContextModifyRes->protocolIEs.list.array[ieIdx]->value.choice.SRBs_SetupMod_List, \
15373                &ueCb->f1UeDb->duUeCfg);
15374          if(ret != ROK)
15375          {
15376             DU_LOG( "\nERROR  -->  F1AP : Failed to build SRB setupmod List ");
15377             break;
15378          }
15379       }
15380
15381       freeF1UeDb(ueCb->f1UeDb);
15382       ueCb->f1UeDb = NULLP;
15383
15384       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
15385
15386       /* Encode the F1SetupRequest type as APER */
15387       memset(encBuf, 0, ENC_BUF_MAX_LEN);
15388       encBufSize = 0;
15389       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf,encBuf);
15390
15391       /* Encode results */
15392       if(encRetVal.encoded == ENCODE_FAIL)
15393       {
15394          DU_LOG( "\nERROR  -->  F1AP : Could not encode UE Context Setup Request structure (at %s)\n",\
15395                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
15396          ret = RFAILED;
15397          break;
15398       }
15399       else
15400       {
15401          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UE Context Modification Response\n");
15402          for(int i=0; i< encBufSize; i++)
15403          {
15404             printf("%x",encBuf[i]);
15405          }
15406       }
15407
15408       /* Sending  msg  */
15409       if(sendF1APMsg() != ROK)
15410       {
15411          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Setup Res Failed");
15412          ret = RFAILED;
15413          break;
15414       }
15415
15416       ret = ROK;
15417       break;
15418    }
15419    FreeUeContextModResp(f1apMsg);
15420    return ret;
15421 }
15422 /*******************************************************************
15423  *
15424  * @brief Deallocating the memory allocated by the aper decoder
15425  *          for QOSInfo
15426  *
15427  * @details
15428  *
15429  *    Function : freeAperDecodeQosInfo
15430  *
15431  *    Functionality:  Deallocating the memory allocated for QOSInfo
15432  *
15433  * @params[in] QoSFlowLevelQoSParameters_t *drbQos
15434  *
15435  * @return void
15436  *
15437  * ****************************************************************/
15438
15439 void freeAperDecodeQosInfo(QoSFlowLevelQoSParameters_t *drbQos)
15440 {
15441    if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI != NULLP)
15442    {
15443       if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow!=NULLP)
15444       {
15445          if(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume!=NULLP)
15446          {
15447             free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->maxDataBurstVolume);
15448          }
15449          free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI->averagingWindow);
15450       }
15451       free(drbQos->qoS_Characteristics.choice.non_Dynamic_5QI);
15452    }
15453 }
15454 /*******************************************************************
15455  *
15456  * @brief Deallocating the memory allocated by the aper decoder
15457  *          for UlTnlInfoforDrb
15458  *
15459  * @details
15460  *
15461  *    Function : freeAperDecodeUlTnlInfoforDrbSetupMod 
15462  *
15463  *    Functionality:  Deallocating memory allocated for UlTnlInfoforDrb
15464  *
15465  * @params[in] ULUPTNLInformation_ToBeSetup_List_t *ulInfo
15466  *
15467  * @return void
15468  *
15469  * ****************************************************************/
15470 void freeAperDecodeUlTnlInfoforDrbSetupMod(ULUPTNLInformation_ToBeSetup_List_t *ulInfo)
15471 {
15472    uint8_t arrIdx =0;
15473
15474    if(ulInfo->list.array)
15475    {
15476       for(arrIdx=0; arrIdx<ulInfo->list.count ; arrIdx++)
15477       {
15478          if(ulInfo->list.array[arrIdx])
15479          {
15480             if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel )
15481             {
15482                if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->transportLayerAddress.buf)
15483                {
15484                   if(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->gTP_TEID.buf)
15485                   {
15486                      free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
15487                            gTP_TEID.buf);
15488                   }
15489                   free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel->\
15490                         transportLayerAddress.buf);
15491                }
15492                free(ulInfo->list.array[arrIdx]->uLUPTNLInformation.choice.gTPTunnel);
15493             }
15494             free(ulInfo->list.array[arrIdx]);
15495          }
15496       }
15497       free(ulInfo->list.array);
15498    }
15499 }
15500 /*******************************************************************
15501  *
15502  * @brief Deallocating the memory allocated by the aper decoder
15503  *          for DrbSetupModItem  
15504  *
15505  * @details
15506  *
15507  *    Function : freeAperDecodeDrbSetupModItem 
15508  *
15509  *    Functionality:  Deallocating memory allocated for DrbSetupModItem
15510  *
15511  * @params[in] DRBs_ToBeSetupMod_Item_t *drbItem
15512  *
15513  * @return void
15514  *
15515  * ****************************************************************/
15516
15517 void freeAperDecodeDrbSetupModItem(DRBs_ToBeSetupMod_Item_t *drbItem)
15518 {
15519    uint8_t arrIdx =0;
15520    SNSSAI_t *snssai =NULLP;
15521    Flows_Mapped_To_DRB_List_t *flowMap = NULLP;
15522
15523    drbItem->qoSInformation.present = QoSInformation_PR_choice_extension;
15524    switch(drbItem->qoSInformation.present)
15525    {
15526       case QoSInformation_PR_NOTHING:
15527          break;
15528       case QoSInformation_PR_eUTRANQoS:
15529          {
15530             if(drbItem->qoSInformation.choice.eUTRANQoS)
15531             {
15532                free(drbItem->qoSInformation.choice.eUTRANQoS);
15533             }
15534             break;
15535          }
15536       case QoSInformation_PR_choice_extension:
15537          {
15538             if(drbItem->qoSInformation.choice.choice_extension)
15539             {
15540                freeAperDecodeQosInfo(&drbItem->qoSInformation.choice.choice_extension->value.choice.\
15541                      DRB_Information.dRB_QoS);
15542                snssai = &drbItem->qoSInformation.choice.choice_extension->value.choice.DRB_Information.sNSSAI;
15543                if(snssai->sST.buf)
15544                {
15545                   free(snssai->sST.buf);
15546                }
15547                if(snssai->sD)
15548                {
15549                   if(snssai->sD->buf)
15550                   {
15551                      free(snssai->sD->buf);
15552                   }
15553                   free(snssai->sD);
15554                }
15555
15556                flowMap = &drbItem->qoSInformation.choice.choice_extension->value.choice.\
15557                          DRB_Information.flows_Mapped_To_DRB_List;
15558                if(flowMap->list.array)
15559                {
15560                   for(arrIdx=0; arrIdx<flowMap->list.count; arrIdx++)
15561                   {
15562                      if(flowMap->list.array[arrIdx] )
15563                      {
15564                         freeAperDecodeQosInfo(&flowMap->list.array[arrIdx]->qoSFlowLevelQoSParameters);
15565                         free(flowMap->list.array[arrIdx]);
15566                      }
15567                   }
15568                   free(flowMap->list.array);
15569                }
15570
15571                free(drbItem->qoSInformation.choice.choice_extension);
15572             }
15573             break;
15574          }
15575
15576    }
15577    freeAperDecodeUlTnlInfoforDrbSetupMod(&drbItem->uLUPTNLInformation_ToBeSetup_List);
15578    if(drbItem->uLConfiguration)
15579    {
15580       free(drbItem->uLConfiguration);
15581    }
15582 }
15583
15584 /*******************************************************************
15585  *
15586  * @brief Deallocating the memory allocated by the aper decoder
15587  *          for DrbToBeSetupModList
15588  *
15589  * @details
15590  *
15591  *    Function : freeAperDecodeDrbToBeSetupModList
15592  *
15593  *    Functionality:  Deallocating memory allocated for DrbToBeSetupModList
15594  *
15595  * @params[in] DRBs_ToBeSetupMod_List_t *drbSet
15596  *
15597  * @return void
15598  *
15599  * ****************************************************************/
15600
15601 void freeAperDecodeDrbToBeSetupModList(DRBs_ToBeSetupMod_List_t *drbSet)
15602 {
15603    uint8_t arrIdx =0;
15604    struct DRBs_ToBeSetupMod_ItemIEs *drbItemIe;
15605
15606    if(drbSet->list.array)
15607    {
15608       for(arrIdx=0; arrIdx<drbSet->list.count ; arrIdx++)
15609       {
15610          if(drbSet->list.array[arrIdx] != NULLP)
15611          {
15612             if(arrIdx == 0)
15613             {
15614                drbItemIe = (DRBs_ToBeSetupMod_ItemIEs_t *)drbSet->list.array[arrIdx];
15615                freeAperDecodeDrbSetupModItem(&(drbItemIe->value.choice.DRBs_ToBeSetupMod_Item));
15616             }
15617             free(drbSet->list.array[arrIdx]);
15618          }
15619       }
15620       free(drbSet->list.array);
15621    }
15622
15623 }
15624 /*******************************************************************
15625  *
15626  * @brief Deallocating the memory allocated by the aper decoder
15627  *          for UeContextModificationReqMsg
15628  *
15629  * @details
15630  *
15631  *    Function : freeAperDecodeUeContextModificationReqMsg
15632  *
15633  *    Functionality:  Deallocating memory allocated for
15634  *                  UeContextModificationReqMsg
15635  *
15636  * @params[in] UEContextModificationRequest_t *UeContextModifyReq
15637  *
15638  * @return void
15639  *
15640  * ****************************************************************/
15641 void freeAperDecodeUeContextModificationReqMsg(UEContextModificationRequest_t *ueContextModifyReq )
15642 {
15643    uint8_t arrIdx, ieId;
15644
15645    if(ueContextModifyReq->protocolIEs.list.array)
15646    {
15647       for( arrIdx = 0 ; arrIdx<ueContextModifyReq->protocolIEs.list.count ; arrIdx++)
15648       {
15649          if(ueContextModifyReq->protocolIEs.list.array[arrIdx])
15650          {
15651             ieId = ueContextModifyReq->protocolIEs.list.array[arrIdx]->id;
15652             switch(ieId)
15653             {
15654                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15655                   break;
15656                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15657                   break;
15658                case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
15659                   {
15660                      freeAperDecodeDrbToBeSetupModList(&ueContextModifyReq->protocolIEs.list.array[arrIdx]->\
15661                            value.choice.DRBs_ToBeSetupMod_List);
15662                      break;
15663                   }
15664                case ProtocolIE_ID_id_TransmissionActionIndicator:
15665                   break;
15666                case ProtocolIE_ID_id_RRCContainer:
15667                   {
15668                      free(ueContextModifyReq->protocolIEs.list.array[arrIdx]->value.choice.RRCContainer.buf);
15669                   }
15670             }
15671             free(ueContextModifyReq->protocolIEs.list.array[arrIdx]);
15672          }
15673       }
15674       free(ueContextModifyReq->protocolIEs.list.array);
15675    }
15676 }
15677 /*******************************************************************
15678  *
15679  * @brief processing the F1 UeContextModificationReq
15680  *
15681  * @details
15682  *
15683  *    Function : procF1UeContextModificationReq
15684  *
15685  *    Functionality:  processing the F1 UeContextModificationReq
15686  *
15687  * @params[in] F1AP_PDU_t *f1apMsg
15688  *
15689  * @return
15690  * ****************************************************************/
15691 uint8_t procF1UeContextModificationReq(F1AP_PDU_t *f1apMsg)
15692 {
15693    UEContextModificationRequest_t *ueContextModifyReq = NULLP;
15694    uint8_t  ret = ROK, ieIdx = 0, cellIdx=0;
15695    DuUeCb   *duUeCb = NULLP;
15696    DRBs_ToBeSetupMod_List_t *drbSetupModCfg;
15697    DRBs_ToBeModified_List_t *drbModifiedCfg;
15698    uint32_t gnbCuUeF1apId, gnbDuUeF1apId;
15699
15700    ueContextModifyReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextModificationRequest;
15701    for(ieIdx=0; (ieIdx < ueContextModifyReq->protocolIEs.list.count && ret == ROK); ieIdx++)
15702    {
15703       switch(ueContextModifyReq->protocolIEs.list.array[ieIdx]->id)
15704       {
15705          case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
15706             {
15707                gnbCuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
15708                break;
15709             }
15710          case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
15711             {
15712                gnbDuUeF1apId = ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
15713                for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
15714                {
15715                   if(duCb.actvCellLst[cellIdx])
15716                   {
15717                      if((duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbDuUeF1apId == gnbDuUeF1apId)&&\
15718                            (duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1].gnbCuUeF1apId == gnbCuUeF1apId))
15719                      {
15720                         duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[gnbDuUeF1apId-1];
15721                         if(duUeCb->f1UeDb == NULLP)
15722                         {
15723                            DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
15724                            duUeCb->f1UeDb->cellIdx = cellIdx;
15725                            duUeCb->f1UeDb->actionType = UE_CTXT_MOD;
15726                         }
15727                         break;
15728                      }
15729                   }
15730                }
15731                if(duUeCb == NULLP)
15732                {
15733                   DU_LOG("\nERROR  -->  DU APP : wrong values of gnbCuUeF1apId and gnbDuUeF1apId ");
15734                   ret = RFAILED;
15735                }
15736                break;
15737             }
15738
15739          case ProtocolIE_ID_id_RRCContainer:
15740             {
15741                /* Filling Dl RRC Msg Info */
15742                DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
15743                if(!duUeCb->f1UeDb->dlRrcMsg)
15744                {
15745                   DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
15746                         Memory allocation failed ");
15747                   ret = RFAILED;
15748                }
15749                else
15750                {
15751                   duUeCb->f1UeDb->dlRrcMsgPres = true;
15752                   memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
15753                   ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
15754                         &ueContextModifyReq->protocolIEs.list.array[ieIdx]->\
15755                         value.choice.RRCContainer);
15756                }
15757
15758                break;
15759             }
15760
15761          case ProtocolIE_ID_id_DRBs_ToBeSetupMod_List:
15762          case ProtocolIE_ID_id_DRBs_ToBeModified_List:
15763             {
15764                if(duUeCb->f1UeDb)
15765                {
15766                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present ==\
15767                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeSetupMod_List)
15768                   {
15769                      drbSetupModCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
15770                                       choice.DRBs_ToBeSetupMod_List;
15771
15772                      if(extractDrbListToSetupMod(NULL, drbSetupModCfg, NULL, drbSetupModCfg->list.count,\
15773                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, NULL))
15774                      {
15775                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbSetupModList");
15776                         ret = RFAILED;
15777                      }
15778                   }
15779
15780                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.present == \
15781                         UEContextModificationRequestIEs__value_PR_DRBs_ToBeModified_List)
15782
15783                   {
15784                      drbModifiedCfg = &ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.\
15785                                       choice.DRBs_ToBeModified_List;
15786                      if(extractDrbListToSetupMod(NULL, NULL, drbModifiedCfg, drbModifiedCfg->list.count,\
15787                               &duUeCb->f1UeDb->duUeCfg, &duUeCb->drbBitMap, &duUeCb->rlcUeCfg))
15788                      {
15789                         DU_LOG("\nERROR  -->  DU APP : Failed at extractDrbListToSetupMod() for DrbModifiedList");
15790                         ret = RFAILED;
15791                      }
15792                   }
15793                }
15794                break;
15795             }
15796
15797          case ProtocolIE_ID_id_GNB_DUConfigurationQuery:
15798             {
15799                DU_LOG("\nINFO  -->  DU APP : Received GNB DU Configuration Query in UE Context Modification Request from CU");
15800                if(duUeCb->f1UeDb)
15801                {
15802                   duUeCb->f1UeDb->actionType = UE_CTXT_CFG_QUERY;
15803                }
15804                break;
15805             }
15806
15807          case ProtocolIE_ID_id_RRCReconfigurationCompleteIndicator:
15808             {
15809                if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.RRCReconfigurationCompleteIndicator == \
15810                   RRCReconfigurationCompleteIndicator_true)
15811                {
15812                   duUeCb->f1UeDb->actionType = UE_CTXT_RRC_RECFG_COMPLETE;
15813                }
15814                break;
15815             }
15816          case ProtocolIE_ID_id_TransmissionActionIndicator:
15817             {
15818                if(duUeCb->f1UeDb)
15819                {
15820                   if(ueContextModifyReq->protocolIEs.list.array[ieIdx]->value.choice.TransmissionActionIndicator  == TransmissionActionIndicator_stop)
15821                   {
15822                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = STOP_TRANSMISSION; 
15823                   }
15824                   else 
15825                   {
15826                      duUeCb->f1UeDb->duUeCfg.dataTransmissionAction = RESTART_TRANSMISSION; 
15827                   }
15828                }
15829                break;
15830             }
15831
15832          case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
15833             {
15834                if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
15835                {
15836                   duUeCb->f1UeDb->dlRrcMsg->deliveryStatRpt = true;
15837                }
15838                break;
15839             }
15840               
15841       }
15842    }
15843
15844    if(ret != RFAILED) 
15845    {
15846       ret = duProcUeContextModReq(duUeCb);
15847    }
15848    freeAperDecodeUeContextModificationReqMsg(ueContextModifyReq);
15849    return ret; 
15850 }
15851
15852 /*****************************************************************i
15853 *
15854 * @brief Free memory allocated for UE Context Release Request
15855 *
15856 * @details
15857 *
15858 *    Function : FreeUeContextReleaseReq
15859 *
15860 *    Functionality:
15861 *         - Free memory allocated for UE Context Release Request
15862 *
15863 * @params[in] F1AP_PDU_t *f1apMsg
15864 * @return void 
15865 *
15866 * *************************************************************/
15867 void FreeUeContextReleaseReq(F1AP_PDU_t *f1apMsg)
15868 {
15869    uint8_t ieIdx;
15870    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
15871    
15872    if(f1apMsg)
15873    {
15874       if(f1apMsg->choice.initiatingMessage)
15875       {
15876          ueReleaseReq =&f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
15877          if(ueReleaseReq->protocolIEs.list.array)
15878          {
15879             for(ieIdx=0 ; ieIdx<ueReleaseReq->protocolIEs.list.count; ieIdx++)
15880             {
15881                DU_FREE(ueReleaseReq->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseRequest_t));
15882             }
15883             DU_FREE(ueReleaseReq->protocolIEs.list.array, ueReleaseReq->protocolIEs.list.size);
15884          }
15885          DU_FREE(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
15886       }
15887       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
15888    }
15889
15890 }
15891 /*****************************************************************i
15892 *
15893 * @brief Build and Send UE Context Release Request  
15894 *
15895 * @details
15896 *
15897 *    Function : BuildAndSendUeContextReleaseReq
15898 *
15899 *    Functionality:
15900 *         - Build and Send UE Context Release Request 
15901 *
15902 * @params[in]
15903 * @return ROK     - success
15904 *         RFAILED - failure
15905 *
15906 * *************************************************************/
15907 uint8_t BuildAndSendUeContextReleaseReq(uint16_t cellId, uint8_t ueId)
15908 {
15909    bool memAllocFail = false;
15910    uint8_t ieIdx =0;
15911    uint8_t ret = RFAILED;
15912    uint16_t cellIdx =0;
15913    uint16_t crnti = 0;
15914    uint8_t  elementCnt = 0;
15915    uint32_t  gnbCuUeF1apId =0;   /* gNB-CU UE F1AP Id */
15916    uint32_t  gnbDuUeF1apId =0;   /* gNB-DU UE F1AP Id */
15917    asn_enc_rval_t encRetVal; 
15918    F1AP_PDU_t *f1apMsg = NULLP;
15919    UEContextReleaseRequest_t *ueReleaseReq = NULLP;
15920
15921    DU_LOG("\nINFO  --> Building the UE Context Release Request");
15922    do
15923    {
15924       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
15925       if(f1apMsg == NULLP)
15926       {
15927          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for f1apMsg");
15928          break;
15929       }
15930
15931       f1apMsg->present = F1AP_PDU_PR_initiatingMessage;
15932       DU_ALLOC(f1apMsg->choice.initiatingMessage, sizeof(InitiatingMessage_t));
15933       if(f1apMsg->choice.initiatingMessage == NULLP)
15934       {
15935          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for\
15936          initiatingMessage");   
15937          break;
15938       }
15939       f1apMsg->choice.initiatingMessage->procedureCode = ProcedureCode_id_UEContextReleaseRequest;
15940       f1apMsg->choice.initiatingMessage->criticality = Criticality_reject;
15941       f1apMsg->choice.initiatingMessage->value.present = \
15942       InitiatingMessage__value_PR_UEContextReleaseRequest;
15943
15944       ueReleaseReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseRequest;
15945
15946       elementCnt = 2;
15947
15948       ueReleaseReq->protocolIEs.list.count = elementCnt;
15949       ueReleaseReq->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseRequest_t *);
15950
15951       /* Initialize the F1Setup members */
15952       DU_ALLOC(ueReleaseReq->protocolIEs.list.array,ueReleaseReq->protocolIEs.list.size);
15953       if(ueReleaseReq->protocolIEs.list.array == NULLP)
15954       {
15955          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE array");
15956          break;
15957       }
15958       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
15959       {
15960          DU_ALLOC(ueReleaseReq->protocolIEs.list.array[ieIdx],\
15961                sizeof(UEContextReleaseRequest_t));
15962          if(ueReleaseReq->protocolIEs.list.array[ieIdx] == NULLP)
15963          {
15964             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): Memory allocation failed for IE elements");
15965             memAllocFail = true;  
15966             break;
15967          }
15968       }
15969       if(memAllocFail == true)
15970          break;
15971
15972       /* Fetching Ue Cb Info*/
15973       GET_CELL_IDX(cellId, cellIdx);
15974       if(duCb.actvCellLst[cellIdx] == NULLP)
15975       {
15976          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): CellId[%d] does not exist", cellId);
15977          break;
15978       }
15979       else
15980       {
15981          GET_CRNTI(crnti, ueId);
15982          if(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].crnti != crnti)
15983          {
15984             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseReq(): crnti[%d] does not exist", crnti);
15985             break;
15986          }
15987          gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
15988          gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
15989       }
15990
15991       ieIdx=0; 
15992       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID; 
15993       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
15994       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present = \
15995       UEContextReleaseRequestIEs__value_PR_GNB_CU_UE_F1AP_ID;
15996       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
15997       
15998       ieIdx++;
15999       ueReleaseReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16000       ueReleaseReq->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16001       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.present =\
16002       UEContextReleaseRequestIEs__value_PR_GNB_DU_UE_F1AP_ID;
16003       ueReleaseReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
16004       
16005       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16006
16007       /* Encode the F1SetupRequest type as APER */
16008       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16009       encBufSize = 0;
16010       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
16011       /* Encode results */
16012       if(encRetVal.encoded == ENCODE_FAIL)
16013       {
16014          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseRequest structure (at %s)\n",\
16015                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16016          break;
16017       }
16018       else
16019       {
16020          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseRequest\n");
16021          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
16022          {
16023             printf("%x",encBuf[ieIdx]);
16024          }
16025       }
16026
16027       /* Sending msg */
16028       if(sendF1APMsg() != ROK)
16029       {
16030          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Request failed");
16031          break;
16032       }
16033       ret = ROK;
16034       break;
16035    }while(true);
16036
16037    FreeUeContextReleaseReq(f1apMsg);
16038    return ret;
16039 }
16040 /*****************************************************************i
16041  *
16042  * @brief Free memory allocated for UE Context Release Complete
16043  *
16044  * @details
16045  *
16046  *    Function : FreeUeContextReleaseComplete
16047  *
16048  *    Functionality:
16049  *         - Free memory allocated for UE Context Release Complete
16050  *
16051  * @params[in] F1AP_PDU_t *f1apMsg
16052  * @return void
16053  *
16054  * *************************************************************/
16055 void FreeUeContextReleaseComplete(F1AP_PDU_t *f1apMsg)
16056 {
16057    uint8_t ieIdx;
16058    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
16059
16060    if(f1apMsg)
16061    {
16062       if(f1apMsg->choice.successfulOutcome)
16063       {
16064          ueReleaseComplete =&f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
16065          if(ueReleaseComplete->protocolIEs.list.array)
16066          {
16067             for(ieIdx=0 ; ieIdx<ueReleaseComplete->protocolIEs.list.count; ieIdx++)
16068             {
16069                DU_FREE(ueReleaseComplete->protocolIEs.list.array[ieIdx], sizeof(UEContextReleaseComplete_t));
16070             }
16071             DU_FREE(ueReleaseComplete->protocolIEs.list.array, ueReleaseComplete->protocolIEs.list.size);
16072          }
16073          DU_FREE(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16074       }
16075       DU_FREE(f1apMsg, sizeof(F1AP_PDU_t));
16076    }
16077
16078 }
16079 /*****************************************************************i
16080  *
16081  * @brief Build and Send UE Context Release Complete
16082  *
16083  * @details
16084  *
16085  *    Function : BuildAndSendUeContextReleaseComplete
16086  *
16087  *    Functionality:
16088  *         - Build and Send UE Context Release Complete
16089  *
16090  * @params[in]  cellId,  gnbCuUeF1apId, gnbDuUeF1apId
16091  * @return ROK     - success
16092  *         RFAILED - failure
16093  *
16094  * *************************************************************/
16095 uint8_t BuildAndSendUeContextReleaseComplete(uint16_t cellId, uint32_t gnbCuUeF1apId, uint32_t gnbDuUeF1apId)
16096 {
16097    bool memAllocFail = false;
16098    uint8_t ieIdx =0, ret = RFAILED, elementCnt = 0;
16099    asn_enc_rval_t encRetVal;
16100    F1AP_PDU_t *f1apMsg = NULLP;
16101    UEContextReleaseComplete_t *ueReleaseComplete = NULLP;
16102
16103    DU_LOG("\nINFO  --> Building the UE Context Release Complete");
16104    do
16105    {
16106       DU_ALLOC(f1apMsg, sizeof(F1AP_PDU_t));
16107       if(f1apMsg == NULLP)
16108       {
16109          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for f1apMsg");
16110          break;
16111       }
16112
16113       f1apMsg->present = F1AP_PDU_PR_successfulOutcome;
16114       DU_ALLOC(f1apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcome_t));
16115       if(f1apMsg->choice.successfulOutcome == NULLP)
16116       {
16117          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for\
16118                successfulOutcome");
16119          break;
16120       }
16121       f1apMsg->choice.successfulOutcome->procedureCode = ProcedureCode_id_UEContextRelease;
16122       f1apMsg->choice.successfulOutcome->criticality = Criticality_reject;
16123       f1apMsg->choice.successfulOutcome->value.present = \
16124       SuccessfulOutcome__value_PR_UEContextReleaseComplete;
16125
16126       ueReleaseComplete = &f1apMsg->choice.successfulOutcome->value.choice.UEContextReleaseComplete;
16127
16128       elementCnt = 2;
16129       ueReleaseComplete->protocolIEs.list.count = elementCnt;
16130       ueReleaseComplete->protocolIEs.list.size = elementCnt * sizeof(UEContextReleaseComplete_t *);
16131
16132       /* Initialize the UE Release Complete members */
16133       DU_ALLOC(ueReleaseComplete->protocolIEs.list.array,ueReleaseComplete->protocolIEs.list.size);
16134       if(ueReleaseComplete->protocolIEs.list.array == NULLP)
16135       {
16136          DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE array");
16137          break;
16138       }
16139       for(ieIdx=0; ieIdx<elementCnt; ieIdx++)
16140       {
16141          DU_ALLOC(ueReleaseComplete->protocolIEs.list.array[ieIdx],\
16142                sizeof(UEContextReleaseComplete_t));
16143          if(ueReleaseComplete->protocolIEs.list.array[ieIdx] == NULLP)
16144          {
16145             DU_LOG("\nERROR  -->  F1AP : BuildAndSendUeContextReleaseComplete(): Memory allocation failed for IE\
16146             elements");
16147             memAllocFail = true;
16148             break;
16149          }
16150       }
16151       if(memAllocFail == true)
16152          break;
16153
16154
16155       ieIdx=0;
16156       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
16157       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16158       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present = \
16159       UEContextReleaseCompleteIEs__value_PR_GNB_CU_UE_F1AP_ID;
16160       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID =gnbCuUeF1apId;
16161
16162       ieIdx++;
16163       ueReleaseComplete->protocolIEs.list.array[ieIdx]->id = ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
16164       ueReleaseComplete->protocolIEs.list.array[ieIdx]->criticality= Criticality_reject;
16165       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.present =\
16166       UEContextReleaseCompleteIEs__value_PR_GNB_DU_UE_F1AP_ID;
16167       ueReleaseComplete->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID =gnbDuUeF1apId;
16168
16169       xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16170
16171       /* Encode the F1SetupComplete type as APER */
16172       memset(encBuf, 0, ENC_BUF_MAX_LEN);
16173       encBufSize = 0;
16174       encRetVal = aper_encode(&asn_DEF_F1AP_PDU, 0, f1apMsg, PrepFinalEncBuf, encBuf);
16175       /* Encode results */
16176       if(encRetVal.encoded == ENCODE_FAIL)
16177       {
16178          DU_LOG("\nERROR  -->  F1AP : Could not encode UEContextReleaseComplete structure (at %s)\n",\
16179                encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
16180          break;
16181       }
16182       else
16183       {
16184          DU_LOG("\nDEBUG   -->  F1AP : Created APER encoded buffer for UEContextReleaseComplete\n");
16185          for(ieIdx=0; ieIdx< encBufSize; ieIdx++)
16186          {
16187             printf("%x",encBuf[ieIdx]);
16188          }
16189       }
16190
16191       /* Sending msg */
16192       if(sendF1APMsg() != ROK)
16193       {
16194          DU_LOG("\nERROR  -->  F1AP : Sending UE Context Release Complete failed");
16195          break;
16196       }
16197       ret = ROK;
16198       break;
16199    }while(true);
16200    
16201    if((ret == ROK) && (duCb.actvCellLst[cellId-1]) && (duCb.actvCellLst[cellId-1]->cellStatus == DELETION_IN_PROGRESS) 
16202          && (duCb.actvCellLst[cellId-1]->numActvUes == 0))
16203    {
16204       ret = duSendCellDeletReq(cellId);
16205       if(ret != ROK)
16206       {
16207          DU_LOG("\nERROR  -->  F1AP: BuildAndSendUeContextReleaseComplete(): Failed to process cell\
16208                Delete req for CellId");
16209       }
16210    }
16211    FreeUeContextReleaseComplete(f1apMsg);
16212    return ret;
16213
16214 }
16215
16216 /*******************************************************************
16217 *
16218 * @brief added free part for the memory allocated by aper_decoder 
16219 *
16220 * @details
16221 *
16222 *    Function : freeAperDecodeUeContextReleaseCommand 
16223 *
16224 *    Functionality: added free part for the memory allocated by aper_decoder
16225 *
16226 * @params[in] F1AP_PDU_t *f1apMsg
16227 * @return void
16228 *
16229 * ****************************************************************/
16230 void freeAperDecodeUeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
16231 {
16232    uint8_t ieIdx=0;
16233    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
16234
16235    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
16236    
16237    if(ueContextReleaseCommand->protocolIEs.list.array)
16238    {
16239       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
16240       {
16241          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
16242          {
16243             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
16244             {
16245                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16246                   break;
16247                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16248                   break;
16249                case ProtocolIE_ID_id_Cause:
16250                   break;
16251                case ProtocolIE_ID_id_RRCContainer:
16252                {
16253                   if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf)
16254                   {
16255                      free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf);
16256                   }
16257                   break;
16258                }
16259                default :
16260                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
16261                        ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
16262                   break;
16263             }
16264          }
16265          free(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]);
16266       }
16267       free(ueContextReleaseCommand->protocolIEs.list.array);
16268    }
16269 }
16270 /*******************************************************************
16271 *
16272 * @brief processing of UE Context Release Command
16273 *
16274 * @details
16275 *
16276 *    Function : procF1UeContextReleaseCommand 
16277 *
16278 *    Functionality: processing of UE Context Release Command
16279 *
16280 * @params[in] F1AP_PDU_t *f1apMsg
16281 * @return void
16282 *
16283 * ****************************************************************/
16284 uint8_t procF1UeContextReleaseCommand(F1AP_PDU_t *f1apMsg)
16285 {
16286    uint8_t  ieIdx=0, ret=ROK, ueIdx=0;
16287    uint16_t cellIdx =0, cellId = 0;
16288    bool ueIdxFound = false;
16289    uint32_t gnbCuUeF1apId=0, gnbDuUeF1apId=0;
16290    DuUeCb   *duUeCb = NULLP;
16291    UEContextReleaseCommand_t *ueContextReleaseCommand = NULLP;
16292
16293    ueContextReleaseCommand = &f1apMsg->choice.initiatingMessage->value.choice.UEContextReleaseCommand;
16294
16295    if(ueContextReleaseCommand->protocolIEs.list.array)
16296    {
16297       for(ieIdx=0; ieIdx < ueContextReleaseCommand->protocolIEs.list.count; ieIdx++)
16298       {
16299          if(ueContextReleaseCommand->protocolIEs.list.array[ieIdx])
16300          {
16301             switch(ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id)
16302             {
16303                case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
16304                   {
16305                      gnbCuUeF1apId= ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
16306                                     value.choice.GNB_CU_UE_F1AP_ID;
16307                      break;
16308                   }
16309
16310                case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
16311                   {
16312                      gnbDuUeF1apId = ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
16313                                      value.choice.GNB_DU_UE_F1AP_ID;
16314                      break;
16315                   }
16316
16317                case ProtocolIE_ID_id_Cause:
16318                   {
16319                      for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
16320                      {
16321                         for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
16322                         {
16323                            if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId)&&\
16324                                  (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId))
16325                            {
16326                               cellId = duCb.actvCellLst[cellIdx]->cellId;
16327                               duUeCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
16328                               ueIdxFound = true;
16329                               break;
16330                            }
16331                         }
16332                         if(ueIdxFound == true)
16333                         {
16334                            break;
16335                         }
16336                      }
16337                      
16338                      if(!ueIdxFound)
16339                      {
16340                         DU_LOG("\nERROR  -->  F1AP: procF1UeContextReleaseCommand(): Ue Information is not available");
16341                         ret = RFAILED;
16342                      }
16343                      break;
16344                   }
16345
16346                case ProtocolIE_ID_id_RRCContainer:
16347                   {
16348                      if(ueIdxFound == true)  
16349                      {
16350                         DU_ALLOC(duUeCb->f1UeDb, sizeof(F1UeContextSetupDb));
16351                         if(duUeCb->f1UeDb)
16352                         {
16353                            memset(duUeCb->f1UeDb, 0, sizeof(F1UeContextSetupDb));
16354                            duUeCb->f1UeDb->actionType = UE_CTXT_RELEASE;
16355                            duUeCb->f1UeDb->cellIdx = cellIdx;
16356                            /* Filling Dl RRC Msg Info */
16357                            DU_ALLOC_SHRABL_BUF(duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
16358                            if(!duUeCb->f1UeDb->dlRrcMsg)
16359                            {
16360                               DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16361                                     Memory allocation failed ");
16362                               ret = RFAILED;
16363                            }
16364                            else
16365                            {
16366                               duUeCb->f1UeDb->dlRrcMsgPres = true;
16367                               memset(duUeCb->f1UeDb->dlRrcMsg, 0, sizeof(F1DlRrcMsg));
16368                               ret = extractDlRrcMsg(gnbDuUeF1apId, gnbCuUeF1apId, duUeCb->f1UeDb->dlRrcMsg,\
16369                                     &ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->\
16370                                     value.choice.RRCContainer);
16371                            }
16372
16373                         }
16374                         else
16375                         {
16376                            DU_LOG("\nERROR  -->  DU APP : procF1UeContextReleaseCommand(): \
16377                                  Memory allocation failed ");
16378                            ret = RFAILED;
16379
16380                         }
16381                      }
16382                      break;
16383                   }
16384                default :
16385                   DU_LOG("\nERROR  -->  F1AP: freeAperDecodeUeContextReleaseCommand():Invalid IE Received: %ld"\
16386                         ,ueContextReleaseCommand->protocolIEs.list.array[ieIdx]->id);
16387                   break;
16388             }
16389          }
16390       }
16391    }
16392    if(ret != RFAILED)
16393    {
16394       duProcUeContextReleaseCommand(cellId, duUeCb);
16395    }
16396    freeAperDecodeUeContextReleaseCommand(f1apMsg);
16397    return ret;
16398 }
16399
16400 /**************************************************************
16401  *
16402  * @brief free the memory allocated by aper decoder for paging
16403  *
16404  * @details
16405  *
16406  *    Function : freeAperDecodePagingMsg
16407  *
16408  *    Functionality:
16409  *         - free the memory allocated by aper decoder for
16410  *         the paging f1ap msg
16411  *
16412  * @params[in] Paging_t   *paging
16413  * @return ROK     - success
16414  *         RFAILED - failure
16415  *
16416  ****************************************************************/
16417 void freeAperDecodePagingMsg(Paging_t   *paging)
16418 {
16419    uint8_t ieIdx, cellIdx;
16420    PagingCell_ItemIEs_t *pagingCellItemIes;
16421    PagingCell_Item_t *pagingCellItem;
16422    PagingCell_list_t  *pagingCelllist;
16423
16424    if(paging)
16425    {
16426       if(paging->protocolIEs.list.array)
16427       {
16428          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
16429          {
16430             if(paging->protocolIEs.list.array[ieIdx])
16431             {
16432                switch(paging->protocolIEs.list.array[ieIdx]->id)
16433                {
16434                   case ProtocolIE_ID_id_UEIdentityIndexValue:
16435                      {
16436                         free(paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10.buf);
16437                         break;
16438                      }
16439                   case ProtocolIE_ID_id_PagingIdentity:
16440                      {
16441                         if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present == PagingIdentity_PR_cNUEPagingIdentity)
16442                         {
16443                            if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)
16444                            {
16445                               if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->present == \
16446                                     CNUEPagingIdentity_PR_fiveG_S_TMSI)
16447                               {
16448                                  free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity->choice.fiveG_S_TMSI.buf);
16449                               }
16450                               free(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity);
16451                            }
16452                         }
16453                         break;
16454                      }
16455                   case ProtocolIE_ID_id_PagingCell_List:
16456                      {
16457                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list;
16458                         if(pagingCelllist->list.array)
16459                         {
16460                            for(cellIdx = 0; cellIdx < pagingCelllist->list.count; cellIdx++)
16461                            {
16462                               if(pagingCelllist->list.array[cellIdx])
16463                               {
16464                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellIdx];
16465                                  if(pagingCellItemIes->id == ProtocolIE_ID_id_PagingCell_Item)
16466                                  {
16467                                     pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
16468                                     free(pagingCellItem->nRCGI.pLMN_Identity.buf);
16469                                     free(pagingCellItem->nRCGI.nRCellIdentity.buf);
16470                                  }
16471                                  free(pagingCelllist->list.array[cellIdx]);
16472                               }
16473                            }
16474                            free(pagingCelllist->list.array);
16475                         }
16476                         break;
16477                      }
16478                }
16479                free(paging->protocolIEs.list.array[ieIdx]);
16480             }
16481          }
16482          free(paging->protocolIEs.list.array);
16483
16484       }
16485    }
16486 }
16487
16488 /**************************************************************
16489  *
16490  * @brief processing the paging f1ap msg received from CU 
16491  *
16492  * @details
16493  *
16494  *    Function : procPagingMsg
16495  *
16496  *    Functionality:
16497  *         - processing the paging f1ap msg received from CU
16498  *
16499  * @params[in] F1AP_PDU_t *f1apMsg
16500  * @return ROK     - success
16501  *         RFAILED - failure
16502  *
16503  *
16504  ****************************************************************/
16505 uint8_t procPagingMsg(F1AP_PDU_t *f1apMsg) 
16506 {
16507    uint8_t ieIdx = 0, cellListIdx = 0;
16508    uint16_t cellId = 0;
16509    Paging_t   *paging = NULLP;
16510    PagingCell_list_t  *pagingCelllist = NULLP;
16511    PagingCell_ItemIEs_t *pagingCellItemIes = NULLP;
16512    PagingCell_Item_t *pagingCellItem = NULLP;
16513    DuPagingMsg *tmpPagingParam = NULLP;
16514
16515    DU_LOG("\nINFO  --> DU APP : Processing the Paging Message");
16516    paging = &f1apMsg->choice.initiatingMessage->value.choice.Paging;
16517    if(paging)
16518    {
16519       if(paging->protocolIEs.list.array)
16520       {
16521          DU_ALLOC(tmpPagingParam, sizeof(DuPagingMsg));
16522          if(tmpPagingParam == NULLP)
16523          {
16524             DU_LOG("\nERROR  --> DU APP : Memory Allocation Failure in procPagingMsg");
16525             freeAperDecodePagingMsg(paging);
16526             return RFAILED;
16527          }
16528          for(ieIdx=0 ; ieIdx<paging->protocolIEs.list.count; ieIdx++)
16529          {
16530             if(paging->protocolIEs.list.array[ieIdx])
16531             {
16532                switch(paging->protocolIEs.list.array[ieIdx]->id)
16533                {
16534                   case ProtocolIE_ID_id_UEIdentityIndexValue:
16535                      {
16536                         bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.UEIdentityIndexValue.choice.indexLength10,\
16537                                          &tmpPagingParam->pagUeId);
16538                         break;
16539                      }
16540
16541                   case ProtocolIE_ID_id_PagingIdentity:
16542                      {
16543                         switch(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.present)
16544                         {
16545                            case PagingIdentity_PR_cNUEPagingIdentity: 
16546                               {
16547                                  if(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.cNUEPagingIdentity)  
16548                                  {
16549                                     bitStringToInt(&paging->protocolIEs.list.array[ieIdx]->value.choice.PagingIdentity.choice.\
16550                                           cNUEPagingIdentity->choice.fiveG_S_TMSI, &tmpPagingParam->sTmsi);
16551
16552                                  }
16553                                  break;
16554                               }
16555                             case PagingIdentity_PR_rANUEPagingIdentity:
16556                                {
16557                                   /*TODO: This Identifier is specific to RAN Initiated Paging â€“ Connected Mode Paging*/
16558                                   break;
16559                                }
16560                             default:
16561                                {
16562                                   DU_LOG("ERROR  -->  DU APP: Invalid UE Paging Identity, Skipping this Paging Message:");
16563                                   continue;
16564                                }
16565                         }
16566                      }
16567
16568                   case ProtocolIE_ID_id_PagingDRX:
16569                      {
16570                         tmpPagingParam->pagingDrxPres = TRUE;
16571                         tmpPagingParam->pagingDrx = convertPagingCycleEnumToValue(paging->protocolIEs.list.array[ieIdx]->value.choice.PagingDRX);
16572                         break;
16573                      }
16574
16575                   case ProtocolIE_ID_id_PagingPriority:
16576                      {
16577                         tmpPagingParam->pagPriority = paging->protocolIEs.list.array[ieIdx]->value.choice.PagingPriority;
16578                         break;
16579                      }
16580
16581                   case ProtocolIE_ID_id_PagingCell_List:
16582                      {
16583                         pagingCelllist = &paging->protocolIEs.list.array[ieIdx]->value.choice.PagingCell_list; 
16584                         if(pagingCelllist->list.array)
16585                         {
16586                            for(cellListIdx = 0; cellListIdx < pagingCelllist->list.count; cellListIdx++)
16587                            {
16588                               if(pagingCelllist->list.array[cellListIdx])
16589                               {
16590                                  pagingCellItemIes = (PagingCell_ItemIEs_t *)pagingCelllist->list.array[cellListIdx];
16591                                  pagingCellItem = &pagingCellItemIes->value.choice.PagingCell_Item;
16592                                  bitStringToInt(&pagingCellItem->nRCGI.nRCellIdentity, &cellId);
16593                                  if(processPagingMsg(cellId, tmpPagingParam) != ROK)
16594                                  {
16595                                     DU_LOG("\nERROR  --> DU APP : Paging Processing Failed at CellId:%d",cellId);
16596                                     continue;
16597                                  }
16598                               }
16599                            }
16600                         }
16601                         break;
16602                      }
16603                    default:
16604                      {
16605                          DU_LOG("\nERROR  --> F1AP : Incorrect Paging IE option");
16606                          break;
16607                      }
16608                }
16609             }
16610          }
16611       }
16612    }
16613    DU_FREE(tmpPagingParam, sizeof(DuPagingMsg));
16614    freeAperDecodePagingMsg(paging);
16615   
16616    return ROK;
16617 }
16618
16619 /**************************************************************
16620  *
16621  * @brief Handles received F1AP message and sends back response  
16622  *
16623  * @details
16624  *
16625  *    Function : F1APMsgHdlr
16626  *
16627  *    Functionality:
16628  *         - Decodes received F1AP control message
16629  *         - Prepares response message, encodes and sends to SCTP
16630  *
16631  * @params[in] 
16632  * @return ROK     - success
16633  *         RFAILED - failure
16634  *
16635  * ****************************************************************/
16636 void F1APMsgHdlr(Buffer *mBuf)
16637 {
16638    int i =0;
16639    char *recvBuf =NULLP;
16640    MsgLen copyCnt =0;
16641    MsgLen recvBufLen =0;
16642    F1AP_PDU_t *f1apMsg =NULLP;
16643    asn_dec_rval_t rval; /* Decoder return value */
16644    F1AP_PDU_t f1apasnmsg ;
16645    DU_LOG("\nINFO  -->  F1AP : Received F1AP message buffer");
16646    ODU_PRINT_MSG(mBuf, 0,0);
16647
16648    /* Copy mBuf into char array to decode it */
16649    ODU_GET_MSG_LEN(mBuf, &recvBufLen);
16650    DU_ALLOC(recvBuf, (Size)recvBufLen);
16651
16652    if(recvBuf == NULLP)
16653    {
16654       DU_LOG("\nERROR  -->  F1AP : Memory allocation failed");
16655       return;
16656    }
16657    if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, &copyCnt) != ROK)
16658    {
16659       DU_LOG("\nERROR   -->  F1AP : Failed while copying %d", copyCnt);
16660       return;
16661    }
16662
16663    printf("\nDEBUG   -->  F1AP : Received flat buffer to be decoded : ");
16664    for(i=0; i< recvBufLen; i++)
16665    {
16666       printf("%x",recvBuf[i]);
16667    }
16668
16669    /* Decoding flat buffer into F1AP messsage */
16670    f1apMsg = &f1apasnmsg;
16671    memset(f1apMsg, 0, sizeof(F1AP_PDU_t));
16672
16673    rval = aper_decode(0, &asn_DEF_F1AP_PDU, (void **)&f1apMsg, recvBuf, recvBufLen, 0, 0);
16674
16675    if(rval.code == RC_FAIL || rval.code == RC_WMORE)
16676    {
16677       DU_LOG("\nERROR  -->  F1AP : ASN decode failed");
16678       return;
16679    }
16680    printf("\n");
16681    xer_fprint(stdout, &asn_DEF_F1AP_PDU, f1apMsg);
16682
16683    switch(f1apMsg->present)
16684    {
16685       case F1AP_PDU_PR_successfulOutcome:
16686          {
16687             switch(f1apMsg->choice.successfulOutcome->value.present)
16688             {
16689                case SuccessfulOutcome__value_PR_ResetAcknowledge:
16690                   {
16691                      DU_LOG("\nINFO   -->  F1AP : F1ResetAcknowledge is received successfully ");
16692                      break;
16693                   }
16694                case SuccessfulOutcome__value_PR_F1SetupResponse:
16695                   {                             
16696 #ifndef ODU_TEST_STUB
16697                      procF1SetupRsp(f1apMsg, recvBufLen, recvBuf);
16698 #endif
16699                      break;
16700                   }
16701
16702                case SuccessfulOutcome__value_PR_GNBDUConfigurationUpdateAcknowledge:
16703                   {
16704                      procF1GNBDUCfgUpdAck(f1apMsg);
16705                      break;
16706                   }
16707
16708                default:
16709                   {
16710                      DU_LOG("\nERROR  -->  F1AP : Invalid type of SuccessfulOutcome__value_PR_ResetAcknowledge [%d]",\
16711                            f1apMsg->choice.successfulOutcome->value.present);
16712                      return;
16713                   }
16714             }/* End of switch(successfulOutcome) */
16715             free(f1apMsg->choice.successfulOutcome);
16716             break;
16717          }
16718       case F1AP_PDU_PR_initiatingMessage:
16719          {
16720             switch(f1apMsg->choice.initiatingMessage->value.present)
16721             {
16722                case InitiatingMessage__value_PR_Reset:
16723                   {
16724                      procF1ResetReq(f1apMsg);
16725                      break;
16726                   }
16727                case InitiatingMessage__value_PR_DLRRCMessageTransfer:
16728                   {
16729                      procF1DlRrcMsgTrans(f1apMsg);
16730                      break;
16731                   }
16732                case InitiatingMessage__value_PR_UEContextSetupRequest:
16733                   {
16734                      procF1UeContextSetupReq(f1apMsg);
16735                      break;
16736                   }
16737                case InitiatingMessage__value_PR_UEContextModificationRequest:
16738                   {
16739                      procF1UeContextModificationReq(f1apMsg);
16740                      break;
16741                   }
16742                case InitiatingMessage__value_PR_UEContextReleaseCommand:
16743                   {
16744                       procF1UeContextReleaseCommand(f1apMsg);
16745                       break;
16746                   }
16747                case InitiatingMessage__value_PR_Paging:
16748                   {
16749                      procPagingMsg(f1apMsg);
16750                      break;
16751                   }
16752                default:
16753                   {
16754                      DU_LOG("\nERROR  -->  F1AP : Invalid type of F1AP_PDU_PR_initiatingMessage [%d]",
16755                            f1apMsg->choice.initiatingMessage->value.present);
16756                      return;
16757                   }
16758             }/* End of switch(initiatingMessage) */
16759             free(f1apMsg->choice.initiatingMessage);
16760             break;
16761          }
16762
16763       default:
16764          {
16765             DU_LOG("\nERROR  -->  F1AP : Invalid type of f1apMsg->present [%d]",f1apMsg->present);
16766             return;
16767          }
16768          free(f1apMsg);
16769
16770    }/* End of switch(f1apMsg->present) */
16771    
16772    DU_FREE(recvBuf, (Size)recvBufLen);
16773 } /* End of F1APMsgHdlr */
16774
16775 /**********************************************************************
16776   End of file
16777  **********************************************************************/