/* This file contains all SCTP related functionality */
-#include <stdio.h>
+#include "common_def.h"
#include "cu_f1ap_msg_hdl.h"
#include "cu_stub_sctp.h"
#include "cu_stub_egtp.h"
+#include "du_log.h"
+CuSctpDestCb f1Params;
/**************************************************************************
* @brief Task Initiation callback function.
*
connUp = FALSE;
assocId = 0;
nonblocking = FALSE;
- sctpCfg = &(cuCfgParams.sctpParams);
+ sctpCfg = cuCfgParams.sctpParams;
return ROK;
}
return ROK;
}
+/**************************************************************************
+ * @brief Function to configure the Sctp Params during config Request
+ *
+ * @details
+ *
+ * Function : duSctpCfgReq
+ *
+ * Functionality:
+ * This function configures SCTP Params during the config Request
+ *
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ***************************************************************************/
+
+S16 sctpCfgReq()
+{
+
+/* Fill F1 Params */
+ f1Params.destPort = sctpCfg.duPort;
+ f1Params.srcPort = sctpCfg.cuPort;
+ f1Params.bReadFdSet = ROK;
+ memset(&f1Params.sockFd, -1, sizeof(CmInetFd));
+ memset(&f1Params.lstnSockFd, -1, sizeof(CmInetFd));
+ fillDestNetAddr(&f1Params.destIpNetAddr, &sctpCfg.duIpAddr);
+
+ return ROK;
+}
+
+
/*******************************************************************
*
- * @brief Opens a non-blocking socket and binds to local address
+ * @brief Fills the address List of the source Ip Address
*
* @details
*
- * Function : openSctpEndp
+ * Function : fillAddrLst
*
* Functionality:
- * Opens a non-blocking socket and binds to local address
+ * Fills the address List of source Ip Address
*
- * @params[in]
+ * @params[in] CmInetNetAddrLst *addrLstPtr, Address List pointer
+ * @params[in] F1IpAddr *srcIpAddr, src Ip Adrress to be filled in the Address List
* @return ROK - success
* RFAILED - failure
*
- * ****************************************************************/
-S16 openSctpEndp()
-{
- U8 ret;
- U8 numRetry = 0;
+ ******************************************************************/
- /* Opening a non-blocking SCTP socket */
- socket_type = CM_INET_STREAM;
-
- do{
- ret = cmInetSocket(socket_type, &lstnSockFd, IPPROTO_SCTP);
- if (ret != ROK)
- {
- numRetry++;
- if(numRetry >= MAX_RETRY)
- {
- DU_LOG("\nSCTP : All attempts to open socket failed.");
- /* Send indication to du_app */
- RETVALUE(RFAILED);
- }
- else
- {
- DU_LOG("\nSCTP : Retrying socket opening");
- }
- }
- else
- {
- DU_LOG("\nSCTP : Socket[%d] open",lstnSockFd.fd);
- break;
- }
- }while(numRetry < MAX_RETRY);
-
- RETVALUE(ROK);
-} /* End of openSctpEndp */
+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_UINT32(ipAddr->ipV4Addr);
+ return ROK;
+}
-/*******************************************************************
+/******************************************************************************
*
- * @brief Bind socket to local Ip address and port
+ * @brief Fills the address List of the source Ip Address
*
* @details
*
- * Function : bindSctpEndp
+ * Function : fillDestNetAddr
*
* Functionality:
- * -Bind socket to local Ip address and port
+ * Fills the address List of destinatoion Ip Address
*
- * @params[in]
+ * @params[in] CmInetNetAddr *destAddrPtr, Address List pointer
+ * @params[in] F1IpAddr *dstIpAddr, destIp Address to be filled in the Address List
* @return ROK - success
* RFAILED - failure
*
- * ****************************************************************/
-S16 bindSctpEndp()
+ *******************************************************************************/
+S16 fillDestNetAddr(CmInetNetAddr *destAddrPtr, SctpIpAddr *dstIpPtr)
{
+ /* Filling destination address */
+ destAddrPtr->type = CM_INET_IPV4ADDR_TYPE;
+ destAddrPtr->u.ipv4NetAddr = CM_INET_NTOH_UINT32(dstIpPtr->ipV4Addr);
+ return ROK;
+}
- U8 ret;
- U8 numRetry = 0;
+/******************************************************************************
+ *
+ * @brief Eastablishes the Assoc Req for the received interface type
+ *
+ * @details
+ *
+ * Function : sctpStartReq
+ *
+ * Functionality:
+ * Eastablishes the Assoc Req for the received interface type
+ *
+ * @params[in] DuSctpDestCb *paramPtr
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ *******************************************************************************/
- /* Binding the socket with local address */
- localAddrLst.count = 1;
- if(sctpCfg->cuIpAddr.ipV4Pres)
+S16 sctpStartReq()
+{
+ S16 ret = ROK;
+ socket_type = CM_INET_STREAM;
+ fillAddrLst(&f1Params.localAddrLst, &sctpCfg.cuIpAddr);
+
+ if((ret = cmInetSocket(socket_type, &f1Params.lstnSockFd, IPPROTO_SCTP) != ROK))
+ {
+ DU_LOG("\nSCTP : Socket[%d] coudnt open for listening", f1Params.lstnSockFd.fd);
+ }
+ else if((ret = cmInetSctpBindx(&f1Params.lstnSockFd, &f1Params.localAddrLst, f1Params.srcPort)) != ROK)
{
- localAddrLst.addrs[0].type = CM_INET_IPV4ADDR_TYPE;
- localAddrLst.addrs[0].u.ipv4NetAddr = CM_INET_NTOH_U32(sctpCfg->cuIpAddr.ipV4Addr);
+ DU_LOG("\nSCTP: Binding failed at CU");
}
- else if(sctpCfg->cuIpAddr.ipV6Pres)
+ else if((ret = sctpAccept(&f1Params.lstnSockFd, &f1Params.peerAddr, &f1Params.sockFd)) != ROK)
{
- localAddrLst.addrs[0].type = CM_INET_IPV6ADDR_TYPE;
- // CM_INET_COPY_IPV6ADDR(&(localAddrLst.addrs[0].u.ipv6NetAddr),&(sctpCfg->cuIpAddr.ipV6Addr);
+ DU_LOG("\nSCTP: Unable to accept the connection at CU");
}
- else
+ else if(sctpSockPoll() != ROK)
{
- localAddrLst.addrs[0].type = CM_INET_IPV4ADDR_TYPE;
- localAddrLst.addrs[0].u.ipv4NetAddr = 0;
- }
-
- do{
- ret = cmInetSctpBindx(&lstnSockFd, &localAddrLst, sctpCfg->cuPort);
- if (ret != ROK)
- {
- numRetry++;
- if(numRetry >= MAX_RETRY)
- {
- DU_LOG("\nSCTP : All attempts to bind socket failed.");
- cmInetClose(&lstnSockFd);
- /* Send indication to du_app */
- RETVALUE(RFAILED);
- }
- else
- {
- DU_LOG("\nSCTP : Retrying socket binding");
- }
- }
- else
- {
- DU_LOG("\nSCTP : Socket bind successful");
- break;
- }
- }while(numRetry < MAX_RETRY);
-
- RETVALUE(ROK);
-
-} /* End of bindSctpEndp() */
-
+ DU_LOG("\nSCTP: Polling failed to start at CU");
+ }
+ return (ret);
+}
/*******************************************************************
*
* @brief Sets socket options as per requirement
* RFAILED - failure
*
* ****************************************************************/
-S16 sctpSetSockOpts()
+S16 sctpSetSockOpts(CmInetFd *sock_Fd)
{
+ S16 ret = ROK;
CmSctpEvent sctpEvent;
sctpEvent.dataIoEvent = TRUE;
sctpEvent.partialDeliveryEvent = TRUE;
sctpEvent.adaptationLayerEvent = TRUE;
- cmInetSetOpt(&sockFd, CM_SOCKOPT_LEVEL_SCTP, CM_SOCKOPT_OPT_SCTP_EVENTS, &sctpEvent);
- RETVALUE(ROK);
+ if((ret = cmInetSetOpt(sock_Fd, CM_SOCKOPT_LEVEL_SCTP, CM_SOCKOPT_OPT_SCTP_EVENTS, &sctpEvent)) != ROK)
+ {
+ ret = RFAILED;
+ }
+
+ return (ret);
}
/*******************************************************************
* RFAILED - failure
*
* ****************************************************************/
-S16 sctpAccept()
+S16 sctpAccept(CmInetFd *lstnSock_Fd, CmInetAddr *peerAddr, CmInetFd *sock_Fd)
{
- U8 ret;
- CmInetAddr peerAddr;
-
- ret = cmInetListen(&lstnSockFd, 1);;
+ uint8_t ret;
+
+ ret = cmInetListen(lstnSock_Fd, 1);
if (ret != ROK)
{
DU_LOG("\nSCTP : Listening on socket failed");
- cmInetClose(&lstnSockFd);
- RETVALUE(RFAILED);
+ cmInetClose(lstnSock_Fd);
+ return RFAILED;
}
DU_LOG("\nSCTP : Connecting");
while(!connUp)
{
- ret = cmInetAccept(&lstnSockFd, &peerAddr, &sockFd);
+ ret = cmInetAccept(lstnSock_Fd, peerAddr, sock_Fd);
if (ret == ROKDNA)
{
continue;
else if(ret != ROK)
{
DU_LOG("\nSCTP : Failed to accept connection");
- RETVALUE(RFAILED);
+ return RFAILED;
}
else
{
connUp = TRUE;
- sctpSetSockOpts();
+ sctpSetSockOpts(sock_Fd);
break;
}
}
DU_LOG("\nSCTP : Connection established");
- RETVALUE(ROK);
-}/* End of sctpAccept() */
+ return ROK;
+}
/*******************************************************************
*
case CM_INET_SCTP_SHUTDOWN_EVENT : /* peer socket gracefully closed */
DU_LOG("\nSCTP : Shutdown Event notification received\n");
connUp = FALSE;
+ exit(0);
break;
case CM_INET_SCTP_ADAPTATION_INDICATION :
DU_LOG("\nSCTP : Adaptation Indication received\n");
}
sctpNtfyInd(ntfy);
- RETVALUE(ROK);
+ return ROK;
}/* End of sctpNtfyHdlr */
/*******************************************************************
* ****************************************************************/
S16 sctpSockPoll()
{
- U8 ret;
- S16 numFds;
- CmInetFdSet readFd;
- U16 port;
- U32 timeout; /* timeout for cmInetSelect() */
- U32 *timeoutPtr; /* pointer to timeout */
- U32 flag;
- Buffer *mBuf;
+ uint16_t ret = ROK;
+ uint32_t timeout;
+ uint32_t *timeoutPtr;
Buffer *egtpBuf;
- MsgLen bufLen;
MsgLen egtpBufLen;
- CmInetAddr egtpFromAddr; /* Egtp data sender address */
- CmInetMemInfo memInfo; /* buffer allocation info */
- CmInetNetAddr addr;
- CmInetSctpSndRcvInfo info;
- CmInetSctpNotification ntfy;
+ CmInetAddr egtpFromAddr;
+ CmInetMemInfo memInfo;
+ sctpSockPollParams f1PollParams;
- if (sockFd.blocking)
+ memset(&f1PollParams, 0, sizeof(sctpSockPollParams));
+
+ egtpFromAddr.port = egtpCb.dstCb.dstPort;
+ egtpFromAddr.address = egtpCb.dstCb.dstIp;
+
+ if(f1Params.sockFd.blocking)
{
/* blocking */
timeoutPtr = NULLP;
memInfo.region = CU_APP_MEM_REG;
memInfo.pool = CU_POOL;
- egtpFromAddr.port = egtpCb.dstCb.dstPort;
- egtpFromAddr.address = egtpCb.dstCb.dstIp;
-
- CM_INET_FD_ZERO(&readFd);
+ CM_INET_FD_ZERO(&f1PollParams.readFd);
while(1)
{
- /* Receiving SCTP data */
- CM_INET_FD_SET(&sockFd, &readFd);
- ret = cmInetSelect(&readFd, NULLP, timeoutPtr, &numFds);
- if (CM_INET_FD_ISSET(&sockFd, &readFd))
+ if((ret = processPolling(&f1PollParams, &f1Params.sockFd, timeoutPtr, &memInfo)) != ROK)
{
- CM_INET_FD_CLR(&sockFd, &readFd);
- ret = cmInetSctpRecvMsg(&sockFd, &addr, &port, &memInfo, &mBuf, &bufLen, &info, &flag, &ntfy);
- if (ret != ROK)
- {
- DU_LOG("\nSCTP : Failed to receive sctp msg\n");
- }
- else
- {
- if ((flag & CM_INET_SCTP_MSG_NOTIFICATION) != 0)
- {
- ret = sctpNtfyHdlr(&ntfy);
- if(ret != ROK)
- {
- DU_LOG("\nSCTP : Failed to process sctp notify msg\n");
- }
- }
- else if(connUp) /* If data received */
- {
- F1APMsgHdlr(mBuf);
- SPutMsg(mBuf);
- }
- else
- {
- SPutMsg(mBuf);
- }
- }
+ DU_LOG("\nSCTP : Failed to RecvMsg for F1 at CU\n");
}
/* Receiving EGTP data */
if(ret == ROK && egtpBuf != NULLP)
{
DU_LOG("\nEGTP : Received message \n");
- SPrntMsg(egtpBuf, 0 ,0);
+ ODU_PRINT_MSG(egtpBuf, 0 ,0);
cuEgtpHdlRecvMsg(egtpBuf);
}
};
+ return (ret);
+}/* End of sctpSockPoll() */
- RETVALUE(ROK);
+/*******************************************************************
+ *
+ * @brief checks for valid readFd and process the InetSctpRecvMsg
+ * during polling
+ *
+ * @details
+ *
+ * Function : processPolling
+ *
+ * Functionality:
+ * checks for valid readFd and process the InetSctpRecvMsg
+ * during polling
+ *
+ * @params[in] Params required for polling
+ * @params[in] SockFd for file descriptor
+ * @params[in] timeoutPtr indicates the timeout value
+ * @params[in] MemInfo indicates memory region
+ *
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+
+S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, uint32_t *timeoutPtr, CmInetMemInfo *memInfo)
+{
+ uint16_t ret = ROK;
+ CM_INET_FD_SET(sockFd, &pollParams->readFd);
+ ret = cmInetSelect(&pollParams->readFd, NULLP, timeoutPtr, &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))
+ {
+ f1Params.bReadFdSet = RFAILED;
+ }
+ else
+ {
+ if(((pollParams->flag & CM_INET_SCTP_MSG_NOTIFICATION) != 0) && (ret == ROK))
+ {
+ ret = sctpNtfyHdlr(&pollParams->ntfy);
+ if(ret != ROK)
+ {
+ DU_LOG("\nSCTP : Failed to process sctp notify msg\n");
+ }
+ }
+ else if(connUp & (pollParams->port == f1Params.destPort))
+ {
+ F1APMsgHdlr(pollParams->mBuf);
+ ODU_PUT_MSG_BUF(pollParams->mBuf);
+ }
+ else
+ {
+ ODU_PUT_MSG_BUF(pollParams->mBuf);
+ }
+ }
+ }
+ return ROK;
}/* End of sctpSockPoll() */
/*******************************************************************
* ****************************************************************/
S16 sctpSend(Buffer *mBuf)
{
- U8 ret;
+ uint8_t ret;
MsgLen len; /* number of actually sent octets */
- CmInetNetAddr peerAddr; /* destination port address */
- CmInetNetAddr *dstAddr;
CmInetMemInfo memInfo;
memInfo.region = CU_APP_MEM_REG;
memInfo.pool = CU_POOL;
+ ret = cmInetSctpSendMsg(&f1Params.sockFd, &f1Params.destIpNetAddr, f1Params.destPort, &memInfo, mBuf, &len, 0, FALSE, 0, 0/*SCT_PROTID_NONE*/, RWOULDBLOCK);
- if(sctpCfg->duIpAddr.ipV4Pres)
- {
- peerAddr.type = CM_INET_IPV4ADDR_TYPE;
- peerAddr.u.ipv4NetAddr = CM_INET_NTOH_U32(sctpCfg->duIpAddr.ipV4Addr);
- dstAddr = &peerAddr;
- }
- else if(sctpCfg->duIpAddr.ipV6Pres)
- {
- peerAddr.type = CM_INET_IPV6ADDR_TYPE;
- //CM_INET_COPY_IPV6ADDR(&(primDstAddr.u.ipv6NetAddr),&(sctpCfg->duIpAddr.ipV6Addr);
- dstAddr = &peerAddr;
- }
- else
- {
- dstAddr = NULLP;
- }
-
- ret = cmInetSctpSendMsg(&sockFd, dstAddr, sctpCfg->duPort, &memInfo, mBuf, &len, 0, FALSE, 0, 0/*SCT_PROTID_NONE*/, RWOULDBLOCK);
if(ret != ROK && ret != RWOULDBLOCK)
{
DU_LOG("\nSCTP : Send message failed");
- RETVALUE(RFAILED);
+ return RFAILED;
}
- RETVALUE(ROK);
+ return ROK;
} /* End of sctpSend */
-/*******************************************************************
- *
- * @brief Start SCTP at CU
- *
- * @details
- *
- * Function : sctpStartReq
- *
- * Functionality:
- * Start SCTP at CU
- *
- * @params[in]
- * @return ROK - success
- * RFAILED - failure
- *
- * ****************************************************************/
-void sctpStartReq()
-{
- if(openSctpEndp() != ROK)
- {
- DU_LOG("\nSCTP : Failed while opening socket");
- }
- else if(bindSctpEndp() != ROK)
- {
- DU_LOG("\nSCTP : Failed while binding socket");
- }
- else if(sctpAccept() != ROK)
- {
- DU_LOG("\nSCTP : Failed while accepting connection");
- }
- else if(sctpSockPoll() != ROK)
- {
- DU_LOG("\nSCTP : Failed while polling");
- }
-} /* End of sctpAssocReq */
-
/**********************************************************************
End of file
**********************************************************************/