Merge "Restructure O1 module to run as a thread in O-DU High binary [Issue-Id: ODUHIG...
[o-du/l2.git] / src / du_app / du_msg_hdl.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /* This file contains message handling functionality for DU APP */
20 #include "common_def.h"
21 #include "lrg.h"
22 #include "legtp.h"
23 #include "lkw.h"
24 #include "kwu.h"
25 #include "lrg.x"
26 #include "lkw.x"
27 #include "kwu.x"
28 #include "du_app_mac_inf.h"
29 #include "du_app_rlc_inf.h"
30 #include "du_cfg.h"
31 #include "du_app_rlc_inf.h"
32 #include "du_mgr.h"
33 #include "du_sctp.h"
34 #include "F1AP-PDU.h"
35 #include "du_f1ap_msg_hdl.h"
36 #include "du_ue_mgr.h"
37 #include "lsctp.h"
38 #include "legtp.h"
39 #include "lphy_stub.h"
40 #include "du_utils.h"
41 #include "du_cell_mgr.h" 
42
43 #ifdef O1_ENABLE
44
45 #include "AlarmInterface.h"
46
47 #endif 
48
49 uint8_t rlcDlCfg = 0;
50 uint8_t numRlcDlSaps = 0;
51 uint8_t rlcUlCfg = 0;
52 uint8_t numRlcMacSaps = 0;
53 uint8_t macCfg = 0;
54 uint8_t macCfgInst = 0;
55
56 DuCfgParams duCfgParam;
57 uint8_t packRlcConfigReq(Pst *pst, RlcMngmt *cfg);
58 uint8_t cmPkLkwCntrlReq(Pst *pst, RlcMngmt *cfg);
59 uint8_t cmPkLrgCfgReq(Pst *pst, RgMngmt *cfg);
60 uint8_t BuildAndSendE2SetupReq();
61 uint8_t egtpHdlDatInd(EgtpMsg egtpMsg);
62 uint8_t BuildAndSendDUConfigUpdate();
63 uint16_t getTransId();
64 uint8_t cmPkLrgSchCfgReq(Pst * pst,RgMngmt * cfg);
65
66 packMacCellCfgReq packMacCellCfgOpts[] =
67 {
68    packMacCellCfg, /* packing for loosely coupled */
69    MacProcCellCfgReq, /* packing for tightly coupled */
70    packMacCellCfg, /* packing for light weight loosly coupled */
71 };
72
73 DuMacCellStart packMacCellStartOpts[] =
74 {
75    packMacCellStart,   /* Loose coupling */
76    MacProcCellStart,   /* TIght coupling */
77    packMacCellStart    /* Light weight-loose coupling */
78 };
79
80 DuMacCellStop packMacCellStopOpts[] =
81 {
82    packMacCellStop,   /* Loose coupling */
83    MacProcCellStop,   /* TIght coupling */
84    packMacCellStop    /* Light weight-loose coupling */
85 };
86
87 /**************************************************************************
88  * @brief Function to fill configs required by RLC
89  *
90  * @details
91  *
92  *      Function : duBuildRlcCfg 
93  * 
94  *      Functionality:
95  *           Initiates general Configs towards RLC 
96  *     
97  * @param[in] Inst  Specifies if RLC UL or RLC DL instance 
98  * @return ROK     - success
99  *         RFAILED - failure
100  *
101  ***************************************************************************/
102 uint8_t duBuildRlcCfg(Inst inst)
103 {
104    RlcMngmt   rlcMngmt;
105    RlcGenCfg  *genCfg = NULLP;
106    Pst pst;
107
108    DU_SET_ZERO(&rlcMngmt, sizeof(RlcMngmt));
109    DU_SET_ZERO(&pst, sizeof(Pst));
110
111    genCfg   = &(rlcMngmt.t.cfg.s.gen);
112
113    /*----------- Fill General Configuration Parameters ---------*/
114    genCfg->maxUe       = duCfgParam.maxUe;
115    genCfg->maxKwuSaps  = 2;
116    genCfg->maxUdxSaps  = 1; 
117    genCfg->rlcMode     = (inst == RLC_UL_INST) ?
118       LKW_RLC_MODE_UL : LKW_RLC_MODE_DL;
119    genCfg->timeRes     = 1; 
120    genCfg->maxRguSaps  = DEFAULT_CELLS;
121
122    /*----------- Fill lmPst
123     * Parameters ---------*/
124    genCfg->lmPst.dstProcId = DU_PROC;
125    genCfg->lmPst.srcProcId = DU_PROC;
126    genCfg->lmPst.dstEnt    = ENTDUAPP;
127    genCfg->lmPst.dstInst   = DU_INST;
128    genCfg->lmPst.srcEnt    = ENTRLC;
129    genCfg->lmPst.srcInst   = inst;
130    genCfg->lmPst.prior     = PRIOR0;
131    genCfg->lmPst.route     = RTESPEC;
132    genCfg->lmPst.region    = (inst == RLC_UL_INST) ?
133       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
134    genCfg->lmPst.pool      = RLC_POOL;
135    genCfg->lmPst.selector  = ODU_SELECTOR_LC;
136
137    /* Fill Header */
138    rlcMngmt.hdr.msgType             = TCFG;
139    rlcMngmt.hdr.msgLen              = 0;
140    rlcMngmt.hdr.entId.ent           = ENTRLC;
141    rlcMngmt.hdr.entId.inst          = (Inst)0;
142    rlcMngmt.hdr.elmId.elmnt         = STGEN;
143    rlcMngmt.hdr.seqNmb              = 0;
144    rlcMngmt.hdr.version             = 0;
145    rlcMngmt.hdr.transId             = 0;
146    rlcMngmt.hdr.response.prior      = PRIOR0;
147    rlcMngmt.hdr.response.route      = RTESPEC;
148    rlcMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
149       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
150    rlcMngmt.hdr.response.mem.pool   = DU_POOL;
151    rlcMngmt.hdr.response.selector   = ODU_SELECTOR_LC;
152
153    /* Fill Pst */
154    pst.selector  = ODU_SELECTOR_LC;
155    pst.srcEnt    = ENTDUAPP;
156    pst.dstEnt    = ENTRLC;
157    pst.dstInst   = inst;
158    pst.dstProcId = DU_PROC;
159    pst.srcProcId = DU_PROC;
160    pst.region    = duCb.init.region;
161
162    DU_LOG("\nDEBUG   -->  DU_APP : RLC Gen Cfg Req sent for inst %d", inst);
163
164    /* Send the request to RLC */
165    packRlcConfigReq(&pst, &rlcMngmt);
166
167    return ROK;
168 }
169
170 /**************************************************************************
171  * @brief Function to fill configs required by RLC
172  *
173  * @details
174  *
175  *      Function : duBuildRlcLsapCfg 
176  * 
177  *      Functionality:
178  *           Initiates general Configs towards RLC 
179  *     
180  * @param[in] Inst  Specifies if RLC UL or RLC DL instance 
181  * @return ROK     - success
182  *         RFAILED - failure
183  *
184  ***************************************************************************/
185 uint8_t duBuildRlcLsapCfg(Ent ent, Inst inst, uint8_t lsapInst)
186 {
187
188    RlcMngmt   rlcMngmt;
189    RlcSapCfg  *lSap = NULLP;
190    Pst        pst;
191
192    DU_SET_ZERO(&rlcMngmt, sizeof(RlcMngmt));
193    DU_SET_ZERO(&pst, sizeof(Pst));
194
195    /* Fill Header */
196    rlcMngmt.hdr.msgType             = TCFG;
197    rlcMngmt.hdr.entId.ent           = ENTRLC;
198    rlcMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
199       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
200
201    rlcMngmt.hdr.response.mem.pool   = RLC_POOL;
202
203    /* Fill Pst */
204    pst.selector  = ODU_SELECTOR_LC;
205    pst.srcEnt    = ENTDUAPP;
206    pst.dstEnt    = ENTRLC;
207    pst.dstProcId = DU_PROC;
208    pst.dstInst   = inst;
209    pst.srcProcId = DU_PROC;
210    pst.region    = duCb.init.region;
211    lSap   = &(rlcMngmt.t.cfg.s.sap);
212
213    lSap->mem.region = (inst == RLC_UL_INST) ?
214       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
215    lSap->mem.pool    = RLC_POOL;
216    lSap->mem.spare   = 0;
217    lSap->bndTmrIntvl = 10;
218    lSap->priority    = PRIOR0;
219    lSap->route       = RTESPEC;
220    if (ent == ENTMAC)
221    {
222       lSap->procId      = DU_PROC;
223       lSap->ent         = ENTMAC;
224       lSap->inst        = lsapInst;
225       lSap->sapId       = lsapInst;      /* SapId will be stored as suId in MAC */
226       lSap->selector    = (inst == RLC_UL_INST) ? ODU_SELECTOR_LWLC : ODU_SELECTOR_TC;
227       rlcMngmt.hdr.elmId.elmnt  = STRGUSAP;
228       DU_LOG("\nDEBUG   -->  DU_APP : RLC MAC Lower Sap Cfg Req sent for inst %d", inst);
229
230    }
231    else
232    {
233       lSap->procId    = DU_PROC;
234       lSap->ent       = ENTRLC;
235       lSap->inst      = (inst == RLC_UL_INST) ?
236          RLC_DL_INST : RLC_UL_INST;
237       lSap->sapId       = 0;
238       lSap->selector = ODU_SELECTOR_LC;
239       rlcMngmt.hdr.elmId.elmnt  = STUDXSAP;
240       DU_LOG("\nDEBUG   -->  DU_APP : RLC DL/UL Lower Sap Cfg Req sent for inst %d", inst);
241    }
242
243    packRlcConfigReq(&pst, &rlcMngmt);
244    return ROK;
245 }
246
247 /**************************************************************************
248  * @brief Function to fill configs required by RLC
249  *
250  * @details
251  *
252  *      Function : duBuildRlcUsapCfg 
253  * 
254  *      Functionality:
255  *           Initiates general Configs towards RLC 
256  *     
257  * @param[in] Inst  Specifies if RLC UL or RLC DL instance 
258  * @return ROK     - success
259  *         RFAILED - failure
260  *
261  ***************************************************************************/
262 uint8_t duBuildRlcUsapCfg(uint8_t elemId, Ent ent, Inst inst)
263 {
264    RlcMngmt   rlcMngmt;
265    RlcSapCfg  *uSap = NULLP;
266    Pst        pst;
267
268    DU_SET_ZERO(&rlcMngmt, sizeof(RlcMngmt));
269    DU_SET_ZERO(&pst, sizeof(Pst));
270
271    uSap   = &(rlcMngmt.t.cfg.s.sap);
272
273    uSap->selector   = ODU_SELECTOR_LC;
274    uSap->mem.region = (inst == RLC_UL_INST) ?
275       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
276    uSap->mem.pool = RLC_POOL;
277    uSap->mem.spare = 0;
278
279    uSap->procId = DU_PROC;
280    uSap->ent = ENTRLC;
281    uSap->sapId = 0;
282
283    uSap->inst = (inst == RLC_UL_INST) ?
284       RLC_DL_INST : RLC_UL_INST;
285    uSap->bndTmrIntvl = 1000;
286    uSap->priority = PRIOR0;
287    uSap->route = RTESPEC;
288
289    /* Fill Header */
290    rlcMngmt.hdr.msgType             = TCFG;
291    rlcMngmt.hdr.entId.ent           = ENTRLC;
292    rlcMngmt.hdr.elmId.elmnt         = STUDXSAP;
293    rlcMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
294       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
295
296    rlcMngmt.hdr.response.mem.pool   = RLC_POOL;
297
298    /* Fill Pst */
299    pst.selector  = ODU_SELECTOR_LC;
300    pst.srcEnt    = ENTDUAPP;
301    pst.dstEnt    = ENTRLC;
302    pst.dstProcId = DU_PROC;
303    pst.dstInst = inst;
304    pst.srcProcId = DU_PROC;
305    pst.region = duCb.init.region;
306
307    DU_LOG("\nDEBUG   -->  DU_APP : RLC Kwu Upper Sap Cfg Req sent for inst %d", inst);
308    packRlcConfigReq(&pst, &rlcMngmt);
309
310    return ROK;
311 }
312
313 /**************************************************************************
314  * @brief Function to populate internal DS of DU APP
315  *
316  * @details
317  *
318  *      Function : duProcCfgComplete
319  * 
320  *      Functionality:
321  *           Populates internal data structures of DU APP after 
322  *           receiving configurations.
323  *     
324  * @param[in]  void
325  * @return ROK     - success
326  *         RFAILED - failure
327  *
328  ***************************************************************************/
329 uint8_t duProcCfgComplete()
330 {
331    uint8_t         ret = ROK;
332    static uint16_t cellId = 0;
333    uint16_t        idx;
334    for(idx=0; idx< DEFAULT_CELLS; idx++)
335    {
336       DuCellCb *cell = NULLP;
337       DU_ALLOC(cell, sizeof(DuCellCb))
338       if(cell == NULLP)
339       {
340          DU_LOG("\nERROR  -->  DU_APP : Memory Allocation failed in duProcCfgComplete");
341          ret = RFAILED;
342       }
343       else
344       {
345          uint8_t idx1=0; 
346          memset(cell, 0, sizeof(DuCellCb));
347          cell->cellId = ++cellId;
348          memset(&cell->cellInfo.nrEcgi.plmn, 0, sizeof(Plmn));
349          cell->cellInfo.nrEcgi.plmn.mcc[0] = PLMN_MCC0;
350          cell->cellInfo.nrEcgi.plmn.mcc[1] = PLMN_MCC1;
351          cell->cellInfo.nrEcgi.plmn.mcc[2] = PLMN_MCC2;
352          cell->cellInfo.nrEcgi.plmn.mnc[0] = PLMN_MNC0;
353          cell->cellInfo.nrEcgi.plmn.mnc[1] = PLMN_MNC1;
354          cell->cellInfo.nrEcgi.cellId = NR_CELL_ID;
355          cell->cellInfo.nrPci = NR_PCI; 
356          cell->cellInfo.fiveGsTac = DU_TAC;
357          memset(&cell->cellInfo.plmn[idx1], 0, sizeof(Plmn));
358          for(idx1=0; idx1<MAX_PLMN; idx1++)
359          {
360             cell->cellInfo.plmn[idx1].mcc[0] = PLMN_MCC0;
361             cell->cellInfo.plmn[idx1].mcc[1] = PLMN_MCC1;
362             cell->cellInfo.plmn[idx1].mcc[2] = PLMN_MCC2;
363             cell->cellInfo.plmn[idx1].mnc[0] = PLMN_MNC0;
364             cell->cellInfo.plmn[idx1].mnc[1] = PLMN_MNC1;
365          }
366          cell->cellInfo.maxUe = duCfgParam.maxUe;
367          cell->cellStatus = CELL_OUT_OF_SERVICE;
368
369          duCb.cfgCellLst[duCb.numCfgCells] = cell;
370          duCb.numCfgCells++;
371       }
372    }
373    if(ret != RFAILED)
374    {
375       //Start layer configs
376       ret = duSendRlcUlCfg();
377    }
378    return ret;
379 }
380 /**************************************************************************
381  * @brief Function to invoke DU Layer Configs
382  *
383  * @details
384  *
385  *      Function : duSendRlcUlCfg 
386  * 
387  *      Functionality:
388  *           Initiates Configs towards layers of DU
389  *     
390  * @param[in]  void
391  * @return ROK     - success
392  *         RFAILED - failure
393  *
394  ***************************************************************************/
395 uint8_t duSendRlcUlCfg()
396 {
397    uint8_t cellIdx; 
398
399    duBuildRlcCfg((Inst)RLC_UL_INST);
400    for(cellIdx = 0; cellIdx < DEFAULT_CELLS; cellIdx++)
401    {
402       duBuildRlcLsapCfg(ENTMAC, (Inst)RLC_UL_INST, cellIdx);
403    }
404    duBuildRlcLsapCfg(ENTRLC, (Inst)RLC_UL_INST, 0);
405
406    return ROK;
407 }
408
409 /**************************************************************************
410  * @brief Function to invoke DU Layer Configs
411  *
412  * @details
413  *
414  *      Function : duSendRlcDlCfg 
415  * 
416  *      Functionality:
417  *           Initiates Configs towards layers of DU
418  *     
419  * @param[in]  void
420  * @return ROK     - success
421  *         RFAILED - failure
422  *
423  ***************************************************************************/
424 uint8_t duSendRlcDlCfg()
425 {
426    uint8_t cellIdx; 
427
428    duBuildRlcCfg((Inst)RLC_DL_INST);
429    duBuildRlcUsapCfg(STUDXSAP, ENTRLC, (Inst)RLC_DL_INST);
430    for(cellIdx = 0; cellIdx < DEFAULT_CELLS; cellIdx++)
431    {
432       duBuildRlcLsapCfg(ENTMAC, (Inst)RLC_DL_INST, cellIdx);
433    }
434
435    return ROK;
436 }
437 /**************************************************************************
438  * @brief Function to handle Config Confirm from RLC
439  *
440  * @details
441  *
442  *      Function : DuHdlRlcCfgComplete 
443  * 
444  *      Functionality:
445  *           Handles Gen Config Confirm from RLC
446  *     
447  * @param[in]  Pst     *pst, Post structure of the primitive.     
448  * @param[in]  RlcMngmt *cfm, Unpacked primitive info received from RLC
449  * @return ROK     - success
450  *         RFAILED - failure
451  *
452  ***************************************************************************/
453 uint8_t DuHdlRlcCfgComplete(Pst *pst, RlcMngmt *cfm)
454 {
455    uint8_t ret = ROK;
456    if (pst->srcInst == RLC_UL_INST)
457    {
458       ret = duProcRlcUlCfgComplete(pst, cfm);
459    }
460    else
461    {
462       ret = duProcRlcDlCfgComplete(pst, cfm);
463    }
464    return ret;
465 }
466
467 /**************************************************************************
468  * @brief Function to handle Control Config Confirm from RLC
469  *
470  * @details
471  *
472  *      Function : duHdlRlcCntrlCfgComplete 
473  * 
474  *      Functionality:
475  *           Handles Control Config Confirm from RLC
476  *     
477  * @param[in]  Pst     *pst, Post structure of the primitive.     
478  * @param[in]  RlcMngmt *cfm, Unpacked primitive info received from RLC
479  * @return ROK     - success
480  *         RFAILED - failure
481  *
482  ***************************************************************************/
483 uint8_t duHdlRlcCntrlCfgComplete(Pst *pst, RlcMngmt *cntrl)
484 {
485    uint8_t ret = ROK;
486
487    if (cntrl->cfm.status == LCM_PRIM_OK)
488    {
489       switch (cntrl->hdr.elmId.elmnt)
490       {
491          case  STRGUSAP:
492             {
493                if (pst->srcInst == RLC_DL_INST)
494                {
495                   DU_LOG("\nDEBUG   -->  DU_APP : BIND OF RLC DL TO MAC (RGU) SAP SUCCESSFUL");
496                   macCfgInst++;
497                   if(macCfgInst < DEFAULT_CELLS)
498                   {
499                      macCfgInst = 0;
500                      duBindUnbindRlcToMacSap((Inst) RLC_DL_INST, ABND);
501                   }
502                   else
503                   {
504                      duBindUnbindRlcToMacSap((Inst) RLC_UL_INST, ABND);
505                   }
506                }
507                else
508                {
509                   DU_LOG("\nDEBUG   -->  DU_APP : BIND OF RLC UL TO MAC (RGU) SAP SUCCESSFUL");
510                   macCfgInst++;
511                   if(macCfgInst < DEFAULT_CELLS)
512                   {
513                      duBindUnbindRlcToMacSap((Inst) RLC_UL_INST, ABND);
514                   }
515                   else
516                   {
517                      duSendSchCfg();
518                   }
519                   break;
520                }
521             }
522
523       }
524    }
525    return ret;
526 }
527 /**************************************************************************
528  * @brief Function to handle Config Confirm from RLC UL
529  *
530  * @details
531  *
532  *      Function : duHdlRlcUlCfgComplete 
533  * 
534  *      Functionality:
535  *           Handles Config Confirm from RLC UL
536  *     
537  * @param[in]  Pst     *pst, Post structure of the primitive.     
538  * @param[in]  RlcMngmt *cfm, Unpacked primitive info received from RLC UL
539  * @return ROK     - success
540  *         RFAILED - failure
541  *
542  ***************************************************************************/
543 uint8_t duProcRlcUlCfgComplete(Pst *pst, RlcMngmt *cfm)
544 {
545    uint8_t ret;
546
547    DU_LOG("\nDEBUG   -->  DU_APP : RLC UL Cfg Status %d", cfm->cfm.status);
548    if (cfm->cfm.status == LCM_PRIM_OK)
549    {
550       switch(cfm->hdr.elmId.elmnt)
551       {
552          case STGEN:
553             {
554                rlcUlCfg |= RLC_GEN_CFG;
555                break;
556             }
557          case STRGUSAP:
558             {
559                numRlcMacSaps++;
560                if(numRlcMacSaps == DEFAULT_CELLS)
561                {
562                   rlcUlCfg |= RLC_MAC_SAP_CFG;
563                   numRlcMacSaps = 0;
564                }
565                break;
566             }
567          case STUDXSAP:
568             {
569                rlcUlCfg |= RLC_UDX_SAP_CFG;
570                break;
571
572             }
573          default:
574             break;
575       }
576       DU_LOG("\nDEBUG   -->  DU_APP : RLC UL Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
577       if(rlcUlCfg == DU_RLC_UL_CONFIGURED)
578       {
579          rlcUlCfg = 0;
580          numRlcMacSaps = 0;
581          //Start configuration of RLC DL
582          duSendRlcDlCfg();
583
584       }
585    }
586    else
587    {
588       DU_LOG("\nERROR  -->  DU_APP : Config confirm NOK from RLC UL");
589       ret = RFAILED;
590    }
591    return ret;
592 }
593
594 /**************************************************************************
595  * @brief Function to handle Config Confirm from RLC DL
596  *
597  * @details
598  *
599  *      Function : duHdlRlcDlCfgComplete 
600  * 
601  *      Functionality:
602  *           Handles Config Confirm from RLC DL
603  *     
604  * @param[in]  Pst     *pst, Post structure of the primitive.     
605  * @param[in]  RlcMngmt *cfm, Unpacked primitive info received from RLC DL
606  * @return ROK     - success
607  *         RFAILED - failure
608  *
609  ***************************************************************************/
610 uint8_t duProcRlcDlCfgComplete(Pst *pst, RlcMngmt *cfm)
611 {
612    DU_LOG("\nDEBUG   -->  DU_APP : RLC DL Cfg Status %d", cfm->cfm.status);
613    if (cfm->cfm.status == LCM_PRIM_OK)
614    {
615       switch(cfm->hdr.elmId.elmnt)
616       {
617          case STGEN:
618             {
619                rlcDlCfg |= RLC_GEN_CFG;
620                break;
621             }
622          case STRGUSAP:
623             {
624                numRlcMacSaps++;
625                if(numRlcMacSaps == DEFAULT_CELLS)
626                {
627                   rlcDlCfg |= RLC_MAC_SAP_CFG;
628                   numRlcMacSaps = 0;
629                }
630                break;
631             }
632          case STUDXSAP:
633             {
634                rlcDlCfg |= RLC_UDX_SAP_CFG;
635                break;
636
637             }
638          default:
639             break;
640
641       }
642       DU_LOG("\nDEBUG   -->  DU_APP : RLC DL Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
643       if(rlcDlCfg == DU_RLC_DL_CONFIGURED)
644       {
645          rlcDlCfg = 0;
646          //Start configuration of MAC
647          duSendMacCfg();
648
649       }
650    }
651    else
652    {
653       DU_LOG("\nERROR  -->  DU_APP : Config confirm NOK from RLC DL");
654    }
655    return ROK;
656 }
657
658 /**************************************************************************
659  * @brief Function to send configs to MAC
660  *
661  * @details
662  *
663  *      Function : duSendMacCfg 
664  * 
665  *      Functionality:
666  *           Initiates Configs towards MAC layer
667  *     
668  * @param[in]  void
669  * @return ROK     - success
670  *         RFAILED - failure
671  *
672  ***************************************************************************/
673 uint8_t duSendMacCfg()
674 {
675    duBuildMacGenCfg();
676    duBuildMacUsapCfg(RLC_UL_INST);
677    duBuildMacUsapCfg(RLC_DL_INST);
678
679    return ROK;
680 }
681
682 /**************************************************************************
683  * @brief Function to fill gen config required by MAC
684  *
685  * @details
686  *
687  *      Function : duBuildMacGenCfg 
688  * 
689  *      Functionality:
690  *           Initiates general Configs towards MAC
691  *     
692  * @param[in] void
693  * @return ROK     - success
694  *         RFAILED - failure
695  *
696  ***************************************************************************/
697 uint8_t duBuildMacGenCfg()
698 {
699    RgMngmt       rgMngmt;
700    RgGenCfg      *genCfg=NULLP;
701    Pst           pst;
702
703    DU_SET_ZERO(&pst, sizeof(Pst));
704    DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
705
706    genCfg   = &(rgMngmt.t.cfg.s.genCfg);
707
708    /*----------- Fill General Configuration Parameters ---------*/
709    genCfg->mem.region = MAC_MEM_REGION;
710    genCfg->mem.pool   = MAC_POOL;
711    genCfg->tmrRes     = 10;
712    genCfg->numRguSaps = 2;
713
714    genCfg->lmPst.dstProcId = DU_PROC;
715    genCfg->lmPst.srcProcId = DU_PROC;
716    genCfg->lmPst.dstEnt    = ENTDUAPP;
717    genCfg->lmPst.dstInst   = 0;
718    genCfg->lmPst.srcEnt    = ENTMAC;
719    genCfg->lmPst.srcInst   = macCfgInst;
720    genCfg->lmPst.prior     = PRIOR0;
721    genCfg->lmPst.route     = RTESPEC;
722    genCfg->lmPst.region    = MAC_MEM_REGION;
723    genCfg->lmPst.pool      = MAC_POOL;
724    genCfg->lmPst.selector  = ODU_SELECTOR_LC;
725
726    /* Fill Header */
727    rgMngmt.hdr.msgType             = TCFG;
728    rgMngmt.hdr.msgLen              = 0;
729    rgMngmt.hdr.entId.ent           = ENTMAC;
730    rgMngmt.hdr.entId.inst          = (Inst)0;
731    rgMngmt.hdr.elmId.elmnt         = STGEN;
732    rgMngmt.hdr.seqNmb              = 0;
733    rgMngmt.hdr.version             = 0;
734    rgMngmt.hdr.transId             = 0;
735
736    rgMngmt.hdr.response.prior      = PRIOR0;
737    rgMngmt.hdr.response.route      = RTESPEC;
738    rgMngmt.hdr.response.mem.region = MAC_MEM_REGION;
739    rgMngmt.hdr.response.mem.pool   = MAC_POOL;
740    rgMngmt.hdr.response.selector   = ODU_SELECTOR_LC;
741
742    /* Fill Pst */
743    pst.selector  = ODU_SELECTOR_LC;
744    pst.srcEnt    = ENTDUAPP;
745    pst.dstEnt    = ENTMAC;
746    pst.dstInst   = macCfgInst;
747    pst.dstProcId = DU_PROC;
748    pst.srcProcId = DU_PROC;
749    pst.region = duCb.init.region;
750
751    DU_LOG("\nDEBUG   -->  DU_APP : MAC Gen Cfg Req sent");
752
753    /* Send the request to MAC */
754    cmPkLrgCfgReq(&pst, &rgMngmt);
755
756    return ROK;
757 }
758
759 /**************************************************************************
760  * @brief Function to fill USAP config required by MAC
761  *
762  * @details
763  *
764  *      Function : duBuildMacUsapCfg 
765  * 
766  *      Functionality:
767  *           Initiates USAP Configs towards MAC
768  *     
769  * @param[in] SpId  Specifies if RLC UL or RLC DL instance 
770  * @return ROK     - success
771  *         RFAILED - failure
772  *
773  ***************************************************************************/
774 uint8_t duBuildMacUsapCfg(SpId sapId)
775 {
776    RgMngmt     rgMngmt;
777    RgUpSapCfg  *uSap = NULLP;
778    Pst         pst;
779
780    DU_SET_ZERO(&pst, sizeof(Pst));
781    DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
782
783    uSap   = &(rgMngmt.t.cfg.s.rguSap);
784
785    uSap->mem.region = MAC_MEM_REGION;
786    uSap->mem.pool   = MAC_POOL;
787    uSap->suId       = 0;
788    uSap->spId       = sapId;
789    uSap->procId     = DU_PROC;
790    uSap->ent        = ENTRLC;
791    uSap->inst       = sapId;
792    uSap->prior      = PRIOR0;
793    uSap->route      = RTESPEC;
794    uSap->selector   = ODU_SELECTOR_LC ;
795
796    /* fill header */
797    rgMngmt.hdr.msgType             = TCFG;
798    rgMngmt.hdr.entId.ent           = ENTMAC;
799    rgMngmt.hdr.entId.inst          = (Inst)0;
800    rgMngmt.hdr.elmId.elmnt         = STRGUSAP;
801    rgMngmt.hdr.response.mem.region = MAC_MEM_REGION;
802    rgMngmt.hdr.response.mem.pool   = MAC_POOL;
803
804    /* fill pst */
805    pst.selector  = ODU_SELECTOR_LC;
806    pst.srcEnt    = ENTDUAPP;
807    pst.dstEnt    = ENTMAC;
808    pst.dstInst   = macCfgInst;
809    pst.dstProcId = DU_PROC;
810    pst.srcProcId = DU_PROC;
811    pst.region    = duCb.init.region;
812
813    DU_LOG("\nDEBUG  -->  DU_APP : MAC Rgu USap Cfg Req sent");
814
815    /* Send the request to MAC */
816    cmPkLrgCfgReq(&pst, &rgMngmt);
817
818    return ROK;
819 }
820
821 /**************************************************************************
822  * @brief Function to handle Config Confirm from MAC
823  *
824  * @details
825  *
826  *      Function : duHdlMacCfgComplete 
827  * 
828  *      Functionality:
829  *           Handles Gen Config Confirm from MAC
830  *     
831  * @param[in]  Pst     *pst, Post structure of the primitive.     
832  * @param[in]  RgMngmt *cfm, Unpacked primitive info received from MAC
833  * @return ROK     - success
834  *         RFAILED - failure
835  *
836  ***************************************************************************/
837 uint8_t duHdlMacCfgComplete(Pst *pst, RgMngmt *cfm)
838 {
839    uint8_t ret = ROK;
840
841    if (cfm->cfm.status == LCM_PRIM_OK)
842    {
843       switch (cfm->hdr.elmId.elmnt)
844       {
845          case STGEN:
846             {
847                macCfg |= MAC_GEN_CFG;
848                break;
849             }
850          case STRGUSAP:
851             {
852                macCfg |= MAC_SAP_CFG;
853                numRlcMacSaps++;
854                break;
855             }
856          default:
857             break;
858       }
859       DU_LOG("\nDEBUG   -->  DU_APP : MAC Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
860       if(macCfg == MAC_CONFIGURED && numRlcMacSaps == MAX_MAC_SAP)
861       {
862          macCfg = 0;
863          DU_LOG("\nDEBUG   -->  DU_APP : Completed sending Configs");
864          macCfgInst = 0;
865          duBindUnbindRlcToMacSap(RLC_DL_INST, ABND);
866       }
867
868    }
869    else
870    {
871       DU_LOG("\nERROR  -->  DU_APP : Config confirm NOK from MAC");
872       ret = RFAILED;
873    }
874    return ret;
875 }
876
877 /**************************************************************************
878  * @brief Function to bind/unbind RLC to MAC SAP
879  *
880  * @details
881  *
882  *      Function : duBindUnbindRlcToMacSap 
883  * 
884  *      Functionality:
885  *           Initiates Bind/Unbind from RLC to MAC
886  *     
887  * @param[in] Inst   Specifies if RLC UL or RLC DL instance 
888  * @param[in] action Specifies if action is bind or unbind
889  * @return ROK     - success
890  *         RFAILED - failure
891  *
892  ***************************************************************************/
893 uint8_t duBindUnbindRlcToMacSap(uint8_t inst, uint8_t action)
894 {
895    RlcCntrl  *cntrl = NULLP;
896    RlcMngmt  rlcMngmt;
897    Pst      pst;
898
899
900    DU_SET_ZERO(&rlcMngmt, sizeof(RlcMngmt));
901    DU_SET_ZERO(&pst, sizeof(Pst));
902
903    if (action == ABND)
904    {
905       DU_LOG("\nDEBUG   -->  DU_APP : Cntrl Req to RLC inst %d to bind MAC sap", inst);
906    }
907    else
908    {
909       DU_LOG("\nDEBUG   -->  DU_APP : Cntrl Req to RLC inst %d to unbind MAC sap", inst);
910    }
911    cntrl = &(rlcMngmt.t.cntrl);
912
913    cntrl->action            =  action;
914    cntrl->subAction         =  DU_ZERO_VAL;
915    cntrl->s.sapCntrl.suId   =  macCfgInst;
916    cntrl->s.sapCntrl.spId   =  inst;
917
918    /* Fill header */
919    rlcMngmt.hdr.msgType             = TCNTRL;
920    rlcMngmt.hdr.entId.ent           = ENTRLC;
921    rlcMngmt.hdr.entId.inst          = inst;
922    rlcMngmt.hdr.elmId.elmnt         = 186; /* ambiguous defines in lkw.h and lrg.h so direct hardcoded*/
923    rlcMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
924       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
925    rlcMngmt.hdr.response.mem.pool   = RLC_POOL;
926
927    /* Fill pst */
928    pst.selector  = ODU_SELECTOR_LC;
929    pst.srcEnt    = ENTDUAPP;
930    pst.dstEnt    = ENTRLC;
931    pst.dstProcId = DU_PROC;
932    pst.dstInst   = inst;
933    pst.srcProcId = DU_PROC;
934    pst.region    = duCb.init.region;
935
936    cmPkLkwCntrlReq(&pst, &rlcMngmt);
937
938    return ROK;
939 }
940 /*******************************************************************
941  *
942  * @brief Handles SCTP notifications
943  *
944  * @details
945  *
946  *    Function : duSctpNtfyHdl
947  *
948  *    Functionality:
949  *         Handles SCTP notification
950  *
951  * @params[in] Message Buffer
952  *             SCTP notification
953  *
954  * @return ROK     - success
955  *         RFAILED - failure
956  *
957  * ****************************************************************/
958
959 uint8_t duSctpNtfyHdl(Buffer *mBuf, CmInetSctpNotification *ntfy)
960 {
961    if(f1Params.assocId == ntfy->u.assocChange.assocId)
962    {
963       if(BuildAndSendF1SetupReq() != ROK)
964       {
965          return RFAILED;
966       }
967    }
968    else if(ricParams.assocId == ntfy->u.assocChange.assocId)
969    {
970       if(BuildAndSendE2SetupReq() != ROK)
971       {
972          return RFAILED;
973       }
974    }
975    else
976    {
977       DU_LOG("\nERROR  -->  DU_APP : Invalid assocId %d received", ntfy->u.assocChange.assocId);
978       return RFAILED;
979    }
980    return ROK;
981 }
982
983 /*******************************************************************
984  *
985  * @brief  Fills Pst struct for ENTEGTP
986  *
987  * @details
988  *
989  *    Function : duFillEgtpPst
990  *
991  *    Functionality:
992  *       Fills Pst struct for ENTEGTP
993  *
994  * @params[in] 
995  * @return ROK     - success
996  *         RFAILED - failure
997  *
998  * ****************************************************************/
999 uint8_t duFillEgtpPst(Pst *pst, Event event)
1000 {
1001    memset(pst, 0, sizeof(Pst));
1002    pst->srcEnt = (Ent)ENTDUAPP;
1003    pst->srcInst = (Inst)DU_INST;
1004    pst->srcProcId = DU_PROC;
1005    pst->dstEnt = (Ent)ENTEGTP;
1006    pst->dstInst = (Inst)EGTP_INST;
1007    pst->dstProcId = pst->srcProcId;
1008    pst->event = event;
1009    pst->selector = ODU_SELECTOR_LC;
1010    pst->pool= DU_POOL;
1011
1012    return ROK;
1013 }
1014
1015
1016 /*******************************************************************
1017  *
1018  * @brief  Function to configure EGTP
1019  *
1020  * @details
1021  *
1022  *    Function : duBuildEgtpCfgReq
1023  *
1024  *    Functionality:
1025  *       Function to configure EGTP
1026  *
1027  * @params[in] 
1028  * @return ROK     - success
1029  *         RFAILED - failure
1030  *
1031  * ****************************************************************/
1032
1033 uint8_t duBuildEgtpCfgReq()
1034 {
1035    Pst pst;
1036    EgtpConfig egtpCfg;
1037
1038    DU_LOG("\nDEBUG   -->  DU_APP : Sending EGTP config request");
1039
1040    memset(&egtpCfg, 0, sizeof(EgtpConfig));
1041    memcpy(&egtpCfg, &duCfgParam.egtpParams, sizeof(EgtpConfig));
1042
1043    duFillEgtpPst(&pst, EVTCFGREQ);
1044    packEgtpCfgReq(&pst, egtpCfg);
1045
1046    return ROK;
1047 }
1048
1049 /*******************************************************************
1050  *
1051  * @brief  Function to configure EGTP
1052  *
1053  * @details
1054  *
1055  *    Function : duBuildEgtpCfgReq
1056  *
1057  *    Functionality:
1058  *       Function to configure EGTP
1059  *
1060  * @params[in] 
1061  * @return ROK     - success
1062  *         RFAILED - failure
1063  *
1064  * ****************************************************************/
1065 uint8_t duHdlEgtpCfgComplete(CmStatus cfm)
1066 {
1067    uint8_t ret = ROK;
1068
1069    if(cfm.status == LCM_PRIM_OK)
1070    {
1071       DU_LOG("\nDEBUG   -->  DU_APP : EGTP configuraton complete");
1072 #ifdef EGTP_TEST
1073       duSendEgtpSrvOpenReq();
1074 #endif
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();
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()
1562 {
1563    Pst pst;
1564    OduCellId *cellId = NULL;
1565
1566    DU_LOG("\nINFO   -->  DU APP : Building and Sending cell stop request to MAC");
1567
1568    /* Send Cell Stop Request to MAC */
1569    DU_ALLOC_SHRABL_BUF(cellId, sizeof(OduCellId));
1570    if(!cellId)
1571    {
1572       DU_LOG("\nERROR  -->  DU APP : Memory alloc failed while building cell stop request");
1573       return RFAILED;
1574    }
1575    cellId->cellId = duCb.actvCellLst[0]->cellId;
1576
1577    /* Fill Pst */
1578    FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_STOP);
1579
1580    return (*packMacCellStopOpts[pst.selector])(&pst, cellId);
1581 }
1582
1583 /*******************************************************************
1584  *
1585  * @brief Handles stop indication from MAC
1586  *
1587  * @details
1588  *
1589  *    Function : duHandleStopInd
1590  *
1591  *    Functionality:
1592  *      Handles stop indication from MAC
1593  *
1594  * @params[in] Post structure pointer
1595  * @return ROK     - success
1596  *         RFAILED - failure
1597  *
1598  * ****************************************************************/
1599 uint8_t duHandleStopInd(Pst *pst, OduCellId *cellId)
1600 {
1601    DuCellCb *cellCb = NULLP;
1602
1603    if(cellId->cellId <=0 || cellId->cellId > MAX_NUM_CELL)
1604    {
1605       DU_LOG("\nERROR  -->  DU APP : Invalid Cell Id %d in duHandleStopInd()", cellId->cellId);
1606    }
1607
1608    if(duGetCellCb(cellId->cellId, &cellCb) != ROK)
1609       return RFAILED;
1610
1611    if((cellCb->cellStatus == ACTIVATED))
1612    {
1613       DU_LOG("\nINFO   -->  DU APP : 5G-NR Cell %d is DOWN", cellId->cellId);
1614       cellCb->cellStatus = DELETION_IN_PROGRESS;
1615
1616 #ifdef O1_ENABLE
1617       DU_LOG("\nINFO   -->  DU APP : Raise cell down alarm for cell id=%d", cellId->cellId);
1618       raiseCellAlrm(CELL_DOWN_ALARM_ID, cellId->cellId);
1619 #endif
1620    }
1621
1622    if((pst->selector == ODU_SELECTOR_LWLC) || (pst->selector == ODU_SELECTOR_TC))
1623       DU_FREE_SHRABL_BUF(MAC_MEM_REGION, pst->pool, cellId, sizeof(OduCellId));
1624
1625    cellCb->cellStatus = CELL_OUT_OF_SERVICE; //TODO: cell status must be set to OOS after all UE and cell cleanup which is not
1626                                              //supported now
1627
1628    return ROK;
1629 }
1630
1631 /*******************************************************************
1632  *
1633  * @brief Handles slot indication from MAC
1634  *
1635  * @details
1636  *
1637  *    Function : duHandleUlCcchInd
1638  *
1639  *    Functionality:
1640  *      Handles UL CCCH indication from MAC
1641  *
1642  * @params[in] Post structure pointer
1643  *             UL CCCH Ind pointer
1644  * @return ROK     - success
1645  *         RFAILED - failure
1646  *
1647  * ****************************************************************/
1648 uint8_t duHandleUlCcchInd(Pst *pst, UlCcchIndInfo *ulCcchIndInfo)
1649 {
1650
1651    DU_LOG("\nINFO  -->  DU APP : UL CCCH Indication received");
1652
1653    return (duProcUlCcchInd(ulCcchIndInfo));
1654 }
1655
1656 /*******************************************************************
1657  *
1658  * @brief Process UL RRC Message from RLC
1659  *
1660  * @details
1661  *
1662  *    Function : DuProcRlcUlRrcMsgTrans
1663  *
1664  *    Functionality: Process UL RRC Message from RLC
1665  *
1666  * @params[in] Post structure
1667  *             UL RRC Message Info
1668  * @return ROK     - success
1669  *         RFAILED - failure
1670  *
1671  * ****************************************************************/
1672 uint8_t DuProcRlcUlRrcMsgTrans(Pst *pst, RlcUlRrcMsgInfo *ulRrcMsgInfo)
1673 {
1674    DuCellCb *cellCb = NULLP;
1675    DuUeCb   ueCb ={0};
1676   
1677    if(duGetCellCb(ulRrcMsgInfo->cellId, &cellCb) != ROK)
1678       return RFAILED;
1679    if(ulRrcMsgInfo->ueIdx > 0)
1680    {
1681    ueCb = cellCb->ueCb[ulRrcMsgInfo->ueIdx -1];
1682
1683
1684    BuildAndSendULRRCMessageTransfer(ueCb, ulRrcMsgInfo->lcId, ulRrcMsgInfo->msgLen, \
1685       ulRrcMsgInfo->rrcMsg);
1686
1687    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulRrcMsgInfo->rrcMsg, ulRrcMsgInfo->msgLen);
1688    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulRrcMsgInfo, sizeof(RlcUlRrcMsgInfo));
1689    }
1690    return ROK;
1691 }
1692
1693 /*******************************************************************
1694 *
1695 * @brief Process RRC delivery report from RLC
1696 *
1697 * @details
1698 *
1699 *    Function : DuProcRlcRrcDeliveryReport
1700 *
1701 *    Functionality: Process RRC delivery Message from RLC
1702 *
1703 * @params[in] Post structure
1704 *             UL RRC Message Info
1705 * @return ROK     - success
1706 *         RFAILED - failure
1707 *
1708 * ****************************************************************/
1709 uint8_t DuProcRlcRrcDeliveryReport(Pst *pst, RrcDeliveryReport *rrcDeliveryReport)
1710 {
1711    DuCellCb *cellCb = NULLP;
1712    DuUeCb   ueCb;
1713    uint8_t  ret = RFAILED;
1714
1715    if(duGetCellCb(rrcDeliveryReport->cellId, &cellCb) != ROK)
1716       return RFAILED;
1717    
1718    ueCb = cellCb->ueCb[rrcDeliveryReport->ueIdx -1];
1719    ret = BuildAndSendRrcDeliveryReport(ueCb.gnbCuUeF1apId, ueCb.gnbDuUeF1apId,rrcDeliveryReport);
1720
1721    DU_FREE_SHRABL_BUF(pst->region, pst->pool, rrcDeliveryReport, sizeof(RrcDeliveryReport));
1722    return ret;
1723 }
1724
1725 /*******************************************************************
1726  *
1727  * @brief Process UL user data from RLC
1728  *
1729  * @details
1730  *
1731  *    Function : DuProcRlcUlUserDataTrans
1732  *
1733  *    Functionality: Process UL user data from RLC
1734  *
1735  * @params[in] Post structure
1736  *             UL user data
1737  * @return ROK     - success
1738  *         RFAILED - failure
1739  *
1740  * ****************************************************************/
1741 uint8_t DuProcRlcUlUserDataTrans(Pst *pst, RlcUlUserDatInfo *ulUserData)
1742 {
1743    uint8_t  rbIdx;
1744    EgtpMsg  egtpMsg;
1745    Buffer   *mBuf;
1746
1747    DU_LOG("\nDEBUG  -->  DU APP : Received UL user data");
1748
1749    /* Fill EGTP header */
1750    egtpMsg.msgHdr.msgType = EGTPU_MSG_GPDU;
1751    egtpMsg.msgHdr.nPdu.pres = FALSE;
1752    egtpMsg.msgHdr.seqNum.pres = FALSE;
1753    egtpMsg.msgHdr.extHdr.udpPort.pres = FALSE;
1754    egtpMsg.msgHdr.extHdr.pdcpNmb.pres = FALSE;
1755
1756    /* Fetch EGTP tunnel info */
1757    for(rbIdx = 0; rbIdx < duCb.numDrb; rbIdx++)
1758    {
1759       if((duCb.upTnlCfg[rbIdx] != NULLP) && (duCb.upTnlCfg[rbIdx]->drbId == ulUserData->rbId))
1760       {
1761          if(duCb.upTnlCfg[rbIdx]->tnlCfg1)
1762          {
1763             egtpMsg.msgHdr.teId = duCb.upTnlCfg[rbIdx]->tnlCfg1->teId; /*As we are supporting only 1 tunnel per DRB*/
1764             break;
1765          }
1766       }
1767    }
1768
1769    if (ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) != ROK)
1770    {
1771       DU_LOG("\nERROR  -->  DU APP : Failed to allocated buffer memory in DuProcRlcUlUserDataTrans");
1772       DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulUserData->userData, ulUserData->msgLen);
1773       DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulUserData, sizeof(RlcUlUserDatInfo));
1774       return RFAILED;
1775    }
1776    oduCpyFixBufToMsg(ulUserData->userData, mBuf, ulUserData->msgLen);
1777    ODU_PRINT_MSG(mBuf, 0, 0);
1778    egtpMsg.msg = mBuf;
1779    egtpHdlDatInd(egtpMsg);
1780
1781    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulUserData->userData, ulUserData->msgLen);
1782    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulUserData, sizeof(RlcUlUserDatInfo));
1783    return ROK;
1784 }
1785
1786 /**********************************************************************
1787   End of file
1788  **********************************************************************/