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