E2AP code changes
[o-du/l2.git] / src / cm / lsctp.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 DU APP and SCTP interface functions */
20
21 #include "du_sctp.h"
22
23
24 /*******************************************************************
25  *
26  * @brief Packs SCTP notification 
27  *
28  * @details
29  *
30  *    Function : cmPkSctpNtfy
31  *
32  *    Functionality:
33  *       Packs SCTP notification
34  *
35  * @params[in] Notification 
36  * @return ROK     - success
37  *         RFAILED - failure
38  *
39  * ****************************************************************/
40
41 S16 cmPkSctpNtfy(Pst *pst, CmInetSctpNotification *ntfy)
42 {
43    Buffer *mBuf;
44
45    if(SGetMsg(DU_APP_MEM_REGION, DU_POOL, &mBuf) != ROK)
46    {
47       printf("\nSCTP : Failed to allocate memory");
48       RETVALUE(RFAILED);
49    }
50
51    if(ntfy->header.nType == CM_INET_SCTP_ASSOC_CHANGE)
52    {
53       SPkU16(ntfy->u.assocChange.state, mBuf);
54       SPkU16(ntfy->u.assocChange.assocId, mBuf);
55    }
56    SPkU16(ntfy->header.nType, mBuf);
57
58    if (SPstTsk(pst, mBuf) != ROK)
59    {
60       printf("\nSCTP : SPstTsk failed while sending SCTP notification");
61       RETVALUE(RFAILED);
62    }
63
64    RETVALUE(ROK);
65 }
66
67 /*******************************************************************
68  *
69  * @brief Unpacks SCTP notification 
70  *
71  * @details
72  *
73  *    Function : cmUnpkSctpNtfy 
74  *
75  *    Functionality:
76  *       Unpacks SCTP notification 
77  *
78  * @params[in] 
79  * @return ROK     - success
80  *         RFAILED - failure
81  *
82  * ****************************************************************/
83
84 S16 cmUnpkSctpNtfy(SctpNtfy func, Pst *pst, Buffer *mBuf)
85 {
86    CmInetSctpNotification ntfy;
87    cmMemset((U8*)&ntfy, 0, sizeof(CmInetSctpNotification));
88
89    SUnpkU16(&(ntfy.header.nType), mBuf);
90    if(ntfy.header.nType == CM_INET_SCTP_ASSOC_CHANGE)
91    {
92       SUnpkU16(&(ntfy.u.assocChange.assocId), mBuf);
93       SUnpkU16(&(ntfy.u.assocChange.state), mBuf);
94    }
95
96    RETVALUE((*func)(mBuf, &ntfy));
97 }
98
99 /**********************************************************************
100          End of file
101 **********************************************************************/