jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * OpenGGSN - Gateway GPRS Support Node |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 3 | * Copyright (C) 2002, 2003 Mondru AB. |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 4 | * |
| 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 | * |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #ifndef _PDP_H |
| 13 | #define _PDP_H |
| 14 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 15 | #define PDP_MAX 1024 /* Max number of PDP contexts */ |
| 16 | #define PDP_MAXNSAPI 16 /* Max number of NSAPI */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 17 | |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 18 | /* GTP Information elements from 29.060 v3.9.0 7.7 Information Elements */ |
| 19 | /* Also covers version 0. Note that version 0 6: QOS Profile was superceded * |
| 20 | * by 135: QOS Profile in version 1 */ |
| 21 | |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 22 | struct sl_t { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 23 | unsigned int l; |
| 24 | char *v; |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | struct ul_t { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 28 | unsigned int l; |
| 29 | unsigned char *v; |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | struct ul16_t { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 33 | unsigned int l; |
| 34 | unsigned char v[16]; |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | struct ul66_t { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 38 | unsigned int l; |
| 39 | unsigned char v[66]; |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | struct ul255_t { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 43 | unsigned int l; |
| 44 | unsigned char v[255]; |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
jjako | 2c38133 | 2003-10-21 19:09:53 +0000 | [diff] [blame] | 47 | /* ***************************************************************** |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 48 | * Information storage for each PDP context |
| 49 | * |
jjako | 2c38133 | 2003-10-21 19:09:53 +0000 | [diff] [blame] | 50 | * Information storage for each PDP context is defined in 23.060 |
| 51 | * section 13.3 and 03.60. Includes IMSI, MSISDN, APN, PDP-type, |
| 52 | * PDP-address (IP address), sequence numbers, charging ID. For the |
| 53 | * SGSN it also includes radio related mobility information. |
| 54 | * |
| 55 | * The following structure is a combination of the storage |
| 56 | * requirements for each PDP context for the GGSN and SGSN. It |
| 57 | * contains both 23.060 as well as 03.60 parameters. Information is |
| 58 | * stored in the format for information elements described in 29.060 |
| 59 | * and 09.60. |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 60 | * 31 * 4 + 15 structs + = 120 + 15 structs ~ 2k / context |
| 61 | * Structs: IP address 16+4 bytes (6), APN 255 bytes (2) |
| 62 | * QOS: 255 bytes (3), msisdn 16 bytes (1), |
| 63 | * |
| 64 | * TODO: We need to consider who manages the pdp_t hash tables |
| 65 | * Is it gtp_lib, or is it the application? |
| 66 | * I suppose that it will be gtp_lib. |
| 67 | * SGSN will ask gtplib for new pdp_t. Fill out the fields, |
| 68 | * and pass it on to gtp_create_pdp_req. |
| 69 | * GGSN will receive gtp_create_pdp_ind, create new pdp_t and |
| 70 | * send responce to SGSN. |
| 71 | * SGSN will receive response and gtplib will find the |
| 72 | * original pdp_t corresponding to the request. This will be |
| 73 | * passed on to the application. |
| 74 | * Eventually the SGSN will close the connection, and the |
| 75 | * pdp_t will be freed by gtplib in SGSN and GGSN |
| 76 | * This means that gtplib need to have functions to |
| 77 | * allocate, free, sort and find pdp_t |
| 78 | * (newpdp, freepdp, getpdp) |
| 79 | * Hash tables: TID, IMSI, IP etc.) |
jjako | 2c38133 | 2003-10-21 19:09:53 +0000 | [diff] [blame] | 80 | * |
| 81 | * |
| 82 | * Secondary PDP Context Activation Procedure |
| 83 | * |
| 84 | * With GTP version 1 it is possible to establish multiple PDP |
| 85 | * contexts with the same IP address. With this scheme the first |
| 86 | * context is established as normal. Following contexts are |
| 87 | * established by referencing one of the allready existing ones. Each |
| 88 | * context is uniquely identified by IMSI and NSAPI. Each context is |
| 89 | * allocated an tei_di, but they all share the same tei_c. |
| 90 | * |
| 91 | * For Delete PDP Context the context is referenced by tei_c and |
| 92 | * nsapi. As an option it is possible to include a teardown indicater, |
| 93 | * in which case all PDP contexts with the same tei_c (IP address) are |
| 94 | * deleted. |
| 95 | * |
| 96 | * For Update PDP Context the context is normally referenced by tei_c |
| 97 | * and nsapi. If moving from GTP0 to GTP1 during an update the context |
| 98 | * is referenced instead by IMSI and NSAPI. |
| 99 | *****************************************************************/ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 100 | |
| 101 | struct pdp_t { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 102 | /* Parameter determining if this PDP is in use. */ |
| 103 | uint8_t inuse; /* 0=free. 1=used by somebody */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 104 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 105 | /* Pointers related to hash tables */ |
| 106 | struct pdp_t *tidnext; |
| 107 | struct pdp_t *ipnext; |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 108 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 109 | /* Parameters shared by all PDP context belonging to the same MS */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 110 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 111 | void *ipif; /* IP network interface */ |
| 112 | void *peer; /* Pointer to peer protocol */ |
| 113 | void *asap; /* Application specific service access point */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 114 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 115 | uint64_t imsi; /* International Mobile Subscriber Identity. */ |
| 116 | struct ul16_t msisdn; /* The basic MSISDN of the MS. */ |
| 117 | uint8_t mnrg; /* Indicates whether the MS is marked as not reachable for PS at the HLR. (1 bit, not transmitted) */ |
| 118 | uint8_t cch_sub; /* The charging characteristics for the MS, e.g. normal, prepaid, flat-rate, and/or hot billing subscription. (not transmitted) */ |
| 119 | uint16_t traceref; /* Identifies a record or a collection of records for a particular trace. */ |
| 120 | uint16_t tracetype; /* Indicates the type of trace. */ |
| 121 | struct ul_t triggerid; /* Identifies the entity that initiated the trace. */ |
| 122 | struct ul_t omcid; /* Identifies the OMC that shall receive the trace record(s). */ |
| 123 | uint8_t rec_hlr; /* Indicates if HLR or VLR is performing database recovery. (1 bit, not transmitted) */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 124 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 125 | /* Parameters specific to each individual PDP context */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 126 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 127 | uint8_t pdp_id; /* Index of the PDP context. (PDP context identifier) */ |
| 128 | uint8_t pdp_state; /* PDP State Packet data protocol state, INACTIVE or ACTIVE. (1 bit, not transmitted) */ |
| 129 | /* struct ul_t pdp_type; * PDP type; e.g. PPP or IP. */ |
| 130 | /* struct ul_t pdp_addr; * PDP address; e.g. an IP address. */ |
| 131 | struct ul66_t eua; /* End user address. PDP type and address combined */ |
| 132 | uint8_t pdp_dyn; /* Indicates whether PDP Address is static or dynamic. (1 bit, not transmitted) */ |
| 133 | struct ul255_t apn_req; /* The APN requested. */ |
| 134 | struct ul255_t apn_sub; /* The APN received from the HLR. */ |
| 135 | struct ul255_t apn_use; /* The APN Network Identifier currently used. */ |
| 136 | uint8_t nsapi; /* Network layer Service Access Point Identifier. (4 bit) */ |
| 137 | uint16_t ti; /* Transaction Identifier. (4 or 12 bit) */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 138 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 139 | uint32_t teic_own; /* (Own Tunnel Endpoint Identifier Control) */ |
| 140 | uint32_t teid_own; /* (Own Tunnel Endpoint Identifier Data I) */ |
| 141 | uint32_t teic_gn; /* Tunnel Endpoint Identifier for the Gn and Gp interfaces. (Control plane) */ |
| 142 | uint32_t teid_gn; /* Tunnel Endpoint Identifier for the Gn and Gp interfaces. (Data I) */ |
| 143 | uint32_t tei_iu; /* Tunnel Endpoint Identifier for the Iu interface. */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 144 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 145 | uint16_t fllc; /* (Local Flow Label Control, gtp0) */ |
| 146 | uint16_t fllu; /* (Local Flow Label Data I, gtp0) */ |
| 147 | uint16_t flrc; /* (Remote gn/gp Flow Label Control, gtp0) */ |
| 148 | uint16_t flru; /* (Remote gn/gp Flow Label Data I, gtp0) */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 149 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 150 | struct ul255_t tft; /* Traffic flow template. */ |
| 151 | /*struct ul16_t sgsnc; * The IP address of the SGSN currently serving this MS. (Control plane) */ |
| 152 | /*struct ul16_t sgsnu; * The IP address of the SGSN currently serving this MS. (User plane) */ |
| 153 | /*struct ul16_t ggsnc; * The IP address of the GGSN currently used. (Control plane) */ |
| 154 | /*struct ul16_t ggsnu; * The IP address of the GGSN currently used. (User plane) */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 155 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 156 | struct ul16_t gsnlc; /* The IP address of the local GSN. (Control plane) */ |
| 157 | struct ul16_t gsnlu; /* The IP address of the local GSN. (User plane) */ |
| 158 | struct ul16_t gsnrc; /* The IP address of the remote GSN. (Control plane) */ |
| 159 | struct ul16_t gsnru; /* The IP address of the remote GSN. (User plane) */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 160 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 161 | 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) */ |
| 162 | uint8_t qos_sub0[3]; /* The quality of service profile subscribed. */ |
| 163 | uint8_t qos_req0[3]; /* The quality of service profile requested. */ |
| 164 | uint8_t qos_neg0[3]; /* The quality of service profile negotiated. */ |
| 165 | struct ul255_t qos_sub; /* The quality of service profile subscribed. */ |
| 166 | struct ul255_t qos_req; /* The quality of service profile requested. */ |
| 167 | struct ul255_t qos_neg; /* The quality of service profile negotiated. */ |
| 168 | uint8_t radio_pri; /* The RLC/MAC radio priority level for uplink user data transmission. (4 bit) */ |
| 169 | uint16_t flow_id; /* Packet flow identifier. */ |
| 170 | /* 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) */ |
| 171 | uint8_t sndcpd; /* SNDCP sequence number of the next downlink N-PDU to be sent to the MS. */ |
| 172 | uint8_t sndcpu; /* SNDCP sequence number of the next uplink N-PDU expected from the MS. */ |
| 173 | uint8_t rec_sgsn; /* Indicates if the SGSN is performing database recovery. (1 bit, not transmitted) */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 174 | /* uint16_t gtpsnd; GTP-U sequence number of the next downlink N-PDU to be sent to the SGSN / received from the GGSN. */ |
| 175 | /* uint16_t gtpsnu; GTP-U sequence number of the next uplink N-PDU to be received from the SGSN / sent to the GGSN */ |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 176 | uint16_t gtpsntx; /* GTP-U sequence number of the next downlink N-PDU to be sent (09.60 section 8.1.1.1) */ |
| 177 | uint16_t gtpsnrx; /* GTP-U sequence number of the next uplink N-PDU to be received (09.60 section 8.1.1.1) */ |
| 178 | uint8_t pdcpsndd; /* Sequence number of the next downlink in-sequence PDCP-PDU to be sent to the MS. */ |
| 179 | uint8_t pdcpsndu; /* Sequence number of the next uplink in-sequence PDCP-PDU expected from the MS. */ |
| 180 | uint32_t cid; /* Charging identifier, identifies charging records generated by SGSN and GGSN. */ |
| 181 | uint16_t cch_pdp; /* The charging characteristics for this PDP context, e.g. normal, prepaid, flat-rate, and/or hot billing. */ |
| 182 | struct ul16_t rnc_addr; /* The IP address of the RNC currently used. */ |
| 183 | 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) */ |
| 184 | struct ul255_t pco_req; /* Requested packet control options. */ |
| 185 | struct ul255_t pco_neg; /* Negotiated packet control options. */ |
| 186 | uint32_t selmode; /* Selection mode. */ |
| 187 | struct ul255_t rattype; /* Radio Access Technology Type */ |
| 188 | int rattype_given; /* Radio Access Technology Type given */ |
| 189 | struct ul255_t userloc; /* User Location Information */ |
| 190 | int userloc_given; /* User Location Information given */ |
| 191 | struct ul255_t rai; /* Routing Area Information */ |
| 192 | int rai_given; /* Routing Area Information given */ |
| 193 | struct ul255_t mstz; /* MS Time Zone */ |
| 194 | int mstz_given; /* MS Time Zone given */ |
| 195 | struct ul255_t imeisv; /* IMEI Software Version */ |
| 196 | int imeisv_given; /* IMEI Software Version given */ |
| 197 | int norecovery_given; /* norecovery given */ |
jjako | 08d331d | 2003-10-13 20:33:30 +0000 | [diff] [blame] | 198 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 199 | /* Additional parameters used by library */ |
jjako | 08d331d | 2003-10-13 20:33:30 +0000 | [diff] [blame] | 200 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 201 | int version; /* Protocol version currently in use. 0 or 1 */ |
jjako | 08d331d | 2003-10-13 20:33:30 +0000 | [diff] [blame] | 202 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 203 | uint64_t tid; /* Combination of imsi and nsapi */ |
| 204 | uint16_t seq; /* Sequence number of last request */ |
| 205 | struct sockaddr_in sa_peer; /* Address of last request */ |
| 206 | int fd; /* File descriptor request was received on */ |
jjako | 2c38133 | 2003-10-21 19:09:53 +0000 | [diff] [blame] | 207 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 208 | uint8_t teic_confirmed; /* 0: Not confirmed. 1: Confirmed */ |
jjako | 2c38133 | 2003-10-21 19:09:53 +0000 | [diff] [blame] | 209 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 210 | /* Parameters used for secondary activation procedure (tei data) */ |
| 211 | /* If (secondary == 1) then teic_own indicates linked PDP context */ |
| 212 | uint8_t secondary; /* 0: Primary (control). 1: Secondary (data only) */ |
| 213 | uint8_t nodata; /* 0: User plane PDP context. 1: No user plane */ |
jjako | 2c38133 | 2003-10-21 19:09:53 +0000 | [diff] [blame] | 214 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 215 | /* Secondary contexts of this primary context */ |
| 216 | uint32_t secondary_tei[PDP_MAXNSAPI]; |
jjako | 193e8b1 | 2003-11-10 12:31:41 +0000 | [diff] [blame] | 217 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 218 | /* IP address used for Create and Update PDP Context Requests */ |
| 219 | struct in_addr hisaddr0; /* Server address */ |
| 220 | struct in_addr hisaddr1; /* Server address */ |
jjako | 193e8b1 | 2003-11-10 12:31:41 +0000 | [diff] [blame] | 221 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 222 | /* to be used by libgtp callers/users (to attach their own private state) */ |
| 223 | void *priv; |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 224 | }; |
| 225 | |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 226 | /* functions related to pdp_t management */ |
| 227 | int pdp_init(); |
| 228 | int pdp_newpdp(struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi, |
| 229 | struct pdp_t *pdp_old); |
| 230 | int pdp_freepdp(struct pdp_t *pdp); |
| 231 | int pdp_getpdp(struct pdp_t **pdp); |
| 232 | |
| 233 | int pdp_getgtp0(struct pdp_t **pdp, uint16_t fl); |
jjako | 08d331d | 2003-10-13 20:33:30 +0000 | [diff] [blame] | 234 | int pdp_getgtp1(struct pdp_t **pdp, uint32_t tei); |
| 235 | |
| 236 | int pdp_getimsi(struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 237 | |
| 238 | int pdp_tidhash(uint64_t tid); |
| 239 | int pdp_tidset(struct pdp_t *pdp, uint64_t tid); |
| 240 | int pdp_tiddel(struct pdp_t *pdp); |
| 241 | int pdp_tidget(struct pdp_t **pdp, uint64_t tid); |
| 242 | |
Pablo Neira Ayuso | 746b944 | 2014-03-24 17:58:27 +0100 | [diff] [blame] | 243 | void pdp_set_imsi_nsapi(struct pdp_t *pdp, uint64_t teid); |
| 244 | |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 245 | /* |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 246 | int pdp_iphash(void* ipif, struct ul66_t *eua); |
| 247 | int pdp_ipset(struct pdp_t *pdp, void* ipif, struct ul66_t *eua); |
| 248 | int pdp_ipdel(struct pdp_t *pdp); |
| 249 | int pdp_ipget(struct pdp_t **pdp, void* ipif, struct ul66_t *eua); |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 250 | */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 251 | |
| 252 | int pdp_ntoeua(struct in_addr *src, struct ul66_t *eua); |
jjako | a7cd249 | 2003-04-11 09:40:12 +0000 | [diff] [blame] | 253 | int pdp_euaton(struct ul66_t *eua, struct in_addr *dst); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 254 | uint64_t pdp_gettid(uint64_t imsi, uint8_t nsapi); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 255 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 256 | #endif /* !_PDP_H */ |