U8, U16, U32 data type changes
[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 uint8_t BuildAndSendRrcDeliveryReport(uint32_t gnbCuUeF1apId, uint32_t gnbDuUeF1apId, RrcDeliveryReport *rrcDelivery);
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             uint32_t nci;
340             uint8_t idx1; 
341             memset(cell, 0, sizeof(DuCellCb));
342             cell->cellId = ++cellId;
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.plmn.mnc[2] = PLMN_MNC2;
349             cell->cellInfo.nrEcgi.cellId = NR_CELL_ID;
350             cell->cellInfo.nrPci = NR_PCI; 
351             cell->cellInfo.fiveGsTac = DU_TAC;
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                cell->cellInfo.plmn[idx1].mnc[2] = PLMN_MNC2;
360             }
361             cell->cellInfo.maxUe = duCfgParam.maxUe;
362             cell->cellStatus = CELL_OUT_OF_SERVICE;
363             nci = (uint16_t)cell->cellInfo.nrEcgi.cellId;
364
365             duCb.cfgCellLst[nci-1] = cell;
366             duCb.numCfgCells++;
367          }
368       }
369    if(ret != RFAILED)
370    {
371       //Start layer configs
372       ret = duSendRlcUlCfg();
373    }
374    return ret;
375 }
376 /**************************************************************************
377  * @brief Function to invoke DU Layer Configs
378  *
379  * @details
380  *
381  *      Function : duSendRlcUlCfg 
382  * 
383  *      Functionality:
384  *           Initiates Configs towards layers of DU
385  *     
386  * @param[in]  void
387  * @return ROK     - success
388  *         RFAILED - failure
389  *
390  ***************************************************************************/
391 uint8_t duSendRlcUlCfg()
392 {
393    uint8_t cellIdx; 
394
395    duBuildRlcCfg((Inst)RLC_UL_INST);
396    for(cellIdx = 0; cellIdx < DEFAULT_CELLS; cellIdx++)
397    {
398       duBuildRlcLsapCfg(ENTMAC, (Inst)RLC_UL_INST, cellIdx);
399    }
400    duBuildRlcLsapCfg(ENTRLC, (Inst)RLC_UL_INST, 0);
401
402    return ROK;
403 }
404
405 /**************************************************************************
406  * @brief Function to invoke DU Layer Configs
407  *
408  * @details
409  *
410  *      Function : duSendRlcDlCfg 
411  * 
412  *      Functionality:
413  *           Initiates Configs towards layers of DU
414  *     
415  * @param[in]  void
416  * @return ROK     - success
417  *         RFAILED - failure
418  *
419  ***************************************************************************/
420 uint8_t duSendRlcDlCfg()
421 {
422    uint8_t cellIdx; 
423
424    duBuildRlcCfg((Inst)RLC_DL_INST);
425    duBuildRlcUsapCfg(STUDXSAP, ENTRLC, (Inst)RLC_DL_INST);
426    for(cellIdx = 0; cellIdx < DEFAULT_CELLS; cellIdx++)
427    {
428       duBuildRlcLsapCfg(ENTMAC, (Inst)RLC_DL_INST, cellIdx);
429    }
430
431    return ROK;
432 }
433 /**************************************************************************
434  * @brief Function to handle Config Confirm from RLC
435  *
436  * @details
437  *
438  *      Function : DuHdlRlcCfgComplete 
439  * 
440  *      Functionality:
441  *           Handles Gen Config Confirm from RLC
442  *     
443  * @param[in]  Pst     *pst, Post structure of the primitive.     
444  * @param[in]  RlcMngmt *cfm, Unpacked primitive info received from RLC
445  * @return ROK     - success
446  *         RFAILED - failure
447  *
448  ***************************************************************************/
449 uint8_t DuHdlRlcCfgComplete(Pst *pst, RlcMngmt *cfm)
450 {
451    uint8_t ret = ROK;
452    if (pst->srcInst == RLC_UL_INST)
453    {
454       ret = duProcRlcUlCfgComplete(pst, cfm);
455    }
456    else
457    {
458       ret = duProcRlcDlCfgComplete(pst, cfm);
459    }
460    return ret;
461 }
462
463 /**************************************************************************
464  * @brief Function to handle Control Config Confirm from RLC
465  *
466  * @details
467  *
468  *      Function : duHdlRlcCntrlCfgComplete 
469  * 
470  *      Functionality:
471  *           Handles Control Config Confirm from RLC
472  *     
473  * @param[in]  Pst     *pst, Post structure of the primitive.     
474  * @param[in]  RlcMngmt *cfm, Unpacked primitive info received from RLC
475  * @return ROK     - success
476  *         RFAILED - failure
477  *
478  ***************************************************************************/
479 uint8_t duHdlRlcCntrlCfgComplete(Pst *pst, RlcMngmt *cntrl)
480 {
481    uint8_t ret = ROK;
482
483    if (cntrl->cfm.status == LCM_PRIM_OK)
484    {
485       switch (cntrl->hdr.elmId.elmnt)
486       {
487          case  STRGUSAP:
488             {
489                if (pst->srcInst == RLC_DL_INST)
490                {
491                   DU_LOG("\nDU_APP : BIND OF RLC DL TO MAC (RGU) SAP SUCCESSFUL");
492                   macCfgInst++;
493                   if(macCfgInst < DEFAULT_CELLS)
494                   {
495                      macCfgInst = 0;
496                      duBindUnbindRlcToMacSap((Inst) RLC_DL_INST, ABND);
497                   }
498                   else
499                   {
500                      duBindUnbindRlcToMacSap((Inst) RLC_UL_INST, ABND);
501                   }
502                }
503                else
504                {
505                   DU_LOG("\nDU_APP : BIND OF RLC UL TO MAC (RGU) SAP SUCCESSFUL");
506                   macCfgInst++;
507                   if(macCfgInst < DEFAULT_CELLS)
508                   {
509                      duBindUnbindRlcToMacSap((Inst) RLC_UL_INST, ABND);
510                   }
511                   else
512                   {
513                      duSendSchCfg();
514                   }
515                   break;
516                }
517             }
518
519       }
520    }
521    return ret;
522 }
523 /**************************************************************************
524  * @brief Function to handle Config Confirm from RLC UL
525  *
526  * @details
527  *
528  *      Function : duHdlRlcUlCfgComplete 
529  * 
530  *      Functionality:
531  *           Handles Config Confirm from RLC UL
532  *     
533  * @param[in]  Pst     *pst, Post structure of the primitive.     
534  * @param[in]  RlcMngmt *cfm, Unpacked primitive info received from RLC UL
535  * @return ROK     - success
536  *         RFAILED - failure
537  *
538  ***************************************************************************/
539 uint8_t duProcRlcUlCfgComplete(Pst *pst, RlcMngmt *cfm)
540 {
541    uint8_t ret;
542
543    DU_LOG("\nDU_APP : RLC UL Cfg Status %d", cfm->cfm.status);
544    if (cfm->cfm.status == LCM_PRIM_OK)
545    {
546       switch(cfm->hdr.elmId.elmnt)
547       {
548          case STGEN:
549             {
550                rlcUlCfg |= RLC_GEN_CFG;
551                break;
552             }
553          case STRGUSAP:
554             {
555                numRlcMacSaps++;
556                if(numRlcMacSaps == DEFAULT_CELLS)
557                {
558                   rlcUlCfg |= RLC_MAC_SAP_CFG;
559                   numRlcMacSaps = 0;
560                }
561                break;
562             }
563          case STUDXSAP:
564             {
565                rlcUlCfg |= RLC_UDX_SAP_CFG;
566                break;
567
568             }
569          default:
570             break;
571       }
572       DU_LOG("\nDU_APP : RLC UL Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
573       if(rlcUlCfg == DU_RLC_UL_CONFIGURED)
574       {
575          rlcUlCfg = 0;
576          numRlcMacSaps = 0;
577          //Start configuration of RLC DL
578          duSendRlcDlCfg();
579
580       }
581    }
582    else
583    {
584       DU_LOG("\nDU_APP : Config confirm NOK from RLC UL");
585       ret = RFAILED;
586    }
587    return ret;
588 }
589
590 /**************************************************************************
591  * @brief Function to handle Config Confirm from RLC DL
592  *
593  * @details
594  *
595  *      Function : duHdlRlcDlCfgComplete 
596  * 
597  *      Functionality:
598  *           Handles Config Confirm from RLC DL
599  *     
600  * @param[in]  Pst     *pst, Post structure of the primitive.     
601  * @param[in]  RlcMngmt *cfm, Unpacked primitive info received from RLC DL
602  * @return ROK     - success
603  *         RFAILED - failure
604  *
605  ***************************************************************************/
606 uint8_t duProcRlcDlCfgComplete(Pst *pst, RlcMngmt *cfm)
607 {
608    DU_LOG("\nDU_APP : RLC DL Cfg Status %d", cfm->cfm.status);
609    if (cfm->cfm.status == LCM_PRIM_OK)
610    {
611       switch(cfm->hdr.elmId.elmnt)
612       {
613          case STGEN:
614             {
615                rlcDlCfg |= RLC_GEN_CFG;
616                break;
617             }
618          case STRGUSAP:
619             {
620                numRlcMacSaps++;
621                if(numRlcMacSaps == DEFAULT_CELLS)
622                {
623                   rlcDlCfg |= RLC_MAC_SAP_CFG;
624                   numRlcMacSaps = 0;
625                }
626                break;
627             }
628          case STUDXSAP:
629             {
630                rlcDlCfg |= RLC_UDX_SAP_CFG;
631                break;
632
633             }
634          default:
635             break;
636
637       }
638       DU_LOG("\nDU_APP : RLC DL Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
639       if(rlcDlCfg == DU_RLC_DL_CONFIGURED)
640       {
641          rlcDlCfg = 0;
642          //Start configuration of MAC
643          duSendMacCfg();
644
645       }
646    }
647    else
648    {
649       DU_LOG("\nDU_APP : Config confirm NOK from RLC DL");
650    }
651    return ROK;
652 }
653
654 /**************************************************************************
655  * @brief Function to send configs to MAC
656  *
657  * @details
658  *
659  *      Function : duSendMacCfg 
660  * 
661  *      Functionality:
662  *           Initiates Configs towards MAC layer
663  *     
664  * @param[in]  void
665  * @return ROK     - success
666  *         RFAILED - failure
667  *
668  ***************************************************************************/
669 uint8_t duSendMacCfg()
670 {
671    duBuildMacGenCfg();
672    duBuildMacUsapCfg(RLC_UL_INST);
673    duBuildMacUsapCfg(RLC_DL_INST);
674
675    return ROK;
676 }
677
678 /**************************************************************************
679  * @brief Function to fill gen config required by MAC
680  *
681  * @details
682  *
683  *      Function : duBuildMacGenCfg 
684  * 
685  *      Functionality:
686  *           Initiates general Configs towards MAC
687  *     
688  * @param[in] void
689  * @return ROK     - success
690  *         RFAILED - failure
691  *
692  ***************************************************************************/
693 uint8_t duBuildMacGenCfg()
694 {
695    RgMngmt       rgMngmt;
696    RgGenCfg      *genCfg=NULLP;
697    Pst           pst;
698
699    DU_SET_ZERO(&pst, sizeof(Pst));
700    DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
701
702    genCfg   = &(rgMngmt.t.cfg.s.genCfg);
703
704    /*----------- Fill General Configuration Parameters ---------*/
705    genCfg->mem.region = MAC_MEM_REGION;
706    genCfg->mem.pool   = MAC_POOL;
707    genCfg->tmrRes     = 10;
708    genCfg->numRguSaps = 2;
709
710    genCfg->lmPst.dstProcId = DU_PROC;
711    genCfg->lmPst.srcProcId = DU_PROC;
712    genCfg->lmPst.dstEnt    = ENTDUAPP;
713    genCfg->lmPst.dstInst   = 0;
714    genCfg->lmPst.srcEnt    = ENTMAC;
715    genCfg->lmPst.srcInst   = macCfgInst;
716    genCfg->lmPst.prior     = PRIOR0;
717    genCfg->lmPst.route     = RTESPEC;
718    genCfg->lmPst.region    = MAC_MEM_REGION;
719    genCfg->lmPst.pool      = MAC_POOL;
720    genCfg->lmPst.selector  = ODU_SELECTOR_LC;
721
722    /* Fill Header */
723    rgMngmt.hdr.msgType             = TCFG;
724    rgMngmt.hdr.msgLen              = 0;
725    rgMngmt.hdr.entId.ent           = ENTMAC;
726    rgMngmt.hdr.entId.inst          = (Inst)0;
727    rgMngmt.hdr.elmId.elmnt         = STGEN;
728    rgMngmt.hdr.seqNmb              = 0;
729    rgMngmt.hdr.version             = 0;
730    rgMngmt.hdr.transId             = 0;
731
732    rgMngmt.hdr.response.prior      = PRIOR0;
733    rgMngmt.hdr.response.route      = RTESPEC;
734    rgMngmt.hdr.response.mem.region = MAC_MEM_REGION;
735    rgMngmt.hdr.response.mem.pool   = MAC_POOL;
736    rgMngmt.hdr.response.selector   = ODU_SELECTOR_LC;
737
738    /* Fill Pst */
739    pst.selector  = ODU_SELECTOR_LC;
740    pst.srcEnt    = ENTDUAPP;
741    pst.dstEnt    = ENTMAC;
742    pst.dstInst   = macCfgInst;
743    pst.dstProcId = DU_PROC;
744    pst.srcProcId = DU_PROC;
745    pst.region = duCb.init.region;
746
747    DU_LOG("\nDU_APP : MAC Gen Cfg Req sent");
748
749    /* Send the request to MAC */
750    cmPkLrgCfgReq(&pst, &rgMngmt);
751
752    return ROK;
753 }
754
755 /**************************************************************************
756  * @brief Function to fill USAP config required by MAC
757  *
758  * @details
759  *
760  *      Function : duBuildMacUsapCfg 
761  * 
762  *      Functionality:
763  *           Initiates USAP Configs towards MAC
764  *     
765  * @param[in] SpId  Specifies if RLC UL or RLC DL instance 
766  * @return ROK     - success
767  *         RFAILED - failure
768  *
769  ***************************************************************************/
770 uint8_t duBuildMacUsapCfg(SpId sapId)
771 {
772    RgMngmt     rgMngmt;
773    RgUpSapCfg  *uSap = NULLP;
774    Pst         pst;
775
776    DU_SET_ZERO(&pst, sizeof(Pst));
777    DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
778
779    uSap   = &(rgMngmt.t.cfg.s.rguSap);
780
781    uSap->mem.region = MAC_MEM_REGION;
782    uSap->mem.pool   = MAC_POOL;
783    uSap->suId       = 0;
784    uSap->spId       = sapId;
785    uSap->procId     = DU_PROC;
786    uSap->ent        = ENTRLC;
787    uSap->inst       = sapId;
788    uSap->prior      = PRIOR0;
789    uSap->route      = RTESPEC;
790    uSap->selector   = ODU_SELECTOR_LC ;
791
792    /* fill header */
793    rgMngmt.hdr.msgType             = TCFG;
794    rgMngmt.hdr.entId.ent           = ENTMAC;
795    rgMngmt.hdr.entId.inst          = (Inst)0;
796    rgMngmt.hdr.elmId.elmnt         = STRGUSAP;
797    rgMngmt.hdr.response.mem.region = MAC_MEM_REGION;
798    rgMngmt.hdr.response.mem.pool   = MAC_POOL;
799
800    /* fill pst */
801    pst.selector  = ODU_SELECTOR_LC;
802    pst.srcEnt    = ENTDUAPP;
803    pst.dstEnt    = ENTMAC;
804    pst.dstInst   = macCfgInst;
805    pst.dstProcId = DU_PROC;
806    pst.srcProcId = DU_PROC;
807    pst.region    = duCb.init.region;
808
809    DU_LOG("\nDU_APP : MAC Rgu USap Cfg Req sent");
810
811    /* Send the request to MAC */
812    cmPkLrgCfgReq(&pst, &rgMngmt);
813
814    return ROK;
815 }
816
817 /**************************************************************************
818  * @brief Function to handle Config Confirm from MAC
819  *
820  * @details
821  *
822  *      Function : duHdlMacCfgComplete 
823  * 
824  *      Functionality:
825  *           Handles Gen Config Confirm from MAC
826  *     
827  * @param[in]  Pst     *pst, Post structure of the primitive.     
828  * @param[in]  RgMngmt *cfm, Unpacked primitive info received from MAC
829  * @return ROK     - success
830  *         RFAILED - failure
831  *
832  ***************************************************************************/
833 uint8_t duHdlMacCfgComplete(Pst *pst, RgMngmt *cfm)
834 {
835    uint8_t ret = ROK;
836
837    if (cfm->cfm.status == LCM_PRIM_OK)
838    {
839       switch (cfm->hdr.elmId.elmnt)
840       {
841          case STGEN:
842             {
843                macCfg |= MAC_GEN_CFG;
844                break;
845             }
846          case STRGUSAP:
847             {
848                macCfg |= MAC_SAP_CFG;
849                numRlcMacSaps++;
850                break;
851             }
852          default:
853             break;
854       }
855       DU_LOG("\nDU_APP : MAC Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
856       if(macCfg == MAC_CONFIGURED && numRlcMacSaps == MAX_MAC_SAP)
857       {
858          macCfg = 0;
859          DU_LOG("\nDU_APP : Completed sending Configs");
860          macCfgInst = 0;
861          duBindUnbindRlcToMacSap(RLC_DL_INST, ABND);
862       }
863
864    }
865    else
866    {
867       DU_LOG("\nDU_APP : Config confirm NOK from MAC");
868       ret = RFAILED;
869    }
870    return ret;
871 }
872
873 /**************************************************************************
874  * @brief Function to bind/unbind RLC to MAC SAP
875  *
876  * @details
877  *
878  *      Function : duBindUnbindRlcToMacSap 
879  * 
880  *      Functionality:
881  *           Initiates Bind/Unbind from RLC to MAC
882  *     
883  * @param[in] Inst   Specifies if RLC UL or RLC DL instance 
884  * @param[in] action Specifies if action is bind or unbind
885  * @return ROK     - success
886  *         RFAILED - failure
887  *
888  ***************************************************************************/
889 uint8_t duBindUnbindRlcToMacSap(uint8_t inst, uint8_t action)
890 {
891    RlcCntrl  *cntrl = NULLP;
892    RlcMngmt  rlcMngmt;
893    Pst      pst;
894
895
896    DU_SET_ZERO(&rlcMngmt, sizeof(RlcMngmt));
897    DU_SET_ZERO(&pst, sizeof(Pst));
898
899    if (action == ABND)
900    {
901       DU_LOG("\nDU_APP : Cntrl Req to RLC inst %d to bind MAC sap", inst);
902    }
903    else
904    {
905       DU_LOG("\nDU_APP : Cntrl Req to RLC inst %d to unbind MAC sap", inst);
906    }
907    cntrl = &(rlcMngmt.t.cntrl);
908
909    cntrl->action            =  action;
910    cntrl->subAction         =  DU_ZERO_VAL;
911    cntrl->s.sapCntrl.suId   =  macCfgInst;
912    cntrl->s.sapCntrl.spId   =  inst;
913
914    /* Fill header */
915    rlcMngmt.hdr.msgType             = TCNTRL;
916    rlcMngmt.hdr.entId.ent           = ENTRLC;
917    rlcMngmt.hdr.entId.inst          = inst;
918    rlcMngmt.hdr.elmId.elmnt         = 186; /* ambiguous defines in lkw.h and lrg.h so direct hardcoded*/
919    rlcMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
920       RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
921    rlcMngmt.hdr.response.mem.pool   = RLC_POOL;
922
923    /* Fill pst */
924    pst.selector  = ODU_SELECTOR_LC;
925    pst.srcEnt    = ENTDUAPP;
926    pst.dstEnt    = ENTRLC;
927    pst.dstProcId = DU_PROC;
928    pst.dstInst   = inst;
929    pst.srcProcId = DU_PROC;
930    pst.region    = duCb.init.region;
931
932    cmPkLkwCntrlReq(&pst, &rlcMngmt);
933
934    return ROK;
935 }
936 /*******************************************************************
937  *
938  * @brief Handles SCTP notifications
939  *
940  * @details
941  *
942  *    Function : duSctpNtfyHdl
943  *
944  *    Functionality:
945  *         Handles SCTP notification
946  *
947  * @params[in] Message Buffer
948  *             SCTP notification
949  *
950  * @return ROK     - success
951  *         RFAILED - failure
952  *
953  * ****************************************************************/
954
955 uint8_t duSctpNtfyHdl(Buffer *mBuf, CmInetSctpNotification *ntfy)
956 {
957    if(f1Params.assocId == ntfy->u.assocChange.assocId)
958    {
959       if(BuildAndSendF1SetupReq() != ROK)
960       {
961          return RFAILED;
962       }
963    }
964    else if(ricParams.assocId == ntfy->u.assocChange.assocId)
965    {
966       if(BuildAndSendE2SetupReq() != ROK)
967       {
968          return RFAILED;
969       }
970    }
971    else
972    {
973       DU_LOG("\nDU_APP : Invalid assocId %d received", ntfy->u.assocChange.assocId);
974       return RFAILED;
975    }
976    return ROK;
977 }
978
979 /*******************************************************************
980  *
981  * @brief  Fills Pst struct for ENTEGTP
982  *
983  * @details
984  *
985  *    Function : duFillEgtpPst
986  *
987  *    Functionality:
988  *       Fills Pst struct for ENTEGTP
989  *
990  * @params[in] 
991  * @return ROK     - success
992  *         RFAILED - failure
993  *
994  * ****************************************************************/
995 uint8_t duFillEgtpPst(Pst *pst, Event event)
996 {
997    memset(pst, 0, sizeof(Pst));
998    pst->srcEnt = (Ent)ENTDUAPP;
999    pst->srcInst = (Inst)DU_INST;
1000    pst->srcProcId = DU_PROC;
1001    pst->dstEnt = (Ent)ENTEGTP;
1002    pst->dstInst = (Inst)EGTP_INST;
1003    pst->dstProcId = pst->srcProcId;
1004    pst->event = event;
1005    pst->selector = ODU_SELECTOR_LC;
1006    pst->pool= DU_POOL;
1007
1008    return ROK;
1009 }
1010
1011
1012 /*******************************************************************
1013  *
1014  * @brief  Function to configure EGTP
1015  *
1016  * @details
1017  *
1018  *    Function : duBuildEgtpCfgReq
1019  *
1020  *    Functionality:
1021  *       Function to configure EGTP
1022  *
1023  * @params[in] 
1024  * @return ROK     - success
1025  *         RFAILED - failure
1026  *
1027  * ****************************************************************/
1028
1029 uint8_t duBuildEgtpCfgReq()
1030 {
1031    Pst pst;
1032    EgtpConfig egtpCfg;
1033
1034    DU_LOG("\nDU_APP : Sending EGTP config request");
1035
1036    memset(&egtpCfg, 0, sizeof(EgtpConfig));
1037    memcpy(&egtpCfg, &duCfgParam.egtpParams, sizeof(EgtpConfig));
1038
1039    duFillEgtpPst(&pst, EVTCFGREQ);
1040    packEgtpCfgReq(&pst, egtpCfg);
1041
1042    return ROK;
1043 }
1044
1045 /*******************************************************************
1046  *
1047  * @brief  Function to configure EGTP
1048  *
1049  * @details
1050  *
1051  *    Function : duBuildEgtpCfgReq
1052  *
1053  *    Functionality:
1054  *       Function to configure EGTP
1055  *
1056  * @params[in] 
1057  * @return ROK     - success
1058  *         RFAILED - failure
1059  *
1060  * ****************************************************************/
1061 uint8_t duHdlEgtpCfgComplete(CmStatus cfm)
1062 {
1063    uint8_t ret = ROK;
1064
1065    if(cfm.status == LCM_PRIM_OK)
1066    {
1067       DU_LOG("\nDU_APP : EGTP configuraton complete");
1068 #ifdef EGTP_TEST
1069       duSendEgtpSrvOpenReq();
1070 #endif
1071    }
1072    else
1073    {
1074       DU_LOG("\nDU_APP : EGTP configuraton failed");
1075       ret = RFAILED;
1076    }
1077
1078    return (ret);
1079 }
1080
1081 /*******************************************************************
1082  *
1083  * @brief  Sends server open request to EGTP
1084  *
1085  * @details
1086  *
1087  *    Function : duSendEgtpSrvOpenReq
1088  *
1089  *    Functionality:
1090  *       Sends server open request to EGTP
1091  *
1092  * @params[in] 
1093  * @return ROK     - success
1094  *         RFAILED - failure
1095  *
1096  * ****************************************************************/
1097
1098 uint8_t duSendEgtpSrvOpenReq()
1099 {
1100    Pst pst;
1101
1102    DU_LOG("\nDU_APP : Sending EGTP server open request");
1103
1104    duFillEgtpPst(&pst, EVTSRVOPENREQ);
1105    packEgtpSrvOpenReq(&pst);
1106
1107    return ROK;
1108 }
1109
1110 /*******************************************************************
1111  *
1112  * @brief Handles server open confirmation
1113  *
1114  * @details
1115  *
1116  *    Function : duHdlEgtpSrvOpenComplete
1117  *
1118  *    Functionality:
1119  *        Handles server open confirmation
1120  *
1121  * @params[in] 
1122  * @return ROK     - success
1123  *         RFAILED - failure
1124  *
1125  *****************************************************************/
1126
1127 uint8_t duHdlEgtpSrvOpenComplete(CmStatus cfm)
1128 {
1129    uint8_t ret = ROK;
1130
1131    if(cfm.status == LCM_PRIM_OK)
1132    {
1133       DU_LOG("\nDU_APP : EGTP server opened successfully");
1134 #ifdef EGTP_TEST
1135       duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_ADD, EGTP_LCL_TEID, EGTP_REM_TEID);
1136 #endif
1137    }
1138    else
1139    {
1140       DU_LOG("\nDU_APP : EGTP server opening failed");
1141       ret = RFAILED;
1142    }
1143
1144    return (ret);
1145 }
1146
1147 /*******************************************************************
1148  *
1149  * @brief Sends tunnel management request
1150  *
1151  * @details
1152  *
1153  *    Function : duSendEgtpTnlMgmtReq 
1154  *
1155  *    Functionality:
1156  *        Builds and sends tunnel management request to EGTP
1157  *
1158  * @params[in] Action
1159  *             Local tunnel endpoint id
1160  *             Remote tunnel endpoint id 
1161  * @return ROK     - success
1162  *         RFAILED - failure
1163  *
1164  * ****************************************************************/
1165
1166 uint8_t duSendEgtpTnlMgmtReq(uint8_t action, uint32_t lclTeid, uint32_t remTeid)
1167 {
1168    Pst pst;
1169    EgtpTnlEvt tnlEvt;
1170
1171    tnlEvt.action = action;
1172    tnlEvt.lclTeid = lclTeid;
1173    tnlEvt.remTeid = remTeid;
1174
1175    DU_LOG("\nDU_APP : Sending EGTP tunnel management request");
1176
1177    duFillEgtpPst(&pst, EVTTNLMGMTREQ);
1178    packEgtpTnlMgmtReq(&pst, tnlEvt);
1179
1180    return ROK;
1181 }
1182
1183 /*******************************************************************
1184  *
1185  * @brief Handles Tunnel management confirm 
1186  *
1187  * @details
1188  *
1189  *    Function : duHdlEgtpTnlMgmtCfm
1190  *
1191  *    Functionality:
1192  *      Handles tunnel management confirm received from Egtp
1193  *
1194  * @params[in] Tunnel Event  
1195  * @return ROK     - success
1196  *         RFAILED - failure
1197  *
1198  * ****************************************************************/
1199 uint8_t duHdlEgtpTnlMgmtCfm(EgtpTnlEvt tnlEvtCfm)
1200 {
1201    uint8_t ret = ROK;
1202
1203    if(tnlEvtCfm.cfmStatus.status == LCM_PRIM_OK)
1204    {
1205       DU_LOG("\nDU_APP : Tunnel management confirm OK");
1206    }
1207    else
1208    {
1209       DU_LOG("\nDU_APP : Tunnel management failed");
1210       ret = RFAILED;
1211    }
1212
1213    return (ret);
1214 }
1215
1216 uint8_t duSendEgtpDatInd(Buffer *mBuf)
1217 {
1218    EgtpMsg  egtpMsg;
1219
1220    /* Fill EGTP header */
1221    egtpMsg.msgHdr.msgType = EGTPU_MSG_GPDU;
1222    egtpMsg.msgHdr.nPdu.pres = FALSE;
1223    egtpMsg.msgHdr.seqNum.pres = FALSE;
1224    egtpMsg.msgHdr.extHdr.udpPort.pres = FALSE;
1225    egtpMsg.msgHdr.extHdr.pdcpNmb.pres = FALSE;
1226    egtpMsg.msgHdr.teId = 1;
1227    egtpMsg.msg = mBuf;
1228
1229    egtpHdlDatInd(egtpMsg);
1230
1231    return ROK;
1232
1233 }
1234
1235 #ifdef EGTP_TEST
1236 /*******************************************************************
1237  *
1238  * @brief Simulate UL Data for intial test
1239  *
1240  * @details
1241  *
1242  *    Function : duSendEgtpTestData
1243  *
1244  *    Functionality:
1245  *      Simulate UL data for initial test
1246  *
1247  * @params[in] 
1248  * @return ROK     - success
1249  *         RFAILED - failure
1250  *
1251  * ****************************************************************/
1252 uint8_t duSendEgtpTestData()
1253 {
1254    char data[30] = "This is EGTP data from DU";
1255    int datSize = 30;
1256
1257    Buffer   *mBuf;
1258
1259    if(ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) == ROK)
1260    {
1261       if(ODU_ADD_POST_MSG_MULT((Data *)data, datSize, mBuf) != ROK)
1262       {
1263          DU_LOG("\nDU_APP : ODU_ADD_POST_MSG_MULT failed");
1264          ODU_PUT_MSG_BUF(mBuf);
1265          return RFAILED;
1266       }
1267    }
1268    else
1269    {
1270       DU_LOG("\nDU_APP : Failed to allocate memory");
1271       return RFAILED;
1272    }
1273
1274    /* filling IPv4 header */ 
1275    CmIpv4Hdr ipv4Hdr;
1276    MsgLen    mLen;
1277
1278    mLen = 0;
1279    ODU_GET_MSG_LEN(mBuf, &mLen);
1280
1281    memset(&ipv4Hdr, 0, sizeof(CmIpv4Hdr));
1282    ipv4Hdr.length = CM_IPV4_HDRLEN + mLen;
1283    ipv4Hdr.hdrVer = 0x45;
1284    ipv4Hdr.proto = 1;
1285    ipv4Hdr.srcAddr = CM_INET_NTOH_UINT32(duCfgParam.egtpParams.localIp.ipV4Addr);
1286    ipv4Hdr.destAddr = CM_INET_NTOH_UINT32(duCfgParam.egtpParams.destIp.ipV4Addr);
1287
1288    /* Packing IPv4 header into buffer */
1289    uint8_t          ret, cnt, idx;
1290    Data         revPkArray[CM_IPV4_HDRLEN];
1291    Data         pkArray[CM_IPV4_HDRLEN];
1292
1293    /* initialize locals */
1294    cnt = 0;
1295    memset(revPkArray, 0, CM_IPV4_HDRLEN);
1296    memset(pkArray, 0, CM_IPV4_HDRLEN);
1297
1298    /* Pack Header Version */
1299    pkArray[cnt++] = ipv4Hdr.hdrVer;
1300
1301    /* Pack TOS */
1302    pkArray[cnt++] = ipv4Hdr.tos;
1303
1304    pkArray[cnt++] = (Data)GetHiByte(ipv4Hdr.length);
1305    pkArray[cnt++] = (Data)GetLoByte(ipv4Hdr.length);
1306
1307    /* Pack Id */
1308    pkArray[cnt++] = (Data) GetHiByte(ipv4Hdr.id);
1309    pkArray[cnt++] = (Data) GetLoByte(ipv4Hdr.id);
1310
1311    /* Pack Offset */
1312    pkArray[cnt++] = (Data)GetHiByte(ipv4Hdr.off);
1313    pkArray[cnt++] = (Data)GetLoByte(ipv4Hdr.off);
1314
1315    /* Pack TTL */
1316    pkArray[cnt++] = ipv4Hdr.ttl;
1317
1318    /* Pack Protocol */
1319    pkArray[cnt++] = ipv4Hdr.proto;
1320
1321    /* Pack Checksum */
1322    pkArray[cnt++] = (Data)GetHiByte(ipv4Hdr.chkSum);
1323    pkArray[cnt++] = (Data)GetLoByte(ipv4Hdr.chkSum);
1324
1325    /* Pack Source Address */
1326    pkArray[cnt++] = (Data)GetHiByte(GetHiWord(ipv4Hdr.srcAddr));
1327    pkArray[cnt++] = (Data)GetLoByte(GetHiWord(ipv4Hdr.srcAddr));
1328    pkArray[cnt++] = (Data)GetHiByte(GetLoWord(ipv4Hdr.srcAddr));
1329    pkArray[cnt++] = (Data)GetLoByte(GetLoWord(ipv4Hdr.srcAddr));
1330
1331    /* Pack Destination Address */
1332    pkArray[cnt++] = (Data)GetHiByte(GetHiWord(ipv4Hdr.destAddr));
1333    pkArray[cnt++] = (Data)GetLoByte(GetHiWord(ipv4Hdr.destAddr));
1334    pkArray[cnt++] = (Data)GetHiByte(GetLoWord(ipv4Hdr.destAddr));
1335    pkArray[cnt++] = (Data)GetLoByte(GetLoWord(ipv4Hdr.destAddr));
1336
1337    for (idx = 0;  idx < CM_IPV4_HDRLEN;  idx++)
1338       revPkArray[idx] = pkArray[CM_IPV4_HDRLEN - idx -1];
1339
1340    /* this function automatically reverses revPkArray */
1341    ret = ODU_ADD_PRE_MSG_MULT(revPkArray, (MsgLen)cnt, mBuf);
1342
1343    duSendEgtpDatInd(mBuf);
1344
1345    return ROK;
1346 }
1347 #endif /* EGTP_TEST */
1348
1349
1350 /**************************************************************************
1351  * @brief Function to send configs to SCH
1352  *
1353  * @details
1354  *
1355  *      Function : duSendSchCfg 
1356  * 
1357  *      Functionality:
1358  *           Sends general config to Scheduler via MAC layer
1359  *     
1360  * @param[in]  void
1361  * @return ROK     - success
1362  *         RFAILED - failure
1363  *
1364  ***************************************************************************/
1365 uint8_t duSendSchCfg()
1366 {
1367    RgMngmt       rgMngmt;
1368    RgSchInstCfg  *cfg = NULLP;
1369    Pst           pst;
1370
1371    DU_SET_ZERO(&pst, sizeof(Pst));
1372    DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
1373
1374    cfg = &(rgMngmt.t.cfg.s.schInstCfg);
1375
1376    /* Filling of Instance Id */
1377    cfg->instId = DEFAULT_CELLS + 1;
1378    /* Filling of Gen config */
1379    cfg->genCfg.mem.region = MAC_MEM_REGION;
1380    cfg->genCfg.mem.pool = MAC_POOL;
1381    cfg->genCfg.tmrRes = 10;
1382
1383 #ifdef LTE_ADV
1384    cfg->genCfg.forceCntrlSrbBoOnPCel = FALSE;
1385    cfg->genCfg.isSCellActDeactAlgoEnable = TRUE;
1386 #endif/*LTE_ADV*/
1387    cfg->genCfg.startCellId     = 1;
1388    cfg->genCfg.lmPst.dstProcId = DU_PROC;
1389    cfg->genCfg.lmPst.srcProcId = DU_PROC;
1390    cfg->genCfg.lmPst.dstEnt    = ENTDUAPP;
1391    cfg->genCfg.lmPst.dstInst   = DU_INST;
1392    cfg->genCfg.lmPst.srcEnt    = ENTMAC;
1393    cfg->genCfg.lmPst.srcInst   = DEFAULT_CELLS + 1;
1394    cfg->genCfg.lmPst.prior     = PRIOR0;
1395    cfg->genCfg.lmPst.route     = RTESPEC;
1396    cfg->genCfg.lmPst.region    = MAC_MEM_REGION;
1397    cfg->genCfg.lmPst.pool      = MAC_POOL;
1398    cfg->genCfg.lmPst.selector  = ODU_SELECTOR_LC;
1399
1400    /* Fill Header */
1401    rgMngmt.hdr.msgType             = TCFG;
1402    rgMngmt.hdr.entId.ent           = ENTMAC;
1403    rgMngmt.hdr.entId.inst          = DU_INST;
1404    rgMngmt.hdr.elmId.elmnt         = STSCHINST;
1405    rgMngmt.hdr.response.mem.region = MAC_MEM_REGION;
1406    rgMngmt.hdr.response.mem.pool   = MAC_POOL;
1407
1408    /* Fill Pst */
1409    pst.selector  = ODU_SELECTOR_LC;
1410    pst.srcEnt    = ENTDUAPP;
1411    pst.dstEnt    = ENTMAC;
1412    pst.dstProcId = DU_PROC;
1413    pst.srcProcId = DU_PROC;
1414    pst.srcInst   = DU_INST;
1415    pst.dstInst   = 0;
1416    pst.region    = duCb.init.region;
1417    pst.event    = (Event) EVTMACSCHGENCFGREQ;
1418
1419    DU_LOG("\nDU_APP : MAC Sch Cfg sent");
1420
1421    /* Send the request to MAC */
1422    cmPkLrgSchCfgReq(&pst, &rgMngmt);
1423
1424    return ROK;
1425 }
1426
1427
1428 /**************************************************************************
1429  * @brief Function to configure SCTP params and 
1430  *  responsible for F1 and E2 interfaces
1431  *
1432  * @details
1433  *
1434  *      Function : duLayerConfigComplete
1435  * 
1436  *      Functionality:
1437  *           Configures SCTP Params and responsible for handling
1438  *           F1 and E2 interface.
1439  *     
1440  * @param[in]  void
1441  * @return ROK     - success
1442  *         RFAILED - failure
1443  *
1444  ***************************************************************************/
1445 uint8_t duLayerConfigComplete()
1446 {
1447    uint8_t ret = ROK;
1448
1449    DU_LOG("\nDU_APP : Configuring all Layer is complete");
1450
1451    if((ret = duSctpCfgReq(duCfgParam.sctpParams)) != ROK)
1452    {
1453       DU_LOG("\nDU_APP : Failed configuring Sctp Params");
1454       ret = RFAILED;
1455    }
1456    if((ret = duSctpAssocReq(F1_INTERFACE)) != ROK)
1457    {
1458       DU_LOG("\nDU_APP : Failed to send AssocReq F1");
1459       ret = RFAILED;
1460    }
1461    if((ret = duSctpAssocReq(E2_INTERFACE)) != ROK)
1462    {
1463       DU_LOG("\nDU_APP : Failed to send AssocReq E2");
1464       ret = RFAILED;
1465    }
1466
1467    return (ret); 
1468
1469
1470 /**************************************************************************
1471  * @brief Function to handle  SCH Config Confirm from MAC
1472  *
1473  * @details
1474  *
1475  *      Function : duHdlSchCfgComplete 
1476  * 
1477  *      Functionality:
1478  *           Handles Scheduler Gen Config Confirm from MAC
1479  *     
1480  * @param[in]  Pst     *pst, Post structure of the primitive.     
1481  * @param[in]  RgMngmt *cfm, Unpacked primitive info received from MAC
1482  * @return ROK     - success
1483  *         RFAILED - failure
1484  *
1485  ***************************************************************************/
1486 uint8_t duHdlSchCfgComplete(Pst *pst, RgMngmt *cfm)
1487 {
1488    if (cfm->cfm.status == LCM_PRIM_OK)
1489    {
1490       switch (cfm->hdr.elmId.elmnt)
1491       {
1492          case STSCHINST:
1493             {
1494                DU_LOG("\nDU_APP : Received SCH CFG CFM at DU APP");
1495                break;
1496             }
1497          default:
1498             break;
1499       }
1500    }
1501    duLayerConfigComplete();
1502    duBuildEgtpCfgReq();
1503    return ROK;
1504 }
1505
1506 /*******************************************************************
1507  *
1508  * @brief Sends Slot indication to EGTP
1509  *
1510  * @details
1511  *
1512  *    Function : duSendEgtpSlotInd
1513  *
1514  *    Functionality:
1515  *     Sends Slot indication to EGTP
1516  *
1517  * @params[in] 
1518  * @return ROK     - success
1519  *         RFAILED - failure
1520  *
1521  * ****************************************************************/
1522 uint8_t duSendEgtpSlotInd()
1523 {
1524    Pst pst;
1525
1526    duFillEgtpPst(&pst, EVTSLOTIND);
1527    packEgtpSlotInd(&pst);
1528
1529    return ROK;
1530
1531 }
1532
1533 /**************************************************************************
1534  * @brief Function to fill and send MacCellconfig
1535  *
1536  * @details
1537  *
1538  *      Function : duBuildAndSendMacCellCfg 
1539  * 
1540  *      Functionality:
1541  *           Initiates MAC Configs towards MAC
1542  *     
1543  * @param[in]cell id
1544  * @return ROK     - success
1545  *         RFAILED - failure
1546  *
1547  ***************************************************************************/
1548 uint8_t duBuildAndSendMacCellCfg(uint16_t cellId)
1549 {
1550    Pst 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 duCellCb so that we can free on confirm msg */
1560    duCb.actvCellLst[cellId-1]->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    for(actvCellIdx = 0; actvCellIdx < MAX_NUM_CELL; actvCellIdx++)
1593    {
1594       if(macCellCfgCfm->cellId == duCb.actvCellLst[actvCellIdx]->cellId)
1595       {
1596          duCb.actvCellLst[actvCellIdx]->duMacCellCfg = NULLP;
1597       }
1598    }
1599    if(macCellCfgCfm->rsp == ROK)
1600    {
1601       /* Build and send GNB-DU config update */
1602       ret = BuildAndSendDUConfigUpdate();
1603
1604       /* Build and Send Cell Start Req to MAC */
1605       ret = duBuildAndSendMacCellStartReq();
1606    }
1607    else
1608    {
1609       /* TODO : Action to be taken if cell configuration fails. 
1610        * Should CU be informed? */
1611
1612       DU_LOG("\nMac cell cfg failed");
1613       ret = RFAILED;
1614    }
1615    return ret;
1616 }
1617
1618 /*******************************************************************
1619  *
1620  * @brief Handles slot indication from MAC
1621  *
1622  * @details
1623  *
1624  *    Function : duHandleSlotInd
1625  *
1626  *    Functionality:
1627  *      Handles slot indication from MAC
1628  *
1629  * @params[in] Post structure pointer
1630  *             Slot Info pointer
1631  * @return ROK     - success
1632  *         RFAILED - failure
1633  *
1634  * ****************************************************************/
1635 uint8_t duHandleSlotInd(Pst *pst, SlotIndInfo *slotInfo)
1636 {
1637    if(slotInfo->cellId <=0 || slotInfo->cellId > MAX_NUM_CELL)
1638    {
1639       DU_LOG("\nDU APP : Invalid Cell Id %d", slotInfo->cellId);
1640    }
1641    if(!duCb.actvCellLst[slotInfo->cellId-1]->firstSlotIndRcvd)
1642    {
1643 #ifdef ODU_SLOT_IND_DEBUG_LOG
1644    DU_LOG("\nDU APP : Slot Indication received");
1645 #endif
1646       duCb.actvCellLst[slotInfo->cellId-1]->firstSlotIndRcvd = true;
1647       if((duCb.actvCellLst[slotInfo->cellId-1] != NULL) && \
1648             (duCb.actvCellLst[slotInfo->cellId-1]->cellStatus == \
1649              ACTIVATION_IN_PROGRESS))
1650       {
1651          DU_LOG("\nDU APP : 5G-NR Cell %d is UP", slotInfo->cellId);
1652          duCb.actvCellLst[slotInfo->cellId-1]->cellStatus = ACTIVATED;
1653       }
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 < MAX_NUM_CELL; id++) 
1701    {
1702       if(duCb.actvCellLst[id])
1703       {
1704          duCb.actvCellLst[id]->firstSlotIndRcvd = FALSE;
1705          cellStartInfo->cellId = duCb.actvCellLst[id]->cellInfo.nrEcgi.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    if(cellStopId->cellId <=0 || cellStopId->cellId > MAX_NUM_CELL)
1773    {
1774       DU_LOG("\nDU APP : Invalid Cell Id %d", cellStopId->cellId);
1775    }
1776    if(duCb.actvCellLst[cellStopId->cellId-1] != NULL)
1777    {
1778       if(duCb.actvCellLst[cellStopId->cellId-1]->firstSlotIndRcvd)
1779       {
1780          duCb.actvCellLst[cellStopId->cellId-1]->firstSlotIndRcvd = false;
1781          if((duCb.actvCellLst[cellStopId->cellId-1]->cellStatus == \
1782                   ACTIVATED))
1783          {
1784             DU_LOG("\nDU APP : 5G-NR Cell %d is DOWN", cellStopId->cellId);
1785             duCb.actvCellLst[cellStopId->cellId-1]->cellStatus = DELETION_IN_PROGRESS;
1786          }
1787       }
1788    }
1789    if((pst->selector == ODU_SELECTOR_LWLC) || (pst->selector == ODU_SELECTOR_TC))
1790       DU_FREE_SHRABL_BUF(MAC_MEM_REGION, pst->pool, cellStopId, sizeof(MacCellStopInfo));
1791
1792    return ROK;
1793 }
1794
1795 /*******************************************************************
1796  *
1797  * @brief Handles slot indication from MAC
1798  *
1799  * @details
1800  *
1801  *    Function : duHandleUlCcchInd
1802  *
1803  *    Functionality:
1804  *      Handles UL CCCH indication from MAC
1805  *
1806  * @params[in] Post structure pointer
1807  *             UL CCCH Ind pointer
1808  * @return ROK     - success
1809  *         RFAILED - failure
1810  *
1811  * ****************************************************************/
1812 uint8_t duHandleUlCcchInd(Pst *pst, UlCcchIndInfo *ulCcchIndInfo)
1813 {
1814
1815    DU_LOG("\nDU APP : UL CCCH Indication received");
1816
1817    return (duProcUlCcchInd(ulCcchIndInfo));
1818 }
1819
1820 /*******************************************************************
1821  *
1822  * @brief Process UL RRC Message from RLC
1823  *
1824  * @details
1825  *
1826  *    Function : DuProcRlcUlRrcMsgTrans
1827  *
1828  *    Functionality: Process UL RRC Message from RLC
1829  *
1830  * @params[in] Post structure
1831  *             UL RRC Message Info
1832  * @return ROK     - success
1833  *         RFAILED - failure
1834  *
1835  * ****************************************************************/
1836 uint8_t DuProcRlcUlRrcMsgTrans(Pst *pst, RlcUlRrcMsgInfo *ulRrcMsgInfo)
1837 {
1838    DuUeCb   ueCb;
1839    
1840    ueCb = duCb.actvCellLst[ulRrcMsgInfo->cellId -1]->ueCb[ulRrcMsgInfo->ueIdx -1];
1841    BuildAndSendULRRCMessageTransfer(ueCb, ulRrcMsgInfo->lcId, ulRrcMsgInfo->msgLen, \
1842       ulRrcMsgInfo->rrcMsg);
1843
1844    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulRrcMsgInfo->rrcMsg, ulRrcMsgInfo->msgLen);
1845    DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulRrcMsgInfo, sizeof(RlcUlRrcMsgInfo));
1846    return ROK;
1847 }
1848
1849 /*******************************************************************
1850 *
1851 * @brief Process RRC delivery report from RLC
1852 *
1853 * @details
1854 *
1855 *    Function : DuProcRlcRrcDeliveryReport
1856 *
1857 *    Functionality: Process RRC delivery Message from RLC
1858 *
1859 * @params[in] Post structure
1860 *             UL RRC Message Info
1861 * @return ROK     - success
1862 *         RFAILED - failure
1863 *
1864 * ****************************************************************/
1865 uint8_t DuProcRlcRrcDeliveryReport(Pst *pst, RrcDeliveryReport *rrcDeliveryReport)
1866 {
1867        DuUeCb   ueCb;
1868        uint8_t  ret = RFAILED;
1869
1870        ueCb = duCb.actvCellLst[rrcDeliveryReport->cellId -1]->ueCb[rrcDeliveryReport->ueIdx -1];
1871        ret = BuildAndSendRrcDeliveryReport(ueCb.gnbCuUeF1apId, ueCb.gnbDuUeF1apId,rrcDeliveryReport);
1872
1873        DU_FREE_SHRABL_BUF(pst->region, pst->pool, rrcDeliveryReport, sizeof(RrcDeliveryReport));
1874        return ret;
1875 }
1876
1877
1878 /**********************************************************************
1879   End of file
1880  **********************************************************************/