Moving all common header file into common_def.h file
[o-du/l2.git] / src / cm / legtp.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 EGTP interface functions */
20 #include "common_def.h"
21 #include "lrg.h"
22 #include "legtp.h"
23 #include "lkw.x"
24 #include "lrg.x"
25 #include "du_cfg.h"
26 #include "du_egtp.h"
27
28 /*******************************************************************
29  *
30  * @brief Packs EGTP confirm status
31  *
32  * @details
33  *
34  *    Function : packEgtpCfmStatus
35  *
36  *    Functionality:
37  *       Packs EGTP confirm status
38  *
39  * @params[in] Confirm status
40  *             Message buffer
41  * @return ROK     - success
42  *         RFAILED - failure
43  *
44  ******************************************************************/
45 S16 packEgtpCfmStatus(CmStatus cfm, Buffer *mBuf)
46 {
47    SPkU16(cfm.status, mBuf);
48    SPkU16(cfm.reason, mBuf);
49    
50    RETVALUE(ROK);
51 }
52
53 /*******************************************************************
54  *
55  * @brief Unpacks EGTP confirm status
56  *
57  * @details
58  *
59  *    Function : unpackEgtpCfmStatus
60  *
61  *    Functionality:
62  *       Packs EGTP confirm status
63  *
64  * @params[in] Confirm status
65  *             Message buffer 
66  * @return ROK     - success
67  *         RFAILED - failure
68  *
69  ******************************************************************/
70
71 S16 unpackEgtpCfmStatus(CmStatus *cfm, Buffer *mBuf)
72 {
73    SUnpkU16(&(cfm->reason), mBuf);
74    SUnpkU16(&(cfm->status), mBuf);
75
76    RETVALUE(ROK);
77 }
78
79 /*******************************************************************
80  *
81  * @brief Packs EGTP configuration 
82  *
83  * @details
84  *
85  *    Function : packEgtpCfgReq 
86  *
87  *    Functionality:
88  *       Packs EGTP configuration
89  *
90  * @params[in] Post structure
91  *             EGTP configuration 
92  * @return ROK     - success
93  *         RFAILED - failure
94  *
95  ******************************************************************/
96 S16 packEgtpCfgReq(Pst *pst, EgtpConfig egtpCfg)
97 {
98    Buffer *mBuf;
99
100    if(SGetMsg(DFLT_REGION, DU_POOL, &mBuf) != ROK)
101    {
102       printf("\nDU_APP : Failed to allocate memory");
103       RETVALUE(RFAILED);
104    }
105    if(egtpCfg.localIp.ipV4Pres)
106    {
107       SPkU32(egtpCfg.localIp.ipV4Addr, mBuf);
108    }
109    cmPkBool(egtpCfg.localIp.ipV4Pres, mBuf);
110    SPkU16(egtpCfg.localPort, mBuf);
111
112    if(egtpCfg.destIp.ipV4Pres)
113    {
114       SPkU32(egtpCfg.destIp.ipV4Addr, mBuf);
115    }
116    cmPkBool(egtpCfg.destIp.ipV4Pres, mBuf);
117    SPkU16(egtpCfg.destPort, mBuf);
118
119    SPkU32(egtpCfg.minTunnelId, mBuf);
120    SPkU32(egtpCfg.maxTunnelId, mBuf);
121
122    SPstTsk(pst, mBuf);
123
124    RETVALUE(ROK);
125 }
126
127 /*******************************************************************
128  *
129  * @brief Unpacks EGTP configuration
130  *
131  * @details
132  *
133  *    Function : unpackEgtpCfgReq
134  *
135  *    Functionality:
136  *       Unpacks EGTP configuration
137  *
138  * @params[in] Configuration Request handler
139  *             Post structure
140  *             Message Buffer 
141  * @return ROK     - success
142  *         RFAILED - failure
143  *
144  * ****************************************************************/
145 S16 unpackEgtpCfgReq(EgtpCfgReq func, Pst *pst, Buffer *mBuf)
146 {
147    EgtpConfig egtpCfg;
148
149    cmMemset((U8 *)&egtpCfg, 0, sizeof(EgtpConfig));
150
151    SUnpkU32(&(egtpCfg.maxTunnelId), mBuf);
152    SUnpkU32(&(egtpCfg.minTunnelId), mBuf);
153   
154    SUnpkU16(&(egtpCfg.destPort), mBuf);
155    cmUnpkBool(&(egtpCfg.destIp.ipV4Pres), mBuf);
156    if(egtpCfg.destIp.ipV4Pres)
157    {  
158       SUnpkU32(&(egtpCfg.destIp.ipV4Addr), mBuf);
159    }
160
161    SUnpkU16(&(egtpCfg.localPort), mBuf);
162    cmUnpkBool(&(egtpCfg.localIp.ipV4Pres), mBuf);
163    if(egtpCfg.localIp.ipV4Pres)
164    {
165       SUnpkU32(&(egtpCfg.localIp.ipV4Addr), mBuf);
166    }
167    
168    SPutMsg(mBuf);
169  
170    RETVALUE((*func)(pst, egtpCfg));
171 }
172
173
174 /*******************************************************************
175  *
176  * @brief Packs EGTP configuration results
177  *
178  * @details
179  *
180  *    Function : packEgtpCfgCfm
181  *
182  *    Functionality:
183  *       Packs EGTP configuration result
184  *
185  * @params[in] Post structure
186  *             Status confirm 
187  * @return ROK     - success
188  *         RFAILED - failure
189  *
190  ******************************************************************/
191
192 S16 packEgtpCfgCfm(Pst *pst, CmStatus cfm)
193 {
194    Buffer *mBuf;
195   
196    if(SGetMsg(DFLT_REGION, DU_POOL, &mBuf) != ROK)
197    {
198       printf("\nEGTP : Failed to allocate memory");
199       RETVALUE(RFAILED);
200    }
201  
202    packEgtpCfmStatus(cfm, mBuf); 
203    SPstTsk(pst, mBuf); 
204    RETVALUE(ROK); 
205 }
206
207 /*******************************************************************
208  *
209  * @brief Unpacks EGTP configuration results
210  *
211  * @details
212  *
213  *    Function : unpackEgtpCfgCfm
214  *
215  *    Functionality:
216  *       Unpacks EGTP configuration result
217  *
218  * @params[in] Config Cfm Hanlder
219  *             Message buffer
220  * @return ROK     - success
221  *         RFAILED - failure
222  *
223  ******************************************************************/
224  
225 S16 unpackEgtpCfgCfm(EgtpCfgCfm func, Buffer *mBuf)
226 {
227    CmStatus cfm;
228    
229    cmMemset((U8 *)&cfm, 0, sizeof(CmStatus));
230    unpackEgtpCfmStatus(&cfm, mBuf);
231
232    RETVALUE((*func)(cfm));
233 }
234
235 /*******************************************************************
236  *
237  * @brief Packs EGTP server open request
238  *
239  * @details
240  *
241  *    Function : packEgtpSrvOpenReq
242  *
243  *    Functionality:
244  *       Packs EGTP server open request
245  *
246  * @params[in] Post structure
247  * @return ROK     - success
248  *         RFAILED - failure
249  *
250   *******************************************************************/ 
251 S16 packEgtpSrvOpenReq(Pst *pst)
252 {
253    Buffer *mBuf;
254  
255    if(SGetMsg(DFLT_REGION, DU_POOL, &mBuf) != ROK)
256    {
257       printf("\nDU_APP : Failed to allocate memory");
258       RETVALUE(RFAILED);
259    }
260   
261    SPstTsk(pst, mBuf);
262    RETVALUE(ROK);
263 }
264
265 /*******************************************************************
266  *
267  * @brief Unpacks EGTP server open req
268  *
269  * @details
270  *
271  *    Function : unpackEgtpSrvOpenReq
272  *
273  *    Functionality:
274  *       Unpacks EGTP server open req
275  *
276  * @params[in] Hanlder function pointer
277  *             Message buffer
278  * @return ROK     - success
279  *         RFAILED - failure
280  *
281  ******************************************************************/
282 S16 unpackEgtpSrvOpenReq(EgtpSrvOpenReq func, Pst *pst, Buffer *mBuf)
283 {
284     RETVALUE((*func)(pst));
285 }
286
287
288 /*******************************************************************
289  *
290  * @brief Packs EGTP server open confirm
291  *
292  * @details
293  *
294  *    Function : packEgtpSrvOpenCfm
295  *
296  *    Functionality:
297  *       Packs EGTP server open confirm
298  *
299  * @params[in] Post structure
300  * @return ROK     - success
301  *         RFAILED - failure
302  *
303  *******************************************************************/
304 S16 packEgtpSrvOpenCfm(Pst *pst, CmStatus cfm)
305 {
306    Buffer *mBuf;
307  
308    if(SGetMsg(DFLT_REGION, DU_POOL, &mBuf) != ROK)
309    {
310       printf("\nEGTP : Failed to allocate memory");
311       RETVALUE(RFAILED);
312    }
313  
314    packEgtpCfmStatus(cfm, mBuf); 
315    SPstTsk(pst, mBuf);
316    RETVALUE(ROK);
317
318 }
319
320 /*******************************************************************
321  *
322  * @brief Unpacks EGTP server open confirm
323  *
324  * @details
325  *
326  *    Function : unpackEgtpSrvOpenCfm
327  *
328  *    Functionality:
329  *       Unpacks EGTP server open confirm
330  *
331  * @params[in] Hanlder function pointer
332  *             Message buffer
333  * @return ROK     - success
334  *         RFAILED - failure
335  *
336  *******************************************************************/
337 S16 unpackEgtpSrvOpenCfm(EgtpSrvOpenCfm func, Buffer *mBuf)
338 {
339    CmStatus cfm;
340     
341    cmMemset((U8 *)&cfm, 0, sizeof(CmStatus));
342    unpackEgtpCfmStatus(&cfm, mBuf);
343
344    RETVALUE((*func)(cfm));
345 }
346
347 /*******************************************************************
348  *
349  * @brief Packs EGTP tunnel management request
350  *
351  * @details
352  *
353  *    Function : packEgtpTnlMgmtReq
354  *
355  *    Functionality:
356  *       Packs EGTP tunnel management request
357  *
358  * @params[in] Post structure
359  *             Tunnel action
360  *             Local tunnel endpoint id
361  *             Remote tunnel endpoint id
362  * @return ROK     - success
363  *         RFAILED - failure
364  *
365  *******************************************************************/
366 S16 packEgtpTnlMgmtReq(Pst *pst, EgtpTnlEvt tnlEvt)
367 {
368    Buffer *mBuf;
369
370    if(SGetMsg(DFLT_REGION, DU_POOL, &mBuf) != ROK)
371    {
372       printf("\nDU_APP : Failed to allocate memory");
373       RETVALUE(RFAILED);
374    }
375
376    SPkU8(tnlEvt.action, mBuf);
377    SPkU32(tnlEvt.lclTeid, mBuf);
378    SPkU32(tnlEvt.remTeid, mBuf);
379
380    SPstTsk(pst, mBuf);
381    RETVALUE(ROK);
382 }
383
384
385 /*******************************************************************
386  *
387  * @brief Unpacks EGTP tunnel management request
388  *
389  * @details
390  *
391  *    Function : unpackEgtpTnlMgmtReq
392  *
393  *    Functionality:
394  *       Unpacks EGTP tunnel management request
395  *
396  * @params[in] Hanlder function pointer
397  *             Post structure
398  *             Message buffer
399  * @return ROK     - success
400  *         RFAILED - failure
401  * 
402  * *******************************************************************/
403 S16 unpackEgtpTnlMgmtReq(EgtpTnlMgmtReq func, Pst *pst, Buffer *mBuf)
404 {
405    EgtpTnlEvt tnlEvt;
406
407    cmMemset((U8 *)&tnlEvt, 0, sizeof(EgtpTnlEvt));
408
409    SUnpkU32(&(tnlEvt.remTeid), mBuf);
410    SUnpkU32(&(tnlEvt.lclTeid), mBuf);
411    SUnpkU8(&(tnlEvt.action), mBuf);
412
413    RETVALUE((* func)(pst, tnlEvt));
414
415 }
416
417 /*******************************************************************
418  *
419  * @brief Packs EGTP tunnel management confirm
420  *
421  * @details
422  *
423  *    Function : packEgtpTnlMgmtCfm
424  *
425  *    Functionality:
426  *      Packs EGTP tunnel management cfm
427  *
428  * @params[in] Post structure
429  *             Tunnel Event structure
430  *
431  * @return ROK     - success
432  *         RFAILED - failure
433  *
434  ********************************************************************/
435
436 S16 packEgtpTnlMgmtCfm(Pst *pst, EgtpTnlEvt tnlEvt)
437 {
438    Buffer *mBuf;
439
440    if(SGetMsg(DFLT_REGION, DU_POOL, &mBuf) != ROK)
441    {
442       printf("\nEGTP : Failed to allocate memory");
443       RETVALUE(RFAILED);
444    }
445     
446    SPkU8(tnlEvt.action, mBuf);
447    SPkU32(tnlEvt.lclTeid, mBuf);
448    SPkU32(tnlEvt.remTeid, mBuf);
449    
450    packEgtpCfmStatus(tnlEvt.cfmStatus, mBuf);
451     
452    SPstTsk(pst, mBuf);
453    RETVALUE(ROK);
454
455 }
456
457 /*******************************************************************
458  *
459  * @brief Unpacks EGTP tunnel management confirm
460  *
461  * @details
462  *
463  *    Function : unpackEgtpTnlMgmtCfm
464  *
465  *    Functionality:
466  *       Unpacks EGTP tunnel management confirm
467  *
468  * @params[in] Hanlder function pointer
469  *             Post structure
470  *             Message buffer
471  * @return ROK     - success
472  *         RFAILED - failure
473  * 
474  * *******************************************************************/
475 S16 unpackEgtpTnlMgmtCfm(EgtpTnlMgmtCfm func, Buffer *mBuf)
476 {
477    EgtpTnlEvt tnlEvt;
478  
479    cmMemset((U8 *)&tnlEvt, 0, sizeof(EgtpTnlEvt));
480
481    unpackEgtpCfmStatus(&(tnlEvt.cfmStatus), mBuf); 
482    SUnpkU32(&(tnlEvt.remTeid), mBuf);
483    SUnpkU32(&(tnlEvt.lclTeid), mBuf);
484    SUnpkU8(&(tnlEvt.action), mBuf);
485  
486    RETVALUE((* func)(tnlEvt));
487  
488 }
489
490 /*******************************************************************
491  *
492  * @brief Packs Slot indication and sends to EGTP
493  *
494  * @details
495  *
496  *    Function : packEgtpSlotInd
497  *
498  *    Functionality:
499  *       Packs slot indication and sends tp EGTP
500  *
501  * @params[in] Post structure
502  * @return ROK     - success
503  *         RFAILED - failure
504  *
505  *******************************************************************/
506 S16 packEgtpSlotInd(Pst *pst)
507 {
508    Buffer *mBuf;
509
510    if(SGetMsg(DFLT_REGION, DU_POOL, &mBuf) != ROK)
511    {
512       printf("\nDU_APP : Failed to allocate memory");
513       RETVALUE(RFAILED);
514    }
515
516    SPstTsk(pst, mBuf);
517    RETVALUE(ROK);
518  
519 }
520
521 /*******************************************************************
522  *
523  * @brief Unpacks slot indication
524  *
525  * @details
526  *
527  *    Function : unpackEgtpSlotInd
528  *
529  *    Functionality:
530  *       Unpacks slot indication
531  *
532  * @params[in]
533  * @return ROK     - success
534  *         RFAILED - failure
535  *
536 ******************************************************************/
537 S16 unpackEgtpSlotInd(EgtpSlotInd func, Pst *pst, Buffer *mBuf)
538 {
539     RETVALUE((*func)());
540 }