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