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