Moving all common header file into common_def.h file
[o-du/l2.git] / src / du_app / du_sctp.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /* This file contains all SCTP related functionality */
20 #include "common_def.h"
21 #include "lrg.h"
22 #include "legtp.h"
23 #include "lrg.x"
24 #include "lkw.x"
25 #include "du_cfg.h"
26 #include "du_sctp.h"
27 #include "lsctp.h"
28
29
30 /**************************************************************************
31  * @brief Task Initiation callback function. 
32  *
33  * @details
34  *
35  *     Function : sctpActvInit 
36  *    
37  *     Functionality:
38  *             This function is supplied as one of parameters during SCTP's 
39  *             task registration. SSI will invoke this function once, after
40  *             it creates and attaches this TAPA Task to a system task.
41  *     
42  * @param[in]  Ent entity, the entity ID of this task.     
43  * @param[in]  Inst inst, the instance ID of this task.
44  * @param[in]  Region region, the region ID registered for memory 
45  *              usage of this task.
46  * @param[in]  Reason reason.
47  * @return ROK     - success
48  *         RFAILED - failure
49  ***************************************************************************/
50 S16 sctpActvInit(Ent entity, Inst inst, Region region, Reason reason)
51 {
52    DU_LOG("\n\nSCTP : Initializing");
53    SSetProcId(DU_PROC);
54    connUp = FALSE;
55    f1Params.assocId = -1;
56    ricParams.assocId = -1;
57    nonblocking = FALSE;
58    return ROK;
59
60 }
61
62 /**************************************************************************
63  * @brief Task Activation callback function. 
64  *
65  * @details
66  *
67  *      Function : sctpActvTsk 
68  * 
69  *      Functionality:
70  *           This function handles all SCTP messages received
71  *           This API is registered with SSI during the 
72  *           Task Registration of DU APP.
73  *     
74  * @param[in]  Pst     *pst, Post structure of the primitive.     
75  * @param[in]  Buffer *mBuf, Packed primitive parameters in the
76  *  buffer.
77  * @return ROK     - success
78  *         RFAILED - failure
79  *
80  ***************************************************************************/
81 S16 sctpActvTsk(Pst *pst, Buffer *mBuf)
82 {
83    switch(pst->srcEnt)
84    {
85       case ENTDUAPP:
86          {
87             switch(pst->event)
88             {
89                case EVTSTARTPOLL:
90                {
91                   sctpSockPoll();
92                   break;
93                } 
94             }
95             break;
96          }
97    }
98    SExitTsk();
99    return ROK;
100 }
101 /*******************************************************************
102  *
103  * @brief Checks the status of the received information
104  *
105  * @details
106  *
107  *    Function : duCheckReqStatus
108  *
109  *    Functionality:
110  *       Checks the status of the received information
111  *
112  * @params[in] Confirm status
113  * @return ROK     - success
114  *         RFAILED - failure
115  *
116  ******************************************************************/
117 S16 duCheckReqStatus(CmStatus *cfm)
118 {
119    S16 ret = ROK;
120    if(cfm->status != LCM_PRIM_OK)
121    {
122       DU_LOG("\nDU_APP : Failed to process the request successfully");
123       ret = RFAILED;
124    }
125    RETVALUE(ret); 
126 }
127
128 /**************************************************************************
129  * @brief Function to configure the Sctp Params during config Request
130  *
131  * @details
132  *
133  *      Function : duSctpCfgReq
134  * 
135  *      Functionality:
136  *           This function configures SCTP Params during the config Request
137  *     
138  * @param[in]  SctpParams sctpCfg, common structure which has all the configuration
139  * @param[in]  CmStatus cfm, Builds the cfm status and reason
140  *  buffer.
141  *
142  * @return ROK     - success
143  *         RFAILED - failure
144  *
145  ***************************************************************************/
146
147 S16 duSctpCfgReq(SctpParams sctpCfg)
148 {
149    S16 ret = ROK;
150         CmStatus cfm;
151
152 /* Fill F1 Params */
153    f1Params.destIpAddr.ipV4Pres  = sctpCfg.cuIpAddr.ipV4Pres;
154    f1Params.destIpAddr.ipV4Addr  = sctpCfg.cuIpAddr.ipV4Addr;
155    f1Params.destPort             = sctpCfg.cuPort;
156    f1Params.itfState             = DU_SCTP_DOWN;
157    f1Params.srcPort              = sctpCfg.duPort[F1_INTERFACE];
158    f1Params.recvMsgSet           = ROK;
159    cmMemset ((U8 *)&f1Params.sockFd, -1, sizeof(CmInetFd));
160    fillDestNetAddr(&f1Params.destIpNetAddr, &f1Params.destIpAddr);
161    fillAddrLst(&f1Params.destAddrLst, &f1Params.destIpAddr);
162
163 /* Fill RIC Params */
164    ricParams.destIpAddr.ipV4Pres = sctpCfg.ricIpAddr.ipV4Pres;
165    ricParams.destIpAddr.ipV4Addr = sctpCfg.ricIpAddr.ipV4Addr;
166    ricParams.destPort            = sctpCfg.ricPort;
167    ricParams.itfState            = DU_SCTP_DOWN;
168    ricParams.srcPort             = sctpCfg.duPort[E2_INTERFACE];
169    ricParams.recvMsgSet          = ROK;
170    cmMemset ((U8 *)&ricParams.sockFd, -1, sizeof(CmInetFd));
171    fillDestNetAddr(&ricParams.destIpNetAddr, &ricParams.destIpAddr);
172    fillAddrLst(&ricParams.destAddrLst, &ricParams.destIpAddr);
173
174 /* Fill AddressList */
175    fillAddrLst(&localAddrLst, &sctpCfg.duIpAddr);
176
177 /* Set polling to FALSE */
178    pollingState = FALSE;  
179
180 /* Fill Cfm Status */
181    cfm.status = LCM_PRIM_OK;
182    cfm.reason = LCM_REASON_NOT_APPL;
183
184    ret = duCheckReqStatus(&cfm);
185
186    RETVALUE(ret);
187 }
188
189 /*******************************************************************
190  *
191  * @brief Fills the address List of the source Ip Address
192  *
193  * @details
194  *
195  *    Function : fillAddrLst
196  *
197  *    Functionality:
198  *       Fills the address List of source Ip Address
199  *
200  * @params[in] CmInetNetAddrLst *addrLstPtr, Address List pointer
201  * @params[in] F1IpAddr *srcIpAddr, src Ip Adrress to be filled in the Address List
202  *
203  * @return ROK     - success
204  *         RFAILED - failure
205  *
206  ******************************************************************/
207
208 S16 fillAddrLst(CmInetNetAddrLst *addrLstPtr, F1IpAddr *ipAddr)
209
210    addrLstPtr->count++;
211    addrLstPtr->addrs[(addrLstPtr->count - 1)].type = CM_INET_IPV4ADDR_TYPE;
212    addrLstPtr->addrs[(addrLstPtr->count - 1)].u.ipv4NetAddr = CM_INET_NTOH_U32(ipAddr->ipV4Addr);
213
214    RETVALUE(ROK);
215 }
216
217 /******************************************************************************
218  *
219  * @brief Fills the address List of the source Ip Address
220  *
221  * @details
222  *
223  *    Function : fillDestNetAddr
224  *
225  *    Functionality:
226  *       Fills the address List of destinatoion Ip Address
227  *
228  * @params[in] CmInetNetAddr *destAddrPtr, Address List pointer
229  * @params[in] F1IpAddr *dstIpAddr, destIp Address to be filled in the Address List
230  *
231  * @return ROK     - success
232  *         RFAILED - failure
233  *
234  *******************************************************************************/
235 S16 fillDestNetAddr(CmInetNetAddr *destAddrPtr, F1IpAddr *dstIpPtr)
236 {
237    /* Filling destination address */
238    destAddrPtr->type = CM_INET_IPV4ADDR_TYPE;
239    destAddrPtr->u.ipv4NetAddr = CM_INET_NTOH_U32(dstIpPtr->ipV4Addr);
240    RETVALUE(ROK);
241 }
242
243 /******************************************************************************
244  *
245  * @brief Establishes the Assoc Req for the received interface type
246  *
247  * @details
248  *
249  *    Function : establishAssocReq
250  *
251  *    Functionality:
252  *       Eastablishes the Assoc Req for the received interface type
253  *
254  * @params[in] DuSctpDestCb *paramPtr
255  *
256  * @return ROK     - success
257  *         RFAILED - failure
258  *
259  *******************************************************************************/
260
261 S16 establishReq(DuSctpDestCb *paramPtr)
262 {
263    Pst pst;
264    S16 ret = ROK;
265    socket_type = CM_INET_STREAM;
266
267    if((ret = cmInetSocket(socket_type, &paramPtr->sockFd, IPPROTO_SCTP)) != ROK)
268    {
269       DU_LOG("\nSCTP : Failed while opening a socket in ODU");
270    } 
271    else if((ret = cmInetSctpBindx(&paramPtr->sockFd, &localAddrLst, paramPtr->srcPort)) != ROK)
272    {
273       DU_LOG("\nSCTP:  Failed during Binding in ODU");
274    }
275    else if((ret = sctpSetSockOpts(&paramPtr->sockFd)) != ROK)
276    {
277       DU_LOG("\nSCTP : Failed to set Socket Opt in ODU");
278    }     
279    else
280    { 
281       if(ret != ROK)
282       {
283          DU_LOG("\nSCTP : Failed while establishing Req at DU");
284          ret = RFAILED;
285       }
286       else 
287       {
288          ret = cmInetSctpConnectx(&paramPtr->sockFd, &paramPtr->destIpNetAddr, &paramPtr->destAddrLst, paramPtr->destPort);
289          /* 115 error_code indicates that Operation is in progress and hence ignored if SctpConnect failed due to this */
290          if(ret == 18)             
291          {
292            ret = ROK; 
293          }
294       }
295    }
296    if((ret == ROK) & (paramPtr->itfState == DU_SCTP_DOWN))
297    {
298       paramPtr->itfState = DU_SCTP_CONNECTING;
299    }
300
301    /* Post the EVTSTARTPOLL Msg */
302    if(!pollingState)
303    {
304       pollingState = TRUE;
305       duFillSctpPst(&pst, EVTSTARTPOLL);
306    }
307    
308    RETVALUE(ret);
309 }
310
311 /******************************************************************************
312  *
313  * @brief Processes the assoc Req for the received interface type
314  *
315  * @details
316  *
317  *    Function : duSctpAssocReq
318  *
319  *    Functionality:
320  *       Processes the Assoc Req for the received interface type
321  *
322  * @params[in] itfType interface Type, 
323  * @params[in] cfm , represents the status of request
324  * 
325  * @return ROK     - success
326  *         RFAILED - failure
327  *
328  *******************************************************************************/
329
330 S16 duSctpAssocReq(U8 itfType)
331 {
332    S16 ret = ROK;
333         CmStatus cfm;
334    DuSctpDestCb *paramPtr = NULLP;
335
336    if(SGetSBuf(DU_APP_MEM_REGION, DU_POOL, (Data **)&paramPtr, (Size)sizeof(DuSctpDestCb)) != ROK)
337    {
338       printf("\nDU_APP : Failed to allocate memory");
339       RETVALUE(RFAILED);
340    }
341    switch(itfType)
342    {
343       case F1_INTERFACE:
344       {
345          paramPtr = &f1Params;
346          ret = establishReq(paramPtr);
347          break;
348       }
349       case E2_INTERFACE:
350       {
351          paramPtr = &ricParams;
352          ret = establishReq(paramPtr);
353          break;
354       }
355       default:
356       {
357          DU_LOG("\nSCTP : Invalid Interface Type");
358          break;
359       }
360    }  
361    if(ret != ROK)
362    { 
363       DU_LOG("\nSCTP : ASSOC Req Failed.");
364       cfm.status = LCM_PRIM_NOK;
365       cfm.reason = LCM_REASON_NOT_APPL;
366    }
367    else
368    {
369       cfm.status = LCM_PRIM_OK;
370       cfm.reason = LCM_REASON_NOT_APPL;
371    }
372    ret = duCheckReqStatus(&cfm);
373
374    RETVALUE(ret);
375 }
376 /*******************************************************************
377  *
378  * @brief  Fills Pst struct for ENTSCTP
379  *
380  * @details
381  *
382  *    Function : duFillSctpPst
383  *
384  *    Functionality:
385  *       Fills Pst struct for ENTSCTP
386  *
387  * @params[in] 
388  * @return ROK     - success
389  *         RFAILED - failure
390  *
391  * ****************************************************************/
392 S16 duFillSctpPst(Pst *pst, Event event)
393 {
394    Buffer *mBuf;
395    if(SGetMsg(DFLT_REGION, DU_POOL, &mBuf) != ROK)
396    {
397       printf("\nDU_APP : Failed to allocate memory");
398       RETVALUE(RFAILED);
399    }
400    cmMemset((U8 *)pst, 0, sizeof(Pst));
401    pst->srcEnt = (Ent)ENTDUAPP;
402    pst->srcInst = (Inst)DU_INST;
403    pst->srcProcId = DU_PROC;
404    pst->dstEnt = (Ent)ENTSCTP;
405    pst->dstInst = (Inst)SCTP_INST;
406    pst->dstProcId = pst->srcProcId;
407    pst->event = event;
408    pst->selector = ODU_SELECTOR_LC;
409    pst->pool= DU_POOL;
410    SPstTsk(pst, mBuf); 
411
412    RETVALUE(ROK);
413 }
414
415 /*******************************************************************
416  *
417  * @brief Sets socket options as per requirement
418  *
419  * @details
420  *
421  *    Function : sctpSetSockOpts
422  *
423  *    Functionality: 
424  *       Sets socket options as per requirement
425  *
426  * @params[in] sock_Fd  determines the sockFd to be set
427  * @return ROK     - success
428  *         RFAILED - failure
429  *
430  * ****************************************************************/
431 S16 sctpSetSockOpts(CmInetFd *sock_Fd)
432 {
433     S16 ret = ROK;
434     CmSctpEvent sctpEvent;
435
436    sctpEvent.dataIoEvent          = TRUE;
437    sctpEvent.associationEvent     = TRUE;
438    sctpEvent.addressEvent         = TRUE;
439    sctpEvent.sendFailureEvent     = TRUE;
440    sctpEvent.peerErrorEvent       = TRUE;
441    sctpEvent.shutdownEvent        = TRUE;
442    sctpEvent.partialDeliveryEvent = TRUE;
443    sctpEvent.adaptationLayerEvent = TRUE;
444
445    if((ret = cmInetSetOpt(sock_Fd, CM_SOCKOPT_LEVEL_SCTP, CM_SOCKOPT_OPT_SCTP_EVENTS, &sctpEvent) != ROK))
446    {
447      ret = RFAILED;
448    }
449
450    RETVALUE(ret);
451 }
452
453 /*******************************************************************
454  *
455  * @brief Post received data/notification to DU APP 
456  *
457  * @details
458  *
459  *    Function : sendToDuApp 
460  *
461  *    Functionality:
462  *         Post received data/notification to DU APP
463  *
464  * @params[in]  Message buffer
465  *              Message event
466  *
467  * @return ROK     - success
468  *         RFAILED - failure
469  *
470  * ****************************************************************/
471 void sendToDuApp(Buffer *mBuf, Event event)
472 {
473    Pst pst;
474    DU_LOG("\nSCTP : Forwarding received message to duApp");
475    SPrntMsg(mBuf, 0, 0);
476
477
478    cmMemset((U8 *)&(pst), 0, sizeof(Pst));
479    pst.srcEnt = (Ent)ENTSCTP;
480    pst.srcInst = (Inst)SCTP_INST;
481    pst.srcProcId = DU_PROC;
482    pst.dstEnt = (Ent)ENTDUAPP;
483    pst.dstInst = (Inst)DU_INST;
484    pst.dstProcId = pst.srcProcId;
485    pst.event = event;
486    pst.selector = ODU_SELECTOR_LC;
487    pst.pool= DU_POOL;
488    pst.region = DFLT_REGION;
489
490    if (SPstTsk(&pst, mBuf) != ROK)
491    {
492       DU_LOG("\nSCTP : SPstTsk failed in duReadCfg");
493    }
494 }
495
496 /*******************************************************************
497  *
498  * @brief Handles an SCTP notification message
499  *
500  * @Sending *
501  *    Function : sctpNtfyHdlr
502  *
503  *    Functionality:
504  *      Handles an SCTP notification message
505  *
506  * @params[in] Notify message
507  *
508  * @return ROK     - success
509  *         RFAILED - failure
510  *
511  * ****************************************************************/
512 S16 sctpNtfyHdlr(CmInetSctpNotification *ntfy, U8 *itfState)
513 {
514    Pst pst;
515
516    switch(ntfy->header.nType)
517    {
518       case CM_INET_SCTP_ASSOC_CHANGE :
519          DU_LOG("\nSCTP : Assoc change notification received");
520          switch(ntfy->u.assocChange.state)
521          {
522             case CM_INET_SCTP_COMM_UP:
523                DU_LOG("Event : COMMUNICATION UP");
524                *itfState = DU_SCTP_UP;
525                break;
526             case CM_INET_SCTP_COMM_LOST:
527                DU_LOG("Event : COMMUNICATION LOST");
528                *itfState = DU_SCTP_DOWN;
529                break;
530             case CM_INET_SCTP_RESTART:
531                DU_LOG("Event : SCTP RESTART");
532                *itfState = DU_SCTP_DOWN;
533                break;
534             case CM_INET_SCTP_SHUTDOWN_COMP: /* association gracefully shutdown */
535                DU_LOG("Event : SHUTDOWN COMPLETE");
536                *itfState = DU_SCTP_DOWN;
537                break;
538             case CM_INET_SCTP_CANT_STR_ASSOC:
539                DU_LOG("Event : CANT START ASSOC");
540                *itfState = DU_SCTP_DOWN;
541                break;
542             default:
543                DU_LOG("\nInvalid event");
544                break;
545          }
546          break;
547       case CM_INET_SCTP_PEER_ADDR_CHANGE :
548          DU_LOG("\nSCTP : Peer Address Change notificarion received");
549          /* Need to add handler */
550          break;
551       case CM_INET_SCTP_REMOTE_ERROR :
552          DU_LOG("\nSCTP : Remote Error notification received");
553          break;
554       case CM_INET_SCTP_SEND_FAILED :
555          DU_LOG("\nSCTP : Send Failed notification received\n");
556          break;
557       case CM_INET_SCTP_SHUTDOWN_EVENT : /* peer socket gracefully closed */
558          DU_LOG("\nSCTP : Shutdown Event notification received\n");
559          *itfState = DU_SCTP_DOWN;
560          exit(0);
561          break;
562       case CM_INET_SCTP_ADAPTATION_INDICATION :
563          DU_LOG("\nSCTP : Adaptation Indication received\n");
564          break;
565       case CM_INET_SCTP_PARTIAL_DELIVERY_EVENT:
566          DU_LOG("\nSCTP : Partial Delivery Event received\n");
567          break;
568       default:
569          DU_LOG("\nSCTP : Invalid sctp notification type\n");
570          break;
571    }
572
573    /* Pack notification and send to APP */
574    DU_LOG("\nSCTP : Forwarding received message to duApp");
575     
576    cmMemset((U8 *)&(pst), 0, sizeof(Pst));
577    pst.srcEnt = (Ent)ENTSCTP;
578    pst.srcInst = (Inst)SCTP_INST;
579    pst.srcProcId = DU_PROC;
580    pst.dstEnt = (Ent)ENTDUAPP;
581    pst.dstInst = (Inst)DU_INST;
582    pst.dstProcId = pst.srcProcId;
583    pst.event = EVENT_SCTP_NTFY;
584    pst.selector = ODU_SELECTOR_LC;
585    pst.pool= DU_POOL;
586    pst.region = DFLT_REGION;
587    
588    if(cmPkSctpNtfy(&pst, ntfy) != ROK)
589    {
590       DU_LOG("\nSCTP : Failed to pack SCTP notification");
591       RETVALUE(RFAILED);
592    }
593    RETVALUE(ROK);
594 }
595
596 /*******************************************************************
597  *
598  * @brief checks for valid readFd and process the InetSctpRecvMsg
599  * during polling 
600  *
601  * @details
602  *
603  *    Function : processPolling
604  *
605  *    Functionality:
606  *         checks for valid readFd and process the InetSctpRecvMsg
607  *         during polling
608  *
609  * @params[in]  Params required for polling
610  * @params[in]  SockFd for file descriptor
611  * @params[in]  timeoutPtr indicates the timeout value
612  * @params[in]  MemInfo, recvMsgSet
613  *
614  * @return ROK     - success
615  *         RFAILED - failure
616  *
617  * ****************************************************************/
618
619 S16 processPolling(sctpSockPollParams *pollParams, CmInetFd *sockFd, U32 *timeoutPtr, CmInetMemInfo *memInfo, Bool recvMsgSet)
620 {
621    U16 ret = ROK;
622    CM_INET_FD_SET(sockFd, &pollParams->readFd);
623    ret = cmInetSelect(&pollParams->readFd, NULLP, timeoutPtr, &pollParams->numFd);
624    if(CM_INET_FD_ISSET(sockFd, &pollParams->readFd))
625    {
626       CM_INET_FD_CLR(sockFd, &pollParams->readFd);
627       ret = cmInetSctpRecvMsg(sockFd, &pollParams->addr, &pollParams->port, memInfo, &(pollParams->mBuf), &pollParams->bufLen, &pollParams->info, &pollParams->flag, &pollParams->ntfy);
628         
629       if(ret != ROK)
630       {
631          DU_LOG("\n SCTP: Failed to receive sctp msg for sockFd[%d]\n", sockFd->fd);
632          recvMsgSet = RFAILED;
633       }
634       else
635       {
636          if((((pollParams->flag & CM_INET_SCTP_MSG_NOTIFICATION) != 0)) && ret == ROK)
637          {
638             if(pollParams->port == f1Params.destPort)
639             {
640                f1Params.assocId = pollParams->ntfy.u.assocChange.assocId;
641                DU_LOG("\nSCTP : AssocId assigned to F1Params from PollParams [%d]\n", f1Params.assocId);
642                ret = sctpNtfyHdlr(&pollParams->ntfy, &f1Params.itfState);
643             }
644             else if(pollParams->port == ricParams.destPort)
645             {
646                ricParams.assocId = pollParams->ntfy.u.assocChange.assocId;
647                DU_LOG("\nSCTP : AssocId assigned to ricParams from PollParams [%d]\n", ricParams.assocId);
648                ret = sctpNtfyHdlr(&pollParams->ntfy, &ricParams.itfState);
649             }
650             else
651             {
652                DU_LOG("\nSCTP : Failed to fill AssocId\n");
653                RETVALUE(RFAILED);
654             }
655             if(ret != ROK)
656             {
657                DU_LOG("\nSCTP : Failed to process sctp notify msg\n");
658             }
659          }
660          else if(f1Params.itfState & (pollParams->port == f1Params.destPort))
661          {  
662             sendToDuApp(pollParams->mBuf, EVENT_CU_DATA);
663          }
664          else if(ricParams.itfState & (pollParams->port == ricParams.destPort))
665          {  
666             sendToDuApp(pollParams->mBuf, EVENT_RIC_DATA);
667          }
668
669          else
670          {
671             SPutMsg(pollParams->mBuf);
672          }
673       }
674   }
675   RETVALUE(ROK);
676 }
677 /*******************************************************************
678  *
679  * @brief Receives message on the socket
680  *
681  * @details
682  *
683  *    Function : sctpSockPoll
684  *
685  *    Functionality:
686  *      Receives message on the socket
687  *
688  * @params[in] 
689  * @return ROK     - success
690  *         RFAILED - failure
691  *
692  * ****************************************************************/
693 S16 sctpSockPoll()
694 {
695    U16 ret       = ROK;
696    U32           timeout;
697    U32           *timeout_Ptr;
698    CmInetMemInfo memInfo;
699    sctpSockPollParams f1PollParams, e2PollParams;
700
701    memset(&f1PollParams, 0, sizeof(sctpSockPollParams));
702    memset(&e2PollParams, 0, sizeof(sctpSockPollParams));
703
704    if (f1Params.sockFd.blocking & ricParams.sockFd.blocking)
705    {
706       /* blocking */
707       timeout_Ptr = NULLP;
708    }
709    else
710    {
711       /* non-blocking */
712       timeout = 0;
713       timeout_Ptr = &timeout;
714    }
715    memInfo.region = DU_APP_MEM_REGION;
716    memInfo.pool   = DU_POOL;
717
718    CM_INET_FD_ZERO(&f1PollParams.readFd);
719    CM_INET_FD_ZERO(&e2PollParams.readFd);
720
721    DU_LOG("\nSCTP : Polling started at DU\n");
722    while(1)
723    {
724       if(f1Params.itfState)
725       {
726          if((ret = processPolling(&f1PollParams, &f1Params.sockFd, timeout_Ptr, &memInfo, f1Params.recvMsgSet)) != ROK)
727          {
728             DU_LOG("\nSCTP : Failed to RecvMsg for F1\n");
729          }
730       }
731       if(ricParams.itfState)
732       {
733          if((ret = processPolling(&e2PollParams, &ricParams.sockFd, timeout_Ptr, &memInfo, ricParams.recvMsgSet)) != ROK)
734          {
735             DU_LOG("\nSCTP : Failed to RecvMsg for E2\n");
736          }
737       }
738    };
739    RETVALUE(ret);
740 }/* End of sctpSockPoll() */
741
742 /*******************************************************************
743  *
744  * @brief Send message on SCTP socket
745  *
746  * @details
747  *
748  *    Function : sctpSend 
749  *
750  *    Functionality:
751  *        Send message on SCTP socket
752  *
753  * @params[in] 
754  * @return ROK     - success
755  *         RFAILED - failure
756  *
757  * ****************************************************************/
758 S16 sctpSend(Buffer *mBuf, U8 itfType)
759 {
760    U8               ret;
761    MsgLen           len;          /* number of actually sent octets */
762    CmInetMemInfo    memInfo;                        
763    
764    memInfo.region = DU_APP_MEM_REGION;               
765    memInfo.pool   = DU_POOL;
766
767    if(itfType == F1_INTERFACE)
768    {
769       DU_LOG("\nSCTP : sending the message to DuApp");
770       ret = cmInetSctpSendMsg(&f1Params.sockFd, &f1Params.destIpNetAddr, f1Params.destPort, &memInfo, mBuf, &len, 0, FALSE, 0, 0/*SCT_PROTID_NONE*/, RWOULDBLOCK);
771    }
772
773    if(itfType == E2_INTERFACE)
774    {
775       DU_LOG("\nSCTP : sending the message to ric");
776       ret = cmInetSctpSendMsg(&ricParams.sockFd, &ricParams.destIpNetAddr, ricParams.destPort, &memInfo, mBuf, &len, 0, FALSE, 0, 0/*SCT_PROTID_NONE*/, RWOULDBLOCK);
777    }
778
779    if(ret != ROK && ret != RWOULDBLOCK)
780    {
781       DU_LOG("\nSCTP : Failed sending the message");
782       RETVALUE(RFAILED);
783    }
784
785    RETVALUE(ROK);
786 } /* End of sctpSend */
787
788 /**********************************************************************
789          End of file
790 **********************************************************************/