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