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