Removed EGTP_TEST flag and Modified algorithm for pumping DL data [Issue-ID: ODUHIGH...
[o-du/l2.git] / src / du_app / du_msg_hdl.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /* This file contains message handling functionality for DU APP */
20 #include "common_def.h"
21 #include "lrg.h"
22 #include "legtp.h"
23 #include "lkw.h"
24 #include "kwu.h"
25 #include "lrg.x"
26 #include "lkw.x"
27 #include "kwu.x"
28 #include "du_app_mac_inf.h"
29 #include "du_app_rlc_inf.h"
30 #include "du_cfg.h"
31 #include "du_app_rlc_inf.h"
32 #include "du_mgr.h"
33 #include "du_sctp.h"
34 #include "F1AP-PDU.h"
35 #include "du_f1ap_msg_hdl.h"
36 #include "du_ue_mgr.h"
37 #include "lsctp.h"
38 #include "legtp.h"
39 #include "du_utils.h"
40 #include "du_cell_mgr.h" 
41
42 #ifdef O1_ENABLE
43
44 #include "AlarmInterface.h"
45 #include "ConfigInterface.h"
46
47 #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 uint8_t sendCellDeleteReqToMac(uint16_t cellId);
66
67 packMacCellCfgReq packMacCellCfgOpts[] =
68 {
69    packMacCellCfg, /* packing for loosely coupled */
70    MacProcCellCfgReq, /* packing for tightly coupled */
71    packMacCellCfg, /* packing for light weight loosly coupled */
72 };
73
74 DuMacCellStart packMacCellStartOpts[] =
75 {
76    packMacCellStart,   /* Loose coupling */
77    MacProcCellStart,   /* TIght coupling */
78    packMacCellStart    /* Light weight-loose coupling */
79 };
80
81 DuMacCellStop packMacCellStopOpts[] =
82 {
83    packMacCellStop,   /* Loose coupling */
84    MacProcCellStop,   /* TIght coupling */
85    packMacCellStop    /* Light weight-loose coupling */
86 };
87
88 /**************************************************************************
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    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 = cell->cellId;
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          cell->gnbDuUeF1apIdGenerator = 0;
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       duSendEgtpSrvOpenReq();
1075    }
1076    else
1077    {
1078       DU_LOG("\nERROR  -->  DU_APP : EGTP configuraton failed");
1079       ret = RFAILED;
1080    }
1081
1082    return (ret);
1083 }
1084
1085 /*******************************************************************
1086  *
1087  * @brief  Sends server open request to EGTP
1088  *
1089  * @details
1090  *
1091  *    Function : duSendEgtpSrvOpenReq
1092  *
1093  *    Functionality:
1094  *       Sends server open request to EGTP
1095  *
1096  * @params[in] 
1097  * @return ROK     - success
1098  *         RFAILED - failure
1099  *
1100  * ****************************************************************/
1101
1102 uint8_t duSendEgtpSrvOpenReq()
1103 {
1104    Pst pst;
1105
1106    DU_LOG("\nDEBUG   -->  DU_APP : Sending EGTP server open request");
1107
1108    duFillEgtpPst(&pst, EVTSRVOPENREQ);
1109    packEgtpSrvOpenReq(&pst);
1110
1111    return ROK;
1112 }
1113
1114 /*******************************************************************
1115  *
1116  * @brief Handles server open confirmation
1117  *
1118  * @details
1119  *
1120  *    Function : duHdlEgtpSrvOpenComplete
1121  *
1122  *    Functionality:
1123  *        Handles server open confirmation
1124  *
1125  * @params[in] 
1126  * @return ROK     - success
1127  *         RFAILED - failure
1128  *
1129  *****************************************************************/
1130
1131 uint8_t duHdlEgtpSrvOpenComplete(CmStatus cfm)
1132 {
1133    uint8_t ret = ROK;
1134
1135    if(cfm.status == LCM_PRIM_OK)
1136    {
1137       DU_LOG("\nDEBUG   -->  DU_APP : EGTP server opened successfully");
1138    }
1139    else
1140    {
1141       DU_LOG("\nERROR  -->  DU_APP : EGTP server opening failed");
1142       ret = RFAILED;
1143    }
1144
1145    return (ret);
1146 }
1147
1148 /*******************************************************************
1149  *
1150  * @brief Sends tunnel management request
1151  *
1152  * @details
1153  *
1154  *    Function : duSendEgtpTnlMgmtReq 
1155  *
1156  *    Functionality:
1157  *        Builds and sends tunnel management request to EGTP
1158  *
1159  * @params[in] Action
1160  *             Local tunnel endpoint id
1161  *             Remote tunnel endpoint id 
1162  * @return ROK     - success
1163  *         RFAILED - failure
1164  *
1165  * ****************************************************************/
1166
1167 uint8_t duSendEgtpTnlMgmtReq(uint8_t action, uint32_t teIdTobeMod, GtpTnlCfg *ueCbTnlCfg)
1168 {
1169    uint8_t ret =ROK;
1170    Pst pst;
1171    EgtpTnlEvt tnlEvt;
1172
1173    DU_LOG("\nDEBUG   -->  DU_APP : Sending EGTP tunnel management request for teId [%d]", ueCbTnlCfg->teId);
1174
1175    /* ADD/MOD/DEL per tunnel */
1176    tnlEvt.action = action;
1177    tnlEvt.remTeid = ueCbTnlCfg->teId;
1178    if(action != EGTP_TNL_MGMT_ADD)
1179    {
1180       tnlEvt.lclTeid = teIdTobeMod;
1181    }
1182    else
1183    {
1184       tnlEvt.lclTeid = ueCbTnlCfg->teId;
1185    }
1186    duFillEgtpPst(&pst, EVTTNLMGMTREQ);
1187    ret = egtpTnlMgmtReq(&pst, tnlEvt);
1188    return ret;
1189 }
1190
1191 /*******************************************************************
1192  *
1193  * @brief Handles Tunnel management confirm 
1194  *
1195  * @details
1196  *
1197  *    Function : duHdlEgtpTnlMgmtCfm
1198  *
1199  *    Functionality:
1200  *      Handles tunnel management confirm received from Egtp
1201  *
1202  * @params[in] Tunnel Event  
1203  * @return ROK     - success
1204  *         RFAILED - failure
1205  *
1206  * ****************************************************************/
1207 uint8_t duHdlEgtpTnlMgmtCfm(EgtpTnlEvt tnlEvtCfm)
1208 {
1209    uint8_t ret = ROK;
1210
1211    if(tnlEvtCfm.cfmStatus.status == LCM_PRIM_OK)
1212    {
1213       DU_LOG("\nDEBUG  -->  DU_APP: Tunnel management confirm OK");
1214    }
1215    else
1216    {
1217       DU_LOG("\nERROR  -->  DU_APP: Tunnel management failed");
1218       ret = RFAILED;
1219    }
1220
1221    return (ret);
1222 }
1223
1224 /*******************************************************************
1225  *
1226  * @brief Sends UL user data over to EGTP
1227  *
1228  * @details
1229  *
1230  *    Function : duSendEgtpDatInd
1231  *
1232  *    Functionality: Sends UL user data over to EGTP
1233  *
1234  * @params[in] UL data buffer
1235  * @return ROK     - success
1236  *         RFAILED - failure
1237  *
1238  * ****************************************************************/
1239 uint8_t duSendEgtpDatInd(Buffer *mBuf)
1240 {
1241    EgtpMsg  egtpMsg;
1242
1243    /* Fill EGTP header */
1244    egtpMsg.msgHdr.msgType = EGTPU_MSG_GPDU;
1245    egtpMsg.msgHdr.nPdu.pres = FALSE;
1246    egtpMsg.msgHdr.seqNum.pres = FALSE;
1247    egtpMsg.msgHdr.extHdr.udpPort.pres = FALSE;
1248    egtpMsg.msgHdr.extHdr.pdcpNmb.pres = FALSE;
1249    egtpMsg.msgHdr.teId = 1;
1250    egtpMsg.msg = mBuf;
1251
1252    egtpHdlDatInd(egtpMsg);
1253
1254    return ROK;
1255
1256 }
1257
1258 /**************************************************************************
1259  * @brief Function to send configs to SCH
1260  *
1261  * @details
1262  *
1263  *      Function : duSendSchCfg 
1264  * 
1265  *      Functionality:
1266  *           Sends general config to Scheduler via MAC layer
1267  *     
1268  * @param[in]  void
1269  * @return ROK     - success
1270  *         RFAILED - failure
1271  *
1272  ***************************************************************************/
1273 uint8_t duSendSchCfg()
1274 {
1275    RgMngmt       rgMngmt;
1276    RgSchInstCfg  *cfg = NULLP;
1277    Pst           pst;
1278
1279    DU_SET_ZERO(&pst, sizeof(Pst));
1280    DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
1281
1282    cfg = &(rgMngmt.t.cfg.s.schInstCfg);
1283
1284    /* Filling of Instance Id */
1285    cfg->instId = DEFAULT_CELLS + 1;
1286    /* Filling of Gen config */
1287    cfg->genCfg.mem.region = MAC_MEM_REGION;
1288    cfg->genCfg.mem.pool = MAC_POOL;
1289    cfg->genCfg.tmrRes = 10;
1290
1291 #ifdef LTE_ADV
1292    cfg->genCfg.forceCntrlSrbBoOnPCel = FALSE;
1293    cfg->genCfg.isSCellActDeactAlgoEnable = TRUE;
1294 #endif/*LTE_ADV*/
1295    cfg->genCfg.startCellId     = 1;
1296    cfg->genCfg.lmPst.dstProcId = DU_PROC;
1297    cfg->genCfg.lmPst.srcProcId = DU_PROC;
1298    cfg->genCfg.lmPst.dstEnt    = ENTDUAPP;
1299    cfg->genCfg.lmPst.dstInst   = DU_INST;
1300    cfg->genCfg.lmPst.srcEnt    = ENTMAC;
1301    cfg->genCfg.lmPst.srcInst   = DEFAULT_CELLS + 1;
1302    cfg->genCfg.lmPst.prior     = PRIOR0;
1303    cfg->genCfg.lmPst.route     = RTESPEC;
1304    cfg->genCfg.lmPst.region    = MAC_MEM_REGION;
1305    cfg->genCfg.lmPst.pool      = MAC_POOL;
1306    cfg->genCfg.lmPst.selector  = ODU_SELECTOR_LC;
1307
1308    /* Fill Header */
1309    rgMngmt.hdr.msgType             = TCFG;
1310    rgMngmt.hdr.entId.ent           = ENTMAC;
1311    rgMngmt.hdr.entId.inst          = DU_INST;
1312    rgMngmt.hdr.elmId.elmnt         = STSCHINST;
1313    rgMngmt.hdr.response.mem.region = MAC_MEM_REGION;
1314    rgMngmt.hdr.response.mem.pool   = MAC_POOL;
1315
1316    /* Fill Pst */
1317    pst.selector  = ODU_SELECTOR_LC;
1318    pst.srcEnt    = ENTDUAPP;
1319    pst.dstEnt    = ENTMAC;
1320    pst.dstProcId = DU_PROC;
1321    pst.srcProcId = DU_PROC;
1322    pst.srcInst   = DU_INST;
1323    pst.dstInst   = 0;
1324    pst.region    = duCb.init.region;
1325    pst.event    = (Event) EVTMACSCHGENCFGREQ;
1326
1327    DU_LOG("\nDEBUG   -->  DU_APP : MAC Sch Cfg sent");
1328
1329    /* Send the request to MAC */
1330    cmPkLrgSchCfgReq(&pst, &rgMngmt);
1331
1332    return ROK;
1333 }
1334
1335
1336 /**************************************************************************
1337  * @brief Function to configure SCTP params and 
1338  *  responsible for F1 and E2 interfaces
1339  *
1340  * @details
1341  *
1342  *      Function : duLayerConfigComplete
1343  * 
1344  *      Functionality:
1345  *           Configures SCTP Params and responsible for handling
1346  *           F1 and E2 interface.
1347  *     
1348  * @param[in]  void
1349  * @return ROK     - success
1350  *         RFAILED - failure
1351  *
1352  ***************************************************************************/
1353 uint8_t duLayerConfigComplete()
1354 {
1355    uint8_t ret = ROK;
1356
1357    DU_LOG("\nINFO   -->  DU_APP : Configuring all Layer is complete");
1358
1359    if((ret = duSctpCfgReq(duCfgParam.sctpParams)) != ROK)
1360    {
1361       DU_LOG("\nERROR  -->  DU_APP : Failed configuring Sctp Params");
1362       ret = RFAILED;
1363    }
1364    if((ret = duSctpAssocReq(F1_INTERFACE)) != ROK)
1365    {
1366       DU_LOG("\nERROR  -->  DU_APP : Failed to send AssocReq F1");
1367       ret = RFAILED;
1368    }
1369    if((ret = duSctpAssocReq(E2_INTERFACE)) != ROK)
1370    {
1371       DU_LOG("\nERROR  -->  DU_APP : Failed to send AssocReq E2");
1372       ret = RFAILED;
1373    }
1374
1375    return (ret); 
1376
1377
1378 /**************************************************************************
1379  * @brief Function to handle  SCH Config Confirm from MAC
1380  *
1381  * @details
1382  *
1383  *      Function : duHdlSchCfgComplete 
1384  * 
1385  *      Functionality:
1386  *           Handles Scheduler Gen Config Confirm from MAC
1387  *     
1388  * @param[in]  Pst     *pst, Post structure of the primitive.     
1389  * @param[in]  RgMngmt *cfm, Unpacked primitive info received from MAC
1390  * @return ROK     - success
1391  *         RFAILED - failure
1392  *
1393  ***************************************************************************/
1394 uint8_t duHdlSchCfgComplete(Pst *pst, RgMngmt *cfm)
1395 {
1396    if (cfm->cfm.status == LCM_PRIM_OK)
1397    {
1398       switch (cfm->hdr.elmId.elmnt)
1399       {
1400          case STSCHINST:
1401             {
1402                DU_LOG("\nDEBUG   -->  DU_APP : Received SCH CFG CFM at DU APP");
1403                break;
1404             }
1405          default:
1406             break;
1407       }
1408    }
1409    duLayerConfigComplete();
1410    duBuildEgtpCfgReq();
1411    return ROK;
1412 }
1413
1414 /**************************************************************************
1415  * @brief Function to fill and send MacCellconfig
1416  *
1417  * @details
1418  *
1419  *      Function : duBuildAndSendMacCellCfg 
1420  * 
1421  *      Functionality:
1422  *           Initiates MAC Configs towards MAC
1423  *     
1424  * @param[in]cell id
1425  * @return ROK     - success
1426  *         RFAILED - failure
1427  *
1428  ***************************************************************************/
1429 uint8_t duBuildAndSendMacCellCfg(uint16_t cellId)
1430 {
1431    Pst pst;
1432    MacCellCfg *duMacCellCfg = NULLP;
1433
1434    DU_ALLOC_SHRABL_BUF(duMacCellCfg, sizeof(MacCellCfg));
1435    if(duMacCellCfg == NULLP)
1436    {
1437       return RFAILED;
1438    }
1439
1440    /* store the address in the duCellCb so that we can free on confirm msg */
1441    duCb.actvCellLst[cellId-1]->duMacCellCfg = duMacCellCfg;
1442
1443    /* copy the mac config structure from duCfgParams */
1444    memcpy(duMacCellCfg,&duCfgParam.macCellCfg,sizeof(MacCellCfg));
1445
1446    /* Fill Pst */
1447    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_CONFIG_REQ);
1448
1449    /* Send MAC cell config to MAC */
1450    return (*packMacCellCfgOpts[pst.selector])(&pst, duMacCellCfg);
1451 }
1452
1453 /**************************************************************************
1454  * @brief Function to Handle MAC cell config confirm
1455  *
1456  * @details
1457  *
1458  *      Function : duHandleMacCellCfgCfm 
1459  * 
1460  *      Functionality:
1461  *           Initiates general Configs towards MAC
1462  *     
1463  * @param[in] void
1464  * @return ROK     - success
1465  *         RFAILED - failure
1466  *
1467  ***************************************************************************/
1468 uint8_t  duHandleMacCellCfgCfm(Pst *pst, MacCellCfgCfm *macCellCfgCfm)
1469 {
1470    uint8_t  actvCellIdx  = 0;
1471    uint8_t  ret          = ROK;
1472
1473    for(actvCellIdx = 0; actvCellIdx < MAX_NUM_CELL; actvCellIdx++)
1474    {
1475       if(macCellCfgCfm->cellId == duCb.actvCellLst[actvCellIdx]->cellId)
1476       {
1477          duCb.actvCellLst[actvCellIdx]->duMacCellCfg = NULLP;
1478       }
1479    }
1480    if(macCellCfgCfm->rsp == ROK)
1481    {
1482       /* Build and send GNB-DU config update */
1483       ret = BuildAndSendDUConfigUpdate(SERV_CELL_TO_MODIFY);
1484
1485       /* Build and Send Cell Start Req to MAC */
1486       ret = duBuildAndSendMacCellStart();
1487    }
1488    else
1489    {
1490       /* TODO : Action to be taken if cell configuration fails. 
1491        * Should CU be informed? */
1492
1493       DU_LOG("\nERROR  -->  DU_APP : Mac cell cfg failed");
1494       ret = RFAILED;
1495    }
1496    return ret;
1497 }
1498
1499 /*******************************************************************
1500  *
1501  * @brief Builds and sends cell start request to MAC
1502  *
1503  * @details
1504  *
1505  *    Function : duBuildAndSendMacCellStart
1506  *
1507  *    Functionality:
1508  *       Builds and sends cell start request to MAC
1509  *
1510  * @params[in] 
1511  * @return ROK     - success
1512  *         RFAILED - failure
1513  *
1514  * ****************************************************************/
1515 uint8_t duBuildAndSendMacCellStart()
1516 {
1517    Pst pst;
1518    OduCellId *cellId = NULL;
1519
1520    DU_LOG("\nINFO   -->  DU APP : Building and Sending cell start request to MAC");
1521
1522    /* Send Cell Start Request to MAC */
1523    DU_ALLOC_SHRABL_BUF(cellId, sizeof(OduCellId));
1524    if(!cellId)
1525    {
1526       DU_LOG("\nERROR  -->  DU APP : Memory alloc failed while building cell start request");
1527       return RFAILED;
1528    }
1529
1530    for(uint8_t id = 0; id < duCb.numActvCells; id++) 
1531    {
1532       if(duCb.actvCellLst[id])
1533       {
1534          cellId->cellId = duCb.actvCellLst[id]->cellId;
1535
1536          /* Fill Pst */
1537          FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_START);
1538
1539          return (*packMacCellStartOpts[pst.selector])(&pst, cellId);
1540       }
1541    }
1542    return ROK;
1543 }
1544
1545 /*******************************************************************
1546  *
1547  * @brief Builds and sends cell stop request to MAC
1548  *
1549  * @details
1550  *
1551  *    Function : duBuildAndSendMacCellStop 
1552  *
1553  *    Functionality:
1554  *       Builds and sends cell stop request to MAC
1555  *
1556  * @params[in] 
1557  * @return ROK     - success
1558  *         RFAILED - failure
1559  *
1560  * ****************************************************************/
1561 uint8_t duBuildAndSendMacCellStop(uint16_t cellId)
1562 {
1563    Pst pst;
1564    uint16_t cellIdx=0;
1565    OduCellId *oduCellId = NULL;
1566    
1567    DU_LOG("\nINFO   -->  DU APP : Building and Sending cell stop request to MAC");
1568
1569    GET_CELL_IDX(cellId, cellIdx);
1570    if(duCb.actvCellLst[cellIdx] != NULLP)
1571    {
1572       /* Send Cell Stop Request to MAC */
1573       DU_ALLOC_SHRABL_BUF(oduCellId, sizeof(OduCellId));
1574       if(!oduCellId)
1575       {
1576          DU_LOG("\nERROR  -->  DU APP : duBuildAndSendMacCellStop():  Memory allocation failed ");
1577          return RFAILED;
1578       }
1579       memset(oduCellId, 0, sizeof(OduCellId));
1580       oduCellId->cellId = duCb.actvCellLst[cellIdx]->cellId;
1581
1582       /* Fill Pst */
1583       FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_STOP);
1584
1585       return (*packMacCellStopOpts[pst.selector])(&pst, oduCellId);
1586    }
1587    else
1588    {
1589       DU_LOG("\nERROR  -->  DU APP : duBuildAndSendMacCellStop(): cellId[%d] doesnot exists", cellId);
1590       return RFAILED;
1591    }
1592    return ROK;
1593 }
1594
1595 /*******************************************************************
1596  *
1597  * @brief Handles stop indication from MAC
1598  *
1599  * @details
1600  *
1601  *    Function : duHandleStopInd
1602  *
1603  *    Functionality:
1604  *      Handles stop indication from MAC
1605  *
1606  * @params[in] Post structure pointer
1607  * @return ROK     - success
1608  *         RFAILED - failure
1609  *
1610  * ****************************************************************/
1611 uint8_t duHandleStopInd(Pst *pst, OduCellId *cellId)
1612 {
1613    DuCellCb *cellCb = NULLP;
1614
1615    if(cellId->cellId <=0 || cellId->cellId > MAX_NUM_CELL)
1616    {
1617       DU_LOG("\nERROR  -->  DU APP : Invalid Cell Id %d in duHandleStopInd()", cellId->cellId);
1618    }
1619
1620    if(duGetCellCb(cellId->cellId, &cellCb) != ROK)
1621       return RFAILED;
1622
1623    if((cellCb->cellStatus == ACTIVATED) || (cellCb->cellStatus == DELETION_IN_PROGRESS))
1624    {
1625       DU_LOG("\nINFO   -->  DU APP : 5G-NR Cell %d is DOWN", cellId->cellId);
1626       if(sendCellDeleteReqToMac(cellId->cellId) == RFAILED)
1627       {
1628          DU_LOG("\nERROR  -->  DU APP : duHandleStopInd(): Failed to send Cell delete req to MAC for\
1629                cellId[%d]", cellId->cellId);
1630          return RFAILED;
1631       }
1632
1633
1634 #ifdef O1_ENABLE
1635       DU_LOG("\nINFO   -->  DU APP : Raise cell down alarm for cell id=%d", cellId->cellId);
1636       raiseCellAlrm(CELL_DOWN_ALARM_ID, cellId->cellId);
1637       setCellOpState(cellId->cellId, DISABLED, INACTIVE);
1638 #endif
1639    }
1640
1641    if((pst->selector == ODU_SELECTOR_LWLC) || (pst->selector == ODU_SELECTOR_TC))
1642       DU_FREE_SHRABL_BUF(MAC_MEM_REGION, pst->pool, cellId, sizeof(OduCellId));
1643
1644    cellCb->cellStatus = CELL_OUT_OF_SERVICE; //TODO: cell status must be set to OOS after all UE and cell cleanup which is not
1645                                              //supported now
1646
1647    return ROK;
1648 }
1649
1650 /*******************************************************************
1651  *
1652  * @brief Handles slot indication from MAC
1653  *
1654  * @details
1655  *
1656  *    Function : duHandleUlCcchInd
1657  *
1658  *    Functionality:
1659  *      Handles UL CCCH indication from MAC
1660  *
1661  * @params[in] Post structure pointer
1662  *             UL CCCH Ind pointer
1663  * @return ROK     - success
1664  *         RFAILED - failure
1665  *
1666  * ****************************************************************/
1667 uint8_t duHandleUlCcchInd(Pst *pst, UlCcchIndInfo *ulCcchIndInfo)
1668 {
1669
1670    DU_LOG("\nINFO  -->  DU APP : UL CCCH Indication received");
1671
1672    return (duProcUlCcchInd(ulCcchIndInfo));
1673 }
1674
1675 /*******************************************************************
1676  *
1677  * @brief Process UL RRC Message from RLC
1678  *
1679  * @details
1680  *
1681  *    Function : DuProcRlcUlRrcMsgTrans
1682  *
1683  *    Functionality: Process UL RRC Message from RLC
1684  *
1685  * @params[in] Post structure
1686  *             UL RRC Message Info
1687  * @return ROK     - success
1688  *         RFAILED - failure
1689  *
1690  * ****************************************************************/
1691 uint8_t DuProcRlcUlRrcMsgTrans(Pst *pst, RlcUlRrcMsgInfo *ulRrcMsgInfo)
1692 {
1693    DuCellCb *cellCb = NULLP;
1694    DuUeCb   ueCb ={0};
1695   
1696    if(duGetCellCb(ulRrcMsgInfo->cellId, &cellCb) != ROK)
1697       return RFAILED;
1698    if(ulRrcMsgInfo->ueIdx > 0)
1699    {
1700    ueCb = cellCb->ueCb[ulRrcMsgInfo->ueIdx -1];
1701
1702
1703    BuildAndSendULRRCMessageTransfer(ueCb, ulRrcMsgInfo->lcId, ulRrcMsgInfo->msgLen, \
1704       ulRrcMsgInfo->rrcMsg);
1705
1706    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulRrcMsgInfo->rrcMsg, ulRrcMsgInfo->msgLen);
1707    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulRrcMsgInfo, sizeof(RlcUlRrcMsgInfo));
1708    }
1709    return ROK;
1710 }
1711
1712 /*******************************************************************
1713 *
1714 * @brief Process RRC delivery report from RLC
1715 *
1716 * @details
1717 *
1718 *    Function : DuProcRlcRrcDeliveryReport
1719 *
1720 *    Functionality: Process RRC delivery Message from RLC
1721 *
1722 * @params[in] Post structure
1723 *             UL RRC Message Info
1724 * @return ROK     - success
1725 *         RFAILED - failure
1726 *
1727 * ****************************************************************/
1728 uint8_t DuProcRlcRrcDeliveryReport(Pst *pst, RrcDeliveryReport *rrcDeliveryReport)
1729 {
1730    DuCellCb *cellCb = NULLP;
1731    DuUeCb   ueCb;
1732    uint8_t  ret = RFAILED;
1733
1734    if(duGetCellCb(rrcDeliveryReport->cellId, &cellCb) != ROK)
1735       return RFAILED;
1736    
1737    ueCb = cellCb->ueCb[rrcDeliveryReport->ueIdx -1];
1738    ret = BuildAndSendRrcDeliveryReport(ueCb.gnbCuUeF1apId, ueCb.gnbDuUeF1apId,rrcDeliveryReport);
1739
1740    DU_FREE_SHRABL_BUF(pst->region, pst->pool, rrcDeliveryReport, sizeof(RrcDeliveryReport));
1741    return ret;
1742 }
1743
1744 /*******************************************************************
1745  *
1746  * @brief Process UL user data from RLC
1747  *
1748  * @details
1749  *
1750  *    Function : DuProcRlcUlUserDataTrans
1751  *
1752  *    Functionality: Process UL user data from RLC
1753  *
1754  * @params[in] Post structure
1755  *             UL user data
1756  * @return ROK     - success
1757  *         RFAILED - failure
1758  *
1759  * ****************************************************************/
1760 uint8_t DuProcRlcUlUserDataTrans(Pst *pst, RlcUlUserDatInfo *ulUserData)
1761 {
1762    uint8_t  rbIdx;
1763    EgtpMsg  egtpMsg;
1764    Buffer   *mBuf;
1765
1766    DU_LOG("\nDEBUG  -->  DU APP : Received UL user data");
1767
1768    /* Fill EGTP header */
1769    egtpMsg.msgHdr.msgType = EGTPU_MSG_GPDU;
1770    egtpMsg.msgHdr.nPdu.pres = FALSE;
1771    egtpMsg.msgHdr.seqNum.pres = FALSE;
1772    egtpMsg.msgHdr.extHdr.udpPort.pres = FALSE;
1773    egtpMsg.msgHdr.extHdr.pdcpNmb.pres = FALSE;
1774
1775    /* Fetch EGTP tunnel info */
1776    for(rbIdx = 0; rbIdx < duCb.numDrb; rbIdx++)
1777    {
1778       if((duCb.upTnlCfg[rbIdx] != NULLP) && (duCb.upTnlCfg[rbIdx]->drbId == ulUserData->rbId))
1779       {
1780          if(duCb.upTnlCfg[rbIdx]->tnlCfg1)
1781          {
1782             egtpMsg.msgHdr.teId = duCb.upTnlCfg[rbIdx]->tnlCfg1->teId; /*As we are supporting only 1 tunnel per DRB*/
1783             break;
1784          }
1785       }
1786    }
1787
1788    if (ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) != ROK)
1789    {
1790       DU_LOG("\nERROR  -->  DU APP : Failed to allocated buffer memory in DuProcRlcUlUserDataTrans");
1791       DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulUserData->userData, ulUserData->msgLen);
1792       DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulUserData, sizeof(RlcUlUserDatInfo));
1793       return RFAILED;
1794    }
1795    oduCpyFixBufToMsg(ulUserData->userData, mBuf, ulUserData->msgLen);
1796    ODU_PRINT_MSG(mBuf, 0, 0);
1797    egtpMsg.msg = mBuf;
1798    egtpHdlDatInd(egtpMsg);
1799
1800    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulUserData->userData, ulUserData->msgLen);
1801    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulUserData, sizeof(RlcUlUserDatInfo));
1802    return ROK;
1803 }
1804
1805 /**********************************************************************
1806   End of file
1807  **********************************************************************/