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