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