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