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