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