[Issue-ID : ODUHIGH-487] EGTP Port fix at F1 interface
[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 #define EGTP_TNL_MGMT_ADD 1
25 #define EGTP_TNL_MGMT_MOD 2
26 #define EGTP_TNL_MGMT_DEL 3
27
28 #define EGTP_MAX_HDR_LEN 40
29  
30 #define EGTP_EXT_HDR_UDP_TYPE 64
31 #define EGTP_EXT_HDR_PDCP_TYPE 192
32  
33 #define EGTP_MASK_BIT1                   0x01
34 #define EGTP_MASK_BIT2                   0x02
35 #define EGTP_MASK_BIT3                   0x04
36 #define EGTP_MASK_BIT4                   0x08
37 #define EGTP_MASK_BIT5                   0x10
38 #define EGTP_MASK_BIT6                   0x20
39 #define EGTP_MASK_BIT7                   0x40
40 #define EGTP_MASK_BIT8                   0x80
41
42 /*VALID Tunnel ID*/
43 #define MIN_TEID 1   /*[Spec 29.281,Sec 5.1]: All Zero TEIDs are never assigned for setting up GTP-U Tunnel*/
44 #define MAX_TEID MAX_NUM_DRB * MAX_NUM_UE /*[Spec 29.281]: Max limit is not mentioned but as per GTP-U Header Format, TEID occupies 4 octets */
45
46 #define NUM_TUNNEL_TO_PUMP_DATA 4
47 #define NUM_DL_PACKETS 1
48
49 uint8_t         sockType;
50 uint8_t         protType;
51
52 typedef enum egtpMsgType
53 {
54    EGTP_MSG_INVALID,
55    EGTPU_MSG_ECHO_REQ,
56    EGTPU_MSG_ECHO_RSP,
57    EGTPU_MSG_ERROR_IND          = 26,
58    EGTPU_MSG_SUPP_EXT_HDR_NTF   = 31,
59    EGTPU_MSG_END_MARKER         = 254,
60    EGTPU_MSG_GPDU,
61    EGTP_MSG_MAX
62 }EgtpMsgType;
63
64 /*Extension Header */
65 typedef struct egtpExtHdr
66 {
67    TknUInt16   udpPort;                       /**< UDP Port */
68    TknUInt16   pdcpNmb;                       /**< PDCP Number */
69 }EgtpExtHdr;
70  
71 /*Structure for MsgHdr */
72 typedef struct egtpMsgHdr
73 {
74    TknUInt8   nPdu;                      /**< N-PDU Number */
75    TknUInt32  seqNum;                    /**< Sequence Number */
76    EgtpExtHdr extHdr;                       /**< Extension headers present flag */
77    uint32_t   teId;                         /**< Tunnel Endpoint Id */
78    uint8_t    msgType;                      /**< eGTP-U Message Type */
79 }EgtpMsgHdr;
80  
81 typedef struct egtpMsg
82 {
83    EgtpMsgHdr msgHdr;
84    Buffer     *msg;
85 }EgtpMsg;
86
87 typedef struct egtpTnlEvt
88 {
89    uint8_t  action;
90    uint32_t lclTeid;
91    uint32_t remTeid;
92 }EgtpTnlEvt;
93
94 typedef struct EgtpTeIdCb
95 {
96    uint32_t teId;              /* Local tunnel id */
97    uint32_t remTeId;           /* Remote tunnel id */
98    struct
99    {
100       uint8_t hdr[EGTP_MAX_HDR_LEN];
101       uint8_t cnt;
102    }preEncodedHdr;        /* Pre-encoded header for PDUs on this tunnel */
103 }EgtpTeIdCb;
104
105 typedef struct egtpDstCb
106 {
107    uint32_t      duId;
108    CmInetAddr    dstAddr;
109    uint32_t      numTunn;        /* Number of tunnels */
110    CmHashListCp  teIdLst;        /* Tunnel Id list for this destination */
111 }EgtpDstCb;
112
113 typedef struct egtpDstCfg 
114 {
115    SctpIpAddr  dstIp;
116    uint16_t    dstPort;
117 }EgtpDstCfg;
118
119 typedef struct cuEgtpParams
120 {
121    uint32_t       currTunnelId;
122    uint32_t       minTunnelId;
123    uint32_t       maxTunnelId;
124    uint8_t        numDu;
125    SctpIpAddr     localIp;
126    uint16_t       localPort;
127    EgtpDstCfg     dstCfg[MAX_DU_SUPPORTED];
128 }CuEgtpParams;
129
130 typedef struct egtpGlobalCb
131 {
132    CuEgtpParams egtpCfg;         /* EGTP configuration */
133    CmInetAddr   localAddr;
134    CmInetFd     sockFd;     /* Socket file descriptor */
135    uint8_t      numDu;
136    EgtpDstCb    dstCb[MAX_DU_SUPPORTED];          /* Destination endpoint */
137    uint8_t      gCntPdu[MAX_TEID+1]; /* Maintaining PDU count for each bearer */
138 }EgtpGlobalCb;
139 EgtpGlobalCb egtpCb;   /* EGTP global control block */
140
141 S16 egtpActvInit();
142 S16 cuEgtpCfgReq();
143 S16 cuEgtpSrvOpenReq();
144 S16 cuEgtpTnlMgmtReq(uint32_t duId,EgtpTnlEvt tnlEvt);
145 S16 cuEgtpTnlAdd(uint32_t duId, EgtpTnlEvt tnlEvt);
146 S16 cuEgtpTnlMod(uint32_t duId,EgtpTnlEvt tnlEvt);
147 S16 cuEgtpTnlDel(uint32_t duId,EgtpTnlEvt tnlEvt);
148 S16 cuEgtpEncodeHdr(uint8_t *preEncodedHdr, EgtpMsgHdr *preDefHdr, uint8_t *hdrIdx);
149 S16 cuEgtpHdlRecvMsg(Buffer *mBuf);
150 uint16_t cuEgtpDatReq(uint32_t duId, uint8_t teId);
151 S16 BuildAppMsg(uint32_t duId, EgtpMsg  *egtpMsg);
152 S16 BuildEgtpMsg(uint32_t duId, EgtpMsg *egtpMsg);
153 S16 cuEgtpSendMsg(uint32_t duId, Buffer *mBuf);
154 S16 cuEgtpDecodeHdr(Buffer *mBuf);
155
156 #endif