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