5addcb0f64c35b5a8ef0af660c0dac3d879b9c29
[o-du/l2.git] / src / cu_stub / cu_stub_egtp.h
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 all SCTP related functionality */
20  
21 #ifndef __CU_STUB_EGTP_H__
22 #define __CU_STUB_EGTP_H__
23
24 #include "cu_stub.h"
25 #include "cm_inet.h"
26 #include "cm_tpt.h"
27  
28 #include "cm_inet.x"
29 #include "cm_tpt.x"
30
31 #define EGTP_DFLT_PORT 2152
32 #define EGTP_TNL_MGMT_ADD 1
33 #define EGTP_TNL_MGMT_MOD 2
34 #define EGTP_TNL_MGMT_DEL 3
35
36 #define EGTP_MAX_HDR_LEN 40
37  
38 #define EGTP_EXT_HDR_UDP_TYPE 64
39 #define EGTP_EXT_HDR_PDCP_TYPE 192
40  
41 #define EGTP_MASK_BIT1                   0x01
42 #define EGTP_MASK_BIT2                   0x02
43 #define EGTP_MASK_BIT3                   0x04
44 #define EGTP_MASK_BIT4                   0x08
45 #define EGTP_MASK_BIT5                   0x10
46 #define EGTP_MASK_BIT6                   0x20
47 #define EGTP_MASK_BIT7                   0x40
48 #define EGTP_MASK_BIT8                   0x80
49
50 #define NUM_DL_PACKETS 4
51
52 uint8_t         sockType;
53 uint8_t         protType;
54
55 typedef enum egtpMsgType
56 {
57    EGTP_MSG_INVALID,
58    EGTPU_MSG_ECHO_REQ,
59    EGTPU_MSG_ECHO_RSP,
60    EGTPU_MSG_ERROR_IND          = 26,
61    EGTPU_MSG_SUPP_EXT_HDR_NTF   = 31,
62    EGTPU_MSG_END_MARKER         = 254,
63    EGTPU_MSG_GPDU,
64    EGTP_MSG_MAX
65 }EgtpMsgType;
66
67 /*Extension Header */
68 typedef struct egtpExtHdr
69 {
70    TknUInt16   udpPort;                       /**< UDP Port */
71    TknUInt16   pdcpNmb;                       /**< PDCP Number */
72 }EgtpExtHdr;
73  
74 /*Structure for MsgHdr */
75 typedef struct egtpMsgHdr
76 {
77    TknUInt8   nPdu;                      /**< N-PDU Number */
78    TknUInt32  seqNum;                    /**< Sequence Number */
79    EgtpExtHdr extHdr;                       /**< Extension headers present flag */
80    uint32_t   teId;                         /**< Tunnel Endpoint Id */
81    uint8_t    msgType;                      /**< eGTP-U Message Type */
82 }EgtpMsgHdr;
83  
84 typedef struct egtpMsg
85 {
86    EgtpMsgHdr msgHdr;
87    Buffer     *msg;
88 }EgtpMsg;
89
90 typedef struct egtpTnlEvt
91 {
92    uint8_t  action;
93    uint32_t lclTeid;
94    uint32_t remTeid;
95 }EgtpTnlEvt;
96
97 typedef struct egtpTptSrvr
98 {
99    CmInetAddr  addr; 
100    CmInetFd    sockFd;     /* Socket file descriptor */
101 }EgtpTptSrvr;
102
103 typedef struct EgtpTeIdCb
104 {
105    uint32_t teId;              /* Local tunnel id */
106    uint32_t remTeId;           /* Remote tunnel id */
107    struct
108    {
109       uint8_t hdr[EGTP_MAX_HDR_LEN];
110       uint8_t cnt;
111    }preEncodedHdr;        /* Pre-encoded header for PDUs on this tunnel */
112 }EgtpTeIdCb;
113
114 typedef struct egtpDstCb
115 {
116    CmInetIpAddr  dstIp;          /* destination IP */
117    uint16_t      dstPort;        /* Remote port that sends data */
118    EgtpTptSrvr   sendTptSrvr;    /* Transport server for sending UDP msg to */
119    uint32_t      numTunn;        /* Number of tunnels */
120    CmHashListCp  teIdLst;        /* Tunnel Id list for this destination */
121 }EgtpDstCb;
122
123 typedef struct egtpGlobalCb
124 {
125    EgtpParams   egtpCfg;         /* EGTP configuration */
126    EgtpTptSrvr  recvTptSrvr;     /* Transport server for receiving UDP msg */
127    EgtpDstCb    dstCb;           /* Destination endpoint */
128    uint8_t      gCntPdu[MAX_TEID+1]; /* Maintaining PDU count for each bearer */
129 }EgtpGlobalCb;
130 EgtpGlobalCb egtpCb;   /* EGTP global control block */
131
132 S16 egtpActvInit();
133 S16 cuEgtpCfgReq();
134 S16 cuEgtpSrvOpenReq();
135 S16 cuEgtpTnlMgmtReq(EgtpTnlEvt tnlEvt);
136 S16 cuEgtpTnlAdd(EgtpTnlEvt tnlEvt);
137 S16 cuEgtpTnlMod(EgtpTnlEvt tnlEvt);
138 S16 cuEgtpTnlDel(EgtpTnlEvt tnlEvt);
139 S16 cuEgtpEncodeHdr(uint8_t *preEncodedHdr, EgtpMsgHdr *preDefHdr, uint8_t *hdrIdx);
140 S16 cuEgtpHdlRecvMsg(Buffer *mBuf);
141 uint16_t cuEgtpDatReq(uint8_t teId);
142 S16 BuildAppMsg(EgtpMsg  *egtpMsg);
143 S16 BuildEgtpMsg(EgtpMsg *egtpMsg);
144 S16 cuEgtpSendMsg(Buffer *mBuf);
145 S16 cuEgtpDecodeHdr(Buffer *mBuf);
146
147 #endif