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