Release image for e-release yaml
[o-du/l2.git] / src / du_app / du_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 message handling functionality for DU APP */
20 #include "common_def.h"
21 #include "lrg.h"
22 #include "legtp.h"
23 #include "lkw.h"
24 #include "kwu.h"
25 #include "lrg.x"
26 #include "lkw.x"
27 #include "kwu.x"
28 #include "du_app_mac_inf.h"
29 #include "du_app_rlc_inf.h"
30 #include "du_cfg.h"
31 #include "du_app_rlc_inf.h"
32 #include "du_mgr.h"
33 #include "du_sctp.h"
34 #include "F1AP-PDU.h"
35 #include "du_f1ap_msg_hdl.h"
36 #include "du_ue_mgr.h"
37 #include "lsctp.h"
38 #include "legtp.h"
39 #include "du_utils.h"
40 #include "du_cell_mgr.h" 
41
42 #ifdef O1_ENABLE
43
44 #include "AlarmInterface.h"
45 #include "CmInterface.h"
46 #include "PmInterface.h"
47
48 #endif 
49
50 uint8_t rlcDlCfg = 0;
51 uint8_t numRlcDlSaps = 0;
52 uint8_t rlcUlCfg = 0;
53 uint8_t numRlcMacSaps = 0;
54 uint8_t macCfg = 0;
55 uint8_t macCfgInst = 0;
56
57 DuCfgParams duCfgParam;
58 uint8_t packRlcConfigReq(Pst *pst, RlcMngmt *cfg);
59 uint8_t cmPkLkwCntrlReq(Pst *pst, RlcMngmt *cfg);
60 uint8_t cmPkLrgCfgReq(Pst *pst, RgMngmt *cfg);
61 uint8_t BuildAndSendE2SetupReq();
62 uint8_t egtpHdlDatInd(EgtpMsg egtpMsg);
63 uint8_t BuildAndSendDUConfigUpdate();
64 uint16_t getTransId();
65 uint8_t cmPkLrgSchCfgReq(Pst * pst,RgMngmt * cfg);
66 uint8_t sendCellDeleteReqToMac(uint16_t cellId);
67
68 packMacCellCfgReq packMacCellCfgOpts[] =
69 {
70    packMacCellCfg, /* packing for loosely coupled */
71    MacProcCellCfgReq, /* packing for tightly coupled */
72    packMacCellCfg, /* packing for light weight loosly coupled */
73 };
74
75 DuMacCellStart packMacCellStartOpts[] =
76 {
77    packMacCellStart,   /* Loose coupling */
78    MacProcCellStart,   /* TIght coupling */
79    packMacCellStart    /* Light weight-loose coupling */
80 };
81
82 DuMacCellStop packMacCellStopOpts[] =
83 {
84    packMacCellStop,   /* Loose coupling */
85    MacProcCellStop,   /* TIght coupling */
86    packMacCellStop    /* Light weight-loose coupling */
87 };
88
89 DuMacSliceCfgReq packMacSliceCfgReqOpts[] =
90 {
91    packDuMacSliceCfgReq,       /* Loose coupling */
92    MacProcSliceCfgReq,         /* TIght coupling */
93    packDuMacSliceCfgReq        /* Light weight-loose coupling */
94 };
95
96
97 DuMacSliceRecfgReq packMacSliceReCfgReqOpts[] =
98 {
99    packDuMacSliceRecfgReq,       /* Loose coupling */
100    MacProcSliceReCfgReq,         /* TIght coupling */
101    packDuMacSliceRecfgReq        /* Light weight-loose coupling */
102 };
103 /**************************************************************************
104  * @brief Function to fill configs required by RLC
105  *
106  * @details
107  *
108  *      Function : duBuildRlcCfg 
109  * 
110  *      Functionality:
111  *           Initiates general Configs towards RLC 
112  *     
113  * @param[in] Inst  Specifies if RLC UL or RLC DL instance 
114  * @return ROK     - success
115  *         RFAILED - failure
116  *
117  ***************************************************************************/
118 uint8_t duBuildRlcCfg(Inst inst)
119 {
120    RlcMngmt   rlcMngmt;
121    RlcGenCfg  *genCfg = NULLP;
122    Pst pst;
123
124    DU_SET_ZERO(&rlcMngmt, sizeof(RlcMngmt));
125    DU_SET_ZERO(&pst, sizeof(Pst));
126
127    genCfg   = &(rlcMngmt.t.cfg.s.gen);
128
129    /*----------- Fill General Configuration Parameters ---------*/
130    genCfg->maxUe       = duCfgParam.maxUe;
131    genCfg->maxKwuSaps  = 2;
132    genCfg->maxUdxSaps  = 1; 
133    genCfg->rlcMode     = (inst == RLC_UL_INST) ?
134       LKW_RLC_MODE_UL : LKW_RLC_MODE_DL;
135    genCfg->timeRes     = 1; 
136    genCfg->maxRguSaps  = DEFAULT_CELLS;
137
138    /*----------- Fill lmPst
139     * Parameters ---------*/
140    genCfg->lmPst.dstProcId = DU_PROC;
141    genCfg->lmPst.srcProcId = DU_PROC;
142    genCfg->lmPst.dstEnt    = ENTDUAPP;
143    genCfg->lmPst.dstInst   = DU_INST;
144    genCfg->lmPst.srcEnt    = ENTRLC;
145    genCfg->lmPst.srcInst   = inst;
146    genCfg->lmPst.prior     = PRIOR0;
147    genCfg->lmPst.route     = RTESPEC;
148    genCfg->lmPst.region    = (inst == RLC_UL_INST) ?
149       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
150    genCfg->lmPst.pool      = RLC_POOL;
151    genCfg->lmPst.selector  = ODU_SELECTOR_LC;
152
153    /* Fill Header */
154    rlcMngmt.hdr.msgType             = TCFG;
155    rlcMngmt.hdr.msgLen              = 0;
156    rlcMngmt.hdr.entId.ent           = ENTRLC;
157    rlcMngmt.hdr.entId.inst          = (Inst)0;
158    rlcMngmt.hdr.elmId.elmnt         = STGEN;
159    rlcMngmt.hdr.seqNmb              = 0;
160    rlcMngmt.hdr.version             = 0;
161    rlcMngmt.hdr.transId             = 0;
162    rlcMngmt.hdr.response.prior      = PRIOR0;
163    rlcMngmt.hdr.response.route      = RTESPEC;
164    rlcMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
165       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
166    rlcMngmt.hdr.response.mem.pool   = DU_POOL;
167    rlcMngmt.hdr.response.selector   = ODU_SELECTOR_LC;
168
169    /* Fill Pst */
170    pst.selector  = ODU_SELECTOR_LC;
171    pst.srcEnt    = ENTDUAPP;
172    pst.dstEnt    = ENTRLC;
173    pst.dstInst   = inst;
174    pst.dstProcId = DU_PROC;
175    pst.srcProcId = DU_PROC;
176    pst.region    = duCb.init.region;
177
178    DU_LOG("\nDEBUG   -->  DU_APP : RLC Gen Cfg Req sent for inst %d", inst);
179
180    /* Send the request to RLC */
181    packRlcConfigReq(&pst, &rlcMngmt);
182
183    return ROK;
184 }
185
186 /**************************************************************************
187  * @brief Function to fill configs required by RLC
188  *
189  * @details
190  *
191  *      Function : duBuildRlcLsapCfg 
192  * 
193  *      Functionality:
194  *           Initiates general Configs towards RLC 
195  *     
196  * @param[in] Inst  Specifies if RLC UL or RLC DL instance 
197  * @return ROK     - success
198  *         RFAILED - failure
199  *
200  ***************************************************************************/
201 uint8_t duBuildRlcLsapCfg(Ent ent, Inst inst, uint8_t lsapInst)
202 {
203
204    RlcMngmt   rlcMngmt;
205    RlcSapCfg  *lSap = NULLP;
206    Pst        pst;
207
208    DU_SET_ZERO(&rlcMngmt, sizeof(RlcMngmt));
209    DU_SET_ZERO(&pst, sizeof(Pst));
210
211    /* Fill Header */
212    rlcMngmt.hdr.msgType             = TCFG;
213    rlcMngmt.hdr.entId.ent           = ENTRLC;
214    rlcMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
215       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
216
217    rlcMngmt.hdr.response.mem.pool   = RLC_POOL;
218
219    /* Fill Pst */
220    pst.selector  = ODU_SELECTOR_LC;
221    pst.srcEnt    = ENTDUAPP;
222    pst.dstEnt    = ENTRLC;
223    pst.dstProcId = DU_PROC;
224    pst.dstInst   = inst;
225    pst.srcProcId = DU_PROC;
226    pst.region    = duCb.init.region;
227    lSap   = &(rlcMngmt.t.cfg.s.sap);
228
229    lSap->mem.region = (inst == RLC_UL_INST) ?
230       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
231    lSap->mem.pool    = RLC_POOL;
232    lSap->mem.spare   = 0;
233    lSap->bndTmrIntvl = 10;
234    lSap->priority    = PRIOR0;
235    lSap->route       = RTESPEC;
236    if (ent == ENTMAC)
237    {
238       lSap->procId      = DU_PROC;
239       lSap->ent         = ENTMAC;
240       lSap->inst        = lsapInst;
241       lSap->sapId       = lsapInst;      /* SapId will be stored as suId in MAC */
242       lSap->selector    = (inst == RLC_UL_INST) ? ODU_SELECTOR_LWLC : ODU_SELECTOR_TC;
243       rlcMngmt.hdr.elmId.elmnt  = STRGUSAP;
244       DU_LOG("\nDEBUG   -->  DU_APP : RLC MAC Lower Sap Cfg Req sent for inst %d", inst);
245
246    }
247    else
248    {
249       lSap->procId    = DU_PROC;
250       lSap->ent       = ENTRLC;
251       lSap->inst      = (inst == RLC_UL_INST) ?
252          RLC_DL_INST : RLC_UL_INST;
253       lSap->sapId       = 0;
254       lSap->selector = ODU_SELECTOR_LC;
255       rlcMngmt.hdr.elmId.elmnt  = STUDXSAP;
256       DU_LOG("\nDEBUG   -->  DU_APP : RLC DL/UL Lower Sap Cfg Req sent for inst %d", inst);
257    }
258
259    packRlcConfigReq(&pst, &rlcMngmt);
260    return ROK;
261 }
262
263 /**************************************************************************
264  * @brief Function to fill configs required by RLC
265  *
266  * @details
267  *
268  *      Function : duBuildRlcUsapCfg 
269  * 
270  *      Functionality:
271  *           Initiates general Configs towards RLC 
272  *     
273  * @param[in] Inst  Specifies if RLC UL or RLC DL instance 
274  * @return ROK     - success
275  *         RFAILED - failure
276  *
277  ***************************************************************************/
278 uint8_t duBuildRlcUsapCfg(uint8_t elemId, Ent ent, Inst inst)
279 {
280    RlcMngmt   rlcMngmt;
281    RlcSapCfg  *uSap = NULLP;
282    Pst        pst;
283
284    DU_SET_ZERO(&rlcMngmt, sizeof(RlcMngmt));
285    DU_SET_ZERO(&pst, sizeof(Pst));
286
287    uSap   = &(rlcMngmt.t.cfg.s.sap);
288
289    uSap->selector   = ODU_SELECTOR_LC;
290    uSap->mem.region = (inst == RLC_UL_INST) ?
291       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
292    uSap->mem.pool = RLC_POOL;
293    uSap->mem.spare = 0;
294
295    uSap->procId = DU_PROC;
296    uSap->ent = ENTRLC;
297    uSap->sapId = 0;
298
299    uSap->inst = (inst == RLC_UL_INST) ?
300       RLC_DL_INST : RLC_UL_INST;
301    uSap->bndTmrIntvl = 1000;
302    uSap->priority = PRIOR0;
303    uSap->route = RTESPEC;
304
305    /* Fill Header */
306    rlcMngmt.hdr.msgType             = TCFG;
307    rlcMngmt.hdr.entId.ent           = ENTRLC;
308    rlcMngmt.hdr.elmId.elmnt         = STUDXSAP;
309    rlcMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
310       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
311
312    rlcMngmt.hdr.response.mem.pool   = RLC_POOL;
313
314    /* Fill Pst */
315    pst.selector  = ODU_SELECTOR_LC;
316    pst.srcEnt    = ENTDUAPP;
317    pst.dstEnt    = ENTRLC;
318    pst.dstProcId = DU_PROC;
319    pst.dstInst = inst;
320    pst.srcProcId = DU_PROC;
321    pst.region = duCb.init.region;
322
323    DU_LOG("\nDEBUG   -->  DU_APP : RLC Kwu Upper Sap Cfg Req sent for inst %d", inst);
324    packRlcConfigReq(&pst, &rlcMngmt);
325
326    return ROK;
327 }
328
329 /**************************************************************************
330  * @brief Function to populate internal DS of DU APP
331  *
332  * @details
333  *
334  *      Function : duProcCfgComplete
335  * 
336  *      Functionality:
337  *           Populates internal data structures of DU APP after 
338  *           receiving configurations.
339  *     
340  * @param[in]  void
341  * @return ROK     - success
342  *         RFAILED - failure
343  *
344  ***************************************************************************/
345 uint8_t duProcCfgComplete()
346 {
347    uint8_t         ret = ROK;
348    uint16_t        cellId = 0;
349    uint16_t        idx;
350    for(idx=0; idx< DEFAULT_CELLS; idx++)
351    {
352       DuCellCb *cell = NULLP;
353       DU_ALLOC(cell, sizeof(DuCellCb));
354       if(cell == NULLP)
355       {
356          DU_LOG("\nERROR  -->  DU_APP : Memory Allocation failed in duProcCfgComplete");
357          ret = RFAILED;
358       }
359       else
360       {
361          uint8_t idx1=0; 
362          memset(cell, 0, sizeof(DuCellCb));
363          cell->cellId = ++cellId;
364          memset(&cell->cellInfo.nrEcgi.plmn, 0, sizeof(Plmn));
365          cell->cellInfo.nrEcgi.plmn.mcc[0] = PLMN_MCC0;
366          cell->cellInfo.nrEcgi.plmn.mcc[1] = PLMN_MCC1;
367          cell->cellInfo.nrEcgi.plmn.mcc[2] = PLMN_MCC2;
368          cell->cellInfo.nrEcgi.plmn.mnc[0] = PLMN_MNC0;
369          cell->cellInfo.nrEcgi.plmn.mnc[1] = PLMN_MNC1;
370          cell->cellInfo.nrEcgi.cellId = cell->cellId;
371          cell->cellInfo.nrPci = NR_PCI; 
372          cell->cellInfo.fiveGsTac = DU_TAC;
373          memset(&cell->cellInfo.plmn[idx1], 0, sizeof(Plmn));
374          for(idx1=0; idx1<MAX_PLMN; idx1++)
375          {
376             cell->cellInfo.plmn[idx1].mcc[0] = PLMN_MCC0;
377             cell->cellInfo.plmn[idx1].mcc[1] = PLMN_MCC1;
378             cell->cellInfo.plmn[idx1].mcc[2] = PLMN_MCC2;
379             cell->cellInfo.plmn[idx1].mnc[0] = PLMN_MNC0;
380             cell->cellInfo.plmn[idx1].mnc[1] = PLMN_MNC1;
381          }
382          cell->cellInfo.maxUe = duCfgParam.maxUe;
383          cell->cellStatus = CELL_OUT_OF_SERVICE;
384          gCellStatus = CELL_DOWN;
385          cell->gnbDuUeF1apIdGenerator = 0;
386          duCb.cfgCellLst[duCb.numCfgCells] = cell;
387          duCb.numCfgCells++;
388       }
389    }
390    if(ret != RFAILED)
391    {
392       //Start layer configs
393       ret = duSendRlcUlCfg();
394    }
395    return ret;
396 }
397 /**************************************************************************
398  * @brief Function to invoke DU Layer Configs
399  *
400  * @details
401  *
402  *      Function : duSendRlcUlCfg 
403  * 
404  *      Functionality:
405  *           Initiates Configs towards layers of DU
406  *     
407  * @param[in]  void
408  * @return ROK     - success
409  *         RFAILED - failure
410  *
411  ***************************************************************************/
412 uint8_t duSendRlcUlCfg()
413 {
414    uint8_t cellIdx; 
415
416    duBuildRlcCfg((Inst)RLC_UL_INST);
417    for(cellIdx = 0; cellIdx < DEFAULT_CELLS; cellIdx++)
418    {
419       duBuildRlcLsapCfg(ENTMAC, (Inst)RLC_UL_INST, cellIdx);
420    }
421    duBuildRlcLsapCfg(ENTRLC, (Inst)RLC_UL_INST, 0);
422
423    return ROK;
424 }
425
426 /**************************************************************************
427  * @brief Function to invoke DU Layer Configs
428  *
429  * @details
430  *
431  *      Function : duSendRlcDlCfg 
432  * 
433  *      Functionality:
434  *           Initiates Configs towards layers of DU
435  *     
436  * @param[in]  void
437  * @return ROK     - success
438  *         RFAILED - failure
439  *
440  ***************************************************************************/
441 uint8_t duSendRlcDlCfg()
442 {
443    uint8_t cellIdx; 
444
445    duBuildRlcCfg((Inst)RLC_DL_INST);
446    duBuildRlcUsapCfg(STUDXSAP, ENTRLC, (Inst)RLC_DL_INST);
447    for(cellIdx = 0; cellIdx < DEFAULT_CELLS; cellIdx++)
448    {
449       duBuildRlcLsapCfg(ENTMAC, (Inst)RLC_DL_INST, cellIdx);
450    }
451
452    return ROK;
453 }
454 /**************************************************************************
455  * @brief Function to handle Config Confirm from RLC
456  *
457  * @details
458  *
459  *      Function : DuHdlRlcCfgComplete 
460  * 
461  *      Functionality:
462  *           Handles Gen Config Confirm from RLC
463  *     
464  * @param[in]  Pst     *pst, Post structure of the primitive.     
465  * @param[in]  RlcMngmt *cfm, Unpacked primitive info received from RLC
466  * @return ROK     - success
467  *         RFAILED - failure
468  *
469  ***************************************************************************/
470 uint8_t DuHdlRlcCfgComplete(Pst *pst, RlcMngmt *cfm)
471 {
472    uint8_t ret = ROK;
473    if (pst->srcInst == RLC_UL_INST)
474    {
475       ret = duProcRlcUlCfgComplete(pst, cfm);
476    }
477    else
478    {
479       ret = duProcRlcDlCfgComplete(pst, cfm);
480    }
481    return ret;
482 }
483
484 /**************************************************************************
485  * @brief Function to handle Control Config Confirm from RLC
486  *
487  * @details
488  *
489  *      Function : duHdlRlcCntrlCfgComplete 
490  * 
491  *      Functionality:
492  *           Handles Control Config Confirm from RLC
493  *     
494  * @param[in]  Pst     *pst, Post structure of the primitive.     
495  * @param[in]  RlcMngmt *cfm, Unpacked primitive info received from RLC
496  * @return ROK     - success
497  *         RFAILED - failure
498  *
499  ***************************************************************************/
500 uint8_t duHdlRlcCntrlCfgComplete(Pst *pst, RlcMngmt *cntrl)
501 {
502    uint8_t ret = ROK;
503
504    if (cntrl->cfm.status == LCM_PRIM_OK)
505    {
506       switch (cntrl->hdr.elmId.elmnt)
507       {
508          case  STRGUSAP:
509             {
510                if (pst->srcInst == RLC_DL_INST)
511                {
512                   DU_LOG("\nDEBUG   -->  DU_APP : BIND OF RLC DL TO MAC (RGU) SAP SUCCESSFUL");
513                   macCfgInst++;
514                   if(macCfgInst < DEFAULT_CELLS)
515                   {
516                      macCfgInst = 0;
517                      duBindUnbindRlcToMacSap((Inst) RLC_DL_INST, ABND);
518                   }
519                   else
520                   {
521                      duBindUnbindRlcToMacSap((Inst) RLC_UL_INST, ABND);
522                   }
523                }
524                else
525                {
526                   DU_LOG("\nDEBUG   -->  DU_APP : BIND OF RLC UL TO MAC (RGU) SAP SUCCESSFUL");
527                   macCfgInst++;
528                   if(macCfgInst < DEFAULT_CELLS)
529                   {
530                      duBindUnbindRlcToMacSap((Inst) RLC_UL_INST, ABND);
531                   }
532                   else
533                   {
534                      duSendSchCfg();
535                   }
536                   break;
537                }
538             }
539
540       }
541    }
542    return ret;
543 }
544 /**************************************************************************
545  * @brief Function to handle Config Confirm from RLC UL
546  *
547  * @details
548  *
549  *      Function : duHdlRlcUlCfgComplete 
550  * 
551  *      Functionality:
552  *           Handles Config Confirm from RLC UL
553  *     
554  * @param[in]  Pst     *pst, Post structure of the primitive.     
555  * @param[in]  RlcMngmt *cfm, Unpacked primitive info received from RLC UL
556  * @return ROK     - success
557  *         RFAILED - failure
558  *
559  ***************************************************************************/
560 uint8_t duProcRlcUlCfgComplete(Pst *pst, RlcMngmt *cfm)
561 {
562    uint8_t ret;
563
564    DU_LOG("\nDEBUG   -->  DU_APP : RLC UL Cfg Status %d", cfm->cfm.status);
565    if (cfm->cfm.status == LCM_PRIM_OK)
566    {
567       switch(cfm->hdr.elmId.elmnt)
568       {
569          case STGEN:
570             {
571                rlcUlCfg |= RLC_GEN_CFG;
572                break;
573             }
574          case STRGUSAP:
575             {
576                numRlcMacSaps++;
577                if(numRlcMacSaps == DEFAULT_CELLS)
578                {
579                   rlcUlCfg |= RLC_MAC_SAP_CFG;
580                   numRlcMacSaps = 0;
581                }
582                break;
583             }
584          case STUDXSAP:
585             {
586                rlcUlCfg |= RLC_UDX_SAP_CFG;
587                break;
588
589             }
590          default:
591             break;
592       }
593       DU_LOG("\nDEBUG   -->  DU_APP : RLC UL Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
594       if(rlcUlCfg == DU_RLC_UL_CONFIGURED)
595       {
596          rlcUlCfg = 0;
597          numRlcMacSaps = 0;
598          //Start configuration of RLC DL
599          duSendRlcDlCfg();
600
601       }
602    }
603    else
604    {
605       DU_LOG("\nERROR  -->  DU_APP : Config confirm NOK from RLC UL");
606       ret = RFAILED;
607    }
608    return ret;
609 }
610
611 /**************************************************************************
612  * @brief Function to handle Config Confirm from RLC DL
613  *
614  * @details
615  *
616  *      Function : duHdlRlcDlCfgComplete 
617  * 
618  *      Functionality:
619  *           Handles Config Confirm from RLC DL
620  *     
621  * @param[in]  Pst     *pst, Post structure of the primitive.     
622  * @param[in]  RlcMngmt *cfm, Unpacked primitive info received from RLC DL
623  * @return ROK     - success
624  *         RFAILED - failure
625  *
626  ***************************************************************************/
627 uint8_t duProcRlcDlCfgComplete(Pst *pst, RlcMngmt *cfm)
628 {
629    DU_LOG("\nDEBUG   -->  DU_APP : RLC DL Cfg Status %d", cfm->cfm.status);
630    if (cfm->cfm.status == LCM_PRIM_OK)
631    {
632       switch(cfm->hdr.elmId.elmnt)
633       {
634          case STGEN:
635             {
636                rlcDlCfg |= RLC_GEN_CFG;
637                break;
638             }
639          case STRGUSAP:
640             {
641                numRlcMacSaps++;
642                if(numRlcMacSaps == DEFAULT_CELLS)
643                {
644                   rlcDlCfg |= RLC_MAC_SAP_CFG;
645                   numRlcMacSaps = 0;
646                }
647                break;
648             }
649          case STUDXSAP:
650             {
651                rlcDlCfg |= RLC_UDX_SAP_CFG;
652                break;
653
654             }
655          default:
656             break;
657
658       }
659       DU_LOG("\nDEBUG   -->  DU_APP : RLC DL Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
660       if(rlcDlCfg == DU_RLC_DL_CONFIGURED)
661       {
662          rlcDlCfg = 0;
663          //Start configuration of MAC
664          duSendMacCfg();
665
666       }
667    }
668    else
669    {
670       DU_LOG("\nERROR  -->  DU_APP : Config confirm NOK from RLC DL");
671    }
672    return ROK;
673 }
674
675 /**************************************************************************
676  * @brief Function to send configs to MAC
677  *
678  * @details
679  *
680  *      Function : duSendMacCfg 
681  * 
682  *      Functionality:
683  *           Initiates Configs towards MAC layer
684  *     
685  * @param[in]  void
686  * @return ROK     - success
687  *         RFAILED - failure
688  *
689  ***************************************************************************/
690 uint8_t duSendMacCfg()
691 {
692    duBuildMacGenCfg();
693    duBuildMacUsapCfg(RLC_UL_INST);
694    duBuildMacUsapCfg(RLC_DL_INST);
695
696    return ROK;
697 }
698
699 /**************************************************************************
700  * @brief Function to fill gen config required by MAC
701  *
702  * @details
703  *
704  *      Function : duBuildMacGenCfg 
705  * 
706  *      Functionality:
707  *           Initiates general Configs towards MAC
708  *     
709  * @param[in] void
710  * @return ROK     - success
711  *         RFAILED - failure
712  *
713  ***************************************************************************/
714 uint8_t duBuildMacGenCfg()
715 {
716    RgMngmt       rgMngmt;
717    RgGenCfg      *genCfg=NULLP;
718    Pst           pst;
719
720    DU_SET_ZERO(&pst, sizeof(Pst));
721    DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
722
723    genCfg   = &(rgMngmt.t.cfg.s.genCfg);
724
725    /*----------- Fill General Configuration Parameters ---------*/
726    genCfg->mem.region = MAC_MEM_REGION;
727    genCfg->mem.pool   = MAC_POOL;
728    genCfg->tmrRes     = 10;
729    genCfg->numRguSaps = 2;
730
731    genCfg->lmPst.dstProcId = DU_PROC;
732    genCfg->lmPst.srcProcId = DU_PROC;
733    genCfg->lmPst.dstEnt    = ENTDUAPP;
734    genCfg->lmPst.dstInst   = 0;
735    genCfg->lmPst.srcEnt    = ENTMAC;
736    genCfg->lmPst.srcInst   = macCfgInst;
737    genCfg->lmPst.prior     = PRIOR0;
738    genCfg->lmPst.route     = RTESPEC;
739    genCfg->lmPst.region    = MAC_MEM_REGION;
740    genCfg->lmPst.pool      = MAC_POOL;
741    genCfg->lmPst.selector  = ODU_SELECTOR_LC;
742
743    /* Fill Header */
744    rgMngmt.hdr.msgType             = TCFG;
745    rgMngmt.hdr.msgLen              = 0;
746    rgMngmt.hdr.entId.ent           = ENTMAC;
747    rgMngmt.hdr.entId.inst          = (Inst)0;
748    rgMngmt.hdr.elmId.elmnt         = STGEN;
749    rgMngmt.hdr.seqNmb              = 0;
750    rgMngmt.hdr.version             = 0;
751    rgMngmt.hdr.transId             = 0;
752
753    rgMngmt.hdr.response.prior      = PRIOR0;
754    rgMngmt.hdr.response.route      = RTESPEC;
755    rgMngmt.hdr.response.mem.region = MAC_MEM_REGION;
756    rgMngmt.hdr.response.mem.pool   = MAC_POOL;
757    rgMngmt.hdr.response.selector   = ODU_SELECTOR_LC;
758
759    /* Fill Pst */
760    pst.selector  = ODU_SELECTOR_LC;
761    pst.srcEnt    = ENTDUAPP;
762    pst.dstEnt    = ENTMAC;
763    pst.dstInst   = macCfgInst;
764    pst.dstProcId = DU_PROC;
765    pst.srcProcId = DU_PROC;
766    pst.region = duCb.init.region;
767
768    DU_LOG("\nDEBUG   -->  DU_APP : MAC Gen Cfg Req sent");
769
770    /* Send the request to MAC */
771    cmPkLrgCfgReq(&pst, &rgMngmt);
772
773    return ROK;
774 }
775
776 /**************************************************************************
777  * @brief Function to fill USAP config required by MAC
778  *
779  * @details
780  *
781  *      Function : duBuildMacUsapCfg 
782  * 
783  *      Functionality:
784  *           Initiates USAP Configs towards MAC
785  *     
786  * @param[in] SpId  Specifies if RLC UL or RLC DL instance 
787  * @return ROK     - success
788  *         RFAILED - failure
789  *
790  ***************************************************************************/
791 uint8_t duBuildMacUsapCfg(SpId sapId)
792 {
793    RgMngmt     rgMngmt;
794    RgUpSapCfg  *uSap = NULLP;
795    Pst         pst;
796
797    DU_SET_ZERO(&pst, sizeof(Pst));
798    DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
799
800    uSap   = &(rgMngmt.t.cfg.s.rguSap);
801
802    uSap->mem.region = MAC_MEM_REGION;
803    uSap->mem.pool   = MAC_POOL;
804    uSap->suId       = 0;
805    uSap->spId       = sapId;
806    uSap->procId     = DU_PROC;
807    uSap->ent        = ENTRLC;
808    uSap->inst       = sapId;
809    uSap->prior      = PRIOR0;
810    uSap->route      = RTESPEC;
811    uSap->selector   = ODU_SELECTOR_LC ;
812
813    /* fill header */
814    rgMngmt.hdr.msgType             = TCFG;
815    rgMngmt.hdr.entId.ent           = ENTMAC;
816    rgMngmt.hdr.entId.inst          = (Inst)0;
817    rgMngmt.hdr.elmId.elmnt         = STRGUSAP;
818    rgMngmt.hdr.response.mem.region = MAC_MEM_REGION;
819    rgMngmt.hdr.response.mem.pool   = MAC_POOL;
820
821    /* fill pst */
822    pst.selector  = ODU_SELECTOR_LC;
823    pst.srcEnt    = ENTDUAPP;
824    pst.dstEnt    = ENTMAC;
825    pst.dstInst   = macCfgInst;
826    pst.dstProcId = DU_PROC;
827    pst.srcProcId = DU_PROC;
828    pst.region    = duCb.init.region;
829
830    DU_LOG("\nDEBUG  -->  DU_APP : MAC Rgu USap Cfg Req sent");
831
832    /* Send the request to MAC */
833    cmPkLrgCfgReq(&pst, &rgMngmt);
834
835    return ROK;
836 }
837
838 /**************************************************************************
839  * @brief Function to handle Config Confirm from MAC
840  *
841  * @details
842  *
843  *      Function : duHdlMacCfgComplete 
844  * 
845  *      Functionality:
846  *           Handles Gen Config Confirm from MAC
847  *     
848  * @param[in]  Pst     *pst, Post structure of the primitive.     
849  * @param[in]  RgMngmt *cfm, Unpacked primitive info received from MAC
850  * @return ROK     - success
851  *         RFAILED - failure
852  *
853  ***************************************************************************/
854 uint8_t duHdlMacCfgComplete(Pst *pst, RgMngmt *cfm)
855 {
856    uint8_t ret = ROK;
857
858    if (cfm->cfm.status == LCM_PRIM_OK)
859    {
860       switch (cfm->hdr.elmId.elmnt)
861       {
862          case STGEN:
863             {
864                macCfg |= MAC_GEN_CFG;
865                break;
866             }
867          case STRGUSAP:
868             {
869                macCfg |= MAC_SAP_CFG;
870                numRlcMacSaps++;
871                break;
872             }
873          default:
874             break;
875       }
876       DU_LOG("\nDEBUG   -->  DU_APP : MAC Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
877       if(macCfg == MAC_CONFIGURED && numRlcMacSaps == MAX_MAC_SAP)
878       {
879          macCfg = 0;
880          DU_LOG("\nDEBUG   -->  DU_APP : Completed sending Configs");
881          macCfgInst = 0;
882          duBindUnbindRlcToMacSap(RLC_DL_INST, ABND);
883       }
884
885    }
886    else
887    {
888       DU_LOG("\nERROR  -->  DU_APP : Config confirm NOK from MAC");
889       ret = RFAILED;
890    }
891    return ret;
892 }
893
894 /**************************************************************************
895  * @brief Function to bind/unbind RLC to MAC SAP
896  *
897  * @details
898  *
899  *      Function : duBindUnbindRlcToMacSap 
900  * 
901  *      Functionality:
902  *           Initiates Bind/Unbind from RLC to MAC
903  *     
904  * @param[in] Inst   Specifies if RLC UL or RLC DL instance 
905  * @param[in] action Specifies if action is bind or unbind
906  * @return ROK     - success
907  *         RFAILED - failure
908  *
909  ***************************************************************************/
910 uint8_t duBindUnbindRlcToMacSap(uint8_t inst, uint8_t action)
911 {
912    RlcCntrl  *cntrl = NULLP;
913    RlcMngmt  rlcMngmt;
914    Pst      pst;
915
916
917    DU_SET_ZERO(&rlcMngmt, sizeof(RlcMngmt));
918    DU_SET_ZERO(&pst, sizeof(Pst));
919
920    if (action == ABND)
921    {
922       DU_LOG("\nDEBUG   -->  DU_APP : Cntrl Req to RLC inst %d to bind MAC sap", inst);
923    }
924    else
925    {
926       DU_LOG("\nDEBUG   -->  DU_APP : Cntrl Req to RLC inst %d to unbind MAC sap", inst);
927    }
928    cntrl = &(rlcMngmt.t.cntrl);
929
930    cntrl->action            =  action;
931    cntrl->subAction         =  DU_ZERO_VAL;
932    cntrl->s.sapCntrl.suId   =  macCfgInst;
933    cntrl->s.sapCntrl.spId   =  inst;
934
935    /* Fill header */
936    rlcMngmt.hdr.msgType             = TCNTRL;
937    rlcMngmt.hdr.entId.ent           = ENTRLC;
938    rlcMngmt.hdr.entId.inst          = inst;
939    rlcMngmt.hdr.elmId.elmnt         = 186; /* ambiguous defines in lkw.h and lrg.h so direct hardcoded*/
940    rlcMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
941       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
942    rlcMngmt.hdr.response.mem.pool   = RLC_POOL;
943
944    /* Fill pst */
945    pst.selector  = ODU_SELECTOR_LC;
946    pst.srcEnt    = ENTDUAPP;
947    pst.dstEnt    = ENTRLC;
948    pst.dstProcId = DU_PROC;
949    pst.dstInst   = inst;
950    pst.srcProcId = DU_PROC;
951    pst.region    = duCb.init.region;
952
953    cmPkLkwCntrlReq(&pst, &rlcMngmt);
954
955    return ROK;
956 }
957 /*******************************************************************
958  *
959  * @brief Handles SCTP notifications
960  *
961  * @details
962  *
963  *    Function : duSctpNtfyHdl
964  *
965  *    Functionality:
966  *         Handles SCTP notification
967  *
968  * @params[in] Message Buffer
969  *             SCTP notification
970  *
971  * @return ROK     - success
972  *         RFAILED - failure
973  *
974  * ****************************************************************/
975
976 uint8_t duSctpNtfyHdl(Buffer *mBuf, CmInetSctpNotification *ntfy)
977 {
978    if(f1Params.assocId == ntfy->u.assocChange.assocId)
979    {
980       if(BuildAndSendF1SetupReq() != ROK)
981       {
982          return RFAILED;
983       }
984    }
985    else if(ricParams.assocId == ntfy->u.assocChange.assocId)
986    {
987       if(BuildAndSendE2SetupReq() != ROK)
988       {
989          return RFAILED;
990       }
991    }
992    else
993    {
994       DU_LOG("\nERROR  -->  DU_APP : Invalid assocId %d received", ntfy->u.assocChange.assocId);
995       return RFAILED;
996    }
997    return ROK;
998 }
999
1000 /*******************************************************************
1001  *
1002  * @brief  Fills Pst struct for ENTEGTP
1003  *
1004  * @details
1005  *
1006  *    Function : duFillEgtpPst
1007  *
1008  *    Functionality:
1009  *       Fills Pst struct for ENTEGTP
1010  *
1011  * @params[in] 
1012  * @return ROK     - success
1013  *         RFAILED - failure
1014  *
1015  * ****************************************************************/
1016 uint8_t duFillEgtpPst(Pst *pst, Event event)
1017 {
1018    memset(pst, 0, sizeof(Pst));
1019    pst->srcEnt = (Ent)ENTDUAPP;
1020    pst->srcInst = (Inst)DU_INST;
1021    pst->srcProcId = DU_PROC;
1022    pst->dstEnt = (Ent)ENTEGTP;
1023    pst->dstInst = (Inst)EGTP_INST;
1024    pst->dstProcId = pst->srcProcId;
1025    pst->event = event;
1026    pst->selector = ODU_SELECTOR_LC;
1027    pst->pool= DU_POOL;
1028
1029    return ROK;
1030 }
1031
1032
1033 /*******************************************************************
1034  *
1035  * @brief  Function to configure EGTP
1036  *
1037  * @details
1038  *
1039  *    Function : duBuildEgtpCfgReq
1040  *
1041  *    Functionality:
1042  *       Function to configure EGTP
1043  *
1044  * @params[in] 
1045  * @return ROK     - success
1046  *         RFAILED - failure
1047  *
1048  * ****************************************************************/
1049
1050 uint8_t duBuildEgtpCfgReq()
1051 {
1052    Pst pst;
1053    EgtpConfig egtpCfg;
1054
1055    DU_LOG("\nDEBUG   -->  DU_APP : Sending EGTP config request");
1056
1057    memset(&egtpCfg, 0, sizeof(EgtpConfig));
1058    memcpy(&egtpCfg, &duCfgParam.egtpParams, sizeof(EgtpConfig));
1059
1060    duFillEgtpPst(&pst, EVTCFGREQ);
1061    packEgtpCfgReq(&pst, egtpCfg);
1062
1063    return ROK;
1064 }
1065
1066 /*******************************************************************
1067  *
1068  * @brief  Function to configure EGTP
1069  *
1070  * @details
1071  *
1072  *    Function : duBuildEgtpCfgReq
1073  *
1074  *    Functionality:
1075  *       Function to configure EGTP
1076  *
1077  * @params[in] 
1078  * @return ROK     - success
1079  *         RFAILED - failure
1080  *
1081  * ****************************************************************/
1082 uint8_t duHdlEgtpCfgComplete(CmStatus cfm)
1083 {
1084    uint8_t ret = ROK;
1085
1086    if(cfm.status == LCM_PRIM_OK)
1087    {
1088       DU_LOG("\nDEBUG   -->  DU_APP : EGTP configuraton complete");
1089       duSendEgtpSrvOpenReq();
1090    }
1091    else
1092    {
1093       DU_LOG("\nERROR  -->  DU_APP : EGTP configuraton failed");
1094       ret = RFAILED;
1095    }
1096
1097    return (ret);
1098 }
1099
1100 /*******************************************************************
1101  *
1102  * @brief  Sends server open request to EGTP
1103  *
1104  * @details
1105  *
1106  *    Function : duSendEgtpSrvOpenReq
1107  *
1108  *    Functionality:
1109  *       Sends server open request to EGTP
1110  *
1111  * @params[in] 
1112  * @return ROK     - success
1113  *         RFAILED - failure
1114  *
1115  * ****************************************************************/
1116
1117 uint8_t duSendEgtpSrvOpenReq()
1118 {
1119    Pst pst;
1120
1121    DU_LOG("\nDEBUG   -->  DU_APP : Sending EGTP server open request");
1122
1123    duFillEgtpPst(&pst, EVTSRVOPENREQ);
1124    packEgtpSrvOpenReq(&pst);
1125
1126    return ROK;
1127 }
1128
1129 /*******************************************************************
1130  *
1131  * @brief Handles server open confirmation
1132  *
1133  * @details
1134  *
1135  *    Function : duHdlEgtpSrvOpenComplete
1136  *
1137  *    Functionality:
1138  *        Handles server open confirmation
1139  *
1140  * @params[in] 
1141  * @return ROK     - success
1142  *         RFAILED - failure
1143  *
1144  *****************************************************************/
1145
1146 uint8_t duHdlEgtpSrvOpenComplete(CmStatus cfm)
1147 {
1148    uint8_t ret = ROK;
1149
1150    if(cfm.status == LCM_PRIM_OK)
1151    {
1152       DU_LOG("\nDEBUG   -->  DU_APP : EGTP server opened successfully");
1153    }
1154    else
1155    {
1156       DU_LOG("\nERROR  -->  DU_APP : EGTP server opening failed");
1157       ret = RFAILED;
1158    }
1159
1160    return (ret);
1161 }
1162
1163 /*******************************************************************
1164  *
1165  * @brief Sends tunnel management request
1166  *
1167  * @details
1168  *
1169  *    Function : duSendEgtpTnlMgmtReq 
1170  *
1171  *    Functionality:
1172  *        Builds and sends tunnel management request to EGTP
1173  *
1174  * @params[in] Action
1175  *             Local tunnel endpoint id
1176  *             Remote tunnel endpoint id 
1177  * @return ROK     - success
1178  *         RFAILED - failure
1179  *
1180  * ****************************************************************/
1181
1182 uint8_t duSendEgtpTnlMgmtReq(uint8_t action, uint32_t teIdTobeMod, GtpTnlCfg *ueCbTnlCfg)
1183 {
1184    uint8_t ret =ROK;
1185    Pst pst;
1186    EgtpTnlEvt tnlEvt;
1187
1188    DU_LOG("\nDEBUG   -->  DU_APP : Sending EGTP tunnel management request for teId [%d]", ueCbTnlCfg->teId);
1189
1190    /* ADD/MOD/DEL per tunnel */
1191    tnlEvt.action = action;
1192    tnlEvt.remTeid = ueCbTnlCfg->teId;
1193    if(action != EGTP_TNL_MGMT_ADD)
1194    {
1195       tnlEvt.lclTeid = teIdTobeMod;
1196    }
1197    else
1198    {
1199       tnlEvt.lclTeid = ueCbTnlCfg->teId;
1200    }
1201    duFillEgtpPst(&pst, EVTTNLMGMTREQ);
1202    ret = egtpTnlMgmtReq(&pst, tnlEvt);
1203    return ret;
1204 }
1205
1206 /*******************************************************************
1207  *
1208  * @brief Handles Tunnel management confirm 
1209  *
1210  * @details
1211  *
1212  *    Function : duHdlEgtpTnlMgmtCfm
1213  *
1214  *    Functionality:
1215  *      Handles tunnel management confirm received from Egtp
1216  *
1217  * @params[in] Tunnel Event  
1218  * @return ROK     - success
1219  *         RFAILED - failure
1220  *
1221  * ****************************************************************/
1222 uint8_t duHdlEgtpTnlMgmtCfm(EgtpTnlEvt tnlEvtCfm)
1223 {
1224    uint8_t ret = ROK;
1225
1226    if(tnlEvtCfm.cfmStatus.status == LCM_PRIM_OK)
1227    {
1228       DU_LOG("\nDEBUG  -->  DU_APP: Tunnel management confirm OK");
1229    }
1230    else
1231    {
1232       DU_LOG("\nERROR  -->  DU_APP: Tunnel management failed");
1233       ret = RFAILED;
1234    }
1235
1236    return (ret);
1237 }
1238
1239 /*******************************************************************
1240  *
1241  * @brief Sends UL user data over to EGTP
1242  *
1243  * @details
1244  *
1245  *    Function : duSendEgtpDatInd
1246  *
1247  *    Functionality: Sends UL user data over to EGTP
1248  *
1249  * @params[in] UL data buffer
1250  * @return ROK     - success
1251  *         RFAILED - failure
1252  *
1253  * ****************************************************************/
1254 uint8_t duSendEgtpDatInd(Buffer *mBuf)
1255 {
1256    EgtpMsg  egtpMsg;
1257
1258    /* Fill EGTP header */
1259    egtpMsg.msgHdr.msgType = EGTPU_MSG_GPDU;
1260    egtpMsg.msgHdr.nPdu.pres = FALSE;
1261    egtpMsg.msgHdr.seqNum.pres = FALSE;
1262    egtpMsg.msgHdr.extHdr.udpPort.pres = FALSE;
1263    egtpMsg.msgHdr.extHdr.pdcpNmb.pres = FALSE;
1264    egtpMsg.msgHdr.teId = 1;
1265    egtpMsg.msg = mBuf;
1266    
1267    egtpHdlDatInd(egtpMsg);
1268
1269    return ROK;
1270
1271 }
1272
1273 /**************************************************************************
1274  * @brief Function to send configs to SCH
1275  *
1276  * @details
1277  *
1278  *      Function : duSendSchCfg 
1279  * 
1280  *      Functionality:
1281  *           Sends general config to Scheduler via MAC layer
1282  *     
1283  * @param[in]  void
1284  * @return ROK     - success
1285  *         RFAILED - failure
1286  *
1287  ***************************************************************************/
1288 uint8_t duSendSchCfg()
1289 {
1290    RgMngmt       rgMngmt;
1291    RgSchInstCfg  *cfg = NULLP;
1292    Pst           pst;
1293
1294    DU_SET_ZERO(&pst, sizeof(Pst));
1295    DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
1296
1297    cfg = &(rgMngmt.t.cfg.s.schInstCfg);
1298
1299    /* Filling of Instance Id */
1300    cfg->instId = DEFAULT_CELLS + 1;
1301    /* Filling of Gen config */
1302    cfg->genCfg.mem.region = MAC_MEM_REGION;
1303    cfg->genCfg.mem.pool = MAC_POOL;
1304    cfg->genCfg.tmrRes = 10;
1305
1306 #ifdef LTE_ADV
1307    cfg->genCfg.forceCntrlSrbBoOnPCel = FALSE;
1308    cfg->genCfg.isSCellActDeactAlgoEnable = TRUE;
1309 #endif/*LTE_ADV*/
1310    cfg->genCfg.startCellId     = 1;
1311    cfg->genCfg.lmPst.dstProcId = DU_PROC;
1312    cfg->genCfg.lmPst.srcProcId = DU_PROC;
1313    cfg->genCfg.lmPst.dstEnt    = ENTDUAPP;
1314    cfg->genCfg.lmPst.dstInst   = DU_INST;
1315    cfg->genCfg.lmPst.srcEnt    = ENTMAC;
1316    cfg->genCfg.lmPst.srcInst   = DEFAULT_CELLS + 1;
1317    cfg->genCfg.lmPst.prior     = PRIOR0;
1318    cfg->genCfg.lmPst.route     = RTESPEC;
1319    cfg->genCfg.lmPst.region    = MAC_MEM_REGION;
1320    cfg->genCfg.lmPst.pool      = MAC_POOL;
1321    cfg->genCfg.lmPst.selector  = ODU_SELECTOR_LC;
1322
1323    /* Fill Header */
1324    rgMngmt.hdr.msgType             = TCFG;
1325    rgMngmt.hdr.entId.ent           = ENTMAC;
1326    rgMngmt.hdr.entId.inst          = DU_INST;
1327    rgMngmt.hdr.elmId.elmnt         = STSCHINST;
1328    rgMngmt.hdr.response.mem.region = MAC_MEM_REGION;
1329    rgMngmt.hdr.response.mem.pool   = MAC_POOL;
1330
1331    /* Fill Pst */
1332    pst.selector  = ODU_SELECTOR_LC;
1333    pst.srcEnt    = ENTDUAPP;
1334    pst.dstEnt    = ENTMAC;
1335    pst.dstProcId = DU_PROC;
1336    pst.srcProcId = DU_PROC;
1337    pst.srcInst   = DU_INST;
1338    pst.dstInst   = 0;
1339    pst.region    = duCb.init.region;
1340    pst.event    = (Event) EVTMACSCHGENCFGREQ;
1341
1342    DU_LOG("\nDEBUG   -->  DU_APP : MAC Sch Cfg sent");
1343
1344    /* Send the request to MAC */
1345    cmPkLrgSchCfgReq(&pst, &rgMngmt);
1346
1347    return ROK;
1348 }
1349
1350
1351 /**************************************************************************
1352  * @brief Function to configure SCTP params and 
1353  *  responsible for F1 and E2 interfaces
1354  *
1355  * @details
1356  *
1357  *      Function : duLayerConfigComplete
1358  * 
1359  *      Functionality:
1360  *           Configures SCTP Params and responsible for handling
1361  *           F1 and E2 interface.
1362  *     
1363  * @param[in]  void
1364  * @return ROK     - success
1365  *         RFAILED - failure
1366  *
1367  ***************************************************************************/
1368 uint8_t duLayerConfigComplete()
1369 {
1370    uint8_t ret = ROK;
1371
1372    DU_LOG("\nINFO   -->  DU_APP : Configuring all Layer is complete");
1373
1374    if((ret = duSctpCfgReq(duCfgParam.sctpParams)) != ROK)
1375    {
1376       DU_LOG("\nERROR  -->  DU_APP : Failed configuring Sctp Params");
1377       ret = RFAILED;
1378    }
1379    if((ret = duSctpAssocReq(F1_INTERFACE)) != ROK)
1380    {
1381       DU_LOG("\nERROR  -->  DU_APP : Failed to send AssocReq F1");
1382       ret = RFAILED;
1383    }
1384    if((ret = duSctpAssocReq(E2_INTERFACE)) != ROK)
1385    {
1386       DU_LOG("\nERROR  -->  DU_APP : Failed to send AssocReq E2");
1387       ret = RFAILED;
1388    }
1389
1390    return (ret); 
1391
1392
1393 /**************************************************************************
1394  * @brief Function to handle  SCH Config Confirm from MAC
1395  *
1396  * @details
1397  *
1398  *      Function : duHdlSchCfgComplete 
1399  * 
1400  *      Functionality:
1401  *           Handles Scheduler Gen Config Confirm from MAC
1402  *     
1403  * @param[in]  Pst     *pst, Post structure of the primitive.     
1404  * @param[in]  RgMngmt *cfm, Unpacked primitive info received from MAC
1405  * @return ROK     - success
1406  *         RFAILED - failure
1407  *
1408  ***************************************************************************/
1409 uint8_t duHdlSchCfgComplete(Pst *pst, RgMngmt *cfm)
1410 {
1411    if (cfm->cfm.status == LCM_PRIM_OK)
1412    {
1413       switch (cfm->hdr.elmId.elmnt)
1414       {
1415          case STSCHINST:
1416             {
1417                DU_LOG("\nDEBUG   -->  DU_APP : Received SCH CFG CFM at DU APP");
1418                break;
1419             }
1420          default:
1421             break;
1422       }
1423    }
1424    duLayerConfigComplete();
1425    duBuildEgtpCfgReq();
1426    return ROK;
1427 }
1428
1429 /**************************************************************************
1430  * @brief Function to fill and send MacCellconfig
1431  *
1432  * @details
1433  *
1434  *      Function : duBuildAndSendMacCellCfg 
1435  * 
1436  *      Functionality:
1437  *           Initiates MAC Configs towards MAC
1438  *     
1439  * @param[in]cell id
1440  * @return ROK     - success
1441  *         RFAILED - failure
1442  *
1443  ***************************************************************************/
1444 uint8_t duBuildAndSendMacCellCfg(uint16_t cellId)
1445 {
1446    Pst pst;
1447    MacCellCfg *duMacCellCfg = NULLP;
1448
1449    DU_ALLOC_SHRABL_BUF(duMacCellCfg, sizeof(MacCellCfg));
1450    if(duMacCellCfg == NULLP)
1451    {
1452       return RFAILED;
1453    }
1454
1455    /* store the address in the duCellCb so that we can free on confirm msg */
1456    duCb.actvCellLst[cellId-1]->duMacCellCfg = duMacCellCfg;
1457
1458    /* copy the mac config structure from duCfgParams */
1459    memcpy(duMacCellCfg,&duCfgParam.macCellCfg,sizeof(MacCellCfg));
1460
1461    /* Fill Pst */
1462    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_CONFIG_REQ);
1463
1464    /* Send MAC cell config to MAC */
1465    return (*packMacCellCfgOpts[pst.selector])(&pst, duMacCellCfg);
1466 }
1467
1468 /**************************************************************************
1469  * @brief Function to Handle MAC cell config confirm
1470  *
1471  * @details
1472  *
1473  *      Function : duHandleMacCellCfgCfm 
1474  * 
1475  *      Functionality:
1476  *           Initiates general Configs towards MAC
1477  *     
1478  * @param[in] void
1479  * @return ROK     - success
1480  *         RFAILED - failure
1481  *
1482  ***************************************************************************/
1483 uint8_t  duHandleMacCellCfgCfm(Pst *pst, MacCellCfgCfm *macCellCfgCfm)
1484 {
1485    uint8_t  actvCellIdx  = 0;
1486    uint8_t  ret          = ROK;
1487
1488    for(actvCellIdx = 0; actvCellIdx < MAX_NUM_CELL; actvCellIdx++)
1489    {
1490       if(macCellCfgCfm->cellId == duCb.actvCellLst[actvCellIdx]->cellId)
1491       {
1492          duCb.actvCellLst[actvCellIdx]->duMacCellCfg = NULLP;
1493       }
1494    }
1495    if(macCellCfgCfm->rsp == ROK)
1496    {
1497       /* Build and send GNB-DU config update */
1498       ret = BuildAndSendDUConfigUpdate(SERV_CELL_TO_MODIFY);
1499
1500       /* Build and Send Cell Start Req to MAC */
1501       ret = duBuildAndSendMacCellStart();
1502    }
1503    else
1504    {
1505       /* TODO : Action to be taken if cell configuration fails. 
1506        * Should CU be informed? */
1507
1508       DU_LOG("\nERROR  -->  DU_APP : Mac cell cfg failed");
1509       ret = RFAILED;
1510    }
1511    return ret;
1512 }
1513
1514 /*******************************************************************
1515  *
1516  * @brief Builds and sends cell start request to MAC
1517  *
1518  * @details
1519  *
1520  *    Function : duBuildAndSendMacCellStart
1521  *
1522  *    Functionality:
1523  *       Builds and sends cell start request to MAC
1524  *
1525  * @params[in] 
1526  * @return ROK     - success
1527  *         RFAILED - failure
1528  *
1529  * ****************************************************************/
1530 uint8_t duBuildAndSendMacCellStart()
1531 {
1532    Pst pst;
1533    OduCellId *cellId = NULL;
1534
1535    DU_LOG("\nINFO   -->  DU APP : Building and Sending cell start request to MAC");
1536
1537    /* Send Cell Start Request to MAC */
1538    DU_ALLOC_SHRABL_BUF(cellId, sizeof(OduCellId));
1539    if(!cellId)
1540    {
1541       DU_LOG("\nERROR  -->  DU APP : Memory alloc failed while building cell start request");
1542       return RFAILED;
1543    }
1544
1545    for(uint8_t id = 0; id < duCb.numActvCells; id++) 
1546    {
1547       if(duCb.actvCellLst[id])
1548       {
1549          cellId->cellId = duCb.actvCellLst[id]->cellId;
1550
1551          /* Fill Pst */
1552          FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_START);
1553
1554          return (*packMacCellStartOpts[pst.selector])(&pst, cellId);
1555       }
1556    }
1557    return ROK;
1558 }
1559
1560 /*******************************************************************
1561  *
1562  * @brief Builds and sends cell stop request to MAC
1563  *
1564  * @details
1565  *
1566  *    Function : duBuildAndSendMacCellStop 
1567  *
1568  *    Functionality:
1569  *       Builds and sends cell stop request to MAC
1570  *
1571  * @params[in] 
1572  * @return ROK     - success
1573  *         RFAILED - failure
1574  *
1575  * ****************************************************************/
1576 uint8_t duBuildAndSendMacCellStop(uint16_t cellId)
1577 {
1578    Pst pst;
1579    uint16_t cellIdx=0;
1580    OduCellId *oduCellId = NULL;
1581    
1582    DU_LOG("\nINFO   -->  DU APP : Building and Sending cell stop request to MAC");
1583
1584    GET_CELL_IDX(cellId, cellIdx);
1585    if(duCb.actvCellLst[cellIdx] != NULLP)
1586    {
1587       /* Send Cell Stop Request to MAC */
1588       DU_ALLOC_SHRABL_BUF(oduCellId, sizeof(OduCellId));
1589       if(!oduCellId)
1590       {
1591          DU_LOG("\nERROR  -->  DU APP : duBuildAndSendMacCellStop():  Memory allocation failed ");
1592          return RFAILED;
1593       }
1594       memset(oduCellId, 0, sizeof(OduCellId));
1595       oduCellId->cellId = duCb.actvCellLst[cellIdx]->cellId;
1596
1597       /* Fill Pst */
1598       FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_STOP);
1599
1600       return (*packMacCellStopOpts[pst.selector])(&pst, oduCellId);
1601    }
1602    else
1603    {
1604       DU_LOG("\nERROR  -->  DU APP : duBuildAndSendMacCellStop(): cellId[%d] doesnot exists", cellId);
1605       return RFAILED;
1606    }
1607    return ROK;
1608 }
1609
1610 /*******************************************************************
1611  *
1612  * @brief Handles stop indication from MAC
1613  *
1614  * @details
1615  *
1616  *    Function : duHandleStopInd
1617  *
1618  *    Functionality:
1619  *      Handles stop indication from MAC
1620  *
1621  * @params[in] Post structure pointer
1622  * @return ROK     - success
1623  *         RFAILED - failure
1624  *
1625  * ****************************************************************/
1626 uint8_t duHandleStopInd(Pst *pst, OduCellId *cellId)
1627 {
1628    DuCellCb *cellCb = NULLP;
1629
1630    if(cellId->cellId <=0 || cellId->cellId > MAX_NUM_CELL)
1631    {
1632       DU_LOG("\nERROR  -->  DU APP : Invalid Cell Id %d in duHandleStopInd()", cellId->cellId);
1633    }
1634
1635    if(duGetCellCb(cellId->cellId, &cellCb) != ROK)
1636       return RFAILED;
1637
1638    if((cellCb->cellStatus == ACTIVATED) || (cellCb->cellStatus == DELETION_IN_PROGRESS))
1639    {
1640       DU_LOG("\nINFO   -->  DU APP : 5G-NR Cell %d is DOWN", cellId->cellId);
1641       if(sendCellDeleteReqToMac(cellId->cellId) == RFAILED)
1642       {
1643          DU_LOG("\nERROR  -->  DU APP : duHandleStopInd(): Failed to send Cell delete req to MAC for\
1644                cellId[%d]", cellId->cellId);
1645          return RFAILED;
1646       }
1647
1648
1649 #ifdef O1_ENABLE
1650       DU_LOG("\nINFO   -->  DU APP : Raise cell down alarm for cell id=%d", cellId->cellId);
1651       raiseCellAlrm(CELL_DOWN_ALARM_ID, cellId->cellId);
1652       setCellOpState(cellId->cellId, DISABLED, INACTIVE);
1653 #endif
1654    }
1655
1656    if((pst->selector == ODU_SELECTOR_LWLC) || (pst->selector == ODU_SELECTOR_TC))
1657       DU_FREE_SHRABL_BUF(MAC_MEM_REGION, pst->pool, cellId, sizeof(OduCellId));
1658
1659    cellCb->cellStatus = CELL_OUT_OF_SERVICE; //TODO: cell status must be set to OOS after all UE and cell cleanup which is not
1660                                              //supported now
1661
1662    return ROK;
1663 }
1664
1665 /*******************************************************************
1666  *
1667  * @brief Handles slot indication from MAC
1668  *
1669  * @details
1670  *
1671  *    Function : duHandleUlCcchInd
1672  *
1673  *    Functionality:
1674  *      Handles UL CCCH indication from MAC
1675  *
1676  * @params[in] Post structure pointer
1677  *             UL CCCH Ind pointer
1678  * @return ROK     - success
1679  *         RFAILED - failure
1680  *
1681  * ****************************************************************/
1682 uint8_t duHandleUlCcchInd(Pst *pst, UlCcchIndInfo *ulCcchIndInfo)
1683 {
1684
1685    DU_LOG("\nINFO  -->  DU APP : UL CCCH Indication received");
1686
1687    return (duProcUlCcchInd(ulCcchIndInfo));
1688 }
1689
1690 /*******************************************************************
1691  *
1692  * @brief Process UL RRC Message from RLC
1693  *
1694  * @details
1695  *
1696  *    Function : DuProcRlcUlRrcMsgTrans
1697  *
1698  *    Functionality: Process UL RRC Message from RLC
1699  *
1700  * @params[in] Post structure
1701  *             UL RRC Message Info
1702  * @return ROK     - success
1703  *         RFAILED - failure
1704  *
1705  * ****************************************************************/
1706 uint8_t DuProcRlcUlRrcMsgTrans(Pst *pst, RlcUlRrcMsgInfo *ulRrcMsgInfo)
1707 {
1708    DuCellCb *cellCb = NULLP;
1709    DuUeCb   ueCb ={0};
1710   
1711    if(duGetCellCb(ulRrcMsgInfo->cellId, &cellCb) != ROK)
1712       return RFAILED;
1713    if(ulRrcMsgInfo->ueIdx > 0)
1714    {
1715    ueCb = cellCb->ueCb[ulRrcMsgInfo->ueIdx -1];
1716
1717
1718    BuildAndSendULRRCMessageTransfer(ueCb, ulRrcMsgInfo->lcId, ulRrcMsgInfo->msgLen, \
1719       ulRrcMsgInfo->rrcMsg);
1720
1721    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulRrcMsgInfo->rrcMsg, ulRrcMsgInfo->msgLen);
1722    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulRrcMsgInfo, sizeof(RlcUlRrcMsgInfo));
1723    }
1724    return ROK;
1725 }
1726
1727 /*******************************************************************
1728 *
1729 * @brief Process RRC delivery report from RLC
1730 *
1731 * @details
1732 *
1733 *    Function : DuProcRlcRrcDeliveryReport
1734 *
1735 *    Functionality: Process RRC delivery Message from RLC
1736 *
1737 * @params[in] Post structure
1738 *             UL RRC Message Info
1739 * @return ROK     - success
1740 *         RFAILED - failure
1741 *
1742 * ****************************************************************/
1743 uint8_t DuProcRlcRrcDeliveryReport(Pst *pst, RrcDeliveryReport *rrcDeliveryReport)
1744 {
1745    DuCellCb *cellCb = NULLP;
1746    DuUeCb   ueCb;
1747    uint8_t  ret = RFAILED;
1748
1749    if(duGetCellCb(rrcDeliveryReport->cellId, &cellCb) != ROK)
1750       return RFAILED;
1751    
1752    ueCb = cellCb->ueCb[rrcDeliveryReport->ueIdx -1];
1753    ret = BuildAndSendRrcDeliveryReport(ueCb.gnbCuUeF1apId, ueCb.gnbDuUeF1apId,rrcDeliveryReport);
1754
1755    DU_FREE_SHRABL_BUF(pst->region, pst->pool, rrcDeliveryReport, sizeof(RrcDeliveryReport));
1756    return ret;
1757 }
1758
1759 /*******************************************************************
1760  *
1761  * @brief Process UL user data from RLC
1762  *
1763  * @details
1764  *
1765  *    Function : DuProcRlcUlUserDataTrans
1766  *
1767  *    Functionality: Process UL user data from RLC
1768  *
1769  * @params[in] Post structure
1770  *             UL user data
1771  * @return ROK     - success
1772  *         RFAILED - failure
1773  *
1774  * ****************************************************************/
1775 uint8_t DuProcRlcUlUserDataTrans(Pst *pst, RlcUlUserDatInfo *ulUserData)
1776 {
1777    uint8_t  rbIdx;
1778    EgtpMsg  egtpMsg;
1779    Buffer   *mBuf;
1780
1781    DU_LOG("\nDEBUG  -->  DU APP : Received UL user data");
1782
1783    /* Fill EGTP header */
1784    egtpMsg.msgHdr.msgType = EGTPU_MSG_GPDU;
1785    egtpMsg.msgHdr.nPdu.pres = FALSE;
1786    egtpMsg.msgHdr.seqNum.pres = FALSE;
1787    egtpMsg.msgHdr.extHdr.udpPort.pres = FALSE;
1788    egtpMsg.msgHdr.extHdr.pdcpNmb.pres = FALSE;
1789
1790    /* Fetch EGTP tunnel info */
1791    for(rbIdx = 0; rbIdx < duCb.numDrb; rbIdx++)
1792    {
1793       if((duCb.upTnlCfg[rbIdx] != NULLP) && (duCb.upTnlCfg[rbIdx]->ueIdx == ulUserData->ueIdx) && \
1794          (duCb.upTnlCfg[rbIdx]->drbId == ulUserData->rbId))
1795       {
1796          if(duCb.upTnlCfg[rbIdx]->tnlCfg1)
1797          {
1798             egtpMsg.msgHdr.teId = duCb.upTnlCfg[rbIdx]->tnlCfg1->teId; /*As we are supporting only 1 tunnel per DRB*/
1799             break;
1800          }
1801       }
1802    }
1803
1804    if (ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) != ROK)
1805    {
1806       DU_LOG("\nERROR  -->  DU APP : Failed to allocated buffer memory in DuProcRlcUlUserDataTrans");
1807       DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulUserData->userData, ulUserData->msgLen);
1808       DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulUserData, sizeof(RlcUlUserDatInfo));
1809       return RFAILED;
1810    }
1811    oduCpyFixBufToMsg(ulUserData->userData, mBuf, ulUserData->msgLen);
1812    ODU_PRINT_MSG(mBuf, 0, 0);
1813    egtpMsg.msg = mBuf;
1814    egtpHdlDatInd(egtpMsg);
1815
1816    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulUserData->userData, ulUserData->msgLen);
1817    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulUserData, sizeof(RlcUlUserDatInfo));
1818    return ROK;
1819 }
1820
1821 /*******************************************************************
1822  *
1823  * @brief Free tempSLiceCfg stored in duCfgParams
1824  *
1825  * @details
1826  *
1827  *    Function :  duFreeTempSliceCfg
1828  *
1829  *    Functionality: Free tempSLiceCfg stored in duCfgParams 
1830  *
1831  * @params[in] Post structure, 
1832  *             
1833  * @return Void
1834  *
1835  * ****************************************************************/
1836
1837 void duFreeTempSliceCfg()
1838 {
1839     uint8_t policyIdx = 0, memberListTdx =0;
1840     CopyOfRecvdSliceCfg *tempSliceCfg = &duCfgParam.tempSliceCfg;
1841     
1842     if(tempSliceCfg->totalRrmPolicy)
1843     {
1844        for(policyIdx = 0; policyIdx<tempSliceCfg->totalRrmPolicy; policyIdx++)
1845        {
1846           if(tempSliceCfg->rrmPolicy[policyIdx]->numMemberList)
1847           {
1848              for(memberListTdx = 0; memberListTdx<tempSliceCfg->rrmPolicy[policyIdx]->numMemberList; memberListTdx++)
1849              {
1850                  DU_FREE(tempSliceCfg->rrmPolicy[policyIdx]->memberList[memberListTdx], sizeof(PolicyMemberList));
1851              }
1852              DU_FREE(tempSliceCfg->rrmPolicy[policyIdx]->memberList, (tempSliceCfg->rrmPolicy[policyIdx]->numMemberList) * sizeof(PolicyMemberList*));
1853           }
1854           DU_FREE(tempSliceCfg->rrmPolicy[policyIdx], sizeof(RrmPolicy));
1855        }
1856        DU_FREE(tempSliceCfg->rrmPolicy, tempSliceCfg->totalRrmPolicy* sizeof(RrmPolicy*));
1857     }
1858     memset(tempSliceCfg, 0, sizeof(CopyOfRecvdSliceCfg));
1859 }
1860
1861 /*******************************************************************
1862  *
1863  * @brief  free the slice cfg rsp
1864  *
1865  * @details
1866  *
1867  *    Function : duFreeSliceCfgRsp 
1868  *
1869  *    Functionality: free the slice cfg rsp 
1870  *
1871  * @params[in] Post structure, MacSliceCfgRsp  *cfgRsp
1872  *             
1873  * @return ROK     - success
1874  *         RFAILED - failure
1875  *
1876  **********************************************************************/
1877 void duFreeSliceCfgRsp(Pst *pst,  MacSliceCfgRsp *cfgRsp) 
1878 {
1879    uint8_t cfgIdx;
1880
1881    if(cfgRsp)
1882    {
1883       if(cfgRsp->numSliceCfgRsp)
1884       {
1885          for(cfgIdx = 0; cfgIdx<cfgRsp->numSliceCfgRsp; cfgIdx++)
1886          {
1887             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp->listOfSliceCfgRsp[cfgIdx], sizeof(MacSliceRsp)); 
1888          }
1889          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp->listOfSliceCfgRsp, cfgRsp->numSliceCfgRsp * sizeof(MacSliceRsp*)); 
1890       }
1891       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(MacSliceCfgRsp)); 
1892    }
1893    return ROK;
1894 }
1895
1896 /*******************************************************************
1897  *
1898  * @brief process the slice cfg rsp received from MAC
1899  *
1900  * @details
1901  *
1902  *    Function : DuProcMacSliceCfgRsp
1903  *
1904  *    Functionality: process the slice cfg rsp received from MAC
1905  *
1906  * @params[in] Post structure, MacSliceCfgRsp  *cfgRsp
1907  *             
1908  * @return ROK     - success
1909  *         RFAILED - failure
1910  *
1911  **********************************************************************/
1912 uint8_t DuProcMacSliceCfgRsp(Pst *pst,  MacSliceCfgRsp *cfgRsp)
1913 {
1914     uint8_t cfgIdx = 0;
1915     
1916     if(cfgRsp)
1917     {
1918         if(cfgRsp->listOfSliceCfgRsp)
1919         {
1920             for(cfgIdx = 0; cfgIdx<cfgRsp->numSliceCfgRsp; cfgIdx++)
1921             {
1922                 if(cfgRsp->listOfSliceCfgRsp[cfgIdx]->rsp ==  MAC_DU_APP_RSP_OK)
1923                 {
1924                     duCb.sliceState = SLICE_CONFIGURED;
1925                 }
1926             }
1927             DU_LOG("\nINFO  -->  DU_APP : Slice Configuration is done sucessfully ");
1928         }
1929         duFreeSliceCfgRsp(pst, cfgRsp);
1930     }
1931     duFreeTempSliceCfg();
1932     return ROK;
1933 }
1934
1935 /*******************************************************************
1936  *
1937  * @brief Fill the slice configration and rrm policy ratio 
1938  *    information received form O1
1939  *
1940  * @details
1941  *
1942  *    Function : fillSliceCfgReCfgInfo 
1943  *
1944  *    Functionality: Fill the slice configration and recfg info 
1945  *
1946  * @params[in] Post structure
1947  *             
1948  * @return ROK     - success
1949  *         RFAILED - failure
1950  *
1951  * ****************************************************************/
1952
1953 uint8_t fillSliceCfgReCfgInfo(MacSliceCfgReq *sliceCfgReq, RrmPolicy *rrmPolicy[], uint8_t totalRrmPolicy, uint8_t totalSliceCount)
1954 {
1955    uint8_t sliceIdx = 0, cfgIdx = 0, memberListIdx = 0;
1956    
1957    if(totalRrmPolicy)
1958    {
1959       DU_ALLOC_SHRABL_BUF(sliceCfgReq->listOfSliceCfg, totalSliceCount*sizeof(MacSliceRrmPolicy*)); 
1960       if(sliceCfgReq->listOfSliceCfg == NULLP)
1961       {
1962          DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed in fillSliceCfgReCfgInfo");
1963          return RFAILED;
1964       }
1965
1966       for(sliceIdx = 0; sliceIdx<totalRrmPolicy; sliceIdx++)
1967       {
1968          for(memberListIdx = 0; memberListIdx<rrmPolicy[sliceIdx]->numMemberList; memberListIdx++)
1969          {
1970             DU_ALLOC_SHRABL_BUF(sliceCfgReq->listOfSliceCfg[cfgIdx], sizeof(MacSliceRrmPolicy));
1971             if(sliceCfgReq->listOfSliceCfg[cfgIdx] == NULLP)
1972             { 
1973                DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed in fillSliceCfgReCfgInfo");
1974                return RFAILED;
1975             }
1976
1977
1978             memcpy(&sliceCfgReq->listOfSliceCfg[cfgIdx]->snssai, &rrmPolicy[sliceIdx]->memberList[memberListIdx]->snssai, sizeof(Snssai));
1979
1980             DU_ALLOC_SHRABL_BUF(sliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio, sizeof(RrmPolicyRatio));
1981             if(sliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio == NULLP)
1982             { 
1983                DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed in fillSliceCfgReCfgInfo");
1984                return RFAILED;
1985             }
1986
1987             sliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyMaxRatio = rrmPolicy[sliceIdx]->policyMaxRatio;
1988             sliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyMinRatio = rrmPolicy[sliceIdx]->policyMinRatio;
1989             sliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyDedicatedRatio = rrmPolicy[sliceIdx]->policyDedicatedRatio; 
1990             sliceCfgReq->numOfConfiguredSlice++;
1991             cfgIdx++;
1992          }
1993       }
1994    }
1995    return ROK;
1996 }
1997
1998 /*******************************************************************
1999  *
2000  * @brief Fill the slice configration and rrm policy related
2001  *    information received form O1
2002  *
2003  * @details
2004  *
2005  *    Function : BuildAndSendSliceConfigReq 
2006  *
2007  *    Functionality: Fill the slice configration and rrm policy related 
2008  *
2009  * @params[in] RrmPolicy *rrmPolicy[], uint8_t totalRrmPolicy, uint8_t
2010  * totalSliceCnt 
2011  *             
2012  * @return ROK     - success
2013  *         RFAILED - failure
2014  *
2015  * ****************************************************************/
2016 uint8_t BuildAndSendSliceConfigReq(RrmPolicy *rrmPolicy[], uint8_t totalRrmPolicy, uint8_t totalSliceCnt)
2017 {
2018    Pst pst;
2019    MacSliceCfgReq *sliceCfgReq;
2020
2021    DU_ALLOC_SHRABL_BUF(sliceCfgReq, sizeof(MacSliceCfgReq));
2022    if(sliceCfgReq == NULLP)
2023    {
2024       DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed in BuildAndSendSliceConfigReq");
2025       return RFAILED;
2026    }
2027    else
2028    {
2029       if(fillSliceCfgReCfgInfo(sliceCfgReq, rrmPolicy, totalRrmPolicy, totalSliceCnt) != ROK)
2030       {   
2031          DU_LOG("\nERROR  -->  DU_APP : Failed to fill slice Configuration info in MacSliceCfgReq");
2032          return RFAILED;
2033       }
2034       FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_SLICE_CFG_REQ);
2035
2036       DU_LOG("\nDEBUG  -->  DU_APP : Sending Slice Cfg Request to MAC ");
2037       if((*packMacSliceCfgReqOpts[pst.selector])(&pst, sliceCfgReq) == RFAILED)
2038       {
2039          DU_LOG("\nERROR  -->  DU_APP : Failed to send Slice Cfg Req to MAC");
2040          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, sliceCfgReq, sizeof(MacSliceCfgReq));
2041       }
2042    }
2043    return ROK;  
2044 }
2045
2046
2047 /*******************************************************************
2048  *
2049  * @brief Fill the slice configration and rrm policy related
2050  *    information received form O1
2051  *
2052  * @details
2053  *
2054  *    Function : BuildAndSendSliceReCfgReq 
2055  *
2056  *    Functionality: Fill the slice configration and rrm policy related 
2057  *
2058  * @params[in] RrmPolicy rrmPolicy[], uint8_t totalSliceCount 
2059  *             
2060  * @return ROK     - success
2061  *         RFAILED - failure
2062  *
2063  * ****************************************************************/
2064 uint8_t BuildAndSendSliceReCfgReq(RrmPolicy *rrmPolicy[], uint8_t totalRrmPolicy, uint8_t totalSliceCount)
2065 {
2066    Pst pst;
2067    MacSliceCfgReq *sliceReCfgReq = NULLP;
2068    
2069    DU_LOG("\nINFO  --> DU_APP : Slice ReConfiguration Request received");
2070
2071    DU_ALLOC_SHRABL_BUF(sliceReCfgReq, sizeof(MacSliceCfgReq));
2072    if(sliceReCfgReq == NULLP)
2073    {
2074       DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed to BuildAndSendSliceReCfgReq");
2075       return RFAILED;
2076    }
2077    else
2078    {
2079       if(fillSliceCfgReCfgInfo(sliceReCfgReq, rrmPolicy, totalRrmPolicy, totalSliceCount) != ROK)
2080       {
2081          DU_LOG("\nERROR  -->  DU_APP: Failed to fill slice cfg request info");
2082          return RFAILED;
2083       }
2084       FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_SLICE_RECFG_REQ);
2085
2086       DU_LOG("\nDEBUG  -->  DU_APP: Sending Slice ReCfg Request to MAC ");
2087       if( (*packMacSliceReCfgReqOpts[pst.selector])(&pst, sliceReCfgReq) == RFAILED)
2088       {
2089          DU_LOG("\nERROR  -->  DU_APP: Failed to send Slice ReCfg Req to MAC");
2090          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, sliceReCfgReq, sizeof(MacSliceCfgReq));
2091       }
2092    }
2093    return ROK;  
2094 }
2095 /*******************************************************************
2096  *
2097  * @brief process the slice ReCfg rsp received from MAC
2098  *
2099  * @details
2100  *
2101  *    Function : DuProcMacSliceReCfgRsp
2102  *
2103  *    Functionality: process the slice ReCfg rsp received from MAC
2104  *
2105  * @params[in] Post structure, MacSliceCfgRsp  *ReCfgRsp
2106  *             
2107  * @return ROK     - success
2108  *         RFAILED - failure
2109  *
2110  **********************************************************************/
2111 uint8_t DuProcMacSliceReCfgRsp(Pst *pst,  MacSliceCfgRsp *reCfgRsp)
2112 {
2113    uint8_t cfgIdx = 0, sliceIdx =0;
2114    
2115    if(reCfgRsp)
2116    {
2117       if(reCfgRsp->listOfSliceCfgRsp)
2118       {
2119          for(cfgIdx = 0; cfgIdx < reCfgRsp->numSliceCfgRsp; cfgIdx++)
2120          {
2121             if(reCfgRsp->listOfSliceCfgRsp[cfgIdx]->rsp == MAC_DU_APP_RSP_OK)
2122             {
2123                duCb.sliceState = SLICE_RECONFIGURED; 
2124             }
2125             else
2126             {
2127                DU_LOG("\nERROR  -->  DU_APP : Slice not available");
2128             }
2129          }
2130          DU_LOG("\nINFO  --> DU_APP : Slice ReCOnfiguration response received");
2131       }
2132       duFreeSliceCfgRsp(pst, reCfgRsp);
2133    }
2134    duFreeTempSliceCfg();
2135    return ROK;
2136 }
2137
2138 /*******************************************************************
2139 *
2140 * @brief Handles received Slice Metrics from RLC and forward it to O1 
2141 *
2142 * @details
2143 *
2144 *    Function : DuProcRlcSliceMetrics
2145 *
2146 *    Functionality:
2147 *      Handles received Slice Metrics from RLC and forward it to O1
2148 *
2149 * @params[in] Post structure pointer
2150 *              SlicePmList *sliceStats
2151 *
2152 * @return ROK     - success
2153 *         RFAILED - failure
2154 *
2155 * ****************************************************************/
2156 uint8_t DuProcRlcSliceMetrics(Pst *pst, SlicePmList *sliceStats)
2157 {
2158     uint8_t sliceRecord = 0;
2159
2160     DU_LOG("\nDEBUG  -->  DU APP : Received Slice Metrics");
2161     if(sliceStats == NULLP)
2162     {
2163        DU_LOG("\nERROR  -->  DU APP : Empty Metrics");
2164        return RFAILED;
2165     }
2166     
2167     for(sliceRecord = 0; sliceRecord < sliceStats->numSlice; sliceRecord++)
2168     {
2169        DU_LOG("\nINFO   -->  DU_APP: SliceIndx:%d, DlTput %.5lf, UlTput:%.5lf", sliceStats->sliceRecord[sliceRecord].networkSliceIdentifier,\
2170                         sliceStats->sliceRecord[sliceRecord].ThpDl, sliceStats->sliceRecord[sliceRecord].ThpUl);
2171     }
2172 #ifdef O1_ENABLE
2173     if(sliceStats)
2174     {
2175        sendSliceMetric((SliceMetricList*) sliceStats);
2176     }
2177 #endif
2178
2179    DU_FREE_SHRABL_BUF(pst->region, pst->pool,sliceStats->sliceRecord, (sliceStats->numSlice) * (sizeof(SlicePm)));
2180    DU_FREE_SHRABL_BUF(pst->region, pst->pool,sliceStats, sizeof(SlicePmList));
2181
2182    return ROK;
2183 }
2184
2185 /**********************************************************************
2186   End of file
2187  **********************************************************************/