X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fric_stub%2Fric_stub_sctp.c;h=679c43ecab0095c54e6cc79e08cd85ba7883ff81;hb=5638504e06269c208f2006868788ebc9a8a626c9;hp=8cd497379bbf798acb50065b00119be99d079236;hpb=8660dd47a5ef27b62300fabf6b027852f1d5d026;p=o-du%2Fl2.git diff --git a/src/ric_stub/ric_stub_sctp.c b/src/ric_stub/ric_stub_sctp.c index 8cd497379..679c43eca 100644 --- a/src/ric_stub/ric_stub_sctp.c +++ b/src/ric_stub/ric_stub_sctp.c @@ -18,74 +18,23 @@ /* This file contains all SCTP related functionality */ -#include +#include "common_def.h" #include "ric_e2ap_msg_hdl.h" #include "ric_stub_sctp.h" +#include "ric_stub.h" +#include "E2AP-PDU.h" +#include "du_log.h" CuSctpDestCb ricParams; - -/************************************************************************** - * @brief Task Initiation callback function. - * - * @details - * - * Function : sctpActvInit - * - * Functionality: - * This function is supplied as one of parameters during SCTP's - * task registration. SSI will invoke this function once, after - * it creates and attaches this TAPA Task to a system task. - * - * @param[in] Ent entity, the entity ID of this task. - * @param[in] Inst inst, the instance ID of this task. - * @param[in] Region region, the region ID registered for memory - * usage of this task. - * @param[in] Reason reason. - * @return ROK - success - * RFAILED - failure - ***************************************************************************/ -S16 sctpActvInit() -{ - DU_LOG("\n\nSCTP : Initializing"); - connUp = FALSE; - assocId = 0; - nonblocking = FALSE; - sctpCfg = cuCfgParams.sctpParams; - return ROK; - -} - -/************************************************************************** - * @brief Task Activation callback function. - * - * @details - * - * Function : sctpActvTsk - * - * Functionality: - * This function handles all SCTP messages received - * This API is registered with SSI during the - * Task Registration of DU APP. - * - * @param[in] Pst *pst, Post structure of the primitive. - * @param[in] Buffer *mBuf, Packed primitive parameters in the - * buffer. - * @return ROK - success - * RFAILED - failure - * - ***************************************************************************/ -S16 sctpActvTsk(Pst *pst, Buffer *mBuf) -{ - -//TODO: TBD - return ROK; -} +RicSctpParams sctpCfg; +S16 fillAddrLst(CmInetNetAddrLst *addrLstPtr, SctpIpAddr *ipAddr); +S16 fillDestNetAddr(CmInetNetAddr *destAddrPtr, SctpIpAddr *dstIpPtr); /************************************************************************** * @brief Function to configure the Sctp Params during config Request * * @details * - * Function : duSctpCfgReq + * Function : sctpCfgReq * * Functionality: * This function configures SCTP Params during the config Request @@ -97,16 +46,18 @@ S16 sctpActvTsk(Pst *pst, Buffer *mBuf) S16 sctpCfgReq() { + connUp = FALSE; + sctpCfg = ricCfgParams.sctpParams; /* Fill F1 Params */ ricParams.destPort = sctpCfg.duPort; ricParams.srcPort = sctpCfg.ricPort; ricParams.bReadFdSet = ROK; - cmMemset ((U8 *)&ricParams.sockFd, -1, sizeof(CmInetFd)); - cmMemset ((U8 *)&ricParams.lstnSockFd, -1, sizeof(CmInetFd)); + memset(&ricParams.sockFd, -1, sizeof(CmInetFd)); + memset(&ricParams.lstnSockFd, -1, sizeof(CmInetFd)); fillDestNetAddr(&ricParams.destIpNetAddr, &sctpCfg.duIpAddr); - RETVALUE(ROK); + return ROK; } /******************************************************************* @@ -131,9 +82,9 @@ S16 fillAddrLst(CmInetNetAddrLst *addrLstPtr, SctpIpAddr *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; } /****************************************************************************** @@ -157,8 +108,8 @@ S16 fillDestNetAddr(CmInetNetAddr *destAddrPtr, SctpIpAddr *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; } /****************************************************************************** @@ -186,21 +137,21 @@ S16 sctpStartReq() if((ret = cmInetSocket(socket_type, &ricParams.lstnSockFd, IPPROTO_SCTP) != ROK)) { - DU_LOG("\nSCTP : Socket[%d] coudnt open for listening", ricParams.lstnSockFd.fd); + DU_LOG("\nERROR --> SCTP : Socket[%d] coudnt open for listening", ricParams.lstnSockFd.fd); } else if((ret = cmInetSctpBindx(&ricParams.lstnSockFd, &ricParams.localAddrLst, ricParams.srcPort)) != ROK) { - DU_LOG("\nSCTP: Binding failed at CU"); + DU_LOG("\nERROR --> SCTP: Binding failed at RIC"); } else if((ret = sctpAccept(&ricParams.lstnSockFd, &ricParams.peerAddr, &ricParams.sockFd)) != ROK) { - DU_LOG("\nSCTP: Unable to accept the connection at CU"); + DU_LOG("\nERROR --> SCTP: Unable to accept the connection at RIC"); } else if(sctpSockPoll() != ROK) { - DU_LOG("\nSCTP: Polling failed to start at RIC"); + DU_LOG("\nERROR --> SCTP: Polling failed to start at RIC"); } - RETVALUE(ret); + return (ret); } /******************************************************************* * @@ -237,7 +188,7 @@ S16 sctpSetSockOpts(CmInetFd *sock_Fd) ret = RFAILED; } - RETVALUE(ret); + return (ret); } /******************************************************************* @@ -259,17 +210,17 @@ S16 sctpSetSockOpts(CmInetFd *sock_Fd) * ****************************************************************/ S16 sctpAccept(CmInetFd *lstnSock_Fd, CmInetAddr *peerAddr, CmInetFd *sock_Fd) { - U8 ret; - - ret = cmInetListen(lstnSock_Fd, 1);; + uint8_t ret; + + ret = cmInetListen(lstnSock_Fd, 1); if (ret != ROK) { - DU_LOG("\nSCTP : Listening on socket failed"); + DU_LOG("\nERROR --> SCTP : Listening on socket failed"); cmInetClose(lstnSock_Fd); - RETVALUE(RFAILED); + return RFAILED; } - DU_LOG("\nSCTP : Connecting"); + DU_LOG("\nINFO --> SCTP : Connecting"); while(!connUp) { @@ -280,8 +231,8 @@ S16 sctpAccept(CmInetFd *lstnSock_Fd, CmInetAddr *peerAddr, CmInetFd *sock_Fd) } else if(ret != ROK) { - DU_LOG("\nSCTP : Failed to accept connection"); - RETVALUE(RFAILED); + DU_LOG("\nERROR --> SCTP : Failed to accept connection"); + return RFAILED; } else { @@ -290,9 +241,9 @@ S16 sctpAccept(CmInetFd *lstnSock_Fd, CmInetAddr *peerAddr, CmInetFd *sock_Fd) break; } } - DU_LOG("\nSCTP : Connection established"); + DU_LOG("\nINFO --> SCTP : Connection established"); - RETVALUE(ROK); + return ROK; } /******************************************************************* @@ -317,62 +268,62 @@ S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy) switch(ntfy->header.nType) { case CM_INET_SCTP_ASSOC_CHANGE : - DU_LOG("\nSCTP : Assoc change notification received"); + DU_LOG("\nINFO --> SCTP : Assoc change notification received"); switch(ntfy->u.assocChange.state) { case CM_INET_SCTP_COMM_UP: - DU_LOG("Event : COMMUNICATION UP"); + DU_LOG("\nINFO --> Event : COMMUNICATION UP"); connUp = TRUE; break; case CM_INET_SCTP_COMM_LOST: - DU_LOG("Event : COMMUNICATION LOST"); + DU_LOG("\nINFO --> Event : COMMUNICATION LOST"); connUp = FALSE; break; case CM_INET_SCTP_RESTART: - DU_LOG("Event : SCTP RESTART"); + DU_LOG("\nINFO --> Event : SCTP RESTART"); connUp = FALSE; break; case CM_INET_SCTP_SHUTDOWN_COMP: /* association gracefully shutdown */ - DU_LOG("Event : SHUTDOWN COMPLETE"); + DU_LOG("\nINFO --> Event : SHUTDOWN COMPLETE"); connUp = FALSE; break; case CM_INET_SCTP_CANT_STR_ASSOC: - DU_LOG("Event : CANT START ASSOC"); + DU_LOG("\nINFO --> Event : CANT START ASSOC"); connUp = FALSE; break; default: - DU_LOG("\nInvalid event"); + DU_LOG("\nERROR --> Invalid event"); break; } break; case CM_INET_SCTP_PEER_ADDR_CHANGE : - DU_LOG("\nSCTP : Peer Address Change notificarion received"); + DU_LOG("\nINFO --> SCTP : Peer Address Change notificarion received"); /* Need to add handler */ break; case CM_INET_SCTP_REMOTE_ERROR : - DU_LOG("\nSCTP : Remote Error notification received"); + DU_LOG("\nINFO --> SCTP : Remote Error notification received"); break; case CM_INET_SCTP_SEND_FAILED : - DU_LOG("\nSCTP : Send Failed notification received\n"); + DU_LOG("\nINFO --> SCTP : Send Failed notification received\n"); break; case CM_INET_SCTP_SHUTDOWN_EVENT : /* peer socket gracefully closed */ - DU_LOG("\nSCTP : Shutdown Event notification received\n"); + DU_LOG("\nINFO --> SCTP : Shutdown Event notification received\n"); connUp = FALSE; exit(0); break; case CM_INET_SCTP_ADAPTATION_INDICATION : - DU_LOG("\nSCTP : Adaptation Indication received\n"); + DU_LOG("\nINFO --> SCTP : Adaptation Indication received\n"); break; case CM_INET_SCTP_PARTIAL_DELIVERY_EVENT: - DU_LOG("\nSCTP : Partial Delivery Event received\n"); + DU_LOG("\nINFO --> SCTP : Partial Delivery Event received\n"); break; default: - DU_LOG("\nSCTP : Invalid notification type\n"); + DU_LOG("\nERROR --> SCTP : Invalid notification type\n"); break; } sctpNtfyInd(ntfy); - RETVALUE(ROK); + return ROK; }/* End of sctpNtfyHdlr */ /******************************************************************* @@ -393,10 +344,10 @@ S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy) * ****************************************************************/ S16 sctpSockPoll() { - U16 ret = ROK; - U32 timeout; - U32 *timeoutPtr; - CmInetMemInfo memInfo; + uint16_t ret = ROK; + uint32_t timeout; + uint32_t *timeoutPtr; + CmInetMemInfo memInfo; sctpSockPollParams e2PollParams; memset(&e2PollParams, 0, sizeof(sctpSockPollParams)); @@ -418,15 +369,15 @@ S16 sctpSockPoll() CM_INET_FD_ZERO(&e2PollParams.readFd); - DU_LOG("\nSCTP : Polling started at RIC\n"); + DU_LOG("\nINFO --> SCTP : Polling started at RIC\n"); while(1) { if((ret = processPolling(&e2PollParams, &ricParams.sockFd, timeoutPtr, &memInfo)) != ROK) { - DU_LOG("\nSCTP : Failed to RecvMsg for E2 at CU \n"); + DU_LOG("\nERROR --> SCTP : Failed to RecvMsg for E2 at RIC \n"); } }; - RETVALUE(ret); + return (ret); }/* End of sctpSockPoll() */ /******************************************************************* @@ -453,11 +404,11 @@ S16 sctpSockPoll() * ****************************************************************/ -S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, U32 *timeoutPtr, CmInetMemInfo *memInfo) +S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, uint32_t *timeoutPtr, CmInetMemInfo *memInfo) { - U16 ret = ROK; + uint16_t ret = ROK; CM_INET_FD_SET(sockFd, &pollParams->readFd); - ret = cmInetSelect(&pollParams->readFd, NULLP, timeoutPtr, &pollParams->numFds); + ret = cmInetSelect(&pollParams->readFd, NULLP, timeoutPtr, &pollParams->numFd); if(CM_INET_FD_ISSET(sockFd, &pollParams->readFd)) { CM_INET_FD_CLR(sockFd, &pollParams->readFd); @@ -473,21 +424,21 @@ S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, U32 *timeou ret = sctpNtfyHdlr(&pollParams->ntfy); if(ret != ROK) { - DU_LOG("\nSCTP : Failed to process sctp notify msg\n"); + DU_LOG("\nERROR --> SCTP : Failed to process sctp notify msg\n"); } } else if(connUp & (pollParams->port == ricParams.destPort)) { E2APMsgHdlr(pollParams->mBuf); - SPutMsg(pollParams->mBuf); + ODU_PUT_MSG_BUF(pollParams->mBuf); } else { - SPutMsg(pollParams->mBuf); + ODU_PUT_MSG_BUF(pollParams->mBuf); } } } - RETVALUE(ROK); + return ROK; }/* End of sctpSockPoll() */ /******************************************************************* @@ -508,7 +459,7 @@ S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, U32 *timeou * ****************************************************************/ S16 sctpSend(Buffer *mBuf) { - U8 ret; + uint8_t ret; MsgLen len; /* number of actually sent octets */ CmInetMemInfo memInfo; @@ -519,11 +470,11 @@ S16 sctpSend(Buffer *mBuf) if(ret != ROK && ret != RWOULDBLOCK) { - DU_LOG("\nSCTP : Send message failed"); - RETVALUE(RFAILED); + DU_LOG("\nERROR --> SCTP : Send message failed"); + return RFAILED; } - RETVALUE(ROK); + return ROK; } /* End of sctpSend */ /********************************************************************** End of file