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