0ca75fc20b7cef091e4138a9d8a706c8dbc68934
[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_DFLT_PORT 2152
25 #define EGTP_TNL_MGMT_ADD 1
26 #define EGTP_TNL_MGMT_MOD 2
27 #define EGTP_TNL_MGMT_DEL 3
28
29 #define EGTP_MAX_HDR_LEN 40
30  
31 #define EGTP_EXT_HDR_UDP_TYPE 64
32 #define EGTP_EXT_HDR_PDCP_TYPE 192
33  
34 #define EGTP_MASK_BIT1                   0x01
35 #define EGTP_MASK_BIT2                   0x02
36 #define EGTP_MASK_BIT3                   0x04
37 #define EGTP_MASK_BIT4                   0x08
38 #define EGTP_MASK_BIT5                   0x10
39 #define EGTP_MASK_BIT6                   0x20
40 #define EGTP_MASK_BIT7                   0x40
41 #define EGTP_MASK_BIT8                   0x80
42
43 /*VALID Tunnel ID*/
44 #define MIN_TEID 1   /*[Spec 29.281,Sec 5.1]: All Zero TEIDs are never assigned for setting up GTP-U Tunnel*/
45 #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 */
46
47 #define NUM_TUNNEL_TO_PUMP_DATA 9
48 #define NUM_DL_PACKETS 1
49
50 uint8_t         sockType;
51 uint8_t         protType;
52
53 typedef enum egtpMsgType
54 {
55    EGTP_MSG_INVALID,
56    EGTPU_MSG_ECHO_REQ,
57    EGTPU_MSG_ECHO_RSP,
58    EGTPU_MSG_ERROR_IND          = 26,
59    EGTPU_MSG_SUPP_EXT_HDR_NTF   = 31,
60    EGTPU_MSG_END_MARKER         = 254,
61    EGTPU_MSG_GPDU,
62    EGTP_MSG_MAX
63 }EgtpMsgType;
64
65 /*Extension Header */
66 typedef struct egtpExtHdr
67 {
68    TknUInt16   udpPort;                       /**< UDP Port */
69    TknUInt16   pdcpNmb;                       /**< PDCP Number */
70 }EgtpExtHdr;
71  
72 /*Structure for MsgHdr */
73 typedef struct egtpMsgHdr
74 {
75    TknUInt8   nPdu;                      /**< N-PDU Number */
76    TknUInt32  seqNum;                    /**< Sequence Number */
77    EgtpExtHdr extHdr;                       /**< Extension headers present flag */
78    uint32_t   teId;                         /**< Tunnel Endpoint Id */
79    uint8_t    msgType;                      /**< eGTP-U Message Type */
80 }EgtpMsgHdr;
81  
82 typedef struct egtpMsg
83 {
84    EgtpMsgHdr msgHdr;
85    Buffer     *msg;
86 }EgtpMsg;
87
88 typedef struct egtpTnlEvt
89 {
90    uint8_t  action;
91    uint32_t lclTeid;
92    uint32_t remTeid;
93 }EgtpTnlEvt;
94
95 typedef struct egtpTptSrvr
96 {
97    CmInetAddr  addr; 
98    CmInetFd    sockFd;     /* Socket file descriptor */
99 }EgtpTptSrvr;
100
101 typedef struct EgtpTeIdCb
102 {
103    uint32_t teId;              /* Local tunnel id */
104    uint32_t remTeId;           /* Remote tunnel id */
105    struct
106    {
107       uint8_t hdr[EGTP_MAX_HDR_LEN];
108       uint8_t cnt;
109    }preEncodedHdr;        /* Pre-encoded header for PDUs on this tunnel */
110 }EgtpTeIdCb;
111
112 typedef struct egtpDstCb
113 {
114    CmInetIpAddr  dstIp;          /* destination IP */
115    uint16_t      dstPort;        /* Remote port that sends data */
116    EgtpTptSrvr   sendTptSrvr;    /* Transport server for sending UDP msg to */
117    uint32_t      numTunn;        /* Number of tunnels */
118    CmHashListCp  teIdLst;        /* Tunnel Id list for this destination */
119 }EgtpDstCb;
120
121 typedef struct egtpParams
122 {
123    SctpIpAddr  localIp;
124    uint16_t    localPort;
125    SctpIpAddr  destIp;
126    uint16_t    destPort;
127    uint32_t    currTunnelId;
128    uint32_t    minTunnelId;
129    uint32_t    maxTunnelId;
130 }EgtpParams;
131
132 typedef struct egtpGlobalCb
133 {
134    EgtpParams   egtpCfg;         /* EGTP configuration */
135    EgtpTptSrvr  recvTptSrvr;     /* Transport server for receiving UDP msg */
136    EgtpDstCb    dstCb;           /* 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(EgtpTnlEvt tnlEvt);
145 S16 cuEgtpTnlAdd(EgtpTnlEvt tnlEvt);
146 S16 cuEgtpTnlMod(EgtpTnlEvt tnlEvt);
147 S16 cuEgtpTnlDel(EgtpTnlEvt tnlEvt);
148 S16 cuEgtpEncodeHdr(uint8_t *preEncodedHdr, EgtpMsgHdr *preDefHdr, uint8_t *hdrIdx);
149 S16 cuEgtpHdlRecvMsg(Buffer *mBuf);
150 uint16_t cuEgtpDatReq(uint8_t teId);
151 S16 BuildAppMsg(EgtpMsg  *egtpMsg);
152 S16 BuildEgtpMsg(EgtpMsg *egtpMsg);
153 S16 cuEgtpSendMsg(Buffer *mBuf);
154 S16 cuEgtpDecodeHdr(Buffer *mBuf);
155
156 #endif