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 cell management */
22 #include "f1ap_msg_hdl.h"
31 extern S16 cmPkLkwCfgReq(Pst *pst, KwMngmt *cfg);
32 extern S16 cmPkLkwCntrlReq(Pst *pst, KwMngmt *cfg);
33 extern S16 cmPkLrgCfgReq(Pst *pst, RgMngmt *cfg);
35 /**************************************************************************
36 * @brief Function to fill configs required by RLC
40 * Function : duBuildRlcCfg
43 * Initiates general Configs towards RLC
45 * @param[in] Inst Specifies if RLC UL or RLC DL instance
46 * @return ROK - success
49 ***************************************************************************/
50 S16 duBuildRlcCfg(Inst inst)
53 KwGenCfg *genCfg = NULLP;
56 DU_SET_ZERO(&kwMngmt, sizeof(KwMngmt));
57 DU_SET_ZERO(&pst, sizeof(Pst));
59 genCfg = &(kwMngmt.t.cfg.s.gen);
61 /*----------- Fill General Configuration Parameters ---------*/
62 genCfg->maxUe = duCfgParam.maxUe;
63 genCfg->maxKwuSaps = 2;
64 genCfg->maxUdxSaps = 1;
65 genCfg->rlcMode = (inst == RLC_UL_INST) ?
66 LKW_RLC_MODE_UL : LKW_RLC_MODE_DL;
68 genCfg->maxRguSaps = DEFAULT_CELLS;
70 /*----------- Fill lmPst
71 * Parameters ---------*/
72 genCfg->lmPst.dstProcId = DU_PROC;
73 genCfg->lmPst.srcProcId = DU_PROC;
74 genCfg->lmPst.dstEnt = ENTDUAPP;
75 genCfg->lmPst.dstInst = DU_INST;
76 genCfg->lmPst.srcEnt = ENTKW;
77 genCfg->lmPst.srcInst = inst;
78 genCfg->lmPst.prior = PRIOR0;
79 genCfg->lmPst.route = RTESPEC;
80 genCfg->lmPst.region = (inst == RLC_UL_INST) ?
81 RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
82 genCfg->lmPst.pool = RLC_POOL;
83 genCfg->lmPst.selector = DU_SELECTOR_LC;
86 kwMngmt.hdr.msgType = TCFG;
87 kwMngmt.hdr.msgLen = 0;
88 kwMngmt.hdr.entId.ent = ENTKW;
89 kwMngmt.hdr.entId.inst = (Inst)0;
90 kwMngmt.hdr.elmId.elmnt = STGEN;
91 kwMngmt.hdr.seqNmb = 0;
92 kwMngmt.hdr.version = 0;
93 kwMngmt.hdr.transId = 0;
94 kwMngmt.hdr.response.prior = PRIOR0;
95 kwMngmt.hdr.response.route = RTESPEC;
96 kwMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
97 RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
98 kwMngmt.hdr.response.mem.pool = DU_POOL;
99 kwMngmt.hdr.response.selector = DU_SELECTOR_LC;
102 pst.selector = DU_SELECTOR_LC;
103 pst.srcEnt = ENTDUAPP;
106 pst.dstProcId = DU_PROC;
107 pst.srcProcId = DU_PROC;
108 pst.region = duCb.init.region;
110 printf("\nRLC Gen Cfg Req sent for inst %d", inst);
112 /* Send the request to RLC */
113 cmPkLkwCfgReq(&pst, &kwMngmt);
118 /**************************************************************************
119 * @brief Function to fill configs required by RLC
123 * Function : duBuildRlcLsapCfg
126 * Initiates general Configs towards RLC
128 * @param[in] Inst Specifies if RLC UL or RLC DL instance
129 * @return ROK - success
132 ***************************************************************************/
133 S16 duBuildRlcLsapCfg(Ent ent, Inst inst, U8 lsapInst)
137 KwSapCfg *lSap = NULLP;
140 DU_SET_ZERO(&kwMngmt, sizeof(KwMngmt));
141 DU_SET_ZERO(&pst, sizeof(Pst));
144 kwMngmt.hdr.msgType = TCFG;
145 kwMngmt.hdr.entId.ent = ENTKW;
146 kwMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
147 RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
149 kwMngmt.hdr.response.mem.pool = RLC_POOL;
152 pst.selector = DU_SELECTOR_LC;
153 pst.srcEnt = ENTDUAPP;
155 pst.dstProcId = DU_PROC;
157 pst.srcProcId = DU_PROC;
158 pst.region = duCb.init.region;
159 lSap = &(kwMngmt.t.cfg.s.sap);
161 lSap->mem.region = (inst == RLC_UL_INST) ?
162 RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
163 lSap->mem.pool = RLC_POOL;
165 lSap->bndTmrIntvl = 10;
166 lSap->priority = PRIOR0;
167 lSap->route = RTESPEC;
170 lSap->procId = DU_PROC;
172 lSap->inst = lsapInst;
173 lSap->sapId = lsapInst; /* SapId will be stored as suId in MAC */
174 lSap->selector = (inst == RLC_UL_INST) ? DU_SELECTOR_LWLC : DU_SELECTOR_TC;
175 kwMngmt.hdr.elmId.elmnt = STRGUSAP;
176 printf("\nRLC MAC Lower Sap Cfg Req sent for inst %d", inst);
181 lSap->procId = DU_PROC;
183 lSap->inst = (inst == RLC_UL_INST) ?
184 RLC_DL_INST : RLC_UL_INST;
186 lSap->selector = DU_SELECTOR_LC;
187 kwMngmt.hdr.elmId.elmnt = STUDXSAP;
188 printf("\nRLC DL/UL Lower Sap Cfg Req sent for inst %d", inst);
191 cmPkLkwCfgReq(&pst, &kwMngmt);
195 /**************************************************************************
196 * @brief Function to fill configs required by RLC
200 * Function : duBuildRlcUsapCfg
203 * Initiates general Configs towards RLC
205 * @param[in] Inst Specifies if RLC UL or RLC DL instance
206 * @return ROK - success
209 ***************************************************************************/
210 S16 duBuildRlcUsapCfg(U8 elemId, Ent ent, Inst inst)
213 KwSapCfg *uSap = NULLP;
216 DU_SET_ZERO(&kwMngmt, sizeof(KwMngmt));
217 DU_SET_ZERO(&pst, sizeof(Pst));
219 uSap = &(kwMngmt.t.cfg.s.sap);
221 uSap->selector = DU_SELECTOR_LC;
222 uSap->mem.region = (inst == RLC_UL_INST) ?
223 RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
224 uSap->mem.pool = RLC_POOL;
227 uSap->procId = DU_PROC;
231 uSap->inst = (inst == RLC_UL_INST) ?
232 RLC_DL_INST : RLC_UL_INST;
233 uSap->bndTmrIntvl = 1000;
234 uSap->priority = PRIOR0;
235 uSap->route = RTESPEC;
238 kwMngmt.hdr.msgType = TCFG;
239 kwMngmt.hdr.entId.ent = ENTKW;
240 kwMngmt.hdr.elmId.elmnt = STUDXSAP;
241 kwMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
242 RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
244 kwMngmt.hdr.response.mem.pool = RLC_POOL;
247 pst.selector = DU_SELECTOR_LC;
248 pst.srcEnt = ENTDUAPP;
250 pst.dstProcId = DU_PROC;
252 pst.srcProcId = DU_PROC;
253 pst.region = duCb.init.region;
255 printf("\nRLC Kwu Upper Sap Cfg Req sent for inst %d", inst);
256 cmPkLkwCfgReq(&pst, &kwMngmt);
260 /**************************************************************************
261 * @brief Function to invoke DU Layer Configs
265 * Function : duSendRlcUlCfg
268 * Initiates Configs towards layers of DU
271 * @return ROK - success
274 ***************************************************************************/
279 duBuildRlcCfg((Inst)RLC_UL_INST);
280 for(cellIdx = 0; cellIdx < DEFAULT_CELLS; cellIdx++)
282 duBuildRlcLsapCfg(ENTRG, (Inst)RLC_UL_INST, cellIdx);
284 duBuildRlcLsapCfg(ENTKW, (Inst)RLC_UL_INST, 0);
289 /**************************************************************************
290 * @brief Function to invoke DU Layer Configs
294 * Function : duSendRlcDlCfg
297 * Initiates Configs towards layers of DU
300 * @return ROK - success
303 ***************************************************************************/
308 duBuildRlcCfg((Inst)RLC_DL_INST);
309 duBuildRlcUsapCfg(STUDXSAP, ENTKW, (Inst)RLC_DL_INST);
310 for(cellIdx = 0; cellIdx < DEFAULT_CELLS; cellIdx++)
312 duBuildRlcLsapCfg(ENTRG, (Inst)RLC_DL_INST, cellIdx);
317 /**************************************************************************
318 * @brief Function to handle Config Confirm from RLC
322 * Function : duHdlRlcCfgComplete
325 * Handles Gen Config Confirm from RLC
327 * @param[in] Pst *pst, Post structure of the primitive.
328 * @param[in] KwMngmt *cfm, Unpacked primitive info received from RLC
329 * @return ROK - success
332 ***************************************************************************/
333 S16 duHdlRlcCfgComplete(Pst *pst, KwMngmt *cfm)
336 if (pst->srcInst == RLC_UL_INST)
338 ret = duProcRlcUlCfgComplete(pst, cfm);
342 ret = duProcRlcDlCfgComplete(pst, cfm);
347 /**************************************************************************
348 * @brief Function to handle Control Config Confirm from RLC
352 * Function : duHdlRlcCntrlCfgComplete
355 * Handles Control Config Confirm from RLC
357 * @param[in] Pst *pst, Post structure of the primitive.
358 * @param[in] KwMngmt *cfm, Unpacked primitive info received from RLC
359 * @return ROK - success
362 ***************************************************************************/
363 S16 duHdlRlcCntrlCfgComplete(Pst *pst, KwMngmt *cntrl)
367 if (cntrl->cfm.status == LCM_PRIM_OK)
369 switch (cntrl->hdr.elmId.elmnt)
373 if (pst->srcInst == RLC_DL_INST)
375 printf("\nBIND OF RLC DL TO MAC (RGU) SAP SUCCESSFUL");
377 if(macCfgInst < DEFAULT_CELLS)
380 duBindUnbindRlcToMacSap((Inst) RLC_DL_INST, ABND);
384 duBindUnbindRlcToMacSap((Inst) RLC_UL_INST, ABND);
389 printf("\nBIND OF RLC UL TO MAC (RGU) SAP SUCCESSFUL");
391 if(macCfgInst < DEFAULT_CELLS)
393 duBindUnbindRlcToMacSap((Inst) RLC_UL_INST, ABND);
408 /**************************************************************************
409 * @brief Function to handle Config Confirm from RLC UL
413 * Function : duHdlRlcUlCfgComplete
416 * Handles Config Confirm from RLC UL
418 * @param[in] Pst *pst, Post structure of the primitive.
419 * @param[in] KwMngmt *cfm, Unpacked primitive info received from RLC UL
420 * @return ROK - success
423 ***************************************************************************/
424 S16 duProcRlcUlCfgComplete(Pst *pst, KwMngmt *cfm)
428 printf("\nRLC UL Cfg Status %d", cfm->cfm.status);
429 if (cfm->cfm.status == LCM_PRIM_OK)
431 switch(cfm->hdr.elmId.elmnt)
435 rlcUlCfg |= RLC_GEN_CFG;
441 if(numRlcMacSaps == DEFAULT_CELLS)
443 rlcUlCfg |= RLC_MAC_SAP_CFG;
450 rlcUlCfg |= RLC_UDX_SAP_CFG;
457 printf("\n RLC UL Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
458 if(rlcUlCfg == DU_RLC_UL_CONFIGURED)
462 //Start configuration of RLC DL
469 printf("\nConfig confirm NOK from RLC UL");
475 /**************************************************************************
476 * @brief Function to handle Config Confirm from RLC DL
480 * Function : duHdlRlcDlCfgComplete
483 * Handles Config Confirm from RLC DL
485 * @param[in] Pst *pst, Post structure of the primitive.
486 * @param[in] KwMngmt *cfm, Unpacked primitive info received from RLC DL
487 * @return ROK - success
490 ***************************************************************************/
491 S16 duProcRlcDlCfgComplete(Pst *pst, KwMngmt *cfm)
493 printf("\nRLC DL Cfg Status %d", cfm->cfm.status);
494 if (cfm->cfm.status == LCM_PRIM_OK)
496 switch(cfm->hdr.elmId.elmnt)
500 rlcDlCfg |= RLC_GEN_CFG;
506 if(numRlcMacSaps == DEFAULT_CELLS)
508 rlcDlCfg |= RLC_MAC_SAP_CFG;
515 rlcDlCfg |= RLC_UDX_SAP_CFG;
523 printf("\n RLC DL Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
524 if(rlcDlCfg == DU_RLC_DL_CONFIGURED)
527 //Start configuration of MAC
534 printf("\nConfig confirm NOK from RLC DL");
539 /**************************************************************************
540 * @brief Function to send configs to MAC
544 * Function : duSendMacCfg
547 * Initiates Configs towards MAC layer
550 * @return ROK - success
553 ***************************************************************************/
557 duBuildMacUsapCfg(RLC_UL_INST);
558 duBuildMacUsapCfg(RLC_DL_INST);
563 /**************************************************************************
564 * @brief Function to fill gen config required by MAC
568 * Function : duBuildMacGenCfg
571 * Initiates general Configs towards MAC
574 * @return ROK - success
577 ***************************************************************************/
578 S16 duBuildMacGenCfg()
581 RgGenCfg *genCfg=NULLP;
584 DU_SET_ZERO(&pst, sizeof(Pst));
585 DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
587 genCfg = &(rgMngmt.t.cfg.s.genCfg);
589 /*----------- Fill General Configuration Parameters ---------*/
590 genCfg->mem.region = RG_MEM_REGION;
591 genCfg->mem.pool = RG_POOL;
593 genCfg->numRguSaps = 2;
595 genCfg->lmPst.dstProcId = DU_PROC;
596 genCfg->lmPst.srcProcId = DU_PROC;
597 genCfg->lmPst.dstEnt = ENTDUAPP;
598 genCfg->lmPst.dstInst = 0;
599 genCfg->lmPst.srcEnt = ENTRG;
600 genCfg->lmPst.srcInst = macCfgInst;
601 genCfg->lmPst.prior = PRIOR0;
602 genCfg->lmPst.route = RTESPEC;
603 genCfg->lmPst.region = RG_MEM_REGION;
604 genCfg->lmPst.pool = RG_POOL;
605 genCfg->lmPst.selector = DU_SELECTOR_LC;
608 rgMngmt.hdr.msgType = TCFG;
609 rgMngmt.hdr.msgLen = 0;
610 rgMngmt.hdr.entId.ent = ENTRG;
611 rgMngmt.hdr.entId.inst = (Inst)0;
612 rgMngmt.hdr.elmId.elmnt = STGEN;
613 rgMngmt.hdr.seqNmb = 0;
614 rgMngmt.hdr.version = 0;
615 rgMngmt.hdr.transId = 0;
617 rgMngmt.hdr.response.prior = PRIOR0;
618 rgMngmt.hdr.response.route = RTESPEC;
619 rgMngmt.hdr.response.mem.region = RG_MEM_REGION;
620 rgMngmt.hdr.response.mem.pool = RG_POOL;
621 rgMngmt.hdr.response.selector = DU_SELECTOR_LC;
624 pst.selector = DU_SELECTOR_LC;
625 pst.srcEnt = ENTDUAPP;
627 pst.dstInst = macCfgInst;
628 pst.dstProcId = DU_PROC;
629 pst.srcProcId = DU_PROC;
630 pst.region = duCb.init.region;
632 printf("\nMAC Gen Cfg Req sent");
634 /* Send the request to MAC */
635 cmPkLrgCfgReq(&pst, &rgMngmt);
640 /**************************************************************************
641 * @brief Function to fill USAP config required by MAC
645 * Function : duBuildMacUsapCfg
648 * Initiates USAP Configs towards MAC
650 * @param[in] SpId Specifies if RLC UL or RLC DL instance
651 * @return ROK - success
654 ***************************************************************************/
655 S16 duBuildMacUsapCfg(SpId sapId)
658 RgUpSapCfg *uSap = NULLP;
661 DU_SET_ZERO(&pst, sizeof(Pst));
662 DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
664 uSap = &(rgMngmt.t.cfg.s.rguSap);
666 uSap->mem.region = RG_MEM_REGION;
667 uSap->mem.pool = RG_POOL;
670 uSap->procId = DU_PROC;
673 uSap->prior = PRIOR0;
674 uSap->route = RTESPEC;
675 uSap->selector = DU_SELECTOR_LC ;
678 rgMngmt.hdr.msgType = TCFG;
679 rgMngmt.hdr.entId.ent = ENTRG;
680 rgMngmt.hdr.entId.inst = (Inst)0;
681 rgMngmt.hdr.elmId.elmnt = STRGUSAP;
682 rgMngmt.hdr.response.mem.region = RG_MEM_REGION;
683 rgMngmt.hdr.response.mem.pool = RG_POOL;
686 pst.selector = DU_SELECTOR_LC;
687 pst.srcEnt = ENTDUAPP;
689 pst.dstInst = macCfgInst;
690 pst.dstProcId = DU_PROC;
691 pst.srcProcId = DU_PROC;
692 pst.region = duCb.init.region;
694 printf("\nMAC Rgu USap Cfg Req sent");
696 /* Send the request to MAC */
697 cmPkLrgCfgReq(&pst, &rgMngmt);
702 /**************************************************************************
703 * @brief Function to handle Config Confirm from MAC
707 * Function : duHdlMacCfgComplete
710 * Handles Gen Config Confirm from MAC
712 * @param[in] Pst *pst, Post structure of the primitive.
713 * @param[in] RgMngmt *cfm, Unpacked primitive info received from MAC
714 * @return ROK - success
717 ***************************************************************************/
718 S16 duHdlMacCfgComplete(Pst *pst, RgMngmt *cfm)
722 if (cfm->cfm.status == LCM_PRIM_OK)
724 switch (cfm->hdr.elmId.elmnt)
728 macCfg |= MAC_GEN_CFG;
733 macCfg |= MAC_SAP_CFG;
740 printf("\n MAC Cfg Cfm received for the element %d ",cfm->hdr.elmId.elmnt);
741 if(macCfg == MAC_CONFIGURED && numRlcMacSaps == MAX_MAC_SAP)
744 printf("\n Completed sending Configs");
746 duBindUnbindRlcToMacSap(RLC_DL_INST, ABND);
752 printf("\nConfig confirm NOK from MAC");
758 /**************************************************************************
759 * @brief Function to bind/unbind RLC to MAC SAP
763 * Function : duBindUnbindRlcToMacSap
766 * Initiates Bind/Unbind from RLC to MAC
768 * @param[in] Inst Specifies if RLC UL or RLC DL instance
769 * @param[in] action Specifies if action is bind or unbind
770 * @return ROK - success
773 ***************************************************************************/
774 S16 duBindUnbindRlcToMacSap(U8 inst, U8 action)
776 KwCntrl *cntrl = NULLP;
780 TRC2(smBindKwToRguSap)
782 DU_SET_ZERO(&kwMngmt, sizeof(KwMngmt));
783 DU_SET_ZERO(&pst, sizeof(Pst));
787 printf("\nCntrl Req to RLC inst %d to bind MAC sap", inst);
791 printf("\nCntrl Req to RLC inst %d to unbind MAC sap", inst);
793 cntrl = &(kwMngmt.t.cntrl);
795 cntrl->action = action;
796 cntrl->subAction = DU_ZERO_VAL;
797 cntrl->s.sapCntrl.suId = macCfgInst;
798 cntrl->s.sapCntrl.spId = inst;
801 kwMngmt.hdr.msgType = TCNTRL;
802 kwMngmt.hdr.entId.ent = ENTKW;
803 kwMngmt.hdr.entId.inst = inst;
804 kwMngmt.hdr.elmId.elmnt = 186; /* ambiguous defines in lkw.h and lrg.h so direct hardcoded*/
805 kwMngmt.hdr.response.mem.region = (inst == RLC_UL_INST) ?
806 RLC_UL_MEM_REGION:RLC_DL_MEM_REGION;
807 kwMngmt.hdr.response.mem.pool = RLC_POOL;
810 pst.selector = DU_SELECTOR_LC;
811 pst.srcEnt = ENTDUAPP;
813 pst.dstProcId = DU_PROC;
815 pst.srcProcId = DU_PROC;
816 pst.region = duCb.init.region;
818 cmPkLkwCntrlReq(&pst, &kwMngmt);
822 /*******************************************************************
824 * @brief Function to start SCTP
828 * Function : duSctpStartReq
831 * Function to start SCTP
836 * ****************************************************************/
842 cmMemset((U8 *)&(pst), 0, sizeof(Pst));
843 pst.srcEnt = (Ent)ENTDUAPP;
844 pst.srcInst = (Inst)DU_INST;
845 pst.srcProcId = DU_PROC;
846 pst.dstEnt = (Ent)ENTSCTP;
847 pst.dstInst = (Inst)SCTP_INST;
848 pst.dstProcId = pst.srcProcId;
849 pst.event = EVTSCTPSTRT;
850 pst.selector = DU_SELECTOR_LC;
852 if(SGetMsg(DFLT_REGION, DU_POOL, &mBuf) != ROK)
854 printf("\nMemory allocation failed in duReadCfg");
862 /*******************************************************************
864 * @brief Handles SCTP notifications
868 * Function : duSctpNtfyHdl
871 * Handles SCTP notification
873 * @params[in] Message Buffer
876 * @return ROK - success
879 * ****************************************************************/
881 S16 duSctpNtfyHdl(Buffer *mBuf, CmInetSctpNotification *ntfy)
886 switch(ntfy->header.nType)
888 case CM_INET_SCTP_ASSOC_CHANGE:
889 switch(ntfy->u.assocChange.state)
891 case CM_INET_SCTP_COMM_UP:
893 printf("\nSCTP communication UP");
894 duCb.sctpStatus = TRUE;
898 /* Build and send F1 Setup response */
903 /* Reversing the encoded string */
904 if(SGetSBuf(1, 1, (Data **)&finalBuf, (Size)encBufSize) != ROK)
906 printf("Memory allocation failed");
909 for(i = 0, j = encBufSize-1; i<encBufSize; i++, j--)
911 finalBuf[j] = encBuf[i];
914 if(SGetMsg(1, 1, &f1SetupReq) == ROK)
916 if(SCpyFixMsg((Data *)finalBuf, f1SetupReq, 0, encBufSize, ©Cnt) == ROK)
918 printf("\nSending F1 setup request");
919 SPrntMsg(f1SetupReq, 0,0);
920 if(sctpOutMsgSend(f1SetupReq) != ROK)
922 printf("\nFailed Sending");
938 /**********************************************************************
940 **********************************************************************/