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