c1826e1e40422b447f09d4517730c153c1cca1b0
[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 egtpHdlDatInd(EgtpMsg egtpMsg);
62 uint8_t BuildAndSendDUConfigUpdate();
63 uint16_t getTransId();
64 uint8_t cmPkLrgSchCfgReq(Pst * pst,RgMngmt * cfg);
65 uint8_t sendCellDeleteReqToMac(uint16_t cellId);
66
67 packMacCellCfgReq packMacCellCfgOpts[] =
68 {
69    packMacCellCfg, /* packing for loosely coupled */
70    MacProcCellCfgReq, /* packing for tightly coupled */
71    packMacCellCfg, /* packing for light weight loosly coupled */
72 };
73
74 DuMacCellStart packMacCellStartOpts[] =
75 {
76    packMacCellStart,   /* Loose coupling */
77    MacProcCellStart,   /* TIght coupling */
78    packMacCellStart    /* Light weight-loose coupling */
79 };
80
81 DuMacCellStop packMacCellStopOpts[] =
82 {
83    packMacCellStop,   /* Loose coupling */
84    MacProcCellStop,   /* TIght coupling */
85    packMacCellStop    /* Light weight-loose coupling */
86 };
87
88 DuMacSliceCfgReq packMacSliceCfgReqOpts[] =
89 {
90    packDuMacSliceCfgReq,       /* Loose coupling */
91    MacProcSliceCfgReq,         /* TIght coupling */
92    packDuMacSliceCfgReq        /* Light weight-loose coupling */
93 };
94
95
96 DuMacSliceRecfgReq packMacSliceReCfgReqOpts[] =
97 {
98    packDuMacSliceRecfgReq,       /* Loose coupling */
99    MacProcSliceReCfgReq,         /* TIght coupling */
100    packDuMacSliceRecfgReq        /* Light weight-loose coupling */
101 };
102 /**************************************************************************
103  * @brief Function to fill configs required by RLC
104  *
105  * @details
106  *
107  *      Function : duBuildRlcCfg 
108  * 
109  *      Functionality:
110  *           Initiates general Configs towards RLC 
111  *     
112  * @param[in] Inst  Specifies if RLC UL or RLC DL instance 
113  * @return ROK     - success
114  *         RFAILED - failure
115  *
116  ***************************************************************************/
117 uint8_t duBuildRlcCfg(Inst inst)
118 {
119    RlcMngmt   rlcMngmt;
120    RlcGenCfg  *genCfg = NULLP;
121    Pst pst;
122
123    DU_SET_ZERO(&rlcMngmt, sizeof(RlcMngmt));
124    DU_SET_ZERO(&pst, sizeof(Pst));
125
126    genCfg   = &(rlcMngmt.t.cfg.s.gen);
127
128    /*----------- Fill General Configuration Parameters ---------*/
129    genCfg->maxUe       = duCfgParam.maxUe;
130    genCfg->maxKwuSaps  = 2;
131    genCfg->maxUdxSaps  = 1; 
132    genCfg->rlcMode     = (inst == RLC_UL_INST) ?
133       LKW_RLC_MODE_UL : LKW_RLC_MODE_DL;
134    genCfg->timeRes     = 1; 
135    genCfg->maxRguSaps  = DEFAULT_CELLS;
136
137    /*----------- Fill lmPst
138     * Parameters ---------*/
139    genCfg->lmPst.dstProcId = DU_PROC;
140    genCfg->lmPst.srcProcId = DU_PROC;
141    genCfg->lmPst.dstEnt    = ENTDUAPP;
142    genCfg->lmPst.dstInst   = DU_INST;
143    genCfg->lmPst.srcEnt    = ENTRLC;
144    genCfg->lmPst.srcInst   = inst;
145    genCfg->lmPst.prior     = PRIOR0;
146    genCfg->lmPst.route     = RTESPEC;
147    genCfg->lmPst.region    = (inst == RLC_UL_INST) ?
148       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
149    genCfg->lmPst.pool      = RLC_POOL;
150    genCfg->lmPst.selector  = ODU_SELECTOR_LC;
151
152    /* Fill Header */
153    rlcMngmt.hdr.msgType             = TCFG;
154    rlcMngmt.hdr.msgLen              = 0;
155    rlcMngmt.hdr.entId.ent           = ENTRLC;
156    rlcMngmt.hdr.entId.inst          = (Inst)0;
157    rlcMngmt.hdr.elmId.elmnt         = STGEN;
158    rlcMngmt.hdr.seqNmb              = 0;
159    rlcMngmt.hdr.version             = 0;
160    rlcMngmt.hdr.transId             = 0;
161    rlcMngmt.hdr.response.prior      = PRIOR0;
162    rlcMngmt.hdr.response.route      = RTESPEC;
163    rlcMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
164       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
165    rlcMngmt.hdr.response.mem.pool   = DU_POOL;
166    rlcMngmt.hdr.response.selector   = ODU_SELECTOR_LC;
167
168    /* Fill Pst */
169    pst.selector  = ODU_SELECTOR_LC;
170    pst.srcEnt    = ENTDUAPP;
171    pst.dstEnt    = ENTRLC;
172    pst.dstInst   = inst;
173    pst.dstProcId = DU_PROC;
174    pst.srcProcId = DU_PROC;
175    pst.region    = duCb.init.region;
176
177    DU_LOG("\nDEBUG   -->  DU_APP : RLC Gen Cfg Req sent for inst %d", inst);
178
179    /* Send the request to RLC */
180    packRlcConfigReq(&pst, &rlcMngmt);
181
182    return ROK;
183 }
184
185 /**************************************************************************
186  * @brief Function to fill configs required by RLC
187  *
188  * @details
189  *
190  *      Function : duBuildRlcLsapCfg 
191  * 
192  *      Functionality:
193  *           Initiates general Configs towards RLC 
194  *     
195  * @param[in] Inst  Specifies if RLC UL or RLC DL instance 
196  * @return ROK     - success
197  *         RFAILED - failure
198  *
199  ***************************************************************************/
200 uint8_t duBuildRlcLsapCfg(Ent ent, Inst inst, uint8_t lsapInst)
201 {
202
203    RlcMngmt   rlcMngmt;
204    RlcSapCfg  *lSap = NULLP;
205    Pst        pst;
206
207    DU_SET_ZERO(&rlcMngmt, sizeof(RlcMngmt));
208    DU_SET_ZERO(&pst, sizeof(Pst));
209
210    /* Fill Header */
211    rlcMngmt.hdr.msgType             = TCFG;
212    rlcMngmt.hdr.entId.ent           = ENTRLC;
213    rlcMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
214       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
215
216    rlcMngmt.hdr.response.mem.pool   = RLC_POOL;
217
218    /* Fill Pst */
219    pst.selector  = ODU_SELECTOR_LC;
220    pst.srcEnt    = ENTDUAPP;
221    pst.dstEnt    = ENTRLC;
222    pst.dstProcId = DU_PROC;
223    pst.dstInst   = inst;
224    pst.srcProcId = DU_PROC;
225    pst.region    = duCb.init.region;
226    lSap   = &(rlcMngmt.t.cfg.s.sap);
227
228    lSap->mem.region = (inst == RLC_UL_INST) ?
229       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
230    lSap->mem.pool    = RLC_POOL;
231    lSap->mem.spare   = 0;
232    lSap->bndTmrIntvl = 10;
233    lSap->priority    = PRIOR0;
234    lSap->route       = RTESPEC;
235    if (ent == ENTMAC)
236    {
237       lSap->procId      = DU_PROC;
238       lSap->ent         = ENTMAC;
239       lSap->inst        = lsapInst;
240       lSap->sapId       = lsapInst;      /* SapId will be stored as suId in MAC */
241       lSap->selector    = (inst == RLC_UL_INST) ? ODU_SELECTOR_LWLC : ODU_SELECTOR_TC;
242       rlcMngmt.hdr.elmId.elmnt  = STRGUSAP;
243       DU_LOG("\nDEBUG   -->  DU_APP : RLC MAC Lower Sap Cfg Req sent for inst %d", inst);
244
245    }
246    else
247    {
248       lSap->procId    = DU_PROC;
249       lSap->ent       = ENTRLC;
250       lSap->inst      = (inst == RLC_UL_INST) ?
251          RLC_DL_INST : RLC_UL_INST;
252       lSap->sapId       = 0;
253       lSap->selector = ODU_SELECTOR_LC;
254       rlcMngmt.hdr.elmId.elmnt  = STUDXSAP;
255       DU_LOG("\nDEBUG   -->  DU_APP : RLC DL/UL Lower Sap Cfg Req sent for inst %d", inst);
256    }
257
258    packRlcConfigReq(&pst, &rlcMngmt);
259    return ROK;
260 }
261
262 /**************************************************************************
263  * @brief Function to fill configs required by RLC
264  *
265  * @details
266  *
267  *      Function : duBuildRlcUsapCfg 
268  * 
269  *      Functionality:
270  *           Initiates general Configs towards RLC 
271  *     
272  * @param[in] Inst  Specifies if RLC UL or RLC DL instance 
273  * @return ROK     - success
274  *         RFAILED - failure
275  *
276  ***************************************************************************/
277 uint8_t duBuildRlcUsapCfg(uint8_t elemId, Ent ent, Inst inst)
278 {
279    RlcMngmt   rlcMngmt;
280    RlcSapCfg  *uSap = NULLP;
281    Pst        pst;
282
283    DU_SET_ZERO(&rlcMngmt, sizeof(RlcMngmt));
284    DU_SET_ZERO(&pst, sizeof(Pst));
285
286    uSap   = &(rlcMngmt.t.cfg.s.sap);
287
288    uSap->selector   = ODU_SELECTOR_LC;
289    uSap->mem.region = (inst == RLC_UL_INST) ?
290       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
291    uSap->mem.pool = RLC_POOL;
292    uSap->mem.spare = 0;
293
294    uSap->procId = DU_PROC;
295    uSap->ent = ENTRLC;
296    uSap->sapId = 0;
297
298    uSap->inst = (inst == RLC_UL_INST) ?
299       RLC_DL_INST : RLC_UL_INST;
300    uSap->bndTmrIntvl = 1000;
301    uSap->priority = PRIOR0;
302    uSap->route = RTESPEC;
303
304    /* Fill Header */
305    rlcMngmt.hdr.msgType             = TCFG;
306    rlcMngmt.hdr.entId.ent           = ENTRLC;
307    rlcMngmt.hdr.elmId.elmnt         = STUDXSAP;
308    rlcMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
309       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
310
311    rlcMngmt.hdr.response.mem.pool   = RLC_POOL;
312
313    /* Fill Pst */
314    pst.selector  = ODU_SELECTOR_LC;
315    pst.srcEnt    = ENTDUAPP;
316    pst.dstEnt    = ENTRLC;
317    pst.dstProcId = DU_PROC;
318    pst.dstInst = inst;
319    pst.srcProcId = DU_PROC;
320    pst.region = duCb.init.region;
321
322    DU_LOG("\nDEBUG   -->  DU_APP : RLC Kwu Upper Sap Cfg Req sent for inst %d", inst);
323    packRlcConfigReq(&pst, &rlcMngmt);
324
325    return ROK;
326 }
327
328 /**************************************************************************
329  * @brief Function to populate internal DS of DU APP
330  *
331  * @details
332  *
333  *      Function : duProcCfgComplete
334  * 
335  *      Functionality:
336  *           Populates internal data structures of DU APP after 
337  *           receiving configurations.
338  *     
339  * @param[in]  void
340  * @return ROK     - success
341  *         RFAILED - failure
342  *
343  ***************************************************************************/
344 uint8_t duProcCfgComplete()
345 {
346    uint8_t         ret = ROK;
347    uint16_t        cellId = 0;
348    uint16_t        idx;
349    for(idx=0; idx< DEFAULT_CELLS; idx++)
350    {
351       DuCellCb *cell = NULLP;
352       DU_ALLOC(cell, sizeof(DuCellCb));
353       if(cell == NULLP)
354       {
355          DU_LOG("\nERROR  -->  DU_APP : Memory Allocation failed in duProcCfgComplete");
356          ret = RFAILED;
357       }
358       else
359       {
360          uint8_t idx1=0; 
361          memset(cell, 0, sizeof(DuCellCb));
362          cell->cellId = NR_CELL_ID; //++cellId;
363          memset(&cell->cellInfo.nrEcgi.plmn, 0, sizeof(Plmn));
364          cell->cellInfo.nrEcgi.plmn.mcc[0] = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].plmn.mcc[0];
365          cell->cellInfo.nrEcgi.plmn.mcc[1] = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].plmn.mcc[1];
366          cell->cellInfo.nrEcgi.plmn.mcc[2] = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].plmn.mcc[2];
367          cell->cellInfo.nrEcgi.plmn.mnc[0] = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].plmn.mnc[0];
368          cell->cellInfo.nrEcgi.plmn.mnc[1] = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].plmn.mnc[1];
369          cell->cellInfo.nrEcgi.plmn.mnc[2] = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].plmn.mnc[2];
370          cell->cellInfo.nrEcgi.cellId = cell->cellId;
371          cell->cellInfo.nrPci = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrPci; 
372          cell->cellInfo.fiveGsTac = duCfgParam.srvdCellLst[0].duCellInfo.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] = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].plmn.mcc[0];
377             cell->cellInfo.plmn[idx1].mcc[1] = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].plmn.mcc[1];
378             cell->cellInfo.plmn[idx1].mcc[2] = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].plmn.mcc[2];
379             cell->cellInfo.plmn[idx1].mnc[0] = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].plmn.mnc[0];
380             cell->cellInfo.plmn[idx1].mnc[1] = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].plmn.mnc[1];
381             cell->cellInfo.plmn[idx1].mnc[2] = duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].plmn.mnc[2];
382          }
383          cell->cellInfo.maxUe = duCfgParam.maxUe;
384          cell->cellStatus = CELL_OUT_OF_SERVICE;
385          gCellStatus = CELL_DOWN;
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        return ROK;
988    }
989    else
990    {
991       DU_LOG("\nERROR  -->  DU_APP : Invalid assocId %d received", ntfy->u.assocChange.assocId);
992       return RFAILED;
993    }
994    return ROK;
995 }
996
997 /*******************************************************************
998  *
999  * @brief  Fills Pst struct for ENTEGTP
1000  *
1001  * @details
1002  *
1003  *    Function : duFillEgtpPst
1004  *
1005  *    Functionality:
1006  *       Fills Pst struct for ENTEGTP
1007  *
1008  * @params[in] 
1009  * @return ROK     - success
1010  *         RFAILED - failure
1011  *
1012  * ****************************************************************/
1013 uint8_t duFillEgtpPst(Pst *pst, Event event)
1014 {
1015    memset(pst, 0, sizeof(Pst));
1016    pst->srcEnt = (Ent)ENTDUAPP;
1017    pst->srcInst = (Inst)DU_INST;
1018    pst->srcProcId = DU_PROC;
1019    pst->dstEnt = (Ent)ENTEGTP;
1020    pst->dstInst = (Inst)EGTP_INST;
1021    pst->dstProcId = pst->srcProcId;
1022    pst->event = event;
1023    pst->selector = ODU_SELECTOR_LC;
1024    pst->pool= DU_POOL;
1025
1026    return ROK;
1027 }
1028
1029
1030 /*******************************************************************
1031  *
1032  * @brief  Function to configure EGTP
1033  *
1034  * @details
1035  *
1036  *    Function : duBuildEgtpCfgReq
1037  *
1038  *    Functionality:
1039  *       Function to configure EGTP
1040  *
1041  * @params[in] 
1042  * @return ROK     - success
1043  *         RFAILED - failure
1044  *
1045  * ****************************************************************/
1046
1047 uint8_t duBuildEgtpCfgReq()
1048 {
1049    Pst pst;
1050    EgtpConfig egtpCfg;
1051
1052    DU_LOG("\nDEBUG   -->  DU_APP : Sending EGTP config request");
1053
1054    memset(&egtpCfg, 0, sizeof(EgtpConfig));
1055    memcpy(&egtpCfg, &duCfgParam.egtpParams, sizeof(EgtpConfig));
1056
1057    duFillEgtpPst(&pst, EVTCFGREQ);
1058    packEgtpCfgReq(&pst, egtpCfg);
1059
1060    return ROK;
1061 }
1062
1063 /*******************************************************************
1064  *
1065  * @brief  Function to configure EGTP
1066  *
1067  * @details
1068  *
1069  *    Function : duBuildEgtpCfgReq
1070  *
1071  *    Functionality:
1072  *       Function to configure EGTP
1073  *
1074  * @params[in] 
1075  * @return ROK     - success
1076  *         RFAILED - failure
1077  *
1078  * ****************************************************************/
1079 uint8_t duHdlEgtpCfgComplete(CmStatus cfm)
1080 {
1081    uint8_t ret = ROK;
1082
1083    if(cfm.status == LCM_PRIM_OK)
1084    {
1085       DU_LOG("\nDEBUG   -->  DU_APP : EGTP configuraton complete");
1086       duSendEgtpSrvOpenReq();
1087    }
1088    else
1089    {
1090       DU_LOG("\nERROR  -->  DU_APP : EGTP configuraton failed");
1091       ret = RFAILED;
1092    }
1093
1094    return (ret);
1095 }
1096
1097 /*******************************************************************
1098  *
1099  * @brief  Sends server open request to EGTP
1100  *
1101  * @details
1102  *
1103  *    Function : duSendEgtpSrvOpenReq
1104  *
1105  *    Functionality:
1106  *       Sends server open request to EGTP
1107  *
1108  * @params[in] 
1109  * @return ROK     - success
1110  *         RFAILED - failure
1111  *
1112  * ****************************************************************/
1113
1114 uint8_t duSendEgtpSrvOpenReq()
1115 {
1116    Pst pst;
1117
1118    DU_LOG("\nDEBUG   -->  DU_APP : Sending EGTP server open request");
1119
1120    duFillEgtpPst(&pst, EVTSRVOPENREQ);
1121    packEgtpSrvOpenReq(&pst);
1122
1123    return ROK;
1124 }
1125
1126 /*******************************************************************
1127  *
1128  * @brief Handles server open confirmation
1129  *
1130  * @details
1131  *
1132  *    Function : duHdlEgtpSrvOpenComplete
1133  *
1134  *    Functionality:
1135  *        Handles server open confirmation
1136  *
1137  * @params[in] 
1138  * @return ROK     - success
1139  *         RFAILED - failure
1140  *
1141  *****************************************************************/
1142
1143 uint8_t duHdlEgtpSrvOpenComplete(CmStatus cfm)
1144 {
1145    uint8_t ret = ROK;
1146
1147    if(cfm.status == LCM_PRIM_OK)
1148    {
1149       DU_LOG("\nDEBUG   -->  DU_APP : EGTP server opened successfully");
1150    }
1151    else
1152    {
1153       DU_LOG("\nERROR  -->  DU_APP : EGTP server opening failed");
1154       ret = RFAILED;
1155    }
1156
1157    return (ret);
1158 }
1159
1160 /*******************************************************************
1161  *
1162  * @brief Sends tunnel management request
1163  *
1164  * @details
1165  *
1166  *    Function : duSendEgtpTnlMgmtReq 
1167  *
1168  *    Functionality:
1169  *        Builds and sends tunnel management request to EGTP
1170  *
1171  * @params[in] Action
1172  *             Local tunnel endpoint id
1173  *             Remote tunnel endpoint id 
1174  * @return ROK     - success
1175  *         RFAILED - failure
1176  *
1177  * ****************************************************************/
1178
1179 uint8_t duSendEgtpTnlMgmtReq(uint8_t action, uint32_t teIdTobeMod, GtpTnlCfg *ueCbTnlCfg)
1180 {
1181    uint8_t ret =ROK;
1182    Pst pst;
1183    EgtpTnlEvt tnlEvt;
1184
1185    DU_LOG("\nDEBUG   -->  DU_APP : Sending EGTP tunnel management request for teId [%d]", ueCbTnlCfg->teId);
1186
1187    /* ADD/MOD/DEL per tunnel */
1188    tnlEvt.action = action;
1189    tnlEvt.remTeid = ueCbTnlCfg->teId;
1190    if(action != EGTP_TNL_MGMT_ADD)
1191    {
1192       tnlEvt.lclTeid = teIdTobeMod;
1193    }
1194    else
1195    {
1196       tnlEvt.lclTeid = ueCbTnlCfg->teId;
1197    }
1198    duFillEgtpPst(&pst, EVTTNLMGMTREQ);
1199    ret = egtpTnlMgmtReq(&pst, tnlEvt);
1200    return ret;
1201 }
1202
1203 /*******************************************************************
1204  *
1205  * @brief Handles Tunnel management confirm 
1206  *
1207  * @details
1208  *
1209  *    Function : duHdlEgtpTnlMgmtCfm
1210  *
1211  *    Functionality:
1212  *      Handles tunnel management confirm received from Egtp
1213  *
1214  * @params[in] Tunnel Event  
1215  * @return ROK     - success
1216  *         RFAILED - failure
1217  *
1218  * ****************************************************************/
1219 uint8_t duHdlEgtpTnlMgmtCfm(EgtpTnlEvt tnlEvtCfm)
1220 {
1221    uint8_t ret = ROK;
1222
1223    if(tnlEvtCfm.cfmStatus.status == LCM_PRIM_OK)
1224    {
1225       DU_LOG("\nDEBUG  -->  DU_APP: Tunnel management confirm OK");
1226    }
1227    else
1228    {
1229       DU_LOG("\nERROR  -->  DU_APP: Tunnel management failed");
1230       ret = RFAILED;
1231    }
1232
1233    return (ret);
1234 }
1235
1236 /*******************************************************************
1237  *
1238  * @brief Sends UL user data over to EGTP
1239  *
1240  * @details
1241  *
1242  *    Function : duSendEgtpDatInd
1243  *
1244  *    Functionality: Sends UL user data over to EGTP
1245  *
1246  * @params[in] UL data buffer
1247  * @return ROK     - success
1248  *         RFAILED - failure
1249  *
1250  * ****************************************************************/
1251 uint8_t duSendEgtpDatInd(Buffer *mBuf)
1252 {
1253    EgtpMsg  egtpMsg;
1254
1255    /* Fill EGTP header */
1256    egtpMsg.msgHdr.msgType = EGTPU_MSG_GPDU;
1257    egtpMsg.msgHdr.nPdu.pres = FALSE;
1258    egtpMsg.msgHdr.seqNum.pres = FALSE;
1259    egtpMsg.msgHdr.extHdr.udpPort.pres = FALSE;
1260    egtpMsg.msgHdr.extHdr.pdcpNmb.pres = FALSE;
1261    egtpMsg.msgHdr.teId = 1;
1262    egtpMsg.msg = mBuf;
1263    
1264    egtpHdlDatInd(egtpMsg);
1265
1266    return ROK;
1267
1268 }
1269
1270 /**************************************************************************
1271  * @brief Function to send configs to SCH
1272  *
1273  * @details
1274  *
1275  *      Function : duSendSchCfg 
1276  * 
1277  *      Functionality:
1278  *           Sends general config to Scheduler via MAC layer
1279  *     
1280  * @param[in]  void
1281  * @return ROK     - success
1282  *         RFAILED - failure
1283  *
1284  ***************************************************************************/
1285 uint8_t duSendSchCfg()
1286 {
1287    RgMngmt       rgMngmt;
1288    RgSchInstCfg  *cfg = NULLP;
1289    Pst           pst;
1290
1291    DU_SET_ZERO(&pst, sizeof(Pst));
1292    DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
1293
1294    cfg = &(rgMngmt.t.cfg.s.schInstCfg);
1295
1296    /* Filling of Instance Id */
1297    cfg->instId = DEFAULT_CELLS + 1;
1298    /* Filling of Gen config */
1299    cfg->genCfg.mem.region = MAC_MEM_REGION;
1300    cfg->genCfg.mem.pool = MAC_POOL;
1301    cfg->genCfg.tmrRes = 10;
1302
1303 #ifdef LTE_ADV
1304    cfg->genCfg.forceCntrlSrbBoOnPCel = FALSE;
1305    cfg->genCfg.isSCellActDeactAlgoEnable = TRUE;
1306 #endif/*LTE_ADV*/
1307    cfg->genCfg.startCellId     = 1;
1308    cfg->genCfg.lmPst.dstProcId = DU_PROC;
1309    cfg->genCfg.lmPst.srcProcId = DU_PROC;
1310    cfg->genCfg.lmPst.dstEnt    = ENTDUAPP;
1311    cfg->genCfg.lmPst.dstInst   = DU_INST;
1312    cfg->genCfg.lmPst.srcEnt    = ENTMAC;
1313    cfg->genCfg.lmPst.srcInst   = DEFAULT_CELLS + 1;
1314    cfg->genCfg.lmPst.prior     = PRIOR0;
1315    cfg->genCfg.lmPst.route     = RTESPEC;
1316    cfg->genCfg.lmPst.region    = MAC_MEM_REGION;
1317    cfg->genCfg.lmPst.pool      = MAC_POOL;
1318    cfg->genCfg.lmPst.selector  = ODU_SELECTOR_LC;
1319
1320    /* Fill Header */
1321    rgMngmt.hdr.msgType             = TCFG;
1322    rgMngmt.hdr.entId.ent           = ENTMAC;
1323    rgMngmt.hdr.entId.inst          = DU_INST;
1324    rgMngmt.hdr.elmId.elmnt         = STSCHINST;
1325    rgMngmt.hdr.response.mem.region = MAC_MEM_REGION;
1326    rgMngmt.hdr.response.mem.pool   = MAC_POOL;
1327
1328    /* Fill Pst */
1329    pst.selector  = ODU_SELECTOR_LC;
1330    pst.srcEnt    = ENTDUAPP;
1331    pst.dstEnt    = ENTMAC;
1332    pst.dstProcId = DU_PROC;
1333    pst.srcProcId = DU_PROC;
1334    pst.srcInst   = DU_INST;
1335    pst.dstInst   = 0;
1336    pst.region    = duCb.init.region;
1337    pst.event    = (Event) EVTMACSCHGENCFGREQ;
1338
1339    DU_LOG("\nDEBUG   -->  DU_APP : MAC Sch Cfg sent");
1340
1341    /* Send the request to MAC */
1342    cmPkLrgSchCfgReq(&pst, &rgMngmt);
1343
1344    return ROK;
1345 }
1346
1347
1348 /**************************************************************************
1349  * @brief Function to configure SCTP params and 
1350  *  responsible for F1 and E2 interfaces
1351  *
1352  * @details
1353  *
1354  *      Function : duLayerConfigComplete
1355  * 
1356  *      Functionality:
1357  *           Configures SCTP Params and responsible for handling
1358  *           F1 and E2 interface.
1359  *     
1360  * @param[in]  void
1361  * @return ROK     - success
1362  *         RFAILED - failure
1363  *
1364  ***************************************************************************/
1365 uint8_t duLayerConfigComplete()
1366 {
1367    uint8_t ret = ROK;
1368
1369    DU_LOG("\nINFO   -->  DU_APP : Configuring all Layer is complete");
1370
1371    if((ret = duSctpCfgReq(duCfgParam.sctpParams)) != ROK)
1372    {
1373       DU_LOG("\nERROR  -->  DU_APP : Failed configuring Sctp Params");
1374       ret = RFAILED;
1375    }
1376    if((ret = duSctpAssocReq(F1_INTERFACE)) != ROK)
1377    {
1378       DU_LOG("\nERROR  -->  DU_APP : Failed to send AssocReq F1");
1379       ret = RFAILED;
1380    }
1381    if((ret = duSctpAssocReq(E2_INTERFACE)) != ROK)
1382    {
1383       DU_LOG("\nERROR  -->  DU_APP : Failed to send AssocReq E2");
1384       ret = RFAILED;
1385    }
1386
1387    return (ret); 
1388
1389
1390 /**************************************************************************
1391  * @brief Function to handle  SCH Config Confirm from MAC
1392  *
1393  * @details
1394  *
1395  *      Function : duHdlSchCfgComplete 
1396  * 
1397  *      Functionality:
1398  *           Handles Scheduler Gen Config Confirm from MAC
1399  *     
1400  * @param[in]  Pst     *pst, Post structure of the primitive.     
1401  * @param[in]  RgMngmt *cfm, Unpacked primitive info received from MAC
1402  * @return ROK     - success
1403  *         RFAILED - failure
1404  *
1405  ***************************************************************************/
1406 uint8_t duHdlSchCfgComplete(Pst *pst, RgMngmt *cfm)
1407 {
1408    if (cfm->cfm.status == LCM_PRIM_OK)
1409    {
1410       switch (cfm->hdr.elmId.elmnt)
1411       {
1412          case STSCHINST:
1413             {
1414                DU_LOG("\nDEBUG   -->  DU_APP : Received SCH CFG CFM at DU APP");
1415                break;
1416             }
1417          default:
1418             break;
1419       }
1420    }
1421    duLayerConfigComplete();
1422    duBuildEgtpCfgReq();
1423    return ROK;
1424 }
1425
1426 /**************************************************************************
1427  * @brief Function to fill and send MacCellconfig
1428  *
1429  * @details
1430  *
1431  *      Function : duBuildAndSendMacCellCfg 
1432  * 
1433  *      Functionality:
1434  *           Initiates MAC Configs towards MAC
1435  *     
1436  * @param[in]cell id
1437  * @return ROK     - success
1438  *         RFAILED - failure
1439  *
1440  ***************************************************************************/
1441 uint8_t duBuildAndSendMacCellCfg(uint16_t cellId)
1442 {
1443    Pst pst;
1444    MacCellCfg *duMacCellCfg = NULLP;
1445
1446    DU_ALLOC_SHRABL_BUF(duMacCellCfg, sizeof(MacCellCfg));
1447    if(duMacCellCfg == NULLP)
1448    {
1449       return RFAILED;
1450    }
1451
1452    /* store the address in the duCellCb so that we can free on confirm msg */
1453    if(duCb.actvCellLst[cellId-1])
1454       duCb.actvCellLst[cellId-1]->duMacCellCfg = duMacCellCfg;
1455    else
1456    {
1457       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, duMacCellCfg, sizeof(MacCellCfg));
1458       return RFAILED;
1459    }
1460
1461    /* copy the mac config structure from duCfgParams */
1462    memcpy(duMacCellCfg,&duCfgParam.macCellCfg,sizeof(MacCellCfg));
1463
1464    /* Fill Pst */
1465    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_CONFIG_REQ);
1466
1467    /* Send MAC cell config to MAC */
1468    return (*packMacCellCfgOpts[pst.selector])(&pst, duMacCellCfg);
1469 }
1470
1471 /**************************************************************************
1472  * @brief Function to Handle MAC cell config confirm
1473  *
1474  * @details
1475  *
1476  *      Function : duHandleMacCellCfgCfm 
1477  * 
1478  *      Functionality:
1479  *           Initiates general Configs towards MAC
1480  *     
1481  * @param[in] void
1482  * @return ROK     - success
1483  *         RFAILED - failure
1484  *
1485  ***************************************************************************/
1486 uint8_t  duHandleMacCellCfgCfm(Pst *pst, MacCellCfgCfm *macCellCfgCfm)
1487 {
1488    uint8_t  actvCellIdx  = 0;
1489    uint8_t  ret          = ROK;
1490
1491    for(actvCellIdx = 0; actvCellIdx < MAX_NUM_CELL; actvCellIdx++)
1492    {
1493       if((duCb.actvCellLst[actvCellIdx]) && (macCellCfgCfm->cellId == duCb.actvCellLst[actvCellIdx]->cellId))
1494       {
1495          duCb.actvCellLst[actvCellIdx]->duMacCellCfg = NULLP;
1496       }
1497    }
1498    if(macCellCfgCfm->rsp == ROK)
1499    {
1500       /* Build and send GNB-DU config update */
1501       ret = BuildAndSendDUConfigUpdate(SERV_CELL_TO_MODIFY);
1502
1503       /* Build and Send Cell Start Req to MAC */
1504       ret = duBuildAndSendMacCellStart();
1505    }
1506    else
1507    {
1508       /* TODO : Action to be taken if cell configuration fails. 
1509        * Should CU be informed? */
1510
1511       DU_LOG("\nERROR  -->  DU_APP : Mac cell cfg failed");
1512       ret = RFAILED;
1513    }
1514    return ret;
1515 }
1516
1517 /*******************************************************************
1518  *
1519  * @brief Builds and sends cell start request to MAC
1520  *
1521  * @details
1522  *
1523  *    Function : duBuildAndSendMacCellStart
1524  *
1525  *    Functionality:
1526  *       Builds and sends cell start request to MAC
1527  *
1528  * @params[in] 
1529  * @return ROK     - success
1530  *         RFAILED - failure
1531  *
1532  * ****************************************************************/
1533 uint8_t duBuildAndSendMacCellStart()
1534 {
1535    Pst pst;
1536    OduCellId *cellId = NULL;
1537
1538    DU_LOG("\nINFO   -->  DU APP : Building and Sending cell start request to MAC");
1539
1540    /* Send Cell Start Request to MAC */
1541    DU_ALLOC_SHRABL_BUF(cellId, sizeof(OduCellId));
1542    if(!cellId)
1543    {
1544       DU_LOG("\nERROR  -->  DU APP : Memory alloc failed while building cell start request");
1545       return RFAILED;
1546    }
1547
1548    for(uint8_t id = 0; id < MAX_NUM_CELL; id++) 
1549    {
1550       if(duCb.actvCellLst[id])
1551       {
1552          cellId->cellId = duCb.actvCellLst[id]->cellId;
1553
1554          /* Fill Pst */
1555          FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_START);
1556
1557          return (*packMacCellStartOpts[pst.selector])(&pst, cellId);
1558       }
1559    }
1560    return ROK;
1561 }
1562
1563 /*******************************************************************
1564  *
1565  * @brief Builds and sends cell stop request to MAC
1566  *
1567  * @details
1568  *
1569  *    Function : duBuildAndSendMacCellStop 
1570  *
1571  *    Functionality:
1572  *       Builds and sends cell stop request to MAC
1573  *
1574  * @params[in] 
1575  * @return ROK     - success
1576  *         RFAILED - failure
1577  *
1578  * ****************************************************************/
1579 uint8_t duBuildAndSendMacCellStop(uint16_t cellId)
1580 {
1581    Pst pst;
1582    uint16_t cellIdx=0;
1583    OduCellId *oduCellId = NULL;
1584    
1585    DU_LOG("\nINFO   -->  DU APP : Building and Sending cell stop request to MAC");
1586
1587    GET_CELL_IDX(cellId, cellIdx);
1588    if(duCb.actvCellLst[cellIdx] != NULLP)
1589    {
1590       /* Send Cell Stop Request to MAC */
1591       DU_ALLOC_SHRABL_BUF(oduCellId, sizeof(OduCellId));
1592       if(!oduCellId)
1593       {
1594          DU_LOG("\nERROR  -->  DU APP : duBuildAndSendMacCellStop():  Memory allocation failed ");
1595          return RFAILED;
1596       }
1597       memset(oduCellId, 0, sizeof(OduCellId));
1598       oduCellId->cellId = duCb.actvCellLst[cellIdx]->cellId;
1599
1600       /* Fill Pst */
1601       FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_STOP);
1602
1603       return (*packMacCellStopOpts[pst.selector])(&pst, oduCellId);
1604    }
1605    else
1606    {
1607       DU_LOG("\nERROR  -->  DU APP : duBuildAndSendMacCellStop(): cellId[%d] doesnot exists", cellId);
1608       return RFAILED;
1609    }
1610    return ROK;
1611 }
1612
1613 /*******************************************************************
1614  *
1615  * @brief Handles stop indication from MAC
1616  *
1617  * @details
1618  *
1619  *    Function : duHandleStopInd
1620  *
1621  *    Functionality:
1622  *      Handles stop indication from MAC
1623  *
1624  * @params[in] Post structure pointer
1625  * @return ROK     - success
1626  *         RFAILED - failure
1627  *
1628  * ****************************************************************/
1629 uint8_t duHandleStopInd(Pst *pst, OduCellId *cellId)
1630 {
1631    DuCellCb *cellCb = NULLP;
1632
1633    if(cellId->cellId <=0 || cellId->cellId > MAX_NUM_CELL)
1634    {
1635       DU_LOG("\nERROR  -->  DU APP : Invalid Cell Id %d in duHandleStopInd()", cellId->cellId);
1636    }
1637
1638    if(duGetCellCb(cellId->cellId, &cellCb) != ROK)
1639       return RFAILED;
1640
1641    if((cellCb->cellStatus == ACTIVATED) || (cellCb->cellStatus == DELETION_IN_PROGRESS))
1642    {
1643       DU_LOG("\nINFO   -->  DU APP : 5G-NR Cell %d is DOWN", cellId->cellId);
1644       if(sendCellDeleteReqToMac(cellId->cellId) == RFAILED)
1645       {
1646          DU_LOG("\nERROR  -->  DU APP : duHandleStopInd(): Failed to send Cell delete req to MAC for\
1647                cellId[%d]", cellId->cellId);
1648          return RFAILED;
1649       }
1650
1651
1652 #ifdef O1_ENABLE
1653       DU_LOG("\nINFO   -->  DU APP : Raise cell down alarm for cell id=%d", cellId->cellId);
1654       raiseCellAlrm(CELL_DOWN_ALARM_ID, cellId->cellId);
1655       setCellOpState(cellId->cellId, DISABLED, INACTIVE);
1656 #endif
1657    }
1658
1659    if((pst->selector == ODU_SELECTOR_LWLC) || (pst->selector == ODU_SELECTOR_TC))
1660       DU_FREE_SHRABL_BUF(MAC_MEM_REGION, pst->pool, cellId, sizeof(OduCellId));
1661
1662    cellCb->cellStatus = CELL_OUT_OF_SERVICE; //TODO: cell status must be set to OOS after all UE and cell cleanup which is not
1663                                              //supported now
1664
1665    return ROK;
1666 }
1667
1668 /*******************************************************************
1669  *
1670  * @brief Handles slot indication from MAC
1671  *
1672  * @details
1673  *
1674  *    Function : duHandleUlCcchInd
1675  *
1676  *    Functionality:
1677  *      Handles UL CCCH indication from MAC
1678  *
1679  * @params[in] Post structure pointer
1680  *             UL CCCH Ind pointer
1681  * @return ROK     - success
1682  *         RFAILED - failure
1683  *
1684  * ****************************************************************/
1685 uint8_t duHandleUlCcchInd(Pst *pst, UlCcchIndInfo *ulCcchIndInfo)
1686 {
1687
1688    DU_LOG("\nINFO  -->  DU APP : UL CCCH Indication received");
1689
1690    return (duProcUlCcchInd(ulCcchIndInfo));
1691 }
1692
1693 /*******************************************************************
1694  *
1695  * @brief Process UL RRC Message from RLC
1696  *
1697  * @details
1698  *
1699  *    Function : DuProcRlcUlRrcMsgTrans
1700  *
1701  *    Functionality: Process UL RRC Message from RLC
1702  *
1703  * @params[in] Post structure
1704  *             UL RRC Message Info
1705  * @return ROK     - success
1706  *         RFAILED - failure
1707  *
1708  * ****************************************************************/
1709 uint8_t DuProcRlcUlRrcMsgTrans(Pst *pst, RlcUlRrcMsgInfo *ulRrcMsgInfo)
1710 {
1711    DuCellCb *cellCb = NULLP;
1712    DuUeCb   ueCb ={0};
1713   
1714    if(duGetCellCb(ulRrcMsgInfo->cellId, &cellCb) != ROK)
1715       return RFAILED;
1716    if(ulRrcMsgInfo->ueId > 0)
1717    {
1718    ueCb = cellCb->ueCb[ulRrcMsgInfo->ueId -1];
1719
1720
1721    BuildAndSendULRRCMessageTransfer(ueCb, ulRrcMsgInfo->lcId, ulRrcMsgInfo->msgLen, ulRrcMsgInfo->rrcMsg);
1722
1723    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulRrcMsgInfo->rrcMsg, ulRrcMsgInfo->msgLen);
1724    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulRrcMsgInfo, sizeof(RlcUlRrcMsgInfo));
1725    }
1726    return ROK;
1727 }
1728
1729 /*******************************************************************
1730 *
1731 * @brief Process RRC delivery report from RLC
1732 *
1733 * @details
1734 *
1735 *    Function : DuProcRlcRrcDeliveryReport
1736 *
1737 *    Functionality: Process RRC delivery Message from RLC
1738 *
1739 * @params[in] Post structure
1740 *             UL RRC Message Info
1741 * @return ROK     - success
1742 *         RFAILED - failure
1743 *
1744 * ****************************************************************/
1745 uint8_t DuProcRlcRrcDeliveryReport(Pst *pst, RrcDeliveryReport *rrcDeliveryReport)
1746 {
1747    DuCellCb *cellCb = NULLP;
1748    DuUeCb   ueCb;
1749    uint8_t  ret = RFAILED;
1750
1751    if(duGetCellCb(rrcDeliveryReport->cellId, &cellCb) != ROK)
1752       return RFAILED;
1753    
1754    ueCb = cellCb->ueCb[rrcDeliveryReport->ueId -1];
1755    ret = BuildAndSendRrcDeliveryReport(ueCb.gnbCuUeF1apId, ueCb.gnbDuUeF1apId,rrcDeliveryReport);
1756
1757    DU_FREE_SHRABL_BUF(pst->region, pst->pool, rrcDeliveryReport, sizeof(RrcDeliveryReport));
1758    return ret;
1759 }
1760
1761 /*******************************************************************
1762  *
1763  * @brief Process UL user data from RLC
1764  *
1765  * @details
1766  *
1767  *    Function : DuProcRlcUlUserDataTrans
1768  *
1769  *    Functionality: Process UL user data from RLC
1770  *
1771  * @params[in] Post structure
1772  *             UL user data
1773  * @return ROK     - success
1774  *         RFAILED - failure
1775  *
1776  * ****************************************************************/
1777 uint8_t DuProcRlcUlUserDataTrans(Pst *pst, RlcUlUserDatInfo *ulUserData)
1778 {
1779    uint8_t  teIdx = 0;
1780    EgtpMsg  egtpMsg;
1781    Buffer   *mBuf;
1782
1783    DU_LOG("\nDEBUG  -->  DU APP : Received UL user data");
1784
1785    /* Fill EGTP header */
1786    egtpMsg.msgHdr.msgType = EGTPU_MSG_GPDU;
1787    egtpMsg.msgHdr.nPdu.pres = FALSE;
1788    egtpMsg.msgHdr.seqNum.pres = FALSE;
1789    egtpMsg.msgHdr.extHdr.udpPort.pres = FALSE;
1790    egtpMsg.msgHdr.extHdr.pdcpNmb.pres = FALSE;
1791
1792    /* Fetch EGTP tunnel info */
1793    for(teIdx = 0; teIdx < duCb.numTeId; teIdx++)
1794    {
1795       /*TODO: If multiple Cell Support is enables then CellId also needs to be validated alongwith ueId and DrbId*/
1796       if((duCb.upTnlCfg[teIdx] != NULLP) && (duCb.upTnlCfg[teIdx]->ueId == ulUserData->ueId) && \
1797          (duCb.upTnlCfg[teIdx]->drbId == ulUserData->rbId))
1798       {
1799          if(duCb.upTnlCfg[teIdx]->tnlCfg1)
1800          {
1801             egtpMsg.msgHdr.teId = duCb.upTnlCfg[teIdx]->tnlCfg1->teId; /*As we are supporting only 1 tunnel per DRB*/
1802             break;
1803          }
1804       }
1805    }
1806
1807    if (ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) != ROK)
1808    {
1809       DU_LOG("\nERROR  -->  DU APP : Failed to allocated buffer memory in DuProcRlcUlUserDataTrans");
1810       DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulUserData->userData, ulUserData->msgLen);
1811       DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulUserData, sizeof(RlcUlUserDatInfo));
1812       return RFAILED;
1813    }
1814    oduCpyFixBufToMsg(ulUserData->userData, mBuf, ulUserData->msgLen);
1815    ODU_PRINT_MSG(mBuf, 0, 0);
1816    egtpMsg.msg = mBuf;
1817    egtpHdlDatInd(egtpMsg);
1818
1819    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulUserData->userData, ulUserData->msgLen);
1820    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulUserData, sizeof(RlcUlUserDatInfo));
1821    return ROK;
1822 }
1823
1824 /*******************************************************************
1825  *
1826  * @brief Free tempSLiceCfg stored in duCfgParams
1827  *
1828  * @details
1829  *
1830  *    Function :  duFreeTempSliceCfg
1831  *
1832  *    Functionality: Free tempSLiceCfg stored in duCfgParams 
1833  *
1834  * @params[in] Post structure, 
1835  *             
1836  * @return Void
1837  *
1838  * ****************************************************************/
1839
1840 void duFreeTempSliceCfg()
1841 {
1842     uint8_t policyIdx = 0, memberListTdx =0;
1843     CopyOfRecvdSliceCfg *tempSliceCfg = &duCfgParam.tempSliceCfg;
1844     
1845     if(tempSliceCfg->totalRrmPolicy)
1846     {
1847        for(policyIdx = 0; policyIdx<tempSliceCfg->totalRrmPolicy; policyIdx++)
1848        {
1849           if(tempSliceCfg->rrmPolicy[policyIdx]->numMemberList)
1850           {
1851              for(memberListTdx = 0; memberListTdx<tempSliceCfg->rrmPolicy[policyIdx]->numMemberList; memberListTdx++)
1852              {
1853                  DU_FREE(tempSliceCfg->rrmPolicy[policyIdx]->memberList[memberListTdx], sizeof(PolicyMemberList));
1854              }
1855              DU_FREE(tempSliceCfg->rrmPolicy[policyIdx]->memberList, (tempSliceCfg->rrmPolicy[policyIdx]->numMemberList) * sizeof(PolicyMemberList*));
1856           }
1857           DU_FREE(tempSliceCfg->rrmPolicy[policyIdx], sizeof(RrmPolicy));
1858        }
1859        DU_FREE(tempSliceCfg->rrmPolicy, tempSliceCfg->totalRrmPolicy* sizeof(RrmPolicy*));
1860     }
1861     memset(tempSliceCfg, 0, sizeof(CopyOfRecvdSliceCfg));
1862 }
1863
1864 /*******************************************************************
1865  *
1866  * @brief  free the slice cfg rsp
1867  *
1868  * @details
1869  *
1870  *    Function : duFreeSliceCfgRsp 
1871  *
1872  *    Functionality: free the slice cfg rsp 
1873  *
1874  * @params[in] Post structure, MacSliceCfgRsp  *cfgRsp
1875  *             
1876  * @return ROK     - success
1877  *         RFAILED - failure
1878  *
1879  **********************************************************************/
1880 void duFreeSliceCfgRsp(Pst *pst,  MacSliceCfgRsp *cfgRsp) 
1881 {
1882    uint8_t cfgIdx;
1883
1884    if(cfgRsp)
1885    {
1886       if(cfgRsp->numSliceCfgRsp)
1887       {
1888          for(cfgIdx = 0; cfgIdx<cfgRsp->numSliceCfgRsp; cfgIdx++)
1889          {
1890             DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp->listOfSliceCfgRsp[cfgIdx], sizeof(MacSliceRsp)); 
1891          }
1892          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp->listOfSliceCfgRsp, cfgRsp->numSliceCfgRsp * sizeof(MacSliceRsp*)); 
1893       }
1894       DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(MacSliceCfgRsp)); 
1895    }
1896 }
1897
1898 /*******************************************************************
1899  *
1900  * @brief process the slice cfg rsp received from MAC
1901  *
1902  * @details
1903  *
1904  *    Function : DuProcMacSliceCfgRsp
1905  *
1906  *    Functionality: process the slice cfg rsp received from MAC
1907  *
1908  * @params[in] Post structure, MacSliceCfgRsp  *cfgRsp
1909  *             
1910  * @return ROK     - success
1911  *         RFAILED - failure
1912  *
1913  **********************************************************************/
1914 uint8_t DuProcMacSliceCfgRsp(Pst *pst,  MacSliceCfgRsp *cfgRsp)
1915 {
1916     uint8_t cfgIdx = 0;
1917     
1918     if(cfgRsp)
1919     {
1920         if(cfgRsp->listOfSliceCfgRsp)
1921         {
1922             for(cfgIdx = 0; cfgIdx<cfgRsp->numSliceCfgRsp; cfgIdx++)
1923             {
1924                 if(cfgRsp->listOfSliceCfgRsp[cfgIdx]->rsp ==  MAC_DU_APP_RSP_OK)
1925                 {
1926                     duCb.sliceState = SLICE_CONFIGURED;
1927                 }
1928             }
1929             DU_LOG("\nINFO  -->  DU_APP : Slice Configuration is done sucessfully ");
1930         }
1931         duFreeSliceCfgRsp(pst, cfgRsp);
1932     }
1933     duFreeTempSliceCfg();
1934     return ROK;
1935 }
1936
1937 /*******************************************************************
1938  *
1939  * @brief Fill the slice configration and rrm policy ratio 
1940  *    information received form O1
1941  *
1942  * @details
1943  *
1944  *    Function : fillSliceCfgReCfgInfo 
1945  *
1946  *    Functionality: Fill the slice configration and recfg info 
1947  *
1948  * @params[in] Post structure
1949  *             
1950  * @return ROK     - success
1951  *         RFAILED - failure
1952  *
1953  * ****************************************************************/
1954
1955 uint8_t fillSliceCfgReCfgInfo(MacSliceCfgReq *sliceCfgReq, RrmPolicy *rrmPolicy[], uint8_t totalRrmPolicy, uint8_t totalSliceCount)
1956 {
1957    uint8_t sliceIdx = 0, cfgIdx = 0, memberListIdx = 0;
1958    
1959    if(totalRrmPolicy)
1960    {
1961       DU_ALLOC_SHRABL_BUF(sliceCfgReq->listOfSliceCfg, totalSliceCount*sizeof(MacSliceRrmPolicy*)); 
1962       if(sliceCfgReq->listOfSliceCfg == NULLP)
1963       {
1964          DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed in fillSliceCfgReCfgInfo");
1965          return RFAILED;
1966       }
1967
1968       for(sliceIdx = 0; sliceIdx<totalRrmPolicy; sliceIdx++)
1969       {
1970          for(memberListIdx = 0; memberListIdx<rrmPolicy[sliceIdx]->numMemberList; memberListIdx++)
1971          {
1972             DU_ALLOC_SHRABL_BUF(sliceCfgReq->listOfSliceCfg[cfgIdx], sizeof(MacSliceRrmPolicy));
1973             if(sliceCfgReq->listOfSliceCfg[cfgIdx] == NULLP)
1974             { 
1975                DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed in fillSliceCfgReCfgInfo");
1976                return RFAILED;
1977             }
1978
1979
1980             memcpy(&sliceCfgReq->listOfSliceCfg[cfgIdx]->snssai, &rrmPolicy[sliceIdx]->memberList[memberListIdx]->snssai, sizeof(Snssai));
1981
1982             DU_ALLOC_SHRABL_BUF(sliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio, sizeof(RrmPolicyRatio));
1983             if(sliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio == NULLP)
1984             { 
1985                DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed in fillSliceCfgReCfgInfo");
1986                return RFAILED;
1987             }
1988
1989             sliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyMaxRatio = rrmPolicy[sliceIdx]->policyMaxRatio;
1990             sliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyMinRatio = rrmPolicy[sliceIdx]->policyMinRatio;
1991             sliceCfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio->policyDedicatedRatio = rrmPolicy[sliceIdx]->policyDedicatedRatio; 
1992             sliceCfgReq->numOfConfiguredSlice++;
1993             cfgIdx++;
1994          }
1995       }
1996    }
1997    return ROK;
1998 }
1999
2000 /*******************************************************************
2001  *
2002  * @brief Fill the slice configration and rrm policy related
2003  *    information received form O1
2004  *
2005  * @details
2006  *
2007  *    Function : BuildAndSendSliceConfigReq 
2008  *
2009  *    Functionality: Fill the slice configration and rrm policy related 
2010  *
2011  * @params[in] RrmPolicy *rrmPolicy[], uint8_t totalRrmPolicy, uint8_t
2012  * totalSliceCnt 
2013  *             
2014  * @return ROK     - success
2015  *         RFAILED - failure
2016  *
2017  * ****************************************************************/
2018 uint8_t BuildAndSendSliceConfigReq(RrmPolicy *rrmPolicy[], uint8_t totalRrmPolicy, uint8_t totalSliceCnt)
2019 {
2020    Pst pst;
2021    MacSliceCfgReq *sliceCfgReq;
2022
2023    DU_ALLOC_SHRABL_BUF(sliceCfgReq, sizeof(MacSliceCfgReq));
2024    if(sliceCfgReq == NULLP)
2025    {
2026       DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed in BuildAndSendSliceConfigReq");
2027       return RFAILED;
2028    }
2029    else
2030    {
2031       if(fillSliceCfgReCfgInfo(sliceCfgReq, rrmPolicy, totalRrmPolicy, totalSliceCnt) != ROK)
2032       {   
2033          DU_LOG("\nERROR  -->  DU_APP : Failed to fill slice Configuration info in MacSliceCfgReq");
2034          return RFAILED;
2035       }
2036       FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_SLICE_CFG_REQ);
2037
2038       DU_LOG("\nDEBUG  -->  DU_APP : Sending Slice Cfg Request to MAC ");
2039       if((*packMacSliceCfgReqOpts[pst.selector])(&pst, sliceCfgReq) == RFAILED)
2040       {
2041          DU_LOG("\nERROR  -->  DU_APP : Failed to send Slice Cfg Req to MAC");
2042          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, sliceCfgReq, sizeof(MacSliceCfgReq));
2043       }
2044    }
2045    return ROK;  
2046 }
2047
2048
2049 /*******************************************************************
2050  *
2051  * @brief Fill the slice configration and rrm policy related
2052  *    information received form O1
2053  *
2054  * @details
2055  *
2056  *    Function : BuildAndSendSliceReCfgReq 
2057  *
2058  *    Functionality: Fill the slice configration and rrm policy related 
2059  *
2060  * @params[in] RrmPolicy rrmPolicy[], uint8_t totalSliceCount 
2061  *             
2062  * @return ROK     - success
2063  *         RFAILED - failure
2064  *
2065  * ****************************************************************/
2066 uint8_t BuildAndSendSliceReCfgReq(RrmPolicy *rrmPolicy[], uint8_t totalRrmPolicy, uint8_t totalSliceCount)
2067 {
2068    Pst pst;
2069    MacSliceCfgReq *sliceReCfgReq = NULLP;
2070    
2071    DU_LOG("\nINFO  --> DU_APP : Slice ReConfiguration Request received");
2072
2073    DU_ALLOC_SHRABL_BUF(sliceReCfgReq, sizeof(MacSliceCfgReq));
2074    if(sliceReCfgReq == NULLP)
2075    {
2076       DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed to BuildAndSendSliceReCfgReq");
2077       return RFAILED;
2078    }
2079    else
2080    {
2081       if(fillSliceCfgReCfgInfo(sliceReCfgReq, rrmPolicy, totalRrmPolicy, totalSliceCount) != ROK)
2082       {
2083          DU_LOG("\nERROR  -->  DU_APP: Failed to fill slice cfg request info");
2084          return RFAILED;
2085       }
2086       FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_SLICE_RECFG_REQ);
2087
2088       DU_LOG("\nDEBUG  -->  DU_APP: Sending Slice ReCfg Request to MAC ");
2089       if( (*packMacSliceReCfgReqOpts[pst.selector])(&pst, sliceReCfgReq) == RFAILED)
2090       {
2091          DU_LOG("\nERROR  -->  DU_APP: Failed to send Slice ReCfg Req to MAC");
2092          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, sliceReCfgReq, sizeof(MacSliceCfgReq));
2093       }
2094    }
2095    return ROK;  
2096 }
2097 /*******************************************************************
2098  *
2099  * @brief process the slice ReCfg rsp received from MAC
2100  *
2101  * @details
2102  *
2103  *    Function : DuProcMacSliceReCfgRsp
2104  *
2105  *    Functionality: process the slice ReCfg rsp received from MAC
2106  *
2107  * @params[in] Post structure, MacSliceCfgRsp  *ReCfgRsp
2108  *             
2109  * @return ROK     - success
2110  *         RFAILED - failure
2111  *
2112  **********************************************************************/
2113 uint8_t DuProcMacSliceReCfgRsp(Pst *pst,  MacSliceCfgRsp *reCfgRsp)
2114 {
2115    uint8_t cfgIdx = 0;
2116
2117    if(reCfgRsp)
2118    {
2119       if(reCfgRsp->listOfSliceCfgRsp)
2120       {
2121          for(cfgIdx = 0; cfgIdx < reCfgRsp->numSliceCfgRsp; cfgIdx++)
2122          {
2123             if(reCfgRsp->listOfSliceCfgRsp[cfgIdx]->rsp == MAC_DU_APP_RSP_OK)
2124             {
2125                duCb.sliceState = SLICE_RECONFIGURED; 
2126             }
2127             else
2128             {
2129                DU_LOG("\nERROR  -->  DU_APP : Slice not available");
2130             }
2131          }
2132          DU_LOG("\nINFO  --> DU_APP : Slice ReCOnfiguration response received");
2133       }
2134       duFreeSliceCfgRsp(pst, reCfgRsp);
2135    }
2136    duFreeTempSliceCfg();
2137    return ROK;
2138 }
2139
2140 /*******************************************************************
2141 *
2142 * @brief Handles received Slice Metrics from RLC and forward it to O1 
2143 *
2144 * @details
2145 *
2146 *    Function : DuProcRlcSliceMetrics
2147 *
2148 *    Functionality:
2149 *      Handles received Slice Metrics from RLC and forward it to O1
2150 *
2151 * @params[in] Post structure pointer
2152 *              SlicePmList *sliceStats
2153 *
2154 * @return ROK     - success
2155 *         RFAILED - failure
2156 *
2157 * ****************************************************************/
2158 uint8_t DuProcRlcSliceMetrics(Pst *pst, SlicePmList *sliceStats)
2159 {
2160     uint8_t sliceRecord = 0;
2161
2162     DU_LOG("\nDEBUG  -->  DU APP : Received Slice Metrics");
2163     if(sliceStats == NULLP)
2164     {
2165        DU_LOG("\nERROR  -->  DU APP : Empty Metrics");
2166        return RFAILED;
2167     }
2168     
2169     for(sliceRecord = 0; sliceRecord < sliceStats->numSlice; sliceRecord++)
2170     {
2171        DU_LOG("\nINFO   -->  DU_APP: SliceIndx:%d, DlTput %.5lf, UlTput:%.5lf", sliceStats->sliceRecord[sliceRecord].networkSliceIdentifier,\
2172                         sliceStats->sliceRecord[sliceRecord].ThpDl, sliceStats->sliceRecord[sliceRecord].ThpUl);
2173     }
2174 #ifdef O1_ENABLE
2175     if(sliceStats)
2176     {
2177        sendSliceMetric((SliceMetricList*) sliceStats);
2178     }
2179 #endif
2180
2181    DU_FREE_SHRABL_BUF(pst->region, pst->pool,sliceStats->sliceRecord, (sliceStats->numSlice) * (sizeof(SlicePm)));
2182    DU_FREE_SHRABL_BUF(pst->region, pst->pool,sliceStats, sizeof(SlicePmList));
2183
2184    return ROK;
2185 }
2186
2187 /**********************************************************************
2188   End of file
2189  **********************************************************************/