blob: fdfa824688ba4708a4810f5179a44c971e22cd4c [file] [log] [blame]
Pau Espin Pedrol5f5fcff2018-01-25 18:09:02 +01001/*
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>
Pau Espin Pedrol5f5fcff2018-01-25 18:09:02 +01005 *
jjako52c24142002-12-16 13:33:51 +00006 * 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.
Pau Espin Pedrol5f5fcff2018-01-25 18:09:02 +010010 *
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>
Pau Espin Pedrol8b90bce2019-06-20 17:06:13 +020017#include <netinet/in.h>
Harald Welte3c1cce22017-09-24 16:40:12 +080018
Pau Espin Pedroleefa30d2019-05-31 15:42:49 +020019#include <osmocom/core/defs.h>
Pau Espin Pedrol05ec2b32019-08-16 13:20:09 +020020#include <osmocom/core/linuxlist.h>
Pau Espin Pedroleefa30d2019-05-31 15:42:49 +020021
Harald Weltee257be12017-08-12 14:55:09 +020022struct gsn_t;
23
Max6a215272017-09-25 10:35:34 +020024#define LOGPDPX(ss, level, pdp, fmt, args...) \
25 LOGP(ss, level, "PDP(%s:%u): " fmt, imsi_gtp2str(&(pdp)->imsi), (pdp)->nsapi, ## args)
26
Harald Weltebed35df2011-11-02 13:06:18 +010027#define PDP_MAX 1024 /* Max number of PDP contexts */
28#define PDP_MAXNSAPI 16 /* Max number of NSAPI */
jjako52c24142002-12-16 13:33:51 +000029
Harald Weltecee75462017-09-24 17:45:05 +080030#define PDP_EUA_ORG_IETF 0xF1
31#define PDP_EUA_TYPE_v4 0x21
32#define PDP_EUA_TYPE_v6 0x57
Pau Espin Pedrol2d6a69e2017-12-06 19:26:25 +010033#define PDP_EUA_TYPE_v4v6 0x8D
Harald Weltecee75462017-09-24 17:45:05 +080034
jjako52c24142002-12-16 13:33:51 +000035/* GTP Information elements from 29.060 v3.9.0 7.7 Information Elements */
36/* Also covers version 0. Note that version 0 6: QOS Profile was superceded *
37 * by 135: QOS Profile in version 1 */
38
jjako52c24142002-12-16 13:33:51 +000039struct sl_t {
Harald Weltebed35df2011-11-02 13:06:18 +010040 unsigned int l;
41 char *v;
jjako52c24142002-12-16 13:33:51 +000042};
43
44struct ul_t {
Harald Weltebed35df2011-11-02 13:06:18 +010045 unsigned int l;
46 unsigned char *v;
jjako52c24142002-12-16 13:33:51 +000047};
48
49struct ul16_t {
Harald Weltebed35df2011-11-02 13:06:18 +010050 unsigned int l;
51 unsigned char v[16];
jjako52c24142002-12-16 13:33:51 +000052};
53
54struct ul66_t {
Harald Weltebed35df2011-11-02 13:06:18 +010055 unsigned int l;
56 unsigned char v[66];
jjako52c24142002-12-16 13:33:51 +000057};
58
59struct ul255_t {
Harald Weltebed35df2011-11-02 13:06:18 +010060 unsigned int l;
61 unsigned char v[255];
jjako52c24142002-12-16 13:33:51 +000062};
63
jjako2c381332003-10-21 19:09:53 +000064/* *****************************************************************
jjako52c24142002-12-16 13:33:51 +000065 * Information storage for each PDP context
66 *
jjako2c381332003-10-21 19:09:53 +000067 * Information storage for each PDP context is defined in 23.060
68 * section 13.3 and 03.60. Includes IMSI, MSISDN, APN, PDP-type,
69 * PDP-address (IP address), sequence numbers, charging ID. For the
70 * SGSN it also includes radio related mobility information.
71 *
72 * The following structure is a combination of the storage
73 * requirements for each PDP context for the GGSN and SGSN. It
74 * contains both 23.060 as well as 03.60 parameters. Information is
75 * stored in the format for information elements described in 29.060
76 * and 09.60.
jjako52c24142002-12-16 13:33:51 +000077 * 31 * 4 + 15 structs + = 120 + 15 structs ~ 2k / context
78 * Structs: IP address 16+4 bytes (6), APN 255 bytes (2)
Pau Espin Pedrol5f5fcff2018-01-25 18:09:02 +010079 * QOS: 255 bytes (3), msisdn 16 bytes (1),
jjako52c24142002-12-16 13:33:51 +000080 *
81 * TODO: We need to consider who manages the pdp_t hash tables
82 * Is it gtp_lib, or is it the application?
Pau Espin Pedrol5f5fcff2018-01-25 18:09:02 +010083 * I suppose that it will be gtp_lib.
jjako52c24142002-12-16 13:33:51 +000084 * SGSN will ask gtplib for new pdp_t. Fill out the fields,
85 * and pass it on to gtp_create_pdp_req.
86 * GGSN will receive gtp_create_pdp_ind, create new pdp_t and
87 * send responce to SGSN.
Pau Espin Pedrol5f5fcff2018-01-25 18:09:02 +010088 * SGSN will receive response and gtplib will find the
jjako52c24142002-12-16 13:33:51 +000089 * original pdp_t corresponding to the request. This will be
90 * passed on to the application.
91 * Eventually the SGSN will close the connection, and the
92 * pdp_t will be freed by gtplib in SGSN and GGSN
93 * This means that gtplib need to have functions to
94 * allocate, free, sort and find pdp_t
95 * (newpdp, freepdp, getpdp)
Pau Espin Pedrol5f5fcff2018-01-25 18:09:02 +010096 * Hash tables: TID, IMSI, IP etc.)
jjako2c381332003-10-21 19:09:53 +000097 *
98 *
Pau Espin Pedrol5f5fcff2018-01-25 18:09:02 +010099 * Secondary PDP Context Activation Procedure
jjako2c381332003-10-21 19:09:53 +0000100 *
101 * With GTP version 1 it is possible to establish multiple PDP
102 * contexts with the same IP address. With this scheme the first
103 * context is established as normal. Following contexts are
104 * established by referencing one of the allready existing ones. Each
105 * context is uniquely identified by IMSI and NSAPI. Each context is
106 * allocated an tei_di, but they all share the same tei_c.
107 *
108 * For Delete PDP Context the context is referenced by tei_c and
109 * nsapi. As an option it is possible to include a teardown indicater,
110 * in which case all PDP contexts with the same tei_c (IP address) are
111 * deleted.
112 *
113 * For Update PDP Context the context is normally referenced by tei_c
114 * and nsapi. If moving from GTP0 to GTP1 during an update the context
115 * is referenced instead by IMSI and NSAPI.
116 *****************************************************************/
jjako52c24142002-12-16 13:33:51 +0000117
118struct pdp_t {
Harald Weltebed35df2011-11-02 13:06:18 +0100119 /* Parameter determining if this PDP is in use. */
120 uint8_t inuse; /* 0=free. 1=used by somebody */
jjako52c24142002-12-16 13:33:51 +0000121
Harald Weltebed35df2011-11-02 13:06:18 +0100122 /* Pointers related to hash tables */
123 struct pdp_t *tidnext;
124 struct pdp_t *ipnext;
jjako52c24142002-12-16 13:33:51 +0000125
Harald Weltebed35df2011-11-02 13:06:18 +0100126 /* Parameters shared by all PDP context belonging to the same MS */
jjako52c24142002-12-16 13:33:51 +0000127
Harald Weltebed35df2011-11-02 13:06:18 +0100128 void *ipif; /* IP network interface */
Pau Espin Pedrol2d6a69e2017-12-06 19:26:25 +0100129 void *peer[2]; /* Pointer to peer protocol */
Harald Weltebed35df2011-11-02 13:06:18 +0100130 void *asap; /* Application specific service access point */
jjako52c24142002-12-16 13:33:51 +0000131
Harald Weltebed35df2011-11-02 13:06:18 +0100132 uint64_t imsi; /* International Mobile Subscriber Identity. */
133 struct ul16_t msisdn; /* The basic MSISDN of the MS. */
134 uint8_t mnrg; /* Indicates whether the MS is marked as not reachable for PS at the HLR. (1 bit, not transmitted) */
135 uint8_t cch_sub; /* The charging characteristics for the MS, e.g. normal, prepaid, flat-rate, and/or hot billing subscription. (not transmitted) */
136 uint16_t traceref; /* Identifies a record or a collection of records for a particular trace. */
137 uint16_t tracetype; /* Indicates the type of trace. */
138 struct ul_t triggerid; /* Identifies the entity that initiated the trace. */
139 struct ul_t omcid; /* Identifies the OMC that shall receive the trace record(s). */
140 uint8_t rec_hlr; /* Indicates if HLR or VLR is performing database recovery. (1 bit, not transmitted) */
jjako52c24142002-12-16 13:33:51 +0000141
Harald Weltebed35df2011-11-02 13:06:18 +0100142 /* Parameters specific to each individual PDP context */
jjako52c24142002-12-16 13:33:51 +0000143
Harald Weltebed35df2011-11-02 13:06:18 +0100144 uint8_t pdp_id; /* Index of the PDP context. (PDP context identifier) */
145 uint8_t pdp_state; /* PDP State Packet data protocol state, INACTIVE or ACTIVE. (1 bit, not transmitted) */
146 /* struct ul_t pdp_type; * PDP type; e.g. PPP or IP. */
147 /* struct ul_t pdp_addr; * PDP address; e.g. an IP address. */
148 struct ul66_t eua; /* End user address. PDP type and address combined */
149 uint8_t pdp_dyn; /* Indicates whether PDP Address is static or dynamic. (1 bit, not transmitted) */
150 struct ul255_t apn_req; /* The APN requested. */
151 struct ul255_t apn_sub; /* The APN received from the HLR. */
152 struct ul255_t apn_use; /* The APN Network Identifier currently used. */
153 uint8_t nsapi; /* Network layer Service Access Point Identifier. (4 bit) */
154 uint16_t ti; /* Transaction Identifier. (4 or 12 bit) */
jjako52c24142002-12-16 13:33:51 +0000155
Harald Weltebed35df2011-11-02 13:06:18 +0100156 uint32_t teic_own; /* (Own Tunnel Endpoint Identifier Control) */
157 uint32_t teid_own; /* (Own Tunnel Endpoint Identifier Data I) */
158 uint32_t teic_gn; /* Tunnel Endpoint Identifier for the Gn and Gp interfaces. (Control plane) */
159 uint32_t teid_gn; /* Tunnel Endpoint Identifier for the Gn and Gp interfaces. (Data I) */
160 uint32_t tei_iu; /* Tunnel Endpoint Identifier for the Iu interface. */
jjako52c24142002-12-16 13:33:51 +0000161
Harald Weltebed35df2011-11-02 13:06:18 +0100162 uint16_t fllc; /* (Local Flow Label Control, gtp0) */
163 uint16_t fllu; /* (Local Flow Label Data I, gtp0) */
164 uint16_t flrc; /* (Remote gn/gp Flow Label Control, gtp0) */
165 uint16_t flru; /* (Remote gn/gp Flow Label Data I, gtp0) */
jjako52c24142002-12-16 13:33:51 +0000166
Harald Weltebed35df2011-11-02 13:06:18 +0100167 struct ul255_t tft; /* Traffic flow template. */
168 /*struct ul16_t sgsnc; * The IP address of the SGSN currently serving this MS. (Control plane) */
169 /*struct ul16_t sgsnu; * The IP address of the SGSN currently serving this MS. (User plane) */
170 /*struct ul16_t ggsnc; * The IP address of the GGSN currently used. (Control plane) */
171 /*struct ul16_t ggsnu; * The IP address of the GGSN currently used. (User plane) */
jjako52c24142002-12-16 13:33:51 +0000172
Harald Weltebed35df2011-11-02 13:06:18 +0100173 struct ul16_t gsnlc; /* The IP address of the local GSN. (Control plane) */
174 struct ul16_t gsnlu; /* The IP address of the local GSN. (User plane) */
175 struct ul16_t gsnrc; /* The IP address of the remote GSN. (Control plane) */
176 struct ul16_t gsnru; /* The IP address of the remote GSN. (User plane) */
jjako52c24142002-12-16 13:33:51 +0000177
Harald Weltebed35df2011-11-02 13:06:18 +0100178 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) */
179 uint8_t qos_sub0[3]; /* The quality of service profile subscribed. */
180 uint8_t qos_req0[3]; /* The quality of service profile requested. */
181 uint8_t qos_neg0[3]; /* The quality of service profile negotiated. */
182 struct ul255_t qos_sub; /* The quality of service profile subscribed. */
183 struct ul255_t qos_req; /* The quality of service profile requested. */
184 struct ul255_t qos_neg; /* The quality of service profile negotiated. */
185 uint8_t radio_pri; /* The RLC/MAC radio priority level for uplink user data transmission. (4 bit) */
186 uint16_t flow_id; /* Packet flow identifier. */
187 /* 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) */
188 uint8_t sndcpd; /* SNDCP sequence number of the next downlink N-PDU to be sent to the MS. */
189 uint8_t sndcpu; /* SNDCP sequence number of the next uplink N-PDU expected from the MS. */
190 uint8_t rec_sgsn; /* Indicates if the SGSN is performing database recovery. (1 bit, not transmitted) */
jjako52c24142002-12-16 13:33:51 +0000191/* uint16_t gtpsnd; GTP-U sequence number of the next downlink N-PDU to be sent to the SGSN / received from the GGSN. */
192/* 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 +0100193 uint16_t gtpsntx; /* GTP-U sequence number of the next downlink N-PDU to be sent (09.60 section 8.1.1.1) */
194 uint16_t gtpsnrx; /* GTP-U sequence number of the next uplink N-PDU to be received (09.60 section 8.1.1.1) */
195 uint8_t pdcpsndd; /* Sequence number of the next downlink in-sequence PDCP-PDU to be sent to the MS. */
196 uint8_t pdcpsndu; /* Sequence number of the next uplink in-sequence PDCP-PDU expected from the MS. */
197 uint32_t cid; /* Charging identifier, identifies charging records generated by SGSN and GGSN. */
198 uint16_t cch_pdp; /* The charging characteristics for this PDP context, e.g. normal, prepaid, flat-rate, and/or hot billing. */
199 struct ul16_t rnc_addr; /* The IP address of the RNC currently used. */
200 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) */
201 struct ul255_t pco_req; /* Requested packet control options. */
202 struct ul255_t pco_neg; /* Negotiated packet control options. */
203 uint32_t selmode; /* Selection mode. */
204 struct ul255_t rattype; /* Radio Access Technology Type */
205 int rattype_given; /* Radio Access Technology Type given */
206 struct ul255_t userloc; /* User Location Information */
207 int userloc_given; /* User Location Information given */
208 struct ul255_t rai; /* Routing Area Information */
209 int rai_given; /* Routing Area Information given */
210 struct ul255_t mstz; /* MS Time Zone */
211 int mstz_given; /* MS Time Zone given */
212 struct ul255_t imeisv; /* IMEI Software Version */
213 int imeisv_given; /* IMEI Software Version given */
214 int norecovery_given; /* norecovery given */
jjako08d331d2003-10-13 20:33:30 +0000215
Harald Weltebed35df2011-11-02 13:06:18 +0100216 /* Additional parameters used by library */
jjako08d331d2003-10-13 20:33:30 +0000217
Harald Weltebed35df2011-11-02 13:06:18 +0100218 int version; /* Protocol version currently in use. 0 or 1 */
jjako08d331d2003-10-13 20:33:30 +0000219
Harald Weltebed35df2011-11-02 13:06:18 +0100220 uint64_t tid; /* Combination of imsi and nsapi */
221 uint16_t seq; /* Sequence number of last request */
222 struct sockaddr_in sa_peer; /* Address of last request */
223 int fd; /* File descriptor request was received on */
jjako2c381332003-10-21 19:09:53 +0000224
Harald Weltebed35df2011-11-02 13:06:18 +0100225 uint8_t teic_confirmed; /* 0: Not confirmed. 1: Confirmed */
jjako2c381332003-10-21 19:09:53 +0000226
Harald Weltebed35df2011-11-02 13:06:18 +0100227 /* Parameters used for secondary activation procedure (tei data) */
228 /* If (secondary == 1) then teic_own indicates linked PDP context */
229 uint8_t secondary; /* 0: Primary (control). 1: Secondary (data only) */
230 uint8_t nodata; /* 0: User plane PDP context. 1: No user plane */
jjako2c381332003-10-21 19:09:53 +0000231
Harald Weltebed35df2011-11-02 13:06:18 +0100232 /* Secondary contexts of this primary context */
233 uint32_t secondary_tei[PDP_MAXNSAPI];
jjako193e8b12003-11-10 12:31:41 +0000234
Harald Weltebed35df2011-11-02 13:06:18 +0100235 /* IP address used for Create and Update PDP Context Requests */
236 struct in_addr hisaddr0; /* Server address */
237 struct in_addr hisaddr1; /* Server address */
jjako193e8b12003-11-10 12:31:41 +0000238
Harald Weltebed35df2011-11-02 13:06:18 +0100239 /* to be used by libgtp callers/users (to attach their own private state) */
240 void *priv;
Harald Weltee257be12017-08-12 14:55:09 +0200241
Pau Espin Pedroleefa30d2019-05-31 15:42:49 +0200242 struct gsn_t *gsn; /* Back pointer to GSN where this pdp ctx belongs to */
Harald Welte3c1cce22017-09-24 16:40:12 +0800243
244 bool tx_gpdu_seq; /* Transmit (true) or suppress G-PDU sequence numbers */
Pau Espin Pedrol05ec2b32019-08-16 13:20:09 +0200245
246 struct llist_head qmsg_list_req; /* list of req qmsg_t in retrans queue belonging this pdp ctx */
jjako52c24142002-12-16 13:33:51 +0000247};
248
jjako52c24142002-12-16 13:33:51 +0000249/* functions related to pdp_t management */
Pau Espin Pedroleefa30d2019-05-31 15:42:49 +0200250int gtp_pdp_newpdp(struct gsn_t *gsn, struct pdp_t **pdp, uint64_t imsi,
251 uint8_t nsapi, struct pdp_t *pdp_old);
jjako52c24142002-12-16 13:33:51 +0000252int pdp_freepdp(struct pdp_t *pdp);
Pau Espin Pedroleefa30d2019-05-31 15:42:49 +0200253int gtp_pdp_getgtp0(struct gsn_t *gsn, struct pdp_t **pdp, uint16_t fl);
254int gtp_pdp_getgtp1(struct gsn_t *gsn, struct pdp_t **pdp, uint32_t tei);
255int gtp_pdp_getgtp1_peer_d(struct gsn_t *gsn, struct pdp_t **pdp, const struct sockaddr_in *peer, uint32_t teid_gn);
256int gtp_pdp_getimsi(struct gsn_t *gsn, struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi);
257int gtp_pdp_tidget(struct gsn_t *gsn, struct pdp_t **pdp, uint64_t tid);
jjako52c24142002-12-16 13:33:51 +0000258
259int pdp_tidhash(uint64_t tid);
260int pdp_tidset(struct pdp_t *pdp, uint64_t tid);
261int pdp_tiddel(struct pdp_t *pdp);
jjako52c24142002-12-16 13:33:51 +0000262
Pau Espin Pedroleefa30d2019-05-31 15:42:49 +0200263uint64_t pdp_gettid(uint64_t imsi, uint8_t nsapi);
Pablo Neira Ayuso746b9442014-03-24 17:58:27 +0100264void pdp_set_imsi_nsapi(struct pdp_t *pdp, uint64_t teid);
265
Pau Espin Pedrol9ee8d322019-05-30 14:11:22 +0200266unsigned int pdp_count_secondary(struct pdp_t *pdp);
267
Pau Espin Pedroleefa30d2019-05-31 15:42:49 +0200268/* Deprecated APIs (support for only 1 GSN per process). Must be used only after first call to gtp_new() and until it is freed. */
269int pdp_init(struct gsn_t *gsn); /* Use only allowed inside libgtp to keep compatiblity with deprecated APIs defined here. */
270int pdp_newpdp(struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi,
271 struct pdp_t *pdp_old) OSMO_DEPRECATED("Use gtp_pdp_newpdp() instead");
272int pdp_getpdp(struct pdp_t **pdp) OSMO_DEPRECATED("Use gsn_t->pdpa field instead");
273int pdp_getgtp0(struct pdp_t **pdp, uint16_t fl) OSMO_DEPRECATED("Use gtp_pdp_getgtp0() instead");
274int pdp_getgtp1(struct pdp_t **pdp, uint32_t tei) OSMO_DEPRECATED("Use gtp_pdp_getgtp1() instead");
275int pdp_getgtp1_peer_d(struct pdp_t **pdp, const struct sockaddr_in *peer, uint32_t teid_gn) OSMO_DEPRECATED("Use gtp_pdp_getgtp1_peer_d() instead");
276int pdp_getimsi(struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi) OSMO_DEPRECATED("Use gtp_pdp_getimsi() instead");
277int pdp_tidget(struct pdp_t **pdp, uint64_t tid) OSMO_DEPRECATED("Use gtp_pdp_tidget() instead");
278
jjako52c24142002-12-16 13:33:51 +0000279
Harald Weltebed35df2011-11-02 13:06:18 +0100280#endif /* !_PDP_H */