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