X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fdu_app%2Fdu_sctp.c;h=e435cfe25742fcf91970cbe22ad3701b5b9bea44;hb=def50dc175cebc67238db5f1acd5ff322a2279bd;hp=8e6bcb7198d20755d2faf5e3e1332e510a1ace26;hpb=8660dd47a5ef27b62300fabf6b027852f1d5d026;p=o-du%2Fl2.git diff --git a/src/du_app/du_sctp.c b/src/du_app/du_sctp.c index 8e6bcb719..e435cfe25 100644 --- a/src/du_app/du_sctp.c +++ b/src/du_app/du_sctp.c @@ -17,11 +17,18 @@ *******************************************************************************/ /* This file contains all SCTP related functionality */ - -#include +#include "common_def.h" +#include "lrg.h" +#include "legtp.h" +#include "lrg.x" +#include "lkw.x" +#include "cm_inet.h" +#include "cm_inet.x" +#include "du_app_mac_inf.h" +#include "du_cfg.h" #include "du_sctp.h" #include "lsctp.h" - +#include "du_utils.h" /************************************************************************** * @brief Task Initiation callback function. @@ -43,10 +50,10 @@ * @return ROK - success * RFAILED - failure ***************************************************************************/ -S16 sctpActvInit(Ent entity, Inst inst, Region region, Reason reason) +uint8_t sctpActvInit(Ent entity, Inst inst, Region region, Reason reason) { DU_LOG("\n\nSCTP : Initializing"); - SSetProcId(DU_PROC); + ODU_SET_PROC_ID(DU_PROC); connUp = FALSE; f1Params.assocId = -1; ricParams.assocId = -1; @@ -74,7 +81,7 @@ S16 sctpActvInit(Ent entity, Inst inst, Region region, Reason reason) * RFAILED - failure * ***************************************************************************/ -S16 sctpActvTsk(Pst *pst, Buffer *mBuf) +uint8_t sctpActvTsk(Pst *pst, Buffer *mBuf) { switch(pst->srcEnt) { @@ -82,7 +89,7 @@ S16 sctpActvTsk(Pst *pst, Buffer *mBuf) { switch(pst->event) { - case EVTSTRTPOLL: + case EVTSTARTPOLL: { sctpSockPoll(); break; @@ -91,9 +98,35 @@ S16 sctpActvTsk(Pst *pst, Buffer *mBuf) break; } } - SExitTsk(); + ODU_EXIT_TASK(); return ROK; } +/******************************************************************* + * + * @brief Checks the status of the received information + * + * @details + * + * Function : duCheckReqStatus + * + * Functionality: + * Checks the status of the received information + * + * @params[in] Confirm status + * @return ROK - success + * RFAILED - failure + * + ******************************************************************/ +uint8_t duCheckReqStatus(CmStatus *cfm) +{ + uint8_t ret = ROK; + if(cfm->status != LCM_PRIM_OK) + { + DU_LOG("\nDU_APP : Failed to process the request successfully"); + ret = RFAILED; + } + return (ret); +} /************************************************************************** * @brief Function to configure the Sctp Params during config Request @@ -114,16 +147,19 @@ S16 sctpActvTsk(Pst *pst, Buffer *mBuf) * ***************************************************************************/ -S16 duSctpCfgReq(SctpParams sctpCfg, CmStatus *cfm) +uint8_t duSctpCfgReq(SctpParams sctpCfg) { + uint8_t ret = ROK; + CmStatus cfm; + /* Fill F1 Params */ f1Params.destIpAddr.ipV4Pres = sctpCfg.cuIpAddr.ipV4Pres; f1Params.destIpAddr.ipV4Addr = sctpCfg.cuIpAddr.ipV4Addr; f1Params.destPort = sctpCfg.cuPort; f1Params.itfState = DU_SCTP_DOWN; - f1Params.srcPort = sctpCfg.duPort[0]; - f1Params.recvMsgSet = ROK; - cmMemset ((U8 *)&f1Params.sockFd, -1, sizeof(CmInetFd)); + f1Params.srcPort = sctpCfg.duPort[F1_INTERFACE]; + f1Params.recvMsgSet = ROK; + memset (&f1Params.sockFd, -1, sizeof(CmInetFd)); fillDestNetAddr(&f1Params.destIpNetAddr, &f1Params.destIpAddr); fillAddrLst(&f1Params.destAddrLst, &f1Params.destIpAddr); @@ -132,9 +168,9 @@ S16 duSctpCfgReq(SctpParams sctpCfg, CmStatus *cfm) ricParams.destIpAddr.ipV4Addr = sctpCfg.ricIpAddr.ipV4Addr; ricParams.destPort = sctpCfg.ricPort; ricParams.itfState = DU_SCTP_DOWN; - ricParams.srcPort = sctpCfg.duPort[1]; - ricParams.recvMsgSet = ROK; - cmMemset ((U8 *)&ricParams.sockFd, -1, sizeof(CmInetFd)); + ricParams.srcPort = sctpCfg.duPort[E2_INTERFACE]; + ricParams.recvMsgSet = ROK; + memset (&ricParams.sockFd, -1, sizeof(CmInetFd)); fillDestNetAddr(&ricParams.destIpNetAddr, &ricParams.destIpAddr); fillAddrLst(&ricParams.destAddrLst, &ricParams.destIpAddr); @@ -145,10 +181,12 @@ S16 duSctpCfgReq(SctpParams sctpCfg, CmStatus *cfm) pollingState = FALSE; /* Fill Cfm Status */ - cfm->status = LCM_PRIM_OK; - cfm->reason = LCM_REASON_NOT_APPL; + cfm.status = LCM_PRIM_OK; + cfm.reason = LCM_REASON_NOT_APPL; - RETVALUE(ROK); + ret = duCheckReqStatus(&cfm); + + return (ret); } /******************************************************************* @@ -170,13 +208,13 @@ S16 duSctpCfgReq(SctpParams sctpCfg, CmStatus *cfm) * ******************************************************************/ -S16 fillAddrLst(CmInetNetAddrLst *addrLstPtr, F1IpAddr *ipAddr) +uint8_t fillAddrLst(CmInetNetAddrLst *addrLstPtr, F1IpAddr *ipAddr) { addrLstPtr->count++; addrLstPtr->addrs[(addrLstPtr->count - 1)].type = CM_INET_IPV4ADDR_TYPE; - addrLstPtr->addrs[(addrLstPtr->count - 1)].u.ipv4NetAddr = CM_INET_NTOH_U32(ipAddr->ipV4Addr); + addrLstPtr->addrs[(addrLstPtr->count - 1)].u.ipv4NetAddr = CM_INET_NTOH_UINT32(ipAddr->ipV4Addr); - RETVALUE(ROK); + return ROK; } /****************************************************************************** @@ -197,12 +235,12 @@ S16 fillAddrLst(CmInetNetAddrLst *addrLstPtr, F1IpAddr *ipAddr) * RFAILED - failure * *******************************************************************************/ -S16 fillDestNetAddr(CmInetNetAddr *destAddrPtr, F1IpAddr *dstIpPtr) +uint8_t fillDestNetAddr(CmInetNetAddr *destAddrPtr, F1IpAddr *dstIpPtr) { /* Filling destination address */ destAddrPtr->type = CM_INET_IPV4ADDR_TYPE; - destAddrPtr->u.ipv4NetAddr = CM_INET_NTOH_U32(dstIpPtr->ipV4Addr); - RETVALUE(ROK); + destAddrPtr->u.ipv4NetAddr = CM_INET_NTOH_UINT32(dstIpPtr->ipV4Addr); + return ROK; } /****************************************************************************** @@ -223,10 +261,10 @@ S16 fillDestNetAddr(CmInetNetAddr *destAddrPtr, F1IpAddr *dstIpPtr) * *******************************************************************************/ -S16 establishReq(DuSctpDestCb *paramPtr) +uint8_t establishReq(DuSctpDestCb *paramPtr) { Pst pst; - S16 ret = ROK; + uint8_t ret = ROK; socket_type = CM_INET_STREAM; if((ret = cmInetSocket(socket_type, ¶mPtr->sockFd, IPPROTO_SCTP)) != ROK) @@ -260,17 +298,17 @@ S16 establishReq(DuSctpDestCb *paramPtr) } if((ret == ROK) & (paramPtr->itfState == DU_SCTP_DOWN)) { - paramPtr->itfState = DU_SCTP_UP; + paramPtr->itfState = DU_SCTP_CONNECTING; } - /* Post the EVTSTRTPOLL Msg */ + /* Post the EVTSTARTPOLL Msg */ if(!pollingState) { pollingState = TRUE; - duFillSctpPst(&pst, EVTSTRTPOLL); + duFillSctpPst(&pst, EVTSTARTPOLL); } - RETVALUE(ret); + return (ret); } /****************************************************************************** @@ -292,14 +330,17 @@ S16 establishReq(DuSctpDestCb *paramPtr) * *******************************************************************************/ -S16 duSctpAssocReq(U8 itfType, CmStatus *cfm) +uint8_t duSctpAssocReq(uint8_t itfType) { - S16 ret = ROK; + uint8_t ret = ROK; + CmStatus cfm; DuSctpDestCb *paramPtr = NULLP; - if(SGetSBuf(DU_APP_MEM_REGION, DU_POOL, (Data **)¶mPtr, (Size)sizeof(DuSctpDestCb)) != ROK) + + DU_ALLOC(paramPtr, sizeof(DuSctpDestCb)); + if(paramPtr == NULLP) { printf("\nDU_APP : Failed to allocate memory"); - RETVALUE(RFAILED); + return RFAILED; } switch(itfType) { @@ -324,16 +365,17 @@ S16 duSctpAssocReq(U8 itfType, CmStatus *cfm) if(ret != ROK) { DU_LOG("\nSCTP : ASSOC Req Failed."); - cfm->status = LCM_PRIM_NOK; - cfm->reason = LCM_REASON_NOT_APPL; + cfm.status = LCM_PRIM_NOK; + cfm.reason = LCM_REASON_NOT_APPL; } else { - cfm->status = LCM_PRIM_OK; - cfm->reason = LCM_REASON_NOT_APPL; + cfm.status = LCM_PRIM_OK; + cfm.reason = LCM_REASON_NOT_APPL; } + ret = duCheckReqStatus(&cfm); - RETVALUE(ret); + return (ret); } /******************************************************************* * @@ -351,15 +393,15 @@ S16 duSctpAssocReq(U8 itfType, CmStatus *cfm) * RFAILED - failure * * ****************************************************************/ -S16 duFillSctpPst(Pst *pst, Event event) +uint8_t duFillSctpPst(Pst *pst, Event event) { Buffer *mBuf; - if(SGetMsg(DFLT_REGION, DU_POOL, &mBuf) != ROK) + if(ODU_GET_MSG_BUF(DFLT_REGION, DU_POOL, &mBuf) != ROK) { printf("\nDU_APP : Failed to allocate memory"); - RETVALUE(RFAILED); + return RFAILED; } - cmMemset((U8 *)pst, 0, sizeof(Pst)); + memset(pst, 0, sizeof(Pst)); pst->srcEnt = (Ent)ENTDUAPP; pst->srcInst = (Inst)DU_INST; pst->srcProcId = DU_PROC; @@ -367,11 +409,11 @@ S16 duFillSctpPst(Pst *pst, Event event) pst->dstInst = (Inst)SCTP_INST; pst->dstProcId = pst->srcProcId; pst->event = event; - pst->selector = DU_SELECTOR_LC; + pst->selector = ODU_SELECTOR_LC; pst->pool= DU_POOL; - SPstTsk(pst, mBuf); + ODU_POST_TASK(pst, mBuf); - RETVALUE(ROK); + return ROK; } /******************************************************************* @@ -390,9 +432,9 @@ S16 duFillSctpPst(Pst *pst, Event event) * RFAILED - failure * * ****************************************************************/ -S16 sctpSetSockOpts(CmInetFd *sock_Fd) +uint8_t sctpSetSockOpts(CmInetFd *sock_Fd) { - S16 ret = ROK; + uint8_t ret = ROK; CmSctpEvent sctpEvent; sctpEvent.dataIoEvent = TRUE; @@ -409,7 +451,7 @@ S16 sctpSetSockOpts(CmInetFd *sock_Fd) ret = RFAILED; } - RETVALUE(ret); + return (ret); } /******************************************************************* @@ -434,10 +476,10 @@ void sendToDuApp(Buffer *mBuf, Event event) { Pst pst; DU_LOG("\nSCTP : Forwarding received message to duApp"); - SPrntMsg(mBuf, 0, 0); + ODU_PRINT_MSG(mBuf, 0, 0); - cmMemset((U8 *)&(pst), 0, sizeof(Pst)); + memset(&(pst), 0, sizeof(Pst)); pst.srcEnt = (Ent)ENTSCTP; pst.srcInst = (Inst)SCTP_INST; pst.srcProcId = DU_PROC; @@ -445,13 +487,13 @@ void sendToDuApp(Buffer *mBuf, Event event) pst.dstInst = (Inst)DU_INST; pst.dstProcId = pst.srcProcId; pst.event = event; - pst.selector = DU_SELECTOR_LC; + pst.selector = ODU_SELECTOR_LC; pst.pool= DU_POOL; pst.region = DFLT_REGION; - if (SPstTsk(&pst, mBuf) != ROK) + if (ODU_POST_TASK(&pst, mBuf) != ROK) { - DU_LOG("\nSCTP : SPstTsk failed in duReadCfg"); + DU_LOG("\nSCTP : ODU_POST_TASK failed in duReadCfg"); } } @@ -471,7 +513,7 @@ void sendToDuApp(Buffer *mBuf, Event event) * RFAILED - failure * * ****************************************************************/ -S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy) +uint8_t sctpNtfyHdlr(CmInetSctpNotification *ntfy, uint8_t *itfState) { Pst pst; @@ -483,23 +525,23 @@ S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy) { case CM_INET_SCTP_COMM_UP: DU_LOG("Event : COMMUNICATION UP"); - connUp = TRUE; + *itfState = DU_SCTP_UP; break; case CM_INET_SCTP_COMM_LOST: DU_LOG("Event : COMMUNICATION LOST"); - connUp = FALSE; + *itfState = DU_SCTP_DOWN; break; case CM_INET_SCTP_RESTART: DU_LOG("Event : SCTP RESTART"); - connUp = FALSE; + *itfState = DU_SCTP_DOWN; break; case CM_INET_SCTP_SHUTDOWN_COMP: /* association gracefully shutdown */ DU_LOG("Event : SHUTDOWN COMPLETE"); - connUp = FALSE; + *itfState = DU_SCTP_DOWN; break; case CM_INET_SCTP_CANT_STR_ASSOC: DU_LOG("Event : CANT START ASSOC"); - connUp = FALSE; + *itfState = DU_SCTP_DOWN; break; default: DU_LOG("\nInvalid event"); @@ -518,7 +560,7 @@ S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy) break; case CM_INET_SCTP_SHUTDOWN_EVENT : /* peer socket gracefully closed */ DU_LOG("\nSCTP : Shutdown Event notification received\n"); - connUp = FALSE; + *itfState = DU_SCTP_DOWN; exit(0); break; case CM_INET_SCTP_ADAPTATION_INDICATION : @@ -535,24 +577,24 @@ S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy) /* Pack notification and send to APP */ DU_LOG("\nSCTP : Forwarding received message to duApp"); - cmMemset((U8 *)&(pst), 0, sizeof(Pst)); + memset(&(pst), 0, sizeof(Pst)); pst.srcEnt = (Ent)ENTSCTP; pst.srcInst = (Inst)SCTP_INST; pst.srcProcId = DU_PROC; pst.dstEnt = (Ent)ENTDUAPP; pst.dstInst = (Inst)DU_INST; pst.dstProcId = pst.srcProcId; - pst.event = EVTSCTPNTFY; - pst.selector = DU_SELECTOR_LC; + pst.event = EVENT_SCTP_NTFY; + pst.selector = ODU_SELECTOR_LC; pst.pool= DU_POOL; - pst.region = DFLT_REGION; + pst.region = DU_APP_MEM_REGION; if(cmPkSctpNtfy(&pst, ntfy) != ROK) { DU_LOG("\nSCTP : Failed to pack SCTP notification"); - RETVALUE(RFAILED); + return RFAILED; } - RETVALUE(ROK); + return ROK; } /******************************************************************* @@ -578,17 +620,17 @@ S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy) * * ****************************************************************/ -S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, U32 *timeoutPtr, CmInetMemInfo *memInfo, Bool recvMsgSet) +uint8_t processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, uint32_t *timeoutPtr, CmInetMemInfo *memInfo, bool recvMsgSet) { - U16 ret = ROK; + uint8_t ret = ROK; CM_INET_FD_SET(sockFd, &pollParams->readFd); - ret = cmInetSelect(&pollParams->readFd, NULLP, timeoutPtr, &pollParams->numFds); + ret = cmInetSelect(&pollParams->readFd, NULLP, timeoutPtr, (int16_t *)&pollParams->numFd); if(CM_INET_FD_ISSET(sockFd, &pollParams->readFd)) { CM_INET_FD_CLR(sockFd, &pollParams->readFd); ret = cmInetSctpRecvMsg(sockFd, &pollParams->addr, &pollParams->port, memInfo, &(pollParams->mBuf), &pollParams->bufLen, &pollParams->info, &pollParams->flag, &pollParams->ntfy); - if(connUp && ret != ROK) + if(ret != ROK) { DU_LOG("\n SCTP: Failed to receive sctp msg for sockFd[%d]\n", sockFd->fd); recvMsgSet = RFAILED; @@ -601,38 +643,40 @@ S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, U32 *timeou { f1Params.assocId = pollParams->ntfy.u.assocChange.assocId; DU_LOG("\nSCTP : AssocId assigned to F1Params from PollParams [%d]\n", f1Params.assocId); + ret = sctpNtfyHdlr(&pollParams->ntfy, &f1Params.itfState); } else if(pollParams->port == ricParams.destPort) { ricParams.assocId = pollParams->ntfy.u.assocChange.assocId; DU_LOG("\nSCTP : AssocId assigned to ricParams from PollParams [%d]\n", ricParams.assocId); + ret = sctpNtfyHdlr(&pollParams->ntfy, &ricParams.itfState); } else { DU_LOG("\nSCTP : Failed to fill AssocId\n"); - } - ret = sctpNtfyHdlr(&pollParams->ntfy); + return RFAILED; + } if(ret != ROK) { DU_LOG("\nSCTP : Failed to process sctp notify msg\n"); } } - else if(connUp & (pollParams->port == f1Params.destPort)) + else if(f1Params.itfState & (pollParams->port == f1Params.destPort)) { - sendToDuApp(pollParams->mBuf, EVTSCTPDATA); + sendToDuApp(pollParams->mBuf, EVENT_CU_DATA); } - else if(connUp & (pollParams->port == ricParams.destPort)) + else if(ricParams.itfState & (pollParams->port == ricParams.destPort)) { - sendToDuApp(pollParams->mBuf, EVTRICDATA); + sendToDuApp(pollParams->mBuf, EVENT_RIC_DATA); } else { - SPutMsg(pollParams->mBuf); + ODU_PUT_MSG_BUF(pollParams->mBuf); } } } - RETVALUE(ROK); + return ROK; } /******************************************************************* * @@ -650,11 +694,11 @@ S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, U32 *timeou * RFAILED - failure * * ****************************************************************/ -S16 sctpSockPoll() +uint8_t sctpSockPoll() { - U16 ret = ROK; - U32 timeout; - U32 *timeout_Ptr; + uint8_t ret = ROK; + uint32_t timeout; + uint32_t *timeout_Ptr; CmInetMemInfo memInfo; sctpSockPollParams f1PollParams, e2PollParams; @@ -679,7 +723,7 @@ S16 sctpSockPoll() CM_INET_FD_ZERO(&e2PollParams.readFd); DU_LOG("\nSCTP : Polling started at DU\n"); - while(1) + while(true) { if(f1Params.itfState) { @@ -696,7 +740,7 @@ S16 sctpSockPoll() } } }; - RETVALUE(ret); + return (ret); }/* End of sctpSockPoll() */ /******************************************************************* @@ -715,9 +759,9 @@ S16 sctpSockPoll() * RFAILED - failure * * ****************************************************************/ -S16 sctpSend(Buffer *mBuf, U8 itfType) +uint8_t sctpSend(Buffer *mBuf, uint8_t itfType) { - U8 ret; + uint8_t ret; MsgLen len; /* number of actually sent octets */ CmInetMemInfo memInfo; @@ -739,10 +783,10 @@ S16 sctpSend(Buffer *mBuf, U8 itfType) if(ret != ROK && ret != RWOULDBLOCK) { DU_LOG("\nSCTP : Failed sending the message"); - RETVALUE(RFAILED); + return RFAILED; } - RETVALUE(ROK); + return ROK; } /* End of sctpSend */ /**********************************************************************