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