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