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