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