fb79204a89f145405d450b1defee276156c002e5
[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_TUNNEL_TO_PUMP_DATA 9
51 #define NUM_DL_PACKETS 1
52
53 uint8_t         sockType;
54 uint8_t         protType;
55
56 typedef enum egtpMsgType
57 {
58    EGTP_MSG_INVALID,
59    EGTPU_MSG_ECHO_REQ,
60    EGTPU_MSG_ECHO_RSP,
61    EGTPU_MSG_ERROR_IND          = 26,
62    EGTPU_MSG_SUPP_EXT_HDR_NTF   = 31,
63    EGTPU_MSG_END_MARKER         = 254,
64    EGTPU_MSG_GPDU,
65    EGTP_MSG_MAX
66 }EgtpMsgType;
67
68 /*Extension Header */
69 typedef struct egtpExtHdr
70 {
71    TknUInt16   udpPort;                       /**< UDP Port */
72    TknUInt16   pdcpNmb;                       /**< PDCP Number */
73 }EgtpExtHdr;
74  
75 /*Structure for MsgHdr */
76 typedef struct egtpMsgHdr
77 {
78    TknUInt8   nPdu;                      /**< N-PDU Number */
79    TknUInt32  seqNum;                    /**< Sequence Number */
80    EgtpExtHdr extHdr;                       /**< Extension headers present flag */
81    uint32_t   teId;                         /**< Tunnel Endpoint Id */
82    uint8_t    msgType;                      /**< eGTP-U Message Type */
83 }EgtpMsgHdr;
84  
85 typedef struct egtpMsg
86 {
87    EgtpMsgHdr msgHdr;
88    Buffer     *msg;
89 }EgtpMsg;
90
91 typedef struct egtpTnlEvt
92 {
93    uint8_t  action;
94    uint32_t lclTeid;
95    uint32_t remTeid;
96 }EgtpTnlEvt;
97
98 typedef struct egtpTptSrvr
99 {
100    CmInetAddr  addr; 
101    CmInetFd    sockFd;     /* Socket file descriptor */
102 }EgtpTptSrvr;
103
104 typedef struct EgtpTeIdCb
105 {
106    uint32_t teId;              /* Local tunnel id */
107    uint32_t remTeId;           /* Remote tunnel id */
108    struct
109    {
110       uint8_t hdr[EGTP_MAX_HDR_LEN];
111       uint8_t cnt;
112    }preEncodedHdr;        /* Pre-encoded header for PDUs on this tunnel */
113 }EgtpTeIdCb;
114
115 typedef struct egtpDstCb
116 {
117    CmInetIpAddr  dstIp;          /* destination IP */
118    uint16_t      dstPort;        /* Remote port that sends data */
119    EgtpTptSrvr   sendTptSrvr;    /* Transport server for sending UDP msg to */
120    uint32_t      numTunn;        /* Number of tunnels */
121    CmHashListCp  teIdLst;        /* Tunnel Id list for this destination */
122 }EgtpDstCb;
123
124 typedef struct egtpGlobalCb
125 {
126    EgtpParams   egtpCfg;         /* EGTP configuration */
127    EgtpTptSrvr  recvTptSrvr;     /* Transport server for receiving UDP msg */
128    EgtpDstCb    dstCb;           /* Destination endpoint */
129    uint8_t      gCntPdu[MAX_TEID+1]; /* Maintaining PDU count for each bearer */
130 }EgtpGlobalCb;
131 EgtpGlobalCb egtpCb;   /* EGTP global control block */
132
133 S16 egtpActvInit();
134 S16 cuEgtpCfgReq();
135 S16 cuEgtpSrvOpenReq();
136 S16 cuEgtpTnlMgmtReq(EgtpTnlEvt tnlEvt);
137 S16 cuEgtpTnlAdd(EgtpTnlEvt tnlEvt);
138 S16 cuEgtpTnlMod(EgtpTnlEvt tnlEvt);
139 S16 cuEgtpTnlDel(EgtpTnlEvt tnlEvt);
140 S16 cuEgtpEncodeHdr(uint8_t *preEncodedHdr, EgtpMsgHdr *preDefHdr, uint8_t *hdrIdx);
141 S16 cuEgtpHdlRecvMsg(Buffer *mBuf);
142 uint16_t cuEgtpDatReq(uint8_t teId);
143 S16 BuildAppMsg(EgtpMsg  *egtpMsg);
144 S16 BuildEgtpMsg(EgtpMsg *egtpMsg);
145 S16 cuEgtpSendMsg(Buffer *mBuf);
146 S16 cuEgtpDecodeHdr(Buffer *mBuf);
147
148 #endif