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