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