Initial commit for Bronze release
[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  * @brief Packs SCTP configuration 
26  *
27  * @details
28  *
29  *    Function : cmPkSctpAssocReq
30  *
31  *    Functionality:
32  *       Packs SCTP configuration
33  *
34  * @params[in] Notification 
35  * @return ROK     - success
36  *         RFAILED - failure
37  *
38  ******************************************************************/
39 S16 cmPkSctpAssocReq(Pst *pst, F1SctpParams sctpCfgParam)
40 {
41    Buffer *mBuf;
42
43    if(SGetMsg(DFLT_REGION, DU_POOL, &mBuf) != ROK)
44    {
45       printf("\nDU_APP : Failed to allocate memory");
46       RETVALUE(RFAILED);
47    }
48   
49    if(sctpCfgParam.duIpAddr.ipV4Pres)
50    {
51       SPkU32(sctpCfgParam.duIpAddr.ipV4Addr, mBuf);
52    }
53    cmPkBool(sctpCfgParam.duIpAddr.ipV4Pres, mBuf);
54    SPkU16(sctpCfgParam.duPort, mBuf);
55
56    if(sctpCfgParam.cuIpAddr.ipV4Pres)
57    {
58       SPkU32(sctpCfgParam.cuIpAddr.ipV4Addr, mBuf);
59    }
60    cmPkBool(sctpCfgParam.cuIpAddr.ipV4Pres, mBuf);
61    SPkU16(sctpCfgParam.cuPort, mBuf);
62
63    SPstTsk(pst, mBuf);
64
65    RETVALUE(ROK);
66 }
67
68 /*******************************************************************
69  *
70  * @brief Unpacks SCTP configuration 
71  *
72  * @details
73  *
74  *    Function : cmUnpkSctpAssocReq
75  *
76  *    Functionality:
77  *       Unpacks SCTP configuration
78  *
79  * @params[in] Notification 
80  * @return ROK     - success
81  *         RFAILED - failure
82  *
83  ******************************************************************/
84 S16 cmUnpkSctpAssocReq(Buffer *mBuf) 
85 {
86    cmMemset((U8*)&sctpCfg, 0, sizeof(F1SctpParams));  
87
88    SUnpkU16(&(sctpCfg.cuPort), mBuf);
89    cmUnpkBool(&(sctpCfg.cuIpAddr.ipV4Pres), mBuf);
90    if(sctpCfg.cuIpAddr.ipV4Pres)
91    {
92       SUnpkU32(&(sctpCfg.cuIpAddr.ipV4Addr), mBuf);
93    }
94    
95    SUnpkU16(&(sctpCfg.duPort), mBuf);
96    cmUnpkBool(&(sctpCfg.duIpAddr.ipV4Pres), mBuf);
97    if(sctpCfg.duIpAddr.ipV4Pres)
98    {
99       SUnpkU32(&(sctpCfg.duIpAddr.ipV4Addr), mBuf);
100    }
101
102    RETVALUE(ROK);
103 }
104
105 /*******************************************************************
106  *
107  * @brief Packs SCTP notification 
108  *
109  * @details
110  *
111  *    Function : cmPkSctpNtfy
112  *
113  *    Functionality:
114  *       Packs SCTP notification
115  *
116  * @params[in] Notification 
117  * @return ROK     - success
118  *         RFAILED - failure
119  *
120  * ****************************************************************/
121
122 S16 cmPkSctpNtfy(Pst *pst, CmInetSctpNotification *ntfy)
123 {
124    Buffer *mBuf;
125
126    if(SGetMsg(DU_APP_MEM_REGION, DU_POOL, &mBuf) != ROK)
127    {
128       printf("\nSCTP : Failed to allocate memory");
129       RETVALUE(RFAILED);
130    }
131
132    if(ntfy->header.nType == CM_INET_SCTP_ASSOC_CHANGE)
133    {
134       SPkU16(ntfy->u.assocChange.state, mBuf);
135    }
136    SPkU16(ntfy->header.nType, mBuf);
137
138    if (SPstTsk(pst, mBuf) != ROK)
139    {
140       printf("\nSCTP : SPstTsk failed while sending SCTP notification");
141       RETVALUE(RFAILED);
142    }
143
144    RETVALUE(ROK);
145 }
146
147 /*******************************************************************
148  *
149  * @brief Unpacks SCTP notification 
150  *
151  * @details
152  *
153  *    Function : cmUnpkSctpNtfy 
154  *
155  *    Functionality:
156  *       Unpacks SCTP notification 
157  *
158  * @params[in] 
159  * @return ROK     - success
160  *         RFAILED - failure
161  *
162  * ****************************************************************/
163
164 S16 cmUnpkSctpNtfy(SctpNtfy func, Pst *pst, Buffer *mBuf)
165 {
166    CmInetSctpNotification ntfy;
167    cmMemset((U8*)&ntfy, 0, sizeof(CmInetSctpNotification));
168
169    SUnpkU16(&(ntfy.header.nType), mBuf);
170    if(ntfy.header.nType == CM_INET_SCTP_ASSOC_CHANGE)
171    {
172       SUnpkU16(&(ntfy.u.assocChange.state), mBuf);
173    }
174
175    RETVALUE((*func)(mBuf, &ntfy));
176 }
177
178 /**********************************************************************
179          End of file
180 **********************************************************************/