blob: 106d5443e5dc8961495bde11aa03067bc347b2ce [file] [log] [blame]
jjako52c24142002-12-16 13:33:51 +00001/*
Harald Welte632e8432017-09-05 18:12:14 +02002 * OsmoGGSN - Gateway GPRS Support Node
jjakoa7cd2492003-04-11 09:40:12 +00003 * Copyright (C) 2002, 2003 Mondru AB.
Harald Welte632e8432017-09-05 18:12:14 +02004 * Copyright (C) 2017 Harald Welte <laforge@gnumonks.org>
jjako52c24142002-12-16 13:33:51 +00005 *
6 * The contents of this file may be used under the terms of the GNU
7 * General Public License Version 2, provided that the above copyright
8 * notice and this permission notice is included in all copies or
9 * substantial portions of the software.
10 *
jjako52c24142002-12-16 13:33:51 +000011 */
12
13#ifndef _PDP_H
14#define _PDP_H
15
Harald Welte3c1cce22017-09-24 16:40:12 +080016#include <stdbool.h>
17
Harald Weltee257be12017-08-12 14:55:09 +020018struct gsn_t;
19
Max6a215272017-09-25 10:35:34 +020020#define LOGPDPX(ss, level, pdp, fmt, args...) \
21 LOGP(ss, level, "PDP(%s:%u): " fmt, imsi_gtp2str(&(pdp)->imsi), (pdp)->nsapi, ## args)
22
Harald Weltebed35df2011-11-02 13:06:18 +010023#define PDP_MAX 1024 /* Max number of PDP contexts */
24#define PDP_MAXNSAPI 16 /* Max number of NSAPI */
jjako52c24142002-12-16 13:33:51 +000025
jjako52c24142002-12-16 13:33:51 +000026/* GTP Information elements from 29.060 v3.9.0 7.7 Information Elements */
27/* Also covers version 0. Note that version 0 6: QOS Profile was superceded *
28 * by 135: QOS Profile in version 1 */
29
jjako52c24142002-12-16 13:33:51 +000030struct sl_t {
Harald Weltebed35df2011-11-02 13:06:18 +010031 unsigned int l;
32 char *v;
jjako52c24142002-12-16 13:33:51 +000033};
34
35struct ul_t {
Harald Weltebed35df2011-11-02 13:06:18 +010036 unsigned int l;
37 unsigned char *v;
jjako52c24142002-12-16 13:33:51 +000038};
39
40struct ul16_t {
Harald Weltebed35df2011-11-02 13:06:18 +010041 unsigned int l;
42 unsigned char v[16];
jjako52c24142002-12-16 13:33:51 +000043};
44
45struct ul66_t {
Harald Weltebed35df2011-11-02 13:06:18 +010046 unsigned int l;
47 unsigned char v[66];
jjako52c24142002-12-16 13:33:51 +000048};
49
50struct ul255_t {
Harald Weltebed35df2011-11-02 13:06:18 +010051 unsigned int l;
52 unsigned char v[255];
jjako52c24142002-12-16 13:33:51 +000053};
54
jjako2c381332003-10-21 19:09:53 +000055/* *****************************************************************
jjako52c24142002-12-16 13:33:51 +000056 * Information storage for each PDP context
57 *
jjako2c381332003-10-21 19:09:53 +000058 * Information storage for each PDP context is defined in 23.060
59 * section 13.3 and 03.60. Includes IMSI, MSISDN, APN, PDP-type,
60 * PDP-address (IP address), sequence numbers, charging ID. For the
61 * SGSN it also includes radio related mobility information.
62 *
63 * The following structure is a combination of the storage
64 * requirements for each PDP context for the GGSN and SGSN. It
65 * contains both 23.060 as well as 03.60 parameters. Information is
66 * stored in the format for information elements described in 29.060
67 * and 09.60.
jjako52c24142002-12-16 13:33:51 +000068 * 31 * 4 + 15 structs + = 120 + 15 structs ~ 2k / context
69 * Structs: IP address 16+4 bytes (6), APN 255 bytes (2)
70 * QOS: 255 bytes (3), msisdn 16 bytes (1),
71 *
72 * TODO: We need to consider who manages the pdp_t hash tables
73 * Is it gtp_lib, or is it the application?
74 * I suppose that it will be gtp_lib.
75 * SGSN will ask gtplib for new pdp_t. Fill out the fields,
76 * and pass it on to gtp_create_pdp_req.
77 * GGSN will receive gtp_create_pdp_ind, create new pdp_t and
78 * send responce to SGSN.
79 * SGSN will receive response and gtplib will find the
80 * original pdp_t corresponding to the request. This will be
81 * passed on to the application.
82 * Eventually the SGSN will close the connection, and the
83 * pdp_t will be freed by gtplib in SGSN and GGSN
84 * This means that gtplib need to have functions to
85 * allocate, free, sort and find pdp_t
86 * (newpdp, freepdp, getpdp)
87 * Hash tables: TID, IMSI, IP etc.)
jjako2c381332003-10-21 19:09:53 +000088 *
89 *
90 * Secondary PDP Context Activation Procedure
91 *
92 * With GTP version 1 it is possible to establish multiple PDP
93 * contexts with the same IP address. With this scheme the first
94 * context is established as normal. Following contexts are
95 * established by referencing one of the allready existing ones. Each
96 * context is uniquely identified by IMSI and NSAPI. Each context is
97 * allocated an tei_di, but they all share the same tei_c.
98 *
99 * For Delete PDP Context the context is referenced by tei_c and
100 * nsapi. As an option it is possible to include a teardown indicater,
101 * in which case all PDP contexts with the same tei_c (IP address) are
102 * deleted.
103 *
104 * For Update PDP Context the context is normally referenced by tei_c
105 * and nsapi. If moving from GTP0 to GTP1 during an update the context
106 * is referenced instead by IMSI and NSAPI.
107 *****************************************************************/
jjako52c24142002-12-16 13:33:51 +0000108
109struct pdp_t {
Harald Weltebed35df2011-11-02 13:06:18 +0100110 /* Parameter determining if this PDP is in use. */
111 uint8_t inuse; /* 0=free. 1=used by somebody */
jjako52c24142002-12-16 13:33:51 +0000112
Harald Weltebed35df2011-11-02 13:06:18 +0100113 /* Pointers related to hash tables */
114 struct pdp_t *tidnext;
115 struct pdp_t *ipnext;
jjako52c24142002-12-16 13:33:51 +0000116
Harald Weltebed35df2011-11-02 13:06:18 +0100117 /* Parameters shared by all PDP context belonging to the same MS */
jjako52c24142002-12-16 13:33:51 +0000118
Harald Weltebed35df2011-11-02 13:06:18 +0100119 void *ipif; /* IP network interface */
120 void *peer; /* Pointer to peer protocol */
121 void *asap; /* Application specific service access point */
jjako52c24142002-12-16 13:33:51 +0000122
Harald Weltebed35df2011-11-02 13:06:18 +0100123 uint64_t imsi; /* International Mobile Subscriber Identity. */
124 struct ul16_t msisdn; /* The basic MSISDN of the MS. */
125 uint8_t mnrg; /* Indicates whether the MS is marked as not reachable for PS at the HLR. (1 bit, not transmitted) */
126 uint8_t cch_sub; /* The charging characteristics for the MS, e.g. normal, prepaid, flat-rate, and/or hot billing subscription. (not transmitted) */
127 uint16_t traceref; /* Identifies a record or a collection of records for a particular trace. */
128 uint16_t tracetype; /* Indicates the type of trace. */
129 struct ul_t triggerid; /* Identifies the entity that initiated the trace. */
130 struct ul_t omcid; /* Identifies the OMC that shall receive the trace record(s). */
131 uint8_t rec_hlr; /* Indicates if HLR or VLR is performing database recovery. (1 bit, not transmitted) */
jjako52c24142002-12-16 13:33:51 +0000132
Harald Weltebed35df2011-11-02 13:06:18 +0100133 /* Parameters specific to each individual PDP context */
jjako52c24142002-12-16 13:33:51 +0000134
Harald Weltebed35df2011-11-02 13:06:18 +0100135 uint8_t pdp_id; /* Index of the PDP context. (PDP context identifier) */
136 uint8_t pdp_state; /* PDP State Packet data protocol state, INACTIVE or ACTIVE. (1 bit, not transmitted) */
137 /* struct ul_t pdp_type; * PDP type; e.g. PPP or IP. */
138 /* struct ul_t pdp_addr; * PDP address; e.g. an IP address. */
139 struct ul66_t eua; /* End user address. PDP type and address combined */
140 uint8_t pdp_dyn; /* Indicates whether PDP Address is static or dynamic. (1 bit, not transmitted) */
141 struct ul255_t apn_req; /* The APN requested. */
142 struct ul255_t apn_sub; /* The APN received from the HLR. */
143 struct ul255_t apn_use; /* The APN Network Identifier currently used. */
144 uint8_t nsapi; /* Network layer Service Access Point Identifier. (4 bit) */
145 uint16_t ti; /* Transaction Identifier. (4 or 12 bit) */
jjako52c24142002-12-16 13:33:51 +0000146
Harald Weltebed35df2011-11-02 13:06:18 +0100147 uint32_t teic_own; /* (Own Tunnel Endpoint Identifier Control) */
148 uint32_t teid_own; /* (Own Tunnel Endpoint Identifier Data I) */
149 uint32_t teic_gn; /* Tunnel Endpoint Identifier for the Gn and Gp interfaces. (Control plane) */
150 uint32_t teid_gn; /* Tunnel Endpoint Identifier for the Gn and Gp interfaces. (Data I) */
151 uint32_t tei_iu; /* Tunnel Endpoint Identifier for the Iu interface. */
jjako52c24142002-12-16 13:33:51 +0000152
Harald Weltebed35df2011-11-02 13:06:18 +0100153 uint16_t fllc; /* (Local Flow Label Control, gtp0) */
154 uint16_t fllu; /* (Local Flow Label Data I, gtp0) */
155 uint16_t flrc; /* (Remote gn/gp Flow Label Control, gtp0) */
156 uint16_t flru; /* (Remote gn/gp Flow Label Data I, gtp0) */
jjako52c24142002-12-16 13:33:51 +0000157
Harald Weltebed35df2011-11-02 13:06:18 +0100158 struct ul255_t tft; /* Traffic flow template. */
159 /*struct ul16_t sgsnc; * The IP address of the SGSN currently serving this MS. (Control plane) */
160 /*struct ul16_t sgsnu; * The IP address of the SGSN currently serving this MS. (User plane) */
161 /*struct ul16_t ggsnc; * The IP address of the GGSN currently used. (Control plane) */
162 /*struct ul16_t ggsnu; * The IP address of the GGSN currently used. (User plane) */
jjako52c24142002-12-16 13:33:51 +0000163
Harald Weltebed35df2011-11-02 13:06:18 +0100164 struct ul16_t gsnlc; /* The IP address of the local GSN. (Control plane) */
165 struct ul16_t gsnlu; /* The IP address of the local GSN. (User plane) */
166 struct ul16_t gsnrc; /* The IP address of the remote GSN. (Control plane) */
167 struct ul16_t gsnru; /* The IP address of the remote GSN. (User plane) */
jjako52c24142002-12-16 13:33:51 +0000168
Harald Weltebed35df2011-11-02 13:06:18 +0100169 uint8_t vplmn_allow; /* Specifies whether the MS is allowed to use the APN in the domain of the HPLMN only, or additionally the APN in the domain of the VPLMN. (1 bit) */
170 uint8_t qos_sub0[3]; /* The quality of service profile subscribed. */
171 uint8_t qos_req0[3]; /* The quality of service profile requested. */
172 uint8_t qos_neg0[3]; /* The quality of service profile negotiated. */
173 struct ul255_t qos_sub; /* The quality of service profile subscribed. */
174 struct ul255_t qos_req; /* The quality of service profile requested. */
175 struct ul255_t qos_neg; /* The quality of service profile negotiated. */
176 uint8_t radio_pri; /* The RLC/MAC radio priority level for uplink user data transmission. (4 bit) */
177 uint16_t flow_id; /* Packet flow identifier. */
178 /* struct ul_t bssqos_neg; * The aggregate BSS quality of service profile negotiated for the packet flow that this PDP context belongs to. (NOT GTP) */
179 uint8_t sndcpd; /* SNDCP sequence number of the next downlink N-PDU to be sent to the MS. */
180 uint8_t sndcpu; /* SNDCP sequence number of the next uplink N-PDU expected from the MS. */
181 uint8_t rec_sgsn; /* Indicates if the SGSN is performing database recovery. (1 bit, not transmitted) */
jjako52c24142002-12-16 13:33:51 +0000182/* uint16_t gtpsnd; GTP-U sequence number of the next downlink N-PDU to be sent to the SGSN / received from the GGSN. */
183/* uint16_t gtpsnu; GTP-U sequence number of the next uplink N-PDU to be received from the SGSN / sent to the GGSN */
Harald Weltebed35df2011-11-02 13:06:18 +0100184 uint16_t gtpsntx; /* GTP-U sequence number of the next downlink N-PDU to be sent (09.60 section 8.1.1.1) */
185 uint16_t gtpsnrx; /* GTP-U sequence number of the next uplink N-PDU to be received (09.60 section 8.1.1.1) */
186 uint8_t pdcpsndd; /* Sequence number of the next downlink in-sequence PDCP-PDU to be sent to the MS. */
187 uint8_t pdcpsndu; /* Sequence number of the next uplink in-sequence PDCP-PDU expected from the MS. */
188 uint32_t cid; /* Charging identifier, identifies charging records generated by SGSN and GGSN. */
189 uint16_t cch_pdp; /* The charging characteristics for this PDP context, e.g. normal, prepaid, flat-rate, and/or hot billing. */
190 struct ul16_t rnc_addr; /* The IP address of the RNC currently used. */
191 uint8_t reorder; /* Specifies whether the GGSN shall reorder N-PDUs received from the SGSN / Specifies whether the SGSN shall reorder N-PDUs before delivering the N-PSUs to the MS. (1 bit) */
192 struct ul255_t pco_req; /* Requested packet control options. */
193 struct ul255_t pco_neg; /* Negotiated packet control options. */
194 uint32_t selmode; /* Selection mode. */
195 struct ul255_t rattype; /* Radio Access Technology Type */
196 int rattype_given; /* Radio Access Technology Type given */
197 struct ul255_t userloc; /* User Location Information */
198 int userloc_given; /* User Location Information given */
199 struct ul255_t rai; /* Routing Area Information */
200 int rai_given; /* Routing Area Information given */
201 struct ul255_t mstz; /* MS Time Zone */
202 int mstz_given; /* MS Time Zone given */
203 struct ul255_t imeisv; /* IMEI Software Version */
204 int imeisv_given; /* IMEI Software Version given */
205 int norecovery_given; /* norecovery given */
jjako08d331d2003-10-13 20:33:30 +0000206
Harald Weltebed35df2011-11-02 13:06:18 +0100207 /* Additional parameters used by library */
jjako08d331d2003-10-13 20:33:30 +0000208
Harald Weltebed35df2011-11-02 13:06:18 +0100209 int version; /* Protocol version currently in use. 0 or 1 */
jjako08d331d2003-10-13 20:33:30 +0000210
Harald Weltebed35df2011-11-02 13:06:18 +0100211 uint64_t tid; /* Combination of imsi and nsapi */
212 uint16_t seq; /* Sequence number of last request */
213 struct sockaddr_in sa_peer; /* Address of last request */
214 int fd; /* File descriptor request was received on */
jjako2c381332003-10-21 19:09:53 +0000215
Harald Weltebed35df2011-11-02 13:06:18 +0100216 uint8_t teic_confirmed; /* 0: Not confirmed. 1: Confirmed */
jjako2c381332003-10-21 19:09:53 +0000217
Harald Weltebed35df2011-11-02 13:06:18 +0100218 /* Parameters used for secondary activation procedure (tei data) */
219 /* If (secondary == 1) then teic_own indicates linked PDP context */
220 uint8_t secondary; /* 0: Primary (control). 1: Secondary (data only) */
221 uint8_t nodata; /* 0: User plane PDP context. 1: No user plane */
jjako2c381332003-10-21 19:09:53 +0000222
Harald Weltebed35df2011-11-02 13:06:18 +0100223 /* Secondary contexts of this primary context */
224 uint32_t secondary_tei[PDP_MAXNSAPI];
jjako193e8b12003-11-10 12:31:41 +0000225
Harald Weltebed35df2011-11-02 13:06:18 +0100226 /* IP address used for Create and Update PDP Context Requests */
227 struct in_addr hisaddr0; /* Server address */
228 struct in_addr hisaddr1; /* Server address */
jjako193e8b12003-11-10 12:31:41 +0000229
Harald Weltebed35df2011-11-02 13:06:18 +0100230 /* to be used by libgtp callers/users (to attach their own private state) */
231 void *priv;
Harald Weltee257be12017-08-12 14:55:09 +0200232
233 struct gsn_t *gsn;
Harald Welte3c1cce22017-09-24 16:40:12 +0800234
235 bool tx_gpdu_seq; /* Transmit (true) or suppress G-PDU sequence numbers */
jjako52c24142002-12-16 13:33:51 +0000236};
237
jjako52c24142002-12-16 13:33:51 +0000238/* functions related to pdp_t management */
239int pdp_init();
240int pdp_newpdp(struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi,
241 struct pdp_t *pdp_old);
242int pdp_freepdp(struct pdp_t *pdp);
243int pdp_getpdp(struct pdp_t **pdp);
244
245int pdp_getgtp0(struct pdp_t **pdp, uint16_t fl);
jjako08d331d2003-10-13 20:33:30 +0000246int pdp_getgtp1(struct pdp_t **pdp, uint32_t tei);
Harald Welte37d5b152017-08-12 23:58:29 +0200247int pdp_getgtp1_peer_d(struct pdp_t **pdp, const struct sockaddr_in *peer, uint32_t teid_gn);
jjako08d331d2003-10-13 20:33:30 +0000248
249int pdp_getimsi(struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi);
jjako52c24142002-12-16 13:33:51 +0000250
251int pdp_tidhash(uint64_t tid);
252int pdp_tidset(struct pdp_t *pdp, uint64_t tid);
253int pdp_tiddel(struct pdp_t *pdp);
254int pdp_tidget(struct pdp_t **pdp, uint64_t tid);
255
Pablo Neira Ayuso746b9442014-03-24 17:58:27 +0100256void pdp_set_imsi_nsapi(struct pdp_t *pdp, uint64_t teid);
257
jjakoa7cd2492003-04-11 09:40:12 +0000258/*
jjako52c24142002-12-16 13:33:51 +0000259int pdp_iphash(void* ipif, struct ul66_t *eua);
260int pdp_ipset(struct pdp_t *pdp, void* ipif, struct ul66_t *eua);
261int pdp_ipdel(struct pdp_t *pdp);
262int pdp_ipget(struct pdp_t **pdp, void* ipif, struct ul66_t *eua);
jjakoa7cd2492003-04-11 09:40:12 +0000263*/
jjako52c24142002-12-16 13:33:51 +0000264
265int pdp_ntoeua(struct in_addr *src, struct ul66_t *eua);
jjakoa7cd2492003-04-11 09:40:12 +0000266int pdp_euaton(struct ul66_t *eua, struct in_addr *dst);
jjako52c24142002-12-16 13:33:51 +0000267uint64_t pdp_gettid(uint64_t imsi, uint8_t nsapi);
jjako52c24142002-12-16 13:33:51 +0000268
Harald Weltebed35df2011-11-02 13:06:18 +0100269#endif /* !_PDP_H */