1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
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 #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
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 *******************************************************************************/
19 /* This file contains message handling functionality for DU APP */
23 #include "du_f1ap_msg_hdl.h"
26 #include "lphy_stub.h"
35 extern DuCfgParams duCfgParam;
36 extern S16 cmPkLkwCfgReq(Pst *pst, KwMngmt *cfg);
37 extern S16 cmPkLkwCntrlReq(Pst *pst, KwMngmt *cfg);
38 extern S16 cmPkLrgCfgReq(Pst *pst, RgMngmt *cfg);
40 packMacCellCfgReq packMacCellCfgOpts[] =
42 packMacCellCfg, /* packing for loosely coupled */
43 MacHdlCellCfgReq, /* packing for tightly coupled */
44 packMacCellCfg, /* packing for light weight loosly coupled */
47 DuMacCellStartReq packMacCellStartReqOpts[] =
49 packMacCellStartReq, /* Loose coupling */
50 MacHdlCellStartReq, /* TIght coupling */
51 packMacCellStartReq /* Light weight-loose coupling */
54 DuMacCellStopReq packMacCellStopReqOpts[] =
56 packMacCellStopReq, /* Loose coupling */
57 MacHdlCellStopReq, /* TIght coupling */
58 packMacCellStopReq /* Light weight-loose coupling */
61 /**************************************************************************
62 * @brief Function to fill configs required by RLC
66 * Function : duBuildRlcCfg
69 * Initiates general Configs towards RLC
71 * @param[in] Inst Specifies if RLC UL or RLC DL instance
72 * @return ROK - success
75 ***************************************************************************/
76 S16 duBuildRlcCfg(Inst inst)
79 KwGenCfg *genCfg = NULLP;
82 DU_SET_ZERO(&kwMngmt, sizeof(KwMngmt));
83 DU_SET_ZERO(&pst, sizeof(Pst));
85 genCfg = &(kwMngmt.t.cfg.s.gen);
87 /*----------- Fill General Configuration Parameters ---------*/
88 genCfg->maxUe = duCfgParam.maxUe;
89 genCfg->maxKwuSaps = 2;
90 genCfg->maxUdxSaps = 1;
91 genCfg->rlcMode = (inst == RLC_UL_INST) ?
92 LKW_RLC_MODE_UL : LKW_RLC_MODE_DL;
94 genCfg->maxRguSaps = DEFAULT_CELLS;
96 /*----------- Fill lmPst
97 * Parameters ---------*/
98 genCfg->lmPst.dstProcId = DU_PROC;
99 genCfg->lmPst.srcProcId = DU_PROC;
100 genCfg->lmPst.dstEnt = ENTDUAPP;
101 genCfg->lmPst.dstInst = DU_INST;
102 genCfg->lmPst.srcEnt = ENTKW;
103 genCfg->lmPst.srcInst = inst;
104 genCfg->lmPst.prior = PRIOR0;
105 genCfg->lmPst.route = RTESPEC;
106 genCfg->lmPst.region = (inst == RLC_UL_INST) ?
107 RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
108 genCfg->lmPst.pool = RLC_POOL;
109 genCfg->lmPst.selector = DU_SELECTOR_LC;
112 kwMngmt.hdr.msgType = TCFG;
113 kwMngmt.hdr.msgLen = 0;
114 kwMngmt.hdr.entId.ent = ENTKW;
115 kwMngmt.hdr.entId.inst = (Inst)0;
116 kwMngmt.hdr.elmId.elmnt = STGEN;
117 kwMngmt.hdr.seqNmb = 0;
118 kwMngmt.hdr.version = 0;
119 kwMngmt.hdr.transId = 0;
120 kwMngmt.hdr.response.prior = PRIOR0;
121 kwMngmt.hdr.response.route = RTESPEC;
122 kwMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
123 RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
124 kwMngmt.hdr.response.mem.pool = DU_POOL;
125 kwMngmt.hdr.response.selector = DU_SELECTOR_LC;
128 pst.selector = DU_SELECTOR_LC;
129 pst.srcEnt = ENTDUAPP;
132 pst.dstProcId = DU_PROC;
133 pst.srcProcId = DU_PROC;
134 pst.region = duCb.init.region;
136 DU_LOG("\nDU_APP : RLC Gen Cfg Req sent for inst %d", inst);
138 /* Send the request to RLC */
139 cmPkLkwCfgReq(&pst, &kwMngmt);
144 /**************************************************************************
145 * @brief Function to fill configs required by RLC
149 * Function : duBuildRlcLsapCfg
152 * Initiates general Configs towards RLC
154 * @param[in] Inst Specifies if RLC UL or RLC DL instance
155 * @return ROK - success
158 ***************************************************************************/
159 S16 duBuildRlcLsapCfg(Ent ent, Inst inst, U8 lsapInst)
163 KwSapCfg *lSap = NULLP;
166 DU_SET_ZERO(&kwMngmt, sizeof(KwMngmt));
167 DU_SET_ZERO(&pst, sizeof(Pst));
170 kwMngmt.hdr.msgType = TCFG;
171 kwMngmt.hdr.entId.ent = ENTKW;
172 kwMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
173 RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
175 kwMngmt.hdr.response.mem.pool = RLC_POOL;
178 pst.selector = DU_SELECTOR_LC;
179 pst.srcEnt = ENTDUAPP;
181 pst.dstProcId = DU_PROC;
183 pst.srcProcId = DU_PROC;
184 pst.region = duCb.init.region;
185 lSap = &(kwMngmt.t.cfg.s.sap);
187 lSap->mem.region = (inst == RLC_UL_INST) ?
188 RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
189 lSap->mem.pool = RLC_POOL;
191 lSap->bndTmrIntvl = 10;
192 lSap->priority = PRIOR0;
193 lSap->route = RTESPEC;
196 lSap->procId = DU_PROC;
198 lSap->inst = lsapInst;
199 lSap->sapId = lsapInst; /* SapId will be stored as suId in MAC */
200 lSap->selector = (inst == RLC_UL_INST) ? DU_SELECTOR_LWLC : DU_SELECTOR_TC;
201 kwMngmt.hdr.elmId.elmnt = STRGUSAP;
202 DU_LOG("\nDU_APP : RLC MAC Lower Sap Cfg Req sent for inst %d", inst);
207 lSap->procId = DU_PROC;
209 lSap->inst = (inst == RLC_UL_INST) ?
210 RLC_DL_INST : RLC_UL_INST;
212 lSap->selector = DU_SELECTOR_LC;
213 kwMngmt.hdr.elmId.elmnt = STUDXSAP;
214 DU_LOG("\nDU_APP : RLC DL/UL Lower Sap Cfg Req sent for inst %d", inst);
217 cmPkLkwCfgReq(&pst, &kwMngmt);
221 /**************************************************************************
222 * @brief Function to fill configs required by RLC
226 * Function : duBuildRlcUsapCfg
229 * Initiates general Configs towards RLC
231 * @param[in] Inst Specifies if RLC UL or RLC DL instance
232 * @return ROK - success
235 ***************************************************************************/
236 S16 duBuildRlcUsapCfg(U8 elemId, Ent ent, Inst inst)
239 KwSapCfg *uSap = NULLP;
242 DU_SET_ZERO(&kwMngmt, sizeof(KwMngmt));
243 DU_SET_ZERO(&pst, sizeof(Pst));
245 uSap = &(kwMngmt.t.cfg.s.sap);
247 uSap->selector = DU_SELECTOR_LC;
248 uSap->mem.region = (inst == RLC_UL_INST) ?
249 RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
250 uSap->mem.pool = RLC_POOL;
253 uSap->procId = DU_PROC;
257 uSap->inst = (inst == RLC_UL_INST) ?
258 RLC_DL_INST : RLC_UL_INST;
259 uSap->bndTmrIntvl = 1000;
260 uSap->priority = PRIOR0;
261 uSap->route = RTESPEC;
264 kwMngmt.hdr.msgType = TCFG;
265 kwMngmt.hdr.entId.ent = ENTKW;
266 kwMngmt.hdr.elmId.elmnt = STUDXSAP;
267 kwMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
268 RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
270 kwMngmt.hdr.response.mem.pool = RLC_POOL;
273 pst.selector = DU_SELECTOR_LC;
274 pst.srcEnt = ENTDUAPP;
276 pst.dstProcId = DU_PROC;
278 pst.srcProcId = DU_PROC;
279 pst.region = duCb.init.region;
281 DU_LOG("\nDU_APP : RLC Kwu Upper Sap Cfg Req sent for inst %d", inst);
282 cmPkLkwCfgReq(&pst, &kwMngmt);
287 /**************************************************************************
288 * @brief Function to populate internal DS of DU APP
292 * Function : duProcCfgComplete
295 * Populates internal data structures of DU APP after
296 * receiving configurations.
299 * @return ROK - success
302 ***************************************************************************/
303 S16 duProcCfgComplete()
306 static U16 cellId = 0;
308 for(idx=0; idx< DEFAULT_CELLS; idx++)
311 DU_ALLOC(cell, sizeof(DuCellCb))
314 DU_LOG("\nDU_APP : Memory Allocation failed in duProcCfgComplete");
321 memset(cell, 0, sizeof(DuCellCb));
322 cell->cellId = cellId++;
323 cell->cellInfo.nrEcgi.plmn.mcc[0] = PLMN_MCC0;
324 cell->cellInfo.nrEcgi.plmn.mcc[1] = PLMN_MCC1;
325 cell->cellInfo.nrEcgi.plmn.mcc[2] = PLMN_MCC2;
326 cell->cellInfo.nrEcgi.plmn.mnc[0] = PLMN_MNC0;
327 cell->cellInfo.nrEcgi.plmn.mnc[1] = PLMN_MNC1;
328 cell->cellInfo.nrEcgi.plmn.mnc[2] = PLMN_MNC2;
329 cell->cellInfo.nrEcgi.cellId = NR_CELL_ID;
330 cell->cellInfo.nrPci = NR_PCI;
331 cell->cellInfo.fiveGsTac = DU_TAC;
332 for(idx1=0; idx1<MAX_PLMN; idx1++)
334 cell->cellInfo.plmn[idx1].mcc[0] = PLMN_MCC0;
335 cell->cellInfo.plmn[idx1].mcc[1] = PLMN_MCC1;
336 cell->cellInfo.plmn[idx1].mcc[2] = PLMN_MCC2;
337 cell->cellInfo.plmn[idx1].mnc[0] = PLMN_MNC0;
338 cell->cellInfo.plmn[idx1].mnc[1] = PLMN_MNC1;
339 cell->cellInfo.plmn[idx1].mnc[2] = PLMN_MNC2;
341 cell->cellInfo.maxUe = duCfgParam.maxUe;
342 cell->cellStatus = CELL_OUT_OF_SERVICE;
343 nci = (U16)cell->cellInfo.nrEcgi.cellId;
345 duCb.cfgCellLst[nci-1] = cell;
350 //Start layer configs
351 ret = duSendRlcUlCfg();
355 /**************************************************************************
356 * @brief Function to invoke DU Layer Configs
360 * Function : duSendRlcUlCfg
363 * Initiates Configs towards layers of DU
366 * @return ROK - success
369 ***************************************************************************/
374 duBuildRlcCfg((Inst)RLC_UL_INST);
375 for(cellIdx = 0; cellIdx < DEFAULT_CELLS; cellIdx++)
377 duBuildRlcLsapCfg(ENTRG, (Inst)RLC_UL_INST, cellIdx);
379 duBuildRlcLsapCfg(ENTKW, (Inst)RLC_UL_INST, 0);
384 /**************************************************************************
385 * @brief Function to invoke DU Layer Configs
389 * Function : duSendRlcDlCfg
392 * Initiates Configs towards layers of DU
395 * @return ROK - success
398 ***************************************************************************/
403 duBuildRlcCfg((Inst)RLC_DL_INST);
404 duBuildRlcUsapCfg(STUDXSAP, ENTKW, (Inst)RLC_DL_INST);
405 for(cellIdx = 0; cellIdx < DEFAULT_CELLS; cellIdx++)
407 duBuildRlcLsapCfg(ENTRG, (Inst)RLC_DL_INST, cellIdx);
412 /**************************************************************************
413 * @brief Function to handle Config Confirm from RLC
417 * Function : duHdlRlcCfgComplete
420 * Handles Gen Config Confirm from RLC
422 * @param[in] Pst *pst, Post structure of the primitive.
423 * @param[in] KwMngmt *cfm, Unpacked primitive info received from RLC
424 * @return ROK - success
427 ***************************************************************************/
428 S16 duHdlRlcCfgComplete(Pst *pst, KwMngmt *cfm)
431 if (pst->srcInst == RLC_UL_INST)
433 ret = duProcRlcUlCfgComplete(pst, cfm);
437 ret = duProcRlcDlCfgComplete(pst, cfm);
442 /**************************************************************************
443 * @brief Function to handle Control Config Confirm from RLC
447 * Function : duHdlRlcCntrlCfgComplete
450 * Handles Control Config Confirm from RLC
452 * @param[in] Pst *pst, Post structure of the primitive.
453 * @param[in] KwMngmt *cfm, Unpacked primitive info received from RLC
454 * @return ROK - success
457 ***************************************************************************/
458 S16 duHdlRlcCntrlCfgComplete(Pst *pst, KwMngmt *cntrl)
462 if (cntrl->cfm.status == LCM_PRIM_OK)
464 switch (cntrl->hdr.elmId.elmnt)
468 if (pst->srcInst == RLC_DL_INST)
470 DU_LOG("\nDU_APP : BIND OF RLC DL TO MAC (RGU) SAP SUCCESSFUL");
472 if(macCfgInst < DEFAULT_CELLS)
475 duBindUnbindRlcToMacSap((Inst) RLC_DL_INST, ABND);
479 duBindUnbindRlcToMacSap((Inst) RLC_UL_INST, ABND);
484 DU_LOG("\nDU_APP : BIND OF RLC UL TO MAC (RGU) SAP SUCCESSFUL");
486 if(macCfgInst < DEFAULT_CELLS)
488 duBindUnbindRlcToMacSap((Inst) RLC_UL_INST, ABND);
502 /**************************************************************************
503 * @brief Function to handle Config Confirm from RLC UL
507 * Function : duHdlRlcUlCfgComplete
510 * Handles Config Confirm from RLC UL
512 * @param[in] Pst *pst, Post structure of the primitive.
513 * @param[in] KwMngmt *cfm, Unpacked primitive info received from RLC UL
514 * @return ROK - success
517 ***************************************************************************/
518 S16 duProcRlcUlCfgComplete(Pst *pst, KwMngmt *cfm)
522 DU_LOG("\nDU_APP : RLC UL Cfg Status %d", cfm->cfm.status);
523 if (cfm->cfm.status == LCM_PRIM_OK)
525 switch(cfm->hdr.elmId.elmnt)
529 rlcUlCfg |= RLC_GEN_CFG;
535 if(numRlcMacSaps == DEFAULT_CELLS)
537 rlcUlCfg |= RLC_MAC_SAP_CFG;
544 rlcUlCfg |= RLC_UDX_SAP_CFG;
551 DU_LOG("\nDU_APP : RLC UL Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
552 if(rlcUlCfg == DU_RLC_UL_CONFIGURED)
556 //Start configuration of RLC DL
563 DU_LOG("\nDU_APP : Config confirm NOK from RLC UL");
569 /**************************************************************************
570 * @brief Function to handle Config Confirm from RLC DL
574 * Function : duHdlRlcDlCfgComplete
577 * Handles Config Confirm from RLC DL
579 * @param[in] Pst *pst, Post structure of the primitive.
580 * @param[in] KwMngmt *cfm, Unpacked primitive info received from RLC DL
581 * @return ROK - success
584 ***************************************************************************/
585 S16 duProcRlcDlCfgComplete(Pst *pst, KwMngmt *cfm)
587 DU_LOG("\nDU_APP : RLC DL Cfg Status %d", cfm->cfm.status);
588 if (cfm->cfm.status == LCM_PRIM_OK)
590 switch(cfm->hdr.elmId.elmnt)
594 rlcDlCfg |= RLC_GEN_CFG;
600 if(numRlcMacSaps == DEFAULT_CELLS)
602 rlcDlCfg |= RLC_MAC_SAP_CFG;
609 rlcDlCfg |= RLC_UDX_SAP_CFG;
617 DU_LOG("\nDU_APP : RLC DL Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
618 if(rlcDlCfg == DU_RLC_DL_CONFIGURED)
621 //Start configuration of MAC
628 DU_LOG("\nDU_APP : Config confirm NOK from RLC DL");
633 /**************************************************************************
634 * @brief Function to send configs to MAC
638 * Function : duSendMacCfg
641 * Initiates Configs towards MAC layer
644 * @return ROK - success
647 ***************************************************************************/
651 duBuildMacUsapCfg(RLC_UL_INST);
652 duBuildMacUsapCfg(RLC_DL_INST);
657 /**************************************************************************
658 * @brief Function to fill gen config required by MAC
662 * Function : duBuildMacGenCfg
665 * Initiates general Configs towards MAC
668 * @return ROK - success
671 ***************************************************************************/
672 S16 duBuildMacGenCfg()
675 RgGenCfg *genCfg=NULLP;
678 DU_SET_ZERO(&pst, sizeof(Pst));
679 DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
681 genCfg = &(rgMngmt.t.cfg.s.genCfg);
683 /*----------- Fill General Configuration Parameters ---------*/
684 genCfg->mem.region = RG_MEM_REGION;
685 genCfg->mem.pool = RG_POOL;
687 genCfg->numRguSaps = 2;
689 genCfg->lmPst.dstProcId = DU_PROC;
690 genCfg->lmPst.srcProcId = DU_PROC;
691 genCfg->lmPst.dstEnt = ENTDUAPP;
692 genCfg->lmPst.dstInst = 0;
693 genCfg->lmPst.srcEnt = ENTRG;
694 genCfg->lmPst.srcInst = macCfgInst;
695 genCfg->lmPst.prior = PRIOR0;
696 genCfg->lmPst.route = RTESPEC;
697 genCfg->lmPst.region = RG_MEM_REGION;
698 genCfg->lmPst.pool = RG_POOL;
699 genCfg->lmPst.selector = DU_SELECTOR_LC;
702 rgMngmt.hdr.msgType = TCFG;
703 rgMngmt.hdr.msgLen = 0;
704 rgMngmt.hdr.entId.ent = ENTRG;
705 rgMngmt.hdr.entId.inst = (Inst)0;
706 rgMngmt.hdr.elmId.elmnt = STGEN;
707 rgMngmt.hdr.seqNmb = 0;
708 rgMngmt.hdr.version = 0;
709 rgMngmt.hdr.transId = 0;
711 rgMngmt.hdr.response.prior = PRIOR0;
712 rgMngmt.hdr.response.route = RTESPEC;
713 rgMngmt.hdr.response.mem.region = RG_MEM_REGION;
714 rgMngmt.hdr.response.mem.pool = RG_POOL;
715 rgMngmt.hdr.response.selector = DU_SELECTOR_LC;
718 pst.selector = DU_SELECTOR_LC;
719 pst.srcEnt = ENTDUAPP;
721 pst.dstInst = macCfgInst;
722 pst.dstProcId = DU_PROC;
723 pst.srcProcId = DU_PROC;
724 pst.region = duCb.init.region;
726 DU_LOG("\nDU_APP : MAC Gen Cfg Req sent");
728 /* Send the request to MAC */
729 cmPkLrgCfgReq(&pst, &rgMngmt);
734 /**************************************************************************
735 * @brief Function to fill USAP config required by MAC
739 * Function : duBuildMacUsapCfg
742 * Initiates USAP Configs towards MAC
744 * @param[in] SpId Specifies if RLC UL or RLC DL instance
745 * @return ROK - success
748 ***************************************************************************/
749 S16 duBuildMacUsapCfg(SpId sapId)
752 RgUpSapCfg *uSap = NULLP;
755 DU_SET_ZERO(&pst, sizeof(Pst));
756 DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
758 uSap = &(rgMngmt.t.cfg.s.rguSap);
760 uSap->mem.region = RG_MEM_REGION;
761 uSap->mem.pool = RG_POOL;
764 uSap->procId = DU_PROC;
767 uSap->prior = PRIOR0;
768 uSap->route = RTESPEC;
769 uSap->selector = DU_SELECTOR_LC ;
772 rgMngmt.hdr.msgType = TCFG;
773 rgMngmt.hdr.entId.ent = ENTRG;
774 rgMngmt.hdr.entId.inst = (Inst)0;
775 rgMngmt.hdr.elmId.elmnt = STRGUSAP;
776 rgMngmt.hdr.response.mem.region = RG_MEM_REGION;
777 rgMngmt.hdr.response.mem.pool = RG_POOL;
780 pst.selector = DU_SELECTOR_LC;
781 pst.srcEnt = ENTDUAPP;
783 pst.dstInst = macCfgInst;
784 pst.dstProcId = DU_PROC;
785 pst.srcProcId = DU_PROC;
786 pst.region = duCb.init.region;
788 DU_LOG("\nDU_APP : MAC Rgu USap Cfg Req sent");
790 /* Send the request to MAC */
791 cmPkLrgCfgReq(&pst, &rgMngmt);
796 /**************************************************************************
797 * @brief Function to handle Config Confirm from MAC
801 * Function : duHdlMacCfgComplete
804 * Handles Gen Config Confirm from MAC
806 * @param[in] Pst *pst, Post structure of the primitive.
807 * @param[in] RgMngmt *cfm, Unpacked primitive info received from MAC
808 * @return ROK - success
811 ***************************************************************************/
812 S16 duHdlMacCfgComplete(Pst *pst, RgMngmt *cfm)
816 if (cfm->cfm.status == LCM_PRIM_OK)
818 switch (cfm->hdr.elmId.elmnt)
822 macCfg |= MAC_GEN_CFG;
827 macCfg |= MAC_SAP_CFG;
834 DU_LOG("\nDU_APP : MAC Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
835 if(macCfg == MAC_CONFIGURED && numRlcMacSaps == MAX_MAC_SAP)
838 DU_LOG("\nDU_APP : Completed sending Configs");
840 duBindUnbindRlcToMacSap(RLC_DL_INST, ABND);
846 DU_LOG("\nDU_APP : Config confirm NOK from MAC");
852 /**************************************************************************
853 * @brief Function to bind/unbind RLC to MAC SAP
857 * Function : duBindUnbindRlcToMacSap
860 * Initiates Bind/Unbind from RLC to MAC
862 * @param[in] Inst Specifies if RLC UL or RLC DL instance
863 * @param[in] action Specifies if action is bind or unbind
864 * @return ROK - success
867 ***************************************************************************/
868 S16 duBindUnbindRlcToMacSap(U8 inst, U8 action)
870 KwCntrl *cntrl = NULLP;
874 TRC2(smBindKwToRguSap)
876 DU_SET_ZERO(&kwMngmt, sizeof(KwMngmt));
877 DU_SET_ZERO(&pst, sizeof(Pst));
881 DU_LOG("\nDU_APP : Cntrl Req to RLC inst %d to bind MAC sap", inst);
885 DU_LOG("\nDU_APP : Cntrl Req to RLC inst %d to unbind MAC sap", inst);
887 cntrl = &(kwMngmt.t.cntrl);
889 cntrl->action = action;
890 cntrl->subAction = DU_ZERO_VAL;
891 cntrl->s.sapCntrl.suId = macCfgInst;
892 cntrl->s.sapCntrl.spId = inst;
895 kwMngmt.hdr.msgType = TCNTRL;
896 kwMngmt.hdr.entId.ent = ENTKW;
897 kwMngmt.hdr.entId.inst = inst;
898 kwMngmt.hdr.elmId.elmnt = 186; /* ambiguous defines in lkw.h and lrg.h so direct hardcoded*/
899 kwMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
900 RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
901 kwMngmt.hdr.response.mem.pool = RLC_POOL;
904 pst.selector = DU_SELECTOR_LC;
905 pst.srcEnt = ENTDUAPP;
907 pst.dstProcId = DU_PROC;
909 pst.srcProcId = DU_PROC;
910 pst.region = duCb.init.region;
912 cmPkLkwCntrlReq(&pst, &kwMngmt);
916 /*******************************************************************
918 * @brief Handles SCTP notifications
922 * Function : duSctpNtfyHdl
925 * Handles SCTP notification
927 * @params[in] Message Buffer
930 * @return ROK - success
933 * ****************************************************************/
935 S16 duSctpNtfyHdl(Buffer *mBuf, CmInetSctpNotification *ntfy)
937 if(f1Params.assocId == ntfy->u.assocChange.assocId)
939 if(BuildAndSendF1SetupReq() != ROK)
944 else if(ricParams.assocId == ntfy->u.assocChange.assocId)
946 if(BuildAndSendE2SetupReq() != ROK)
953 DU_LOG("\nDU_APP : Invalid assocId %d received", ntfy->u.assocChange.assocId);
959 /*******************************************************************
961 * @brief Fills Pst struct for ENTEGTP
965 * Function : duFillEgtpPst
968 * Fills Pst struct for ENTEGTP
971 * @return ROK - success
974 * ****************************************************************/
975 S16 duFillEgtpPst(Pst *pst, Event event)
977 cmMemset((U8 *)pst, 0, sizeof(Pst));
978 pst->srcEnt = (Ent)ENTDUAPP;
979 pst->srcInst = (Inst)DU_INST;
980 pst->srcProcId = DU_PROC;
981 pst->dstEnt = (Ent)ENTEGTP;
982 pst->dstInst = (Inst)EGTP_INST;
983 pst->dstProcId = pst->srcProcId;
985 pst->selector = DU_SELECTOR_LC;
992 /*******************************************************************
994 * @brief Function to configure EGTP
998 * Function : duBuildEgtpCfgReq
1001 * Function to configure EGTP
1004 * @return ROK - success
1007 * ****************************************************************/
1009 S16 duBuildEgtpCfgReq()
1014 DU_LOG("\nDU_APP : Sending EGTP config request");
1016 cmMemset((U8 *)&egtpCfg, 0, sizeof(EgtpConfig));
1017 cmMemcpy((U8 *)&egtpCfg, (U8 *)&duCfgParam.egtpParams, (PTR)sizeof(EgtpConfig));
1019 duFillEgtpPst(&pst, EVTCFGREQ);
1020 packEgtpCfgReq(&pst, egtpCfg);
1025 /*******************************************************************
1027 * @brief Function to configure EGTP
1031 * Function : duBuildEgtpCfgReq
1034 * Function to configure EGTP
1037 * @return ROK - success
1040 * ****************************************************************/
1041 S16 duHdlEgtpCfgComplete(CmStatus cfm)
1045 if(cfm.status == LCM_PRIM_OK)
1047 DU_LOG("\nDU_APP : EGTP configuraton complete");
1049 duSendEgtpSrvOpenReq();
1054 DU_LOG("\nDU_APP : EGTP configuraton failed");
1061 /*******************************************************************
1063 * @brief Sends server open request to EGTP
1067 * Function : duSendEgtpSrvOpenReq
1070 * Sends server open request to EGTP
1073 * @return ROK - success
1076 * ****************************************************************/
1078 S16 duSendEgtpSrvOpenReq()
1082 DU_LOG("\nDU_APP : Sending EGTP server open request");
1084 duFillEgtpPst(&pst, EVTSRVOPENREQ);
1085 packEgtpSrvOpenReq(&pst);
1090 /*******************************************************************
1092 * @brief Handles server open confirmation
1096 * Function : duHdlEgtpSrvOpenComplete
1099 * Handles server open confirmation
1102 * @return ROK - success
1105 *****************************************************************/
1107 S16 duHdlEgtpSrvOpenComplete(CmStatus cfm)
1111 if(cfm.status == LCM_PRIM_OK)
1113 DU_LOG("\nDU_APP : EGTP server opened successfully");
1115 duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_ADD, EGTP_LCL_TEID, EGTP_REM_TEID);
1120 DU_LOG("\nDU_APP : EGTP server opening failed");
1127 /*******************************************************************
1129 * @brief Sends tunnel management request
1133 * Function : duSendEgtpTnlMgmtReq
1136 * Builds and sends tunnel management request to EGTP
1138 * @params[in] Action
1139 * Local tunnel endpoint id
1140 * Remote tunnel endpoint id
1141 * @return ROK - success
1144 * ****************************************************************/
1146 S16 duSendEgtpTnlMgmtReq(U8 action, U32 lclTeid, U32 remTeid)
1151 tnlEvt.action = action;
1152 tnlEvt.lclTeid = lclTeid;
1153 tnlEvt.remTeid = remTeid;
1155 DU_LOG("\nDU_APP : Sending EGTP tunnel management request");
1157 duFillEgtpPst(&pst, EVTTNLMGMTREQ);
1158 packEgtpTnlMgmtReq(&pst, tnlEvt);
1163 /*******************************************************************
1165 * @brief Handles Tunnel management confirm
1169 * Function : duHdlEgtpTnlMgmtCfm
1172 * Handles tunnel management confirm received from Egtp
1174 * @params[in] Tunnel Event
1175 * @return ROK - success
1178 * ****************************************************************/
1179 S16 duHdlEgtpTnlMgmtCfm(EgtpTnlEvt tnlEvtCfm)
1183 if(tnlEvtCfm.cfmStatus.status == LCM_PRIM_OK)
1185 DU_LOG("\nDU_APP : Tunnel management confirm OK");
1188 duSendUeCreateReqToRlc();
1190 duSendEgtpTestData();
1195 DU_LOG("\nDU_APP : Tunnel management failed");
1202 S16 duSendEgtpDatInd(Buffer *mBuf)
1206 /* Fill EGTP header */
1207 egtpMsg.msgHdr.msgType = EGTPU_MSG_GPDU;
1208 egtpMsg.msgHdr.nPdu.pres = FALSE;
1209 egtpMsg.msgHdr.seqNum.pres = FALSE;
1210 egtpMsg.msgHdr.extHdr.udpPort.pres = FALSE;
1211 egtpMsg.msgHdr.extHdr.pdcpNmb.pres = FALSE;
1212 egtpMsg.msgHdr.teId = 1;
1215 egtpHdlDatInd(egtpMsg);
1222 /*******************************************************************
1224 * @brief Simulate UL Data for intial test
1228 * Function : duSendEgtpTestData
1231 * Simulate UL data for initial test
1234 * @return ROK - success
1237 * ****************************************************************/
1238 S16 duSendEgtpTestData()
1240 char data[30] = "This is EGTP data from DU";
1245 if(SGetMsg(DU_APP_MEM_REGION, DU_POOL, &mBuf) == ROK)
1247 if(SAddPstMsgMult((Data *)data, datSize, mBuf) != ROK)
1249 DU_LOG("\nDU_APP : SAddPstMsgMult failed");
1256 DU_LOG("\nDU_APP : Failed to allocate memory");
1260 /* filling IPv4 header */
1265 SFndLenMsg(mBuf, &mLen);
1267 cmMemset((U8 *)&ipv4Hdr, 0, sizeof(CmIpv4Hdr));
1268 ipv4Hdr.length = CM_IPV4_HDRLEN + mLen;
1269 ipv4Hdr.hdrVer = 0x45;
1271 ipv4Hdr.srcAddr = CM_INET_NTOH_U32(duCfgParam.egtpParams.localIp.ipV4Addr);
1272 ipv4Hdr.destAddr = CM_INET_NTOH_U32(duCfgParam.egtpParams.destIp.ipV4Addr);
1274 /* Packing IPv4 header into buffer */
1276 Data revPkArray[CM_IPV4_HDRLEN];
1277 Data pkArray[CM_IPV4_HDRLEN];
1279 /* initialize locals */
1281 cmMemset(revPkArray, 0, CM_IPV4_HDRLEN);
1282 cmMemset(pkArray, 0, CM_IPV4_HDRLEN);
1284 /* Pack Header Version */
1285 pkArray[cnt++] = ipv4Hdr.hdrVer;
1288 pkArray[cnt++] = ipv4Hdr.tos;
1290 pkArray[cnt++] = (Data)GetHiByte(ipv4Hdr.length);
1291 pkArray[cnt++] = (Data)GetLoByte(ipv4Hdr.length);
1294 pkArray[cnt++] = (Data) GetHiByte(ipv4Hdr.id);
1295 pkArray[cnt++] = (Data) GetLoByte(ipv4Hdr.id);
1298 pkArray[cnt++] = (Data)GetHiByte(ipv4Hdr.off);
1299 pkArray[cnt++] = (Data)GetLoByte(ipv4Hdr.off);
1302 pkArray[cnt++] = ipv4Hdr.ttl;
1305 pkArray[cnt++] = ipv4Hdr.proto;
1308 pkArray[cnt++] = (Data)GetHiByte(ipv4Hdr.chkSum);
1309 pkArray[cnt++] = (Data)GetLoByte(ipv4Hdr.chkSum);
1311 /* Pack Source Address */
1312 pkArray[cnt++] = (Data)GetHiByte(GetHiWord(ipv4Hdr.srcAddr));
1313 pkArray[cnt++] = (Data)GetLoByte(GetHiWord(ipv4Hdr.srcAddr));
1314 pkArray[cnt++] = (Data)GetHiByte(GetLoWord(ipv4Hdr.srcAddr));
1315 pkArray[cnt++] = (Data)GetLoByte(GetLoWord(ipv4Hdr.srcAddr));
1317 /* Pack Destination Address */
1318 pkArray[cnt++] = (Data)GetHiByte(GetHiWord(ipv4Hdr.destAddr));
1319 pkArray[cnt++] = (Data)GetLoByte(GetHiWord(ipv4Hdr.destAddr));
1320 pkArray[cnt++] = (Data)GetHiByte(GetLoWord(ipv4Hdr.destAddr));
1321 pkArray[cnt++] = (Data)GetLoByte(GetLoWord(ipv4Hdr.destAddr));
1323 for (idx = 0; idx < CM_IPV4_HDRLEN; idx++)
1324 revPkArray[idx] = pkArray[CM_IPV4_HDRLEN - idx -1];
1326 /* this function automatically reverses revPkArray */
1327 ret = SAddPreMsgMult(revPkArray, (MsgLen)cnt, mBuf);
1329 duSendEgtpDatInd(mBuf);
1333 #endif /* EGTP_TEST */
1336 /**************************************************************************
1337 * @brief Function to send configs to SCH
1341 * Function : duSendSchCfg
1344 * Sends general config to Scheduler via MAC layer
1347 * @return ROK - success
1350 ***************************************************************************/
1354 RgSchInstCfg *cfg = NULLP;
1357 DU_SET_ZERO(&pst, sizeof(Pst));
1358 DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
1360 cfg = &(rgMngmt.t.cfg.s.schInstCfg);
1362 /* Filling of Instance Id */
1363 cfg->instId = DEFAULT_CELLS + 1;
1364 /* Filling of Gen config */
1365 cfg->genCfg.mem.region = RG_MEM_REGION;
1366 cfg->genCfg.mem.pool = RG_POOL;
1367 cfg->genCfg.tmrRes = 10;
1370 cfg->genCfg.forceCntrlSrbBoOnPCel = FALSE;
1371 cfg->genCfg.isSCellActDeactAlgoEnable = TRUE;
1373 cfg->genCfg.startCellId = 1;
1374 cfg->genCfg.lmPst.dstProcId = DU_PROC;
1375 cfg->genCfg.lmPst.srcProcId = DU_PROC;
1376 cfg->genCfg.lmPst.dstEnt = ENTDUAPP;
1377 cfg->genCfg.lmPst.dstInst = DU_INST;
1378 cfg->genCfg.lmPst.srcEnt = ENTRG;
1379 cfg->genCfg.lmPst.srcInst = DEFAULT_CELLS + 1;
1380 cfg->genCfg.lmPst.prior = PRIOR0;
1381 cfg->genCfg.lmPst.route = RTESPEC;
1382 cfg->genCfg.lmPst.region = RG_MEM_REGION;
1383 cfg->genCfg.lmPst.pool = RG_POOL;
1384 cfg->genCfg.lmPst.selector = DU_SELECTOR_LC;
1387 rgMngmt.hdr.msgType = TCFG;
1388 rgMngmt.hdr.entId.ent = ENTRG;
1389 rgMngmt.hdr.entId.inst = DU_INST;
1390 rgMngmt.hdr.elmId.elmnt = STSCHINST;
1391 rgMngmt.hdr.response.mem.region = RG_MEM_REGION;
1392 rgMngmt.hdr.response.mem.pool = RG_POOL;
1395 pst.selector = DU_SELECTOR_LC;
1396 pst.srcEnt = ENTDUAPP;
1398 pst.dstProcId = DU_PROC;
1399 pst.srcProcId = DU_PROC;
1400 pst.srcInst = DU_INST;
1402 pst.region = duCb.init.region;
1403 pst.event = (Event) EVTMACSCHGENCFGREQ;
1405 DU_LOG("\nDU_APP : MAC Sch Cfg sent");
1407 /* Send the request to MAC */
1408 cmPkLrgSchCfgReq(&pst, &rgMngmt);
1414 /**************************************************************************
1415 * @brief Function to configure SCTP params and
1416 * responsible for F1 and E2 interfaces
1420 * Function : duLayerConfigComplete
1423 * Configures SCTP Params and responsible for handling
1424 * F1 and E2 interface.
1427 * @return ROK - success
1430 ***************************************************************************/
1431 S16 duLayerConfigComplete()
1435 DU_LOG("\nDU_APP : Configuring all Layer is complete");
1437 if((ret = duSctpCfgReq(duCfgParam.sctpParams)) != ROK)
1439 DU_LOG("\nDU_APP : Failed configuring Sctp Params");
1442 if((ret = duSctpAssocReq(F1_INTERFACE)) != ROK)
1444 DU_LOG("\nDU_APP : Failed to send AssocReq F1");
1447 if((ret = duSctpAssocReq(E2_INTERFACE)) != ROK)
1449 DU_LOG("\nDU_APP : Failed to send AssocReq E2");
1456 /**************************************************************************
1457 * @brief Function to handle SCH Config Confirm from MAC
1461 * Function : duHdlSchCfgComplete
1464 * Handles Scheduler Gen Config Confirm from MAC
1466 * @param[in] Pst *pst, Post structure of the primitive.
1467 * @param[in] RgMngmt *cfm, Unpacked primitive info received from MAC
1468 * @return ROK - success
1471 ***************************************************************************/
1472 S16 duHdlSchCfgComplete(Pst *pst, RgMngmt *cfm)
1474 if (cfm->cfm.status == LCM_PRIM_OK)
1476 switch (cfm->hdr.elmId.elmnt)
1480 DU_LOG("\nDU_APP : Received SCH CFG CFM at DU APP");
1487 duLayerConfigComplete();
1488 duBuildEgtpCfgReq();
1492 /*******************************************************************
1494 * @brief Sends Slot indication to EGTP
1498 * Function : duSendEgtpSlotInd
1501 * Sends Slot indication to EGTP
1504 * @return ROK - success
1507 * ****************************************************************/
1508 S16 duSendEgtpSlotInd()
1512 duFillEgtpPst(&pst, EVTSLOTIND);
1513 packEgtpSlotInd(&pst);
1519 /**************************************************************************
1520 * @brief Function to fill and send MacCellconfig
1524 * Function : duBuildAndSendMacCellCfg
1527 * Initiates MAC Configs towards MAC
1530 * @return ROK - success
1533 ***************************************************************************/
1534 S16 duBuildAndSendMacCellCfg()
1537 DU_SET_ZERO(&pst, sizeof(Pst));
1538 MacCellCfg *duMacCellCfg = NULLP;
1540 DU_ALLOC(duMacCellCfg, sizeof(MacCellCfg));
1541 if(duMacCellCfg == NULLP)
1546 /* store the address in the duCb so that we can free on confirm msg */
1547 duCb.duMacCellCfg = duMacCellCfg;
1549 /* copy the mac config structure from duCfgParams */
1550 memcpy(duMacCellCfg,&duCfgParam.macCellCfg,sizeof(MacCellCfg));
1552 duMacCellCfg->transId = getTransId(); /* transaction ID */
1555 pst.selector = DU_SELECTOR_LWLC;
1556 pst.srcEnt = ENTDUAPP;
1560 pst.dstProcId = DU_PROC;
1561 pst.srcProcId = DU_PROC;
1562 pst.region = duCb.init.region;
1563 pst.event = EVENT_MAC_CELL_CONFIG_REQ;
1565 /* Send MAC cell config to MAC */
1566 return (*packMacCellCfgOpts[pst.selector])(&pst, duMacCellCfg);
1569 /**************************************************************************
1570 * @brief Function to Handle MAC cell config confirm
1574 * Function : duHandleMacCellCfgCfm
1577 * Initiates general Configs towards MAC
1580 * @return ROK - success
1583 ***************************************************************************/
1584 uint16_t duHandleMacCellCfgCfm(MacCellCfgCfm *macCellCfgCfm)
1588 if(macCellCfgCfm->rsp == ROK)
1590 if(macCellCfgCfm->transId == duCb.duMacCellCfg->transId)
1592 /* free the memory allocated during sending macCellCfg request */
1593 DU_FREE(duCb.duMacCellCfg->sib1Cfg.sib1Pdu, duCfgParam.srvdCellLst[0].duSysInfo.sib1Len);
1594 DU_FREE(duCb.duMacCellCfg,sizeof(MacCellCfg));
1595 duCb.duMacCellCfg = NULLP;
1597 /* Build and send GNB-DU config update */
1598 ret = BuildAndSendDUConfigUpdate();
1600 /* TODO: Trigger cell start req once cell up slot ind is received*/
1601 /* Build and Send Cell Start Req to MAC */
1602 ret = duBuildAndSendMacCellStartReq();
1607 /* transaction ID missmatch */
1608 DU_LOG("\n transaction ID mismatch in macCellCfg");
1614 DU_LOG("\nMac cell cfg failed");
1620 /*******************************************************************
1622 * @brief Handles slot indication from MAC
1626 * Function : duHandleSlotInd
1629 * Handles slot indication from MAC
1631 * @params[in] Post structure pointer
1633 * @return ROK - success
1636 * ****************************************************************/
1637 uint16_t duHandleSlotInd(Pst *pst, SlotInfo *slotInfo)
1640 DU_LOG("\nDU APP : Slot Indication received");
1642 if(slotInfo->cellId <=0 || slotInfo->cellId > DU_MAX_CELLS)
1644 DU_LOG("\nDU APP : Invalid Cell Id %d", slotInfo->cellId);
1646 if(!duCb.actvCellLst[slotInfo->cellId-1]->firstSlotIndRcvd)
1648 duCb.actvCellLst[slotInfo->cellId-1]->firstSlotIndRcvd = true;
1649 if((duCb.actvCellLst[slotInfo->cellId-1] != NULL) && \
1650 (duCb.actvCellLst[slotInfo->cellId-1]->cellStatus == \
1651 ACTIVATION_IN_PROGRESS))
1653 DU_LOG("\nDU APP : Cell Id %d is ACTIVE", slotInfo->cellId);
1654 duCb.actvCellLst[slotInfo->cellId-1]->cellStatus = ACTIVATED;
1659 /* TODO : Slot Indication to be moved out of EGTP_TEST when
1660 * data path is established */
1662 duSendEgtpSlotInd();
1664 DU_FREE_MEM(pst->region, pst->pool, slotInfo, sizeof(SlotInfo));
1668 /*******************************************************************
1670 * @brief Builds and sends cell start request to MAC
1674 * Function : duBuildAndSendMacCellStartReq
1677 * Builds and sends cell start request to MAC
1680 * @return ROK - success
1683 * ****************************************************************/
1684 uint16_t duBuildAndSendMacCellStartReq()
1687 MacCellStartInfo *cellStartInfo = NULL;
1689 DU_LOG("\nDU APP : Building and Sending cell start request to MAC");
1691 /* Send Cell Start Request to MAC */
1692 DU_ALLOC(cellStartInfo, sizeof(MacCellStartInfo));
1695 DU_LOG("\nDU APP : Memory alloc failed while building cell start request");
1699 for(uint8_t id = 0; id < DU_MAX_CELLS; id++)
1701 if(duCb.actvCellLst[id])
1703 duCb.actvCellLst[id]->firstSlotIndRcvd = FALSE;
1704 cellStartInfo->cellId = duCb.actvCellLst[id]->cellInfo.nrEcgi.cellId;
1707 pst.selector = DU_MAC_LWLC;
1708 pst.srcEnt = ENTDUAPP;
1712 pst.dstProcId = DU_PROC;
1713 pst.srcProcId = DU_PROC;
1714 pst.region = DU_APP_MEM_REGION;
1716 pst.event = EVENT_MAC_CELL_START_REQ;
1718 return (*packMacCellStartReqOpts[pst.selector])(&pst, cellStartInfo);
1724 /*******************************************************************
1726 * @brief Builds and sends cell stop request to MAC
1730 * Function : duBuildAndSendMacCellStopReq
1733 * Builds and sends cell stop request to MAC
1736 * @return ROK - success
1739 * ****************************************************************/
1740 S16 duBuildAndSendMacCellStopReq()
1743 MacCellStopInfo *cellStopInfo = NULL;
1745 DU_LOG("\nDU APP : Building and Sending cell stop request to MAC");
1747 /* Send Cell Stop Request to MAC */
1748 DU_ALLOC(cellStopInfo, sizeof(MacCellStopInfo));
1751 DU_LOG("\nDU APP : Memory alloc failed while building cell stop request");
1754 cellStopInfo->cellId = duCb.actvCellLst[0]->cellId;
1757 pst.selector = DU_MAC_LWLC;
1758 pst.srcEnt = ENTDUAPP;
1762 pst.dstProcId = DU_PROC;
1763 pst.srcProcId = DU_PROC;
1764 pst.region = DU_APP_MEM_REGION;
1766 pst.event = EVENT_MAC_CELL_STOP_REQ;
1768 return (*packMacCellStopReqOpts[pst.selector])(&pst, cellStopInfo);
1772 /**********************************************************************
1774 **********************************************************************/