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