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