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