/* This file contains all SCTP related functionality */
#include "common_def.h"
+#include "OCTET_STRING.h"
#include "cu_f1ap_msg_hdl.h"
#include "cu_stub_sctp.h"
#include "cu_stub_egtp.h"
-#include "du_log.h"
+#include "cu_stub.h"
+#include "cm_inet.h"
+#include "cm_tpt.h"
-CuSctpDestCb f1Params;
+#include "cm_inet.x"
+#include "cm_tpt.x"
+
+ SctpGlobalCb sctpCb;
+uint8_t socket_type;
/**************************************************************************
* @brief Task Initiation callback function.
*
* @return ROK - success
* RFAILED - failure
***************************************************************************/
-S16 sctpActvInit()
+uint8_t sctpActvInit()
{
DU_LOG("\n\nDEBUG --> SCTP : Initializing");
- connUp = FALSE;
- assocId = 0;
- nonblocking = FALSE;
- sctpCfg = cuCfgParams.sctpParams;
+ memset(&sctpCb, 0, sizeof(SctpGlobalCb));
+ sctpCb.sctpCfg = cuCb.cuCfgParams.sctpParams;
return ROK;
-
}
/**************************************************************************
* RFAILED - failure
*
***************************************************************************/
-S16 sctpActvTsk(Pst *pst, Buffer *mBuf)
+uint8_t sctpActvTsk(Pst *pst, Buffer *mBuf)
{
//TODO: TBD
*
***************************************************************************/
-S16 sctpCfgReq()
+uint8_t sctpCfgReq()
{
+ int destIdx = 0, assocIdx = 0;
+
+ fillAddrLst(&sctpCb.localAddrLst, &sctpCb.sctpCfg.localIpAddr);
+ memset(&sctpCb.f1LstnSockFd, -1, sizeof(CmInetFd));
-/* 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);
+ for(destIdx=0; destIdx < sctpCb.sctpCfg.f1SctpInfo.numDestNode; destIdx++)
+ {
+ sctpCb.assocCb[assocIdx].intf = F1_INTERFACE;
+ sctpCb.assocCb[assocIdx].destPort = sctpCb.sctpCfg.f1SctpInfo.destCb[destIdx].destPort;
+ sctpCb.assocCb[assocIdx].bReadFdSet = ROK;
+ memset(&sctpCb.assocCb[assocIdx].sockFd, -1, sizeof(CmInetFd));
+ fillDestNetAddr(&sctpCb.assocCb[assocIdx].destIpNetAddr, &sctpCb.sctpCfg.f1SctpInfo.destCb[destIdx].destIpAddr);
+ assocIdx++;
+ }
+ sctpCb.localXnNodeType = sctpCb.sctpCfg.xnSctpInfo.localNodeType;
+ for(destIdx=0; destIdx < sctpCb.sctpCfg.xnSctpInfo.numDestNode; destIdx++)
+ {
+ sctpCb.assocCb[assocIdx].intf = XN_INTERFACE;
+ sctpCb.assocCb[assocIdx].destPort = sctpCb.sctpCfg.xnSctpInfo.destCb[destIdx].destPort;
+ sctpCb.assocCb[assocIdx].bReadFdSet = ROK;
+ memset(&sctpCb.assocCb[assocIdx].sockFd, -1, sizeof(CmInetFd));
+ fillDestNetAddr(&sctpCb.assocCb[assocIdx].destIpNetAddr, &sctpCb.sctpCfg.xnSctpInfo.destCb[destIdx].destIpAddr);
+ assocIdx++;
+ }
+ sctpCb.numAssoc = assocIdx;
return ROK;
}
*
******************************************************************/
-S16 fillAddrLst(CmInetNetAddrLst *addrLstPtr, SctpIpAddr *ipAddr)
+uint8_t fillAddrLst(CmInetNetAddrLst *addrLstPtr, SctpIpAddr *ipAddr)
{
+ addrLstPtr->addrs[addrLstPtr->count].type = CM_INET_IPV4ADDR_TYPE;
+ addrLstPtr->addrs[addrLstPtr->count].u.ipv4NetAddr = CM_INET_NTOH_UINT32(ipAddr->ipV4Addr);
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;
}
* RFAILED - failure
*
*******************************************************************************/
-S16 fillDestNetAddr(CmInetNetAddr *destAddrPtr, SctpIpAddr *dstIpPtr)
+uint8_t fillDestNetAddr(CmInetNetAddr *destAddrPtr, SctpIpAddr *dstIpPtr)
{
/* Filling destination address */
destAddrPtr->type = CM_INET_IPV4ADDR_TYPE;
*
*******************************************************************************/
-S16 sctpStartReq()
+uint8_t sctpStartReq()
{
- S16 ret = ROK;
+ uint8_t assocIdx;
+ uint8_t ret = ROK;
+ CmInetFd sockFd;
+
socket_type = CM_INET_STREAM;
- fillAddrLst(&f1Params.localAddrLst, &sctpCfg.cuIpAddr);
- if((ret = cmInetSocket(socket_type, &f1Params.lstnSockFd, IPPROTO_SCTP) != ROK))
- {
- DU_LOG("\nERROR --> SCTP : Socket[%d] coudnt open for listening", f1Params.lstnSockFd.fd);
- }
- else if((ret = cmInetSctpBindx(&f1Params.lstnSockFd, &f1Params.localAddrLst, f1Params.srcPort)) != ROK)
+ /* Establish SCTP association at XN interface */
+ if(sctpCb.sctpCfg.xnSctpInfo.numDestNode)
{
- DU_LOG("\nERROR --> SCTP: Binding failed at CU");
+ if(sctpCb.localXnNodeType == SERVER)
+ {
+ if((ret = cmInetSocket(socket_type, &sctpCb.xnLstnSockFd, IPPROTO_SCTP) != ROK))
+ {
+ DU_LOG("\nERROR --> SCTP : Socket[%d] coudnt open for listening", sctpCb.f1LstnSockFd.fd);
+ }
+ else if((ret = cmInetSctpBindx(&sctpCb.xnLstnSockFd, &sctpCb.localAddrLst, sctpCb.sctpCfg.xnSctpInfo.port)) != ROK)
+ {
+ DU_LOG("\nERROR --> SCTP: Binding failed at CU");
+ }
+ else if(ret = cmInetListen(&sctpCb.xnLstnSockFd, 1) != ROK)
+ {
+ DU_LOG("\nERROR --> SCTP : Listening on socket failed");
+ cmInetClose(&sctpCb.xnLstnSockFd);
+ return RFAILED;
+ }
+ else
+ {
+ for(assocIdx=0; assocIdx < sctpCb.numAssoc; assocIdx++)
+ {
+ if(sctpCb.assocCb[assocIdx].intf == XN_INTERFACE)
+ {
+ if((ret = sctpAccept(&sctpCb.xnLstnSockFd, &sctpCb.assocCb[assocIdx])) != ROK)
+ {
+ DU_LOG("\nERROR --> SCTP: Unable to accept the connection at CU");
+ }
+ }
+ }
+ }
+ }
+ else if(sctpCb.localXnNodeType == CLIENT)
+ {
+ for(assocIdx=0; assocIdx < sctpCb.numAssoc; assocIdx++)
+ {
+ if(sctpCb.assocCb[assocIdx].intf == XN_INTERFACE)
+ {
+ if((ret = cmInetSocket(socket_type, &sctpCb.assocCb[assocIdx].sockFd, IPPROTO_SCTP)) != ROK)
+ {
+ DU_LOG("\nERROR --> SCTP : Failed while opening a socket in ODU");
+ }
+ else if((ret = cmInetSctpBindx(&sctpCb.assocCb[assocIdx].sockFd, &sctpCb.localAddrLst, sctpCb.sctpCfg.xnSctpInfo.port)) != ROK)
+ {
+ DU_LOG("\nERROR --> SCTP: Failed during Binding in ODU");
+ }
+ else if((ret = sctpSetSockOpts(&sctpCb.assocCb[assocIdx].sockFd)) != ROK)
+ {
+ DU_LOG("\nERROR --> SCTP : Failed to set Socket Opt in ODU");
+ }
+ else
+ {
+ if(ret != ROK)
+ {
+ DU_LOG("\nERROR --> SCTP : Failed while establishing Req at DU");
+ ret = RFAILED;
+ }
+ else
+ {
+ ret = cmInetSctpConnectx(&sctpCb.assocCb[assocIdx].sockFd, &sctpCb.assocCb[assocIdx].destIpNetAddr, \
+ &sctpCb.assocCb[assocIdx].destAddrLst, sctpCb.assocCb[assocIdx].destPort);
+ /* 115 error_code indicates that Operation is in progress and hence ignored if SctpConnect failed due to this */
+ if(ret == 18)
+ {
+ ret = ROK;
+ }
+ }
+ }
+ }
+ }
+ }
}
- else if((ret = sctpAccept(&f1Params.lstnSockFd, &f1Params.peerAddr, &f1Params.sockFd)) != ROK)
+
+ /* Establish SCTP association at F1 interface */
+ if(sctpCb.sctpCfg.f1SctpInfo.numDestNode)
{
- DU_LOG("\nERROR --> SCTP: Unable to accept the connection at CU");
+ if((ret = cmInetSocket(socket_type, &sctpCb.f1LstnSockFd, IPPROTO_SCTP) != ROK))
+ {
+ DU_LOG("\nERROR --> SCTP : Socket[%d] coudnt open for listening", sctpCb.f1LstnSockFd.fd);
+ }
+ else if((ret = cmInetSctpBindx(&sctpCb.f1LstnSockFd, &sctpCb.localAddrLst, sctpCb.sctpCfg.f1SctpInfo.port)) != ROK)
+ {
+ DU_LOG("\nERROR --> SCTP: Binding failed at CU");
+ }
+ else if(ret = cmInetListen(&sctpCb.f1LstnSockFd, 1) != ROK)
+ {
+ DU_LOG("\nERROR --> SCTP : Listening on socket failed");
+ cmInetClose(&sctpCb.f1LstnSockFd);
+ return RFAILED;
+ }
+ else
+ {
+ for(assocIdx=0; assocIdx < sctpCb.numAssoc; assocIdx++)
+ {
+ if(sctpCb.assocCb[assocIdx].intf == F1_INTERFACE)
+ {
+ if((ret = sctpAccept(&sctpCb.f1LstnSockFd, &sctpCb.assocCb[assocIdx])) != ROK)
+ {
+ DU_LOG("\nERROR --> SCTP: Unable to accept the connection at CU");
+ }
+ }
+ }
+ }
}
- else if(sctpSockPoll() != ROK)
+
+ if(ret == ROK)
{
- DU_LOG("\nERROR --> SCTP: Polling failed to start at CU");
+ if(sctpSockPoll() != ROK)
+ {
+ DU_LOG("\nERROR --> SCTP: Polling failed to start at CU");
+ }
}
return (ret);
}
+
/*******************************************************************
*
* @brief Sets socket options as per requirement
* RFAILED - failure
*
* ****************************************************************/
-S16 sctpSetSockOpts(CmInetFd *sock_Fd)
+uint8_t sctpSetSockOpts(CmInetFd *sock_Fd)
{
S16 ret = ROK;
CmSctpEvent sctpEvent;
* RFAILED - failure
*
* ****************************************************************/
-S16 sctpAccept(CmInetFd *lstnSock_Fd, CmInetAddr *peerAddr, CmInetFd *sock_Fd)
+uint8_t sctpAccept(CmInetFd *lstnSockFd, CuSctpAssocCb *assocCb)
{
uint8_t ret;
- ret = cmInetListen(lstnSock_Fd, 1);
- if (ret != ROK)
- {
- DU_LOG("\nERROR --> SCTP : Listening on socket failed");
- cmInetClose(lstnSock_Fd);
- return RFAILED;
- }
-
DU_LOG("\nINFO --> SCTP : Connecting");
- while(!connUp)
+ while(!assocCb->connUp)
{
- ret = cmInetAccept(lstnSock_Fd, peerAddr, sock_Fd);
+ ret = cmInetAccept(lstnSockFd, &assocCb->peerAddr, &assocCb->sockFd);
if (ret == ROKDNA)
{
continue;
}
else
{
- connUp = TRUE;
- sctpSetSockOpts(sock_Fd);
+ assocCb->connUp = TRUE;
+ sctpSetSockOpts(&assocCb->sockFd);
break;
}
}
* RFAILED - failure
*
* ****************************************************************/
-S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy)
+uint8_t sctpNtfyHdlr(CuSctpAssocCb *assocCb, CmInetSctpNotification *ntfy)
{
switch(ntfy->header.nType)
{
{
case CM_INET_SCTP_COMM_UP:
DU_LOG("DEBUG --> Event : COMMUNICATION UP");
- connUp = TRUE;
+ assocCb->connUp = TRUE;
break;
case CM_INET_SCTP_COMM_LOST:
DU_LOG("DEBUG --> Event : COMMUNICATION LOST");
- connUp = FALSE;
+ assocCb->connUp = FALSE;
break;
case CM_INET_SCTP_RESTART:
DU_LOG("DEBUG --> Event : SCTP RESTART");
- connUp = FALSE;
+ assocCb->connUp = FALSE;
break;
case CM_INET_SCTP_SHUTDOWN_COMP: /* association gracefully shutdown */
DU_LOG("DEBUG --> Event : SHUTDOWN COMPLETE");
- connUp = FALSE;
+ assocCb->connUp = FALSE;
break;
case CM_INET_SCTP_CANT_STR_ASSOC:
DU_LOG("DEBUG --> Event : CANT START ASSOC");
- connUp = FALSE;
+ assocCb->connUp = FALSE;
break;
default:
DU_LOG("\nERROR --> Invalid event");
break;
case CM_INET_SCTP_SHUTDOWN_EVENT : /* peer socket gracefully closed */
DU_LOG("\nINFO --> SCTP : Shutdown Event notification received\n");
- connUp = FALSE;
+ assocCb->connUp = FALSE;
exit(0);
break;
case CM_INET_SCTP_ADAPTATION_INDICATION :
* RFAILED - failure
*
* ****************************************************************/
-S16 sctpSockPoll()
+uint8_t sctpSockPoll()
{
+ uint8_t assocIdx = 0, destIdx = 0;
uint16_t ret = ROK;
uint32_t timeout;
uint32_t *timeoutPtr;
Buffer *egtpBuf;
MsgLen egtpBufLen;
- CmInetAddr egtpFromAddr;
CmInetMemInfo memInfo;
- sctpSockPollParams f1PollParams;
+ sctpSockPollParams pollParams;
+ uint64_t numMsgRcvd = 0;
+ CmInetAddr fromAddr;
- memset(&f1PollParams, 0, sizeof(sctpSockPollParams));
+ memset(&pollParams, 0, sizeof(sctpSockPollParams));
- egtpFromAddr.port = egtpCb.dstCb.dstPort;
- egtpFromAddr.address = egtpCb.dstCb.dstIp;
- if(f1Params.sockFd.blocking)
- {
- /* blocking */
- timeoutPtr = NULLP;
- }
- else
- {
- /* non-blocking */
- timeout = 0;
- timeoutPtr = &timeout;
- }
+ /* All sockets are non-blocking */
+ timeout = 0;
+ timeoutPtr = &timeout;
memInfo.region = CU_APP_MEM_REG;
memInfo.pool = CU_POOL;
- CM_INET_FD_ZERO(&f1PollParams.readFd);
+ CM_INET_FD_ZERO(&pollParams.readFd);
while(1)
{
- if((ret = processPolling(&f1PollParams, &f1Params.sockFd, timeoutPtr, &memInfo)) != ROK)
+ /* Receiving SCTP data */
+ for(assocIdx = 0; assocIdx < sctpCb.numAssoc; assocIdx++)
{
- DU_LOG("\nERROR --> SCTP : Failed to RecvMsg for F1 at CU\n");
+ if((ret = processPolling(&pollParams, &sctpCb.assocCb[assocIdx], timeoutPtr, &memInfo)) != ROK)
+ {
+ DU_LOG("\nERROR --> SCTP : Failed to RecvMsg for F1 at CU\n");
+ }
}
/* Receiving EGTP data */
egtpBufLen = -1;
- ret = cmInetRecvMsg(&(egtpCb.recvTptSrvr.sockFd), &egtpFromAddr, &memInfo, &egtpBuf, &egtpBufLen, CM_INET_NO_FLAG);
+ ret = cmInetRecvMsg(&(egtpCb.sockFd), &fromAddr, &memInfo, &egtpBuf, &egtpBufLen, CM_INET_NO_FLAG);
if(ret == ROK && egtpBuf != NULLP)
{
- DU_LOG("\nINFO --> EGTP : Received message \n");
- ODU_PRINT_MSG(egtpBuf, 0 ,0);
- cuEgtpHdlRecvMsg(egtpBuf);
+ for(destIdx = 0; destIdx < egtpCb.numDu; destIdx++)
+ {
+ if((fromAddr.port == egtpCb.dstCb[destIdx].dstAddr.port) && (fromAddr.address == egtpCb.dstCb[destIdx].dstAddr.address))
+ {
+ DU_LOG("\nINFO --> EGTP : Received UL Message [%ld] from DU Id [%d]\n", numMsgRcvd+1, egtpCb.dstCb[destIdx].duId);
+ numMsgRcvd++;
+ //ODU_PRINT_MSG(egtpBuf, 0 ,0);
+ cuEgtpHdlRecvMsg(egtpBuf);
+ break;
+ }
+ }
}
};
return (ret);
*
* ****************************************************************/
-S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, uint32_t *timeoutPtr, CmInetMemInfo *memInfo)
+uint8_t processPolling(sctpSockPollParams *pollParams, CuSctpAssocCb *assocCb, uint32_t *timeoutPtr, CmInetMemInfo *memInfo)
{
uint16_t ret = ROK;
- CM_INET_FD_SET(sockFd, &pollParams->readFd);
+ CM_INET_FD_SET(&assocCb->sockFd, &pollParams->readFd);
ret = cmInetSelect(&pollParams->readFd, NULLP, timeoutPtr, &pollParams->numFd);
- if(CM_INET_FD_ISSET(sockFd, &pollParams->readFd))
+ if(CM_INET_FD_ISSET(&assocCb->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))
+ CM_INET_FD_CLR(&assocCb->sockFd, &pollParams->readFd);
+ ret = cmInetSctpRecvMsg(&assocCb->sockFd, &pollParams->addr, &pollParams->port, memInfo, &pollParams->mBuf, \
+ &pollParams->bufLen, &pollParams->info, &pollParams->flag, &pollParams->ntfy);
+ if(assocCb->connUp & (ret != ROK))
{
- f1Params.bReadFdSet = RFAILED;
+ assocCb->bReadFdSet = RFAILED;
}
else
{
if(((pollParams->flag & CM_INET_SCTP_MSG_NOTIFICATION) != 0) && (ret == ROK))
{
- ret = sctpNtfyHdlr(&pollParams->ntfy);
+ ret = sctpNtfyHdlr(assocCb, &pollParams->ntfy);
if(ret != ROK)
{
DU_LOG("\nERROR --> SCTP : Failed to process sctp notify msg\n");
}
}
- else if(connUp & (pollParams->port == f1Params.destPort))
+ else if(assocCb->connUp && assocCb->intf == F1_INTERFACE)
{
- F1APMsgHdlr(pollParams->mBuf);
+ F1APMsgHdlr(&assocCb->destId, pollParams->mBuf);
+ ODU_PUT_MSG_BUF(pollParams->mBuf);
+ }
+ else if(assocCb->connUp && assocCb->intf == XN_INTERFACE)
+ {
+ DU_LOG("\nDEBUG --> SCTP : Received message at XN interface");
+ ODU_PRINT_MSG(pollParams->mBuf, 0,0);
+ XNAPMsgHdlr(&assocCb->destId, pollParams->mBuf);
ODU_PUT_MSG_BUF(pollParams->mBuf);
}
else
/*******************************************************************
*
- * @brief Send message on SCTP socket
+ * @brief Send message on an SCTP Association
*
* @details
*
- * Function : sctpSend
+ * Function : sendOnSctpAssoc
*
* Functionality:
- * Send message on SCTP socket
+ * Send message on SCTP association
*
* @params[in]
* @return ROK - success
* RFAILED - failure
*
* ****************************************************************/
-S16 sctpSend(Buffer *mBuf)
+uint8_t sendOnSctpAssoc(CuSctpAssocCb *assocCb, Buffer *mBuf)
{
- uint8_t ret;
- MsgLen len; /* number of actually sent octets */
- CmInetMemInfo memInfo;
+ uint8_t ret = ROK;
+ MsgLen len = 0; /* number of actually sent octets */
+ CmInetMemInfo memInfo;
- memInfo.region = CU_APP_MEM_REG;
+ memset(&memInfo , 0, sizeof(CmInetMemInfo));
+ 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);
+ ret = cmInetSctpSendMsg(&assocCb->sockFd, &assocCb->destIpNetAddr, assocCb->destPort, &memInfo, mBuf, &len, 0, \
+ FALSE, 0, 0/*SCT_PROTID_NONE*/, RWOULDBLOCK);
if(ret != ROK && ret != RWOULDBLOCK)
{
DU_LOG("\nERROR --> SCTP : Send message failed");
return RFAILED;
}
-
return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Send message on SCTP socket
+ *
+ * @details
+ *
+ * Function : sctpSend
+ *
+ * Functionality:
+ * Send message on SCTP socket
+ *
+ * @params[in]
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t sctpSend(InterfaceType intf, uint32_t destId, Buffer *mBuf)
+{
+ uint8_t assocIdx = 0;
+
+ for(assocIdx=0; assocIdx < sctpCb.numAssoc; assocIdx++)
+ {
+ if((sctpCb.assocCb[assocIdx].intf == intf) && (sctpCb.assocCb[assocIdx].destId == destId))
+ {
+ if(sendOnSctpAssoc(&sctpCb.assocCb[assocIdx], mBuf) == ROK)
+ return ROK;
+ else
+ break;
+ }
+ }
+ DU_LOG("\nERROR --> SCTP : Dest ID [%d] at Interface [%d] not found in SCTP DestCb list. Failed to send message", destId, intf);
+ return RFAILED;
} /* End of sctpSend */
/**********************************************************************