blob: b6fea6e71e6ce6a3e5fa55e1caf22fe288d5d916 [file] [log] [blame]
jjako52c24142002-12-16 13:33:51 +00001/*
Harald Welte632e8432017-09-05 18:12:14 +02002 * OsmoGGSN - Gateway GPRS Support Node
jjako0fe0df02004-09-17 11:30:40 +00003 * Copyright (C) 2002, 2003, 2004 Mondru AB.
jjako52c24142002-12-16 13:33:51 +00004 *
5 * The contents of this file may be used under the terms of the GNU
6 * General Public License Version 2, provided that the above copyright
7 * notice and this permission notice is included in all copies or
8 * substantial portions of the software.
9 *
jjako52c24142002-12-16 13:33:51 +000010 */
11
12#ifndef _GTPIE_H
13#define _GTPIE_H
14
Harald Welte83769722017-10-13 15:57:48 +020015#include <arpa/inet.h>
16
jjako52c24142002-12-16 13:33:51 +000017/* Macroes for conversion between host and network byte order */
18#define hton8(x) (x)
19#define ntoh8(x) (x)
20#define hton16(x) htons(x)
21#define ntoh16(x) ntohs(x)
22#define hton32(x) htonl(x)
23#define ntoh32(x) ntohl(x)
24
jjako08d331d2003-10-13 20:33:30 +000025#if BYTE_ORDER == LITTLE_ENDIAN
Harald Weltebed35df2011-11-02 13:06:18 +010026static __inline uint64_t hton64(uint64_t q)
jjako08d331d2003-10-13 20:33:30 +000027{
Harald Weltebed35df2011-11-02 13:06:18 +010028 register uint32_t u, l;
29 u = q >> 32;
30 l = (uint32_t) q;
jjako08d331d2003-10-13 20:33:30 +000031
Harald Weltebed35df2011-11-02 13:06:18 +010032 return htonl(u) | ((uint64_t) htonl(l) << 32);
jjako08d331d2003-10-13 20:33:30 +000033}
34
35#define ntoh64(_x) hton64(_x)
36
37#elif BYTE_ORDER == BIG_ENDIAN
38
39#define hton64(_x) (_x)
40#define ntoh64(_x) hton64(_x)
41
42#else
43#error "Please fix <machine/endian.h>"
44#endif
45
Harald Weltebed35df2011-11-02 13:06:18 +010046#define GTPIE_SIZE 256 /* Max number of information elements */
47#define GTPIE_MAX 0xffff /* Max length of information elements */
48#define GTPIE_MAX_TV 28 /* Max length of type value pair */
49#define GTPIE_MAX_TLV 0xffff-3 /* Max length of TLV (GTP length is 16 bit) */
jjako08d331d2003-10-13 20:33:30 +000050
Harald Weltebed35df2011-11-02 13:06:18 +010051#define GTPIE_DEBUG 0 /* Print debug information */
jjako52c24142002-12-16 13:33:51 +000052
Harald Weltebc41c8d2017-10-09 10:15:04 +080053/* GTP Information elements from 29.060 v11.8.0 7.7 Information Elements */
jjako52c24142002-12-16 13:33:51 +000054/* Also covers version 0. Note that version 0 6: QOS Profile was superceded *
55 * by 135: QOS Profile in version 1 */
56
Harald Weltebed35df2011-11-02 13:06:18 +010057#define GTPIE_CAUSE 1 /* Cause 1 */
58#define GTPIE_IMSI 2 /* International Mobile Subscriber Identity 8 */
59#define GTPIE_RAI 3 /* Routing Area Identity (RAI) 8 */
60#define GTPIE_TLLI 4 /* Temporary Logical Link Identity (TLLI) 4 */
61#define GTPIE_P_TMSI 5 /* Packet TMSI (P-TMSI) 4 */
62#define GTPIE_QOS_PROFILE0 6 /* Quality of Service Profile GTP version 0 3 */
63 /* 6-7 SPARE *//* 6 is QoS Profile vers 0 */
64#define GTPIE_REORDER 8 /* Reordering Required 1 */
65#define GTPIE_AUTH_TRIPLET 9 /* Authentication Triplet 28 */
66 /* 10 SPARE */
67#define GTPIE_MAP_CAUSE 11 /* MAP Cause 1 */
68#define GTPIE_P_TMSI_S 12 /* P-TMSI Signature 3 */
69#define GTPIE_MS_VALIDATED 13 /* MS Validated 1 */
70#define GTPIE_RECOVERY 14 /* Recovery 1 */
71#define GTPIE_SELECTION_MODE 15 /* Selection Mode 1 */
72#define GTPIE_FL_DI 16 /* Flow Label Data I 2 */
73#define GTPIE_TEI_DI 16 /* Tunnel Endpoint Identifier Data I 4 */
74#define GTPIE_TEI_C 17 /* Tunnel Endpoint Identifier Control Plane 4 */
75#define GTPIE_FL_C 17 /* Flow Label Signalling 2 */
76#define GTPIE_TEI_DII 18 /* Tunnel Endpoint Identifier Data II 5 */
77#define GTPIE_TEARDOWN 19 /* Teardown Ind 1 */
78#define GTPIE_NSAPI 20 /* NSAPI 1 */
79#define GTPIE_RANAP_CAUSE 21 /* RANAP Cause 1 */
80#define GTPIE_RAB_CONTEXT 22 /* RAB Context 7 */
81#define GTPIE_RP_SMS 23 /* Radio Priority SMS 1 */
82#define GTPIE_RP 24 /* Radio Priority 1 */
83#define GTPIE_PFI 25 /* Packet Flow Id 2 */
84#define GTPIE_CHARGING_C 26 /* Charging Characteristics 2 */
85#define GTPIE_TRACE_REF 27 /* Trace Reference 2 */
86#define GTPIE_TRACE_TYPE 28 /* Trace Type 2 */
87#define GTPIE_MS_NOT_REACH 29 /* MS Not Reachable Reason 1 */
88 /* 30-116 UNUSED */
Harald Weltebc41c8d2017-10-09 10:15:04 +080089/* 117-126 Reserved for the GPRS charging protocol (see GTP' in GSM 12.15 / 32.295) */
Harald Weltebed35df2011-11-02 13:06:18 +010090#define GTPIE_CHARGING_ID 127 /* Charging ID 4 */
91#define GTPIE_EUA 128 /* End User Address */
92#define GTPIE_MM_CONTEXT 129 /* MM Context */
93#define GTPIE_PDP_CONTEXT 130 /* PDP Context */
94#define GTPIE_APN 131 /* Access Point Name */
95#define GTPIE_PCO 132 /* Protocol Configuration Options */
96#define GTPIE_GSN_ADDR 133 /* GSN Address */
97#define GTPIE_MSISDN 134 /* MS International PSTN/ISDN Number */
98#define GTPIE_QOS_PROFILE 135 /* Quality of Service Profile */
99#define GTPIE_AUTH_QUINTUP 136 /* Authentication Quintuplet */
100#define GTPIE_TFT 137 /* Traffic Flow Template */
101#define GTPIE_TARGET_INF 138 /* Target Identification */
102#define GTPIE_UTRAN_TRANS 139 /* UTRAN Transparent Container */
103#define GTPIE_RAB_SETUP 140 /* RAB Setup Information */
104#define GTPIE_EXT_HEADER_T 141 /* Extension Header Type List */
105#define GTPIE_TRIGGER_ID 142 /* Trigger Id */
106#define GTPIE_OMC_ID 143 /* OMC Identity */
Harald Weltebc41c8d2017-10-09 10:15:04 +0800107#define GTPIE_RAN_T_CONTAIN 144 /* RAN Transparent Container */
108#define GTPIE_PDP_CTX_PRIO 145 /* PDP Context Prioritization */
109#define GTPIE_ADDL_RAB_S_I 146 /* Additional RAB Setup Information */
110#define GTPIE_SGSN_NUMBER 147 /* SGSN Number */
Harald Welte89e1abc2017-10-08 07:50:20 +0800111#define GTPIE_COMMON_FLAGS 148 /* Common Flags */
Harald Weltebc41c8d2017-10-09 10:15:04 +0800112#define GTPIE_APN_RESTR 149 /* APN Restriction */
113#define GTPIE_R_PRIO_LCS 150 /* Radio Priority LCS */
Harald Weltebed35df2011-11-02 13:06:18 +0100114#define GTPIE_RAT_TYPE 151 /* Radio Access Technology Type */
115#define GTPIE_USER_LOC 152 /* User Location Information */
116#define GTPIE_MS_TZ 153 /* MS Time Zone */
117#define GTPIE_IMEI_SV 154 /* IMEI Software Version */
Harald Weltebc41c8d2017-10-09 10:15:04 +0800118#define GTPIE_CML_CHG_I_CT 155 /* CAMEL Charging Information Container */
119#define GTPIE_MBMS_UE_CTX 156 /* MSMS UE Context */
120#define GTPIE_TMGI 157 /* Temporary Mobile Group Identity (TMGI) */
121#define GTPIE_RIM_ROUT_ADDR 158 /* RIM Routing Address */
122#define GTPIE_MBMS_PCO 159 /* MBMS Protocol Configuratin Options */
123#define GTPIE_MBMS_SA 160 /* MBMS Service Area */
124#define GTPIE_SRNC_PDCP_CTX 161 /* Source RNC PDCP Context Info */
125#define GTPIE_ADDL_TRACE 162 /* Additional Trace Info */
126#define GTPIE_HOP_CTR 163 /* Hop Counter */
127#define GTPIE_SEL_PLMN_ID 164 /* Selected PLMN ID */
128#define GTPIE_MBMS_SESS_ID 165 /* MBMS Session Identifier */
129#define GTPIE_MBMS_2_3G_IND 166 /* MBMS 2G/3G Indicator */
130#define GTPIE_ENH_NSAPI 167 /* Enhanced NSAPI */
131#define GTPIE_MBMS_SESS_DUR 168 /* MBMS Session Duration */
132#define GTPIE_A_MBMS_TRAC_I 169 /* Additional MBMS Trace Info */
133#define GTPIE_MBMS_S_REP_N 170 /* MBMS Session Repetition Number */
134#define GTPIE_MBMS_TTDT 171 /* MBMS Time To Data Transfer */
135#define GTPIE_PS_HO_REQ_CTX 172 /* PS Handover Request Context */
136#define GTPIE_BSS_CONTAINER 173 /* BSS Container */
137#define GTPIE_CELL_ID 174 /* Cell Identification */
138#define GTPIE_PDU_NUMBERS 175 /* PDU Numbers */
139#define GTPIE_BSSGP_CAUSE 176 /* BSSGP Cause */
140#define GTPIE_RQD_MBMS_BCAP 177 /* Required MBMS Bearer Capabilities */
141#define GTPIE_RIM_RA_DISCR 178 /* RIM Routing Address Discriminator */
142#define GTPIE_L_SETUP_PFCS 179 /* List of set-up PFCs */
143#define GTPIE_PS_HO_XID_PAR 180 /* PS Handover XID Parameters */
144#define GTPIE_MS_CHG_REP_A 181 /* MS Info Change Reporting Action */
145#define GTPIE_DIR_TUN_FLAGS 182 /* Direct Tunnel Flags */
146#define GTPIE_CORREL_ID 183 /* Correlation-ID */
BJovke03dbafb2016-09-15 13:41:41 +0200147#define GTPIE_BCM 184 /* Bearer control mode */
Harald Weltebc41c8d2017-10-09 10:15:04 +0800148#define GTPIE_MBMS_FLOWI 185 /* MBMS Flow Identifier */
149#define GTPIE_MBMS_MC_DIST 186 /* MBMS IP Multicast Distribution */
150#define GTPIE_MBMS_DIST_ACK 187 /* MBMS Distribution Acknowledgement */
151#define GTPIE_R_IRAT_HO_INF 188 /* Reliable INTER RAT HANDOVER INFO */
152#define GTPIE_RFSP_IDX 189 /* RFSP Index */
153#define GTPIE_FQDN 190 /* FQDN */
154#define GTPIE_E_ALL_PRIO_1 191 /* Evolvd Allocation/Retention Priority I */
155#define GTPIE_E_ALL_PRIO_2 192 /* Evolvd Allocation/Retention Priority II */
156#define GTPIE_E_CMN_FLAGS 193 /* Extended Common Flags */
157#define GTPIE_U_CSG_INFO 194 /* User CSG Information (UCI) */
158#define GTPIE_CSG_I_REP_ACT 195 /* CSG Information Reporting Action */
159#define GTPIE_CSG_ID 196 /* CSG ID */
160#define GTPIE_CSG_MEMB_IND 197 /* CSG Membership Indication (CMI) */
161#define GTPIE_AMBR 198 /* Aggregate Maximum Bit Rate (AMBR) */
162#define GTPIE_UE_NET_CAPA 199 /* UE Network Capability */
163#define GTPIE_UE_AMBR 200 /* UE-AMBR */
164#define GTPIE_APN_AMBR_NS 201 /* APN-AMBR with NSAPI */
165#define GTPIE_GGSN_BACKOFF 202 /* GGSN Back-Off Time */
166#define GTPIE_S_PRIO_IND 203 /* Signalling Priority Indication */
167#define GTPIE_S_PRIO_IND_NS 204 /* Signalling Priority Indication with NSAPI */
168#define GTPIE_H_BR_16MBPS_F 205 /* Higher Bitrates than 16 Mbps flag */
169/* 206: Reserved */
170#define GTPIE_A_MMCTX_SRVCC 207 /* Additional MM context for SRVCC */
171#define GTPIE_A_FLAGS_SRVCC 208 /* Additional flags fro SRVC */
172#define GTPIE_STN_SR 209 /* STN-SR */
173#define GTPIE_C_MSISDN 210 /* C-MSISDN */
174#define GTPIE_E_RANAP_CAUSE 211 /* Extended RANAP Cause */
175#define GTPIE_ENODEB_ID 212 /* eNodeB ID */
176#define GTPIE_SEL_MODE_NS 213 /* Selection Mode with NSAPI */
177#define GTPIE_ULI_TIMESTAMP 214 /* ULI Timestamp */
178/* 215-238 Spare. For future use */
179/* 239-250 Reserved for the GPRS charging protocol (see GTP' in GSM 12.15 / 32.295) */
Harald Weltebed35df2011-11-02 13:06:18 +0100180#define GTPIE_CHARGING_ADDR 251 /* Charging Gateway Address */
Harald Weltebc41c8d2017-10-09 10:15:04 +0800181/* 252-254 Reserved for the GPRS charging protocol (see GTP' in GSM 12.15 / 32.295) */
Harald Weltebed35df2011-11-02 13:06:18 +0100182#define GTPIE_PRIVATE 255 /* Private Extension */
jjako52c24142002-12-16 13:33:51 +0000183
184/* GTP information element structs in network order */
Harald Weltebed35df2011-11-02 13:06:18 +0100185struct gtpie_ext { /* Extension header */
186 uint8_t t; /* Type */
187 uint8_t l; /* Length */
188 uint8_t *p; /* Value */
189} __attribute__ ((packed));
jjako52c24142002-12-16 13:33:51 +0000190
Harald Weltebed35df2011-11-02 13:06:18 +0100191struct gtpie_tlv { /* Type length value pair */
192 uint8_t t; /* Type */
193 uint16_t l; /* Length */
194 uint8_t v[GTPIE_MAX_TLV]; /* Value */
195} __attribute__ ((packed));
jjako52c24142002-12-16 13:33:51 +0000196
Harald Weltebed35df2011-11-02 13:06:18 +0100197struct gtpie_tv0 { /* 1 byte type value pair */
198 uint8_t t; /* Type */
199 uint8_t v[GTPIE_MAX_TV]; /* Pointer to value */
200} __attribute__ ((packed));
jjako52c24142002-12-16 13:33:51 +0000201
Harald Weltebed35df2011-11-02 13:06:18 +0100202struct gtpie_tv1 { /* 1 byte type value pair */
203 uint8_t t; /* Type */
204 uint8_t v; /* Value */
205} __attribute__ ((packed));
jjako52c24142002-12-16 13:33:51 +0000206
Harald Weltebed35df2011-11-02 13:06:18 +0100207struct gtpie_tv2 { /* 2 byte type value pair */
208 uint8_t t; /* Type */
209 uint16_t v; /* Value */
210} __attribute__ ((packed));
jjako52c24142002-12-16 13:33:51 +0000211
Harald Weltebed35df2011-11-02 13:06:18 +0100212struct gtpie_tv4 { /* 4 byte type value pair */
213 uint8_t t; /* Type */
214 uint32_t v; /* Value */
215} __attribute__ ((packed));
jjako52c24142002-12-16 13:33:51 +0000216
Harald Weltebed35df2011-11-02 13:06:18 +0100217struct gtpie_tv8 { /* 8 byte type value pair */
218 uint8_t t; /* Type */
219 uint64_t v; /* Value */
220} __attribute__ ((packed));
jjako52c24142002-12-16 13:33:51 +0000221
222union gtpie_member {
Harald Weltebed35df2011-11-02 13:06:18 +0100223 uint8_t t;
224 struct gtpie_ext ext;
225 struct gtpie_tlv tlv;
226 struct gtpie_tv0 tv0;
227 struct gtpie_tv1 tv1;
228 struct gtpie_tv2 tv2;
229 struct gtpie_tv4 tv4;
230 struct gtpie_tv8 tv8;
231} __attribute__ ((packed));
jjako52c24142002-12-16 13:33:51 +0000232
233/*
234cause
235imsi
236rai
237tlli
238p_tmsi
239qos_profile0
240reorder
241auth
242map_cause
243p_tmsi_s
244ms_validated
245recovery
246selection_mode
247tei_di
248tei_c
249tei_dii
250teardown
251nsapi
252ranap_cause
253rab_context
254rp_sms
255rp
256pfi
257charging_c
258trace_ref
259trace_type
260ms_not_reach
261charging_id
262eua
263mm_context
264pdp_context
265apn
266pco
267gsn_addr
268msisdn
269qos_profile
270auth
271tft
272target_inf
273utran_trans
274rab_setup
275ext_header_t
276trigger_id
277omc_id
278charging_addr
279private
280*/
281
282struct tlv1 {
Harald Weltebed35df2011-11-02 13:06:18 +0100283 uint8_t type;
284 uint8_t length;
285} __attribute__ ((packed));
jjako52c24142002-12-16 13:33:51 +0000286
287struct tlv2 {
Harald Weltebed35df2011-11-02 13:06:18 +0100288 uint8_t type;
289 uint16_t length;
290} __attribute__ ((packed));
jjako52c24142002-12-16 13:33:51 +0000291
Harald Weltef54a1f42010-05-04 11:08:38 +0200292extern int gtpie_tlv(void *p, unsigned int *length, unsigned int size,
Harald Welte02af9b32017-10-13 05:04:33 +0200293 uint8_t t, int l, const void *v);
Harald Weltebed35df2011-11-02 13:06:18 +0100294extern int gtpie_tv0(void *p, unsigned int *length, unsigned int size,
Harald Welte02af9b32017-10-13 05:04:33 +0200295 uint8_t t, int l, const uint8_t * v);
Harald Weltebed35df2011-11-02 13:06:18 +0100296extern int gtpie_tv1(void *p, unsigned int *length, unsigned int size,
297 uint8_t t, uint8_t v);
298extern int gtpie_tv2(void *p, unsigned int *length, unsigned int size,
299 uint8_t t, uint16_t v);
300extern int gtpie_tv4(void *p, unsigned int *length, unsigned int size,
301 uint8_t t, uint32_t v);
302extern int gtpie_tv8(void *p, unsigned int *length, unsigned int size,
303 uint8_t t, uint64_t v);
304extern int gtpie_getie(union gtpie_member *ie[], int type, int instance);
305extern int gtpie_exist(union gtpie_member *ie[], int type, int instance);
306extern int gtpie_gettlv(union gtpie_member *ie[], int type, int instance,
Harald Weltef54a1f42010-05-04 11:08:38 +0200307 unsigned int *length, void *dst, unsigned int size);
Harald Weltebed35df2011-11-02 13:06:18 +0100308extern int gtpie_gettv0(union gtpie_member *ie[], int type, int instance,
Harald Weltef54a1f42010-05-04 11:08:38 +0200309 void *dst, unsigned int size);
Harald Weltebed35df2011-11-02 13:06:18 +0100310extern int gtpie_gettv1(union gtpie_member *ie[], int type, int instance,
311 uint8_t * dst);
312extern int gtpie_gettv2(union gtpie_member *ie[], int type, int instance,
313 uint16_t * dst);
314extern int gtpie_gettv4(union gtpie_member *ie[], int type, int instance,
315 uint32_t * dst);
316extern int gtpie_gettv8(union gtpie_member *ie[], int type, int instance,
317 uint64_t * dst);
jjako52c24142002-12-16 13:33:51 +0000318
Harald Weltebed35df2011-11-02 13:06:18 +0100319extern int gtpie_decaps(union gtpie_member *ie[], int version,
Harald Weltea9640272017-10-13 12:06:08 +0200320 const void *pack, unsigned len);
Harald Weltebed35df2011-11-02 13:06:18 +0100321extern int gtpie_encaps(union gtpie_member *ie[], void *pack, unsigned *len);
Harald Weltef54a1f42010-05-04 11:08:38 +0200322extern int gtpie_encaps2(union gtpie_member ie[], unsigned int size,
Harald Weltebed35df2011-11-02 13:06:18 +0100323 void *pack, unsigned *len);
jjako52c24142002-12-16 13:33:51 +0000324
Harald Weltebed35df2011-11-02 13:06:18 +0100325#endif /* !_GTPIE_H */