*******************************************************************************/
/* This file contains all SCTP related functionality */
-
-#include <stdio.h>
+#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 "du_common.h"
-
-/* Global variable declaration */
-CmInetFd sockFd; /* Socket file descriptor */
-U8 socket_type; /* Socket type */
-Bool nonblocking; /* Blocking/Non-blocking socket */
-Bool connUp; /* Is connection up */
-int assocId; /* Assoc Id of connected assoc */
-
-CmInetNetAddrLst localAddrLst;
-CmInetNetAddrLst remoteAddrLst;
-
-F1SctpParams *sctpCfg; /* SCTP configurations at DU */
-S16 sctpOutMsgSend(Buffer *mBuf);
+#include "lsctp.h"
+#include "du_app_rlc_inf.h"
+#include "du_mgr.h"
+#include "du_utils.h"
/**************************************************************************
* @brief Task Initiation callback function.
* @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)
{
- SSetProcId(DU_PROC);
+ DU_LOG("\n\nDEBUG --> SCTP : Initializing");
+ ODU_SET_PROC_ID(DU_PROC);
connUp = FALSE;
- assocId = 0;
+
+ memset(&f1Params, 0, sizeof(DuSctpDestCb));
+ f1Params.assocId = -1;
+ memset(&ricParams, 0, sizeof(DuSctpDestCb));
+ ricParams.assocId = -1;
nonblocking = FALSE;
- sctpCfg = &(duCfgParam.sctpParams);
return ROK;
}
+/**************************************************************************
+* @brief Function prints src, dest, msg infor about all the msgs that received.
+*
+* @details
+*
+* Function : callFlowSctpActvTsk
+*
+* Function prints src, dest, msg infor about all the msgs that received
+*
+* @param[in] Pst *pst, Post structure of the primitive.
+*
+* @return void
+***************************************************************************/
+void callFlowSctpActvTsk(Pst *pst)
+{
+ char sourceTask[50];
+ char destTask[50]="ENTSCTP";
+ char message[100];
+
+ switch(pst->srcEnt)
+ {
+ case ENTDUAPP:
+ {
+ strcpy(sourceTask,"ENTDUAPP");
+ switch(pst->event)
+ {
+ case EVTSTARTPOLL:
+ {
+ strcpy(message,"EVTSTARTPOLL");
+ break;
+ }
+ }
+ break;
+ }
+ }
+ DU_LOG("\nCall Flow: %s -> %s : %s\n", sourceTask, destTask, message);
+}
+
/**************************************************************************
* @brief Task Activation callback function.
*
* RFAILED - failure
*
***************************************************************************/
-S16 sctpActvTsk(Pst *pst, Buffer *mBuf)
+uint8_t sctpActvTsk(Pst *pst, Buffer *mBuf)
{
+
+#ifdef CALL_FLOW_DEBUG_LOG
+ callFlowSctpActvTsk(pst);
+#endif
+
+
switch(pst->srcEnt)
{
case ENTDUAPP:
{
switch(pst->event)
{
- case EVTSCTPSTRT:
+ case EVTSTARTPOLL:
{
- SPutMsg(mBuf);
- sctpAssocReq();
+ sctpSockPoll();
break;
- }
+ }
}
break;
}
}
- SExitTsk();
+ ODU_EXIT_TASK();
return ROK;
}
-
/*******************************************************************
*
- * @brief Opens a non-blocking socket and binds to local address
+ * @brief Checks the status of the received information
*
* @details
*
- * Function : openSctpEndp
+ * Function : duCheckReqStatus
*
* Functionality:
- * Opens a non-blocking socket and binds to local address
+ * Checks the status of the received information
*
- * @params[in]
+ * @params[in] Confirm status
* @return ROK - success
* RFAILED - failure
*
- * ****************************************************************/
-S16 openSctpEndp()
+ ******************************************************************/
+uint8_t duCheckReqStatus(CmStatus *cfm)
{
- U8 ret;
- U8 numRetry = 0;
+ uint8_t ret = ROK;
+ if(cfm->status != LCM_PRIM_OK)
+ {
+ DU_LOG("\nERROR --> DU_APP : Failed to process the request successfully");
+ ret = RFAILED;
+ }
+ return (ret);
+}
- /* Opening a non-blocking SCTP socket */
- socket_type = CM_INET_STREAM;
+/**************************************************************************
+ * @brief Function to configure the Sctp Params during config Request
+ *
+ * @details
+ *
+ * Function : duSctpCfgReq
+ *
+ * Functionality:
+ * This function configures SCTP Params during the config Request
+ *
+ * @param[in] SctpParams sctpCfg, common structure which has all the configuration
+ * @param[in] CmStatus cfm, Builds the cfm status and reason
+ * buffer.
+ *
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ***************************************************************************/
- do{
- ret = cmInetSocket(socket_type, &sockFd, IPPROTO_SCTP,(sctpCfg->duIpAddr.ipV4Pres ? CM_INET_IPV4_DOMAIN : CM_INET_IPV6_DOMAIN));
- if (ret != ROK)
- {
- numRetry++;
- if(numRetry >= MAX_RETRY)
- {
- printf("\nAll attempts to open socket failed.");
- /* Send indication to du_app */
- RETVALUE(RFAILED);
- }
- else
- {
- printf("\nRetrying socket opening");
- }
- }
- else
- {
- printf("\nSocket[%d] opened successfully",sockFd.fd);
- break;
- }
- }while(numRetry < MAX_RETRY);
+uint8_t duSctpCfgReq(SctpParams sctpCfg)
+{
+ uint8_t ret = ROK;
+ CmStatus cfm;
+
+#ifdef CALL_FLOW_DEBUG_LOG
+ DU_LOG("\nCall Flow: ENTDUAPP -> ENTSCTP : EVENT_CFG_REQ_TO_SCTP\n");
+#endif
+/* 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[F1_INTERFACE];
+ f1Params.recvMsgSet = ROK;
+ memset (&f1Params.sockFd, -1, sizeof(CmInetFd));
+ fillDestNetAddr(&f1Params.destIpNetAddr, &f1Params.destIpAddr);
+ fillAddrLst(&f1Params.destAddrLst, &f1Params.destIpAddr);
+
+/* Fill RIC Params */
+ ricParams.destIpAddr.ipV4Pres = sctpCfg.ricIpAddr.ipV4Pres;
+ ricParams.destIpAddr.ipV4Addr = sctpCfg.ricIpAddr.ipV4Addr;
+ ricParams.destPort = sctpCfg.ricPort;
+ ricParams.itfState = DU_SCTP_DOWN;
+ 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);
+
+/* Fill AddressList */
+ fillAddrLst(&localAddrLst, &sctpCfg.duIpAddr);
+
+/* Set polling to FALSE */
+ pollingState = FALSE;
+
+/* Fill Cfm Status */
+ cfm.status = LCM_PRIM_OK;
+ cfm.reason = LCM_REASON_NOT_APPL;
+
+ ret = duCheckReqStatus(&cfm);
+
+ return (ret);
+}
- RETVALUE(ROK);
-} /* End of openSctpEndp */
+/*******************************************************************
+ *
+ * @brief Fills the address List of the source Ip Address
+ *
+ * @details
+ *
+ * Function : fillAddrLst
+ *
+ * Functionality:
+ * Fills the address List of source Ip Address
+ *
+ * @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
+ *
+ ******************************************************************/
+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_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] CmInetNetAddr *destAddrPtr, Address List pointer
+ * @params[in] F1IpAddr *dstIpAddr, destIp Address to be filled in the Address List
*
- * @params[in]
* @return ROK - success
* RFAILED - failure
*
- * ****************************************************************/
-S16 bindSctpEndp()
+ *******************************************************************************/
+uint8_t fillDestNetAddr(CmInetNetAddr *destAddrPtr, F1IpAddr *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 Establishes the Assoc Req for the received interface type
+ *
+ * @details
+ *
+ * Function : establishAssocReq
+ *
+ * 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->duIpAddr.ipV4Pres)
+uint8_t establishReq(DuSctpDestCb *paramPtr)
+{
+ Pst pst;
+ uint8_t ret = ROK;
+ socket_type = CM_INET_STREAM;
+
+ if((ret = cmInetSocket(socket_type, ¶mPtr->sockFd, IPPROTO_SCTP)) != ROK)
{
- localAddrLst.addrs[0].type = CM_INET_IPV4ADDR_TYPE;
- localAddrLst.addrs[0].u.ipv4NetAddr = CM_INET_NTOH_U32(sctpCfg->duIpAddr.ipV4Addr);
- }
- else if(sctpCfg->duIpAddr.ipV6Pres)
+ DU_LOG("\nERROR --> SCTP : Failed while opening a socket in ODU");
+ }
+ else if((ret = cmInetSctpBindx(¶mPtr->sockFd, &localAddrLst, paramPtr->srcPort)) != ROK)
{
- localAddrLst.addrs[0].type = CM_INET_IPV6ADDR_TYPE;
- // CM_INET_COPY_IPV6ADDR(&(localAddrLst.addrs[0].u.ipv6NetAddr),&(sctpCfg->duIpAddr.ipV6Addr);
+ DU_LOG("\nERROR --> SCTP: Failed during Binding in ODU");
}
- else
+ else if((ret = sctpSetSockOpts(¶mPtr->sockFd)) != ROK)
{
- localAddrLst.addrs[0].type = CM_INET_IPV4ADDR_TYPE;
- localAddrLst.addrs[0].u.ipv4NetAddr = 0;
- }
-
- do{
- ret = cmInetSctpBindx(&sockFd, &localAddrLst, sctpCfg->duPort);
- if (ret != ROK)
+ DU_LOG("\nERROR --> SCTP : Failed to set Socket Opt in ODU");
+ }
+ else
+ {
+ if(ret != ROK)
{
- numRetry++;
- if(numRetry >= MAX_RETRY)
- {
- printf("\nAll attempts to bind socket failed.");
- cmInetClose(&sockFd);
- /* Send indication to du_app */
- RETVALUE(RFAILED);
- }
- else
+ DU_LOG("\nERROR --> SCTP : Failed while establishing Req at DU");
+ ret = RFAILED;
+ }
+ else
+ {
+ ret = cmInetSctpConnectx(¶mPtr->sockFd, ¶mPtr->destIpNetAddr, ¶mPtr->destAddrLst, paramPtr->destPort);
+ /* 115 error_code indicates that Operation is in progress and hence ignored if SctpConnect failed due to this */
+ if(ret == 18)
{
- printf("\nRetrying socket binding");
+ ret = ROK;
}
}
- else
+ }
+ if((ret == ROK) & (paramPtr->itfState == DU_SCTP_DOWN))
+ {
+ paramPtr->itfState = DU_SCTP_CONNECTING;
+ }
+
+ /* Post the EVTSTARTPOLL Msg */
+ if(!pollingState)
+ {
+ pollingState = TRUE;
+ duFillSctpPst(&pst, EVTSTARTPOLL);
+ }
+
+ return (ret);
+}
+
+/******************************************************************************
+ *
+ * @brief Processes the assoc Req for the received interface type
+ *
+ * @details
+ *
+ * Function : duSctpAssocReq
+ *
+ * Functionality:
+ * Processes the Assoc Req for the received interface type
+ *
+ * @params[in] itfType interface Type,
+ * @params[in] cfm , represents the status of request
+ *
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ *******************************************************************************/
+
+uint8_t duSctpAssocReq(uint8_t itfType)
+{
+ uint8_t ret = ROK;
+ CmStatus cfm;
+ DuSctpDestCb *paramPtr = NULLP;
+
+#ifdef CALL_FLOW_DEBUG_LOG
+ DU_LOG("\nCall Flow: ENTDUAPP -> ENTSCTP : EVENT_ASSOC_REQ_TO_SCTP\n");
+#endif
+
+ DU_ALLOC(paramPtr, sizeof(DuSctpDestCb));
+ if(paramPtr == NULLP)
+ {
+ DU_LOG("\nERROR --> DU_APP : Failed to allocate memory");
+ return RFAILED;
+ }
+ switch(itfType)
+ {
+ case F1_INTERFACE:
{
- printf("\nSocket bind successful");
+ paramPtr = &f1Params;
+ ret = establishReq(paramPtr);
break;
}
- }while(numRetry < MAX_RETRY);
-
- RETVALUE(ROK);
-
-} /* End of bindSctpEndp() */
+ case E2_INTERFACE:
+ {
+ paramPtr = &ricParams;
+ ret = establishReq(paramPtr);
+ break;
+ }
+ default:
+ {
+ DU_LOG("\nERROR --> SCTP : Invalid Interface Type %d", itfType);
+ break;
+ }
+ }
+ if(ret != ROK)
+ {
+ DU_LOG("\nERROR --> SCTP : ASSOC Req Failed.");
+ cfm.status = LCM_PRIM_NOK;
+ cfm.reason = LCM_REASON_NOT_APPL;
+ }
+ else
+ {
+ cfm.status = LCM_PRIM_OK;
+ cfm.reason = LCM_REASON_NOT_APPL;
+ }
+ ret = duCheckReqStatus(&cfm);
+ return (ret);
+}
/*******************************************************************
*
- * @brief Sets socket options as per requirement
+ * @brief Fills Pst struct for ENTSCTP
*
* @details
*
- * Function : sctpSetSockOpts
+ * Function : duFillSctpPst
*
- * Functionality:
- * Sets socket options as per requirement
+ * Functionality:
+ * Fills Pst struct for ENTSCTP
*
* @params[in]
* @return ROK - success
* RFAILED - failure
*
* ****************************************************************/
-S16 sctpSetSockOpts()
+uint8_t duFillSctpPst(Pst *pst, Event event)
{
- CmSctpEvent sctpEvent;
-
- sctpEvent.dataIoEvent = TRUE;
- sctpEvent.associationEvent = TRUE;
- sctpEvent.addressEvent = TRUE;
- sctpEvent.sendFailureEvent = TRUE;
- sctpEvent.peerErrorEvent = TRUE;
- sctpEvent.shutdownEvent = TRUE;
- sctpEvent.partialDeliveryEvent = TRUE;
- sctpEvent.adaptationLayerEvent = TRUE;
-
- cmInetSetOpt(&sockFd, CM_SOCKOPT_LEVEL_SCTP, CM_SOCKOPT_OPT_SCTP_EVENTS, &sctpEvent);
- RETVALUE(ROK);
+ Buffer *mBuf;
+ if(ODU_GET_MSG_BUF(DFLT_REGION, DU_POOL, &mBuf) != ROK)
+ {
+ DU_LOG("\nERROR --> DU_APP : Failed to allocate memory");
+ return RFAILED;
+ }
+ memset(pst, 0, sizeof(Pst));
+ pst->srcEnt = (Ent)ENTDUAPP;
+ pst->srcInst = (Inst)DU_INST;
+ pst->srcProcId = DU_PROC;
+ pst->dstEnt = (Ent)ENTSCTP;
+ pst->dstInst = (Inst)SCTP_INST;
+ pst->dstProcId = pst->srcProcId;
+ pst->event = event;
+ pst->selector = ODU_SELECTOR_LC;
+ pst->pool= DU_POOL;
+ ODU_POST_TASK(pst, mBuf);
- RETVALUE(ROK);
+ return ROK;
}
/*******************************************************************
*
- * @brief Initiates connection with peer SCTP
+ * @brief Sets socket options as per requirement
*
* @details
*
- * Function : sctpConnect
+ * Function : sctpSetSockOpts
*
- * Functionality:
- * Establishes SCTP connection with peer.
- * Here, DU-SCTP will initate connection towards CU-SCTP
+ * Functionality:
+ * Sets socket options as per requirement
*
- * @params[in]
+ * @params[in] sock_Fd determines the sockFd to be set
* @return ROK - success
* RFAILED - failure
*
* ****************************************************************/
-S16 sctpConnect()
+uint8_t sctpSetSockOpts(CmInetFd *sock_Fd)
{
- U8 ret;
- U8 numRetry = 0;
- CmInetNetAddr primDstAddr; /* primary destination address */
+ uint8_t ret = ROK;
+ CmSctpEvent sctpEvent;
- /* Filling primary destination address */
- if(sctpCfg->cuIpAddr.ipV4Pres)
- {
- primDstAddr.type = CM_INET_IPV4ADDR_TYPE;
- primDstAddr.u.ipv4NetAddr = CM_INET_NTOH_U32(sctpCfg->cuIpAddr.ipV4Addr);
- }
- else if(sctpCfg->cuIpAddr.ipV6Pres)
- {
- primDstAddr.type = CM_INET_IPV6ADDR_TYPE;
- //CM_INET_COPY_IPV6ADDR(&(primDstAddr.u.ipv6NetAddr),&(sctpCfg->cuIpAddr.ipV6Addr);
- }
- else
- {
- primDstAddr.type = CM_INET_IPV4ADDR_TYPE;
- primDstAddr.u.ipv4NetAddr = 0;
- }
+ sctpEvent.dataIoEvent = TRUE;
+ sctpEvent.associationEvent = TRUE;
+ sctpEvent.addressEvent = TRUE;
+ sctpEvent.sendFailureEvent = TRUE;
+ sctpEvent.peerErrorEvent = TRUE;
+ sctpEvent.shutdownEvent = TRUE;
+ sctpEvent.partialDeliveryEvent = TRUE;
+ sctpEvent.adaptationLayerEvent = TRUE;
- /* Filling destination address list */
- remoteAddrLst.count = 1;
- if(sctpCfg->cuIpAddr.ipV4Pres)
- {
- remoteAddrLst.addrs[0].type = CM_INET_IPV4ADDR_TYPE;
- remoteAddrLst.addrs[0].u.ipv4NetAddr = CM_INET_NTOH_U32(sctpCfg->cuIpAddr.ipV4Addr);
- }
- else if(sctpCfg->cuIpAddr.ipV6Pres)
+ if((ret = cmInetSetOpt(sock_Fd, CM_SOCKOPT_LEVEL_SCTP, CM_SOCKOPT_OPT_SCTP_EVENTS, &sctpEvent) != ROK))
{
- remoteAddrLst.addrs[0].type = CM_INET_IPV6ADDR_TYPE;
- //CM_INET_COPY_IPV6ADDR(&(remoteAddrLst.addrs[0].u.ipv6NetAddr),&(sctpCfg->cuIpAddr.ipV6Addr);
- }
- else
- {
- remoteAddrLst.addrs[0].type = CM_INET_IPV4ADDR_TYPE;
- remoteAddrLst.addrs[0].u.ipv4NetAddr = 0;
+ ret = RFAILED;
}
- /* Sending connect request to remote */
- do{
- ret = cmInetSctpConnectx(&sockFd, &primDstAddr, &remoteAddrLst, sctpCfg->cuPort);
- if (ret == RFAILED || ret == ROKDNA || ret == RCLOSED)
- {
- numRetry++;
- if(numRetry >= MAX_RETRY)
- {
- printf("\nAll attempts to connect failed.");
- cmInetClose(&sockFd);
- /* Send indication to du_app */
- RETVALUE(RFAILED);
- }
- else
- {
- printf("\nRetrying connection");
- }
- }
- else if(ret == RINPROGRESS)
- {
- printf("\nConnection in progess");
- break;
- }
- else
- {
- connUp = TRUE;
- printf("\nSCTP connect successful");
- break;
- }
- }while(numRetry < MAX_RETRY);
-
- RETVALUE(ROK);
-}/* End of sctpConnect() */
+ return (ret);
+}
/*******************************************************************
*
void sendToDuApp(Buffer *mBuf, Event event)
{
Pst pst;
- printf("\nForwarding received message to duApp");
- SPrntMsg(mBuf, 0, 0);
+ DU_LOG("\nDEBUG --> SCTP : Forwarding received message to duApp");
+ 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;
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)
{
- printf("\nSPstTsk failed in duReadCfg");
- // return RFAILED;
+ DU_LOG("\nERROR --> SCTP : ODU_POST_TASK failed in duReadCfg");
}
}
* RFAILED - failure
*
* ****************************************************************/
-S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy)
+uint8_t sctpNtfyHdlr(CmInetSctpNotification *ntfy, uint8_t *itfState)
{
+ Pst pst;
switch(ntfy->header.nType)
{
case CM_INET_SCTP_ASSOC_CHANGE :
+ DU_LOG("\nDEBUG --> SCTP : Assoc change notification received");
switch(ntfy->u.assocChange.state)
{
case CM_INET_SCTP_COMM_UP:
- printf("\nSCTP notify assocchange(comm up) received");
- connUp = TRUE;
+ DU_LOG("INFO --> Event : COMMUNICATION UP");
+ *itfState = DU_SCTP_UP;
break;
case CM_INET_SCTP_COMM_LOST:
- printf("\nSCTP notify assocchange(comm lost) received");
- connUp = FALSE;
+ DU_LOG("INFO --> Event : COMMUNICATION LOST");
+ *itfState = DU_SCTP_DOWN;
break;
case CM_INET_SCTP_RESTART:
- printf("\nSCTP notify assocchange(sctp restart) received");
- connUp = FALSE;
+ DU_LOG("INFO --> Event : SCTP RESTART");
+ *itfState = DU_SCTP_DOWN;
break;
case CM_INET_SCTP_SHUTDOWN_COMP: /* association gracefully shutdown */
- printf("\nSCTP notify assocchange(shutdown complete) received\n");
- connUp = FALSE;
+ DU_LOG("INFO --> Event : SHUTDOWN COMPLETE");
+ *itfState = DU_SCTP_DOWN;
break;
case CM_INET_SCTP_CANT_STR_ASSOC:
- printf("\nSCTP notify assocchange(cant str assoc) received\n");
- connUp = FALSE;
+ DU_LOG("INFO --> Event : CANT START ASSOC");
+ *itfState = DU_SCTP_DOWN;
break;
default:
- printf("\nInvalid event");
+ DU_LOG("\nERROR --> Invalid event %d", ntfy->u.assocChange.state);
break;
}
break;
case CM_INET_SCTP_PEER_ADDR_CHANGE :
- printf("\nSCTP notify peer addr change received");
+ DU_LOG("\nINFO --> SCTP : Peer Address Change notificarion received");
/* Need to add handler */
break;
case CM_INET_SCTP_REMOTE_ERROR :
- printf("\nSCTP notify remote error received");
+ DU_LOG("\nINFO --> SCTP : Remote Error notification received");
break;
case CM_INET_SCTP_SEND_FAILED :
- printf("\nSCTP notify send failed received\n");
+ DU_LOG("\nINFO --> SCTP : Send Failed notification received\n");
break;
case CM_INET_SCTP_SHUTDOWN_EVENT : /* peer socket gracefully closed */
- printf("\nSCTP notify shutdown event received\n");
- connUp = FALSE;
+ DU_LOG("\nINFO --> SCTP : Shutdown Event notification received\n");
+ *itfState = DU_SCTP_DOWN;
+ exit(0);
break;
case CM_INET_SCTP_ADAPTATION_INDICATION :
- printf("\nSCTP notify adaptation indication received\n");
+ DU_LOG("\nINFO --> SCTP : Adaptation Indication received\n");
break;
case CM_INET_SCTP_PARTIAL_DELIVERY_EVENT:
- printf("\nSCTP notify partial delivery received\n");
+ DU_LOG("\nINFO --> SCTP : Partial Delivery Event received\n");
break;
default:
- printf("\nInvalid sctp notification type\n");
+ DU_LOG("\nERROR --> SCTP : Invalid sctp notification type %d", ntfy->header.nType);
break;
}
/* Pack notification and send to APP */
- if(cmPkSctpNtfy(ntfy) != ROK)
+ DU_LOG("\nDEBUG --> SCTP : Forwarding received message to duApp");
+
+ 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 = EVENT_SCTP_NTFY;
+ pst.selector = ODU_SELECTOR_LC;
+ pst.pool= DU_POOL;
+ pst.region = DU_APP_MEM_REGION;
+
+ if(cmPkSctpNtfy(&pst, ntfy) != ROK)
{
- printf("\nFailed to pack SCTP notification");
- RETVALUE(RFAILED);
+ DU_LOG("\nERROR --> SCTP : Failed to pack SCTP notification");
+ return RFAILED;
}
- RETVALUE(ROK);
+ return ROK;
}
/*******************************************************************
*
- * @brief Receives message on the socket
+ * @brief checks for valid readFd and process the InetSctpRecvMsg
+ * during polling
*
* @details
*
- * Function : sctpSockPoll
+ * Function : processPolling
*
* Functionality:
- * Receives message on the socket
+ * 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, recvMsgSet
*
- * @params[in]
* @return ROK - success
* RFAILED - failure
*
* ****************************************************************/
-S16 sctpSockPoll()
-{
- U8 ret;
- S16 numFds;
- CmInetFdSet readFd;
- U16 port;
- U32 timeout; /* timeout for cmInetSelect() */
- U32 *timeoutPtr; /* pointer to timeout */
- U32 flag;
- Buffer *mBuf;
- MsgLen bufLen;
- CmInetMemInfo memInfo; /* buffer allocation info */
- CmInetNetAddr addr;
- CmInetSctpSndRcvInfo info;
- CmInetSctpNotification ntfy;
-
- if (sockFd.blocking)
- {
- /* blocking */
- timeoutPtr = NULLP;
- }
- else
- {
- /* non-blocking */
- timeout = 0;
- timeoutPtr = &timeout;
- }
- memInfo.region = DU_APP_MEM_REGION;
- memInfo.pool = DU_POOL;
- CM_INET_FD_ZERO(&readFd);
- while(1)
+uint8_t processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, uint32_t *timeoutPtr, CmInetMemInfo *memInfo, bool recvMsgSet)
+{
+ uint8_t ret = ROK;
+ CM_INET_FD_SET(sockFd, &pollParams->readFd);
+ ret = cmInetSelect(&pollParams->readFd, NULLP, timeoutPtr, (int16_t *)&pollParams->numFd);
+ if(CM_INET_FD_ISSET(sockFd, &pollParams->readFd))
{
- CM_INET_FD_SET(&sockFd, &readFd);
- ret = cmInetSelect(&readFd, NULLP, timeoutPtr, &numFds);
- if (CM_INET_FD_ISSET(&sockFd, &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(ret != ROK)
{
- CM_INET_FD_CLR(&sockFd, &readFd);
- ret = cmInetSctpRecvMsg(&sockFd, &addr, &port, &memInfo, &mBuf, &bufLen, &info, &flag, &ntfy);
- if (connUp && ret != ROK)
- {
- printf("\nFailed to receive sctp msg\n");
- }
+ DU_LOG("\nERROR --> SCTP: Failed to receive sctp msg for sockFd[%d]\n", sockFd->fd);
+ recvMsgSet = RFAILED;
+ }
+ else
+ {
+#ifdef CALL_FLOW_DEBUG_LOG
+ if(pollParams->port == f1Params.destPort)
+ DU_LOG("\nCall Flow: CU -> ENTSCTP : EVENT_SCTP_MSG\n");
else
+ DU_LOG("\nCall Flow: RIC -> ENTSCTP : EVENT_SCTP_MSG\n");
+#endif
+ if((((pollParams->flag & CM_INET_SCTP_MSG_NOTIFICATION) != 0)) && ret == ROK)
{
- /* If SCTP notification received */
- if ((flag & CM_INET_SCTP_MSG_NOTIFICATION) != 0)
+ if(pollParams->port == f1Params.destPort)
{
- ret = sctpNtfyHdlr(&ntfy);
- if(ret != ROK)
- {
- printf("\nFailed to process sctp notify msg\n");
- }
+ f1Params.assocId = pollParams->ntfy.u.assocChange.assocId;
+ DU_LOG("\nDEBUG --> SCTP : AssocId assigned to F1Params from PollParams [%d]\n", f1Params.assocId);
+ ret = sctpNtfyHdlr(&pollParams->ntfy, &f1Params.itfState);
}
- else if(connUp) /* If data received */
+ else if(pollParams->port == ricParams.destPort)
{
- sendToDuApp(mBuf, EVTSCTPDATA);
+ ricParams.assocId = pollParams->ntfy.u.assocChange.assocId;
+ DU_LOG("\nDEBUG --> SCTP : AssocId assigned to ricParams from PollParams [%d]\n", ricParams.assocId);
+ ret = sctpNtfyHdlr(&pollParams->ntfy, &ricParams.itfState);
}
else
{
- SPutMsg(mBuf);
+ DU_LOG("\nERROR --> SCTP : Failed to fill AssocId\n");
+ return RFAILED;
+ }
+ if(ret != ROK)
+ {
+ DU_LOG("\nERROR --> SCTP : Failed to process sctp notify msg\n");
}
}
- }
- };
-
- RETVALUE(ROK);
-}/* End of sctpSockPoll() */
+ else if(f1Params.itfState & (pollParams->port == f1Params.destPort))
+ {
+ sendToDuApp(pollParams->mBuf, EVENT_CU_DATA);
+ }
+ else if(ricParams.itfState & (pollParams->port == ricParams.destPort))
+ {
+ sendToDuApp(pollParams->mBuf, EVENT_RIC_DATA);
+ }
+ else
+ {
+ ODU_PUT_MSG_BUF(pollParams->mBuf);
+ }
+ }
+ }
+ return ROK;
+}
/*******************************************************************
*
- * @brief Send message on SCTP socket
+ * @brief Receives message on the socket
*
* @details
*
- * Function : sctpOutMsgSend
+ * Function : sctpSockPoll
*
* Functionality:
- * Send message on SCTP socket
+ * Receives message on the socket
*
* @params[in]
* @return ROK - success
* RFAILED - failure
*
* ****************************************************************/
-S16 sctpOutMsgSend(Buffer *mBuf)
+uint8_t sctpSockPoll()
{
- U8 ret;
- MsgLen len; /* number of actually sent octets */
- CmInetNetAddr peerAddr; /* destination port address */
- CmInetNetAddr *dstAddr;
- CmInetMemInfo memInfo;
-
- memInfo.region = DU_APP_MEM_REGION;
- memInfo.pool = DU_POOL;
+ uint8_t ret = ROK;
+ uint32_t timeout;
+ uint32_t *timeout_Ptr;
+ CmInetMemInfo memInfo;
+ sctpSockPollParams f1PollParams, e2PollParams;
+ memset(&f1PollParams, 0, sizeof(sctpSockPollParams));
+ memset(&e2PollParams, 0, sizeof(sctpSockPollParams));
- if(sctpCfg->cuIpAddr.ipV4Pres)
+ if (f1Params.sockFd.blocking & ricParams.sockFd.blocking)
{
- peerAddr.type = CM_INET_IPV4ADDR_TYPE;
- peerAddr.u.ipv4NetAddr = CM_INET_NTOH_U32(sctpCfg->cuIpAddr.ipV4Addr);
- dstAddr = &peerAddr;
- }
- else if(sctpCfg->cuIpAddr.ipV6Pres)
- {
- peerAddr.type = CM_INET_IPV6ADDR_TYPE;
- //CM_INET_COPY_IPV6ADDR(&(primDstAddr.u.ipv6NetAddr),&(sctpCfg->cuIpAddr.ipV6Addr);
- dstAddr = &peerAddr;
+ /* blocking */
+ timeout_Ptr = NULLP;
}
else
{
- dstAddr = NULLP;
+ /* non-blocking */
+ timeout = 0;
+ timeout_Ptr = &timeout;
}
+ memInfo.region = DU_APP_MEM_REGION;
+ memInfo.pool = DU_POOL;
- ret = cmInetSctpSendMsg(&sockFd, dstAddr, sctpCfg->cuPort, &memInfo, mBuf, &len, 0, FALSE, 0, 0/*SCT_PROTID_NONE*/, RWOULDBLOCK);
- if(ret != ROK && ret != RWOULDBLOCK)
- {
- printf("\nFailed sending the message");
- RETVALUE(RFAILED);
- }
+ CM_INET_FD_ZERO(&f1PollParams.readFd);
+ CM_INET_FD_ZERO(&e2PollParams.readFd);
- RETVALUE(ROK);
-} /* End of sctpOutMsgSend */
+ DU_LOG("\nINFO --> SCTP : Polling started at DU\n");
+ while(true)
+ {
+ if(f1Params.itfState)
+ {
+ if((ret = processPolling(&f1PollParams, &f1Params.sockFd, timeout_Ptr, &memInfo, f1Params.recvMsgSet)) != ROK)
+ {
+ DU_LOG("\nERROR --> SCTP : Failed to RecvMsg for F1\n");
+ }
+ }
+ if(ricParams.itfState)
+ {
+ if((ret = processPolling(&e2PollParams, &ricParams.sockFd, timeout_Ptr, &memInfo, ricParams.recvMsgSet)) != ROK)
+ {
+ DU_LOG("\nERROR --> SCTP : Failed to RecvMsg for E2\n");
+ }
+ }
+ };
+ return (ret);
+}/* End of sctpSockPoll() */
/*******************************************************************
*
- * @brief SCTP Assoc establishment request from DU
+ * @brief Send message on SCTP socket
*
* @details
*
- * Function : sctpAssocReq
+ * Function : sctpSend
*
* Functionality:
- * This function opens a socket at DU and
- * intiates SCTP connection.
+ * Send message on SCTP socket
*
- * @params[in]
+ * @params[in]
* @return ROK - success
* RFAILED - failure
*
* ****************************************************************/
-void sctpAssocReq()
+uint8_t sctpSend(Buffer *mBuf, uint8_t itfType)
{
- if(openSctpEndp() != ROK)
+ uint8_t ret =0;
+ MsgLen len =0; /* number of actually sent octets */
+ CmInetMemInfo memInfo;
+
+ memInfo.region = DU_APP_MEM_REGION;
+ memInfo.pool = DU_POOL;
+
+#ifdef CALL_FLOW_DEBUG_LOG
+ if(itfType == F1_INTERFACE)
{
- printf("\nFailed while opening socket");
+ DU_LOG("\nCall Flow: ENTDUAPP -> ENTSCTP : EVENT_F1AP_MSG_TO_SCTP\n");
}
- else if(bindSctpEndp() != ROK)
+ else
{
- printf("\nFailed while binding socket");
+ DU_LOG("\nCall Flow: ENTDUAPP -> ENTSCTP : EVENT_E2AP_MSG_TO_SCTP\n");
}
- else if(sctpSetSockOpts() != ROK)
+#endif
+
+ if(itfType == F1_INTERFACE)
{
- printf("\nFailed while setting socket options");
+ DU_LOG("\nDEBUG --> SCTP : sending the message to CU");
+#ifdef CALL_FLOW_DEBUG_LOG
+ DU_LOG("\nCall Flow: ENTSCTP -> CU : EVENT_F1AP_MSG_TO_CU\n");
+#endif
+ ret = cmInetSctpSendMsg(&f1Params.sockFd, &f1Params.destIpNetAddr, f1Params.destPort, &memInfo, mBuf, &len, 0, FALSE, 0, 0/*SCT_PROTID_NONE*/, RWOULDBLOCK);
}
- else if(sctpConnect() != ROK)
+
+ if(itfType == E2_INTERFACE)
{
- printf("\nFailed while connecting to peer");
+ DU_LOG("\nDEBUG --> SCTP : sending the message to ric");
+#ifdef CALL_FLOW_DEBUG_LOG
+ DU_LOG("\nCall Flow: ENTSCTP -> RIC : EVENT_E2AP_MSG_TO_RIC\n");
+#endif
+ ret = cmInetSctpSendMsg(&ricParams.sockFd, &ricParams.destIpNetAddr, ricParams.destPort, &memInfo, mBuf, &len, 0, FALSE, 0, 0/*SCT_PROTID_NONE*/, RWOULDBLOCK);
}
- else if(sctpSockPoll() != ROK)
+
+ if(ret != ROK && ret != RWOULDBLOCK)
{
- printf("\nFailed while polling");
+ DU_LOG("\nERROR --> SCTP : Failed sending the message");
+ return RFAILED;
}
-} /* End of sctpAssocReq */
+
+ return ROK;
+} /* End of sctpSend */
/**********************************************************************
End of file