blob: bd60d4ed34fa9a7c72638a9a401caf10894d1da7 [file] [log] [blame]
Harald Welte9b455bf2010-03-14 15:45:01 +08001#ifndef _GPRS_SGSN_H
2#define _GPRS_SGSN_H
3
Harald Welteeaa614c2010-05-02 11:26:34 +02004#include <stdint.h>
Harald Welted193cb32010-05-17 22:58:03 +02005#include <netinet/in.h>
6
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +01007#include <osmocom/gsm/gsm48.h>
Harald Welteeaa614c2010-05-02 11:26:34 +02008
Harald Welte496aee42010-06-30 19:59:55 +02009#include <osmocom/crypt/gprs_cipher.h>
10
Harald Welte2720e732010-05-17 00:44:57 +020011#define GSM_IMSI_LENGTH 17
12#define GSM_IMEI_LENGTH 17
13#define GSM_EXTENSION_LENGTH 15
14
Harald Welte807a5d82010-06-01 11:53:01 +020015struct gprs_llc_lle;
16
Harald Welte9b455bf2010-03-14 15:45:01 +080017/* TS 04.08 4.1.3.3 GMM mobility management states on the network side */
18enum gprs_mm_state {
19 GMM_DEREGISTERED, /* 4.1.3.3.1.1 */
20 GMM_COMMON_PROC_INIT, /* 4.1.3.3.1.2 */
21 GMM_REGISTERED_NORMAL, /* 4.1.3.3.2.1 */
22 GMM_REGISTERED_SUSPENDED, /* 4.1.3.3.2.2 */
23 GMM_DEREGISTERED_INIT, /* 4.1.3.3.1.4 */
24};
25
Harald Weltec2e8cc42010-05-31 20:23:38 +020026enum gprs_mm_ctr {
Harald Welte8acd88f2010-05-18 10:57:45 +020027 GMM_CTR_PKTS_SIG_IN,
28 GMM_CTR_PKTS_SIG_OUT,
29 GMM_CTR_PKTS_UDATA_IN,
30 GMM_CTR_PKTS_UDATA_OUT,
31 GMM_CTR_BYTES_UDATA_IN,
32 GMM_CTR_BYTES_UDATA_OUT,
33 GMM_CTR_PDP_CTX_ACT,
34 GMM_CTR_SUSPEND,
35 GMM_CTR_PAGING_PS,
36 GMM_CTR_PAGING_CS,
37 GMM_CTR_RA_UPDATE,
38};
39
Harald Welteefbdee92010-06-10 00:20:12 +020040enum gprs_pdp_ctx {
41 PDP_CTR_PKTS_UDATA_IN,
42 PDP_CTR_PKTS_UDATA_OUT,
43 PDP_CTR_BYTES_UDATA_IN,
44 PDP_CTR_BYTES_UDATA_OUT,
45};
46
Harald Weltec2e8cc42010-05-31 20:23:38 +020047enum gprs_t3350_mode {
48 GMM_T3350_MODE_ATT,
49 GMM_T3350_MODE_RAU,
50 GMM_T3350_MODE_PTMSI_REALL,
51};
52
Harald Welte9b455bf2010-03-14 15:45:01 +080053#define MS_RADIO_ACCESS_CAPA
54
55/* According to TS 03.60, Table 5: SGSN MM and PDP Contexts */
Harald Weltef533e132010-05-01 16:45:46 +020056/* Extended by 3GPP TS 23.060, Table 6: SGSN MM and PDP Contexts */
Harald Welte9b455bf2010-03-14 15:45:01 +080057struct sgsn_mm_ctx {
58 struct llist_head list;
59
60 char imsi[GSM_IMSI_LENGTH];
61 enum gprs_mm_state mm_state;
Harald Welteeaa614c2010-05-02 11:26:34 +020062 uint32_t p_tmsi;
Harald Weltec2e8cc42010-05-31 20:23:38 +020063 uint32_t p_tmsi_old; /* old P-TMSI before new is confirmed */
Harald Welteeaa614c2010-05-02 11:26:34 +020064 uint32_t p_tmsi_sig;
Harald Welte9b455bf2010-03-14 15:45:01 +080065 char imei[GSM_IMEI_LENGTH];
Harald Weltef533e132010-05-01 16:45:46 +020066 /* Opt: Software Version Numbber / TS 23.195 */
Harald Welte9b455bf2010-03-14 15:45:01 +080067 char msisdn[GSM_EXTENSION_LENGTH];
68 struct gprs_ra_id ra;
Harald Welteeaa614c2010-05-02 11:26:34 +020069 uint16_t cell_id;
70 uint32_t cell_id_age;
71 uint16_t sac; /* Iu: Service Area Code */
72 uint32_t sac_age;/* Iu: Service Area Code age */
Harald Welte9b455bf2010-03-14 15:45:01 +080073 /* VLR number */
Harald Welteeaa614c2010-05-02 11:26:34 +020074 uint32_t new_sgsn_addr;
Harald Welte9b455bf2010-03-14 15:45:01 +080075 /* Authentication Triplets */
76 /* Kc */
Harald Weltef533e132010-05-01 16:45:46 +020077 /* Iu: CK, IK, KSI */
Harald Welte9b455bf2010-03-14 15:45:01 +080078 /* CKSN */
79 enum gprs_ciph_algo ciph_algo;
80 struct {
Harald Welteeaa614c2010-05-02 11:26:34 +020081 uint8_t buf[14]; /* 10.5.5.12a */
82 uint8_t len;
Harald Welte9b455bf2010-03-14 15:45:01 +080083 } ms_radio_access_capa;
84 struct {
Harald Welteeaa614c2010-05-02 11:26:34 +020085 uint8_t buf[4]; /* 10.5.5.12 */
86 uint8_t len;
Harald Welte9b455bf2010-03-14 15:45:01 +080087 } ms_network_capa;
Harald Welteeaa614c2010-05-02 11:26:34 +020088 uint16_t drx_parms;
Harald Welte9b455bf2010-03-14 15:45:01 +080089 int mnrg; /* MS reported to HLR? */
90 int ngaf; /* MS reported to MSC/VLR? */
91 int ppf; /* paging for GPRS + non-GPRS? */
92 /* SMS Parameters */
93 int recovery;
Harald Welteba850c52010-05-02 14:40:32 +020094 uint8_t radio_prio_sms;
Harald Welte9b455bf2010-03-14 15:45:01 +080095
96 struct llist_head pdp_list;
97
98 /* Additional bits not present in the GSM TS */
Harald Welte807a5d82010-06-01 11:53:01 +020099 struct gprs_llc_llme *llme;
Harald Welteeaa614c2010-05-02 11:26:34 +0200100 uint32_t tlli;
Harald Welte807a5d82010-06-01 11:53:01 +0200101 uint32_t tlli_new;
Harald Welte6abf94e2010-05-18 10:35:06 +0200102 uint16_t nsei;
103 uint16_t bvci;
Harald Welte8acd88f2010-05-18 10:57:45 +0200104 struct rate_ctr_group *ctrg;
Harald Welte9b455bf2010-03-14 15:45:01 +0800105 struct timer_list timer;
Harald Weltec2e8cc42010-05-31 20:23:38 +0200106 unsigned int T; /* Txxxx number */
107 unsigned int num_T_exp; /* number of consecutive T expirations */
108
109 enum gprs_t3350_mode t3350_mode;
110 uint8_t t3370_id_type;
Harald Welte9b455bf2010-03-14 15:45:01 +0800111};
112
Harald Welte9b455bf2010-03-14 15:45:01 +0800113/* look-up a SGSN MM context based on TLLI + RAI */
Harald Welteeaa614c2010-05-02 11:26:34 +0200114struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli(uint32_t tlli,
Harald Welte9b455bf2010-03-14 15:45:01 +0800115 const struct gprs_ra_id *raid);
Harald Welteeaa614c2010-05-02 11:26:34 +0200116struct sgsn_mm_ctx *sgsn_mm_ctx_by_ptmsi(uint32_t tmsi);
Harald Welte9b455bf2010-03-14 15:45:01 +0800117struct sgsn_mm_ctx *sgsn_mm_ctx_by_imsi(const char *imsi);
118
119/* Allocate a new SGSN MM context */
Harald Welteeaa614c2010-05-02 11:26:34 +0200120struct sgsn_mm_ctx *sgsn_mm_ctx_alloc(uint32_t tlli,
Harald Welte9b455bf2010-03-14 15:45:01 +0800121 const struct gprs_ra_id *raid);
Harald Weltec728eea2010-12-24 23:07:18 +0100122void sgsn_mm_ctx_free(struct sgsn_mm_ctx *mm);
Harald Welte9b455bf2010-03-14 15:45:01 +0800123
Harald Welted193cb32010-05-17 22:58:03 +0200124
125enum pdp_ctx_state {
126 PDP_STATE_NONE,
Harald Welte6abf94e2010-05-18 10:35:06 +0200127 PDP_STATE_CR_REQ,
128 PDP_STATE_CR_CONF,
Harald Weltea9b473a2010-12-24 21:13:26 +0100129
130 /* 04.08 / Figure 6.2 / 6.1.2.2 */
131 PDP_STATE_INACT_PEND,
132 PDP_STATE_INACTIVE = PDP_STATE_NONE,
Harald Welted193cb32010-05-17 22:58:03 +0200133};
134
135enum pdp_type {
136 PDP_TYPE_NONE,
Harald Welte6abf94e2010-05-18 10:35:06 +0200137 PDP_TYPE_ETSI_PPP,
138 PDP_TYPE_IANA_IPv4,
139 PDP_TYPE_IANA_IPv6,
Harald Welted193cb32010-05-17 22:58:03 +0200140};
141
142struct sgsn_pdp_ctx {
143 struct llist_head list; /* list_head for mmctx->pdp_list */
144 struct llist_head g_list; /* list_head for global list */
145 struct sgsn_mm_ctx *mm; /* back pointer to MM CTX */
146 struct sgsn_ggsn_ctx *ggsn; /* which GGSN serves this PDP */
Harald Welteefbdee92010-06-10 00:20:12 +0200147 struct rate_ctr_group *ctrg;
Harald Welted193cb32010-05-17 22:58:03 +0200148
149 //unsigned int id;
150 struct pdp_t *lib; /* pointer to libgtp PDP ctx */
151 enum pdp_ctx_state state;
152 enum pdp_type type;
153 uint32_t address;
154 char *apn_subscribed;
155 //char *apn_used;
Harald Welte6abf94e2010-05-18 10:35:06 +0200156 uint16_t nsapi; /* SNDCP */
157 uint16_t sapi; /* LLC */
Harald Welted193cb32010-05-17 22:58:03 +0200158 uint8_t ti; /* transaction identifier */
159 int vplmn_allowed;
160 uint32_t qos_profile_subscr;
161 //uint32_t qos_profile_req;
162 //uint32_t qos_profile_neg;
163 uint8_t radio_prio;
164 uint32_t tx_npdu_nr;
165 uint32_t rx_npdu_nr;
166 uint32_t tx_gtp_snd;
167 uint32_t rx_gtp_snu;
168 //uint32_t charging_id;
169 int reordering_reqd;
Harald Weltea9b473a2010-12-24 21:13:26 +0100170
171 struct timer_list timer;
172 unsigned int T; /* Txxxx number */
173 unsigned int num_T_exp; /* number of consecutive T expirations */
Harald Welted193cb32010-05-17 22:58:03 +0200174};
175
176
Harald Welte96df6062010-06-03 06:37:26 +0200177/* look up PDP context by MM context and NSAPI */
Harald Welted193cb32010-05-17 22:58:03 +0200178struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_nsapi(const struct sgsn_mm_ctx *mm,
179 uint8_t nsapi);
Harald Welte96df6062010-06-03 06:37:26 +0200180/* look up PDP context by MM context and transaction ID */
Harald Welte77289c22010-05-18 14:32:29 +0200181struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_tid(const struct sgsn_mm_ctx *mm,
182 uint8_t tid);
Harald Welte96df6062010-06-03 06:37:26 +0200183
Harald Welted193cb32010-05-17 22:58:03 +0200184struct sgsn_pdp_ctx *sgsn_pdp_ctx_alloc(struct sgsn_mm_ctx *mm,
185 uint8_t nsapi);
186void sgsn_pdp_ctx_free(struct sgsn_pdp_ctx *pdp);
187
188
Harald Welte77289c22010-05-18 14:32:29 +0200189struct sgsn_ggsn_ctx {
Harald Welted193cb32010-05-17 22:58:03 +0200190 struct llist_head list;
191 uint32_t id;
192 unsigned int gtp_version;
193 struct in_addr remote_addr;
Harald Weltea9b473a2010-12-24 21:13:26 +0100194 int remote_restart_ctr;
Harald Welted193cb32010-05-17 22:58:03 +0200195 struct gsn_t *gsn;
196};
Harald Weltecd4dd4d2010-05-18 17:20:49 +0200197struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_alloc(uint32_t id);
198struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_id(uint32_t id);
Harald Weltea9b473a2010-12-24 21:13:26 +0100199struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_addr(struct in_addr *addr);
Harald Weltecd4dd4d2010-05-18 17:20:49 +0200200struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_find_alloc(uint32_t id);
Harald Welted193cb32010-05-17 22:58:03 +0200201
202struct apn_ctx {
203 struct llist_head list;
Harald Welte77289c22010-05-18 14:32:29 +0200204 struct sgsn_ggsn_ctx *ggsn;
Harald Welted193cb32010-05-17 22:58:03 +0200205 char *name;
206 char *description;
207};
208
209extern struct llist_head sgsn_mm_ctxts;
210extern struct llist_head sgsn_ggsn_ctxts;
211extern struct llist_head sgsn_apn_ctxts;
212extern struct llist_head sgsn_pdp_ctxts;
213
Harald Welte6463c072010-05-18 17:04:55 +0200214uint32_t sgsn_alloc_ptmsi(void);
215
Harald Weltea9b473a2010-12-24 21:13:26 +0100216/* High-level function to be called in case a GGSN has disappeared or
217 * ottherwise lost state (recovery procedure) */
218int drop_all_pdp_for_ggsn(struct sgsn_ggsn_ctx *ggsn);
219
Harald Welte9b455bf2010-03-14 15:45:01 +0800220#endif /* _GPRS_SGSN_H */