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