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