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