X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fdu_app%2Fdu_sctp.c;h=0fbee10b51d15ddbf6fa5f8453aab209dd8f0c46;hb=f6b4a534606e865d803b06de1f188c35820a2603;hp=9ba579151e8468a02e979348408bdcf94ef14d3c;hpb=829bbd114f1c3dc00c1da47bca0a8207c049df3f;p=o-du%2Fl2.git diff --git a/src/du_app/du_sctp.c b/src/du_app/du_sctp.c index 9ba579151..0fbee10b5 100644 --- a/src/du_app/du_sctp.c +++ b/src/du_app/du_sctp.c @@ -19,28 +19,11 @@ /* This file contains all SCTP related functionality */ #include -#include -#include -#include -#include -#include -#include - #include "du_sctp.h" -#include "du_common.h" +#include "lsctp.h" /* Global variable declaration */ -S8 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 */ - -sockaddr_storage_t local_addr; /* Local Address */ -sockaddr_storage_t remote_addr; /* Remote Address */ -U8 la_len; /* Local Address length */ -U8 ra_len; /* Remote Address length */ -F1SctpParams *sctpCfg; /* SCTP configurations at DU */ +F1SctpParams sctpCfg; /* SCTP configurations at DU */ /************************************************************************** * @brief Task Initiation callback function. @@ -64,11 +47,11 @@ F1SctpParams *sctpCfg; /* SCTP configurations at DU */ ***************************************************************************/ S16 sctpActvInit(Ent entity, Inst inst, Region region, Reason reason) { - sockFd = 0; + DU_LOG("\n\nSCTP : Initializing"); + SSetProcId(DU_PROC); connUp = FALSE; assocId = 0; nonblocking = FALSE; - sctpCfg = &(ducfgparam.sctpParams); return ROK; } @@ -94,150 +77,175 @@ S16 sctpActvInit(Ent entity, Inst inst, Region region, Reason reason) ***************************************************************************/ S16 sctpActvTsk(Pst *pst, Buffer *mBuf) { - -//TODO: TBD + switch(pst->srcEnt) + { + case ENTDUAPP: + { + switch(pst->event) + { + case EVTSCTPSTRT: + { + cmUnpkSctpAssocReq(mBuf); + SPutMsg(mBuf); + sctpAssocReq(); + break; + } + } + break; + } + } + SExitTsk(); return ROK; } /******************************************************************* * - * @brief Converts internet address to sockaddr type + * @brief Opens a non-blocking socket and binds to local address * * @details * - * Function : getSockAddr + * Function : openSctpEndp * * Functionality: - * Converts internet address to sockaddr type + * Opens a non-blocking socket and binds to local address * * @params[in] * @return ROK - success * RFAILED - failure * * ****************************************************************/ - -S16 getSockAddr(char *hostIp, U16 portNum, Bool ipv4Pres, Bool local) +S16 openSctpEndp() { - sockaddr_storage_t address; - struct hostent *host; - void *la_raw; + U8 ret; + U8 numRetry = 0; - /* Getting the transport address for local host name */ - if(ipv4Pres) - { - host = gethostbyname(hostIp); - if (host == NULL || host->h_length < 1) + /* Opening a non-blocking SCTP socket */ + socket_type = CM_INET_STREAM; + + do{ + ret = cmInetSocket(socket_type, &sockFd, IPPROTO_SCTP); + if (ret != ROK) { - printf("\nBad hostname: %s", hostIp); - RETVALUE(NULLP); + 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"); + } } - la_raw = &address.v4.sin_addr; - address.v4.sin_family = AF_INET; - address.v4.sin_port = htons(portNum); - } - else - { - host = gethostbyname2(hostIp, AF_INET6); - if (host == NULL || host->h_length < 1) + else { - printf("\n Bad hostname: %s", hostIp); - RETVALUE(RFAILED); + DU_LOG("\nSCTP : Socket[%d] open",sockFd.fd); + break; } - la_raw = &address.v6.sin6_addr; - address.v6.sin6_family = AF_INET6; - address.v6.sin6_port = htons(portNum); - address.v6.sin6_scope_id = 0; - } + }while(numRetry < MAX_RETRY); - memcpy((U8 *)la_raw, (U8 *)host->h_addr_list[0], host->h_length); - - if(local) + RETVALUE(ROK); +} /* End of openSctpEndp */ + + +/******************************************************************* + * + * @brief Bind socket to local Ip address and port + * + * @details + * + * Function : bindSctpEndp + * + * Functionality: + * -Bind socket to local Ip address and port + * + * @params[in] + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ +S16 bindSctpEndp() +{ + + U8 ret; + U8 numRetry = 0; + + /* Binding the socket with local address */ + localAddrLst.count = 1; + if(sctpCfg.duIpAddr.ipV4Pres) { - local_addr = address; + localAddrLst.addrs[0].type = CM_INET_IPV4ADDR_TYPE; + localAddrLst.addrs[0].u.ipv4NetAddr = CM_INET_NTOH_U32(sctpCfg.duIpAddr.ipV4Addr); } else { - remote_addr = address; - } + localAddrLst.addrs[0].type = CM_INET_IPV4ADDR_TYPE; + localAddrLst.addrs[0].u.ipv4NetAddr = 0; + } - RETVALUE(ROK); -} /* End of getSockAddr() */ + do{ + ret = cmInetSctpBindx(&sockFd, &localAddrLst, sctpCfg.duPort); + if (ret != ROK) + { + numRetry++; + if(numRetry >= MAX_RETRY) + { + DU_LOG("\nSCTP : All attempts to bind socket failed."); + cmInetClose(&sockFd); + /* 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() */ /******************************************************************* * - * @brief Opens a non-blocking socket and binds to local address + * @brief Sets socket options as per requirement * * @details * - * Function : openSctpEndp + * Function : sctpSetSockOpts * - * Functionality: - * Opens a non-blocking socket and binds to local address + * Functionality: + * Sets socket options as per requirement * * @params[in] * @return ROK - success * RFAILED - failure * * ****************************************************************/ -S16 openSctpEndp() +S16 sctpSetSockOpts() { - sa_family_t la_family; - U8 error; - - - /* Getting the transport address for local host name */ - if(sctpCfg->duIpAddr.ipV4Pres) - { - if(getSockAddr(sctpCfg->duIpAddr.ipV4Addr, sctpCfg->duPort, TRUE, TRUE) != ROK ) - { - printf("\nUnable to get local address"); - RETVALUE(RFAILED); - } - la_family = AF_INET; - } - else - { - if(getSockAddr(sctpCfg->duIpAddr.ipV6Addr, sctpCfg->duPort, FALSE, TRUE) != ROK ) - { - printf("\nUnable to get local address"); - RETVALUE(RFAILED); - } - la_family = AF_INET6; - } - - socket_type = SOCK_STREAM; - - /* Creating new end point */ - sockFd = socket(la_family, socket_type, IPPROTO_SCTP); - if (sockFd < 0) - { - printf("\n Failed to create socket %s", strerror(errno)); - RETVALUE(RFAILED); - } - - /* Binding socket to local address and port */ - error = bind(sockFd, &local_addr.sa, la_len); - if(error != 0) - { - printf("\n Failed to bind to socket. Error [%s]", strerror(errno)); - RETVALUE(RFAILED); - } - - /* Setting socket as non-blocking*/ - error = fcntl(sockFd, F_SETFL, O_NONBLOCK); - if (error != 0) - { - printf("\n Failed to set socket as non blocking. Error [%s]", strerror(errno)); - RETVALUE(RFAILED); - } - else - { - nonblocking = TRUE; - } - - RETVALUE(ROK); + 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); -} /* End of openSctpEndp() */ + RETVALUE(ROK); +} /******************************************************************* * @@ -258,170 +266,207 @@ S16 openSctpEndp() * ****************************************************************/ S16 sctpConnect() { - U8 error; U8 ret; + U8 numRetry = 0; + CmInetNetAddr primDstAddr; /* primary destination address */ - /* Getting the transport address for remote host name */ - if(sctpCfg->cuIpAddr.ipV4Pres) + /* Filling primary destination address */ + if(sctpCfg.cuIpAddr.ipV4Pres) { - ret = getSockAddr(sctpCfg->cuIpAddr.ipV4Addr, sctpCfg->cuPort, TRUE, FALSE); + primDstAddr.type = CM_INET_IPV4ADDR_TYPE; + primDstAddr.u.ipv4NetAddr = CM_INET_NTOH_U32(sctpCfg.cuIpAddr.ipV4Addr); } else { - ret = getSockAddr(sctpCfg->cuIpAddr.ipV6Addr, sctpCfg->cuPort, FALSE, FALSE); + primDstAddr.type = CM_INET_IPV4ADDR_TYPE; + primDstAddr.u.ipv4NetAddr = 0; } - if(ret != ROK) + + /* Filling destination address list */ + remoteAddrLst.count = 1; + if(sctpCfg.cuIpAddr.ipV4Pres) { - printf("\nUnable to get remote address"); - RETVALUE(RFAILED); + remoteAddrLst.addrs[0].type = CM_INET_IPV4ADDR_TYPE; + remoteAddrLst.addrs[0].u.ipv4NetAddr = CM_INET_NTOH_U32(sctpCfg.cuIpAddr.ipV4Addr); } - - /* Initiating connection establishment with remote */ - if(!connUp) + else { - error = sctp_connectx(sockFd, &remote_addr.sa, 1, &assocId); - if(error != 0) + remoteAddrLst.addrs[0].type = CM_INET_IPV4ADDR_TYPE; + remoteAddrLst.addrs[0].u.ipv4NetAddr = 0; + } + + /* 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) + { + DU_LOG("\nSCTP : All attempts to connect failed."); + cmInetClose(&sockFd); + /* Send indication to du_app */ + RETVALUE(RFAILED); + } + else + { + DU_LOG("\nSCTP : Retrying connection"); + } + } + else if(ret == RINPROGRESS) { - printf("\nError connecting to peer. Error[%s]", strerror(errno)); - RETVALUE(RFAILED); + DU_LOG("\nSCTP : Connection in progess"); + break; } else { - /* Mark SCTP connection UP */ connUp = TRUE; + DU_LOG("\nSCTP : Connect successful"); + break; } - } + }while(numRetry < MAX_RETRY); RETVALUE(ROK); }/* End of sctpConnect() */ /******************************************************************* * - * @brief Handles an incoming message + * @brief Post received data/notification to DU APP * * @details * - * Function : sctpInmsgHdlr + * Function : sendToDuApp * * Functionality: - * Handles an incoming message + * Post received data/notification to DU APP * - * @params[in] Socket file descriptor - * Incoming message header - * Message Length + * @params[in] Message buffer + * Message event * * @return ROK - success * RFAILED - failure * * ****************************************************************/ -S16 sctpInmsgHdlr(struct msghdr *msg, size_t msgLen) +void sendToDuApp(Buffer *mBuf, Event event) { - sctp_cmsg_data_t *data; - struct cmsghdr *cmsg; - union sctp_notification *sn; - Buffer *mBuf; - Pst *pst; - - for (cmsg = CMSG_FIRSTHDR(msg); cmsg != NULL; cmsg = CMSG_NXTHDR(msg, cmsg)) + Pst pst; + DU_LOG("\nSCTP : Forwarding received message to duApp"); + SPrntMsg(mBuf, 0, 0); + + + cmMemset((U8 *)&(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; + pst.selector = DU_SELECTOR_LC; + pst.pool= DU_POOL; + pst.region = DFLT_REGION; + + if (SPstTsk(&pst, mBuf) != ROK) { - data = (sctp_cmsg_data_t *)CMSG_DATA(cmsg); + DU_LOG("\nSCTP : SPstTsk failed in duReadCfg"); } +} - printf("\nReceived Message"); +/******************************************************************* + * + * @brief Handles an SCTP notification message + * + * @Sending * + * Function : sctpNtfyHdlr + * + * Functionality: + * Handles an SCTP notification message + * + * @params[in] Notify message + * + * @return ROK - success + * RFAILED - failure + * + * ****************************************************************/ +S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy) +{ + Pst pst; - /* if incoming message is data */ - if (!(MSG_NOTIFICATION & msg->msg_flags)) + switch(ntfy->header.nType) { - /* Extract message */ - U8 index = 0; - char *recvBuf; - char *temp = recvBuf; - U8 len = msgLen; - U8 temp_len; - U8 i; - - while( msgLen > 0) - { - temp = msg->msg_iov[index].iov_base; - temp_len = msg->msg_iov[index].iov_len; - - if(temp_len > msgLen) - { - temp[(temp_len = msgLen) - 1] = '\0'; - } - - if((msgLen -= temp_len) > 0) - { - index++; - } - for (i = 0; i < temp_len-1 ; ++i) + case CM_INET_SCTP_ASSOC_CHANGE : + DU_LOG("\nSCTP : Assoc change notification received"); + switch(ntfy->u.assocChange.state) { - if (!isprint(temp[i])) - temp[i] = '.'; - } - printf("\nPrinting temp %s", temp); - temp = temp + temp_len; - index++; - } - recvBuf[len - 1] = '\0'; - printf("\n Message: %s temp %s", recvBuf, temp); - - /* Post received message to du_App */ - if(SGetMsg(0, 0, &mBuf) == ROK ) - { - if(SAddPstMsgMult((Data *)recvBuf, len, mBuf) == ROK) - { - pst->dstProcId; - pst->srcProcId; - pst->dstEnt = ENTDUAPP; - pst->dstInst = 0; - pst->srcEnt = ENTSCTP; - pst->srcInst = 0; - pst->prior; - pst->route; - pst->event = EVTSCTPUP; - pst->region = 0; - pst->pool = 0; - pst->selector = 0; - pst->intfVer; - - SPstTsk(pst, mBuf); + case CM_INET_SCTP_COMM_UP: + DU_LOG("Event : COMMUNICATION UP"); + connUp = TRUE; + break; + case CM_INET_SCTP_COMM_LOST: + DU_LOG("Event : COMMUNICATION LOST"); + connUp = FALSE; + break; + case CM_INET_SCTP_RESTART: + DU_LOG("Event : SCTP RESTART"); + connUp = FALSE; + break; + case CM_INET_SCTP_SHUTDOWN_COMP: /* association gracefully shutdown */ + DU_LOG("Event : SHUTDOWN COMPLETE"); + connUp = FALSE; + break; + case CM_INET_SCTP_CANT_STR_ASSOC: + DU_LOG("Event : CANT START ASSOC"); + connUp = FALSE; + break; + default: + DU_LOG("\nInvalid event"); + break; } - } - - + break; + case CM_INET_SCTP_PEER_ADDR_CHANGE : + DU_LOG("\nSCTP : Peer Address Change notificarion received"); + /* Need to add handler */ + break; + case CM_INET_SCTP_REMOTE_ERROR : + DU_LOG("\nSCTP : Remote Error notification received"); + break; + case CM_INET_SCTP_SEND_FAILED : + DU_LOG("\nSCTP : Send Failed notification received\n"); + break; + case CM_INET_SCTP_SHUTDOWN_EVENT : /* peer socket gracefully closed */ + DU_LOG("\nSCTP : Shutdown Event notification received\n"); + connUp = FALSE; + break; + case CM_INET_SCTP_ADAPTATION_INDICATION : + DU_LOG("\nSCTP : Adaptation Indication received\n"); + break; + case CM_INET_SCTP_PARTIAL_DELIVERY_EVENT: + DU_LOG("\nSCTP : Partial Delivery Event received\n"); + break; + default: + DU_LOG("\nSCTP : Invalid sctp notification type\n"); + break; } - else /* If the incoming message is notification */ - { - /* Extract and perform necessary action - Change the connUp state accordingly */ - union sctp_notification *notify; - notify = (union sctp_notification *)msg->msg_iov->iov_base; - - if (SCTP_ASSOC_CHANGE != notify->sn_header.sn_type) - { - printf("\nReceived unexpected notification: %d", notify->sn_header.sn_type); - RETVALUE(RFAILED); - } - switch(notify->sn_assoc_change.sac_state) - { - case SCTP_COMM_UP: - printf("Received SCTP_COMM_UP\n"); - break; - case SCTP_COMM_LOST: - printf("Received SCTP_COMM_LOST\n"); - break; - case SCTP_RESTART: - printf("Received SCTP_RESTART\n"); - break; - case SCTP_SHUTDOWN_COMP: - printf("Received SCTP_SHUTDOWN_COMP\n"); - break; - case SCTP_CANT_STR_ASSOC: - printf("Received SCTP_CANT_STR_ASSOC\n"); - break; - } + /* Pack notification and send to APP */ + DU_LOG("\nSCTP : Forwarding received message to duApp"); + + cmMemset((U8 *)&(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.pool= DU_POOL; + pst.region = DFLT_REGION; + + if(cmPkSctpNtfy(&pst, ntfy) != ROK) + { + DU_LOG("\nSCTP : Failed to pack SCTP notification"); + RETVALUE(RFAILED); } RETVALUE(ROK); } @@ -444,64 +489,70 @@ S16 sctpInmsgHdlr(struct msghdr *msg, size_t msgLen) * ****************************************************************/ S16 sctpSockPoll() { - U8 error; - struct msghdr inmessage; - struct iovec iov; - char incmsg[CMSG_SPACE(sizeof(_sctp_cmsg_data_t))]; - sockaddr_storage_t msgname; - - /* Initialize inmessage with enough space for DATA... */ - memset(&inmessage, 0, sizeof(inmessage)); - if ((iov.iov_base = malloc(REALLY_BIG)) == NULL) + 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) { - printf("\n malloc not enough memory!!!"); - close(sockFd); - connUp = FALSE; - RETVALUE(RFAILED); + /* blocking */ + timeoutPtr = NULLP; } - iov.iov_len = REALLY_BIG; - inmessage.msg_iov = &iov; - inmessage.msg_iovlen = 1; - /* or a control message. */ - inmessage.msg_control = incmsg; - inmessage.msg_controllen = sizeof(incmsg); - inmessage.msg_name = &msgname; - inmessage.msg_namelen = sizeof(msgname); - - while (connUp) + else { - error = recvmsg(sockFd, &inmessage, MSG_WAITALL); - if (error < 0) + /* non-blocking */ + timeout = 0; + timeoutPtr = &timeout; + } + memInfo.region = DU_APP_MEM_REGION; + memInfo.pool = DU_POOL; + CM_INET_FD_ZERO(&readFd); + + while(1) + { + CM_INET_FD_SET(&sockFd, &readFd); + ret = cmInetSelect(&readFd, NULLP, timeoutPtr, &numFds); + if (CM_INET_FD_ISSET(&sockFd, &readFd)) { - if (nonblocking && (EAGAIN == errno)) + CM_INET_FD_CLR(&sockFd, &readFd); + ret = cmInetSctpRecvMsg(&sockFd, &addr, &port, &memInfo, &mBuf, &bufLen, &info, &flag, &ntfy); + if (connUp && ret != ROK) { - error = 0; - continue; + DU_LOG("\nFailed to receive sctp msg\n"); } - if (socket_type == SOCK_STREAM) + else { - if (ENOTCONN != errno) + /* If SCTP notification received */ + if ((flag & CM_INET_SCTP_MSG_NOTIFICATION) != 0) { - break; + ret = sctpNtfyHdlr(&ntfy); + if(ret != ROK) + { + DU_LOG("\nSCTP : Failed to process sctp notify msg\n"); + } + } + else if(connUp) /* If data received */ + { + sendToDuApp(mBuf, EVTSCTPDATA); } - printf("No association is present now!!\n"); - close(sockFd); - sockFd = 0; - connUp = FALSE; - } - break; + else + { + SPutMsg(mBuf); + } + } } - - sctpInmsgHdlr(&inmessage, error); + }; - inmessage.msg_control = incmsg; - inmessage.msg_controllen = sizeof(incmsg); - inmessage.msg_name = &msgname; - inmessage.msg_namelen = sizeof(msgname); - iov.iov_len = REALLY_BIG; - - }/* End of while(connUp) */ - RETVALUE(ROK); }/* End of sctpSockPoll() */ @@ -511,7 +562,7 @@ S16 sctpSockPoll() * * @details * - * Function : sctpOutMsgSend + * Function : sctpSend * * Functionality: * Send message on SCTP socket @@ -521,50 +572,38 @@ S16 sctpSockPoll() * RFAILED - failure * * ****************************************************************/ -S16 sctpOutMsgSend(char *message, U8 msglen) +S16 sctpSend(Buffer *mBuf) { - struct msghdr outmsg; - struct iovec iov; - int error = 0; - - do{ - if(connUp && msglen != 0) - { - iov.iov_base = message; - iov.iov_len = msglen; + U8 ret; + MsgLen len; /* number of actually sent octets */ + CmInetNetAddr peerAddr; /* destination port address */ + CmInetNetAddr *dstAddr; + CmInetMemInfo memInfo; - outmsg.msg_iov = &iov; - outmsg.msg_iovlen = 1; - outmsg.msg_control = NULL; - outmsg.msg_controllen = 0; - outmsg.msg_name = &remote_addr; - outmsg.msg_namelen = ra_len; - outmsg.msg_flags = 0; - - error = sendmsg(sockFd, &outmsg, 0); - } - - if(error != msglen) - { - if(nonblocking && EAGAIN == errno) - { - continue; - } - else - { - printf("\n Error [%s] while sending message on SCTP assoc", strerror(errno)); - RETVALUE(RFAILED); - } - } - else - { - break; - } - }while(error != msglen); + memInfo.region = DU_APP_MEM_REGION; + memInfo.pool = DU_POOL; - RETVALUE(ROK); -} /* End of sctpOutMsgSend */ + if(sctpCfg.cuIpAddr.ipV4Pres) + { + peerAddr.type = CM_INET_IPV4ADDR_TYPE; + peerAddr.u.ipv4NetAddr = CM_INET_NTOH_U32(sctpCfg.cuIpAddr.ipV4Addr); + dstAddr = &peerAddr; + } + else + { + dstAddr = NULLP; + } + + ret = cmInetSctpSendMsg(&sockFd, dstAddr, sctpCfg.cuPort, &memInfo, mBuf, &len, 0, FALSE, 0, 0/*SCT_PROTID_NONE*/, RWOULDBLOCK); + if(ret != ROK && ret != RWOULDBLOCK) + { + DU_LOG("\nSCTP : Failed sending the message"); + RETVALUE(RFAILED); + } + + RETVALUE(ROK); +} /* End of sctpSend */ /******************************************************************* * @@ -583,37 +622,27 @@ S16 sctpOutMsgSend(char *message, U8 msglen) * RFAILED - failure * * ****************************************************************/ - void sctpAssocReq() -{ - /* Open SCTP socket and bind to local address */ +{ if(openSctpEndp() != ROK) { - printf("\nFailed while opening SCTP endpoint"); - if(sockFd > 0 ) - { - close(sockFd); - sockFd = 0; - } - /* TODO : Send Assoc establishment failure to du_app if needed*/ + DU_LOG("\nSCTP : Failed while opening socket"); } - else if(sctpConnect() != ROK) /* send connection request */ + else if(bindSctpEndp() != ROK) { - printf("\nFailed while connecting to peer"); - close(sockFd); - sockFd = 0; - assocId = 0; - nonblocking = FALSE; - /* TODO : Send Assoc establishment failure to du_app */ + DU_LOG("\nSCTP : Failed while binding socket"); } - else + else if(sctpSetSockOpts() != ROK) { - /* Send AssocCfm to du_app */ - if(sctpSockPoll() != ROK) - { - printf("\nFailed while polling"); - /* Send failure to du_app */ - } + DU_LOG("\nSCTP : Failed while setting socket options"); + } + else if(sctpConnect() != ROK) + { + DU_LOG("\nSCTP : Failed while connecting to peer"); + } + else if(sctpSockPoll() != ROK) + { + DU_LOG("\nSCTP : Failed while polling"); } } /* End of sctpAssocReq */